Skip to content

Commit

Permalink
eth: fbnic: hwmon: Add completion infrastructure for firmware requests
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Sanman Pradhan authored and Jakub Kicinski committed Jan 15, 2025
1 parent 586b298 commit 378e5cc
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions drivers/net/ethernet/meta/fbnic/fbnic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
79 changes: 79 additions & 0 deletions drivers/net/ethernet/meta/fbnic/fbnic_fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
13 changes: 13 additions & 0 deletions drivers/net/ethernet/meta/fbnic/fbnic_fw.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 { \
Expand Down

0 comments on commit 378e5cc

Please sign in to comment.