eth: fbnic: Add support for multiple concurrent completion messages
authorLee Trager <lee@trager.us>
Mon, 12 May 2025 18:53:59 +0000 (11:53 -0700)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 15 May 2025 10:59:18 +0000 (12:59 +0200)
Extend fbnic mailbox to support multiple concurrent completion messages at
once. This enables fbnic to support running multiple operations at once
which depend on a response from firmware via the mailbox.

Signed-off-by: Lee Trager <lee@trager.us>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Simon Horman <horms@kernel.org>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Link: https://patch.msgid.link/20250512190109.2475614-4-lee@trager.us
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/ethernet/meta/fbnic/fbnic.h
drivers/net/ethernet/meta/fbnic/fbnic_fw.c
drivers/net/ethernet/meta/fbnic/fbnic_fw.h
drivers/net/ethernet/meta/fbnic/fbnic_mac.c

index ad01ed05d78bbdf5647fdfd7f35bdcf9b83a82c6..65815d4f379e43abd71f73fc3d9df74595da6232 100644 (file)
@@ -19,6 +19,7 @@
 struct fbnic_napi_vector;
 
 #define FBNIC_MAX_NAPI_VECTORS         128u
+#define FBNIC_MBX_CMPL_SLOTS           4
 
 struct fbnic_dev {
        struct device *dev;
@@ -42,7 +43,7 @@ struct fbnic_dev {
 
        struct fbnic_fw_mbx mbx[FBNIC_IPC_MBX_INDICES];
        struct fbnic_fw_cap fw_cap;
-       struct fbnic_fw_completion *cmpl_data;
+       struct fbnic_fw_completion *cmpl_data[FBNIC_MBX_CMPL_SLOTS];
        /* Lock protecting Tx Mailbox queue to prevent possible races */
        spinlock_t fw_tx_lock;
 
index e4f72fb730a6f203f6956765fb21f95d6c61ea14..6fcba4e8c21e5234d21f5ad89e1edc6e03cb5958 100644 (file)
@@ -237,6 +237,44 @@ static int fbnic_mbx_map_tlv_msg(struct fbnic_dev *fbd,
        return err;
 }
 
+static int fbnic_mbx_set_cmpl_slot(struct fbnic_dev *fbd,
+                                  struct fbnic_fw_completion *cmpl_data)
+{
+       struct fbnic_fw_mbx *tx_mbx = &fbd->mbx[FBNIC_IPC_MBX_TX_IDX];
+       int free = -EXFULL;
+       int i;
+
+       if (!tx_mbx->ready)
+               return -ENODEV;
+
+       for (i = 0; i < FBNIC_MBX_CMPL_SLOTS; i++) {
+               if (!fbd->cmpl_data[i])
+                       free = i;
+               else if (fbd->cmpl_data[i]->msg_type == cmpl_data->msg_type)
+                       return -EEXIST;
+       }
+
+       if (free == -EXFULL)
+               return -EXFULL;
+
+       fbd->cmpl_data[free] = cmpl_data;
+
+       return 0;
+}
+
+static void fbnic_mbx_clear_cmpl_slot(struct fbnic_dev *fbd,
+                                     struct fbnic_fw_completion *cmpl_data)
+{
+       int i;
+
+       for (i = 0; i < FBNIC_MBX_CMPL_SLOTS; i++) {
+               if (fbd->cmpl_data[i] == cmpl_data) {
+                       fbd->cmpl_data[i] = NULL;
+                       break;
+               }
+       }
+}
+
 static void fbnic_mbx_process_tx_msgs(struct fbnic_dev *fbd)
 {
        struct fbnic_fw_mbx *tx_mbx = &fbd->mbx[FBNIC_IPC_MBX_TX_IDX];
@@ -258,6 +296,19 @@ static void fbnic_mbx_process_tx_msgs(struct fbnic_dev *fbd)
        tx_mbx->head = head;
 }
 
+int fbnic_mbx_set_cmpl(struct fbnic_dev *fbd,
+                      struct fbnic_fw_completion *cmpl_data)
+{
+       unsigned long flags;
+       int err;
+
+       spin_lock_irqsave(&fbd->fw_tx_lock, flags);
+       err = fbnic_mbx_set_cmpl_slot(fbd, cmpl_data);
+       spin_unlock_irqrestore(&fbd->fw_tx_lock, flags);
+
+       return err;
+}
+
 static int fbnic_mbx_map_req_w_cmpl(struct fbnic_dev *fbd,
                                    struct fbnic_tlv_msg *msg,
                                    struct fbnic_fw_completion *cmpl_data)
@@ -266,23 +317,20 @@ static int fbnic_mbx_map_req_w_cmpl(struct fbnic_dev *fbd,
        int err;
 
        spin_lock_irqsave(&fbd->fw_tx_lock, flags);
-
-       /* If we are already waiting on a completion then abort */
-       if (cmpl_data && fbd->cmpl_data) {
-               err = -EBUSY;
-               goto unlock_mbx;
+       if (cmpl_data) {
+               err = fbnic_mbx_set_cmpl_slot(fbd, cmpl_data);
+               if (err)
+                       goto unlock_mbx;
        }
 
-       /* Record completion location and submit request */
-       if (cmpl_data)
-               fbd->cmpl_data = cmpl_data;
-
        err = fbnic_mbx_map_msg(fbd, FBNIC_IPC_MBX_TX_IDX, msg,
                                le16_to_cpu(msg->hdr.len) * sizeof(u32), 1);
 
-       /* If msg failed then clear completion data for next caller */
+       /* If we successfully reserved a completion and msg failed
+        * then clear completion data for next caller
+        */
        if (err && cmpl_data)
-               fbd->cmpl_data = NULL;
+               fbnic_mbx_clear_cmpl_slot(fbd, cmpl_data);
 
 unlock_mbx:
        spin_unlock_irqrestore(&fbd->fw_tx_lock, flags);
@@ -304,12 +352,18 @@ fbnic_fw_get_cmpl_by_type(struct fbnic_dev *fbd, u32 msg_type)
 {
        struct fbnic_fw_completion *cmpl_data = NULL;
        unsigned long flags;
+       int i;
 
        spin_lock_irqsave(&fbd->fw_tx_lock, flags);
-       if (fbd->cmpl_data && fbd->cmpl_data->msg_type == msg_type) {
-               cmpl_data = fbd->cmpl_data;
-               kref_get(&fbd->cmpl_data->ref_count);
+       for (i = 0; i < FBNIC_MBX_CMPL_SLOTS; i++) {
+               if (fbd->cmpl_data[i] &&
+                   fbd->cmpl_data[i]->msg_type == msg_type) {
+                       cmpl_data = fbd->cmpl_data[i];
+                       kref_get(&cmpl_data->ref_count);
+                       break;
+               }
        }
+
        spin_unlock_irqrestore(&fbd->fw_tx_lock, flags);
 
        return cmpl_data;
@@ -925,10 +979,16 @@ static void __fbnic_fw_evict_cmpl(struct fbnic_fw_completion *cmpl_data)
 
 static void fbnic_mbx_evict_all_cmpl(struct fbnic_dev *fbd)
 {
-       if (fbd->cmpl_data) {
-               __fbnic_fw_evict_cmpl(fbd->cmpl_data);
-               fbd->cmpl_data = NULL;
+       int i;
+
+       for (i = 0; i < FBNIC_MBX_CMPL_SLOTS; i++) {
+               struct fbnic_fw_completion *cmpl_data = fbd->cmpl_data[i];
+
+               if (cmpl_data)
+                       __fbnic_fw_evict_cmpl(cmpl_data);
        }
+
+       memset(fbd->cmpl_data, 0, sizeof(fbd->cmpl_data));
 }
 
 void fbnic_mbx_flush_tx(struct fbnic_dev *fbd)
@@ -989,12 +1049,13 @@ void fbnic_fw_init_cmpl(struct fbnic_fw_completion *fw_cmpl,
        kref_init(&fw_cmpl->ref_count);
 }
 
-void fbnic_fw_clear_compl(struct fbnic_dev *fbd)
+void fbnic_fw_clear_cmpl(struct fbnic_dev *fbd,
+                        struct fbnic_fw_completion *fw_cmpl)
 {
        unsigned long flags;
 
        spin_lock_irqsave(&fbd->fw_tx_lock, flags);
-       fbd->cmpl_data = NULL;
+       fbnic_mbx_clear_cmpl_slot(fbd, fw_cmpl);
        spin_unlock_irqrestore(&fbd->fw_tx_lock, flags);
 }
 
index 692dfd8746e78a9d1eda6276d41c54e476bad5fa..39dec0792090a626eaac4e7de5463fd7101c0495 100644 (file)
@@ -60,6 +60,8 @@ struct fbnic_fw_completion {
 
 void fbnic_mbx_init(struct fbnic_dev *fbd);
 void fbnic_mbx_clean(struct fbnic_dev *fbd);
+int fbnic_mbx_set_cmpl(struct fbnic_dev *fbd,
+                      struct fbnic_fw_completion *cmpl_data);
 void fbnic_mbx_poll(struct fbnic_dev *fbd);
 int fbnic_mbx_poll_tx_ready(struct fbnic_dev *fbd);
 void fbnic_mbx_flush_tx(struct fbnic_dev *fbd);
@@ -70,7 +72,8 @@ int fbnic_fw_xmit_tsene_read_msg(struct fbnic_dev *fbd,
                                 struct fbnic_fw_completion *cmpl_data);
 void fbnic_fw_init_cmpl(struct fbnic_fw_completion *cmpl_data,
                        u32 msg_type);
-void fbnic_fw_clear_compl(struct fbnic_dev *fbd);
+void fbnic_fw_clear_cmpl(struct fbnic_dev *fbd,
+                        struct fbnic_fw_completion *cmpl_data);
 void fbnic_fw_put_cmpl(struct fbnic_fw_completion *cmpl_data);
 
 #define fbnic_mk_full_fw_ver_str(_rev_id, _delim, _commit, _str, _str_sz) \
index dde4a37116e20e99864bad48d29f5b17846653bc..4ba6f8d107754b8f2f3646656ab3ab1480d77108 100644 (file)
@@ -744,7 +744,7 @@ static int fbnic_mac_get_sensor_asic(struct fbnic_dev *fbd, int id,
 
        *val = *sensor;
 exit_cleanup:
-       fbnic_fw_clear_compl(fbd);
+       fbnic_fw_clear_cmpl(fbd, fw_cmpl);
 exit_free:
        fbnic_fw_put_cmpl(fw_cmpl);