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

Source file repositories/reference/linux-study-clean/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/meta/fbnic/fbnic_devlink.c
Extension
.c
Size
16587 bytes
Lines
670
Domain
Driver Families
Bucket
drivers/net
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (!fbnic_mbx_wait_for_cmpl(cmpl)) {
			err = -ETIMEDOUT;
			break;
		}

		err = cmpl->result;
		if (err)
			break;

		/* Verify firmware is requesting the next chunk in the seq. */
		if (cmpl->u.fw_update.offset != offset + length) {
			err = -EFAULT;
			break;
		}

		offset = cmpl->u.fw_update.offset;
		length = cmpl->u.fw_update.length;

		if (length > TLV_MAX_DATA || offset + length > size) {
			err = -EFAULT;
			break;
		}

		devlink_flash_update_status_notify(devlink, "Flashing",
						   component_name,
						   offset, size);

		/* Mailbox will set length to 0 once it receives the finish
		 * message.
		 */
		if (!length)
			continue;

		reinit_completion(&cmpl->done);
		err = fbnic_fw_xmit_fw_write_chunk(fbd, data, offset, length,
						   0);
		if (err)
			break;
	}

	if (err) {
		fbnic_fw_xmit_fw_write_chunk(fbd, NULL, 0, 0, err);
err_no_msg:
		snprintf(buf, sizeof(buf), "Mailbox encountered error %d!",
			 err);
		devlink_flash_update_status_notify(devlink, buf,
						   component_name, 0, 0);
	}

	fbnic_mbx_clear_cmpl(fbd, cmpl);
cmpl_free:
	fbnic_fw_put_cmpl(cmpl);

	return err;
}

static const struct pldmfw_ops fbnic_pldmfw_ops = {
	.match_record = fbnic_pldm_match_record,
	.flash_component = fbnic_flash_component,
};

static int
fbnic_devlink_flash_update(struct devlink *devlink,
			   struct devlink_flash_update_params *params,
			   struct netlink_ext_ack *extack)
{
	struct fbnic_dev *fbd = devlink_priv(devlink);
	const struct firmware *fw = params->fw;
	struct device *dev = fbd->dev;
	struct pldmfw context;
	char *err_msg;
	int err;

	context.ops = &fbnic_pldmfw_ops;
	context.dev = dev;

	err = pldmfw_flash_image(&context, fw);
	if (err) {
		switch (err) {
		case -EINVAL:
			err_msg = "Invalid image";
			break;
		case -EOPNOTSUPP:
			err_msg = "Unsupported image";
			break;
		case -ENOMEM:
			err_msg = "Out of memory";
			break;
		case -EFAULT:
			err_msg = "Invalid header";

Annotation

Implementation Notes