Skip to content

Commit ce2fa1d

Browse files
ahduyckPaolo Abeni
authored and
Paolo Abeni
committed
fbnic: Do not allow mailbox to toggle to ready outside fbnic_mbx_poll_tx_ready
We had originally thought to have the mailbox go to ready in the background while we were doing other things. One issue with this though is that we can't disable it by clearing the ready state without also blocking interrupts or calls to mbx_poll as it will just pop back to life during an interrupt. In order to prevent that from happening we can pull the code for toggling to ready out of the interrupt path and instead place it in the fbnic_mbx_poll_tx_ready path so that it becomes the only spot where the Rx/Tx can toggle to the ready state. By doing this we can prevent races where we disable the DMA and/or free buffers only to have an interrupt fire and undo what we have done. Fixes: da3cde0 ("eth: fbnic: Add FW communication mechanism") Signed-off-by: Alexander Duyck <alexanderduyck@fb.com> Reviewed-by: Jacob Keller <jacob.e.keller@intel.com> Link: https://patch.msgid.link/174654722518.499179.11612865740376848478.stgit@ahduyck-xeon-server.home.arpa Reviewed-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 1b34d1c commit ce2fa1d

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

drivers/net/ethernet/meta/fbnic/fbnic_fw.c

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,6 @@ static void fbnic_mbx_init_desc_ring(struct fbnic_dev *fbd, int mbx_idx)
356356
{
357357
struct fbnic_fw_mbx *mbx = &fbd->mbx[mbx_idx];
358358

359-
/* This is a one time init, so just exit if it is completed */
360-
if (mbx->ready)
361-
return;
362-
363359
mbx->ready = true;
364360

365361
switch (mbx_idx) {
@@ -379,21 +375,18 @@ static void fbnic_mbx_init_desc_ring(struct fbnic_dev *fbd, int mbx_idx)
379375
}
380376
}
381377

382-
static void fbnic_mbx_postinit(struct fbnic_dev *fbd)
378+
static bool fbnic_mbx_event(struct fbnic_dev *fbd)
383379
{
384-
int i;
385-
386380
/* We only need to do this on the first interrupt following reset.
387381
* this primes the mailbox so that we will have cleared all the
388382
* skip descriptors.
389383
*/
390384
if (!(rd32(fbd, FBNIC_INTR_STATUS(0)) & (1u << FBNIC_FW_MSIX_ENTRY)))
391-
return;
385+
return false;
392386

393387
wr32(fbd, FBNIC_INTR_CLEAR(0), 1u << FBNIC_FW_MSIX_ENTRY);
394388

395-
for (i = 0; i < FBNIC_IPC_MBX_INDICES; i++)
396-
fbnic_mbx_init_desc_ring(fbd, i);
389+
return true;
397390
}
398391

399392
/**
@@ -870,7 +863,7 @@ static void fbnic_mbx_process_rx_msgs(struct fbnic_dev *fbd)
870863

871864
void fbnic_mbx_poll(struct fbnic_dev *fbd)
872865
{
873-
fbnic_mbx_postinit(fbd);
866+
fbnic_mbx_event(fbd);
874867

875868
fbnic_mbx_process_tx_msgs(fbd);
876869
fbnic_mbx_process_rx_msgs(fbd);
@@ -879,11 +872,9 @@ void fbnic_mbx_poll(struct fbnic_dev *fbd)
879872
int fbnic_mbx_poll_tx_ready(struct fbnic_dev *fbd)
880873
{
881874
unsigned long timeout = jiffies + 10 * HZ + 1;
882-
struct fbnic_fw_mbx *tx_mbx;
883-
int err;
875+
int err, i;
884876

885-
tx_mbx = &fbd->mbx[FBNIC_IPC_MBX_TX_IDX];
886-
while (!tx_mbx->ready) {
877+
do {
887878
if (!time_is_after_jiffies(timeout))
888879
return -ETIMEDOUT;
889880

@@ -898,9 +889,11 @@ int fbnic_mbx_poll_tx_ready(struct fbnic_dev *fbd)
898889
return -ENODEV;
899890

900891
msleep(20);
892+
} while (!fbnic_mbx_event(fbd));
901893

902-
fbnic_mbx_poll(fbd);
903-
}
894+
/* FW has shown signs of life. Enable DMA and start Tx/Rx */
895+
for (i = 0; i < FBNIC_IPC_MBX_INDICES; i++)
896+
fbnic_mbx_init_desc_ring(fbd, i);
904897

905898
/* Request an update from the firmware. This should overwrite
906899
* mgmt.version once we get the actual version from the firmware

0 commit comments

Comments
 (0)