Skip to content

Commit fdb9029

Browse files
Geetha sowjanyadavem330
authored andcommitted
octeontx2-af: Sync hw mbox with bounce buffer.
If mailbox client has a bounce buffer or a intermediate buffer where mbox messages are framed then copy them from there to HW buffer. If 'mbase' and 'hw_mbase' are not same then assume 'mbase' points to bounce buffer. This patch also adds msg_size field to mbox header to copy only valid data instead of whole buffer. Signed-off-by: Geetha sowjanya <[email protected]> Signed-off-by: Sunil Goutham <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a36740f commit fdb9029

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

drivers/net/ethernet/marvell/octeontx2/af/mbox.c

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,20 @@ static const u16 msgs_offset = ALIGN(sizeof(struct mbox_hdr), MBOX_MSG_ALIGN);
1919

2020
void otx2_mbox_reset(struct otx2_mbox *mbox, int devid)
2121
{
22+
void *hw_mbase = mbox->hwbase + (devid * MBOX_SIZE);
2223
struct otx2_mbox_dev *mdev = &mbox->dev[devid];
2324
struct mbox_hdr *tx_hdr, *rx_hdr;
2425

25-
tx_hdr = mdev->mbase + mbox->tx_start;
26-
rx_hdr = mdev->mbase + mbox->rx_start;
26+
tx_hdr = hw_mbase + mbox->tx_start;
27+
rx_hdr = hw_mbase + mbox->rx_start;
2728

2829
spin_lock(&mdev->mbox_lock);
2930
mdev->msg_size = 0;
3031
mdev->rsp_size = 0;
3132
tx_hdr->num_msgs = 0;
33+
tx_hdr->msg_size = 0;
3234
rx_hdr->num_msgs = 0;
35+
rx_hdr->msg_size = 0;
3336
spin_unlock(&mdev->mbox_lock);
3437
}
3538
EXPORT_SYMBOL(otx2_mbox_reset);
@@ -133,16 +136,17 @@ EXPORT_SYMBOL(otx2_mbox_init);
133136

134137
int otx2_mbox_wait_for_rsp(struct otx2_mbox *mbox, int devid)
135138
{
139+
unsigned long timeout = jiffies + msecs_to_jiffies(MBOX_RSP_TIMEOUT);
136140
struct otx2_mbox_dev *mdev = &mbox->dev[devid];
137-
int timeout = 0, sleep = 1;
141+
struct device *sender = &mbox->pdev->dev;
138142

139-
while (mdev->num_msgs != mdev->msgs_acked) {
140-
msleep(sleep);
141-
timeout += sleep;
142-
if (timeout >= MBOX_RSP_TIMEOUT)
143-
return -EIO;
143+
while (!time_after(jiffies, timeout)) {
144+
if (mdev->num_msgs == mdev->msgs_acked)
145+
return 0;
146+
usleep_range(800, 1000);
144147
}
145-
return 0;
148+
dev_dbg(sender, "timed out while waiting for rsp\n");
149+
return -EIO;
146150
}
147151
EXPORT_SYMBOL(otx2_mbox_wait_for_rsp);
148152

@@ -162,13 +166,25 @@ EXPORT_SYMBOL(otx2_mbox_busy_poll_for_rsp);
162166

163167
void otx2_mbox_msg_send(struct otx2_mbox *mbox, int devid)
164168
{
169+
void *hw_mbase = mbox->hwbase + (devid * MBOX_SIZE);
165170
struct otx2_mbox_dev *mdev = &mbox->dev[devid];
166171
struct mbox_hdr *tx_hdr, *rx_hdr;
167172

168-
tx_hdr = mdev->mbase + mbox->tx_start;
169-
rx_hdr = mdev->mbase + mbox->rx_start;
173+
tx_hdr = hw_mbase + mbox->tx_start;
174+
rx_hdr = hw_mbase + mbox->rx_start;
175+
176+
/* If bounce buffer is implemented copy mbox messages from
177+
* bounce buffer to hw mbox memory.
178+
*/
179+
if (mdev->mbase != hw_mbase)
180+
memcpy(hw_mbase + mbox->tx_start + msgs_offset,
181+
mdev->mbase + mbox->tx_start + msgs_offset,
182+
mdev->msg_size);
170183

171184
spin_lock(&mdev->mbox_lock);
185+
186+
tx_hdr->msg_size = mdev->msg_size;
187+
172188
/* Reset header for next messages */
173189
mdev->msg_size = 0;
174190
mdev->rsp_size = 0;
@@ -215,7 +231,7 @@ struct mbox_msghdr *otx2_mbox_alloc_msg_rsp(struct otx2_mbox *mbox, int devid,
215231
msghdr = mdev->mbase + mbox->tx_start + msgs_offset + mdev->msg_size;
216232

217233
/* Clear the whole msg region */
218-
memset(msghdr, 0, sizeof(*msghdr) + size);
234+
memset(msghdr, 0, size);
219235
/* Init message header with reset values */
220236
msghdr->ver = OTX2_MBOX_VERSION;
221237
mdev->msg_size += size;

drivers/net/ethernet/marvell/octeontx2/af/mbox.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
#define INTR_MASK(pfvfs) ((pfvfs < 64) ? (BIT_ULL(pfvfs) - 1) : (~0ull))
3838

39-
#define MBOX_RSP_TIMEOUT 1000 /* in ms, Time to wait for mbox response */
39+
#define MBOX_RSP_TIMEOUT 2000 /* Time(ms) to wait for mbox response */
4040

4141
#define MBOX_MSG_ALIGN 16 /* Align mbox msg start to 16bytes */
4242

@@ -75,6 +75,7 @@ struct otx2_mbox {
7575

7676
/* Header which preceeds all mbox messages */
7777
struct mbox_hdr {
78+
u64 msg_size; /* Total msgs size embedded */
7879
u16 num_msgs; /* No of msgs embedded */
7980
};
8081

0 commit comments

Comments
 (0)