Skip to contentSkip to conversation

Add iecm and idpf

PATCH New Alan Brady 6 participants 83 messages Jan 28, 2022 – Feb 4, 2022 Page 2 of 5

Subsystems (4)
lore
Share & tools
lore
#27 lore raw

PATCH 6/19 iecm: add virtchnl messages for queues

In reply to Alan Brady

From: Alan Brady <[email protected]>
Date: Thu, 27 Jan 2022 16:09:56 -0800

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 21 lines

This continues adding virtchnl messages. This largely relates to adding messages needed to negotiate and setup traffic queues.

---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    |   14 +
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   |  161 +++
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   | 1127 ++++++++++++++++-
 drivers/net/ethernet/intel/include/iecm.h     |   22 +
 .../net/ethernet/intel/include/iecm_txrx.h    |  196 +++
 5 files changed, 1505 insertions(+), 15 deletions(-)
drivers/net/ethernet/intel/iecm/iecm_lib.c +0 -0
index e2e523f0700e..4e9cc7f2d138 100644

--- 8< ---

Quoted 13 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +13 -0
+void iecm_vport_calc_num_q_desc(struct iecm_vport *vport)
+{
+	int num_req_txq_desc = vport->adapter->config_data.num_req_txq_desc;
+	int num_req_rxq_desc = vport->adapter->config_data.num_req_rxq_desc;
+	int num_bufqs = vport->num_bufqs_per_qgrp;
+	int i = 0;
+
+	vport->complq_desc_count = 0;
+	if (num_req_txq_desc) {
+		vport->txq_desc_count = num_req_txq_desc;
+		if (iecm_is_queue_model_split(vport->txq_model)) {
+			vport->complq_desc_count = num_req_txq_desc;
+			if (vport->complq_desc_count < IECM_MIN_TXQ_COMPLQ_DESC)

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+				vport->complq_desc_count =
+					IECM_MIN_TXQ_COMPLQ_DESC;
+		}
+	} else {
+		vport->txq_desc_count =
+			IECM_DFLT_TX_Q_DESC_COUNT;
+		if (iecm_is_queue_model_split(vport->txq_model)) {
+			vport->complq_desc_count =
+				IECM_DFLT_TX_COMPLQ_DESC_COUNT;
+		}

Braces are redundant here since the path is a one-liner.

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 12 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +12 -0
+	}
+
+	if (num_req_rxq_desc)
+		vport->rxq_desc_count = num_req_rxq_desc;
+	else
+		vport->rxq_desc_count = IECM_DFLT_RX_Q_DESC_COUNT;
+
+	for (i = 0; i < num_bufqs; i++) {
+		if (!vport->bufq_desc_count[i])
+			vport->bufq_desc_count[i] =
+				IECM_RX_BUFQ_DESC_COUNT(vport->rxq_desc_count,
+							num_bufqs);
		if (vport->bufq_desc_count[i])
			continue;

		vport-> ...

-1 indent level with that.

Quoted 490 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +96 -0
+	}
+}
+EXPORT_SYMBOL(iecm_vport_calc_num_q_desc);
+
+/**
+ * iecm_vport_calc_total_qs - Calculate total number of queues
+ * @adapter: private data struct
+ * @vport_msg: message to fill with data
+ */
+void iecm_vport_calc_total_qs(struct iecm_adapter *adapter,
+			      struct virtchnl2_create_vport *vport_msg)
+{
+	unsigned int num_req_tx_qs = adapter->config_data.num_req_tx_qs;
+	unsigned int num_req_rx_qs = adapter->config_data.num_req_rx_qs;
+	int dflt_splitq_txq_grps, dflt_singleq_txqs;
+	int dflt_splitq_rxq_grps, dflt_singleq_rxqs;
+	int num_txq_grps, num_rxq_grps;
+	int num_cpus;
+	u16 max_q;
+
+	/* Restrict num of queues to cpus online as a default configuration to
+	 * give best performance. User can always override to a max number
+	 * of queues via ethtool.
+	 */
+	num_cpus = num_online_cpus();
+	max_q = adapter->max_queue_limit;
+
+	dflt_splitq_txq_grps = min_t(int, max_q, num_cpus);
+	dflt_singleq_txqs = min_t(int, max_q, num_cpus);
+	dflt_splitq_rxq_grps = min_t(int, max_q, num_cpus);
+	dflt_singleq_rxqs = min_t(int, max_q, num_cpus);
+
+	if (iecm_is_queue_model_split(le16_to_cpu(vport_msg->txq_model))) {
+		num_txq_grps = num_req_tx_qs ? num_req_tx_qs : dflt_splitq_txq_grps;
+		vport_msg->num_tx_complq = cpu_to_le16(num_txq_grps *
+						       IECM_COMPLQ_PER_GROUP);
+		vport_msg->num_tx_q = cpu_to_le16(num_txq_grps *
+						  IECM_DFLT_SPLITQ_TXQ_PER_GROUP);
+	} else {
+		num_txq_grps = IECM_DFLT_SINGLEQ_TX_Q_GROUPS;
+		vport_msg->num_tx_q =
+				cpu_to_le16(num_txq_grps *
+					    (num_req_tx_qs ? num_req_tx_qs :
+					    dflt_singleq_txqs));
+		vport_msg->num_tx_complq = 0;
+	}
+	if (iecm_is_queue_model_split(le16_to_cpu(vport_msg->rxq_model))) {
+		num_rxq_grps = num_req_rx_qs ? num_req_rx_qs : dflt_splitq_rxq_grps;
+		vport_msg->num_rx_bufq =
+					cpu_to_le16(num_rxq_grps *
+						    IECM_MAX_BUFQS_PER_RXQ_GRP);
+
+		vport_msg->num_rx_q = cpu_to_le16(num_rxq_grps *
+						  IECM_DFLT_SPLITQ_RXQ_PER_GROUP);
+	} else {
+		num_rxq_grps = IECM_DFLT_SINGLEQ_RX_Q_GROUPS;
+		vport_msg->num_rx_bufq = 0;
+		vport_msg->num_rx_q =
+				cpu_to_le16(num_rxq_grps *
+					    (num_req_rx_qs ? num_req_rx_qs :
+					    dflt_singleq_rxqs));
+	}
+}
+
+/**
+ * iecm_vport_calc_num_q_groups - Calculate number of queue groups
+ * @vport: vport to calculate q groups for
+ */
+void iecm_vport_calc_num_q_groups(struct iecm_vport *vport)
+{
+	if (iecm_is_queue_model_split(vport->txq_model))
+		vport->num_txq_grp = vport->num_txq;
+	else
+		vport->num_txq_grp = IECM_DFLT_SINGLEQ_TX_Q_GROUPS;
+
+	if (iecm_is_queue_model_split(vport->rxq_model))
+		vport->num_rxq_grp = vport->num_rxq;
+	else
+		vport->num_rxq_grp = IECM_DFLT_SINGLEQ_RX_Q_GROUPS;
+}
+EXPORT_SYMBOL(iecm_vport_calc_num_q_groups);
+
+/**
+ * iecm_vport_calc_num_q_vec - Calculate total number of vectors required for
+ * this vport
+ * @vport: virtual port
+ *
+ */
+void iecm_vport_calc_num_q_vec(struct iecm_vport *vport)
+{
+	if (iecm_is_queue_model_split(vport->txq_model))
+		vport->num_q_vectors = vport->num_txq_grp;
+	else
+		vport->num_q_vectors = vport->num_txq;
+}
+EXPORT_SYMBOL(iecm_vport_calc_num_q_vec);
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +362 -3
index aae06064d706..d8152e657e24 100644
@@ -859,6 +859,48 @@ static int iecm_recv_get_caps_msg(struct iecm_adapter *adapter)
 				sizeof(struct virtchnl2_get_capabilities));
 }
 
+/**
+ * iecm_get_reg_intr_vecs - Get vector queue register offset
+ * @vport: virtual port structure
+ * @reg_vals: Register offsets to store in
+ * @num_vecs: Number of vector registers
+ *
+ * Returns number of regsiters that got populated
+ */
+int iecm_get_reg_intr_vecs(struct iecm_vport *vport,
+			   struct iecm_vec_regs *reg_vals, int num_vecs)
+{
+	struct virtchnl2_vector_chunks *chunks;
+	struct iecm_vec_regs reg_val;
+	u16 num_vchunks, num_vec;
+	int num_regs = 0, i, j;
+
+	chunks = &vport->adapter->req_vec_chunks->vchunks;
+	num_vchunks = le16_to_cpu(chunks->num_vchunks);
+
+	for (j = 0; j < num_vchunks; j++) {
+		struct virtchnl2_vector_chunk *chunk = &chunks->vchunks[j];
+
+		num_vec = le16_to_cpu(chunk->num_vectors);
+		reg_val.dyn_ctl_reg = le32_to_cpu(chunk->dynctl_reg_start);
+		reg_val.itrn_reg = le32_to_cpu(chunk->itrn_reg_start);
+		for (i = 0; i < num_vec; i++) {
+			if (num_regs == num_vecs)
+				break;
+			reg_vals[i].dyn_ctl_reg = reg_val.dyn_ctl_reg;
+			reg_vals[i].itrn_reg = reg_val.itrn_reg;
+			reg_val.dyn_ctl_reg +=
+				le32_to_cpu(chunk->dynctl_reg_spacing);
+			reg_val.itrn_reg +=
+				le32_to_cpu(chunk->itrn_reg_spacing);
+			num_regs++;
+		}
+	}
+
+	return num_regs;
+}
+EXPORT_SYMBOL(iecm_get_reg_intr_vecs);
+
 /**
  * iecm_send_create_vport_msg - Send virtchnl create vport message
  * @adapter: Driver specific private structure
@@ -869,8 +911,36 @@ static int iecm_recv_get_caps_msg(struct iecm_adapter *adapter)
  */
 static int iecm_send_create_vport_msg(struct iecm_adapter *adapter)
 {
-	/* stub */
-	return 0;
+	struct virtchnl2_create_vport *vport_msg;
+	int buf_size;
+
+	buf_size = sizeof(struct virtchnl2_create_vport);
+	if (!adapter->vport_params_reqd[0]) {
+		adapter->vport_params_reqd[0] = kzalloc(buf_size, GFP_KERNEL);
+		if (!adapter->vport_params_reqd[0])
+			return -ENOMEM;
+	}
+
+	vport_msg = (struct virtchnl2_create_vport *)
+			adapter->vport_params_reqd[0];
+	vport_msg->vport_type = cpu_to_le16(VIRTCHNL2_VPORT_TYPE_DEFAULT);
+
+	if (test_bit(__IECM_REQ_TX_SPLITQ, adapter->flags))
+		vport_msg->txq_model = cpu_to_le16(VIRTCHNL2_QUEUE_MODEL_SPLIT);
+	else
+		vport_msg->txq_model = cpu_to_le16(VIRTCHNL2_QUEUE_MODEL_SINGLE);
+
+	if (test_bit(__IECM_REQ_RX_SPLITQ, adapter->flags))
+		vport_msg->rxq_model = cpu_to_le16(VIRTCHNL2_QUEUE_MODEL_SPLIT);
+	else
+		vport_msg->rxq_model = cpu_to_le16(VIRTCHNL2_QUEUE_MODEL_SINGLE);
+
+	adapter->dev_ops.vc_ops.init_max_queues(adapter);
+
+	iecm_vport_calc_total_qs(adapter, vport_msg);
+
+	return iecm_send_mb_msg(adapter, VIRTCHNL2_OP_CREATE_VPORT, buf_size,
+				(u8 *)vport_msg);
 }
 
 /**
@@ -884,7 +954,25 @@ static int iecm_send_create_vport_msg(struct iecm_adapter *adapter)
 static int iecm_recv_create_vport_msg(struct iecm_adapter *adapter,
 				      int *vport_id)
 {
-	/* stub */
+	struct virtchnl2_create_vport *vport_msg;
+	int err;
+
+	if (!adapter->vport_params_recvd[0]) {
+		adapter->vport_params_recvd[0] = kzalloc(IECM_DFLT_MBX_BUF_SIZE,
+							 GFP_KERNEL);
+		if (!adapter->vport_params_recvd[0])
+			return -ENOMEM;
+	}
+
+	vport_msg = (struct virtchnl2_create_vport *)
+			adapter->vport_params_recvd[0];
+
+	err = iecm_recv_mb_msg(adapter, VIRTCHNL2_OP_CREATE_VPORT, vport_msg,
+			       IECM_DFLT_MBX_BUF_SIZE);
+	if (err)
+		return err;
+
+	*vport_id = le32_to_cpu(vport_msg->vport_id);
 	return 0;
 }
 
@@ -966,6 +1054,920 @@ int iecm_wait_for_event(struct iecm_adapter *adapter,
 }
 EXPORT_SYMBOL(iecm_wait_for_event);
 
+/**
+ * iecm_wait_for_marker_event - wait for software marker response
+ * @vport: virtual port data structure
+ *
+ * Returns 0 success, negative on failure.
+ **/
+static int iecm_wait_for_marker_event(struct iecm_vport *vport)
+{
+	int event = 0;
+	int i;
+
+	for (i = 0; i < vport->num_txq; i++)
+		set_bit(__IECM_Q_SW_MARKER, vport->txqs[i]->flags);
+
+	event = wait_event_timeout(vport->adapter->sw_marker_wq,
+				   test_and_clear_bit(__IECM_SW_MARKER,
+						      vport->adapter->flags),
+				   msecs_to_jiffies(500));
+	if (event)
+		return 0;
+	return -ETIMEDOUT;
+}
+
+/**
+ * iecm_send_destroy_vport_msg - Send virtchnl destroy vport message
+ * @vport: virtual port data structure
+ *
+ * Send virtchnl destroy vport message.  Returns 0 on success, negative on
+ * failure.
+ */
+int iecm_send_destroy_vport_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_vport v_id;
+	int err;
+
+	v_id.vport_id = cpu_to_le32(vport->vport_id);
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_DESTROY_VPORT,
+			       sizeof(v_id), (u8 *)&v_id);
+	if (err)
+		return err;
+
+	return iecm_min_wait_for_event(adapter, IECM_VC_DESTROY_VPORT,
+				       IECM_VC_DESTROY_VPORT_ERR);
+}
+
+/**
+ * iecm_send_enable_vport_msg - Send virtchnl enable vport message
+ * @vport: virtual port data structure
+ *
+ * Send enable vport virtchnl message.  Returns 0 on success, negative on
+ * failure.
+ */
+int iecm_send_enable_vport_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_vport v_id;
+	int err;
+
+	v_id.vport_id = cpu_to_le32(vport->vport_id);
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_ENABLE_VPORT,
+			       sizeof(v_id), (u8 *)&v_id);
+	if (err)
+		return err;
+
+	return iecm_wait_for_event(adapter, IECM_VC_ENA_VPORT,
+				   IECM_VC_ENA_VPORT_ERR);
+}
+
+/**
+ * iecm_send_disable_vport_msg - Send virtchnl disable vport message
+ * @vport: virtual port data structure
+ *
+ * Send disable vport virtchnl message.  Returns 0 on success, negative on
+ * failure.
+ */
+int iecm_send_disable_vport_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_vport v_id;
+	int err;
+
+	v_id.vport_id = cpu_to_le32(vport->vport_id);
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_DISABLE_VPORT,
+			       sizeof(v_id), (u8 *)&v_id);
+	if (err)
+		return err;
+
+	return iecm_min_wait_for_event(adapter, IECM_VC_DIS_VPORT,
+				       IECM_VC_DIS_VPORT_ERR);
+}
+
+/**
+ * iecm_send_config_tx_queues_msg - Send virtchnl config tx queues message
+ * @vport: virtual port data structure
+ *
+ * Send config tx queues virtchnl message. Returns 0 on success, negative on
+ * failure.
+ */
+int iecm_send_config_tx_queues_msg(struct iecm_vport *vport)
+{
+	struct virtchnl2_config_tx_queues *ctq = NULL;
+	int config_data_size, chunk_size, buf_size = 0;
+	int totqs, num_msgs, num_chunks;
+	struct virtchnl2_txq_info *qi;
+	int err = 0, i, k = 0;
+	bool alloc = false;
+
+	totqs = vport->num_txq + vport->num_complq;
+	qi = kcalloc(totqs, sizeof(struct virtchnl2_txq_info), GFP_KERNEL);
+	if (!qi)
+		return -ENOMEM;
+
+	/* Populate the queue info buffer with all queue context info */
+	for (i = 0; i < vport->num_txq_grp; i++) {
+		struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+		int j;
+
+		for (j = 0; j < tx_qgrp->num_txq; j++, k++) {
+			qi[k].queue_id =
+				cpu_to_le32(tx_qgrp->txqs[j]->q_id);
+			qi[k].model =
+				cpu_to_le16(vport->txq_model);
+			qi[k].type =
+				cpu_to_le32(tx_qgrp->txqs[j]->q_type);
+			qi[k].ring_len =
+				cpu_to_le16(tx_qgrp->txqs[j]->desc_count);
+			qi[k].dma_ring_addr =
+				cpu_to_le64(tx_qgrp->txqs[j]->dma);
+			if (iecm_is_queue_model_split(vport->txq_model)) {
+				struct iecm_queue *q = tx_qgrp->txqs[j];
+
+				qi[k].tx_compl_queue_id =
+					cpu_to_le16(tx_qgrp->complq->q_id);
+
+				if (test_bit(__IECM_Q_FLOW_SCH_EN, q->flags))
+					qi[k].sched_mode =
+					cpu_to_le16(VIRTCHNL2_TXQ_SCHED_MODE_FLOW);
+				else
+					qi[k].sched_mode =
+					cpu_to_le16(VIRTCHNL2_TXQ_SCHED_MODE_QUEUE);
+			} else {
+				qi[k].sched_mode =
+					cpu_to_le16(VIRTCHNL2_TXQ_SCHED_MODE_QUEUE);
+			}
+		}
+
+		if (iecm_is_queue_model_split(vport->txq_model)) {
+			qi[k].queue_id =
+				cpu_to_le32(tx_qgrp->complq->q_id);
+			qi[k].model =
+				cpu_to_le16(vport->txq_model);
+			qi[k].type =
+				cpu_to_le32(tx_qgrp->complq->q_type);
+			qi[k].ring_len =
+				cpu_to_le16(tx_qgrp->complq->desc_count);
+			qi[k].dma_ring_addr =
+				cpu_to_le64(tx_qgrp->complq->dma);
+			k++;
+		}
+	}
+
+	/* Make sure accounting agrees */
+	if (k != totqs) {
+		err = -EINVAL;
+		goto error;
+	}
+
+	/* Chunk up the queue contexts into multiple messages to avoid
+	 * sending a control queue message buffer that is too large
+	 */
+	config_data_size = sizeof(struct virtchnl2_config_tx_queues);
+	chunk_size = sizeof(struct virtchnl2_txq_info);
+
+	num_chunks = IECM_NUM_CHUNKS_PER_MSG(config_data_size, chunk_size) + 1;
+	if (totqs < num_chunks)
+		num_chunks = totqs;
+
+	num_msgs = totqs / num_chunks;
+	if (totqs % num_chunks)
+		num_msgs++;
+
+	for (i = 0, k = 0; i < num_msgs; i++) {
+		if (!ctq || alloc) {
+			buf_size = (chunk_size * (num_chunks - 1)) +
+					config_data_size;
+			kfree(ctq);
+			ctq = kzalloc(buf_size, GFP_KERNEL);
+			if (!ctq) {
+				err = -ENOMEM;
+				goto error;
+			}
+		} else {
+			memset(ctq, 0, buf_size);
+		}
+
+		ctq->vport_id = cpu_to_le32(vport->vport_id);
+		ctq->num_qinfo = cpu_to_le16(num_chunks);
+		memcpy(ctq->qinfo, &qi[k], chunk_size * num_chunks);
+
+		err = iecm_send_mb_msg(vport->adapter,
+				       VIRTCHNL2_OP_CONFIG_TX_QUEUES,
+				       buf_size, (u8 *)ctq);
+		if (err)
+			goto mbx_error;
+
+		err = iecm_wait_for_event(vport->adapter, IECM_VC_CONFIG_TXQ,
+					  IECM_VC_CONFIG_TXQ_ERR);
+		if (err)
+			goto mbx_error;
+
+		k += num_chunks;
+		totqs -= num_chunks;
+		if (totqs < num_chunks) {
+			num_chunks = totqs;
+			alloc = true;
+		}
+	}
+
+mbx_error:
+	kfree(ctq);
+error:
+	kfree(qi);
+	return err;
+}
+
+/**
+ * iecm_send_config_rx_queues_msg - Send virtchnl config rx queues message
+ * @vport: virtual port data structure
+ *
+ * Send config rx queues virtchnl message.  Returns 0 on success, negative on
+ * failure.
+ */
+int iecm_send_config_rx_queues_msg(struct iecm_vport *vport)
+{
+	struct virtchnl2_config_rx_queues *crq = NULL;
+	int config_data_size, chunk_size, buf_size = 0;
+	int totqs, num_msgs, num_chunks;
+	struct virtchnl2_rxq_info *qi;
+	int err = 0, i, k = 0;
+	bool alloc = false;
+
+	totqs = vport->num_rxq + vport->num_bufq;
+	qi = kcalloc(totqs, sizeof(struct virtchnl2_rxq_info), GFP_KERNEL);
+	if (!qi)
+		return -ENOMEM;
+
+	/* Populate the queue info buffer with all queue context info */
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+		int num_rxq;
+		int j;
+
+		if (iecm_is_queue_model_split(vport->rxq_model)) {
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++, k++) {
+				struct iecm_queue *bufq =
+					&rx_qgrp->splitq.bufq_sets[j].bufq;
+
+				qi[k].queue_id =
+					cpu_to_le32(bufq->q_id);
+				qi[k].model =
+					cpu_to_le16(vport->rxq_model);
+				qi[k].type =
+					cpu_to_le32(bufq->q_type);
+				qi[k].desc_ids =
+					cpu_to_le64(VIRTCHNL2_RXDID_1_FLEX_SPLITQ_M);
+				qi[k].ring_len =
+					cpu_to_le16(bufq->desc_count);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1337

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+				qi[k].dma_ring_addr =
+					cpu_to_le64(bufq->dma);
+				qi[k].data_buffer_size =
+					cpu_to_le32(bufq->rx_buf_size);
+				qi[k].buffer_notif_stride =
+					bufq->rx_buf_stride;
+				qi[k].rx_buffer_low_watermark =
+					cpu_to_le16(bufq->rx_buffer_low_watermark);
+			}
+		}
		if (iecm_is_queue_model_split(vport->rxq_model))
			goto here;

-1 indent level for the for-loop.
Braces for 'if' are not needed since the for-loop has their own.

Quoted 19 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +19 -0
+
+		if (iecm_is_queue_model_split(vport->rxq_model))
+			num_rxq = rx_qgrp->splitq.num_rxq_sets;
+		else
+			num_rxq = rx_qgrp->singleq.num_rxq;
+
+		for (j = 0; j < num_rxq; j++, k++) {
+			struct iecm_queue *rxq;
+
+			if (iecm_is_queue_model_split(vport->rxq_model)) {
+				rxq = &rx_qgrp->splitq.rxq_sets[j]->rxq;
+				qi[k].rx_bufq1_id =
+				  cpu_to_le16(rxq->rxq_grp->splitq.bufq_sets[0].bufq.q_id);
+				qi[k].rx_bufq2_id =
+				  cpu_to_le16(rxq->rxq_grp->splitq.bufq_sets[1].bufq.q_id);
+				qi[k].hdr_buffer_size =
+					cpu_to_le16(rxq->rx_hbuf_size);
+				qi[k].rx_buffer_low_watermark =
+					cpu_to_le16(rxq->rx_buffer_low_watermark);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1366

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+
+				if (rxq->rx_hsplit_en) {
+					qi[k].qflags =
+						cpu_to_le16(VIRTCHNL2_RXQ_HDR_SPLIT);
+					qi[k].hdr_buffer_size =
+						cpu_to_le16(rxq->rx_hbuf_size);
+				}
+			} else {
+				rxq = rx_qgrp->singleq.rxqs[j];
+			}

Same here, but with rxq = ... + goto.

Quoted 141 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +141 -0
+
+			qi[k].queue_id =
+				cpu_to_le32(rxq->q_id);
+			qi[k].model =
+				cpu_to_le16(vport->rxq_model);
+			qi[k].type =
+				cpu_to_le32(rxq->q_type);
+			qi[k].ring_len =
+				cpu_to_le16(rxq->desc_count);
+			qi[k].dma_ring_addr =
+				cpu_to_le64(rxq->dma);
+			qi[k].max_pkt_size =
+				cpu_to_le32(rxq->rx_max_pkt_size);
+			qi[k].data_buffer_size =
+				cpu_to_le32(rxq->rx_buf_size);
+			qi[k].qflags |=
+				cpu_to_le16(VIRTCHNL2_RX_DESC_SIZE_32BYTE);
+			qi[k].desc_ids =
+				cpu_to_le64(rxq->rxdids);
+		}
+	}
+
+	/* Make sure accounting agrees */
+	if (k != totqs) {
+		err = -EINVAL;
+		goto error;
+	}
+
+	/* Chunk up the queue contexts into multiple messages to avoid
+	 * sending a control queue message buffer that is too large
+	 */
+	config_data_size = sizeof(struct virtchnl2_config_rx_queues);
+	chunk_size = sizeof(struct virtchnl2_rxq_info);
+
+	num_chunks = IECM_NUM_CHUNKS_PER_MSG(config_data_size, chunk_size) + 1;
+	if (totqs < num_chunks)
+		num_chunks = totqs;
+
+	num_msgs = totqs / num_chunks;
+	if (totqs % num_chunks)
+		num_msgs++;
+
+	for (i = 0, k = 0; i < num_msgs; i++) {
+		if (!crq || alloc) {
+			buf_size = (chunk_size * (num_chunks - 1)) +
+					config_data_size;
+			kfree(crq);
+			crq = kzalloc(buf_size, GFP_KERNEL);
+			if (!crq) {
+				err = -ENOMEM;
+				goto error;
+			}
+		} else {
+			memset(crq, 0, buf_size);
+		}
+
+		crq->vport_id = cpu_to_le32(vport->vport_id);
+		crq->num_qinfo = cpu_to_le16(num_chunks);
+		memcpy(crq->qinfo, &qi[k], chunk_size * num_chunks);
+
+		err = iecm_send_mb_msg(vport->adapter,
+				       VIRTCHNL2_OP_CONFIG_RX_QUEUES,
+				       buf_size, (u8 *)crq);
+		if (err)
+			goto mbx_error;
+
+		err = iecm_wait_for_event(vport->adapter, IECM_VC_CONFIG_RXQ,
+					  IECM_VC_CONFIG_RXQ_ERR);
+		if (err)
+			goto mbx_error;
+
+		k += num_chunks;
+		totqs -= num_chunks;
+		if (totqs < num_chunks) {
+			num_chunks = totqs;
+			alloc = true;
+		}
+	}
+
+mbx_error:
+	kfree(crq);
+error:
+	kfree(qi);
+	return err;
+}
+
+/**
+ * iecm_send_ena_dis_queues_msg - Send virtchnl enable or disable
+ * queues message
+ * @vport: virtual port data structure
+ * @vc_op: virtchnl op code to send
+ *
+ * Send enable or disable queues virtchnl message. Returns 0 on success,
+ * negative on failure.
+ */
+static int iecm_send_ena_dis_queues_msg(struct iecm_vport *vport,
+					enum virtchnl_ops vc_op)
+{
+	int num_msgs, num_chunks, config_data_size, chunk_size;
+	int num_txq, num_rxq, num_q, buf_size, err = 0;
+	struct virtchnl2_del_ena_dis_queues *eq = NULL;
+	struct virtchnl2_queue_chunk *qc;
+	bool alloc = false;
+	int i, j, k = 0;
+
+	/* validate virtchnl op */
+	switch (vc_op) {
+	case VIRTCHNL2_OP_ENABLE_QUEUES:
+	case VIRTCHNL2_OP_DISABLE_QUEUES:
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	num_txq = vport->num_txq + vport->num_complq;
+	num_rxq = vport->num_rxq + vport->num_bufq;
+	num_q = num_txq + num_rxq;
+	buf_size = sizeof(struct virtchnl2_queue_chunk) * (num_q);
+	qc = kzalloc(buf_size, GFP_KERNEL);
+	if (!qc)
+		return -ENOMEM;
+
+	for (i = 0; i < vport->num_txq_grp; i++) {
+		struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+
+		for (j = 0; j < tx_qgrp->num_txq; j++, k++) {
+			qc[k].type = cpu_to_le32(tx_qgrp->txqs[j]->q_type);
+			qc[k].start_queue_id =
+					cpu_to_le32(tx_qgrp->txqs[j]->q_id);
+			qc[k].num_queues = cpu_to_le32(1);
+		}
+	}
+	if (vport->num_txq != k) {
+		err = -EINVAL;
+		goto error;
+	}
+
+	if (iecm_is_queue_model_split(vport->txq_model)) {
+		for (i = 0; i < vport->num_txq_grp; i++, k++) {
+			struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1517

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+			qc[k].type = cpu_to_le32(tx_qgrp->complq->q_type);
+			qc[k].start_queue_id =
+					cpu_to_le32(tx_qgrp->complq->q_id);
+			qc[k].num_queues = cpu_to_le32(1);
+		}
+		if (vport->num_complq != (k - vport->num_txq)) {
+			err = -EINVAL;
+			goto error;
+		}
+	}

...and here.

Quoted 38 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +38 -0
+
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+
+		if (iecm_is_queue_model_split(vport->rxq_model))
+			num_rxq = rx_qgrp->splitq.num_rxq_sets;
+		else
+			num_rxq = rx_qgrp->singleq.num_rxq;
+
+		for (j = 0; j < num_rxq; j++, k++) {
+			if (iecm_is_queue_model_split(vport->rxq_model)) {
+				qc[k].start_queue_id =
+				cpu_to_le32(rx_qgrp->splitq.rxq_sets[j]->rxq.q_id);
+				qc[k].type =
+				cpu_to_le32(rx_qgrp->splitq.rxq_sets[j]->rxq.q_type);
+			} else {
+				qc[k].start_queue_id =
+				cpu_to_le32(rx_qgrp->singleq.rxqs[j]->q_id);
+				qc[k].type =
+				cpu_to_le32(rx_qgrp->singleq.rxqs[j]->q_type);
+			}
+			qc[k].num_queues = cpu_to_le32(1);
+		}
+	}
+	if (vport->num_rxq != k - (vport->num_txq + vport->num_complq)) {
+		err = -EINVAL;
+		goto error;
+	}
+
+	if (iecm_is_queue_model_split(vport->rxq_model)) {
+		for (i = 0; i < vport->num_rxq_grp; i++) {
+			struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++, k++) {
+				struct iecm_queue *q = &rx_qgrp->splitq.bufq_sets[j].bufq;
+
+				qc[k].type = cpu_to_le32(q->q_type);
+				qc[k].start_queue_id = cpu_to_le32(q->q_id);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1565

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+				qc[k].num_queues = cpu_to_le32(1);
+			}
+		}
+		if (vport->num_bufq != k - (vport->num_txq +
+					       vport->num_complq +
+					       vport->num_rxq)) {
+			err = -EINVAL;
+			goto error;
+		}
+	}

...and here.

Quoted 116 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +116 -0
+
+	/* Chunk up the queue info into multiple messages */
+	config_data_size = sizeof(struct virtchnl2_del_ena_dis_queues);
+	chunk_size = sizeof(struct virtchnl2_queue_chunk);
+
+	num_chunks = IECM_NUM_CHUNKS_PER_MSG(config_data_size, chunk_size) + 1;
+	if (num_q < num_chunks)
+		num_chunks = num_q;
+
+	num_msgs = num_q / num_chunks;
+	if (num_q % num_chunks)
+		num_msgs++;
+
+	for (i = 0, k = 0; i < num_msgs; i++) {
+		if (!eq || alloc) {
+			buf_size = (chunk_size * (num_chunks - 1)) +
+					config_data_size;
+			kfree(eq);
+			eq = kzalloc(buf_size, GFP_KERNEL);
+			if (!eq) {
+				err = -ENOMEM;
+				goto error;
+			}
+		} else {
+			memset(eq, 0, buf_size);
+		}
+		eq->vport_id = cpu_to_le32(vport->vport_id);
+		eq->chunks.num_chunks = cpu_to_le16(num_chunks);
+		memcpy(eq->chunks.chunks, &qc[k], chunk_size * num_chunks);
+
+		err = iecm_send_mb_msg(vport->adapter, vc_op, buf_size,
+				       (u8 *)eq);
+		if (err)
+			goto mbx_error;
+		k += num_chunks;
+		num_q -= num_chunks;
+		if (num_q < num_chunks) {
+			num_chunks = num_q;
+			alloc = true;
+		}
+	}
+mbx_error:
+	kfree(eq);
+error:
+	kfree(qc);
+	return err;
+}
+
+/**
+ * iecm_send_map_unmap_queue_vector_msg - Send virtchnl map or unmap queue
+ * vector message
+ * @vport: virtual port data structure
+ * @map: true for map and false for unmap
+ *
+ * Send map or unmap queue vector virtchnl message.  Returns 0 on success,
+ * negative on failure.
+ */
+int iecm_send_map_unmap_queue_vector_msg(struct iecm_vport *vport, bool map)
+{
+	int num_msgs, num_chunks, config_data_size, chunk_size;
+	struct virtchnl2_queue_vector_maps *vqvm = NULL;
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_queue_vector *vqv;
+	int buf_size, num_q, err = 0;
+	bool alloc = false;
+	int i, j, k = 0;
+
+	num_q = vport->num_txq + vport->num_rxq;
+
+	buf_size = sizeof(struct virtchnl2_queue_vector) * num_q;
+	vqv = kzalloc(buf_size, GFP_KERNEL);
+	if (!vqv)
+		return -ENOMEM;
+
+	for (i = 0; i < vport->num_txq_grp; i++) {
+		struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+
+		for (j = 0; j < tx_qgrp->num_txq; j++, k++) {
+			vqv[k].queue_type = cpu_to_le32(tx_qgrp->txqs[j]->q_type);
+			vqv[k].queue_id = cpu_to_le32(tx_qgrp->txqs[j]->q_id);
+
+			if (iecm_is_queue_model_split(vport->txq_model)) {
+				vqv[k].vector_id =
+				cpu_to_le16(tx_qgrp->complq->q_vector->v_idx);
+				vqv[k].itr_idx =
+				cpu_to_le32(tx_qgrp->complq->q_vector->tx_itr_idx);
+			} else {
+				vqv[k].vector_id =
+				cpu_to_le16(tx_qgrp->txqs[j]->q_vector->v_idx);
+				vqv[k].itr_idx =
+				cpu_to_le32(tx_qgrp->txqs[j]->q_vector->tx_itr_idx);
+			}
+		}
+	}
+
+	if (vport->num_txq != k) {
+		err = -EINVAL;
+		goto error;
+	}
+
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+		int num_rxq;
+
+		if (iecm_is_queue_model_split(vport->rxq_model))
+			num_rxq = rx_qgrp->splitq.num_rxq_sets;
+		else
+			num_rxq = rx_qgrp->singleq.num_rxq;
+
+		for (j = 0; j < num_rxq; j++, k++) {
+			struct iecm_queue *rxq;
+
+			if (iecm_is_queue_model_split(vport->rxq_model))
+				rxq = &rx_qgrp->splitq.rxq_sets[j]->rxq;
+			else
+				rxq = rx_qgrp->singleq.rxqs[j];

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1691

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+
+			vqv[k].queue_type = cpu_to_le32(rxq->q_type);
+			vqv[k].queue_id = cpu_to_le32(rxq->q_id);
+			vqv[k].vector_id = cpu_to_le16(rxq->q_vector->v_idx);
+			vqv[k].itr_idx = cpu_to_le32(rxq->q_vector->rx_itr_idx);
+		}
+	}
+
+	if (iecm_is_queue_model_split(vport->txq_model)) {
+		if (vport->num_rxq != k - vport->num_complq) {
	if (iecm_is_queue_model_split() && vport->num_rxq != ...) {

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1252

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +4 -0
+			err = -EINVAL;
+			goto error;
+		}
+	} else {

Don't forget to convert this then into !split + ..., either with 'else' or not.

Quoted 415 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +375 -12
+		if (vport->num_rxq != k - vport->num_txq) {
+			err = -EINVAL;
+			goto error;
+		}
+	}
+
+	/* Chunk up the vector info into multiple messages */
+	config_data_size = sizeof(struct virtchnl2_queue_vector_maps);
+	chunk_size = sizeof(struct virtchnl2_queue_vector);
+
+	num_chunks = IECM_NUM_CHUNKS_PER_MSG(config_data_size, chunk_size) + 1;
+	if (num_q < num_chunks)
+		num_chunks = num_q;
+
+	num_msgs = num_q / num_chunks;
+	if (num_q % num_chunks)
+		num_msgs++;
+
+	for (i = 0, k = 0; i < num_msgs; i++) {
+		if (!vqvm || alloc) {
+			buf_size = (chunk_size * (num_chunks - 1)) +
+					config_data_size;
+			kfree(vqvm);
+			vqvm = kzalloc(buf_size, GFP_KERNEL);
+			if (!vqvm) {
+				err = -ENOMEM;
+				goto error;
+			}
+		} else {
+			memset(vqvm, 0, buf_size);
+		}
+		vqvm->vport_id = cpu_to_le32(vport->vport_id);
+		vqvm->num_qv_maps = cpu_to_le16(num_chunks);
+		memcpy(vqvm->qv_maps, &vqv[k], chunk_size * num_chunks);
+
+		if (map) {
+			err = iecm_send_mb_msg(adapter,
+					       VIRTCHNL2_OP_MAP_QUEUE_VECTOR,
+					       buf_size, (u8 *)vqvm);
+			if (!err)
+				err = iecm_wait_for_event(adapter,
+							  IECM_VC_MAP_IRQ,
+							  IECM_VC_MAP_IRQ_ERR);
+		} else {
+			err = iecm_send_mb_msg(adapter,
+					       VIRTCHNL2_OP_UNMAP_QUEUE_VECTOR,
+					       buf_size, (u8 *)vqvm);
+			if (!err)
+				err =
+				iecm_min_wait_for_event(adapter,
+							IECM_VC_UNMAP_IRQ,
+							IECM_VC_UNMAP_IRQ_ERR);
+		}
+		if (err)
+			goto mbx_error;
+
+		k += num_chunks;
+		num_q -= num_chunks;
+		if (num_q < num_chunks) {
+			num_chunks = num_q;
+			alloc = true;
+		}
+	}
+mbx_error:
+	kfree(vqvm);
+error:
+	kfree(vqv);
+	return err;
+}
+EXPORT_SYMBOL(iecm_send_map_unmap_queue_vector_msg);
+
+/**
+ * iecm_send_enable_queues_msg - send enable queues virtchnl message
+ * @vport: Virtual port private data structure
+ *
+ * Will send enable queues virtchnl message.  Returns 0 on success, negative on
+ * failure.
+ */
+static int iecm_send_enable_queues_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	int err;
+
+	err = iecm_send_ena_dis_queues_msg(vport,
+					   VIRTCHNL2_OP_ENABLE_QUEUES);
+	if (err)
+		return err;
+
+	return iecm_wait_for_event(adapter, IECM_VC_ENA_QUEUES,
+				   IECM_VC_ENA_QUEUES_ERR);
+}
+
+/**
+ * iecm_send_disable_queues_msg - send disable queues virtchnl message
+ * @vport: Virtual port private data structure
+ *
+ * Will send disable queues virtchnl message.  Returns 0 on success, negative
+ * on failure.
+ */
+static int iecm_send_disable_queues_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	int err;
+
+	err = iecm_send_ena_dis_queues_msg(vport,
+					   VIRTCHNL2_OP_DISABLE_QUEUES);
+	if (err)
+		return err;
+
+	err = iecm_min_wait_for_event(adapter, IECM_VC_DIS_QUEUES,
+				      IECM_VC_DIS_QUEUES_ERR);
+	if (err)
+		return err;
+
+	return iecm_wait_for_marker_event(vport);
+}
+
+/**
+ * iecm_convert_reg_to_queue_chunks - Copy queue chunk information to the right
+ * structure
+ * @dchunks: Destination chunks to store data to
+ * @schunks: Source chunks to copy data from
+ * @num_chunks: number of chunks to copy
+ */
+static void
+iecm_convert_reg_to_queue_chunks(struct virtchnl2_queue_chunk *dchunks,
+				 struct virtchnl2_queue_reg_chunk *schunks,
+				 u16 num_chunks)
+{
+	u16 i;
+
+	for (i = 0; i < num_chunks; i++) {
+		dchunks[i].type = schunks[i].type;
+		dchunks[i].start_queue_id = schunks[i].start_queue_id;
+		dchunks[i].num_queues = schunks[i].num_queues;
+	}
+}
+
+/**
+ * iecm_send_delete_queues_msg - send delete queues virtchnl message
+ * @vport: Virtual port private data structure
+ *
+ * Will send delete queues virtchnl message. Return 0 on success, negative on
+ * failure.
+ */
+int iecm_send_delete_queues_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_create_vport *vport_params;
+	struct virtchnl2_queue_reg_chunks *chunks;
+	struct virtchnl2_del_ena_dis_queues *eq;
+	int buf_size, err;
+	u16 num_chunks;
+
+	if (vport->adapter->config_data.req_qs_chunks) {
+		struct virtchnl2_add_queues *vc_aq =
+			(struct virtchnl2_add_queues *)
+			vport->adapter->config_data.req_qs_chunks;
+		chunks = &vc_aq->chunks;
+	} else {
+		vport_params = (struct virtchnl2_create_vport *)
+				vport->adapter->vport_params_recvd[0];
+		 chunks = &vport_params->chunks;
+	}
+
+	num_chunks = le16_to_cpu(chunks->num_chunks);
+	buf_size = sizeof(struct virtchnl2_del_ena_dis_queues) +
+			  (sizeof(struct virtchnl2_queue_chunk) *
+			  (num_chunks - 1));
+
+	eq = kzalloc(buf_size, GFP_KERNEL);
+	if (!eq)
+		return -ENOMEM;
+
+	eq->vport_id = cpu_to_le32(vport->vport_id);
+	eq->chunks.num_chunks = cpu_to_le16(num_chunks);
+
+	iecm_convert_reg_to_queue_chunks(eq->chunks.chunks, chunks->chunks,
+					 num_chunks);
+
+	err = iecm_send_mb_msg(vport->adapter, VIRTCHNL2_OP_DEL_QUEUES,
+			       buf_size, (u8 *)eq);
+	if (err)
+		goto error;
+
+	err = iecm_min_wait_for_event(adapter, IECM_VC_DEL_QUEUES,
+				      IECM_VC_DEL_QUEUES_ERR);
+error:
+	kfree(eq);
+	return err;
+}
+
+/**
+ * iecm_send_config_queues_msg - Send config queues virtchnl message
+ * @vport: Virtual port private data structure
+ *
+ * Will send config queues virtchnl message. Returns 0 on success, negative on
+ * failure.
+ */
+static int iecm_send_config_queues_msg(struct iecm_vport *vport)
+{
+	int err;
+
+	err = iecm_send_config_tx_queues_msg(vport);
+	if (err)
+		return err;
+
+	return iecm_send_config_rx_queues_msg(vport);
+}
+
+/**
+ * iecm_send_add_queues_msg - Send virtchnl add queues message
+ * @vport: Virtual port private data structure
+ * @num_tx_q: number of transmit queues
+ * @num_complq: number of transmit completion queues
+ * @num_rx_q: number of receive queues
+ * @num_rx_bufq: number of receive buffer queues
+ *
+ * Returns 0 on success, negative on failure.
+ */
+int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,
+			     u16 num_complq, u16 num_rx_q, u16 num_rx_bufq)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_add_queues aq = {0};
+	struct virtchnl2_add_queues *vc_msg;
+	int size, err;
+
+	vc_msg = (struct virtchnl2_add_queues *)adapter->vc_msg;
+
+	aq.vport_id = cpu_to_le32(vport->vport_id);
+	aq.num_tx_q = cpu_to_le16(num_tx_q);
+	aq.num_tx_complq = cpu_to_le16(num_complq);
+	aq.num_rx_q = cpu_to_le16(num_rx_q);
+	aq.num_rx_bufq = cpu_to_le16(num_rx_bufq);
+
+	err = iecm_send_mb_msg(adapter,
+			       VIRTCHNL2_OP_ADD_QUEUES,
+			       sizeof(struct virtchnl2_add_queues), (u8 *)&aq);
+	if (err)
+		return err;
+
+	err = iecm_wait_for_event(adapter, IECM_VC_ADD_QUEUES,
+				  IECM_VC_ADD_QUEUES_ERR);
+	if (err)
+		return err;
+
+	kfree(adapter->config_data.req_qs_chunks);
+	adapter->config_data.req_qs_chunks = NULL;
+
+	/* compare vc_msg num queues with vport num queues */
+	if (le16_to_cpu(vc_msg->num_tx_q) != num_tx_q ||
+	    le16_to_cpu(vc_msg->num_rx_q) != num_rx_q ||
+	    le16_to_cpu(vc_msg->num_tx_complq) != num_complq ||
+	    le16_to_cpu(vc_msg->num_rx_bufq) != num_rx_bufq) {
+		err = -EINVAL;
+		goto error;
+	}
+
+	size = sizeof(struct virtchnl2_add_queues) +
+			((le16_to_cpu(vc_msg->chunks.num_chunks) - 1) *
+			sizeof(struct virtchnl2_queue_reg_chunk));
+	adapter->config_data.req_qs_chunks =
+		kzalloc(size, GFP_KERNEL);
+	if (!adapter->config_data.req_qs_chunks) {
+		err = -ENOMEM;
+		goto error;
+	}
+	memcpy(adapter->config_data.req_qs_chunks,
+	       adapter->vc_msg, size);
+error:
+	clear_bit(__IECM_VC_MSG_PENDING, adapter->flags);
+	return err;
+}
+
 /**
  * iecm_find_ctlq - Given a type and id, find ctlq info
  * @hw: hardware struct
@@ -1217,6 +2219,13 @@ static void iecm_vport_init(struct iecm_vport *vport,
 	/*Initialize Tx and Rx profiles for Dynamic Interrupt Moderation */
 	memcpy(vport->rx_itr_profile, rx_itr, IECM_DIM_PROFILE_SLOTS);
 	memcpy(vport->tx_itr_profile, tx_itr, IECM_DIM_PROFILE_SLOTS);
+
+	iecm_vport_set_hsplit(vport, true);
+
+	iecm_vport_init_num_qs(vport, vport_msg);
+	iecm_vport_calc_num_q_desc(vport);
+	iecm_vport_calc_num_q_groups(vport);
+	iecm_vport_calc_num_q_vec(vport);
 }
 
 /**
@@ -1316,8 +2325,82 @@ static int
 __iecm_vport_queue_ids_init(struct iecm_vport *vport, u32 *qids,
 			    int num_qids, u32 q_type)
 {
-	/* stub */
-	return 0;
+	struct iecm_queue *q;
+	int i, j, k = 0;
+
+	switch (q_type) {
+	case VIRTCHNL2_QUEUE_TYPE_TX:
+		for (i = 0; i < vport->num_txq_grp; i++) {
+			struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+
+			for (j = 0; j < tx_qgrp->num_txq; j++) {
+				if (k < num_qids) {
+					tx_qgrp->txqs[j]->q_id = qids[k];
+					tx_qgrp->txqs[j]->q_type =
+						VIRTCHNL2_QUEUE_TYPE_TX;
+					k++;
+				} else {
+					break;
+				}
+			}
+		}
+		break;
+	case VIRTCHNL2_QUEUE_TYPE_RX:
+		for (i = 0; i < vport->num_rxq_grp; i++) {
+			struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+			int num_rxq;
+
+			if (iecm_is_queue_model_split(vport->rxq_model))
+				num_rxq = rx_qgrp->splitq.num_rxq_sets;
+			else
+				num_rxq = rx_qgrp->singleq.num_rxq;
+
+			for (j = 0; j < num_rxq && k < num_qids; j++, k++) {
+				if (iecm_is_queue_model_split(vport->rxq_model))
+					q = &rx_qgrp->splitq.rxq_sets[j]->rxq;
+				else
+					q = rx_qgrp->singleq.rxqs[j];
+				q->q_id = qids[k];
+				q->q_type = VIRTCHNL2_QUEUE_TYPE_RX;
+			}
+		}
+		break;
+	case VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION:
+		for (i = 0; i < vport->num_txq_grp; i++) {
+			struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+
+			if (k < num_qids) {
+				tx_qgrp->complq->q_id = qids[k];
+				tx_qgrp->complq->q_type =
+					VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION;
+				k++;
+			} else {
+				break;
+			}
+		}
+		break;
+	case VIRTCHNL2_QUEUE_TYPE_RX_BUFFER:
+		for (i = 0; i < vport->num_rxq_grp; i++) {
+			struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++) {
+				if (k < num_qids) {
+					q = &rx_qgrp->splitq.bufq_sets[j].bufq;
+					q->q_id = qids[k];
+					q->q_type =
+						VIRTCHNL2_QUEUE_TYPE_RX_BUFFER;
+					k++;
+				} else {
+					break;
+				}
+			}
+		}
+		break;
+	default:
+		break;
+	}
+
+	return k;
 }
 
 /**
@@ -1425,6 +2508,20 @@ static bool iecm_is_capability_ena(struct iecm_adapter *adapter, bool all,
 		return !!(*cap_field & flag);
 }
 
+/**
+ * iecm_get_reserved_vectors - Default implementation to get reserved vectors
+ * @adapter: Private data struct
+ *
+ * Return number of vectors reserved
+ */
+static u16 iecm_get_reserved_vectors(struct iecm_adapter *adapter)
+{
+	struct virtchnl2_get_capabilities *caps;
+
+	caps = (struct virtchnl2_get_capabilities *)adapter->caps;
+	return le16_to_cpu(caps->num_allocated_vectors);
+}
+
 /**
  * iecm_vc_ops_init - Initialize virtchnl common api
  * @adapter: Driver specific private structure
@@ -1441,16 +2538,16 @@ void iecm_vc_ops_init(struct iecm_adapter *adapter)
 	vc_ops->vport_queue_ids_init = iecm_vport_queue_ids_init;
 	vc_ops->get_caps = iecm_send_get_caps_msg;
 	vc_ops->is_cap_ena = iecm_is_capability_ena;
-	vc_ops->get_reserved_vecs = NULL;
-	vc_ops->config_queues = NULL;
-	vc_ops->enable_queues = NULL;
-	vc_ops->disable_queues = NULL;
-	vc_ops->add_queues = NULL;
-	vc_ops->delete_queues = NULL;
-	vc_ops->irq_map_unmap = NULL;
-	vc_ops->enable_vport = NULL;
-	vc_ops->disable_vport = NULL;
-	vc_ops->destroy_vport = NULL;
+	vc_ops->get_reserved_vecs = iecm_get_reserved_vectors;
+	vc_ops->config_queues = iecm_send_config_queues_msg;
+	vc_ops->enable_queues = iecm_send_enable_queues_msg;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c void iecm_vc_ops_init(struct iecm_adapter *adapter) · line 2553

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +7 -0
+	vc_ops->disable_queues = iecm_send_disable_queues_msg;
+	vc_ops->add_queues = iecm_send_add_queues_msg;
+	vc_ops->delete_queues = iecm_send_delete_queues_msg;
+	vc_ops->irq_map_unmap = iecm_send_map_unmap_queue_vector_msg;
+	vc_ops->enable_vport = iecm_send_enable_vport_msg;
+	vc_ops->disable_vport = iecm_send_disable_vport_msg;
+	vc_ops->destroy_vport = iecm_send_destroy_vport_msg;
 	vc_ops->get_ptype = NULL;
 	vc_ops->get_set_rss_key = NULL;
 	vc_ops->get_set_rss_lut = NULL;

Forgot to mention earlier, any reason to not declare this ops as static const and just assign a pointer then? I don't see any alternations here to e.g. fill callbacks with different functions or so.

Quoted 186 lines
drivers/net/ethernet/intel/include/iecm.h +22 -0
index 994664dfe419..8dd6272db7d3 100644
@@ -432,6 +432,8 @@ struct iecm_adapter {
 	u16 num_alloc_vport;
 	u16 next_vport;		/* Next free slot in pf->vport[] - 0-based! */
 
+	u16 max_queue_limit;	/* Max number of queues user can request */
+
 	struct delayed_work init_task; /* delayed init task */
 	struct workqueue_struct *init_wq;
 	u32 mb_wait_count;
@@ -510,6 +512,12 @@ static inline bool __iecm_is_cap_ena(struct iecm_adapter *adapter, bool all,
 	return adapter->dev_ops.vc_ops.is_cap_ena(adapter, all, field, flag);
 }
 
+#define IECM_CAP_HSPLIT (\
+	VIRTCHNL2_CAP_RX_HSPLIT_AT_L2   |\
+	VIRTCHNL2_CAP_RX_HSPLIT_AT_L3   |\
+	VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V4 |\
+	VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V6)
+
 /**
  * iecm_is_reset_detected - check if we were reset at some point
  * @adapter: driver specific private structure
@@ -530,6 +538,8 @@ int iecm_init_dflt_mbx(struct iecm_adapter *adapter);
 void iecm_deinit_dflt_mbx(struct iecm_adapter *adapter);
 void iecm_vc_ops_init(struct iecm_adapter *adapter);
 int iecm_vc_core_init(struct iecm_adapter *adapter, int *vport_id);
+int iecm_get_reg_intr_vecs(struct iecm_vport *vport,
+			   struct iecm_vec_regs *reg_vals, int num_vecs);
 int iecm_wait_for_event(struct iecm_adapter *adapter,
 			enum iecm_vport_vc_state state,
 			enum iecm_vport_vc_state err_check);
@@ -537,6 +547,14 @@ int iecm_min_wait_for_event(struct iecm_adapter *adapter,
 			    enum iecm_vport_vc_state state,
 			    enum iecm_vport_vc_state err_check);
 int iecm_send_get_caps_msg(struct iecm_adapter *adapter);
+int iecm_send_delete_queues_msg(struct iecm_vport *vport);
+int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,
+			     u16 num_complq, u16 num_rx_q, u16 num_rx_bufq);
+int iecm_send_config_tx_queues_msg(struct iecm_vport *vport);
+int iecm_send_config_rx_queues_msg(struct iecm_vport *vport);
+int iecm_send_enable_vport_msg(struct iecm_vport *vport);
+int iecm_send_disable_vport_msg(struct iecm_vport *vport);
+int iecm_send_destroy_vport_msg(struct iecm_vport *vport);
 int iecm_vport_params_buf_alloc(struct iecm_adapter *adapter);
 void iecm_vport_params_buf_rel(struct iecm_adapter *adapter);
 int iecm_get_vec_ids(struct iecm_adapter *adapter,
@@ -546,7 +564,11 @@ int iecm_recv_mb_msg(struct iecm_adapter *adapter, enum virtchnl_ops op,
 		     void *msg, int msg_size);
 int iecm_send_mb_msg(struct iecm_adapter *adapter, enum virtchnl_ops op,
 		     u16 msg_size, u8 *msg);
+void iecm_vport_set_hsplit(struct iecm_vport *vport, bool ena);
+int iecm_send_enable_channels_msg(struct iecm_vport *vport);
+int iecm_send_disable_channels_msg(struct iecm_vport *vport);
 int iecm_set_msg_pending(struct iecm_adapter *adapter,
 			 struct iecm_ctlq_msg *ctlq_msg,
 			 enum iecm_vport_vc_state err_enum);
+int iecm_send_map_unmap_queue_vector_msg(struct iecm_vport *vport, bool map);
 #endif /* !_IECM_H_ */
drivers/net/ethernet/intel/include/iecm_txrx.h +109 -0
index e1348011c991..448cae0bf6e7 100644
@@ -81,6 +81,22 @@
 
 #define IECM_TX_COMPLQ_CLEAN_BUDGET	256
 
+enum iecm_queue_flags_t {
+	__IECM_Q_GEN_CHK,
+	__IECM_RFLQ_GEN_CHK,
+	__IECM_Q_FLOW_SCH_EN,
+	__IECM_Q_ETF_EN,
+	__IECM_Q_SW_MARKER,
+	__IECM_Q_VLAN_TAG_LOC_L2TAG1,
+	__IECM_Q_VLAN_TAG_LOC_L2TAG2,
+	__IECM_Q_FLAGS_NBITS,
+};
+
+struct iecm_vec_regs {
+	u32 dyn_ctl_reg;
+	u32 itrn_reg;
+};
+
 struct iecm_intr_reg {
 	u32 dyn_ctl;
 	u32 dyn_ctl_intena_m;
@@ -122,6 +138,186 @@ struct iecm_q_vector {
 	char name[IECM_INT_NAME_STR_LEN];
 };
 
+struct iecm_rx_queue_stats {
+	u64 packets;
+	u64 bytes;
+	u64 rsc_pkts;
+};
+
+struct iecm_tx_queue_stats {
+	u64 packets;
+	u64 bytes;
+	u64 lso_pkts;
+};
+
+union iecm_queue_stats {
+	struct iecm_rx_queue_stats rx;
+	struct iecm_tx_queue_stats tx;
+};
+
+/* queue associated with a vport */
+struct iecm_queue {
+	struct device *dev;		/* Used for DMA mapping */
+	struct iecm_vport *vport;	/* Backreference to associated vport */
+	union {
+		struct iecm_txq_group *txq_grp;
+		struct iecm_rxq_group *rxq_grp;
+	};
+	/* bufq: Used as group id, either 0 or 1, on clean Buf Q uses this
+	 *       index to determine which group of refill queues to clean.
+	 *       Bufqs are use in splitq only.
+	 * txq: Index to map between Tx Q group and hot path Tx ptrs stored in
+	 *      vport.  Used in both single Q/split Q
+	 * rxq: Index to total rxq across groups, used for skb reporting
+	 */
+	u16 idx;
+	/* Used for both Q models single and split. In split Q model relevant
+	 * only to Tx Q and Rx Q
+	 */
+	u8 __iomem *tail;
+	/* Used in both single and split Q.  In single Q, Tx Q uses tx_buf and
+	 * Rx Q uses rx_buf.  In split Q, Tx Q uses tx_buf, Rx Q uses skb, and
+	 * Buf Q uses rx_buf.
+	 */
+	union {
+		struct iecm_tx_buf *tx_buf;
+		struct {
+			struct iecm_rx_buf *buf;
+			struct iecm_dma_mem **hdr_buf;
+		} rx_buf;
+		struct sk_buff *skb;
+	};
+	u16 q_type;
+	/* Queue id(Tx/Tx compl/Rx/Bufq) */
+	u32 q_id;
+	u16 desc_count;		/* Number of descriptors */
+
+	/* Relevant in both split & single Tx Q & Buf Q*/
+	u16 next_to_use;
+	/* In split q model only relevant for Tx Compl Q and Rx Q */
+	u16 next_to_clean;	/* used in interrupt processing */
+	/* Used only for Rx. In split Q model only relevant to Rx Q */
+	u16 next_to_alloc;
+	/* Generation bit check stored, as HW flips the bit at Queue end */
+	DECLARE_BITMAP(flags, __IECM_Q_FLAGS_NBITS);
+
+	union iecm_queue_stats q_stats;
+	struct u64_stats_sync stats_sync;
+
+	bool rx_hsplit_en;
+
+	u16 rx_hbuf_size;	/* Header buffer size */
+	u16 rx_buf_size;
+	u16 rx_max_pkt_size;
+	u16 rx_buf_stride;
+	u8 rx_buffer_low_watermark;
+	u64 rxdids;
+	/* Used for both Q models single and split. In split Q model relavant
+	 * only to Tx compl Q and Rx compl Q
+	 */
+	struct iecm_q_vector *q_vector;	/* Backreference to associated vector */
+	unsigned int size;		/* length of descriptor ring in bytes */
+	dma_addr_t dma;			/* physical address of ring */
+	void *desc_ring;		/* Descriptor ring memory */
+
+	u16 tx_buf_key;			/* 16 bit unique "identifier" (index)
+					 * to be used as the completion tag when
+					 * queue is using flow based scheduling
+					 */
+	u16 tx_max_bufs;		/* Max buffers that can be transmitted
+					 * with scatter-gather
+					 */
+	DECLARE_HASHTABLE(sched_buf_hash, 12);
+} ____cacheline_internodealigned_in_smp;
+
+/* Software queues are used in splitq mode to manage buffers between rxq

drivers/net/ethernet/intel/include/iecm_txrx.h struct iecm_q_vector { · line 243

Quoted 10 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +10 -0
+ * producer and the bufq consumer.  These are required in order to maintain a
+ * lockless buffer management system and are strictly software only constructs.
+ */
+struct iecm_sw_queue {
+	u16 next_to_clean ____cacheline_aligned_in_smp;
+	u16 next_to_alloc ____cacheline_aligned_in_smp;
+	u16 next_to_use ____cacheline_aligned_in_smp;
+	DECLARE_BITMAP(flags, __IECM_Q_FLAGS_NBITS)
+		____cacheline_aligned_in_smp;
+	u16 *ring ____cacheline_aligned_in_smp;

This will result in this part being FIVE cachelines long for 3 * 2 + 8 + 8 = 22 bytes, i.e. 320 bytes for 22! Just making the entire structure cacheline-aligned after its declaration is enough, these ones are not even an overkill, it's an overslaughter.

Quoted 82 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +77 -0
+	u16 desc_count;
+	u16 buf_size;
+	struct device *dev;
+} ____cacheline_internodealigned_in_smp;
+
+/* Splitq only.  iecm_rxq_set associates an rxq with at an array of refillqs.
+ * Each rxq needs a refillq to return used buffers back to the respective bufq.
+ * Bufqs then clean these refillqs for buffers to give to hardware.
+ */
+struct iecm_rxq_set {
+	struct iecm_queue rxq;
+	/* refillqs assoc with bufqX mapped to this rxq */
+	struct iecm_sw_queue *refillq0;
+	struct iecm_sw_queue *refillq1;
+};
+
+/* Splitq only.  iecm_bufq_set associates a bufq to an array of refillqs.
+ * In this bufq_set, there will be one refillq for each rxq in this rxq_group.
+ * Used buffers received by rxqs will be put on refillqs which bufqs will
+ * clean to return new buffers back to hardware.
+ *
+ * Buffers needed by some number of rxqs associated in this rxq_group are
+ * managed by at most two bufqs (depending on performance configuration).
+ */
+struct iecm_bufq_set {
+	struct iecm_queue bufq;
+	/* This is always equal to num_rxq_sets in iecm_rxq_group */
+	int num_refillqs;
+	struct iecm_sw_queue *refillqs;
+};
+
+/* In singleq mode, an rxq_group is simply an array of rxqs.  In splitq, a
+ * rxq_group contains all the rxqs, bufqs and refillqs needed to
+ * manage buffers in splitq mode.
+ */
+struct iecm_rxq_group {
+	struct iecm_vport *vport; /* back pointer */
+
+	union {
+		struct {
+			int num_rxq;
+			/* store queue pointers */
+			struct iecm_queue *rxqs[IECM_LARGE_MAX_Q];
+		} singleq;
+		struct {
+			int num_rxq_sets;
+			/* store queue pointers */
+			struct iecm_rxq_set *rxq_sets[IECM_LARGE_MAX_Q];
+			struct iecm_bufq_set *bufq_sets;
+		} splitq;
+	};
+};
+
+/* Between singleq and splitq, a txq_group is largely the same except for the
+ * complq.  In splitq a single complq is responsible for handling completions
+ * for some number of txqs associated in this txq_group.
+ */
+struct iecm_txq_group {
+	struct iecm_vport *vport; /* back pointer */
+
+	int num_txq;
+	/* store queue pointers */
+	struct iecm_queue *txqs[IECM_LARGE_MAX_Q];
+
+	/* splitq only */
+	struct iecm_queue *complq;
+};
+
+struct iecm_adapter;
+
+void iecm_vport_init_num_qs(struct iecm_vport *vport,
+			    struct virtchnl2_create_vport *vport_msg);
+void iecm_vport_calc_num_q_desc(struct iecm_vport *vport);
+void iecm_vport_calc_total_qs(struct iecm_adapter *adapter,
+			      struct virtchnl2_create_vport *vport_msg);
+void iecm_vport_calc_num_q_groups(struct iecm_vport *vport);
+void iecm_vport_calc_num_q_vec(struct iecm_vport *vport);
 irqreturn_t
 iecm_vport_intr_clean_queues(int __always_unused irq, void *data);
 #endif /* !_IECM_TXRX_H_ */
Signature · 1 line
2.33.0

Thanks,
Al

#28 lore raw

PATCH 6/19 iecm: add virtchnl messages for queues

Quoted 55 lines

-----Original Message-----
From: Lobakin, Alexandr <[email protected]>
Sent: Friday, January 28, 2022 5:03 AM
To: Brady, Alan <[email protected]>
Cc: Lobakin, Alexandr <[email protected]>; intel-wired- lan at lists.osuosl.org; Linga, Pavan Kumar <[email protected]>; Chittim, Madhu <[email protected]>; Burra, Phani R <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net-next 06/19] iecm: add virtchnl messages for queues

From: Alan Brady <[email protected]>
Date: Thu, 27 Jan 2022 16:09:56 -0800

Quoted 17 lines

This continues adding virtchnl messages. This largely relates to adding messages needed to negotiate and setup traffic queues.

---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    |   14 +
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   |  161 +++
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   | 1127 ++++++++++++++++-
 drivers/net/ethernet/intel/include/iecm.h     |   22 +
 .../net/ethernet/intel/include/iecm_txrx.h    |  196 +++
 5 files changed, 1505 insertions(+), 15 deletions(-)

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/iecm/iecm_lib.c

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 3 lines

index e2e523f0700e..4e9cc7f2d138 100644

drivers/net/ethernet/intel/iecm/iecm_lib.c +0 -0

--- 8< ---

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +3 -0
+void iecm_vport_calc_num_q_desc(struct iecm_vport *vport)
+{
+	int num_req_txq_desc = vport->adapter-

config_data.num_req_txq_desc;

drivers/net/ethernet/intel/iecm/iecm_lib.c +1 -0
+	int num_req_rxq_desc = vport->adapter-

config_data.num_req_rxq_desc;

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +9 -0
+	int num_bufqs = vport->num_bufqs_per_qgrp;
+	int i = 0;
+
+	vport->complq_desc_count = 0;
+	if (num_req_txq_desc) {
+		vport->txq_desc_count = num_req_txq_desc;
+		if (iecm_is_queue_model_split(vport->txq_model)) {
+			vport->complq_desc_count = num_req_txq_desc;
+			if (vport->complq_desc_count <

IECM_MIN_TXQ_COMPLQ_DESC)

Quoted 13 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+				vport->complq_desc_count =
+					IECM_MIN_TXQ_COMPLQ_DESC;
+		}
+	} else {
+		vport->txq_desc_count =
+			IECM_DFLT_TX_Q_DESC_COUNT;
+		if (iecm_is_queue_model_split(vport->txq_model)) {
+			vport->complq_desc_count =
+				IECM_DFLT_TX_COMPLQ_DESC_COUNT;
+		}

Braces are redundant here since the path is a one-liner.

Correct me if I'm wrong but believe the guidance here is if it goes beyond one line with line wrapping, it is optional whether or not to use braces, even if the statement is 'one line'. We have generally preferred to keep braces in multiline statements. However you do have a point that it is not consistent in this function. Will fix.

Quoted 556 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 13 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +11 -0
+	}
+
+	if (num_req_rxq_desc)
+		vport->rxq_desc_count = num_req_rxq_desc;
+	else
+		vport->rxq_desc_count = IECM_DFLT_RX_Q_DESC_COUNT;
+
+	for (i = 0; i < num_bufqs; i++) {
+		if (!vport->bufq_desc_count[i])
+			vport->bufq_desc_count[i] =
+				IECM_RX_BUFQ_DESC_COUNT(vport-

rxq_desc_count,

drivers/net/ethernet/intel/iecm/iecm_lib.c +1 -0
+							num_bufqs);
		if (vport->bufq_desc_count[i])
			continue;

		vport-> ...

-1 indent level with that.

Quoted 24 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +24 -0
+	}
+}
+EXPORT_SYMBOL(iecm_vport_calc_num_q_desc);
+
+/**
+ * iecm_vport_calc_total_qs - Calculate total number of queues
+ * @adapter: private data struct
+ * @vport_msg: message to fill with data
+ */
+void iecm_vport_calc_total_qs(struct iecm_adapter *adapter,
+			      struct virtchnl2_create_vport *vport_msg)
+{
+	unsigned int num_req_tx_qs = adapter->config_data.num_req_tx_qs;
+	unsigned int num_req_rx_qs = adapter->config_data.num_req_rx_qs;
+	int dflt_splitq_txq_grps, dflt_singleq_txqs;
+	int dflt_splitq_rxq_grps, dflt_singleq_rxqs;
+	int num_txq_grps, num_rxq_grps;
+	int num_cpus;
+	u16 max_q;
+
+	/* Restrict num of queues to cpus online as a default configuration to
+	 * give best performance. User can always override to a max number
+	 * of queues via ethtool.
+	 */

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+	num_cpus = num_online_cpus();
+	max_q = adapter->max_queue_limit;
+
+	dflt_splitq_txq_grps = min_t(int, max_q, num_cpus);
+	dflt_singleq_txqs = min_t(int, max_q, num_cpus);
+	dflt_splitq_rxq_grps = min_t(int, max_q, num_cpus);
+	dflt_singleq_rxqs = min_t(int, max_q, num_cpus);
+
+	if (iecm_is_queue_model_split(le16_to_cpu(vport_msg->txq_model))) {
+		num_txq_grps = num_req_tx_qs ? num_req_tx_qs :

dflt_splitq_txq_grps;

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +2 -0
+		vport_msg->num_tx_complq = cpu_to_le16(num_txq_grps *
+

IECM_COMPLQ_PER_GROUP);

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +2 -0
+		vport_msg->num_tx_q = cpu_to_le16(num_txq_grps *
+

IECM_DFLT_SPLITQ_TXQ_PER_GROUP);

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+	} else {
+		num_txq_grps = IECM_DFLT_SINGLEQ_TX_Q_GROUPS;
+		vport_msg->num_tx_q =
+				cpu_to_le16(num_txq_grps *
+					    (num_req_tx_qs ? num_req_tx_qs :
+					    dflt_singleq_txqs));
+		vport_msg->num_tx_complq = 0;
+	}
+	if (iecm_is_queue_model_split(le16_to_cpu(vport_msg->rxq_model))) {
+		num_rxq_grps = num_req_rx_qs ? num_req_rx_qs :

dflt_splitq_rxq_grps;

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +3 -0
+		vport_msg->num_rx_bufq =
+					cpu_to_le16(num_rxq_grps *
+

IECM_MAX_BUFQS_PER_RXQ_GRP);

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +3 -0
+
+		vport_msg->num_rx_q = cpu_to_le16(num_rxq_grps *
+

IECM_DFLT_SPLITQ_RXQ_PER_GROUP);

Quoted 20 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +20 -0
+	} else {
+		num_rxq_grps = IECM_DFLT_SINGLEQ_RX_Q_GROUPS;
+		vport_msg->num_rx_bufq = 0;
+		vport_msg->num_rx_q =
+				cpu_to_le16(num_rxq_grps *
+					    (num_req_rx_qs ? num_req_rx_qs :
+					    dflt_singleq_rxqs));
+	}
+}
+
+/**
+ * iecm_vport_calc_num_q_groups - Calculate number of queue groups
+ * @vport: vport to calculate q groups for
+ */
+void iecm_vport_calc_num_q_groups(struct iecm_vport *vport)
+{
+	if (iecm_is_queue_model_split(vport->txq_model))
+		vport->num_txq_grp = vport->num_txq;
+	else
+		vport->num_txq_grp = IECM_DFLT_SINGLEQ_TX_Q_GROUPS;

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+
+	if (iecm_is_queue_model_split(vport->rxq_model))
+		vport->num_rxq_grp = vport->num_rxq;
+	else
+		vport->num_rxq_grp = IECM_DFLT_SINGLEQ_RX_Q_GROUPS;
+}
+EXPORT_SYMBOL(iecm_vport_calc_num_q_groups);
+
+/**
+ * iecm_vport_calc_num_q_vec - Calculate total number of vectors required

for

Review

Quoted 13 lines

+ * this vport
+ * @vport: virtual port
+ *
+ */

drivers/net/ethernet/intel/iecm/iecm_lib.c +8 -0
+void iecm_vport_calc_num_q_vec(struct iecm_vport *vport)
+{
+	if (iecm_is_queue_model_split(vport->txq_model))
+		vport->num_q_vectors = vport->num_txq_grp;
+	else
+		vport->num_q_vectors = vport->num_txq;
+}
+EXPORT_SYMBOL(iecm_vport_calc_num_q_vec);
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/iecm/iecm_virtchnl.c

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_recv_get_caps_msg(struct

Quoted 4 lines

index aae06064d706..d8152e657e24 100644

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +0 -0
@@ -859,6 +859,48 @@ static int iecm_recv_get_caps_msg(struct

iecm_adapter *adapter)

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_recv_get_caps_msg(struct

Quoted 49 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +42 -0
 				sizeof(struct virtchnl2_get_capabilities));
 }
 
+/**
+ * iecm_get_reg_intr_vecs - Get vector queue register offset
+ * @vport: virtual port structure
+ * @reg_vals: Register offsets to store in
+ * @num_vecs: Number of vector registers
+ *
+ * Returns number of regsiters that got populated
+ */
+int iecm_get_reg_intr_vecs(struct iecm_vport *vport,
+			   struct iecm_vec_regs *reg_vals, int num_vecs)
+{
+	struct virtchnl2_vector_chunks *chunks;
+	struct iecm_vec_regs reg_val;
+	u16 num_vchunks, num_vec;
+	int num_regs = 0, i, j;
+
+	chunks = &vport->adapter->req_vec_chunks->vchunks;
+	num_vchunks = le16_to_cpu(chunks->num_vchunks);
+
+	for (j = 0; j < num_vchunks; j++) {
+		struct virtchnl2_vector_chunk *chunk = &chunks->vchunks[j];
+
+		num_vec = le16_to_cpu(chunk->num_vectors);
+		reg_val.dyn_ctl_reg = le32_to_cpu(chunk->dynctl_reg_start);
+		reg_val.itrn_reg = le32_to_cpu(chunk->itrn_reg_start);
+		for (i = 0; i < num_vec; i++) {
+			if (num_regs == num_vecs)
+				break;
+			reg_vals[i].dyn_ctl_reg = reg_val.dyn_ctl_reg;
+			reg_vals[i].itrn_reg = reg_val.itrn_reg;
+			reg_val.dyn_ctl_reg +=
+				le32_to_cpu(chunk->dynctl_reg_spacing);
+			reg_val.itrn_reg +=
+				le32_to_cpu(chunk->itrn_reg_spacing);
+			num_regs++;
+		}
+	}
+
+	return num_regs;
+}
+EXPORT_SYMBOL(iecm_get_reg_intr_vecs);
+
 /**
  * iecm_send_create_vport_msg - Send virtchnl create vport message
  * @adapter: Driver specific private structure
@@ -869,8 +911,36 @@ static int iecm_recv_get_caps_msg(struct

iecm_adapter *adapter)

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_recv_get_caps_msg(struct iecm_adapter *adapter)

Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +6 -2
  */
 static int iecm_send_create_vport_msg(struct iecm_adapter *adapter)
 {
-	/* stub */
-	return 0;
+	struct virtchnl2_create_vport *vport_msg;
+	int buf_size;
+
+	buf_size = sizeof(struct virtchnl2_create_vport);
+	if (!adapter->vport_params_reqd[0]) {
+		adapter->vport_params_reqd[0] = kzalloc(buf_size,

GFP_KERNEL);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_recv_get_caps_msg(struct iecm_adapter *adapter)

Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +7 -0
+		if (!adapter->vport_params_reqd[0])
+			return -ENOMEM;
+	}
+
+	vport_msg = (struct virtchnl2_create_vport *)
+			adapter->vport_params_reqd[0];
+	vport_msg->vport_type =

cpu_to_le16(VIRTCHNL2_VPORT_TYPE_DEFAULT);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_recv_get_caps_msg(struct iecm_adapter *adapter)

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +3 -0
+
+	if (test_bit(__IECM_REQ_TX_SPLITQ, adapter->flags))
+		vport_msg->txq_model =

cpu_to_le16(VIRTCHNL2_QUEUE_MODEL_SPLIT);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_recv_get_caps_msg(struct · line 931

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +2 -0
+	else
+		vport_msg->txq_model =

cpu_to_le16(VIRTCHNL2_QUEUE_MODEL_SINGLE);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_recv_get_caps_msg(struct iecm_adapter *adapter)

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +3 -0
+
+	if (test_bit(__IECM_REQ_RX_SPLITQ, adapter->flags))
+		vport_msg->rxq_model =

cpu_to_le16(VIRTCHNL2_QUEUE_MODEL_SPLIT);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_recv_get_caps_msg(struct · line 936

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +2 -0
+	else
+		vport_msg->rxq_model =

cpu_to_le16(VIRTCHNL2_QUEUE_MODEL_SINGLE);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_recv_get_caps_msg(struct iecm_adapter *adapter)

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +6 -0
+
+	adapter->dev_ops.vc_ops.init_max_queues(adapter);
+
+	iecm_vport_calc_total_qs(adapter, vport_msg);
+
+	return iecm_send_mb_msg(adapter, VIRTCHNL2_OP_CREATE_VPORT,

buf_size,

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_send_create_vport_msg(struct

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +1 -0
+				(u8 *)vport_msg);
 }
 
 /**
@@ -884,7 +954,25 @@ static int iecm_send_create_vport_msg(struct

iecm_adapter *adapter)

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_send_create_vport_msg(struct iecm_adapter *adapter)

Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +5 -1
 static int iecm_recv_create_vport_msg(struct iecm_adapter *adapter,
 				      int *vport_id)
 {
-	/* stub */
+	struct virtchnl2_create_vport *vport_msg;
+	int err;
+
+	if (!adapter->vport_params_recvd[0]) {
+		adapter->vport_params_recvd[0] =

kzalloc(IECM_DFLT_MBX_BUF_SIZE,

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_send_create_vport_msg(struct iecm_adapter *adapter)

Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +9 -0
+							 GFP_KERNEL);
+		if (!adapter->vport_params_recvd[0])
+			return -ENOMEM;
+	}
+
+	vport_msg = (struct virtchnl2_create_vport *)
+			adapter->vport_params_recvd[0];
+
+	err = iecm_recv_mb_msg(adapter, VIRTCHNL2_OP_CREATE_VPORT,

vport_msg,

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter

Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +5 -0
+			       IECM_DFLT_MBX_BUF_SIZE);
+	if (err)
+		return err;
+
+	*vport_id = le32_to_cpu(vport_msg->vport_id);
 	return 0;
 }
 
@@ -966,6 +1054,920 @@ int iecm_wait_for_event(struct iecm_adapter

*adapter,

Quoted 90 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +87 -0
 }
 EXPORT_SYMBOL(iecm_wait_for_event);
 
+/**
+ * iecm_wait_for_marker_event - wait for software marker response
+ * @vport: virtual port data structure
+ *
+ * Returns 0 success, negative on failure.
+ **/
+static int iecm_wait_for_marker_event(struct iecm_vport *vport)
+{
+	int event = 0;
+	int i;
+
+	for (i = 0; i < vport->num_txq; i++)
+		set_bit(__IECM_Q_SW_MARKER, vport->txqs[i]->flags);
+
+	event = wait_event_timeout(vport->adapter->sw_marker_wq,
+				   test_and_clear_bit(__IECM_SW_MARKER,
+						      vport->adapter->flags),
+				   msecs_to_jiffies(500));
+	if (event)
+		return 0;
+	return -ETIMEDOUT;
+}
+
+/**
+ * iecm_send_destroy_vport_msg - Send virtchnl destroy vport message
+ * @vport: virtual port data structure
+ *
+ * Send virtchnl destroy vport message.  Returns 0 on success, negative on
+ * failure.
+ */
+int iecm_send_destroy_vport_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_vport v_id;
+	int err;
+
+	v_id.vport_id = cpu_to_le32(vport->vport_id);
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_DESTROY_VPORT,
+			       sizeof(v_id), (u8 *)&v_id);
+	if (err)
+		return err;
+
+	return iecm_min_wait_for_event(adapter, IECM_VC_DESTROY_VPORT,
+				       IECM_VC_DESTROY_VPORT_ERR);
+}
+
+/**
+ * iecm_send_enable_vport_msg - Send virtchnl enable vport message
+ * @vport: virtual port data structure
+ *
+ * Send enable vport virtchnl message.  Returns 0 on success, negative on
+ * failure.
+ */
+int iecm_send_enable_vport_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_vport v_id;
+	int err;
+
+	v_id.vport_id = cpu_to_le32(vport->vport_id);
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_ENABLE_VPORT,
+			       sizeof(v_id), (u8 *)&v_id);
+	if (err)
+		return err;
+
+	return iecm_wait_for_event(adapter, IECM_VC_ENA_VPORT,
+				   IECM_VC_ENA_VPORT_ERR);
+}
+
+/**
+ * iecm_send_disable_vport_msg - Send virtchnl disable vport message
+ * @vport: virtual port data structure
+ *
+ * Send disable vport virtchnl message.  Returns 0 on success, negative on
+ * failure.
+ */
+int iecm_send_disable_vport_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_vport v_id;
+	int err;
+
+	v_id.vport_id = cpu_to_le32(vport->vport_id);
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_DISABLE_VPORT,

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+			       sizeof(v_id), (u8 *)&v_id);
+	if (err)
+		return err;
+
+	return iecm_min_wait_for_event(adapter, IECM_VC_DIS_VPORT,
+				       IECM_VC_DIS_VPORT_ERR);
+}
+
+/**
+ * iecm_send_config_tx_queues_msg - Send virtchnl config tx queues

message

Quoted 35 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +35 -0
+ * @vport: virtual port data structure
+ *
+ * Send config tx queues virtchnl message. Returns 0 on success, negative on
+ * failure.
+ */
+int iecm_send_config_tx_queues_msg(struct iecm_vport *vport)
+{
+	struct virtchnl2_config_tx_queues *ctq = NULL;
+	int config_data_size, chunk_size, buf_size = 0;
+	int totqs, num_msgs, num_chunks;
+	struct virtchnl2_txq_info *qi;
+	int err = 0, i, k = 0;
+	bool alloc = false;
+
+	totqs = vport->num_txq + vport->num_complq;
+	qi = kcalloc(totqs, sizeof(struct virtchnl2_txq_info), GFP_KERNEL);
+	if (!qi)
+		return -ENOMEM;
+
+	/* Populate the queue info buffer with all queue context info */
+	for (i = 0; i < vport->num_txq_grp; i++) {
+		struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+		int j;
+
+		for (j = 0; j < tx_qgrp->num_txq; j++, k++) {
+			qi[k].queue_id =
+				cpu_to_le32(tx_qgrp->txqs[j]->q_id);
+			qi[k].model =
+				cpu_to_le16(vport->txq_model);
+			qi[k].type =
+				cpu_to_le32(tx_qgrp->txqs[j]->q_type);
+			qi[k].ring_len =
+				cpu_to_le16(tx_qgrp->txqs[j]->desc_count);
+			qi[k].dma_ring_addr =
+				cpu_to_le64(tx_qgrp->txqs[j]->dma);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1206

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +9 -0
+			if (iecm_is_queue_model_split(vport->txq_model)) {
+				struct iecm_queue *q = tx_qgrp->txqs[j];
+
+				qi[k].tx_compl_queue_id =
+					cpu_to_le16(tx_qgrp->complq->q_id);
+
+				if (test_bit(__IECM_Q_FLOW_SCH_EN, q-
 flags))
+					qi[k].sched_mode =
+
	cpu_to_le16(VIRTCHNL2_TXQ_SCHED_MODE_FLOW);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1206

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +3 -0
+				else
+					qi[k].sched_mode =
+
	cpu_to_le16(VIRTCHNL2_TXQ_SCHED_MODE_QUEUE);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1206

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +3 -0
+			} else {
+				qi[k].sched_mode =
+
	cpu_to_le16(VIRTCHNL2_TXQ_SCHED_MODE_QUEUE);
Quoted 21 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +21 -0
+			}
+		}
+
+		if (iecm_is_queue_model_split(vport->txq_model)) {
+			qi[k].queue_id =
+				cpu_to_le32(tx_qgrp->complq->q_id);
+			qi[k].model =
+				cpu_to_le16(vport->txq_model);
+			qi[k].type =
+				cpu_to_le32(tx_qgrp->complq->q_type);
+			qi[k].ring_len =
+				cpu_to_le16(tx_qgrp->complq->desc_count);
+			qi[k].dma_ring_addr =
+				cpu_to_le64(tx_qgrp->complq->dma);
+			k++;
+		}
+	}
+
+	/* Make sure accounting agrees */
+	if (k != totqs) {
+		err = -EINVAL;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+		goto error;
+	}
+
+	/* Chunk up the queue contexts into multiple messages to avoid
+	 * sending a control queue message buffer that is too large
+	 */
+	config_data_size = sizeof(struct virtchnl2_config_tx_queues);
+	chunk_size = sizeof(struct virtchnl2_txq_info);
+
+	num_chunks = IECM_NUM_CHUNKS_PER_MSG(config_data_size,

chunk_size) + 1;

Quoted 22 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +22 -0
+	if (totqs < num_chunks)
+		num_chunks = totqs;
+
+	num_msgs = totqs / num_chunks;
+	if (totqs % num_chunks)
+		num_msgs++;
+
+	for (i = 0, k = 0; i < num_msgs; i++) {
+		if (!ctq || alloc) {
+			buf_size = (chunk_size * (num_chunks - 1)) +
+					config_data_size;
+			kfree(ctq);
+			ctq = kzalloc(buf_size, GFP_KERNEL);
+			if (!ctq) {
+				err = -ENOMEM;
+				goto error;
+			}
+		} else {
+			memset(ctq, 0, buf_size);
+		}
+
+		ctq->vport_id = cpu_to_le32(vport->vport_id);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+		ctq->num_qinfo = cpu_to_le16(num_chunks);
+		memcpy(ctq->qinfo, &qi[k], chunk_size * num_chunks);
+
+		err = iecm_send_mb_msg(vport->adapter,
+				       VIRTCHNL2_OP_CONFIG_TX_QUEUES,
+				       buf_size, (u8 *)ctq);
+		if (err)
+			goto mbx_error;
+
+		err = iecm_wait_for_event(vport->adapter,

IECM_VC_CONFIG_TXQ,

Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +11 -0
+					  IECM_VC_CONFIG_TXQ_ERR);
+		if (err)
+			goto mbx_error;
+
+		k += num_chunks;
+		totqs -= num_chunks;
+		if (totqs < num_chunks) {
+			num_chunks = totqs;
+			alloc = true;
+		}
+	}

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+
+mbx_error:
+	kfree(ctq);
+error:
+	kfree(qi);
+	return err;
+}
+
+/**
+ * iecm_send_config_rx_queues_msg - Send virtchnl config rx queues

message

Quoted 28 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +28 -0
+ * @vport: virtual port data structure
+ *
+ * Send config rx queues virtchnl message.  Returns 0 on success, negative on
+ * failure.
+ */
+int iecm_send_config_rx_queues_msg(struct iecm_vport *vport)
+{
+	struct virtchnl2_config_rx_queues *crq = NULL;
+	int config_data_size, chunk_size, buf_size = 0;
+	int totqs, num_msgs, num_chunks;
+	struct virtchnl2_rxq_info *qi;
+	int err = 0, i, k = 0;
+	bool alloc = false;
+
+	totqs = vport->num_rxq + vport->num_bufq;
+	qi = kcalloc(totqs, sizeof(struct virtchnl2_rxq_info), GFP_KERNEL);
+	if (!qi)
+		return -ENOMEM;
+
+	/* Populate the queue info buffer with all queue context info */
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+		int num_rxq;
+		int j;
+
+		if (iecm_is_queue_model_split(vport->rxq_model)) {
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++, k++) {
+				struct iecm_queue *bufq =

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1338

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+					&rx_qgrp->splitq.bufq_sets[j].bufq;
+
+				qi[k].queue_id =
+					cpu_to_le32(bufq->q_id);
+				qi[k].model =
+					cpu_to_le16(vport->rxq_model);
+				qi[k].type =
+					cpu_to_le32(bufq->q_type);
+				qi[k].desc_ids =
+
	cpu_to_le64(VIRTCHNL2_RXDID_1_FLEX_SPLITQ_M);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1337

Quoted 13 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +12 -0
+				qi[k].ring_len =
+					cpu_to_le16(bufq->desc_count);
+				qi[k].dma_ring_addr =
+					cpu_to_le64(bufq->dma);
+				qi[k].data_buffer_size =
+					cpu_to_le32(bufq->rx_buf_size);
+				qi[k].buffer_notif_stride =
+					bufq->rx_buf_stride;
+				qi[k].rx_buffer_low_watermark =
+					cpu_to_le16(bufq-
 rx_buffer_low_watermark);
+			}
+		}
		if (iecm_is_queue_model_split(vport->rxq_model))
			goto here;
Quoted 1 line

-1 indent level for the for-loop.

I'm afraid I'm not following, please elaborate. Where are we goto'ing? The for loop below needs to be executed for both and if we just tack the above for loop at the bottom of the function and goto in and out of it to save an indent does not sound great and makes the code harder to follow IMO.

Quoted 2 lines

Braces for 'if' are not needed since the for-loop has their own.

They're not required but we have generally preferred to keep braces on statements extending across more than one line.

Quoted 27 lines
Quoted 22 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +15 -0
+
+		if (iecm_is_queue_model_split(vport->rxq_model))
+			num_rxq = rx_qgrp->splitq.num_rxq_sets;
+		else
+			num_rxq = rx_qgrp->singleq.num_rxq;
+
+		for (j = 0; j < num_rxq; j++, k++) {
+			struct iecm_queue *rxq;
+
+			if (iecm_is_queue_model_split(vport->rxq_model)) {
+				rxq = &rx_qgrp->splitq.rxq_sets[j]->rxq;
+				qi[k].rx_bufq1_id =
+				  cpu_to_le16(rxq->rxq_grp-
 splitq.bufq_sets[0].bufq.q_id);
+				qi[k].rx_bufq2_id =
+				  cpu_to_le16(rxq->rxq_grp-

splitq.bufq_sets[1].bufq.q_id);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +4 -0
+				qi[k].hdr_buffer_size =
+					cpu_to_le16(rxq->rx_hbuf_size);
+				qi[k].rx_buffer_low_watermark =
+					cpu_to_le16(rxq-

rx_buffer_low_watermark);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1367

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +4 -0
+
+				if (rxq->rx_hsplit_en) {
+					qi[k].qflags =
+
	cpu_to_le16(VIRTCHNL2_RXQ_HDR_SPLIT);
Quoted 10 lines

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1366

Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +2 -0
+					qi[k].hdr_buffer_size =
+						cpu_to_le16(rxq-

rx_hbuf_size);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +4 -0
+				}
+			} else {
+				rxq = rx_qgrp->singleq.rxqs[j];
+			}

Same here, but with rxq = ... + goto.

Please elaborate.

Quoted 1,106 lines
Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +7 -0
+
+			qi[k].queue_id =
+				cpu_to_le32(rxq->q_id);
+			qi[k].model =
+				cpu_to_le16(vport->rxq_model);
+			qi[k].type =
+				cpu_to_le32(rxq->q_type);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1388

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+			qi[k].ring_len =
+				cpu_to_le16(rxq->desc_count);
+			qi[k].dma_ring_addr =
+				cpu_to_le64(rxq->dma);
+			qi[k].max_pkt_size =
+				cpu_to_le32(rxq->rx_max_pkt_size);
+			qi[k].data_buffer_size =
+				cpu_to_le32(rxq->rx_buf_size);
+			qi[k].qflags |=
+
	cpu_to_le16(VIRTCHNL2_RX_DESC_SIZE_32BYTE);
Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +8 -0
+			qi[k].desc_ids =
+				cpu_to_le64(rxq->rxdids);
+		}
+	}
+
+	/* Make sure accounting agrees */
+	if (k != totqs) {
+		err = -EINVAL;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+		goto error;
+	}
+
+	/* Chunk up the queue contexts into multiple messages to avoid
+	 * sending a control queue message buffer that is too large
+	 */
+	config_data_size = sizeof(struct virtchnl2_config_rx_queues);
+	chunk_size = sizeof(struct virtchnl2_rxq_info);
+
+	num_chunks = IECM_NUM_CHUNKS_PER_MSG(config_data_size,

chunk_size) + 1;

Quoted 22 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +22 -0
+	if (totqs < num_chunks)
+		num_chunks = totqs;
+
+	num_msgs = totqs / num_chunks;
+	if (totqs % num_chunks)
+		num_msgs++;
+
+	for (i = 0, k = 0; i < num_msgs; i++) {
+		if (!crq || alloc) {
+			buf_size = (chunk_size * (num_chunks - 1)) +
+					config_data_size;
+			kfree(crq);
+			crq = kzalloc(buf_size, GFP_KERNEL);
+			if (!crq) {
+				err = -ENOMEM;
+				goto error;
+			}
+		} else {
+			memset(crq, 0, buf_size);
+		}
+
+		crq->vport_id = cpu_to_le32(vport->vport_id);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+		crq->num_qinfo = cpu_to_le16(num_chunks);
+		memcpy(crq->qinfo, &qi[k], chunk_size * num_chunks);
+
+		err = iecm_send_mb_msg(vport->adapter,
+				       VIRTCHNL2_OP_CONFIG_RX_QUEUES,
+				       buf_size, (u8 *)crq);
+		if (err)
+			goto mbx_error;
+
+		err = iecm_wait_for_event(vport->adapter,

IECM_VC_CONFIG_RXQ,

Quoted 74 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +74 -0
+					  IECM_VC_CONFIG_RXQ_ERR);
+		if (err)
+			goto mbx_error;
+
+		k += num_chunks;
+		totqs -= num_chunks;
+		if (totqs < num_chunks) {
+			num_chunks = totqs;
+			alloc = true;
+		}
+	}
+
+mbx_error:
+	kfree(crq);
+error:
+	kfree(qi);
+	return err;
+}
+
+/**
+ * iecm_send_ena_dis_queues_msg - Send virtchnl enable or disable
+ * queues message
+ * @vport: virtual port data structure
+ * @vc_op: virtchnl op code to send
+ *
+ * Send enable or disable queues virtchnl message. Returns 0 on success,
+ * negative on failure.
+ */
+static int iecm_send_ena_dis_queues_msg(struct iecm_vport *vport,
+					enum virtchnl_ops vc_op)
+{
+	int num_msgs, num_chunks, config_data_size, chunk_size;
+	int num_txq, num_rxq, num_q, buf_size, err = 0;
+	struct virtchnl2_del_ena_dis_queues *eq = NULL;
+	struct virtchnl2_queue_chunk *qc;
+	bool alloc = false;
+	int i, j, k = 0;
+
+	/* validate virtchnl op */
+	switch (vc_op) {
+	case VIRTCHNL2_OP_ENABLE_QUEUES:
+	case VIRTCHNL2_OP_DISABLE_QUEUES:
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	num_txq = vport->num_txq + vport->num_complq;
+	num_rxq = vport->num_rxq + vport->num_bufq;
+	num_q = num_txq + num_rxq;
+	buf_size = sizeof(struct virtchnl2_queue_chunk) * (num_q);
+	qc = kzalloc(buf_size, GFP_KERNEL);
+	if (!qc)
+		return -ENOMEM;
+
+	for (i = 0; i < vport->num_txq_grp; i++) {
+		struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+
+		for (j = 0; j < tx_qgrp->num_txq; j++, k++) {
+			qc[k].type = cpu_to_le32(tx_qgrp->txqs[j]->q_type);
+			qc[k].start_queue_id =
+					cpu_to_le32(tx_qgrp->txqs[j]->q_id);
+			qc[k].num_queues = cpu_to_le32(1);
+		}
+	}
+	if (vport->num_txq != k) {
+		err = -EINVAL;
+		goto error;
+	}
+
+	if (iecm_is_queue_model_split(vport->txq_model)) {
+		for (i = 0; i < vport->num_txq_grp; i++, k++) {
+			struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1517

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+			qc[k].type = cpu_to_le32(tx_qgrp->complq->q_type);
+			qc[k].start_queue_id =
+					cpu_to_le32(tx_qgrp->complq->q_id);
+			qc[k].num_queues = cpu_to_le32(1);
+		}
+		if (vport->num_complq != (k - vport->num_txq)) {
+			err = -EINVAL;
+			goto error;
+		}
+	}

...and here.

Quoted 41 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +13 -0
+
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+
+		if (iecm_is_queue_model_split(vport->rxq_model))
+			num_rxq = rx_qgrp->splitq.num_rxq_sets;
+		else
+			num_rxq = rx_qgrp->singleq.num_rxq;
+
+		for (j = 0; j < num_rxq; j++, k++) {
+			if (iecm_is_queue_model_split(vport->rxq_model)) {
+				qc[k].start_queue_id =
+				cpu_to_le32(rx_qgrp->splitq.rxq_sets[j]-

rxq.q_id);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +2 -0
+				qc[k].type =
+				cpu_to_le32(rx_qgrp->splitq.rxq_sets[j]-

rxq.q_type);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +20 -0
+			} else {
+				qc[k].start_queue_id =
+				cpu_to_le32(rx_qgrp->singleq.rxqs[j]->q_id);
+				qc[k].type =
+				cpu_to_le32(rx_qgrp->singleq.rxqs[j]->q_type);
+			}
+			qc[k].num_queues = cpu_to_le32(1);
+		}
+	}
+	if (vport->num_rxq != k - (vport->num_txq + vport->num_complq)) {
+		err = -EINVAL;
+		goto error;
+	}
+
+	if (iecm_is_queue_model_split(vport->rxq_model)) {
+		for (i = 0; i < vport->num_rxq_grp; i++) {
+			struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++, k++) {
+				struct iecm_queue *q = &rx_qgrp-

splitq.bufq_sets[j].bufq;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +3 -0
+
+				qc[k].type = cpu_to_le32(q->q_type);
+				qc[k].start_queue_id = cpu_to_le32(q->q_id);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1565

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+				qc[k].num_queues = cpu_to_le32(1);
+			}
+		}
+		if (vport->num_bufq != k - (vport->num_txq +
+					       vport->num_complq +
+					       vport->num_rxq)) {
+			err = -EINVAL;
+			goto error;
+		}
+	}

...and here.

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +6 -0
+
+	/* Chunk up the queue info into multiple messages */
+	config_data_size = sizeof(struct virtchnl2_del_ena_dis_queues);
+	chunk_size = sizeof(struct virtchnl2_queue_chunk);
+
+	num_chunks = IECM_NUM_CHUNKS_PER_MSG(config_data_size,

chunk_size) + 1;

Quoted 13 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +13 -0
+	if (num_q < num_chunks)
+		num_chunks = num_q;
+
+	num_msgs = num_q / num_chunks;
+	if (num_q % num_chunks)
+		num_msgs++;
+
+	for (i = 0, k = 0; i < num_msgs; i++) {
+		if (!eq || alloc) {
+			buf_size = (chunk_size * (num_chunks - 1)) +
+					config_data_size;
+			kfree(eq);
+			eq = kzalloc(buf_size, GFP_KERNEL);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+			if (!eq) {
+				err = -ENOMEM;
+				goto error;
+			}
+		} else {
+			memset(eq, 0, buf_size);
+		}
+		eq->vport_id = cpu_to_le32(vport->vport_id);
+		eq->chunks.num_chunks = cpu_to_le16(num_chunks);
+		memcpy(eq->chunks.chunks, &qc[k], chunk_size *

num_chunks);

Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +11 -0
+
+		err = iecm_send_mb_msg(vport->adapter, vc_op, buf_size,
+				       (u8 *)eq);
+		if (err)
+			goto mbx_error;
+		k += num_chunks;
+		num_q -= num_chunks;
+		if (num_q < num_chunks) {
+			num_chunks = num_q;
+			alloc = true;
+		}

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+	}
+mbx_error:
+	kfree(eq);
+error:
+	kfree(qc);
+	return err;
+}
+
+/**
+ * iecm_send_map_unmap_queue_vector_msg - Send virtchnl map or unmap

queue

Quoted 8 lines

+ * vector message
+ * @vport: virtual port data structure
+ * @map: true for map and false for unmap
+ *
+ * Send map or unmap queue vector virtchnl message. Returns 0 on success,
+ * negative on failure.
+ */
+int iecm_send_map_unmap_queue_vector_msg(struct iecm_vport *vport,

bool map)

Quoted 63 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +21 -0
+{
+	int num_msgs, num_chunks, config_data_size, chunk_size;
+	struct virtchnl2_queue_vector_maps *vqvm = NULL;
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_queue_vector *vqv;
+	int buf_size, num_q, err = 0;
+	bool alloc = false;
+	int i, j, k = 0;
+
+	num_q = vport->num_txq + vport->num_rxq;
+
+	buf_size = sizeof(struct virtchnl2_queue_vector) * num_q;
+	vqv = kzalloc(buf_size, GFP_KERNEL);
+	if (!vqv)
+		return -ENOMEM;
+
+	for (i = 0; i < vport->num_txq_grp; i++) {
+		struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+
+		for (j = 0; j < tx_qgrp->num_txq; j++, k++) {
+			vqv[k].queue_type = cpu_to_le32(tx_qgrp->txqs[j]-

q_type);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +5 -0
+			vqv[k].queue_id = cpu_to_le32(tx_qgrp->txqs[j]->q_id);
+
+			if (iecm_is_queue_model_split(vport->txq_model)) {
+				vqv[k].vector_id =
+				cpu_to_le16(tx_qgrp->complq->q_vector-

v_idx);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +2 -0
+				vqv[k].itr_idx =
+				cpu_to_le32(tx_qgrp->complq->q_vector-

tx_itr_idx);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +3 -0
+			} else {
+				vqv[k].vector_id =
+				cpu_to_le16(tx_qgrp->txqs[j]->q_vector-

v_idx);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +2 -0
+				vqv[k].itr_idx =
+				cpu_to_le32(tx_qgrp->txqs[j]->q_vector-

tx_itr_idx);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +25 -0
+			}
+		}
+	}
+
+	if (vport->num_txq != k) {
+		err = -EINVAL;
+		goto error;
+	}
+
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+		int num_rxq;
+
+		if (iecm_is_queue_model_split(vport->rxq_model))
+			num_rxq = rx_qgrp->splitq.num_rxq_sets;
+		else
+			num_rxq = rx_qgrp->singleq.num_rxq;
+
+		for (j = 0; j < num_rxq; j++, k++) {
+			struct iecm_queue *rxq;
+
+			if (iecm_is_queue_model_split(vport->rxq_model))
+				rxq = &rx_qgrp->splitq.rxq_sets[j]->rxq;
+			else
+				rxq = rx_qgrp->singleq.rxqs[j];

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1691

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+
+			vqv[k].queue_type = cpu_to_le32(rxq->q_type);
+			vqv[k].queue_id = cpu_to_le32(rxq->q_id);
+			vqv[k].vector_id = cpu_to_le16(rxq->q_vector->v_idx);
+			vqv[k].itr_idx = cpu_to_le32(rxq->q_vector->rx_itr_idx);
+		}
+	}
+
+	if (iecm_is_queue_model_split(vport->txq_model)) {
+		if (vport->num_rxq != k - vport->num_complq) {
	if (iecm_is_queue_model_split() && vport->num_rxq != ...) {

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1252

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +4 -0
+			err = -EINVAL;
+			goto error;
+		}
+	} else {

Don't forget to convert this then into !split + ..., either with 'else' or not.

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +11 -0
+		if (vport->num_rxq != k - vport->num_txq) {
+			err = -EINVAL;
+			goto error;
+		}
+	}
+
+	/* Chunk up the vector info into multiple messages */
+	config_data_size = sizeof(struct virtchnl2_queue_vector_maps);
+	chunk_size = sizeof(struct virtchnl2_queue_vector);
+
+	num_chunks = IECM_NUM_CHUNKS_PER_MSG(config_data_size,

chunk_size) + 1;

Quoted 17 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +17 -0
+	if (num_q < num_chunks)
+		num_chunks = num_q;
+
+	num_msgs = num_q / num_chunks;
+	if (num_q % num_chunks)
+		num_msgs++;
+
+	for (i = 0, k = 0; i < num_msgs; i++) {
+		if (!vqvm || alloc) {
+			buf_size = (chunk_size * (num_chunks - 1)) +
+					config_data_size;
+			kfree(vqvm);
+			vqvm = kzalloc(buf_size, GFP_KERNEL);
+			if (!vqvm) {
+				err = -ENOMEM;
+				goto error;
+			}

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1751

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+		} else {
+			memset(vqvm, 0, buf_size);
+		}
+		vqvm->vport_id = cpu_to_le32(vport->vport_id);
+		vqvm->num_qv_maps = cpu_to_le16(num_chunks);
+		memcpy(vqvm->qv_maps, &vqv[k], chunk_size * num_chunks);
+
+		if (map) {
+			err = iecm_send_mb_msg(adapter,
+

VIRTCHNL2_OP_MAP_QUEUE_VECTOR,

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1751

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +5 -0
+					       buf_size, (u8 *)vqvm);
+			if (!err)
+				err = iecm_wait_for_event(adapter,
+							  IECM_VC_MAP_IRQ,
+

IECM_VC_MAP_IRQ_ERR);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1751

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +3 -0
+		} else {
+			err = iecm_send_mb_msg(adapter,
+

VIRTCHNL2_OP_UNMAP_QUEUE_VECTOR,

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1751

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +5 -0
+					       buf_size, (u8 *)vqvm);
+			if (!err)
+				err =
+				iecm_min_wait_for_event(adapter,
+

IECM_VC_UNMAP_IRQ,

Quoted 1 line

+

	IECM_VC_UNMAP_IRQ_ERR);
Quoted 14 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +14 -0
+		}
+		if (err)
+			goto mbx_error;
+
+		k += num_chunks;
+		num_q -= num_chunks;
+		if (num_q < num_chunks) {
+			num_chunks = num_q;
+			alloc = true;
+		}
+	}
+mbx_error:
+	kfree(vqvm);
+error:

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+	kfree(vqv);
+	return err;
+}
+EXPORT_SYMBOL(iecm_send_map_unmap_queue_vector_msg);
+
+/**
+ * iecm_send_enable_queues_msg - send enable queues virtchnl message
+ * @vport: Virtual port private data structure
+ *
+ * Will send enable queues virtchnl message.  Returns 0 on success, negative

on

Quoted 33 lines

+ * failure.
+ */

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +31 -0
+static int iecm_send_enable_queues_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	int err;
+
+	err = iecm_send_ena_dis_queues_msg(vport,
+					   VIRTCHNL2_OP_ENABLE_QUEUES);
+	if (err)
+		return err;
+
+	return iecm_wait_for_event(adapter, IECM_VC_ENA_QUEUES,
+				   IECM_VC_ENA_QUEUES_ERR);
+}
+
+/**
+ * iecm_send_disable_queues_msg - send disable queues virtchnl message
+ * @vport: Virtual port private data structure
+ *
+ * Will send disable queues virtchnl message.  Returns 0 on success, negative
+ * on failure.
+ */
+static int iecm_send_disable_queues_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	int err;
+
+	err = iecm_send_ena_dis_queues_msg(vport,
+					   VIRTCHNL2_OP_DISABLE_QUEUES);
+	if (err)
+		return err;
+

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+	err = iecm_min_wait_for_event(adapter, IECM_VC_DIS_QUEUES,
+				      IECM_VC_DIS_QUEUES_ERR);
+	if (err)
+		return err;
+
+	return iecm_wait_for_marker_event(vport);
+}
+
+/**
+ * iecm_convert_reg_to_queue_chunks - Copy queue chunk information to

the right

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c

Quoted 7 lines

+ * structure
+ * @dchunks: Destination chunks to store data to
+ * @schunks: Source chunks to copy data from
+ * @num_chunks: number of chunks to copy
+ */

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +2 -0
+static void
+iecm_convert_reg_to_queue_chunks(struct virtchnl2_queue_chunk

*dchunks,

Quoted 53 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +52 -0
+				 struct virtchnl2_queue_reg_chunk *schunks,
+				 u16 num_chunks)
+{
+	u16 i;
+
+	for (i = 0; i < num_chunks; i++) {
+		dchunks[i].type = schunks[i].type;
+		dchunks[i].start_queue_id = schunks[i].start_queue_id;
+		dchunks[i].num_queues = schunks[i].num_queues;
+	}
+}
+
+/**
+ * iecm_send_delete_queues_msg - send delete queues virtchnl message
+ * @vport: Virtual port private data structure
+ *
+ * Will send delete queues virtchnl message. Return 0 on success, negative on
+ * failure.
+ */
+int iecm_send_delete_queues_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_create_vport *vport_params;
+	struct virtchnl2_queue_reg_chunks *chunks;
+	struct virtchnl2_del_ena_dis_queues *eq;
+	int buf_size, err;
+	u16 num_chunks;
+
+	if (vport->adapter->config_data.req_qs_chunks) {
+		struct virtchnl2_add_queues *vc_aq =
+			(struct virtchnl2_add_queues *)
+			vport->adapter->config_data.req_qs_chunks;
+		chunks = &vc_aq->chunks;
+	} else {
+		vport_params = (struct virtchnl2_create_vport *)
+				vport->adapter->vport_params_recvd[0];
+		 chunks = &vport_params->chunks;
+	}
+
+	num_chunks = le16_to_cpu(chunks->num_chunks);
+	buf_size = sizeof(struct virtchnl2_del_ena_dis_queues) +
+			  (sizeof(struct virtchnl2_queue_chunk) *
+			  (num_chunks - 1));
+
+	eq = kzalloc(buf_size, GFP_KERNEL);
+	if (!eq)
+		return -ENOMEM;
+
+	eq->vport_id = cpu_to_le32(vport->vport_id);
+	eq->chunks.num_chunks = cpu_to_le16(num_chunks);
+
+	iecm_convert_reg_to_queue_chunks(eq->chunks.chunks, chunks-

chunks,

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +3 -0
+					 num_chunks);
+
+	err = iecm_send_mb_msg(vport->adapter,

VIRTCHNL2_OP_DEL_QUEUES,

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +6 -0
+			       buf_size, (u8 *)eq);
+	if (err)
+		goto error;
+
+	err = iecm_min_wait_for_event(adapter, IECM_VC_DEL_QUEUES,
+				      IECM_VC_DEL_QUEUES_ERR);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+error:
+	kfree(eq);
+	return err;
+}
+
+/**
+ * iecm_send_config_queues_msg - Send config queues virtchnl message
+ * @vport: Virtual port private data structure
+ *
+ * Will send config queues virtchnl message. Returns 0 on success, negative

on

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static void iecm_vport_init(struct iecm_vport

Quoted 82 lines

+ * failure.
+ */

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +76 -0
+static int iecm_send_config_queues_msg(struct iecm_vport *vport)
+{
+	int err;
+
+	err = iecm_send_config_tx_queues_msg(vport);
+	if (err)
+		return err;
+
+	return iecm_send_config_rx_queues_msg(vport);
+}
+
+/**
+ * iecm_send_add_queues_msg - Send virtchnl add queues message
+ * @vport: Virtual port private data structure
+ * @num_tx_q: number of transmit queues
+ * @num_complq: number of transmit completion queues
+ * @num_rx_q: number of receive queues
+ * @num_rx_bufq: number of receive buffer queues
+ *
+ * Returns 0 on success, negative on failure.
+ */
+int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,
+			     u16 num_complq, u16 num_rx_q, u16 num_rx_bufq)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_add_queues aq = {0};
+	struct virtchnl2_add_queues *vc_msg;
+	int size, err;
+
+	vc_msg = (struct virtchnl2_add_queues *)adapter->vc_msg;
+
+	aq.vport_id = cpu_to_le32(vport->vport_id);
+	aq.num_tx_q = cpu_to_le16(num_tx_q);
+	aq.num_tx_complq = cpu_to_le16(num_complq);
+	aq.num_rx_q = cpu_to_le16(num_rx_q);
+	aq.num_rx_bufq = cpu_to_le16(num_rx_bufq);
+
+	err = iecm_send_mb_msg(adapter,
+			       VIRTCHNL2_OP_ADD_QUEUES,
+			       sizeof(struct virtchnl2_add_queues), (u8 *)&aq);
+	if (err)
+		return err;
+
+	err = iecm_wait_for_event(adapter, IECM_VC_ADD_QUEUES,
+				  IECM_VC_ADD_QUEUES_ERR);
+	if (err)
+		return err;
+
+	kfree(adapter->config_data.req_qs_chunks);
+	adapter->config_data.req_qs_chunks = NULL;
+
+	/* compare vc_msg num queues with vport num queues */
+	if (le16_to_cpu(vc_msg->num_tx_q) != num_tx_q ||
+	    le16_to_cpu(vc_msg->num_rx_q) != num_rx_q ||
+	    le16_to_cpu(vc_msg->num_tx_complq) != num_complq ||
+	    le16_to_cpu(vc_msg->num_rx_bufq) != num_rx_bufq) {
+		err = -EINVAL;
+		goto error;
+	}
+
+	size = sizeof(struct virtchnl2_add_queues) +
+			((le16_to_cpu(vc_msg->chunks.num_chunks) - 1) *
+			sizeof(struct virtchnl2_queue_reg_chunk));
+	adapter->config_data.req_qs_chunks =
+		kzalloc(size, GFP_KERNEL);
+	if (!adapter->config_data.req_qs_chunks) {
+		err = -ENOMEM;
+		goto error;
+	}
+	memcpy(adapter->config_data.req_qs_chunks,
+	       adapter->vc_msg, size);
+error:
+	clear_bit(__IECM_VC_MSG_PENDING, adapter->flags);
+	return err;
+}
+
 /**
  * iecm_find_ctlq - Given a type and id, find ctlq info
  * @hw: hardware struct
@@ -1217,6 +2219,13 @@ static void iecm_vport_init(struct iecm_vport

*vport,

Quoted 58 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +45 -2
 	/*Initialize Tx and Rx profiles for Dynamic Interrupt Moderation */
 	memcpy(vport->rx_itr_profile, rx_itr, IECM_DIM_PROFILE_SLOTS);
 	memcpy(vport->tx_itr_profile, tx_itr, IECM_DIM_PROFILE_SLOTS);
+
+	iecm_vport_set_hsplit(vport, true);
+
+	iecm_vport_init_num_qs(vport, vport_msg);
+	iecm_vport_calc_num_q_desc(vport);
+	iecm_vport_calc_num_q_groups(vport);
+	iecm_vport_calc_num_q_vec(vport);
 }
 
 /**
@@ -1316,8 +2325,82 @@ static int
 __iecm_vport_queue_ids_init(struct iecm_vport *vport, u32 *qids,
 			    int num_qids, u32 q_type)
 {
-	/* stub */
-	return 0;
+	struct iecm_queue *q;
+	int i, j, k = 0;
+
+	switch (q_type) {
+	case VIRTCHNL2_QUEUE_TYPE_TX:
+		for (i = 0; i < vport->num_txq_grp; i++) {
+			struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+
+			for (j = 0; j < tx_qgrp->num_txq; j++) {
+				if (k < num_qids) {
+					tx_qgrp->txqs[j]->q_id = qids[k];
+					tx_qgrp->txqs[j]->q_type =
+						VIRTCHNL2_QUEUE_TYPE_TX;
+					k++;
+				} else {
+					break;
+				}
+			}
+		}
+		break;
+	case VIRTCHNL2_QUEUE_TYPE_RX:
+		for (i = 0; i < vport->num_rxq_grp; i++) {
+			struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+			int num_rxq;
+
+			if (iecm_is_queue_model_split(vport->rxq_model))
+				num_rxq = rx_qgrp->splitq.num_rxq_sets;
+			else
+				num_rxq = rx_qgrp->singleq.num_rxq;
+
+			for (j = 0; j < num_rxq && k < num_qids; j++, k++) {
+				if (iecm_is_queue_model_split(vport-
 rxq_model))
+					q = &rx_qgrp->splitq.rxq_sets[j]->rxq;
+				else
+					q = rx_qgrp->singleq.rxqs[j];
+				q->q_id = qids[k];
+				q->q_type = VIRTCHNL2_QUEUE_TYPE_RX;
+			}

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int · line 2376

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+		}
+		break;
+	case VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION:
+		for (i = 0; i < vport->num_txq_grp; i++) {
+			struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+
+			if (k < num_qids) {
+				tx_qgrp->complq->q_id = qids[k];
+				tx_qgrp->complq->q_type =
+
	VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION;
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +6 -0
+				k++;
+			} else {
+				break;
+			}
+		}
+		break;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int · line 2402

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+	case VIRTCHNL2_QUEUE_TYPE_RX_BUFFER:
+		for (i = 0; i < vport->num_rxq_grp; i++) {
+			struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++) {
+				if (k < num_qids) {
+					q = &rx_qgrp->splitq.bufq_sets[j].bufq;
+					q->q_id = qids[k];
+					q->q_type =
+
	VIRTCHNL2_QUEUE_TYPE_RX_BUFFER;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static bool iecm_is_capability_ena(struct

Quoted 16 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +12 -0
+					k++;
+				} else {
+					break;
+				}
+			}
+		}
+		break;
+	default:
+		break;
+	}
+
+	return k;
 }
 

/**

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +0 -0
@@ -1425,6 +2508,20 @@ static bool iecm_is_capability_ena(struct

iecm_adapter *adapter, bool all,

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static bool iecm_is_capability_ena(struct iecm_adapter *adapter, bool all,

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +2 -0
 		return !!(*cap_field & flag);
 }
 
+/**
+ * iecm_get_reserved_vectors - Default implementation to get reserved

vectors

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c void iecm_vc_ops_init(struct iecm_adapter

Quoted 16 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +12 -0
+ * @adapter: Private data struct
+ *
+ * Return number of vectors reserved
+ */
+static u16 iecm_get_reserved_vectors(struct iecm_adapter *adapter)
+{
+	struct virtchnl2_get_capabilities *caps;
+
+	caps = (struct virtchnl2_get_capabilities *)adapter->caps;
+	return le16_to_cpu(caps->num_allocated_vectors);
+}
+
 /**
  * iecm_vc_ops_init - Initialize virtchnl common api
  * @adapter: Driver specific private structure
@@ -1441,16 +2538,16 @@ void iecm_vc_ops_init(struct iecm_adapter

*adapter)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +0 -7
 	vc_ops->vport_queue_ids_init = iecm_vport_queue_ids_init;
 	vc_ops->get_caps = iecm_send_get_caps_msg;
 	vc_ops->is_cap_ena = iecm_is_capability_ena;
-	vc_ops->get_reserved_vecs = NULL;
-	vc_ops->config_queues = NULL;
-	vc_ops->enable_queues = NULL;
-	vc_ops->disable_queues = NULL;
-	vc_ops->add_queues = NULL;
-	vc_ops->delete_queues = NULL;
-	vc_ops->irq_map_unmap = NULL;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c void iecm_vc_ops_init(struct iecm_adapter *adapter)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +7 -3
-	vc_ops->enable_vport = NULL;
-	vc_ops->disable_vport = NULL;
-	vc_ops->destroy_vport = NULL;
+	vc_ops->get_reserved_vecs = iecm_get_reserved_vectors;
+	vc_ops->config_queues = iecm_send_config_queues_msg;
+	vc_ops->enable_queues = iecm_send_enable_queues_msg;
+	vc_ops->disable_queues = iecm_send_disable_queues_msg;
+	vc_ops->add_queues = iecm_send_add_queues_msg;
+	vc_ops->delete_queues = iecm_send_delete_queues_msg;
+	vc_ops->irq_map_unmap =

iecm_send_map_unmap_queue_vector_msg;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c void iecm_vc_ops_init(struct iecm_adapter *adapter) · line 2553

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +3 -0
+	vc_ops->enable_vport = iecm_send_enable_vport_msg;
+	vc_ops->disable_vport = iecm_send_disable_vport_msg;
+	vc_ops->destroy_vport = iecm_send_destroy_vport_msg;
 	vc_ops->get_ptype = NULL;
 	vc_ops->get_set_rss_key = NULL;
 	vc_ops->get_set_rss_lut = NULL;

Forgot to mention earlier, any reason to not declare this ops as static const and just assign a pointer then? I don't see any alternations here to e.g. fill callbacks with different functions or so.

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/include/iecm.h

drivers/net/ethernet/intel/include/iecm.h static inline bool __iecm_is_cap_ena(struct

Quoted 13 lines

index 994664dfe419..8dd6272db7d3 100644

drivers/net/ethernet/intel/include/iecm.h +2 -0
@@ -432,6 +432,8 @@ struct iecm_adapter {
 	u16 num_alloc_vport;
 	u16 next_vport;		/* Next free slot in pf->vport[] - 0-based! */
 
+	u16 max_queue_limit;	/* Max number of queues user can request */
+
 	struct delayed_work init_task; /* delayed init task */
 	struct workqueue_struct *init_wq;
 	u32 mb_wait_count;
@@ -510,6 +512,12 @@ static inline bool __iecm_is_cap_ena(struct

iecm_adapter *adapter, bool all,

drivers/net/ethernet/intel/include/iecm.h int iecm_min_wait_for_event(struct iecm_adapter

Quoted 22 lines
drivers/net/ethernet/intel/include/iecm.h +8 -0
 	return adapter->dev_ops.vc_ops.is_cap_ena(adapter, all, field, flag);
 }
 
+#define IECM_CAP_HSPLIT (\
+	VIRTCHNL2_CAP_RX_HSPLIT_AT_L2   |\
+	VIRTCHNL2_CAP_RX_HSPLIT_AT_L3   |\
+	VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V4 |\
+	VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V6)
+
 /**
  * iecm_is_reset_detected - check if we were reset at some point
  * @adapter: driver specific private structure
@@ -530,6 +538,8 @@ int iecm_init_dflt_mbx(struct iecm_adapter *adapter);
 void iecm_deinit_dflt_mbx(struct iecm_adapter *adapter);
 void iecm_vc_ops_init(struct iecm_adapter *adapter);
 int iecm_vc_core_init(struct iecm_adapter *adapter, int *vport_id);
+int iecm_get_reg_intr_vecs(struct iecm_vport *vport,
+			   struct iecm_vec_regs *reg_vals, int num_vecs);
 int iecm_wait_for_event(struct iecm_adapter *adapter,
 			enum iecm_vport_vc_state state,
 			enum iecm_vport_vc_state err_check);
@@ -537,6 +547,14 @@ int iecm_min_wait_for_event(struct iecm_adapter

*adapter,

drivers/net/ethernet/intel/include/iecm.h int iecm_recv_mb_msg(struct iecm_adapter

Quoted 15 lines
drivers/net/ethernet/intel/include/iecm.h +8 -0
 			    enum iecm_vport_vc_state state,
 			    enum iecm_vport_vc_state err_check);
 int iecm_send_get_caps_msg(struct iecm_adapter *adapter);
+int iecm_send_delete_queues_msg(struct iecm_vport *vport);
+int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,
+			     u16 num_complq, u16 num_rx_q, u16 num_rx_bufq);
+int iecm_send_config_tx_queues_msg(struct iecm_vport *vport);
+int iecm_send_config_rx_queues_msg(struct iecm_vport *vport);
+int iecm_send_enable_vport_msg(struct iecm_vport *vport);
+int iecm_send_disable_vport_msg(struct iecm_vport *vport);
+int iecm_send_destroy_vport_msg(struct iecm_vport *vport);
 int iecm_vport_params_buf_alloc(struct iecm_adapter *adapter);
 void iecm_vport_params_buf_rel(struct iecm_adapter *adapter);
 int iecm_get_vec_ids(struct iecm_adapter *adapter,
@@ -546,7 +564,11 @@ int iecm_recv_mb_msg(struct iecm_adapter

*adapter, enum virtchnl_ops op,

drivers/net/ethernet/intel/include/iecm.h int iecm_recv_mb_msg(struct iecm_adapter *adapter, enum virtchnl_ops op,

Quoted 10 lines
drivers/net/ethernet/intel/include/iecm.h +4 -0
 		     void *msg, int msg_size);
 int iecm_send_mb_msg(struct iecm_adapter *adapter, enum virtchnl_ops op,
 		     u16 msg_size, u8 *msg);
+void iecm_vport_set_hsplit(struct iecm_vport *vport, bool ena);
+int iecm_send_enable_channels_msg(struct iecm_vport *vport);
+int iecm_send_disable_channels_msg(struct iecm_vport *vport);
 int iecm_set_msg_pending(struct iecm_adapter *adapter,
 			 struct iecm_ctlq_msg *ctlq_msg,
 			 enum iecm_vport_vc_state err_enum);
+int iecm_send_map_unmap_queue_vector_msg(struct iecm_vport *vport,

bool map);

Review

Quoted 2 lines
drivers/net/ethernet/intel/include/iecm.h +0 -0
 #endif /* !_IECM_H_ */
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/include/iecm_txrx.h

Quoted 41 lines

index e1348011c991..448cae0bf6e7 100644

drivers/net/ethernet/intel/include/iecm_txrx.h +27 -0
@@ -81,6 +81,22 @@
 
 #define IECM_TX_COMPLQ_CLEAN_BUDGET	256
 
+enum iecm_queue_flags_t {
+	__IECM_Q_GEN_CHK,
+	__IECM_RFLQ_GEN_CHK,
+	__IECM_Q_FLOW_SCH_EN,
+	__IECM_Q_ETF_EN,
+	__IECM_Q_SW_MARKER,
+	__IECM_Q_VLAN_TAG_LOC_L2TAG1,
+	__IECM_Q_VLAN_TAG_LOC_L2TAG2,
+	__IECM_Q_FLAGS_NBITS,
+};
+
+struct iecm_vec_regs {
+	u32 dyn_ctl_reg;
+	u32 itrn_reg;
+};
+
 struct iecm_intr_reg {
 	u32 dyn_ctl;
 	u32 dyn_ctl_intena_m;
@@ -122,6 +138,186 @@ struct iecm_q_vector {
 	char name[IECM_INT_NAME_STR_LEN];
 };
 
+struct iecm_rx_queue_stats {
+	u64 packets;
+	u64 bytes;
+	u64 rsc_pkts;
+};
+
+struct iecm_tx_queue_stats {
+	u64 packets;
+	u64 bytes;
+	u64 lso_pkts;
+};

drivers/net/ethernet/intel/include/iecm_txrx.h struct iecm_q_vector { · line 161

Quoted 10 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +10 -0
+
+union iecm_queue_stats {
+	struct iecm_rx_queue_stats rx;
+	struct iecm_tx_queue_stats tx;
+};
+
+/* queue associated with a vport */
+struct iecm_queue {
+	struct device *dev;		/* Used for DMA mapping */
+	struct iecm_vport *vport;	/* Backreference to associated vport

*/

Quoted 47 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +47 -0
+	union {
+		struct iecm_txq_group *txq_grp;
+		struct iecm_rxq_group *rxq_grp;
+	};
+	/* bufq: Used as group id, either 0 or 1, on clean Buf Q uses this
+	 *       index to determine which group of refill queues to clean.
+	 *       Bufqs are use in splitq only.
+	 * txq: Index to map between Tx Q group and hot path Tx ptrs stored in
+	 *      vport.  Used in both single Q/split Q
+	 * rxq: Index to total rxq across groups, used for skb reporting
+	 */
+	u16 idx;
+	/* Used for both Q models single and split. In split Q model relevant
+	 * only to Tx Q and Rx Q
+	 */
+	u8 __iomem *tail;
+	/* Used in both single and split Q.  In single Q, Tx Q uses tx_buf and
+	 * Rx Q uses rx_buf.  In split Q, Tx Q uses tx_buf, Rx Q uses skb, and
+	 * Buf Q uses rx_buf.
+	 */
+	union {
+		struct iecm_tx_buf *tx_buf;
+		struct {
+			struct iecm_rx_buf *buf;
+			struct iecm_dma_mem **hdr_buf;
+		} rx_buf;
+		struct sk_buff *skb;
+	};
+	u16 q_type;
+	/* Queue id(Tx/Tx compl/Rx/Bufq) */
+	u32 q_id;
+	u16 desc_count;		/* Number of descriptors */
+
+	/* Relevant in both split & single Tx Q & Buf Q*/
+	u16 next_to_use;
+	/* In split q model only relevant for Tx Compl Q and Rx Q */
+	u16 next_to_clean;	/* used in interrupt processing */
+	/* Used only for Rx. In split Q model only relevant to Rx Q */
+	u16 next_to_alloc;
+	/* Generation bit check stored, as HW flips the bit at Queue end */
+	DECLARE_BITMAP(flags, __IECM_Q_FLAGS_NBITS);
+
+	union iecm_queue_stats q_stats;
+	struct u64_stats_sync stats_sync;
+
+	bool rx_hsplit_en;
+

drivers/net/ethernet/intel/include/iecm_txrx.h struct iecm_q_vector {

Quoted 10 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +10 -0
+	u16 rx_hbuf_size;	/* Header buffer size */
+	u16 rx_buf_size;
+	u16 rx_max_pkt_size;
+	u16 rx_buf_stride;
+	u8 rx_buffer_low_watermark;
+	u64 rxdids;
+	/* Used for both Q models single and split. In split Q model relavant
+	 * only to Tx compl Q and Rx compl Q
+	 */
+	struct iecm_q_vector *q_vector;	/* Backreference to associated vector

*/

drivers/net/ethernet/intel/include/iecm_txrx.h struct iecm_q_vector {

Quoted 6 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +6 -0
+	unsigned int size;		/* length of descriptor ring in bytes */
+	dma_addr_t dma;			/* physical address of ring */
+	void *desc_ring;		/* Descriptor ring memory */
+
+	u16 tx_buf_key;			/* 16 bit unique "identifier" (index)
+					 * to be used as the completion tag

when

drivers/net/ethernet/intel/include/iecm_txrx.h struct iecm_q_vector {

Quoted 11 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +11 -0
+					 * queue is using flow based scheduling
+					 */
+	u16 tx_max_bufs;		/* Max buffers that can be transmitted
+					 * with scatter-gather
+					 */
+	DECLARE_HASHTABLE(sched_buf_hash, 12);
+} ____cacheline_internodealigned_in_smp;
+
+/* Software queues are used in splitq mode to manage buffers between rxq
+ * producer and the bufq consumer.  These are required in order to maintain a
+ * lockless buffer management system and are strictly software only

constructs.

drivers/net/ethernet/intel/include/iecm_txrx.h struct iecm_q_vector { · line 243

Quoted 8 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +8 -0
+ */
+struct iecm_sw_queue {
+	u16 next_to_clean ____cacheline_aligned_in_smp;
+	u16 next_to_alloc ____cacheline_aligned_in_smp;
+	u16 next_to_use ____cacheline_aligned_in_smp;
+	DECLARE_BITMAP(flags, __IECM_Q_FLAGS_NBITS)
+		____cacheline_aligned_in_smp;
+	u16 *ring ____cacheline_aligned_in_smp;

This will result in this part being FIVE cachelines long for 3 * 2 + 8 + 8 = 22 bytes, i.e. 320 bytes for 22! Just making the entire structure cacheline-aligned after its declaration is enough, these ones are not even an overkill, it's an overslaughter.

Quoted 81 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +77 -1
+	u16 desc_count;
+	u16 buf_size;
+	struct device *dev;
+} ____cacheline_internodealigned_in_smp;
+
+/* Splitq only.  iecm_rxq_set associates an rxq with at an array of refillqs.
+ * Each rxq needs a refillq to return used buffers back to the respective bufq.
+ * Bufqs then clean these refillqs for buffers to give to hardware.
+ */
+struct iecm_rxq_set {
+	struct iecm_queue rxq;
+	/* refillqs assoc with bufqX mapped to this rxq */
+	struct iecm_sw_queue *refillq0;
+	struct iecm_sw_queue *refillq1;
+};
+
+/* Splitq only.  iecm_bufq_set associates a bufq to an array of refillqs.
+ * In this bufq_set, there will be one refillq for each rxq in this rxq_group.
+ * Used buffers received by rxqs will be put on refillqs which bufqs will
+ * clean to return new buffers back to hardware.
+ *
+ * Buffers needed by some number of rxqs associated in this rxq_group are
+ * managed by at most two bufqs (depending on performance configuration).
+ */
+struct iecm_bufq_set {
+	struct iecm_queue bufq;
+	/* This is always equal to num_rxq_sets in iecm_rxq_group */
+	int num_refillqs;
+	struct iecm_sw_queue *refillqs;
+};
+
+/* In singleq mode, an rxq_group is simply an array of rxqs.  In splitq, a
+ * rxq_group contains all the rxqs, bufqs and refillqs needed to
+ * manage buffers in splitq mode.
+ */
+struct iecm_rxq_group {
+	struct iecm_vport *vport; /* back pointer */
+
+	union {
+		struct {
+			int num_rxq;
+			/* store queue pointers */
+			struct iecm_queue *rxqs[IECM_LARGE_MAX_Q];
+		} singleq;
+		struct {
+			int num_rxq_sets;
+			/* store queue pointers */
+			struct iecm_rxq_set *rxq_sets[IECM_LARGE_MAX_Q];
+			struct iecm_bufq_set *bufq_sets;
+		} splitq;
+	};
+};
+
+/* Between singleq and splitq, a txq_group is largely the same except for the
+ * complq.  In splitq a single complq is responsible for handling completions
+ * for some number of txqs associated in this txq_group.
+ */
+struct iecm_txq_group {
+	struct iecm_vport *vport; /* back pointer */
+
+	int num_txq;
+	/* store queue pointers */
+	struct iecm_queue *txqs[IECM_LARGE_MAX_Q];
+
+	/* splitq only */
+	struct iecm_queue *complq;
+};
+
+struct iecm_adapter;
+
+void iecm_vport_init_num_qs(struct iecm_vport *vport,
+			    struct virtchnl2_create_vport *vport_msg);
+void iecm_vport_calc_num_q_desc(struct iecm_vport *vport);
+void iecm_vport_calc_total_qs(struct iecm_adapter *adapter,
+			      struct virtchnl2_create_vport *vport_msg);
+void iecm_vport_calc_num_q_groups(struct iecm_vport *vport);
+void iecm_vport_calc_num_q_vec(struct iecm_vport *vport);
 irqreturn_t
 iecm_vport_intr_clean_queues(int __always_unused irq, void *data);
 #endif /* !_IECM_TXRX_H_ */
--
Quoted 1 line

2.33.0

Thanks,
Al

#29 lore raw

PATCH 6/19 iecm: add virtchnl messages for queues

Quoted 31 lines · Alan
Quoted 31 lines

-----Original Message-----
From: Lobakin, Alexandr <[email protected]>
Sent: Friday, January 28, 2022 5:03 AM
To: Brady, Alan <[email protected]>
Cc: Lobakin, Alexandr <[email protected]>; intel-wired- lan at lists.osuosl.org; Linga, Pavan Kumar <[email protected]>; Chittim, Madhu <[email protected]>; Burra, Phani R <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net-next 06/19] iecm: add virtchnl messages for queues

From: Alan Brady <[email protected]>
Date: Thu, 27 Jan 2022 16:09:56 -0800

Quoted 17 lines

This continues adding virtchnl messages. This largely relates to adding messages needed to negotiate and setup traffic queues.

---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    |   14 +
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   |  161 +++
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   | 1127 ++++++++++++++++-
 drivers/net/ethernet/intel/include/iecm.h     |   22 +
 .../net/ethernet/intel/include/iecm_txrx.h    |  196 +++
 5 files changed, 1505 insertions(+), 15 deletions(-)
Quoted 7 lines
Quoted 7 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/iecm/iecm_lib.c

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 3 lines

index e2e523f0700e..4e9cc7f2d138 100644

drivers/net/ethernet/intel/iecm/iecm_lib.c +0 -0

--- 8< ---

I think we could trim a bit more in these responses, so they would be easier to follow for people :)

Quoted 31 lines
Quoted 17 lines
Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +3 -0
+void iecm_vport_calc_num_q_desc(struct iecm_vport *vport)
+{
+	int num_req_txq_desc = vport->adapter-

config_data.num_req_txq_desc;

drivers/net/ethernet/intel/iecm/iecm_lib.c +1 -0
+	int num_req_rxq_desc = vport->adapter-

config_data.num_req_rxq_desc;

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +9 -0
+	int num_bufqs = vport->num_bufqs_per_qgrp;
+	int i = 0;
+
+	vport->complq_desc_count = 0;
+	if (num_req_txq_desc) {
+		vport->txq_desc_count = num_req_txq_desc;
+		if (iecm_is_queue_model_split(vport->txq_model)) {
+			vport->complq_desc_count = num_req_txq_desc;
+			if (vport->complq_desc_count <

IECM_MIN_TXQ_COMPLQ_DESC)

Quoted 13 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+				vport->complq_desc_count =
+					IECM_MIN_TXQ_COMPLQ_DESC;
+		}
+	} else {
+		vport->txq_desc_count =
+			IECM_DFLT_TX_Q_DESC_COUNT;
+		if (iecm_is_queue_model_split(vport->txq_model)) {
+			vport->complq_desc_count =
+				IECM_DFLT_TX_COMPLQ_DESC_COUNT;
+		}

Braces are redundant here since the path is a one-liner.

Quoted 5 lines

Correct me if I'm wrong but believe the guidance here is if it goes beyond one line with line wrapping, it is optional whether or not to use braces, even if the statement is 'one line'. We have generally preferred to keep braces in multiline statements. However you do have a point that it is not consistent in this function. Will fix.

That's the first time I hear about something like that. Interesting that checkpatch won't scream at you for this, but I'm with Alex in here.

Quoted 25 lines
Quoted 25 lines
Quoted 13 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +11 -0
+	}
+
+	if (num_req_rxq_desc)
+		vport->rxq_desc_count = num_req_rxq_desc;
+	else
+		vport->rxq_desc_count = IECM_DFLT_RX_Q_DESC_COUNT;
+
+	for (i = 0; i < num_bufqs; i++) {
+		if (!vport->bufq_desc_count[i])
+			vport->bufq_desc_count[i] =
+				IECM_RX_BUFQ_DESC_COUNT(vport-

rxq_desc_count,

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_lib.c +1 -0
+							num_bufqs);
		if (vport->bufq_desc_count[i])
			continue;

		vport-> ...

-1 indent level with that.

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +3 -0
+	}
+}
+

(...)

Quoted 59 lines
Quoted 59 lines
Quoted 2 lines

+/**
+ * iecm_send_config_rx_queues_msg - Send virtchnl config rx queues

message

Quoted 28 lines

+ * @vport: virtual port data structure
+ *
+ * Send config rx queues virtchnl message. Returns 0 on success, negative on
+ * failure.
+ */

drivers/net/ethernet/intel/iecm/iecm_lib.c +23 -0
+int iecm_send_config_rx_queues_msg(struct iecm_vport *vport)
+{
+	struct virtchnl2_config_rx_queues *crq = NULL;
+	int config_data_size, chunk_size, buf_size = 0;
+	int totqs, num_msgs, num_chunks;
+	struct virtchnl2_rxq_info *qi;
+	int err = 0, i, k = 0;
+	bool alloc = false;
+
+	totqs = vport->num_rxq + vport->num_bufq;
+	qi = kcalloc(totqs, sizeof(struct virtchnl2_rxq_info), GFP_KERNEL);
+	if (!qi)
+		return -ENOMEM;
+
+	/* Populate the queue info buffer with all queue context info */
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+		int num_rxq;
+		int j;
+
+		if (iecm_is_queue_model_split(vport->rxq_model)) {
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++, k++) {
+				struct iecm_queue *bufq =

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+					&rx_qgrp->splitq.bufq_sets[j].bufq;
+
+				qi[k].queue_id =
+					cpu_to_le32(bufq->q_id);
+				qi[k].model =
+					cpu_to_le16(vport->rxq_model);
+				qi[k].type =
+					cpu_to_le32(bufq->q_type);
+				qi[k].desc_ids =
+
	cpu_to_le64(VIRTCHNL2_RXDID_1_FLEX_SPLITQ_M);

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 13 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+				qi[k].ring_len =
+					cpu_to_le16(bufq->desc_count);
+				qi[k].dma_ring_addr =
+					cpu_to_le64(bufq->dma);
+				qi[k].data_buffer_size =
+					cpu_to_le32(bufq->rx_buf_size);
+				qi[k].buffer_notif_stride =
+					bufq->rx_buf_stride;
+				qi[k].rx_buffer_low_watermark =
+					cpu_to_le16(bufq-

rx_buffer_low_watermark);

drivers/net/ethernet/intel/iecm/iecm_lib.c +2 -0
+			}
+		}
		if (iecm_is_queue_model_split(vport->rxq_model))
			goto here;
Quoted 7 lines
Quoted 1 line

-1 indent level for the for-loop.

I'm afraid I'm not following, please elaborate. Where are we goto'ing? The for loop below needs to be executed for both and if we just tack the above for loop at the bottom of the function and goto in and out of it to save an indent does not sound great and makes the code harder to follow IMO.

Below or above? I think Alex meant to skip the for loop execution for nonsplitq model. And by reducing indent you probably could have all of the assignments stored on the single line.

Quoted 6 lines
Quoted 3 lines

Braces for 'if' are not needed since the for-loop has their own.

They're not required but we have generally preferred to keep braces on statements extending across more than one line.

Here I'm actually okay with keeping the braces as in future maybe you might want to introduce something for the splitq case outside of the current loop so it might get tricky when you forgot to supply the outer 'if' with braces. Just my 0.02$.

Quoted 39 lines
Quoted 28 lines
Quoted 23 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +13 -0
+
+		if (iecm_is_queue_model_split(vport->rxq_model))
+			num_rxq = rx_qgrp->splitq.num_rxq_sets;
+		else
+			num_rxq = rx_qgrp->singleq.num_rxq;
+
+		for (j = 0; j < num_rxq; j++, k++) {
+			struct iecm_queue *rxq;
+
+			if (iecm_is_queue_model_split(vport->rxq_model)) {
+				rxq = &rx_qgrp->splitq.rxq_sets[j]->rxq;
+				qi[k].rx_bufq1_id =
+				  cpu_to_le16(rxq->rxq_grp-

splitq.bufq_sets[0].bufq.q_id);

drivers/net/ethernet/intel/iecm/iecm_lib.c +2 -0
+				qi[k].rx_bufq2_id =
+				  cpu_to_le16(rxq->rxq_grp-

splitq.bufq_sets[1].bufq.q_id);

drivers/net/ethernet/intel/iecm/iecm_lib.c +4 -0
+				qi[k].hdr_buffer_size =
+					cpu_to_le16(rxq->rx_hbuf_size);
+				qi[k].rx_buffer_low_watermark =
+					cpu_to_le16(rxq-

rx_buffer_low_watermark);

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +4 -0
+
+				if (rxq->rx_hsplit_en) {
+					qi[k].qflags =
+
	cpu_to_le16(VIRTCHNL2_RXQ_HDR_SPLIT);
Quoted 10 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +2 -0
+					qi[k].hdr_buffer_size =
+						cpu_to_le16(rxq-

rx_hbuf_size);

drivers/net/ethernet/intel/iecm/iecm_lib.c +4 -0
+				}
+			} else {
+				rxq = rx_qgrp->singleq.rxqs[j];
+			}

Same here, but with rxq = ... + goto.

Quoted 1 line

Please elaborate.

		if (!iecm_is_queue_model_split(vport->rxq_model)) {
			rxq = rx_qgrp->singleq.rxqs[j];
			goto skip_splitq_init;
		}
		rxq = &rx_qgrp->splitq.rxq_sets[j]->rxq;
		qi[k].rx_bufq1_id = cpu_to_le16(rxq->rxq_grp->splitq.bufq_sets[0].bufq.q_id);
		qi[k].rx_bufq2_id = cpu_to_le16(rxq->rxq_grp->splitq.bufq_sets[1].bufq.q_id);
		qi[k].hdr_buffer_size = cpu_to_le16(rxq->rx_hbuf_size);
		qi[k].rx_buffer_low_watermark = cpu_to_le16(rxq->rx_buffer_low_watermark);

		if (rxq->rx_hsplit_en) {
			qi[k].qflags = cpu_to_le16(VIRTCHNL2_RXQ_HDR_SPLIT);
			qi[k].hdr_buffer_size = cpu_to_le16(rxq->rx_hbuf_size);
		}
skip_splitq_init:
		(...)

More readable to me.
What's 'k' though? Maybe let's think of better variable naming in here?

Quoted 90 lines
Quoted 90 lines
Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +7 -0
+
+			qi[k].queue_id =
+				cpu_to_le32(rxq->q_id);
+			qi[k].model =
+				cpu_to_le16(vport->rxq_model);
+			qi[k].type =
+				cpu_to_le32(rxq->q_type);

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+			qi[k].ring_len =
+				cpu_to_le16(rxq->desc_count);
+			qi[k].dma_ring_addr =
+				cpu_to_le64(rxq->dma);
+			qi[k].max_pkt_size =
+				cpu_to_le32(rxq->rx_max_pkt_size);
+			qi[k].data_buffer_size =
+				cpu_to_le32(rxq->rx_buf_size);
+			qi[k].qflags |=
+
	cpu_to_le16(VIRTCHNL2_RX_DESC_SIZE_32BYTE);
Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +8 -0
+			qi[k].desc_ids =
+				cpu_to_le64(rxq->rxdids);
+		}
+	}
+
+	/* Make sure accounting agrees */
+	if (k != totqs) {
+		err = -EINVAL;

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+		goto error;
+	}
+
+	/* Chunk up the queue contexts into multiple messages to avoid
+	 * sending a control queue message buffer that is too large
+	 */
+	config_data_size = sizeof(struct virtchnl2_config_rx_queues);
+	chunk_size = sizeof(struct virtchnl2_rxq_info);
+
+	num_chunks = IECM_NUM_CHUNKS_PER_MSG(config_data_size,

chunk_size) + 1;

Quoted 22 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +22 -0
+	if (totqs < num_chunks)
+		num_chunks = totqs;
+
+	num_msgs = totqs / num_chunks;
+	if (totqs % num_chunks)
+		num_msgs++;
+
+	for (i = 0, k = 0; i < num_msgs; i++) {
+		if (!crq || alloc) {
+			buf_size = (chunk_size * (num_chunks - 1)) +
+					config_data_size;
+			kfree(crq);
+			crq = kzalloc(buf_size, GFP_KERNEL);
+			if (!crq) {
+				err = -ENOMEM;
+				goto error;
+			}
+		} else {
+			memset(crq, 0, buf_size);
+		}
+
+		crq->vport_id = cpu_to_le32(vport->vport_id);

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+		crq->num_qinfo = cpu_to_le16(num_chunks);
+		memcpy(crq->qinfo, &qi[k], chunk_size * num_chunks);
+
+		err = iecm_send_mb_msg(vport->adapter,
+				       VIRTCHNL2_OP_CONFIG_RX_QUEUES,
+				       buf_size, (u8 *)crq);
+		if (err)
+			goto mbx_error;
+
+		err = iecm_wait_for_event(vport->adapter,

IECM_VC_CONFIG_RXQ,

Quoted 19 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +19 -0
+					  IECM_VC_CONFIG_RXQ_ERR);
+		if (err)
+			goto mbx_error;
+
+		k += num_chunks;
+		totqs -= num_chunks;
+		if (totqs < num_chunks) {
+			num_chunks = totqs;
+			alloc = true;
+		}
+	}
+
+mbx_error:
+	kfree(crq);
+error:
+	kfree(qi);
+	return err;
+}
+

(...)

Quoted 82 lines
Quoted 82 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +4 -0
+/* queue associated with a vport */
+struct iecm_queue {
+	struct device *dev;		/* Used for DMA mapping */
+	struct iecm_vport *vport;	/* Backreference to associated vport

*/

Quoted 47 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +47 -0
+	union {
+		struct iecm_txq_group *txq_grp;
+		struct iecm_rxq_group *rxq_grp;
+	};
+	/* bufq: Used as group id, either 0 or 1, on clean Buf Q uses this
+	 *       index to determine which group of refill queues to clean.
+	 *       Bufqs are use in splitq only.
+	 * txq: Index to map between Tx Q group and hot path Tx ptrs stored in
+	 *      vport.  Used in both single Q/split Q
+	 * rxq: Index to total rxq across groups, used for skb reporting
+	 */
+	u16 idx;
+	/* Used for both Q models single and split. In split Q model relevant
+	 * only to Tx Q and Rx Q
+	 */
+	u8 __iomem *tail;
+	/* Used in both single and split Q.  In single Q, Tx Q uses tx_buf and
+	 * Rx Q uses rx_buf.  In split Q, Tx Q uses tx_buf, Rx Q uses skb, and
+	 * Buf Q uses rx_buf.
+	 */
+	union {
+		struct iecm_tx_buf *tx_buf;
+		struct {
+			struct iecm_rx_buf *buf;
+			struct iecm_dma_mem **hdr_buf;
+		} rx_buf;
+		struct sk_buff *skb;
+	};
+	u16 q_type;
+	/* Queue id(Tx/Tx compl/Rx/Bufq) */
+	u32 q_id;
+	u16 desc_count;		/* Number of descriptors */
+
+	/* Relevant in both split & single Tx Q & Buf Q*/
+	u16 next_to_use;
+	/* In split q model only relevant for Tx Compl Q and Rx Q */
+	u16 next_to_clean;	/* used in interrupt processing */
+	/* Used only for Rx. In split Q model only relevant to Rx Q */
+	u16 next_to_alloc;
+	/* Generation bit check stored, as HW flips the bit at Queue end */
+	DECLARE_BITMAP(flags, __IECM_Q_FLAGS_NBITS);
+
+	union iecm_queue_stats q_stats;
+	struct u64_stats_sync stats_sync;
+
+	bool rx_hsplit_en;
+

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+	u16 rx_hbuf_size;	/* Header buffer size */
+	u16 rx_buf_size;
+	u16 rx_max_pkt_size;
+	u16 rx_buf_stride;
+	u8 rx_buffer_low_watermark;
+	u64 rxdids;
+	/* Used for both Q models single and split. In split Q model relavant
+	 * only to Tx compl Q and Rx compl Q
+	 */
+	struct iecm_q_vector *q_vector;	/* Backreference to associated vector

*/

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +6 -0
+	unsigned int size;		/* length of descriptor ring in bytes */
+	dma_addr_t dma;			/* physical address of ring */
+	void *desc_ring;		/* Descriptor ring memory */
+
+	u16 tx_buf_key;			/* 16 bit unique "identifier" (index)
+					 * to be used as the completion tag

when

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +11 -0
+					 * queue is using flow based scheduling
+					 */
+	u16 tx_max_bufs;		/* Max buffers that can be transmitted
+					 * with scatter-gather
+					 */
+	DECLARE_HASHTABLE(sched_buf_hash, 12);
+} ____cacheline_internodealigned_in_smp;
+
+/* Software queues are used in splitq mode to manage buffers between rxq
+ * producer and the bufq consumer.  These are required in order to maintain a
+ * lockless buffer management system and are strictly software only

constructs.

Quoted 14 lines
Quoted 6 lines
Quoted 6 lines

+ */

drivers/net/ethernet/intel/iecm/iecm_lib.c +5 -0
+struct iecm_sw_queue {
+	u16 next_to_clean ____cacheline_aligned_in_smp;
+	u16 next_to_alloc ____cacheline_aligned_in_smp;
+	u16 next_to_use ____cacheline_aligned_in_smp;
+	DECLARE_BITMAP(flags, __IECM_Q_FLAGS_NBITS)
Quoted 8 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +2 -0
+		____cacheline_aligned_in_smp;
+	u16 *ring ____cacheline_aligned_in_smp;

This will result in this part being FIVE cachelines long for 3 * 2 + 8 + 8 = 22 bytes, i.e. 320 bytes for 22! Just making the entire structure cacheline-aligned after its declaration is enough, these ones are not even an overkill, it's an overslaughter.

Good catch!

Quoted 90 lines
Quoted 78 lines
Quoted 78 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +77 -0
+	u16 desc_count;
+	u16 buf_size;
+	struct device *dev;
+} ____cacheline_internodealigned_in_smp;
+
+/* Splitq only.  iecm_rxq_set associates an rxq with at an array of refillqs.
+ * Each rxq needs a refillq to return used buffers back to the respective bufq.
+ * Bufqs then clean these refillqs for buffers to give to hardware.
+ */
+struct iecm_rxq_set {
+	struct iecm_queue rxq;
+	/* refillqs assoc with bufqX mapped to this rxq */
+	struct iecm_sw_queue *refillq0;
+	struct iecm_sw_queue *refillq1;
+};
+
+/* Splitq only.  iecm_bufq_set associates a bufq to an array of refillqs.
+ * In this bufq_set, there will be one refillq for each rxq in this rxq_group.
+ * Used buffers received by rxqs will be put on refillqs which bufqs will
+ * clean to return new buffers back to hardware.
+ *
+ * Buffers needed by some number of rxqs associated in this rxq_group are
+ * managed by at most two bufqs (depending on performance configuration).
+ */
+struct iecm_bufq_set {
+	struct iecm_queue bufq;
+	/* This is always equal to num_rxq_sets in iecm_rxq_group */
+	int num_refillqs;
+	struct iecm_sw_queue *refillqs;
+};
+
+/* In singleq mode, an rxq_group is simply an array of rxqs.  In splitq, a
+ * rxq_group contains all the rxqs, bufqs and refillqs needed to
+ * manage buffers in splitq mode.
+ */
+struct iecm_rxq_group {
+	struct iecm_vport *vport; /* back pointer */
+
+	union {
+		struct {
+			int num_rxq;
+			/* store queue pointers */
+			struct iecm_queue *rxqs[IECM_LARGE_MAX_Q];
+		} singleq;
+		struct {
+			int num_rxq_sets;
+			/* store queue pointers */
+			struct iecm_rxq_set *rxq_sets[IECM_LARGE_MAX_Q];
+			struct iecm_bufq_set *bufq_sets;
+		} splitq;
+	};
+};
+
+/* Between singleq and splitq, a txq_group is largely the same except for the
+ * complq.  In splitq a single complq is responsible for handling completions
+ * for some number of txqs associated in this txq_group.
+ */
+struct iecm_txq_group {
+	struct iecm_vport *vport; /* back pointer */
+
+	int num_txq;
+	/* store queue pointers */
+	struct iecm_queue *txqs[IECM_LARGE_MAX_Q];
+
+	/* splitq only */
+	struct iecm_queue *complq;
+};
+
+struct iecm_adapter;
+
+void iecm_vport_init_num_qs(struct iecm_vport *vport,
+			    struct virtchnl2_create_vport *vport_msg);
+void iecm_vport_calc_num_q_desc(struct iecm_vport *vport);
+void iecm_vport_calc_total_qs(struct iecm_adapter *adapter,
+			      struct virtchnl2_create_vport *vport_msg);
+void iecm_vport_calc_num_q_groups(struct iecm_vport *vport);
+void iecm_vport_calc_num_q_vec(struct iecm_vport *vport);
Quoted 8 lines
Quoted 5 lines

irqreturn_t
iecm_vport_intr_clean_queues(int __always_unused irq, void *data); #endif /* !_IECM_TXRX_H_ */
--
2.33.0

Thanks,
Al

_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan at osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan

#30 lore raw

PATCH 6/19 iecm: add virtchnl messages for queues

In reply to Brady

From: Alan Brady <[email protected]>
Date: Wed, 2 Feb 2022 23:48:48 +0100

Quoted 69 lines
Quoted 55 lines

-----Original Message-----
From: Lobakin, Alexandr <[email protected]>
Sent: Friday, January 28, 2022 5:03 AM
To: Brady, Alan <[email protected]>
Cc: Lobakin, Alexandr <[email protected]>; intel-wired- lan at lists.osuosl.org; Linga, Pavan Kumar <[email protected]>; Chittim, Madhu <[email protected]>; Burra, Phani R <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net-next 06/19] iecm: add virtchnl messages for queues

From: Alan Brady <[email protected]>
Date: Thu, 27 Jan 2022 16:09:56 -0800

Quoted 17 lines

This continues adding virtchnl messages. This largely relates to adding messages needed to negotiate and setup traffic queues.

---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    |   14 +
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   |  161 +++
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   | 1127 ++++++++++++++++-
 drivers/net/ethernet/intel/include/iecm.h     |   22 +
 .../net/ethernet/intel/include/iecm_txrx.h    |  196 +++
 5 files changed, 1505 insertions(+), 15 deletions(-)

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/iecm/iecm_lib.c

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 3 lines

index e2e523f0700e..4e9cc7f2d138 100644

drivers/net/ethernet/intel/iecm/iecm_lib.c +0 -0

--- 8< ---

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +3 -0
+void iecm_vport_calc_num_q_desc(struct iecm_vport *vport)
+{
+	int num_req_txq_desc = vport->adapter-

config_data.num_req_txq_desc;

drivers/net/ethernet/intel/iecm/iecm_lib.c +1 -0
+	int num_req_rxq_desc = vport->adapter-

config_data.num_req_rxq_desc;

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +9 -0
+	int num_bufqs = vport->num_bufqs_per_qgrp;
+	int i = 0;
+
+	vport->complq_desc_count = 0;
+	if (num_req_txq_desc) {
+		vport->txq_desc_count = num_req_txq_desc;
+		if (iecm_is_queue_model_split(vport->txq_model)) {
+			vport->complq_desc_count = num_req_txq_desc;
+			if (vport->complq_desc_count <

IECM_MIN_TXQ_COMPLQ_DESC)

Quoted 13 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+				vport->complq_desc_count =
+					IECM_MIN_TXQ_COMPLQ_DESC;
+		}
+	} else {
+		vport->txq_desc_count =
+			IECM_DFLT_TX_Q_DESC_COUNT;
+		if (iecm_is_queue_model_split(vport->txq_model)) {
+			vport->complq_desc_count =
+				IECM_DFLT_TX_COMPLQ_DESC_COUNT;
+		}

Braces are redundant here since the path is a one-liner.

Quoted 1 line

Correct me if I'm wrong but believe the guidance here is if it goes beyond one line with line wrapping, it is optional whether or not to use braces, even if the statement is 'one line'. We have generally preferred to keep braces in multiline statements. However you do have a point that it is not consistent in this function. Will fix.

It's not really optional whether to use or not braces. They should be used in a minimum possible amount, i.e.:

* when we need to perform several statements separated by ';' under the same condition;

	if (c1) {
		f2(v1);
		f3(v2);
	}

* when we do only one statement with one ';' at the end, but we have another branch that must be braced due to bullet #1.

	if (c1) {
		f2(v1);
	} else {
		f3(v2);
		f4(v5);
	}

Line breaks are not included. Even comments are not included, thus

	if (c1)
		/* Do f2, because r3 */
		f2(v1);
	else
		extremely_long_v2 =
			f3(v9);

is fully correct and should be preferred.

Quoted 557 lines
Quoted 557 lines
Quoted 13 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +11 -0
+	}
+
+	if (num_req_rxq_desc)
+		vport->rxq_desc_count = num_req_rxq_desc;
+	else
+		vport->rxq_desc_count = IECM_DFLT_RX_Q_DESC_COUNT;
+
+	for (i = 0; i < num_bufqs; i++) {
+		if (!vport->bufq_desc_count[i])
+			vport->bufq_desc_count[i] =
+				IECM_RX_BUFQ_DESC_COUNT(vport-

rxq_desc_count,

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_lib.c +1 -0
+							num_bufqs);
		if (vport->bufq_desc_count[i])
			continue;

		vport-> ...

-1 indent level with that.

Quoted 24 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +24 -0
+	}
+}
+EXPORT_SYMBOL(iecm_vport_calc_num_q_desc);
+
+/**
+ * iecm_vport_calc_total_qs - Calculate total number of queues
+ * @adapter: private data struct
+ * @vport_msg: message to fill with data
+ */
+void iecm_vport_calc_total_qs(struct iecm_adapter *adapter,
+			      struct virtchnl2_create_vport *vport_msg)
+{
+	unsigned int num_req_tx_qs = adapter->config_data.num_req_tx_qs;
+	unsigned int num_req_rx_qs = adapter->config_data.num_req_rx_qs;
+	int dflt_splitq_txq_grps, dflt_singleq_txqs;
+	int dflt_splitq_rxq_grps, dflt_singleq_rxqs;
+	int num_txq_grps, num_rxq_grps;
+	int num_cpus;
+	u16 max_q;
+
+	/* Restrict num of queues to cpus online as a default configuration to
+	 * give best performance. User can always override to a max number
+	 * of queues via ethtool.
+	 */

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+	num_cpus = num_online_cpus();
+	max_q = adapter->max_queue_limit;
+
+	dflt_splitq_txq_grps = min_t(int, max_q, num_cpus);
+	dflt_singleq_txqs = min_t(int, max_q, num_cpus);
+	dflt_splitq_rxq_grps = min_t(int, max_q, num_cpus);
+	dflt_singleq_rxqs = min_t(int, max_q, num_cpus);
+
+	if (iecm_is_queue_model_split(le16_to_cpu(vport_msg->txq_model))) {
+		num_txq_grps = num_req_tx_qs ? num_req_tx_qs :

dflt_splitq_txq_grps;

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +2 -0
+		vport_msg->num_tx_complq = cpu_to_le16(num_txq_grps *
+

IECM_COMPLQ_PER_GROUP);

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +2 -0
+		vport_msg->num_tx_q = cpu_to_le16(num_txq_grps *
+

IECM_DFLT_SPLITQ_TXQ_PER_GROUP);

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+	} else {
+		num_txq_grps = IECM_DFLT_SINGLEQ_TX_Q_GROUPS;
+		vport_msg->num_tx_q =
+				cpu_to_le16(num_txq_grps *
+					    (num_req_tx_qs ? num_req_tx_qs :
+					    dflt_singleq_txqs));
+		vport_msg->num_tx_complq = 0;
+	}
+	if (iecm_is_queue_model_split(le16_to_cpu(vport_msg->rxq_model))) {
+		num_rxq_grps = num_req_rx_qs ? num_req_rx_qs :

dflt_splitq_rxq_grps;

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +3 -0
+		vport_msg->num_rx_bufq =
+					cpu_to_le16(num_rxq_grps *
+

IECM_MAX_BUFQS_PER_RXQ_GRP);

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +3 -0
+
+		vport_msg->num_rx_q = cpu_to_le16(num_rxq_grps *
+

IECM_DFLT_SPLITQ_RXQ_PER_GROUP);

Quoted 20 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +20 -0
+	} else {
+		num_rxq_grps = IECM_DFLT_SINGLEQ_RX_Q_GROUPS;
+		vport_msg->num_rx_bufq = 0;
+		vport_msg->num_rx_q =
+				cpu_to_le16(num_rxq_grps *
+					    (num_req_rx_qs ? num_req_rx_qs :
+					    dflt_singleq_rxqs));
+	}
+}
+
+/**
+ * iecm_vport_calc_num_q_groups - Calculate number of queue groups
+ * @vport: vport to calculate q groups for
+ */
+void iecm_vport_calc_num_q_groups(struct iecm_vport *vport)
+{
+	if (iecm_is_queue_model_split(vport->txq_model))
+		vport->num_txq_grp = vport->num_txq;
+	else
+		vport->num_txq_grp = IECM_DFLT_SINGLEQ_TX_Q_GROUPS;

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+
+	if (iecm_is_queue_model_split(vport->rxq_model))
+		vport->num_rxq_grp = vport->num_rxq;
+	else
+		vport->num_rxq_grp = IECM_DFLT_SINGLEQ_RX_Q_GROUPS;
+}
+EXPORT_SYMBOL(iecm_vport_calc_num_q_groups);
+
+/**
+ * iecm_vport_calc_num_q_vec - Calculate total number of vectors required

for

Review

Quoted 13 lines

+ * this vport
+ * @vport: virtual port
+ *
+ */

drivers/net/ethernet/intel/iecm/iecm_lib.c +8 -0
+void iecm_vport_calc_num_q_vec(struct iecm_vport *vport)
+{
+	if (iecm_is_queue_model_split(vport->txq_model))
+		vport->num_q_vectors = vport->num_txq_grp;
+	else
+		vport->num_q_vectors = vport->num_txq;
+}
+EXPORT_SYMBOL(iecm_vport_calc_num_q_vec);
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/iecm/iecm_virtchnl.c

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_recv_get_caps_msg(struct

Quoted 4 lines

index aae06064d706..d8152e657e24 100644

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +0 -0
@@ -859,6 +859,48 @@ static int iecm_recv_get_caps_msg(struct

iecm_adapter *adapter)

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_recv_get_caps_msg(struct

Quoted 49 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +42 -0
 				sizeof(struct virtchnl2_get_capabilities));
 }
 
+/**
+ * iecm_get_reg_intr_vecs - Get vector queue register offset
+ * @vport: virtual port structure
+ * @reg_vals: Register offsets to store in
+ * @num_vecs: Number of vector registers
+ *
+ * Returns number of regsiters that got populated
+ */
+int iecm_get_reg_intr_vecs(struct iecm_vport *vport,
+			   struct iecm_vec_regs *reg_vals, int num_vecs)
+{
+	struct virtchnl2_vector_chunks *chunks;
+	struct iecm_vec_regs reg_val;
+	u16 num_vchunks, num_vec;
+	int num_regs = 0, i, j;
+
+	chunks = &vport->adapter->req_vec_chunks->vchunks;
+	num_vchunks = le16_to_cpu(chunks->num_vchunks);
+
+	for (j = 0; j < num_vchunks; j++) {
+		struct virtchnl2_vector_chunk *chunk = &chunks->vchunks[j];
+
+		num_vec = le16_to_cpu(chunk->num_vectors);
+		reg_val.dyn_ctl_reg = le32_to_cpu(chunk->dynctl_reg_start);
+		reg_val.itrn_reg = le32_to_cpu(chunk->itrn_reg_start);
+		for (i = 0; i < num_vec; i++) {
+			if (num_regs == num_vecs)
+				break;
+			reg_vals[i].dyn_ctl_reg = reg_val.dyn_ctl_reg;
+			reg_vals[i].itrn_reg = reg_val.itrn_reg;
+			reg_val.dyn_ctl_reg +=
+				le32_to_cpu(chunk->dynctl_reg_spacing);
+			reg_val.itrn_reg +=
+				le32_to_cpu(chunk->itrn_reg_spacing);
+			num_regs++;
+		}
+	}
+
+	return num_regs;
+}
+EXPORT_SYMBOL(iecm_get_reg_intr_vecs);
+
 /**
  * iecm_send_create_vport_msg - Send virtchnl create vport message
  * @adapter: Driver specific private structure
@@ -869,8 +911,36 @@ static int iecm_recv_get_caps_msg(struct

iecm_adapter *adapter)

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_recv_get_caps_msg(struct iecm_adapter *adapter)

Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +6 -2
  */
 static int iecm_send_create_vport_msg(struct iecm_adapter *adapter)
 {
-	/* stub */
-	return 0;
+	struct virtchnl2_create_vport *vport_msg;
+	int buf_size;
+
+	buf_size = sizeof(struct virtchnl2_create_vport);
+	if (!adapter->vport_params_reqd[0]) {
+		adapter->vport_params_reqd[0] = kzalloc(buf_size,

GFP_KERNEL);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_recv_get_caps_msg(struct iecm_adapter *adapter)

Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +7 -0
+		if (!adapter->vport_params_reqd[0])
+			return -ENOMEM;
+	}
+
+	vport_msg = (struct virtchnl2_create_vport *)
+			adapter->vport_params_reqd[0];
+	vport_msg->vport_type =

cpu_to_le16(VIRTCHNL2_VPORT_TYPE_DEFAULT);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_recv_get_caps_msg(struct iecm_adapter *adapter)

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +3 -0
+
+	if (test_bit(__IECM_REQ_TX_SPLITQ, adapter->flags))
+		vport_msg->txq_model =

cpu_to_le16(VIRTCHNL2_QUEUE_MODEL_SPLIT);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_recv_get_caps_msg(struct · line 931

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +2 -0
+	else
+		vport_msg->txq_model =

cpu_to_le16(VIRTCHNL2_QUEUE_MODEL_SINGLE);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_recv_get_caps_msg(struct iecm_adapter *adapter)

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +3 -0
+
+	if (test_bit(__IECM_REQ_RX_SPLITQ, adapter->flags))
+		vport_msg->rxq_model =

cpu_to_le16(VIRTCHNL2_QUEUE_MODEL_SPLIT);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_recv_get_caps_msg(struct · line 936

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +2 -0
+	else
+		vport_msg->rxq_model =

cpu_to_le16(VIRTCHNL2_QUEUE_MODEL_SINGLE);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_recv_get_caps_msg(struct iecm_adapter *adapter)

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +6 -0
+
+	adapter->dev_ops.vc_ops.init_max_queues(adapter);
+
+	iecm_vport_calc_total_qs(adapter, vport_msg);
+
+	return iecm_send_mb_msg(adapter, VIRTCHNL2_OP_CREATE_VPORT,

buf_size,

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_send_create_vport_msg(struct

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +1 -0
+				(u8 *)vport_msg);
 }
 
 /**
@@ -884,7 +954,25 @@ static int iecm_send_create_vport_msg(struct

iecm_adapter *adapter)

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_send_create_vport_msg(struct iecm_adapter *adapter)

Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +5 -1
 static int iecm_recv_create_vport_msg(struct iecm_adapter *adapter,
 				      int *vport_id)
 {
-	/* stub */
+	struct virtchnl2_create_vport *vport_msg;
+	int err;
+
+	if (!adapter->vport_params_recvd[0]) {
+		adapter->vport_params_recvd[0] =

kzalloc(IECM_DFLT_MBX_BUF_SIZE,

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_send_create_vport_msg(struct iecm_adapter *adapter)

Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +9 -0
+							 GFP_KERNEL);
+		if (!adapter->vport_params_recvd[0])
+			return -ENOMEM;
+	}
+
+	vport_msg = (struct virtchnl2_create_vport *)
+			adapter->vport_params_recvd[0];
+
+	err = iecm_recv_mb_msg(adapter, VIRTCHNL2_OP_CREATE_VPORT,

vport_msg,

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter

Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +5 -0
+			       IECM_DFLT_MBX_BUF_SIZE);
+	if (err)
+		return err;
+
+	*vport_id = le32_to_cpu(vport_msg->vport_id);
 	return 0;
 }
 
@@ -966,6 +1054,920 @@ int iecm_wait_for_event(struct iecm_adapter

*adapter,

Quoted 90 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +87 -0
 }
 EXPORT_SYMBOL(iecm_wait_for_event);
 
+/**
+ * iecm_wait_for_marker_event - wait for software marker response
+ * @vport: virtual port data structure
+ *
+ * Returns 0 success, negative on failure.
+ **/
+static int iecm_wait_for_marker_event(struct iecm_vport *vport)
+{
+	int event = 0;
+	int i;
+
+	for (i = 0; i < vport->num_txq; i++)
+		set_bit(__IECM_Q_SW_MARKER, vport->txqs[i]->flags);
+
+	event = wait_event_timeout(vport->adapter->sw_marker_wq,
+				   test_and_clear_bit(__IECM_SW_MARKER,
+						      vport->adapter->flags),
+				   msecs_to_jiffies(500));
+	if (event)
+		return 0;
+	return -ETIMEDOUT;
+}
+
+/**
+ * iecm_send_destroy_vport_msg - Send virtchnl destroy vport message
+ * @vport: virtual port data structure
+ *
+ * Send virtchnl destroy vport message.  Returns 0 on success, negative on
+ * failure.
+ */
+int iecm_send_destroy_vport_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_vport v_id;
+	int err;
+
+	v_id.vport_id = cpu_to_le32(vport->vport_id);
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_DESTROY_VPORT,
+			       sizeof(v_id), (u8 *)&v_id);
+	if (err)
+		return err;
+
+	return iecm_min_wait_for_event(adapter, IECM_VC_DESTROY_VPORT,
+				       IECM_VC_DESTROY_VPORT_ERR);
+}
+
+/**
+ * iecm_send_enable_vport_msg - Send virtchnl enable vport message
+ * @vport: virtual port data structure
+ *
+ * Send enable vport virtchnl message.  Returns 0 on success, negative on
+ * failure.
+ */
+int iecm_send_enable_vport_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_vport v_id;
+	int err;
+
+	v_id.vport_id = cpu_to_le32(vport->vport_id);
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_ENABLE_VPORT,
+			       sizeof(v_id), (u8 *)&v_id);
+	if (err)
+		return err;
+
+	return iecm_wait_for_event(adapter, IECM_VC_ENA_VPORT,
+				   IECM_VC_ENA_VPORT_ERR);
+}
+
+/**
+ * iecm_send_disable_vport_msg - Send virtchnl disable vport message
+ * @vport: virtual port data structure
+ *
+ * Send disable vport virtchnl message.  Returns 0 on success, negative on
+ * failure.
+ */
+int iecm_send_disable_vport_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_vport v_id;
+	int err;
+
+	v_id.vport_id = cpu_to_le32(vport->vport_id);
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_DISABLE_VPORT,

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+			       sizeof(v_id), (u8 *)&v_id);
+	if (err)
+		return err;
+
+	return iecm_min_wait_for_event(adapter, IECM_VC_DIS_VPORT,
+				       IECM_VC_DIS_VPORT_ERR);
+}
+
+/**
+ * iecm_send_config_tx_queues_msg - Send virtchnl config tx queues

message

Quoted 35 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +35 -0
+ * @vport: virtual port data structure
+ *
+ * Send config tx queues virtchnl message. Returns 0 on success, negative on
+ * failure.
+ */
+int iecm_send_config_tx_queues_msg(struct iecm_vport *vport)
+{
+	struct virtchnl2_config_tx_queues *ctq = NULL;
+	int config_data_size, chunk_size, buf_size = 0;
+	int totqs, num_msgs, num_chunks;
+	struct virtchnl2_txq_info *qi;
+	int err = 0, i, k = 0;
+	bool alloc = false;
+
+	totqs = vport->num_txq + vport->num_complq;
+	qi = kcalloc(totqs, sizeof(struct virtchnl2_txq_info), GFP_KERNEL);
+	if (!qi)
+		return -ENOMEM;
+
+	/* Populate the queue info buffer with all queue context info */
+	for (i = 0; i < vport->num_txq_grp; i++) {
+		struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+		int j;
+
+		for (j = 0; j < tx_qgrp->num_txq; j++, k++) {
+			qi[k].queue_id =
+				cpu_to_le32(tx_qgrp->txqs[j]->q_id);
+			qi[k].model =
+				cpu_to_le16(vport->txq_model);
+			qi[k].type =
+				cpu_to_le32(tx_qgrp->txqs[j]->q_type);
+			qi[k].ring_len =
+				cpu_to_le16(tx_qgrp->txqs[j]->desc_count);
+			qi[k].dma_ring_addr =
+				cpu_to_le64(tx_qgrp->txqs[j]->dma);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1206

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +9 -0
+			if (iecm_is_queue_model_split(vport->txq_model)) {
+				struct iecm_queue *q = tx_qgrp->txqs[j];
+
+				qi[k].tx_compl_queue_id =
+					cpu_to_le16(tx_qgrp->complq->q_id);
+
+				if (test_bit(__IECM_Q_FLOW_SCH_EN, q-
 flags))
+					qi[k].sched_mode =
+
	cpu_to_le16(VIRTCHNL2_TXQ_SCHED_MODE_FLOW);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1206

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +3 -0
+				else
+					qi[k].sched_mode =
+
	cpu_to_le16(VIRTCHNL2_TXQ_SCHED_MODE_QUEUE);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1206

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +3 -0
+			} else {
+				qi[k].sched_mode =
+
	cpu_to_le16(VIRTCHNL2_TXQ_SCHED_MODE_QUEUE);
Quoted 21 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +21 -0
+			}
+		}
+
+		if (iecm_is_queue_model_split(vport->txq_model)) {
+			qi[k].queue_id =
+				cpu_to_le32(tx_qgrp->complq->q_id);
+			qi[k].model =
+				cpu_to_le16(vport->txq_model);
+			qi[k].type =
+				cpu_to_le32(tx_qgrp->complq->q_type);
+			qi[k].ring_len =
+				cpu_to_le16(tx_qgrp->complq->desc_count);
+			qi[k].dma_ring_addr =
+				cpu_to_le64(tx_qgrp->complq->dma);
+			k++;
+		}
+	}
+
+	/* Make sure accounting agrees */
+	if (k != totqs) {
+		err = -EINVAL;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+		goto error;
+	}
+
+	/* Chunk up the queue contexts into multiple messages to avoid
+	 * sending a control queue message buffer that is too large
+	 */
+	config_data_size = sizeof(struct virtchnl2_config_tx_queues);
+	chunk_size = sizeof(struct virtchnl2_txq_info);
+
+	num_chunks = IECM_NUM_CHUNKS_PER_MSG(config_data_size,

chunk_size) + 1;

Quoted 22 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +22 -0
+	if (totqs < num_chunks)
+		num_chunks = totqs;
+
+	num_msgs = totqs / num_chunks;
+	if (totqs % num_chunks)
+		num_msgs++;
+
+	for (i = 0, k = 0; i < num_msgs; i++) {
+		if (!ctq || alloc) {
+			buf_size = (chunk_size * (num_chunks - 1)) +
+					config_data_size;
+			kfree(ctq);
+			ctq = kzalloc(buf_size, GFP_KERNEL);
+			if (!ctq) {
+				err = -ENOMEM;
+				goto error;
+			}
+		} else {
+			memset(ctq, 0, buf_size);
+		}
+
+		ctq->vport_id = cpu_to_le32(vport->vport_id);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+		ctq->num_qinfo = cpu_to_le16(num_chunks);
+		memcpy(ctq->qinfo, &qi[k], chunk_size * num_chunks);
+
+		err = iecm_send_mb_msg(vport->adapter,
+				       VIRTCHNL2_OP_CONFIG_TX_QUEUES,
+				       buf_size, (u8 *)ctq);
+		if (err)
+			goto mbx_error;
+
+		err = iecm_wait_for_event(vport->adapter,

IECM_VC_CONFIG_TXQ,

Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +11 -0
+					  IECM_VC_CONFIG_TXQ_ERR);
+		if (err)
+			goto mbx_error;
+
+		k += num_chunks;
+		totqs -= num_chunks;
+		if (totqs < num_chunks) {
+			num_chunks = totqs;
+			alloc = true;
+		}
+	}

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+
+mbx_error:
+	kfree(ctq);
+error:
+	kfree(qi);
+	return err;
+}
+
+/**
+ * iecm_send_config_rx_queues_msg - Send virtchnl config rx queues

message

Quoted 28 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +28 -0
+ * @vport: virtual port data structure
+ *
+ * Send config rx queues virtchnl message.  Returns 0 on success, negative on
+ * failure.
+ */
+int iecm_send_config_rx_queues_msg(struct iecm_vport *vport)
+{
+	struct virtchnl2_config_rx_queues *crq = NULL;
+	int config_data_size, chunk_size, buf_size = 0;
+	int totqs, num_msgs, num_chunks;
+	struct virtchnl2_rxq_info *qi;
+	int err = 0, i, k = 0;
+	bool alloc = false;
+
+	totqs = vport->num_rxq + vport->num_bufq;
+	qi = kcalloc(totqs, sizeof(struct virtchnl2_rxq_info), GFP_KERNEL);
+	if (!qi)
+		return -ENOMEM;
+
+	/* Populate the queue info buffer with all queue context info */
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+		int num_rxq;
+		int j;
+
+		if (iecm_is_queue_model_split(vport->rxq_model)) {
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++, k++) {
+				struct iecm_queue *bufq =

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1338

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+					&rx_qgrp->splitq.bufq_sets[j].bufq;
+
+				qi[k].queue_id =
+					cpu_to_le32(bufq->q_id);
+				qi[k].model =
+					cpu_to_le16(vport->rxq_model);
+				qi[k].type =
+					cpu_to_le32(bufq->q_type);
+				qi[k].desc_ids =
+
	cpu_to_le64(VIRTCHNL2_RXDID_1_FLEX_SPLITQ_M);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1337

Quoted 13 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +12 -0
+				qi[k].ring_len =
+					cpu_to_le16(bufq->desc_count);
+				qi[k].dma_ring_addr =
+					cpu_to_le64(bufq->dma);
+				qi[k].data_buffer_size =
+					cpu_to_le32(bufq->rx_buf_size);
+				qi[k].buffer_notif_stride =
+					bufq->rx_buf_stride;
+				qi[k].rx_buffer_low_watermark =
+					cpu_to_le16(bufq-
 rx_buffer_low_watermark);
+			}
+		}
		if (iecm_is_queue_model_split(vport->rxq_model))
			goto here;
Quoted 3 lines
Quoted 1 line

-1 indent level for the for-loop.

I'm afraid I'm not following, please elaborate. Where are we goto'ing? The for loop below needs to be executed for both and if we just tack the above for loop at the bottom of the function and goto in and out of it to save an indent does not sound great and makes the code harder to follow IMO.

Ah sorry, I forgot to invert the condition.
Here's the full loop:

	for (i = 0; i < vport->num_rxq_grp; i++) {
		struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
		int num_rxq;
		int j;

		if (!iecm_is_queue_model_split(vport->rxq_model))
			goto label_name_1;

		for (j = 0; j < vport->num_bufqs_per_qgrp; j++, k++) {
			struct iecm_queue *bufq =
				&rx_qgrp->splitq.bufq_sets[j].bufq;
			/* bufq ^ should be const here BTW, you only read it */

			qi[k].queue_id =
				cpu_to_le32(bufq->q_id);

			...

			qi[k].rx_buffer_low_watermark =
				cpu_to_le16(bufq->rx_buffer_low_watermark);
		}

label_name_1:

		if (iecm_is_queue_model_split(vport->rxq_model))
			num_rxq = rx_qgrp->splitq.num_rxq_sets;
		else
			num_rxq = rx_qgrp->singleq.num_rxq;

		for (j = 0; j < num_rxq; j++, k++) {
			struct iecm_queue *rxq;
			/* const here ^ as well */

			if (!iecm_is_queue_model_split(vport->rxq_model)) {
				rxq = rx_qgrp->singleq.rxqs[j];
				goto label_name_2;
			}

			rxq = &rx_qgrp->splitq.rxq_sets[j]->rxq;
			qi[k].rx_bufq1_id =

			...

			qi[k].hdr_buffer_size =
				cpu_to_le16(rxq->rx_hbuf_size);

label_name_2:

			qi[k].queue_id =
				cpu_to_le32(rxq->q_id);
			qi[k].model =
				cpu_to_le16(vport->rxq_model);

			...

			qi[k].qflags |=
				cpu_to_le16(VIRTCHNL2_RX_DESC_SIZE_32BYTE);
			qi[k].desc_ids =
				cpu_to_le64(rxq->rxdids);
		}
	}

	/* Make sure accounting agrees */
	if (k != totqs) {
		err = -EINVAL;
		goto error;
	}

	/* Chunk up the queue contexts into multiple messages to avoid
	...

Hope I didn't m{i,e}ss anything this time.

Quoted 5 lines
Quoted 3 lines

Braces for 'if' are not needed since the for-loop has their own.

They're not required but we have generally preferred to keep braces on statements extending across more than one line.

See my answer to the prev. patch.

Quoted 39 lines
Quoted 28 lines
Quoted 23 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +15 -0
+
+		if (iecm_is_queue_model_split(vport->rxq_model))
+			num_rxq = rx_qgrp->splitq.num_rxq_sets;
+		else
+			num_rxq = rx_qgrp->singleq.num_rxq;
+
+		for (j = 0; j < num_rxq; j++, k++) {
+			struct iecm_queue *rxq;
+
+			if (iecm_is_queue_model_split(vport->rxq_model)) {
+				rxq = &rx_qgrp->splitq.rxq_sets[j]->rxq;
+				qi[k].rx_bufq1_id =
+				  cpu_to_le16(rxq->rxq_grp-
 splitq.bufq_sets[0].bufq.q_id);
+				qi[k].rx_bufq2_id =
+				  cpu_to_le16(rxq->rxq_grp-

splitq.bufq_sets[1].bufq.q_id);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +4 -0
+				qi[k].hdr_buffer_size =
+					cpu_to_le16(rxq->rx_hbuf_size);
+				qi[k].rx_buffer_low_watermark =
+					cpu_to_le16(rxq-

rx_buffer_low_watermark);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1367

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +4 -0
+
+				if (rxq->rx_hsplit_en) {
+					qi[k].qflags =
+
	cpu_to_le16(VIRTCHNL2_RXQ_HDR_SPLIT);
Quoted 10 lines

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1366

Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +2 -0
+					qi[k].hdr_buffer_size =
+						cpu_to_le16(rxq-

rx_hbuf_size);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +4 -0
+				}
+			} else {
+				rxq = rx_qgrp->singleq.rxqs[j];
+			}

Same here, but with rxq = ... + goto.

Quoted 1 line

Please elaborate.

2 replies above.

Quoted 1,099 lines
Quoted 1,099 lines
Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +7 -0
+
+			qi[k].queue_id =
+				cpu_to_le32(rxq->q_id);
+			qi[k].model =
+				cpu_to_le16(vport->rxq_model);
+			qi[k].type =
+				cpu_to_le32(rxq->q_type);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1388

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+			qi[k].ring_len =
+				cpu_to_le16(rxq->desc_count);
+			qi[k].dma_ring_addr =
+				cpu_to_le64(rxq->dma);
+			qi[k].max_pkt_size =
+				cpu_to_le32(rxq->rx_max_pkt_size);
+			qi[k].data_buffer_size =
+				cpu_to_le32(rxq->rx_buf_size);
+			qi[k].qflags |=
+
	cpu_to_le16(VIRTCHNL2_RX_DESC_SIZE_32BYTE);
Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +8 -0
+			qi[k].desc_ids =
+				cpu_to_le64(rxq->rxdids);
+		}
+	}
+
+	/* Make sure accounting agrees */
+	if (k != totqs) {
+		err = -EINVAL;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+		goto error;
+	}
+
+	/* Chunk up the queue contexts into multiple messages to avoid
+	 * sending a control queue message buffer that is too large
+	 */
+	config_data_size = sizeof(struct virtchnl2_config_rx_queues);
+	chunk_size = sizeof(struct virtchnl2_rxq_info);
+
+	num_chunks = IECM_NUM_CHUNKS_PER_MSG(config_data_size,

chunk_size) + 1;

Quoted 22 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +22 -0
+	if (totqs < num_chunks)
+		num_chunks = totqs;
+
+	num_msgs = totqs / num_chunks;
+	if (totqs % num_chunks)
+		num_msgs++;
+
+	for (i = 0, k = 0; i < num_msgs; i++) {
+		if (!crq || alloc) {
+			buf_size = (chunk_size * (num_chunks - 1)) +
+					config_data_size;
+			kfree(crq);
+			crq = kzalloc(buf_size, GFP_KERNEL);
+			if (!crq) {
+				err = -ENOMEM;
+				goto error;
+			}
+		} else {
+			memset(crq, 0, buf_size);
+		}
+
+		crq->vport_id = cpu_to_le32(vport->vport_id);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+		crq->num_qinfo = cpu_to_le16(num_chunks);
+		memcpy(crq->qinfo, &qi[k], chunk_size * num_chunks);
+
+		err = iecm_send_mb_msg(vport->adapter,
+				       VIRTCHNL2_OP_CONFIG_RX_QUEUES,
+				       buf_size, (u8 *)crq);
+		if (err)
+			goto mbx_error;
+
+		err = iecm_wait_for_event(vport->adapter,

IECM_VC_CONFIG_RXQ,

Quoted 74 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +74 -0
+					  IECM_VC_CONFIG_RXQ_ERR);
+		if (err)
+			goto mbx_error;
+
+		k += num_chunks;
+		totqs -= num_chunks;
+		if (totqs < num_chunks) {
+			num_chunks = totqs;
+			alloc = true;
+		}
+	}
+
+mbx_error:
+	kfree(crq);
+error:
+	kfree(qi);
+	return err;
+}
+
+/**
+ * iecm_send_ena_dis_queues_msg - Send virtchnl enable or disable
+ * queues message
+ * @vport: virtual port data structure
+ * @vc_op: virtchnl op code to send
+ *
+ * Send enable or disable queues virtchnl message. Returns 0 on success,
+ * negative on failure.
+ */
+static int iecm_send_ena_dis_queues_msg(struct iecm_vport *vport,
+					enum virtchnl_ops vc_op)
+{
+	int num_msgs, num_chunks, config_data_size, chunk_size;
+	int num_txq, num_rxq, num_q, buf_size, err = 0;
+	struct virtchnl2_del_ena_dis_queues *eq = NULL;
+	struct virtchnl2_queue_chunk *qc;
+	bool alloc = false;
+	int i, j, k = 0;
+
+	/* validate virtchnl op */
+	switch (vc_op) {
+	case VIRTCHNL2_OP_ENABLE_QUEUES:
+	case VIRTCHNL2_OP_DISABLE_QUEUES:
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	num_txq = vport->num_txq + vport->num_complq;
+	num_rxq = vport->num_rxq + vport->num_bufq;
+	num_q = num_txq + num_rxq;
+	buf_size = sizeof(struct virtchnl2_queue_chunk) * (num_q);
+	qc = kzalloc(buf_size, GFP_KERNEL);
+	if (!qc)
+		return -ENOMEM;
+
+	for (i = 0; i < vport->num_txq_grp; i++) {
+		struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+
+		for (j = 0; j < tx_qgrp->num_txq; j++, k++) {
+			qc[k].type = cpu_to_le32(tx_qgrp->txqs[j]->q_type);
+			qc[k].start_queue_id =
+					cpu_to_le32(tx_qgrp->txqs[j]->q_id);
+			qc[k].num_queues = cpu_to_le32(1);
+		}
+	}
+	if (vport->num_txq != k) {
+		err = -EINVAL;
+		goto error;
+	}
+
+	if (iecm_is_queue_model_split(vport->txq_model)) {
+		for (i = 0; i < vport->num_txq_grp; i++, k++) {
+			struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1517

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+			qc[k].type = cpu_to_le32(tx_qgrp->complq->q_type);
+			qc[k].start_queue_id =
+					cpu_to_le32(tx_qgrp->complq->q_id);
+			qc[k].num_queues = cpu_to_le32(1);
+		}
+		if (vport->num_complq != (k - vport->num_txq)) {
+			err = -EINVAL;
+			goto error;
+		}
+	}

...and here.

Quoted 41 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +13 -0
+
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+
+		if (iecm_is_queue_model_split(vport->rxq_model))
+			num_rxq = rx_qgrp->splitq.num_rxq_sets;
+		else
+			num_rxq = rx_qgrp->singleq.num_rxq;
+
+		for (j = 0; j < num_rxq; j++, k++) {
+			if (iecm_is_queue_model_split(vport->rxq_model)) {
+				qc[k].start_queue_id =
+				cpu_to_le32(rx_qgrp->splitq.rxq_sets[j]-

rxq.q_id);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +2 -0
+				qc[k].type =
+				cpu_to_le32(rx_qgrp->splitq.rxq_sets[j]-

rxq.q_type);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +20 -0
+			} else {
+				qc[k].start_queue_id =
+				cpu_to_le32(rx_qgrp->singleq.rxqs[j]->q_id);
+				qc[k].type =
+				cpu_to_le32(rx_qgrp->singleq.rxqs[j]->q_type);
+			}
+			qc[k].num_queues = cpu_to_le32(1);
+		}
+	}
+	if (vport->num_rxq != k - (vport->num_txq + vport->num_complq)) {
+		err = -EINVAL;
+		goto error;
+	}
+
+	if (iecm_is_queue_model_split(vport->rxq_model)) {
+		for (i = 0; i < vport->num_rxq_grp; i++) {
+			struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++, k++) {
+				struct iecm_queue *q = &rx_qgrp-

splitq.bufq_sets[j].bufq;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +3 -0
+
+				qc[k].type = cpu_to_le32(q->q_type);
+				qc[k].start_queue_id = cpu_to_le32(q->q_id);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1565

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+				qc[k].num_queues = cpu_to_le32(1);
+			}
+		}
+		if (vport->num_bufq != k - (vport->num_txq +
+					       vport->num_complq +
+					       vport->num_rxq)) {
+			err = -EINVAL;
+			goto error;
+		}
+	}

...and here.

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +6 -0
+
+	/* Chunk up the queue info into multiple messages */
+	config_data_size = sizeof(struct virtchnl2_del_ena_dis_queues);
+	chunk_size = sizeof(struct virtchnl2_queue_chunk);
+
+	num_chunks = IECM_NUM_CHUNKS_PER_MSG(config_data_size,

chunk_size) + 1;

Quoted 13 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +13 -0
+	if (num_q < num_chunks)
+		num_chunks = num_q;
+
+	num_msgs = num_q / num_chunks;
+	if (num_q % num_chunks)
+		num_msgs++;
+
+	for (i = 0, k = 0; i < num_msgs; i++) {
+		if (!eq || alloc) {
+			buf_size = (chunk_size * (num_chunks - 1)) +
+					config_data_size;
+			kfree(eq);
+			eq = kzalloc(buf_size, GFP_KERNEL);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+			if (!eq) {
+				err = -ENOMEM;
+				goto error;
+			}
+		} else {
+			memset(eq, 0, buf_size);
+		}
+		eq->vport_id = cpu_to_le32(vport->vport_id);
+		eq->chunks.num_chunks = cpu_to_le16(num_chunks);
+		memcpy(eq->chunks.chunks, &qc[k], chunk_size *

num_chunks);

Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +11 -0
+
+		err = iecm_send_mb_msg(vport->adapter, vc_op, buf_size,
+				       (u8 *)eq);
+		if (err)
+			goto mbx_error;
+		k += num_chunks;
+		num_q -= num_chunks;
+		if (num_q < num_chunks) {
+			num_chunks = num_q;
+			alloc = true;
+		}

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+	}
+mbx_error:
+	kfree(eq);
+error:
+	kfree(qc);
+	return err;
+}
+
+/**
+ * iecm_send_map_unmap_queue_vector_msg - Send virtchnl map or unmap

queue

Quoted 8 lines

+ * vector message
+ * @vport: virtual port data structure
+ * @map: true for map and false for unmap
+ *
+ * Send map or unmap queue vector virtchnl message. Returns 0 on success,
+ * negative on failure.
+ */
+int iecm_send_map_unmap_queue_vector_msg(struct iecm_vport *vport,

bool map)

Quoted 63 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +21 -0
+{
+	int num_msgs, num_chunks, config_data_size, chunk_size;
+	struct virtchnl2_queue_vector_maps *vqvm = NULL;
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_queue_vector *vqv;
+	int buf_size, num_q, err = 0;
+	bool alloc = false;
+	int i, j, k = 0;
+
+	num_q = vport->num_txq + vport->num_rxq;
+
+	buf_size = sizeof(struct virtchnl2_queue_vector) * num_q;
+	vqv = kzalloc(buf_size, GFP_KERNEL);
+	if (!vqv)
+		return -ENOMEM;
+
+	for (i = 0; i < vport->num_txq_grp; i++) {
+		struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+
+		for (j = 0; j < tx_qgrp->num_txq; j++, k++) {
+			vqv[k].queue_type = cpu_to_le32(tx_qgrp->txqs[j]-

q_type);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +5 -0
+			vqv[k].queue_id = cpu_to_le32(tx_qgrp->txqs[j]->q_id);
+
+			if (iecm_is_queue_model_split(vport->txq_model)) {
+				vqv[k].vector_id =
+				cpu_to_le16(tx_qgrp->complq->q_vector-

v_idx);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +2 -0
+				vqv[k].itr_idx =
+				cpu_to_le32(tx_qgrp->complq->q_vector-

tx_itr_idx);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +3 -0
+			} else {
+				vqv[k].vector_id =
+				cpu_to_le16(tx_qgrp->txqs[j]->q_vector-

v_idx);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +2 -0
+				vqv[k].itr_idx =
+				cpu_to_le32(tx_qgrp->txqs[j]->q_vector-

tx_itr_idx);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +25 -0
+			}
+		}
+	}
+
+	if (vport->num_txq != k) {
+		err = -EINVAL;
+		goto error;
+	}
+
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+		int num_rxq;
+
+		if (iecm_is_queue_model_split(vport->rxq_model))
+			num_rxq = rx_qgrp->splitq.num_rxq_sets;
+		else
+			num_rxq = rx_qgrp->singleq.num_rxq;
+
+		for (j = 0; j < num_rxq; j++, k++) {
+			struct iecm_queue *rxq;
+
+			if (iecm_is_queue_model_split(vport->rxq_model))
+				rxq = &rx_qgrp->splitq.rxq_sets[j]->rxq;
+			else
+				rxq = rx_qgrp->singleq.rxqs[j];

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1691

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+
+			vqv[k].queue_type = cpu_to_le32(rxq->q_type);
+			vqv[k].queue_id = cpu_to_le32(rxq->q_id);
+			vqv[k].vector_id = cpu_to_le16(rxq->q_vector->v_idx);
+			vqv[k].itr_idx = cpu_to_le32(rxq->q_vector->rx_itr_idx);
+		}
+	}
+
+	if (iecm_is_queue_model_split(vport->txq_model)) {
+		if (vport->num_rxq != k - vport->num_complq) {
	if (iecm_is_queue_model_split() && vport->num_rxq != ...) {

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1252

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +4 -0
+			err = -EINVAL;
+			goto error;
+		}
+	} else {

Don't forget to convert this then into !split + ..., either with 'else' or not.

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +11 -0
+		if (vport->num_rxq != k - vport->num_txq) {
+			err = -EINVAL;
+			goto error;
+		}
+	}
+
+	/* Chunk up the vector info into multiple messages */
+	config_data_size = sizeof(struct virtchnl2_queue_vector_maps);
+	chunk_size = sizeof(struct virtchnl2_queue_vector);
+
+	num_chunks = IECM_NUM_CHUNKS_PER_MSG(config_data_size,

chunk_size) + 1;

Quoted 17 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +17 -0
+	if (num_q < num_chunks)
+		num_chunks = num_q;
+
+	num_msgs = num_q / num_chunks;
+	if (num_q % num_chunks)
+		num_msgs++;
+
+	for (i = 0, k = 0; i < num_msgs; i++) {
+		if (!vqvm || alloc) {
+			buf_size = (chunk_size * (num_chunks - 1)) +
+					config_data_size;
+			kfree(vqvm);
+			vqvm = kzalloc(buf_size, GFP_KERNEL);
+			if (!vqvm) {
+				err = -ENOMEM;
+				goto error;
+			}

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1751

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+		} else {
+			memset(vqvm, 0, buf_size);
+		}
+		vqvm->vport_id = cpu_to_le32(vport->vport_id);
+		vqvm->num_qv_maps = cpu_to_le16(num_chunks);
+		memcpy(vqvm->qv_maps, &vqv[k], chunk_size * num_chunks);
+
+		if (map) {
+			err = iecm_send_mb_msg(adapter,
+

VIRTCHNL2_OP_MAP_QUEUE_VECTOR,

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1751

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +5 -0
+					       buf_size, (u8 *)vqvm);
+			if (!err)
+				err = iecm_wait_for_event(adapter,
+							  IECM_VC_MAP_IRQ,
+

IECM_VC_MAP_IRQ_ERR);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1751

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +3 -0
+		} else {
+			err = iecm_send_mb_msg(adapter,
+

VIRTCHNL2_OP_UNMAP_QUEUE_VECTOR,

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1751

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +5 -0
+					       buf_size, (u8 *)vqvm);
+			if (!err)
+				err =
+				iecm_min_wait_for_event(adapter,
+

IECM_VC_UNMAP_IRQ,

Quoted 1 line

+

	IECM_VC_UNMAP_IRQ_ERR);
Quoted 14 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +14 -0
+		}
+		if (err)
+			goto mbx_error;
+
+		k += num_chunks;
+		num_q -= num_chunks;
+		if (num_q < num_chunks) {
+			num_chunks = num_q;
+			alloc = true;
+		}
+	}
+mbx_error:
+	kfree(vqvm);
+error:

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+	kfree(vqv);
+	return err;
+}
+EXPORT_SYMBOL(iecm_send_map_unmap_queue_vector_msg);
+
+/**
+ * iecm_send_enable_queues_msg - send enable queues virtchnl message
+ * @vport: Virtual port private data structure
+ *
+ * Will send enable queues virtchnl message.  Returns 0 on success, negative

on

Quoted 33 lines

+ * failure.
+ */

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +31 -0
+static int iecm_send_enable_queues_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	int err;
+
+	err = iecm_send_ena_dis_queues_msg(vport,
+					   VIRTCHNL2_OP_ENABLE_QUEUES);
+	if (err)
+		return err;
+
+	return iecm_wait_for_event(adapter, IECM_VC_ENA_QUEUES,
+				   IECM_VC_ENA_QUEUES_ERR);
+}
+
+/**
+ * iecm_send_disable_queues_msg - send disable queues virtchnl message
+ * @vport: Virtual port private data structure
+ *
+ * Will send disable queues virtchnl message.  Returns 0 on success, negative
+ * on failure.
+ */
+static int iecm_send_disable_queues_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	int err;
+
+	err = iecm_send_ena_dis_queues_msg(vport,
+					   VIRTCHNL2_OP_DISABLE_QUEUES);
+	if (err)
+		return err;
+

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+	err = iecm_min_wait_for_event(adapter, IECM_VC_DIS_QUEUES,
+				      IECM_VC_DIS_QUEUES_ERR);
+	if (err)
+		return err;
+
+	return iecm_wait_for_marker_event(vport);
+}
+
+/**
+ * iecm_convert_reg_to_queue_chunks - Copy queue chunk information to

the right

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c

Quoted 7 lines

+ * structure
+ * @dchunks: Destination chunks to store data to
+ * @schunks: Source chunks to copy data from
+ * @num_chunks: number of chunks to copy
+ */

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +2 -0
+static void
+iecm_convert_reg_to_queue_chunks(struct virtchnl2_queue_chunk

*dchunks,

Quoted 53 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +52 -0
+				 struct virtchnl2_queue_reg_chunk *schunks,
+				 u16 num_chunks)
+{
+	u16 i;
+
+	for (i = 0; i < num_chunks; i++) {
+		dchunks[i].type = schunks[i].type;
+		dchunks[i].start_queue_id = schunks[i].start_queue_id;
+		dchunks[i].num_queues = schunks[i].num_queues;
+	}
+}
+
+/**
+ * iecm_send_delete_queues_msg - send delete queues virtchnl message
+ * @vport: Virtual port private data structure
+ *
+ * Will send delete queues virtchnl message. Return 0 on success, negative on
+ * failure.
+ */
+int iecm_send_delete_queues_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_create_vport *vport_params;
+	struct virtchnl2_queue_reg_chunks *chunks;
+	struct virtchnl2_del_ena_dis_queues *eq;
+	int buf_size, err;
+	u16 num_chunks;
+
+	if (vport->adapter->config_data.req_qs_chunks) {
+		struct virtchnl2_add_queues *vc_aq =
+			(struct virtchnl2_add_queues *)
+			vport->adapter->config_data.req_qs_chunks;
+		chunks = &vc_aq->chunks;
+	} else {
+		vport_params = (struct virtchnl2_create_vport *)
+				vport->adapter->vport_params_recvd[0];
+		 chunks = &vport_params->chunks;
+	}
+
+	num_chunks = le16_to_cpu(chunks->num_chunks);
+	buf_size = sizeof(struct virtchnl2_del_ena_dis_queues) +
+			  (sizeof(struct virtchnl2_queue_chunk) *
+			  (num_chunks - 1));
+
+	eq = kzalloc(buf_size, GFP_KERNEL);
+	if (!eq)
+		return -ENOMEM;
+
+	eq->vport_id = cpu_to_le32(vport->vport_id);
+	eq->chunks.num_chunks = cpu_to_le16(num_chunks);
+
+	iecm_convert_reg_to_queue_chunks(eq->chunks.chunks, chunks-

chunks,

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +3 -0
+					 num_chunks);
+
+	err = iecm_send_mb_msg(vport->adapter,

VIRTCHNL2_OP_DEL_QUEUES,

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +6 -0
+			       buf_size, (u8 *)eq);
+	if (err)
+		goto error;
+
+	err = iecm_min_wait_for_event(adapter, IECM_VC_DEL_QUEUES,
+				      IECM_VC_DEL_QUEUES_ERR);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+error:
+	kfree(eq);
+	return err;
+}
+
+/**
+ * iecm_send_config_queues_msg - Send config queues virtchnl message
+ * @vport: Virtual port private data structure
+ *
+ * Will send config queues virtchnl message. Returns 0 on success, negative

on

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static void iecm_vport_init(struct iecm_vport

Quoted 82 lines

+ * failure.
+ */

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +76 -0
+static int iecm_send_config_queues_msg(struct iecm_vport *vport)
+{
+	int err;
+
+	err = iecm_send_config_tx_queues_msg(vport);
+	if (err)
+		return err;
+
+	return iecm_send_config_rx_queues_msg(vport);
+}
+
+/**
+ * iecm_send_add_queues_msg - Send virtchnl add queues message
+ * @vport: Virtual port private data structure
+ * @num_tx_q: number of transmit queues
+ * @num_complq: number of transmit completion queues
+ * @num_rx_q: number of receive queues
+ * @num_rx_bufq: number of receive buffer queues
+ *
+ * Returns 0 on success, negative on failure.
+ */
+int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,
+			     u16 num_complq, u16 num_rx_q, u16 num_rx_bufq)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_add_queues aq = {0};
+	struct virtchnl2_add_queues *vc_msg;
+	int size, err;
+
+	vc_msg = (struct virtchnl2_add_queues *)adapter->vc_msg;
+
+	aq.vport_id = cpu_to_le32(vport->vport_id);
+	aq.num_tx_q = cpu_to_le16(num_tx_q);
+	aq.num_tx_complq = cpu_to_le16(num_complq);
+	aq.num_rx_q = cpu_to_le16(num_rx_q);
+	aq.num_rx_bufq = cpu_to_le16(num_rx_bufq);
+
+	err = iecm_send_mb_msg(adapter,
+			       VIRTCHNL2_OP_ADD_QUEUES,
+			       sizeof(struct virtchnl2_add_queues), (u8 *)&aq);
+	if (err)
+		return err;
+
+	err = iecm_wait_for_event(adapter, IECM_VC_ADD_QUEUES,
+				  IECM_VC_ADD_QUEUES_ERR);
+	if (err)
+		return err;
+
+	kfree(adapter->config_data.req_qs_chunks);
+	adapter->config_data.req_qs_chunks = NULL;
+
+	/* compare vc_msg num queues with vport num queues */
+	if (le16_to_cpu(vc_msg->num_tx_q) != num_tx_q ||
+	    le16_to_cpu(vc_msg->num_rx_q) != num_rx_q ||
+	    le16_to_cpu(vc_msg->num_tx_complq) != num_complq ||
+	    le16_to_cpu(vc_msg->num_rx_bufq) != num_rx_bufq) {
+		err = -EINVAL;
+		goto error;
+	}
+
+	size = sizeof(struct virtchnl2_add_queues) +
+			((le16_to_cpu(vc_msg->chunks.num_chunks) - 1) *
+			sizeof(struct virtchnl2_queue_reg_chunk));
+	adapter->config_data.req_qs_chunks =
+		kzalloc(size, GFP_KERNEL);
+	if (!adapter->config_data.req_qs_chunks) {
+		err = -ENOMEM;
+		goto error;
+	}
+	memcpy(adapter->config_data.req_qs_chunks,
+	       adapter->vc_msg, size);
+error:
+	clear_bit(__IECM_VC_MSG_PENDING, adapter->flags);
+	return err;
+}
+
 /**
  * iecm_find_ctlq - Given a type and id, find ctlq info
  * @hw: hardware struct
@@ -1217,6 +2219,13 @@ static void iecm_vport_init(struct iecm_vport

*vport,

Quoted 58 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +45 -2
 	/*Initialize Tx and Rx profiles for Dynamic Interrupt Moderation */
 	memcpy(vport->rx_itr_profile, rx_itr, IECM_DIM_PROFILE_SLOTS);
 	memcpy(vport->tx_itr_profile, tx_itr, IECM_DIM_PROFILE_SLOTS);
+
+	iecm_vport_set_hsplit(vport, true);
+
+	iecm_vport_init_num_qs(vport, vport_msg);
+	iecm_vport_calc_num_q_desc(vport);
+	iecm_vport_calc_num_q_groups(vport);
+	iecm_vport_calc_num_q_vec(vport);
 }
 
 /**
@@ -1316,8 +2325,82 @@ static int
 __iecm_vport_queue_ids_init(struct iecm_vport *vport, u32 *qids,
 			    int num_qids, u32 q_type)
 {
-	/* stub */
-	return 0;
+	struct iecm_queue *q;
+	int i, j, k = 0;
+
+	switch (q_type) {
+	case VIRTCHNL2_QUEUE_TYPE_TX:
+		for (i = 0; i < vport->num_txq_grp; i++) {
+			struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+
+			for (j = 0; j < tx_qgrp->num_txq; j++) {
+				if (k < num_qids) {
+					tx_qgrp->txqs[j]->q_id = qids[k];
+					tx_qgrp->txqs[j]->q_type =
+						VIRTCHNL2_QUEUE_TYPE_TX;
+					k++;
+				} else {
+					break;
+				}
+			}
+		}
+		break;
+	case VIRTCHNL2_QUEUE_TYPE_RX:
+		for (i = 0; i < vport->num_rxq_grp; i++) {
+			struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+			int num_rxq;
+
+			if (iecm_is_queue_model_split(vport->rxq_model))
+				num_rxq = rx_qgrp->splitq.num_rxq_sets;
+			else
+				num_rxq = rx_qgrp->singleq.num_rxq;
+
+			for (j = 0; j < num_rxq && k < num_qids; j++, k++) {
+				if (iecm_is_queue_model_split(vport-
 rxq_model))
+					q = &rx_qgrp->splitq.rxq_sets[j]->rxq;
+				else
+					q = rx_qgrp->singleq.rxqs[j];
+				q->q_id = qids[k];
+				q->q_type = VIRTCHNL2_QUEUE_TYPE_RX;
+			}

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int · line 2376

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+		}
+		break;
+	case VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION:
+		for (i = 0; i < vport->num_txq_grp; i++) {
+			struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+
+			if (k < num_qids) {
+				tx_qgrp->complq->q_id = qids[k];
+				tx_qgrp->complq->q_type =
+
	VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION;
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +6 -0
+				k++;
+			} else {
+				break;
+			}
+		}
+		break;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int · line 2402

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+	case VIRTCHNL2_QUEUE_TYPE_RX_BUFFER:
+		for (i = 0; i < vport->num_rxq_grp; i++) {
+			struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++) {
+				if (k < num_qids) {
+					q = &rx_qgrp->splitq.bufq_sets[j].bufq;
+					q->q_id = qids[k];
+					q->q_type =
+
	VIRTCHNL2_QUEUE_TYPE_RX_BUFFER;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static bool iecm_is_capability_ena(struct

Quoted 16 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +12 -0
+					k++;
+				} else {
+					break;
+				}
+			}
+		}
+		break;
+	default:
+		break;
+	}
+
+	return k;
 }
 

/**

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +0 -0
@@ -1425,6 +2508,20 @@ static bool iecm_is_capability_ena(struct

iecm_adapter *adapter, bool all,

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static bool iecm_is_capability_ena(struct iecm_adapter *adapter, bool all,

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +2 -0
 		return !!(*cap_field & flag);
 }
 
+/**
+ * iecm_get_reserved_vectors - Default implementation to get reserved

vectors

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c void iecm_vc_ops_init(struct iecm_adapter

Quoted 16 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +12 -0
+ * @adapter: Private data struct
+ *
+ * Return number of vectors reserved
+ */
+static u16 iecm_get_reserved_vectors(struct iecm_adapter *adapter)
+{
+	struct virtchnl2_get_capabilities *caps;
+
+	caps = (struct virtchnl2_get_capabilities *)adapter->caps;
+	return le16_to_cpu(caps->num_allocated_vectors);
+}
+
 /**
  * iecm_vc_ops_init - Initialize virtchnl common api
  * @adapter: Driver specific private structure
@@ -1441,16 +2538,16 @@ void iecm_vc_ops_init(struct iecm_adapter

*adapter)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +0 -7
 	vc_ops->vport_queue_ids_init = iecm_vport_queue_ids_init;
 	vc_ops->get_caps = iecm_send_get_caps_msg;
 	vc_ops->is_cap_ena = iecm_is_capability_ena;
-	vc_ops->get_reserved_vecs = NULL;
-	vc_ops->config_queues = NULL;
-	vc_ops->enable_queues = NULL;
-	vc_ops->disable_queues = NULL;
-	vc_ops->add_queues = NULL;
-	vc_ops->delete_queues = NULL;
-	vc_ops->irq_map_unmap = NULL;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c void iecm_vc_ops_init(struct iecm_adapter *adapter)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +7 -3
-	vc_ops->enable_vport = NULL;
-	vc_ops->disable_vport = NULL;
-	vc_ops->destroy_vport = NULL;
+	vc_ops->get_reserved_vecs = iecm_get_reserved_vectors;
+	vc_ops->config_queues = iecm_send_config_queues_msg;
+	vc_ops->enable_queues = iecm_send_enable_queues_msg;
+	vc_ops->disable_queues = iecm_send_disable_queues_msg;
+	vc_ops->add_queues = iecm_send_add_queues_msg;
+	vc_ops->delete_queues = iecm_send_delete_queues_msg;
+	vc_ops->irq_map_unmap =

iecm_send_map_unmap_queue_vector_msg;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c void iecm_vc_ops_init(struct iecm_adapter *adapter) · line 2553

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +3 -0
+	vc_ops->enable_vport = iecm_send_enable_vport_msg;
+	vc_ops->disable_vport = iecm_send_disable_vport_msg;
+	vc_ops->destroy_vport = iecm_send_destroy_vport_msg;
 	vc_ops->get_ptype = NULL;
 	vc_ops->get_set_rss_key = NULL;
 	vc_ops->get_set_rss_lut = NULL;

Forgot to mention earlier, any reason to not declare this ops as static const and just assign a pointer then? I don't see any alternations here to e.g. fill callbacks with different functions or so.

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/include/iecm.h

drivers/net/ethernet/intel/include/iecm.h static inline bool __iecm_is_cap_ena(struct

Quoted 13 lines

index 994664dfe419..8dd6272db7d3 100644

drivers/net/ethernet/intel/include/iecm.h +2 -0
@@ -432,6 +432,8 @@ struct iecm_adapter {
 	u16 num_alloc_vport;
 	u16 next_vport;		/* Next free slot in pf->vport[] - 0-based! */
 
+	u16 max_queue_limit;	/* Max number of queues user can request */
+
 	struct delayed_work init_task; /* delayed init task */
 	struct workqueue_struct *init_wq;
 	u32 mb_wait_count;
@@ -510,6 +512,12 @@ static inline bool __iecm_is_cap_ena(struct

iecm_adapter *adapter, bool all,

drivers/net/ethernet/intel/include/iecm.h int iecm_min_wait_for_event(struct iecm_adapter

Quoted 22 lines
drivers/net/ethernet/intel/include/iecm.h +8 -0
 	return adapter->dev_ops.vc_ops.is_cap_ena(adapter, all, field, flag);
 }
 
+#define IECM_CAP_HSPLIT (\
+	VIRTCHNL2_CAP_RX_HSPLIT_AT_L2   |\
+	VIRTCHNL2_CAP_RX_HSPLIT_AT_L3   |\
+	VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V4 |\
+	VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V6)
+
 /**
  * iecm_is_reset_detected - check if we were reset at some point
  * @adapter: driver specific private structure
@@ -530,6 +538,8 @@ int iecm_init_dflt_mbx(struct iecm_adapter *adapter);
 void iecm_deinit_dflt_mbx(struct iecm_adapter *adapter);
 void iecm_vc_ops_init(struct iecm_adapter *adapter);
 int iecm_vc_core_init(struct iecm_adapter *adapter, int *vport_id);
+int iecm_get_reg_intr_vecs(struct iecm_vport *vport,
+			   struct iecm_vec_regs *reg_vals, int num_vecs);
 int iecm_wait_for_event(struct iecm_adapter *adapter,
 			enum iecm_vport_vc_state state,
 			enum iecm_vport_vc_state err_check);
@@ -537,6 +547,14 @@ int iecm_min_wait_for_event(struct iecm_adapter

*adapter,

drivers/net/ethernet/intel/include/iecm.h int iecm_recv_mb_msg(struct iecm_adapter

Quoted 15 lines
drivers/net/ethernet/intel/include/iecm.h +8 -0
 			    enum iecm_vport_vc_state state,
 			    enum iecm_vport_vc_state err_check);
 int iecm_send_get_caps_msg(struct iecm_adapter *adapter);
+int iecm_send_delete_queues_msg(struct iecm_vport *vport);
+int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,
+			     u16 num_complq, u16 num_rx_q, u16 num_rx_bufq);
+int iecm_send_config_tx_queues_msg(struct iecm_vport *vport);
+int iecm_send_config_rx_queues_msg(struct iecm_vport *vport);
+int iecm_send_enable_vport_msg(struct iecm_vport *vport);
+int iecm_send_disable_vport_msg(struct iecm_vport *vport);
+int iecm_send_destroy_vport_msg(struct iecm_vport *vport);
 int iecm_vport_params_buf_alloc(struct iecm_adapter *adapter);
 void iecm_vport_params_buf_rel(struct iecm_adapter *adapter);
 int iecm_get_vec_ids(struct iecm_adapter *adapter,
@@ -546,7 +564,11 @@ int iecm_recv_mb_msg(struct iecm_adapter

*adapter, enum virtchnl_ops op,

drivers/net/ethernet/intel/include/iecm.h int iecm_recv_mb_msg(struct iecm_adapter *adapter, enum virtchnl_ops op,

Quoted 10 lines
drivers/net/ethernet/intel/include/iecm.h +4 -0
 		     void *msg, int msg_size);
 int iecm_send_mb_msg(struct iecm_adapter *adapter, enum virtchnl_ops op,
 		     u16 msg_size, u8 *msg);
+void iecm_vport_set_hsplit(struct iecm_vport *vport, bool ena);
+int iecm_send_enable_channels_msg(struct iecm_vport *vport);
+int iecm_send_disable_channels_msg(struct iecm_vport *vport);
 int iecm_set_msg_pending(struct iecm_adapter *adapter,
 			 struct iecm_ctlq_msg *ctlq_msg,
 			 enum iecm_vport_vc_state err_enum);
+int iecm_send_map_unmap_queue_vector_msg(struct iecm_vport *vport,

bool map);

Review

Quoted 2 lines
drivers/net/ethernet/intel/include/iecm.h +0 -0
 #endif /* !_IECM_H_ */
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/include/iecm_txrx.h

Quoted 41 lines

index e1348011c991..448cae0bf6e7 100644

drivers/net/ethernet/intel/include/iecm_txrx.h +27 -0
@@ -81,6 +81,22 @@
 
 #define IECM_TX_COMPLQ_CLEAN_BUDGET	256
 
+enum iecm_queue_flags_t {
+	__IECM_Q_GEN_CHK,
+	__IECM_RFLQ_GEN_CHK,
+	__IECM_Q_FLOW_SCH_EN,
+	__IECM_Q_ETF_EN,
+	__IECM_Q_SW_MARKER,
+	__IECM_Q_VLAN_TAG_LOC_L2TAG1,
+	__IECM_Q_VLAN_TAG_LOC_L2TAG2,
+	__IECM_Q_FLAGS_NBITS,
+};
+
+struct iecm_vec_regs {
+	u32 dyn_ctl_reg;
+	u32 itrn_reg;
+};
+
 struct iecm_intr_reg {
 	u32 dyn_ctl;
 	u32 dyn_ctl_intena_m;
@@ -122,6 +138,186 @@ struct iecm_q_vector {
 	char name[IECM_INT_NAME_STR_LEN];
 };
 
+struct iecm_rx_queue_stats {
+	u64 packets;
+	u64 bytes;
+	u64 rsc_pkts;
+};
+
+struct iecm_tx_queue_stats {
+	u64 packets;
+	u64 bytes;
+	u64 lso_pkts;
+};

drivers/net/ethernet/intel/include/iecm_txrx.h struct iecm_q_vector { · line 161

Quoted 10 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +10 -0
+
+union iecm_queue_stats {
+	struct iecm_rx_queue_stats rx;
+	struct iecm_tx_queue_stats tx;
+};
+
+/* queue associated with a vport */
+struct iecm_queue {
+	struct device *dev;		/* Used for DMA mapping */
+	struct iecm_vport *vport;	/* Backreference to associated vport

*/

Quoted 47 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +47 -0
+	union {
+		struct iecm_txq_group *txq_grp;
+		struct iecm_rxq_group *rxq_grp;
+	};
+	/* bufq: Used as group id, either 0 or 1, on clean Buf Q uses this
+	 *       index to determine which group of refill queues to clean.
+	 *       Bufqs are use in splitq only.
+	 * txq: Index to map between Tx Q group and hot path Tx ptrs stored in
+	 *      vport.  Used in both single Q/split Q
+	 * rxq: Index to total rxq across groups, used for skb reporting
+	 */
+	u16 idx;
+	/* Used for both Q models single and split. In split Q model relevant
+	 * only to Tx Q and Rx Q
+	 */
+	u8 __iomem *tail;
+	/* Used in both single and split Q.  In single Q, Tx Q uses tx_buf and
+	 * Rx Q uses rx_buf.  In split Q, Tx Q uses tx_buf, Rx Q uses skb, and
+	 * Buf Q uses rx_buf.
+	 */
+	union {
+		struct iecm_tx_buf *tx_buf;
+		struct {
+			struct iecm_rx_buf *buf;
+			struct iecm_dma_mem **hdr_buf;
+		} rx_buf;
+		struct sk_buff *skb;
+	};
+	u16 q_type;
+	/* Queue id(Tx/Tx compl/Rx/Bufq) */
+	u32 q_id;
+	u16 desc_count;		/* Number of descriptors */
+
+	/* Relevant in both split & single Tx Q & Buf Q*/
+	u16 next_to_use;
+	/* In split q model only relevant for Tx Compl Q and Rx Q */
+	u16 next_to_clean;	/* used in interrupt processing */
+	/* Used only for Rx. In split Q model only relevant to Rx Q */
+	u16 next_to_alloc;
+	/* Generation bit check stored, as HW flips the bit at Queue end */
+	DECLARE_BITMAP(flags, __IECM_Q_FLAGS_NBITS);
+
+	union iecm_queue_stats q_stats;
+	struct u64_stats_sync stats_sync;
+
+	bool rx_hsplit_en;
+

drivers/net/ethernet/intel/include/iecm_txrx.h struct iecm_q_vector {

Quoted 10 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +10 -0
+	u16 rx_hbuf_size;	/* Header buffer size */
+	u16 rx_buf_size;
+	u16 rx_max_pkt_size;
+	u16 rx_buf_stride;
+	u8 rx_buffer_low_watermark;
+	u64 rxdids;
+	/* Used for both Q models single and split. In split Q model relavant
+	 * only to Tx compl Q and Rx compl Q
+	 */
+	struct iecm_q_vector *q_vector;	/* Backreference to associated vector

*/

drivers/net/ethernet/intel/include/iecm_txrx.h struct iecm_q_vector {

Quoted 6 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +6 -0
+	unsigned int size;		/* length of descriptor ring in bytes */
+	dma_addr_t dma;			/* physical address of ring */
+	void *desc_ring;		/* Descriptor ring memory */
+
+	u16 tx_buf_key;			/* 16 bit unique "identifier" (index)
+					 * to be used as the completion tag

when

drivers/net/ethernet/intel/include/iecm_txrx.h struct iecm_q_vector {

Quoted 11 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +11 -0
+					 * queue is using flow based scheduling
+					 */
+	u16 tx_max_bufs;		/* Max buffers that can be transmitted
+					 * with scatter-gather
+					 */
+	DECLARE_HASHTABLE(sched_buf_hash, 12);
+} ____cacheline_internodealigned_in_smp;
+
+/* Software queues are used in splitq mode to manage buffers between rxq
+ * producer and the bufq consumer.  These are required in order to maintain a
+ * lockless buffer management system and are strictly software only

constructs.

drivers/net/ethernet/intel/include/iecm_txrx.h struct iecm_q_vector { · line 243

Quoted 8 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +8 -0
+ */
+struct iecm_sw_queue {
+	u16 next_to_clean ____cacheline_aligned_in_smp;
+	u16 next_to_alloc ____cacheline_aligned_in_smp;
+	u16 next_to_use ____cacheline_aligned_in_smp;
+	DECLARE_BITMAP(flags, __IECM_Q_FLAGS_NBITS)
+		____cacheline_aligned_in_smp;
+	u16 *ring ____cacheline_aligned_in_smp;

This will result in this part being FIVE cachelines long for 3 * 2 + 8 + 8 = 22 bytes, i.e. 320 bytes for 22! Just making the entire structure cacheline-aligned after its declaration is enough, these ones are not even an overkill, it's an overslaughter.

Quoted 77 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +77 -0
+	u16 desc_count;
+	u16 buf_size;
+	struct device *dev;
+} ____cacheline_internodealigned_in_smp;
+
+/* Splitq only.  iecm_rxq_set associates an rxq with at an array of refillqs.
+ * Each rxq needs a refillq to return used buffers back to the respective bufq.
+ * Bufqs then clean these refillqs for buffers to give to hardware.
+ */
+struct iecm_rxq_set {
+	struct iecm_queue rxq;
+	/* refillqs assoc with bufqX mapped to this rxq */
+	struct iecm_sw_queue *refillq0;
+	struct iecm_sw_queue *refillq1;
+};
+
+/* Splitq only.  iecm_bufq_set associates a bufq to an array of refillqs.
+ * In this bufq_set, there will be one refillq for each rxq in this rxq_group.
+ * Used buffers received by rxqs will be put on refillqs which bufqs will
+ * clean to return new buffers back to hardware.
+ *
+ * Buffers needed by some number of rxqs associated in this rxq_group are
+ * managed by at most two bufqs (depending on performance configuration).
+ */
+struct iecm_bufq_set {
+	struct iecm_queue bufq;
+	/* This is always equal to num_rxq_sets in iecm_rxq_group */
+	int num_refillqs;
+	struct iecm_sw_queue *refillqs;
+};
+
+/* In singleq mode, an rxq_group is simply an array of rxqs.  In splitq, a
+ * rxq_group contains all the rxqs, bufqs and refillqs needed to
+ * manage buffers in splitq mode.
+ */
+struct iecm_rxq_group {
+	struct iecm_vport *vport; /* back pointer */
+
+	union {
+		struct {
+			int num_rxq;
+			/* store queue pointers */
+			struct iecm_queue *rxqs[IECM_LARGE_MAX_Q];
+		} singleq;
+		struct {
+			int num_rxq_sets;
+			/* store queue pointers */
+			struct iecm_rxq_set *rxq_sets[IECM_LARGE_MAX_Q];
+			struct iecm_bufq_set *bufq_sets;
+		} splitq;
+	};
+};
+
+/* Between singleq and splitq, a txq_group is largely the same except for the
+ * complq.  In splitq a single complq is responsible for handling completions
+ * for some number of txqs associated in this txq_group.
+ */
+struct iecm_txq_group {
+	struct iecm_vport *vport; /* back pointer */
+
+	int num_txq;
+	/* store queue pointers */
+	struct iecm_queue *txqs[IECM_LARGE_MAX_Q];
+
+	/* splitq only */
+	struct iecm_queue *complq;
+};
+
+struct iecm_adapter;
+
+void iecm_vport_init_num_qs(struct iecm_vport *vport,
+			    struct virtchnl2_create_vport *vport_msg);
+void iecm_vport_calc_num_q_desc(struct iecm_vport *vport);
+void iecm_vport_calc_total_qs(struct iecm_adapter *adapter,
+			      struct virtchnl2_create_vport *vport_msg);
+void iecm_vport_calc_num_q_groups(struct iecm_vport *vport);
+void iecm_vport_calc_num_q_vec(struct iecm_vport *vport);
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +0 -1
 irqreturn_t
 iecm_vport_intr_clean_queues(int __always_unused irq, void *data);
 #endif /* !_IECM_TXRX_H_ */
--

2.33.0

Thanks,
Al

Please don't forget to fix parts you didn't comment such as cacheline and const ops issues.

Thanks,
Al

author
#31 lore raw

PATCH 7/19 iecm: finish virtchnl messages

In reply to Alan Brady

This adds the rest of the needed virtchnl messages mostly related to negotiating ptypes and initializing queue registers.

---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    |   21 +-
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   |  226 +++-
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   | 1187 ++++++++++++++++-
 drivers/net/ethernet/intel/include/iecm.h     |   36 +
 .../net/ethernet/intel/include/iecm_txrx.h    |  198 ++-
 5 files changed, 1635 insertions(+), 33 deletions(-)
drivers/net/ethernet/intel/iecm/iecm_lib.c +20 -1
index 4e9cc7f2d138..aab8ee40424e 100644
@@ -10,6 +10,25 @@ const char * const iecm_vport_vc_state_str[] = {
 };
 EXPORT_SYMBOL(iecm_vport_vc_state_str);
 
+/**
+ * iecm_is_feature_ena - Determine if a particular feature is enabled
+ * @vport: vport to check
+ * @feature: netdev flag to check
+ *
+ * Returns true or false if a particular feature is enabled.
+ */
+bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)
+{
+	bool ena;
+
+	switch (feature) {
+	default:
+		ena = vport->netdev->features & feature;
+		break;
+	}
+	return ena;
+}
+
 /**
  * iecm_cfg_hw - Initialize HW struct
  * @adapter: adapter to setup hw struct for
@@ -132,7 +151,7 @@ iecm_vport_alloc(struct iecm_adapter *adapter, int vport_id)
 	adapter->num_alloc_vport++;
 
 	/* Setup default MSIX irq handler for the vport */
-	vport->irq_q_handler = iecm_vport_intr_clean_queues;
+	vport->irq_q_handler = NULL;
 	vport->q_vector_base = IECM_NONQ_VEC;
 
 	mutex_init(&vport->stop_mutex);
drivers/net/ethernet/intel/iecm/iecm_txrx.c +212 -14

234 lines not on this page · raw message

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +1172 -15

1,241 lines not on this page · raw message

drivers/net/ethernet/intel/include/iecm.h +36 -0
index 8dd6272db7d3..d736db65da06 100644
@@ -346,6 +346,7 @@ struct iecm_vport {
 	int num_rxq_grp;
 	struct iecm_rxq_group *rxq_grps;
 	u32 rxq_model;
+	struct iecm_rx_ptype_decoded rx_ptype_lkup[IECM_RX_MAX_PTYPE];
 
 	struct iecm_adapter *adapter;
 	struct net_device *netdev;
@@ -382,6 +383,30 @@ enum iecm_user_flags {
 	__IECM_USER_FLAGS_NBITS,
 };
 
+#define IECM_GET_PTYPE_SIZE(p) \
+	(sizeof(struct virtchnl2_ptype) + \
+	(((p)->proto_id_count ? ((p)->proto_id_count - 1) : 0) * sizeof(u16)))
+
+#define IECM_TUN_IP_GRE (\
+	IECM_PTYPE_TUNNEL_IP |\
+	IECM_PTYPE_TUNNEL_IP_GRENAT)
+
+#define IECM_TUN_IP_GRE_MAC (\
+	IECM_TUN_IP_GRE |\
+	IECM_PTYPE_TUNNEL_IP_GRENAT_MAC)
+
+enum iecm_tunnel_state {
+	IECM_PTYPE_TUNNEL_IP                    = BIT(0),
+	IECM_PTYPE_TUNNEL_IP_GRENAT             = BIT(1),
+	IECM_PTYPE_TUNNEL_IP_GRENAT_MAC         = BIT(2),
+	IECM_PTYPE_TUNNEL_IP_GRENAT_MAC_VLAN    = BIT(3),
+};
+
+struct iecm_ptype_state {
+	bool outer_ip;
+	bool outer_frag;
+	u8 tunnel_state;
+};
 /* User defined configuration values */
 struct iecm_user_config_data {
 	u32 num_req_tx_qs; /* user requested TX queues through ethtool */
@@ -534,6 +559,7 @@ int iecm_probe(struct pci_dev *pdev,
 	       const struct pci_device_id __always_unused *ent,
 	       struct iecm_adapter *adapter);
 void iecm_remove(struct pci_dev *pdev);
+void iecm_vport_adjust_qs(struct iecm_vport *vport);
 int iecm_init_dflt_mbx(struct iecm_adapter *adapter);
 void iecm_deinit_dflt_mbx(struct iecm_adapter *adapter);
 void iecm_vc_ops_init(struct iecm_adapter *adapter);
@@ -555,8 +581,15 @@ int iecm_send_config_rx_queues_msg(struct iecm_vport *vport);
 int iecm_send_enable_vport_msg(struct iecm_vport *vport);
 int iecm_send_disable_vport_msg(struct iecm_vport *vport);
 int iecm_send_destroy_vport_msg(struct iecm_vport *vport);
+int iecm_send_get_rx_ptype_msg(struct iecm_vport *vport);
+int iecm_send_get_set_rss_key_msg(struct iecm_vport *vport, bool get);
+int iecm_send_get_set_rss_lut_msg(struct iecm_vport *vport, bool get);
+int iecm_send_get_set_rss_hash_msg(struct iecm_vport *vport, bool get);
+int iecm_send_dealloc_vectors_msg(struct iecm_adapter *adapter);
+int iecm_send_alloc_vectors_msg(struct iecm_adapter *adapter, u16 num_vectors);
 int iecm_vport_params_buf_alloc(struct iecm_adapter *adapter);
 void iecm_vport_params_buf_rel(struct iecm_adapter *adapter);
+int iecm_send_get_stats_msg(struct iecm_vport *vport);
 int iecm_get_vec_ids(struct iecm_adapter *adapter,
 		     u16 *vecids, int num_vecids,
 		     struct virtchnl2_vector_chunks *chunks);
@@ -567,6 +600,9 @@ int iecm_send_mb_msg(struct iecm_adapter *adapter, enum virtchnl_ops op,
 void iecm_vport_set_hsplit(struct iecm_vport *vport, bool ena);
 int iecm_send_enable_channels_msg(struct iecm_vport *vport);
 int iecm_send_disable_channels_msg(struct iecm_vport *vport);
+bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature);
+int iecm_check_descs(struct iecm_vport *vport, u64 rx_desc_ids,
+		     u64 tx_desc_ids, u16 rxq_model, u16 txq_model);
 int iecm_set_msg_pending(struct iecm_adapter *adapter,
 			 struct iecm_ctlq_msg *ctlq_msg,
 			 enum iecm_vport_vc_state err_enum);
drivers/net/ethernet/intel/include/iecm_txrx.h +195 -3

216 lines not on this page · raw message

Signature · 1 line
2.33.0
#32 lore raw

PATCH 7/19 iecm: finish virtchnl messages

From: Alan Brady <[email protected]>
Date: Thu, 27 Jan 2022 16:09:57 -0800

Quoted 33 lines

This adds the rest of the needed virtchnl messages mostly related to negotiating ptypes and initializing queue registers.

---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    |   21 +-
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   |  226 +++-
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   | 1187 ++++++++++++++++-
 drivers/net/ethernet/intel/include/iecm.h     |   36 +
 .../net/ethernet/intel/include/iecm_txrx.h    |  198 ++-
 5 files changed, 1635 insertions(+), 33 deletions(-)
drivers/net/ethernet/intel/iecm/iecm_lib.c +8 -0
index 4e9cc7f2d138..aab8ee40424e 100644
@@ -10,6 +10,25 @@ const char * const iecm_vport_vc_state_str[] = {
 };
 EXPORT_SYMBOL(iecm_vport_vc_state_str);
 
+/**
+ * iecm_is_feature_ena - Determine if a particular feature is enabled
+ * @vport: vport to check
+ * @feature: netdev flag to check
+ *
+ * Returns true or false if a particular feature is enabled.
+ */
+bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)

drivers/net/ethernet/intel/iecm/iecm_lib.c const char * const iecm_vport_vc_state_str[] = { · line 30

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+{
+	bool ena;
+
+	switch (feature) {
+	default:
+		ena = vport->netdev->features & feature;
+		break;
+	}
+	return ena;
+}

This makes absolutely no sense, please rewrite to

	return vport->netdev->features & feature;

If it will be expanded later, convert it to a switch-case only then.

Quoted 298 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +2 -1
+
 /**
  * iecm_cfg_hw - Initialize HW struct
  * @adapter: adapter to setup hw struct for
@@ -132,7 +151,7 @@ iecm_vport_alloc(struct iecm_adapter *adapter, int vport_id)
 	adapter->num_alloc_vport++;
 
 	/* Setup default MSIX irq handler for the vport */
-	vport->irq_q_handler = iecm_vport_intr_clean_queues;
+	vport->irq_q_handler = NULL;
 	vport->q_vector_base = IECM_NONQ_VEC;
 
 	mutex_init(&vport->stop_mutex);
drivers/net/ethernet/intel/iecm/iecm_txrx.c +212 -14
index 2dfb0be002e3..bd0cfd89bf03 100644
@@ -3,22 +3,220 @@
 
 #include "iecm.h"
 
-/**
- * iecm_vport_intr_clean_queues - MSIX mode Interrupt Handler
- * @irq: interrupt number
- * @data: pointer to a q_vector
- *
- */
-irqreturn_t
-iecm_vport_intr_clean_queues(int __always_unused irq, void *data)
-{
-	struct iecm_q_vector *q_vector = (struct iecm_q_vector *)data;
+const struct iecm_rx_ptype_decoded iecm_ptype_lookup[IECM_RX_MAX_PTYPE] = {
+	/* ptype indices are dynamic and package dependent. Indices represented
+	 * in this lookup table are for reference and will be replaced by the
+	 * values which CP sends. Also these values are static for older
+	 * versions of virtchnl and if VIRTCHNL2_CAP_PTYPE is not set in
+	 * virtchnl2_get_capabilities.
+	 */
+	/* L2 Packet types */
+	IECM_PTT_UNUSED_ENTRY(0),
+	IECM_PTT(1,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
+	IECM_PTT(2,  L2, NONE, NOF, NONE, NONE, NOF, TS,   PAY2),
+	IECM_PTT(3,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
+	IECM_PTT_UNUSED_ENTRY(4),
+	IECM_PTT_UNUSED_ENTRY(5),
+	IECM_PTT(6,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
+	IECM_PTT(7,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
+	IECM_PTT_UNUSED_ENTRY(8),
+	IECM_PTT_UNUSED_ENTRY(9),
+	IECM_PTT(10, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
+	IECM_PTT(11, L2, NONE, NOF, NONE, NONE, NOF, NONE, NONE),
+	IECM_PTT(12, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(13, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(14, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(15, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(16, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(17, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(18, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(19, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(20, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(21, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
 
-	q_vector->total_events++;
-	napi_schedule(&q_vector->napi);
+	/* Non Tunneled IPv4 */
+	IECM_PTT(22, IP, IPV4, FRG, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(23, IP, IPV4, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(24, IP, IPV4, NOF, NONE, NONE, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(25),
+	IECM_PTT(26, IP, IPV4, NOF, NONE, NONE, NOF, TCP,  PAY4),
+	IECM_PTT(27, IP, IPV4, NOF, NONE, NONE, NOF, SCTP, PAY4),
+	IECM_PTT(28, IP, IPV4, NOF, NONE, NONE, NOF, ICMP, PAY4),
 
-	return IRQ_HANDLED;
-}
+	/* IPv4 --> IPv4 */
+	IECM_PTT(29, IP, IPV4, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
+	IECM_PTT(30, IP, IPV4, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
+	IECM_PTT(31, IP, IPV4, NOF, IP_IP, IPV4, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(32),
+	IECM_PTT(33, IP, IPV4, NOF, IP_IP, IPV4, NOF, TCP,  PAY4),
+	IECM_PTT(34, IP, IPV4, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
+	IECM_PTT(35, IP, IPV4, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
+
+	/* IPv4 --> IPv6 */
+	IECM_PTT(36, IP, IPV4, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
+	IECM_PTT(37, IP, IPV4, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
+	IECM_PTT(38, IP, IPV4, NOF, IP_IP, IPV6, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(39),
+	IECM_PTT(40, IP, IPV4, NOF, IP_IP, IPV6, NOF, TCP,  PAY4),
+	IECM_PTT(41, IP, IPV4, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
+	IECM_PTT(42, IP, IPV4, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
+
+	/* IPv4 --> GRE/NAT */
+	IECM_PTT(43, IP, IPV4, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
+
+	/* IPv4 --> GRE/NAT --> IPv4 */
+	IECM_PTT(44, IP, IPV4, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
+	IECM_PTT(45, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
+	IECM_PTT(46, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(47),
+	IECM_PTT(48, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, TCP,  PAY4),
+	IECM_PTT(49, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
+	IECM_PTT(50, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
+
+	/* IPv4 --> GRE/NAT --> IPv6 */
+	IECM_PTT(51, IP, IPV4, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
+	IECM_PTT(52, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
+	IECM_PTT(53, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(54),
+	IECM_PTT(55, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, TCP,  PAY4),
+	IECM_PTT(56, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
+	IECM_PTT(57, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
+
+	/* IPv4 --> GRE/NAT --> MAC */
+	IECM_PTT(58, IP, IPV4, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
+
+	/* IPv4 --> GRE/NAT --> MAC --> IPv4 */
+	IECM_PTT(59, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
+	IECM_PTT(60, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
+	IECM_PTT(61, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(62),
+	IECM_PTT(63, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP,  PAY4),
+	IECM_PTT(64, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
+	IECM_PTT(65, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
+
+	/* IPv4 --> GRE/NAT -> MAC --> IPv6 */
+	IECM_PTT(66, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
+	IECM_PTT(67, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
+	IECM_PTT(68, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(69),
+	IECM_PTT(70, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP,  PAY4),
+	IECM_PTT(71, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
+	IECM_PTT(72, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
+
+	/* IPv4 --> GRE/NAT --> MAC/VLAN */
+	IECM_PTT(73, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
+
+	/* IPv4 ---> GRE/NAT -> MAC/VLAN --> IPv4 */
+	IECM_PTT(74, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
+	IECM_PTT(75, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
+	IECM_PTT(76, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(77),
+	IECM_PTT(78, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP,  PAY4),
+	IECM_PTT(79, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
+	IECM_PTT(80, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
+
+	/* IPv4 -> GRE/NAT -> MAC/VLAN --> IPv6 */
+	IECM_PTT(81, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
+	IECM_PTT(82, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
+	IECM_PTT(83, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(84),
+	IECM_PTT(85, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP,  PAY4),
+	IECM_PTT(86, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
+	IECM_PTT(87, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
+
+	/* Non Tunneled IPv6 */
+	IECM_PTT(88, IP, IPV6, FRG, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(89, IP, IPV6, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(90, IP, IPV6, NOF, NONE, NONE, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(91),
+	IECM_PTT(92, IP, IPV6, NOF, NONE, NONE, NOF, TCP,  PAY4),
+	IECM_PTT(93, IP, IPV6, NOF, NONE, NONE, NOF, SCTP, PAY4),
+	IECM_PTT(94, IP, IPV6, NOF, NONE, NONE, NOF, ICMP, PAY4),
+
+	/* IPv6 --> IPv4 */
+	IECM_PTT(95,  IP, IPV6, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
+	IECM_PTT(96,  IP, IPV6, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
+	IECM_PTT(97,  IP, IPV6, NOF, IP_IP, IPV4, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(98),
+	IECM_PTT(99,  IP, IPV6, NOF, IP_IP, IPV4, NOF, TCP,  PAY4),
+	IECM_PTT(100, IP, IPV6, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
+	IECM_PTT(101, IP, IPV6, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
+
+	/* IPv6 --> IPv6 */
+	IECM_PTT(102, IP, IPV6, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
+	IECM_PTT(103, IP, IPV6, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
+	IECM_PTT(104, IP, IPV6, NOF, IP_IP, IPV6, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(105),
+	IECM_PTT(106, IP, IPV6, NOF, IP_IP, IPV6, NOF, TCP,  PAY4),
+	IECM_PTT(107, IP, IPV6, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
+	IECM_PTT(108, IP, IPV6, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
+
+	/* IPv6 --> GRE/NAT */
+	IECM_PTT(109, IP, IPV6, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
+
+	/* IPv6 --> GRE/NAT -> IPv4 */
+	IECM_PTT(110, IP, IPV6, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
+	IECM_PTT(111, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
+	IECM_PTT(112, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(113),
+	IECM_PTT(114, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, TCP,  PAY4),
+	IECM_PTT(115, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
+	IECM_PTT(116, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
+
+	/* IPv6 --> GRE/NAT -> IPv6 */
+	IECM_PTT(117, IP, IPV6, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
+	IECM_PTT(118, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
+	IECM_PTT(119, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(120),
+	IECM_PTT(121, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, TCP,  PAY4),
+	IECM_PTT(122, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
+	IECM_PTT(123, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
+
+	/* IPv6 --> GRE/NAT -> MAC */
+	IECM_PTT(124, IP, IPV6, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
+
+	/* IPv6 --> GRE/NAT -> MAC -> IPv4 */
+	IECM_PTT(125, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
+	IECM_PTT(126, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
+	IECM_PTT(127, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(128),
+	IECM_PTT(129, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP,  PAY4),
+	IECM_PTT(130, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
+	IECM_PTT(131, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
+
+	/* IPv6 --> GRE/NAT -> MAC -> IPv6 */
+	IECM_PTT(132, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
+	IECM_PTT(133, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
+	IECM_PTT(134, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(135),
+	IECM_PTT(136, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP,  PAY4),
+	IECM_PTT(137, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
+	IECM_PTT(138, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
+
+	/* IPv6 --> GRE/NAT -> MAC/VLAN */
+	IECM_PTT(139, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
+
+	/* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv4 */
+	IECM_PTT(140, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
+	IECM_PTT(141, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
+	IECM_PTT(142, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(143),
+	IECM_PTT(144, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP,  PAY4),
+	IECM_PTT(145, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
+	IECM_PTT(146, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
+
+	/* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv6 */
+	IECM_PTT(147, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
+	IECM_PTT(148, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
+	IECM_PTT(149, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(150),
+	IECM_PTT(151, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP,  PAY4),
+	IECM_PTT(152, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
+	IECM_PTT(153, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
+
+	/* rest of the entries are unused */
+};
+EXPORT_SYMBOL(iecm_ptype_lookup);
 
 /**
  * iecm_vport_init_num_qs - Initialize number of queues
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +31 -0
index d8152e657e24..c4ae56897d1b 100644
@@ -859,6 +859,15 @@ static int iecm_recv_get_caps_msg(struct iecm_adapter *adapter)
 				sizeof(struct virtchnl2_get_capabilities));
 }
 
+/**
+ * iecm_vport_init_max_qs - Initialize max queues supported on this device
+ * @adapter: Driver specific private structure
+ */
+static void iecm_vport_init_max_qs(struct iecm_adapter *adapter)
+{
+	adapter->max_queue_limit = IECM_MAX_Q;
+}
+
 /**
  * iecm_get_reg_intr_vecs - Get vector queue register offset
  * @vport: virtual port structure
@@ -901,6 +910,199 @@ int iecm_get_reg_intr_vecs(struct iecm_vport *vport,
 }
 EXPORT_SYMBOL(iecm_get_reg_intr_vecs);
 
+/**
+ * iecm_vport_get_q_reg - Get the queue registers for the vport
+ * @reg_vals: register values needing to be set
+ * @num_regs: amount we expect to fill
+ * @q_type: queue model
+ * @chunks: queue regs received over mailbox
+ */
+static int
+iecm_vport_get_q_reg(u32 *reg_vals, int num_regs, u32 q_type,
+		     struct virtchnl2_queue_reg_chunks *chunks)
+{
+	u16 num_chunks = le16_to_cpu(chunks->num_chunks);
+	int reg_filled = 0, i;
+	u32 reg_val;
+	u16 num_q;
+
+	while (num_chunks) {
+		struct virtchnl2_queue_reg_chunk *chunk = &chunks->chunks[num_chunks - 1];
+
+		if (le32_to_cpu(chunk->type) == q_type) {
+			num_q = le32_to_cpu(chunk->num_queues);
+			reg_val = le64_to_cpu(chunk->qtail_reg_start);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_get_reg_intr_vecs(struct iecm_vport *vport, · line 944

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+			for (i = 0; i < num_q; i++) {
+				if (reg_filled == num_regs)
+					break;
+				reg_vals[reg_filled++] = reg_val;
+				reg_val +=
+					le32_to_cpu(chunk->qtail_reg_spacing);
+			}
+		}
+		num_chunks--;
+	}
	while (num_chunks--) {
		struct ... = ... [num_chunks];

		if (le32_to_cpu(chunk->type) != q_type)
			continue;

		...
	}

-1 indent level, -complexity.

Quoted 1,047 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +1005 -0
+
+	return reg_filled;
+}
+
+/**
+ * __iecm_queue_reg_init - initialize queue registers
+ * @vport: virtual port structure
+ * @reg_vals: registers we are initializing
+ * @num_regs: how many registers there are in total
+ * @q_type: queue model
+ *
+ * Return number of queues that are initialized
+ */
+static int
+__iecm_queue_reg_init(struct iecm_vport *vport, u32 *reg_vals,
+		      int num_regs, u32 q_type)
+{
+	struct iecm_hw *hw = &vport->adapter->hw;
+	struct iecm_queue *q;
+	int i, j, k = 0;
+
+	switch (q_type) {
+	case VIRTCHNL2_QUEUE_TYPE_TX:
+		for (i = 0; i < vport->num_txq_grp; i++) {
+			struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+
+			for (j = 0; j < tx_qgrp->num_txq; j++) {
+				if (k == num_regs)
+					break;
+
+				tx_qgrp->txqs[j]->tail =
+				  (__force u8 __iomem *)(hw->hw_addr +
+							 reg_vals[k]);
+				k++;
+			}
+		}
+		break;
+	case VIRTCHNL2_QUEUE_TYPE_RX:
+		for (i = 0; i < vport->num_rxq_grp; i++) {
+			struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+			int num_rxq = rx_qgrp->singleq.num_rxq;
+
+			for (j = 0; j < num_rxq; j++) {
+				if (k == num_regs)
+					break;
+
+				q = rx_qgrp->singleq.rxqs[j];
+				q->tail = (__force u8 __iomem *)(hw->hw_addr +
+								 reg_vals[k]);
+				k++;
+			}
+		}
+		break;
+	case VIRTCHNL2_QUEUE_TYPE_RX_BUFFER:
+		for (i = 0; i < vport->num_rxq_grp; i++) {
+			struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++) {
+				if (k == num_regs)
+					break;
+
+				q = &rx_qgrp->splitq.bufq_sets[j].bufq;
+				q->tail = (__force u8 __iomem *)(hw->hw_addr +
+								 reg_vals[k]);
+				k++;
+			}
+		}
+		break;
+	default:
+		break;
+	}
+
+	return k;
+}
+
+/**
+ * iecm_queue_reg_init - initialize queue registers
+ * @vport: virtual port structure
+ *
+ * Return 0 on success, negative on failure
+ */
+static int iecm_queue_reg_init(struct iecm_vport *vport)
+{
+	struct virtchnl2_create_vport *vport_params;
+	struct virtchnl2_queue_reg_chunks *chunks;
+	int num_regs, ret = 0;
+	u32 *reg_vals;
+
+	/* We may never deal with more than 256 same type of queues */
+	reg_vals = kmalloc(sizeof(void *) * IECM_LARGE_MAX_Q,
+			   GFP_KERNEL);
+	if (!reg_vals)
+		return -ENOMEM;
+
+	if (vport->adapter->config_data.req_qs_chunks) {
+		struct virtchnl2_add_queues *vc_aq =
+		  (struct virtchnl2_add_queues *)
+		  vport->adapter->config_data.req_qs_chunks;
+		chunks = &vc_aq->chunks;
+	} else {
+		vport_params = (struct virtchnl2_create_vport *)
+			vport->adapter->vport_params_recvd[0];
+		chunks = &vport_params->chunks;
+	}
+
+	/* Initialize Tx queue tail register address */
+	num_regs = iecm_vport_get_q_reg(reg_vals, IECM_LARGE_MAX_Q,
+					VIRTCHNL2_QUEUE_TYPE_TX,
+					chunks);
+	if (num_regs < vport->num_txq) {
+		ret = -EINVAL;
+		goto free_reg_vals;
+	}
+
+	num_regs = __iecm_queue_reg_init(vport, reg_vals, num_regs,
+					 VIRTCHNL2_QUEUE_TYPE_TX);
+	if (num_regs < vport->num_txq) {
+		ret = -EINVAL;
+		goto free_reg_vals;
+	}
+
+	/* Initialize Rx/buffer queue tail register address based on Rx queue
+	 * model
+	 */
+	if (iecm_is_queue_model_split(vport->rxq_model)) {
+		num_regs = iecm_vport_get_q_reg(reg_vals, IECM_LARGE_MAX_Q,
+						VIRTCHNL2_QUEUE_TYPE_RX_BUFFER,
+						chunks);
+		if (num_regs < vport->num_bufq) {
+			ret = -EINVAL;
+			goto free_reg_vals;
+		}
+
+		num_regs = __iecm_queue_reg_init(vport, reg_vals, num_regs,
+						 VIRTCHNL2_QUEUE_TYPE_RX_BUFFER);
+		if (num_regs < vport->num_bufq) {
+			ret = -EINVAL;
+			goto free_reg_vals;
+		}
+	} else {
+		num_regs = iecm_vport_get_q_reg(reg_vals, IECM_LARGE_MAX_Q,
+						VIRTCHNL2_QUEUE_TYPE_RX,
+						chunks);
+		if (num_regs < vport->num_rxq) {
+			ret = -EINVAL;
+			goto free_reg_vals;
+		}
+
+		num_regs = __iecm_queue_reg_init(vport, reg_vals, num_regs,
+						 VIRTCHNL2_QUEUE_TYPE_RX);
+		if (num_regs < vport->num_rxq) {
+			ret = -EINVAL;
+			goto free_reg_vals;
+		}
+	}
+
+free_reg_vals:
+	kfree(reg_vals);
+	return ret;
+}
+
 /**
  * iecm_send_create_vport_msg - Send virtchnl create vport message
  * @adapter: Driver specific private structure
@@ -943,6 +1145,66 @@ static int iecm_send_create_vport_msg(struct iecm_adapter *adapter)
 				(u8 *)vport_msg);
 }
 
+/**
+ * iecm_check_descs - Verify we have the descriptor support required
+ * @vport: virtual port structure
+ * @rx_desc_ids: Rx descriptor ids to check
+ * @tx_desc_ids: Tx descriptor ids to check
+ * @rxq_model: Rx queue model
+ * @txq_model: Tx queue model
+ *
+ * Returns 0 on success, negative if we didn't get sufficient descriptor
+ * support.
+ */
+int iecm_check_descs(struct iecm_vport *vport, u64 rx_desc_ids,
+		     u64 tx_desc_ids, u16 rxq_model, u16 txq_model)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+
+	if (rxq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) {
+		if (!(rx_desc_ids & VIRTCHNL2_RXDID_1_FLEX_SPLITQ_M)) {
+			dev_err(&adapter->pdev->dev, "No supported RX descriptors provided");
+			return -EINVAL;
+		}
+	} else {
+		if (!(rx_desc_ids & VIRTCHNL2_RXDID_2_FLEX_SQ_NIC_M))
+			vport->base_rxd = true;
+	}
+
+	if (txq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) {
+#define MIN_SUPPORT_TXDID (\
+		VIRTCHNL2_TXDID_FLEX_FLOW_SCHED |\
+		VIRTCHNL2_TXDID_FLEX_TSO_CTX |\
+		VIRTCHNL2_TXDID_FLEX_DATA)
+		if ((tx_desc_ids & MIN_SUPPORT_TXDID) != MIN_SUPPORT_TXDID) {
+			dev_err(&adapter->pdev->dev, "Minimum TX descriptor support not provided");
+			return -EINVAL;
+		}
+	}
+	return 0;
+}
+EXPORT_SYMBOL(iecm_check_descs);
+
+/**
+ * iecm_get_supported_desc_ids - Get supported Rx and Tx descriptor ids
+ * @vport: virtual port structure
+ *
+ * Return 0 on success, error on failure
+ */
+static int iecm_get_supported_desc_ids(struct iecm_vport *vport)
+{
+	struct virtchnl2_create_vport *vport_msg;
+
+	vport_msg = (struct virtchnl2_create_vport *)
+			vport->adapter->vport_params_recvd[0];
+	vport_msg->rx_desc_ids = cpu_to_le64(VIRTCHNL2_RXDID_1_FLEX_SPLITQ_M);
+	vport_msg->tx_desc_ids = cpu_to_le64(MIN_SUPPORT_TXDID);
+
+	return iecm_check_descs(vport, le64_to_cpu(vport_msg->rx_desc_ids),
+				le64_to_cpu(vport_msg->tx_desc_ids),
+				vport->rxq_model, vport->txq_model);
+}
+
 /**
  * iecm_recv_create_vport_msg - Receive virtchnl create vport message
  * @adapter: Driver specific private structure
@@ -1333,6 +1595,9 @@ int iecm_send_config_rx_queues_msg(struct iecm_vport *vport)
 					bufq->rx_buf_stride;
 				qi[k].rx_buffer_low_watermark =
 					cpu_to_le16(bufq->rx_buffer_low_watermark);
+				if (iecm_is_feature_ena(vport, NETIF_F_GRO_HW))
+					qi[k].qflags |=
+						cpu_to_le16(VIRTCHNL2_RXQ_RSC);
 			}
 		}
 
@@ -1361,6 +1626,9 @@ int iecm_send_config_rx_queues_msg(struct iecm_vport *vport)
 					qi[k].hdr_buffer_size =
 						cpu_to_le16(rxq->rx_hbuf_size);
 				}
+				if (iecm_is_feature_ena(vport, NETIF_F_GRO_HW))
+					qi[k].qflags |=
+						cpu_to_le16(VIRTCHNL2_RXQ_RSC);
 			} else {
 				rxq = rx_qgrp->singleq.rxqs[j];
 			}
@@ -1968,6 +2236,765 @@ int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,
 	return err;
 }
 
+/**
+ * iecm_send_alloc_vectors_msg - Send virtchnl alloc vectors message
+ * @adapter: Driver specific private structure
+ * @num_vectors: number of vectors to be allocated
+ *
+ * Returns 0 on success, negative on failure.
+ */
+int iecm_send_alloc_vectors_msg(struct iecm_adapter *adapter, u16 num_vectors)
+{
+	struct virtchnl2_alloc_vectors *alloc_vec;
+	struct virtchnl2_alloc_vectors ac = {0};
+	int size, err;
+
+	ac.num_vectors = cpu_to_le16(num_vectors);
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_ALLOC_VECTORS,
+			       sizeof(ac), (u8 *)&ac);
+	if (err)
+		return err;
+
+	err = iecm_wait_for_event(adapter, IECM_VC_ALLOC_VECTORS,
+				  IECM_VC_ALLOC_VECTORS_ERR);
+	if (err)
+		return err;
+
+	size = sizeof(struct virtchnl2_alloc_vectors) +
+		((num_vectors - 1) *
+		sizeof(struct virtchnl2_vector_chunk));
+
+	kfree(adapter->req_vec_chunks);
+	adapter->req_vec_chunks = NULL;
+	adapter->req_vec_chunks = kzalloc(size, GFP_KERNEL);
+	if (!adapter->req_vec_chunks) {
+		err = -ENOMEM;
+		goto error;
+	}
+	memcpy(adapter->req_vec_chunks, adapter->vc_msg, size);
+
+	alloc_vec = adapter->req_vec_chunks;
+	if (le16_to_cpu(alloc_vec->num_vectors) < num_vectors) {
+		kfree(adapter->req_vec_chunks);
+		adapter->req_vec_chunks = NULL;
+		err = -EINVAL;
+	}
+error:
+	clear_bit(__IECM_VC_MSG_PENDING, adapter->flags);
+	return err;
+}
+
+/**
+ * iecm_send_dealloc_vectors_msg - Send virtchnl de allocate vectors message
+ * @adapter: Driver specific private structure
+ *
+ * Returns 0 on success, negative on failure.
+ */
+int iecm_send_dealloc_vectors_msg(struct iecm_adapter *adapter)
+{
+	struct virtchnl2_vector_chunks *vcs;
+	struct virtchnl2_alloc_vectors *ac;
+	int buf_size, err;
+
+	ac = adapter->req_vec_chunks;
+	vcs = &ac->vchunks;
+
+	buf_size = sizeof(struct virtchnl2_vector_chunks) +
+			((le16_to_cpu(vcs->num_vchunks) - 1) *
+			sizeof(struct virtchnl2_vector_chunk));
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_DEALLOC_VECTORS, buf_size,
+			       (u8 *)vcs);
+	if (err)
+		return err;
+	err = iecm_min_wait_for_event(adapter, IECM_VC_DEALLOC_VECTORS,
+				      IECM_VC_DEALLOC_VECTORS_ERR);
+	if (err)
+		return err;
+
+	kfree(adapter->req_vec_chunks);
+	adapter->req_vec_chunks = NULL;
+	return 0;
+}
+
+/**
+ * iecm_send_get_stats_msg - Send virtchnl get statistics message
+ * @vport: vport to get stats for
+ *
+ * Returns 0 on success, negative on failure.
+ */
+int iecm_send_get_stats_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_vport_stats *stats;
+	int err = 0;
+
+	stats = (struct virtchnl2_vport_stats *)adapter->vc_msg;
+
+	/* Don't send get_stats message if one is pending or the
+	 * link is down
+	 */
+	if (test_bit(IECM_VC_GET_STATS, adapter->vc_state) ||
+	    adapter->state <= __IECM_DOWN)
+		goto error;
+
+	stats->vport_id = cpu_to_le32(vport->vport_id);
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_GET_STATS,
+			       sizeof(stats), (u8 *)&stats);
+	if (err)
+		goto error;
+
+	err = iecm_wait_for_event(adapter, IECM_VC_GET_STATS,
+				  IECM_VC_GET_STATS_ERR);
+	if (err)
+		goto error;
+
+	vport->netstats.rx_packets = le64_to_cpu(stats->rx_unicast) +
+				     le64_to_cpu(stats->rx_multicast) +
+				     le64_to_cpu(stats->rx_broadcast);
+	vport->netstats.tx_packets = le64_to_cpu(stats->tx_unicast) +
+				     le64_to_cpu(stats->tx_multicast) +
+				     le64_to_cpu(stats->tx_broadcast);
+	vport->netstats.rx_bytes = le64_to_cpu(stats->rx_bytes);
+	vport->netstats.tx_bytes = le64_to_cpu(stats->tx_bytes);
+	vport->netstats.tx_errors = le64_to_cpu(stats->tx_errors);
+	vport->netstats.rx_dropped = le64_to_cpu(stats->rx_discards);
+	vport->netstats.tx_dropped = le64_to_cpu(stats->tx_discards);
+	vport->port_stats.vport_stats = *stats;
+	clear_bit(__IECM_VC_MSG_PENDING, adapter->flags);
+error:
+	clear_bit(__IECM_MB_STATS_PENDING, vport->adapter->flags);
+
+	return err;
+}
+
+/**
+ * iecm_send_get_set_rss_hash_msg - Send set or get rss hash message
+ * @vport: virtual port data structure
+ * @get: flag to get or set rss hash
+ *
+ * Returns 0 on success, negative on failure.
+ */
+int iecm_send_get_set_rss_hash_msg(struct iecm_vport *vport, bool get)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_rss_hash rh = {0};
+	int err;
+
+	rh.vport_id = cpu_to_le32(vport->vport_id);
+	rh.ptype_groups = cpu_to_le64(adapter->rss_data.rss_hash);
+
+	if (get) {
+		err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_GET_RSS_HASH,
+				       sizeof(rh), (u8 *)&rh);
+		if (err)
+			return err;
+
+		err = iecm_wait_for_event(adapter, IECM_VC_GET_RSS_HASH,
+					  IECM_VC_GET_RSS_HASH_ERR);
+		if (err)
+			return err;
+
+		memcpy(&rh, adapter->vc_msg, sizeof(rh));
+		adapter->rss_data.rss_hash = le64_to_cpu(rh.ptype_groups);
+		/* Leave the buffer clean for next message */
+		memset(adapter->vc_msg, 0, IECM_DFLT_MBX_BUF_SIZE);
+		clear_bit(__IECM_VC_MSG_PENDING, adapter->flags);
+
+		return 0;
+	}
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_SET_RSS_HASH,
+			       sizeof(rh), (u8 *)&rh);
+	if (err)
+		return err;
+
+	return  iecm_wait_for_event(adapter, IECM_VC_SET_RSS_HASH,
+				    IECM_VC_SET_RSS_HASH_ERR);
+}
+
+/**
+ * iecm_send_get_set_rss_lut_msg - Send virtchnl get or set rss lut message
+ * @vport: virtual port data structure
+ * @get: flag to set or get rss look up table
+ *
+ * Returns 0 on success, negative on failure.
+ */
+int iecm_send_get_set_rss_lut_msg(struct iecm_vport *vport, bool get)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_rss_lut *recv_rl;
+	struct virtchnl2_rss_lut *rl;
+	int buf_size, lut_buf_size;
+	int i, err = 0;
+
+	buf_size = sizeof(struct virtchnl2_rss_lut) +
+		       (sizeof(u32) * (adapter->rss_data.rss_lut_size - 1));
+	rl = kzalloc(buf_size, GFP_KERNEL);
+	if (!rl)
+		return -ENOMEM;
+
+	if (!get) {
+		rl->lut_entries = cpu_to_le16(adapter->rss_data.rss_lut_size);
+		for (i = 0; i < adapter->rss_data.rss_lut_size; i++)
+			rl->lut[i] = cpu_to_le32(adapter->rss_data.rss_lut[i]);
+	}
+	rl->vport_id = cpu_to_le32(vport->vport_id);
+
+	if (get) {
+		err = iecm_send_mb_msg(vport->adapter, VIRTCHNL2_OP_GET_RSS_LUT,
+				       buf_size, (u8 *)rl);
+		if (err)
+			goto error;
+
+		err = iecm_wait_for_event(adapter, IECM_VC_GET_RSS_LUT,
+					  IECM_VC_GET_RSS_LUT_ERR);
+		if (err)
+			goto error;
+
+		recv_rl = (struct virtchnl2_rss_lut *)adapter->vc_msg;
+		if (adapter->rss_data.rss_lut_size !=
+		    le16_to_cpu(recv_rl->lut_entries)) {
+			adapter->rss_data.rss_lut_size =
+				le16_to_cpu(recv_rl->lut_entries);
+			kfree(adapter->rss_data.rss_lut);
+
+			lut_buf_size = adapter->rss_data.rss_lut_size *
+					sizeof(u32);
+			adapter->rss_data.rss_lut = kzalloc(lut_buf_size,
+							    GFP_KERNEL);
+			if (!adapter->rss_data.rss_lut) {
+				adapter->rss_data.rss_lut_size = 0;
+				/* Leave the buffer clean */
+				memset(adapter->vc_msg, 0,
+				       IECM_DFLT_MBX_BUF_SIZE);
+				clear_bit(__IECM_VC_MSG_PENDING,
+					  adapter->flags);
+				err = -ENOMEM;
+				goto error;
+			}
+		}
+		memcpy(adapter->rss_data.rss_lut, adapter->vc_msg,
+		       adapter->rss_data.rss_lut_size);
+		/* Leave the buffer clean for next message */
+		memset(adapter->vc_msg, 0, IECM_DFLT_MBX_BUF_SIZE);
+		clear_bit(__IECM_VC_MSG_PENDING, adapter->flags);
+	} else {
+		err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_SET_RSS_LUT,
+				       buf_size, (u8 *)rl);
+		if (err)
+			goto error;
+
+		err = iecm_wait_for_event(adapter, IECM_VC_SET_RSS_LUT,
+					  IECM_VC_SET_RSS_LUT_ERR);
+	}
+error:
+	kfree(rl);
+	return err;
+}
+
+/**
+ * iecm_send_get_set_rss_key_msg - Send virtchnl get or set rss key message
+ * @vport: virtual port data structure
+ * @get: flag to set or get rss look up table
+ *
+ * Returns 0 on success, negative on failure
+ */
+int iecm_send_get_set_rss_key_msg(struct iecm_vport *vport, bool get)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_rss_key *recv_rk;
+	struct virtchnl2_rss_key *rk;
+	int i, buf_size, err = 0;
+
+	buf_size = sizeof(struct virtchnl2_rss_key) +
+		       (sizeof(u8) * (adapter->rss_data.rss_key_size - 1));
+	rk = kzalloc(buf_size, GFP_KERNEL);
+	if (!rk)
+		return -ENOMEM;
+	rk->vport_id = cpu_to_le32(vport->vport_id);
+
+	if (get) {
+		err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_GET_RSS_KEY,
+				       buf_size, (u8 *)rk);
+		if (err)
+			goto error;
+
+		err = iecm_wait_for_event(adapter, IECM_VC_GET_RSS_KEY,
+					  IECM_VC_GET_RSS_KEY_ERR);
+		if (err)
+			goto error;
+
+		recv_rk = (struct virtchnl2_rss_key *)adapter->vc_msg;
+		if (adapter->rss_data.rss_key_size !=
+		    le16_to_cpu(recv_rk->key_len)) {
+			adapter->rss_data.rss_key_size =
+				min_t(u16, NETDEV_RSS_KEY_LEN,
+				      le16_to_cpu(recv_rk->key_len));
+			kfree(adapter->rss_data.rss_key);
+			adapter->rss_data.rss_key = kzalloc(adapter->rss_data.rss_key_size,
+							    GFP_KERNEL);
+			if (!adapter->rss_data.rss_key) {
+				adapter->rss_data.rss_key_size = 0;
+				/* Leave the buffer clean */
+				memset(adapter->vc_msg, 0,
+				       IECM_DFLT_MBX_BUF_SIZE);
+				clear_bit(__IECM_VC_MSG_PENDING,
+					  adapter->flags);
+				err = -ENOMEM;
+				goto error;
+			}
+		}
+		memcpy(adapter->rss_data.rss_key, adapter->vc_msg,
+		       adapter->rss_data.rss_key_size);
+		/* Leave the buffer clean for next message */
+		memset(adapter->vc_msg, 0, IECM_DFLT_MBX_BUF_SIZE);
+		clear_bit(__IECM_VC_MSG_PENDING, adapter->flags);
+	} else {
+		rk->key_len = cpu_to_le16(adapter->rss_data.rss_key_size);
+		for (i = 0; i < adapter->rss_data.rss_key_size; i++)
+			rk->key[i] = adapter->rss_data.rss_key[i];
+
+		err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_SET_RSS_KEY,
+				       buf_size, (u8 *)rk);
+		if (err)
+			goto error;
+
+		err = iecm_wait_for_event(adapter, IECM_VC_SET_RSS_KEY,
+					  IECM_VC_SET_RSS_KEY_ERR);
+	}
+error:
+	kfree(rk);
+	return err;
+}
+
+/**
+ * iecm_tpid_to_ethertype - transform from VLAN TPID to virtchnl ethertype
+ * @tpid: VLAN TPID (i.e. 0x8100, 0x88a8, etc.)
+ *
+ * Return virtchnl ethertype
+ */
+static u32 iecm_tpid_to_ethertype(u16 tpid)
+{
+	switch (tpid) {
+	case ETH_P_8021Q:
+		return VIRTCHNL_VLAN_ETHERTYPE_8100;
+	case ETH_P_8021AD:
+		return VIRTCHNL_VLAN_ETHERTYPE_88A8;
+	}
+
+	return 0;
+}
+
+/**
+ * iecm_set_vlan_offload_ethertype - set ethertype for offload message
+ * @adapter: adapter structure
+ * @msg: message structure used for updating offloads
+ * @offload_op: opcode used to determine which support structure to check
+ *
+ * Return 0 on success, negative on failure.
+ */
+static int
+iecm_set_vlan_offload_ethertype(struct iecm_adapter *adapter,
+				struct virtchnl_vlan_setting *msg,
+				enum virtchnl_ops offload_op)
+{
+	struct virtchnl_vlan_supported_caps *offload_support;
+	u16 tpid = adapter->config_data.vlan_ethertype;
+	u32 vc_ethertype;
+
+	vc_ethertype = iecm_tpid_to_ethertype(tpid);
+	/* reference the correct offload support structure */
+	switch (offload_op) {
+	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
+	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
+		offload_support =
+			&adapter->vlan_caps->offloads.stripping_support;
+		break;
+	case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
+	case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
+		offload_support =
+			&adapter->vlan_caps->offloads.insertion_support;
+		break;
+	default:
+		dev_err(&adapter->pdev->dev, "Invalid opcode %d for setting virtchnl ethertype to enable/disable VLAN offloads\n",
+			offload_op);
+		return -EINVAL;
+	}
+
+	/* make sure ethertype is supported and turning feature on/off
+	 * is allowed
+	 */
+	if ((offload_support->outer & vc_ethertype) &&
+	    (offload_support->outer & VIRTCHNL_VLAN_TOGGLE)) {
+		msg->outer_ethertype_setting = vc_ethertype;
+	} else if ((offload_support->inner & vc_ethertype) &&
+		   (offload_support->inner & VIRTCHNL_VLAN_TOGGLE)) {
+		msg->inner_ethertype_setting = vc_ethertype;
+	} else {
+		dev_err(&adapter->pdev->dev, "opcode %d unsupported for VLAN TPID 0x%04x\n",
+			offload_op, tpid);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+/**
+ * iecm_send_strip_vlan_msg - Send enable/disable vlan stripping message
+ * @vport: vport structure
+ * @ena: enable or disable vlan stripping
+ *
+ * Returns 0 on success, negative on failure.
+ */
+static int iecm_send_strip_vlan_msg(struct iecm_vport *vport, bool ena)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	enum iecm_vport_vc_state vc, vc_err;
+	struct virtchnl_vlan_setting *msg;
+	enum virtchnl_ops vop;
+	int err, len;
+
+	len = sizeof(struct virtchnl_vlan_setting);
+	msg = kzalloc(sizeof(*msg), GFP_KERNEL);
+
+	if (!msg)
+		return -ENOMEM;
+
+	msg->vport_id = vport->vport_id;
+	if (ena) {
+		vop = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2;
+		vc = IECM_VC_STRIPPING_ENA_VLAN_V2;
+		vc_err = IECM_VC_STRIPPING_ENA_VLAN_V2_ERR;
+	} else {
+		vop = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2;
+		vc = IECM_VC_STRIPPING_DIS_VLAN_V2;
+		vc_err = IECM_VC_STRIPPING_DIS_VLAN_V2_ERR;
+	}
+
+	err = iecm_set_vlan_offload_ethertype(adapter, msg, vop);
+	if (!err) {
+		err = iecm_send_mb_msg(adapter, vop, len, (u8 *)msg);
+		if (!err)
+			err = iecm_wait_for_event(adapter, vc, vc_err);
+	}
+
+	kfree(msg);
+
+	return err;
+}
+
+/**
+ * iecm_send_insert_vlan_msg - Send enable/disable vlan insertion message
+ * @vport: vport structure
+ * @ena: enable/disable vlan insertion
+ *
+ * Returns 0 on success, negative on failure.
+ */
+static int iecm_send_insert_vlan_msg(struct iecm_vport *vport, bool ena)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	enum iecm_vport_vc_state vc, vc_err;
+	struct virtchnl_vlan_setting *msg;
+	enum virtchnl_ops vop;
+	int err, len;
+
+	len = sizeof(struct virtchnl_vlan_setting);
+	msg = kzalloc(sizeof(*msg), GFP_KERNEL);
+
+	if (!msg)
+		return -ENOMEM;
+
+	msg->vport_id = vport->vport_id;
+
+	if (ena) {
+		vop = VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2;
+		vc = IECM_VC_INSERTION_ENA_VLAN_V2;
+		vc_err = IECM_VC_INSERTION_ENA_VLAN_V2_ERR;
+	} else {
+		vop = VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2;
+		vc = IECM_VC_INSERTION_DIS_VLAN_V2;
+		vc_err = IECM_VC_INSERTION_DIS_VLAN_V2_ERR;
+	}
+
+	err = iecm_set_vlan_offload_ethertype(adapter, msg, vop);
+	if (!err) {
+		err = iecm_send_mb_msg(adapter, vop, len, (u8 *)msg);
+		if (!err)
+			err = iecm_wait_for_event(adapter, vc, vc_err);
+	}
+
+	kfree(msg);
+
+	return err;
+}
+
+/**
+ * iecm_fill_ptype_lookup - Fill L3 specific fields in ptype lookup table
+ * @ptype: ptype lookup table
+ * @pstate: state machine for ptype lookup table
+ * @ipv4: ipv4 or ipv6
+ * @frag: fragmentation allowed
+ *
+ */
+static void iecm_fill_ptype_lookup(struct iecm_rx_ptype_decoded *ptype,
+				   struct iecm_ptype_state *pstate,
+				   bool ipv4, bool frag)
+{
+	if (!pstate->outer_ip || !pstate->outer_frag) {
+		ptype->outer_ip = IECM_RX_PTYPE_OUTER_IP;
+		pstate->outer_ip = true;
+
+		if (ipv4)
+			ptype->outer_ip_ver = IECM_RX_PTYPE_OUTER_IPV4;
+		else
+			ptype->outer_ip_ver = IECM_RX_PTYPE_OUTER_IPV6;
+
+		if (frag) {
+			ptype->outer_frag = IECM_RX_PTYPE_FRAG;
+			pstate->outer_frag = true;
+		}
+	} else {
+		ptype->tunnel_type = IECM_RX_PTYPE_TUNNEL_IP_IP;
+		pstate->tunnel_state = IECM_PTYPE_TUNNEL_IP;
+
+		if (ipv4)
+			ptype->tunnel_end_prot =
+					IECM_RX_PTYPE_TUNNEL_END_IPV4;
+		else
+			ptype->tunnel_end_prot =
+					IECM_RX_PTYPE_TUNNEL_END_IPV6;
+
+		if (frag)
+			ptype->tunnel_end_frag = IECM_RX_PTYPE_FRAG;
+	}
+}
+
+/**
+ * iecm_send_get_rx_ptype_msg - Send virtchnl for ptype info
+ * @vport: virtual port data structure
+ *
+ * Returns 0 on success, negative on failure.
+ */
+int iecm_send_get_rx_ptype_msg(struct iecm_vport *vport)
+{
+	struct iecm_rx_ptype_decoded *ptype_lkup = vport->rx_ptype_lkup;
+	struct virtchnl2_get_ptype_info *get_ptype_info, *ptype_info;
+	int max_ptype, ptypes_recvd = 0, len, ptype_offset;
+	struct iecm_adapter *adapter = vport->adapter;
+	int err = 0, i, j, k = 0;
+
+	if (iecm_is_queue_model_split(vport->rxq_model))
+		max_ptype = IECM_RX_MAX_PTYPE;
+	else
+		max_ptype = IECM_RX_MAX_BASE_PTYPE;
+
+	for (i = 0; i < max_ptype; i++)
+		ptype_lkup[i] = iecm_ptype_lookup[0];
+
+	len = sizeof(struct virtchnl2_get_ptype_info);
+	get_ptype_info = kzalloc(len, GFP_KERNEL);
+	if (!get_ptype_info)
+		return -ENOMEM;
+
+	get_ptype_info->start_ptype_id = 0;
+	get_ptype_info->num_ptypes = cpu_to_le16(max_ptype);
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_GET_PTYPE_INFO,
+			       len, (u8 *)get_ptype_info);
+	if (err)
+		goto get_ptype_rel;
+
+	while (ptypes_recvd < max_ptype) {
+		err = iecm_wait_for_event(adapter, IECM_VC_GET_PTYPE_INFO,
+					  IECM_VC_GET_PTYPE_INFO_ERR);
+		if (err)
+			goto get_ptype_rel;
+
+		len = IECM_DFLT_MBX_BUF_SIZE;
+		ptype_info = kzalloc(len, GFP_KERNEL);
+		if (!ptype_info) {
+			err = -ENOMEM;
+			goto clear_vc_flag;
+		}
+
+		memcpy(ptype_info, adapter->vc_msg, len);
+
+		ptypes_recvd += le16_to_cpu(ptype_info->num_ptypes);
+		if (ptypes_recvd > max_ptype) {
+			err = -EINVAL;
+			goto ptype_rel;
+		}
+
+		ptype_offset = sizeof(struct virtchnl2_get_ptype_info) -
+						sizeof(struct virtchnl2_ptype);
+
+		for (i = 0; i < le16_to_cpu(ptype_info->num_ptypes); i++) {
+			struct iecm_ptype_state pstate = { 0 };
+			struct virtchnl2_ptype *ptype;
+			u16 id;
+
+			ptype = (struct virtchnl2_ptype *)
+					((u8 *)ptype_info + ptype_offset);
+
+			ptype_offset += IECM_GET_PTYPE_SIZE(ptype);
+			if (ptype_offset > len) {
+				err = -EINVAL;
+				goto ptype_rel;
+			}
+
+			if (le16_to_cpu(ptype->ptype_id_10) == 0xFFFF)
+				goto ptype_rel;
+
+			if (iecm_is_queue_model_split(vport->rxq_model))
+				k = le16_to_cpu(ptype->ptype_id_10);
+			else
+				k = ptype->ptype_id_8;
+
+			if (ptype->proto_id_count)
+				ptype_lkup[k].known = 1;
+
+			for (j = 0; j < ptype->proto_id_count; j++) {
+				id = le16_to_cpu(ptype->proto_id[j]);
+				switch (id) {
+				case VIRTCHNL2_PROTO_HDR_GRE:
+					if (pstate.tunnel_state ==
+							IECM_PTYPE_TUNNEL_IP) {
+						ptype_lkup[k].tunnel_type =
+						IECM_RX_PTYPE_TUNNEL_IP_GRENAT;
+						pstate.tunnel_state |=
+						IECM_PTYPE_TUNNEL_IP_GRENAT;
+					}
+					break;
+				case VIRTCHNL2_PROTO_HDR_MAC:
+					ptype_lkup[k].outer_ip =
+						IECM_RX_PTYPE_OUTER_L2;
+					if (pstate.tunnel_state ==
+							IECM_TUN_IP_GRE) {
+						ptype_lkup[k].tunnel_type =
+						IECM_RX_PTYPE_TUNNEL_IP_GRENAT_MAC;
+						pstate.tunnel_state |=
+						IECM_PTYPE_TUNNEL_IP_GRENAT_MAC;
+					}
+					break;
+				case VIRTCHNL2_PROTO_HDR_VLAN:
+					if (pstate.tunnel_state ==
+							IECM_TUN_IP_GRE_MAC) {
+						ptype_lkup[k].tunnel_type =
+						IECM_RX_PTYPE_TUNNEL_IP_GRENAT_MAC_VLAN;
+						pstate.tunnel_state |=
+						IECM_PTYPE_TUNNEL_IP_GRENAT_MAC_VLAN;
+					}
+					break;
+				case VIRTCHNL2_PROTO_HDR_IPV4:
+					iecm_fill_ptype_lookup(&ptype_lkup[k],
+							       &pstate, true,
+							       false);
+					break;
+				case VIRTCHNL2_PROTO_HDR_IPV6:
+					iecm_fill_ptype_lookup(&ptype_lkup[k],
+							       &pstate, false,
+							       false);
+					break;
+				case VIRTCHNL2_PROTO_HDR_IPV4_FRAG:
+					iecm_fill_ptype_lookup(&ptype_lkup[k],
+							       &pstate, true,
+							       true);
+					break;
+				case VIRTCHNL2_PROTO_HDR_IPV6_FRAG:
+					iecm_fill_ptype_lookup(&ptype_lkup[k],
+							       &pstate, false,
+							       true);
+					break;
+				case VIRTCHNL2_PROTO_HDR_UDP:
+					ptype_lkup[k].inner_prot =
+					IECM_RX_PTYPE_INNER_PROT_UDP;
+					break;
+				case VIRTCHNL2_PROTO_HDR_TCP:
+					ptype_lkup[k].inner_prot =
+					IECM_RX_PTYPE_INNER_PROT_TCP;
+					break;
+				case VIRTCHNL2_PROTO_HDR_SCTP:
+					ptype_lkup[k].inner_prot =
+					IECM_RX_PTYPE_INNER_PROT_SCTP;
+					break;
+				case VIRTCHNL2_PROTO_HDR_ICMP:
+					ptype_lkup[k].inner_prot =
+					IECM_RX_PTYPE_INNER_PROT_ICMP;
+					break;
+				case VIRTCHNL2_PROTO_HDR_PAY:
+					ptype_lkup[k].payload_layer =
+						IECM_RX_PTYPE_PAYLOAD_LAYER_PAY2;
+					break;
+				case VIRTCHNL2_PROTO_HDR_ICMPV6:
+				case VIRTCHNL2_PROTO_HDR_IPV6_EH:
+				case VIRTCHNL2_PROTO_HDR_PRE_MAC:
+				case VIRTCHNL2_PROTO_HDR_POST_MAC:
+				case VIRTCHNL2_PROTO_HDR_ETHERTYPE:
+				case VIRTCHNL2_PROTO_HDR_SVLAN:
+				case VIRTCHNL2_PROTO_HDR_CVLAN:
+				case VIRTCHNL2_PROTO_HDR_MPLS:
+				case VIRTCHNL2_PROTO_HDR_MMPLS:
+				case VIRTCHNL2_PROTO_HDR_PTP:
+				case VIRTCHNL2_PROTO_HDR_CTRL:
+				case VIRTCHNL2_PROTO_HDR_LLDP:
+				case VIRTCHNL2_PROTO_HDR_ARP:
+				case VIRTCHNL2_PROTO_HDR_ECP:
+				case VIRTCHNL2_PROTO_HDR_EAPOL:
+				case VIRTCHNL2_PROTO_HDR_PPPOD:
+				case VIRTCHNL2_PROTO_HDR_PPPOE:
+				case VIRTCHNL2_PROTO_HDR_IGMP:
+				case VIRTCHNL2_PROTO_HDR_AH:
+				case VIRTCHNL2_PROTO_HDR_ESP:
+				case VIRTCHNL2_PROTO_HDR_IKE:
+				case VIRTCHNL2_PROTO_HDR_NATT_KEEP:
+				case VIRTCHNL2_PROTO_HDR_L2TPV2:
+				case VIRTCHNL2_PROTO_HDR_L2TPV2_CONTROL:
+				case VIRTCHNL2_PROTO_HDR_L2TPV3:
+				case VIRTCHNL2_PROTO_HDR_GTP:
+				case VIRTCHNL2_PROTO_HDR_GTP_EH:
+				case VIRTCHNL2_PROTO_HDR_GTPCV2:
+				case VIRTCHNL2_PROTO_HDR_GTPC_TEID:
+				case VIRTCHNL2_PROTO_HDR_GTPU:
+				case VIRTCHNL2_PROTO_HDR_GTPU_UL:
+				case VIRTCHNL2_PROTO_HDR_GTPU_DL:
+				case VIRTCHNL2_PROTO_HDR_ECPRI:
+				case VIRTCHNL2_PROTO_HDR_VRRP:
+				case VIRTCHNL2_PROTO_HDR_OSPF:
+				case VIRTCHNL2_PROTO_HDR_TUN:
+				case VIRTCHNL2_PROTO_HDR_NVGRE:
+				case VIRTCHNL2_PROTO_HDR_VXLAN:
+				case VIRTCHNL2_PROTO_HDR_VXLAN_GPE:
+				case VIRTCHNL2_PROTO_HDR_GENEVE:
+				case VIRTCHNL2_PROTO_HDR_NSH:
+				case VIRTCHNL2_PROTO_HDR_QUIC:
+				case VIRTCHNL2_PROTO_HDR_PFCP:
+				case VIRTCHNL2_PROTO_HDR_PFCP_NODE:
+				case VIRTCHNL2_PROTO_HDR_PFCP_SESSION:
+				case VIRTCHNL2_PROTO_HDR_RTP:
+				case VIRTCHNL2_PROTO_HDR_NO_PROTO:
+				default:
+					continue;
+				}
+			}
+		}
+		clear_bit(__IECM_VC_MSG_PENDING, adapter->flags);
+		kfree(ptype_info);
+	}
+	kfree(get_ptype_info);
+	return 0;
+
+ptype_rel:
+	kfree(ptype_info);
+clear_vc_flag:
+	clear_bit(__IECM_VC_MSG_PENDING, adapter->flags);
+get_ptype_rel:
+	kfree(get_ptype_info);
+	return err;
+}
+
 /**
  * iecm_find_ctlq - Given a type and id, find ctlq info
  * @hw: hardware struct
@@ -2478,6 +3505,25 @@ static int iecm_vport_queue_ids_init(struct iecm_vport *vport)
 	return 0;
 }
 
+/**
+ * iecm_vport_adjust_qs - Adjust to new requested queues
+ * @vport: virtual port data struct
+ *
+ * Renegotiate queues.  Returns 0 on success, negative on failure.
+ */
+void iecm_vport_adjust_qs(struct iecm_vport *vport)
+{
+	struct virtchnl2_create_vport vport_msg;
+
+	vport_msg.txq_model = cpu_to_le16(vport->txq_model);
+	vport_msg.rxq_model = cpu_to_le16(vport->rxq_model);
+	iecm_vport_calc_total_qs(vport->adapter, &vport_msg);
+
+	iecm_vport_init_num_qs(vport, &vport_msg);
+	iecm_vport_calc_num_q_groups(vport);
+	iecm_vport_calc_num_q_vec(vport);
+}
+
 /**
  * iecm_is_capability_ena - Default implementation of capability checking
  * @adapter: Private data struct
@@ -2522,6 +3568,117 @@ static u16 iecm_get_reserved_vectors(struct iecm_adapter *adapter)
 	return le16_to_cpu(caps->num_allocated_vectors);
 }
 

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static u16 iecm_get_reserved_vectors(struct iecm_adapter *adapter) · line 3580

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+/**
+ * iecm_get_max_tx_bufs - Max scatter-gather TX buffers
+ * @adapter: Private data struct
+ *
+ * Return maximum number of buffers that can be used in scatter-gather before
+ * they need to be linearized for hardware.
+ */
+static unsigned int iecm_get_max_tx_bufs(struct iecm_adapter *adapter)
+{
+	return ((struct virtchnl2_get_capabilities *)adapter->caps)->max_sg_bufs_per_tx_pkt;

93-cols line here, you can introduce some interm variables to reduce the burden.

Quoted 16 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +16 -0
+}
+
+/**
+ * iecm_add_del_vlans - Add or delete vlan filter
+ * @vport: vport structure
+ * @add: add or delete
+ *
+ * Request that the PF add one or more VLAN filters to our VSI.
+ */
+static void iecm_add_del_vlans(struct iecm_vport *vport, bool add)
+{
+	struct virtchnl_vlan_supported_caps *filtering_support;
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl_vlan_filter_list_v2 *vvfl_v2;
+	int total_vlans = 0, num_vlans, i, len;
+	struct iecm_vlan_filter *f, *ftmp;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static u16 iecm_get_reserved_vectors(struct iecm_adapter *adapter) · line 3606

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+	struct virtchnl_vlan *vlan;
+	enum virtchnl_ops vop;
+	int err = 0;
+
+	spin_lock_bh(&adapter->vlan_list_lock);
+
+	list_for_each_entry(f, &adapter->config_data.vlan_filter_list, list) {
+		if ((add && f->add) || (!add && f->remove))
+			total_vlans++;
+	}

Braces are redundant, if-something is one command from the outer view.

Quoted 260 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +90 -15
+
+	if (!total_vlans) {
+		spin_unlock_bh(&adapter->vlan_list_lock);
+		return;
+	}
+
+	len = sizeof(struct virtchnl_vlan_filter_list_v2) +
+		(IECM_VLANS_PER_MSG * sizeof(struct virtchnl_vlan_filter));
+	vvfl_v2 = kzalloc(len, GFP_ATOMIC);
+
+	if (!vvfl_v2) {
+		err = -ENOMEM;
+		goto error;
+	}
+
+	if (add)
+		vop = VIRTCHNL_OP_ADD_VLAN_V2;
+	else
+		vop = VIRTCHNL_OP_DEL_VLAN_V2;
+
+	while (total_vlans) {
+		if (total_vlans > IECM_VLANS_PER_MSG)
+			num_vlans = IECM_VLANS_PER_MSG;
+		else
+			num_vlans = total_vlans;
+		total_vlans -= num_vlans;
+
+		len = sizeof(struct virtchnl_vlan_filter_list_v2) +
+			((num_vlans - 1) * sizeof(struct virtchnl_vlan_filter));
+		vvfl_v2->vport_id = vport->vport_id;
+		vvfl_v2->num_elements = num_vlans;
+		i = 0;
+		list_for_each_entry_safe(f, ftmp,
+					 &adapter->config_data.vlan_filter_list,
+					 list) {
+			filtering_support =
+			&adapter->vlan_caps->filtering.filtering_support;
+			if (add && f->add) {
+				/* give priority over outer if it's enabled */
+				if (filtering_support->outer)
+					vlan = &vvfl_v2->filters[i].outer;
+				else
+					vlan = &vvfl_v2->filters[i].inner;
+				vlan->tci = f->vlan.vid;
+				vlan->tpid = f->vlan.tpid;
+				i++;
+				f->add = false;
+			} else if (!add && f->remove) {
+				/* give priority over outer if it's enabled */
+				if (filtering_support->outer)
+					vlan = &vvfl_v2->filters[i].outer;
+				else
+					vlan = &vvfl_v2->filters[i].inner;
+				vlan->tci = f->vlan.vid;
+				vlan->tpid = f->vlan.tpid;
+				i++;
+				f->remove = false;
+			}
+			if (i == num_vlans)
+				break;
+		}
+		spin_unlock_bh(&adapter->vlan_list_lock);
+		iecm_send_mb_msg(adapter, vop, len, (u8 *)vvfl_v2);
+		spin_lock_bh(&adapter->vlan_list_lock);
+	}
+	spin_unlock_bh(&adapter->vlan_list_lock);
+	kfree(vvfl_v2);
+	return;
+error:
+	spin_unlock_bh(&adapter->vlan_list_lock);
+	if (err)
+		dev_err(&adapter->pdev->dev,
+			"Failed to add or del vlan filters %d", err);
+}
+
 /**
  * iecm_vc_ops_init - Initialize virtchnl common api
  * @adapter: Driver specific private structure
@@ -2548,21 +3705,21 @@ void iecm_vc_ops_init(struct iecm_adapter *adapter)
 	vc_ops->enable_vport = iecm_send_enable_vport_msg;
 	vc_ops->disable_vport = iecm_send_disable_vport_msg;
 	vc_ops->destroy_vport = iecm_send_destroy_vport_msg;
-	vc_ops->get_ptype = NULL;
-	vc_ops->get_set_rss_key = NULL;
-	vc_ops->get_set_rss_lut = NULL;
-	vc_ops->get_set_rss_hash = NULL;
-	vc_ops->adjust_qs = NULL;
-	vc_ops->add_del_vlans = NULL;
-	vc_ops->strip_vlan_msg = NULL;
-	vc_ops->insert_vlan_msg = NULL;
-	vc_ops->init_max_queues = NULL;
-	vc_ops->get_max_tx_bufs = NULL;
-	vc_ops->vportq_reg_init = NULL;
-	vc_ops->alloc_vectors = NULL;
-	vc_ops->dealloc_vectors = NULL;
-	vc_ops->get_supported_desc_ids = NULL;
-	vc_ops->get_stats_msg = NULL;
+	vc_ops->get_ptype = iecm_send_get_rx_ptype_msg;
+	vc_ops->get_set_rss_key = iecm_send_get_set_rss_key_msg;
+	vc_ops->get_set_rss_lut = iecm_send_get_set_rss_lut_msg;
+	vc_ops->get_set_rss_hash = iecm_send_get_set_rss_hash_msg;
+	vc_ops->adjust_qs = iecm_vport_adjust_qs;
+	vc_ops->add_del_vlans = iecm_add_del_vlans;
+	vc_ops->strip_vlan_msg = iecm_send_strip_vlan_msg;
+	vc_ops->insert_vlan_msg = iecm_send_insert_vlan_msg;
+	vc_ops->init_max_queues = iecm_vport_init_max_qs;
+	vc_ops->get_max_tx_bufs = iecm_get_max_tx_bufs;
+	vc_ops->vportq_reg_init = iecm_queue_reg_init;
+	vc_ops->alloc_vectors = iecm_send_alloc_vectors_msg;
+	vc_ops->dealloc_vectors = iecm_send_dealloc_vectors_msg;
+	vc_ops->get_supported_desc_ids = iecm_get_supported_desc_ids;
+	vc_ops->get_stats_msg = iecm_send_get_stats_msg;
 	vc_ops->recv_mbx_msg = NULL;
 }
 EXPORT_SYMBOL(iecm_vc_ops_init);
drivers/net/ethernet/intel/include/iecm.h +36 -0
index 8dd6272db7d3..d736db65da06 100644
@@ -346,6 +346,7 @@ struct iecm_vport {
 	int num_rxq_grp;
 	struct iecm_rxq_group *rxq_grps;
 	u32 rxq_model;
+	struct iecm_rx_ptype_decoded rx_ptype_lkup[IECM_RX_MAX_PTYPE];
 
 	struct iecm_adapter *adapter;
 	struct net_device *netdev;
@@ -382,6 +383,30 @@ enum iecm_user_flags {
 	__IECM_USER_FLAGS_NBITS,
 };
 
+#define IECM_GET_PTYPE_SIZE(p) \
+	(sizeof(struct virtchnl2_ptype) + \
+	(((p)->proto_id_count ? ((p)->proto_id_count - 1) : 0) * sizeof(u16)))
+
+#define IECM_TUN_IP_GRE (\
+	IECM_PTYPE_TUNNEL_IP |\
+	IECM_PTYPE_TUNNEL_IP_GRENAT)
+
+#define IECM_TUN_IP_GRE_MAC (\
+	IECM_TUN_IP_GRE |\
+	IECM_PTYPE_TUNNEL_IP_GRENAT_MAC)
+
+enum iecm_tunnel_state {
+	IECM_PTYPE_TUNNEL_IP                    = BIT(0),
+	IECM_PTYPE_TUNNEL_IP_GRENAT             = BIT(1),
+	IECM_PTYPE_TUNNEL_IP_GRENAT_MAC         = BIT(2),
+	IECM_PTYPE_TUNNEL_IP_GRENAT_MAC_VLAN    = BIT(3),
+};
+
+struct iecm_ptype_state {
+	bool outer_ip;
+	bool outer_frag;
+	u8 tunnel_state;
+};
 /* User defined configuration values */
 struct iecm_user_config_data {
 	u32 num_req_tx_qs; /* user requested TX queues through ethtool */
@@ -534,6 +559,7 @@ int iecm_probe(struct pci_dev *pdev,
 	       const struct pci_device_id __always_unused *ent,
 	       struct iecm_adapter *adapter);
 void iecm_remove(struct pci_dev *pdev);
+void iecm_vport_adjust_qs(struct iecm_vport *vport);
 int iecm_init_dflt_mbx(struct iecm_adapter *adapter);
 void iecm_deinit_dflt_mbx(struct iecm_adapter *adapter);
 void iecm_vc_ops_init(struct iecm_adapter *adapter);
@@ -555,8 +581,15 @@ int iecm_send_config_rx_queues_msg(struct iecm_vport *vport);
 int iecm_send_enable_vport_msg(struct iecm_vport *vport);
 int iecm_send_disable_vport_msg(struct iecm_vport *vport);
 int iecm_send_destroy_vport_msg(struct iecm_vport *vport);
+int iecm_send_get_rx_ptype_msg(struct iecm_vport *vport);
+int iecm_send_get_set_rss_key_msg(struct iecm_vport *vport, bool get);
+int iecm_send_get_set_rss_lut_msg(struct iecm_vport *vport, bool get);
+int iecm_send_get_set_rss_hash_msg(struct iecm_vport *vport, bool get);
+int iecm_send_dealloc_vectors_msg(struct iecm_adapter *adapter);
+int iecm_send_alloc_vectors_msg(struct iecm_adapter *adapter, u16 num_vectors);
 int iecm_vport_params_buf_alloc(struct iecm_adapter *adapter);
 void iecm_vport_params_buf_rel(struct iecm_adapter *adapter);
+int iecm_send_get_stats_msg(struct iecm_vport *vport);
 int iecm_get_vec_ids(struct iecm_adapter *adapter,
 		     u16 *vecids, int num_vecids,
 		     struct virtchnl2_vector_chunks *chunks);
@@ -567,6 +600,9 @@ int iecm_send_mb_msg(struct iecm_adapter *adapter, enum virtchnl_ops op,
 void iecm_vport_set_hsplit(struct iecm_vport *vport, bool ena);
 int iecm_send_enable_channels_msg(struct iecm_vport *vport);
 int iecm_send_disable_channels_msg(struct iecm_vport *vport);
+bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature);
+int iecm_check_descs(struct iecm_vport *vport, u64 rx_desc_ids,
+		     u64 tx_desc_ids, u16 rxq_model, u16 txq_model);
 int iecm_set_msg_pending(struct iecm_adapter *adapter,
 			 struct iecm_ctlq_msg *ctlq_msg,
 			 enum iecm_vport_vc_state err_enum);
drivers/net/ethernet/intel/include/iecm_txrx.h +50 -1
index 448cae0bf6e7..9f3086bfe575 100644
@@ -4,6 +4,9 @@
 #ifndef _IECM_TXRX_H_
 #define _IECM_TXRX_H_
 
+#include "virtchnl_lan_desc.h"
+#include <linux/indirect_call_wrapper.h>
+
 #define IECM_LARGE_MAX_Q			256
 #define IECM_MAX_Q				16
 /* Mailbox Queue */
@@ -77,9 +80,200 @@
 #define IECM_MAX_RXBUFFER			9728
 #define IECM_MAX_MTU		\
 	(IECM_MAX_RXBUFFER - IECM_PACKET_HDR_PAD)
-#define IECM_INT_NAME_STR_LEN	(IFNAMSIZ + 16)
+
+#define MAKEMASK(m, s)	((m) << (s))
+
+/* Checksum offload bits decoded from the receive descriptor. */
+struct iecm_rx_csum_decoded {
+	u8 l3l4p : 1;
+	u8 ipe : 1;
+	u8 eipe : 1;
+	u8 eudpe : 1;
+	u8 ipv6exadd : 1;
+	u8 l4e : 1;
+	u8 pprs : 1;
+	u8 nat : 1;
+	u8 rsc : 1;
+	u8 raw_csum_inv : 1;
+	u16 raw_csum;
+};
+
+struct iecm_rx_extracted {
+	unsigned int size;
+	u16 vlan_tag;
+	u16 rx_ptype;
+};
 
 #define IECM_TX_COMPLQ_CLEAN_BUDGET	256
+#define IECM_TX_MIN_LEN			17
+#define IECM_TX_DESCS_FOR_SKB_DATA_PTR	1
+#define IECM_TX_MAX_BUF			8
+#define IECM_TX_DESCS_PER_CACHE_LINE	4
+#define IECM_TX_DESCS_FOR_CTX		1
+/* TX descriptors needed, worst case */
+#define IECM_TX_DESC_NEEDED (MAX_SKB_FRAGS + IECM_TX_DESCS_FOR_CTX + \
+			     IECM_TX_DESCS_PER_CACHE_LINE + \
+			     IECM_TX_DESCS_FOR_SKB_DATA_PTR)
+
+/* The size limit for a transmit buffer in a descriptor is (16K - 1).
+ * In order to align with the read requests we will align the value to
+ * the nearest 4K which represents our maximum read request size.
+ */
+#define IECM_TX_MAX_READ_REQ_SIZE	4096
+#define IECM_TX_MAX_DESC_DATA		(16 * 1024 - 1)
+#define IECM_TX_MAX_DESC_DATA_ALIGNED \
+	(~(IECM_TX_MAX_READ_REQ_SIZE - 1) & IECM_TX_MAX_DESC_DATA)
+
+#define IECM_RX_DMA_ATTR \
+	(DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING)
+#define IECM_RX_DESC(R, i)	\
+	(&(((union virtchnl2_rx_desc *)((R)->desc_ring))[i]))
+

drivers/net/ethernet/intel/include/iecm_txrx.h line 141

Quoted 10 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +10 -0
+struct iecm_page_info {
+	dma_addr_t dma;
+	struct page *page;
+	unsigned int page_offset;
+	u16 pagecnt_bias;
+};
+
+struct iecm_rx_buf {
+#define IECM_RX_BUF_MAX_PAGES 2
+	struct iecm_page_info page_info[IECM_RX_BUF_MAX_PAGES];

As I said previously, it will most likely be rejected upstream. They will either suggest using compounds or page_pool (it uses compounds for non-zero-order pages) or maybe introduce folio support to the networking stack or so, but not such stuff.

Quoted 147 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +135 -2
+	u8 page_indx;
+	u16 buf_id;
+	u16 buf_size;
+	struct sk_buff *skb;
+};
+
+/* Packet type non-ip values */
+enum iecm_rx_ptype_l2 {
+	IECM_RX_PTYPE_L2_RESERVED	= 0,
+	IECM_RX_PTYPE_L2_MAC_PAY2	= 1,
+	IECM_RX_PTYPE_L2_TIMESYNC_PAY2	= 2,
+	IECM_RX_PTYPE_L2_FIP_PAY2	= 3,
+	IECM_RX_PTYPE_L2_OUI_PAY2	= 4,
+	IECM_RX_PTYPE_L2_MACCNTRL_PAY2	= 5,
+	IECM_RX_PTYPE_L2_LLDP_PAY2	= 6,
+	IECM_RX_PTYPE_L2_ECP_PAY2	= 7,
+	IECM_RX_PTYPE_L2_EVB_PAY2	= 8,
+	IECM_RX_PTYPE_L2_QCN_PAY2	= 9,
+	IECM_RX_PTYPE_L2_EAPOL_PAY2	= 10,
+	IECM_RX_PTYPE_L2_ARP		= 11,
+};
+
+enum iecm_rx_ptype_outer_ip {
+	IECM_RX_PTYPE_OUTER_L2	= 0,
+	IECM_RX_PTYPE_OUTER_IP	= 1,
+};
+
+enum iecm_rx_ptype_outer_ip_ver {
+	IECM_RX_PTYPE_OUTER_NONE	= 0,
+	IECM_RX_PTYPE_OUTER_IPV4	= 1,
+	IECM_RX_PTYPE_OUTER_IPV6	= 2,
+};
+
+enum iecm_rx_ptype_outer_fragmented {
+	IECM_RX_PTYPE_NOT_FRAG	= 0,
+	IECM_RX_PTYPE_FRAG	= 1,
+};
+
+enum iecm_rx_ptype_tunnel_type {
+	IECM_RX_PTYPE_TUNNEL_NONE		= 0,
+	IECM_RX_PTYPE_TUNNEL_IP_IP		= 1,
+	IECM_RX_PTYPE_TUNNEL_IP_GRENAT		= 2,
+	IECM_RX_PTYPE_TUNNEL_IP_GRENAT_MAC	= 3,
+	IECM_RX_PTYPE_TUNNEL_IP_GRENAT_MAC_VLAN	= 4,
+};
+
+enum iecm_rx_ptype_tunnel_end_prot {
+	IECM_RX_PTYPE_TUNNEL_END_NONE	= 0,
+	IECM_RX_PTYPE_TUNNEL_END_IPV4	= 1,
+	IECM_RX_PTYPE_TUNNEL_END_IPV6	= 2,
+};
+
+enum iecm_rx_ptype_inner_prot {
+	IECM_RX_PTYPE_INNER_PROT_NONE		= 0,
+	IECM_RX_PTYPE_INNER_PROT_UDP		= 1,
+	IECM_RX_PTYPE_INNER_PROT_TCP		= 2,
+	IECM_RX_PTYPE_INNER_PROT_SCTP		= 3,
+	IECM_RX_PTYPE_INNER_PROT_ICMP		= 4,
+	IECM_RX_PTYPE_INNER_PROT_TIMESYNC	= 5,
+};
+
+enum iecm_rx_ptype_payload_layer {
+	IECM_RX_PTYPE_PAYLOAD_LAYER_NONE	= 0,
+	IECM_RX_PTYPE_PAYLOAD_LAYER_PAY2	= 1,
+	IECM_RX_PTYPE_PAYLOAD_LAYER_PAY3	= 2,
+	IECM_RX_PTYPE_PAYLOAD_LAYER_PAY4	= 3,
+};
+
+struct iecm_rx_ptype_decoded {
+	u32 ptype:10;
+	u32 known:1;
+	u32 outer_ip:1;
+	u32 outer_ip_ver:2;
+	u32 outer_frag:1;
+	u32 tunnel_type:3;
+	u32 tunnel_end_prot:2;
+	u32 tunnel_end_frag:1;
+	u32 inner_prot:4;
+	u32 payload_layer:3;
+};
+
+enum iecm_rx_hsplit {
+	IECM_RX_NO_HDR_SPLIT = 0,
+	IECM_RX_HDR_SPLIT = 1,
+};
+
+/* The iecm_ptype_lkup table is used to convert from the 10-bit ptype in the
+ * hardware to a bit-field that can be used by SW to more easily determine the
+ * packet type.
+ *
+ * Macros are used to shorten the table lines and make this table human
+ * readable.
+ *
+ * We store the PTYPE in the top byte of the bit field - this is just so that
+ * we can check that the table doesn't have a row missing, as the index into
+ * the table should be the PTYPE.
+ *
+ * Typical work flow:
+ *
+ * IF NOT iecm_ptype_lkup[ptype].known
+ * THEN
+ *      Packet is unknown
+ * ELSE IF iecm_ptype_lkup[ptype].outer_ip == IECM_RX_PTYPE_OUTER_IP
+ *      Use the rest of the fields to look at the tunnels, inner protocols, etc
+ * ELSE
+ *      Use the enum iecm_rx_ptype_l2 to decode the packet type
+ * ENDIF
+ */
+/* macro to make the table lines short */
+#define IECM_PTT(PTYPE, OUTER_IP, OUTER_IP_VER, OUTER_FRAG, T, TE, TEF, I, PL)\
+	{	PTYPE, \
+		1, \
+		IECM_RX_PTYPE_OUTER_##OUTER_IP, \
+		IECM_RX_PTYPE_OUTER_##OUTER_IP_VER, \
+		IECM_RX_PTYPE_##OUTER_FRAG, \
+		IECM_RX_PTYPE_TUNNEL_##T, \
+		IECM_RX_PTYPE_TUNNEL_END_##TE, \
+		IECM_RX_PTYPE_##TEF, \
+		IECM_RX_PTYPE_INNER_PROT_##I, \
+		IECM_RX_PTYPE_PAYLOAD_LAYER_##PL }
+
+#define IECM_PTT_UNUSED_ENTRY(PTYPE) { PTYPE, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
+
+/* shorter macros makes the table fit but are terse */
+#define IECM_RX_PTYPE_NOF		IECM_RX_PTYPE_NOT_FRAG
+#define IECM_RX_PTYPE_FRG		IECM_RX_PTYPE_FRAG
+#define IECM_RX_PTYPE_INNER_PROT_TS	IECM_RX_PTYPE_INNER_PROT_TIMESYNC
+#define IECM_RX_SUPP_PTYPE		18
+#define IECM_RX_MAX_PTYPE		1024
+#define IECM_RX_MAX_BASE_PTYPE		256
+
+#define IECM_INT_NAME_STR_LEN	(IFNAMSIZ + 16)
+
+/* Lookup table mapping the HW PTYPE to the bit field for decoding */
+extern const struct iecm_rx_ptype_decoded iecm_ptype_lookup[IECM_RX_MAX_PTYPE];
 
 enum iecm_queue_flags_t {
 	__IECM_Q_GEN_CHK,
@@ -318,6 +512,4 @@ void iecm_vport_calc_total_qs(struct iecm_adapter *adapter,
 			      struct virtchnl2_create_vport *vport_msg);
 void iecm_vport_calc_num_q_groups(struct iecm_vport *vport);
 void iecm_vport_calc_num_q_vec(struct iecm_vport *vport);
-irqreturn_t
-iecm_vport_intr_clean_queues(int __always_unused irq, void *data);
 #endif /* !_IECM_TXRX_H_ */
Signature · 1 line
2.33.0

Thanks,
Al

#33 lore raw

PATCH 7/19 iecm: finish virtchnl messages

Quoted 62 lines

-----Original Message-----
From: Lobakin, Alexandr <[email protected]>
Sent: Friday, January 28, 2022 5:20 AM
To: Brady, Alan <[email protected]>
Cc: Lobakin, Alexandr <[email protected]>; intel-wired- lan at lists.osuosl.org; Linga, Pavan Kumar <[email protected]>; Chittim, Madhu <[email protected]>; Burra, Phani R <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net-next 07/19] iecm: finish virtchnl messages

From: Alan Brady <[email protected]>
Date: Thu, 27 Jan 2022 16:09:57 -0800

Quoted 17 lines

This adds the rest of the needed virtchnl messages mostly related to negotiating ptypes and initializing queue registers.

---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    |   21 +-
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   |  226 +++-
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   | 1187 ++++++++++++++++-
 drivers/net/ethernet/intel/include/iecm.h     |   36 +
 .../net/ethernet/intel/include/iecm_txrx.h    |  198 ++-
 5 files changed, 1635 insertions(+), 33 deletions(-)

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 5 lines

index 4e9cc7f2d138..aab8ee40424e 100644

drivers/net/ethernet/intel/iecm/iecm_lib.c +0 -0
@@ -10,6 +10,25 @@ const char * const iecm_vport_vc_state_str[] = {
 };

drivers/net/ethernet/intel/iecm/iecm_lib.c const char * const iecm_vport_vc_state_str[] = { · line 20

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +8 -0
 EXPORT_SYMBOL(iecm_vport_vc_state_str);
 
+/**
+ * iecm_is_feature_ena - Determine if a particular feature is enabled
+ * @vport: vport to check
+ * @feature: netdev flag to check
+ *
+ * Returns true or false if a particular feature is enabled.
+ */
+bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t

feature)

drivers/net/ethernet/intel/iecm/iecm_lib.c const char * const iecm_vport_vc_state_str[] = { · line 30

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+{
+	bool ena;
+
+	switch (feature) {
+	default:
+		ena = vport->netdev->features & feature;
+		break;
+	}
+	return ena;
+}

This makes absolutely no sense, please rewrite to

Quoted 4 lines
	return vport->netdev->features & feature;

If it will be expanded later, convert it to a switch-case only then.

A case is added later in this series of patches but I can thrash this in the middle of the series if you feel strongly about it.

Quoted 1,476 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c iecm_vport_alloc(struct iecm_adapter *adapter, int

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +1 -0
+
 /**
  * iecm_cfg_hw - Initialize HW struct
  * @adapter: adapter to setup hw struct for
@@ -132,7 +151,7 @@ iecm_vport_alloc(struct iecm_adapter *adapter, int

vport_id)

Review

Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +1 -1
 	adapter->num_alloc_vport++;
 
 	/* Setup default MSIX irq handler for the vport */
-	vport->irq_q_handler = iecm_vport_intr_clean_queues;
+	vport->irq_q_handler = NULL;
 	vport->q_vector_base = IECM_NONQ_VEC;
 
 	mutex_init(&vport->stop_mutex);
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/iecm/iecm_txrx.c

Quoted 8 lines

index 2dfb0be002e3..bd0cfd89bf03 100644

drivers/net/ethernet/intel/iecm/iecm_txrx.c +0 -1
@@ -3,22 +3,220 @@
 
 #include "iecm.h"
 
-/**

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 6

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -9
- * iecm_vport_intr_clean_queues - MSIX mode Interrupt Handler
- * @irq: interrupt number
- * @data: pointer to a q_vector
- *
- */
-irqreturn_t
-iecm_vport_intr_clean_queues(int __always_unused irq, void *data)
-{
-	struct iecm_q_vector *q_vector = (struct iecm_q_vector *)data;
+const struct iecm_rx_ptype_decoded

iecm_ptype_lookup[IECM_RX_MAX_PTYPE] = {

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 7

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	/* ptype indices are dynamic and package dependent. Indices

represented

Quoted 73 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +67 -4
+	 * in this lookup table are for reference and will be replaced by the
+	 * values which CP sends. Also these values are static for older
+	 * versions of virtchnl and if VIRTCHNL2_CAP_PTYPE is not set in
+	 * virtchnl2_get_capabilities.
+	 */
+	/* L2 Packet types */
+	IECM_PTT_UNUSED_ENTRY(0),
+	IECM_PTT(1,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
+	IECM_PTT(2,  L2, NONE, NOF, NONE, NONE, NOF, TS,   PAY2),
+	IECM_PTT(3,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
+	IECM_PTT_UNUSED_ENTRY(4),
+	IECM_PTT_UNUSED_ENTRY(5),
+	IECM_PTT(6,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
+	IECM_PTT(7,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
+	IECM_PTT_UNUSED_ENTRY(8),
+	IECM_PTT_UNUSED_ENTRY(9),
+	IECM_PTT(10, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
+	IECM_PTT(11, L2, NONE, NOF, NONE, NONE, NOF, NONE, NONE),
+	IECM_PTT(12, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(13, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(14, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(15, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(16, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(17, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(18, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(19, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(20, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(21, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
 
-	q_vector->total_events++;
-	napi_schedule(&q_vector->napi);
+	/* Non Tunneled IPv4 */
+	IECM_PTT(22, IP, IPV4, FRG, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(23, IP, IPV4, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(24, IP, IPV4, NOF, NONE, NONE, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(25),
+	IECM_PTT(26, IP, IPV4, NOF, NONE, NONE, NOF, TCP,  PAY4),
+	IECM_PTT(27, IP, IPV4, NOF, NONE, NONE, NOF, SCTP, PAY4),
+	IECM_PTT(28, IP, IPV4, NOF, NONE, NONE, NOF, ICMP, PAY4),
 
-	return IRQ_HANDLED;
-}
+	/* IPv4 --> IPv4 */
+	IECM_PTT(29, IP, IPV4, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
+	IECM_PTT(30, IP, IPV4, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
+	IECM_PTT(31, IP, IPV4, NOF, IP_IP, IPV4, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(32),
+	IECM_PTT(33, IP, IPV4, NOF, IP_IP, IPV4, NOF, TCP,  PAY4),
+	IECM_PTT(34, IP, IPV4, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
+	IECM_PTT(35, IP, IPV4, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
+
+	/* IPv4 --> IPv6 */
+	IECM_PTT(36, IP, IPV4, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
+	IECM_PTT(37, IP, IPV4, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
+	IECM_PTT(38, IP, IPV4, NOF, IP_IP, IPV6, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(39),
+	IECM_PTT(40, IP, IPV4, NOF, IP_IP, IPV6, NOF, TCP,  PAY4),
+	IECM_PTT(41, IP, IPV4, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
+	IECM_PTT(42, IP, IPV4, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
+
+	/* IPv4 --> GRE/NAT */
+	IECM_PTT(43, IP, IPV4, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
+
+	/* IPv4 --> GRE/NAT --> IPv4 */
+	IECM_PTT(44, IP, IPV4, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
+	IECM_PTT(45, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
+	IECM_PTT(46, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(47),
+	IECM_PTT(48, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, TCP,  PAY4),
+	IECM_PTT(49, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
+	IECM_PTT(50, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
+
+	/* IPv4 --> GRE/NAT --> IPv6 */

drivers/net/ethernet/intel/iecm/iecm_txrx.c

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+	IECM_PTT(51, IP, IPV4, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
+	IECM_PTT(52, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
+	IECM_PTT(53, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(54),
+	IECM_PTT(55, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, TCP,  PAY4),
+	IECM_PTT(56, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
+	IECM_PTT(57, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
+
+	/* IPv4 --> GRE/NAT --> MAC */
+	IECM_PTT(58, IP, IPV4, NOF, IP_GRENAT_MAC, NONE, NOF, NONE,

PAY3),

drivers/net/ethernet/intel/iecm/iecm_txrx.c

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
+
+	/* IPv4 --> GRE/NAT --> MAC --> IPv4 */
+	IECM_PTT(59, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE,

PAY3),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 90

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	IECM_PTT(60, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE,

PAY3),

drivers/net/ethernet/intel/iecm/iecm_txrx.c

Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +8 -0
+	IECM_PTT(61, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(62),
+	IECM_PTT(63, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP,  PAY4),
+	IECM_PTT(64, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
+	IECM_PTT(65, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
+
+	/* IPv4 --> GRE/NAT -> MAC --> IPv6 */
+	IECM_PTT(66, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE,

PAY3),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 99

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	IECM_PTT(67, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE,

PAY3),

drivers/net/ethernet/intel/iecm/iecm_txrx.c

Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +8 -0
+	IECM_PTT(68, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(69),
+	IECM_PTT(70, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP,  PAY4),
+	IECM_PTT(71, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
+	IECM_PTT(72, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
+
+	/* IPv4 --> GRE/NAT --> MAC/VLAN */
+	IECM_PTT(73, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF,

NONE, PAY3),

drivers/net/ethernet/intel/iecm/iecm_txrx.c

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
+
+	/* IPv4 ---> GRE/NAT -> MAC/VLAN --> IPv4 */
+	IECM_PTT(74, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG,

NONE, PAY3),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 111

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	IECM_PTT(75, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF,

NONE, PAY3),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 112

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	IECM_PTT(76, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP,

PAY4),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 114

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +2 -0
+	IECM_PTT_UNUSED_ENTRY(77),
+	IECM_PTT(78, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP,

PAY4),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 115

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	IECM_PTT(79, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP,

PAY4),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 116

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	IECM_PTT(80, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP,

PAY4),

drivers/net/ethernet/intel/iecm/iecm_txrx.c

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
+
+	/* IPv4 -> GRE/NAT -> MAC/VLAN --> IPv6 */
+	IECM_PTT(81, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG,

NONE, PAY3),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 120

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	IECM_PTT(82, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF,

NONE, PAY3),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 121

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	IECM_PTT(83, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP,

PAY4),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 123

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +2 -0
+	IECM_PTT_UNUSED_ENTRY(84),
+	IECM_PTT(85, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP,

PAY4),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 124

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	IECM_PTT(86, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP,

PAY4),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 125

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	IECM_PTT(87, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP,

PAY4),

Quoted 41 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +41 -0
+
+	/* Non Tunneled IPv6 */
+	IECM_PTT(88, IP, IPV6, FRG, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(89, IP, IPV6, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(90, IP, IPV6, NOF, NONE, NONE, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(91),
+	IECM_PTT(92, IP, IPV6, NOF, NONE, NONE, NOF, TCP,  PAY4),
+	IECM_PTT(93, IP, IPV6, NOF, NONE, NONE, NOF, SCTP, PAY4),
+	IECM_PTT(94, IP, IPV6, NOF, NONE, NONE, NOF, ICMP, PAY4),
+
+	/* IPv6 --> IPv4 */
+	IECM_PTT(95,  IP, IPV6, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
+	IECM_PTT(96,  IP, IPV6, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
+	IECM_PTT(97,  IP, IPV6, NOF, IP_IP, IPV4, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(98),
+	IECM_PTT(99,  IP, IPV6, NOF, IP_IP, IPV4, NOF, TCP,  PAY4),
+	IECM_PTT(100, IP, IPV6, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
+	IECM_PTT(101, IP, IPV6, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
+
+	/* IPv6 --> IPv6 */
+	IECM_PTT(102, IP, IPV6, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
+	IECM_PTT(103, IP, IPV6, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
+	IECM_PTT(104, IP, IPV6, NOF, IP_IP, IPV6, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(105),
+	IECM_PTT(106, IP, IPV6, NOF, IP_IP, IPV6, NOF, TCP,  PAY4),
+	IECM_PTT(107, IP, IPV6, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
+	IECM_PTT(108, IP, IPV6, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
+
+	/* IPv6 --> GRE/NAT */
+	IECM_PTT(109, IP, IPV6, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
+
+	/* IPv6 --> GRE/NAT -> IPv4 */
+	IECM_PTT(110, IP, IPV6, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
+	IECM_PTT(111, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
+	IECM_PTT(112, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(113),
+	IECM_PTT(114, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, TCP,  PAY4),
+	IECM_PTT(115, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
+	IECM_PTT(116, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
+
+	/* IPv6 --> GRE/NAT -> IPv6 */

drivers/net/ethernet/intel/iecm/iecm_txrx.c

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+	IECM_PTT(117, IP, IPV6, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
+	IECM_PTT(118, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
+	IECM_PTT(119, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(120),
+	IECM_PTT(121, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, TCP,  PAY4),
+	IECM_PTT(122, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
+	IECM_PTT(123, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
+
+	/* IPv6 --> GRE/NAT -> MAC */
+	IECM_PTT(124, IP, IPV6, NOF, IP_GRENAT_MAC, NONE, NOF, NONE,

PAY3),

drivers/net/ethernet/intel/iecm/iecm_txrx.c

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
+
+	/* IPv6 --> GRE/NAT -> MAC -> IPv4 */
+	IECM_PTT(125, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE,

PAY3),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 180

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	IECM_PTT(126, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE,

PAY3),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 181

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	IECM_PTT(127, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP,

PAY4),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 183

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +2 -0
+	IECM_PTT_UNUSED_ENTRY(128),
+	IECM_PTT(129, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP,

PAY4),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 184

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	IECM_PTT(130, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP,

PAY4),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 185

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	IECM_PTT(131, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP,

PAY4),

drivers/net/ethernet/intel/iecm/iecm_txrx.c

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
+
+	/* IPv6 --> GRE/NAT -> MAC -> IPv6 */
+	IECM_PTT(132, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE,

PAY3),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 189

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	IECM_PTT(133, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE,

PAY3),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 190

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	IECM_PTT(134, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP,

PAY4),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 192

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +2 -0
+	IECM_PTT_UNUSED_ENTRY(135),
+	IECM_PTT(136, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP,

PAY4),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 193

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	IECM_PTT(137, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP,

PAY4),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 194

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	IECM_PTT(138, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP,

PAY4),

drivers/net/ethernet/intel/iecm/iecm_txrx.c

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
+
+	/* IPv6 --> GRE/NAT -> MAC/VLAN */
+	IECM_PTT(139, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF,

NONE, PAY3),

drivers/net/ethernet/intel/iecm/iecm_txrx.c

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
+
+	/* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv4 */
+	IECM_PTT(140, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG,

NONE, PAY3),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 201

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	IECM_PTT(141, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF,

NONE, PAY3),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 202

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	IECM_PTT(142, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP,

PAY4),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 204

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +2 -0
+	IECM_PTT_UNUSED_ENTRY(143),
+	IECM_PTT(144, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP,

PAY4),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 205

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	IECM_PTT(145, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF,

SCTP, PAY4),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 206

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	IECM_PTT(146, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF,

ICMP, PAY4),

drivers/net/ethernet/intel/iecm/iecm_txrx.c

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
+
+	/* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv6 */
+	IECM_PTT(147, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG,

NONE, PAY3),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 210

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	IECM_PTT(148, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF,

NONE, PAY3),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 211

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	IECM_PTT(149, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP,

PAY4),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 213

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +2 -0
+	IECM_PTT_UNUSED_ENTRY(150),
+	IECM_PTT(151, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP,

PAY4),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 214

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	IECM_PTT(152, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF,

SCTP, PAY4),

drivers/net/ethernet/intel/iecm/iecm_txrx.c line 215

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	IECM_PTT(153, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF,

ICMP, PAY4),

Review

Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +4 -0
+
+	/* rest of the entries are unused */
+};
+EXPORT_SYMBOL(iecm_ptype_lookup);
 
 /**
  * iecm_vport_init_num_qs - Initialize number of queues
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/iecm/iecm_virtchnl.c

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_recv_get_caps_msg(struct

Quoted 4 lines

index d8152e657e24..c4ae56897d1b 100644

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +0 -0
@@ -859,6 +859,15 @@ static int iecm_recv_get_caps_msg(struct

iecm_adapter *adapter)

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_get_reg_intr_vecs(struct iecm_vport

Quoted 16 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +9 -0
 				sizeof(struct virtchnl2_get_capabilities));
 }
 
+/**
+ * iecm_vport_init_max_qs - Initialize max queues supported on this device
+ * @adapter: Driver specific private structure
+ */
+static void iecm_vport_init_max_qs(struct iecm_adapter *adapter)
+{
+	adapter->max_queue_limit = IECM_MAX_Q;
+}
+
 /**
  * iecm_get_reg_intr_vecs - Get vector queue register offset
  * @vport: virtual port structure
@@ -901,6 +910,199 @@ int iecm_get_reg_intr_vecs(struct iecm_vport

*vport,

Quoted 27 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +23 -0
 }
 EXPORT_SYMBOL(iecm_get_reg_intr_vecs);
 
+/**
+ * iecm_vport_get_q_reg - Get the queue registers for the vport
+ * @reg_vals: register values needing to be set
+ * @num_regs: amount we expect to fill
+ * @q_type: queue model
+ * @chunks: queue regs received over mailbox
+ */
+static int
+iecm_vport_get_q_reg(u32 *reg_vals, int num_regs, u32 q_type,
+		     struct virtchnl2_queue_reg_chunks *chunks)
+{
+	u16 num_chunks = le16_to_cpu(chunks->num_chunks);
+	int reg_filled = 0, i;
+	u32 reg_val;
+	u16 num_q;
+
+	while (num_chunks) {
+		struct virtchnl2_queue_reg_chunk *chunk = &chunks-
 chunks[num_chunks - 1];
+
+		if (le32_to_cpu(chunk->type) == q_type) {
+			num_q = le32_to_cpu(chunk->num_queues);
+			reg_val = le64_to_cpu(chunk->qtail_reg_start);
+			for (i = 0; i < num_q; i++) {

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_get_reg_intr_vecs(struct iecm_vport *vport, · line 944

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +9 -0
+				if (reg_filled == num_regs)
+					break;
+				reg_vals[reg_filled++] = reg_val;
+				reg_val +=
+					le32_to_cpu(chunk-
 qtail_reg_spacing);
+			}
+		}
+		num_chunks--;
+	}
	while (num_chunks--) {
		struct ... = ... [num_chunks];

		if (le32_to_cpu(chunk->type) != q_type)
			continue;

		...
	}

-1 indent level, -complexity.

Quoted 38 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +38 -0
+
+	return reg_filled;
+}
+
+/**
+ * __iecm_queue_reg_init - initialize queue registers
+ * @vport: virtual port structure
+ * @reg_vals: registers we are initializing
+ * @num_regs: how many registers there are in total
+ * @q_type: queue model
+ *
+ * Return number of queues that are initialized
+ */
+static int
+__iecm_queue_reg_init(struct iecm_vport *vport, u32 *reg_vals,
+		      int num_regs, u32 q_type)
+{
+	struct iecm_hw *hw = &vport->adapter->hw;
+	struct iecm_queue *q;
+	int i, j, k = 0;
+
+	switch (q_type) {
+	case VIRTCHNL2_QUEUE_TYPE_TX:
+		for (i = 0; i < vport->num_txq_grp; i++) {
+			struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+
+			for (j = 0; j < tx_qgrp->num_txq; j++) {
+				if (k == num_regs)
+					break;
+
+				tx_qgrp->txqs[j]->tail =
+				  (__force u8 __iomem *)(hw->hw_addr +
+							 reg_vals[k]);
+				k++;
+			}
+		}
+		break;
+	case VIRTCHNL2_QUEUE_TYPE_RX:

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_get_reg_intr_vecs(struct iecm_vport *vport,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+		for (i = 0; i < vport->num_rxq_grp; i++) {
+			struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+			int num_rxq = rx_qgrp->singleq.num_rxq;
+
+			for (j = 0; j < num_rxq; j++) {
+				if (k == num_regs)
+					break;
+
+				q = rx_qgrp->singleq.rxqs[j];
+				q->tail = (__force u8 __iomem *)(hw->hw_addr

+

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +5 -0
+								 reg_vals[k]);
+				k++;
+			}
+		}
+		break;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_get_reg_intr_vecs(struct iecm_vport *vport,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+	case VIRTCHNL2_QUEUE_TYPE_RX_BUFFER:
+		for (i = 0; i < vport->num_rxq_grp; i++) {
+			struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++) {
+				if (k == num_regs)
+					break;
+
+				q = &rx_qgrp->splitq.bufq_sets[j].bufq;
+				q->tail = (__force u8 __iomem *)(hw->hw_addr

+

Quoted 53 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +53 -0
+								 reg_vals[k]);
+				k++;
+			}
+		}
+		break;
+	default:
+		break;
+	}
+
+	return k;
+}
+
+/**
+ * iecm_queue_reg_init - initialize queue registers
+ * @vport: virtual port structure
+ *
+ * Return 0 on success, negative on failure
+ */
+static int iecm_queue_reg_init(struct iecm_vport *vport)
+{
+	struct virtchnl2_create_vport *vport_params;
+	struct virtchnl2_queue_reg_chunks *chunks;
+	int num_regs, ret = 0;
+	u32 *reg_vals;
+
+	/* We may never deal with more than 256 same type of queues */
+	reg_vals = kmalloc(sizeof(void *) * IECM_LARGE_MAX_Q,
+			   GFP_KERNEL);
+	if (!reg_vals)
+		return -ENOMEM;
+
+	if (vport->adapter->config_data.req_qs_chunks) {
+		struct virtchnl2_add_queues *vc_aq =
+		  (struct virtchnl2_add_queues *)
+		  vport->adapter->config_data.req_qs_chunks;
+		chunks = &vc_aq->chunks;
+	} else {
+		vport_params = (struct virtchnl2_create_vport *)
+			vport->adapter->vport_params_recvd[0];
+		chunks = &vport_params->chunks;
+	}
+
+	/* Initialize Tx queue tail register address */
+	num_regs = iecm_vport_get_q_reg(reg_vals, IECM_LARGE_MAX_Q,
+					VIRTCHNL2_QUEUE_TYPE_TX,
+					chunks);
+	if (num_regs < vport->num_txq) {
+		ret = -EINVAL;
+		goto free_reg_vals;
+	}
+
+	num_regs = __iecm_queue_reg_init(vport, reg_vals, num_regs,
+					 VIRTCHNL2_QUEUE_TYPE_TX);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_get_reg_intr_vecs(struct iecm_vport *vport,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+	if (num_regs < vport->num_txq) {
+		ret = -EINVAL;
+		goto free_reg_vals;
+	}
+
+	/* Initialize Rx/buffer queue tail register address based on Rx queue
+	 * model
+	 */
+	if (iecm_is_queue_model_split(vport->rxq_model)) {
+		num_regs = iecm_vport_get_q_reg(reg_vals,

IECM_LARGE_MAX_Q,

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_get_reg_intr_vecs(struct iecm_vport · line 1073

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +1 -0
+

VIRTCHNL2_QUEUE_TYPE_RX_BUFFER,

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_get_reg_intr_vecs(struct iecm_vport *vport, · line 1092

Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +8 -0
+						chunks);
+		if (num_regs < vport->num_bufq) {
+			ret = -EINVAL;
+			goto free_reg_vals;
+		}
+
+		num_regs = __iecm_queue_reg_init(vport, reg_vals, num_regs,
+

VIRTCHNL2_QUEUE_TYPE_RX_BUFFER);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_get_reg_intr_vecs(struct iecm_vport *vport,

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +6 -0
+		if (num_regs < vport->num_bufq) {
+			ret = -EINVAL;
+			goto free_reg_vals;
+		}
+	} else {
+		num_regs = iecm_vport_get_q_reg(reg_vals,

IECM_LARGE_MAX_Q,

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_get_reg_intr_vecs(struct iecm_vport *vport, · line 1100

Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +9 -0
+						VIRTCHNL2_QUEUE_TYPE_RX,
+						chunks);
+		if (num_regs < vport->num_rxq) {
+			ret = -EINVAL;
+			goto free_reg_vals;
+		}
+
+		num_regs = __iecm_queue_reg_init(vport, reg_vals, num_regs,
+

VIRTCHNL2_QUEUE_TYPE_RX);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_send_create_vport_msg(struct

Quoted 15 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +11 -0
+		if (num_regs < vport->num_rxq) {
+			ret = -EINVAL;
+			goto free_reg_vals;
+		}
+	}
+
+free_reg_vals:
+	kfree(reg_vals);
+	return ret;
+}
+
 /**

* iecm_send_create_vport_msg - Send virtchnl create vport message
* @adapter: Driver specific private structure

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +0 -0
@@ -943,6 +1145,66 @@ static int iecm_send_create_vport_msg(struct

iecm_adapter *adapter)

Quoted 12 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +9 -0
 				(u8 *)vport_msg);
 }
 
+/**
+ * iecm_check_descs - Verify we have the descriptor support required
+ * @vport: virtual port structure
+ * @rx_desc_ids: Rx descriptor ids to check
+ * @tx_desc_ids: Tx descriptor ids to check
+ * @rxq_model: Rx queue model
+ * @txq_model: Tx queue model
+ *
+ * Returns 0 on success, negative if we didn't get sufficient descriptor

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_send_create_vport_msg(struct iecm_adapter *adapter)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+ * support.
+ */
+int iecm_check_descs(struct iecm_vport *vport, u64 rx_desc_ids,
+		     u64 tx_desc_ids, u16 rxq_model, u16 txq_model)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+
+	if (rxq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) {
+		if (!(rx_desc_ids & VIRTCHNL2_RXDID_1_FLEX_SPLITQ_M)) {
+			dev_err(&adapter->pdev->dev, "No supported RX

descriptors provided");

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_send_create_vport_msg(struct iecm_adapter *adapter)

Quoted 13 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +13 -0
+			return -EINVAL;
+		}
+	} else {
+		if (!(rx_desc_ids & VIRTCHNL2_RXDID_2_FLEX_SQ_NIC_M))
+			vport->base_rxd = true;
+	}
+
+	if (txq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) {
+#define MIN_SUPPORT_TXDID (\
+		VIRTCHNL2_TXDID_FLEX_FLOW_SCHED |\
+		VIRTCHNL2_TXDID_FLEX_TSO_CTX |\
+		VIRTCHNL2_TXDID_FLEX_DATA)
+		if ((tx_desc_ids & MIN_SUPPORT_TXDID) !=

MIN_SUPPORT_TXDID) {

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_send_create_vport_msg(struct · line 1180

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +1 -0
+			dev_err(&adapter->pdev->dev, "Minimum TX descriptor

support not provided");

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+			return -EINVAL;
+		}
+	}
+	return 0;
+}
+EXPORT_SYMBOL(iecm_check_descs);
+
+/**
+ * iecm_get_supported_desc_ids - Get supported Rx and Tx descriptor ids
+ * @vport: virtual port structure

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_send_create_vport_msg(struct iecm_adapter *adapter)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+ *
+ * Return 0 on success, error on failure
+ */
+static int iecm_get_supported_desc_ids(struct iecm_vport *vport)
+{
+	struct virtchnl2_create_vport *vport_msg;
+
+	vport_msg = (struct virtchnl2_create_vport *)
+			vport->adapter->vport_params_recvd[0];
+	vport_msg->rx_desc_ids =

cpu_to_le64(VIRTCHNL2_RXDID_1_FLEX_SPLITQ_M);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_send_config_rx_queues_msg(struct

Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +7 -0
+	vport_msg->tx_desc_ids = cpu_to_le64(MIN_SUPPORT_TXDID);
+
+	return iecm_check_descs(vport, le64_to_cpu(vport_msg->rx_desc_ids),
+				le64_to_cpu(vport_msg->tx_desc_ids),
+				vport->rxq_model, vport->txq_model);
+}
+
 /**
  * iecm_recv_create_vport_msg - Receive virtchnl create vport message
  * @adapter: Driver specific private structure
@@ -1333,6 +1595,9 @@ int iecm_send_config_rx_queues_msg(struct

iecm_vport *vport)

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_send_config_rx_queues_msg(struct · line 1599

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +1 -0
 					bufq->rx_buf_stride;
 				qi[k].rx_buffer_low_watermark =
 					cpu_to_le16(bufq-
 rx_buffer_low_watermark);
+				if (iecm_is_feature_ena(vport,

NETIF_F_GRO_HW))

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_send_config_rx_queues_msg(struct · line 1601

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +2 -0
+					qi[k].qflags |=
+
	cpu_to_le16(VIRTCHNL2_RXQ_RSC);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_send_config_rx_queues_msg(struct

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +0 -0
 			}
 		}
@@ -1361,6 +1626,9 @@ int iecm_send_config_rx_queues_msg(struct

iecm_vport *vport)

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_send_config_rx_queues_msg(struct · line 1630

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +1 -0
 					qi[k].hdr_buffer_size =
 						cpu_to_le16(rxq-
 rx_hbuf_size);
 				}
+				if (iecm_is_feature_ena(vport,

NETIF_F_GRO_HW))

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_send_config_rx_queues_msg(struct · line 1632

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +2 -0
+					qi[k].qflags |=
+
	cpu_to_le16(VIRTCHNL2_RXQ_RSC);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_send_add_queues_msg(struct

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +0 -0
 			} else {
 				rxq = rx_qgrp->singleq.rxqs[j];
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +0 -0
 			}
@@ -1968,6 +2236,765 @@ int iecm_send_add_queues_msg(struct

iecm_vport *vport, u16 num_tx_q,

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,

Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +8 -0
 	return err;
 }
 
+/**
+ * iecm_send_alloc_vectors_msg - Send virtchnl alloc vectors message
+ * @adapter: Driver specific private structure
+ * @num_vectors: number of vectors to be allocated
+ *
+ * Returns 0 on success, negative on failure.
+ */
+int iecm_send_alloc_vectors_msg(struct iecm_adapter *adapter, u16

num_vectors)

Quoted 33 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +33 -0
+{
+	struct virtchnl2_alloc_vectors *alloc_vec;
+	struct virtchnl2_alloc_vectors ac = {0};
+	int size, err;
+
+	ac.num_vectors = cpu_to_le16(num_vectors);
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_ALLOC_VECTORS,
+			       sizeof(ac), (u8 *)&ac);
+	if (err)
+		return err;
+
+	err = iecm_wait_for_event(adapter, IECM_VC_ALLOC_VECTORS,
+				  IECM_VC_ALLOC_VECTORS_ERR);
+	if (err)
+		return err;
+
+	size = sizeof(struct virtchnl2_alloc_vectors) +
+		((num_vectors - 1) *
+		sizeof(struct virtchnl2_vector_chunk));
+
+	kfree(adapter->req_vec_chunks);
+	adapter->req_vec_chunks = NULL;
+	adapter->req_vec_chunks = kzalloc(size, GFP_KERNEL);
+	if (!adapter->req_vec_chunks) {
+		err = -ENOMEM;
+		goto error;
+	}
+	memcpy(adapter->req_vec_chunks, adapter->vc_msg, size);
+
+	alloc_vec = adapter->req_vec_chunks;
+	if (le16_to_cpu(alloc_vec->num_vectors) < num_vectors) {
+		kfree(adapter->req_vec_chunks);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+		adapter->req_vec_chunks = NULL;
+		err = -EINVAL;
+	}
+error:
+	clear_bit(__IECM_VC_MSG_PENDING, adapter->flags);
+	return err;
+}
+
+/**
+ * iecm_send_dealloc_vectors_msg - Send virtchnl de allocate vectors

message

Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +8 -0
+ * @adapter: Driver specific private structure
+ *
+ * Returns 0 on success, negative on failure.
+ */
+int iecm_send_dealloc_vectors_msg(struct iecm_adapter *adapter)
+{
+	struct virtchnl2_vector_chunks *vcs;
+	struct virtchnl2_alloc_vectors *ac;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+	int buf_size, err;
+
+	ac = adapter->req_vec_chunks;
+	vcs = &ac->vchunks;
+
+	buf_size = sizeof(struct virtchnl2_vector_chunks) +
+			((le16_to_cpu(vcs->num_vchunks) - 1) *
+			sizeof(struct virtchnl2_vector_chunk));
+
+	err = iecm_send_mb_msg(adapter,

VIRTCHNL2_OP_DEALLOC_VECTORS, buf_size,

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +4 -0
+			       (u8 *)vcs);
+	if (err)
+		return err;
+	err = iecm_min_wait_for_event(adapter,

IECM_VC_DEALLOC_VECTORS,

Quoted 69 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +69 -0
+				      IECM_VC_DEALLOC_VECTORS_ERR);
+	if (err)
+		return err;
+
+	kfree(adapter->req_vec_chunks);
+	adapter->req_vec_chunks = NULL;
+	return 0;
+}
+
+/**
+ * iecm_send_get_stats_msg - Send virtchnl get statistics message
+ * @vport: vport to get stats for
+ *
+ * Returns 0 on success, negative on failure.
+ */
+int iecm_send_get_stats_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_vport_stats *stats;
+	int err = 0;
+
+	stats = (struct virtchnl2_vport_stats *)adapter->vc_msg;
+
+	/* Don't send get_stats message if one is pending or the
+	 * link is down
+	 */
+	if (test_bit(IECM_VC_GET_STATS, adapter->vc_state) ||
+	    adapter->state <= __IECM_DOWN)
+		goto error;
+
+	stats->vport_id = cpu_to_le32(vport->vport_id);
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_GET_STATS,
+			       sizeof(stats), (u8 *)&stats);
+	if (err)
+		goto error;
+
+	err = iecm_wait_for_event(adapter, IECM_VC_GET_STATS,
+				  IECM_VC_GET_STATS_ERR);
+	if (err)
+		goto error;
+
+	vport->netstats.rx_packets = le64_to_cpu(stats->rx_unicast) +
+				     le64_to_cpu(stats->rx_multicast) +
+				     le64_to_cpu(stats->rx_broadcast);
+	vport->netstats.tx_packets = le64_to_cpu(stats->tx_unicast) +
+				     le64_to_cpu(stats->tx_multicast) +
+				     le64_to_cpu(stats->tx_broadcast);
+	vport->netstats.rx_bytes = le64_to_cpu(stats->rx_bytes);
+	vport->netstats.tx_bytes = le64_to_cpu(stats->tx_bytes);
+	vport->netstats.tx_errors = le64_to_cpu(stats->tx_errors);
+	vport->netstats.rx_dropped = le64_to_cpu(stats->rx_discards);
+	vport->netstats.tx_dropped = le64_to_cpu(stats->tx_discards);
+	vport->port_stats.vport_stats = *stats;
+	clear_bit(__IECM_VC_MSG_PENDING, adapter->flags);
+error:
+	clear_bit(__IECM_MB_STATS_PENDING, vport->adapter->flags);
+
+	return err;
+}
+
+/**
+ * iecm_send_get_set_rss_hash_msg - Send set or get rss hash message
+ * @vport: virtual port data structure
+ * @get: flag to get or set rss hash
+ *
+ * Returns 0 on success, negative on failure.
+ */
+int iecm_send_get_set_rss_hash_msg(struct iecm_vport *vport, bool get)

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_rss_hash rh = {0};
+	int err;
+
+	rh.vport_id = cpu_to_le32(vport->vport_id);
+	rh.ptype_groups = cpu_to_le64(adapter->rss_data.rss_hash);
+
+	if (get) {
+		err = iecm_send_mb_msg(adapter,

VIRTCHNL2_OP_GET_RSS_HASH,

Quoted 47 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +47 -0
+				       sizeof(rh), (u8 *)&rh);
+		if (err)
+			return err;
+
+		err = iecm_wait_for_event(adapter, IECM_VC_GET_RSS_HASH,
+					  IECM_VC_GET_RSS_HASH_ERR);
+		if (err)
+			return err;
+
+		memcpy(&rh, adapter->vc_msg, sizeof(rh));
+		adapter->rss_data.rss_hash = le64_to_cpu(rh.ptype_groups);
+		/* Leave the buffer clean for next message */
+		memset(adapter->vc_msg, 0, IECM_DFLT_MBX_BUF_SIZE);
+		clear_bit(__IECM_VC_MSG_PENDING, adapter->flags);
+
+		return 0;
+	}
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_SET_RSS_HASH,
+			       sizeof(rh), (u8 *)&rh);
+	if (err)
+		return err;
+
+	return  iecm_wait_for_event(adapter, IECM_VC_SET_RSS_HASH,
+				    IECM_VC_SET_RSS_HASH_ERR);
+}
+
+/**
+ * iecm_send_get_set_rss_lut_msg - Send virtchnl get or set rss lut message
+ * @vport: virtual port data structure
+ * @get: flag to set or get rss look up table
+ *
+ * Returns 0 on success, negative on failure.
+ */
+int iecm_send_get_set_rss_lut_msg(struct iecm_vport *vport, bool get)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_rss_lut *recv_rl;
+	struct virtchnl2_rss_lut *rl;
+	int buf_size, lut_buf_size;
+	int i, err = 0;
+
+	buf_size = sizeof(struct virtchnl2_rss_lut) +
+		       (sizeof(u32) * (adapter->rss_data.rss_lut_size - 1));
+	rl = kzalloc(buf_size, GFP_KERNEL);
+	if (!rl)
+		return -ENOMEM;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+
+	if (!get) {
+		rl->lut_entries = cpu_to_le16(adapter->rss_data.rss_lut_size);
+		for (i = 0; i < adapter->rss_data.rss_lut_size; i++)
+			rl->lut[i] = cpu_to_le32(adapter->rss_data.rss_lut[i]);
+	}
+	rl->vport_id = cpu_to_le32(vport->vport_id);
+
+	if (get) {
+		err = iecm_send_mb_msg(vport->adapter,

VIRTCHNL2_OP_GET_RSS_LUT,

Quoted 28 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +28 -0
+				       buf_size, (u8 *)rl);
+		if (err)
+			goto error;
+
+		err = iecm_wait_for_event(adapter, IECM_VC_GET_RSS_LUT,
+					  IECM_VC_GET_RSS_LUT_ERR);
+		if (err)
+			goto error;
+
+		recv_rl = (struct virtchnl2_rss_lut *)adapter->vc_msg;
+		if (adapter->rss_data.rss_lut_size !=
+		    le16_to_cpu(recv_rl->lut_entries)) {
+			adapter->rss_data.rss_lut_size =
+				le16_to_cpu(recv_rl->lut_entries);
+			kfree(adapter->rss_data.rss_lut);
+
+			lut_buf_size = adapter->rss_data.rss_lut_size *
+					sizeof(u32);
+			adapter->rss_data.rss_lut = kzalloc(lut_buf_size,
+							    GFP_KERNEL);
+			if (!adapter->rss_data.rss_lut) {
+				adapter->rss_data.rss_lut_size = 0;
+				/* Leave the buffer clean */
+				memset(adapter->vc_msg, 0,
+				       IECM_DFLT_MBX_BUF_SIZE);
+				clear_bit(__IECM_VC_MSG_PENDING,
+					  adapter->flags);
+				err = -ENOMEM;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+				goto error;
+			}
+		}
+		memcpy(adapter->rss_data.rss_lut, adapter->vc_msg,
+		       adapter->rss_data.rss_lut_size);
+		/* Leave the buffer clean for next message */
+		memset(adapter->vc_msg, 0, IECM_DFLT_MBX_BUF_SIZE);
+		clear_bit(__IECM_VC_MSG_PENDING, adapter->flags);
+	} else {
+		err = iecm_send_mb_msg(adapter,

VIRTCHNL2_OP_SET_RSS_LUT,

Quoted 25 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +25 -0
+				       buf_size, (u8 *)rl);
+		if (err)
+			goto error;
+
+		err = iecm_wait_for_event(adapter, IECM_VC_SET_RSS_LUT,
+					  IECM_VC_SET_RSS_LUT_ERR);
+	}
+error:
+	kfree(rl);
+	return err;
+}
+
+/**
+ * iecm_send_get_set_rss_key_msg - Send virtchnl get or set rss key message
+ * @vport: virtual port data structure
+ * @get: flag to set or get rss look up table
+ *
+ * Returns 0 on success, negative on failure
+ */
+int iecm_send_get_set_rss_key_msg(struct iecm_vport *vport, bool get)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_rss_key *recv_rk;
+	struct virtchnl2_rss_key *rk;
+	int i, buf_size, err = 0;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+
+	buf_size = sizeof(struct virtchnl2_rss_key) +
+		       (sizeof(u8) * (adapter->rss_data.rss_key_size - 1));
+	rk = kzalloc(buf_size, GFP_KERNEL);
+	if (!rk)
+		return -ENOMEM;
+	rk->vport_id = cpu_to_le32(vport->vport_id);
+
+	if (get) {
+		err = iecm_send_mb_msg(adapter,

VIRTCHNL2_OP_GET_RSS_KEY,

Quoted 31 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +30 -0
+				       buf_size, (u8 *)rk);
+		if (err)
+			goto error;
+
+		err = iecm_wait_for_event(adapter, IECM_VC_GET_RSS_KEY,
+					  IECM_VC_GET_RSS_KEY_ERR);
+		if (err)
+			goto error;
+
+		recv_rk = (struct virtchnl2_rss_key *)adapter->vc_msg;
+		if (adapter->rss_data.rss_key_size !=
+		    le16_to_cpu(recv_rk->key_len)) {
+			adapter->rss_data.rss_key_size =
+				min_t(u16, NETDEV_RSS_KEY_LEN,
+				      le16_to_cpu(recv_rk->key_len));
+			kfree(adapter->rss_data.rss_key);
+			adapter->rss_data.rss_key = kzalloc(adapter-
 rss_data.rss_key_size,
+							    GFP_KERNEL);
+			if (!adapter->rss_data.rss_key) {
+				adapter->rss_data.rss_key_size = 0;
+				/* Leave the buffer clean */
+				memset(adapter->vc_msg, 0,
+				       IECM_DFLT_MBX_BUF_SIZE);
+				clear_bit(__IECM_VC_MSG_PENDING,
+					  adapter->flags);
+				err = -ENOMEM;
+				goto error;
+			}
+		}
+		memcpy(adapter->rss_data.rss_key, adapter->vc_msg,

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+		       adapter->rss_data.rss_key_size);
+		/* Leave the buffer clean for next message */
+		memset(adapter->vc_msg, 0, IECM_DFLT_MBX_BUF_SIZE);
+		clear_bit(__IECM_VC_MSG_PENDING, adapter->flags);
+	} else {
+		rk->key_len = cpu_to_le16(adapter->rss_data.rss_key_size);
+		for (i = 0; i < adapter->rss_data.rss_key_size; i++)
+			rk->key[i] = adapter->rss_data.rss_key[i];
+
+		err = iecm_send_mb_msg(adapter,

VIRTCHNL2_OP_SET_RSS_KEY,

Quoted 52 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +52 -0
+				       buf_size, (u8 *)rk);
+		if (err)
+			goto error;
+
+		err = iecm_wait_for_event(adapter, IECM_VC_SET_RSS_KEY,
+					  IECM_VC_SET_RSS_KEY_ERR);
+	}
+error:
+	kfree(rk);
+	return err;
+}
+
+/**
+ * iecm_tpid_to_ethertype - transform from VLAN TPID to virtchnl ethertype
+ * @tpid: VLAN TPID (i.e. 0x8100, 0x88a8, etc.)
+ *
+ * Return virtchnl ethertype
+ */
+static u32 iecm_tpid_to_ethertype(u16 tpid)
+{
+	switch (tpid) {
+	case ETH_P_8021Q:
+		return VIRTCHNL_VLAN_ETHERTYPE_8100;
+	case ETH_P_8021AD:
+		return VIRTCHNL_VLAN_ETHERTYPE_88A8;
+	}
+
+	return 0;
+}
+
+/**
+ * iecm_set_vlan_offload_ethertype - set ethertype for offload message
+ * @adapter: adapter structure
+ * @msg: message structure used for updating offloads
+ * @offload_op: opcode used to determine which support structure to check
+ *
+ * Return 0 on success, negative on failure.
+ */
+static int
+iecm_set_vlan_offload_ethertype(struct iecm_adapter *adapter,
+				struct virtchnl_vlan_setting *msg,
+				enum virtchnl_ops offload_op)
+{
+	struct virtchnl_vlan_supported_caps *offload_support;
+	u16 tpid = adapter->config_data.vlan_ethertype;
+	u32 vc_ethertype;
+
+	vc_ethertype = iecm_tpid_to_ethertype(tpid);
+	/* reference the correct offload support structure */
+	switch (offload_op) {
+	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
+	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+		offload_support =
+			&adapter->vlan_caps->offloads.stripping_support;
+		break;
+	case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
+	case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
+		offload_support =
+			&adapter->vlan_caps->offloads.insertion_support;
+		break;
+	default:
+		dev_err(&adapter->pdev->dev, "Invalid opcode %d for setting

virtchnl ethertype to enable/disable VLAN offloads\n",

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +5 -0
+			offload_op);
+		return -EINVAL;
+	}
+
+	/* make sure ethertype is supported and turning feature on/off

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+	 * is allowed
+	 */
+	if ((offload_support->outer & vc_ethertype) &&
+	    (offload_support->outer & VIRTCHNL_VLAN_TOGGLE)) {
+		msg->outer_ethertype_setting = vc_ethertype;
+	} else if ((offload_support->inner & vc_ethertype) &&
+		   (offload_support->inner & VIRTCHNL_VLAN_TOGGLE)) {
+		msg->inner_ethertype_setting = vc_ethertype;
+	} else {
+		dev_err(&adapter->pdev->dev, "opcode %d unsupported for

VLAN TPID 0x%04x\n",

Quoted 164 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +164 -0
+			offload_op, tpid);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+/**
+ * iecm_send_strip_vlan_msg - Send enable/disable vlan stripping message
+ * @vport: vport structure
+ * @ena: enable or disable vlan stripping
+ *
+ * Returns 0 on success, negative on failure.
+ */
+static int iecm_send_strip_vlan_msg(struct iecm_vport *vport, bool ena)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	enum iecm_vport_vc_state vc, vc_err;
+	struct virtchnl_vlan_setting *msg;
+	enum virtchnl_ops vop;
+	int err, len;
+
+	len = sizeof(struct virtchnl_vlan_setting);
+	msg = kzalloc(sizeof(*msg), GFP_KERNEL);
+
+	if (!msg)
+		return -ENOMEM;
+
+	msg->vport_id = vport->vport_id;
+	if (ena) {
+		vop = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2;
+		vc = IECM_VC_STRIPPING_ENA_VLAN_V2;
+		vc_err = IECM_VC_STRIPPING_ENA_VLAN_V2_ERR;
+	} else {
+		vop = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2;
+		vc = IECM_VC_STRIPPING_DIS_VLAN_V2;
+		vc_err = IECM_VC_STRIPPING_DIS_VLAN_V2_ERR;
+	}
+
+	err = iecm_set_vlan_offload_ethertype(adapter, msg, vop);
+	if (!err) {
+		err = iecm_send_mb_msg(adapter, vop, len, (u8 *)msg);
+		if (!err)
+			err = iecm_wait_for_event(adapter, vc, vc_err);
+	}
+
+	kfree(msg);
+
+	return err;
+}
+
+/**
+ * iecm_send_insert_vlan_msg - Send enable/disable vlan insertion message
+ * @vport: vport structure
+ * @ena: enable/disable vlan insertion
+ *
+ * Returns 0 on success, negative on failure.
+ */
+static int iecm_send_insert_vlan_msg(struct iecm_vport *vport, bool ena)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	enum iecm_vport_vc_state vc, vc_err;
+	struct virtchnl_vlan_setting *msg;
+	enum virtchnl_ops vop;
+	int err, len;
+
+	len = sizeof(struct virtchnl_vlan_setting);
+	msg = kzalloc(sizeof(*msg), GFP_KERNEL);
+
+	if (!msg)
+		return -ENOMEM;
+
+	msg->vport_id = vport->vport_id;
+
+	if (ena) {
+		vop = VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2;
+		vc = IECM_VC_INSERTION_ENA_VLAN_V2;
+		vc_err = IECM_VC_INSERTION_ENA_VLAN_V2_ERR;
+	} else {
+		vop = VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2;
+		vc = IECM_VC_INSERTION_DIS_VLAN_V2;
+		vc_err = IECM_VC_INSERTION_DIS_VLAN_V2_ERR;
+	}
+
+	err = iecm_set_vlan_offload_ethertype(adapter, msg, vop);
+	if (!err) {
+		err = iecm_send_mb_msg(adapter, vop, len, (u8 *)msg);
+		if (!err)
+			err = iecm_wait_for_event(adapter, vc, vc_err);
+	}
+
+	kfree(msg);
+
+	return err;
+}
+
+/**
+ * iecm_fill_ptype_lookup - Fill L3 specific fields in ptype lookup table
+ * @ptype: ptype lookup table
+ * @pstate: state machine for ptype lookup table
+ * @ipv4: ipv4 or ipv6
+ * @frag: fragmentation allowed
+ *
+ */
+static void iecm_fill_ptype_lookup(struct iecm_rx_ptype_decoded *ptype,
+				   struct iecm_ptype_state *pstate,
+				   bool ipv4, bool frag)
+{
+	if (!pstate->outer_ip || !pstate->outer_frag) {
+		ptype->outer_ip = IECM_RX_PTYPE_OUTER_IP;
+		pstate->outer_ip = true;
+
+		if (ipv4)
+			ptype->outer_ip_ver = IECM_RX_PTYPE_OUTER_IPV4;
+		else
+			ptype->outer_ip_ver = IECM_RX_PTYPE_OUTER_IPV6;
+
+		if (frag) {
+			ptype->outer_frag = IECM_RX_PTYPE_FRAG;
+			pstate->outer_frag = true;
+		}
+	} else {
+		ptype->tunnel_type = IECM_RX_PTYPE_TUNNEL_IP_IP;
+		pstate->tunnel_state = IECM_PTYPE_TUNNEL_IP;
+
+		if (ipv4)
+			ptype->tunnel_end_prot =
+					IECM_RX_PTYPE_TUNNEL_END_IPV4;
+		else
+			ptype->tunnel_end_prot =
+					IECM_RX_PTYPE_TUNNEL_END_IPV6;
+
+		if (frag)
+			ptype->tunnel_end_frag = IECM_RX_PTYPE_FRAG;
+	}
+}
+
+/**
+ * iecm_send_get_rx_ptype_msg - Send virtchnl for ptype info
+ * @vport: virtual port data structure
+ *
+ * Returns 0 on success, negative on failure.
+ */
+int iecm_send_get_rx_ptype_msg(struct iecm_vport *vport)
+{
+	struct iecm_rx_ptype_decoded *ptype_lkup = vport->rx_ptype_lkup;
+	struct virtchnl2_get_ptype_info *get_ptype_info, *ptype_info;
+	int max_ptype, ptypes_recvd = 0, len, ptype_offset;
+	struct iecm_adapter *adapter = vport->adapter;
+	int err = 0, i, j, k = 0;
+
+	if (iecm_is_queue_model_split(vport->rxq_model))
+		max_ptype = IECM_RX_MAX_PTYPE;
+	else
+		max_ptype = IECM_RX_MAX_BASE_PTYPE;
+
+	for (i = 0; i < max_ptype; i++)
+		ptype_lkup[i] = iecm_ptype_lookup[0];
+
+	len = sizeof(struct virtchnl2_get_ptype_info);
+	get_ptype_info = kzalloc(len, GFP_KERNEL);
+	if (!get_ptype_info)
+		return -ENOMEM;
+

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+	get_ptype_info->start_ptype_id = 0;
+	get_ptype_info->num_ptypes = cpu_to_le16(max_ptype);
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_GET_PTYPE_INFO,
+			       len, (u8 *)get_ptype_info);
+	if (err)
+		goto get_ptype_rel;
+
+	while (ptypes_recvd < max_ptype) {
+		err = iecm_wait_for_event(adapter,

IECM_VC_GET_PTYPE_INFO,

Quoted 43 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +43 -0
+					  IECM_VC_GET_PTYPE_INFO_ERR);
+		if (err)
+			goto get_ptype_rel;
+
+		len = IECM_DFLT_MBX_BUF_SIZE;
+		ptype_info = kzalloc(len, GFP_KERNEL);
+		if (!ptype_info) {
+			err = -ENOMEM;
+			goto clear_vc_flag;
+		}
+
+		memcpy(ptype_info, adapter->vc_msg, len);
+
+		ptypes_recvd += le16_to_cpu(ptype_info->num_ptypes);
+		if (ptypes_recvd > max_ptype) {
+			err = -EINVAL;
+			goto ptype_rel;
+		}
+
+		ptype_offset = sizeof(struct virtchnl2_get_ptype_info) -
+						sizeof(struct virtchnl2_ptype);
+
+		for (i = 0; i < le16_to_cpu(ptype_info->num_ptypes); i++) {
+			struct iecm_ptype_state pstate = { 0 };
+			struct virtchnl2_ptype *ptype;
+			u16 id;
+
+			ptype = (struct virtchnl2_ptype *)
+					((u8 *)ptype_info + ptype_offset);
+
+			ptype_offset += IECM_GET_PTYPE_SIZE(ptype);
+			if (ptype_offset > len) {
+				err = -EINVAL;
+				goto ptype_rel;
+			}
+
+			if (le16_to_cpu(ptype->ptype_id_10) == 0xFFFF)
+				goto ptype_rel;
+
+			if (iecm_is_queue_model_split(vport->rxq_model))
+				k = le16_to_cpu(ptype->ptype_id_10);
+			else
+				k = ptype->ptype_id_8;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+
+			if (ptype->proto_id_count)
+				ptype_lkup[k].known = 1;
+
+			for (j = 0; j < ptype->proto_id_count; j++) {
+				id = le16_to_cpu(ptype->proto_id[j]);
+				switch (id) {
+				case VIRTCHNL2_PROTO_HDR_GRE:
+					if (pstate.tunnel_state ==
+
	IECM_PTYPE_TUNNEL_IP) {

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_send_add_queues_msg(struct · line 2867

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +2 -0
+						ptype_lkup[k].tunnel_type =
+
	IECM_RX_PTYPE_TUNNEL_IP_GRENAT;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_send_add_queues_msg(struct · line 2869

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +2 -0
+						pstate.tunnel_state |=
+
	IECM_PTYPE_TUNNEL_IP_GRENAT;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,

Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +9 -0
+					}
+					break;
+				case VIRTCHNL2_PROTO_HDR_MAC:
+					ptype_lkup[k].outer_ip =
+						IECM_RX_PTYPE_OUTER_L2;
+					if (pstate.tunnel_state ==
+							IECM_TUN_IP_GRE) {
+						ptype_lkup[k].tunnel_type =
+
	IECM_RX_PTYPE_TUNNEL_IP_GRENAT_MAC;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_send_add_queues_msg(struct · line 2880

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +2 -0
+						pstate.tunnel_state |=
+
	IECM_PTYPE_TUNNEL_IP_GRENAT_MAC;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +5 -0
+					}
+					break;
+				case VIRTCHNL2_PROTO_HDR_VLAN:
+					if (pstate.tunnel_state ==
+
	IECM_TUN_IP_GRE_MAC) {

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_send_add_queues_msg(struct · line 2887

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +2 -0
+						ptype_lkup[k].tunnel_type =
+
	IECM_RX_PTYPE_TUNNEL_IP_GRENAT_MAC_VLAN;

159 lines not shown · raw message

Quoted 10 lines

8 lines not shown · raw message

472 lines not shown · raw message

Part of this message is not shown here. View the raw message.

#34 lore raw

PATCH 7/19 iecm: finish virtchnl messages

From: Alan Brady <[email protected]>
Date: Thu, 3 Feb 2022 00:06:00 +0100

Quoted 62 lines
Quoted 62 lines

-----Original Message-----
From: Lobakin, Alexandr <[email protected]>
Sent: Friday, January 28, 2022 5:20 AM
To: Brady, Alan <[email protected]>
Cc: Lobakin, Alexandr <[email protected]>; intel-wired- lan at lists.osuosl.org; Linga, Pavan Kumar <[email protected]>; Chittim, Madhu <[email protected]>; Burra, Phani R <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net-next 07/19] iecm: finish virtchnl messages

From: Alan Brady <[email protected]>
Date: Thu, 27 Jan 2022 16:09:57 -0800

Quoted 17 lines

This adds the rest of the needed virtchnl messages mostly related to negotiating ptypes and initializing queue registers.

---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    |   21 +-
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   |  226 +++-
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   | 1187 ++++++++++++++++-
 drivers/net/ethernet/intel/include/iecm.h     |   36 +
 .../net/ethernet/intel/include/iecm_txrx.h    |  198 ++-
 5 files changed, 1635 insertions(+), 33 deletions(-)

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 5 lines

index 4e9cc7f2d138..aab8ee40424e 100644

drivers/net/ethernet/intel/iecm/iecm_lib.c +0 -0
@@ -10,6 +10,25 @@ const char * const iecm_vport_vc_state_str[] = {
 };

drivers/net/ethernet/intel/iecm/iecm_lib.c const char * const iecm_vport_vc_state_str[] = { · line 20

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +8 -0
 EXPORT_SYMBOL(iecm_vport_vc_state_str);
 
+/**
+ * iecm_is_feature_ena - Determine if a particular feature is enabled
+ * @vport: vport to check
+ * @feature: netdev flag to check
+ *
+ * Returns true or false if a particular feature is enabled.
+ */
+bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t

feature)

drivers/net/ethernet/intel/iecm/iecm_lib.c const char * const iecm_vport_vc_state_str[] = { · line 30

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+{
+	bool ena;
+
+	switch (feature) {
+	default:
+		ena = vport->netdev->features & feature;
+		break;
+	}
+	return ena;
+}

This makes absolutely no sense, please rewrite to

Quoted 6 lines
Quoted 4 lines
	return vport->netdev->features & feature;

If it will be expanded later, convert it to a switch-case only then.

A case is added later in this series of patches but I can thrash this in the middle of the series if you feel strongly about it.

Doesn't matter. The code of each patch should be reasonable. Even those function stubs don't look nice, but I don't know for sure if this is acceptable, so I didn't speak about them. Sometimes we do such stuff if hardly needed, but at least we leave some good comment then. But I'd go for converting this into a switch-case ad hoc later.

Quoted 5 lines
Quoted 5 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c const char * const iecm_vport_vc_state_str[] = { · line 34

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +1 -0
+
 /**
  * iecm_cfg_hw - Initialize HW struct
  * @adapter: adapter to setup hw struct for

--- 8< ---

Quoted 33 lines
Quoted 33 lines
Quoted 19 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +7 -0
+	u16 num_chunks = le16_to_cpu(chunks->num_chunks);
+	int reg_filled = 0, i;
+	u32 reg_val;
+	u16 num_q;
+
+	while (num_chunks) {
+		struct virtchnl2_queue_reg_chunk *chunk = &chunks-

chunks[num_chunks - 1];

drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+
+		if (le32_to_cpu(chunk->type) == q_type) {
+			num_q = le32_to_cpu(chunk->num_queues);
+			reg_val = le64_to_cpu(chunk->qtail_reg_start);
+			for (i = 0; i < num_q; i++) {
+				if (reg_filled == num_regs)
+					break;
+				reg_vals[reg_filled++] = reg_val;
+				reg_val +=
+					le32_to_cpu(chunk-

qtail_reg_spacing);

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +4 -0
+			}
+		}
+		num_chunks--;
+	}
	while (num_chunks--) {
		struct ... = ... [num_chunks];

		if (le32_to_cpu(chunk->type) != q_type)
			continue;

		...
	}
Quoted 8 lines
Quoted 8 lines

-1 indent level, -complexity.

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +6 -0
+
+	return reg_filled;
+}
+
+/**
+ * __iecm_queue_reg_init - initialize queue registers

--- 8< ---

Quoted 17 lines
Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +7 -0
+struct iecm_page_info {
+	dma_addr_t dma;
+	struct page *page;
+	unsigned int page_offset;
+	u16 pagecnt_bias;
+};
+
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +3 -0
+struct iecm_rx_buf {
+#define IECM_RX_BUF_MAX_PAGES 2
+	struct iecm_page_info page_info[IECM_RX_BUF_MAX_PAGES];

As I said previously, it will most likely be rejected upstream. They will either suggest using compounds or page_pool (it uses compounds for non-zero-order pages) or maybe introduce folio support to the networking stack or so, but not such stuff.

Quoted 3 lines

Perhaps I missed it but I didn't see previous comment about this. We have done our own buffer management in the past and it hasn't been issue. I believe there was an attempt to implement this with compound pages but it didn't work in the ways we needed it to for one reason or another (I don't recall exactly why it was problematic but I can check if you're interested).

A page pool might be a different solution here that may be worth trying, but for many caveats of the data path we've relied on the methods otherwise done in other Intel drivers that have otherwise seemed to do well.

All Intel upstream drivers starting from at least ixgbe and up to (including) ice use compound pages with no issues. There are no 2-page arrays neither in any Intel driver nor in any driver in drivers/net/ at all. Compounds, Page Pool, local page ring, order-0 + multi-frags, kmalloc(HW_JUMBO_LIMIT) and that's it. "We use this [wrong] approach because any other would require more work to be done" is not an argument at all in upstream.

Quoted 6 lines
Quoted 6 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +5 -0
+	u8 page_indx;
+	u16 buf_id;
+	u16 buf_size;
+	struct sk_buff *skb;
+};

--- 8< ---

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

--
2.33.0

Thanks,
Al

Thanks,
Al

#35 lore raw

PATCH 7/19 iecm: finish virtchnl messages

Quoted 152 lines · Alexander Lobakin

From: Alan Brady <[email protected]>
Date: Thu, 3 Feb 2022 00:06:00 +0100

Quoted 62 lines
Quoted 62 lines

-----Original Message-----
From: Lobakin, Alexandr <[email protected]>
Sent: Friday, January 28, 2022 5:20 AM
To: Brady, Alan <[email protected]>
Cc: Lobakin, Alexandr <[email protected]>; intel-wired- lan at lists.osuosl.org; Linga, Pavan Kumar <[email protected]>; Chittim, Madhu <[email protected]>; Burra, Phani R <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net-next 07/19] iecm: finish virtchnl messages

From: Alan Brady <[email protected]>
Date: Thu, 27 Jan 2022 16:09:57 -0800

Quoted 17 lines

This adds the rest of the needed virtchnl messages mostly related to negotiating ptypes and initializing queue registers.

---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    |   21 +-
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   |  226 +++-
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   | 1187 ++++++++++++++++-
 drivers/net/ethernet/intel/include/iecm.h     |   36 +
 .../net/ethernet/intel/include/iecm_txrx.h    |  198 ++-
 5 files changed, 1635 insertions(+), 33 deletions(-)

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 5 lines

index 4e9cc7f2d138..aab8ee40424e 100644

drivers/net/ethernet/intel/iecm/iecm_lib.c +0 -0
@@ -10,6 +10,25 @@ const char * const iecm_vport_vc_state_str[] = {
 };

drivers/net/ethernet/intel/iecm/iecm_lib.c const char * const iecm_vport_vc_state_str[] = { · line 20

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +8 -0
 EXPORT_SYMBOL(iecm_vport_vc_state_str);
 
+/**
+ * iecm_is_feature_ena - Determine if a particular feature is enabled
+ * @vport: vport to check
+ * @feature: netdev flag to check
+ *
+ * Returns true or false if a particular feature is enabled.
+ */
+bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t

feature)

drivers/net/ethernet/intel/iecm/iecm_lib.c const char * const iecm_vport_vc_state_str[] = { · line 30

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+{
+	bool ena;
+
+	switch (feature) {
+	default:
+		ena = vport->netdev->features & feature;
+		break;
+	}
+	return ena;
+}

This makes absolutely no sense, please rewrite to

Quoted 6 lines
Quoted 4 lines
	return vport->netdev->features & feature;

If it will be expanded later, convert it to a switch-case only then.

A case is added later in this series of patches but I can thrash this in the middle of the series if you feel strongly about it.

Doesn't matter. The code of each patch should be reasonable. Even those function stubs don't look nice, but I don't know for sure if this is acceptable, so I didn't speak about them. Sometimes we do such stuff if hardly needed, but at least we leave some good comment then. But I'd go for converting this into a switch-case ad hoc later.

Quoted 5 lines
Quoted 5 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c const char * const iecm_vport_vc_state_str[] = { · line 34

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +1 -0
+
 /**
  * iecm_cfg_hw - Initialize HW struct
  * @adapter: adapter to setup hw struct for

--- 8< ---

Quoted 33 lines
Quoted 33 lines
Quoted 19 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +7 -0
+	u16 num_chunks = le16_to_cpu(chunks->num_chunks);
+	int reg_filled = 0, i;
+	u32 reg_val;
+	u16 num_q;
+
+	while (num_chunks) {
+		struct virtchnl2_queue_reg_chunk *chunk = &chunks-

chunks[num_chunks - 1];

drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+
+		if (le32_to_cpu(chunk->type) == q_type) {
+			num_q = le32_to_cpu(chunk->num_queues);
+			reg_val = le64_to_cpu(chunk->qtail_reg_start);
+			for (i = 0; i < num_q; i++) {
+				if (reg_filled == num_regs)
+					break;
+				reg_vals[reg_filled++] = reg_val;
+				reg_val +=
+					le32_to_cpu(chunk-

qtail_reg_spacing);

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +4 -0
+			}
+		}
+		num_chunks--;
+	}
	while (num_chunks--) {
		struct ... = ... [num_chunks];

		if (le32_to_cpu(chunk->type) != q_type)
			continue;

		...
	}
Quoted 8 lines
Quoted 8 lines

-1 indent level, -complexity.

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +6 -0
+
+	return reg_filled;
+}
+
+/**
+ * __iecm_queue_reg_init - initialize queue registers

--- 8< ---

Quoted 17 lines
Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +7 -0
+struct iecm_page_info {
+	dma_addr_t dma;
+	struct page *page;
+	unsigned int page_offset;
+	u16 pagecnt_bias;
+};
+
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +3 -0
+struct iecm_rx_buf {
+#define IECM_RX_BUF_MAX_PAGES 2
+	struct iecm_page_info page_info[IECM_RX_BUF_MAX_PAGES];

As I said previously, it will most likely be rejected upstream. They will either suggest using compounds or page_pool (it uses compounds for non-zero-order pages) or maybe introduce folio support to the networking stack or so, but not such stuff.

Quoted 3 lines

Perhaps I missed it but I didn't see previous comment about this. We have done our own buffer management in the past and it hasn't been issue. I believe there was an attempt to implement this with compound pages but it didn't work in the ways we needed it to for one reason or another (I don't recall exactly why it was problematic but I can check if you're interested).

A page pool might be a different solution here that may be worth trying, but for many caveats of the data path we've relied on the methods otherwise done in other Intel drivers that have otherwise seemed to do well.

Quoted 7 lines

All Intel upstream drivers starting from at least ixgbe and up to (including) ice use compound pages with no issues. There are no 2-page arrays neither in any Intel driver nor in any driver in drivers/net/ at all. Compounds, Page Pool, local page ring, order-0 + multi-frags, kmalloc(HW_JUMBO_LIMIT) and that's it. "We use this [wrong] approach because any other would require more work to be done" is not an argument at all in upstream.

Maybe not purely rejected but might be controversial to throw in driver quirk onto a patch that by title suppose to add virtchnl messages?

Could you at least describe this change in the commit message? And provide some justification why this approach was picked?

Quoted 22 lines
Quoted 7 lines
Quoted 7 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +5 -0
+	u8 page_indx;
+	u16 buf_id;
+	u16 buf_size;
+	struct sk_buff *skb;
+};

--- 8< ---

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

--
2.33.0

Thanks,
Al

Thanks,
Al
_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan at osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan

author
#36 lore raw

PATCH 8/19 iecm: add interrupts and configure netdev

In reply to Alan Brady

This finishes implementing init_task by adding everything we need to configure the netdevice for the vport and setup its interrupts.

---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    | 813 +++++++++++++++++-
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   |  17 +
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   | 165 ++++
 drivers/net/ethernet/intel/include/iecm.h     | 112 ++-
 .../net/ethernet/intel/include/iecm_txrx.h    |   2 +
 5 files changed, 1104 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/iecm/iecm_lib.c +812 -1
index aab8ee40424e..255b04c25683 100644
@@ -5,11 +5,35 @@
 
 #include "iecm.h"
 
+static const struct net_device_ops iecm_netdev_ops_splitq;
+static const struct net_device_ops iecm_netdev_ops_singleq;
+
 const char * const iecm_vport_vc_state_str[] = {
 	IECM_FOREACH_VPORT_VC_STATE(IECM_GEN_STRING)
 };
 EXPORT_SYMBOL(iecm_vport_vc_state_str);
 
+/**
+ * iecm_get_vport_index - Get the vport index
+ * @adapter: adapter structure to get the vports array
+ * @vport: vport pointer for which the index to find
+ */
+static int iecm_get_vport_index(struct iecm_adapter *adapter,
+				struct iecm_vport *vport)
+{
+	int i, err = -EINVAL;
+
+	if (!adapter->vports)
+		return err;
+
+	for (i = 0; i < adapter->num_alloc_vport; i++) {
+		if (adapter->vports[i] != vport)
+			continue;
+		return i;
+	}
+	return err;
+}
+
 /**
  * iecm_is_feature_ena - Determine if a particular feature is enabled
  * @vport: vport to check
@@ -29,6 +53,595 @@ bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)
 	return ena;
 }
 
+/**
+ * iecm_is_vlan_cap_ena - Check if VLAN capability is enabled
+ * @adapter: pointer to adapter
+ * @vcaps: VLAN capability bit
+ *
+ * Returns true if VLAN capability is set, false otherwise
+ */
+static bool iecm_is_vlan_cap_ena(struct iecm_adapter *adapter,
+				 enum iecm_vlan_caps vcaps)
+{
+	if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_VLAN)) {
+		struct virtchnl_vlan_supported_caps *offload;
+
+		if (!adapter->vlan_caps)
+			return false;
+
+		switch (vcaps) {
+		case IECM_CAP_VLAN_CTAG_INSERT:
+			offload =
+			&adapter->vlan_caps->offloads.insertion_support;
+			if ((offload->outer & IECM_VLAN_8100) == IECM_VLAN_8100 ||
+			    (offload->inner & IECM_VLAN_8100) == IECM_VLAN_8100)
+				return true;
+			break;
+		case IECM_CAP_VLAN_STAG_INSERT:
+			offload =
+			&adapter->vlan_caps->offloads.insertion_support;
+			if ((offload->outer & IECM_VLAN_88A8) == IECM_VLAN_88A8)
+				return true;
+			break;
+		case IECM_CAP_VLAN_CTAG_STRIP:
+			offload =
+			&adapter->vlan_caps->offloads.stripping_support;
+			if ((offload->outer & IECM_VLAN_8100) == IECM_VLAN_8100 ||
+			    (offload->inner & IECM_VLAN_8100) == IECM_VLAN_8100)
+				return true;
+			break;
+		case IECM_CAP_VLAN_STAG_STRIP:
+			offload =
+			&adapter->vlan_caps->offloads.stripping_support;
+			if ((offload->outer & IECM_VLAN_88A8) == IECM_VLAN_88A8)
+				return true;
+			break;
+		case IECM_CAP_VLAN_CTAG_ADD_DEL:
+			offload =
+			&adapter->vlan_caps->filtering.filtering_support;
+			if ((offload->outer & VIRTCHNL_VLAN_ETHERTYPE_8100) ||
+			    (offload->inner & VIRTCHNL_VLAN_ETHERTYPE_8100))
+				return true;
+			break;
+		case IECM_CAP_VLAN_STAG_ADD_DEL:
+			offload =
+			&adapter->vlan_caps->filtering.filtering_support;
+			if ((offload->outer & VIRTCHNL_VLAN_ETHERTYPE_88A8) ||
+			    (offload->inner & VIRTCHNL_VLAN_ETHERTYPE_88A8))
+				return true;
+			break;
+		default:
+			dev_err(&adapter->pdev->dev, "Invalid VLAN capability %d\n",
+				vcaps);
+			return false;
+		}
+	} else if (iecm_is_cap_ena(adapter, IECM_BASE_CAPS,
+				   VIRTCHNL2_CAP_VLAN)) {
+		switch (vcaps) {
+		case IECM_CAP_VLAN_CTAG_INSERT:
+		case IECM_CAP_VLAN_CTAG_STRIP:
+		case IECM_CAP_VLAN_CTAG_ADD_DEL:
+			return true;
+		default:
+			return false;
+		}
+	}
+
+	return false;
+}
+
+/**
+ * iecm_netdev_to_vport - get a vport handle from a netdev
+ * @netdev: network interface device structure
+ */
+struct iecm_vport *iecm_netdev_to_vport(struct net_device *netdev)
+{
+	struct iecm_netdev_priv *np = netdev_priv(netdev);
+
+	return np->vport;
+}
+
+/**
+ * iecm_mb_intr_rel_irq - Free the IRQ association with the OS
+ * @adapter: adapter structure
+ */
+static void iecm_mb_intr_rel_irq(struct iecm_adapter *adapter)
+{
+	int irq_num;
+
+	irq_num = adapter->msix_entries[0].vector;
+	free_irq(irq_num, adapter);
+}
+
+/**
+ * iecm_intr_rel - Release interrupt capabilities and free memory
+ * @adapter: adapter to disable interrupts on
+ */
+static void iecm_intr_rel(struct iecm_adapter *adapter)
+{
+	if (!adapter->msix_entries)
+		return;
+	clear_bit(__IECM_MB_INTR_MODE, adapter->flags);
+	clear_bit(__IECM_MB_INTR_TRIGGER, adapter->flags);
+	iecm_mb_intr_rel_irq(adapter);
+
+	pci_free_irq_vectors(adapter->pdev);
+	if (adapter->dev_ops.vc_ops.dealloc_vectors) {
+		int err;
+
+		err = adapter->dev_ops.vc_ops.dealloc_vectors(adapter);
+		if (err) {
+			dev_err(&adapter->pdev->dev,
+				"Failed to deallocate vectors: %d\n", err);
+		}
+	}
+	kfree(adapter->msix_entries);
+	adapter->msix_entries = NULL;
+	kfree(adapter->req_vec_chunks);
+	adapter->req_vec_chunks = NULL;
+}
+
+/**
+ * iecm_mb_intr_clean - Interrupt handler for the mailbox
+ * @irq: interrupt number
+ * @data: pointer to the adapter structure
+ */
+static irqreturn_t iecm_mb_intr_clean(int __always_unused irq, void *data)
+{
+	struct iecm_adapter *adapter = (struct iecm_adapter *)data;
+
+	set_bit(__IECM_MB_INTR_TRIGGER, adapter->flags);
+	queue_delayed_work(adapter->serv_wq, &adapter->serv_task,
+			   msecs_to_jiffies(0));
+	return IRQ_HANDLED;
+}
+
+/**
+ * iecm_mb_irq_enable - Enable MSIX interrupt for the mailbox
+ * @adapter: adapter to get the hardware address for register write
+ */
+static void iecm_mb_irq_enable(struct iecm_adapter *adapter)
+{
+	struct iecm_hw *hw = &adapter->hw;
+	struct iecm_intr_reg *intr = &adapter->mb_vector.intr_reg;
+	u32 val;
+
+	val = intr->dyn_ctl_intena_m | intr->dyn_ctl_itridx_m;
+	wr32(hw, intr->dyn_ctl, val);
+	wr32(hw, intr->icr_ena, intr->icr_ena_ctlq_m);
+}
+
+/**
+ * iecm_mb_intr_req_irq - Request irq for the mailbox interrupt
+ * @adapter: adapter structure to pass to the mailbox irq handler
+ */
+static int iecm_mb_intr_req_irq(struct iecm_adapter *adapter)
+{
+	struct iecm_q_vector *mb_vector = &adapter->mb_vector;
+	int irq_num, mb_vidx = 0, err;
+
+	irq_num = adapter->msix_entries[mb_vidx].vector;
+	snprintf(mb_vector->name, sizeof(mb_vector->name) - 1,
+		 "%s-%s-%d", dev_driver_string(&adapter->pdev->dev),
+		 "Mailbox", mb_vidx);
+	err = request_irq(irq_num, adapter->irq_mb_handler, 0,
+			  mb_vector->name, adapter);
+	if (err) {
+		dev_err(&adapter->pdev->dev,
+			"Request_irq for mailbox failed, error: %d\n", err);
+		return err;
+	}
+	set_bit(__IECM_MB_INTR_MODE, adapter->flags);
+	return 0;
+}
+
+/**
+ * iecm_get_mb_vec_id - Get vector index for mailbox
+ * @adapter: adapter structure to access the vector chunks
+ *
+ * The first vector id in the requested vector chunks from the CP is for
+ * the mailbox
+ */
+static void iecm_get_mb_vec_id(struct iecm_adapter *adapter)
+{
+	if (adapter->req_vec_chunks) {
+		struct virtchnl2_get_capabilities *caps;
+
+		caps = (struct virtchnl2_get_capabilities *)adapter->caps;
+		adapter->mb_vector.v_idx = le16_to_cpu(caps->mailbox_vector_id);
+	} else {
+		adapter->mb_vector.v_idx = 0;
+	}
+}
+
+/**
+ * iecm_mb_intr_init - Initialize the mailbox interrupt
+ * @adapter: adapter structure to store the mailbox vector
+ */
+static int iecm_mb_intr_init(struct iecm_adapter *adapter)
+{
+	adapter->dev_ops.reg_ops.mb_intr_reg_init(adapter);
+	adapter->irq_mb_handler = iecm_mb_intr_clean;
+	return iecm_mb_intr_req_irq(adapter);
+}
+
+/**
+ * iecm_intr_distribute - Distribute MSIX vectors
+ * @adapter: adapter structure to get the vports
+ * @pre_req: before or after msi request
+ *
+ * Distribute the MSIX vectors acquired from the OS to the vports based on the
+ * num of vectors requested by each vport
+ */
+static int
+iecm_intr_distribute(struct iecm_adapter *adapter, bool pre_req)
+{
+	struct iecm_vport *vport = adapter->vports[0];
+	int err = 0;
+
+	if (pre_req) {
+		u16 vecs_avail;
+
+		vecs_avail = iecm_get_reserved_vecs(adapter);
+		if (vecs_avail < IECM_MIN_VEC) {
+			return -EAGAIN;
+		} else if (vecs_avail == IECM_MIN_VEC) {
+			vport->num_q_vectors = IECM_MIN_Q_VEC;
+		} else {
+			vport->num_q_vectors = vecs_avail - IECM_NONQ_VEC -
+						IECM_MAX_RDMA_VEC;
+		}
+	} else {
+		if (adapter->num_msix_entries != adapter->num_req_msix)
+			vport->num_q_vectors = adapter->num_msix_entries -
+					       IECM_NONQ_VEC;
+	}
+
+	return err;
+}
+
+/**
+ * iecm_intr_req - Request interrupt capabilities
+ * @adapter: adapter to enable interrupts on
+ *
+ * Returns 0 on success, negative on failure
+ */
+static int iecm_intr_req(struct iecm_adapter *adapter)
+{
+	int min_vectors, max_vectors, err = 0;
+	int num_q_vecs, total_num_vecs;
+	u16 vecids[IECM_MAX_VECIDS];
+	unsigned int vector;
+	int v_actual;
+
+	err = iecm_intr_distribute(adapter, true);
+	if (err)
+		return err;
+
+	num_q_vecs = adapter->vports[0]->num_q_vectors;
+
+	total_num_vecs = num_q_vecs + IECM_NONQ_VEC;
+
+	if (adapter->dev_ops.vc_ops.alloc_vectors) {
+		err = adapter->dev_ops.vc_ops.alloc_vectors(adapter,
+							    num_q_vecs);
+		if (err) {
+			dev_err(&adapter->pdev->dev,
+				"Failed to allocate vectors: %d\n", err);
+			return -EAGAIN;
+		}
+	}
+
+	min_vectors = IECM_MIN_VEC;
+	max_vectors = total_num_vecs;
+	v_actual = pci_alloc_irq_vectors(adapter->pdev, min_vectors,
+					 max_vectors, PCI_IRQ_MSIX);
+	if (v_actual < 0) {
+		dev_err(&adapter->pdev->dev, "Failed to allocate MSIX vectors: %d\n",
+			v_actual);
+		if (adapter->dev_ops.vc_ops.dealloc_vectors)
+			adapter->dev_ops.vc_ops.dealloc_vectors(adapter);
+		return -EAGAIN;
+	}
+
+	adapter->msix_entries = kcalloc(v_actual, sizeof(struct msix_entry),
+					GFP_KERNEL);
+
+	if (!adapter->msix_entries) {
+		pci_free_irq_vectors(adapter->pdev);
+		if (adapter->dev_ops.vc_ops.dealloc_vectors)
+			adapter->dev_ops.vc_ops.dealloc_vectors(adapter);
+		return -ENOMEM;
+	}
+
+	iecm_get_mb_vec_id(adapter);
+
+	if (adapter->req_vec_chunks) {
+		struct virtchnl2_vector_chunks *vchunks;
+		struct virtchnl2_alloc_vectors *ac;
+
+		ac = adapter->req_vec_chunks;
+		vchunks = &ac->vchunks;
+
+		iecm_get_vec_ids(adapter, vecids, IECM_MAX_VECIDS, vchunks);
+	} else {
+		int i = 0;
+
+		for (i = 0; i < v_actual; i++)
+			vecids[i] = i;
+	}
+
+	for (vector = 0; vector < v_actual; vector++) {
+		adapter->msix_entries[vector].entry = vecids[vector];
+		adapter->msix_entries[vector].vector =
+			pci_irq_vector(adapter->pdev, vector);
+	}
+	adapter->num_msix_entries = v_actual;
+	adapter->num_req_msix = total_num_vecs;
+
+	iecm_intr_distribute(adapter, false);
+
+	err = iecm_mb_intr_init(adapter);
+	if (err)
+		goto intr_rel;
+	iecm_mb_irq_enable(adapter);
+	return err;
+
+intr_rel:
+	iecm_intr_rel(adapter);
+	return err;
+}
+
+/**
+ * iecm_find_mac_filter - Search filter list for specific mac filter
+ * @vport: main vport structure
+ * @macaddr: the MAC address
+ *
+ * Returns ptr to the filter object or NULL. Must be called while holding the
+ * mac_filter_list_lock.
+ **/
+static struct
+iecm_mac_filter *iecm_find_mac_filter(struct iecm_vport *vport,
+				      const u8 *macaddr)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_mac_filter *f;
+
+	if (!macaddr)
+		return NULL;
+
+	list_for_each_entry(f, &adapter->config_data.mac_filter_list, list) {
+		if (ether_addr_equal(macaddr, f->macaddr))
+			return f;
+	}
+	return NULL;
+}
+
+/**
+ * __iecm_add_mac_filter - Add mac filter helper function
+ * @vport: main vport struct
+ * @macaddr: address to add
+ *
+ * Takes mac_filter_list_lock spinlock to add new filter to list.
+ */
+static struct
+iecm_mac_filter *__iecm_add_mac_filter(struct iecm_vport *vport,
+				       const u8 *macaddr)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_mac_filter *f = NULL;
+
+	spin_lock_bh(&adapter->mac_filter_list_lock);
+	f = iecm_find_mac_filter(vport, macaddr);
+	if (!f) {
+		f = kzalloc(sizeof(*f), GFP_ATOMIC);
+		if (!f) {
+			dev_err(&adapter->pdev->dev, "Failed to allocate filter: %pM",
+				macaddr);
+			goto error;
+		}
+
+		ether_addr_copy(f->macaddr, macaddr);
+
+		list_add_tail(&f->list, &adapter->config_data.mac_filter_list);
+		f->add = true;
+	} else {
+		f->remove = false;
+	}
+error:
+	spin_unlock_bh(&adapter->mac_filter_list_lock);
+
+	return f;
+}
+
+/**
+ * iecm_add_mac_filter - Add a mac filter to the filter list
+ * @vport: main vport structure
+ * @macaddr: the MAC address
+ *
+ * Returns ptr to the filter or NULL on error. If interface is up, we'll also
+ * send the virtchnl message to tell hardware about the filter.
+ **/
+static struct iecm_mac_filter *iecm_add_mac_filter(struct iecm_vport *vport,
+						   const u8 *macaddr)
+{
+	struct iecm_mac_filter *f;
+
+	if (!macaddr)
+		return NULL;
+
+	f = __iecm_add_mac_filter(vport, macaddr);
+	if (!f)
+		return NULL;
+
+	if (vport->adapter->state == __IECM_UP)
+		iecm_add_del_ether_addrs(vport, true, false);
+
+	return f;
+}
+
+/**
+ * iecm_init_mac_addr - initialize mac address for vport
+ * @vport: main vport structure
+ * @netdev: pointer to netdev struct associated with this vport
+ */
+static int iecm_init_mac_addr(struct iecm_vport *vport,
+			      struct net_device *netdev)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+
+	if (!is_valid_ether_addr(vport->default_mac_addr)) {
+		if (!iecm_is_cap_ena(vport->adapter, IECM_OTHER_CAPS,
+				     VIRTCHNL2_CAP_MACFILTER)) {
+			dev_err(&adapter->pdev->dev,
+				"MAC address not provided and capability is not set\n");
+			return -EINVAL;
+		}
+
+		dev_info(&adapter->pdev->dev, "Invalid MAC address %pM, using random\n",
+			 vport->default_mac_addr);
+		eth_hw_addr_random(netdev);
+
+		if (!iecm_add_mac_filter(vport, netdev->dev_addr))
+			return -ENOMEM;
+
+		ether_addr_copy(vport->default_mac_addr, netdev->dev_addr);
+	} else {
+		dev_addr_mod(netdev, 0, vport->default_mac_addr, ETH_ALEN);
+		ether_addr_copy(netdev->perm_addr, vport->default_mac_addr);
+	}
+
+	return 0;
+}
+
+/**
+ * iecm_cfg_netdev - Allocate, configure and register a netdev
+ * @vport: main vport structure
+ *
+ * Returns 0 on success, negative value on failure.
+ */
+static int iecm_cfg_netdev(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	netdev_features_t dflt_features;
+	netdev_features_t offloads = 0;
+	struct iecm_netdev_priv *np;
+	struct net_device *netdev;
+	u16 max_q;
+	int err;
+
+	lockdep_assert_held(&adapter->sw_mutex);
+
+	/* It's possible we already have a netdev allocated and registered for
+	 * this vport
+	 */
+	if (adapter->netdevs[vport->idx]) {
+		netdev = adapter->netdevs[vport->idx];
+		np = netdev_priv(netdev);
+		np->vport = vport;
+		vport->netdev = netdev;
+
+		return iecm_init_mac_addr(vport, netdev);
+	}
+
+	max_q = adapter->max_queue_limit;
+
+	netdev = alloc_etherdev_mqs(sizeof(struct iecm_netdev_priv),
+				    max_q, max_q);
+	if (!netdev)
+		return -ENOMEM;
+	vport->netdev = netdev;
+	np = netdev_priv(netdev);
+	np->vport = vport;
+
+	err = iecm_init_mac_addr(vport, netdev);
+	if (err)
+		goto err;
+
+	/* assign netdev_ops */
+	if (iecm_is_queue_model_split(vport->txq_model))
+		netdev->netdev_ops = &iecm_netdev_ops_splitq;
+	else
+		netdev->netdev_ops = &iecm_netdev_ops_singleq;
+
+	/* setup watchdog timeout value to be 5 second */
+	netdev->watchdog_timeo = 5 * HZ;
+
+	/* configure default MTU size */
+	netdev->min_mtu = ETH_MIN_MTU;
+	netdev->max_mtu = vport->max_mtu;
+
+	dflt_features = NETIF_F_SG	|
+			NETIF_F_HIGHDMA;
+
+	if (iecm_is_cap_ena_all(adapter, IECM_RSS_CAPS, IECM_CAP_RSS))
+		dflt_features |= NETIF_F_RXHASH;
+	if (iecm_is_cap_ena_all(adapter, IECM_CSUM_CAPS, IECM_CAP_RX_CSUM_L4V4))
+		dflt_features |= NETIF_F_IP_CSUM;
+	if (iecm_is_cap_ena_all(adapter, IECM_CSUM_CAPS, IECM_CAP_RX_CSUM_L4V6))
+		dflt_features |= NETIF_F_IPV6_CSUM;
+	if (iecm_is_cap_ena(adapter, IECM_CSUM_CAPS, IECM_CAP_RX_CSUM))
+		dflt_features |= NETIF_F_RXCSUM;
+	if (iecm_is_cap_ena_all(adapter, IECM_CSUM_CAPS, IECM_CAP_SCTP_CSUM))
+		dflt_features |= NETIF_F_SCTP_CRC;
+
+	if (iecm_is_vlan_cap_ena(adapter, IECM_CAP_VLAN_CTAG_INSERT))
+		dflt_features |= IECM_F_HW_VLAN_CTAG_TX;
+	if (iecm_is_vlan_cap_ena(adapter, IECM_CAP_VLAN_CTAG_STRIP))
+		dflt_features |= IECM_F_HW_VLAN_CTAG_RX;
+	if (iecm_is_vlan_cap_ena(adapter, IECM_CAP_VLAN_CTAG_ADD_DEL))
+		dflt_features |= IECM_F_HW_VLAN_CTAG_FILTER;
+
+	if (iecm_is_vlan_cap_ena(adapter, IECM_CAP_VLAN_STAG_INSERT))
+		dflt_features |= NETIF_F_HW_VLAN_STAG_TX;
+	if (iecm_is_vlan_cap_ena(adapter, IECM_CAP_VLAN_STAG_STRIP))
+		dflt_features |= NETIF_F_HW_VLAN_STAG_RX;
+	if (iecm_is_vlan_cap_ena(adapter, IECM_CAP_VLAN_STAG_ADD_DEL))
+		dflt_features |= NETIF_F_HW_VLAN_STAG_FILTER;
+	/* Enable cloud filter if ADQ is supported */
+	if (iecm_is_cap_ena(adapter, IECM_BASE_CAPS, VIRTCHNL2_CAP_ADQ) ||
+	    iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_ADQ))
+		dflt_features |= NETIF_F_HW_TC;
+	if (iecm_is_cap_ena(adapter, IECM_SEG_CAPS, VIRTCHNL2_CAP_SEG_IPV4_TCP))
+		dflt_features |= NETIF_F_TSO;
+	if (iecm_is_cap_ena(adapter, IECM_SEG_CAPS, VIRTCHNL2_CAP_SEG_IPV6_TCP))
+		dflt_features |= NETIF_F_TSO6;
+	if (iecm_is_cap_ena_all(adapter, IECM_SEG_CAPS,
+				VIRTCHNL2_CAP_SEG_IPV4_UDP |
+				VIRTCHNL2_CAP_SEG_IPV6_UDP))
+		dflt_features |= NETIF_F_GSO_UDP_L4;
+	if (iecm_is_cap_ena_all(adapter, IECM_RSC_CAPS, IECM_CAP_RSC))
+		offloads |= NETIF_F_GRO_HW;
+	netdev->features |= dflt_features;
+	netdev->hw_features |= dflt_features | offloads;
+	netdev->hw_enc_features |= dflt_features | offloads;
+
+	SET_NETDEV_DEV(netdev, &adapter->pdev->dev);
+
+	/* carrier off on init to avoid Tx hangs */
+	netif_carrier_off(netdev);
+
+	/* make sure transmit queues start off as stopped */
+	netif_tx_stop_all_queues(netdev);
+
+	/* register last */
+	err = register_netdev(netdev);
+	if (err)
+		goto err;
+
+	/* The vport can be arbitrarily released so we need to also track
+	 * netdevs in the adapter struct
+	 */
+	adapter->netdevs[vport->idx] = netdev;
+
+	return 0;
+err:
+	free_netdev(vport->netdev);
+	vport->netdev = NULL;
+
+	return err;
+}
+
 /**
  * iecm_cfg_hw - Initialize HW struct
  * @adapter: adapter to setup hw struct for
@@ -77,6 +690,24 @@ static int iecm_get_free_slot(void *array, int size, int curr)
 	return next;
 }
 
+/**
+ * iecm_decfg_netdev - Unregister the netdev
+ * @vport: vport for which netdev to be unregistred
+ */
+static void iecm_decfg_netdev(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+
+	if (!vport->netdev)
+		return;
+
+	unregister_netdev(vport->netdev);
+	free_netdev(vport->netdev);
+	vport->netdev = NULL;
+
+	adapter->netdevs[vport->idx] = NULL;
+}
+
 /**
  * iecm_vport_rel - Delete a vport and free its resources
  * @vport: the vport being removed
@@ -102,6 +733,8 @@ static void iecm_vport_rel_all(struct iecm_adapter *adapter)
 		if (!adapter->vports[i])
 			continue;
 
+		if (!test_bit(__IECM_HR_RESET_IN_PROG, adapter->flags))
+			iecm_decfg_netdev(adapter->vports[i]);
 		iecm_vport_rel(adapter->vports[i]);
 		adapter->vports[i] = NULL;
 		adapter->next_vport = 0;
@@ -151,7 +784,7 @@ iecm_vport_alloc(struct iecm_adapter *adapter, int vport_id)
 	adapter->num_alloc_vport++;
 
 	/* Setup default MSIX irq handler for the vport */
-	vport->irq_q_handler = NULL;
+	vport->irq_q_handler = iecm_vport_intr_clean_queues;
 	vport->q_vector_base = IECM_NONQ_VEC;
 
 	mutex_init(&vport->stop_mutex);
@@ -184,8 +817,94 @@ static void iecm_statistics_task(struct work_struct *work)
  *
  */
 static void iecm_service_task(struct work_struct *work)
+{
+	struct iecm_adapter *adapter = container_of(work,
+						    struct iecm_adapter,
+						    serv_task.work);
+
+	if (test_bit(__IECM_MB_INTR_MODE, adapter->flags)) {
+		if (test_and_clear_bit(__IECM_MB_INTR_TRIGGER,
+				       adapter->flags)) {
+			iecm_recv_mb_msg(adapter, VIRTCHNL_OP_UNKNOWN, NULL, 0);
+			iecm_mb_irq_enable(adapter);
+		}
+	} else {
+		iecm_recv_mb_msg(adapter, VIRTCHNL_OP_UNKNOWN, NULL, 0);
+	}
+
+	if (iecm_is_reset_detected(adapter) &&
+	    !iecm_is_reset_in_prog(adapter)) {
+		dev_info(&adapter->pdev->dev, "HW reset detected\n");
+		set_bit(__IECM_HR_FUNC_RESET, adapter->flags);
+		queue_delayed_work(adapter->vc_event_wq,
+				   &adapter->vc_event_task,
+				   msecs_to_jiffies(10));
+	}
+
+	queue_delayed_work(adapter->serv_wq, &adapter->serv_task,
+			   msecs_to_jiffies(300));
+}
+
+/* iecm_set_vlan_offload_features - set vlan offload features
+ * @netdev: netdev structure
+ * @prev_features: previously set features
+ * @features: current features received from user
+ *
+ * Returns 0 on success, error value on failure
+ */
+static int
+iecm_set_vlan_offload_features(struct net_device *netdev,
+			       netdev_features_t prev_features,
+			       netdev_features_t features)
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+	bool stripping_ena = true, insertion_ena = true;
+	struct iecm_virtchnl_ops *vc_ops;
+	u16 vlan_ethertype = 0;
+
+	vc_ops = &vport->adapter->dev_ops.vc_ops;
+	/* keep cases separate because one ethertype for offloads can be
+	 * disabled at the same time as another is disabled, so check for an
+	 * enabled ethertype first, then check for disabled. Default to
+	 * ETH_P_8021Q so an ethertype is specified if disabling insertion
+	 * and stripping.
+	 */
+	if (features & (NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_STAG_TX))
+		vlan_ethertype = ETH_P_8021AD;
+	else if (features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX))
+		vlan_ethertype = ETH_P_8021Q;
+	else if (prev_features & (NETIF_F_HW_VLAN_STAG_RX |
+				  NETIF_F_HW_VLAN_STAG_TX))
+		vlan_ethertype = ETH_P_8021AD;
+	else if (prev_features & (NETIF_F_HW_VLAN_CTAG_RX |
+				  NETIF_F_HW_VLAN_CTAG_TX))
+		vlan_ethertype = ETH_P_8021Q;
+	else
+		vlan_ethertype = ETH_P_8021Q;
+
+	if (!(features & (NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_CTAG_RX)))
+		stripping_ena = false;
+	if (!(features & (NETIF_F_HW_VLAN_STAG_TX | NETIF_F_HW_VLAN_CTAG_TX)))
+		insertion_ena = false;
+
+	vport->adapter->config_data.vlan_ethertype = vlan_ethertype;
+
+	vc_ops->strip_vlan_msg(vport, stripping_ena);
+	if (vc_ops->insert_vlan_msg)
+		vc_ops->insert_vlan_msg(vport, insertion_ena);
+
+	return 0;
+}
+
+/**
+ * iecm_vport_open - Bring up a vport
+ * @vport: vport to bring up
+ * @alloc_res: allocate queue resources
+ */
+static int iecm_vport_open(struct iecm_vport *vport, bool alloc_res)
 {
 	/* stub */
+	return 0;
 }
 
 /**
@@ -206,6 +925,7 @@ static void iecm_init_task(struct work_struct *work)
 	struct iecm_vport *vport;
 	struct pci_dev *pdev;
 	int vport_id, err;
+	int index;
 
 	err = adapter->dev_ops.vc_ops.core_init(adapter, &vport_id);
 	if (err)
@@ -219,6 +939,65 @@ static void iecm_init_task(struct work_struct *work)
 			err);
 		return;
 	}
+	/* Start the service task before requesting vectors. This will ensure
+	 * vector information response from mailbox is handled
+	 */
+	queue_delayed_work(adapter->serv_wq, &adapter->serv_task,
+			   msecs_to_jiffies(5 * (pdev->devfn & 0x07)));
+	err = iecm_intr_req(adapter);
+	if (err) {
+		dev_err(&pdev->dev, "failed to enable interrupt vectors: %d\n",
+			err);
+		goto intr_req_err;
+	}
+	err = iecm_send_vlan_v2_caps_msg(adapter);
+	if (err)
+		goto vlan_v2_caps_failed;
+
+	err = adapter->dev_ops.vc_ops.get_supported_desc_ids(vport);
+	if (err) {
+		dev_err(&pdev->dev, "failed to get required descriptor ids\n");
+		goto rxdids_failed;
+	}
+
+	if (iecm_cfg_netdev(vport))
+		goto cfg_netdev_err;
+
+	if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_VLAN) ||
+	    iecm_is_cap_ena(adapter, IECM_BASE_CAPS, VIRTCHNL2_CAP_VLAN)) {
+		err = iecm_set_vlan_offload_features(vport->netdev, 0,
+						     vport->netdev->features);
+		if (err)
+			goto cfg_netdev_err;
+	}
+
+	err = adapter->dev_ops.vc_ops.get_ptype(vport);
+	if (err)
+		goto cfg_netdev_err;
+	queue_delayed_work(adapter->stats_wq, &adapter->stats_task,
+			   msecs_to_jiffies(10 * (pdev->devfn & 0x07)));
+	set_bit(__IECM_VPORT_INIT_PROMISC, vport->flags);
+	/* Once state is put into DOWN, driver is ready for dev_open */
+	adapter->state = __IECM_DOWN;
+	if (test_and_clear_bit(__IECM_UP_REQUESTED, adapter->flags))
+		iecm_vport_open(vport, true);
+
+	/* Clear the reset flag unconditionally here in case we were in reset
+	 * and the link was down
+	 */
+	clear_bit(__IECM_HR_RESET_IN_PROG, vport->adapter->flags);
+
+	return;
+
+vlan_v2_caps_failed:
+rxdids_failed:
+cfg_netdev_err:
+	iecm_intr_rel(adapter);
+intr_req_err:
+	index = iecm_get_vport_index(adapter, vport);
+	if (index >= 0)
+		adapter->vports[index] = NULL;
+	iecm_vport_rel(vport);
 }
 
 /**
@@ -614,3 +1393,35 @@ void iecm_free_dma_mem(struct iecm_hw *hw, struct iecm_dma_mem *mem)
 	mem->va = NULL;
 	mem->pa = 0;
 }
+
+static const struct net_device_ops iecm_netdev_ops_splitq = {
+	.ndo_open = NULL,
+	.ndo_stop = NULL,
+	.ndo_start_xmit = NULL,
+	.ndo_set_rx_mode = NULL,
+	.ndo_validate_addr = eth_validate_addr,
+	.ndo_set_mac_address = NULL,
+	.ndo_change_mtu = NULL,
+	.ndo_get_stats64 = NULL,
+	.ndo_fix_features = NULL,
+	.ndo_set_features = NULL,
+	.ndo_vlan_rx_add_vid = NULL,
+	.ndo_vlan_rx_kill_vid = NULL,
+	.ndo_setup_tc = NULL,
+};
+
+static const struct net_device_ops iecm_netdev_ops_singleq = {
+	.ndo_open = NULL,
+	.ndo_stop = NULL,
+	.ndo_start_xmit = NULL,
+	.ndo_set_rx_mode = NULL,
+	.ndo_validate_addr = eth_validate_addr,
+	.ndo_set_mac_address = NULL,
+	.ndo_change_mtu = NULL,
+	.ndo_get_stats64 = NULL,
+	.ndo_fix_features = NULL,
+	.ndo_set_features = NULL,
+	.ndo_vlan_rx_add_vid = NULL,
+	.ndo_vlan_rx_kill_vid = NULL,
+	.ndo_setup_tc           = NULL,
+};
drivers/net/ethernet/intel/iecm/iecm_txrx.c +17 -0
index bd0cfd89bf03..bb7f5830cffb 100644
@@ -218,6 +218,23 @@ const struct iecm_rx_ptype_decoded iecm_ptype_lookup[IECM_RX_MAX_PTYPE] = {
 };
 EXPORT_SYMBOL(iecm_ptype_lookup);
 
+/**
+ * iecm_vport_intr_clean_queues - MSIX mode Interrupt Handler
+ * @irq: interrupt number
+ * @data: pointer to a q_vector
+ *
+ */
+irqreturn_t
+iecm_vport_intr_clean_queues(int __always_unused irq, void *data)
+{
+	struct iecm_q_vector *q_vector = (struct iecm_q_vector *)data;
+
+	q_vector->total_events++;
+	napi_schedule(&q_vector->napi);
+
+	return IRQ_HANDLED;
+}
+
 /**
  * iecm_vport_init_num_qs - Initialize number of queues
  * @vport: vport to initialize queues
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +165 -0

177 lines not on this page · raw message

drivers/net/ethernet/intel/include/iecm.h +108 -4

162 lines not on this page · raw message

drivers/net/ethernet/intel/include/iecm_txrx.h +2 -0
index 9f3086bfe575..0aa1eac70e7c 100644
@@ -512,4 +512,6 @@ void iecm_vport_calc_total_qs(struct iecm_adapter *adapter,
 			      struct virtchnl2_create_vport *vport_msg);
 void iecm_vport_calc_num_q_groups(struct iecm_vport *vport);
 void iecm_vport_calc_num_q_vec(struct iecm_vport *vport);
+irqreturn_t
+iecm_vport_intr_clean_queues(int __always_unused irq, void *data);
 #endif /* !_IECM_TXRX_H_ */
Signature · 1 line
2.33.0
#37 lore raw

PATCH 8/19 iecm: add interrupts and configure netdev

From: Alan Brady <[email protected]>
Date: Thu, 27 Jan 2022 16:09:58 -0800

Quoted 202 lines

This finishes implementing init_task by adding everything we need to configure the netdevice for the vport and setup its interrupts.

---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    | 813 +++++++++++++++++-
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   |  17 +
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   | 165 ++++
 drivers/net/ethernet/intel/include/iecm.h     | 112 ++-
 .../net/ethernet/intel/include/iecm_txrx.h    |   2 +
 5 files changed, 1104 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/iecm/iecm_lib.c +165 -0
index aab8ee40424e..255b04c25683 100644
@@ -5,11 +5,35 @@
 
 #include "iecm.h"
 
+static const struct net_device_ops iecm_netdev_ops_splitq;
+static const struct net_device_ops iecm_netdev_ops_singleq;
+
 const char * const iecm_vport_vc_state_str[] = {
 	IECM_FOREACH_VPORT_VC_STATE(IECM_GEN_STRING)
 };
 EXPORT_SYMBOL(iecm_vport_vc_state_str);
 
+/**
+ * iecm_get_vport_index - Get the vport index
+ * @adapter: adapter structure to get the vports array
+ * @vport: vport pointer for which the index to find
+ */
+static int iecm_get_vport_index(struct iecm_adapter *adapter,
+				struct iecm_vport *vport)
+{
+	int i, err = -EINVAL;
+
+	if (!adapter->vports)
+		return err;
+
+	for (i = 0; i < adapter->num_alloc_vport; i++) {
+		if (adapter->vports[i] != vport)
+			continue;
+		return i;
+	}
+	return err;
+}
+
 /**
  * iecm_is_feature_ena - Determine if a particular feature is enabled
  * @vport: vport to check
@@ -29,6 +53,595 @@ bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)
 	return ena;
 }
 
+/**
+ * iecm_is_vlan_cap_ena - Check if VLAN capability is enabled
+ * @adapter: pointer to adapter
+ * @vcaps: VLAN capability bit
+ *
+ * Returns true if VLAN capability is set, false otherwise
+ */
+static bool iecm_is_vlan_cap_ena(struct iecm_adapter *adapter,
+				 enum iecm_vlan_caps vcaps)
+{
+	if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_VLAN)) {
+		struct virtchnl_vlan_supported_caps *offload;
+
+		if (!adapter->vlan_caps)
+			return false;
+
+		switch (vcaps) {
+		case IECM_CAP_VLAN_CTAG_INSERT:
+			offload =
+			&adapter->vlan_caps->offloads.insertion_support;
+			if ((offload->outer & IECM_VLAN_8100) == IECM_VLAN_8100 ||
+			    (offload->inner & IECM_VLAN_8100) == IECM_VLAN_8100)
+				return true;
+			break;
+		case IECM_CAP_VLAN_STAG_INSERT:
+			offload =
+			&adapter->vlan_caps->offloads.insertion_support;
+			if ((offload->outer & IECM_VLAN_88A8) == IECM_VLAN_88A8)
+				return true;
+			break;
+		case IECM_CAP_VLAN_CTAG_STRIP:
+			offload =
+			&adapter->vlan_caps->offloads.stripping_support;
+			if ((offload->outer & IECM_VLAN_8100) == IECM_VLAN_8100 ||
+			    (offload->inner & IECM_VLAN_8100) == IECM_VLAN_8100)
+				return true;
+			break;
+		case IECM_CAP_VLAN_STAG_STRIP:
+			offload =
+			&adapter->vlan_caps->offloads.stripping_support;
+			if ((offload->outer & IECM_VLAN_88A8) == IECM_VLAN_88A8)
+				return true;
+			break;
+		case IECM_CAP_VLAN_CTAG_ADD_DEL:
+			offload =
+			&adapter->vlan_caps->filtering.filtering_support;
+			if ((offload->outer & VIRTCHNL_VLAN_ETHERTYPE_8100) ||
+			    (offload->inner & VIRTCHNL_VLAN_ETHERTYPE_8100))
+				return true;
+			break;
+		case IECM_CAP_VLAN_STAG_ADD_DEL:
+			offload =
+			&adapter->vlan_caps->filtering.filtering_support;
+			if ((offload->outer & VIRTCHNL_VLAN_ETHERTYPE_88A8) ||
+			    (offload->inner & VIRTCHNL_VLAN_ETHERTYPE_88A8))
+				return true;
+			break;
+		default:
+			dev_err(&adapter->pdev->dev, "Invalid VLAN capability %d\n",
+				vcaps);
+			return false;
+		}
+	} else if (iecm_is_cap_ena(adapter, IECM_BASE_CAPS,
+				   VIRTCHNL2_CAP_VLAN)) {
+		switch (vcaps) {
+		case IECM_CAP_VLAN_CTAG_INSERT:
+		case IECM_CAP_VLAN_CTAG_STRIP:
+		case IECM_CAP_VLAN_CTAG_ADD_DEL:
+			return true;
+		default:
+			return false;
+		}
+	}
+
+	return false;
+}
+
+/**
+ * iecm_netdev_to_vport - get a vport handle from a netdev
+ * @netdev: network interface device structure
+ */
+struct iecm_vport *iecm_netdev_to_vport(struct net_device *netdev)
+{
+	struct iecm_netdev_priv *np = netdev_priv(netdev);
+
+	return np->vport;
+}
+
+/**
+ * iecm_mb_intr_rel_irq - Free the IRQ association with the OS
+ * @adapter: adapter structure
+ */
+static void iecm_mb_intr_rel_irq(struct iecm_adapter *adapter)
+{
+	int irq_num;
+
+	irq_num = adapter->msix_entries[0].vector;
+	free_irq(irq_num, adapter);
+}
+
+/**
+ * iecm_intr_rel - Release interrupt capabilities and free memory
+ * @adapter: adapter to disable interrupts on
+ */
+static void iecm_intr_rel(struct iecm_adapter *adapter)
+{
+	if (!adapter->msix_entries)
+		return;
+	clear_bit(__IECM_MB_INTR_MODE, adapter->flags);
+	clear_bit(__IECM_MB_INTR_TRIGGER, adapter->flags);
+	iecm_mb_intr_rel_irq(adapter);
+
+	pci_free_irq_vectors(adapter->pdev);
+	if (adapter->dev_ops.vc_ops.dealloc_vectors) {
+		int err;
+
+		err = adapter->dev_ops.vc_ops.dealloc_vectors(adapter);
+		if (err) {
+			dev_err(&adapter->pdev->dev,
+				"Failed to deallocate vectors: %d\n", err);
+		}
+	}
+	kfree(adapter->msix_entries);
+	adapter->msix_entries = NULL;
+	kfree(adapter->req_vec_chunks);
+	adapter->req_vec_chunks = NULL;
+}
+
+/**
+ * iecm_mb_intr_clean - Interrupt handler for the mailbox
+ * @irq: interrupt number
+ * @data: pointer to the adapter structure
+ */
+static irqreturn_t iecm_mb_intr_clean(int __always_unused irq, void *data)
+{
+	struct iecm_adapter *adapter = (struct iecm_adapter *)data;
+
+	set_bit(__IECM_MB_INTR_TRIGGER, adapter->flags);
+	queue_delayed_work(adapter->serv_wq, &adapter->serv_task,
+			   msecs_to_jiffies(0));
+	return IRQ_HANDLED;

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature) · line 206

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+}
+
+/**
+ * iecm_mb_irq_enable - Enable MSIX interrupt for the mailbox
+ * @adapter: adapter to get the hardware address for register write
+ */
+static void iecm_mb_irq_enable(struct iecm_adapter *adapter)
+{
+	struct iecm_hw *hw = &adapter->hw;
+	struct iecm_intr_reg *intr = &adapter->mb_vector.intr_reg;

Please don't break Reverse Christmas Tree declaration style. *intr doesn't depend on *hw.

Quoted 200 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +200 -0
+	u32 val;
+
+	val = intr->dyn_ctl_intena_m | intr->dyn_ctl_itridx_m;
+	wr32(hw, intr->dyn_ctl, val);
+	wr32(hw, intr->icr_ena, intr->icr_ena_ctlq_m);
+}
+
+/**
+ * iecm_mb_intr_req_irq - Request irq for the mailbox interrupt
+ * @adapter: adapter structure to pass to the mailbox irq handler
+ */
+static int iecm_mb_intr_req_irq(struct iecm_adapter *adapter)
+{
+	struct iecm_q_vector *mb_vector = &adapter->mb_vector;
+	int irq_num, mb_vidx = 0, err;
+
+	irq_num = adapter->msix_entries[mb_vidx].vector;
+	snprintf(mb_vector->name, sizeof(mb_vector->name) - 1,
+		 "%s-%s-%d", dev_driver_string(&adapter->pdev->dev),
+		 "Mailbox", mb_vidx);
+	err = request_irq(irq_num, adapter->irq_mb_handler, 0,
+			  mb_vector->name, adapter);
+	if (err) {
+		dev_err(&adapter->pdev->dev,
+			"Request_irq for mailbox failed, error: %d\n", err);
+		return err;
+	}
+	set_bit(__IECM_MB_INTR_MODE, adapter->flags);
+	return 0;
+}
+
+/**
+ * iecm_get_mb_vec_id - Get vector index for mailbox
+ * @adapter: adapter structure to access the vector chunks
+ *
+ * The first vector id in the requested vector chunks from the CP is for
+ * the mailbox
+ */
+static void iecm_get_mb_vec_id(struct iecm_adapter *adapter)
+{
+	if (adapter->req_vec_chunks) {
+		struct virtchnl2_get_capabilities *caps;
+
+		caps = (struct virtchnl2_get_capabilities *)adapter->caps;
+		adapter->mb_vector.v_idx = le16_to_cpu(caps->mailbox_vector_id);
+	} else {
+		adapter->mb_vector.v_idx = 0;
+	}
+}
+
+/**
+ * iecm_mb_intr_init - Initialize the mailbox interrupt
+ * @adapter: adapter structure to store the mailbox vector
+ */
+static int iecm_mb_intr_init(struct iecm_adapter *adapter)
+{
+	adapter->dev_ops.reg_ops.mb_intr_reg_init(adapter);
+	adapter->irq_mb_handler = iecm_mb_intr_clean;
+	return iecm_mb_intr_req_irq(adapter);
+}
+
+/**
+ * iecm_intr_distribute - Distribute MSIX vectors
+ * @adapter: adapter structure to get the vports
+ * @pre_req: before or after msi request
+ *
+ * Distribute the MSIX vectors acquired from the OS to the vports based on the
+ * num of vectors requested by each vport
+ */
+static int
+iecm_intr_distribute(struct iecm_adapter *adapter, bool pre_req)
+{
+	struct iecm_vport *vport = adapter->vports[0];
+	int err = 0;
+
+	if (pre_req) {
+		u16 vecs_avail;
+
+		vecs_avail = iecm_get_reserved_vecs(adapter);
+		if (vecs_avail < IECM_MIN_VEC) {
+			return -EAGAIN;
+		} else if (vecs_avail == IECM_MIN_VEC) {
+			vport->num_q_vectors = IECM_MIN_Q_VEC;
+		} else {
+			vport->num_q_vectors = vecs_avail - IECM_NONQ_VEC -
+						IECM_MAX_RDMA_VEC;
+		}
+	} else {
+		if (adapter->num_msix_entries != adapter->num_req_msix)
+			vport->num_q_vectors = adapter->num_msix_entries -
+					       IECM_NONQ_VEC;
+	}
+
+	return err;
+}
+
+/**
+ * iecm_intr_req - Request interrupt capabilities
+ * @adapter: adapter to enable interrupts on
+ *
+ * Returns 0 on success, negative on failure
+ */
+static int iecm_intr_req(struct iecm_adapter *adapter)
+{
+	int min_vectors, max_vectors, err = 0;
+	int num_q_vecs, total_num_vecs;
+	u16 vecids[IECM_MAX_VECIDS];
+	unsigned int vector;
+	int v_actual;
+
+	err = iecm_intr_distribute(adapter, true);
+	if (err)
+		return err;
+
+	num_q_vecs = adapter->vports[0]->num_q_vectors;
+
+	total_num_vecs = num_q_vecs + IECM_NONQ_VEC;
+
+	if (adapter->dev_ops.vc_ops.alloc_vectors) {
+		err = adapter->dev_ops.vc_ops.alloc_vectors(adapter,
+							    num_q_vecs);
+		if (err) {
+			dev_err(&adapter->pdev->dev,
+				"Failed to allocate vectors: %d\n", err);
+			return -EAGAIN;
+		}
+	}
+
+	min_vectors = IECM_MIN_VEC;
+	max_vectors = total_num_vecs;
+	v_actual = pci_alloc_irq_vectors(adapter->pdev, min_vectors,
+					 max_vectors, PCI_IRQ_MSIX);
+	if (v_actual < 0) {
+		dev_err(&adapter->pdev->dev, "Failed to allocate MSIX vectors: %d\n",
+			v_actual);
+		if (adapter->dev_ops.vc_ops.dealloc_vectors)
+			adapter->dev_ops.vc_ops.dealloc_vectors(adapter);
+		return -EAGAIN;
+	}
+
+	adapter->msix_entries = kcalloc(v_actual, sizeof(struct msix_entry),
+					GFP_KERNEL);
+
+	if (!adapter->msix_entries) {
+		pci_free_irq_vectors(adapter->pdev);
+		if (adapter->dev_ops.vc_ops.dealloc_vectors)
+			adapter->dev_ops.vc_ops.dealloc_vectors(adapter);
+		return -ENOMEM;
+	}
+
+	iecm_get_mb_vec_id(adapter);
+
+	if (adapter->req_vec_chunks) {
+		struct virtchnl2_vector_chunks *vchunks;
+		struct virtchnl2_alloc_vectors *ac;
+
+		ac = adapter->req_vec_chunks;
+		vchunks = &ac->vchunks;
+
+		iecm_get_vec_ids(adapter, vecids, IECM_MAX_VECIDS, vchunks);
+	} else {
+		int i = 0;
+
+		for (i = 0; i < v_actual; i++)
+			vecids[i] = i;
+	}
+
+	for (vector = 0; vector < v_actual; vector++) {
+		adapter->msix_entries[vector].entry = vecids[vector];
+		adapter->msix_entries[vector].vector =
+			pci_irq_vector(adapter->pdev, vector);
+	}
+	adapter->num_msix_entries = v_actual;
+	adapter->num_req_msix = total_num_vecs;
+
+	iecm_intr_distribute(adapter, false);
+
+	err = iecm_mb_intr_init(adapter);
+	if (err)
+		goto intr_rel;
+	iecm_mb_irq_enable(adapter);
+	return err;
+
+intr_rel:
+	iecm_intr_rel(adapter);
+	return err;
+}
+
+/**
+ * iecm_find_mac_filter - Search filter list for specific mac filter
+ * @vport: main vport structure
+ * @macaddr: the MAC address
+ *
+ * Returns ptr to the filter object or NULL. Must be called while holding the
+ * mac_filter_list_lock.
+ **/
+static struct
+iecm_mac_filter *iecm_find_mac_filter(struct iecm_vport *vport,
+				      const u8 *macaddr)
+{

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature) · line 416

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_mac_filter *f;
+
+	if (!macaddr)
+		return NULL;
+
+	list_for_each_entry(f, &adapter->config_data.mac_filter_list, list) {
+		if (ether_addr_equal(macaddr, f->macaddr))
+			return f;
+	}

Excessive braces again.

Quoted 24 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +24 -0
+	return NULL;
+}
+
+/**
+ * __iecm_add_mac_filter - Add mac filter helper function
+ * @vport: main vport struct
+ * @macaddr: address to add
+ *
+ * Takes mac_filter_list_lock spinlock to add new filter to list.
+ */
+static struct
+iecm_mac_filter *__iecm_add_mac_filter(struct iecm_vport *vport,
+				       const u8 *macaddr)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_mac_filter *f = NULL;
+
+	spin_lock_bh(&adapter->mac_filter_list_lock);
+	f = iecm_find_mac_filter(vport, macaddr);
+	if (!f) {
+		f = kzalloc(sizeof(*f), GFP_ATOMIC);
+		if (!f) {
+			dev_err(&adapter->pdev->dev, "Failed to allocate filter: %pM",
+				macaddr);

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature) · line 450

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+			goto error;
+		}
+
+		ether_addr_copy(f->macaddr, macaddr);
+
+		list_add_tail(&f->list, &adapter->config_data.mac_filter_list);
+		f->add = true;
+	} else {
+		f->remove = false;
+	}
	if (f) {
		f->remove = false;
		goto error; /* It's better to rename it */
	}

	f = kzalloc(...

-1 indent level.

Quoted 154 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +154 -0
+error:
+	spin_unlock_bh(&adapter->mac_filter_list_lock);
+
+	return f;
+}
+
+/**
+ * iecm_add_mac_filter - Add a mac filter to the filter list
+ * @vport: main vport structure
+ * @macaddr: the MAC address
+ *
+ * Returns ptr to the filter or NULL on error. If interface is up, we'll also
+ * send the virtchnl message to tell hardware about the filter.
+ **/
+static struct iecm_mac_filter *iecm_add_mac_filter(struct iecm_vport *vport,
+						   const u8 *macaddr)
+{
+	struct iecm_mac_filter *f;
+
+	if (!macaddr)
+		return NULL;
+
+	f = __iecm_add_mac_filter(vport, macaddr);
+	if (!f)
+		return NULL;
+
+	if (vport->adapter->state == __IECM_UP)
+		iecm_add_del_ether_addrs(vport, true, false);
+
+	return f;
+}
+
+/**
+ * iecm_init_mac_addr - initialize mac address for vport
+ * @vport: main vport structure
+ * @netdev: pointer to netdev struct associated with this vport
+ */
+static int iecm_init_mac_addr(struct iecm_vport *vport,
+			      struct net_device *netdev)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+
+	if (!is_valid_ether_addr(vport->default_mac_addr)) {
+		if (!iecm_is_cap_ena(vport->adapter, IECM_OTHER_CAPS,
+				     VIRTCHNL2_CAP_MACFILTER)) {
+			dev_err(&adapter->pdev->dev,
+				"MAC address not provided and capability is not set\n");
+			return -EINVAL;
+		}
+
+		dev_info(&adapter->pdev->dev, "Invalid MAC address %pM, using random\n",
+			 vport->default_mac_addr);
+		eth_hw_addr_random(netdev);
+
+		if (!iecm_add_mac_filter(vport, netdev->dev_addr))
+			return -ENOMEM;
+
+		ether_addr_copy(vport->default_mac_addr, netdev->dev_addr);
+	} else {
+		dev_addr_mod(netdev, 0, vport->default_mac_addr, ETH_ALEN);
+		ether_addr_copy(netdev->perm_addr, vport->default_mac_addr);
+	}
+
+	return 0;
+}
+
+/**
+ * iecm_cfg_netdev - Allocate, configure and register a netdev
+ * @vport: main vport structure
+ *
+ * Returns 0 on success, negative value on failure.
+ */
+static int iecm_cfg_netdev(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	netdev_features_t dflt_features;
+	netdev_features_t offloads = 0;
+	struct iecm_netdev_priv *np;
+	struct net_device *netdev;
+	u16 max_q;
+	int err;
+
+	lockdep_assert_held(&adapter->sw_mutex);
+
+	/* It's possible we already have a netdev allocated and registered for
+	 * this vport
+	 */
+	if (adapter->netdevs[vport->idx]) {
+		netdev = adapter->netdevs[vport->idx];
+		np = netdev_priv(netdev);
+		np->vport = vport;
+		vport->netdev = netdev;
+
+		return iecm_init_mac_addr(vport, netdev);
+	}
+
+	max_q = adapter->max_queue_limit;
+
+	netdev = alloc_etherdev_mqs(sizeof(struct iecm_netdev_priv),
+				    max_q, max_q);
+	if (!netdev)
+		return -ENOMEM;
+	vport->netdev = netdev;
+	np = netdev_priv(netdev);
+	np->vport = vport;
+
+	err = iecm_init_mac_addr(vport, netdev);
+	if (err)
+		goto err;
+
+	/* assign netdev_ops */
+	if (iecm_is_queue_model_split(vport->txq_model))
+		netdev->netdev_ops = &iecm_netdev_ops_splitq;
+	else
+		netdev->netdev_ops = &iecm_netdev_ops_singleq;
+
+	/* setup watchdog timeout value to be 5 second */
+	netdev->watchdog_timeo = 5 * HZ;
+
+	/* configure default MTU size */
+	netdev->min_mtu = ETH_MIN_MTU;
+	netdev->max_mtu = vport->max_mtu;
+
+	dflt_features = NETIF_F_SG	|
+			NETIF_F_HIGHDMA;
+
+	if (iecm_is_cap_ena_all(adapter, IECM_RSS_CAPS, IECM_CAP_RSS))
+		dflt_features |= NETIF_F_RXHASH;
+	if (iecm_is_cap_ena_all(adapter, IECM_CSUM_CAPS, IECM_CAP_RX_CSUM_L4V4))
+		dflt_features |= NETIF_F_IP_CSUM;
+	if (iecm_is_cap_ena_all(adapter, IECM_CSUM_CAPS, IECM_CAP_RX_CSUM_L4V6))
+		dflt_features |= NETIF_F_IPV6_CSUM;
+	if (iecm_is_cap_ena(adapter, IECM_CSUM_CAPS, IECM_CAP_RX_CSUM))
+		dflt_features |= NETIF_F_RXCSUM;
+	if (iecm_is_cap_ena_all(adapter, IECM_CSUM_CAPS, IECM_CAP_SCTP_CSUM))
+		dflt_features |= NETIF_F_SCTP_CRC;
+
+	if (iecm_is_vlan_cap_ena(adapter, IECM_CAP_VLAN_CTAG_INSERT))
+		dflt_features |= IECM_F_HW_VLAN_CTAG_TX;
+	if (iecm_is_vlan_cap_ena(adapter, IECM_CAP_VLAN_CTAG_STRIP))
+		dflt_features |= IECM_F_HW_VLAN_CTAG_RX;
+	if (iecm_is_vlan_cap_ena(adapter, IECM_CAP_VLAN_CTAG_ADD_DEL))
+		dflt_features |= IECM_F_HW_VLAN_CTAG_FILTER;
+
+	if (iecm_is_vlan_cap_ena(adapter, IECM_CAP_VLAN_STAG_INSERT))
+		dflt_features |= NETIF_F_HW_VLAN_STAG_TX;
+	if (iecm_is_vlan_cap_ena(adapter, IECM_CAP_VLAN_STAG_STRIP))
+		dflt_features |= NETIF_F_HW_VLAN_STAG_RX;
+	if (iecm_is_vlan_cap_ena(adapter, IECM_CAP_VLAN_STAG_ADD_DEL))
+		dflt_features |= NETIF_F_HW_VLAN_STAG_FILTER;
+	/* Enable cloud filter if ADQ is supported */
+	if (iecm_is_cap_ena(adapter, IECM_BASE_CAPS, VIRTCHNL2_CAP_ADQ) ||
+	    iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_ADQ))
+		dflt_features |= NETIF_F_HW_TC;

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature) · line 614

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+	if (iecm_is_cap_ena(adapter, IECM_SEG_CAPS, VIRTCHNL2_CAP_SEG_IPV4_TCP))
+		dflt_features |= NETIF_F_TSO;
+	if (iecm_is_cap_ena(adapter, IECM_SEG_CAPS, VIRTCHNL2_CAP_SEG_IPV6_TCP))
+		dflt_features |= NETIF_F_TSO6;
+	if (iecm_is_cap_ena_all(adapter, IECM_SEG_CAPS,
+				VIRTCHNL2_CAP_SEG_IPV4_UDP |
+				VIRTCHNL2_CAP_SEG_IPV6_UDP))
+		dflt_features |= NETIF_F_GSO_UDP_L4;
+	if (iecm_is_cap_ena_all(adapter, IECM_RSC_CAPS, IECM_CAP_RSC))
+		offloads |= NETIF_F_GRO_HW;

I see offloads being used only here, |= -> =.

Quoted 77 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +51 -1
+	netdev->features |= dflt_features;
+	netdev->hw_features |= dflt_features | offloads;
+	netdev->hw_enc_features |= dflt_features | offloads;
+
+	SET_NETDEV_DEV(netdev, &adapter->pdev->dev);
+
+	/* carrier off on init to avoid Tx hangs */
+	netif_carrier_off(netdev);
+
+	/* make sure transmit queues start off as stopped */
+	netif_tx_stop_all_queues(netdev);
+
+	/* register last */
+	err = register_netdev(netdev);
+	if (err)
+		goto err;
+
+	/* The vport can be arbitrarily released so we need to also track
+	 * netdevs in the adapter struct
+	 */
+	adapter->netdevs[vport->idx] = netdev;
+
+	return 0;
+err:
+	free_netdev(vport->netdev);
+	vport->netdev = NULL;
+
+	return err;
+}
+
 /**
  * iecm_cfg_hw - Initialize HW struct
  * @adapter: adapter to setup hw struct for
@@ -77,6 +690,24 @@ static int iecm_get_free_slot(void *array, int size, int curr)
 	return next;
 }
 
+/**
+ * iecm_decfg_netdev - Unregister the netdev
+ * @vport: vport for which netdev to be unregistred
+ */
+static void iecm_decfg_netdev(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+
+	if (!vport->netdev)
+		return;
+
+	unregister_netdev(vport->netdev);
+	free_netdev(vport->netdev);
+	vport->netdev = NULL;
+
+	adapter->netdevs[vport->idx] = NULL;
+}
+
 /**
  * iecm_vport_rel - Delete a vport and free its resources
  * @vport: the vport being removed
@@ -102,6 +733,8 @@ static void iecm_vport_rel_all(struct iecm_adapter *adapter)
 		if (!adapter->vports[i])
 			continue;
 
+		if (!test_bit(__IECM_HR_RESET_IN_PROG, adapter->flags))
+			iecm_decfg_netdev(adapter->vports[i]);
 		iecm_vport_rel(adapter->vports[i]);
 		adapter->vports[i] = NULL;
 		adapter->next_vport = 0;
@@ -151,7 +784,7 @@ iecm_vport_alloc(struct iecm_adapter *adapter, int vport_id)
 	adapter->num_alloc_vport++;
 
 	/* Setup default MSIX irq handler for the vport */
-	vport->irq_q_handler = NULL;
+	vport->irq_q_handler = iecm_vport_intr_clean_queues;
 	vport->q_vector_base = IECM_NONQ_VEC;
 
 	mutex_init(&vport->stop_mutex);

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_statistics_task(struct work_struct *work) · line 823

Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +4 -0
@@ -184,8 +817,94 @@ static void iecm_statistics_task(struct work_struct *work)
  *
  */
 static void iecm_service_task(struct work_struct *work)
+{
+	struct iecm_adapter *adapter = container_of(work,
+						    struct iecm_adapter,
+						    serv_task.work);
	struct iecm_adapter *adapter;

	adapter = container_of(work, typeof(*adapter), serv_task.work);

Same line count, but more elegant with no line wraps.

Quoted 142 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +126 -0
+
+	if (test_bit(__IECM_MB_INTR_MODE, adapter->flags)) {
+		if (test_and_clear_bit(__IECM_MB_INTR_TRIGGER,
+				       adapter->flags)) {
+			iecm_recv_mb_msg(adapter, VIRTCHNL_OP_UNKNOWN, NULL, 0);
+			iecm_mb_irq_enable(adapter);
+		}
+	} else {
+		iecm_recv_mb_msg(adapter, VIRTCHNL_OP_UNKNOWN, NULL, 0);
+	}
+
+	if (iecm_is_reset_detected(adapter) &&
+	    !iecm_is_reset_in_prog(adapter)) {
+		dev_info(&adapter->pdev->dev, "HW reset detected\n");
+		set_bit(__IECM_HR_FUNC_RESET, adapter->flags);
+		queue_delayed_work(adapter->vc_event_wq,
+				   &adapter->vc_event_task,
+				   msecs_to_jiffies(10));
+	}
+
+	queue_delayed_work(adapter->serv_wq, &adapter->serv_task,
+			   msecs_to_jiffies(300));
+}
+
+/* iecm_set_vlan_offload_features - set vlan offload features
+ * @netdev: netdev structure
+ * @prev_features: previously set features
+ * @features: current features received from user
+ *
+ * Returns 0 on success, error value on failure
+ */
+static int
+iecm_set_vlan_offload_features(struct net_device *netdev,
+			       netdev_features_t prev_features,
+			       netdev_features_t features)
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+	bool stripping_ena = true, insertion_ena = true;
+	struct iecm_virtchnl_ops *vc_ops;
+	u16 vlan_ethertype = 0;
+
+	vc_ops = &vport->adapter->dev_ops.vc_ops;
+	/* keep cases separate because one ethertype for offloads can be
+	 * disabled at the same time as another is disabled, so check for an
+	 * enabled ethertype first, then check for disabled. Default to
+	 * ETH_P_8021Q so an ethertype is specified if disabling insertion
+	 * and stripping.
+	 */
+	if (features & (NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_STAG_TX))
+		vlan_ethertype = ETH_P_8021AD;
+	else if (features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX))
+		vlan_ethertype = ETH_P_8021Q;
+	else if (prev_features & (NETIF_F_HW_VLAN_STAG_RX |
+				  NETIF_F_HW_VLAN_STAG_TX))
+		vlan_ethertype = ETH_P_8021AD;
+	else if (prev_features & (NETIF_F_HW_VLAN_CTAG_RX |
+				  NETIF_F_HW_VLAN_CTAG_TX))
+		vlan_ethertype = ETH_P_8021Q;
+	else
+		vlan_ethertype = ETH_P_8021Q;
+
+	if (!(features & (NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_CTAG_RX)))
+		stripping_ena = false;
+	if (!(features & (NETIF_F_HW_VLAN_STAG_TX | NETIF_F_HW_VLAN_CTAG_TX)))
+		insertion_ena = false;
+
+	vport->adapter->config_data.vlan_ethertype = vlan_ethertype;
+
+	vc_ops->strip_vlan_msg(vport, stripping_ena);
+	if (vc_ops->insert_vlan_msg)
+		vc_ops->insert_vlan_msg(vport, insertion_ena);
+
+	return 0;
+}
+
+/**
+ * iecm_vport_open - Bring up a vport
+ * @vport: vport to bring up
+ * @alloc_res: allocate queue resources
+ */
+static int iecm_vport_open(struct iecm_vport *vport, bool alloc_res)
 {
 	/* stub */
+	return 0;
 }
 
 /**
@@ -206,6 +925,7 @@ static void iecm_init_task(struct work_struct *work)
 	struct iecm_vport *vport;
 	struct pci_dev *pdev;
 	int vport_id, err;
+	int index;
 
 	err = adapter->dev_ops.vc_ops.core_init(adapter, &vport_id);
 	if (err)
@@ -219,6 +939,65 @@ static void iecm_init_task(struct work_struct *work)
 			err);
 		return;
 	}
+	/* Start the service task before requesting vectors. This will ensure
+	 * vector information response from mailbox is handled
+	 */
+	queue_delayed_work(adapter->serv_wq, &adapter->serv_task,
+			   msecs_to_jiffies(5 * (pdev->devfn & 0x07)));
+	err = iecm_intr_req(adapter);
+	if (err) {
+		dev_err(&pdev->dev, "failed to enable interrupt vectors: %d\n",
+			err);
+		goto intr_req_err;
+	}
+	err = iecm_send_vlan_v2_caps_msg(adapter);
+	if (err)
+		goto vlan_v2_caps_failed;
+
+	err = adapter->dev_ops.vc_ops.get_supported_desc_ids(vport);
+	if (err) {
+		dev_err(&pdev->dev, "failed to get required descriptor ids\n");
+		goto rxdids_failed;
+	}
+
+	if (iecm_cfg_netdev(vport))
+		goto cfg_netdev_err;
+
+	if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_VLAN) ||
+	    iecm_is_cap_ena(adapter, IECM_BASE_CAPS, VIRTCHNL2_CAP_VLAN)) {
+		err = iecm_set_vlan_offload_features(vport->netdev, 0,
+						     vport->netdev->features);
+		if (err)
+			goto cfg_netdev_err;
+	}
+
+	err = adapter->dev_ops.vc_ops.get_ptype(vport);
+	if (err)
+		goto cfg_netdev_err;
+	queue_delayed_work(adapter->stats_wq, &adapter->stats_task,
+			   msecs_to_jiffies(10 * (pdev->devfn & 0x07)));
+	set_bit(__IECM_VPORT_INIT_PROMISC, vport->flags);
+	/* Once state is put into DOWN, driver is ready for dev_open */
+	adapter->state = __IECM_DOWN;
+	if (test_and_clear_bit(__IECM_UP_REQUESTED, adapter->flags))
+		iecm_vport_open(vport, true);
+

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_init_task(struct work_struct *work) · line 994

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+	/* Clear the reset flag unconditionally here in case we were in reset
+	 * and the link was down
+	 */
+	clear_bit(__IECM_HR_RESET_IN_PROG, vport->adapter->flags);
+
+	return;
+
+vlan_v2_caps_failed:
+rxdids_failed:
+cfg_netdev_err:

No reason to declare 3 labels at the same point.

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +6 -0
+	iecm_intr_rel(adapter);
+intr_req_err:
+	index = iecm_get_vport_index(adapter, vport);
+	if (index >= 0)
+		adapter->vports[index] = NULL;
+	iecm_vport_rel(vport);
 }
 
 /**

drivers/net/ethernet/intel/iecm/iecm_lib.c void iecm_free_dma_mem(struct iecm_hw *hw, struct iecm_dma_mem *mem) · line 1402

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +7 -0
@@ -614,3 +1393,35 @@ void iecm_free_dma_mem(struct iecm_hw *hw, struct iecm_dma_mem *mem)
 	mem->va = NULL;
 	mem->pa = 0;
 }
+
+static const struct net_device_ops iecm_netdev_ops_splitq = {
+	.ndo_open = NULL,
+	.ndo_stop = NULL,
+	.ndo_start_xmit = NULL,
+	.ndo_set_rx_mode = NULL,
+	.ndo_validate_addr = eth_validate_addr,

eth_validate_addr() (or ether_addr_valid()) gets run by default when no .ndo_validate_addr is specified. It's redundant to declare it here.

drivers/net/ethernet/intel/iecm/iecm_lib.c void iecm_free_dma_mem(struct iecm_hw *hw, struct iecm_dma_mem *mem) · line 1410

Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +8 -0
+	.ndo_set_mac_address = NULL,
+	.ndo_change_mtu = NULL,
+	.ndo_get_stats64 = NULL,
+	.ndo_fix_features = NULL,
+	.ndo_set_features = NULL,
+	.ndo_vlan_rx_add_vid = NULL,
+	.ndo_vlan_rx_kill_vid = NULL,
+	.ndo_setup_tc = NULL,

Non-initialized members get zeroed by default, NULLing them is excessive.

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +6 -0
+};
+
+static const struct net_device_ops iecm_netdev_ops_singleq = {
+	.ndo_open = NULL,
+	.ndo_stop = NULL,
+	.ndo_start_xmit = NULL,

drivers/net/ethernet/intel/iecm/iecm_lib.c void iecm_free_dma_mem(struct iecm_hw *hw, struct iecm_dma_mem *mem) · line 1426

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+	.ndo_set_rx_mode = NULL,
+	.ndo_validate_addr = eth_validate_addr,
+	.ndo_set_mac_address = NULL,
+	.ndo_change_mtu = NULL,
+	.ndo_get_stats64 = NULL,
+	.ndo_fix_features = NULL,
+	.ndo_set_features = NULL,
+	.ndo_vlan_rx_add_vid = NULL,
+	.ndo_vlan_rx_kill_vid = NULL,
+	.ndo_setup_tc           = NULL,

Same 2 previous points.

.ndo_setup_tc assignment indentation is weird. Either align all the initializers with tabs or don't align at all (both are valid cases).

Quoted 399 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +1 -0
+};
drivers/net/ethernet/intel/iecm/iecm_txrx.c +17 -0
index bd0cfd89bf03..bb7f5830cffb 100644
@@ -218,6 +218,23 @@ const struct iecm_rx_ptype_decoded iecm_ptype_lookup[IECM_RX_MAX_PTYPE] = {
 };
 EXPORT_SYMBOL(iecm_ptype_lookup);
 
+/**
+ * iecm_vport_intr_clean_queues - MSIX mode Interrupt Handler
+ * @irq: interrupt number
+ * @data: pointer to a q_vector
+ *
+ */
+irqreturn_t
+iecm_vport_intr_clean_queues(int __always_unused irq, void *data)
+{
+	struct iecm_q_vector *q_vector = (struct iecm_q_vector *)data;
+
+	q_vector->total_events++;
+	napi_schedule(&q_vector->napi);
+
+	return IRQ_HANDLED;
+}
+
 /**
  * iecm_vport_init_num_qs - Initialize number of queues
  * @vport: vport to initialize queues
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +165 -0
index c4ae56897d1b..b91716aeef6f 100644
@@ -2731,6 +2731,45 @@ static int iecm_send_insert_vlan_msg(struct iecm_vport *vport, bool ena)
 	return err;
 }
 
+/**
+ * iecm_send_vlan_v2_caps_msg - send virtchnl get offload VLAN V2 caps message
+ * @adapter: adapter info struct
+ *
+ * Returns 0 on success and if VLAN V1 capability is set`, negative on failure.
+ */
+int iecm_send_vlan_v2_caps_msg(struct iecm_adapter *adapter)
+{
+	int err = 0;
+
+	if (!iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_VLAN))
+		return err;
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS,
+			       0, NULL);
+	if (err)
+		return err;
+
+	err = iecm_min_wait_for_event(adapter, IECM_VC_OFFLOAD_VLAN_V2_CAPS,
+				      IECM_VC_OFFLOAD_VLAN_V2_CAPS_ERR);
+
+	if (err) {
+		dev_err(&adapter->pdev->dev, "Failed to recv get caps");
+		return err;
+	}
+
+	if (!adapter->vlan_caps) {
+		adapter->vlan_caps =
+		  kzalloc(sizeof(*adapter->vlan_caps), GFP_KERNEL);
+		if (!adapter->vlan_caps)
+			return -ENOMEM;
+	}
+
+	memcpy(adapter->vlan_caps,
+	       adapter->vc_msg, sizeof(*adapter->vlan_caps));
+
+	return err;
+}
+
 /**
  * iecm_fill_ptype_lookup - Fill L3 specific fields in ptype lookup table
  * @ptype: ptype lookup table
@@ -3580,6 +3619,132 @@ static unsigned int iecm_get_max_tx_bufs(struct iecm_adapter *adapter)
 	return ((struct virtchnl2_get_capabilities *)adapter->caps)->max_sg_bufs_per_tx_pkt;
 }
 
+/**
+ * iecm_add_del_ether_addrs
+ * @vport: virtual port data structure
+ * @add: Add or delete flag
+ * @async: Don't wait for return message
+ *
+ * Request that the PF add or delete one or more addresses to our filters.
+ **/
+void iecm_add_del_ether_addrs(struct iecm_vport *vport, bool add, bool async)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl_ether_addr_list *veal = NULL;
+	int num_entries, num_msgs, total_filters = 0;
+	struct pci_dev *pdev = adapter->pdev;
+	enum iecm_vport_vc_state vc, vc_err;
+	struct virtchnl_ether_addr *eal;
+	struct iecm_mac_filter *f, *tmp;
+	int i = 0, k = 0, err = 0;
+	enum virtchnl_ops vop;
+
+	spin_lock_bh(&adapter->mac_filter_list_lock);
+
+	/* Find the number of newly added filters */
+	list_for_each_entry(f, &adapter->config_data.mac_filter_list, list) {
+		if (add && f->add)
+			total_filters++;
+		else if (!add && f->remove)
+			total_filters++;
+	}
+	if (!total_filters) {
+		spin_unlock_bh(&adapter->mac_filter_list_lock);
+		goto error;
+	}
+
+	/* Fill all the new filters into virtchannel message */
+	eal = kcalloc(total_filters, sizeof(struct virtchnl_ether_addr),
+		      GFP_ATOMIC);
+	if (!eal) {
+		err = -ENOMEM;
+		spin_unlock_bh(&adapter->mac_filter_list_lock);
+		goto error;
+	}
+	list_for_each_entry_safe(f, tmp, &adapter->config_data.mac_filter_list,
+				 list) {
+		if (add && f->add) {
+			ether_addr_copy(eal[i].addr, f->macaddr);
+			i++;
+			f->add = false;
+			if (i == total_filters)
+				break;
+		}
+		if (!add && f->remove) {
+			ether_addr_copy(eal[i].addr, f->macaddr);
+			i++;
+			list_del(&f->list);
+			kfree(f);
+			if (i == total_filters)
+				break;
+		}
+	}
+
+	spin_unlock_bh(&adapter->mac_filter_list_lock);
+
+	/* Chunk up the filters into multiple messages to avoid
+	 * sending a control queue message buffer that is too large
+	 */
+	if (total_filters < IECM_NUM_FILTERS_PER_MSG)
+		num_entries = total_filters;
+	else
+		num_entries = IECM_NUM_FILTERS_PER_MSG;
+
+	num_msgs = DIV_ROUND_UP(total_filters, IECM_NUM_FILTERS_PER_MSG);
+
+	for (i = 0, k = 0; i < num_msgs || num_entries; i++) {
+		int buf_size = sizeof(struct virtchnl_ether_addr_list) +
+			(sizeof(struct virtchnl_ether_addr) * num_entries);
+		if (!veal || num_entries != IECM_NUM_FILTERS_PER_MSG) {
+			kfree(veal);
+			veal = kzalloc(buf_size, GFP_KERNEL);
+			if (!veal) {
+				err = -ENOMEM;
+				goto list_prep_error;
+			}
+		} else {
+			memset(veal, 0, buf_size);
+		}
+
+		veal->vsi_id = vport->vport_id;
+		veal->num_elements = num_entries;
+		memcpy(veal->list, &eal[k],
+		       sizeof(struct virtchnl_ether_addr) * num_entries);
+
+		if (add) {
+			vop = VIRTCHNL_OP_ADD_ETH_ADDR;
+			vc = IECM_VC_ADD_ETH_ADDR;
+			vc_err = IECM_VC_ADD_ETH_ADDR_ERR;
+		} else  {
+			vop = VIRTCHNL_OP_DEL_ETH_ADDR;
+			vc = IECM_VC_DEL_ETH_ADDR;
+			vc_err = IECM_VC_DEL_ETH_ADDR_ERR;
+		}
+		err = iecm_send_mb_msg(vport->adapter, vop, buf_size,
+				       (u8 *)veal);
+		if (err)
+			goto mbx_error;
+
+		if (!async) {
+			err = iecm_wait_for_event(vport->adapter, vc, vc_err);
+			if (err)
+				goto mbx_error;
+		}
+
+		k += num_entries;
+		total_filters -= num_entries;
+		if (total_filters < IECM_NUM_FILTERS_PER_MSG)
+			num_entries = total_filters;
+	}
+mbx_error:
+	kfree(veal);
+list_prep_error:
+	kfree(eal);
+error:
+	if (err)
+		dev_err(&pdev->dev, "Failed to add or del mac filters %d", err);
+}
+
 /**
  * iecm_add_del_vlans - Add or delete vlan filter
  * @vport: vport structure
drivers/net/ethernet/intel/include/iecm.h +108 -4
index d736db65da06..b5bd73be2855 100644
@@ -33,6 +33,11 @@
 #define IECM_MB_MAX_ERR			20
 #define IECM_NUM_CHUNKS_PER_MSG(a, b)	((IECM_DFLT_MBX_BUF_SIZE - (a)) / (b))
 
+/* 2K is the real maximum, but the driver should not be using more than the
+ * below limit
+ */
+#define IECM_MAX_VECIDS			256
+
 #define IECM_MAX_NUM_VPORTS		1
 
 /* available message levels */
@@ -135,6 +140,10 @@ enum iecm_cap_field {
 	IECM_CAP_FIELD_LAST,
 };
 
+struct iecm_netdev_priv {
+	struct iecm_vport *vport;
+};
+
 struct iecm_reset_reg {
 	u32 rstat;
 	u32 rstat_m;
@@ -450,6 +459,8 @@ struct iecm_adapter {
 	struct msix_entry *msix_entries;
 	struct virtchnl2_alloc_vectors *req_vec_chunks;
 	struct iecm_q_vector mb_vector;
+	/* handler for hard interrupt for mailbox*/
+	irqreturn_t (*irq_mb_handler)(int irq, void *data);
 
 	/* vport structs */
 	struct iecm_vport **vports;	/* vports created by the driver */
@@ -537,12 +548,88 @@ static inline bool __iecm_is_cap_ena(struct iecm_adapter *adapter, bool all,
 	return adapter->dev_ops.vc_ops.is_cap_ena(adapter, all, field, flag);
 }
 
-#define IECM_CAP_HSPLIT (\
-	VIRTCHNL2_CAP_RX_HSPLIT_AT_L2   |\
-	VIRTCHNL2_CAP_RX_HSPLIT_AT_L3   |\
-	VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V4 |\
+/* enum used to distinguish vlan capabilities */
+enum iecm_vlan_caps {
+	IECM_CAP_VLAN_CTAG_INSERT,
+	IECM_CAP_VLAN_STAG_INSERT,
+	IECM_CAP_VLAN_CTAG_STRIP,
+	IECM_CAP_VLAN_STAG_STRIP,
+	IECM_CAP_VLAN_CTAG_ADD_DEL,
+	IECM_CAP_VLAN_STAG_ADD_DEL,
+	IECM_CAP_VLAN_LAST,
+};
+
+#define IECM_VLAN_8100 (VIRTCHNL_VLAN_TOGGLE | VIRTCHNL_VLAN_ETHERTYPE_8100)
+#define IECM_VLAN_88A8 (VIRTCHNL_VLAN_TOGGLE | VIRTCHNL_VLAN_ETHERTYPE_88A8)
+
+#define IECM_F_HW_VLAN_CTAG_TX NETIF_F_HW_VLAN_CTAG_TX
+
+#define IECM_F_HW_VLAN_CTAG_RX NETIF_F_HW_VLAN_CTAG_RX
+
+#define IECM_F_HW_VLAN_CTAG_FILTER NETIF_F_HW_VLAN_CTAG_FILTER
+
+#define IECM_CAP_RSS (\
+	VIRTCHNL2_CAP_RSS_IPV4_TCP	|\
+	VIRTCHNL2_CAP_RSS_IPV4_TCP	|\
+	VIRTCHNL2_CAP_RSS_IPV4_UDP	|\
+	VIRTCHNL2_CAP_RSS_IPV4_SCTP	|\
+	VIRTCHNL2_CAP_RSS_IPV4_OTHER	|\
+	VIRTCHNL2_CAP_RSS_IPV4_AH	|\
+	VIRTCHNL2_CAP_RSS_IPV4_ESP	|\
+	VIRTCHNL2_CAP_RSS_IPV4_AH_ESP	|\
+	VIRTCHNL2_CAP_RSS_IPV6_TCP	|\
+	VIRTCHNL2_CAP_RSS_IPV6_TCP	|\
+	VIRTCHNL2_CAP_RSS_IPV6_UDP	|\
+	VIRTCHNL2_CAP_RSS_IPV6_SCTP	|\
+	VIRTCHNL2_CAP_RSS_IPV6_OTHER	|\
+	VIRTCHNL2_CAP_RSS_IPV6_AH	|\
+	VIRTCHNL2_CAP_RSS_IPV6_ESP	|\
+	VIRTCHNL2_CAP_RSS_IPV6_AH_ESP)
+
+#define IECM_CAP_RSC (\
+	VIRTCHNL2_CAP_RSC_IPV4_TCP	|\
+	VIRTCHNL2_CAP_RSC_IPV4_SCTP	|\
+	VIRTCHNL2_CAP_RSC_IPV6_TCP	|\
+	VIRTCHNL2_CAP_RSC_IPV6_SCTP)
+
+#define IECM_CAP_HSPLIT	(\
+	VIRTCHNL2_CAP_RX_HSPLIT_AT_L2	|\
+	VIRTCHNL2_CAP_RX_HSPLIT_AT_L3	|\
+	VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V4	|\
 	VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V6)
 
+#define IECM_CAP_RX_CSUM_L4V4 (\
+	VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_TCP	|\
+	VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_UDP)
+
+#define IECM_CAP_RX_CSUM_L4V6 (\
+	VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_TCP	|\
+	VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_UDP)
+
+#define IECM_CAP_RX_CSUM (\
+	VIRTCHNL2_CAP_RX_CSUM_L3_IPV4		|\
+	VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_TCP	|\
+	VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_UDP	|\
+	VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_SCTP	|\
+	VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_TCP	|\
+	VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_UDP	|\
+	VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_SCTP)
+
+#define IECM_CAP_SCTP_CSUM (\
+	VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_SCTP	|\
+	VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_SCTP	|\
+	VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_SCTP	|\
+	VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_SCTP)
+
+/**
+ * iecm_get_reserved_vecs - Get reserved vectors
+ * @adapter: private data struct
+ */
+static inline u16 iecm_get_reserved_vecs(struct iecm_adapter *adapter)
+{
+	return adapter->dev_ops.vc_ops.get_reserved_vecs(adapter);
+}
+
 /**
  * iecm_is_reset_detected - check if we were reset at some point
  * @adapter: driver specific private structure
@@ -555,6 +642,20 @@ static inline bool iecm_is_reset_detected(struct iecm_adapter *adapter)
 		 adapter->hw.arq->reg.len_ena_mask);
 }
 
+/**
+ * iecm_is_reset_in_prog - check if reset is in progress
+ * @adapter: driver specific private structure
+ *
+ * Returns true if hard reset is in progress, false otherwise
+ */
+static inline bool iecm_is_reset_in_prog(struct iecm_adapter *adapter)
+{
+	return (test_bit(__IECM_HR_RESET_IN_PROG, adapter->flags) ||
+		test_bit(__IECM_HR_FUNC_RESET, adapter->flags) ||
+		test_bit(__IECM_HR_CORE_RESET, adapter->flags) ||
+		test_bit(__IECM_HR_DRV_LOAD, adapter->flags));
+}
+
 int iecm_probe(struct pci_dev *pdev,
 	       const struct pci_device_id __always_unused *ent,
 	       struct iecm_adapter *adapter);
@@ -576,6 +677,7 @@ int iecm_send_get_caps_msg(struct iecm_adapter *adapter);
 int iecm_send_delete_queues_msg(struct iecm_vport *vport);
 int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,
 			     u16 num_complq, u16 num_rx_q, u16 num_rx_bufq);
+int iecm_send_vlan_v2_caps_msg(struct iecm_adapter *adapter);
 int iecm_send_config_tx_queues_msg(struct iecm_vport *vport);
 int iecm_send_config_rx_queues_msg(struct iecm_vport *vport);
 int iecm_send_enable_vport_msg(struct iecm_vport *vport);
@@ -589,6 +691,7 @@ int iecm_send_dealloc_vectors_msg(struct iecm_adapter *adapter);
 int iecm_send_alloc_vectors_msg(struct iecm_adapter *adapter, u16 num_vectors);
 int iecm_vport_params_buf_alloc(struct iecm_adapter *adapter);
 void iecm_vport_params_buf_rel(struct iecm_adapter *adapter);
+struct iecm_vport *iecm_netdev_to_vport(struct net_device *netdev);
 int iecm_send_get_stats_msg(struct iecm_vport *vport);
 int iecm_get_vec_ids(struct iecm_adapter *adapter,
 		     u16 *vecids, int num_vecids,
@@ -598,6 +701,7 @@ int iecm_recv_mb_msg(struct iecm_adapter *adapter, enum virtchnl_ops op,
 int iecm_send_mb_msg(struct iecm_adapter *adapter, enum virtchnl_ops op,
 		     u16 msg_size, u8 *msg);
 void iecm_vport_set_hsplit(struct iecm_vport *vport, bool ena);
+void iecm_add_del_ether_addrs(struct iecm_vport *vport, bool add, bool async);
 int iecm_send_enable_channels_msg(struct iecm_vport *vport);
 int iecm_send_disable_channels_msg(struct iecm_vport *vport);
 bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature);
drivers/net/ethernet/intel/include/iecm_txrx.h +2 -0
index 9f3086bfe575..0aa1eac70e7c 100644
@@ -512,4 +512,6 @@ void iecm_vport_calc_total_qs(struct iecm_adapter *adapter,
 			      struct virtchnl2_create_vport *vport_msg);
 void iecm_vport_calc_num_q_groups(struct iecm_vport *vport);
 void iecm_vport_calc_num_q_vec(struct iecm_vport *vport);
+irqreturn_t
+iecm_vport_intr_clean_queues(int __always_unused irq, void *data);
 #endif /* !_IECM_TXRX_H_ */
Signature · 1 line
2.33.0

Thanks,
Al

#38 lore raw

PATCH 8/19 iecm: add interrupts and configure netdev

Quoted 224 lines

-----Original Message-----
From: Lobakin, Alexandr <[email protected]>
Sent: Friday, January 28, 2022 5:35 AM
To: Brady, Alan <[email protected]>
Cc: Lobakin, Alexandr <[email protected]>; intel-wired- lan at lists.osuosl.org; Linga, Pavan Kumar <[email protected]>; Chittim, Madhu <[email protected]>; Burra, Phani R <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net-next 08/19] iecm: add interrupts and configure netdev

From: Alan Brady <[email protected]>
Date: Thu, 27 Jan 2022 16:09:58 -0800

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport,

Quoted 58 lines

This finishes implementing init_task by adding everything we need to configure the netdevice for the vport and setup its interrupts.

---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    | 813 +++++++++++++++++-
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   |  17 +
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   | 165 ++++
 drivers/net/ethernet/intel/include/iecm.h     | 112 ++-
 .../net/ethernet/intel/include/iecm_txrx.h    |   2 +
 5 files changed, 1104 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/iecm/iecm_lib.c +23 -0
index aab8ee40424e..255b04c25683 100644
@@ -5,11 +5,35 @@
 
 #include "iecm.h"
 
+static const struct net_device_ops iecm_netdev_ops_splitq; static
+const struct net_device_ops iecm_netdev_ops_singleq;
+
 const char * const iecm_vport_vc_state_str[] = {
 	IECM_FOREACH_VPORT_VC_STATE(IECM_GEN_STRING)
 };
 EXPORT_SYMBOL(iecm_vport_vc_state_str);
 
+/**
+ * iecm_get_vport_index - Get the vport index
+ * @adapter: adapter structure to get the vports array
+ * @vport: vport pointer for which the index to find  */ static int
+iecm_get_vport_index(struct iecm_adapter *adapter,
+				struct iecm_vport *vport)
+{
+	int i, err = -EINVAL;
+
+	if (!adapter->vports)
+		return err;
+
+	for (i = 0; i < adapter->num_alloc_vport; i++) {
+		if (adapter->vports[i] != vport)
+			continue;
+		return i;
+	}
+	return err;
+}
+
 /**
  * iecm_is_feature_ena - Determine if a particular feature is enabled
  * @vport: vport to check
@@ -29,6 +53,595 @@ bool iecm_is_feature_ena(struct iecm_vport *vport,

netdev_features_t feature)

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)

Quoted 13 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
 	return ena;
 }
 
+/**
+ * iecm_is_vlan_cap_ena - Check if VLAN capability is enabled
+ * @adapter: pointer to adapter
+ * @vcaps: VLAN capability bit
+ *
+ * Returns true if VLAN capability is set, false otherwise  */ static
+bool iecm_is_vlan_cap_ena(struct iecm_adapter *adapter,
+				 enum iecm_vlan_caps vcaps)
+{
+	if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS,

VIRTCHNL2_CAP_VLAN)) {

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+		struct virtchnl_vlan_supported_caps *offload;
+
+		if (!adapter->vlan_caps)
+			return false;
+
+		switch (vcaps) {
+		case IECM_CAP_VLAN_CTAG_INSERT:
+			offload =
+			&adapter->vlan_caps->offloads.insertion_support;
+			if ((offload->outer & IECM_VLAN_8100) ==

IECM_VLAN_8100 ||

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, · line 76

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_lib.c +1 -0
+			    (offload->inner & IECM_VLAN_8100) ==

IECM_VLAN_8100)

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +6 -0
+				return true;
+			break;
+		case IECM_CAP_VLAN_STAG_INSERT:
+			offload =
+			&adapter->vlan_caps->offloads.insertion_support;
+			if ((offload->outer & IECM_VLAN_88A8) ==

IECM_VLAN_88A8)

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +6 -0
+				return true;
+			break;
+		case IECM_CAP_VLAN_CTAG_STRIP:
+			offload =
+			&adapter->vlan_caps->offloads.stripping_support;
+			if ((offload->outer & IECM_VLAN_8100) ==

IECM_VLAN_8100 ||

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, · line 89

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_lib.c +1 -0
+			    (offload->inner & IECM_VLAN_8100) ==

IECM_VLAN_8100)

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +6 -0
+				return true;
+			break;
+		case IECM_CAP_VLAN_STAG_STRIP:
+			offload =
+			&adapter->vlan_caps->offloads.stripping_support;
+			if ((offload->outer & IECM_VLAN_88A8) ==

IECM_VLAN_88A8)

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +6 -0
+				return true;
+			break;
+		case IECM_CAP_VLAN_CTAG_ADD_DEL:
+			offload =
+			&adapter->vlan_caps->filtering.filtering_support;
+			if ((offload->outer &

VIRTCHNL_VLAN_ETHERTYPE_8100) ||

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, · line 102

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_lib.c +1 -0
+			    (offload->inner &

VIRTCHNL_VLAN_ETHERTYPE_8100))

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +6 -0
+				return true;
+			break;
+		case IECM_CAP_VLAN_STAG_ADD_DEL:
+			offload =
+			&adapter->vlan_caps->filtering.filtering_support;
+			if ((offload->outer &

VIRTCHNL_VLAN_ETHERTYPE_88A8) ||

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, · line 109

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_lib.c +1 -0
+			    (offload->inner &

VIRTCHNL_VLAN_ETHERTYPE_88A8))

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +4 -0
+				return true;
+			break;
+		default:
+			dev_err(&adapter->pdev->dev, "Invalid VLAN capability

%d\n",

Quoted 78 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +78 -0
+				vcaps);
+			return false;
+		}
+	} else if (iecm_is_cap_ena(adapter, IECM_BASE_CAPS,
+				   VIRTCHNL2_CAP_VLAN)) {
+		switch (vcaps) {
+		case IECM_CAP_VLAN_CTAG_INSERT:
+		case IECM_CAP_VLAN_CTAG_STRIP:
+		case IECM_CAP_VLAN_CTAG_ADD_DEL:
+			return true;
+		default:
+			return false;
+		}
+	}
+
+	return false;
+}
+
+/**
+ * iecm_netdev_to_vport - get a vport handle from a netdev
+ * @netdev: network interface device structure  */ struct iecm_vport
+*iecm_netdev_to_vport(struct net_device *netdev) {
+	struct iecm_netdev_priv *np = netdev_priv(netdev);
+
+	return np->vport;
+}
+
+/**
+ * iecm_mb_intr_rel_irq - Free the IRQ association with the OS
+ * @adapter: adapter structure
+ */
+static void iecm_mb_intr_rel_irq(struct iecm_adapter *adapter) {
+	int irq_num;
+
+	irq_num = adapter->msix_entries[0].vector;
+	free_irq(irq_num, adapter);
+}
+
+/**
+ * iecm_intr_rel - Release interrupt capabilities and free memory
+ * @adapter: adapter to disable interrupts on  */ static void
+iecm_intr_rel(struct iecm_adapter *adapter) {
+	if (!adapter->msix_entries)
+		return;
+	clear_bit(__IECM_MB_INTR_MODE, adapter->flags);
+	clear_bit(__IECM_MB_INTR_TRIGGER, adapter->flags);
+	iecm_mb_intr_rel_irq(adapter);
+
+	pci_free_irq_vectors(adapter->pdev);
+	if (adapter->dev_ops.vc_ops.dealloc_vectors) {
+		int err;
+
+		err = adapter->dev_ops.vc_ops.dealloc_vectors(adapter);
+		if (err) {
+			dev_err(&adapter->pdev->dev,
+				"Failed to deallocate vectors: %d\n", err);
+		}
+	}
+	kfree(adapter->msix_entries);
+	adapter->msix_entries = NULL;
+	kfree(adapter->req_vec_chunks);
+	adapter->req_vec_chunks = NULL;
+}
+
+/**
+ * iecm_mb_intr_clean - Interrupt handler for the mailbox
+ * @irq: interrupt number
+ * @data: pointer to the adapter structure  */ static irqreturn_t
+iecm_mb_intr_clean(int __always_unused irq, void *data) {
+	struct iecm_adapter *adapter = (struct iecm_adapter *)data;
+
+	set_bit(__IECM_MB_INTR_TRIGGER, adapter->flags);
+	queue_delayed_work(adapter->serv_wq, &adapter->serv_task,
+			   msecs_to_jiffies(0));
+	return IRQ_HANDLED;
+}
+
+/**
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature) · line 206

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +5 -0
+ * iecm_mb_irq_enable - Enable MSIX interrupt for the mailbox
+ * @adapter: adapter to get the hardware address for register write
+*/ static void iecm_mb_irq_enable(struct iecm_adapter *adapter) {
+	struct iecm_hw *hw = &adapter->hw;
+	struct iecm_intr_reg *intr = &adapter->mb_vector.intr_reg;

Please don't break Reverse Christmas Tree declaration style. *intr doesn't depend on *hw.

Will fix

Quoted 199 lines
Quoted 68 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +67 -0
+	u32 val;
+
+	val = intr->dyn_ctl_intena_m | intr->dyn_ctl_itridx_m;
+	wr32(hw, intr->dyn_ctl, val);
+	wr32(hw, intr->icr_ena, intr->icr_ena_ctlq_m); }
+
+/**
+ * iecm_mb_intr_req_irq - Request irq for the mailbox interrupt
+ * @adapter: adapter structure to pass to the mailbox irq handler  */
+static int iecm_mb_intr_req_irq(struct iecm_adapter *adapter) {
+	struct iecm_q_vector *mb_vector = &adapter->mb_vector;
+	int irq_num, mb_vidx = 0, err;
+
+	irq_num = adapter->msix_entries[mb_vidx].vector;
+	snprintf(mb_vector->name, sizeof(mb_vector->name) - 1,
+		 "%s-%s-%d", dev_driver_string(&adapter->pdev->dev),
+		 "Mailbox", mb_vidx);
+	err = request_irq(irq_num, adapter->irq_mb_handler, 0,
+			  mb_vector->name, adapter);
+	if (err) {
+		dev_err(&adapter->pdev->dev,
+			"Request_irq for mailbox failed, error: %d\n", err);
+		return err;
+	}
+	set_bit(__IECM_MB_INTR_MODE, adapter->flags);
+	return 0;
+}
+
+/**
+ * iecm_get_mb_vec_id - Get vector index for mailbox
+ * @adapter: adapter structure to access the vector chunks
+ *
+ * The first vector id in the requested vector chunks from the CP is
+for
+ * the mailbox
+ */
+static void iecm_get_mb_vec_id(struct iecm_adapter *adapter) {
+	if (adapter->req_vec_chunks) {
+		struct virtchnl2_get_capabilities *caps;
+
+		caps = (struct virtchnl2_get_capabilities *)adapter->caps;
+		adapter->mb_vector.v_idx = le16_to_cpu(caps-
 mailbox_vector_id);
+	} else {
+		adapter->mb_vector.v_idx = 0;
+	}
+}
+
+/**
+ * iecm_mb_intr_init - Initialize the mailbox interrupt
+ * @adapter: adapter structure to store the mailbox vector  */ static
+int iecm_mb_intr_init(struct iecm_adapter *adapter) {
+	adapter->dev_ops.reg_ops.mb_intr_reg_init(adapter);
+	adapter->irq_mb_handler = iecm_mb_intr_clean;
+	return iecm_mb_intr_req_irq(adapter); }
+
+/**
+ * iecm_intr_distribute - Distribute MSIX vectors
+ * @adapter: adapter structure to get the vports
+ * @pre_req: before or after msi request
+ *
+ * Distribute the MSIX vectors acquired from the OS to the vports
+based on the
+ * num of vectors requested by each vport  */ static int
+iecm_intr_distribute(struct iecm_adapter *adapter, bool pre_req) {
+	struct iecm_vport *vport = adapter->vports[0];
+	int err = 0;
+

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+	if (pre_req) {
+		u16 vecs_avail;
+
+		vecs_avail = iecm_get_reserved_vecs(adapter);
+		if (vecs_avail < IECM_MIN_VEC) {
+			return -EAGAIN;
+		} else if (vecs_avail == IECM_MIN_VEC) {
+			vport->num_q_vectors = IECM_MIN_Q_VEC;
+		} else {
+			vport->num_q_vectors = vecs_avail - IECM_NONQ_VEC

-

Quoted 37 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +37 -0
+						IECM_MAX_RDMA_VEC;
+		}
+	} else {
+		if (adapter->num_msix_entries != adapter->num_req_msix)
+			vport->num_q_vectors = adapter->num_msix_entries -
+					       IECM_NONQ_VEC;
+	}
+
+	return err;
+}
+
+/**
+ * iecm_intr_req - Request interrupt capabilities
+ * @adapter: adapter to enable interrupts on
+ *
+ * Returns 0 on success, negative on failure  */ static int
+iecm_intr_req(struct iecm_adapter *adapter) {
+	int min_vectors, max_vectors, err = 0;
+	int num_q_vecs, total_num_vecs;
+	u16 vecids[IECM_MAX_VECIDS];
+	unsigned int vector;
+	int v_actual;
+
+	err = iecm_intr_distribute(adapter, true);
+	if (err)
+		return err;
+
+	num_q_vecs = adapter->vports[0]->num_q_vectors;
+
+	total_num_vecs = num_q_vecs + IECM_NONQ_VEC;
+
+	if (adapter->dev_ops.vc_ops.alloc_vectors) {
+		err = adapter->dev_ops.vc_ops.alloc_vectors(adapter,
+							    num_q_vecs);
+		if (err) {
+			dev_err(&adapter->pdev->dev,
+				"Failed to allocate vectors: %d\n", err);

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+			return -EAGAIN;
+		}
+	}
+
+	min_vectors = IECM_MIN_VEC;
+	max_vectors = total_num_vecs;
+	v_actual = pci_alloc_irq_vectors(adapter->pdev, min_vectors,
+					 max_vectors, PCI_IRQ_MSIX);
+	if (v_actual < 0) {
+		dev_err(&adapter->pdev->dev, "Failed to allocate MSIX vectors:

%d\n",

Quoted 16 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +16 -0
+			v_actual);
+		if (adapter->dev_ops.vc_ops.dealloc_vectors)
+			adapter->dev_ops.vc_ops.dealloc_vectors(adapter);
+		return -EAGAIN;
+	}
+
+	adapter->msix_entries = kcalloc(v_actual, sizeof(struct msix_entry),
+					GFP_KERNEL);
+
+	if (!adapter->msix_entries) {
+		pci_free_irq_vectors(adapter->pdev);
+		if (adapter->dev_ops.vc_ops.dealloc_vectors)
+			adapter->dev_ops.vc_ops.dealloc_vectors(adapter);
+		return -ENOMEM;
+	}
+

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+	iecm_get_mb_vec_id(adapter);
+
+	if (adapter->req_vec_chunks) {
+		struct virtchnl2_vector_chunks *vchunks;
+		struct virtchnl2_alloc_vectors *ac;
+
+		ac = adapter->req_vec_chunks;
+		vchunks = &ac->vchunks;
+
+		iecm_get_vec_ids(adapter, vecids, IECM_MAX_VECIDS,

vchunks);

Quoted 45 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +45 -0
+	} else {
+		int i = 0;
+
+		for (i = 0; i < v_actual; i++)
+			vecids[i] = i;
+	}
+
+	for (vector = 0; vector < v_actual; vector++) {
+		adapter->msix_entries[vector].entry = vecids[vector];
+		adapter->msix_entries[vector].vector =
+			pci_irq_vector(adapter->pdev, vector);
+	}
+	adapter->num_msix_entries = v_actual;
+	adapter->num_req_msix = total_num_vecs;
+
+	iecm_intr_distribute(adapter, false);
+
+	err = iecm_mb_intr_init(adapter);
+	if (err)
+		goto intr_rel;
+	iecm_mb_irq_enable(adapter);
+	return err;
+
+intr_rel:
+	iecm_intr_rel(adapter);
+	return err;
+}
+
+/**
+ * iecm_find_mac_filter - Search filter list for specific mac filter
+ * @vport: main vport structure
+ * @macaddr: the MAC address
+ *
+ * Returns ptr to the filter object or NULL. Must be called while
+holding the
+ * mac_filter_list_lock.
+ **/
+static struct
+iecm_mac_filter *iecm_find_mac_filter(struct iecm_vport *vport,
+				      const u8 *macaddr)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_mac_filter *f;
+
+	if (!macaddr)
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature) · line 416

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +6 -0
+		return NULL;
+
+	list_for_each_entry(f, &adapter->config_data.mac_filter_list, list) {
+		if (ether_addr_equal(macaddr, f->macaddr))
+			return f;
+	}

Excessive braces again.

Will not fix.

Quoted 43 lines
Quoted 13 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +13 -0
+	return NULL;
+}
+
+/**
+ * __iecm_add_mac_filter - Add mac filter helper function
+ * @vport: main vport struct
+ * @macaddr: address to add
+ *
+ * Takes mac_filter_list_lock spinlock to add new filter to list.
+ */
+static struct
+iecm_mac_filter *__iecm_add_mac_filter(struct iecm_vport *vport,
+				       const u8 *macaddr)

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_mac_filter *f = NULL;
+
+	spin_lock_bh(&adapter->mac_filter_list_lock);
+	f = iecm_find_mac_filter(vport, macaddr);
+	if (!f) {
+		f = kzalloc(sizeof(*f), GFP_ATOMIC);
+		if (!f) {
+			dev_err(&adapter->pdev->dev, "Failed to allocate filter:

%pM",

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature) · line 450

Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +11 -0
+				macaddr);
+			goto error;
+		}
+
+		ether_addr_copy(f->macaddr, macaddr);
+
+		list_add_tail(&f->list, &adapter->config_data.mac_filter_list);
+		f->add = true;
+	} else {
+		f->remove = false;
+	}
	if (f) {
		f->remove = false;
		goto error; /* It's better to rename it */
	}

	f = kzalloc(...
Quoted 1 line

-1 indent level.

Will fix

Quoted 170 lines
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +6 -0
+error:
+	spin_unlock_bh(&adapter->mac_filter_list_lock);
+
+	return f;
+}
+

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+/**
+ * iecm_add_mac_filter - Add a mac filter to the filter list
+ * @vport: main vport structure
+ * @macaddr: the MAC address
+ *
+ * Returns ptr to the filter or NULL on error. If interface is up,
+we'll also
+ * send the virtchnl message to tell hardware about the filter.
+ **/
+static struct iecm_mac_filter *iecm_add_mac_filter(struct iecm_vport

*vport,

Quoted 21 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +21 -0
+						   const u8 *macaddr)
+{
+	struct iecm_mac_filter *f;
+
+	if (!macaddr)
+		return NULL;
+
+	f = __iecm_add_mac_filter(vport, macaddr);
+	if (!f)
+		return NULL;
+
+	if (vport->adapter->state == __IECM_UP)
+		iecm_add_del_ether_addrs(vport, true, false);
+
+	return f;
+}
+
+/**
+ * iecm_init_mac_addr - initialize mac address for vport
+ * @vport: main vport structure
+ * @netdev: pointer to netdev struct associated with this vport  */

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+static int iecm_init_mac_addr(struct iecm_vport *vport,
+			      struct net_device *netdev)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+
+	if (!is_valid_ether_addr(vport->default_mac_addr)) {
+		if (!iecm_is_cap_ena(vport->adapter, IECM_OTHER_CAPS,
+				     VIRTCHNL2_CAP_MACFILTER)) {
+			dev_err(&adapter->pdev->dev,
+				"MAC address not provided and capability is not

set\n");

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +4 -0
+			return -EINVAL;
+		}
+
+		dev_info(&adapter->pdev->dev, "Invalid MAC address %pM,

using random\n",

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +9 -0
+			 vport->default_mac_addr);
+		eth_hw_addr_random(netdev);
+
+		if (!iecm_add_mac_filter(vport, netdev->dev_addr))
+			return -ENOMEM;
+
+		ether_addr_copy(vport->default_mac_addr, netdev-
 dev_addr);
+	} else {
+		dev_addr_mod(netdev, 0, vport->default_mac_addr,

ETH_ALEN);

Quoted 59 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +58 -0
+		ether_addr_copy(netdev->perm_addr, vport-
 default_mac_addr);
+	}
+
+	return 0;
+}
+
+/**
+ * iecm_cfg_netdev - Allocate, configure and register a netdev
+ * @vport: main vport structure
+ *
+ * Returns 0 on success, negative value on failure.
+ */
+static int iecm_cfg_netdev(struct iecm_vport *vport) {
+	struct iecm_adapter *adapter = vport->adapter;
+	netdev_features_t dflt_features;
+	netdev_features_t offloads = 0;
+	struct iecm_netdev_priv *np;
+	struct net_device *netdev;
+	u16 max_q;
+	int err;
+
+	lockdep_assert_held(&adapter->sw_mutex);
+
+	/* It's possible we already have a netdev allocated and registered for
+	 * this vport
+	 */
+	if (adapter->netdevs[vport->idx]) {
+		netdev = adapter->netdevs[vport->idx];
+		np = netdev_priv(netdev);
+		np->vport = vport;
+		vport->netdev = netdev;
+
+		return iecm_init_mac_addr(vport, netdev);
+	}
+
+	max_q = adapter->max_queue_limit;
+
+	netdev = alloc_etherdev_mqs(sizeof(struct iecm_netdev_priv),
+				    max_q, max_q);
+	if (!netdev)
+		return -ENOMEM;
+	vport->netdev = netdev;
+	np = netdev_priv(netdev);
+	np->vport = vport;
+
+	err = iecm_init_mac_addr(vport, netdev);
+	if (err)
+		goto err;
+
+	/* assign netdev_ops */
+	if (iecm_is_queue_model_split(vport->txq_model))
+		netdev->netdev_ops = &iecm_netdev_ops_splitq;
+	else
+		netdev->netdev_ops = &iecm_netdev_ops_singleq;
+
+	/* setup watchdog timeout value to be 5 second */
+	netdev->watchdog_timeo = 5 * HZ;
+

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+	/* configure default MTU size */
+	netdev->min_mtu = ETH_MIN_MTU;
+	netdev->max_mtu = vport->max_mtu;
+
+	dflt_features = NETIF_F_SG	|
+			NETIF_F_HIGHDMA;
+
+	if (iecm_is_cap_ena_all(adapter, IECM_RSS_CAPS, IECM_CAP_RSS))
+		dflt_features |= NETIF_F_RXHASH;
+	if (iecm_is_cap_ena_all(adapter, IECM_CSUM_CAPS,

IECM_CAP_RX_CSUM_L4V4))

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, · line 564

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +2 -0
+		dflt_features |= NETIF_F_IP_CSUM;
+	if (iecm_is_cap_ena_all(adapter, IECM_CSUM_CAPS,

IECM_CAP_RX_CSUM_L4V6))

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, · line 566

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +2 -0
+		dflt_features |= NETIF_F_IPV6_CSUM;
+	if (iecm_is_cap_ena(adapter, IECM_CSUM_CAPS,

IECM_CAP_RX_CSUM))

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, · line 568

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +2 -0
+		dflt_features |= NETIF_F_RXCSUM;
+	if (iecm_is_cap_ena_all(adapter, IECM_CSUM_CAPS,

IECM_CAP_SCTP_CSUM))

Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +7 -0
+		dflt_features |= NETIF_F_SCTP_CRC;
+
+	if (iecm_is_vlan_cap_ena(adapter, IECM_CAP_VLAN_CTAG_INSERT))
+		dflt_features |= IECM_F_HW_VLAN_CTAG_TX;
+	if (iecm_is_vlan_cap_ena(adapter, IECM_CAP_VLAN_CTAG_STRIP))
+		dflt_features |= IECM_F_HW_VLAN_CTAG_RX;
+	if (iecm_is_vlan_cap_ena(adapter, IECM_CAP_VLAN_CTAG_ADD_DEL))

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+		dflt_features |= IECM_F_HW_VLAN_CTAG_FILTER;
+
+	if (iecm_is_vlan_cap_ena(adapter, IECM_CAP_VLAN_STAG_INSERT))
+		dflt_features |= NETIF_F_HW_VLAN_STAG_TX;
+	if (iecm_is_vlan_cap_ena(adapter, IECM_CAP_VLAN_STAG_STRIP))
+		dflt_features |= NETIF_F_HW_VLAN_STAG_RX;
+	if (iecm_is_vlan_cap_ena(adapter, IECM_CAP_VLAN_STAG_ADD_DEL))
+		dflt_features |= NETIF_F_HW_VLAN_STAG_FILTER;
+	/* Enable cloud filter if ADQ is supported */
+	if (iecm_is_cap_ena(adapter, IECM_BASE_CAPS, VIRTCHNL2_CAP_ADQ)
||
> +	    iecm_is_cap_ena(adapter, IECM_OTHER_CAPS,

VIRTCHNL2_CAP_ADQ))

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, · line 587

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +2 -0
+		dflt_features |= NETIF_F_HW_TC;
+	if (iecm_is_cap_ena(adapter, IECM_SEG_CAPS,

VIRTCHNL2_CAP_SEG_IPV4_TCP))

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, · line 589

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +2 -0
+		dflt_features |= NETIF_F_TSO;
+	if (iecm_is_cap_ena(adapter, IECM_SEG_CAPS,

VIRTCHNL2_CAP_SEG_IPV6_TCP))

Quoted 10 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature) · line 614

Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +7 -0
+		dflt_features |= NETIF_F_TSO6;
+	if (iecm_is_cap_ena_all(adapter, IECM_SEG_CAPS,
+				VIRTCHNL2_CAP_SEG_IPV4_UDP |
+				VIRTCHNL2_CAP_SEG_IPV6_UDP))
+		dflt_features |= NETIF_F_GSO_UDP_L4;
+	if (iecm_is_cap_ena_all(adapter, IECM_RSC_CAPS, IECM_CAP_RSC))
+		offloads |= NETIF_F_GRO_HW;

I see offloads being used only here, |= -> =.

It makes it easier to add others in future or if some happen to get stripped in/out in the future it makes the code more resilient. We prefer to keep it this way.

Quoted 89 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_vport_rel_all(struct iecm_adapter

Quoted 56 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +30 -0
+	netdev->features |= dflt_features;
+	netdev->hw_features |= dflt_features | offloads;
+	netdev->hw_enc_features |= dflt_features | offloads;
+
+	SET_NETDEV_DEV(netdev, &adapter->pdev->dev);
+
+	/* carrier off on init to avoid Tx hangs */
+	netif_carrier_off(netdev);
+
+	/* make sure transmit queues start off as stopped */
+	netif_tx_stop_all_queues(netdev);
+
+	/* register last */
+	err = register_netdev(netdev);
+	if (err)
+		goto err;
+
+	/* The vport can be arbitrarily released so we need to also track
+	 * netdevs in the adapter struct
+	 */
+	adapter->netdevs[vport->idx] = netdev;
+
+	return 0;
+err:
+	free_netdev(vport->netdev);
+	vport->netdev = NULL;
+
+	return err;
+}
+
 /**
  * iecm_cfg_hw - Initialize HW struct
  * @adapter: adapter to setup hw struct for @@ -77,6 +690,24 @@

static int iecm_get_free_slot(void *array, int size, int curr)

drivers/net/ethernet/intel/iecm/iecm_lib.c +15 -0
 	return next;
 }
 
+/**
+ * iecm_decfg_netdev - Unregister the netdev
+ * @vport: vport for which netdev to be unregistred  */ static void
+iecm_decfg_netdev(struct iecm_vport *vport) {
+	struct iecm_adapter *adapter = vport->adapter;
+
+	if (!vport->netdev)
+		return;
+
+	unregister_netdev(vport->netdev);
+	free_netdev(vport->netdev);
+	vport->netdev = NULL;
+
+	adapter->netdevs[vport->idx] = NULL; }
+
 /**
  * iecm_vport_rel - Delete a vport and free its resources
  * @vport: the vport being removed
@@ -102,6 +733,8 @@ static void iecm_vport_rel_all(struct iecm_adapter

*adapter)

drivers/net/ethernet/intel/iecm/iecm_lib.c iecm_vport_alloc(struct iecm_adapter *adapter, int

Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +2 -0
 		if (!adapter->vports[i])
 			continue;
 
+		if (!test_bit(__IECM_HR_RESET_IN_PROG, adapter->flags))
+			iecm_decfg_netdev(adapter->vports[i]);
 		iecm_vport_rel(adapter->vports[i]);
 		adapter->vports[i] = NULL;
 		adapter->next_vport = 0;
@@ -151,7 +784,7 @@ iecm_vport_alloc(struct iecm_adapter *adapter, int

vport_id)

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_statistics_task(struct work_struct

Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +1 -1
 	adapter->num_alloc_vport++;
 
 	/* Setup default MSIX irq handler for the vport */
-	vport->irq_q_handler = NULL;
+	vport->irq_q_handler = iecm_vport_intr_clean_queues;
 	vport->q_vector_base = IECM_NONQ_VEC;
 
 	mutex_init(&vport->stop_mutex);
@@ -184,8 +817,94 @@ static void iecm_statistics_task(struct work_struct

*work)

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_statistics_task(struct work_struct *work) · line 823

Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +4 -0
  *
  */
 static void iecm_service_task(struct work_struct *work)
+{
+	struct iecm_adapter *adapter = container_of(work,
+						    struct iecm_adapter,
+						    serv_task.work);
	struct iecm_adapter *adapter;

	adapter = container_of(work, typeof(*adapter), serv_task.work);
Quoted 2 lines

Same line count, but more elegant with no line wraps.

Will fix

Quoted 150 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_statistics_task(struct work_struct *work)

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +5 -0
+
+	if (test_bit(__IECM_MB_INTR_MODE, adapter->flags)) {
+		if (test_and_clear_bit(__IECM_MB_INTR_TRIGGER,
+				       adapter->flags)) {
+			iecm_recv_mb_msg(adapter,

VIRTCHNL_OP_UNKNOWN, NULL, 0);

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +4 -0
+			iecm_mb_irq_enable(adapter);
+		}
+	} else {
+		iecm_recv_mb_msg(adapter, VIRTCHNL_OP_UNKNOWN,

NULL, 0);

Quoted 27 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +27 -0
+	}
+
+	if (iecm_is_reset_detected(adapter) &&
+	    !iecm_is_reset_in_prog(adapter)) {
+		dev_info(&adapter->pdev->dev, "HW reset detected\n");
+		set_bit(__IECM_HR_FUNC_RESET, adapter->flags);
+		queue_delayed_work(adapter->vc_event_wq,
+				   &adapter->vc_event_task,
+				   msecs_to_jiffies(10));
+	}
+
+	queue_delayed_work(adapter->serv_wq, &adapter->serv_task,
+			   msecs_to_jiffies(300));
+}
+
+/* iecm_set_vlan_offload_features - set vlan offload features
+ * @netdev: netdev structure
+ * @prev_features: previously set features
+ * @features: current features received from user
+ *
+ * Returns 0 on success, error value on failure  */ static int
+iecm_set_vlan_offload_features(struct net_device *netdev,
+			       netdev_features_t prev_features,
+			       netdev_features_t features) {
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+	bool stripping_ena = true, insertion_ena = true;
+	struct iecm_virtchnl_ops *vc_ops;

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_statistics_task(struct work_struct *work)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+	u16 vlan_ethertype = 0;
+
+	vc_ops = &vport->adapter->dev_ops.vc_ops;
+	/* keep cases separate because one ethertype for offloads can be
+	 * disabled at the same time as another is disabled, so check for an
+	 * enabled ethertype first, then check for disabled. Default to
+	 * ETH_P_8021Q so an ethertype is specified if disabling insertion
+	 * and stripping.
+	 */
+	if (features & (NETIF_F_HW_VLAN_STAG_RX |

NETIF_F_HW_VLAN_STAG_TX))

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_statistics_task(struct work_struct · line 871

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +2 -0
+		vlan_ethertype = ETH_P_8021AD;
+	else if (features & (NETIF_F_HW_VLAN_CTAG_RX |

NETIF_F_HW_VLAN_CTAG_TX))

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_statistics_task(struct work_struct *work)

Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +11 -0
+		vlan_ethertype = ETH_P_8021Q;
+	else if (prev_features & (NETIF_F_HW_VLAN_STAG_RX |
+				  NETIF_F_HW_VLAN_STAG_TX))
+		vlan_ethertype = ETH_P_8021AD;
+	else if (prev_features & (NETIF_F_HW_VLAN_CTAG_RX |
+				  NETIF_F_HW_VLAN_CTAG_TX))
+		vlan_ethertype = ETH_P_8021Q;
+	else
+		vlan_ethertype = ETH_P_8021Q;
+
+	if (!(features & (NETIF_F_HW_VLAN_STAG_RX |

NETIF_F_HW_VLAN_CTAG_RX)))

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_statistics_task(struct work_struct · line 884

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +2 -0
+		stripping_ena = false;
+	if (!(features & (NETIF_F_HW_VLAN_STAG_TX |

NETIF_F_HW_VLAN_CTAG_TX)))

Quoted 49 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +33 -0
+		insertion_ena = false;
+
+	vport->adapter->config_data.vlan_ethertype = vlan_ethertype;
+
+	vc_ops->strip_vlan_msg(vport, stripping_ena);
+	if (vc_ops->insert_vlan_msg)
+		vc_ops->insert_vlan_msg(vport, insertion_ena);
+
+	return 0;
+}
+
+/**
+ * iecm_vport_open - Bring up a vport
+ * @vport: vport to bring up
+ * @alloc_res: allocate queue resources  */ static int
+iecm_vport_open(struct iecm_vport *vport, bool alloc_res)
 {
 	/* stub */
+	return 0;
 }
 
 /**
@@ -206,6 +925,7 @@ static void iecm_init_task(struct work_struct *work)
 	struct iecm_vport *vport;
 	struct pci_dev *pdev;
 	int vport_id, err;
+	int index;
 
 	err = adapter->dev_ops.vc_ops.core_init(adapter, &vport_id);
 	if (err)
@@ -219,6 +939,65 @@ static void iecm_init_task(struct work_struct *work)
 			err);
 		return;
 	}
+	/* Start the service task before requesting vectors. This will ensure
+	 * vector information response from mailbox is handled
+	 */
+	queue_delayed_work(adapter->serv_wq, &adapter->serv_task,
+			   msecs_to_jiffies(5 * (pdev->devfn & 0x07)));
+	err = iecm_intr_req(adapter);
+	if (err) {
+		dev_err(&pdev->dev, "failed to enable interrupt vectors: %d\n",
+			err);
+		goto intr_req_err;
+	}
+	err = iecm_send_vlan_v2_caps_msg(adapter);
+	if (err)
+		goto vlan_v2_caps_failed;
+

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_init_task(struct work_struct *work) · line 966

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+	err = adapter->dev_ops.vc_ops.get_supported_desc_ids(vport);
+	if (err) {
+		dev_err(&pdev->dev, "failed to get required descriptor ids\n");
+		goto rxdids_failed;
+	}
+
+	if (iecm_cfg_netdev(vport))
+		goto cfg_netdev_err;
+
+	if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS,

VIRTCHNL2_CAP_VLAN) ||

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_init_task(struct work_struct *work) · line 967

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_lib.c +1 -0
+	    iecm_is_cap_ena(adapter, IECM_BASE_CAPS,

VIRTCHNL2_CAP_VLAN)) {

Quoted 21 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +21 -0
+		err = iecm_set_vlan_offload_features(vport->netdev, 0,
+						     vport->netdev->features);
+		if (err)
+			goto cfg_netdev_err;
+	}
+
+	err = adapter->dev_ops.vc_ops.get_ptype(vport);
+	if (err)
+		goto cfg_netdev_err;
+	queue_delayed_work(adapter->stats_wq, &adapter->stats_task,
+			   msecs_to_jiffies(10 * (pdev->devfn & 0x07)));
+	set_bit(__IECM_VPORT_INIT_PROMISC, vport->flags);
+	/* Once state is put into DOWN, driver is ready for dev_open */
+	adapter->state = __IECM_DOWN;
+	if (test_and_clear_bit(__IECM_UP_REQUESTED, adapter->flags))
+		iecm_vport_open(vport, true);
+
+	/* Clear the reset flag unconditionally here in case we were in reset
+	 * and the link was down
+	 */
+	clear_bit(__IECM_HR_RESET_IN_PROG, vport->adapter->flags);
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_init_task(struct work_struct *work) · line 994

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +6 -0
+
+	return;
+
+vlan_v2_caps_failed:
+rxdids_failed:
+cfg_netdev_err:

No reason to declare 3 labels at the same point.

Will fix.

Quoted 11 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c void iecm_free_dma_mem(struct iecm_hw *hw,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +6 -0
+	iecm_intr_rel(adapter);
+intr_req_err:
+	index = iecm_get_vport_index(adapter, vport);
+	if (index >= 0)
+		adapter->vports[index] = NULL;
+	iecm_vport_rel(vport);
 }
 
 /**
@@ -614,3 +1393,35 @@ void iecm_free_dma_mem(struct iecm_hw *hw,

struct iecm_dma_mem *mem)

Quoted 14 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c void iecm_free_dma_mem(struct iecm_hw *hw, struct iecm_dma_mem *mem) · line 1402

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +7 -0
 	mem->va = NULL;
 	mem->pa = 0;
 }
+
+static const struct net_device_ops iecm_netdev_ops_splitq = {
+	.ndo_open = NULL,
+	.ndo_stop = NULL,
+	.ndo_start_xmit = NULL,
+	.ndo_set_rx_mode = NULL,
+	.ndo_validate_addr = eth_validate_addr,

eth_validate_addr() (or ether_addr_valid()) gets run by default when no .ndo_validate_addr is specified. It's redundant to declare it here.

Will fix

Quoted 11 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c void iecm_free_dma_mem(struct iecm_hw *hw, struct iecm_dma_mem *mem) · line 1410

Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +8 -0
+	.ndo_set_mac_address = NULL,
+	.ndo_change_mtu = NULL,
+	.ndo_get_stats64 = NULL,
+	.ndo_fix_features = NULL,
+	.ndo_set_features = NULL,
+	.ndo_vlan_rx_add_vid = NULL,
+	.ndo_vlan_rx_kill_vid = NULL,
+	.ndo_setup_tc = NULL,

Non-initialized members get zeroed by default, NULLing them is excessive.

The next patches will add these, they're placeholders. I left it like that because as you read the patches you can know what functions are there yet (as well as a checklist for myself as made the patches).

Quoted 440 lines
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +6 -0
+};
+
+static const struct net_device_ops iecm_netdev_ops_singleq = {
+	.ndo_open = NULL,
+	.ndo_stop = NULL,
+	.ndo_start_xmit = NULL,

drivers/net/ethernet/intel/iecm/iecm_lib.c void iecm_free_dma_mem(struct iecm_hw *hw, struct iecm_dma_mem *mem) · line 1426

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+	.ndo_set_rx_mode = NULL,
+	.ndo_validate_addr = eth_validate_addr,
+	.ndo_set_mac_address = NULL,
+	.ndo_change_mtu = NULL,
+	.ndo_get_stats64 = NULL,
+	.ndo_fix_features = NULL,
+	.ndo_set_features = NULL,
+	.ndo_vlan_rx_add_vid = NULL,
+	.ndo_vlan_rx_kill_vid = NULL,
+	.ndo_setup_tc           = NULL,

Same 2 previous points.

.ndo_setup_tc assignment indentation is weird. Either align all the initializers with tabs or don't align at all (both are valid cases).

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_send_insert_vlan_msg(struct

Quoted 35 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +1 -0
+};
drivers/net/ethernet/intel/iecm/iecm_txrx.c +16 -0
index bd0cfd89bf03..bb7f5830cffb 100644
@@ -218,6 +218,23 @@ const struct iecm_rx_ptype_decoded
 iecm_ptype_lookup[IECM_RX_MAX_PTYPE] = {  };
 EXPORT_SYMBOL(iecm_ptype_lookup);
 
+/**
+ * iecm_vport_intr_clean_queues - MSIX mode Interrupt Handler
+ * @irq: interrupt number
+ * @data: pointer to a q_vector
+ *
+ */
+irqreturn_t
+iecm_vport_intr_clean_queues(int __always_unused irq, void *data) {
+	struct iecm_q_vector *q_vector = (struct iecm_q_vector *)data;
+
+	q_vector->total_events++;
+	napi_schedule(&q_vector->napi);
+
+	return IRQ_HANDLED;
+}
+
 /**
  * iecm_vport_init_num_qs - Initialize number of queues
  * @vport: vport to initialize queues diff --git

a/drivers/net/ethernet/intel/iecm/iecm_virtchnl.c
b/drivers/net/ethernet/intel/iecm/iecm_virtchnl.c
index c4ae56897d1b..b91716aeef6f 100644

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +0 -0
@@ -2731,6 +2731,45 @@ static int iecm_send_insert_vlan_msg(struct

iecm_vport *vport, bool ena)

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +1 -0
 	return err;
 }
 
+/**

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_send_insert_vlan_msg(struct iecm_vport *vport, bool ena)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+ * iecm_send_vlan_v2_caps_msg - send virtchnl get offload VLAN V2
+caps message
+ * @adapter: adapter info struct
+ *
+ * Returns 0 on success and if VLAN V1 capability is set`, negative on failure.
+ */
+int iecm_send_vlan_v2_caps_msg(struct iecm_adapter *adapter) {
+	int err = 0;
+
+	if (!iecm_is_cap_ena(adapter, IECM_OTHER_CAPS,

VIRTCHNL2_CAP_VLAN))

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_send_insert_vlan_msg(struct · line 2747

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +3 -0
+		return err;
+
+	err = iecm_send_mb_msg(adapter,

VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS,

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_send_insert_vlan_msg(struct iecm_vport *vport, bool ena)

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +5 -0
+			       0, NULL);
+	if (err)
+		return err;
+
+	err = iecm_min_wait_for_event(adapter,

IECM_VC_OFFLOAD_VLAN_V2_CAPS,

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static unsigned int iecm_get_max_tx_bufs(struct

Quoted 24 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +20 -0
+				      IECM_VC_OFFLOAD_VLAN_V2_CAPS_ERR);
+
+	if (err) {
+		dev_err(&adapter->pdev->dev, "Failed to recv get caps");
+		return err;
+	}
+
+	if (!adapter->vlan_caps) {
+		adapter->vlan_caps =
+		  kzalloc(sizeof(*adapter->vlan_caps), GFP_KERNEL);
+		if (!adapter->vlan_caps)
+			return -ENOMEM;
+	}
+
+	memcpy(adapter->vlan_caps,
+	       adapter->vc_msg, sizeof(*adapter->vlan_caps));
+
+	return err;
+}
+
 /**
  * iecm_fill_ptype_lookup - Fill L3 specific fields in ptype lookup table
  * @ptype: ptype lookup table
@@ -3580,6 +3619,132 @@ static unsigned int iecm_get_max_tx_bufs(struct

iecm_adapter *adapter)

Quoted 66 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +62 -0
 	return ((struct virtchnl2_get_capabilities
 *)adapter->caps)->max_sg_bufs_per_tx_pkt;
 }
 
+/**
+ * iecm_add_del_ether_addrs
+ * @vport: virtual port data structure
+ * @add: Add or delete flag
+ * @async: Don't wait for return message
+ *
+ * Request that the PF add or delete one or more addresses to our filters.
+ **/
+void iecm_add_del_ether_addrs(struct iecm_vport *vport, bool add,
+bool async) {
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl_ether_addr_list *veal = NULL;
+	int num_entries, num_msgs, total_filters = 0;
+	struct pci_dev *pdev = adapter->pdev;
+	enum iecm_vport_vc_state vc, vc_err;
+	struct virtchnl_ether_addr *eal;
+	struct iecm_mac_filter *f, *tmp;
+	int i = 0, k = 0, err = 0;
+	enum virtchnl_ops vop;
+
+	spin_lock_bh(&adapter->mac_filter_list_lock);
+
+	/* Find the number of newly added filters */
+	list_for_each_entry(f, &adapter->config_data.mac_filter_list, list) {
+		if (add && f->add)
+			total_filters++;
+		else if (!add && f->remove)
+			total_filters++;
+	}
+	if (!total_filters) {
+		spin_unlock_bh(&adapter->mac_filter_list_lock);
+		goto error;
+	}
+
+	/* Fill all the new filters into virtchannel message */
+	eal = kcalloc(total_filters, sizeof(struct virtchnl_ether_addr),
+		      GFP_ATOMIC);
+	if (!eal) {
+		err = -ENOMEM;
+		spin_unlock_bh(&adapter->mac_filter_list_lock);
+		goto error;
+	}
+	list_for_each_entry_safe(f, tmp, &adapter->config_data.mac_filter_list,
+				 list) {
+		if (add && f->add) {
+			ether_addr_copy(eal[i].addr, f->macaddr);
+			i++;
+			f->add = false;
+			if (i == total_filters)
+				break;
+		}
+		if (!add && f->remove) {
+			ether_addr_copy(eal[i].addr, f->macaddr);
+			i++;
+			list_del(&f->list);
+			kfree(f);
+			if (i == total_filters)
+				break;
+		}
+	}
+
+	spin_unlock_bh(&adapter->mac_filter_list_lock);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static unsigned int iecm_get_max_tx_bufs(struct iecm_adapter *adapter)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+
+	/* Chunk up the filters into multiple messages to avoid
+	 * sending a control queue message buffer that is too large
+	 */
+	if (total_filters < IECM_NUM_FILTERS_PER_MSG)
+		num_entries = total_filters;
+	else
+		num_entries = IECM_NUM_FILTERS_PER_MSG;
+
+	num_msgs = DIV_ROUND_UP(total_filters,

IECM_NUM_FILTERS_PER_MSG);

Quoted 42 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +42 -0
+
+	for (i = 0, k = 0; i < num_msgs || num_entries; i++) {
+		int buf_size = sizeof(struct virtchnl_ether_addr_list) +
+			(sizeof(struct virtchnl_ether_addr) * num_entries);
+		if (!veal || num_entries != IECM_NUM_FILTERS_PER_MSG) {
+			kfree(veal);
+			veal = kzalloc(buf_size, GFP_KERNEL);
+			if (!veal) {
+				err = -ENOMEM;
+				goto list_prep_error;
+			}
+		} else {
+			memset(veal, 0, buf_size);
+		}
+
+		veal->vsi_id = vport->vport_id;
+		veal->num_elements = num_entries;
+		memcpy(veal->list, &eal[k],
+		       sizeof(struct virtchnl_ether_addr) * num_entries);
+
+		if (add) {
+			vop = VIRTCHNL_OP_ADD_ETH_ADDR;
+			vc = IECM_VC_ADD_ETH_ADDR;
+			vc_err = IECM_VC_ADD_ETH_ADDR_ERR;
+		} else  {
+			vop = VIRTCHNL_OP_DEL_ETH_ADDR;
+			vc = IECM_VC_DEL_ETH_ADDR;
+			vc_err = IECM_VC_DEL_ETH_ADDR_ERR;
+		}
+		err = iecm_send_mb_msg(vport->adapter, vop, buf_size,
+				       (u8 *)veal);
+		if (err)
+			goto mbx_error;
+
+		if (!async) {
+			err = iecm_wait_for_event(vport->adapter, vc, vc_err);
+			if (err)
+				goto mbx_error;
+		}
+
+		k += num_entries;
+		total_filters -= num_entries;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static unsigned int iecm_get_max_tx_bufs(struct iecm_adapter *adapter) · line 3745

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+		if (total_filters < IECM_NUM_FILTERS_PER_MSG)
+			num_entries = total_filters;
+	}
+mbx_error:
+	kfree(veal);
+list_prep_error:
+	kfree(eal);
+error:
+	if (err)
+		dev_err(&pdev->dev, "Failed to add or del mac filters %d", err);

}

drivers/net/ethernet/intel/include/iecm.h line 34

Quoted 12 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +1 -0
+
 /**
  * iecm_add_del_vlans - Add or delete vlan filter
  * @vport: vport structure
drivers/net/ethernet/intel/include/iecm.h +0 -0
index d736db65da06..b5bd73be2855 100644
@@ -33,6 +33,11 @@
 #define IECM_MB_MAX_ERR			20
 #define IECM_NUM_CHUNKS_PER_MSG(a, b)	((IECM_DFLT_MBX_BUF_SIZE -

(a)) / (b))

drivers/net/ethernet/intel/include/iecm.h static inline bool __iecm_is_cap_ena(struct

Quoted 31 lines
drivers/net/ethernet/intel/include/iecm.h +12 -0
+/* 2K is the real maximum, but the driver should not be using more
+than the
+ * below limit
+ */
+#define IECM_MAX_VECIDS			256
+
 #define IECM_MAX_NUM_VPORTS		1
 
 /* available message levels */
@@ -135,6 +140,10 @@ enum iecm_cap_field {
 	IECM_CAP_FIELD_LAST,
 };
 
+struct iecm_netdev_priv {
+	struct iecm_vport *vport;
+};
+
 struct iecm_reset_reg {
 	u32 rstat;
 	u32 rstat_m;
@@ -450,6 +459,8 @@ struct iecm_adapter {
 	struct msix_entry *msix_entries;
 	struct virtchnl2_alloc_vectors *req_vec_chunks;
 	struct iecm_q_vector mb_vector;
+	/* handler for hard interrupt for mailbox*/
+	irqreturn_t (*irq_mb_handler)(int irq, void *data);
 
 	/* vport structs */
 	struct iecm_vport **vports;	/* vports created by the driver */
@@ -537,12 +548,88 @@ static inline bool __iecm_is_cap_ena(struct

iecm_adapter *adapter, bool all,

Quoted 130 lines
drivers/net/ethernet/intel/include/iecm.h +81 -4
 	return adapter->dev_ops.vc_ops.is_cap_ena(adapter, all, field,
 flag);  }
 
-#define IECM_CAP_HSPLIT (\
-	VIRTCHNL2_CAP_RX_HSPLIT_AT_L2   |\
-	VIRTCHNL2_CAP_RX_HSPLIT_AT_L3   |\
-	VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V4 |\
+/* enum used to distinguish vlan capabilities */ enum iecm_vlan_caps
+{
+	IECM_CAP_VLAN_CTAG_INSERT,
+	IECM_CAP_VLAN_STAG_INSERT,
+	IECM_CAP_VLAN_CTAG_STRIP,
+	IECM_CAP_VLAN_STAG_STRIP,
+	IECM_CAP_VLAN_CTAG_ADD_DEL,
+	IECM_CAP_VLAN_STAG_ADD_DEL,
+	IECM_CAP_VLAN_LAST,
+};
+
+#define IECM_VLAN_8100 (VIRTCHNL_VLAN_TOGGLE |
+VIRTCHNL_VLAN_ETHERTYPE_8100) #define IECM_VLAN_88A8
+(VIRTCHNL_VLAN_TOGGLE | VIRTCHNL_VLAN_ETHERTYPE_88A8)
+
+#define IECM_F_HW_VLAN_CTAG_TX NETIF_F_HW_VLAN_CTAG_TX
+
+#define IECM_F_HW_VLAN_CTAG_RX NETIF_F_HW_VLAN_CTAG_RX
+
+#define IECM_F_HW_VLAN_CTAG_FILTER NETIF_F_HW_VLAN_CTAG_FILTER
+
+#define IECM_CAP_RSS (\
+	VIRTCHNL2_CAP_RSS_IPV4_TCP	|\
+	VIRTCHNL2_CAP_RSS_IPV4_TCP	|\
+	VIRTCHNL2_CAP_RSS_IPV4_UDP	|\
+	VIRTCHNL2_CAP_RSS_IPV4_SCTP	|\
+	VIRTCHNL2_CAP_RSS_IPV4_OTHER	|\
+	VIRTCHNL2_CAP_RSS_IPV4_AH	|\
+	VIRTCHNL2_CAP_RSS_IPV4_ESP	|\
+	VIRTCHNL2_CAP_RSS_IPV4_AH_ESP	|\
+	VIRTCHNL2_CAP_RSS_IPV6_TCP	|\
+	VIRTCHNL2_CAP_RSS_IPV6_TCP	|\
+	VIRTCHNL2_CAP_RSS_IPV6_UDP	|\
+	VIRTCHNL2_CAP_RSS_IPV6_SCTP	|\
+	VIRTCHNL2_CAP_RSS_IPV6_OTHER	|\
+	VIRTCHNL2_CAP_RSS_IPV6_AH	|\
+	VIRTCHNL2_CAP_RSS_IPV6_ESP	|\
+	VIRTCHNL2_CAP_RSS_IPV6_AH_ESP)
+
+#define IECM_CAP_RSC (\
+	VIRTCHNL2_CAP_RSC_IPV4_TCP	|\
+	VIRTCHNL2_CAP_RSC_IPV4_SCTP	|\
+	VIRTCHNL2_CAP_RSC_IPV6_TCP	|\
+	VIRTCHNL2_CAP_RSC_IPV6_SCTP)
+
+#define IECM_CAP_HSPLIT	(\
+	VIRTCHNL2_CAP_RX_HSPLIT_AT_L2	|\
+	VIRTCHNL2_CAP_RX_HSPLIT_AT_L3	|\
+	VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V4	|\
 	VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V6)
 
+#define IECM_CAP_RX_CSUM_L4V4 (\
+	VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_TCP	|\
+	VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_UDP)
+
+#define IECM_CAP_RX_CSUM_L4V6 (\
+	VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_TCP	|\
+	VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_UDP)
+
+#define IECM_CAP_RX_CSUM (\
+	VIRTCHNL2_CAP_RX_CSUM_L3_IPV4		|\
+	VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_TCP	|\
+	VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_UDP	|\
+	VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_SCTP	|\
+	VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_TCP	|\
+	VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_UDP	|\
+	VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_SCTP)
+
+#define IECM_CAP_SCTP_CSUM (\
+	VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_SCTP	|\
+	VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_SCTP	|\
+	VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_SCTP	|\
+	VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_SCTP)
+
+/**
+ * iecm_get_reserved_vecs - Get reserved vectors
+ * @adapter: private data struct
+ */
+static inline u16 iecm_get_reserved_vecs(struct iecm_adapter
+*adapter) {
+	return adapter->dev_ops.vc_ops.get_reserved_vecs(adapter);
+}
+
 /**
  * iecm_is_reset_detected - check if we were reset at some point
  * @adapter: driver specific private structure @@ -555,6 +642,20 @@

static inline bool iecm_is_reset_detected(struct iecm_adapter *adapter)

drivers/net/ethernet/intel/include/iecm.h +12 -0
 		 adapter->hw.arq->reg.len_ena_mask);
 }
 
+/**
+ * iecm_is_reset_in_prog - check if reset is in progress
+ * @adapter: driver specific private structure
+ *
+ * Returns true if hard reset is in progress, false otherwise  */
+static inline bool iecm_is_reset_in_prog(struct iecm_adapter
+*adapter) {
+	return (test_bit(__IECM_HR_RESET_IN_PROG, adapter->flags) ||
+		test_bit(__IECM_HR_FUNC_RESET, adapter->flags) ||
+		test_bit(__IECM_HR_CORE_RESET, adapter->flags) ||
+		test_bit(__IECM_HR_DRV_LOAD, adapter->flags)); }
+
 int iecm_probe(struct pci_dev *pdev,
 	       const struct pci_device_id __always_unused *ent,
 	       struct iecm_adapter *adapter); @@ -576,6 +677,7 @@ int

iecm_send_get_caps_msg(struct iecm_adapter *adapter); int iecm_send_delete_queues_msg(struct iecm_vport *vport); int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,

drivers/net/ethernet/intel/include/iecm.h +1 -0
 			     u16 num_complq, u16 num_rx_q, u16 num_rx_bufq);
+int iecm_send_vlan_v2_caps_msg(struct iecm_adapter *adapter);
 int iecm_send_config_tx_queues_msg(struct iecm_vport *vport);  int

iecm_send_config_rx_queues_msg(struct iecm_vport *vport); int iecm_send_enable_vport_msg(struct iecm_vport *vport); @@ -589,6 +691,7 @@ int iecm_send_dealloc_vectors_msg(struct iecm_adapter *adapter); int iecm_send_alloc_vectors_msg(struct iecm_adapter *adapter, u16 num_vectors); int iecm_vport_params_buf_alloc(struct iecm_adapter *adapter); void iecm_vport_params_buf_rel(struct iecm_adapter *adapter);
+struct iecm_vport *iecm_netdev_to_vport(struct net_device *netdev);
int iecm_send_get_stats_msg(struct iecm_vport *vport); int
iecm_get_vec_ids(struct iecm_adapter *adapter,

drivers/net/ethernet/intel/include/iecm.h +0 -0
 		     u16 *vecids, int num_vecids,

drivers/net/ethernet/intel/include/iecm.h int iecm_recv_mb_msg(struct iecm_adapter *adapter, · line 701

Quoted 1 line
drivers/net/ethernet/intel/include/iecm.h +0 -0
@@ -598,6 +701,7 @@ int iecm_recv_mb_msg(struct iecm_adapter *adapter,
 enum virtchnl_ops op,  int iecm_send_mb_msg(struct iecm_adapter *adapter,

enum virtchnl_ops op,

drivers/net/ethernet/intel/include/iecm_txrx.h void iecm_vport_calc_total_qs(struct iecm_adapter

Quoted 13 lines
drivers/net/ethernet/intel/include/iecm.h +2 -0
 		     u16 msg_size, u8 *msg);
 void iecm_vport_set_hsplit(struct iecm_vport *vport, bool ena);
+void iecm_add_del_ether_addrs(struct iecm_vport *vport, bool add,
+bool async);
 int iecm_send_enable_channels_msg(struct iecm_vport *vport);  int

iecm_send_disable_channels_msg(struct iecm_vport *vport); bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature); diff --git a/drivers/net/ethernet/intel/include/iecm_txrx.h b/drivers/net/ethernet/intel/include/iecm_txrx.h
index 9f3086bfe575..0aa1eac70e7c 100644

drivers/net/ethernet/intel/include/iecm_txrx.h +0 -0
@@ -512,4 +512,6 @@ void iecm_vport_calc_total_qs(struct iecm_adapter

*adapter,

Quoted 8 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +0 -0
 			      struct virtchnl2_create_vport *vport_msg);  void

iecm_vport_calc_num_q_groups(struct iecm_vport *vport); void iecm_vport_calc_num_q_vec(struct iecm_vport *vport);

drivers/net/ethernet/intel/include/iecm_txrx.h +2 -1
+irqreturn_t
+iecm_vport_intr_clean_queues(int __always_unused irq, void *data);
 #endif /* !_IECM_TXRX_H_ */
--

2.33.0

Thanks,
Al

#39 lore raw

PATCH 8/19 iecm: add interrupts and configure netdev

From: Alan Brady <[email protected]>
Date: Thu, 3 Feb 2022 00:17:37 +0100

Quoted 17 lines
Quoted 17 lines

-----Original Message-----
From: Lobakin, Alexandr <[email protected]>
Sent: Friday, January 28, 2022 5:35 AM
To: Brady, Alan <[email protected]>
Cc: Lobakin, Alexandr <[email protected]>; intel-wired- lan at lists.osuosl.org; Linga, Pavan Kumar <[email protected]>; Chittim, Madhu <[email protected]>; Burra, Phani R <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net-next 08/19] iecm: add interrupts and configure netdev

From: Alan Brady <[email protected]>
Date: Thu, 27 Jan 2022 16:09:58 -0800

Quoted 3 lines

This finishes implementing init_task by adding everything we need to configure the netdevice for the vport and setup its interrupts.

Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
Quoted 8 lines
Quoted 8 lines
---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    | 813 +++++++++++++++++-
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   |  17 +
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   | 165 ++++
 drivers/net/ethernet/intel/include/iecm.h     | 112 ++-
 .../net/ethernet/intel/include/iecm_txrx.h    |   2 +
 5 files changed, 1104 insertions(+), 5 deletions(-)

--- 8< ---

Quoted 27 lines
Quoted 17 lines
Quoted 17 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +17 -0
+/**
+ * iecm_find_mac_filter - Search filter list for specific mac filter
+ * @vport: main vport structure
+ * @macaddr: the MAC address
+ *
+ * Returns ptr to the filter object or NULL. Must be called while
+holding the
+ * mac_filter_list_lock.
+ **/
+static struct
+iecm_mac_filter *iecm_find_mac_filter(struct iecm_vport *vport,
+				      const u8 *macaddr)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_mac_filter *f;
+
+	if (!macaddr)
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature) · line 416

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +6 -0
+		return NULL;
+
+	list_for_each_entry(f, &adapter->config_data.mac_filter_list, list) {
+		if (ether_addr_equal(macaddr, f->macaddr))
+			return f;
+	}

Excessive braces again.

Quoted 1 line

Will not fix.

I'd like to remind here that it's a technical discussion in a public list, and every participant should keep it sane, with sane arguments and reasoning.

My arguments are:
* it adds chars and locs for no reason;
* it adds code complexity -> lowers readability a tiny bit;
* checkpatch and/or cocchinelle may complain on this.

I'd double-check the last bullet at first. If it's the case, there's no other choice except for deleting them. Otherwise I'd like to hear reasoning for keeping those braces and some other folks' opinions as well.

Quoted 6 lines
Quoted 6 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature) · line 421

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +5 -0
+	return NULL;
+}
+
+/**
+ * __iecm_add_mac_filter - Add mac filter helper function

--- 8< ---

Quoted 11 lines
Quoted 10 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature) · line 614

Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +7 -0
+		dflt_features |= NETIF_F_TSO6;
+	if (iecm_is_cap_ena_all(adapter, IECM_SEG_CAPS,
+				VIRTCHNL2_CAP_SEG_IPV4_UDP |
+				VIRTCHNL2_CAP_SEG_IPV6_UDP))
+		dflt_features |= NETIF_F_GSO_UDP_L4;
+	if (iecm_is_cap_ena_all(adapter, IECM_RSC_CAPS, IECM_CAP_RSC))
+		offloads |= NETIF_F_GRO_HW;

I see offloads being used only here, |= -> =.

Quoted 1 line

It makes it easier to add others in future or if some happen to get stripped in/out in the future it makes the code more resilient. We prefer to keep it this way.

Ah, again.
It's not that usual in the kernel to make some thing more complicated due to some kind of a hypothetical case in the future. That case may never happen, while code burden will still be there.

Also, a problem might occur *only* if someone places offloads modification before this sentence. If it gets deleted, if offloads gets modified later, assignment is still correct here. And it's a developer's duty then to check for this.

The last thing. Assignment is a pure single store. OR is load + store, 2 operations. Compilers *probably* optimize this on -O2, but that's up to them.
The function itself is cold, yet still this is avoidable.

Quoted 4 lines
Quoted 4 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature) · line 617

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +3 -0
+	netdev->features |= dflt_features;
+	netdev->hw_features |= dflt_features | offloads;
+	netdev->hw_enc_features |= dflt_features | offloads;

--- 8< ---

Quoted 12 lines
Quoted 11 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c void iecm_free_dma_mem(struct iecm_hw *hw, struct iecm_dma_mem *mem) · line 1410

Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +8 -0
+	.ndo_set_mac_address = NULL,
+	.ndo_change_mtu = NULL,
+	.ndo_get_stats64 = NULL,
+	.ndo_fix_features = NULL,
+	.ndo_set_features = NULL,
+	.ndo_vlan_rx_add_vid = NULL,
+	.ndo_vlan_rx_kill_vid = NULL,
+	.ndo_setup_tc = NULL,

Non-initialized members get zeroed by default, NULLing them is excessive.

Quoted 1 line

The next patches will add these, they're placeholders. I left it like that because as you read the patches you can know what functions are there yet (as well as a checklist for myself as made the patches).

As I wrote in one of my prevous replies, each patch is a self-contained/self-complete entity.
With those NULLs being present newly implemented callbacks will result in

.ndo_old_function_1 = iecm_old_function_1,
-.ndo_new_function_2 = NULL,
-.ndo_new_function_3 = NULL,
+.ndo_new_function_2 = iecm_new_function_2,
+.ndo_new_function_3 = iecm_new_function_3,
.ndo_old_function_4 = iecm_old_function_4,

instead of

.ndo_old_function_1 = iecm_old_function_1,
+.ndo_new_function_2 = iecm_new_function_2,
+.ndo_new_function_3 = iecm_new_function_3,
.ndo_old_function_4 = iecm_old_function_4,

This makes a lot of sense, at least to me.

Quoted 20 lines
Quoted 20 lines
Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +6 -0
+};
+
+static const struct net_device_ops iecm_netdev_ops_singleq = {
+	.ndo_open = NULL,
+	.ndo_stop = NULL,
+	.ndo_start_xmit = NULL,

drivers/net/ethernet/intel/iecm/iecm_lib.c void iecm_free_dma_mem(struct iecm_hw *hw, struct iecm_dma_mem *mem) · line 1426

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+	.ndo_set_rx_mode = NULL,
+	.ndo_validate_addr = eth_validate_addr,
+	.ndo_set_mac_address = NULL,
+	.ndo_change_mtu = NULL,
+	.ndo_get_stats64 = NULL,
+	.ndo_fix_features = NULL,
+	.ndo_set_features = NULL,
+	.ndo_vlan_rx_add_vid = NULL,
+	.ndo_vlan_rx_kill_vid = NULL,
+	.ndo_setup_tc           = NULL,

Same 2 previous points.

Quoted 4 lines
Quoted 4 lines

.ndo_setup_tc assignment indentation is weird. Either align all the initializers with tabs or don't align at all (both are valid cases).

Quoted 1 line

+};

--- 8< ---

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

--
2.33.0

Thanks,
Al

Thanks,
Al

author
#40 lore raw

PATCH 9/19 iecm: alloc vport TX resources

In reply to Alan Brady

With init_task out of the way, we can start implementing open and data path. During open we'll allocate queue resources for vport. This only includes what's needed to get the TX resources. The next patch will get RX resources.

The splitq model is unique in that it introduces the concept of "queue groups" where, for TX, we have some number of descriptor queues being serviced by one completion queue in a given group association. By 'splitting' a normal queue into two queues, one context is just handling descriptors and one context handling buffers, we can more effeciently deal with both and configure asymmetric setups (multiple descriptor queues to one completion queue).

---
 drivers/net/ethernet/intel/iecm/Makefile      |    1 +
 drivers/net/ethernet/intel/iecm/iecm_lib.c    |  369 ++++-
 .../ethernet/intel/iecm/iecm_singleq_txrx.c   |   29 +
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   | 1282 ++++++++++++++++-
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   |   29 +
 drivers/net/ethernet/intel/include/iecm.h     |   28 +
 .../ethernet/intel/include/iecm_lan_txrx.h    |  394 +++++
 .../net/ethernet/intel/include/iecm_txrx.h    |   96 ++
 8 files changed, 2214 insertions(+), 14 deletions(-)
 create mode 100644 drivers/net/ethernet/intel/iecm/iecm_singleq_txrx.c
 create mode 100644 drivers/net/ethernet/intel/include/iecm_lan_txrx.h
drivers/net/ethernet/intel/iecm/Makefile +1 -0
index fcb49402334f..205d6f2b436a 100644
@@ -14,6 +14,7 @@ iecm-y := \
 	iecm_lib.o \
 	iecm_virtchnl.o \
 	iecm_txrx.o \
+	iecm_singleq_txrx.o \
 	iecm_controlq.o \
 	iecm_controlq_setup.o \
 	iecm_main.o
drivers/net/ethernet/intel/iecm/iecm_lib.c +364 -5

444 lines not on this page · raw message

drivers/net/ethernet/intel/iecm/iecm_singleq_txrx.c new file +29 -0
new file mode 100644
index 000000000000..d6c47cb84249
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright (C) 2019 Intel Corporation */
+
+#include "iecm.h"
+
+/**
+ * iecm_rx_singleq_buf_hw_alloc_all - Replace used receive buffers
+ * @rx_q: queue for which the hw buffers are allocated
+ * @cleaned_count: number of buffers to replace
+ *
+ * Returns false if all allocations were successful, true if any fail
+ */
+bool iecm_rx_singleq_buf_hw_alloc_all(struct iecm_queue *rx_q,
+				      u16 cleaned_count)
+{
+	/* stub */
+	return true;
+}
+
+/**
+ * iecm_vport_singleq_napi_poll - NAPI handler
+ * @napi: struct from which you get q_vector
+ * @budget: budget provided by stack
+ */
+int iecm_vport_singleq_napi_poll(struct napi_struct *napi, int budget)
+{
+	/* stub */
+	return 0;
+}
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1273 -9

1,302 lines not on this page · raw message

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +29 -0
index b91716aeef6f..919fb3958cf8 100644
@@ -3745,6 +3745,35 @@ void iecm_add_del_ether_addrs(struct iecm_vport *vport, bool add, bool async)
 		dev_err(&pdev->dev, "Failed to add or del mac filters %d", err);
 }
 
+/**
+ * iecm_set_promiscuous - set promiscuous and send message to mailbox
+ * @adapter: Driver specific private structure
+ *
+ * Request that the PF enable promiscuous mode for our VSI.  Message is sent
+ * asynchronously and won't wait for response.  Returns 0 on success, negative
+ * on failure;
+ */
+int iecm_set_promiscuous(struct iecm_adapter *adapter)
+{
+	struct iecm_vport *vport = adapter->vports[0];
+	struct virtchnl_promisc_info vpi;
+	u16 flags = 0;
+	int err = 0;
+
+	if (test_bit(__IECM_PROMISC_UC, adapter->config_data.user_flags))
+		flags |= FLAG_VF_UNICAST_PROMISC;
+	if (test_bit(__IECM_PROMISC_MC,
+		     adapter->config_data.user_flags))
+		flags |= FLAG_VF_MULTICAST_PROMISC;
+
+	vpi.vsi_id = vport->vport_id;
+	vpi.flags = flags;
+	err = iecm_send_mb_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
+			       sizeof(struct virtchnl_promisc_info),
+			       (u8 *)&vpi);
+	return err;
+}
+
 /**
  * iecm_add_del_vlans - Add or delete vlan filter
  * @vport: vport structure
drivers/net/ethernet/intel/include/iecm.h +28 -0
index b5bd73be2855..4304256f7010 100644
@@ -13,6 +13,7 @@
 #include <linux/version.h>
 #include <linux/dim.h>
 
+#include "iecm_lan_txrx.h"
 #include "virtchnl_2.h"
 #include "iecm_txrx.h"
 #include "iecm_controlq.h"
@@ -621,6 +622,17 @@ enum iecm_vlan_caps {
 	VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_SCTP	|\
 	VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_SCTP)
 
+/**
+ * iecm_restore_features - Restore feature configs
+ * @adapter: driver specific private structure
+ * @flag: User settings flag to check
+ */
+static inline bool iecm_is_user_flag_ena(struct iecm_adapter *adapter,
+					 enum iecm_user_flags flag)
+{
+	return test_bit(flag, adapter->config_data.user_flags);
+}
+
 /**
  * iecm_get_reserved_vecs - Get reserved vectors
  * @adapter: private data struct
@@ -656,6 +668,19 @@ static inline bool iecm_is_reset_in_prog(struct iecm_adapter *adapter)
 		test_bit(__IECM_HR_DRV_LOAD, adapter->flags));
 }
 
+/**
+ * iecm_rx_offset - Return expected offset into page to access data
+ * @rx_q: queue we are requesting offset of
+ *
+ * Returns the offset value for queue into the data buffer.
+ */
+static inline unsigned int
+iecm_rx_offset(struct iecm_queue __maybe_unused *rx_q)
+{
+	/* could be non-zero if xdp is enabled */
+	return 0;
+}
+
 int iecm_probe(struct pci_dev *pdev,
 	       const struct pci_device_id __always_unused *ent,
 	       struct iecm_adapter *adapter);
@@ -702,6 +727,7 @@ int iecm_send_mb_msg(struct iecm_adapter *adapter, enum virtchnl_ops op,
 		     u16 msg_size, u8 *msg);
 void iecm_vport_set_hsplit(struct iecm_vport *vport, bool ena);
 void iecm_add_del_ether_addrs(struct iecm_vport *vport, bool add, bool async);
+int iecm_set_promiscuous(struct iecm_adapter *adapter);
 int iecm_send_enable_channels_msg(struct iecm_vport *vport);
 int iecm_send_disable_channels_msg(struct iecm_vport *vport);
 bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature);
@@ -710,5 +736,7 @@ int iecm_check_descs(struct iecm_vport *vport, u64 rx_desc_ids,
 int iecm_set_msg_pending(struct iecm_adapter *adapter,
 			 struct iecm_ctlq_msg *ctlq_msg,
 			 enum iecm_vport_vc_state err_enum);
+void iecm_vport_intr_write_itr(struct iecm_q_vector *q_vector,
+			       u16 itr, bool tx);
 int iecm_send_map_unmap_queue_vector_msg(struct iecm_vport *vport, bool map);
 #endif /* !_IECM_H_ */
drivers/net/ethernet/intel/include/iecm_lan_txrx.h new file +394 -0

394 lines not on this page · raw message

drivers/net/ethernet/intel/include/iecm_txrx.h +96 -0

129 lines not on this page · raw message

Signature · 1 line
2.33.0