drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_mbox.c

Source file repositories/reference/linux-study-clean/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_mbox.c

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_mbox.c
Extension
.c
Size
11742 bytes
Lines
432
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 (notif->s_link_status.status) {
			link_info->oper_up = OCTEP_PFVF_LINK_STATUS_UP;
			netif_carrier_on(oct->netdev);
			dev_info(&oct->pdev->dev, "netif_carrier_on\n");
		} else {
			link_info->oper_up = OCTEP_PFVF_LINK_STATUS_DOWN;
			netif_carrier_off(oct->netdev);
			dev_info(&oct->pdev->dev, "netif_carrier_off\n");
		}
		break;
	default:
		dev_err(&oct->pdev->dev,
			"Received unsupported notif %d\n", notif->s.opcode);
		break;
	}
}

static int __octep_vf_mbox_send_cmd(struct octep_vf_device *oct,
				    union octep_pfvf_mbox_word cmd,
				    union octep_pfvf_mbox_word *rsp)
{
	struct octep_vf_mbox *mbox = oct->mbox;
	u64 reg_val = 0ull;
	int count;

	if (!mbox)
		return OCTEP_PFVF_MBOX_CMD_STATUS_NOT_SETUP;

	cmd.s.type = OCTEP_PFVF_MBOX_TYPE_CMD;
	writeq(cmd.u64, mbox->mbox_write_reg);

	/* No response for notification messages */
	if (!rsp)
		return 0;

	for (count = 0; count < OCTEP_PFVF_MBOX_TIMEOUT_WAIT_COUNT; count++) {
		usleep_range(1000, 1500);
		reg_val = readq(mbox->mbox_write_reg);
		if (reg_val != cmd.u64) {
			rsp->u64 = reg_val;
			break;
		}
	}
	if (count == OCTEP_PFVF_MBOX_TIMEOUT_WAIT_COUNT) {
		dev_err(&oct->pdev->dev, "mbox send command timed out\n");
		return OCTEP_PFVF_MBOX_CMD_STATUS_TIMEDOUT;
	}
	if (rsp->s.type != OCTEP_PFVF_MBOX_TYPE_RSP_ACK) {
		dev_err(&oct->pdev->dev, "mbox_send: Received NACK\n");
		return OCTEP_PFVF_MBOX_CMD_STATUS_NACK;
	}
	rsp->u64 = reg_val;
	return 0;
}

int octep_vf_mbox_send_cmd(struct octep_vf_device *oct, union octep_pfvf_mbox_word cmd,
			   union octep_pfvf_mbox_word *rsp)
{
	struct octep_vf_mbox *mbox = oct->mbox;
	int ret;

	if (!mbox)
		return OCTEP_PFVF_MBOX_CMD_STATUS_NOT_SETUP;
	mutex_lock(&mbox->lock);
	if (pfvf_cmd_versions[cmd.s.opcode] > oct->mbox_neg_ver) {
		dev_dbg(&oct->pdev->dev, "CMD:%d not supported in Version:%d\n",
			cmd.s.opcode, oct->mbox_neg_ver);
		mutex_unlock(&mbox->lock);
		return -EOPNOTSUPP;
	}
	ret = __octep_vf_mbox_send_cmd(oct, cmd, rsp);
	mutex_unlock(&mbox->lock);
	return ret;
}

int octep_vf_mbox_bulk_read(struct octep_vf_device *oct, enum octep_pfvf_mbox_opcode opcode,
			    u8 *data, int *size)
{
	struct octep_vf_mbox *mbox = oct->mbox;
	union octep_pfvf_mbox_word cmd;
	union octep_pfvf_mbox_word rsp;
	int data_len = 0, tmp_len = 0;
	int read_cnt, i = 0, ret;

	if (!mbox)
		return OCTEP_PFVF_MBOX_CMD_STATUS_NOT_SETUP;

	mutex_lock(&mbox->lock);
	cmd.u64 = 0;
	cmd.s_data.opcode = opcode;

Annotation

Implementation Notes