]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
eth: fbnic: hwmon: Add completion infrastructure for firmware requests
authorSanman Pradhan <sanman.p211993@gmail.com>
Tue, 14 Jan 2025 00:07:03 +0000 (16:07 -0800)
committerJakub Kicinski <kuba@kernel.org>
Wed, 15 Jan 2025 22:14:11 +0000 (14:14 -0800)
Add infrastructure to support firmware request/response handling with
completions. Add a completion structure to track message state including
message type for matching, completion for waiting for response, and
result for error propagation. Use existing spinlock to protect the writes.
The data from the various response types will be added to the "union u"
by subsequent commits.

Signed-off-by: Sanman Pradhan <sanman.p211993@gmail.com>
Reviewed-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
Link: https://patch.msgid.link/20250114000705.2081288-2-sanman.p211993@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/meta/fbnic/fbnic.h
drivers/net/ethernet/meta/fbnic/fbnic_fw.c
drivers/net/ethernet/meta/fbnic/fbnic_fw.h

index 50f97f5399ff5f6e6b1620ab79bf0ca12d33fd37..ad8ac5ac7be9bc53c6bb385faf42ed64b15cfbf8 100644 (file)
@@ -41,6 +41,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;
        /* Lock protecting Tx Mailbox queue to prevent possible races */
        spinlock_t fw_tx_lock;
 
index 8f7a2a19ddf8024e70670532dd908159101781b7..320615a122e46fbe3eb4825e62929ce86c72f61f 100644 (file)
@@ -228,6 +228,63 @@ static void fbnic_mbx_process_tx_msgs(struct fbnic_dev *fbd)
        tx_mbx->head = head;
 }
 
+static __maybe_unused int fbnic_mbx_map_req_w_cmpl(struct fbnic_dev *fbd,
+                                                  struct fbnic_tlv_msg *msg,
+                                                  struct fbnic_fw_completion *cmpl_data)
+{
+       unsigned long flags;
+       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;
+       }
+
+       /* 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 (err && cmpl_data)
+               fbd->cmpl_data = NULL;
+
+unlock_mbx:
+       spin_unlock_irqrestore(&fbd->fw_tx_lock, flags);
+
+       return err;
+}
+
+static void fbnic_fw_release_cmpl_data(struct kref *kref)
+{
+       struct fbnic_fw_completion *cmpl_data;
+
+       cmpl_data = container_of(kref, struct fbnic_fw_completion,
+                                ref_count);
+       kfree(cmpl_data);
+}
+
+static __maybe_unused struct fbnic_fw_completion *
+fbnic_fw_get_cmpl_by_type(struct fbnic_dev *fbd, u32 msg_type)
+{
+       struct fbnic_fw_completion *cmpl_data = NULL;
+       unsigned long flags;
+
+       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);
+       }
+       spin_unlock_irqrestore(&fbd->fw_tx_lock, flags);
+
+       return cmpl_data;
+}
+
 /**
  * fbnic_fw_xmit_simple_msg - Transmit a simple single TLV message w/o data
  * @fbd: FBNIC device structure
@@ -802,3 +859,25 @@ void fbnic_get_fw_ver_commit_str(struct fbnic_dev *fbd, char *fw_version,
        fbnic_mk_full_fw_ver_str(mgmt->version, delim, mgmt->commit,
                                 fw_version, str_sz);
 }
+
+void fbnic_fw_init_cmpl(struct fbnic_fw_completion *fw_cmpl,
+                       u32 msg_type)
+{
+       fw_cmpl->msg_type = msg_type;
+       init_completion(&fw_cmpl->done);
+       kref_init(&fw_cmpl->ref_count);
+}
+
+void fbnic_fw_clear_compl(struct fbnic_dev *fbd)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&fbd->fw_tx_lock, flags);
+       fbd->cmpl_data = NULL;
+       spin_unlock_irqrestore(&fbd->fw_tx_lock, flags);
+}
+
+void fbnic_fw_put_cmpl(struct fbnic_fw_completion *fw_cmpl)
+{
+       kref_put(&fw_cmpl->ref_count, fbnic_fw_release_cmpl_data);
+}
index 221faf8c67566c083ab250d73ef6a5151838842a..ff304baade918be3a1fc736321c0efa89ce49cb9 100644 (file)
@@ -44,6 +44,15 @@ struct fbnic_fw_cap {
        u8      link_fec;
 };
 
+struct fbnic_fw_completion {
+       u32 msg_type;
+       struct completion done;
+       struct kref ref_count;
+       int result;
+       union {
+       } u;
+};
+
 void fbnic_mbx_init(struct fbnic_dev *fbd);
 void fbnic_mbx_clean(struct fbnic_dev *fbd);
 void fbnic_mbx_poll(struct fbnic_dev *fbd);
@@ -52,6 +61,10 @@ void fbnic_mbx_flush_tx(struct fbnic_dev *fbd);
 int fbnic_fw_xmit_ownership_msg(struct fbnic_dev *fbd, bool take_ownership);
 int fbnic_fw_init_heartbeat(struct fbnic_dev *fbd, bool poll);
 void fbnic_fw_check_heartbeat(struct fbnic_dev *fbd);
+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_put_cmpl(struct fbnic_fw_completion *cmpl_data);
 
 #define fbnic_mk_full_fw_ver_str(_rev_id, _delim, _commit, _str, _str_sz) \
 do {                                                                   \