Skip to contentSkip to conversation

Add iecm and idpf

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

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

PATCH 9/19 iecm: alloc vport TX resources

In reply to Alan Brady
Quoted 79 lines

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

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

Quoted 31 lines

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

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/iecm/Makefile

Review

Quoted 12 lines

index fcb49402334f..205d6f2b436a 100644

drivers/net/ethernet/intel/iecm/Makefile +1 -0
@@ -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
(quoted diff) +0 -0

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

drivers/net/ethernet/intel/iecm/iecm_lib.c static struct iecm_mac_filter

Quoted 4 lines

index 255b04c25683..037a0e06bb7b 100644

drivers/net/ethernet/intel/iecm/iecm_lib.c +0 -0
@@ -480,6 +480,54 @@ static struct iecm_mac_filter

*iecm_add_mac_filter(struct iecm_vport *vport,

Quoted 14 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +11 -0
 	return f;
 }
 
+/**
+ * iecm_set_all_filters - Re-add all MAC filters in list
+ * @vport: main vport struct
+ *
+ * Takes mac_filter_list_lock spinlock.  Sets add field to true for filters to
+ * resync filters back to HW.
+ */
+static void iecm_set_all_filters(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_mac_filter *f;
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c static struct iecm_mac_filter *iecm_add_mac_filter(struct iecm_vport *vport, · line 499

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +6 -0
+
+	spin_lock_bh(&adapter->mac_filter_list_lock);
+	list_for_each_entry(f, &adapter->config_data.mac_filter_list, list) {
+		if (!f->remove)
+			f->add = true;
+	}

Redundant braces around a single statement.

Will not fix.

Quoted 439 lines
Quoted 12 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +12 -0
+	spin_unlock_bh(&adapter->mac_filter_list_lock);
+
+	iecm_add_del_ether_addrs(vport, true, false);
+}
+
+/**
+ * iecm_set_all_vlans - Re-add all VLANs in list
+ * @vport: main vport struct
+ *
+ * Takes vlan_list_lock spinlock.  Sets add field to true for vlan filters and
+ * resyncs vlans back to HW.
+ */

drivers/net/ethernet/intel/iecm/iecm_lib.c static struct iecm_mac_filter *iecm_add_mac_filter(struct iecm_vport *vport, · line 521

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+static void iecm_set_all_vlans(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_vlan_filter *f;
+
+	spin_lock_bh(&adapter->vlan_list_lock);
+	list_for_each_entry(f, &adapter->config_data.vlan_filter_list, list) {
+		if (!f->remove)
+			f->add = true;
+	}

Same.

drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_get_free_slot(void *array, int size, int

Quoted 13 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +9 -0
+	spin_unlock_bh(&adapter->vlan_list_lock);
+
+	/* Do both add and remove to make sure list is in sync in the case
+	 * filters were added and removed before up.
+	 */
+	adapter->dev_ops.vc_ops.add_del_vlans(vport, false);
+	adapter->dev_ops.vc_ops.add_del_vlans(vport, true);
+}
+
 /**
  * iecm_init_mac_addr - initialize mac address for vport
  * @vport: main vport structure
@@ -690,6 +738,63 @@ static int iecm_get_free_slot(void *array, int size, int

curr)

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_decfg_netdev(struct iecm_vport

Quoted 64 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +57 -0
 	return next;
 }
 
+/**
+ * iecm_vport_stop - Disable a vport
+ * @vport: vport to disable
+ */
+static void iecm_vport_stop(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+
+	mutex_lock(&vport->stop_mutex);
+	if (adapter->state <= __IECM_DOWN)
+		goto stop_unlock;
+
+	netif_tx_stop_all_queues(vport->netdev);
+	netif_carrier_off(vport->netdev);
+	netif_tx_disable(vport->netdev);
+
+	if (adapter->dev_ops.vc_ops.disable_vport)
+		adapter->dev_ops.vc_ops.disable_vport(vport);
+	adapter->dev_ops.vc_ops.disable_queues(vport);
+	adapter->dev_ops.vc_ops.irq_map_unmap(vport, false);
+	/* Normally we ask for queues in create_vport, but if we're changing
+	 * number of requested queues we do a delete then add instead of
+	 * deleting and reallocating the vport.
+	 */
+	if (test_and_clear_bit(__IECM_DEL_QUEUES,
+			       vport->adapter->flags))
+		iecm_send_delete_queues_msg(vport);
+
+	adapter->link_up = false;
+	iecm_vport_intr_deinit(vport);
+	iecm_vport_intr_rel(vport);
+	iecm_vport_queues_rel(vport);
+	adapter->state = __IECM_DOWN;
+
+stop_unlock:
+	mutex_unlock(&vport->stop_mutex);
+}
+
+/**
+ * iecm_stop - Disables a network interface
+ * @netdev: network interface device structure
+ *
+ * The stop entry point is called when an interface is de-activated by the OS,
+ * and the netdevice enters the DOWN state.  The hardware is still under the
+ * driver's control, but the netdev interface is disabled.
+ *
+ * Returns success only - not allowed to fail
+ */
+static int iecm_stop(struct net_device *netdev)
+{
+	struct iecm_netdev_priv *np = netdev_priv(netdev);
+
+	iecm_vport_stop(np->vport);
+
+	return 0;
+}
+
 /**
  * iecm_decfg_netdev - Unregister the netdev
  * @vport: vport for which netdev to be unregistred
@@ -714,6 +819,11 @@ static void iecm_decfg_netdev(struct iecm_vport

*vport)

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_vport_rel_all(struct iecm_adapter

Quoted 12 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +5 -0
  */
 static void iecm_vport_rel(struct iecm_vport *vport)
 {
+	struct iecm_adapter *adapter = vport->adapter;
+
+	iecm_deinit_rss(vport);
+	if (adapter->dev_ops.vc_ops.destroy_vport)
+		adapter->dev_ops.vc_ops.destroy_vport(vport);
 	mutex_destroy(&vport->stop_mutex);
 	kfree(vport);
 }
@@ -733,6 +843,7 @@ 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 8 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +1 -0
 		if (!adapter->vports[i])
 			continue;
 
+		iecm_vport_stop(adapter->vports[i]);
 		if (!test_bit(__IECM_HR_RESET_IN_PROG, adapter->flags))
 			iecm_decfg_netdev(adapter->vports[i]);
 		iecm_vport_rel(adapter->vports[i]);
@@ -782,6 +893,7 @@ iecm_vport_alloc(struct iecm_adapter *adapter, int

vport_id)

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_service_task(struct work_struct

Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +1 -0
 	vport->idx = adapter->next_vport;
 	vport->compln_clean_budget = IECM_TX_COMPLQ_CLEAN_BUDGET;
 	adapter->num_alloc_vport++;
+	adapter->dev_ops.vc_ops.vport_init(vport, vport_id);
 
 	/* Setup default MSIX irq handler for the vport */
 	vport->irq_q_handler = iecm_vport_intr_clean_queues;
@@ -845,6 +957,117 @@ static void iecm_service_task(struct work_struct

*work)

Quoted 12 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +9 -0
 			   msecs_to_jiffies(300));
 }
 
+/**
+ * iecm_restore_vlans - Restore vlan filters/vlan stripping/insert config
+ * @vport: virtual port structure
+ */
+static void iecm_restore_vlans(struct iecm_vport *vport)
+{
+	if (iecm_is_feature_ena(vport, NETIF_F_HW_VLAN_CTAG_FILTER))
+		iecm_set_all_vlans(vport);
+}

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_service_task(struct work_struct *work)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+
+/**
+ * iecm_restore_features - Restore feature configs
+ * @vport: virtual port structure
+ */
+static void iecm_restore_features(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+
+	if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS,

VIRTCHNL2_CAP_MACFILTER))

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_service_task(struct work_struct *work)

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +3 -0
+		iecm_set_all_filters(vport);
+
+	if (iecm_is_cap_ena(adapter, IECM_BASE_CAPS,

VIRTCHNL2_CAP_VLAN) ||

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_service_task(struct work_struct · line 982

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_lib.c +1 -0
+	    iecm_is_cap_ena(adapter, IECM_OTHER_CAPS,

VIRTCHNL2_CAP_VLAN))

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_service_task(struct work_struct *work)

Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +7 -0
+		iecm_restore_vlans(vport);
+
+	if ((iecm_is_user_flag_ena(adapter, __IECM_PROMISC_UC) ||
+	     iecm_is_user_flag_ena(adapter, __IECM_PROMISC_MC)) &&
+	    test_and_clear_bit(__IECM_VPORT_INIT_PROMISC, vport->flags)) {
+		if (iecm_set_promiscuous(adapter))
+			dev_info(&adapter->pdev->dev, "Failed to restore

promiscuous settings\n");

drivers/net/ethernet/intel/iecm/iecm_lib.c iecm_set_vlan_offload_features(struct net_device

Quoted 85 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +81 -0
+	}
+}
+
+/**
+ * iecm_set_real_num_queues - set number of queues for netdev
+ * @vport: virtual port structure
+ *
+ * Returns 0 on success, negative on failure.
+ */
+static int iecm_set_real_num_queues(struct iecm_vport *vport)
+{
+	int err;
+
+	/* If we're in normal up path, the stack already takes the rtnl_lock
+	 * for us, however, if we're doing up as a part of a hard reset, we'll
+	 * need to take the lock ourself before touching the netdev.
+	 */
+	if (test_bit(__IECM_HR_RESET_IN_PROG, vport->adapter->flags))
+		rtnl_lock();
+	err = netif_set_real_num_rx_queues(vport->netdev, vport->num_rxq);
+	if (err)
+		goto error;
+	err = netif_set_real_num_tx_queues(vport->netdev, vport->num_txq);
+error:
+	if (test_bit(__IECM_HR_RESET_IN_PROG, vport->adapter->flags))
+		rtnl_unlock();
+	return err;
+}
+
+/**
+ * iecm_up_complete - Complete interface up sequence
+ * @vport: virtual port strucutre
+ *
+ * Returns 0 on success, negative on failure.
+ */
+static int iecm_up_complete(struct iecm_vport *vport)
+{
+	int err;
+
+	err = iecm_set_real_num_queues(vport);
+	if (err)
+		return err;
+
+	if (vport->adapter->link_up && !netif_carrier_ok(vport->netdev)) {
+		netif_carrier_on(vport->netdev);
+		netif_tx_start_all_queues(vport->netdev);
+	}
+
+	vport->adapter->state = __IECM_UP;
+	return 0;
+}
+
+/**
+ * iecm_rx_init_buf_tail - Write initial buffer ring tail value
+ * @vport: virtual port struct
+ */
+static void iecm_rx_init_buf_tail(struct iecm_vport *vport)
+{
+	int i, j;
+
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		struct iecm_rxq_group *grp = &vport->rxq_grps[i];
+
+		if (iecm_is_queue_model_split(vport->rxq_model)) {
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++) {
+				struct iecm_queue *q =
+					&grp->splitq.bufq_sets[j].bufq;
+
+				writel(q->next_to_alloc, q->tail);
+			}
+		} else {
+			for (j = 0; j < grp->singleq.num_rxq; j++) {
+				struct iecm_queue *q =
+					grp->singleq.rxqs[j];
+
+				writel(q->next_to_alloc, q->tail);
+			}
+		}
+	}
+}
+
 /* iecm_set_vlan_offload_features - set vlan offload features
  * @netdev: netdev structure
  * @prev_features: previously set features
@@ -903,8 +1126,110 @@ iecm_set_vlan_offload_features(struct net_device

*netdev,

Quoted 12 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +8 -1
  */
 static int iecm_vport_open(struct iecm_vport *vport, bool alloc_res)
 {
-	/* stub */
+	struct iecm_adapter *adapter = vport->adapter;
+	int err;
+
+	if (vport->adapter->state != __IECM_DOWN)
+		return -EBUSY;
+
+	/* we do not allow interface up just yet */
+	netif_carrier_off(vport->netdev);

drivers/net/ethernet/intel/iecm/iecm_lib.c iecm_set_vlan_offload_features(struct net_device *netdev,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+
+	if (alloc_res) {
+		err = iecm_vport_queues_alloc(vport);
+		if (err)
+			return err;
+	}
+
+	err = iecm_vport_intr_alloc(vport);
+	if (err) {
+		dev_err(&adapter->pdev->dev, "Call to interrupt alloc returned

%d\n",

drivers/net/ethernet/intel/iecm/iecm_lib.c iecm_set_vlan_offload_features(struct net_device *netdev,

Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +7 -0
+			err);
+		goto unroll_queues_alloc;
+	}
+
+	err = adapter->dev_ops.vc_ops.vport_queue_ids_init(vport);
+	if (err) {
+		dev_err(&adapter->pdev->dev, "Call to queue ids init returned

%d\n",

drivers/net/ethernet/intel/iecm/iecm_lib.c iecm_set_vlan_offload_features(struct net_device *netdev,

Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +7 -0
+			err);
+		goto unroll_intr_alloc;
+	}
+
+	err = adapter->dev_ops.vc_ops.vportq_reg_init(vport);
+	if (err) {
+		dev_err(&adapter->pdev->dev, "Call to queue reg init returned

%d\n",

drivers/net/ethernet/intel/iecm/iecm_lib.c iecm_set_vlan_offload_features(struct net_device *netdev,

Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +8 -0
+			err);
+		goto unroll_intr_alloc;
+	}
+	iecm_rx_init_buf_tail(vport);
+
+	err = iecm_vport_intr_init(vport);
+	if (err) {
+		dev_err(&adapter->pdev->dev, "Call to vport interrupt init

returned %d\n",

drivers/net/ethernet/intel/iecm/iecm_lib.c iecm_set_vlan_offload_features(struct net_device *netdev,

Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +11 -0
+			err);
+		goto unroll_intr_alloc;
+	}
+	err = adapter->dev_ops.vc_ops.config_queues(vport);
+	if (err) {
+		dev_err(&adapter->pdev->dev, "Failed to config queues\n");
+		goto unroll_config_queues;
+	}
+	err = adapter->dev_ops.vc_ops.irq_map_unmap(vport, true);
+	if (err) {
+		dev_err(&adapter->pdev->dev, "Call to irq_map_unmap

returned %d\n",

drivers/net/ethernet/intel/iecm/iecm_lib.c iecm_set_vlan_offload_features(struct net_device *netdev,

Quoted 13 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +13 -0
+			err);
+		goto unroll_config_queues;
+	}
+	err = adapter->dev_ops.vc_ops.enable_queues(vport);
+	if (err) {
+		dev_err(&adapter->pdev->dev, "Failed to enable queues\n");
+		goto unroll_enable_queues;
+	}
+
+	if (adapter->dev_ops.vc_ops.enable_vport) {
+		err = adapter->dev_ops.vc_ops.enable_vport(vport);
+		if (err) {
+			dev_err(&adapter->pdev->dev, "Failed to enable

vport\n");

drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_api_init(struct iecm_adapter

Quoted 44 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +39 -0
+			err = -EAGAIN;
+			goto unroll_vport_enable;
+		}
+	}
+
+	iecm_restore_features(vport);
+
+	if (adapter->rss_data.rss_lut)
+		err = iecm_config_rss(vport);
+	else
+		err = iecm_init_rss(vport);
+	if (err) {
+		dev_err(&adapter->pdev->dev, "Failed to init RSS\n");
+		goto unroll_init_rss;
+	}
+	err = iecm_up_complete(vport);
+	if (err) {
+		dev_err(&adapter->pdev->dev, "Failed to complete up\n");
+		goto unroll_up_comp;
+	}
+
 	return 0;
+
+unroll_up_comp:
+	iecm_deinit_rss(vport);
+unroll_init_rss:
+	adapter->dev_ops.vc_ops.disable_vport(vport);
+unroll_vport_enable:
+	adapter->dev_ops.vc_ops.disable_queues(vport);
+unroll_enable_queues:
+	adapter->dev_ops.vc_ops.irq_map_unmap(vport, false);
+unroll_config_queues:
+	iecm_vport_intr_deinit(vport);
+unroll_intr_alloc:
+	iecm_vport_intr_rel(vport);
+unroll_queues_alloc:
+	if (alloc_res)
+		iecm_vport_queues_rel(vport);
+
+	return err;
 }
 
 /**
@@ -1060,6 +1385,8 @@ static int iecm_api_init(struct iecm_adapter

*adapter)

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_deinit_task(struct iecm_adapter

Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +2 -0
  */
 static void iecm_deinit_task(struct iecm_adapter *adapter)
 {
+	int i;
+
 	set_bit(__IECM_REL_RES_IN_PROG, adapter->flags);
 	/* Wait until the init_task is done else this thread might release
 	 * the resources first and the other thread might end up in a bad state
@@ -1067,8 +1394,21 @@ static void iecm_deinit_task(struct iecm_adapter

*adapter)

Quoted 35 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +23 -0
 	cancel_delayed_work_sync(&adapter->init_task);
 	iecm_vport_rel_all(adapter);
 
+	/* Set all bits as we dont know on which vc_state the vhnl_wq is
+	 * waiting on and wakeup the virtchnl workqueue even if it is waiting
+	 * for the response as we are going down
+	 */
+	for (i = 0; i < IECM_VC_NBITS; i++)
+		set_bit(i, adapter->vc_state);
+	wake_up(&adapter->vchnl_wq);
+
 	cancel_delayed_work_sync(&adapter->serv_task);
 	cancel_delayed_work_sync(&adapter->stats_task);
+	iecm_intr_rel(adapter);
+	/* Clear all the bits */
+	for (i = 0; i < IECM_VC_NBITS; i++)
+		clear_bit(i, adapter->vc_state);
+	clear_bit(__IECM_REL_RES_IN_PROG, adapter->flags);
 }
 
 /**
@@ -1371,6 +1711,25 @@ void iecm_remove(struct pci_dev *pdev)
 }
 EXPORT_SYMBOL(iecm_remove);
 
+/**
+ * iecm_open - Called when a network interface becomes active
+ * @netdev: network interface device structure
+ *
+ * The open entry point is called when a network interface is made
+ * active by the system (IFF_UP).  At this point all resources needed
+ * for transmit and receive operations are allocated, the interrupt
+ * handler is registered with the OS, the netdev watchdog is enabled,
+ * and the stack is notified that the interface is ready.
+ *

drivers/net/ethernet/intel/iecm/iecm_lib.c void iecm_remove(struct pci_dev *pdev) · line 1733

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +9 -0
+ * Returns 0 on success, negative value on failure
+ */
+static int iecm_open(struct net_device *netdev)
+{
+	struct iecm_netdev_priv *np = netdev_priv(netdev);
+
+	return iecm_vport_open(np->vport, true);
+}
+
 void *iecm_alloc_dma_mem(struct iecm_hw *hw, struct iecm_dma_mem

*mem, u64 size)

drivers/net/ethernet/intel/iecm/iecm_lib.c void iecm_free_dma_mem(struct iecm_hw *hw,

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +0 -0
 {
 	struct iecm_adapter *adapter = (struct iecm_adapter *)hw->back;
@@ -1395,8 +1754,8 @@ void iecm_free_dma_mem(struct iecm_hw *hw,

struct iecm_dma_mem *mem)

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

drivers/net/ethernet/intel/iecm/iecm_lib.c void iecm_free_dma_mem(struct iecm_hw *hw, struct iecm_dma_mem *mem) · line 1759

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +2 -2
 static const struct net_device_ops iecm_netdev_ops_splitq = {
-	.ndo_open = NULL,
-	.ndo_stop = NULL,
+	.ndo_open = iecm_open,
+	.ndo_stop = iecm_stop,
 	.ndo_start_xmit = NULL,

Hmm, forgot to mention this earlier as well. Consider marking CONFIG_IECM as depends on BROKEN in Kconfig and remove this line in the last commit. Otherwise, it will be possible to panic the kernel as at least .ndo_start_xmit should always be set, kernel doesn't check for it being non-NULL, it just calls it. Same with open, stop and probably more, so it's a good practice to disable drivers with depending on BROKEN until it receives the workable state.

I don't have the full history on 'BROKEN' being a dependency but it seems silly to me to add some thrash just for that. Will consider.

Quoted 121 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c static const struct net_device_ops

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +0 -0
 	.ndo_set_rx_mode = NULL,
 	.ndo_validate_addr = eth_validate_addr,
@@ -1411,8 +1770,8 @@ static const struct net_device_ops

iecm_netdev_ops_splitq = {

Review

Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +2 -2
 };
 
 static const struct net_device_ops iecm_netdev_ops_singleq = {
-	.ndo_open = NULL,
-	.ndo_stop = NULL,
+	.ndo_open = iecm_open,
+	.ndo_stop = iecm_stop,
 	.ndo_start_xmit = NULL,
 	.ndo_set_rx_mode = NULL,
 	.ndo_validate_addr = eth_validate_addr,
(quoted diff) +0 -0

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

Review

Quoted 35 lines

new file mode 100644
index 000000000000..d6c47cb84249

drivers/net/ethernet/intel/iecm/iecm_singleq_txrx.c new file +29 -0
@@ -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;
+}
(quoted diff) +0 -0

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

drivers/net/ethernet/intel/iecm/iecm_txrx.c const struct iecm_rx_ptype_decoded

Quoted 4 lines

index bb7f5830cffb..85e88a30370d 100644

drivers/net/ethernet/intel/iecm/iecm_txrx.c +0 -0
@@ -219,20 +219,318 @@ const struct iecm_rx_ptype_decoded

iecm_ptype_lookup[IECM_RX_MAX_PTYPE] = {

Quoted 48 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +42 -3
 EXPORT_SYMBOL(iecm_ptype_lookup);
 
 /**
- * iecm_vport_intr_clean_queues - MSIX mode Interrupt Handler
- * @irq: interrupt number
- * @data: pointer to a q_vector
+ * iecm_tx_buf_rel - Release a Tx buffer
+ * @tx_q: the queue that owns the buffer
+ * @tx_buf: the buffer to free
+ */
+void iecm_tx_buf_rel(struct iecm_queue *tx_q, struct iecm_tx_buf *tx_buf)
+{
+	if (tx_buf->skb) {
+		if (dma_unmap_len(tx_buf, len))
+			dma_unmap_single(tx_q->dev,
+					 dma_unmap_addr(tx_buf, dma),
+					 dma_unmap_len(tx_buf, len),
+					 DMA_TO_DEVICE);
+		dev_kfree_skb_any(tx_buf->skb);
+	} else if (dma_unmap_len(tx_buf, len)) {
+		dma_unmap_page(tx_q->dev,
+			       dma_unmap_addr(tx_buf, dma),
+			       dma_unmap_len(tx_buf, len),
+			       DMA_TO_DEVICE);
+	}
+
+	tx_buf->next_to_watch = NULL;
+	tx_buf->skb = NULL;
+	dma_unmap_len_set(tx_buf, len, 0);
+}
+
+/**
+ * iecm_tx_buf_rel_all - Free any empty Tx buffers
+ * @txq: queue to be cleaned
+ */
+static void iecm_tx_buf_rel_all(struct iecm_queue *txq)
+{
+	u16 i;
+
+	/* Buffers already cleared, nothing to do */
+	if (!txq->tx_buf)
+		return;
+
+	/* Free all the Tx buffer sk_buffs */
+	for (i = 0; i < txq->desc_count; i++)
+		iecm_tx_buf_rel(txq, &txq->tx_buf[i]);
+
+	kfree(txq->tx_buf);

drivers/net/ethernet/intel/iecm/iecm_txrx.c const struct iecm_rx_ptype_decoded iecm_ptype_lookup[IECM_RX_MAX_PTYPE] = { · line 273

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+	txq->tx_buf = NULL;
+
+	if (txq->buf_stack.bufs) {
+		for (i = 0; i < txq->buf_stack.size; i++) {
+			iecm_tx_buf_rel(txq, txq->buf_stack.bufs[i]);
+			kfree(txq->buf_stack.bufs[i]);
+		}
+		kfree(txq->buf_stack.bufs);
+		txq->buf_stack.bufs = NULL;
+	}
	if (!txq->buf.stack.bufs)
		return;

	for (...
Quoted 2 lines

-1 indent level.

Will fix.

Quoted 21 lines
Quoted 21 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +13 -3
+}
+
+/**
+ * iecm_tx_desc_rel - Free Tx resources per queue
+ * @txq: Tx descriptor ring for a specific queue
+ * @bufq: buffer q or completion q
  *
+ * Free all transmit software resources
  */
-irqreturn_t
-iecm_vport_intr_clean_queues(int __always_unused irq, void *data)
+static void iecm_tx_desc_rel(struct iecm_queue *txq, bool bufq)
 {
-	struct iecm_q_vector *q_vector = (struct iecm_q_vector *)data;
+	if (bufq) {
+		iecm_tx_buf_rel_all(txq);
+		netdev_tx_reset_queue(netdev_get_tx_queue(txq->vport-
 netdev,
+							  txq->idx));
+	}
 
Quoted 13 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c const struct iecm_rx_ptype_decoded iecm_ptype_lookup[IECM_RX_MAX_PTYPE] = { · line 298

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +8 -2
-	q_vector->total_events++;
-	napi_schedule(&q_vector->napi);
+	if (txq->desc_ring) {
+		dmam_free_coherent(txq->dev, txq->size,
+				   txq->desc_ring, txq->dma);
+		txq->desc_ring = NULL;
+		txq->next_to_alloc = 0;
+		txq->next_to_use = 0;
+		txq->next_to_clean = 0;
+	}
	Same here, !desc_ring -> return immediately.

Will fix

Quoted 178 lines
Quoted 87 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +84 -1
+}
 
-	return IRQ_HANDLED;
+/**
+ * iecm_tx_desc_rel_all - Free Tx Resources for All Queues
+ * @vport: virtual port structure
+ *
+ * Free all transmit software resources
+ */
+static void iecm_tx_desc_rel_all(struct iecm_vport *vport)
+{
+	int i, j;
+
+	if (!vport->txq_grps)
+		return;
+
+	for (i = 0; i < vport->num_txq_grp; i++) {
+		struct iecm_txq_group *txq_grp = &vport->txq_grps[i];
+
+		for (j = 0; j < txq_grp->num_txq; j++)
+			iecm_tx_desc_rel(txq_grp->txqs[j], true);
+		if (iecm_is_queue_model_split(vport->txq_model))
+			iecm_tx_desc_rel(txq_grp->complq, false);
+	}
+}
+
+/**
+ * iecm_tx_buf_alloc_all - Allocate memory for all buffer resources
+ * @tx_q: queue for which the buffers are allocated
+ *
+ * Returns 0 on success, negative on failure
+ */
+static int iecm_tx_buf_alloc_all(struct iecm_queue *tx_q)
+{
+	int buf_size;
+	int i = 0;
+
+	/* Allocate book keeping buffers only. Buffers to be supplied to HW
+	 * are allocated by kernel network stack and received as part of skb
+	 */
+	buf_size = sizeof(struct iecm_tx_buf) * tx_q->desc_count;
+	tx_q->tx_buf = kzalloc(buf_size, GFP_KERNEL);
+	if (!tx_q->tx_buf)
+		return -ENOMEM;
+
+	/* Initialize tx buf stack for out-of-order completions if
+	 * flow scheduling offload is enabled
+	 */
+	tx_q->buf_stack.bufs =
+		kcalloc(tx_q->desc_count, sizeof(struct iecm_tx_buf *),
+			GFP_KERNEL);
+	if (!tx_q->buf_stack.bufs)
+		return -ENOMEM;
+
+	tx_q->buf_stack.size = tx_q->desc_count;
+	tx_q->buf_stack.top = tx_q->desc_count;
+
+	for (i = 0; i < tx_q->desc_count; i++) {
+		tx_q->buf_stack.bufs[i] = kzalloc(sizeof(*tx_q-
 buf_stack.bufs[i]),
+						  GFP_KERNEL);
+		if (!tx_q->buf_stack.bufs[i])
+			return -ENOMEM;
+	}
+
+	return 0;
+}
+
+/**
+ * iecm_tx_desc_alloc - Allocate the Tx descriptors
+ * @tx_q: the tx ring to set up
+ * @bufq: buffer or completion queue
+ *
+ * Returns 0 on success, negative on failure
+ */
+static int iecm_tx_desc_alloc(struct iecm_queue *tx_q, bool bufq)
+{
+	struct device *dev = tx_q->dev;
+	int err = 0;
+
+	if (bufq) {
+		err = iecm_tx_buf_alloc_all(tx_q);
+		if (err)
+			goto err_alloc;
+		tx_q->size = tx_q->desc_count *
+				sizeof(struct iecm_base_tx_desc);
+	} else {

drivers/net/ethernet/intel/iecm/iecm_txrx.c const struct iecm_rx_ptype_decoded iecm_ptype_lookup[IECM_RX_MAX_PTYPE] = {

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+		tx_q->size = tx_q->desc_count *
+				sizeof(struct iecm_splitq_tx_compl_desc);
+	}
+
+	/* Allocate descriptors also round up to nearest 4K */
+	tx_q->size = ALIGN(tx_q->size, 4096);
+	tx_q->desc_ring = dmam_alloc_coherent(dev, tx_q->size, &tx_q->dma,
+					      GFP_KERNEL);
+	if (!tx_q->desc_ring) {
+		dev_info(dev, "Unable to allocate memory for the Tx descriptor

ring, size=%d\n",

Quoted 40 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +40 -0
+			 tx_q->size);
+		err = -ENOMEM;
+		goto err_alloc;
+	}
+
+	tx_q->next_to_alloc = 0;
+	tx_q->next_to_use = 0;
+	tx_q->next_to_clean = 0;
+	set_bit(__IECM_Q_GEN_CHK, tx_q->flags);
+
+err_alloc:
+	if (err)
+		iecm_tx_desc_rel(tx_q, bufq);
+	return err;
+}
+
+/**
+ * iecm_tx_desc_alloc_all - allocate all queues Tx resources
+ * @vport: virtual port private structure
+ *
+ * Returns 0 on success, negative on failure
+ */
+static int iecm_tx_desc_alloc_all(struct iecm_vport *vport)
+{
+	struct pci_dev *pdev = vport->adapter->pdev;
+	int err = 0;
+	int i, j;
+
+	/* Setup buffer queues. In single queue model buffer queues and
+	 * completion queues will be same
+	 */
+	for (i = 0; i < vport->num_txq_grp; i++) {
+		for (j = 0; j < vport->txq_grps[i].num_txq; j++) {
+			err = iecm_tx_desc_alloc(vport->txq_grps[i].txqs[j],
+						 true);
+			if (err) {
+				dev_err(&pdev->dev,
+					"Allocation for Tx Queue %u failed\n",
+					i);
+				goto err_out;

drivers/net/ethernet/intel/iecm/iecm_txrx.c const struct iecm_rx_ptype_decoded iecm_ptype_lookup[IECM_RX_MAX_PTYPE] = {

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+			}
+		}
+
+		if (iecm_is_queue_model_split(vport->txq_model)) {
+			/* Setup completion queues */
+			err = iecm_tx_desc_alloc(vport->txq_grps[i].complq,
+						 false);
+			if (err) {
+				dev_err(&pdev->dev,
+					"Allocation for Tx Completion Queue

%u failed\n",

Quoted 29 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +29 -0
+					i);
+				goto err_out;
+			}
+		}
+	}
+err_out:
+	if (err)
+		iecm_tx_desc_rel_all(vport);
+	return err;
+}
+
+/**
+ * iecm_txq_group_rel - Release all resources for txq groups
+ * @vport: vport to release txq groups on
+ */
+static void iecm_txq_group_rel(struct iecm_vport *vport)
+{
+	struct iecm_txq_group *txq_grp;
+	int i, j, num_txq;
+
+	if (vport->txq_grps) {
+		for (i = 0; i < vport->num_txq_grp; i++) {
+			txq_grp = &vport->txq_grps[i];
+			num_txq = txq_grp->num_txq;
+
+			for (j = 0; j < num_txq; j++) {
+				kfree(txq_grp->txqs[j]);
+				txq_grp->txqs[j] = NULL;
+			}
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c const struct iecm_rx_ptype_decoded iecm_ptype_lookup[IECM_RX_MAX_PTYPE] = { · line 478

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+			kfree(txq_grp->complq);
+			txq_grp->complq = NULL;
+		}
+		kfree(vport->txq_grps);
+		vport->txq_grps = NULL;
+	}

Same here, !txq_grps -> return.

Will fix

Quoted 127 lines
Quoted 21 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +21 -0
+}
+
+/**
+ * iecm_vport_queue_grp_rel_all - Release all queue groups
+ * @vport: vport to release queue groups for
+ */
+static void iecm_vport_queue_grp_rel_all(struct iecm_vport *vport)
+{
+	iecm_txq_group_rel(vport);
+}
+
+/**
+ * iecm_vport_queues_rel - Free memory for all queues
+ * @vport: virtual port
+ *
+ * Free the memory allocated for queues associated to a vport
+ */
+void iecm_vport_queues_rel(struct iecm_vport *vport)
+{
+	iecm_tx_desc_rel_all(vport);
+	iecm_vport_queue_grp_rel_all(vport);

drivers/net/ethernet/intel/iecm/iecm_txrx.c const struct iecm_rx_ptype_decoded iecm_ptype_lookup[IECM_RX_MAX_PTYPE] = {

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+
+	kfree(vport->txqs);
+	vport->txqs = NULL;
+}
+
+/**
+ * iecm_vport_init_fast_path_txqs - Initialize fast path txq array
+ * @vport: vport to init txqs on
+ *
+ * We get a queue index from skb->queue_mapping and we need a fast way

to

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_groups(struct

Quoted 28 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +24 -0
+ * dereference the queue from queue groups.  This allows us to quickly pull a
+ * txq based on a queue index.
+ *
+ * Returns 0 on success, negative on failure
+ */
+static int iecm_vport_init_fast_path_txqs(struct iecm_vport *vport)
+{
+	int i, j, k = 0;
+
+	vport->txqs = kcalloc(vport->num_txq, sizeof(struct iecm_queue *),
+			      GFP_KERNEL);
+
+	if (!vport->txqs)
+		return -ENOMEM;
+
+	for (i = 0; i < vport->num_txq_grp; i++) {
+		struct iecm_txq_group *tx_grp = &vport->txq_grps[i];
+
+		for (j = 0; j < tx_grp->num_txq; j++, k++) {
+			vport->txqs[k] = tx_grp->txqs[j];
+			vport->txqs[k]->idx = k;
+		}
+	}
+	return 0;
 }

/**

drivers/net/ethernet/intel/iecm/iecm_txrx.c +0 -0
@@ -382,6 +680,26 @@ void iecm_vport_calc_num_q_groups(struct

iecm_vport *vport)

Quoted 15 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +12 -0
 }
 EXPORT_SYMBOL(iecm_vport_calc_num_q_groups);
 
+/**
+ * iecm_vport_calc_numq_per_grp - Calculate number of queues per group
+ * @vport: vport to calculate queues for
+ * @num_txq: int return parameter
+ * @num_rxq: int return parameter
+ */
+static void iecm_vport_calc_numq_per_grp(struct iecm_vport *vport,
+					 int *num_txq, int *num_rxq)
+{
+	if (iecm_is_queue_model_split(vport->txq_model))
+		*num_txq = IECM_DFLT_SPLITQ_TXQ_PER_GROUP;
+	else

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_groups(struct iecm_vport *vport)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +8 -0
+		*num_txq = vport->num_txq;
+
+	if (iecm_is_queue_model_split(vport->rxq_model))
+		*num_rxq = IECM_DFLT_SPLITQ_RXQ_PER_GROUP;
+	else
+		*num_rxq = vport->num_rxq;
+}
+
 /**
  * iecm_vport_calc_num_q_vec - Calculate total number of vectors required

for

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_vec(struct

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +0 -0
  * this vport
@@ -396,3 +714,949 @@ void iecm_vport_calc_num_q_vec(struct

iecm_vport *vport)

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
 		vport->num_q_vectors = vport->num_txq;
 }
 EXPORT_SYMBOL(iecm_vport_calc_num_q_vec);
+

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_vec(struct iecm_vport *vport)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+/**
+ * iecm_set_vlan_tag_loc - set the tag location for a tx/rx queue
+ * @adapter: adapter structure
+ * @q: tx/rx queue to set tag location for
+ *
+ */
+static void iecm_set_vlan_tag_loc(struct iecm_adapter *adapter,
+				  struct iecm_queue *q)
+{
+	if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS,

VIRTCHNL2_CAP_VLAN)) {

Quoted 22 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +4 -0
+		struct virtchnl_vlan_supported_caps *insertion_support;
+
+		insertion_support =
+				&adapter->vlan_caps-

offloads.insertion_support;

drivers/net/ethernet/intel/iecm/iecm_txrx.c +17 -0
+		if (insertion_support->outer) {
+			if (insertion_support->outer &
+			    VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1)
+				set_bit(__IECM_Q_VLAN_TAG_LOC_L2TAG1,
+					q->flags);
+			else if (insertion_support->outer &
+				 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2)
+				set_bit(__IECM_Q_VLAN_TAG_LOC_L2TAG2,
+					q->flags);
+		} else if (insertion_support->inner) {
+			if (insertion_support->inner &
+			    VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1)
+				set_bit(__IECM_Q_VLAN_TAG_LOC_L2TAG1,
+					q->flags);
+			else if (insertion_support->inner &
+				 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2)
+				set_bit(__IECM_Q_VLAN_TAG_LOC_L2TAG2,
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_vec(struct iecm_vport *vport) · line 754

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+					q->flags);
+		}
+	} else if (iecm_is_cap_ena(adapter, IECM_BASE_CAPS,
+				   VIRTCHNL2_CAP_VLAN)) {
+		set_bit(__IECM_Q_VLAN_TAG_LOC_L2TAG1, q->flags);
+	}

If !ena -> set_bit() + return, -1 indent.

I'm afraid I'm not following here.

Quoted 124 lines
Quoted 90 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +41 -0
+}
+
+/**
+ * iecm_txq_group_alloc - Allocate all txq group resources
+ * @vport: vport to allocate txq groups for
+ * @num_txq: number of txqs to allocate for each group
+ *
+ * Returns 0 on success, negative on failure
+ */
+static int iecm_txq_group_alloc(struct iecm_vport *vport, int num_txq)
+{
+	int err = 0, i;
+
+	vport->txq_grps = kcalloc(vport->num_txq_grp,
+				  sizeof(*vport->txq_grps), GFP_KERNEL);
+	if (!vport->txq_grps)
+		return -ENOMEM;
+
+	for (i = 0; i < vport->num_txq_grp; i++) {
+		struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+		int j;
+
+		tx_qgrp->vport = vport;
+		tx_qgrp->num_txq = num_txq;
+
+		for (j = 0; j < tx_qgrp->num_txq; j++) {
+			tx_qgrp->txqs[j] = kzalloc(sizeof(*tx_qgrp->txqs[j]),
+						   GFP_KERNEL);
+			if (!tx_qgrp->txqs[j]) {
+				err = -ENOMEM;
+				goto err_alloc;
+			}
+		}
+
+		for (j = 0; j < tx_qgrp->num_txq; j++) {
+			struct iecm_queue *q = tx_qgrp->txqs[j];
+
+			q->dev = &vport->adapter->pdev->dev;
+			q->desc_count = vport->txq_desc_count;
+			q->tx_max_bufs =
+				vport->adapter-

dev_ops.vc_ops.get_max_tx_bufs(vport->adapter);

drivers/net/ethernet/intel/iecm/iecm_txrx.c +48 -0
+			q->vport = vport;
+			q->txq_grp = tx_qgrp;
+			hash_init(q->sched_buf_hash);
+
+			if (!iecm_is_cap_ena(vport->adapter,
+					     IECM_OTHER_CAPS,
+					     VIRTCHNL2_CAP_SPLITQ_QSCHED))
+				set_bit(__IECM_Q_FLOW_SCH_EN, q->flags);
+			iecm_set_vlan_tag_loc(vport->adapter, q);
+		}
+
+		if (!iecm_is_queue_model_split(vport->txq_model))
+			continue;
+
+		tx_qgrp->complq = kcalloc(IECM_COMPLQ_PER_GROUP,
+					  sizeof(*tx_qgrp->complq),
+					  GFP_KERNEL);
+		if (!tx_qgrp->complq) {
+			err = -ENOMEM;
+			goto err_alloc;
+		}
+
+		tx_qgrp->complq->dev = &vport->adapter->pdev->dev;
+		tx_qgrp->complq->desc_count = vport->complq_desc_count;
+		tx_qgrp->complq->vport = vport;
+		tx_qgrp->complq->txq_grp = tx_qgrp;
+	}
+
+err_alloc:
+	if (err)
+		iecm_txq_group_rel(vport);
+	return err;
+}
+
+/**
+ * iecm_vport_queue_grp_alloc_all - Allocate all queue groups/resources
+ * @vport: vport with qgrps to allocate
+ *
+ * Returns 0 on success, negative on failure
+ */
+static int iecm_vport_queue_grp_alloc_all(struct iecm_vport *vport)
+{
+	int num_txq, num_rxq;
+	int err;
+
+	iecm_vport_calc_numq_per_grp(vport, &num_txq, &num_rxq);
+
+	err = iecm_txq_group_alloc(vport, num_txq);

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_vec(struct iecm_vport *vport)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+	if (err)
+		iecm_vport_queue_grp_rel_all(vport);
+	return err;
+}
+
+/**
+ * iecm_vport_queues_alloc - Allocate memory for all queues
+ * @vport: virtual port
+ *
+ * Allocate memory for queues associated with a vport.  Returns 0 on

success,

Quoted 23 lines

+ * negative on failure.
+ */

drivers/net/ethernet/intel/iecm/iecm_txrx.c +21 -0
+int iecm_vport_queues_alloc(struct iecm_vport *vport)
+{
+	int err;
+	int i;
+
+	err = iecm_vport_queue_grp_alloc_all(vport);
+	if (err)
+		goto err_out;
+
+	err = iecm_tx_desc_alloc_all(vport);
+	if (err)
+		goto err_out;
+
+	err = iecm_vport_init_fast_path_txqs(vport);
+	if (err)
+		goto err_out;
+
+	/* Initialize flow scheduling for queues that were requested
+	 * before the interface was brought up
+	 */
+	for (i = 0; i < vport->num_txq; i++) {
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_vec(struct iecm_vport *vport) · line 881

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +2 -0
+		if (test_bit(i, vport->adapter->config_data.etf_qenable)) {
+			set_bit(__IECM_Q_FLOW_SCH_EN, vport->txqs[i]-

flags);

drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
+			set_bit(__IECM_Q_ETF_EN, vport->txqs[i]->flags);
+		}
+	}

Redundant braces for the for-loop.

Will not fix.

Quoted 40 lines
Quoted 27 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +27 -0
+
+	return 0;
+err_out:
+	iecm_vport_queues_rel(vport);
+	return err;
+}
+
+/**
+ * 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_intr_napi_del_all - Unregister napi for all q_vectors in vport
+ * @vport: virtual port structure

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_vec(struct iecm_vport *vport) · line 918

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+ *
+ */
+static void iecm_vport_intr_napi_del_all(struct iecm_vport *vport)
+{
+	u16 v_idx;
+
+	for (v_idx = 0; v_idx < vport->num_q_vectors; v_idx++) {
+		struct iecm_q_vector *q_vector = &vport->q_vectors[v_idx];
+
+		netif_napi_del(&q_vector->napi);

One-liner:

Quoted 2 lines
		netif_napi_del(&vport->q_vectors[v_idx].napi);

Will fix.

Quoted 57 lines
Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +8 -0
+	}
+}
+
+/**
+ * iecm_vport_intr_napi_dis_all - Disable NAPI for all q_vectors in the vport
+ * @vport: main vport structure
+ */
+static void iecm_vport_intr_napi_dis_all(struct iecm_vport *vport)

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_vec(struct iecm_vport *vport) · line 936

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+{
+	int q_idx;
+
+	if (!vport->netdev)
+		return;
+
+	for (q_idx = 0; q_idx < vport->num_q_vectors; q_idx++) {
+		struct iecm_q_vector *q_vector = &vport->q_vectors[q_idx];
+
+		napi_disable(&q_vector->napi);

Same here.

Quoted 25 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +25 -0
+	}
+}
+
+/**
+ * iecm_vport_intr_rel - Free memory allocated for interrupt vectors
+ * @vport: virtual port
+ *
+ * Free the memory allocated for interrupt vectors  associated to a vport
+ */
+void iecm_vport_intr_rel(struct iecm_vport *vport)
+{
+	int i, j, v_idx;
+
+	if (!vport->netdev)
+		return;
+
+	for (v_idx = 0; v_idx < vport->num_q_vectors; v_idx++) {
+		struct iecm_q_vector *q_vector = &vport->q_vectors[v_idx];
+
+		kfree(q_vector->bufq);
+		q_vector->bufq = NULL;
+		kfree(q_vector->tx);
+		q_vector->tx = NULL;
+		kfree(q_vector->rx);
+		q_vector->rx = NULL;

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_vec(struct iecm_vport *vport) · line 977

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+	}
+
+	/* Clean up the mapping of queues to vectors */
+	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)) {
+			for (j = 0; j < rx_qgrp->splitq.num_rxq_sets; j++)
+				rx_qgrp->splitq.rxq_sets[j]->rxq.q_vector =
+

NULL;

Quoted 17 lines
Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +4 -0
+		} else {
+			for (j = 0; j < rx_qgrp->singleq.num_rxq; j++)
+				rx_qgrp->singleq.rxqs[j]->q_vector = NULL;
+		}

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_vec(struct iecm_vport *vport) · line 985

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+	}
+
+	if (iecm_is_queue_model_split(vport->txq_model)) {
+		for (i = 0; i < vport->num_txq_grp; i++)
+			vport->txq_grps[i].complq->q_vector = NULL;
+	} else {
+		for (i = 0; i < vport->num_txq_grp; i++) {
+			for (j = 0; j < vport->txq_grps[i].num_txq; j++)
+				vport->txq_grps[i].txqs[j]->q_vector = NULL;
+		}

Redundant braces.

Will not fix.

Quoted 118 lines
Quoted 83 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +83 -0
+	}
+
+	kfree(vport->q_vectors);
+	vport->q_vectors = NULL;
+}
+
+/**
+ * iecm_vport_intr_rel_irq - Free the IRQ association with the OS
+ * @vport: main vport structure
+ */
+static void iecm_vport_intr_rel_irq(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	int vector;
+
+	for (vector = 0; vector < vport->num_q_vectors; vector++) {
+		struct iecm_q_vector *q_vector = &vport->q_vectors[vector];
+		int irq_num, vidx;
+
+		/* free only the irqs that were actually requested */
+		if (!q_vector)
+			continue;
+
+		vidx = vector + vport->q_vector_base;
+		irq_num = adapter->msix_entries[vidx].vector;
+
+		/* clear the affinity_mask in the IRQ descriptor */
+		irq_set_affinity_hint(irq_num, NULL);
+		free_irq(irq_num, q_vector);
+	}
+}
+
+/**
+ * iecm_vport_intr_dis_irq_all - Disable each interrupt
+ * @vport: main vport structure
+ */
+void iecm_vport_intr_dis_irq_all(struct iecm_vport *vport)
+{
+	struct iecm_q_vector *q_vector = vport->q_vectors;
+	struct iecm_hw *hw = &vport->adapter->hw;
+	int q_idx;
+
+	for (q_idx = 0; q_idx < vport->num_q_vectors; q_idx++)
+		wr32(hw, q_vector[q_idx].intr_reg.dyn_ctl, 0);
+}
+
+/**
+ * iecm_vport_intr_buildreg_itr - Enable default interrupt generation settings
+ * @q_vector: pointer to q_vector
+ * @type: itr index
+ * @itr: itr value
+ */
+static u32 iecm_vport_intr_buildreg_itr(struct iecm_q_vector *q_vector,
+					const int type, u16 itr)
+{
+	u32 itr_val;
+
+	itr &= IECM_ITR_MASK;
+	/* Don't clear PBA because that can cause lost interrupts that
+	 * came in while we were cleaning/polling
+	 */
+	itr_val = q_vector->intr_reg.dyn_ctl_intena_m |
+		  (type << q_vector->intr_reg.dyn_ctl_itridx_s) |
+		  (itr << (q_vector->intr_reg.dyn_ctl_intrvl_s - 1));
+
+	return itr_val;
+}
+
+/**
+ * iecm_net_dim - Update net DIM algorithm
+ * @q_vector: the vector associated with the interrupt
+ *
+ * Create a DIM sample and notify net_dim() so that it can possibly decide
+ * a new ITR value based on incoming packets, bytes, and interrupts.
+ *
+ * This function is a no-op if the queue is not configured to dynamic ITR.
+ */
+static void iecm_net_dim(struct iecm_q_vector *q_vector)
+{
+	if (IECM_ITR_IS_DYNAMIC(q_vector->tx_intr_mode)) {
+		struct dim_sample dim_sample = {};
+		u64 packets = 0, bytes = 0;
+		int i;

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_vec(struct iecm_vport *vport) · line 1078

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+
+		for (i = 0; i < q_vector->num_txq; i++) {
+			packets += q_vector->tx[i]->q_stats.tx.packets;
+			bytes += q_vector->tx[i]->q_stats.tx.bytes;
+		}
+
+		dim_update_sample(q_vector->total_events, packets, bytes,
+				  &dim_sample);
+		net_dim(&q_vector->tx_dim, dim_sample);
+	}
	if (!dynamic_tx)
		goto check_rx;

-1 level.

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +5 -0
+
+	if (IECM_ITR_IS_DYNAMIC(q_vector->rx_intr_mode)) {
+		struct dim_sample dim_sample = {};
+		u64 packets = 0, bytes = 0;
+		int i;

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_vec(struct iecm_vport *vport) · line 1093

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+
+		for (i = 0; i < q_vector->num_rxq; i++) {
+			packets += q_vector->rx[i]->q_stats.rx.packets;
+			bytes += q_vector->rx[i]->q_stats.rx.bytes;
+		}
+
+		dim_update_sample(q_vector->total_events, packets, bytes,
+				  &dim_sample);
+		net_dim(&q_vector->rx_dim, dim_sample);
+	}
	if (!dynamic_rx)
		return;
Quoted 2 lines

-1 as well.

I'm not entirely convinced this is better or more readable but I guess will fix.

Quoted 88 lines

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

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +4 -0
+}
+
+/**
+ * iecm_vport_intr_update_itr_ena_irq - Update itr and re-enable MSIX

interrupt

Quoted 3 lines

+ * @q_vector: q_vector for which itr is being updated and interrupt enabled
+ *
+ * Update the net_dim() algorithm and re-enable the interrupt associated

with

Quoted 56 lines

+ * this vector.
+ */

drivers/net/ethernet/intel/iecm/iecm_txrx.c +54 -0
+void iecm_vport_intr_update_itr_ena_irq(struct iecm_q_vector *q_vector)
+{
+	struct iecm_hw *hw = &q_vector->vport->adapter->hw;
+	u32 intval;
+
+	/* net_dim() updates ITR out-of-band using a work item */
+	iecm_net_dim(q_vector);
+
+	intval = iecm_vport_intr_buildreg_itr(q_vector,
+					      VIRTCHNL2_ITR_IDX_NO_ITR, 0);
+
+	wr32(hw, q_vector->intr_reg.dyn_ctl, intval);
+}
+
+/**
+ * iecm_vport_intr_req_irq - get MSI-X vectors from the OS for the vport
+ * @vport: main vport structure
+ * @basename: name for the vector
+ */
+static int
+iecm_vport_intr_req_irq(struct iecm_vport *vport, char *basename)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	int vector, err, irq_num, vidx;
+
+	for (vector = 0; vector < vport->num_q_vectors; vector++) {
+		struct iecm_q_vector *q_vector = &vport->q_vectors[vector];
+
+		vidx = vector + vport->q_vector_base;
+		irq_num = adapter->msix_entries[vidx].vector;
+
+		snprintf(q_vector->name, sizeof(q_vector->name) - 1,
+			 "%s-%s-%d", basename, "TxRx", vidx);
+
+		err = request_irq(irq_num, vport->irq_q_handler, 0,
+				  q_vector->name, q_vector);
+		if (err) {
+			netdev_err(vport->netdev,
+				   "Request_irq failed, error: %d\n", err);
+			goto free_q_irqs;
+		}
+		/* assign the mask for this irq */
+		irq_set_affinity_hint(irq_num, &q_vector->affinity_mask);
+	}
+
+	return 0;
+
+free_q_irqs:
+	while (vector) {
+		vector--;
+		vidx = vector + vport->q_vector_base;
+		irq_num = adapter->msix_entries[vidx].vector;
+		free_irq(irq_num, &vport->q_vectors[vector]);
+	}

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_vec(struct iecm_vport *vport)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+	return err;
+}
+
+/**
+ * iecm_vport_intr_write_itr - Write ITR value to the ITR register
+ * @q_vector: q_vector structure
+ * @itr: Interrupt throttling rate
+ * @tx: Tx or Rx ITR
+ */
+void iecm_vport_intr_write_itr(struct iecm_q_vector *q_vector, u16 itr, bool

tx)

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_vec(struct iecm_vport *vport) · line 1174

Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +8 -0
+{
+	struct iecm_hw *hw = &q_vector->vport->adapter->hw;
+	struct iecm_intr_reg *intr_reg;
+
+	if (tx && !q_vector->tx)
+		return;
+	else if (!tx && !q_vector->rx)
+		return;
	if ((tx && !q_vector->tx) || (!tx && !q_vector->rx))
		return;
Quoted 2 lines

1 line not shown · raw message

1,217 lines not shown · raw message

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

#42 lore raw

PATCH 9/19 iecm: alloc vport TX resources

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

Quoted 37 lines
Quoted 37 lines

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

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

Quoted 23 lines

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 ++++++++++++++++-
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
 .../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

--- 8< ---

Quoted 10 lines
Quoted 8 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c static struct iecm_mac_filter *iecm_add_mac_filter(struct iecm_vport *vport, · line 499

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +5 -0
+	spin_lock_bh(&adapter->mac_filter_list_lock);
+	list_for_each_entry(f, &adapter->config_data.mac_filter_list, list) {
+		if (!f->remove)
+			f->add = true;
+	}

Redundant braces around a single statement.

Will not fix.

As I said in my previous message, this answer doesn't make this choice clearer neither to me, nor to other reviewers.

Quoted 8 lines
Quoted 8 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c static struct iecm_mac_filter *iecm_add_mac_filter(struct iecm_vport *vport, · line 506

Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +7 -0
+	spin_unlock_bh(&adapter->mac_filter_list_lock);
+
+	iecm_add_del_ether_addrs(vport, true, false);
+}
+
+/**
+ * iecm_set_all_vlans - Re-add all VLANs in list

--- 8< ---

Quoted 21 lines
Quoted 4 lines

Review void iecm_free_dma_mem(struct iecm_hw *hw,

Quoted 1 line
(quoted diff) +0 -0
@@ -1395,8 +1754,8 @@ void iecm_free_dma_mem(struct iecm_hw *hw,

struct iecm_dma_mem *mem)

Quoted 2 lines
(quoted diff) +0 -0
 }
 
Quoted 16 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c void iecm_free_dma_mem(struct iecm_hw *hw, struct iecm_dma_mem *mem) · line 1759

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +2 -2
 static const struct net_device_ops iecm_netdev_ops_splitq = {
-	.ndo_open = NULL,
-	.ndo_stop = NULL,
+	.ndo_open = iecm_open,
+	.ndo_stop = iecm_stop,
 	.ndo_start_xmit = NULL,

Hmm, forgot to mention this earlier as well. Consider marking CONFIG_IECM as depends on BROKEN in Kconfig and remove this line in the last commit. Otherwise, it will be possible to panic the kernel as at least .ndo_start_xmit should always be set, kernel doesn't check for it being non-NULL, it just calls it. Same with open, stop and probably more, so it's a good practice to disable drivers with depending on BROKEN until it receives the workable state.

Quoted 1 line

I don't have the full history on 'BROKEN' being a dependency but it seems silly to me to add some thrash just for that. Will consider.

Here: [0] I add 'depends on BROKEN' as the patch itself only adds some basic functionality and will be ready only after couple patches more.
It's a common practice, we mark some Kconfig symbols such way when they're either will become usable after some more changes or when a particular feature stops working properly or building on some configurations.

This driver is not ready to work right after you add a Kconfig option for it. Notably already mentioned NULLed .ndo_start_xmit() will cause nullptr accesses if register_netdev() is called. It's not a rare case at all when automation build systems and people use Git bisecting and test kernels in the middle of a series. If there is a chance to crash the kernel that way, it will crash sooner or later.

Ok, maybe depends on BROKEN doesn't incremental-building friendly as allmodconfigs will start to build iecm only after removing this line, but at least make sure there's no chance for this driver to probe earlier than it's fully functional.

Quoted 3 lines
Quoted 3 lines

Review void iecm_free_dma_mem(struct iecm_hw *hw, · line 1761

Quoted 3 lines
(quoted diff) +0 -0
 	.ndo_set_rx_mode = NULL,
 	.ndo_validate_addr = eth_validate_addr,

--- 8< ---

Quoted 37 lines
Quoted 27 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_vec(struct iecm_vport *vport)

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +4 -0
+static void iecm_set_vlan_tag_loc(struct iecm_adapter *adapter,
+				  struct iecm_queue *q)
+{
+	if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS,

VIRTCHNL2_CAP_VLAN)) {

Quoted 22 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +4 -0
+		struct virtchnl_vlan_supported_caps *insertion_support;
+
+		insertion_support =
+				&adapter->vlan_caps-

offloads.insertion_support;

drivers/net/ethernet/intel/iecm/iecm_txrx.c +17 -0
+		if (insertion_support->outer) {
+			if (insertion_support->outer &
+			    VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1)
+				set_bit(__IECM_Q_VLAN_TAG_LOC_L2TAG1,
+					q->flags);
+			else if (insertion_support->outer &
+				 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2)
+				set_bit(__IECM_Q_VLAN_TAG_LOC_L2TAG2,
+					q->flags);
+		} else if (insertion_support->inner) {
+			if (insertion_support->inner &
+			    VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1)
+				set_bit(__IECM_Q_VLAN_TAG_LOC_L2TAG1,
+					q->flags);
+			else if (insertion_support->inner &
+				 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2)
+				set_bit(__IECM_Q_VLAN_TAG_LOC_L2TAG2,
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_vec(struct iecm_vport *vport) · line 754

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+					q->flags);
+		}
+	} else if (iecm_is_cap_ena(adapter, IECM_BASE_CAPS,
+				   VIRTCHNL2_CAP_VLAN)) {
+		set_bit(__IECM_Q_VLAN_TAG_LOC_L2TAG1, q->flags);
+	}

If !ena -> set_bit() + return, -1 indent.

Quoted 1 line

I'm afraid I'm not following here.

	/* Do we have OTHER? */
	if (!iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_VLAN)) {
		/* OK, we don't. If we have BASE, set L2TAG1 bit and exit,
		 * otherwise just exit.
		 */
		if (iecm_is_cap_ena(adapter, IECM_BASE_CAPS,
				    VIRTCHNL2_CAP_VLAN))
			set_bit(__IECM_Q_VLAN_TAG_LOC_L2TAG1, q->flags);

		return;
	}

	/* We have OTHER, let's proceed with full-blown features */
	if (insertion_support->outer) {
		...
	}

BTW, just have noticed that these checks for outer and inner being non-0 are pointless, bitops will do the same job.

Quoted 5 lines
Quoted 5 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_vec(struct iecm_vport *vport) · line 758

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +4 -0
+}
+
+/**
+ * iecm_txq_group_alloc - Allocate all txq group resources

--- 8< ---

Quoted 16 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +4 -0
+	/* Initialize flow scheduling for queues that were requested
+	 * before the interface was brought up
+	 */
+	for (i = 0; i < vport->num_txq; i++) {
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_vec(struct iecm_vport *vport) · line 881

Quoted 6 lines
(quoted diff) +2 -0
+		if (test_bit(i, vport->adapter->config_data.etf_qenable)) {
+			set_bit(__IECM_Q_FLOW_SCH_EN, vport->txqs[i]-

flags);

drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
+			set_bit(__IECM_Q_ETF_EN, vport->txqs[i]->flags);
+		}
+	}

Redundant braces for the for-loop.

Will not fix.

Quoted 9 lines
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_vec(struct iecm_vport *vport) · line 890

Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +9 -0
+
+	return 0;
+err_out:
+	iecm_vport_queues_rel(vport);
+	return err;
+}
+
+/**
+ * iecm_vport_intr_clean_queues - MSIX mode Interrupt Handler

--- 8< ---

Quoted 14 lines
Quoted 11 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_vec(struct iecm_vport *vport) · line 985

Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +8 -0
+	if (iecm_is_queue_model_split(vport->txq_model)) {
+		for (i = 0; i < vport->num_txq_grp; i++)
+			vport->txq_grps[i].complq->q_vector = NULL;
+	} else {
+		for (i = 0; i < vport->num_txq_grp; i++) {
+			for (j = 0; j < vport->txq_grps[i].num_txq; j++)
+				vport->txq_grps[i].txqs[j]->q_vector = NULL;
+		}

Redundant braces.

Will not fix.

Quoted 8 lines
Quoted 8 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_vec(struct iecm_vport *vport) · line 993

Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +8 -0
+	}
+
+	kfree(vport->q_vectors);
+	vport->q_vectors = NULL;
+}
+
+/**
+ * iecm_vport_intr_rel_irq - Free the IRQ association with the OS

--- 8< ---

Quoted 41 lines
Quoted 41 lines
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+static void iecm_net_dim(struct iecm_q_vector *q_vector)
+{
+	if (IECM_ITR_IS_DYNAMIC(q_vector->tx_intr_mode)) {
+		struct dim_sample dim_sample = {};
+		u64 packets = 0, bytes = 0;
+		int i;

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_vec(struct iecm_vport *vport) · line 1078

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+
+		for (i = 0; i < q_vector->num_txq; i++) {
+			packets += q_vector->tx[i]->q_stats.tx.packets;
+			bytes += q_vector->tx[i]->q_stats.tx.bytes;
+		}
+
+		dim_update_sample(q_vector->total_events, packets, bytes,
+				  &dim_sample);
+		net_dim(&q_vector->tx_dim, dim_sample);
+	}
	if (!dynamic_tx)
		goto check_rx;

-1 level.

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +5 -0
+
+	if (IECM_ITR_IS_DYNAMIC(q_vector->rx_intr_mode)) {
+		struct dim_sample dim_sample = {};
+		u64 packets = 0, bytes = 0;
+		int i;

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_vec(struct iecm_vport *vport) · line 1093

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+
+		for (i = 0; i < q_vector->num_rxq; i++) {
+			packets += q_vector->rx[i]->q_stats.rx.packets;
+			bytes += q_vector->rx[i]->q_stats.rx.bytes;
+		}
+
+		dim_update_sample(q_vector->total_events, packets, bytes,
+				  &dim_sample);
+		net_dim(&q_vector->rx_dim, dim_sample);
+	}
	if (!dynamic_rx)
		return;
Quoted 4 lines
Quoted 2 lines

-1 as well.

I'm not entirely convinced this is better or more readable but I guess will fix.

	/* Do we have DIM enabled for Tx? If no, proceed with Rx */
	if (!IECM_ITR_IS_DYNAMIC(q_vector->tx_intr_mode))
		goto rx;

	for (i = 0; i < q_vector->num_txq; i++) {
		...

rx:

	/* Do we have DIM enabled for Rx? If no, just exit */
	if (!IECM_ITR_IS_DYNAMIC(q_vector->rx_intr_mode))
		return;

	for (i = 0; i < q_vector->num_rxq; i++) {
		...

I'm not entirely convinced this can look less readable then the code above.

You could even split it into two small functions or even compress it as they only differ with the direction suffixes:

/* Can be a function as well, would just require more arguments */

#define iecm_net_dim_dir(q_vector, dir) ({			\
	struct iecm_q_vector *__qv = (q_vector);		\
								\
	if (IECM_ITR_IS_DYNAMIC(__qv->dir##_intr_mode)) {	\
		struct dim_sample dim_sample = {};		\
		...						\
		net_dim(&__qv->dir##_dim, dim_sample);		\
	}							\
})

#define iecm_net_dim_rx(q_vector) iecm_net_dim_dir(q_vector, rx)
#define iecm_net_dim_tx(q_vector) iecm_net_dim_dir(q_vector, tx)

static void iecm_net_dim(struct iecm_q_vector *q_vector)

{
	iecm_net_dim_rx(q_vector);
	iecm_net_dim_tx(q_vector);
}
Quoted 6 lines
Quoted 6 lines

drivers/net/ethernet/intel/iecm/iecm_lib.c static struct iecm_mac_filter *iecm_add_mac_filter(struct iecm_vport *vport,

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +4 -0
+}
+
+/**
+ * iecm_vport_intr_update_itr_ena_irq - Update itr and re-enable MSIX

interrupt

--- 8< ---

Quoted 14 lines
Quoted 14 lines
Quoted 1 line

+void iecm_vport_intr_write_itr(struct iecm_q_vector *q_vector, u16 itr, bool

tx)

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_vec(struct iecm_vport *vport) · line 1174

Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +8 -0
+{
+	struct iecm_hw *hw = &q_vector->vport->adapter->hw;
+	struct iecm_intr_reg *intr_reg;
+
+	if (tx && !q_vector->tx)
+		return;
+	else if (!tx && !q_vector->rx)
+		return;
	if ((tx && !q_vector->tx) || (!tx && !q_vector->rx))
		return;
Quoted 4 lines
Quoted 2 lines

Fits into 79 cols and looks more elegant-ish.

Yours is a bit harder for humans to grok, would be prefer to keep this as-is.

For me it's harder to follow the ladder with two identical branches (return-return).
I'd also rename tx to at least is_tx as it makes things even more confusing.

Quoted 9 lines
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_vec(struct iecm_vport *vport) · line 1182

Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +8 -0
+
+	intr_reg = &q_vector->intr_reg;
+	wr32(hw, tx ? intr_reg->tx_itr : intr_reg->rx_itr,
+	     ITR_REG_ALIGN(itr) >> IECM_ITR_GRAN_S);
+}
+
+/**
+ * iecm_vport_intr_ena_irq_all - Enable IRQ for the given vport

--- 8< ---

Quoted 12 lines
Quoted 11 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_vec(struct iecm_vport *vport) · line 1593

Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +7 -0
+void iecm_fill_dflt_rss_lut(struct iecm_vport *vport)
+{
+	u16 num_active_rxq = vport->num_rxq;
+	int i;
+
+	for (i = 0; i < vport->adapter->rss_data.rss_lut_size; i++)
+		vport->adapter->rss_data.rss_lut[i] = i % num_active_rxq;

I think I saw a built-in kernel function for that, I'd grep for sth like fill_default_rss.

Quoted 1 line

Hmm I grep'd around and didn't see anything like that. Didn't see anything like that in other drivers I briefly looked at either.

I was sure it's there. It's ethtool_rxfh_indir_default(): [1].

You can deref vport->adapter->rss_data in a separate var to shorten all this.

Quoted 5 lines
Quoted 5 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_vec(struct iecm_vport *vport) · line 1597

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +4 -0
+}
+
+/**
+ * iecm_init_rss - Prepare for RSS

--- 8< ---

Quoted 38 lines
Quoted 38 lines
Quoted 2 lines

+
#define MAKEMASK(m, s) ((m) << (s))

Consider using stock BIT(s) insteead of introducing this MAKEMASK().

Quoted 19 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +18 -0
+struct iecm_tx_buf {
+	struct hlist_node hlist;
+	void *next_to_watch;
+	union {
+		struct sk_buff *skb;
+		struct xdp_frame *xdpf;
+	};
+	unsigned int bytecount;
+	unsigned short gso_segs;
+#define IECM_TX_FLAGS_TSO			BIT(0)
+#define IECM_TX_FLAGS_VLAN_TAG			BIT(1)
+#define IECM_TX_FLAGS_HW_VLAN			BIT(2)
+#define IECM_TX_FLAGS_HW_OUTER_SINGLE_VLAN	BIT(3)
+#define IECM_TX_FLAGS_VLAN_SHIFT		16
+#define IECM_TX_FLAGS_VLAN_MASK			0xFFFF0000
+	u32 tx_flags;
+	DEFINE_DMA_UNMAP_ADDR(dma);
+	DEFINE_DMA_UNMAP_LEN(len);

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

Quoted 10 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +10 -0
+	u16 compl_tag;		/* Unique identifier for buffer; used to
+				 * compare with completion tag returned
+				 * in buffer completion event
+				 */
+};
+
+struct iecm_buf_lifo {
+	u16 top;
+	u16 size;
+	struct iecm_tx_buf **bufs;

There'll probably be a 4-byte gap before @bufs, move @top and @size to the bottop to avoid this.

Quoted 1 line
Quoted 1 line
Quoted 1 line

+};

--- 8< ---

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

--
2.33.0

Thanks,
Al

[0] https://lore.kernel.org/all/20211223002209.1092165-13-alexandr.lobakin at intel.com
[1] https://elixir.bootlin.com/linux/v5.17-rc2/source/include/linux/ethtool.h#L125

Thanks,
Al

author
#43 lore raw

PATCH 10/19 iecm: alloc vport RX resources

In reply to Alan Brady

This finishes what we need to do for open by adding RX resource allocations.

As noted in the TX alloc patch, the splitq model is unique in introducing the concept of queue groups, which also applies to RX, albeit in a slightly different way. For RX we also split the queue between descriptor handling and buffer handling. We have some number of RX completion queues associated with up to two buffer queues in a given queue group. Once buffers are cleaned and recycled, they're given the buffer queues which then posts the buffers back to hardware. To enable this in a lockless way, there's also the concept of 'refill queues' introduced. Recycled buffers are put onto refill queues which is what the buffer queues clean to get buffers back.

---
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   | 769 ++++++++++++++++++
 .../net/ethernet/intel/include/iecm_txrx.h    |   7 +
 2 files changed, 776 insertions(+)
drivers/net/ethernet/intel/iecm/iecm_txrx.c +769 -0
index 85e88a30370d..fb6a61277b00 100644
@@ -452,6 +452,545 @@ static int iecm_tx_desc_alloc_all(struct iecm_vport *vport)
 	return err;
 }
 
+/**
+ * iecm_rx_page_rel - Release an rx buffer page
+ * @rxq: the queue that owns the buffer
+ * @page_info: pointer to page metadata of page to be freed
+ */
+static void iecm_rx_page_rel(struct iecm_queue *rxq,
+			     struct iecm_page_info *page_info)
+{
+	if (!page_info->page)
+		return;
+
+	/* free resources associated with mapping */
+	dma_unmap_page_attrs(rxq->dev, page_info->dma, PAGE_SIZE,
+			     DMA_FROM_DEVICE, IECM_RX_DMA_ATTR);
+
+	__page_frag_cache_drain(page_info->page, page_info->pagecnt_bias);
+
+	page_info->page = NULL;
+	page_info->page_offset = 0;
+}
+
+/**
+ * iecm_rx_buf_rel - Release a rx buffer
+ * @rxq: the queue that owns the buffer
+ * @rx_buf: the buffer to free
+ */
+static void iecm_rx_buf_rel(struct iecm_queue *rxq,
+			    struct iecm_rx_buf *rx_buf)
+{
+	iecm_rx_page_rel(rxq, &rx_buf->page_info[0]);
+#if (PAGE_SIZE < 8192)
+	if (rx_buf->buf_size > IECM_RX_BUF_2048)
+		iecm_rx_page_rel(rxq, &rx_buf->page_info[1]);
+
+#endif
+	if (rx_buf->skb) {
+		dev_kfree_skb_any(rx_buf->skb);
+		rx_buf->skb = NULL;
+	}
+}
+
+/**
+ * iecm_rx_hdr_buf_rel_all - Release header buffer memory
+ * @rxq: queue to use
+ */
+static void iecm_rx_hdr_buf_rel_all(struct iecm_queue *rxq)
+{
+	struct iecm_hw *hw = &rxq->vport->adapter->hw;
+	int i;
+
+	if (!rxq)
+		return;
+
+	if (rxq->rx_buf.hdr_buf) {
+		for (i = 0; i < rxq->desc_count; i++) {
+			struct iecm_dma_mem *hbuf = rxq->rx_buf.hdr_buf[i];
+
+			if (hbuf) {
+				iecm_free_dma_mem(hw, hbuf);
+				kfree(hbuf);
+			}
+			rxq->rx_buf.hdr_buf[i] = NULL;
+		}
+		kfree(rxq->rx_buf.hdr_buf);
+		rxq->rx_buf.hdr_buf = NULL;
+	}
+
+	for (i = 0; i < rxq->hbuf_pages.nr_pages; i++)
+		iecm_rx_page_rel(rxq, &rxq->hbuf_pages.pages[i]);
+
+	kfree(rxq->hbuf_pages.pages);
+}
+
+/**
+ * iecm_rx_buf_rel_all - Free all Rx buffer resources for a queue
+ * @rxq: queue to be cleaned
+ */
+static void iecm_rx_buf_rel_all(struct iecm_queue *rxq)
+{
+	u16 i;
+
+	/* queue already cleared, nothing to do */
+	if (!rxq->rx_buf.buf)
+		return;
+
+	/* Free all the bufs allocated and given to hw on Rx queue */
+	for (i = 0; i < rxq->desc_count; i++)
+		iecm_rx_buf_rel(rxq, &rxq->rx_buf.buf[i]);
+	if (rxq->rx_hsplit_en)
+		iecm_rx_hdr_buf_rel_all(rxq);
+
+	kfree(rxq->rx_buf.buf);
+	rxq->rx_buf.buf = NULL;
+	kfree(rxq->rx_buf.hdr_buf);
+	rxq->rx_buf.hdr_buf = NULL;
+}
+
+/**
+ * iecm_rx_desc_rel - Free a specific Rx q resources
+ * @rxq: queue to clean the resources from
+ * @bufq: buffer q or completion q
+ * @q_model: single or split q model
+ *
+ * Free a specific rx queue resources
+ */
+static void iecm_rx_desc_rel(struct iecm_queue *rxq, bool bufq, s32 q_model)
+{
+	if (!rxq)
+		return;
+
+	if (!bufq && iecm_is_queue_model_split(q_model) && rxq->skb) {
+		dev_kfree_skb_any(rxq->skb);
+		rxq->skb = NULL;
+	}
+
+	if (bufq || !iecm_is_queue_model_split(q_model))
+		iecm_rx_buf_rel_all(rxq);
+
+	if (rxq->desc_ring) {
+		dmam_free_coherent(rxq->dev, rxq->size,
+				   rxq->desc_ring, rxq->dma);
+		rxq->desc_ring = NULL;
+		rxq->next_to_alloc = 0;
+		rxq->next_to_clean = 0;
+		rxq->next_to_use = 0;
+	}
+}
+
+/**
+ * iecm_rx_desc_rel_all - Free Rx Resources for All Queues
+ * @vport: virtual port structure
+ *
+ * Free all rx queues resources
+ */
+static void iecm_rx_desc_rel_all(struct iecm_vport *vport)
+{
+	struct iecm_rxq_group *rx_qgrp;
+	struct iecm_queue *q;
+	int i, j, num_rxq;
+
+	if (!vport->rxq_grps)
+		return;
+
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		rx_qgrp = &vport->rxq_grps[i];
+
+		if (iecm_is_queue_model_split(vport->rxq_model)) {
+			num_rxq = rx_qgrp->splitq.num_rxq_sets;
+			for (j = 0; j < num_rxq; j++) {
+				q = &rx_qgrp->splitq.rxq_sets[j]->rxq;
+				iecm_rx_desc_rel(q, false,
+						 vport->rxq_model);
+			}
+
+			if (!rx_qgrp->splitq.bufq_sets)
+				continue;
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++) {
+				struct iecm_bufq_set *bufq_set =
+					&rx_qgrp->splitq.bufq_sets[j];
+
+				q = &bufq_set->bufq;
+				iecm_rx_desc_rel(q, true, vport->rxq_model);
+			}
+		} else {
+			for (j = 0; j < rx_qgrp->singleq.num_rxq; j++) {
+				q = rx_qgrp->singleq.rxqs[j];
+				iecm_rx_desc_rel(q, false,
+						 vport->rxq_model);
+			}
+		}
+	}
+}
+
+/**
+ * iecm_rx_buf_hw_update - Store the new tail and head values
+ * @rxq: queue to bump
+ * @val: new head index
+ */
+void iecm_rx_buf_hw_update(struct iecm_queue *rxq, u32 val)
+{
+	rxq->next_to_use = val;
+
+	if (unlikely(!rxq->tail))
+		return;
+	/* writel has an implicit memory barrier */
+	writel(val, rxq->tail);
+}
+
+/**
+ * iecm_alloc_page - allocate page to back RX buffer
+ * @rxbufq: pointer to queue struct
+ * @page_info: pointer to page metadata struct
+ */
+static int
+iecm_alloc_page(struct iecm_queue *rxbufq, struct iecm_page_info *page_info)
+{
+	/* alloc new page for storage */
+	page_info->page = alloc_page(GFP_ATOMIC | __GFP_NOWARN);
+	if (unlikely(!page_info->page))
+		return -ENOMEM;
+
+	/* map page for use */
+	page_info->dma = dma_map_page_attrs(rxbufq->dev, page_info->page,
+					    0, PAGE_SIZE, DMA_FROM_DEVICE,
+					    IECM_RX_DMA_ATTR);
+
+	/* if mapping failed free memory back to system since
+	 * there isn't much point in holding memory we can't use
+	 */
+	if (dma_mapping_error(rxbufq->dev, page_info->dma)) {
+		__free_pages(page_info->page, 0);
+		return -ENOMEM;
+	}
+
+	page_info->page_offset = 0;
+
+	/* initialize pagecnt_bias to claim we fully own page */
+	page_ref_add(page_info->page, USHRT_MAX - 1);
+	page_info->pagecnt_bias = USHRT_MAX;
+
+	return 0;
+}
+
+/**
+ * iecm_init_rx_buf_hw_alloc - allocate initial RX buffer pages
+ * @rxbufq: ring to use; equivalent to rxq when operating in singleq mode
+ * @buf: rx_buffer struct to modify
+ *
+ * Returns true if the page was successfully allocated or
+ * reused.
+ */
+bool iecm_init_rx_buf_hw_alloc(struct iecm_queue *rxbufq, struct iecm_rx_buf *buf)
+{
+	if (iecm_alloc_page(rxbufq, &buf->page_info[0]))
+		return false;
+
+#if (PAGE_SIZE < 8192)
+	if (rxbufq->rx_buf_size > IECM_RX_BUF_2048)
+		if (iecm_alloc_page(rxbufq, &buf->page_info[1]))
+			return false;
+#endif
+
+	buf->page_indx = 0;
+	buf->buf_size = rxbufq->rx_buf_size;
+
+	return true;
+}
+
+/**
+ * iecm_rx_hdr_buf_alloc_all - Allocate memory for header buffers
+ * @rxq: ring to use
+ *
+ * Returns 0 on success, negative on failure.
+ */
+static int iecm_rx_hdr_buf_alloc_all(struct iecm_queue *rxq)
+{
+	struct iecm_page_info *page_info;
+	int nr_pages, offset;
+	int i, j = 0;
+
+	rxq->rx_buf.hdr_buf = kcalloc(rxq->desc_count,
+				      sizeof(struct iecm_dma_mem *),
+				      GFP_KERNEL);
+	if (!rxq->rx_buf.hdr_buf)
+		return -ENOMEM;
+
+	for (i = 0; i < rxq->desc_count; i++) {
+		rxq->rx_buf.hdr_buf[i] = kcalloc(1,
+						 sizeof(struct iecm_dma_mem),
+						 GFP_KERNEL);
+		if (!rxq->rx_buf.hdr_buf[i])
+			goto unroll_buf_alloc;
+	}
+
+	/* Determine the number of pages necessary to back the total number of header buffers */
+	nr_pages = (rxq->desc_count * rxq->rx_hbuf_size) / PAGE_SIZE;
+	rxq->hbuf_pages.pages = kcalloc(nr_pages,
+					sizeof(struct iecm_page_info),
+					GFP_KERNEL);
+	if (!rxq->hbuf_pages.pages)
+		goto unroll_buf_alloc;
+
+	rxq->hbuf_pages.nr_pages = nr_pages;
+	for (i = 0; i < nr_pages; i++) {
+		if (iecm_alloc_page(rxq, &rxq->hbuf_pages.pages[i]))
+			goto unroll_buf_alloc;
+	}
+
+	page_info = &rxq->hbuf_pages.pages[0];
+	for (i = 0, offset = 0; i < rxq->desc_count; i++, offset += rxq->rx_hbuf_size) {
+		struct iecm_dma_mem *hbuf = rxq->rx_buf.hdr_buf[i];
+
+		/* Move to next page */
+		if (offset >= PAGE_SIZE) {
+			offset = 0;
+			page_info = &rxq->hbuf_pages.pages[++j];
+		}
+
+		hbuf->va = page_address(page_info->page) + offset;
+		hbuf->pa = page_info->dma + offset;
+		hbuf->size = rxq->rx_hbuf_size;
+	}
+
+	return 0;
+unroll_buf_alloc:
+	iecm_rx_hdr_buf_rel_all(rxq);
+	return -ENOMEM;
+}
+
+/**
+ * iecm_rx_buf_hw_alloc_all - Allocate receive buffers
+ * @rxbufq: queue for which the hw buffers are allocated; equivalent to rxq
+ * when operating in singleq mode
+ * @alloc_count: number of buffers to allocate
+ *
+ * Returns false if all allocations were successful, true if any fail
+ */
+static bool
+iecm_rx_buf_hw_alloc_all(struct iecm_queue *rxbufq, u16 alloc_count)
+{
+	u16 nta = rxbufq->next_to_alloc;
+	struct iecm_rx_buf *buf;
+
+	if (!alloc_count)
+		return false;
+
+	buf = &rxbufq->rx_buf.buf[nta];
+
+	do {
+		if (!iecm_init_rx_buf_hw_alloc(rxbufq, buf))
+			break;
+
+		buf++;
+		nta++;
+		if (unlikely(nta == rxbufq->desc_count)) {
+			buf = rxbufq->rx_buf.buf;
+			nta = 0;
+		}
+
+		alloc_count--;
+	} while (alloc_count);
+
+	return !!alloc_count;
+}
+
+/**
+ * iecm_rx_post_buf_desc - Post buffer to bufq descriptor ring
+ * @bufq: buffer queue to post to
+ * @buf_id: buffer id to post
+ */
+static void iecm_rx_post_buf_desc(struct iecm_queue *bufq, u16 buf_id)
+{
+	struct virtchnl2_splitq_rx_buf_desc *splitq_rx_desc = NULL;
+	struct iecm_page_info *page_info;
+	u16 nta = bufq->next_to_alloc;
+	struct iecm_rx_buf *buf;
+
+	splitq_rx_desc = IECM_SPLITQ_RX_BUF_DESC(bufq, nta);
+	buf = &bufq->rx_buf.buf[buf_id];
+	page_info = &buf->page_info[buf->page_indx];
+	if (bufq->rx_hsplit_en)
+		splitq_rx_desc->hdr_addr = cpu_to_le64(bufq->rx_buf.hdr_buf[buf_id]->pa);
+
+	splitq_rx_desc->pkt_addr = cpu_to_le64(page_info->dma +
+					       page_info->page_offset);
+	splitq_rx_desc->qword0.buf_id = cpu_to_le16(buf_id);
+
+	nta++;
+	if (unlikely(nta == bufq->desc_count))
+		nta = 0;
+	bufq->next_to_alloc = nta;
+}
+
+/**
+ * iecm_rx_post_init_bufs - Post initial buffers to bufq
+ * @bufq: buffer queue to post working set to
+ * @working_set: number of buffers to put in working set
+ */
+static void iecm_rx_post_init_bufs(struct iecm_queue *bufq,
+				   u16 working_set)
+{
+	int i;
+
+	for (i = 0; i < working_set; i++)
+		iecm_rx_post_buf_desc(bufq, i);
+
+	iecm_rx_buf_hw_update(bufq, bufq->next_to_alloc & ~(bufq->rx_buf_stride - 1));
+}
+
+/**
+ * iecm_rx_buf_alloc_all - Allocate memory for all buffer resources
+ * @rxbufq: queue for which the buffers are allocated; equivalent to
+ * rxq when operating in singleq mode
+ *
+ * Returns 0 on success, negative on failure
+ */
+static int iecm_rx_buf_alloc_all(struct iecm_queue *rxbufq)
+{
+	int err = 0;
+
+	/* Allocate book keeping buffers */
+	rxbufq->rx_buf.buf = kcalloc(rxbufq->desc_count,
+				     sizeof(struct iecm_rx_buf), GFP_KERNEL);
+	if (!rxbufq->rx_buf.buf) {
+		err = -ENOMEM;
+		goto rx_buf_alloc_all_out;
+	}
+
+	if (rxbufq->rx_hsplit_en) {
+		err = iecm_rx_hdr_buf_alloc_all(rxbufq);
+		if (err)
+			goto rx_buf_alloc_all_out;
+	}
+
+	/* Allocate buffers to be given to HW.	 */
+	if (iecm_is_queue_model_split(rxbufq->vport->rxq_model)) {
+		if (iecm_rx_buf_hw_alloc_all(rxbufq, rxbufq->desc_count - 1))
+			err = -ENOMEM;
+	} else {
+		if (iecm_rx_singleq_buf_hw_alloc_all(rxbufq, rxbufq->desc_count - 1))
+			err = -ENOMEM;
+	}
+
+rx_buf_alloc_all_out:
+	if (err)
+		iecm_rx_buf_rel_all(rxbufq);
+	return err;
+}
+
+/**
+ * iecm_rx_desc_alloc - Allocate queue Rx resources
+ * @rxq: Rx queue for which the resources are setup
+ * @bufq: buffer or completion queue
+ * @q_model: single or split queue model
+ *
+ * Returns 0 on success, negative on failure
+ */
+static int iecm_rx_desc_alloc(struct iecm_queue *rxq, bool bufq, s32 q_model)
+{
+	struct device *dev = rxq->dev;
+
+	/* As both single and split descriptors are 32 byte, memory size
+	 * will be same for all three singleq_base rx, buf., splitq_base
+	 * rx. So pick anyone of them for size
+	 */
+	if (bufq) {
+		rxq->size = rxq->desc_count *
+			sizeof(struct virtchnl2_splitq_rx_buf_desc);
+	} else {
+		rxq->size = rxq->desc_count *
+			sizeof(union virtchnl2_rx_desc);
+	}
+
+	/* Allocate descriptors and also round up to nearest 4K */
+	rxq->size = ALIGN(rxq->size, 4096);
+	rxq->desc_ring = dmam_alloc_coherent(dev, rxq->size,
+					     &rxq->dma, GFP_KERNEL);
+	if (!rxq->desc_ring) {
+		dev_info(dev, "Unable to allocate memory for the Rx descriptor ring, size=%d\n",
+			 rxq->size);
+		return -ENOMEM;
+	}
+
+	rxq->next_to_alloc = 0;
+	rxq->next_to_clean = 0;
+	rxq->next_to_use = 0;
+	set_bit(__IECM_Q_GEN_CHK, rxq->flags);
+
+	/* Allocate buffers for a rx queue if the q_model is single OR if it
+	 * is a buffer queue in split queue model
+	 */
+	if (bufq || !iecm_is_queue_model_split(q_model)) {
+		int err = 0;
+
+		err = iecm_rx_buf_alloc_all(rxq);
+		if (err) {
+			iecm_rx_desc_rel(rxq, bufq, q_model);
+			return err;
+		}
+	}
+	return 0;
+}
+
+/**
+ * iecm_rx_desc_alloc_all - allocate all RX queues resources
+ * @vport: virtual port structure
+ *
+ * Returns 0 on success, negative on failure
+ */
+static int iecm_rx_desc_alloc_all(struct iecm_vport *vport)
+{
+	struct device *dev = &vport->adapter->pdev->dev;
+	struct iecm_rxq_group *rx_qgrp;
+	int i, j, num_rxq, working_set;
+	struct iecm_queue *q;
+	int err = 0;
+
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		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++) {
+			if (iecm_is_queue_model_split(vport->rxq_model))
+				q = &rx_qgrp->splitq.rxq_sets[j]->rxq;
+			else
+				q = rx_qgrp->singleq.rxqs[j];
+			err = iecm_rx_desc_alloc(q, false, vport->rxq_model);
+			if (err) {
+				dev_err(dev, "Memory allocation for Rx Queue %u failed\n",
+					i);
+				goto err_out;
+			}
+		}
+
+		if (iecm_is_queue_model_split(vport->rxq_model)) {
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++) {
+				q = &rx_qgrp->splitq.bufq_sets[j].bufq;
+				err = iecm_rx_desc_alloc(q, true,
+							 vport->rxq_model);
+				if (err) {
+					dev_err(dev, "Memory allocation for Rx Buffer Queue %u failed\n",
+						i);
+					goto err_out;
+				}
+
+				working_set = IECM_RX_BUFQ_WORKING_SET(q);
+				iecm_rx_post_init_bufs(q, working_set);
+			}
+		}
+	}
+err_out:
+	if (err)
+		iecm_rx_desc_rel_all(vport);
+	return err;
+}
+
 /**
  * iecm_txq_group_rel - Release all resources for txq groups
  * @vport: vport to release txq groups on
@@ -478,6 +1017,61 @@ static void iecm_txq_group_rel(struct iecm_vport *vport)
 	}
 }
 
+/**
+ * iecm_rxq_sw_queue_rel - Release software queue resources
+ * @rx_qgrp: rx queue group with software queues
+ */
+static void iecm_rxq_sw_queue_rel(struct iecm_rxq_group *rx_qgrp)
+{
+	int i, j;
+
+	for (i = 0; i < rx_qgrp->vport->num_bufqs_per_qgrp; i++) {
+		struct iecm_bufq_set *bufq_set = &rx_qgrp->splitq.bufq_sets[i];
+
+		for (j = 0; j < bufq_set->num_refillqs; j++) {
+			kfree(bufq_set->refillqs[j].ring);
+			bufq_set->refillqs[j].ring = NULL;
+		}
+		kfree(bufq_set->refillqs);
+		bufq_set->refillqs = NULL;
+	}
+}
+
+/**
+ * iecm_rxq_group_rel - Release all resources for rxq groups
+ * @vport: vport to release rxq groups on
+ */
+static void iecm_rxq_group_rel(struct iecm_vport *vport)
+{
+	if (vport->rxq_grps) {
+		int i;
+
+		for (i = 0; i < vport->num_rxq_grp; i++) {
+			struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+			int j, num_rxq;
+
+			if (iecm_is_queue_model_split(vport->rxq_model)) {
+				num_rxq = rx_qgrp->splitq.num_rxq_sets;
+				for (j = 0; j < num_rxq; j++) {
+					kfree(rx_qgrp->splitq.rxq_sets[j]);
+					rx_qgrp->splitq.rxq_sets[j] = NULL;
+				}
+				iecm_rxq_sw_queue_rel(rx_qgrp);
+				kfree(rx_qgrp->splitq.bufq_sets);
+				rx_qgrp->splitq.bufq_sets = NULL;
+			} else {
+				num_rxq = rx_qgrp->singleq.num_rxq;
+				for (j = 0; j < num_rxq; j++) {
+					kfree(rx_qgrp->singleq.rxqs[j]);
+					rx_qgrp->singleq.rxqs[j] = NULL;
+				}
+			}
+		}
+		kfree(vport->rxq_grps);
+		vport->rxq_grps = NULL;
+	}
+}
+
 /**
  * iecm_vport_queue_grp_rel_all - Release all queue groups
  * @vport: vport to release queue groups for
@@ -485,6 +1079,7 @@ static void iecm_txq_group_rel(struct iecm_vport *vport)
 static void iecm_vport_queue_grp_rel_all(struct iecm_vport *vport)
 {
 	iecm_txq_group_rel(vport);
+	iecm_rxq_group_rel(vport);
 }
 
 /**
@@ -496,6 +1091,7 @@ static void iecm_vport_queue_grp_rel_all(struct iecm_vport *vport)
 void iecm_vport_queues_rel(struct iecm_vport *vport)
 {
 	iecm_tx_desc_rel_all(vport);
+	iecm_rx_desc_rel_all(vport);
 	iecm_vport_queue_grp_rel_all(vport);
 
 	kfree(vport->txqs);
@@ -715,6 +1311,24 @@ void iecm_vport_calc_num_q_vec(struct iecm_vport *vport)
 }
 EXPORT_SYMBOL(iecm_vport_calc_num_q_vec);
 
+/**
+ * iecm_rxq_set_descids - set the descids supported by this queue
+ * @vport: virtual port data structure
+ * @q: rx queue for which descids are set
+ *
+ */
+static void iecm_rxq_set_descids(struct iecm_vport *vport, struct iecm_queue *q)
+{
+	if (vport->rxq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) {
+		q->rxdids = VIRTCHNL2_RXDID_1_FLEX_SPLITQ_M;
+	} else {
+		if (vport->base_rxd)
+			q->rxdids = VIRTCHNL2_RXDID_1_32B_BASE_M;
+		else
+			q->rxdids = VIRTCHNL2_RXDID_2_FLEX_SQ_NIC_M;
+	}
+}
+
 /**
  * iecm_set_vlan_tag_loc - set the tag location for a tx/rx queue
  * @adapter: adapter structure
@@ -827,6 +1441,152 @@ static int iecm_txq_group_alloc(struct iecm_vport *vport, int num_txq)
 	return err;
 }
 
+/**
+ * iecm_rxq_group_alloc - Allocate all rxq group resources
+ * @vport: vport to allocate rxq groups for
+ * @num_rxq: number of rxqs to allocate for each group
+ *
+ * Returns 0 on success, negative on failure
+ */
+static int iecm_rxq_group_alloc(struct iecm_vport *vport, int num_rxq)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_queue *q;
+	int i, k, err = 0;
+
+	vport->rxq_grps = kcalloc(vport->num_rxq_grp,
+				  sizeof(struct iecm_rxq_group), GFP_KERNEL);
+	if (!vport->rxq_grps)
+		return -ENOMEM;
+
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+		int j;
+
+		rx_qgrp->vport = vport;
+		if (iecm_is_queue_model_split(vport->rxq_model)) {
+			rx_qgrp->splitq.num_rxq_sets = num_rxq;
+
+			for (j = 0; j < num_rxq; j++) {
+				rx_qgrp->splitq.rxq_sets[j] =
+					kzalloc(sizeof(struct iecm_rxq_set),
+						GFP_KERNEL);
+				if (!rx_qgrp->splitq.rxq_sets[j]) {
+					err = -ENOMEM;
+					goto err_alloc;
+				}
+			}
+
+			rx_qgrp->splitq.bufq_sets = kcalloc(vport->num_bufqs_per_qgrp,
+							    sizeof(struct iecm_bufq_set),
+							    GFP_KERNEL);
+			if (!rx_qgrp->splitq.bufq_sets) {
+				err = -ENOMEM;
+				goto err_alloc;
+			}
+
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++) {
+				struct iecm_bufq_set *bufq_set =
+					&rx_qgrp->splitq.bufq_sets[j];
+				int swq_size = sizeof(struct iecm_sw_queue);
+
+				q = &rx_qgrp->splitq.bufq_sets[j].bufq;
+				q->dev = &adapter->pdev->dev;
+				q->desc_count = vport->bufq_desc_count[j];
+				q->vport = vport;
+				q->rxq_grp = rx_qgrp;
+				q->idx = j;
+				q->rx_buf_size = vport->bufq_size[j];
+				q->rx_buffer_low_watermark = IECM_LOW_WATERMARK;
+				q->rx_buf_stride = IECM_RX_BUF_STRIDE;
+
+				if (test_bit(__IECM_PRIV_FLAGS_HDR_SPLIT,
+					     adapter->config_data.user_flags)) {
+					q->rx_hsplit_en = true;
+					q->rx_hbuf_size = IECM_HDR_BUF_SIZE;
+				}
+
+				bufq_set->num_refillqs = num_rxq;
+				bufq_set->refillqs = kcalloc(num_rxq,
+							     swq_size,
+							     GFP_KERNEL);
+				if (!bufq_set->refillqs) {
+					err = -ENOMEM;
+					goto err_alloc;
+				}
+				for (k = 0; k < bufq_set->num_refillqs; k++) {
+					struct iecm_sw_queue *refillq =
+						&bufq_set->refillqs[k];
+
+					refillq->dev =
+						&vport->adapter->pdev->dev;
+					refillq->buf_size = q->rx_buf_size;
+					refillq->desc_count =
+						vport->bufq_desc_count[j];
+					set_bit(__IECM_Q_GEN_CHK,
+						refillq->flags);
+					set_bit(__IECM_RFLQ_GEN_CHK,
+						refillq->flags);
+					refillq->ring = kcalloc(refillq->desc_count,
+								sizeof(u16),
+								GFP_KERNEL);
+					if (!refillq->ring) {
+						err = -ENOMEM;
+						goto err_alloc;
+					}
+				}
+			}
+		} else {
+			rx_qgrp->singleq.num_rxq = num_rxq;
+			for (j = 0; j < num_rxq; j++) {
+				rx_qgrp->singleq.rxqs[j] =
+					kzalloc(sizeof(*rx_qgrp->singleq.rxqs[j]), GFP_KERNEL);
+				if (!rx_qgrp->singleq.rxqs[j]) {
+					err = -ENOMEM;
+					goto err_alloc;
+				}
+			}
+		}
+
+		for (j = 0; j < num_rxq; j++) {
+			if (iecm_is_queue_model_split(vport->rxq_model)) {
+				q = &rx_qgrp->splitq.rxq_sets[j]->rxq;
+				rx_qgrp->splitq.rxq_sets[j]->refillq0 =
+				      &rx_qgrp->splitq.bufq_sets[0].refillqs[j];
+				rx_qgrp->splitq.rxq_sets[j]->refillq1 =
+				      &rx_qgrp->splitq.bufq_sets[1].refillqs[j];
+
+				if (test_bit(__IECM_PRIV_FLAGS_HDR_SPLIT,
+					     adapter->config_data.user_flags)) {
+					q->rx_hsplit_en = true;
+					q->rx_hbuf_size = IECM_HDR_BUF_SIZE;
+				}
+			} else {
+				q = rx_qgrp->singleq.rxqs[j];
+			}
+			q->dev = &adapter->pdev->dev;
+			q->desc_count = vport->rxq_desc_count;
+			q->vport = vport;
+			q->rxq_grp = rx_qgrp;
+			q->idx = (i * num_rxq) + j;
+			/* In splitq mode, RXQ buffer size should be
+			 * set to that of the first buffer queue
+			 * associated with this RXQ
+			 */
+			q->rx_buf_size = vport->bufq_size[0];
+			q->rx_buffer_low_watermark = IECM_LOW_WATERMARK;
+			q->rx_max_pkt_size = vport->netdev->mtu +
+							IECM_PACKET_HDR_PAD;
+			iecm_rxq_set_descids(vport, q);
+			iecm_set_vlan_tag_loc(adapter, q);
+		}
+	}
+err_alloc:
+	if (err)
+		iecm_rxq_group_rel(vport);
+	return err;
+}
+
 /**
  * iecm_vport_queue_grp_alloc_all - Allocate all queue groups/resources
  * @vport: vport with qgrps to allocate
@@ -841,6 +1601,11 @@ static int iecm_vport_queue_grp_alloc_all(struct iecm_vport *vport)
 	iecm_vport_calc_numq_per_grp(vport, &num_txq, &num_rxq);
 
 	err = iecm_txq_group_alloc(vport, num_txq);
+	if (err)
+		goto err_out;
+
+	err = iecm_rxq_group_alloc(vport, num_rxq);
+err_out:
 	if (err)
 		iecm_vport_queue_grp_rel_all(vport);
 	return err;
@@ -866,6 +1631,10 @@ int iecm_vport_queues_alloc(struct iecm_vport *vport)
 	if (err)
 		goto err_out;
 
+	err = iecm_rx_desc_alloc_all(vport);
+	if (err)
+		goto err_out;
+
 	err = iecm_vport_init_fast_path_txqs(vport);
 	if (err)
 		goto err_out;
drivers/net/ethernet/intel/include/iecm_txrx.h +7 -0
index 44c20f8a2039..5e29148938fb 100644
@@ -198,6 +198,11 @@ struct iecm_page_info {
 	u16 pagecnt_bias;
 };
 
+struct iecm_rx_hdr_buf_pages {
+	u32 nr_pages;
+	struct iecm_page_info *pages;
+};
+
 struct iecm_rx_buf {
 #define IECM_RX_BUF_MAX_PAGES 2
 	struct iecm_page_info page_info[IECM_RX_BUF_MAX_PAGES];
@@ -498,6 +503,8 @@ struct iecm_queue {
 					 * with scatter-gather
 					 */
 	DECLARE_HASHTABLE(sched_buf_hash, 12);
+
+	struct iecm_rx_hdr_buf_pages hbuf_pages;
 } ____cacheline_internodealigned_in_smp;
 
 /* Software queues are used in splitq mode to manage buffers between rxq
Signature · 1 line
2.33.0
#44 lore raw

PATCH 10/19 iecm: alloc vport RX resources

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

Quoted 56 lines

This finishes what we need to do for open by adding RX resource allocations.

As noted in the TX alloc patch, the splitq model is unique in introducing the concept of queue groups, which also applies to RX, albeit in a slightly different way. For RX we also split the queue between descriptor handling and buffer handling. We have some number of RX completion queues associated with up to two buffer queues in a given queue group. Once buffers are cleaned and recycled, they're given the buffer queues which then posts the buffers back to hardware. To enable this in a lockless way, there's also the concept of 'refill queues' introduced. Recycled buffers are put onto refill queues which is what the buffer queues clean to get buffers back.

---
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   | 769 ++++++++++++++++++
 .../net/ethernet/intel/include/iecm_txrx.h    |   7 +
 2 files changed, 776 insertions(+)
drivers/net/ethernet/intel/iecm/iecm_txrx.c +25 -0
index 85e88a30370d..fb6a61277b00 100644
@@ -452,6 +452,545 @@ static int iecm_tx_desc_alloc_all(struct iecm_vport *vport)
 	return err;
 }
 
+/**
+ * iecm_rx_page_rel - Release an rx buffer page
+ * @rxq: the queue that owns the buffer
+ * @page_info: pointer to page metadata of page to be freed
+ */
+static void iecm_rx_page_rel(struct iecm_queue *rxq,
+			     struct iecm_page_info *page_info)
+{
+	if (!page_info->page)
+		return;
+
+	/* free resources associated with mapping */
+	dma_unmap_page_attrs(rxq->dev, page_info->dma, PAGE_SIZE,
+			     DMA_FROM_DEVICE, IECM_RX_DMA_ATTR);
+
+	__page_frag_cache_drain(page_info->page, page_info->pagecnt_bias);
+
+	page_info->page = NULL;
+	page_info->page_offset = 0;
+}
+
+/**
+ * iecm_rx_buf_rel - Release a rx buffer
+ * @rxq: the queue that owns the buffer
+ * @rx_buf: the buffer to free

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 489

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+ */
+static void iecm_rx_buf_rel(struct iecm_queue *rxq,
+			    struct iecm_rx_buf *rx_buf)
+{
+	iecm_rx_page_rel(rxq, &rx_buf->page_info[0]);
+#if (PAGE_SIZE < 8192)
+	if (rx_buf->buf_size > IECM_RX_BUF_2048)
+		iecm_rx_page_rel(rxq, &rx_buf->page_info[1]);
+
+#endif

PAGE_SIZE is always defined, thus can be embedded in an if statement.

	if (PAGE_SIZE < 8192 && rx_buf ...)

will produce the same code, but without ifdeffery.

Quoted 21 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +21 -0
+	if (rx_buf->skb) {
+		dev_kfree_skb_any(rx_buf->skb);
+		rx_buf->skb = NULL;
+	}
+}
+
+/**
+ * iecm_rx_hdr_buf_rel_all - Release header buffer memory
+ * @rxq: queue to use
+ */
+static void iecm_rx_hdr_buf_rel_all(struct iecm_queue *rxq)
+{
+	struct iecm_hw *hw = &rxq->vport->adapter->hw;
+	int i;
+
+	if (!rxq)
+		return;
+
+	if (rxq->rx_buf.hdr_buf) {
+		for (i = 0; i < rxq->desc_count; i++) {
+			struct iecm_dma_mem *hbuf = rxq->rx_buf.hdr_buf[i];

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 520

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+
+			if (hbuf) {
+				iecm_free_dma_mem(hw, hbuf);
+				kfree(hbuf);
+			}
+			rxq->rx_buf.hdr_buf[i] = NULL;
+		}
+		kfree(rxq->rx_buf.hdr_buf);
+		rxq->rx_buf.hdr_buf = NULL;
+	}
	if (!hdr_buf)
		goto release_pages;

-1 indent level.

Quoted 50 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +50 -0
+
+	for (i = 0; i < rxq->hbuf_pages.nr_pages; i++)
+		iecm_rx_page_rel(rxq, &rxq->hbuf_pages.pages[i]);
+
+	kfree(rxq->hbuf_pages.pages);
+}
+
+/**
+ * iecm_rx_buf_rel_all - Free all Rx buffer resources for a queue
+ * @rxq: queue to be cleaned
+ */
+static void iecm_rx_buf_rel_all(struct iecm_queue *rxq)
+{
+	u16 i;
+
+	/* queue already cleared, nothing to do */
+	if (!rxq->rx_buf.buf)
+		return;
+
+	/* Free all the bufs allocated and given to hw on Rx queue */
+	for (i = 0; i < rxq->desc_count; i++)
+		iecm_rx_buf_rel(rxq, &rxq->rx_buf.buf[i]);
+	if (rxq->rx_hsplit_en)
+		iecm_rx_hdr_buf_rel_all(rxq);
+
+	kfree(rxq->rx_buf.buf);
+	rxq->rx_buf.buf = NULL;
+	kfree(rxq->rx_buf.hdr_buf);
+	rxq->rx_buf.hdr_buf = NULL;
+}
+
+/**
+ * iecm_rx_desc_rel - Free a specific Rx q resources
+ * @rxq: queue to clean the resources from
+ * @bufq: buffer q or completion q
+ * @q_model: single or split q model
+ *
+ * Free a specific rx queue resources
+ */
+static void iecm_rx_desc_rel(struct iecm_queue *rxq, bool bufq, s32 q_model)
+{
+	if (!rxq)
+		return;
+
+	if (!bufq && iecm_is_queue_model_split(q_model) && rxq->skb) {
+		dev_kfree_skb_any(rxq->skb);
+		rxq->skb = NULL;
+	}
+
+	if (bufq || !iecm_is_queue_model_split(q_model))

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 580

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+		iecm_rx_buf_rel_all(rxq);
+
+	if (rxq->desc_ring) {
+		dmam_free_coherent(rxq->dev, rxq->size,
+				   rxq->desc_ring, rxq->dma);
+		rxq->desc_ring = NULL;
+		rxq->next_to_alloc = 0;
+		rxq->next_to_clean = 0;
+		rxq->next_to_use = 0;
+	}
	if (!desc_ring)
		return;

Same.

Quoted 82 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +82 -0
+}
+
+/**
+ * iecm_rx_desc_rel_all - Free Rx Resources for All Queues
+ * @vport: virtual port structure
+ *
+ * Free all rx queues resources
+ */
+static void iecm_rx_desc_rel_all(struct iecm_vport *vport)
+{
+	struct iecm_rxq_group *rx_qgrp;
+	struct iecm_queue *q;
+	int i, j, num_rxq;
+
+	if (!vport->rxq_grps)
+		return;
+
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		rx_qgrp = &vport->rxq_grps[i];
+
+		if (iecm_is_queue_model_split(vport->rxq_model)) {
+			num_rxq = rx_qgrp->splitq.num_rxq_sets;
+			for (j = 0; j < num_rxq; j++) {
+				q = &rx_qgrp->splitq.rxq_sets[j]->rxq;
+				iecm_rx_desc_rel(q, false,
+						 vport->rxq_model);
+			}
+
+			if (!rx_qgrp->splitq.bufq_sets)
+				continue;
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++) {
+				struct iecm_bufq_set *bufq_set =
+					&rx_qgrp->splitq.bufq_sets[j];
+
+				q = &bufq_set->bufq;
+				iecm_rx_desc_rel(q, true, vport->rxq_model);
+			}
+		} else {
+			for (j = 0; j < rx_qgrp->singleq.num_rxq; j++) {
+				q = rx_qgrp->singleq.rxqs[j];
+				iecm_rx_desc_rel(q, false,
+						 vport->rxq_model);
+			}
+		}
+	}
+}
+
+/**
+ * iecm_rx_buf_hw_update - Store the new tail and head values
+ * @rxq: queue to bump
+ * @val: new head index
+ */
+void iecm_rx_buf_hw_update(struct iecm_queue *rxq, u32 val)
+{
+	rxq->next_to_use = val;
+
+	if (unlikely(!rxq->tail))
+		return;
+	/* writel has an implicit memory barrier */
+	writel(val, rxq->tail);
+}
+
+/**
+ * iecm_alloc_page - allocate page to back RX buffer
+ * @rxbufq: pointer to queue struct
+ * @page_info: pointer to page metadata struct
+ */
+static int
+iecm_alloc_page(struct iecm_queue *rxbufq, struct iecm_page_info *page_info)
+{
+	/* alloc new page for storage */
+	page_info->page = alloc_page(GFP_ATOMIC | __GFP_NOWARN);
+	if (unlikely(!page_info->page))
+		return -ENOMEM;
+
+	/* map page for use */
+	page_info->dma = dma_map_page_attrs(rxbufq->dev, page_info->page,
+					    0, PAGE_SIZE, DMA_FROM_DEVICE,
+					    IECM_RX_DMA_ATTR);
+
+	/* if mapping failed free memory back to system since
+	 * there isn't much point in holding memory we can't use

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 672

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+	 */
+	if (dma_mapping_error(rxbufq->dev, page_info->dma)) {
+		__free_pages(page_info->page, 0);
+		return -ENOMEM;
+	}
+
+	page_info->page_offset = 0;
+
+	/* initialize pagecnt_bias to claim we fully own page */
+	page_ref_add(page_info->page, USHRT_MAX - 1);

Too many references to page_info->page, could be optimized by placing *page onstack and then assigning page_info->page later.

Quoted 13 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +13 -0
+	page_info->pagecnt_bias = USHRT_MAX;
+
+	return 0;
+}
+
+/**
+ * iecm_init_rx_buf_hw_alloc - allocate initial RX buffer pages
+ * @rxbufq: ring to use; equivalent to rxq when operating in singleq mode
+ * @buf: rx_buffer struct to modify
+ *
+ * Returns true if the page was successfully allocated or
+ * reused.
+ */

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 695

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+bool iecm_init_rx_buf_hw_alloc(struct iecm_queue *rxbufq, struct iecm_rx_buf *buf)
+{
+	if (iecm_alloc_page(rxbufq, &buf->page_info[0]))
+		return false;
+
+#if (PAGE_SIZE < 8192)
+	if (rxbufq->rx_buf_size > IECM_RX_BUF_2048)
+		if (iecm_alloc_page(rxbufq, &buf->page_info[1]))
+			return false;
+#endif

Same here with embedding the check.

Quoted 34 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +34 -0
+
+	buf->page_indx = 0;
+	buf->buf_size = rxbufq->rx_buf_size;
+
+	return true;
+}
+
+/**
+ * iecm_rx_hdr_buf_alloc_all - Allocate memory for header buffers
+ * @rxq: ring to use
+ *
+ * Returns 0 on success, negative on failure.
+ */
+static int iecm_rx_hdr_buf_alloc_all(struct iecm_queue *rxq)
+{
+	struct iecm_page_info *page_info;
+	int nr_pages, offset;
+	int i, j = 0;
+
+	rxq->rx_buf.hdr_buf = kcalloc(rxq->desc_count,
+				      sizeof(struct iecm_dma_mem *),
+				      GFP_KERNEL);
+	if (!rxq->rx_buf.hdr_buf)
+		return -ENOMEM;
+
+	for (i = 0; i < rxq->desc_count; i++) {
+		rxq->rx_buf.hdr_buf[i] = kcalloc(1,
+						 sizeof(struct iecm_dma_mem),
+						 GFP_KERNEL);
+		if (!rxq->rx_buf.hdr_buf[i])
+			goto unroll_buf_alloc;
+	}
+
+	/* Determine the number of pages necessary to back the total number of header buffers */

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 739

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+	nr_pages = (rxq->desc_count * rxq->rx_hbuf_size) / PAGE_SIZE;
+	rxq->hbuf_pages.pages = kcalloc(nr_pages,
+					sizeof(struct iecm_page_info),
+					GFP_KERNEL);
+	if (!rxq->hbuf_pages.pages)
+		goto unroll_buf_alloc;
+
+	rxq->hbuf_pages.nr_pages = nr_pages;
+	for (i = 0; i < nr_pages; i++) {
+		if (iecm_alloc_page(rxq, &rxq->hbuf_pages.pages[i]))

And here you allocate pages with GFP_ATOMIC in process context. Atomic allocations must not be used if the function may sleep. Please add gfp_t gfp argument to iecm_alloc_page() and use GFP_KERNEL here (and GFP_ATOMIC on buffer refill hotpath).

Quoted 40 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +40 -0
+			goto unroll_buf_alloc;
+	}
+
+	page_info = &rxq->hbuf_pages.pages[0];
+	for (i = 0, offset = 0; i < rxq->desc_count; i++, offset += rxq->rx_hbuf_size) {
+		struct iecm_dma_mem *hbuf = rxq->rx_buf.hdr_buf[i];
+
+		/* Move to next page */
+		if (offset >= PAGE_SIZE) {
+			offset = 0;
+			page_info = &rxq->hbuf_pages.pages[++j];
+		}
+
+		hbuf->va = page_address(page_info->page) + offset;
+		hbuf->pa = page_info->dma + offset;
+		hbuf->size = rxq->rx_hbuf_size;
+	}
+
+	return 0;
+unroll_buf_alloc:
+	iecm_rx_hdr_buf_rel_all(rxq);
+	return -ENOMEM;
+}
+
+/**
+ * iecm_rx_buf_hw_alloc_all - Allocate receive buffers
+ * @rxbufq: queue for which the hw buffers are allocated; equivalent to rxq
+ * when operating in singleq mode
+ * @alloc_count: number of buffers to allocate
+ *
+ * Returns false if all allocations were successful, true if any fail
+ */
+static bool
+iecm_rx_buf_hw_alloc_all(struct iecm_queue *rxbufq, u16 alloc_count)
+{
+	u16 nta = rxbufq->next_to_alloc;
+	struct iecm_rx_buf *buf;
+
+	if (!alloc_count)
+		return false;

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 789

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+
+	buf = &rxbufq->rx_buf.buf[nta];
+
+	do {
+		if (!iecm_init_rx_buf_hw_alloc(rxbufq, buf))
+			break;
+
+		buf++;
+		nta++;
+		if (unlikely(nta == rxbufq->desc_count)) {
		if (unlikely(++nta == ...)) { /* Just in one line */

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 795

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+			buf = rxbufq->rx_buf.buf;
+			nta = 0;
+		}
+
+		alloc_count--;
+	} while (alloc_count);
	} while (alloc_count--); /* Just in one line */
Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +11 -0
+
+	return !!alloc_count;
+}
+
+/**
+ * iecm_rx_post_buf_desc - Post buffer to bufq descriptor ring
+ * @bufq: buffer queue to post to
+ * @buf_id: buffer id to post
+ */
+static void iecm_rx_post_buf_desc(struct iecm_queue *bufq, u16 buf_id)
+{

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 816

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+	struct virtchnl2_splitq_rx_buf_desc *splitq_rx_desc = NULL;
+	struct iecm_page_info *page_info;
+	u16 nta = bufq->next_to_alloc;
+	struct iecm_rx_buf *buf;
+
+	splitq_rx_desc = IECM_SPLITQ_RX_BUF_DESC(bufq, nta);
+	buf = &bufq->rx_buf.buf[buf_id];
+	page_info = &buf->page_info[buf->page_indx];
+	if (bufq->rx_hsplit_en)
+		splitq_rx_desc->hdr_addr = cpu_to_le64(bufq->rx_buf.hdr_buf[buf_id]->pa);

90-cols line.

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 824

Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +8 -0
+
+	splitq_rx_desc->pkt_addr = cpu_to_le64(page_info->dma +
+					       page_info->page_offset);
+	splitq_rx_desc->qword0.buf_id = cpu_to_le16(buf_id);
+
+	nta++;
+	if (unlikely(nta == bufq->desc_count))
+		nta = 0;

Post-increment can be embedded into a condition check (with converting into a pre-increment obviously).

Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +7 -0
+	bufq->next_to_alloc = nta;
+}
+
+/**
+ * iecm_rx_post_init_bufs - Post initial buffers to bufq
+ * @bufq: buffer queue to post working set to
+ * @working_set: number of buffers to put in working set

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 841

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+ */
+static void iecm_rx_post_init_bufs(struct iecm_queue *bufq,
+				   u16 working_set)
+{
+	int i;
+
+	for (i = 0; i < working_set; i++)
+		iecm_rx_post_buf_desc(bufq, i);
+
+	iecm_rx_buf_hw_update(bufq, bufq->next_to_alloc & ~(bufq->rx_buf_stride - 1));

87-cols line.
Please test all your patches with checkpatch --strict --codespell.

Quoted 55 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +55 -0
+}
+
+/**
+ * iecm_rx_buf_alloc_all - Allocate memory for all buffer resources
+ * @rxbufq: queue for which the buffers are allocated; equivalent to
+ * rxq when operating in singleq mode
+ *
+ * Returns 0 on success, negative on failure
+ */
+static int iecm_rx_buf_alloc_all(struct iecm_queue *rxbufq)
+{
+	int err = 0;
+
+	/* Allocate book keeping buffers */
+	rxbufq->rx_buf.buf = kcalloc(rxbufq->desc_count,
+				     sizeof(struct iecm_rx_buf), GFP_KERNEL);
+	if (!rxbufq->rx_buf.buf) {
+		err = -ENOMEM;
+		goto rx_buf_alloc_all_out;
+	}
+
+	if (rxbufq->rx_hsplit_en) {
+		err = iecm_rx_hdr_buf_alloc_all(rxbufq);
+		if (err)
+			goto rx_buf_alloc_all_out;
+	}
+
+	/* Allocate buffers to be given to HW.	 */
+	if (iecm_is_queue_model_split(rxbufq->vport->rxq_model)) {
+		if (iecm_rx_buf_hw_alloc_all(rxbufq, rxbufq->desc_count - 1))
+			err = -ENOMEM;
+	} else {
+		if (iecm_rx_singleq_buf_hw_alloc_all(rxbufq, rxbufq->desc_count - 1))
+			err = -ENOMEM;
+	}
+
+rx_buf_alloc_all_out:
+	if (err)
+		iecm_rx_buf_rel_all(rxbufq);
+	return err;
+}
+
+/**
+ * iecm_rx_desc_alloc - Allocate queue Rx resources
+ * @rxq: Rx queue for which the resources are setup
+ * @bufq: buffer or completion queue
+ * @q_model: single or split queue model
+ *
+ * Returns 0 on success, negative on failure
+ */
+static int iecm_rx_desc_alloc(struct iecm_queue *rxq, bool bufq, s32 q_model)
+{
+	struct device *dev = rxq->dev;
+
+	/* As both single and split descriptors are 32 byte, memory size

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 906

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+	 * will be same for all three singleq_base rx, buf., splitq_base
+	 * rx. So pick anyone of them for size
+	 */
+	if (bufq) {
+		rxq->size = rxq->desc_count *
+			sizeof(struct virtchnl2_splitq_rx_buf_desc);
+	} else {
+		rxq->size = rxq->desc_count *
+			sizeof(union virtchnl2_rx_desc);
+	}

Oneliners, braces are unneeded.

For counting the array sizes it's required to use array_size():

	rxq->size = array_size(rxq->desc_count, sizeof(...));
	if (unlikely(rxq->size == -EOVERFLOW))
		/* Error path */

There are more such places in the code, I couldn't catch them all.

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 909

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
+
+	/* Allocate descriptors and also round up to nearest 4K */
+	rxq->size = ALIGN(rxq->size, 4096);

4096 = SZ_4K, no need to open-code.

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 920

Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +11 -0
+	rxq->desc_ring = dmam_alloc_coherent(dev, rxq->size,
+					     &rxq->dma, GFP_KERNEL);
+	if (!rxq->desc_ring) {
+		dev_info(dev, "Unable to allocate memory for the Rx descriptor ring, size=%d\n",
+			 rxq->size);
+		return -ENOMEM;
+	}
+
+	rxq->next_to_alloc = 0;
+	rxq->next_to_clean = 0;
+	rxq->next_to_use = 0;

You allocate rxq with kzalloc() (or derivative) IIRC, 'z'-versions zero the memory before returning. These initializers are redundant.

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +4 -0
+	set_bit(__IECM_Q_GEN_CHK, rxq->flags);
+
+	/* Allocate buffers for a rx queue if the q_model is single OR if it
+	 * is a buffer queue in split queue model

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 934

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+	 */
+	if (bufq || !iecm_is_queue_model_split(q_model)) {
+		int err = 0;
+
+		err = iecm_rx_buf_alloc_all(rxq);
+		if (err) {
+			iecm_rx_desc_rel(rxq, bufq, q_model);
+			return err;
+		}
+	}
	if (inverse_the_condition_above)
		return 0;

	err = ...

-1 indent level.

Quoted 109 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +102 -0
+	return 0;
+}
+
+/**
+ * iecm_rx_desc_alloc_all - allocate all RX queues resources
+ * @vport: virtual port structure
+ *
+ * Returns 0 on success, negative on failure
+ */
+static int iecm_rx_desc_alloc_all(struct iecm_vport *vport)
+{
+	struct device *dev = &vport->adapter->pdev->dev;
+	struct iecm_rxq_group *rx_qgrp;
+	int i, j, num_rxq, working_set;
+	struct iecm_queue *q;
+	int err = 0;
+
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		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++) {
+			if (iecm_is_queue_model_split(vport->rxq_model))
+				q = &rx_qgrp->splitq.rxq_sets[j]->rxq;
+			else
+				q = rx_qgrp->singleq.rxqs[j];
+			err = iecm_rx_desc_alloc(q, false, vport->rxq_model);
+			if (err) {
+				dev_err(dev, "Memory allocation for Rx Queue %u failed\n",
+					i);
+				goto err_out;
+			}
+		}
+
+		if (iecm_is_queue_model_split(vport->rxq_model)) {
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++) {
+				q = &rx_qgrp->splitq.bufq_sets[j].bufq;
+				err = iecm_rx_desc_alloc(q, true,
+							 vport->rxq_model);
+				if (err) {
+					dev_err(dev, "Memory allocation for Rx Buffer Queue %u failed\n",
+						i);
+					goto err_out;
+				}
+
+				working_set = IECM_RX_BUFQ_WORKING_SET(q);
+				iecm_rx_post_init_bufs(q, working_set);
+			}
+		}
+	}
+err_out:
+	if (err)
+		iecm_rx_desc_rel_all(vport);
+	return err;
+}
+
 /**
  * iecm_txq_group_rel - Release all resources for txq groups
  * @vport: vport to release txq groups on
@@ -478,6 +1017,61 @@ static void iecm_txq_group_rel(struct iecm_vport *vport)
 	}
 }
 
+/**
+ * iecm_rxq_sw_queue_rel - Release software queue resources
+ * @rx_qgrp: rx queue group with software queues
+ */
+static void iecm_rxq_sw_queue_rel(struct iecm_rxq_group *rx_qgrp)
+{
+	int i, j;
+
+	for (i = 0; i < rx_qgrp->vport->num_bufqs_per_qgrp; i++) {
+		struct iecm_bufq_set *bufq_set = &rx_qgrp->splitq.bufq_sets[i];
+
+		for (j = 0; j < bufq_set->num_refillqs; j++) {
+			kfree(bufq_set->refillqs[j].ring);
+			bufq_set->refillqs[j].ring = NULL;
+		}
+		kfree(bufq_set->refillqs);
+		bufq_set->refillqs = NULL;
+	}
+}
+
+/**
+ * iecm_rxq_group_rel - Release all resources for rxq groups
+ * @vport: vport to release rxq groups on
+ */
+static void iecm_rxq_group_rel(struct iecm_vport *vport)
+{
+	if (vport->rxq_grps) {
+		int i;
+
+		for (i = 0; i < vport->num_rxq_grp; i++) {
+			struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+			int j, num_rxq;
+
+			if (iecm_is_queue_model_split(vport->rxq_model)) {
+				num_rxq = rx_qgrp->splitq.num_rxq_sets;
+				for (j = 0; j < num_rxq; j++) {
+					kfree(rx_qgrp->splitq.rxq_sets[j]);
+					rx_qgrp->splitq.rxq_sets[j] = NULL;
+				}
+				iecm_rxq_sw_queue_rel(rx_qgrp);
+				kfree(rx_qgrp->splitq.bufq_sets);
+				rx_qgrp->splitq.bufq_sets = NULL;
+			} else {

drivers/net/ethernet/intel/iecm/iecm_txrx.c static void iecm_txq_group_rel(struct iecm_vport *vport) · line 1072

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+				num_rxq = rx_qgrp->singleq.num_rxq;
+				for (j = 0; j < num_rxq; j++) {
+					kfree(rx_qgrp->singleq.rxqs[j]);
+					rx_qgrp->singleq.rxqs[j] = NULL;
+				}
+			}
+		}
+		kfree(vport->rxq_grps);
+		vport->rxq_grps = NULL;
+	}
	if (!rxq_grps)
		return;

-1 lvl.

Quoted 227 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +177 -0
+}
+
 /**
  * iecm_vport_queue_grp_rel_all - Release all queue groups
  * @vport: vport to release queue groups for
@@ -485,6 +1079,7 @@ static void iecm_txq_group_rel(struct iecm_vport *vport)
 static void iecm_vport_queue_grp_rel_all(struct iecm_vport *vport)
 {
 	iecm_txq_group_rel(vport);
+	iecm_rxq_group_rel(vport);
 }
 
 /**
@@ -496,6 +1091,7 @@ static void iecm_vport_queue_grp_rel_all(struct iecm_vport *vport)
 void iecm_vport_queues_rel(struct iecm_vport *vport)
 {
 	iecm_tx_desc_rel_all(vport);
+	iecm_rx_desc_rel_all(vport);
 	iecm_vport_queue_grp_rel_all(vport);
 
 	kfree(vport->txqs);
@@ -715,6 +1311,24 @@ void iecm_vport_calc_num_q_vec(struct iecm_vport *vport)
 }
 EXPORT_SYMBOL(iecm_vport_calc_num_q_vec);
 
+/**
+ * iecm_rxq_set_descids - set the descids supported by this queue
+ * @vport: virtual port data structure
+ * @q: rx queue for which descids are set
+ *
+ */
+static void iecm_rxq_set_descids(struct iecm_vport *vport, struct iecm_queue *q)
+{
+	if (vport->rxq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) {
+		q->rxdids = VIRTCHNL2_RXDID_1_FLEX_SPLITQ_M;
+	} else {
+		if (vport->base_rxd)
+			q->rxdids = VIRTCHNL2_RXDID_1_32B_BASE_M;
+		else
+			q->rxdids = VIRTCHNL2_RXDID_2_FLEX_SQ_NIC_M;
+	}
+}
+
 /**
  * iecm_set_vlan_tag_loc - set the tag location for a tx/rx queue
  * @adapter: adapter structure
@@ -827,6 +1441,152 @@ static int iecm_txq_group_alloc(struct iecm_vport *vport, int num_txq)
 	return err;
 }
 
+/**
+ * iecm_rxq_group_alloc - Allocate all rxq group resources
+ * @vport: vport to allocate rxq groups for
+ * @num_rxq: number of rxqs to allocate for each group
+ *
+ * Returns 0 on success, negative on failure
+ */
+static int iecm_rxq_group_alloc(struct iecm_vport *vport, int num_rxq)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_queue *q;
+	int i, k, err = 0;
+
+	vport->rxq_grps = kcalloc(vport->num_rxq_grp,
+				  sizeof(struct iecm_rxq_group), GFP_KERNEL);
+	if (!vport->rxq_grps)
+		return -ENOMEM;
+
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+		int j;
+
+		rx_qgrp->vport = vport;
+		if (iecm_is_queue_model_split(vport->rxq_model)) {
+			rx_qgrp->splitq.num_rxq_sets = num_rxq;
+
+			for (j = 0; j < num_rxq; j++) {
+				rx_qgrp->splitq.rxq_sets[j] =
+					kzalloc(sizeof(struct iecm_rxq_set),
+						GFP_KERNEL);
+				if (!rx_qgrp->splitq.rxq_sets[j]) {
+					err = -ENOMEM;
+					goto err_alloc;
+				}
+			}
+
+			rx_qgrp->splitq.bufq_sets = kcalloc(vport->num_bufqs_per_qgrp,
+							    sizeof(struct iecm_bufq_set),
+							    GFP_KERNEL);
+			if (!rx_qgrp->splitq.bufq_sets) {
+				err = -ENOMEM;
+				goto err_alloc;
+			}
+
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++) {
+				struct iecm_bufq_set *bufq_set =
+					&rx_qgrp->splitq.bufq_sets[j];
+				int swq_size = sizeof(struct iecm_sw_queue);
+
+				q = &rx_qgrp->splitq.bufq_sets[j].bufq;
+				q->dev = &adapter->pdev->dev;
+				q->desc_count = vport->bufq_desc_count[j];
+				q->vport = vport;
+				q->rxq_grp = rx_qgrp;
+				q->idx = j;
+				q->rx_buf_size = vport->bufq_size[j];
+				q->rx_buffer_low_watermark = IECM_LOW_WATERMARK;
+				q->rx_buf_stride = IECM_RX_BUF_STRIDE;
+
+				if (test_bit(__IECM_PRIV_FLAGS_HDR_SPLIT,
+					     adapter->config_data.user_flags)) {
+					q->rx_hsplit_en = true;
+					q->rx_hbuf_size = IECM_HDR_BUF_SIZE;
+				}
+
+				bufq_set->num_refillqs = num_rxq;
+				bufq_set->refillqs = kcalloc(num_rxq,
+							     swq_size,
+							     GFP_KERNEL);
+				if (!bufq_set->refillqs) {
+					err = -ENOMEM;
+					goto err_alloc;
+				}
+				for (k = 0; k < bufq_set->num_refillqs; k++) {
+					struct iecm_sw_queue *refillq =
+						&bufq_set->refillqs[k];
+
+					refillq->dev =
+						&vport->adapter->pdev->dev;
+					refillq->buf_size = q->rx_buf_size;
+					refillq->desc_count =
+						vport->bufq_desc_count[j];
+					set_bit(__IECM_Q_GEN_CHK,
+						refillq->flags);
+					set_bit(__IECM_RFLQ_GEN_CHK,
+						refillq->flags);
+					refillq->ring = kcalloc(refillq->desc_count,
+								sizeof(u16),
+								GFP_KERNEL);
+					if (!refillq->ring) {
+						err = -ENOMEM;
+						goto err_alloc;
+					}
+				}
+			}
+		} else {
+			rx_qgrp->singleq.num_rxq = num_rxq;
+			for (j = 0; j < num_rxq; j++) {
+				rx_qgrp->singleq.rxqs[j] =
+					kzalloc(sizeof(*rx_qgrp->singleq.rxqs[j]), GFP_KERNEL);
+				if (!rx_qgrp->singleq.rxqs[j]) {
+					err = -ENOMEM;
+					goto err_alloc;
+				}
+			}
+		}
+
+		for (j = 0; j < num_rxq; j++) {
+			if (iecm_is_queue_model_split(vport->rxq_model)) {
+				q = &rx_qgrp->splitq.rxq_sets[j]->rxq;
+				rx_qgrp->splitq.rxq_sets[j]->refillq0 =
+				      &rx_qgrp->splitq.bufq_sets[0].refillqs[j];
+				rx_qgrp->splitq.rxq_sets[j]->refillq1 =
+				      &rx_qgrp->splitq.bufq_sets[1].refillqs[j];
+
+				if (test_bit(__IECM_PRIV_FLAGS_HDR_SPLIT,
+					     adapter->config_data.user_flags)) {
+					q->rx_hsplit_en = true;
+					q->rx_hbuf_size = IECM_HDR_BUF_SIZE;
+				}
+			} else {
+				q = rx_qgrp->singleq.rxqs[j];
+			}
+			q->dev = &adapter->pdev->dev;
+			q->desc_count = vport->rxq_desc_count;
+			q->vport = vport;
+			q->rxq_grp = rx_qgrp;
+			q->idx = (i * num_rxq) + j;
+			/* In splitq mode, RXQ buffer size should be
+			 * set to that of the first buffer queue
+			 * associated with this RXQ
+			 */
+			q->rx_buf_size = vport->bufq_size[0];
+			q->rx_buffer_low_watermark = IECM_LOW_WATERMARK;
+			q->rx_max_pkt_size = vport->netdev->mtu +
+							IECM_PACKET_HDR_PAD;
+			iecm_rxq_set_descids(vport, q);
+			iecm_set_vlan_tag_loc(adapter, q);
+		}
+	}
+err_alloc:
+	if (err)
+		iecm_rxq_group_rel(vport);
+	return err;
+}
+
 /**
  * iecm_vport_queue_grp_alloc_all - Allocate all queue groups/resources
  * @vport: vport with qgrps to allocate
@@ -841,6 +1601,11 @@ static int iecm_vport_queue_grp_alloc_all(struct iecm_vport *vport)
 	iecm_vport_calc_numq_per_grp(vport, &num_txq, &num_rxq);
 
 	err = iecm_txq_group_alloc(vport, num_txq);
+	if (err)
+		goto err_out;
+
+	err = iecm_rxq_group_alloc(vport, num_rxq);
+err_out:
 	if (err)
 		iecm_vport_queue_grp_rel_all(vport);
 	return err;
@@ -866,6 +1631,10 @@ int iecm_vport_queues_alloc(struct iecm_vport *vport)
 	if (err)
 		goto err_out;
 
+	err = iecm_rx_desc_alloc_all(vport);
+	if (err)
+		goto err_out;
+
 	err = iecm_vport_init_fast_path_txqs(vport);
 	if (err)
 		goto err_out;
drivers/net/ethernet/intel/include/iecm_txrx.h +0 -0
index 44c20f8a2039..5e29148938fb 100644

drivers/net/ethernet/intel/include/iecm_txrx.h struct iecm_page_info { · line 203

Quoted 6 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +3 -0
@@ -198,6 +198,11 @@ struct iecm_page_info {
 	u16 pagecnt_bias;
 };
 
+struct iecm_rx_hdr_buf_pages {
+	u32 nr_pages;
+	struct iecm_page_info *pages;

Place the pointer at the beginning to avoid gaps and alignment issues.

Quoted 16 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +4 -0
+};
+
 struct iecm_rx_buf {
 #define IECM_RX_BUF_MAX_PAGES 2
 	struct iecm_page_info page_info[IECM_RX_BUF_MAX_PAGES];
@@ -498,6 +503,8 @@ struct iecm_queue {
 					 * with scatter-gather
 					 */
 	DECLARE_HASHTABLE(sched_buf_hash, 12);
+
+	struct iecm_rx_hdr_buf_pages hbuf_pages;
 } ____cacheline_internodealigned_in_smp;
 
 /* Software queues are used in splitq mode to manage buffers between rxq
Signature · 1 line
2.33.0

Thanks,
Al

#45 lore raw

PATCH 10/19 iecm: alloc vport RX resources

Quoted 83 lines

-----Original Message-----
From: Lobakin, Alexandr <[email protected]>
Sent: Friday, January 28, 2022 6:16 AM
To: Brady, Alan <[email protected]>
Cc: Lobakin, Alexandr <[email protected]>; intel-wired-
lan at lists.osuosl.org; Burra, Phani R <[email protected]>; Chittim, Madhu <[email protected]>; Linga, Pavan Kumar <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net-next 10/19] iecm: alloc vport RX resources

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

Quoted 12 lines

This finishes what we need to do for open by adding RX resource allocations.

As noted in the TX alloc patch, the splitq model is unique in introducing the concept of queue groups, which also applies to RX, albeit in a slightly different way. For RX we also split the queue between descriptor handling and buffer handling. We have some number of RX completion queues associated with up to two buffer queues in a given queue group. Once buffers are cleaned and recycled, they're given the buffer queues which then posts the buffers back to hardware. To enable this in a lockless way, there's also the concept of 'refill queues' introduced. Recycled buffers are put onto refill queues which is what

the buffer queues clean to get buffers back.

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport

Quoted 17 lines
---
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   | 769 ++++++++++++++++++
 .../net/ethernet/intel/include/iecm_txrx.h    |   7 +
 2 files changed, 776 insertions(+)
drivers/net/ethernet/intel/iecm/iecm_txrx.c +0 -0
index 85e88a30370d..fb6a61277b00 100644
@@ -452,6 +452,545 @@ static int iecm_tx_desc_alloc_all(struct iecm_vport

*vport)

Quoted 25 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +22 -0
 	return err;
 }
 
+/**
+ * iecm_rx_page_rel - Release an rx buffer page
+ * @rxq: the queue that owns the buffer
+ * @page_info: pointer to page metadata of page to be freed  */
+static void iecm_rx_page_rel(struct iecm_queue *rxq,
+			     struct iecm_page_info *page_info) {
+	if (!page_info->page)
+		return;
+
+	/* free resources associated with mapping */
+	dma_unmap_page_attrs(rxq->dev, page_info->dma, PAGE_SIZE,
+			     DMA_FROM_DEVICE, IECM_RX_DMA_ATTR);
+
+	__page_frag_cache_drain(page_info->page, page_info->pagecnt_bias);
+
+	page_info->page = NULL;
+	page_info->page_offset = 0;
+}
+
+/**
+ * iecm_rx_buf_rel - Release a rx buffer
+ * @rxq: the queue that owns the buffer

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 489

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+ * @rx_buf: the buffer to free
+ */
+static void iecm_rx_buf_rel(struct iecm_queue *rxq,
+			    struct iecm_rx_buf *rx_buf)
+{
+	iecm_rx_page_rel(rxq, &rx_buf->page_info[0]); #if (PAGE_SIZE < 8192)
+	if (rx_buf->buf_size > IECM_RX_BUF_2048)
+		iecm_rx_page_rel(rxq, &rx_buf->page_info[1]);
+
+#endif

PAGE_SIZE is always defined, thus can be embedded in an if statement.

Quoted 4 lines
	if (PAGE_SIZE < 8192 && rx_buf ...)

will produce the same code, but without ifdeffery.

Will fix

Quoted 34 lines
Quoted 20 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +20 -0
+	if (rx_buf->skb) {
+		dev_kfree_skb_any(rx_buf->skb);
+		rx_buf->skb = NULL;
+	}
+}
+
+/**
+ * iecm_rx_hdr_buf_rel_all - Release header buffer memory
+ * @rxq: queue to use
+ */
+static void iecm_rx_hdr_buf_rel_all(struct iecm_queue *rxq) {
+	struct iecm_hw *hw = &rxq->vport->adapter->hw;
+	int i;
+
+	if (!rxq)
+		return;
+
+	if (rxq->rx_buf.hdr_buf) {
+		for (i = 0; i < rxq->desc_count; i++) {
+			struct iecm_dma_mem *hbuf = rxq->rx_buf.hdr_buf[i];

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 520

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+
+			if (hbuf) {
+				iecm_free_dma_mem(hw, hbuf);
+				kfree(hbuf);
+			}
+			rxq->rx_buf.hdr_buf[i] = NULL;
+		}
+		kfree(rxq->rx_buf.hdr_buf);
+		rxq->rx_buf.hdr_buf = NULL;
+	}
	if (!hdr_buf)
		goto release_pages;
Quoted 2 lines

-1 indent level.

Will fix

Quoted 147 lines
Quoted 47 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +47 -0
+
+	for (i = 0; i < rxq->hbuf_pages.nr_pages; i++)
+		iecm_rx_page_rel(rxq, &rxq->hbuf_pages.pages[i]);
+
+	kfree(rxq->hbuf_pages.pages);
+}
+
+/**
+ * iecm_rx_buf_rel_all - Free all Rx buffer resources for a queue
+ * @rxq: queue to be cleaned
+ */
+static void iecm_rx_buf_rel_all(struct iecm_queue *rxq) {
+	u16 i;
+
+	/* queue already cleared, nothing to do */
+	if (!rxq->rx_buf.buf)
+		return;
+
+	/* Free all the bufs allocated and given to hw on Rx queue */
+	for (i = 0; i < rxq->desc_count; i++)
+		iecm_rx_buf_rel(rxq, &rxq->rx_buf.buf[i]);
+	if (rxq->rx_hsplit_en)
+		iecm_rx_hdr_buf_rel_all(rxq);
+
+	kfree(rxq->rx_buf.buf);
+	rxq->rx_buf.buf = NULL;
+	kfree(rxq->rx_buf.hdr_buf);
+	rxq->rx_buf.hdr_buf = NULL;
+}
+
+/**
+ * iecm_rx_desc_rel - Free a specific Rx q resources
+ * @rxq: queue to clean the resources from
+ * @bufq: buffer q or completion q
+ * @q_model: single or split q model
+ *
+ * Free a specific rx queue resources  */ static void
+iecm_rx_desc_rel(struct iecm_queue *rxq, bool bufq, s32 q_model) {
+	if (!rxq)
+		return;
+
+	if (!bufq && iecm_is_queue_model_split(q_model) && rxq->skb) {
+		dev_kfree_skb_any(rxq->skb);
+		rxq->skb = NULL;
+	}
+
+	if (bufq || !iecm_is_queue_model_split(q_model))

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 580

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+		iecm_rx_buf_rel_all(rxq);
+
+	if (rxq->desc_ring) {
+		dmam_free_coherent(rxq->dev, rxq->size,
+				   rxq->desc_ring, rxq->dma);
+		rxq->desc_ring = NULL;
+		rxq->next_to_alloc = 0;
+		rxq->next_to_clean = 0;
+		rxq->next_to_use = 0;
+	}
	if (!desc_ring)
		return;

Same.

Quoted 84 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +83 -0
+}
+
+/**
+ * iecm_rx_desc_rel_all - Free Rx Resources for All Queues
+ * @vport: virtual port structure
+ *
+ * Free all rx queues resources
+ */
+static void iecm_rx_desc_rel_all(struct iecm_vport *vport) {
+	struct iecm_rxq_group *rx_qgrp;
+	struct iecm_queue *q;
+	int i, j, num_rxq;
+
+	if (!vport->rxq_grps)
+		return;
+
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		rx_qgrp = &vport->rxq_grps[i];
+
+		if (iecm_is_queue_model_split(vport->rxq_model)) {
+			num_rxq = rx_qgrp->splitq.num_rxq_sets;
+			for (j = 0; j < num_rxq; j++) {
+				q = &rx_qgrp->splitq.rxq_sets[j]->rxq;
+				iecm_rx_desc_rel(q, false,
+						 vport->rxq_model);
+			}
+
+			if (!rx_qgrp->splitq.bufq_sets)
+				continue;
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++) {
+				struct iecm_bufq_set *bufq_set =
+					&rx_qgrp->splitq.bufq_sets[j];
+
+				q = &bufq_set->bufq;
+				iecm_rx_desc_rel(q, true, vport->rxq_model);
+			}
+		} else {
+			for (j = 0; j < rx_qgrp->singleq.num_rxq; j++) {
+				q = rx_qgrp->singleq.rxqs[j];
+				iecm_rx_desc_rel(q, false,
+						 vport->rxq_model);
+			}
+		}
+	}
+}
+
+/**
+ * iecm_rx_buf_hw_update - Store the new tail and head values
+ * @rxq: queue to bump
+ * @val: new head index
+ */
+void iecm_rx_buf_hw_update(struct iecm_queue *rxq, u32 val) {
+	rxq->next_to_use = val;
+
+	if (unlikely(!rxq->tail))
+		return;
+	/* writel has an implicit memory barrier */
+	writel(val, rxq->tail);
+}
+
+/**
+ * iecm_alloc_page - allocate page to back RX buffer
+ * @rxbufq: pointer to queue struct
+ * @page_info: pointer to page metadata struct  */ static int
+iecm_alloc_page(struct iecm_queue *rxbufq, struct iecm_page_info
+*page_info) {
+	/* alloc new page for storage */
+	page_info->page = alloc_page(GFP_ATOMIC | __GFP_NOWARN);
+	if (unlikely(!page_info->page))
+		return -ENOMEM;
+
+	/* map page for use */
+	page_info->dma = dma_map_page_attrs(rxbufq->dev, page_info-
 page,
+					    0, PAGE_SIZE, DMA_FROM_DEVICE,
+					    IECM_RX_DMA_ATTR);
+
+	/* if mapping failed free memory back to system since
+	 * there isn't much point in holding memory we can't use
+	 */
+	if (dma_mapping_error(rxbufq->dev, page_info->dma)) {
+		__free_pages(page_info->page, 0);
+		return -ENOMEM;
+	}
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 672

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +5 -0
+
+	page_info->page_offset = 0;
+
+	/* initialize pagecnt_bias to claim we fully own page */
+	page_ref_add(page_info->page, USHRT_MAX - 1);

Too many references to page_info->page, could be optimized by placing *page onstack and then assigning page_info->page later.

Will fix

Quoted 62 lines
Quoted 14 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +14 -0
+	page_info->pagecnt_bias = USHRT_MAX;
+
+	return 0;
+}
+
+/**
+ * iecm_init_rx_buf_hw_alloc - allocate initial RX buffer pages
+ * @rxbufq: ring to use; equivalent to rxq when operating in singleq
+mode
+ * @buf: rx_buffer struct to modify
+ *
+ * Returns true if the page was successfully allocated or
+ * reused.
+ */

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 695

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+bool iecm_init_rx_buf_hw_alloc(struct iecm_queue *rxbufq, struct
+iecm_rx_buf *buf) {
+	if (iecm_alloc_page(rxbufq, &buf->page_info[0]))
+		return false;
+
+#if (PAGE_SIZE < 8192)
+	if (rxbufq->rx_buf_size > IECM_RX_BUF_2048)
+		if (iecm_alloc_page(rxbufq, &buf->page_info[1]))
+			return false;
+#endif

Same here with embedding the check.

Quoted 17 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +17 -0
+
+	buf->page_indx = 0;
+	buf->buf_size = rxbufq->rx_buf_size;
+
+	return true;
+}
+
+/**
+ * iecm_rx_hdr_buf_alloc_all - Allocate memory for header buffers
+ * @rxq: ring to use
+ *
+ * Returns 0 on success, negative on failure.
+ */
+static int iecm_rx_hdr_buf_alloc_all(struct iecm_queue *rxq) {
+	struct iecm_page_info *page_info;
+	int nr_pages, offset;
+	int i, j = 0;

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+
+	rxq->rx_buf.hdr_buf = kcalloc(rxq->desc_count,
+				      sizeof(struct iecm_dma_mem *),
+				      GFP_KERNEL);
+	if (!rxq->rx_buf.hdr_buf)
+		return -ENOMEM;
+
+	for (i = 0; i < rxq->desc_count; i++) {
+		rxq->rx_buf.hdr_buf[i] = kcalloc(1,
+						 sizeof(struct

iecm_dma_mem),

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport)

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+						 GFP_KERNEL);
+		if (!rxq->rx_buf.hdr_buf[i])
+			goto unroll_buf_alloc;
+	}
+
+	/* Determine the number of pages necessary to back the total number

of header buffers */

Quoted 16 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 739

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+	nr_pages = (rxq->desc_count * rxq->rx_hbuf_size) / PAGE_SIZE;
+	rxq->hbuf_pages.pages = kcalloc(nr_pages,
+					sizeof(struct iecm_page_info),
+					GFP_KERNEL);
+	if (!rxq->hbuf_pages.pages)
+		goto unroll_buf_alloc;
+
+	rxq->hbuf_pages.nr_pages = nr_pages;
+	for (i = 0; i < nr_pages; i++) {
+		if (iecm_alloc_page(rxq, &rxq->hbuf_pages.pages[i]))

And here you allocate pages with GFP_ATOMIC in process context. Atomic allocations must not be used if the function may sleep. Please add gfp_t gfp argument to iecm_alloc_page() and use GFP_KERNEL here (and GFP_ATOMIC on buffer refill hotpath).

Perhaps I am confused here but it's my understanding we need GFP_ATOMIC when potentially used in a case where we can't sleep as it signals to the memory allocator to not sleep. Not the other way around; we can't sleep if we have memory taken with GFP_ATOMIC. We use it in hotpath as you said, where we can't sleep. What it really means to us is that it has a higher chance of failure to not get alloc'd if the kernel isn't allowed to sleep to free up some memory.

Quoted 44 lines
Quoted 44 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +43 -0
+			goto unroll_buf_alloc;
+	}
+
+	page_info = &rxq->hbuf_pages.pages[0];
+	for (i = 0, offset = 0; i < rxq->desc_count; i++, offset += rxq-
 rx_hbuf_size) {
+		struct iecm_dma_mem *hbuf = rxq->rx_buf.hdr_buf[i];
+
+		/* Move to next page */
+		if (offset >= PAGE_SIZE) {
+			offset = 0;
+			page_info = &rxq->hbuf_pages.pages[++j];
+		}
+
+		hbuf->va = page_address(page_info->page) + offset;
+		hbuf->pa = page_info->dma + offset;
+		hbuf->size = rxq->rx_hbuf_size;
+	}
+
+	return 0;
+unroll_buf_alloc:
+	iecm_rx_hdr_buf_rel_all(rxq);
+	return -ENOMEM;
+}
+
+/**
+ * iecm_rx_buf_hw_alloc_all - Allocate receive buffers
+ * @rxbufq: queue for which the hw buffers are allocated; equivalent
+to rxq
+ * when operating in singleq mode
+ * @alloc_count: number of buffers to allocate
+ *
+ * Returns false if all allocations were successful, true if any fail
+*/ static bool iecm_rx_buf_hw_alloc_all(struct iecm_queue *rxbufq,
+u16 alloc_count) {
+	u16 nta = rxbufq->next_to_alloc;
+	struct iecm_rx_buf *buf;
+
+	if (!alloc_count)
+		return false;
+
+	buf = &rxbufq->rx_buf.buf[nta];
+
+	do {
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 789

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+		if (!iecm_init_rx_buf_hw_alloc(rxbufq, buf))
+			break;
+
+		buf++;
+		nta++;
+		if (unlikely(nta == rxbufq->desc_count)) {
		if (unlikely(++nta == ...)) { /* Just in one line */

Yes but pre-increments are gross and hard for humans to grok.

Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 795

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+			buf = rxbufq->rx_buf.buf;
+			nta = 0;
+		}
+
+		alloc_count--;
+	} while (alloc_count);
	} while (alloc_count--); /* Just in one line */

I believe

} while (--alloc_count);

would be accurate but pre increment/decrement are hard for humans to grok (as evidenced here).

Quoted 16 lines
Quoted 16 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +16 -0
+
+	return !!alloc_count;
+}
+
+/**
+ * iecm_rx_post_buf_desc - Post buffer to bufq descriptor ring
+ * @bufq: buffer queue to post to
+ * @buf_id: buffer id to post
+ */
+static void iecm_rx_post_buf_desc(struct iecm_queue *bufq, u16
+buf_id) {
+	struct virtchnl2_splitq_rx_buf_desc *splitq_rx_desc = NULL;
+	struct iecm_page_info *page_info;
+	u16 nta = bufq->next_to_alloc;
+	struct iecm_rx_buf *buf;
+
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport)

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+	splitq_rx_desc = IECM_SPLITQ_RX_BUF_DESC(bufq, nta);
+	buf = &bufq->rx_buf.buf[buf_id];
+	page_info = &buf->page_info[buf->page_indx];
+	if (bufq->rx_hsplit_en)
+		splitq_rx_desc->hdr_addr =
+cpu_to_le64(bufq->rx_buf.hdr_buf[buf_id]->pa);

90-cols line.

Yes there are many of these not otherwise pointed out. Wil fix.

Quoted 12 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 824

Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +8 -0
+
+	splitq_rx_desc->pkt_addr = cpu_to_le64(page_info->dma +
+					       page_info->page_offset);
+	splitq_rx_desc->qword0.buf_id = cpu_to_le16(buf_id);
+
+	nta++;
+	if (unlikely(nta == bufq->desc_count))
+		nta = 0;

Post-increment can be embedded into a condition check (with converting into a pre-increment obviously).

See previous comments about pre-inrcrement.

Quoted 12 lines
Quoted 12 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +12 -0
+	bufq->next_to_alloc = nta;
+}
+
+/**
+ * iecm_rx_post_init_bufs - Post initial buffers to bufq
+ * @bufq: buffer queue to post working set to
+ * @working_set: number of buffers to put in working set  */ static
+void iecm_rx_post_init_bufs(struct iecm_queue *bufq,
+				   u16 working_set)
+{
+	int i;
+
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport)

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +5 -0
+	for (i = 0; i < working_set; i++)
+		iecm_rx_post_buf_desc(bufq, i);
+
+	iecm_rx_buf_hw_update(bufq, bufq->next_to_alloc &
+~(bufq->rx_buf_stride - 1));

87-cols line.
Please test all your patches with checkpatch --strict --codespell.

Just an FYI, all of these patches do mostly pass checkpatch since otherwise (except for net apparently) in the kernel 100 cols are now acceptable. You must also add --max-line-length=80 to get a warning about 80 cols now.

Quoted 56 lines
Quoted 56 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +55 -0
+}
+
+/**
+ * iecm_rx_buf_alloc_all - Allocate memory for all buffer resources
+ * @rxbufq: queue for which the buffers are allocated; equivalent to
+ * rxq when operating in singleq mode
+ *
+ * Returns 0 on success, negative on failure  */ static int
+iecm_rx_buf_alloc_all(struct iecm_queue *rxbufq) {
+	int err = 0;
+
+	/* Allocate book keeping buffers */
+	rxbufq->rx_buf.buf = kcalloc(rxbufq->desc_count,
+				     sizeof(struct iecm_rx_buf), GFP_KERNEL);
+	if (!rxbufq->rx_buf.buf) {
+		err = -ENOMEM;
+		goto rx_buf_alloc_all_out;
+	}
+
+	if (rxbufq->rx_hsplit_en) {
+		err = iecm_rx_hdr_buf_alloc_all(rxbufq);
+		if (err)
+			goto rx_buf_alloc_all_out;
+	}
+
+	/* Allocate buffers to be given to HW.	 */
+	if (iecm_is_queue_model_split(rxbufq->vport->rxq_model)) {
+		if (iecm_rx_buf_hw_alloc_all(rxbufq, rxbufq->desc_count - 1))
+			err = -ENOMEM;
+	} else {
+		if (iecm_rx_singleq_buf_hw_alloc_all(rxbufq, rxbufq-
 desc_count - 1))
+			err = -ENOMEM;
+	}
+
+rx_buf_alloc_all_out:
+	if (err)
+		iecm_rx_buf_rel_all(rxbufq);
+	return err;
+}
+
+/**
+ * iecm_rx_desc_alloc - Allocate queue Rx resources
+ * @rxq: Rx queue for which the resources are setup
+ * @bufq: buffer or completion queue
+ * @q_model: single or split queue model
+ *
+ * Returns 0 on success, negative on failure  */ static int
+iecm_rx_desc_alloc(struct iecm_queue *rxq, bool bufq, s32 q_model) {
+	struct device *dev = rxq->dev;
+
+	/* As both single and split descriptors are 32 byte, memory size
+	 * will be same for all three singleq_base rx, buf., splitq_base
+	 * rx. So pick anyone of them for size
+	 */
+	if (bufq) {
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 906

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+		rxq->size = rxq->desc_count *
+			sizeof(struct virtchnl2_splitq_rx_buf_desc);
+	} else {
+		rxq->size = rxq->desc_count *
+			sizeof(union virtchnl2_rx_desc);
+	}

Oneliners, braces are unneeded.

Keeping because multi-line with line wrap.

Quoted 8 lines

For counting the array sizes it's required to use array_size():

	rxq->size = array_size(rxq->desc_count, sizeof(...));
	if (unlikely(rxq->size == -EOVERFLOW))
		/* Error path */

There are more such places in the code, I couldn't catch them all.

Will fix.

Quoted 6 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 909

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
+
+	/* Allocate descriptors and also round up to nearest 4K */
+	rxq->size = ALIGN(rxq->size, 4096);

4096 = SZ_4K, no need to open-code.

Will fix.

Quoted 5 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport)

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +4 -0
+	rxq->desc_ring = dmam_alloc_coherent(dev, rxq->size,
+					     &rxq->dma, GFP_KERNEL);
+	if (!rxq->desc_ring) {
+		dev_info(dev, "Unable to allocate memory for the Rx descriptor

ring, size=%d\n",

Quoted 11 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 920

Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +7 -0
+			 rxq->size);
+		return -ENOMEM;
+	}
+
+	rxq->next_to_alloc = 0;
+	rxq->next_to_clean = 0;
+	rxq->next_to_use = 0;

You allocate rxq with kzalloc() (or derivative) IIRC, 'z'-versions zero the memory before returning. These initializers are redundant.

This is allocating descriptors which can change. If we change the descriptor ring it's probably a good idea to reset the queue indexes.

Quoted 20 lines
Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +4 -0
+	set_bit(__IECM_Q_GEN_CHK, rxq->flags);
+
+	/* Allocate buffers for a rx queue if the q_model is single OR if it
+	 * is a buffer queue in split queue model

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 934

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+	 */
+	if (bufq || !iecm_is_queue_model_split(q_model)) {
+		int err = 0;
+
+		err = iecm_rx_buf_alloc_all(rxq);
+		if (err) {
+			iecm_rx_desc_rel(rxq, bufq, q_model);
+			return err;
+		}
+	}
	if (inverse_the_condition_above)
		return 0;

	err = ...
Quoted 2 lines

-1 indent level.

Will fix

Quoted 120 lines
Quoted 20 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +20 -0
+	return 0;
+}
+
+/**
+ * iecm_rx_desc_alloc_all - allocate all RX queues resources
+ * @vport: virtual port structure
+ *
+ * Returns 0 on success, negative on failure  */ static int
+iecm_rx_desc_alloc_all(struct iecm_vport *vport) {
+	struct device *dev = &vport->adapter->pdev->dev;
+	struct iecm_rxq_group *rx_qgrp;
+	int i, j, num_rxq, working_set;
+	struct iecm_queue *q;
+	int err = 0;
+
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		rx_qgrp = &vport->rxq_grps[i];
+		if (iecm_is_queue_model_split(vport->rxq_model))
+			num_rxq = rx_qgrp->splitq.num_rxq_sets;
+		else

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+			num_rxq = rx_qgrp->singleq.num_rxq;
+
+		for (j = 0; j < num_rxq; j++) {
+			if (iecm_is_queue_model_split(vport->rxq_model))
+				q = &rx_qgrp->splitq.rxq_sets[j]->rxq;
+			else
+				q = rx_qgrp->singleq.rxqs[j];
+			err = iecm_rx_desc_alloc(q, false, vport->rxq_model);
+			if (err) {
+				dev_err(dev, "Memory allocation for Rx Queue

%u failed\n",

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport)

Quoted 12 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +12 -0
+					i);
+				goto err_out;
+			}
+		}
+
+		if (iecm_is_queue_model_split(vport->rxq_model)) {
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++) {
+				q = &rx_qgrp->splitq.bufq_sets[j].bufq;
+				err = iecm_rx_desc_alloc(q, true,
+							 vport->rxq_model);
+				if (err) {
+					dev_err(dev, "Memory allocation for

Rx Buffer Queue %u failed\n",

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport)

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +5 -0
+						i);
+					goto err_out;
+				}
+
+				working_set =

IECM_RX_BUFQ_WORKING_SET(q);

Quoted 56 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+				iecm_rx_post_init_bufs(q, working_set);
+			}
+		}
+	}
+err_out:
+	if (err)
+		iecm_rx_desc_rel_all(vport);
+	return err;
+}
+
 /**
  * iecm_txq_group_rel - Release all resources for txq groups
  * @vport: vport to release txq groups on @@ -478,6 +1017,61 @@

static void iecm_txq_group_rel(struct iecm_vport *vport)

drivers/net/ethernet/intel/iecm/iecm_txrx.c +39 -0
 	}
 }
 
+/**
+ * iecm_rxq_sw_queue_rel - Release software queue resources
+ * @rx_qgrp: rx queue group with software queues  */ static void
+iecm_rxq_sw_queue_rel(struct iecm_rxq_group *rx_qgrp) {
+	int i, j;
+
+	for (i = 0; i < rx_qgrp->vport->num_bufqs_per_qgrp; i++) {
+		struct iecm_bufq_set *bufq_set = &rx_qgrp->splitq.bufq_sets[i];
+
+		for (j = 0; j < bufq_set->num_refillqs; j++) {
+			kfree(bufq_set->refillqs[j].ring);
+			bufq_set->refillqs[j].ring = NULL;
+		}
+		kfree(bufq_set->refillqs);
+		bufq_set->refillqs = NULL;
+	}
+}
+
+/**
+ * iecm_rxq_group_rel - Release all resources for rxq groups
+ * @vport: vport to release rxq groups on  */ static void
+iecm_rxq_group_rel(struct iecm_vport *vport) {
+	if (vport->rxq_grps) {
+		int i;
+
+		for (i = 0; i < vport->num_rxq_grp; i++) {
+			struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+			int j, num_rxq;
+
+			if (iecm_is_queue_model_split(vport->rxq_model)) {
+				num_rxq = rx_qgrp->splitq.num_rxq_sets;
+				for (j = 0; j < num_rxq; j++) {
+					kfree(rx_qgrp->splitq.rxq_sets[j]);
+					rx_qgrp->splitq.rxq_sets[j] = NULL;
+				}
+				iecm_rxq_sw_queue_rel(rx_qgrp);
+				kfree(rx_qgrp->splitq.bufq_sets);
+				rx_qgrp->splitq.bufq_sets = NULL;
+			} else {

drivers/net/ethernet/intel/iecm/iecm_txrx.c static void iecm_txq_group_rel(struct iecm_vport *vport) · line 1072

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+				num_rxq = rx_qgrp->singleq.num_rxq;
+				for (j = 0; j < num_rxq; j++) {
+					kfree(rx_qgrp->singleq.rxqs[j]);
+					rx_qgrp->singleq.rxqs[j] = NULL;
+				}
+			}
+		}
+		kfree(vport->rxq_grps);
+		vport->rxq_grps = NULL;
+	}
	if (!rxq_grps)
		return;
Quoted 2 lines

-1 lvl.

Will fix

Quoted 266 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c void iecm_vport_calc_num_q_vec(struct

Quoted 21 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +2 -0
+}
+
 /**
  * iecm_vport_queue_grp_rel_all - Release all queue groups
  * @vport: vport to release queue groups for @@ -485,6 +1079,7 @@

static void iecm_txq_group_rel(struct iecm_vport *vport) static void iecm_vport_queue_grp_rel_all(struct iecm_vport *vport) {

drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
 	iecm_txq_group_rel(vport);
+	iecm_rxq_group_rel(vport);
 }
 
 /**
@@ -496,6 +1091,7 @@ static void iecm_vport_queue_grp_rel_all(struct

iecm_vport *vport) void iecm_vport_queues_rel(struct iecm_vport *vport) {

drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
 	iecm_tx_desc_rel_all(vport);
+	iecm_rx_desc_rel_all(vport);
 	iecm_vport_queue_grp_rel_all(vport);
 
 	kfree(vport->txqs);
@@ -715,6 +1311,24 @@ void iecm_vport_calc_num_q_vec(struct

iecm_vport

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_txq_group_alloc(struct iecm_vport

Quoted 24 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +18 -0
 *vport)  }  EXPORT_SYMBOL(iecm_vport_calc_num_q_vec);
 
+/**
+ * iecm_rxq_set_descids - set the descids supported by this queue
+ * @vport: virtual port data structure
+ * @q: rx queue for which descids are set
+ *
+ */
+static void iecm_rxq_set_descids(struct iecm_vport *vport, struct
+iecm_queue *q) {
+	if (vport->rxq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) {
+		q->rxdids = VIRTCHNL2_RXDID_1_FLEX_SPLITQ_M;
+	} else {
+		if (vport->base_rxd)
+			q->rxdids = VIRTCHNL2_RXDID_1_32B_BASE_M;
+		else
+			q->rxdids = VIRTCHNL2_RXDID_2_FLEX_SQ_NIC_M;
+	}
+}
+
 /**
  * iecm_set_vlan_tag_loc - set the tag location for a tx/rx queue
  * @adapter: adapter structure
@@ -827,6 +1441,152 @@ static int iecm_txq_group_alloc(struct iecm_vport

*vport, int num_txq)

Quoted 30 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +27 -0
 	return err;
 }
 
+/**
+ * iecm_rxq_group_alloc - Allocate all rxq group resources
+ * @vport: vport to allocate rxq groups for
+ * @num_rxq: number of rxqs to allocate for each group
+ *
+ * Returns 0 on success, negative on failure  */ static int
+iecm_rxq_group_alloc(struct iecm_vport *vport, int num_rxq) {
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_queue *q;
+	int i, k, err = 0;
+
+	vport->rxq_grps = kcalloc(vport->num_rxq_grp,
+				  sizeof(struct iecm_rxq_group), GFP_KERNEL);
+	if (!vport->rxq_grps)
+		return -ENOMEM;
+
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+		int j;
+
+		rx_qgrp->vport = vport;
+		if (iecm_is_queue_model_split(vport->rxq_model)) {
+			rx_qgrp->splitq.num_rxq_sets = num_rxq;
+
+			for (j = 0; j < num_rxq; j++) {
+				rx_qgrp->splitq.rxq_sets[j] =
+					kzalloc(sizeof(struct iecm_rxq_set),

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_txq_group_alloc(struct iecm_vport *vport, int num_txq)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +9 -0
+						GFP_KERNEL);
+				if (!rx_qgrp->splitq.rxq_sets[j]) {
+					err = -ENOMEM;
+					goto err_alloc;
+				}
+			}
+
+			rx_qgrp->splitq.bufq_sets = kcalloc(vport-
 num_bufqs_per_qgrp,
+							    sizeof(struct

iecm_bufq_set),

Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +9 -0
+							    GFP_KERNEL);
+			if (!rx_qgrp->splitq.bufq_sets) {
+				err = -ENOMEM;
+				goto err_alloc;
+			}
+
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++) {
+				struct iecm_bufq_set *bufq_set =
+					&rx_qgrp->splitq.bufq_sets[j];

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_txq_group_alloc(struct iecm_vport *vport, int num_txq)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+				int swq_size = sizeof(struct iecm_sw_queue);
+
+				q = &rx_qgrp->splitq.bufq_sets[j].bufq;
+				q->dev = &adapter->pdev->dev;
+				q->desc_count = vport->bufq_desc_count[j];
+				q->vport = vport;
+				q->rxq_grp = rx_qgrp;
+				q->idx = j;
+				q->rx_buf_size = vport->bufq_size[j];
+				q->rx_buffer_low_watermark =

IECM_LOW_WATERMARK;

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_txq_group_alloc(struct iecm_vport *vport, int num_txq)

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+				q->rx_buf_stride = IECM_RX_BUF_STRIDE;
+
+				if (test_bit(__IECM_PRIV_FLAGS_HDR_SPLIT,
+					     adapter->config_data.user_flags)) {
+					q->rx_hsplit_en = true;
+					q->rx_hbuf_size =

IECM_HDR_BUF_SIZE;

Quoted 48 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +46 -0
+				}
+
+				bufq_set->num_refillqs = num_rxq;
+				bufq_set->refillqs = kcalloc(num_rxq,
+							     swq_size,
+							     GFP_KERNEL);
+				if (!bufq_set->refillqs) {
+					err = -ENOMEM;
+					goto err_alloc;
+				}
+				for (k = 0; k < bufq_set->num_refillqs; k++) {
+					struct iecm_sw_queue *refillq =
+						&bufq_set->refillqs[k];
+
+					refillq->dev =
+						&vport->adapter->pdev->dev;
+					refillq->buf_size = q->rx_buf_size;
+					refillq->desc_count =
+						vport->bufq_desc_count[j];
+					set_bit(__IECM_Q_GEN_CHK,
+						refillq->flags);
+					set_bit(__IECM_RFLQ_GEN_CHK,
+						refillq->flags);
+					refillq->ring = kcalloc(refillq-
 desc_count,
+								sizeof(u16),
+								GFP_KERNEL);
+					if (!refillq->ring) {
+						err = -ENOMEM;
+						goto err_alloc;
+					}
+				}
+			}
+		} else {
+			rx_qgrp->singleq.num_rxq = num_rxq;
+			for (j = 0; j < num_rxq; j++) {
+				rx_qgrp->singleq.rxqs[j] =
+					kzalloc(sizeof(*rx_qgrp-
 singleq.rxqs[j]), GFP_KERNEL);
+				if (!rx_qgrp->singleq.rxqs[j]) {
+					err = -ENOMEM;
+					goto err_alloc;
+				}
+			}
+		}
+
+		for (j = 0; j < num_rxq; j++) {
+			if (iecm_is_queue_model_split(vport->rxq_model)) {

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_txq_group_alloc(struct iecm_vport *vport, int num_txq)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+				q = &rx_qgrp->splitq.rxq_sets[j]->rxq;
+				rx_qgrp->splitq.rxq_sets[j]->refillq0 =
+				      &rx_qgrp->splitq.bufq_sets[0].refillqs[j];
+				rx_qgrp->splitq.rxq_sets[j]->refillq1 =
+				      &rx_qgrp->splitq.bufq_sets[1].refillqs[j];
+
+				if (test_bit(__IECM_PRIV_FLAGS_HDR_SPLIT,
+					     adapter->config_data.user_flags)) {
+					q->rx_hsplit_en = true;
+					q->rx_hbuf_size =

IECM_HDR_BUF_SIZE;

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +5 -0
+				}
+			} else {
+				q = rx_qgrp->singleq.rxqs[j];
+			}
+			q->dev = &adapter->pdev->dev;

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_txq_group_alloc(struct iecm_vport *vport, int num_txq)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+			q->desc_count = vport->rxq_desc_count;
+			q->vport = vport;
+			q->rxq_grp = rx_qgrp;
+			q->idx = (i * num_rxq) + j;
+			/* In splitq mode, RXQ buffer size should be
+			 * set to that of the first buffer queue
+			 * associated with this RXQ
+			 */
+			q->rx_buf_size = vport->bufq_size[0];
+			q->rx_buffer_low_watermark =

IECM_LOW_WATERMARK;

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_txq_group_alloc(struct iecm_vport *vport, int num_txq) · line 1589

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +2 -0
+			q->rx_max_pkt_size = vport->netdev->mtu +
+
	IECM_PACKET_HDR_PAD;

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport

Quoted 26 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+			iecm_rxq_set_descids(vport, q);
+			iecm_set_vlan_tag_loc(adapter, q);
+		}
+	}
+err_alloc:
+	if (err)
+		iecm_rxq_group_rel(vport);
+	return err;
+}
+
 /**
  * iecm_vport_queue_grp_alloc_all - Allocate all queue groups/resources
  * @vport: vport with qgrps to allocate @@ -841,6 +1601,11 @@ static

int iecm_vport_queue_grp_alloc_all(struct iecm_vport *vport)

drivers/net/ethernet/intel/iecm/iecm_txrx.c +5 -0
 	iecm_vport_calc_numq_per_grp(vport, &num_txq, &num_rxq);
 
 	err = iecm_txq_group_alloc(vport, num_txq);
+	if (err)
+		goto err_out;
+
+	err = iecm_rxq_group_alloc(vport, num_rxq);
+err_out:
 	if (err)
 		iecm_vport_queue_grp_rel_all(vport);
 	return err;
@@ -866,6 +1631,10 @@ int iecm_vport_queues_alloc(struct iecm_vport

*vport)

Quoted 16 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +4 -0
 	if (err)
 		goto err_out;
 
+	err = iecm_rx_desc_alloc_all(vport);
+	if (err)
+		goto err_out;
+
 	err = iecm_vport_init_fast_path_txqs(vport);
 	if (err)
 		goto err_out;
drivers/net/ethernet/intel/include/iecm_txrx.h +0 -0
index 44c20f8a2039..5e29148938fb 100644

drivers/net/ethernet/intel/include/iecm_txrx.h struct iecm_page_info { · line 203

Quoted 6 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +3 -0
@@ -198,6 +198,11 @@ struct iecm_page_info {
 	u16 pagecnt_bias;
 };
 
+struct iecm_rx_hdr_buf_pages {
+	u32 nr_pages;
+	struct iecm_page_info *pages;

Place the pointer at the beginning to avoid gaps and alignment issues.

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

Quoted 5 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +2 -0
+};
+
 struct iecm_rx_buf {
 #define IECM_RX_BUF_MAX_PAGES 2
 	struct iecm_page_info page_info[IECM_RX_BUF_MAX_PAGES]; @@ -

498,6

Quoted 9 lines

+503,8 @@ struct iecm_queue {

drivers/net/ethernet/intel/include/iecm_txrx.h +2 -0
 					 * with scatter-gather
 					 */
 	DECLARE_HASHTABLE(sched_buf_hash, 12);
+
+	struct iecm_rx_hdr_buf_pages hbuf_pages;
 } ____cacheline_internodealigned_in_smp;
 
 /* Software queues are used in splitq mode to manage buffers between
Quoted 3 lines

rxq
--
2.33.0

Thanks,
Al

#46 lore raw

PATCH 10/19 iecm: alloc vport RX resources

From: Alan Brady <[email protected]>
Date: Thu, 3 Feb 2022 01:13:23 +0100

Quoted 28 lines
Quoted 28 lines

-----Original Message-----
From: Lobakin, Alexandr <[email protected]>
Sent: Friday, January 28, 2022 6:16 AM
To: Brady, Alan <[email protected]>
Cc: Lobakin, Alexandr <[email protected]>; intel-wired-
lan at lists.osuosl.org; Burra, Phani R <[email protected]>; Chittim, Madhu <[email protected]>; Linga, Pavan Kumar <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net-next 10/19] iecm: alloc vport RX resources

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

Quoted 12 lines

This finishes what we need to do for open by adding RX resource allocations.

As noted in the TX alloc patch, the splitq model is unique in introducing the concept of queue groups, which also applies to RX, albeit in a slightly different way. For RX we also split the queue between descriptor handling and buffer handling. We have some number of RX completion queues associated with up to two buffer queues in a given queue group. Once buffers are cleaned and recycled, they're given the buffer queues which then posts the buffers back to hardware. To enable this in a lockless way, there's also the concept of 'refill queues' introduced. Recycled buffers are put onto refill queues which is what

the buffer queues clean to get buffers back.

Quoted 1 line
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
---
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   | 769 ++++++++++++++++++
 .../net/ethernet/intel/include/iecm_txrx.h    |   7 +
 2 files changed, 776 insertions(+)

--- 8< ---

Quoted 11 lines
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 739

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
+	rxq->hbuf_pages.nr_pages = nr_pages;
+	for (i = 0; i < nr_pages; i++) {
+		if (iecm_alloc_page(rxq, &rxq->hbuf_pages.pages[i]))

And here you allocate pages with GFP_ATOMIC in process context. Atomic allocations must not be used if the function may sleep. Please add gfp_t gfp argument to iecm_alloc_page() and use GFP_KERNEL here (and GFP_ATOMIC on buffer refill hotpath).

Perhaps I am confused here but it's my understanding we need GFP_ATOMIC when potentially used in a case where we can't sleep as it signals to the memory allocator to not sleep. Not the other way around; we can't sleep if we have memory taken with GFP_ATOMIC. We use it in hotpath as you said, where we can't sleep. What it really means to us is that it has a higher chance of failure to not get alloc'd if the kernel isn't allowed to sleep to free up some memory.

GFP_ATOMIC must be used only in atomic contexts i.e. hardirq and softirq processing (using them inside spinlocks is debatable). With this flag set, we have less resources available to allocate from, and you can consider those resources as the reserves for critical situations (and e.g. hardirqs are of those kind). This mostly comes from GFP_NOWAIT embedded into GFP_ATOMIC.
This function allocates all the resources on ifup, the context is non-critical and it's okay to sleep there, so using GFP_ATOMIC is an excessive waste of critical memory in case of e.g. memory pressure.
So we use GFP_ATOMIC for buffer refilling only inside NAPI context itself.

Quoted 4 lines
Quoted 4 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 743

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +4 -0
+			goto unroll_buf_alloc;
+	}
+
+	page_info = &rxq->hbuf_pages.pages[0];

--- 8< ---

Quoted 9 lines
Quoted 7 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 789

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +4 -0
+
+		buf++;
+		nta++;
+		if (unlikely(nta == rxbufq->desc_count)) {
		if (unlikely(++nta == ...)) { /* Just in one line */

Yes but pre-increments are gross and hard for humans to grok.

Could you please elaborate on "pre-increments are gross"? I don't get it at all.

Also, "hard for humans to grok" to me doesn't seem really correct here (and in all other places you used it) since you're reflecting your personal opinion, not a mathematical fact I believe?

Quoted 11 lines
Quoted 10 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 795

Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+			buf = rxbufq->rx_buf.buf;
+			nta = 0;
+		}
+
+		alloc_count--;
+	} while (alloc_count);
	} while (alloc_count--); /* Just in one line */
Quoted 5 lines

I believe

} while (--alloc_count);

would be accurate but pre increment/decrement are hard for humans to grok (as evidenced here).

Right, sorry, there should be a pre-increment. Evidenced what and where?
If you're about my off-by-one, it doesn't mean anything, I use pre-increments much more often than post-check-loops (usually it's either for-loop or while {}).

Quoted 7 lines
Quoted 7 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 801

Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+
+	return !!alloc_count;
+}
+
+/**
+ * iecm_rx_post_buf_desc - Post buffer to bufq descriptor ring

--- 8< ---

Quoted 8 lines
Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	iecm_rx_buf_hw_update(bufq, bufq->next_to_alloc &
+~(bufq->rx_buf_stride - 1));

87-cols line.
Please test all your patches with checkpatch --strict --codespell.

Just an FYI, all of these patches do mostly pass checkpatch since otherwise (except for net apparently) in the kernel 100 cols are now acceptable. You must also add --max-line-length=80 to get a warning about 80 cols now.

Netdev maintainers still prefer 79/80 (and so do I), thus pointing out all those long lines here.
Wasn't sure about checkpatch detecting whether it's a networking patch and applying the corresponding settings since I can't recall my last time going past 79.

Quoted 5 lines
Quoted 5 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 845

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +4 -0
+}
+
+/**
+ * iecm_rx_buf_alloc_all - Allocate memory for all buffer resources

--- 8< ---

Quoted 11 lines
Quoted 10 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 906

Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +7 -0
+	if (bufq) {
+		rxq->size = rxq->desc_count *
+			sizeof(struct virtchnl2_splitq_rx_buf_desc);
+	} else {
+		rxq->size = rxq->desc_count *
+			sizeof(union virtchnl2_rx_desc);
+	}

Oneliners, braces are unneeded.

Quoted 1 line

Keeping because multi-line with line wrap.

Please see my previous messages.

Quoted 2 lines
Quoted 2 lines

For counting the array sizes it's required to use array_size():

--- 8< ---

Quoted 10 lines
Quoted 8 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 579

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +4 -0
+
+	rxq->next_to_alloc = 0;
+	rxq->next_to_clean = 0;
+	rxq->next_to_use = 0;

You allocate rxq with kzalloc() (or derivative) IIRC, 'z'-versions zero the memory before returning. These initializers are redundant.

This is allocating descriptors which can change. If we change the descriptor ring it's probably a good idea to reset the queue indexes.

Again, this function takes a freshly zero-allocated ring structure. Those are zeroes in 100% cases. Please correct if I'm wrong.

Also, while searching for iecm_rx_desc_alloc() usages, I spotted that both it and iecm_rx_desc_alloc_all() are used only inside the same file which they're declared in. So they should be static. Please correct if not.

Quoted 4 lines
Quoted 4 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c static int iecm_tx_desc_alloc_all(struct iecm_vport *vport) · line 923

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
+	set_bit(__IECM_Q_GEN_CHK, rxq->flags);
+
+	/* Allocate buffers for a rx queue if the q_model is single OR if it

--- 8< ---

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

--
2.33.0

Thanks,
Al

Thanks,
Al

author
#47 lore raw

PATCH 11/19 iecm: add start_xmit and set_rx_mode

In reply to Alan Brady

With open and stop done, this continues down the netdev_ops struct to add start_xmit and set_rx_mode callbacks. The rest of the data path will be added after netdev_ops are done.

---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    | 247 ++++++-
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   | 667 ++++++++++++++++++
 drivers/net/ethernet/intel/include/iecm.h     |   1 +
 .../net/ethernet/intel/include/iecm_txrx.h    |  60 ++
 4 files changed, 970 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/iecm/iecm_lib.c +242 -5
index 037a0e06bb7b..003057f48f0c 100644
@@ -141,6 +141,17 @@ struct iecm_vport *iecm_netdev_to_vport(struct net_device *netdev)
 	return np->vport;
 }
 
+/**
+ * iecm_netdev_to_adapter - get an adapter handle from a netdev
+ * @netdev: network interface device structure
+ */
+struct iecm_adapter *iecm_netdev_to_adapter(struct net_device *netdev)
+{
+	struct iecm_netdev_priv *np = netdev_priv(netdev);
+
+	return np->vport->adapter;
+}
+
 /**
  * iecm_mb_intr_rel_irq - Free the IRQ association with the OS
  * @adapter: adapter structure
@@ -417,6 +428,61 @@ iecm_mac_filter *iecm_find_mac_filter(struct iecm_vport *vport,
 	return NULL;
 }
 
+/**
+ * __iecm_del_mac_filter - Delete MAC filter helper
+ * @vport: main vport struct
+ * @macaddr: address to delete
+ *
+ * Takes mac_filter_list_lock spinlock to set remove field for filter in list.
+ */
+static struct
+iecm_mac_filter *__iecm_del_mac_filter(struct iecm_vport *vport,
+				       const u8 *macaddr)
+{
+	struct iecm_mac_filter *f;
+
+	spin_lock_bh(&vport->adapter->mac_filter_list_lock);
+	f = iecm_find_mac_filter(vport, macaddr);
+	if (f) {
+		/* If filter was never synced to HW we can just delete it here,
+		 * otherwise mark for removal.
+		 */
+		if (f->add) {
+			list_del(&f->list);
+			kfree(f);
+			f = NULL;
+		} else {
+			f->remove = true;
+		}
+	}
+	spin_unlock_bh(&vport->adapter->mac_filter_list_lock);
+
+	return f;
+}
+
+/**
+ * iecm_del_mac_filter - Delete a MAC filter from the filter list
+ * @vport: main vport structure
+ * @macaddr: the MAC address
+ *
+ * Removes filter from list and if interface is up, tells hardware about the
+ * removed filter.
+ **/
+static void iecm_del_mac_filter(struct iecm_vport *vport, const u8 *macaddr)
+{
+	struct iecm_mac_filter *f;
+
+	if (!macaddr)
+		return;
+
+	f = __iecm_del_mac_filter(vport, macaddr);
+	if (!f)
+		return;
+
+	if (vport->adapter->state == __IECM_UP)
+		iecm_add_del_ether_addrs(vport, false, false);
+}
+
 /**
  * __iecm_add_mac_filter - Add mac filter helper function
  * @vport: main vport struct
@@ -1711,6 +1777,134 @@ void iecm_remove(struct pci_dev *pdev)
 }
 EXPORT_SYMBOL(iecm_remove);
 
+/**
+ * iecm_addr_sync - Callback for dev_(mc|uc)_sync to add address
+ * @netdev: the netdevice
+ * @addr: address to add
+ *
+ * Called by __dev_(mc|uc)_sync when an address needs to be added. We call
+ * __dev_(uc|mc)_sync from .set_rx_mode. Kernel takes addr_list_lock spinlock
+ * meaning we cannot sleep in this context. Due to this, we have to add the
+ * filter and send the virtchnl message asynchronously without waiting for the
+ * response from the other side. We won't know whether or not the operation
+ * actually succeeded until we get the message back.  Returns 0 on success,
+ * negative on failure.
+ */
+static int iecm_addr_sync(struct net_device *netdev, const u8 *addr)
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+
+	if (__iecm_add_mac_filter(vport, addr)) {
+		if (vport->adapter->state == __IECM_UP) {
+			set_bit(__IECM_ADD_ETH_REQ, vport->adapter->flags);
+			iecm_add_del_ether_addrs(vport, true, true);
+		}
+		return 0;
+	}
+
+	return -ENOMEM;
+}
+
+/**
+ * iecm_addr_unsync - Callback for dev_(mc|uc)_sync to remove address
+ * @netdev: the netdevice
+ * @addr: address to add
+ *
+ * Called by __dev_(mc|uc)_sync when an address needs to be added. We call
+ * __dev_(uc|mc)_sync from .set_rx_mode. Kernel takes addr_list_lock spinlock
+ * meaning we cannot sleep in this context. Due to this we have to delete the
+ * filter and send the virtchnl message asychronously without waiting for the
+ * return from the other side.  We won't know whether or not the operation
+ * actually succeeded until we get the message back. Returns 0 on success,
+ * negative on failure.
+ */
+static int iecm_addr_unsync(struct net_device *netdev, const u8 *addr)
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+
+	/* Under some circumstances, we might receive a request to delete
+	 * our own device address from our uc list. Because we store the
+	 * device address in the VSI's MAC/VLAN filter list, we need to ignore
+	 * such requests and not delete our device address from this list.
+	 */
+	if (ether_addr_equal(addr, netdev->dev_addr))
+		return 0;
+
+	if (__iecm_del_mac_filter(vport, addr)) {
+		if (vport->adapter->state == __IECM_UP) {
+			set_bit(__IECM_DEL_ETH_REQ, vport->adapter->flags);
+			iecm_add_del_ether_addrs(vport, false, true);
+		}
+	}
+
+	return 0;
+}
+
+/**
+ * iecm_set_rx_mode - NDO callback to set the netdev filters
+ * @netdev: network interface device structure
+ *
+ * Stack takes addr_list_lock spinlock before calling our .set_rx_mode.  We
+ * cannot sleep in this context.
+ */
+static void iecm_set_rx_mode(struct net_device *netdev)
+{
+	struct iecm_adapter *adapter = iecm_netdev_to_adapter(netdev);
+
+	if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_MACFILTER)) {
+		__dev_uc_sync(netdev, iecm_addr_sync, iecm_addr_unsync);
+		__dev_mc_sync(netdev, iecm_addr_sync, iecm_addr_unsync);
+	}
+
+	if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_PROMISC)) {
+		bool changed = false;
+
+		/* IFF_PROMISC enables both unicast and multicast promiscuous,
+		 * while IFF_ALLMULTI only enables multicast such that:
+		 *
+		 * promisc  + allmulti		= unicast | multicast
+		 * promisc  + !allmulti		= unicast | multicast
+		 * !promisc + allmulti		= multicast
+		 */
+		if ((netdev->flags & IFF_PROMISC) &&
+		    !test_and_set_bit(__IECM_PROMISC_UC,
+				      adapter->config_data.user_flags)) {
+			changed = true;
+			dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
+			if (!test_and_set_bit(__IECM_PROMISC_MC,
+					      adapter->flags))
+				dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n");
+		}
+		if (!(netdev->flags & IFF_PROMISC) &&
+		    test_and_clear_bit(__IECM_PROMISC_UC,
+				       adapter->config_data.user_flags)) {
+			changed = true;
+			dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
+		}
+		if (netdev->flags & IFF_ALLMULTI &&
+		    !test_and_set_bit(__IECM_PROMISC_MC,
+				      adapter->config_data.user_flags)) {
+			changed = true;
+			dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n");
+		}
+		if (!(netdev->flags & (IFF_ALLMULTI | IFF_PROMISC)) &&
+		    test_and_clear_bit(__IECM_PROMISC_MC,
+				       adapter->config_data.user_flags)) {
+			changed = true;
+			dev_info(&adapter->pdev->dev, "Leaving multicast promiscuous mode\n");
+		}
+
+		if (changed) {
+			int err = iecm_set_promiscuous(adapter);
+
+			if (err) {
+				dev_info(&adapter->pdev->dev, "Failed to set promiscuous mode: %d\n",
+					 err);
+			}
+		}
+	}
+}
+
 /**
  * iecm_open - Called when a network interface becomes active
  * @netdev: network interface device structure
@@ -1730,6 +1924,49 @@ static int iecm_open(struct net_device *netdev)
 	return iecm_vport_open(np->vport, true);
 }
 
+/**
+ * iecm_set_mac - NDO callback to set port mac address
+ * @netdev: network interface device structure
+ * @p: pointer to an address structure
+ *
+ * Returns 0 on success, negative on failure
+ **/
+static int iecm_set_mac(struct net_device *netdev, void *p)
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+	struct iecm_mac_filter *f;
+	struct sockaddr *addr = p;
+
+	if (!iecm_is_cap_ena(vport->adapter, IECM_OTHER_CAPS,
+			     VIRTCHNL2_CAP_MACFILTER)) {
+		dev_info(&vport->adapter->pdev->dev, "Setting MAC address is not supported\n");
+		return -EOPNOTSUPP;
+	}
+
+	if (!is_valid_ether_addr(addr->sa_data)) {
+		dev_info(&vport->adapter->pdev->dev, "Invalid MAC address: %pM\n",
+			 addr->sa_data);
+		return -EADDRNOTAVAIL;
+	}
+
+	if (ether_addr_equal(netdev->dev_addr, addr->sa_data))
+		return 0;
+
+	/* Delete the current filter */
+	if (is_valid_ether_addr(vport->default_mac_addr))
+		iecm_del_mac_filter(vport, vport->default_mac_addr);
+
+	/* Add new filter */
+	f = iecm_add_mac_filter(vport, addr->sa_data);
+
+	if (f) {
+		ether_addr_copy(vport->default_mac_addr, addr->sa_data);
+		dev_addr_mod(netdev, 0, addr->sa_data, ETH_ALEN);
+	}
+
+	return f ? 0 : -ENOMEM;
+}
+
 void *iecm_alloc_dma_mem(struct iecm_hw *hw, struct iecm_dma_mem *mem, u64 size)
 {
 	struct iecm_adapter *adapter = (struct iecm_adapter *)hw->back;
@@ -1756,10 +1993,10 @@ void iecm_free_dma_mem(struct iecm_hw *hw, struct iecm_dma_mem *mem)
 static const struct net_device_ops iecm_netdev_ops_splitq = {
 	.ndo_open = iecm_open,
 	.ndo_stop = iecm_stop,
-	.ndo_start_xmit = NULL,
-	.ndo_set_rx_mode = NULL,
+	.ndo_start_xmit = iecm_tx_splitq_start,
+	.ndo_set_rx_mode = iecm_set_rx_mode,
 	.ndo_validate_addr = eth_validate_addr,
-	.ndo_set_mac_address = NULL,
+	.ndo_set_mac_address = iecm_set_mac,
 	.ndo_change_mtu = NULL,
 	.ndo_get_stats64 = NULL,
 	.ndo_fix_features = NULL,
@@ -1773,9 +2010,9 @@ static const struct net_device_ops iecm_netdev_ops_singleq = {
 	.ndo_open = iecm_open,
 	.ndo_stop = iecm_stop,
 	.ndo_start_xmit = NULL,
-	.ndo_set_rx_mode = NULL,
+	.ndo_set_rx_mode = iecm_set_rx_mode,
 	.ndo_validate_addr = eth_validate_addr,
-	.ndo_set_mac_address = NULL,
+	.ndo_set_mac_address = iecm_set_mac,
 	.ndo_change_mtu = NULL,
 	.ndo_get_stats64 = NULL,
 	.ndo_fix_features = NULL,
drivers/net/ethernet/intel/iecm/iecm_txrx.c +667 -0

673 lines not on this page · raw message

drivers/net/ethernet/intel/include/iecm.h +1 -0
index 4304256f7010..f6f9884c10c2 100644
@@ -717,6 +717,7 @@ 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);
+struct iecm_adapter *iecm_netdev_to_adapter(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,
drivers/net/ethernet/intel/include/iecm_txrx.h +60 -0

85 lines not on this page · raw message

Signature · 1 line
2.33.0
#48 lore raw

PATCH 11/19 iecm: add start_xmit and set_rx_mode

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

Quoted 59 lines

With open and stop done, this continues down the netdev_ops struct to add start_xmit and set_rx_mode callbacks. The rest of the data path will be added after netdev_ops are done.

---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    | 247 ++++++-
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   | 667 ++++++++++++++++++
 drivers/net/ethernet/intel/include/iecm.h     |   1 +
 .../net/ethernet/intel/include/iecm_txrx.h    |  60 ++
 4 files changed, 970 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/iecm/iecm_lib.c +28 -0
index 037a0e06bb7b..003057f48f0c 100644
@@ -141,6 +141,17 @@ struct iecm_vport *iecm_netdev_to_vport(struct net_device *netdev)
 	return np->vport;
 }
 
+/**
+ * iecm_netdev_to_adapter - get an adapter handle from a netdev
+ * @netdev: network interface device structure
+ */
+struct iecm_adapter *iecm_netdev_to_adapter(struct net_device *netdev)
+{
+	struct iecm_netdev_priv *np = netdev_priv(netdev);
+
+	return np->vport->adapter;
+}
+
 /**
  * iecm_mb_intr_rel_irq - Free the IRQ association with the OS
  * @adapter: adapter structure
@@ -417,6 +428,61 @@ iecm_mac_filter *iecm_find_mac_filter(struct iecm_vport *vport,
 	return NULL;
 }
 
+/**
+ * __iecm_del_mac_filter - Delete MAC filter helper
+ * @vport: main vport struct
+ * @macaddr: address to delete
+ *
+ * Takes mac_filter_list_lock spinlock to set remove field for filter in list.
+ */
+static struct
+iecm_mac_filter *__iecm_del_mac_filter(struct iecm_vport *vport,
+				       const u8 *macaddr)
+{
+	struct iecm_mac_filter *f;
+
+	spin_lock_bh(&vport->adapter->mac_filter_list_lock);
+	f = iecm_find_mac_filter(vport, macaddr);
+	if (f) {
+		/* If filter was never synced to HW we can just delete it here,

drivers/net/ethernet/intel/iecm/iecm_lib.c iecm_mac_filter *iecm_find_mac_filter(struct iecm_vport *vport, · line 457

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+		 * otherwise mark for removal.
+		 */
+		if (f->add) {
+			list_del(&f->list);
+			kfree(f);
+			f = NULL;
+		} else {
+			f->remove = true;
+		}
+	}
	if (!f)
		goto unlock;

-1 level.

Quoted 49 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +42 -0
+	spin_unlock_bh(&vport->adapter->mac_filter_list_lock);
+
+	return f;
+}
+
+/**
+ * iecm_del_mac_filter - Delete a MAC filter from the filter list
+ * @vport: main vport structure
+ * @macaddr: the MAC address
+ *
+ * Removes filter from list and if interface is up, tells hardware about the
+ * removed filter.
+ **/
+static void iecm_del_mac_filter(struct iecm_vport *vport, const u8 *macaddr)
+{
+	struct iecm_mac_filter *f;
+
+	if (!macaddr)
+		return;
+
+	f = __iecm_del_mac_filter(vport, macaddr);
+	if (!f)
+		return;
+
+	if (vport->adapter->state == __IECM_UP)
+		iecm_add_del_ether_addrs(vport, false, false);
+}
+
 /**
  * __iecm_add_mac_filter - Add mac filter helper function
  * @vport: main vport struct
@@ -1711,6 +1777,134 @@ void iecm_remove(struct pci_dev *pdev)
 }
 EXPORT_SYMBOL(iecm_remove);
 
+/**
+ * iecm_addr_sync - Callback for dev_(mc|uc)_sync to add address
+ * @netdev: the netdevice
+ * @addr: address to add
+ *
+ * Called by __dev_(mc|uc)_sync when an address needs to be added. We call
+ * __dev_(uc|mc)_sync from .set_rx_mode. Kernel takes addr_list_lock spinlock
+ * meaning we cannot sleep in this context. Due to this, we have to add the
+ * filter and send the virtchnl message asynchronously without waiting for the
+ * response from the other side. We won't know whether or not the operation
+ * actually succeeded until we get the message back.  Returns 0 on success,
+ * negative on failure.
+ */
+static int iecm_addr_sync(struct net_device *netdev, const u8 *addr)

drivers/net/ethernet/intel/iecm/iecm_lib.c void iecm_remove(struct pci_dev *pdev) · line 1803

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+
+	if (__iecm_add_mac_filter(vport, addr)) {
+		if (vport->adapter->state == __IECM_UP) {
+			set_bit(__IECM_ADD_ETH_REQ, vport->adapter->flags);
+			iecm_add_del_ether_addrs(vport, true, true);
+		}
+		return 0;
+	}
	if (!add_filter())
		return -ENOMEM;

	if (state != __IECM_UP)
		return 0;

	set_bit(...

-2 (!) levels.

Quoted 25 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +25 -0
+
+	return -ENOMEM;
+}
+
+/**
+ * iecm_addr_unsync - Callback for dev_(mc|uc)_sync to remove address
+ * @netdev: the netdevice
+ * @addr: address to add
+ *
+ * Called by __dev_(mc|uc)_sync when an address needs to be added. We call
+ * __dev_(uc|mc)_sync from .set_rx_mode. Kernel takes addr_list_lock spinlock
+ * meaning we cannot sleep in this context. Due to this we have to delete the
+ * filter and send the virtchnl message asychronously without waiting for the
+ * return from the other side.  We won't know whether or not the operation
+ * actually succeeded until we get the message back. Returns 0 on success,
+ * negative on failure.
+ */
+static int iecm_addr_unsync(struct net_device *netdev, const u8 *addr)
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+
+	/* Under some circumstances, we might receive a request to delete
+	 * our own device address from our uc list. Because we store the
+	 * device address in the VSI's MAC/VLAN filter list, we need to ignore
+	 * such requests and not delete our device address from this list.

drivers/net/ethernet/intel/iecm/iecm_lib.c void iecm_remove(struct pci_dev *pdev) · line 1838

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+	 */
+	if (ether_addr_equal(addr, netdev->dev_addr))
+		return 0;
+
+	if (__iecm_del_mac_filter(vport, addr)) {
+		if (vport->adapter->state == __IECM_UP) {
+			set_bit(__IECM_DEL_ETH_REQ, vport->adapter->flags);
+			iecm_add_del_ether_addrs(vport, false, true);
+		}
+	}

Very same here.

Quoted 57 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +57 -0
+
+	return 0;
+}
+
+/**
+ * iecm_set_rx_mode - NDO callback to set the netdev filters
+ * @netdev: network interface device structure
+ *
+ * Stack takes addr_list_lock spinlock before calling our .set_rx_mode.  We
+ * cannot sleep in this context.
+ */
+static void iecm_set_rx_mode(struct net_device *netdev)
+{
+	struct iecm_adapter *adapter = iecm_netdev_to_adapter(netdev);
+
+	if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_MACFILTER)) {
+		__dev_uc_sync(netdev, iecm_addr_sync, iecm_addr_unsync);
+		__dev_mc_sync(netdev, iecm_addr_sync, iecm_addr_unsync);
+	}
+
+	if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_PROMISC)) {
+		bool changed = false;
+
+		/* IFF_PROMISC enables both unicast and multicast promiscuous,
+		 * while IFF_ALLMULTI only enables multicast such that:
+		 *
+		 * promisc  + allmulti		= unicast | multicast
+		 * promisc  + !allmulti		= unicast | multicast
+		 * !promisc + allmulti		= multicast
+		 */
+		if ((netdev->flags & IFF_PROMISC) &&
+		    !test_and_set_bit(__IECM_PROMISC_UC,
+				      adapter->config_data.user_flags)) {
+			changed = true;
+			dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
+			if (!test_and_set_bit(__IECM_PROMISC_MC,
+					      adapter->flags))
+				dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n");
+		}
+		if (!(netdev->flags & IFF_PROMISC) &&
+		    test_and_clear_bit(__IECM_PROMISC_UC,
+				       adapter->config_data.user_flags)) {
+			changed = true;
+			dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
+		}
+		if (netdev->flags & IFF_ALLMULTI &&
+		    !test_and_set_bit(__IECM_PROMISC_MC,
+				      adapter->config_data.user_flags)) {
+			changed = true;
+			dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n");
+		}
+		if (!(netdev->flags & (IFF_ALLMULTI | IFF_PROMISC)) &&
+		    test_and_clear_bit(__IECM_PROMISC_MC,
+				       adapter->config_data.user_flags)) {
+			changed = true;
+			dev_info(&adapter->pdev->dev, "Leaving multicast promiscuous mode\n");
+		}

drivers/net/ethernet/intel/iecm/iecm_lib.c void iecm_remove(struct pci_dev *pdev) · line 1905

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+
+		if (changed) {
+			int err = iecm_set_promiscuous(adapter);
+
+			if (err) {
+				dev_info(&adapter->pdev->dev, "Failed to set promiscuous mode: %d\n",
+					 err);
+			}
+		}
+	}
	if (!cap_ena())
		return;

-1 level for a big pile of code.

Quoted 40 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +33 -0
+}
+
 /**
  * iecm_open - Called when a network interface becomes active
  * @netdev: network interface device structure
@@ -1730,6 +1924,49 @@ static int iecm_open(struct net_device *netdev)
 	return iecm_vport_open(np->vport, true);
 }
 
+/**
+ * iecm_set_mac - NDO callback to set port mac address
+ * @netdev: network interface device structure
+ * @p: pointer to an address structure
+ *
+ * Returns 0 on success, negative on failure
+ **/
+static int iecm_set_mac(struct net_device *netdev, void *p)
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+	struct iecm_mac_filter *f;
+	struct sockaddr *addr = p;
+
+	if (!iecm_is_cap_ena(vport->adapter, IECM_OTHER_CAPS,
+			     VIRTCHNL2_CAP_MACFILTER)) {
+		dev_info(&vport->adapter->pdev->dev, "Setting MAC address is not supported\n");
+		return -EOPNOTSUPP;
+	}
+
+	if (!is_valid_ether_addr(addr->sa_data)) {
+		dev_info(&vport->adapter->pdev->dev, "Invalid MAC address: %pM\n",
+			 addr->sa_data);
+		return -EADDRNOTAVAIL;
+	}
+
+	if (ether_addr_equal(netdev->dev_addr, addr->sa_data))
+		return 0;
+
+	/* Delete the current filter */
+	if (is_valid_ether_addr(vport->default_mac_addr))
+		iecm_del_mac_filter(vport, vport->default_mac_addr);

drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_open(struct net_device *netdev) · line 1967

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+
+	/* Add new filter */
+	f = iecm_add_mac_filter(vport, addr->sa_data);
+
+	if (f) {
+		ether_addr_copy(vport->default_mac_addr, addr->sa_data);
+		dev_addr_mod(netdev, 0, addr->sa_data, ETH_ALEN);
+	}
+
+	return f ? 0 : -ENOMEM;
	if (!f)
		return -ENOMEM;

	ether_addr(...
	dev_addr(...

	return 0;

Some unneeded complexity here.

Quoted 85 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +7 -5
+}
+
 void *iecm_alloc_dma_mem(struct iecm_hw *hw, struct iecm_dma_mem *mem, u64 size)
 {
 	struct iecm_adapter *adapter = (struct iecm_adapter *)hw->back;
@@ -1756,10 +1993,10 @@ void iecm_free_dma_mem(struct iecm_hw *hw, struct iecm_dma_mem *mem)
 static const struct net_device_ops iecm_netdev_ops_splitq = {
 	.ndo_open = iecm_open,
 	.ndo_stop = iecm_stop,
-	.ndo_start_xmit = NULL,
-	.ndo_set_rx_mode = NULL,
+	.ndo_start_xmit = iecm_tx_splitq_start,
+	.ndo_set_rx_mode = iecm_set_rx_mode,
 	.ndo_validate_addr = eth_validate_addr,
-	.ndo_set_mac_address = NULL,
+	.ndo_set_mac_address = iecm_set_mac,
 	.ndo_change_mtu = NULL,
 	.ndo_get_stats64 = NULL,
 	.ndo_fix_features = NULL,
@@ -1773,9 +2010,9 @@ static const struct net_device_ops iecm_netdev_ops_singleq = {
 	.ndo_open = iecm_open,
 	.ndo_stop = iecm_stop,
 	.ndo_start_xmit = NULL,
-	.ndo_set_rx_mode = NULL,
+	.ndo_set_rx_mode = iecm_set_rx_mode,
 	.ndo_validate_addr = eth_validate_addr,
-	.ndo_set_mac_address = NULL,
+	.ndo_set_mac_address = iecm_set_mac,
 	.ndo_change_mtu = NULL,
 	.ndo_get_stats64 = NULL,
 	.ndo_fix_features = NULL,
drivers/net/ethernet/intel/iecm/iecm_txrx.c +46 -0
index fb6a61277b00..ef5fe659389b 100644
@@ -1655,6 +1655,673 @@ int iecm_vport_queues_alloc(struct iecm_vport *vport)
 	return err;
 }
 
+/**
+ * iecm_tx_splitq_build_ctb - populate command tag and size for queue
+ * based scheduling descriptors
+ * @desc: descriptor to populate
+ * @parms: pointer to tx params struct
+ * @td_cmd: command to be filled in desc
+ * @size: size of buffer
+ */
+void
+iecm_tx_splitq_build_ctb(union iecm_tx_flex_desc *desc,
+			 struct iecm_tx_splitq_params *parms,
+			 u16 td_cmd, u16 size)
+{
+	desc->q.qw1.cmd_dtype =
+		cpu_to_le16(parms->dtype & IECM_FLEX_TXD_QW1_DTYPE_M);
+	desc->q.qw1.cmd_dtype |=
+		cpu_to_le16((td_cmd << IECM_FLEX_TXD_QW1_CMD_S) &
+			    IECM_FLEX_TXD_QW1_CMD_M);
+	desc->q.qw1.buf_size = cpu_to_le16((u16)size);
+	desc->q.qw1.flex.l2tags.l2tag1 = cpu_to_le16(parms->td_tag);
+}
+
+/**
+ * iecm_tx_splitq_build_flow_desc - populate command tag and size for flow
+ * scheduling descriptors
+ * @desc: descriptor to populate
+ * @parms: pointer to tx params struct
+ * @td_cmd: command to be filled in desc
+ * @size: size of buffer
+ */
+void
+iecm_tx_splitq_build_flow_desc(union iecm_tx_flex_desc *desc,
+			       struct iecm_tx_splitq_params *parms,
+			       u16 td_cmd, u16 size)
+{
+	desc->flow.qw1.cmd_dtype = (u16)parms->dtype | td_cmd;
+	desc->flow.qw1.rxr_bufsize = cpu_to_le16((u16)size);
+	desc->flow.qw1.compl_tag = cpu_to_le16(parms->compl_tag);
+}
+
+/**
+ * iecm_tx_buf_avail - Stop Tx if no enough book keeping buffers are available
+ * @tx_q: the queue to be checked
+ *
+ * Return -EBUSY if Tx queue stop is needed, else 0
+ */

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 1713

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+static int iecm_tx_buf_avail(struct iecm_queue *tx_q)
+{
+	/* If We have less than a quarter of the total desc_count left
+	 * stop the queue to wait for more completions
+	 */
+	if (unlikely(IECM_TX_BUF_UNUSED(tx_q) < tx_q->desc_count >> 2)) {
+		netif_stop_subqueue(tx_q->vport->netdev, tx_q->idx);
+		return -EBUSY;
+	}
+	return 0;
	if (likely(...))
		return 0;

What can be easier than this.
I also suggest to

#define iecm_tx_buf_threshold(q) ((q)->desc_count >> 2)

in order to be able to easily find and change this in the future.

Quoted 73 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +73 -0
+}
+
+/**
+ * __iecm_tx_maybe_stop - 2nd level check for Tx stop conditions
+ * @tx_q: the queue to be checked
+ * @size: the size buffer we want to assure is available
+ *
+ * Returns -EBUSY if a stop is needed, else 0
+ */
+static int
+__iecm_tx_maybe_stop(struct iecm_queue *tx_q, unsigned int size)
+{
+	netif_stop_subqueue(tx_q->vport->netdev, tx_q->idx);
+
+	/* Memory barrier before checking head and tail */
+	smp_mb();
+
+	/* Check again in a case another CPU has just made room available. */
+	if (likely(IECM_DESC_UNUSED(tx_q) < size))
+		return -EBUSY;
+
+	/* A reprieve! - use start_subqueue because it doesn't call schedule */
+	netif_start_subqueue(tx_q->vport->netdev, tx_q->idx);
+
+	return 0;
+}
+
+/**
+ * iecm_tx_maybe_stop - 1st level check for Tx stop conditions
+ * @tx_q: the queue to be checked
+ * @size: number of descriptors we want to assure is available
+ *
+ * Returns 0 if stop is not needed
+ */
+int iecm_tx_maybe_stop(struct iecm_queue *tx_q, unsigned int size)
+{
+	if (likely(IECM_DESC_UNUSED(tx_q) >= size))
+		return 0;
+
+	return __iecm_tx_maybe_stop(tx_q, size);
+}
+
+/**
+ * iecm_tx_buf_hw_update - Store the new tail value
+ * @tx_q: queue to bump
+ * @val: new tail index
+ * @xmit_more: more skb's pending
+ *
+ * The naming here is special in that 'hw' signals that this function is about
+ * to do a register write to update our queue status. We know this can only
+ * mean tail here as HW should be owning head for TX.
+ */
+void iecm_tx_buf_hw_update(struct iecm_queue *tx_q, u32 val,
+			   bool xmit_more)
+{
+	struct netdev_queue *nq;
+
+	nq = netdev_get_tx_queue(tx_q->vport->netdev, tx_q->idx);
+	tx_q->next_to_use = val;
+
+	iecm_tx_maybe_stop(tx_q, IECM_TX_DESC_NEEDED);
+
+	/* Force memory writes to complete before letting h/w
+	 * know there are new descriptors to fetch.  (Only
+	 * applicable for weak-ordered memory model archs,
+	 * such as IA-64).
+	 */
+	wmb();
+
+	/* notify HW of packet */
+	if (netif_xmit_stopped(nq) || !xmit_more)
+		writel(val, tx_q->tail);
+}

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 1796

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+
+/**
+ * iecm_size_to_txd_count - Get the number of descriptors needed for Tx
+ * @size: transmit request size in bytes
+ *
+ * Due to hardware alignment restrictions (4K alignment), we need to assume
+ * that we can have no more than 12K of data per descriptor, even though each
+ * descriptor can take up to 16K - 1 bytes of aligned memory.
+ */
+unsigned int iecm_size_to_txd_count(unsigned int size)

It seems to be used only in one file. Static then.
If it will be used in other files later, I'd suggest to make it non-static only then, but in general this should be a static inline as it's small and simple, but is being called from very perf-critical paths. Uninlining two math operations is a huge overkill.

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 1798

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +2 -0
+{
+	return (size / 12288) + IECM_TX_DESCS_FOR_SKB_DATA_PTR;

0. Braces around size / 12288 are not needed.

1. skb_headlen(skb) can hypothetically be == 0, as well as some skb_frag_size(frag). In this case, the function will return 1, although we don't need a descriptor for no data.
It is a rough mistake, it didn't harm only because zero-sized skb segs are not common (zero-sized heads are getting more used tho).

So,

	return size ? size / 12288 + overhead : 0;

2. The logics here is very obscure.
At first, I thought that it's a mistake to naturally-divide as we want it to be rounded-up. But then I realized that this FOR_SKB_DATA_PTR means 1 initial descriptor, thus rounding down. So, with pt. 1 in mind, it would look like

	return DIV_ROUND_UP(size, 12288);

For size == 0 it returns 0,
for size == 1 -> 1,
for 12288 -> 1,
for 12289 -> 2,
...

Oh wait. Your original function returns 1 for 12287 and 2 for 12288. Is that intentional? Does one descriptor fit 12287 or 12288 bytes? If 12287, then you should do DIV_ROUND_UP(size, 12287). If 12288, then use the code 10 lines above, and then it's a mistake in your code which returns 2 desc for 12288.

If I got the meaning of FOR_SKB_DATA_PTR wrong, then please explain. For now it looks like it's not a really fitting name, it sounds like it defines the overhead for one skb, not each fragment (and you call this function for each).

3. Please define 12288 somewhere and move the comment there. I also highly recommend to define it as

ALIGN_DOWN(SZ_16K - 1, SZ_4K)

This explicitly tells the reader that:
- a descriptor can take up to 16K - 1;
- we have the requirement of aligning everything to 4K;
- as 16K doesn't fit into (16K - 1) boundary, we align it down.

With this construction, I could get it even with no commentary, but for now 12288 looks like something magic or just random. Version from e1000 with mul byt 85 and shift by 20 looks even more cryptic. And 32-bit division on any 32-bit arch is atomic and fast.

I've just found that it's actually defined as IECM_TX_MAX_DESC_DATA_ALIGNED (open-coded instead of ALIGN_DOWN()). Please do it a make-up and use here instead of open-coding again and again.

With all those taken into account, this code looks optimal to me (keep in mind that this should be moved to a header file):

/*
* Comment about hardware reqs here
*/
#define IECM_TX_MAX_DESC_DATA_ALIGNED ALIGN_DOWN(SZ_16K - 1, SZ_4K)

...

static inline u32 iecm_size_to_txd_count(u32 size)

{
	return DIV_ROUND_UP(size, IECM_TX_MAX_DESC_DATA_ALIGNED);
}

If something changes in the hardware, you'd only need to adjust the IECM_TX_MAX_BUFFER_LEN and the comment above it, and that's all.

Summarizing, it seems like this hasn't been tested on corner cases, e.g. with skb which has its headlen or one of the frag's len 0, 1, 12287, 12288 and 12289, maybe even hasn't been tested with some frag (or head) larger than 12288 at all (usually it's no larger than PAGE_SIZE, i.e. SZ_4K on x86).
You can craft an arbitrary packet using raw sockets or write a simple self-test in the iecm or idpf module which will create a new skb with your own params right in the kernel (your module) and send it to the wire.

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 1807

Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +9 -0
+}
+
+/**
+ * iecm_tx_desc_count_required - calculate number of Tx descriptors needed
+ * @skb: send buffer
+ *
+ * Returns number of data descriptors needed for this skb.
+ */
+unsigned int iecm_tx_desc_count_required(struct sk_buff *skb)

You only read the skb fields and ptrs, it should be const.

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+{
+	const skb_frag_t *frag = &skb_shinfo(skb)->frags[0];
+	unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
+	unsigned int count = 0, size = skb_headlen(skb);
+
+	for (;;) {

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 1823

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+		count += iecm_size_to_txd_count(size);
+
+		if (!nr_frags--)
+			break;
+
+		size = skb_frag_size(frag++);
+	}
+
+	return count;
+}
	const skb_frag_t *frags = skb_shinfo(skb)->frags;
	u32 i, count = 0;

	for (i = 0; i = skb_shinfo(skb)->nr_frags; i++)
		count += iecm_size_to_txd_count(skb_frag_size(frags + i));

	return count + iecm_size_to_txd_count(skb_headlen(skb));

Two times smaller, two times more readable and I bet the object code will be more optimized.

Quoted 42 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +42 -0
+
+/**
+ * iecm_tx_splitq_map - Build the Tx flex descriptor
+ * @tx_q: queue to send buffer on
+ * @parms: pointer to splitq params struct
+ * @first: first buffer info buffer to use
+ *
+ * This function loops over the skb data pointed to by *first
+ * and gets a physical address for each memory location and programs
+ * it and the length into the transmit flex descriptor.
+ */
+static void
+iecm_tx_splitq_map(struct iecm_queue *tx_q,
+		   struct iecm_tx_splitq_params *parms,
+		   struct iecm_tx_buf *first)
+{
+	union iecm_tx_flex_desc *tx_desc;
+	unsigned int data_len, size;
+	struct iecm_tx_buf *tx_buf;
+	u16 i = tx_q->next_to_use;
+	struct netdev_queue *nq;
+	struct sk_buff *skb;
+	skb_frag_t *frag;
+	u16 td_cmd = 0;
+	dma_addr_t dma;
+
+	skb = first->skb;
+
+	td_cmd = parms->offload.td_cmd;
+	parms->compl_tag = tx_q->tx_buf_key;
+
+	data_len = skb->data_len;
+	size = skb_headlen(skb);
+
+	tx_desc = IECM_FLEX_TX_DESC(tx_q, i);
+
+	dma = dma_map_single(tx_q->dev, skb->data, size, DMA_TO_DEVICE);
+
+	tx_buf = first;
+
+	for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
+		unsigned int max_data = IECM_TX_MAX_DESC_DATA_ALIGNED;

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 1875

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+
+		if (dma_mapping_error(tx_q->dev, dma))
+			goto dma_error;
+
+		/* record length, and DMA address */
+		dma_unmap_len_set(tx_buf, len, size);
+		dma_unmap_addr_set(tx_buf, dma, dma);
+
+		/* align size to end of page */
+		max_data += -dma & (IECM_TX_MAX_READ_REQ_SIZE - 1);

Super-cryptic. What is going on here?
dma_addr_t is unsigned and its bit-width can vary a lot depending on the platform, playing with signedness is playing with fire here. max_data is unsigned.
My test program gave me:

dma: 1
-dma & 4095: 4095
max_data: 16383

max_data is initially set to 12288 which is claimed to be the maximum Tx desc buffer size. And now you increase it to SZ_16K - 1. Either your comment above is incorrect, or this logics is.

dma: 4096
-dma & 4095: 0
max_data: 12288

Ok, maybe I got it, this cryptic -dma & 4095 is basically the distance from the address to the next HW boundary:

rem = 4096 - dma & (4096 - 1);

While your code looks more compact, it at least needs some comments on why you do that.
Still no idea what max_data is. For both dma == 0 and dma == 4096 it equals to 12288.

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 1883

Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +8 -0
+
+		/* buf_addr is in same location for both desc types */
+		tx_desc->q.buf_addr = cpu_to_le64(dma);
+
+		/* account for data chunks larger than the hardware
+		 * can handle
+		 */
+		while (unlikely(size > IECM_TX_MAX_DESC_DATA)) {

In the function which counts the number of descs needed you check head and frag length against 12288, and here's a check against 16383.
I either don't get something basic, or this is another mistake.

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 1885

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +2 -0
+			parms->splitq_build_ctb(tx_desc, parms, td_cmd,
+						max_data);

And now you add indirect calls to hotpath, which on x86_64 is expensive as hell with retpolines.

I checked your previous patch where you set this callback, and there's absolutely no reason for introducing a callback here. It can be set to one of two functions already defined in the same module. So basically it's just a boolean 0/1 or direct bitmap test. At least it could be declared with INDIRECT_CALLABLE_DECLARE() + INDIRECT_CALL_2() to convert it into if-else on x86 with retpolines. But indirect call wrappers are made in mind that the actual callback might be something different from 1st or 2nd function, and in this case it can not.
So it's a pure if-else put into a static inline for convenience.

Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +8 -0
+
+			tx_desc++;
+			i++;
+
+			if (i == tx_q->desc_count) {
+				tx_desc = IECM_FLEX_TX_DESC(tx_q, 0);
+				i = 0;
+			}

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 1903

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+
+			dma += max_data;
+			size -= max_data;
+
+			max_data = IECM_TX_MAX_DESC_DATA_ALIGNED;
+			/* buf_addr is in same location for both desc types */
+			tx_desc->q.buf_addr = cpu_to_le64(dma);
+		}
+
+		if (likely(!data_len))

GSO packets can have up to 16 frags (re. that this driver doesn't support fraglists) and is turned on by default. Driver advertises support for both TSO and UDP L4 GSO, which means that such skbs will be a relatively common thing.
And each of them will hit the unlikely condition branch 15 times. Like one indirect call per each segment was not enough to kill the performance.

Quoted 214 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +214 -0
+			break;
+		parms->splitq_build_ctb(tx_desc, parms, td_cmd, size);
+		tx_desc++;
+		i++;
+
+		if (i == tx_q->desc_count) {
+			tx_desc = IECM_FLEX_TX_DESC(tx_q, 0);
+			i = 0;
+		}
+
+		size = skb_frag_size(frag);
+		data_len -= size;
+
+		dma = skb_frag_dma_map(tx_q->dev, frag, 0, size,
+				       DMA_TO_DEVICE);
+
+		tx_buf->compl_tag = parms->compl_tag;
+		tx_buf = &tx_q->tx_buf[i];
+	}
+
+	/* record bytecount for BQL */
+	nq = netdev_get_tx_queue(tx_q->vport->netdev, tx_q->idx);
+	netdev_tx_sent_queue(nq, first->bytecount);
+
+	/* record SW timestamp if HW timestamp is not available */
+	skb_tx_timestamp(first->skb);
+
+	/* write last descriptor with RS and EOP bits */
+	td_cmd |= parms->eop_cmd;
+	parms->splitq_build_ctb(tx_desc, parms, td_cmd, size);
+	i++;
+	if (i == tx_q->desc_count)
+		i = 0;
+
+	/* set next_to_watch value indicating a packet is present */
+	first->next_to_watch = tx_desc;
+	tx_buf->compl_tag = parms->compl_tag++;
+
+	iecm_tx_buf_hw_update(tx_q, i, netdev_xmit_more());
+
+	/* Update TXQ Completion Tag key for next buffer */
+	tx_q->tx_buf_key = parms->compl_tag;
+
+	return;
+
+dma_error:
+	/* clear dma mappings for failed tx_buf map */
+	for (;;) {
+		tx_buf = &tx_q->tx_buf[i];
+		iecm_tx_buf_rel(tx_q, tx_buf);
+		if (tx_buf == first)
+			break;
+		if (i == 0)
+			i = tx_q->desc_count;
+		i--;
+	}
+
+	tx_q->next_to_use = i;
+}
+
+/**
+ * iecm_tx_prepare_vlan_flags - prepare generic vlan tagging for HW
+ * @tx_q: txq to find the tag location
+ * @first: pointer to struct iecm_tx_buf
+ * @skb: skb being xmitted
+ */
+void iecm_tx_prepare_vlan_flags(struct iecm_queue *tx_q,
+				struct iecm_tx_buf *first,
+				struct sk_buff *skb)
+{
+	struct iecm_vport *vport = tx_q->vport;
+	u32 tx_flags = 0;
+
+	/* Stack sets protocol to 8021q when offload is disabled so SW can take
+	 * any necessary steps to handle it.  We don't need to do anything,
+	 * just set protocol to encapsulated type.
+	 */
+	if (skb->protocol == htons(ETH_P_8021Q) &&
+	    !iecm_is_feature_ena(vport, NETIF_F_HW_VLAN_CTAG_RX)) {
+		skb->protocol = vlan_get_protocol(skb);
+		return;
+	}
+
+	if (!skb_vlan_tag_present(skb))
+		return;
+
+	tx_flags |= skb_vlan_tag_get(skb) << IECM_TX_FLAGS_VLAN_SHIFT;
+	tx_flags |= IECM_TX_FLAGS_VLAN_TAG;
+	if (test_bit(__IECM_Q_VLAN_TAG_LOC_L2TAG2, tx_q->flags))
+		tx_flags |= IECM_TX_FLAGS_HW_OUTER_SINGLE_VLAN;
+	else if (test_bit(__IECM_Q_VLAN_TAG_LOC_L2TAG1, tx_q->flags))
+		tx_flags |= IECM_TX_FLAGS_HW_VLAN;
+	else
+		dev_dbg(&vport->adapter->pdev->dev, "Unsupported Tx VLAN tag location requested\n");
+
+	first->tx_flags |= tx_flags;
+}
+
+/**
+ * iecm_tso - computes mss and TSO length to prepare for TSO
+ * @first: pointer to struct iecm_tx_buf
+ * @off: pointer to struct that holds offload parameters
+ *
+ * Returns error (negative) if TSO doesn't apply to the given skb,
+ * 0 otherwise.
+ *
+ * Note: this function can be used in the splitq and singleq paths
+ */
+int iecm_tso(struct iecm_tx_buf *first, struct iecm_tx_offload_params *off)
+{
+	struct sk_buff *skb = first->skb;
+	union {
+		struct iphdr *v4;
+		struct ipv6hdr *v6;
+		unsigned char *hdr;
+	} ip;
+	union {
+		struct tcphdr *tcp;
+		struct udphdr *udp;
+		unsigned char *hdr;
+	} l4;
+	u32 paylen, l4_start;
+	int err;
+
+	if (!skb_is_gso(skb))
+		return 0;
+
+	err = skb_cow_head(skb, 0);
+	if (err < 0)
+		return err;
+
+	ip.hdr = skb_network_header(skb);
+	l4.hdr = skb_transport_header(skb);
+
+	/* initialize outer IP header fields */
+	if (ip.v4->version == 4) {
+		ip.v4->tot_len = 0;
+		ip.v4->check = 0;
+	} else if (ip.v4->version == 6) {
+		ip.v6->payload_len = 0;
+	} else {
+		return -EINVAL;
+	}
+
+	l4_start = skb_transport_offset(skb);
+
+	/* remove payload length from checksum */
+	paylen = skb->len - l4_start;
+
+	switch (skb_shinfo(skb)->gso_type) {
+	case SKB_GSO_TCPV4:
+	case SKB_GSO_TCPV6:
+		csum_replace_by_diff(&l4.tcp->check,
+				     (__force __wsum)htonl(paylen));
+
+		/* compute length of segmentation header */
+		off->tso_hdr_len = tcp_hdrlen(skb) + l4_start;
+		break;
+	case SKB_GSO_UDP_L4:
+		csum_replace_by_diff(&l4.udp->check,
+				     (__force __wsum)htonl(paylen));
+		/* compute length of segmentation header */
+		off->tso_hdr_len = sizeof(struct udphdr) + l4_start;
+		l4.udp->len =
+			htons(skb_shinfo(skb)->gso_size +
+			      sizeof(struct udphdr));
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	off->tso_len = skb->len - off->tso_hdr_len;
+	off->mss = skb_shinfo(skb)->gso_size;
+
+	/* update gso_segs and bytecount */
+	first->gso_segs = skb_shinfo(skb)->gso_segs;
+	first->bytecount = qdisc_skb_cb(skb)->pkt_len;
+
+	first->tx_flags |= IECM_TX_FLAGS_TSO;
+
+	return 0;
+}
+
+/**
+ * __iecm_chk_linearize - Check skb is not using too many buffers
+ * @skb: send buffer
+ * @max_bufs: maximum number of buffers
+ *
+ * For TSO we need to count the TSO header and segment payload separately.  As
+ * such we need to check cases where we have max_bufs-1 fragments or more as we
+ * can potentially require max_bufs+1 DMA transactions, 1 for the TSO header, 1
+ * for the segment payload in the first descriptor, and another max_buf-1 for
+ * the fragments.
+ */
+static bool __iecm_chk_linearize(struct sk_buff *skb, unsigned int max_bufs)
+{
+	const skb_frag_t *frag, *stale;
+	int nr_frags, sum;
+
+	/* no need to check if number of frags is less than max_bufs - 1 */
+	nr_frags = skb_shinfo(skb)->nr_frags;
+	if (nr_frags < (max_bufs - 1))
+		return false;
+
+	/* We need to walk through the list and validate that each group
+	 * of max_bufs-2 fragments totals at least gso_size.
+	 */
+	nr_frags -= max_bufs - 2;
+	frag = &skb_shinfo(skb)->frags[0];
+
+	/* Initialize size to the negative value of gso_size minus 1.  We use
+	 * this as the worst case scenario in which the frag ahead of us only
+	 * provides one byte which is why we are limited to max_bufs-2
+	 * descriptors for a single transmit as the header and previous

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 2127

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+	 * fragment are already consuming 2 descriptors.
+	 */
+	sum = 1 - skb_shinfo(skb)->gso_size;
+
+	/* Add size of frags 0 through 4 to create our initial sum */
+	sum += skb_frag_size(frag++);
+	sum += skb_frag_size(frag++);
+	sum += skb_frag_size(frag++);
+	sum += skb_frag_size(frag++);
+	sum += skb_frag_size(frag++);

There can be junk values if shinfo->nr_frags < 5. It's not a rare case to have a small GSO packet.
It should check for shinfo->nr_frags first.

Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +8 -0
+
+	/* Walk through fragments adding latest fragment, testing it, and
+	 * then removing stale fragments from the sum.
+	 */
+	for (stale = &skb_shinfo(skb)->frags[0];; stale++) {
+		int stale_size = skb_frag_size(stale);
+
+		sum += skb_frag_size(frag++);

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 2145

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+
+		/* The stale fragment may present us with a smaller
+		 * descriptor than the actual fragment size. To account
+		 * for that we need to remove all the data on the front and
+		 * figure out what the remainder would be in the last
+		 * descriptor associated with the fragment.
+		 */
+		if (stale_size > IECM_TX_MAX_DESC_DATA) {
+			int align_pad = -(skb_frag_off(stale)) &
+					(IECM_TX_MAX_READ_REQ_SIZE - 1);

Open-coded stuff again. Please define this operation once and use the definition.

Quoted 60 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +60 -0
+
+			sum -= align_pad;
+			stale_size -= align_pad;
+
+			do {
+				sum -= IECM_TX_MAX_DESC_DATA_ALIGNED;
+				stale_size -= IECM_TX_MAX_DESC_DATA_ALIGNED;
+			} while (stale_size > IECM_TX_MAX_DESC_DATA);
+		}
+
+		/* if sum is negative we failed to make sufficient progress */
+		if (sum < 0)
+			return true;
+
+		if (!nr_frags--)
+			break;
+
+		sum -= stale_size;
+	}
+
+	return false;
+}
+
+/**
+ * iecm_chk_linearize - Check if skb exceeds max descriptors per packet
+ * @skb: send buffer
+ * @max_bufs: maximum scatter gather buffers for single packet
+ * @count: number of buffers this packet needs
+ *
+ * Make sure we don't exceed maximum scatter gather buffers for a single
+ * packet. We have to do some special checking around the boundary (max_bufs-1)
+ * if TSO is on since we need count the TSO header and payload separately.
+ * E.g.: a packet with 7 fragments can require 9 DMA transactions; 1 for TSO
+ * header, 1 for segment payload, and then 7 for the fragments.
+ */
+bool iecm_chk_linearize(struct sk_buff *skb, unsigned int max_bufs,
+			unsigned int count)
+{
+	if (likely(count < max_bufs))
+		return false;
+	if (skb_is_gso(skb))
+		return __iecm_chk_linearize(skb, max_bufs);
+
+	return count != max_bufs;
+}
+
+/**
+ * iecm_tx_splitq_frame - Sends buffer on Tx ring using flex descriptors
+ * @skb: send buffer
+ * @tx_q: queue to send buffer on
+ *
+ * Returns NETDEV_TX_OK if sent, else an error code
+ */
+static netdev_tx_t
+iecm_tx_splitq_frame(struct sk_buff *skb, struct iecm_queue *tx_q)
+{
+	struct iecm_tx_splitq_params tx_parms = {
+		NULL, (enum iecm_tx_desc_dtype_value)0, 0, {0}, {0}
+	};
+	struct iecm_tx_buf *first;

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 2215

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+	unsigned int count;
+
+	count = iecm_tx_desc_count_required(skb);
+	if (iecm_chk_linearize(skb, tx_q->tx_max_bufs, count)) {
+		if (__skb_linearize(skb)) {
+			dev_kfree_skb_any(skb);
+			return NETDEV_TX_OK;
+		}
+		count = iecm_size_to_txd_count(skb->len);
+		tx_q->vport->port_stats.tx_linearize++;

Why is this counter not protected with u64_stats? Also, please use u64_stats_t type for statistics. It provides tearing protection for 64-bit plaforms. Using plain u64 is discouraged.

Quoted 40 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +40 -0
+	}
+
+	if (iecm_tx_maybe_stop(tx_q, count + IECM_TX_DESCS_PER_CACHE_LINE +
+			       IECM_TX_DESCS_FOR_CTX)) {
+		return NETDEV_TX_BUSY;
+	}
+
+	/* Also check for available book keeping buffers */
+	if (iecm_tx_buf_avail(tx_q))
+		return NETDEV_TX_BUSY;
+
+	/* record the location of the first descriptor for this packet */
+	first = &tx_q->tx_buf[tx_q->next_to_use];
+	first->skb = skb;
+	first->bytecount = max_t(unsigned int, skb->len, ETH_ZLEN);
+	first->gso_segs = 1;
+	first->tx_flags = 0;
+
+	iecm_tx_prepare_vlan_flags(tx_q, first, skb);
+
+	if (iecm_tso(first, &tx_parms.offload) < 0) {
+		/* If tso returns an error, drop the packet */
+		dev_kfree_skb_any(skb);
+		return NETDEV_TX_OK;
+	}
+
+	if (first->tx_flags & IECM_TX_FLAGS_TSO) {
+		/* If tso is needed, set up context desc */
+		union iecm_flex_tx_ctx_desc *ctx_desc;
+		int i = tx_q->next_to_use;
+
+		/* grab the next descriptor */
+		ctx_desc = IECM_FLEX_TX_CTX_DESC(tx_q, i);
+		i++;
+		tx_q->next_to_use = (i < tx_q->desc_count) ? i : 0;
+
+		ctx_desc->tso.qw1.cmd_dtype =
+				cpu_to_le16(IECM_TX_DESC_DTYPE_FLEX_TSO_CTX |
+					    IECM_TX_FLEX_CTX_DESC_CMD_TSO);
+		ctx_desc->tso.qw0.flex_tlen =

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 2265

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+				cpu_to_le32(tx_parms.offload.tso_len &
+					    IECM_TXD_FLEX_CTX_TLEN_M);
+		ctx_desc->tso.qw0.mss_rt =
+				cpu_to_le16(tx_parms.offload.mss &
+					    IECM_TXD_FLEX_CTX_MSS_RT_M);
+		ctx_desc->tso.qw0.hdr_len = tx_parms.offload.tso_hdr_len;
+
+		u64_stats_update_begin(&tx_q->stats_sync);
+		tx_q->q_stats.tx.lso_pkts++;
+		u64_stats_update_end(&tx_q->stats_sync);

And this is protected...

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 2270

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +5 -0
+	}
+
+	if (test_bit(__IECM_Q_FLOW_SCH_EN, tx_q->flags)) {
+		tx_parms.dtype = IECM_TX_DESC_DTYPE_FLEX_FLOW_SCHE;
+		tx_parms.splitq_build_ctb = iecm_tx_splitq_build_flow_desc;

Here's what I was talking about. There's absolutely no need to create indirect call overhead just because of one if-else. Just replace this callback with u8 flow : 1; and assign 0 or 1 here in this function. Use a static inline to call the appropriate function depending on the value of flow.

Quoted 98 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +54 -0
+		tx_parms.eop_cmd =
+			IECM_TXD_FLEX_FLOW_CMD_EOP | IECM_TXD_FLEX_FLOW_CMD_RE;
+
+		if (skb->ip_summed == CHECKSUM_PARTIAL)
+			tx_parms.offload.td_cmd |= IECM_TXD_FLEX_FLOW_CMD_CS_EN;
+
+	} else {
+		tx_parms.dtype = IECM_TX_DESC_DTYPE_FLEX_L2TAG1_L2TAG2;
+		tx_parms.splitq_build_ctb = iecm_tx_splitq_build_ctb;
+		tx_parms.eop_cmd = IECM_TXD_LAST_DESC_CMD;
+
+		if (skb->ip_summed == CHECKSUM_PARTIAL)
+			tx_parms.offload.td_cmd |= IECM_TX_FLEX_DESC_CMD_CS_EN;
+
+		/* VLAN Offload can only be used with queue based scheduling */
+		if (first->tx_flags & IECM_TX_FLAGS_VLAN_TAG) {
+			tx_parms.offload.td_cmd |= (u64)IECM_TX_FLEX_DESC_CMD_IL2TAG1;
+			tx_parms.td_tag = (first->tx_flags & IECM_TX_FLAGS_VLAN_MASK) >>
+					  IECM_TX_FLAGS_VLAN_SHIFT;
+		}
+	}
+
+	iecm_tx_splitq_map(tx_q, &tx_parms, first);
+
+	return NETDEV_TX_OK;
+}
+
+/**
+ * iecm_tx_splitq_start - Selects the right Tx queue to send buffer
+ * @skb: send buffer
+ * @netdev: network interface device structure
+ *
+ * Returns NETDEV_TX_OK if sent, else an error code
+ */
+netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,
+				 struct net_device *netdev)
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+	struct iecm_queue *tx_q;
+
+	if (skb->queue_mapping >= vport->num_txq)
+		return -EINVAL;
+
+	tx_q = vport->txqs[skb->queue_mapping];
+
+	/* hardware can't handle really short frames, hardware padding works
+	 * beyond this point
+	 */
+	if (skb_put_padto(skb, IECM_TX_MIN_LEN))
+		return NETDEV_TX_OK;
+
+	return iecm_tx_splitq_frame(skb, tx_q);
+}
+
 /**
  * iecm_vport_intr_clean_queues - MSIX mode Interrupt Handler
  * @irq: interrupt number
drivers/net/ethernet/intel/include/iecm.h +1 -0
index 4304256f7010..f6f9884c10c2 100644
@@ -717,6 +717,7 @@ 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);
+struct iecm_adapter *iecm_netdev_to_adapter(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,
drivers/net/ethernet/intel/include/iecm_txrx.h +14 -0
index 5e29148938fb..26e480343876 100644
@@ -115,6 +115,11 @@
 
 #define MAKEMASK(m, s)	((m) << (s))
 
+union iecm_tx_flex_desc {
+	struct iecm_flex_tx_desc q; /* queue based scheduling */
+	struct iecm_flex_tx_sched_desc flow; /* flow based scheduling */
+};
+
 struct iecm_tx_buf {
 	struct hlist_node hlist;
 	void *next_to_watch;
@@ -145,6 +150,37 @@ struct iecm_buf_lifo {
 	struct iecm_tx_buf **bufs;
 };
 
+struct iecm_tx_offload_params {
+	u16 td_cmd;	/* command field to be inserted into descriptor */
+	u32 tso_len;	/* total length of payload to segment */
+	u16 mss;
+	u8 tso_hdr_len;	/* length of headers to be duplicated */
+
+	/* Flow scheduling offload timestamp, formatting as hw expects it */
+	/* timestamp = bits[0:22], overflow = bit[23] */
+	u8 desc_ts[3];

drivers/net/ethernet/intel/include/iecm_txrx.h struct iecm_buf_lifo { · line 171

Quoted 10 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +10 -0
+
+	/* For legacy offloads */
+	u32 hdr_offsets;
+};
+
+struct iecm_tx_splitq_params {
+	/* Descriptor build function pointer */
+	void (*splitq_build_ctb)(union iecm_tx_flex_desc *desc,
+				 struct iecm_tx_splitq_params *params,
+				 u16 td_cmd, u16 size);
	^^^^^^^^^^^^^^^^^^^^^^^^
	This one.
Quoted 43 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +28 -0
+
+	/* General descriptor info */
+	enum iecm_tx_desc_dtype_value dtype;
+	u16 eop_cmd;
+	union {
+		u16 compl_tag; /* only relevant for flow scheduling */
+		u16 td_tag; /* only relevant for queue scheduling */
+	};
+
+	struct iecm_tx_offload_params offload;
+};
+
 /* Checksum offload bits decoded from the receive descriptor. */
 struct iecm_rx_csum_decoded {
 	u8 l3l4p : 1;
@@ -588,6 +624,12 @@ struct iecm_txq_group {
 
 struct iecm_adapter;
 
+void iecm_tx_splitq_build_ctb(union iecm_tx_flex_desc *desc,
+			      struct iecm_tx_splitq_params *parms,
+			      u16 td_cmd, u16 size);
+void iecm_tx_splitq_build_flow_desc(union iecm_tx_flex_desc *desc,
+				    struct iecm_tx_splitq_params *parms,
+				    u16 td_cmd, u16 size);
 int iecm_vport_singleq_napi_poll(struct napi_struct *napi, int budget);
 void iecm_vport_init_num_qs(struct iecm_vport *vport,
 			    struct virtchnl2_create_vport *vport_msg);
@@ -614,7 +656,25 @@ int iecm_init_rss(struct iecm_vport *vport);
 void iecm_deinit_rss(struct iecm_vport *vport);
 bool iecm_init_rx_buf_hw_alloc(struct iecm_queue *rxq, struct iecm_rx_buf *buf);
 void iecm_rx_buf_hw_update(struct iecm_queue *rxq, u32 val);
+void iecm_tx_buf_hw_update(struct iecm_queue *tx_q, u32 val,
+			   bool xmit_more);
 void iecm_tx_buf_rel(struct iecm_queue *tx_q, struct iecm_tx_buf *tx_buf);
+unsigned int iecm_size_to_txd_count(unsigned int size);
+unsigned int iecm_tx_desc_count_required(struct sk_buff *skb);
+bool iecm_chk_linearize(struct sk_buff *skb, unsigned int max_bufs,
+			unsigned int count);
+int iecm_tx_maybe_stop(struct iecm_queue *tx_q, unsigned int size);
+void iecm_tx_timeout(struct net_device *netdev,
+		     unsigned int __always_unused txqueue);
+netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,

drivers/net/ethernet/intel/include/iecm_txrx.h int iecm_init_rss(struct iecm_vport *vport); · line 679

Quoted 10 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +8 -0
+				 struct net_device *netdev);
+netdev_tx_t iecm_tx_singleq_start(struct sk_buff *skb,
+				  struct net_device *netdev);
 bool iecm_rx_singleq_buf_hw_alloc_all(struct iecm_queue *rxq,
 				      u16 cleaned_count);
+int iecm_tso(struct iecm_tx_buf *first, struct iecm_tx_offload_params *off);
+void iecm_tx_prepare_vlan_flags(struct iecm_queue *tx_q,
+				struct iecm_tx_buf *first,
+				struct sk_buff *skb);
+

At least some of these functions can be made static. Please double-check.

Quoted 3 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +0 -0
 #endif /* !_IECM_TXRX_H_ */
Signature · 1 line
2.33.0

Thanks,
Al

author
#49 lore raw

PATCH 12/19 iecm: finish netdev_ops

In reply to Alan Brady

This fills out the remaining NDO callbacks. Once netdev_ops are there, the rest of the patches will fill out the data path and advanced features.

---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    | 742 +++++++++++++++++-
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   |  15 +
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   |  63 ++
 drivers/net/ethernet/intel/include/iecm.h     |  14 +
 .../net/ethernet/intel/include/iecm_txrx.h    |   2 +
 5 files changed, 822 insertions(+), 14 deletions(-)
drivers/net/ethernet/intel/iecm/iecm_lib.c +728 -14
index 003057f48f0c..cc82e665dfaf 100644
@@ -568,6 +568,147 @@ static void iecm_set_all_filters(struct iecm_vport *vport)
 	iecm_add_del_ether_addrs(vport, true, false);
 }
 
+/**
+ * iecm_find_vlan - Search filter list for specific vlan filter
+ * @vport: vport structure
+ * @vlan: vlan tag
+ *
+ * Returns ptr to the filter object or NULL. Must be called while holding the
+ * vlan_list_lock.
+ */
+static struct
+iecm_vlan_filter *iecm_find_vlan(struct iecm_vport *vport,
+				 struct iecm_vlan *vlan)
+{
+	struct iecm_vlan_filter *f;
+
+	list_for_each_entry(f, &vport->adapter->config_data.vlan_filter_list,
+			    list) {
+		if (vlan->vid == f->vlan.vid && vlan->tpid == f->vlan.tpid)
+			return f;
+	}
+	return NULL;
+}
+
+/**
+ * iecm_add_vlan - Add a vlan filter to the list
+ * @vport: vport structure
+ * @vlan: VLAN tag
+ *
+ * Returns ptr to the filter object or NULL when no memory available.
+ */
+static struct
+iecm_vlan_filter *iecm_add_vlan(struct iecm_vport *vport,
+				struct iecm_vlan *vlan)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_vlan_filter *f = NULL;
+
+	spin_lock_bh(&adapter->vlan_list_lock);
+
+	f = iecm_find_vlan(vport, vlan);
+	if (!f) {
+		f = kzalloc(sizeof(*f), GFP_ATOMIC);
+		if (!f)
+			goto error;
+
+		f->vlan.vid = vlan->vid;
+		f->vlan.tpid = vlan->tpid;
+
+		list_add_tail(&f->list, &adapter->config_data.vlan_filter_list);
+		f->add = true;
+	}
+
+error:
+	spin_unlock_bh(&adapter->vlan_list_lock);
+	return f;
+}
+
+/**
+ * iecm_del_vlan - Remove a vlan filter from the list
+ * @vport: vport structure
+ * @vlan: VLAN tag
+ */
+static void iecm_del_vlan(struct iecm_vport *vport, struct iecm_vlan *vlan)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_vlan_filter *f;
+
+	spin_lock_bh(&adapter->vlan_list_lock);
+
+	f = iecm_find_vlan(vport, vlan);
+	if (f)
+		f->remove = true;
+
+	spin_unlock_bh(&adapter->vlan_list_lock);
+}
+
+/**
+ * iecm_vlan_rx_add_vid - Add a VLAN filter to the device
+ * @netdev: network device struct
+ * @proto: unused protocol data
+ * @vid: VLAN tag
+ *
+ * Returns 0 on success
+ */
+static int iecm_vlan_rx_add_vid(struct net_device *netdev,
+				__always_unused __be16 proto, u16 vid)
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_vlan vlan;
+
+	vlan = IECM_VLAN(vid, be16_to_cpu(proto));
+	if (!iecm_is_feature_ena(vport, NETIF_F_HW_VLAN_CTAG_FILTER))
+		return -EINVAL;
+
+	iecm_add_vlan(vport, &vlan);
+
+	if (adapter->state == __IECM_UP)
+		adapter->dev_ops.vc_ops.add_del_vlans(vport, true);
+
+	return 0;
+}
+
+/**
+ * iecm_vlan_rx_kill_vid - Remove a VLAN filter from the device
+ * @netdev: network device struct
+ * @proto: unused protocol data
+ * @vid: VLAN tag
+ *
+ * Returns 0 on success
+ */
+static int iecm_vlan_rx_kill_vid(struct net_device *netdev,
+				 __always_unused __be16 proto, u16 vid)
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_vlan_filter *f, *ftmp;
+	struct iecm_vlan vlan;
+
+	vlan = IECM_VLAN(vid, be16_to_cpu(proto));
+	if (!iecm_is_feature_ena(vport, NETIF_F_HW_VLAN_CTAG_FILTER))
+		return -EINVAL;
+
+	if (vport->adapter->state == __IECM_UP) {
+		iecm_del_vlan(vport, &vlan);
+		adapter->dev_ops.vc_ops.add_del_vlans(vport, false);
+	}
+	/* It is safe to delete entry from the list now */
+	spin_lock_bh(&adapter->vlan_list_lock);
+	list_for_each_entry_safe(f, ftmp,
+				 &adapter->config_data.vlan_filter_list,
+				 list) {
+		if (f->vlan.vid == vlan.vid && f->vlan.tpid == vlan.tpid) {
+			list_del(&f->list);
+			kfree(f);
+		}
+	}
+	spin_unlock_bh(&adapter->vlan_list_lock);
+
+	return 0;
+}
+
 /**
  * iecm_set_all_vlans - Re-add all VLANs in list
  * @vport: main vport struct
@@ -804,6 +945,27 @@ static int iecm_get_free_slot(void *array, int size, int curr)
 	return next;
 }
 
+/**
+ * iecm_remove_vlan_filters - Remove all vlan filters
+ * @vport: vport structure
+ */
+static void iecm_remove_vlan_filters(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_user_config_data *config_data;
+
+	config_data = &adapter->config_data;
+	if (!list_empty(&config_data->vlan_filter_list)) {
+		struct iecm_vlan_filter *f;
+
+		spin_lock_bh(&adapter->vlan_list_lock);
+		list_for_each_entry(f, &config_data->vlan_filter_list, list)
+			f->remove = true;
+		spin_unlock_bh(&adapter->vlan_list_lock);
+		adapter->dev_ops.vc_ops.add_del_vlans(vport, false);
+	}
+}
+
 /**
  * iecm_vport_stop - Disable a vport
  * @vport: vport to disable
@@ -831,6 +993,8 @@ static void iecm_vport_stop(struct iecm_vport *vport)
 	if (test_and_clear_bit(__IECM_DEL_QUEUES,
 			       vport->adapter->flags))
 		iecm_send_delete_queues_msg(vport);
+	if (!test_bit(__IECM_REL_RES_IN_PROG, adapter->flags))
+		iecm_remove_vlan_filters(vport);
 
 	adapter->link_up = false;
 	iecm_vport_intr_deinit(vport);
@@ -1581,6 +1745,147 @@ static void iecm_vc_event_task(struct work_struct *work)
 	}
 }
 
+/**
+ * iecm_initiate_soft_reset - Initiate a software reset
+ * @vport: virtual port data struct
+ * @reset_cause: reason for the soft reset
+ *
+ * Soft reset only reallocs vport queue resources. Returns 0 on success,
+ * negative on failure.
+ */
+int iecm_initiate_soft_reset(struct iecm_vport *vport,
+			     enum iecm_flags reset_cause)
+{
+	enum iecm_state current_state = vport->adapter->state;
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_vport *new_vport;
+	int err = 0, i;
+
+	/* make sure we do not end up in initiating multiple resets */
+	mutex_lock(&adapter->reset_lock);
+
+	/* If the system is low on memory, we can end up in bad state if we
+	 * free all the memory for queue resources and try to allocate them
+	 * again. Instead, we can pre-allocate the new resources before doing
+	 * anything and bailing if the alloc fails.
+	 *
+	 * Make a clone of the existing vport to mimic its current configuration,
+	 * then modify the new structure with any requested changes. Once the
+	 * allocation of the new resources is done, stop the existing vport and
+	 * copy the configuration to the main vport. If an error occurred, the
+	 * existing vport will be untouched.
+	 *
+	 */
+	new_vport = kzalloc(sizeof(*vport), GFP_KERNEL);
+	if (!new_vport) {
+		mutex_unlock(&adapter->reset_lock);
+		return -ENOMEM;
+	}
+	memcpy(new_vport, vport, sizeof(*vport));
+
+	/* Adjust resource parameters prior to reallocating resources */
+	switch (reset_cause) {
+	case __IECM_SR_Q_CHANGE:
+		adapter->dev_ops.vc_ops.adjust_qs(new_vport);
+		break;
+	case __IECM_SR_Q_DESC_CHANGE:
+		/* Update queue parameters before allocating resources */
+		iecm_vport_calc_num_q_desc(new_vport);
+		break;
+	case __IECM_SR_Q_SCH_CHANGE:
+	case __IECM_SR_MTU_CHANGE:
+	case __IECM_SR_RSC_CHANGE:
+	case __IECM_SR_HSPLIT_CHANGE:
+		break;
+	default:
+		dev_err(&adapter->pdev->dev, "Unhandled soft reset cause\n");
+		err = -EINVAL;
+		goto err_default;
+	}
+
+	err = iecm_vport_queues_alloc(new_vport);
+	if (err)
+		goto err_default;
+
+	if (adapter->virt_ver_maj == VIRTCHNL_VERSION_MAJOR_2) {
+		if (current_state <= __IECM_DOWN) {
+			adapter->dev_ops.vc_ops.delete_queues(vport);
+		} else {
+			set_bit(__IECM_DEL_QUEUES, adapter->flags);
+			iecm_vport_stop(vport);
+		}
+
+		iecm_deinit_rss(vport);
+		err = adapter->dev_ops.vc_ops.add_queues(new_vport, new_vport->num_txq,
+							 new_vport->num_complq,
+							 new_vport->num_rxq,
+							 new_vport->num_bufq);
+		if (err)
+			goto err_reset;
+	} else {
+		iecm_vport_stop(vport);
+	}
+
+	memcpy(vport, new_vport, sizeof(*vport));
+	/* Since iecm_vport_queues_alloc was called with new_port, the queue
+	 * back pointers are currently pointing to the local new_vport. Reset
+	 * the backpointers to the original vport here
+	 */
+	for (i = 0; i < vport->num_txq_grp; i++) {
+		struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+		int j;
+
+		tx_qgrp->vport = vport;
+		for (j = 0; j < tx_qgrp->num_txq; j++)
+			tx_qgrp->txqs[j]->vport = vport;
+
+		if (iecm_is_queue_model_split(vport->txq_model))
+			tx_qgrp->complq->vport = vport;
+	}
+
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+		struct iecm_queue *q;
+		int j, num_rxq;
+
+		rx_qgrp->vport = vport;
+		for (j = 0; j < vport->num_bufqs_per_qgrp; j++)
+			rx_qgrp->splitq.bufq_sets[j].bufq.vport = vport;
+
+		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++) {
+			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->vport = vport;
+		}
+	}
+
+	/* Post resource allocation reset */
+	if (reset_cause == __IECM_SR_Q_CHANGE) {
+		iecm_intr_rel(adapter);
+		iecm_intr_req(adapter);
+	}
+
+	kfree(new_vport);
+
+	if (current_state == __IECM_UP)
+		err = iecm_vport_open(vport, false);
+	mutex_unlock(&adapter->reset_lock);
+	return err;
+err_reset:
+	iecm_vport_queues_rel(vport);
+err_default:
+	kfree(new_vport);
+	mutex_unlock(&adapter->reset_lock);
+	return err;
+}
+
 /**
  * iecm_probe - Device initialization routine
  * @pdev: PCI device information struct
@@ -1905,6 +2210,47 @@ static void iecm_set_rx_mode(struct net_device *netdev)
 	}
 }
 
+/**
+ * iecm_set_features - set the netdev feature flags
+ * @netdev: ptr to the netdev being adjusted
+ * @features: the feature set that the stack is suggesting
+ */
+static int iecm_set_features(struct net_device *netdev,
+			     netdev_features_t features)
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+	struct iecm_adapter *adapter = vport->adapter;
+	int err = 0;
+
+	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(netdev, netdev->features,
+						     features);
+		if (err)
+			return err;
+	}
+
+	if ((netdev->features ^ features) & NETIF_F_GRO_HW) {
+		netdev->features ^= NETIF_F_GRO_HW;
+		err = iecm_initiate_soft_reset(vport, __IECM_SR_RSC_CHANGE);
+	}
+
+	return err;
+}
+
+/**
+ * iecm_fix_features - fix up the netdev feature bits
+ * @netdev: our net device
+ * @features: desired feature bits
+ *
+ * Returns fixed-up features bits
+ */
+static netdev_features_t iecm_fix_features(struct net_device *netdev,
+					   netdev_features_t features)
+{
+	return features;
+}
+
 /**
  * iecm_open - Called when a network interface becomes active
  * @netdev: network interface device structure
@@ -1924,6 +2270,374 @@ static int iecm_open(struct net_device *netdev)
 	return iecm_vport_open(np->vport, true);
 }
 
+/**
+ * iecm_change_mtu - NDO callback to change the MTU
+ * @netdev: network interface device structure
+ * @new_mtu: new value for maximum frame size
+ *
+ * Returns 0 on success, negative on failure
+ */
+static int iecm_change_mtu(struct net_device *netdev, int new_mtu)
+{
+	struct iecm_vport *vport =  iecm_netdev_to_vport(netdev);
+
+	netdev->mtu = new_mtu;
+
+	return iecm_initiate_soft_reset(vport, __IECM_SR_MTU_CHANGE);
+}
+
+static int iecm_offload_txtime(struct iecm_vport *vport,
+			       struct tc_etf_qopt_offload *qopt)
+{
+	return -EOPNOTSUPP;
+}
+
+/**
+ * iecm_validate_tx_bandwidth - validate the max Tx bandwidth
+ * @vport: vport structure
+ * @max_tx_rate: max Tx bandwidth for a tc
+ **/
+static int iecm_validate_tx_bandwidth(struct iecm_vport *vport,
+				      u64 max_tx_rate)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	int speed = 0, ret = 0;
+
+	if (adapter->link_speed_mbps) {
+		if (adapter->link_speed_mbps < U32_MAX) {
+			speed = adapter->link_speed_mbps;
+			goto validate_bw;
+		} else {
+			dev_err(&adapter->pdev->dev, "Unknown link speed\n");
+			return -EINVAL;
+		}
+	}
+
+	switch (adapter->link_speed) {
+	case VIRTCHNL_LINK_SPEED_40GB:
+		speed = SPEED_40000;
+		break;
+	case VIRTCHNL_LINK_SPEED_25GB:
+		speed = SPEED_25000;
+		break;
+	case VIRTCHNL_LINK_SPEED_20GB:
+		speed = SPEED_20000;
+		break;
+	case VIRTCHNL_LINK_SPEED_10GB:
+		speed = SPEED_10000;
+		break;
+	case VIRTCHNL_LINK_SPEED_5GB:
+		speed = SPEED_5000;
+		break;
+	case VIRTCHNL_LINK_SPEED_2_5GB:
+		speed = SPEED_2500;
+		break;
+	case VIRTCHNL_LINK_SPEED_1GB:
+		speed = SPEED_1000;
+		break;
+	case VIRTCHNL_LINK_SPEED_100MB:
+		speed = SPEED_100;
+		break;
+	default:
+		break;
+	}
+
+validate_bw:
+	if (max_tx_rate > speed) {
+		dev_err(&adapter->pdev->dev, "Invalid tx rate specified\n");
+		ret = -EINVAL;
+	}
+
+	return ret;
+}
+
+/**
+ * iecm_validate_ch_config - validate queue mapping info
+ * @vport: vport structure
+ * @mqprio_qopt: queue parameters
+ * @max_tc_allowed: MAX TC allowed, it could be 4 or 16 depends.
+ *
+ * This function validates if the configuration provided by the user to
+ * configure queue channels is valid or not.
+ *
+ * Returns 0 on a valid config and negative on invalid config.
+ **/
+static int iecm_validate_ch_config(struct iecm_vport *vport,
+				   struct tc_mqprio_qopt_offload *mqprio_qopt,
+				   u8 max_tc_allowed)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	u32 tc, qcount, non_power_2_qcount = 0;
+	u64 total_max_rate = 0;
+	int i, num_qs = 0;
+
+	if (mqprio_qopt->qopt.num_tc > max_tc_allowed ||
+	    mqprio_qopt->qopt.num_tc < 1)
+		return -EINVAL;
+
+	/* For ADQ there are few rules on queue allocation for each TC
+	 *     1. Number of queues for TC0 should always be a power of 2
+	 *     2. Number of queues for rest of TCs can be non-power of 2
+	 *     3. If the previous TC has non-power of 2 queues, then all the
+	 *        following TCs should be either
+	 *        a. same number of queues as that of the previous non-power
+	 *           of 2 or
+	 *        b. less than previous non-power of 2 and power of 2
+	 *        ex: 1 at 0 2 at 1 3 at 3 4 at 6 - Invalid
+	 *            1 at 0 2 at 1 3 at 3 3 at 6 - Valid
+	 *            1 at 0 2 at 1 3 at 3 2 at 6 - Valid
+	 *            1 at 0 2 at 1 3 at 3 1@6 - Valid
+	 */
+	for (tc = 0; tc < mqprio_qopt->qopt.num_tc; tc++) {
+		qcount = mqprio_qopt->qopt.count[tc];
+
+		/* case 1. check for first TC to be always power of 2 in ADQ */
+		if (!tc && !is_power_of_2(qcount)) {
+			dev_err(&adapter->pdev->dev,
+				"TC0:qcount[%d] must be a power of 2\n",
+				qcount);
+			return -EINVAL;
+		}
+		/* case 2 & 3, check for non-power of 2 number of queues */
+		if (tc && non_power_2_qcount) {
+			if (qcount > non_power_2_qcount) {
+				dev_err(&adapter->pdev->dev,
+					"TC%d has %d qcount cannot be > non_power_of_2 qcount [%d]\n",
+					tc, qcount, non_power_2_qcount);
+				return -EINVAL;
+			} else if (qcount < non_power_2_qcount) {
+				/* it must be power of 2, otherwise fail */
+				if (!is_power_of_2(qcount)) {
+					dev_err(&adapter->pdev->dev,
+						"TC%d has %d qcount must be a power of 2 < non_power_of_2 qcount [%d]\n",
+						tc, qcount, non_power_2_qcount);
+					return -EINVAL;
+				}
+			}
+		} else if (tc && !is_power_of_2(qcount)) {
+			/* this is the first TC to have a non-power of 2 queue
+			 * count and the code is going to enter this section
+			 * only once. The qcount for this TC will serve as
+			 * our reference/guide to allocate number of queues
+			 * for all the further TCs as per section a. and b. in
+			 * case 3 mentioned above.
+			 */
+			non_power_2_qcount = qcount;
+			dev_dbg(&adapter->pdev->dev,
+				"TC%d:count[%d] non power of 2\n", tc,
+				qcount);
+			}
+	}
+
+	for (i = 0; i <= mqprio_qopt->qopt.num_tc - 1; i++) {
+		u64 tx_rate = 0;
+
+		if (!mqprio_qopt->qopt.count[i] ||
+		    mqprio_qopt->qopt.offset[i] != num_qs)
+			return -EINVAL;
+		if (mqprio_qopt->min_rate[i]) {
+			dev_err(&adapter->pdev->dev,
+				"Invalid min tx rate (greater than 0) specified\n");
+			return -EINVAL;
+		}
+		/*convert to Mbps */
+		tx_rate = div_u64(mqprio_qopt->max_rate[i], IECM_MBPS_DIVISOR);
+		total_max_rate += tx_rate;
+		num_qs += mqprio_qopt->qopt.count[i];
+	}
+	/* Comparing with num_txq as num_txq and num_rxq are equal for single
+	 * queue model
+	 */
+	if (num_qs > vport->num_txq) {
+		dev_err(&adapter->pdev->dev,
+			"Cannot support requested number of queues\n");
+		return -EINVAL;
+	}
+	/* no point in validating TX bandwidth rate limit if the user hasn't
+	 * specified any rate limit for any TCs, so validate only if it's set.
+	 */
+	if (total_max_rate)
+		return iecm_validate_tx_bandwidth(vport, total_max_rate);
+	else
+		return 0;
+}
+
+/**
+ * __iecm_setup_tc - configure multiple traffic classes
+ * @vport: vport structure
+ * @type_data: tc offload data
+ *
+ * This function processes the config information provided by the
+ * user to configure traffic classes/queue channels and packages the
+ * information to request the PF to setup traffic classes.
+ *
+ * Returns 0 on success.
+ **/
+static int __iecm_setup_tc(struct iecm_vport *vport, void *type_data)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct tc_mqprio_qopt_offload *mqprio_qopt;
+	struct net_device *netdev = vport->netdev;
+	struct iecm_channel_config *ch_config;
+	u8 num_tc = 0, total_qs = 0;
+	int ret = 0;
+	u8 max_tc_allowed;
+	u64 max_tx_rate;
+	u16 mode;
+
+	mqprio_qopt = (struct tc_mqprio_qopt_offload *)type_data;
+	ch_config = &adapter->config_data.ch_config;
+	num_tc = mqprio_qopt->qopt.num_tc;
+	mode = mqprio_qopt->mode;
+
+	/* delete queue_channel */
+	if (!mqprio_qopt->qopt.hw) {
+		if (ch_config->tc_running) {
+			/* reset the tc configuration */
+			netdev_reset_tc(netdev);
+			ch_config->num_tc = 0;
+			netif_tx_stop_all_queues(netdev);
+			netif_tx_disable(netdev);
+			ret = iecm_send_disable_channels_msg(vport);
+			netif_tx_start_all_queues(netdev);
+			if (!test_bit(__IECM_REL_RES_IN_PROG, adapter->flags) &&
+			    !ret) {
+				ch_config->tc_running = false;
+				set_bit(__IECM_HR_FUNC_RESET, adapter->flags);
+				queue_delayed_work(adapter->vc_event_wq,
+						   &adapter->vc_event_task,
+						   msecs_to_jiffies(10));
+			}
+			return ret;
+		} else {
+			return -EINVAL;
+		}
+	}
+
+	if (mode == TC_MQPRIO_MODE_CHANNEL) {
+		int i, netdev_tc = 0;
+
+		if (!iecm_is_cap_ena(adapter, IECM_BASE_CAPS,
+				     VIRTCHNL2_CAP_ADQ) &&
+		    !iecm_is_cap_ena(adapter, IECM_OTHER_CAPS,
+					     VIRTCHNL2_CAP_ADQ)) {
+			dev_info(&adapter->pdev->dev, "ADQ not supported\n");
+			return -EOPNOTSUPP;
+		}
+
+		if (ch_config->tc_running) {
+			dev_info(&adapter->pdev->dev, "TC configuration already exists\n");
+			return -EINVAL;
+		}
+
+		/* If negotiated capability between VF and PF indicated that
+		 * ADQ_V2 is enabled, means it's OK to allow max_tc
+		 * to be 16. This is needed to handle the case where iAVF
+		 * is newer but PF is older or different generation
+		 */
+		if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_ADQ))
+			max_tc_allowed = VIRTCHNL_MAX_ADQ_V2_CHANNELS;
+		else
+			max_tc_allowed = VIRTCHNL_MAX_ADQ_CHANNELS;
+
+		ret = iecm_validate_ch_config(vport, mqprio_qopt,
+					      max_tc_allowed);
+		if (ret)
+			return ret;
+		/* Return if same TC config is requested */
+		if (ch_config->num_tc == num_tc)
+			return 0;
+		ch_config->num_tc = num_tc;
+
+		for (i = 0; i < max_tc_allowed; i++) {
+			if (i < num_tc) {
+				ch_config->ch_info[i].count =
+					mqprio_qopt->qopt.count[i];
+				ch_config->ch_info[i].offset =
+					mqprio_qopt->qopt.offset[i];
+				total_qs += mqprio_qopt->qopt.count[i];
+				max_tx_rate = mqprio_qopt->max_rate[i];
+				/* convert to Mbps */
+				max_tx_rate = div_u64(max_tx_rate,
+						      IECM_MBPS_DIVISOR);
+				ch_config->ch_info[i].max_tx_rate =
+								max_tx_rate;
+			} else {
+				ch_config->ch_info[i].count = 1;
+				ch_config->ch_info[i].offset = 0;
+			}
+		}
+
+		/* Store queue info based on TC so that, VF gets configured
+		 * with correct number of queues when VF completes ADQ config
+		 * flow
+		 */
+		ch_config->total_qs = total_qs;
+
+		netif_tx_stop_all_queues(netdev);
+		netif_tx_disable(netdev);
+		ret = iecm_send_enable_channels_msg(vport);
+		if (ret)
+			return ret;
+		netdev_reset_tc(netdev);
+		/* Report the tc mapping up the stack */
+		netdev_set_num_tc(netdev, num_tc);
+		for (i = 0; i < max_tc_allowed; i++) {
+			u16 qcount = mqprio_qopt->qopt.count[i];
+			u16 qoffset = mqprio_qopt->qopt.offset[i];
+
+			if (i < num_tc)
+				netdev_set_tc_queue(netdev, netdev_tc++, qcount,
+						    qoffset);
+		}
+		/* Start all queues */
+		netif_tx_start_all_queues(netdev);
+		ch_config->tc_running = true;
+		set_bit(__IECM_HR_FUNC_RESET, adapter->flags);
+		queue_delayed_work(adapter->vc_event_wq,
+				   &adapter->vc_event_task,
+				   msecs_to_jiffies(10));
+	}
+	return ret;
+}
+
+/**
+ * iecm_setup_tc - ndo callback to setup up TC schedulers
+ * @netdev: pointer to net_device struct
+ * @type: TC type
+ * @type_data: TC type specific data
+ */
+static int iecm_setup_tc(struct net_device *netdev, enum tc_setup_type type,
+			 void *type_data)
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+	struct iecm_adapter *adapter = vport->adapter;
+	int err = 0;
+
+	switch (type) {
+	case TC_SETUP_QDISC_ETF:
+		if (iecm_is_queue_model_split(vport->txq_model))
+			err =
+			iecm_offload_txtime(vport,
+					    (struct tc_etf_qopt_offload *)
+					     type_data);
+		break;
+	case TC_SETUP_BLOCK:
+		break;
+	case TC_SETUP_QDISC_MQPRIO:
+		if (iecm_is_cap_ena(adapter, IECM_BASE_CAPS,
+				    VIRTCHNL2_CAP_ADQ) ||
+		    iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_ADQ))
+			__iecm_setup_tc(vport, type_data);
+		break;
+	default:
+		err = -EOPNOTSUPP;
+		break;
+	}
+
+	return err;
+}
+
 /**
  * iecm_set_mac - NDO callback to set port mac address
  * @netdev: network interface device structure
@@ -1997,13 +2711,13 @@ static const struct net_device_ops iecm_netdev_ops_splitq = {
 	.ndo_set_rx_mode = iecm_set_rx_mode,
 	.ndo_validate_addr = eth_validate_addr,
 	.ndo_set_mac_address = iecm_set_mac,
-	.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,
+	.ndo_change_mtu = iecm_change_mtu,
+	.ndo_get_stats64 = iecm_get_stats64,
+	.ndo_fix_features = iecm_fix_features,
+	.ndo_set_features = iecm_set_features,
+	.ndo_vlan_rx_add_vid = iecm_vlan_rx_add_vid,
+	.ndo_vlan_rx_kill_vid = iecm_vlan_rx_kill_vid,
+	.ndo_setup_tc = iecm_setup_tc,
 };
 
 static const struct net_device_ops iecm_netdev_ops_singleq = {
@@ -2013,11 +2727,11 @@ static const struct net_device_ops iecm_netdev_ops_singleq = {
 	.ndo_set_rx_mode = iecm_set_rx_mode,
 	.ndo_validate_addr = eth_validate_addr,
 	.ndo_set_mac_address = iecm_set_mac,
-	.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,
+	.ndo_change_mtu = iecm_change_mtu,
+	.ndo_get_stats64 = iecm_get_stats64,
+	.ndo_fix_features = iecm_fix_features,
+	.ndo_set_features = iecm_set_features,
+	.ndo_vlan_rx_add_vid = iecm_vlan_rx_add_vid,
+	.ndo_vlan_rx_kill_vid = iecm_vlan_rx_kill_vid,
+	.ndo_setup_tc = iecm_setup_tc,
 };
drivers/net/ethernet/intel/iecm/iecm_txrx.c +15 -0
index ef5fe659389b..4b9288e1c254 100644
@@ -218,6 +218,21 @@ const struct iecm_rx_ptype_decoded iecm_ptype_lookup[IECM_RX_MAX_PTYPE] = {
 };
 EXPORT_SYMBOL(iecm_ptype_lookup);
 
+/**
+ * iecm_get_stats64 - get statistics for network device structure
+ * @netdev: network interface device structure
+ * @stats: main device statistics structure
+ */
+void iecm_get_stats64(struct net_device *netdev,
+		      struct rtnl_link_stats64 *stats)
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+
+	set_bit(__IECM_MB_STATS_PENDING, vport->adapter->flags);
+
+	*stats = vport->netstats;
+}
+
 /**
  * iecm_tx_buf_rel - Release a Tx buffer
  * @tx_q: the queue that owns the buffer
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +63 -0

69 lines not on this page · raw message

drivers/net/ethernet/intel/include/iecm.h +14 -0
index f6f9884c10c2..a655e797f457 100644
@@ -4,6 +4,8 @@
 #ifndef _IECM_H_
 #define _IECM_H_
 
+#include <net/pkt_sched.h>
+#include <net/pkt_cls.h>
 #include <linux/aer.h>
 #include <linux/pci.h>
 #include <linux/netdevice.h>
@@ -44,6 +46,8 @@
 /* available message levels */
 #define IECM_AVAIL_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
 
+#define IECM_MBPS_DIVISOR		125000 /* divisor to convert to Mbps */
+
 #define IECM_VIRTCHNL_VERSION_MAJOR VIRTCHNL_VERSION_MAJOR_2
 #define IECM_VIRTCHNL_VERSION_MINOR VIRTCHNL_VERSION_MINOR_0
 
@@ -393,6 +397,13 @@ enum iecm_user_flags {
 	__IECM_USER_FLAGS_NBITS,
 };
 
+struct iecm_channel_config {
+	struct virtchnl_channel_info ch_info[VIRTCHNL_MAX_ADQ_V2_CHANNELS];
+	bool tc_running;
+	u8 total_qs;
+	u8 num_tc;
+};
+
 #define IECM_GET_PTYPE_SIZE(p) \
 	(sizeof(struct virtchnl2_ptype) + \
 	(((p)->proto_id_count ? ((p)->proto_id_count - 1) : 0) * sizeof(u16)))
@@ -430,6 +441,7 @@ struct iecm_user_config_data {
 	struct list_head mac_filter_list;
 	struct list_head vlan_filter_list;
 	struct list_head adv_rss_list;
+	struct iecm_channel_config ch_config;
 };
 
 struct iecm_rss_data {
@@ -703,6 +715,8 @@ 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_initiate_soft_reset(struct iecm_vport *vport,
+			     enum iecm_flags reset_cause);
 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);
drivers/net/ethernet/intel/include/iecm_txrx.h +2 -0
index 26e480343876..7ec742fd4c6b 100644
@@ -672,6 +672,8 @@ netdev_tx_t iecm_tx_singleq_start(struct sk_buff *skb,
 				  struct net_device *netdev);
 bool iecm_rx_singleq_buf_hw_alloc_all(struct iecm_queue *rxq,
 				      u16 cleaned_count);
+void iecm_get_stats64(struct net_device *netdev,
+		      struct rtnl_link_stats64 *stats);
 int iecm_tso(struct iecm_tx_buf *first, struct iecm_tx_offload_params *off);
 void iecm_tx_prepare_vlan_flags(struct iecm_queue *tx_q,
 				struct iecm_tx_buf *first,
Signature · 1 line
2.33.0
#50 lore raw

PATCH 12/19 iecm: finish netdev_ops

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

Quoted 25 lines

This fills out the remaining NDO callbacks. Once netdev_ops are there, the rest of the patches will fill out the data path and advanced features.

---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    | 742 +++++++++++++++++-
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   |  15 +
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   |  63 ++
 drivers/net/ethernet/intel/include/iecm.h     |  14 +
 .../net/ethernet/intel/include/iecm_txrx.h    |   2 +
 5 files changed, 822 insertions(+), 14 deletions(-)
drivers/net/ethernet/intel/iecm/iecm_lib.c +1 -0
index 003057f48f0c..cc82e665dfaf 100644
@@ -568,6 +568,147 @@ static void iecm_set_all_filters(struct iecm_vport *vport)
 	iecm_add_del_ether_addrs(vport, true, false);
 }
 
+/**

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_set_all_filters(struct iecm_vport *vport) · line 581

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+ * iecm_find_vlan - Search filter list for specific vlan filter
+ * @vport: vport structure
+ * @vlan: vlan tag
+ *
+ * Returns ptr to the filter object or NULL. Must be called while holding the
+ * vlan_list_lock.
+ */
+static struct
+iecm_vlan_filter *iecm_find_vlan(struct iecm_vport *vport,
+				 struct iecm_vlan *vlan)

Both are read-only here, thus const.

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_set_all_filters(struct iecm_vport *vport) · line 583

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +2 -0
+{
+	struct iecm_vlan_filter *f;

Read-only, const.

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_set_all_filters(struct iecm_vport *vport) · line 589

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +6 -0
+
+	list_for_each_entry(f, &vport->adapter->config_data.vlan_filter_list,
+			    list) {
+		if (vlan->vid == f->vlan.vid && vlan->tpid == f->vlan.tpid)
+			return f;
+	}

Braces are redundant.

Quoted 21 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +21 -0
+	return NULL;
+}
+
+/**
+ * iecm_add_vlan - Add a vlan filter to the list
+ * @vport: vport structure
+ * @vlan: VLAN tag
+ *
+ * Returns ptr to the filter object or NULL when no memory available.
+ */
+static struct
+iecm_vlan_filter *iecm_add_vlan(struct iecm_vport *vport,
+				struct iecm_vlan *vlan)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_vlan_filter *f = NULL;
+
+	spin_lock_bh(&adapter->vlan_list_lock);
+
+	f = iecm_find_vlan(vport, vlan);
+	if (!f) {

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_set_all_filters(struct iecm_vport *vport) · line 620

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+		f = kzalloc(sizeof(*f), GFP_ATOMIC);
+		if (!f)
+			goto error;
+
+		f->vlan.vid = vlan->vid;
+		f->vlan.tpid = vlan->tpid;
+
+		list_add_tail(&f->list, &adapter->config_data.vlan_filter_list);
+		f->add = true;
+	}
	if (f)
		goto error; /* It's better to rename the label */

	f = kzalloc(...
Quoted 76 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +76 -0
+
+error:
+	spin_unlock_bh(&adapter->vlan_list_lock);
+	return f;
+}
+
+/**
+ * iecm_del_vlan - Remove a vlan filter from the list
+ * @vport: vport structure
+ * @vlan: VLAN tag
+ */
+static void iecm_del_vlan(struct iecm_vport *vport, struct iecm_vlan *vlan)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_vlan_filter *f;
+
+	spin_lock_bh(&adapter->vlan_list_lock);
+
+	f = iecm_find_vlan(vport, vlan);
+	if (f)
+		f->remove = true;
+
+	spin_unlock_bh(&adapter->vlan_list_lock);
+}
+
+/**
+ * iecm_vlan_rx_add_vid - Add a VLAN filter to the device
+ * @netdev: network device struct
+ * @proto: unused protocol data
+ * @vid: VLAN tag
+ *
+ * Returns 0 on success
+ */
+static int iecm_vlan_rx_add_vid(struct net_device *netdev,
+				__always_unused __be16 proto, u16 vid)
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_vlan vlan;
+
+	vlan = IECM_VLAN(vid, be16_to_cpu(proto));
+	if (!iecm_is_feature_ena(vport, NETIF_F_HW_VLAN_CTAG_FILTER))
+		return -EINVAL;
+
+	iecm_add_vlan(vport, &vlan);
+
+	if (adapter->state == __IECM_UP)
+		adapter->dev_ops.vc_ops.add_del_vlans(vport, true);
+
+	return 0;
+}
+
+/**
+ * iecm_vlan_rx_kill_vid - Remove a VLAN filter from the device
+ * @netdev: network device struct
+ * @proto: unused protocol data
+ * @vid: VLAN tag
+ *
+ * Returns 0 on success
+ */
+static int iecm_vlan_rx_kill_vid(struct net_device *netdev,
+				 __always_unused __be16 proto, u16 vid)
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_vlan_filter *f, *ftmp;
+	struct iecm_vlan vlan;
+
+	vlan = IECM_VLAN(vid, be16_to_cpu(proto));
+	if (!iecm_is_feature_ena(vport, NETIF_F_HW_VLAN_CTAG_FILTER))
+		return -EINVAL;
+
+	if (vport->adapter->state == __IECM_UP) {
+		iecm_del_vlan(vport, &vlan);
+		adapter->dev_ops.vc_ops.add_del_vlans(vport, false);
+	}

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_set_all_filters(struct iecm_vport *vport) · line 706

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+	/* It is safe to delete entry from the list now */
+	spin_lock_bh(&adapter->vlan_list_lock);
+	list_for_each_entry_safe(f, ftmp,
+				 &adapter->config_data.vlan_filter_list,
+				 list) {
+		if (f->vlan.vid == vlan.vid && f->vlan.tpid == vlan.tpid) {
+			list_del(&f->list);
+			kfree(f);
+		}
+	}

Braces.

Quoted 119 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +98 -0
+	spin_unlock_bh(&adapter->vlan_list_lock);
+
+	return 0;
+}
+
 /**
  * iecm_set_all_vlans - Re-add all VLANs in list
  * @vport: main vport struct
@@ -804,6 +945,27 @@ static int iecm_get_free_slot(void *array, int size, int curr)
 	return next;
 }
 
+/**
+ * iecm_remove_vlan_filters - Remove all vlan filters
+ * @vport: vport structure
+ */
+static void iecm_remove_vlan_filters(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_user_config_data *config_data;
+
+	config_data = &adapter->config_data;
+	if (!list_empty(&config_data->vlan_filter_list)) {
+		struct iecm_vlan_filter *f;
+
+		spin_lock_bh(&adapter->vlan_list_lock);
+		list_for_each_entry(f, &config_data->vlan_filter_list, list)
+			f->remove = true;
+		spin_unlock_bh(&adapter->vlan_list_lock);
+		adapter->dev_ops.vc_ops.add_del_vlans(vport, false);
+	}
+}
+
 /**
  * iecm_vport_stop - Disable a vport
  * @vport: vport to disable
@@ -831,6 +993,8 @@ static void iecm_vport_stop(struct iecm_vport *vport)
 	if (test_and_clear_bit(__IECM_DEL_QUEUES,
 			       vport->adapter->flags))
 		iecm_send_delete_queues_msg(vport);
+	if (!test_bit(__IECM_REL_RES_IN_PROG, adapter->flags))
+		iecm_remove_vlan_filters(vport);
 
 	adapter->link_up = false;
 	iecm_vport_intr_deinit(vport);
@@ -1581,6 +1745,147 @@ static void iecm_vc_event_task(struct work_struct *work)
 	}
 }
 
+/**
+ * iecm_initiate_soft_reset - Initiate a software reset
+ * @vport: virtual port data struct
+ * @reset_cause: reason for the soft reset
+ *
+ * Soft reset only reallocs vport queue resources. Returns 0 on success,
+ * negative on failure.
+ */
+int iecm_initiate_soft_reset(struct iecm_vport *vport,
+			     enum iecm_flags reset_cause)
+{
+	enum iecm_state current_state = vport->adapter->state;
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_vport *new_vport;
+	int err = 0, i;
+
+	/* make sure we do not end up in initiating multiple resets */
+	mutex_lock(&adapter->reset_lock);
+
+	/* If the system is low on memory, we can end up in bad state if we
+	 * free all the memory for queue resources and try to allocate them
+	 * again. Instead, we can pre-allocate the new resources before doing
+	 * anything and bailing if the alloc fails.
+	 *
+	 * Make a clone of the existing vport to mimic its current configuration,
+	 * then modify the new structure with any requested changes. Once the
+	 * allocation of the new resources is done, stop the existing vport and
+	 * copy the configuration to the main vport. If an error occurred, the
+	 * existing vport will be untouched.
+	 *
+	 */
+	new_vport = kzalloc(sizeof(*vport), GFP_KERNEL);
+	if (!new_vport) {
+		mutex_unlock(&adapter->reset_lock);
+		return -ENOMEM;
+	}
+	memcpy(new_vport, vport, sizeof(*vport));
+
+	/* Adjust resource parameters prior to reallocating resources */
+	switch (reset_cause) {
+	case __IECM_SR_Q_CHANGE:
+		adapter->dev_ops.vc_ops.adjust_qs(new_vport);
+		break;
+	case __IECM_SR_Q_DESC_CHANGE:
+		/* Update queue parameters before allocating resources */
+		iecm_vport_calc_num_q_desc(new_vport);
+		break;
+	case __IECM_SR_Q_SCH_CHANGE:
+	case __IECM_SR_MTU_CHANGE:
+	case __IECM_SR_RSC_CHANGE:
+	case __IECM_SR_HSPLIT_CHANGE:
+		break;
+	default:
+		dev_err(&adapter->pdev->dev, "Unhandled soft reset cause\n");
+		err = -EINVAL;
+		goto err_default;
+	}
+
+	err = iecm_vport_queues_alloc(new_vport);
+	if (err)
+		goto err_default;
+
+	if (adapter->virt_ver_maj == VIRTCHNL_VERSION_MAJOR_2) {
+		if (current_state <= __IECM_DOWN) {
+			adapter->dev_ops.vc_ops.delete_queues(vport);
+		} else {
+			set_bit(__IECM_DEL_QUEUES, adapter->flags);
+			iecm_vport_stop(vport);
+		}
+

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_vc_event_task(struct work_struct *work) · line 1827

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+		iecm_deinit_rss(vport);
+		err = adapter->dev_ops.vc_ops.add_queues(new_vport, new_vport->num_txq,
+							 new_vport->num_complq,
+							 new_vport->num_rxq,
+							 new_vport->num_bufq);
+		if (err)
+			goto err_reset;
+	} else {
+		iecm_vport_stop(vport);
+	}
	if (maj != MAJOR_2) {
		iecm_vport_stop(vport);
		goto init;
	}

	...
Quoted 98 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +91 -0
+
+	memcpy(vport, new_vport, sizeof(*vport));
+	/* Since iecm_vport_queues_alloc was called with new_port, the queue
+	 * back pointers are currently pointing to the local new_vport. Reset
+	 * the backpointers to the original vport here
+	 */
+	for (i = 0; i < vport->num_txq_grp; i++) {
+		struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+		int j;
+
+		tx_qgrp->vport = vport;
+		for (j = 0; j < tx_qgrp->num_txq; j++)
+			tx_qgrp->txqs[j]->vport = vport;
+
+		if (iecm_is_queue_model_split(vport->txq_model))
+			tx_qgrp->complq->vport = vport;
+	}
+
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+		struct iecm_queue *q;
+		int j, num_rxq;
+
+		rx_qgrp->vport = vport;
+		for (j = 0; j < vport->num_bufqs_per_qgrp; j++)
+			rx_qgrp->splitq.bufq_sets[j].bufq.vport = vport;
+
+		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++) {
+			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->vport = vport;
+		}
+	}
+
+	/* Post resource allocation reset */
+	if (reset_cause == __IECM_SR_Q_CHANGE) {
+		iecm_intr_rel(adapter);
+		iecm_intr_req(adapter);
+	}
+
+	kfree(new_vport);
+
+	if (current_state == __IECM_UP)
+		err = iecm_vport_open(vport, false);
+	mutex_unlock(&adapter->reset_lock);
+	return err;
+err_reset:
+	iecm_vport_queues_rel(vport);
+err_default:
+	kfree(new_vport);
+	mutex_unlock(&adapter->reset_lock);
+	return err;
+}
+
 /**
  * iecm_probe - Device initialization routine
  * @pdev: PCI device information struct
@@ -1905,6 +2210,47 @@ static void iecm_set_rx_mode(struct net_device *netdev)
 	}
 }
 
+/**
+ * iecm_set_features - set the netdev feature flags
+ * @netdev: ptr to the netdev being adjusted
+ * @features: the feature set that the stack is suggesting
+ */
+static int iecm_set_features(struct net_device *netdev,
+			     netdev_features_t features)
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+	struct iecm_adapter *adapter = vport->adapter;
+	int err = 0;
+
+	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(netdev, netdev->features,
+						     features);
+		if (err)
+			return err;
+	}
+
+	if ((netdev->features ^ features) & NETIF_F_GRO_HW) {
+		netdev->features ^= NETIF_F_GRO_HW;
+		err = iecm_initiate_soft_reset(vport, __IECM_SR_RSC_CHANGE);
+	}
+
+	return err;
+}
+
+/**
+ * iecm_fix_features - fix up the netdev feature bits

drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_set_rx_mode(struct net_device *netdev) · line 2252

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+ * @netdev: our net device
+ * @features: desired feature bits
+ *
+ * Returns fixed-up features bits
+ */
+static netdev_features_t iecm_fix_features(struct net_device *netdev,
+					   netdev_features_t features)
+{
+	return features;
+}

This adds +1 redundant indirect call to hotpath. fix_features is fully optional.

Quoted 19 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +12 -0
+
 /**
  * iecm_open - Called when a network interface becomes active
  * @netdev: network interface device structure
@@ -1924,6 +2270,374 @@ static int iecm_open(struct net_device *netdev)
 	return iecm_vport_open(np->vport, true);
 }
 
+/**
+ * iecm_change_mtu - NDO callback to change the MTU
+ * @netdev: network interface device structure
+ * @new_mtu: new value for maximum frame size
+ *
+ * Returns 0 on success, negative on failure
+ */
+static int iecm_change_mtu(struct net_device *netdev, int new_mtu)
+{
+	struct iecm_vport *vport =  iecm_netdev_to_vport(netdev);
+

drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_open(struct net_device *netdev) · line 2293

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+	netdev->mtu = new_mtu;
+
+	return iecm_initiate_soft_reset(vport, __IECM_SR_MTU_CHANGE);
+}
+
+static int iecm_offload_txtime(struct iecm_vport *vport,
+			       struct tc_etf_qopt_offload *qopt)
+{
+	return -EOPNOTSUPP;
+}

Pointless function. If it will be expanded later, introduce it only then.
Otherwise, code becomes a mess.

Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +11 -0
+
+/**
+ * iecm_validate_tx_bandwidth - validate the max Tx bandwidth
+ * @vport: vport structure
+ * @max_tx_rate: max Tx bandwidth for a tc
+ **/
+static int iecm_validate_tx_bandwidth(struct iecm_vport *vport,
+				      u64 max_tx_rate)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	int speed = 0, ret = 0;

drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_open(struct net_device *netdev) · line 2314

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+
+	if (adapter->link_speed_mbps) {
+		if (adapter->link_speed_mbps < U32_MAX) {
+			speed = adapter->link_speed_mbps;
+			goto validate_bw;
+		} else {
+			dev_err(&adapter->pdev->dev, "Unknown link speed\n");
+			return -EINVAL;
+		}
+	}
	switch (adapter->link_speed_mbps) {
	case 1 ... U32_MAX - 1:
		speed = adapter->link_speed_mbps;
		goto validate_bw;
	case U32_MAX:
		dev_err();
		return -EINVAL;
	case 0:
	default:
		break;
	}

or

	if (link_speed_mbps < U32_MAX)
		set;
	else if (link_speed_mbps) /* This means it's U32_MAX */
		error;
Quoted 16 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +16 -0
+
+	switch (adapter->link_speed) {
+	case VIRTCHNL_LINK_SPEED_40GB:
+		speed = SPEED_40000;
+		break;
+	case VIRTCHNL_LINK_SPEED_25GB:
+		speed = SPEED_25000;
+		break;
+	case VIRTCHNL_LINK_SPEED_20GB:
+		speed = SPEED_20000;
+		break;
+	case VIRTCHNL_LINK_SPEED_10GB:
+		speed = SPEED_10000;
+		break;
+	case VIRTCHNL_LINK_SPEED_5GB:
+		speed = SPEED_5000;

drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_open(struct net_device *netdev) · line 2340

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+		break;
+	case VIRTCHNL_LINK_SPEED_2_5GB:
+		speed = SPEED_2500;
+		break;
+	case VIRTCHNL_LINK_SPEED_1GB:
+		speed = SPEED_1000;
+		break;
+	case VIRTCHNL_LINK_SPEED_100MB:
+		speed = SPEED_100;
+		break;

All these can be converted to an array and compressed using macros.

Quoted 112 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +112 -0
+	default:
+		break;
+	}
+
+validate_bw:
+	if (max_tx_rate > speed) {
+		dev_err(&adapter->pdev->dev, "Invalid tx rate specified\n");
+		ret = -EINVAL;
+	}
+
+	return ret;
+}
+
+/**
+ * iecm_validate_ch_config - validate queue mapping info
+ * @vport: vport structure
+ * @mqprio_qopt: queue parameters
+ * @max_tc_allowed: MAX TC allowed, it could be 4 or 16 depends.
+ *
+ * This function validates if the configuration provided by the user to
+ * configure queue channels is valid or not.
+ *
+ * Returns 0 on a valid config and negative on invalid config.
+ **/
+static int iecm_validate_ch_config(struct iecm_vport *vport,
+				   struct tc_mqprio_qopt_offload *mqprio_qopt,
+				   u8 max_tc_allowed)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	u32 tc, qcount, non_power_2_qcount = 0;
+	u64 total_max_rate = 0;
+	int i, num_qs = 0;
+
+	if (mqprio_qopt->qopt.num_tc > max_tc_allowed ||
+	    mqprio_qopt->qopt.num_tc < 1)
+		return -EINVAL;
+
+	/* For ADQ there are few rules on queue allocation for each TC
+	 *     1. Number of queues for TC0 should always be a power of 2
+	 *     2. Number of queues for rest of TCs can be non-power of 2
+	 *     3. If the previous TC has non-power of 2 queues, then all the
+	 *        following TCs should be either
+	 *        a. same number of queues as that of the previous non-power
+	 *           of 2 or
+	 *        b. less than previous non-power of 2 and power of 2
+	 *        ex: 1 at 0 2 at 1 3 at 3 4 at 6 - Invalid
+	 *            1 at 0 2 at 1 3 at 3 3 at 6 - Valid
+	 *            1 at 0 2 at 1 3 at 3 2 at 6 - Valid
+	 *            1 at 0 2 at 1 3 at 3 1 at 6 - Valid
+	 */
+	for (tc = 0; tc < mqprio_qopt->qopt.num_tc; tc++) {
+		qcount = mqprio_qopt->qopt.count[tc];
+
+		/* case 1. check for first TC to be always power of 2 in ADQ */
+		if (!tc && !is_power_of_2(qcount)) {
+			dev_err(&adapter->pdev->dev,
+				"TC0:qcount[%d] must be a power of 2\n",
+				qcount);
+			return -EINVAL;
+		}
+		/* case 2 & 3, check for non-power of 2 number of queues */
+		if (tc && non_power_2_qcount) {
+			if (qcount > non_power_2_qcount) {
+				dev_err(&adapter->pdev->dev,
+					"TC%d has %d qcount cannot be > non_power_of_2 qcount [%d]\n",
+					tc, qcount, non_power_2_qcount);
+				return -EINVAL;
+			} else if (qcount < non_power_2_qcount) {
+				/* it must be power of 2, otherwise fail */
+				if (!is_power_of_2(qcount)) {
+					dev_err(&adapter->pdev->dev,
+						"TC%d has %d qcount must be a power of 2 < non_power_of_2 qcount [%d]\n",
+						tc, qcount, non_power_2_qcount);
+					return -EINVAL;
+				}
+			}
+		} else if (tc && !is_power_of_2(qcount)) {
+			/* this is the first TC to have a non-power of 2 queue
+			 * count and the code is going to enter this section
+			 * only once. The qcount for this TC will serve as
+			 * our reference/guide to allocate number of queues
+			 * for all the further TCs as per section a. and b. in
+			 * case 3 mentioned above.
+			 */
+			non_power_2_qcount = qcount;
+			dev_dbg(&adapter->pdev->dev,
+				"TC%d:count[%d] non power of 2\n", tc,
+				qcount);
+			}
+	}
+
+	for (i = 0; i <= mqprio_qopt->qopt.num_tc - 1; i++) {
+		u64 tx_rate = 0;
+
+		if (!mqprio_qopt->qopt.count[i] ||
+		    mqprio_qopt->qopt.offset[i] != num_qs)
+			return -EINVAL;
+		if (mqprio_qopt->min_rate[i]) {
+			dev_err(&adapter->pdev->dev,
+				"Invalid min tx rate (greater than 0) specified\n");
+			return -EINVAL;
+		}
+		/*convert to Mbps */
+		tx_rate = div_u64(mqprio_qopt->max_rate[i], IECM_MBPS_DIVISOR);
+		total_max_rate += tx_rate;
+		num_qs += mqprio_qopt->qopt.count[i];
+	}
+	/* Comparing with num_txq as num_txq and num_rxq are equal for single
+	 * queue model
+	 */
+	if (num_qs > vport->num_txq) {
+		dev_err(&adapter->pdev->dev,

drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_open(struct net_device *netdev) · line 2462

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+			"Cannot support requested number of queues\n");
+		return -EINVAL;
+	}
+	/* no point in validating TX bandwidth rate limit if the user hasn't
+	 * specified any rate limit for any TCs, so validate only if it's set.
+	 */
+	if (total_max_rate)
+		return iecm_validate_tx_bandwidth(vport, total_max_rate);
+	else
+		return 0;

else before return is redundant.
I'd invert the condition at all:

	if (!total_max_rate)
		return 0;

	return iecm_ ...

It's more natural to read and follow the flow.

Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +11 -0
+}
+
+/**
+ * __iecm_setup_tc - configure multiple traffic classes
+ * @vport: vport structure
+ * @type_data: tc offload data
+ *
+ * This function processes the config information provided by the
+ * user to configure traffic classes/queue channels and packages the
+ * information to request the PF to setup traffic classes.
+ *

drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_open(struct net_device *netdev) · line 2483

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+ * Returns 0 on success.
+ **/
+static int __iecm_setup_tc(struct iecm_vport *vport, void *type_data)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct tc_mqprio_qopt_offload *mqprio_qopt;
+	struct net_device *netdev = vport->netdev;
+	struct iecm_channel_config *ch_config;
+	u8 num_tc = 0, total_qs = 0;
+	int ret = 0;

Please don't break RCT style.

Quoted 22 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +22 -0
+	u8 max_tc_allowed;
+	u64 max_tx_rate;
+	u16 mode;
+
+	mqprio_qopt = (struct tc_mqprio_qopt_offload *)type_data;
+	ch_config = &adapter->config_data.ch_config;
+	num_tc = mqprio_qopt->qopt.num_tc;
+	mode = mqprio_qopt->mode;
+
+	/* delete queue_channel */
+	if (!mqprio_qopt->qopt.hw) {
+		if (ch_config->tc_running) {
+			/* reset the tc configuration */
+			netdev_reset_tc(netdev);
+			ch_config->num_tc = 0;
+			netif_tx_stop_all_queues(netdev);
+			netif_tx_disable(netdev);
+			ret = iecm_send_disable_channels_msg(vport);
+			netif_tx_start_all_queues(netdev);
+			if (!test_bit(__IECM_REL_RES_IN_PROG, adapter->flags) &&
+			    !ret) {
+				ch_config->tc_running = false;

drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_open(struct net_device *netdev) · line 2515

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+				set_bit(__IECM_HR_FUNC_RESET, adapter->flags);
+				queue_delayed_work(adapter->vc_event_wq,
+						   &adapter->vc_event_task,
+						   msecs_to_jiffies(10));
+			}
+			return ret;
+		} else {
+			return -EINVAL;
+		}
+	}

You can save 2 indent levels by inverting the conditions (and adding one goto).

Quoted 99 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +99 -0
+
+	if (mode == TC_MQPRIO_MODE_CHANNEL) {
+		int i, netdev_tc = 0;
+
+		if (!iecm_is_cap_ena(adapter, IECM_BASE_CAPS,
+				     VIRTCHNL2_CAP_ADQ) &&
+		    !iecm_is_cap_ena(adapter, IECM_OTHER_CAPS,
+					     VIRTCHNL2_CAP_ADQ)) {
+			dev_info(&adapter->pdev->dev, "ADQ not supported\n");
+			return -EOPNOTSUPP;
+		}
+
+		if (ch_config->tc_running) {
+			dev_info(&adapter->pdev->dev, "TC configuration already exists\n");
+			return -EINVAL;
+		}
+
+		/* If negotiated capability between VF and PF indicated that
+		 * ADQ_V2 is enabled, means it's OK to allow max_tc
+		 * to be 16. This is needed to handle the case where iAVF
+		 * is newer but PF is older or different generation
+		 */
+		if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_ADQ))
+			max_tc_allowed = VIRTCHNL_MAX_ADQ_V2_CHANNELS;
+		else
+			max_tc_allowed = VIRTCHNL_MAX_ADQ_CHANNELS;
+
+		ret = iecm_validate_ch_config(vport, mqprio_qopt,
+					      max_tc_allowed);
+		if (ret)
+			return ret;
+		/* Return if same TC config is requested */
+		if (ch_config->num_tc == num_tc)
+			return 0;
+		ch_config->num_tc = num_tc;
+
+		for (i = 0; i < max_tc_allowed; i++) {
+			if (i < num_tc) {
+				ch_config->ch_info[i].count =
+					mqprio_qopt->qopt.count[i];
+				ch_config->ch_info[i].offset =
+					mqprio_qopt->qopt.offset[i];
+				total_qs += mqprio_qopt->qopt.count[i];
+				max_tx_rate = mqprio_qopt->max_rate[i];
+				/* convert to Mbps */
+				max_tx_rate = div_u64(max_tx_rate,
+						      IECM_MBPS_DIVISOR);
+				ch_config->ch_info[i].max_tx_rate =
+								max_tx_rate;
+			} else {
+				ch_config->ch_info[i].count = 1;
+				ch_config->ch_info[i].offset = 0;
+			}
+		}
+
+		/* Store queue info based on TC so that, VF gets configured
+		 * with correct number of queues when VF completes ADQ config
+		 * flow
+		 */
+		ch_config->total_qs = total_qs;
+
+		netif_tx_stop_all_queues(netdev);
+		netif_tx_disable(netdev);
+		ret = iecm_send_enable_channels_msg(vport);
+		if (ret)
+			return ret;
+		netdev_reset_tc(netdev);
+		/* Report the tc mapping up the stack */
+		netdev_set_num_tc(netdev, num_tc);
+		for (i = 0; i < max_tc_allowed; i++) {
+			u16 qcount = mqprio_qopt->qopt.count[i];
+			u16 qoffset = mqprio_qopt->qopt.offset[i];
+
+			if (i < num_tc)
+				netdev_set_tc_queue(netdev, netdev_tc++, qcount,
+						    qoffset);
+		}
+		/* Start all queues */
+		netif_tx_start_all_queues(netdev);
+		ch_config->tc_running = true;
+		set_bit(__IECM_HR_FUNC_RESET, adapter->flags);
+		queue_delayed_work(adapter->vc_event_wq,
+				   &adapter->vc_event_task,
+				   msecs_to_jiffies(10));
+	}
+	return ret;
+}
+
+/**
+ * iecm_setup_tc - ndo callback to setup up TC schedulers
+ * @netdev: pointer to net_device struct
+ * @type: TC type
+ * @type_data: TC type specific data
+ */
+static int iecm_setup_tc(struct net_device *netdev, enum tc_setup_type type,
+			 void *type_data)
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+	struct iecm_adapter *adapter = vport->adapter;

drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_open(struct net_device *netdev) · line 2624

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+	int err = 0;
+
+	switch (type) {
+	case TC_SETUP_QDISC_ETF:
+		if (iecm_is_queue_model_split(vport->txq_model))
+			err =
+			iecm_offload_txtime(vport,
+					    (struct tc_etf_qopt_offload *)
+					     type_data);
+		break;

So if we're using singleq model, it will do nothing and return 0. The kernel will think we've set things up, and we haven't.

drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_open(struct net_device *netdev) · line 2626

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +2 -0
+	case TC_SETUP_BLOCK:
+		break;

Same here.

drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_open(struct net_device *netdev) · line 2632

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +6 -0
+	case TC_SETUP_QDISC_MQPRIO:
+		if (iecm_is_cap_ena(adapter, IECM_BASE_CAPS,
+				    VIRTCHNL2_CAP_ADQ) ||
+		    iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_ADQ))
+			__iecm_setup_tc(vport, type_data);
+		break;

And here if we don't have caps.

Quoted 62 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +22 -14
+	default:
+		err = -EOPNOTSUPP;
+		break;
+	}
+
+	return err;
+}
+
 /**
  * iecm_set_mac - NDO callback to set port mac address
  * @netdev: network interface device structure
@@ -1997,13 +2711,13 @@ static const struct net_device_ops iecm_netdev_ops_splitq = {
 	.ndo_set_rx_mode = iecm_set_rx_mode,
 	.ndo_validate_addr = eth_validate_addr,
 	.ndo_set_mac_address = iecm_set_mac,
-	.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,
+	.ndo_change_mtu = iecm_change_mtu,
+	.ndo_get_stats64 = iecm_get_stats64,
+	.ndo_fix_features = iecm_fix_features,
+	.ndo_set_features = iecm_set_features,
+	.ndo_vlan_rx_add_vid = iecm_vlan_rx_add_vid,
+	.ndo_vlan_rx_kill_vid = iecm_vlan_rx_kill_vid,
+	.ndo_setup_tc = iecm_setup_tc,
 };
 
 static const struct net_device_ops iecm_netdev_ops_singleq = {
@@ -2013,11 +2727,11 @@ static const struct net_device_ops iecm_netdev_ops_singleq = {
 	.ndo_set_rx_mode = iecm_set_rx_mode,
 	.ndo_validate_addr = eth_validate_addr,
 	.ndo_set_mac_address = iecm_set_mac,
-	.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,
+	.ndo_change_mtu = iecm_change_mtu,
+	.ndo_get_stats64 = iecm_get_stats64,
+	.ndo_fix_features = iecm_fix_features,
+	.ndo_set_features = iecm_set_features,
+	.ndo_vlan_rx_add_vid = iecm_vlan_rx_add_vid,
+	.ndo_vlan_rx_kill_vid = iecm_vlan_rx_kill_vid,
+	.ndo_setup_tc = iecm_setup_tc,
 };
drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
index ef5fe659389b..4b9288e1c254 100644
@@ -218,6 +218,21 @@ const struct iecm_rx_ptype_decoded iecm_ptype_lookup[IECM_RX_MAX_PTYPE] = {
 };
 EXPORT_SYMBOL(iecm_ptype_lookup);
 
+/**
+ * iecm_get_stats64 - get statistics for network device structure
+ * @netdev: network interface device structure

drivers/net/ethernet/intel/iecm/iecm_txrx.c const struct iecm_rx_ptype_decoded iecm_ptype_lookup[IECM_RX_MAX_PTYPE] = { · line 233

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+ * @stats: main device statistics structure
+ */
+void iecm_get_stats64(struct net_device *netdev,
+		      struct rtnl_link_stats64 *stats)
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+
+	set_bit(__IECM_MB_STATS_PENDING, vport->adapter->flags);
+
+	*stats = vport->netstats;

This structure is 192 bytes long, I'd suggest using memcpy(), esp. given that it's not on hotpath at all.

Quoted 21 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +2 -0
+}
+
 /**
  * iecm_tx_buf_rel - Release a Tx buffer
  * @tx_q: the queue that owns the buffer
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +8 -0
index 919fb3958cf8..f2516343c199 100644
@@ -2731,6 +2731,69 @@ static int iecm_send_insert_vlan_msg(struct iecm_vport *vport, bool ena)
 	return err;
 }
 
+/**
+ * iecm_send_enable_channels_msg - Send enable channels message
+ * @vport: vport structure
+ *
+ * Request the PF/CP to enable channels as specified by the user via tc tool.
+ * Returns 0 on success, negative on failure.
+ **/
+int iecm_send_enable_channels_msg(struct iecm_vport *vport)

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_send_insert_vlan_msg(struct iecm_vport *vport, bool ena) · line 2751

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_channel_config *ch_config;
+	struct virtchnl_tc_info *vti = NULL;
+	int i, err;
+	u16 len;
+
+	ch_config = &adapter->config_data.ch_config;
+	len = ((ch_config->num_tc - 1) * sizeof(struct virtchnl_channel_info)) +
+		sizeof(struct virtchnl_tc_info);
	len = struct_size(vti, list, ch_config->num_tc - 1);

You can embed it directly in kzalloc() below.
Also please check if num_tc > 1.

Quoted 33 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +33 -0
+
+	vti = kzalloc(len, GFP_KERNEL);
+	if (!vti)
+		return -ENOMEM;
+	vti->num_tc = ch_config->num_tc;
+	for (i = 0; i < vti->num_tc; i++) {
+		vti->list[i].count = ch_config->ch_info[i].count;
+		vti->list[i].offset = ch_config->ch_info[i].offset;
+		vti->list[i].pad = 0;
+		vti->list[i].max_tx_rate = ch_config->ch_info[i].max_tx_rate;
+	}
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL_OP_ENABLE_CHANNELS, len,
+			       (u8 *)vti);
+	if (err)
+		goto error;
+
+	err = iecm_wait_for_event(adapter, IECM_VC_ENA_CHANNELS,
+				  IECM_VC_ENA_CHANNELS_ERR);
+error:
+	kfree(vti);
+	return err;
+}
+
+/**
+ * iecm_send_disable_channels_msg - Send disable channels message
+ * @vport: vport structure to disable channels on
+ *
+ * Returns 0 on success, negative on failure.
+ */
+int iecm_send_disable_channels_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_send_insert_vlan_msg(struct iecm_vport *vport, bool ena) · line 2794

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+	int err;
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL_OP_DISABLE_CHANNELS,
+			       0, NULL);
+	if (err)
+		return err;
+
+	err = iecm_min_wait_for_event(adapter, IECM_VC_DIS_CHANNELS,
+				      IECM_VC_DIS_CHANNELS_ERR);
+	return err;

Just return iecm_min_wait ..., this is redundant and either checkpatch or coccinelle will protest.

Quoted 19 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +2 -0
+}
+
 /**
  * iecm_send_vlan_v2_caps_msg - send virtchnl get offload VLAN V2 caps message
  * @adapter: adapter info struct
drivers/net/ethernet/intel/include/iecm.h +2 -0
index f6f9884c10c2..a655e797f457 100644
@@ -4,6 +4,8 @@
 #ifndef _IECM_H_
 #define _IECM_H_
 
+#include <net/pkt_sched.h>
+#include <net/pkt_cls.h>
 #include <linux/aer.h>
 #include <linux/pci.h>
 #include <linux/netdevice.h>

drivers/net/ethernet/intel/include/iecm.h line 49

Quoted 4 lines
drivers/net/ethernet/intel/include/iecm.h +1 -0
@@ -44,6 +46,8 @@
 /* available message levels */
 #define IECM_AVAIL_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
 
+#define IECM_MBPS_DIVISOR		125000 /* divisor to convert to Mbps */

Isn't this defined somewhere already?

drivers/net/ethernet/intel/include/iecm.h enum iecm_user_flags { · line 402

Quoted 11 lines
drivers/net/ethernet/intel/include/iecm.h +4 -0
+
 #define IECM_VIRTCHNL_VERSION_MAJOR VIRTCHNL_VERSION_MAJOR_2
 #define IECM_VIRTCHNL_VERSION_MINOR VIRTCHNL_VERSION_MINOR_0
 
@@ -393,6 +397,13 @@ enum iecm_user_flags {
 	__IECM_USER_FLAGS_NBITS,
 };
 
+struct iecm_channel_config {
+	struct virtchnl_channel_info ch_info[VIRTCHNL_MAX_ADQ_V2_CHANNELS];
+	bool tc_running;
	u8 tc_running:1;
Quoted 39 lines
drivers/net/ethernet/intel/include/iecm.h +7 -0
+	u8 total_qs;
+	u8 num_tc;
+};
+
 #define IECM_GET_PTYPE_SIZE(p) \
 	(sizeof(struct virtchnl2_ptype) + \
 	(((p)->proto_id_count ? ((p)->proto_id_count - 1) : 0) * sizeof(u16)))
@@ -430,6 +441,7 @@ struct iecm_user_config_data {
 	struct list_head mac_filter_list;
 	struct list_head vlan_filter_list;
 	struct list_head adv_rss_list;
+	struct iecm_channel_config ch_config;
 };
 
 struct iecm_rss_data {
@@ -703,6 +715,8 @@ 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_initiate_soft_reset(struct iecm_vport *vport,
+			     enum iecm_flags reset_cause);
 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);
drivers/net/ethernet/intel/include/iecm_txrx.h +2 -0
index 26e480343876..7ec742fd4c6b 100644
@@ -672,6 +672,8 @@ netdev_tx_t iecm_tx_singleq_start(struct sk_buff *skb,
 				  struct net_device *netdev);
 bool iecm_rx_singleq_buf_hw_alloc_all(struct iecm_queue *rxq,
 				      u16 cleaned_count);
+void iecm_get_stats64(struct net_device *netdev,
+		      struct rtnl_link_stats64 *stats);
 int iecm_tso(struct iecm_tx_buf *first, struct iecm_tx_offload_params *off);
 void iecm_tx_prepare_vlan_flags(struct iecm_queue *tx_q,
 				struct iecm_tx_buf *first,
Signature · 1 line
2.33.0

Thanks,
Al

author
#51 lore raw

PATCH 13/19 iecm: implement splitq napi_poll

In reply to Alan Brady

This adds everything we need to actually receive packets and process spent buffers using the splitq model. This contrasts to more traditional queueing models by essentially splitting a normal queue of descriptors and mapped buffers into separate queues. This allows us to deal with both more efficiently and also allows us to implement asymmetric queuing setups where you have multiple completion queues associated with a single buffer queue.

---
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   | 1468 ++++++++++++++++-
 drivers/net/ethernet/intel/include/iecm.h     |    4 +
 .../net/ethernet/intel/include/iecm_txrx.h    |   20 +
 3 files changed, 1490 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1466 -2
index 4b9288e1c254..85a82b58525a 100644
@@ -218,6 +218,36 @@ const struct iecm_rx_ptype_decoded iecm_ptype_lookup[IECM_RX_MAX_PTYPE] = {
 };
 EXPORT_SYMBOL(iecm_ptype_lookup);
 
+/**
+ * iecm_buf_lifo_push - push a buffer pointer onto stack
+ * @stack: pointer to stack struct
+ * @buf: pointer to buf to push
+ *
+ * Returns 0 on success, negative on failure
+ **/
+static int iecm_buf_lifo_push(struct iecm_buf_lifo *stack,
+			      struct iecm_tx_buf *buf)
+{
+	if (stack->top == stack->size)
+		return -ENOSPC;
+
+	stack->bufs[stack->top++] = buf;
+
+	return 0;
+}
+
+/**
+ * iecm_buf_lifo_pop - pop a buffer pointer from stack
+ * @stack: pointer to stack struct
+ **/
+static struct iecm_tx_buf *iecm_buf_lifo_pop(struct iecm_buf_lifo *stack)
+{
+	if (!stack->top)
+		return NULL;
+
+	return stack->bufs[--stack->top];
+}
+
 /**
  * iecm_get_stats64 - get statistics for network device structure
  * @netdev: network interface device structure
@@ -812,6 +842,30 @@ iecm_rx_buf_hw_alloc_all(struct iecm_queue *rxbufq, u16 alloc_count)
 	return !!alloc_count;
 }
 
+/**
+ * iecm_rx_post_buf_refill - Post buffer id to refill queue
+ * @refillq: refill queue to post to
+ * @buf_id: buffer id to post
+ */
+void iecm_rx_post_buf_refill(struct iecm_sw_queue *refillq, u16 buf_id)
+{
+	u16 nta = refillq->next_to_alloc;
+	u16 *bi;
+
+	bi = IECM_SPLITQ_RX_BI_DESC(refillq, nta);
+	/* store the buffer ID and the SW maintained GEN bit to the refillq */
+	*bi = ((buf_id << IECM_RX_BI_BUFID_S) & IECM_RX_BI_BUFID_M) |
+	      (!!(test_bit(__IECM_Q_GEN_CHK, refillq->flags)) <<
+	       IECM_RX_BI_GEN_S);
+
+	nta++;
+	if (unlikely(nta == refillq->desc_count)) {
+		nta = 0;
+		change_bit(__IECM_Q_GEN_CHK, refillq->flags);
+	}
+	refillq->next_to_alloc = nta;
+}
+
 /**
  * iecm_rx_post_buf_desc - Post buffer to bufq descriptor ring
  * @bufq: buffer queue to post to
@@ -1670,6 +1724,398 @@ int iecm_vport_queues_alloc(struct iecm_vport *vport)
 	return err;
 }
 
+/**
+ * iecm_tx_find_q - Find the tx q based on q id
+ * @vport: the vport we care about
+ * @q_id: Id of the queue
+ *
+ * Returns queue ptr if found else returns NULL
+ */
+static struct iecm_queue *
+iecm_tx_find_q(struct iecm_vport *vport, int q_id)
+{
+	int i;
+
+	for (i = 0; i < vport->num_txq; i++) {
+		struct iecm_queue *tx_q = vport->txqs[i];
+
+		if (tx_q->q_id == q_id)
+			return tx_q;
+	}
+
+	return NULL;
+}
+
+/**
+ * iecm_tx_handle_sw_marker - Handle queue marker packet
+ * @tx_q: tx queue to handle software marker
+ */
+static void iecm_tx_handle_sw_marker(struct iecm_queue *tx_q)
+{
+	struct iecm_vport *vport = tx_q->vport;
+	bool drain_complete = true;
+	int i;
+
+	clear_bit(__IECM_Q_SW_MARKER, tx_q->flags);
+	/* Hardware must write marker packets to all queues associated with
+	 * completion queues. So check if all queues received marker packets
+	 */
+	for (i = 0; i < vport->num_txq; i++) {
+		if (test_bit(__IECM_Q_SW_MARKER, vport->txqs[i]->flags))
+			drain_complete = false;
+	}
+	if (drain_complete) {
+		set_bit(__IECM_SW_MARKER, vport->adapter->flags);
+		wake_up(&vport->adapter->sw_marker_wq);
+	}
+}
+
+/**
+ * iecm_tx_splitq_clean_buf - Clean TX buffer resources
+ * @tx_q: tx queue to clean buffer from
+ * @tx_buf: buffer to be cleaned
+ * @napi_budget: Used to determine if we are in netpoll
+ */
+static void
+iecm_tx_splitq_clean_buf(struct iecm_queue *tx_q, struct iecm_tx_buf *tx_buf,
+			 int napi_budget)
+{
+	/* unmap skb header data */
+	dma_unmap_single(tx_q->dev,
+			 dma_unmap_addr(tx_buf, dma),
+			 dma_unmap_len(tx_buf, len),
+			 DMA_TO_DEVICE);
+
+	napi_consume_skb(tx_buf->skb, napi_budget);
+
+	/* clear tx_buf data */
+	tx_buf->skb = NULL;
+	dma_unmap_len_set(tx_buf, len, 0);
+}
+
+/**
+ * iecm_stash_flow_sch_buffers - store buffere parameter info to be freed at a
+ * later time (only relevant for flow scheduling mode)
+ * @txq: Tx queue to clean
+ * @tx_buf: buffer to store
+ */
+static int
+iecm_stash_flow_sch_buffers(struct iecm_queue *txq, struct iecm_tx_buf *tx_buf)
+{
+	struct iecm_adapter *adapter = txq->vport->adapter;
+	struct iecm_tx_buf *shadow_buf;
+
+	shadow_buf = iecm_buf_lifo_pop(&txq->buf_stack);
+	if (!shadow_buf) {
+		dev_err(&adapter->pdev->dev,
+			"No out-of-order TX buffers left!\n");
+		return -ENOMEM;
+	}
+
+	/* Store buffer params in shadow buffer */
+	shadow_buf->skb = tx_buf->skb;
+	shadow_buf->bytecount = tx_buf->bytecount;
+	shadow_buf->gso_segs = tx_buf->gso_segs;
+	dma_unmap_addr_set(shadow_buf, dma, dma_unmap_addr(tx_buf, dma));
+	dma_unmap_len_set(shadow_buf, len, dma_unmap_len(tx_buf, len));
+	shadow_buf->compl_tag = tx_buf->compl_tag;
+
+	/* Add buffer to buf_hash table to be freed
+	 * later
+	 */
+	hash_add(txq->sched_buf_hash, &shadow_buf->hlist,
+		 shadow_buf->compl_tag);
+
+	memset(tx_buf, 0, sizeof(struct iecm_tx_buf));
+
+	return 0;
+}
+
+/**
+ * iecm_tx_splitq_clean - Reclaim resources from buffer queue
+ * @tx_q: Tx queue to clean
+ * @end: queue index until which it should be cleaned
+ * @napi_budget: Used to determine if we are in netpoll
+ * @descs_only: true if queue is using flow-based scheduling and should
+ * not clean buffers at this time
+ *
+ * Cleans the queue descriptor ring. If the queue is using queue-based
+ * scheduling, the buffers will be cleaned as well and this function will
+ * return the number of bytes/packets cleaned. If the queue is using flow-based
+ * scheduling, only the descriptors are cleaned at this time. Separate packet
+ * completion events will be reported on the completion queue, and the buffers
+ * will be cleaned separately. The stats returned from this function when using
+ * flow-based scheduling are irrelevant.
+ */
+static struct iecm_tx_queue_stats
+iecm_tx_splitq_clean(struct iecm_queue *tx_q, u16 end, int napi_budget,
+		     bool descs_only)
+{
+	union iecm_tx_flex_desc *next_pending_desc = NULL;
+	struct iecm_tx_queue_stats cleaned_stats = {0};
+	union iecm_tx_flex_desc *tx_desc;
+	s16 ntc = tx_q->next_to_clean;
+	struct iecm_tx_buf *tx_buf;
+	unsigned short gso_segs = 0;
+	unsigned int bytecount = 0;
+	struct netdev_queue *nq;
+
+	tx_desc = IECM_FLEX_TX_DESC(tx_q, ntc);
+	next_pending_desc = IECM_FLEX_TX_DESC(tx_q, end);
+	tx_buf = &tx_q->tx_buf[ntc];
+	ntc -= tx_q->desc_count;
+
+	while (tx_desc != next_pending_desc) {
+		union iecm_tx_flex_desc *eop_desc =
+			(union iecm_tx_flex_desc *)tx_buf->next_to_watch;
+
+		/* clear next_to_watch to prevent false hangs */
+		tx_buf->next_to_watch = NULL;
+
+		bytecount += tx_buf->bytecount;
+		gso_segs += tx_buf->gso_segs;
+
+		if (descs_only) {
+			if (iecm_stash_flow_sch_buffers(tx_q, tx_buf))
+				goto tx_splitq_clean_out;
+
+			while (tx_desc != eop_desc) {
+				tx_buf++;
+				tx_desc++;
+				ntc++;
+				if (unlikely(!ntc)) {
+					ntc -= tx_q->desc_count;
+					tx_buf = tx_q->tx_buf;
+					tx_desc = IECM_FLEX_TX_DESC(tx_q, 0);
+				}
+
+				if (dma_unmap_len(tx_buf, len)) {
+					if (iecm_stash_flow_sch_buffers(tx_q,
+									tx_buf))
+						goto tx_splitq_clean_out;
+				}
+			}
+		} else {
+			/* update the statistics for this packet */
+			cleaned_stats.bytes += tx_buf->bytecount;
+			cleaned_stats.packets += tx_buf->gso_segs;
+
+			iecm_tx_splitq_clean_buf(tx_q, tx_buf, napi_budget);
+
+			/* unmap remaining buffers */
+			while (tx_desc != eop_desc) {
+				tx_buf++;
+				tx_desc++;
+				ntc++;
+				if (unlikely(!ntc)) {
+					ntc -= tx_q->desc_count;
+					tx_buf = tx_q->tx_buf;
+					tx_desc = IECM_FLEX_TX_DESC(tx_q, 0);
+				}
+
+				/* unmap any remaining paged data */
+				if (dma_unmap_len(tx_buf, len)) {
+					dma_unmap_page(tx_q->dev,
+						       dma_unmap_addr(tx_buf, dma),
+						       dma_unmap_len(tx_buf, len),
+						       DMA_TO_DEVICE);
+					dma_unmap_len_set(tx_buf, len, 0);
+				}
+			}
+		}
+
+		tx_buf++;
+		tx_desc++;
+		ntc++;
+		if (unlikely(!ntc)) {
+			ntc -= tx_q->desc_count;
+			tx_buf = tx_q->tx_buf;
+			tx_desc = IECM_FLEX_TX_DESC(tx_q, 0);
+		}
+	}
+
+tx_splitq_clean_out:
+	ntc += tx_q->desc_count;
+	tx_q->next_to_clean = ntc;
+
+	nq = netdev_get_tx_queue(tx_q->vport->netdev, tx_q->idx);
+	netdev_tx_completed_queue(nq, gso_segs, bytecount);
+
+	return cleaned_stats;
+}
+
+/**
+ * iecm_tx_clean_flow_sch_bufs - clean bufs that were stored for
+ * out of order completions
+ * @txq: queue to clean
+ * @compl_tag: completion tag of packet to clean (from completion descriptor)
+ * @budget: Used to determine if we are in netpoll
+ */
+static struct iecm_tx_queue_stats
+iecm_tx_clean_flow_sch_bufs(struct iecm_queue *txq, u16 compl_tag,
+			    int budget)
+{
+	struct iecm_tx_queue_stats cleaned_stats = {0};
+	struct hlist_node *tmp_buf = NULL;
+	struct iecm_tx_buf *tx_buf = NULL;
+
+	/* Buffer completion */
+	hash_for_each_possible_safe(txq->sched_buf_hash, tx_buf, tmp_buf,
+				    hlist, compl_tag) {
+		if (tx_buf->compl_tag != compl_tag)
+			continue;
+
+		if (likely(tx_buf->skb)) {
+			/* update the statistics for this packet */
+			cleaned_stats.bytes += tx_buf->bytecount;
+			cleaned_stats.packets += tx_buf->gso_segs;
+
+			iecm_tx_splitq_clean_buf(txq, tx_buf, budget);
+		} else if (dma_unmap_len(tx_buf, len)) {
+			dma_unmap_page(txq->dev,
+				       dma_unmap_addr(tx_buf, dma),
+				       dma_unmap_len(tx_buf, len),
+				       DMA_TO_DEVICE);
+			dma_unmap_len_set(tx_buf, len, 0);
+		}
+		/* Push shadow buf back onto stack */
+		iecm_buf_lifo_push(&txq->buf_stack, tx_buf);
+
+		hash_del(&tx_buf->hlist);
+	}
+
+	return cleaned_stats;
+}
+
+/**
+ * iecm_tx_clean_complq - Reclaim resources on completion queue
+ * @complq: Tx ring to clean
+ * @budget: Used to determine if we are in netpoll
+ *
+ * Returns true if there's any budget left (e.g. the clean is finished)
+ */
+static bool
+iecm_tx_clean_complq(struct iecm_queue *complq, int budget)
+{
+	struct iecm_splitq_tx_compl_desc *tx_desc;
+	struct iecm_vport *vport = complq->vport;
+	s16 ntc = complq->next_to_clean;
+	bool clean_completed = false;
+	unsigned int complq_budget;
+
+	complq_budget = vport->compln_clean_budget;
+	tx_desc = IECM_SPLITQ_TX_COMPLQ_DESC(complq, ntc);
+	ntc -= complq->desc_count;
+
+	do {
+		struct iecm_tx_queue_stats cleaned_stats = {0};
+		struct iecm_queue *tx_q;
+		u16 compl_tag, hw_head;
+		int tx_qid;
+		u8 ctype;	/* completion type */
+		u16 gen;
+
+		/* if the descriptor isn't done, no work yet to do */
+		gen = (le16_to_cpu(tx_desc->qid_comptype_gen) &
+		      IECM_TXD_COMPLQ_GEN_M) >> IECM_TXD_COMPLQ_GEN_S;
+		if (test_bit(__IECM_Q_GEN_CHK, complq->flags) != gen)
+			break;
+
+		/* Find necessary info of TX queue to clean buffers */
+		tx_qid = (le16_to_cpu(tx_desc->qid_comptype_gen) &
+			 IECM_TXD_COMPLQ_QID_M) >> IECM_TXD_COMPLQ_QID_S;
+		tx_q = iecm_tx_find_q(vport, tx_qid);
+		if (!tx_q) {
+			dev_err(&complq->vport->adapter->pdev->dev,
+				"TxQ #%d not found\n", tx_qid);
+			goto fetch_next_desc;
+		}
+
+		/* Determine completion type */
+		ctype = (le16_to_cpu(tx_desc->qid_comptype_gen) &
+			IECM_TXD_COMPLQ_COMPL_TYPE_M) >>
+			IECM_TXD_COMPLQ_COMPL_TYPE_S;
+		switch (ctype) {
+		case IECM_TXD_COMPLT_RE:
+			hw_head = le16_to_cpu(tx_desc->q_head_compl_tag.q_head);
+
+			cleaned_stats = iecm_tx_splitq_clean(tx_q, hw_head,
+							     budget, true);
+			break;
+		case IECM_TXD_COMPLT_RS:
+			if (test_bit(__IECM_Q_FLOW_SCH_EN, tx_q->flags)) {
+				compl_tag =
+				le16_to_cpu(tx_desc->q_head_compl_tag.compl_tag);
+
+				cleaned_stats =
+					iecm_tx_clean_flow_sch_bufs(tx_q,
+								    compl_tag,
+								    budget);
+			} else {
+				hw_head =
+				le16_to_cpu(tx_desc->q_head_compl_tag.q_head);
+
+				cleaned_stats = iecm_tx_splitq_clean(tx_q,
+								     hw_head,
+								     budget,
+								     false);
+			}
+
+			break;
+		case IECM_TXD_COMPLT_SW_MARKER:
+			iecm_tx_handle_sw_marker(tx_q);
+			break;
+		default:
+			dev_err(&tx_q->vport->adapter->pdev->dev,
+				"Unknown TX completion type: %d\n",
+				ctype);
+			goto fetch_next_desc;
+		}
+
+		u64_stats_update_begin(&tx_q->stats_sync);
+		tx_q->q_stats.tx.packets += cleaned_stats.packets;
+		tx_q->q_stats.tx.bytes += cleaned_stats.bytes;
+		u64_stats_update_end(&tx_q->stats_sync);
+
+		if (unlikely(cleaned_stats.packets &&
+			     netif_carrier_ok(tx_q->vport->netdev) &&
+			     (IECM_DESC_UNUSED(tx_q) >= IECM_TX_WAKE_THRESH) &&
+			     (IECM_TX_BUF_UNUSED(tx_q) >= tx_q->desc_count >> 2))) {
+			/* Make sure any other threads stopping queue after
+			 * this see new next_to_clean.
+			 */
+			smp_mb();
+			if (tx_q->vport->adapter->state == __IECM_UP &&
+			    __netif_subqueue_stopped(tx_q->vport->netdev,
+						     tx_q->idx)) {
+				netif_wake_subqueue(tx_q->vport->netdev,
+						    tx_q->idx);
+			}
+		}
+
+fetch_next_desc:
+		tx_desc++;
+		ntc++;
+		if (unlikely(!ntc)) {
+			ntc -= complq->desc_count;
+			tx_desc = IECM_SPLITQ_TX_COMPLQ_DESC(complq, 0);
+			change_bit(__IECM_Q_GEN_CHK, complq->flags);
+		}
+
+		prefetch(tx_desc);
+
+		/* update budget accounting */
+		complq_budget--;
+	} while (likely(complq_budget));
+
+	ntc += complq->desc_count;
+	complq->next_to_clean = ntc;
+
+	clean_completed = !!complq_budget;
+
+	return clean_completed;
+}
+
 /**
  * iecm_tx_splitq_build_ctb - populate command tag and size for queue
  * based scheduling descriptors
@@ -2337,6 +2783,940 @@ netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,
 	return iecm_tx_splitq_frame(skb, tx_q);
 }
 
+/**
+ * iecm_ptype_to_htype - get a hash type
+ * @decoded: Decoded Rx packet type related fields
+ *
+ * Returns appropriate hash type (such as PKT_HASH_TYPE_L2/L3/L4) to be used by
+ * skb_set_hash based on PTYPE as parsed by HW Rx pipeline and is part of
+ * Rx desc.
+ */
+enum
+pkt_hash_types iecm_ptype_to_htype(struct iecm_rx_ptype_decoded *decoded)
+{
+	if (!decoded->known)
+		return PKT_HASH_TYPE_NONE;
+	if (decoded->payload_layer == IECM_RX_PTYPE_PAYLOAD_LAYER_PAY2 &&
+	    decoded->inner_prot)
+		return PKT_HASH_TYPE_L4;
+	if (decoded->payload_layer == IECM_RX_PTYPE_PAYLOAD_LAYER_PAY2 &&
+	    decoded->outer_ip)
+		return PKT_HASH_TYPE_L3;
+	if (decoded->outer_ip == IECM_RX_PTYPE_OUTER_L2)
+		return PKT_HASH_TYPE_L2;
+
+	return PKT_HASH_TYPE_NONE;
+}
+
+/**
+ * iecm_rx_hash - set the hash value in the skb
+ * @rxq: Rx descriptor ring packet is being transacted on
+ * @skb: pointer to current skb being populated
+ * @rx_desc: Receive descriptor
+ * @decoded: Decoded Rx packet type related fields
+ */
+static void
+iecm_rx_hash(struct iecm_queue *rxq, struct sk_buff *skb,
+	     struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc,
+	     struct iecm_rx_ptype_decoded *decoded)
+{
+	u32 hash;
+
+	if (!iecm_is_feature_ena(rxq->vport, NETIF_F_RXHASH))
+		return;
+
+	hash = le16_to_cpu(rx_desc->hash1) |
+	       (rx_desc->ff2_mirrid_hash2.hash2 << 16) |
+	       (rx_desc->hash3 << 24);
+
+	skb_set_hash(skb, hash, iecm_ptype_to_htype(decoded));
+}
+
+/**
+ * iecm_rx_csum - Indicate in skb if checksum is good
+ * @rxq: Rx descriptor ring packet is being transacted on
+ * @skb: pointer to current skb being populated
+ * @csum_bits: checksum fields extracted from the descriptor
+ * @decoded: Decoded Rx packet type related fields
+ *
+ * skb->protocol must be set before this function is called
+ */
+static void iecm_rx_csum(struct iecm_queue *rxq, struct sk_buff *skb,
+			 struct iecm_rx_csum_decoded *csum_bits,
+			 struct iecm_rx_ptype_decoded *decoded)
+{
+	bool ipv4, ipv6;
+
+	/* Start with CHECKSUM_NONE and by default csum_level = 0 */
+	skb->ip_summed = CHECKSUM_NONE;
+
+	/* check if Rx checksum is enabled */
+	if (!iecm_is_feature_ena(rxq->vport, NETIF_F_RXCSUM))
+		return;
+
+	/* check if HW has decoded the packet and checksum */
+	if (!(csum_bits->l3l4p))
+		return;
+
+	ipv4 = (decoded->outer_ip == IECM_RX_PTYPE_OUTER_IP) &&
+	       (decoded->outer_ip_ver == IECM_RX_PTYPE_OUTER_IPV4);
+	ipv6 = (decoded->outer_ip == IECM_RX_PTYPE_OUTER_IP) &&
+	       (decoded->outer_ip_ver == IECM_RX_PTYPE_OUTER_IPV6);
+
+	if (ipv4 && (csum_bits->ipe || csum_bits->eipe))
+		goto checksum_fail;
+
+	if (ipv6 && csum_bits->ipv6exadd)
+		return;
+
+	/* HW checksum will be invalid if vlan stripping is not enabled and
+	 * packet has an outer vlan tag. raw_csum_inv will also not be set
+	 * even though it's invalid.
+	 */
+	if (skb_vlan_tag_present(skb))
+		return;
+
+	/* check for L4 errors and handle packets that were not able to be
+	 * checksummed
+	 */
+	if (csum_bits->l4e)
+		goto checksum_fail;
+
+	/* Only report checksum unnecessary for ICMP, TCP, UDP, or SCTP */
+	switch (decoded->inner_prot) {
+	case IECM_RX_PTYPE_INNER_PROT_ICMP:
+	case IECM_RX_PTYPE_INNER_PROT_TCP:
+	case IECM_RX_PTYPE_INNER_PROT_UDP:
+	case IECM_RX_PTYPE_INNER_PROT_SCTP:
+		skb->ip_summed = CHECKSUM_UNNECESSARY;
+	default:
+		break;
+	}
+	return;
+
+checksum_fail:
+	rxq->vport->port_stats.rx_hw_csum_err++;
+}
+
+/**
+ * iecm_rx_splitq_extract_csum_bits - Extract checksum bits from descriptor
+ * @rx_desc: receive descriptor
+ * @csum: structure to extract checksum fields
+ *
+ **/
+static void
+iecm_rx_splitq_extract_csum_bits(struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc,
+				 struct iecm_rx_csum_decoded *csum)
+{
+	u8 qword0, qword1;
+
+	qword0 = rx_desc->status_err0_qw0;
+	qword1 = rx_desc->status_err0_qw1;
+
+	csum->ipe = !!(qword1 &
+		       BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_XSUM_IPE_S));
+	csum->eipe = !!(qword1 &
+			BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_XSUM_EIPE_S));
+	csum->l4e = !!(qword1 &
+		       BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_XSUM_L4E_S));
+	csum->l3l4p = !!(qword1 &
+			 BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_L3L4P_S));
+	csum->ipv6exadd =
+			!!(qword0 &
+			   BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_IPV6EXADD_S));
+	csum->rsc = !!(le16_to_cpu(rx_desc->hdrlen_flags) &
+		       VIRTCHNL2_RX_FLEX_DESC_ADV_RSC_M);
+	csum->raw_csum_inv = !!(le16_to_cpu(rx_desc->ptype_err_fflags0) &
+				BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_FF0_S));
+	csum->raw_csum = le16_to_cpu(rx_desc->misc.raw_cs);
+	csum->pprs = 0;
+}
+
+/**
+ * iecm_rx_rsc - Set the RSC fields in the skb
+ * @rxq : Rx descriptor ring packet is being transacted on
+ * @skb : pointer to current skb being populated
+ * @rx_desc: Receive descriptor
+ * @decoded: Decoded Rx packet type related fields
+ *
+ * Return 0 on success and error code on failure
+ *
+ * Populate the skb fields with the total number of RSC segments, RSC payload
+ * length and packet type.
+ */
+static int iecm_rx_rsc(struct iecm_queue *rxq, struct sk_buff *skb,
+		       struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc,
+		       struct iecm_rx_ptype_decoded *decoded)
+{
+	u16 rsc_segments, rsc_payload_len;
+	struct tcphdr *tcph;
+	bool ipv4, ipv6;
+
+	if (!decoded->outer_ip)
+		return -EINVAL;
+
+	rsc_payload_len = le16_to_cpu(rx_desc->misc.rscseglen);
+	if (!rsc_payload_len)
+		return -EINVAL;
+
+	ipv4 = (decoded->outer_ip == IECM_RX_PTYPE_OUTER_IP) &&
+		(decoded->outer_ip_ver == IECM_RX_PTYPE_OUTER_IPV4);
+	ipv6 = (decoded->outer_ip == IECM_RX_PTYPE_OUTER_IP) &&
+		(decoded->outer_ip_ver == IECM_RX_PTYPE_OUTER_IPV6);
+
+	if (!(ipv4 ^ ipv6))
+		return -EINVAL;
+
+	rsc_segments = DIV_ROUND_UP(skb->data_len, rsc_payload_len);
+
+	NAPI_GRO_CB(skb)->count = rsc_segments;
+	skb_shinfo(skb)->gso_size = rsc_payload_len;
+
+	skb_reset_network_header(skb);
+
+	if (ipv4) {
+		struct iphdr *ipv4h = ip_hdr(skb);
+
+		skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
+
+		/* Reset and set transport header offset in skb */
+		skb_set_transport_header(skb, sizeof(struct iphdr));
+		tcph = tcp_hdr(skb);
+
+		/* Compute the TCP pseudo header checksum*/
+		tcph->check =
+			~tcp_v4_check(skb->len - skb_transport_offset(skb),
+				      ipv4h->saddr, ipv4h->daddr, 0);
+	} else {
+		struct ipv6hdr *ipv6h = ipv6_hdr(skb);
+
+		skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
+		skb_set_transport_header(skb, sizeof(struct ipv6hdr));
+		tcph = tcp_hdr(skb);
+		tcph->check =
+			~tcp_v6_check(skb->len - skb_transport_offset(skb),
+				      &ipv6h->saddr, &ipv6h->daddr, 0);
+	}
+
+	tcp_gro_complete(skb);
+
+	u64_stats_update_begin(&rxq->stats_sync);
+	rxq->q_stats.rx.rsc_pkts++;
+	u64_stats_update_end(&rxq->stats_sync);
+
+	return 0;
+}
+
+/**
+ * iecm_rx_process_skb_fields - Populate skb header fields from Rx descriptor
+ * @rxq: Rx descriptor ring packet is being transacted on
+ * @skb: pointer to current skb being populated
+ * @rx_desc: Receive descriptor
+ *
+ * This function checks the ring, descriptor, and packet information in
+ * order to populate the hash, checksum, VLAN, protocol, and
+ * other fields within the skb.
+ */
+int
+iecm_rx_process_skb_fields(struct iecm_queue *rxq, struct sk_buff *skb,
+			   struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc)
+{
+	struct iecm_rx_ptype_decoded decoded;
+	struct iecm_rx_csum_decoded csum_bits;
+	u16 rx_ptype;
+	int err = 0;
+
+	rx_ptype = le16_to_cpu(rx_desc->ptype_err_fflags0) &
+				VIRTCHNL2_RX_FLEX_DESC_ADV_PTYPE_M;
+
+	decoded = rxq->vport->rx_ptype_lkup[rx_ptype];
+	if (!decoded.known)
+		return -EINVAL;
+
+	/* modifies the skb - consumes the enet header */
+	skb->protocol = eth_type_trans(skb, rxq->vport->netdev);
+	iecm_rx_splitq_extract_csum_bits(rx_desc, &csum_bits);
+	iecm_rx_csum(rxq, skb, &csum_bits, &decoded);
+	/* process RSS/hash */
+	iecm_rx_hash(rxq, skb, rx_desc, &decoded);
+
+	if (csum_bits.rsc)
+		err = iecm_rx_rsc(rxq, skb, rx_desc, &decoded);
+
+	return err;
+}
+
+/**
+ * iecm_rx_skb - Send a completed packet up the stack
+ * @rxq: Rx ring in play
+ * @skb: packet to send up
+ * @vlan_tag: packet vlan tag
+ *
+ * This function sends the completed packet (via. skb) up the stack using
+ * gro receive functions
+ */
+void iecm_rx_skb(struct iecm_queue *rxq, struct sk_buff *skb, u16 vlan_tag)
+{
+	/* Adding HW VLAN tag to skb must occur after processing csum */
+	if (vlan_tag & VLAN_VID_MASK)
+		__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlan_tag);
+
+	napi_gro_receive(&rxq->q_vector->napi, skb);
+}
+
+/**
+ * iecm_rx_page_is_reserved - check if reuse is possible
+ * @page: page struct to check
+ */
+static bool iecm_rx_page_is_reserved(struct page *page)
+{
+	return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page);
+}
+
+/**
+ * iecm_rx_buf_adjust_pg - Prepare rx buffer for reuse
+ * @rx_buf: Rx buffer to adjust
+ * @size: Size of adjustment
+ *
+ * Update the offset within page so that rx buf will be ready to be reused.
+ * For systems with PAGE_SIZE < 8192 this function will flip the page offset
+ * so the second half of page assigned to rx buffer will be used, otherwise
+ * the offset is moved by the @size bytes
+ */
+void
+iecm_rx_buf_adjust_pg(struct iecm_rx_buf *rx_buf, unsigned int size)
+{
+	struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf->page_indx];
+
+#if (PAGE_SIZE < 8192)
+	if (rx_buf->buf_size > IECM_RX_BUF_2048)
+		/* flip to second page */
+		rx_buf->page_indx = !rx_buf->page_indx;
+	else
+		/* flip page offset to other buffer */
+		page_info->page_offset ^= size;
+#else
+	/* move offset up to the next cache line */
+	page_info->page_offset += size;
+#endif
+}
+
+/**
+ * iecm_rx_can_reuse_page - Determine if page can be reused for another rx
+ * @rx_buf: buffer containing the page
+ *
+ * If page is reusable, we have a green light for calling iecm_reuse_rx_page,
+ * which will assign the current buffer to the buffer that next_to_alloc is
+ * pointing to; otherwise, the dma mapping needs to be destroyed and
+ * page freed
+ */
+bool iecm_rx_can_reuse_page(struct iecm_rx_buf *rx_buf)
+{
+	struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf->page_indx];
+
+#if (PAGE_SIZE >= 8192)
+	unsigned int last_offset = PAGE_SIZE - rx_buf->buf_size;
+#endif /* PAGE_SIZE < 8192) */
+	unsigned int pagecnt_bias = page_info->pagecnt_bias;
+	struct page *page = page_info->page;
+
+	/* avoid re-using remote pages */
+	if (unlikely(iecm_rx_page_is_reserved(page)))
+		return false;
+
+#if (PAGE_SIZE < 8192)
+	/* if we are only owner of page we can reuse it */
+	if (unlikely((page_count(page) - pagecnt_bias) > 1))
+		return false;
+#else
+	if (rx_buf->page_offset > last_offset)
+		return false;
+#endif /* PAGE_SIZE < 8192) */
+
+	/* If we have drained the page fragment pool we need to update
+	 * the pagecnt_bias and page count so that we fully restock the
+	 * number of references the driver holds.
+	 */
+	if (unlikely(pagecnt_bias == 1)) {
+		page_ref_add(page, USHRT_MAX - 1);
+		page_info->pagecnt_bias = USHRT_MAX;
+	}
+
+	return true;
+}
+
+/**
+ * iecm_rx_add_frag - Add contents of Rx buffer to sk_buff as a frag
+ * @rx_buf: buffer containing page to add
+ * @skb: sk_buff to place the data into
+ * @size: packet length from rx_desc
+ *
+ * This function will add the data contained in rx_buf->page to the skb.
+ * It will just attach the page as a frag to the skb.
+ * The function will then update the page offset.
+ */
+void iecm_rx_add_frag(struct iecm_rx_buf *rx_buf, struct sk_buff *skb,
+		      unsigned int size)
+{
+	struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf->page_indx];
+
+#if (PAGE_SIZE >= 8192)
+	unsigned int truesize = SKB_DATA_ALIGN(size);
+#else
+	unsigned int truesize = rx_buf->buf_size;
+#endif
+
+	skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page_info->page,
+			page_info->page_offset, size, truesize);
+
+	iecm_rx_buf_adjust_pg(rx_buf, truesize);
+}
+
+/**
+ * iecm_rx_get_buf_page - Fetch Rx buffer page and synchronize data for use
+ * @dev: device struct
+ * @rx_buf: Rx buf to fetch page for
+ * @size: size of buffer to add to skb
+ *
+ * This function will pull an Rx buffer page from the ring and synchronize it
+ * for use by the CPU.
+ */
+static void
+iecm_rx_get_buf_page(struct device *dev, struct iecm_rx_buf *rx_buf,
+		     const unsigned int size)
+{
+	struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf->page_indx];
+
+	prefetch(page_info->page);
+
+	/* we are reusing so sync this buffer for CPU use */
+	dma_sync_single_range_for_cpu(dev, page_info->dma,
+				      page_info->page_offset, size,
+				      DMA_FROM_DEVICE);
+
+	/* We have pulled a buffer for use, so decrement pagecnt_bias */
+	page_info->pagecnt_bias--;
+}
+
+/**
+ * iecm_rx_construct_skb - Allocate skb and populate it
+ * @rxq: Rx descriptor queue
+ * @rx_buf: Rx buffer to pull data from
+ * @size: the length of the packet
+ *
+ * This function allocates an skb. It then populates it with the page
+ * data from the current receive descriptor, taking care to set up the
+ * skb correctly.
+ */
+struct sk_buff *
+iecm_rx_construct_skb(struct iecm_queue *rxq, struct iecm_rx_buf *rx_buf,
+		      unsigned int size)
+{
+	struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf->page_indx];
+
+	void *va = page_address(page_info->page) + page_info->page_offset;
+	unsigned int headlen;
+	struct sk_buff *skb;
+
+	/* prefetch first cache line of first page */
+	prefetch(va);
+#if L1_CACHE_BYTES < 128
+	prefetch((u8 *)va + L1_CACHE_BYTES);
+#endif /* L1_CACHE_BYTES */
+	/* allocate a skb to store the frags */
+	skb = __napi_alloc_skb(&rxq->q_vector->napi, IECM_RX_HDR_SIZE,
+			       GFP_ATOMIC | __GFP_NOWARN);
+	if (unlikely(!skb))
+		return NULL;
+
+	skb_record_rx_queue(skb, rxq->idx);
+
+	/* Determine available headroom for copy */
+	headlen = size;
+	if (headlen > IECM_RX_HDR_SIZE)
+		headlen = eth_get_headlen(skb->dev, va, IECM_RX_HDR_SIZE);
+
+	/* align pull length to size of long to optimize memcpy performance */
+	memcpy(__skb_put(skb, headlen), va, ALIGN(headlen, sizeof(long)));
+
+	/* if we exhaust the linear part then add what is left as a frag */
+	size -= headlen;
+	if (size) {
+#if (PAGE_SIZE >= 8192)
+		unsigned int truesize = SKB_DATA_ALIGN(size);
+#else
+		unsigned int truesize = rx_buf->buf_size;
+#endif
+		skb_add_rx_frag(skb, 0, page_info->page,
+				page_info->page_offset + headlen, size,
+				truesize);
+		/* buffer is used by skb, update page_offset */
+		iecm_rx_buf_adjust_pg(rx_buf, truesize);
+
+	} else {
+		/* buffer is unused, reset bias back to rx_buf; data was copied
+		 * onto skb's linear part so there's no need for adjusting
+		 * page offset and we can reuse this buffer as-is
+		 */
+		page_info->pagecnt_bias++;
+	}
+
+	return skb;
+}
+
+/**
+ * iecm_rx_hdr_construct_skb - Allocate skb and populate it from header buffer
+ * @rxq: Rx descriptor queue
+ * @hdr_buf: Rx buffer to pull data from
+ * @size: the length of the packet
+ *
+ * This function allocates an skb. It then populates it with the page data from
+ * the current receive descriptor, taking care to set up the skb correctly.
+ * This specifcally uses a header buffer to start building the skb.
+ */
+static struct sk_buff *
+iecm_rx_hdr_construct_skb(struct iecm_queue *rxq, struct iecm_dma_mem *hdr_buf,
+			  unsigned int size)
+{
+	struct sk_buff *skb;
+
+	/* allocate a skb to store the frags */
+	skb = __napi_alloc_skb(&rxq->q_vector->napi, IECM_RX_HDR_SIZE,
+			       GFP_ATOMIC | __GFP_NOWARN);
+	if (unlikely(!skb))
+		return NULL;
+
+	skb_record_rx_queue(skb, rxq->idx);
+
+	memcpy(__skb_put(skb, size), hdr_buf->va, size);
+
+	return skb;
+}
+
+/**
+ * iecm_rx_splitq_test_staterr - tests bits in Rx descriptor
+ * status and error fields
+ * @stat_err_field: field from descriptor to test bits in
+ * @stat_err_bits: value to mask
+ *
+ */
+bool
+iecm_rx_splitq_test_staterr(u8 stat_err_field, const u8 stat_err_bits)
+{
+	return !!(stat_err_field & stat_err_bits);
+}
+
+/**
+ * iecm_rx_splitq_extract_vlan_tag - Extract vlan tag from the descriptor
+ * @desc: Rx flex descriptor
+ * @rxq: rxq to check the vlan flags
+ * @vlan_tag: vlan tag to fill in
+ *
+ * Return true if error bit is set in the descriptor, else return false and
+ * store the vlan_tag in the variable passed in the function parameters
+ */
+bool iecm_rx_splitq_extract_vlan_tag(struct virtchnl2_rx_flex_desc_adv_nic_3 *desc,
+				     struct iecm_queue *rxq, u16 *vlan_tag)
+{
+	u8 stat_err0_qw0, stat_err_bits, stat_err1;
+
+	stat_err_bits = BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_RXE_S);
+	stat_err0_qw0 = desc->status_err0_qw0;
+	if (unlikely(iecm_rx_splitq_test_staterr(stat_err0_qw0, stat_err_bits)))
+		return true;
+
+	stat_err1 = desc->status_err1;
+
+	if (stat_err0_qw0 & BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_L2TAG1P_S) &&
+	    test_bit(__IECM_Q_VLAN_TAG_LOC_L2TAG1, rxq->flags))
+		*vlan_tag = le16_to_cpu(desc->l2tag1);
+	if (stat_err1 & BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS1_L2TAG2P_S) &&
+	    test_bit(__IECM_Q_VLAN_TAG_LOC_L2TAG2, rxq->flags))
+		*vlan_tag = le16_to_cpu(desc->l2tag2);
+
+	return false;
+}
+
+/**
+ * iecm_rx_splitq_is_non_eop - process handling of non-EOP buffers
+ * @rx_desc: Rx descriptor for current buffer
+ *
+ * If the buffer is an EOP buffer, this function exits returning false,
+ * otherwise return true indicating that this is in fact a non-EOP buffer.
+ */
+static bool
+iecm_rx_splitq_is_non_eop(struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc)
+{
+	/* if we are the last buffer then there is nothing else to do */
+#define IECM_RXD_EOF BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_EOF_S)
+	if (likely(iecm_rx_splitq_test_staterr(rx_desc->status_err0_qw1,
+					       IECM_RXD_EOF)))
+		return false;
+
+	return true;
+}
+
+/**
+ * iecm_rx_splitq_recycle_buf - Attempt to recycle or realloc buffer
+ * @rxbufq: receive queue
+ * @rx_buf: Rx buffer to pull data from
+ *
+ * This function will clean up the contents of the rx_buf. It will either
+ * recycle the buffer or unmap it and free the associated resources. The buffer
+ * will then be placed on a refillq where it will later be reclaimed by the
+ * corresponding bufq.
+ *
+ * This works based on page flipping. If we assume e.g., a 4k page, it will be
+ * divided into two 2k buffers. We post the first half to hardware and, after
+ * using it, flip to second half of the page with iecm_adjust_pg_offset and
+ * post that to hardware. The third time through we'll flip back to first half
+ * of page and check if stack is still using it, if not we can reuse the buffer
+ * as is, otherwise we'll drain it and get a new page.
+ */
+static void iecm_rx_splitq_recycle_buf(struct iecm_queue *rxbufq,
+				       struct iecm_rx_buf *rx_buf)
+{
+	struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf->page_indx];
+
+	if (!iecm_rx_can_reuse_page(rx_buf)) {
+		/* we are not reusing the buffer so unmap it */
+		dma_unmap_page_attrs(rxbufq->dev, page_info->dma, PAGE_SIZE,
+				     DMA_FROM_DEVICE, IECM_RX_DMA_ATTR);
+		__page_frag_cache_drain(page_info->page,
+					page_info->pagecnt_bias);
+
+		/* clear contents of buffer_info */
+		page_info->page = NULL;
+		rx_buf->skb = NULL;
+
+		/* It's possible the alloc can fail here but there's not much
+		 * we can do, bufq will have to try and realloc to fill the
+		 * hole.
+		 */
+		iecm_alloc_page(rxbufq, page_info);
+	}
+
+	/* We sync the memory back to hardware now to do as much work in this
+	 * context as feasible.  Hardware won't actually know about the buffer
+	 * until it's reclaimed off the refillq and put back into the bufq.
+	 */
+	if (likely(page_info->page)) {
+		dma_sync_single_range_for_device(rxbufq->dev, page_info->dma,
+						 page_info->page_offset,
+						 rxbufq->rx_buf_size,
+						 DMA_FROM_DEVICE);
+	}
+}
+
+/**
+ * iecm_rx_bump_ntc - Bump and wrap q->next_to_clean value
+ * @q: queue to bump
+ */
+void iecm_rx_bump_ntc(struct iecm_queue *q)
+{
+	u16 ntc = q->next_to_clean + 1;
+	/* fetch, update, and store next to clean */
+	if (ntc < q->desc_count) {
+		q->next_to_clean = ntc;
+	} else {
+		q->next_to_clean = 0;
+		change_bit(__IECM_Q_GEN_CHK, q->flags);
+	}
+}
+
+/**
+ * iecm_rx_splitq_clean - Clean completed descriptors from Rx queue
+ * @rxq: Rx descriptor queue to retrieve receive buffer queue
+ * @budget: Total limit on number of packets to process
+ *
+ * This function provides a "bounce buffer" approach to Rx interrupt
+ * processing. The advantage to this is that on systems that have
+ * expensive overhead for IOMMU access this provides a means of avoiding
+ * it by maintaining the mapping of the page to the system.
+ *
+ * Returns amount of work completed
+ */
+static int iecm_rx_splitq_clean(struct iecm_queue *rxq, int budget)
+{
+	int total_rx_bytes = 0, total_rx_pkts = 0;
+	struct iecm_queue *rx_bufq = NULL;
+	struct sk_buff *skb = rxq->skb;
+	bool failure = false;
+
+	/* Process Rx packets bounded by budget */
+	while (likely(total_rx_pkts < budget)) {
+		struct virtchnl2_rx_flex_desc_adv_nic_3 *splitq_flex_rx_desc;
+		struct iecm_sw_queue *refillq = NULL;
+		struct iecm_dma_mem *hdr_buf = NULL;
+		struct iecm_rxq_set *rxq_set = NULL;
+		struct iecm_rx_buf *rx_buf = NULL;
+		u16 gen_id, buf_id, vlan_tag = 0;
+		union virtchnl2_rx_desc *rx_desc;
+		unsigned int pkt_len = 0;
+		unsigned int hdr_len = 0;
+		 /* Header buffer overflow only valid for header split */
+		bool hbo = false;
+		int bufq_id;
+
+		/* get the Rx desc from Rx queue based on 'next_to_clean' */
+		rx_desc = IECM_RX_DESC(rxq, rxq->next_to_clean);
+		splitq_flex_rx_desc = (struct virtchnl2_rx_flex_desc_adv_nic_3 *)rx_desc;
+
+		/* This memory barrier is needed to keep us from reading
+		 * any other fields out of the rx_desc
+		 */
+		dma_rmb();
+
+		/* if the descriptor isn't done, no work yet to do */
+		gen_id = le16_to_cpu(splitq_flex_rx_desc->pktlen_gen_bufq_id);
+		gen_id = (gen_id & VIRTCHNL2_RX_FLEX_DESC_ADV_GEN_M) >>
+						VIRTCHNL2_RX_FLEX_DESC_ADV_GEN_S;
+		if (test_bit(__IECM_Q_GEN_CHK, rxq->flags) != gen_id)
+			break;
+
+		if ((splitq_flex_rx_desc->rxdid_ucast &
+		    VIRTCHNL2_RX_FLEX_DESC_ADV_RXDID_M) != VIRTCHNL2_RXDID_1_FLEX_SPLITQ) {
+			iecm_rx_bump_ntc(rxq);
+			rxq->vport->port_stats.rx_bad_descs++;
+			continue;
+		}
+
+		pkt_len = le16_to_cpu(splitq_flex_rx_desc->pktlen_gen_bufq_id) &
+			  VIRTCHNL2_RX_FLEX_DESC_ADV_LEN_PBUF_M;
+
+		hbo = splitq_flex_rx_desc->status_err0_qw1 &
+		      BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_HBO_S);
+
+		if (unlikely(hbo)) {
+			rxq->vport->port_stats.rx_hsplit_hbo++;
+			goto bypass_hsplit;
+		}
+
+		hdr_len =
+			le16_to_cpu(splitq_flex_rx_desc->hdrlen_flags) &
+			VIRTCHNL2_RX_FLEX_DESC_ADV_LEN_HDR_M;
+
+bypass_hsplit:
+		bufq_id = le16_to_cpu(splitq_flex_rx_desc->pktlen_gen_bufq_id);
+		bufq_id = (bufq_id & VIRTCHNL2_RX_FLEX_DESC_ADV_BUFQ_ID_M) >>
+			  VIRTCHNL2_RX_FLEX_DESC_ADV_BUFQ_ID_S;
+
+		rxq_set = container_of(rxq, struct iecm_rxq_set, rxq);
+		if (!bufq_id)
+			refillq = rxq_set->refillq0;
+		else
+			refillq = rxq_set->refillq1;
+
+		/* retrieve buffer from the rxq */
+		rx_bufq = &rxq->rxq_grp->splitq.bufq_sets[bufq_id].bufq;
+
+		buf_id = le16_to_cpu(splitq_flex_rx_desc->buf_id);
+
+		if (pkt_len) {
+			rx_buf = &rx_bufq->rx_buf.buf[buf_id];
+			iecm_rx_get_buf_page(rx_bufq->dev, rx_buf, pkt_len);
+		}
+
+		if (hdr_len) {
+			hdr_buf = rx_bufq->rx_buf.hdr_buf[buf_id];
+
+			dma_sync_single_for_cpu(rxq->dev, hdr_buf->pa, hdr_buf->size,
+						DMA_FROM_DEVICE);
+
+			skb = iecm_rx_hdr_construct_skb(rxq, hdr_buf, hdr_len);
+			rxq->vport->port_stats.rx_hsplit++;
+		}
+
+		if (pkt_len) {
+			if (skb)
+				iecm_rx_add_frag(rx_buf, skb, pkt_len);
+			else
+				skb = iecm_rx_construct_skb(rxq, rx_buf,
+							    pkt_len);
+		}
+
+		/* exit if we failed to retrieve a buffer */
+		if (!skb) {
+			/* If we fetched a buffer, but didn't use it
+			 * undo pagecnt_bias decrement
+			 */
+			if (rx_buf)
+				rx_buf->page_info[rx_buf->page_indx].pagecnt_bias++;
+			break;
+		}
+
+		if (rx_buf)
+			iecm_rx_splitq_recycle_buf(rx_bufq, rx_buf);
+		iecm_rx_post_buf_refill(refillq, buf_id);
+
+		iecm_rx_bump_ntc(rxq);
+		/* skip if it is non EOP desc */
+		if (iecm_rx_splitq_is_non_eop(splitq_flex_rx_desc))
+			continue;
+
+		/* extract vlan tag from the descriptor */
+		if (unlikely(iecm_rx_splitq_extract_vlan_tag(splitq_flex_rx_desc,
+							     rxq, &vlan_tag))) {
+			dev_kfree_skb_any(skb);
+			skb = NULL;
+			continue;
+		}
+
+		/* pad skb if needed (to make valid ethernet frame) */
+		if (eth_skb_pad(skb)) {
+			skb = NULL;
+			continue;
+		}
+
+		/* probably a little skewed due to removing CRC */
+		total_rx_bytes += skb->len;
+
+		/* protocol */
+		if (unlikely(iecm_rx_process_skb_fields(rxq, skb,
+							splitq_flex_rx_desc))) {
+			dev_kfree_skb_any(skb);
+			skb = NULL;
+			continue;
+		}
+
+		/* send completed skb up the stack */
+		iecm_rx_skb(rxq, skb, vlan_tag);
+		skb = NULL;
+
+		/* update budget accounting */
+		total_rx_pkts++;
+	}
+	rxq->skb = skb;
+	u64_stats_update_begin(&rxq->stats_sync);
+	rxq->q_stats.rx.packets += total_rx_pkts;
+	rxq->q_stats.rx.bytes += total_rx_bytes;
+	u64_stats_update_end(&rxq->stats_sync);
+
+	/* guarantee a trip back through this routine if there was a failure */
+	return unlikely(failure) ? budget : total_rx_pkts;
+}
+
+/**
+ * iecm_rx_update_bufq_desc - Update buffer queue descriptor
+ * @bufq: Pointer to the buffer queue
+ * @desc: Refill queue descriptor
+ * @buf_desc: Buffer queue descriptor
+ *
+ * Return 0 on success and negative on failure.
+ */
+static int iecm_rx_update_bufq_desc(struct iecm_queue *bufq, u16 *desc,
+				    struct virtchnl2_splitq_rx_buf_desc *buf_desc)
+{
+	struct iecm_page_info *page_info;
+	struct iecm_rx_buf *buf;
+	u16 buf_id;
+
+	buf_id = ((*desc) & IECM_RX_BI_BUFID_M) >> IECM_RX_BI_BUFID_S;
+
+	buf = &bufq->rx_buf.buf[buf_id];
+	page_info = &buf->page_info[buf->page_indx];
+
+	/* It's possible page alloc failed during rxq clean, try to
+	 * recover here.
+	 */
+	if (unlikely(!page_info->page)) {
+		if (iecm_alloc_page(bufq, page_info))
+			return -ENOMEM;
+	}
+	buf_desc->pkt_addr = cpu_to_le64(page_info->dma + page_info->page_offset);
+	buf_desc->qword0.buf_id = cpu_to_le16(buf_id);
+
+	if (bufq->rx_hsplit_en) {
+		struct iecm_dma_mem *hdr_buf = bufq->rx_buf.hdr_buf[buf_id];
+
+		buf_desc->hdr_addr = cpu_to_le64(hdr_buf->pa);
+		dma_sync_single_for_device(bufq->dev, hdr_buf->pa,
+					   hdr_buf->size, DMA_FROM_DEVICE);
+	}
+
+	return 0;
+}
+
+/**
+ * iecm_rx_clean_refillq - Clean refill queue buffers
+ * @bufq: buffer queue to post buffers back to
+ * @refillq: refill queue to clean
+ *
+ * This function takes care of the buffer refill management
+ */
+static void iecm_rx_clean_refillq(struct iecm_queue *bufq,
+				  struct iecm_sw_queue *refillq)
+{
+	struct virtchnl2_splitq_rx_buf_desc *buf_desc;
+	u16 refillq_ntc = refillq->next_to_clean;
+	u16 bufq_nta = bufq->next_to_alloc;
+	u16 *refill_desc;
+	int cleaned = 0;
+	u16 gen;
+
+	refill_desc = IECM_SPLITQ_RX_BI_DESC(refillq, refillq_ntc);
+	buf_desc = IECM_SPLITQ_RX_BUF_DESC(bufq, bufq_nta);
+
+	/* make sure we stop at ring wrap in the unlikely case ring is full */
+	while (likely(cleaned < refillq->desc_count)) {
+		bool failure;
+
+		gen = ((*refill_desc) & IECM_RX_BI_GEN_M) >> IECM_RX_BI_GEN_S;
+		if (test_bit(__IECM_RFLQ_GEN_CHK, refillq->flags) != gen)
+			break;
+
+		failure = iecm_rx_update_bufq_desc(bufq, refill_desc,
+						   buf_desc);
+		if (failure)
+			break;
+
+		refillq_ntc++;
+		refill_desc++;
+		bufq_nta++;
+		buf_desc++;
+		cleaned++;
+
+		if (unlikely(refillq_ntc == refillq->desc_count)) {
+			change_bit(__IECM_RFLQ_GEN_CHK, refillq->flags);
+			refill_desc = IECM_SPLITQ_RX_BI_DESC(refillq, 0);
+			refillq_ntc = 0;
+		}
+		if (unlikely(bufq_nta == bufq->desc_count)) {
+			buf_desc = IECM_SPLITQ_RX_BUF_DESC(bufq, 0);
+			bufq_nta = 0;
+		}
+	}
+
+	if (cleaned) {
+		/* only update hardware tail in strides */
+		if (((bufq->next_to_use <= bufq_nta ? 0 : bufq->desc_count) +
+		    bufq_nta - bufq->next_to_use) >= bufq->rx_buf_stride)
+			iecm_rx_buf_hw_update(bufq, bufq_nta & ~(bufq->rx_buf_stride - 1));
+
+		/* update next to alloc since we have filled the ring */
+		refillq->next_to_clean = refillq_ntc;
+		bufq->next_to_alloc = bufq_nta;
+	}
+}
+
+/**
+ * iecm_rx_clean_refillq_all - Clean all refill queues
+ * @bufq: bufq with refillqs to clean
+ *
+ * Iterates through all refill queues assigned to the buffer queue assigned to
+ * this vector.  Returns true if clean is complete within budget, false
+ * otherwise.
+ */
+static void iecm_rx_clean_refillq_all(struct iecm_queue *bufq)
+{
+	struct iecm_bufq_set *bufq_set;
+	int i = 0;
+
+	bufq_set = container_of(bufq, struct iecm_bufq_set, bufq);
+	for (i = 0; i < bufq_set->num_refillqs; i++)
+		iecm_rx_clean_refillq(bufq, &bufq_set->refillqs[i]);
+}
+
 /**
  * iecm_vport_intr_clean_queues - MSIX mode Interrupt Handler
  * @irq: interrupt number
@@ -2742,6 +4122,64 @@ iecm_vport_intr_napi_ena_all(struct iecm_vport *vport)
 	}
 }
 
+/**
+ * iecm_tx_splitq_clean_all- Clean completetion queues
+ * @q_vec: queue vector
+ * @budget: Used to determine if we are in netpoll
+ *
+ * Returns false if clean is not complete else returns true
+ */
+static bool
+iecm_tx_splitq_clean_all(struct iecm_q_vector *q_vec, int budget)
+{
+	bool clean_complete = true;
+	int i, budget_per_q;
+
+	budget_per_q = max(budget / q_vec->num_txq, 1);
+	for (i = 0; i < q_vec->num_txq; i++) {
+		if (!iecm_tx_clean_complq(q_vec->tx[i], budget_per_q))
+			clean_complete = false;
+	}
+	return clean_complete;
+}
+
+/**
+ * iecm_rx_splitq_clean_all- Clean completetion queues
+ * @q_vec: queue vector
+ * @budget: Used to determine if we are in netpoll
+ * @cleaned: returns number of packets cleaned
+ *
+ * Returns false if clean is not complete else returns true
+ */
+static bool
+iecm_rx_splitq_clean_all(struct iecm_q_vector *q_vec, int budget,
+			 int *cleaned)
+{
+	bool clean_complete = true;
+	int pkts_cleaned = 0;
+	int i, budget_per_q;
+
+	budget_per_q = max(budget / q_vec->num_rxq, 1);
+	for (i = 0; i < q_vec->num_rxq; i++) {
+		struct iecm_queue *rxq = q_vec->rx[i];
+		int pkts_cleaned_per_q;
+
+		pkts_cleaned_per_q = iecm_rx_splitq_clean(rxq, budget_per_q);
+		/* if we clean as many as budgeted, we must not
+		 * be done
+		 */
+		if (pkts_cleaned_per_q >= budget_per_q)
+			clean_complete = false;
+		pkts_cleaned += pkts_cleaned_per_q;
+	}
+	*cleaned = pkts_cleaned;
+
+	for (i = 0; i < q_vec->num_bufq; i++)
+		iecm_rx_clean_refillq_all(q_vec->bufq[i]);
+
+	return clean_complete;
+}
+
 /**
  * iecm_vport_splitq_napi_poll - NAPI handler
  * @napi: struct from which you get q_vector
@@ -2749,8 +4187,34 @@ iecm_vport_intr_napi_ena_all(struct iecm_vport *vport)
  */
 static int iecm_vport_splitq_napi_poll(struct napi_struct *napi, int budget)
 {
-	/* stub */
-	return 0;
+	struct iecm_q_vector *q_vector =
+				container_of(napi, struct iecm_q_vector, napi);
+	bool clean_complete;
+	int work_done = 0;
+
+	clean_complete = iecm_tx_splitq_clean_all(q_vector, budget);
+
+	/* Handle case where we are called by netpoll with a budget of 0 */
+	if (budget <= 0)
+		return budget;
+
+	/* We attempt to distribute budget to each Rx queue fairly, but don't
+	 * allow the budget to go below 1 because that would exit polling early.
+	 */
+	clean_complete |= iecm_rx_splitq_clean_all(q_vector, budget,
+						   &work_done);
+
+	/* If work not completed, return budget and polling will return */
+	if (!clean_complete)
+		return budget;
+
+	/* Exit the polling mode, but don't re-enable interrupts if stack might
+	 * poll us due to busy-polling
+	 */
+	if (likely(napi_complete_done(napi, work_done)))
+		iecm_vport_intr_update_itr_ena_irq(q_vector);
+
+	return min_t(int, work_done, budget - 1);
 }
 
 /**
drivers/net/ethernet/intel/include/iecm.h +4 -0
index a655e797f457..3cf2a2f0cb0f 100644
@@ -12,6 +12,10 @@
 #include <linux/etherdevice.h>
 #include <linux/ethtool.h>
 #include <net/tcp.h>
+#include <net/ip6_checksum.h>
+#include <net/ipv6.h>
+#include <net/sch_generic.h>
+#include <net/gro.h>
 #include <linux/version.h>
 #include <linux/dim.h>
 
drivers/net/ethernet/intel/include/iecm_txrx.h +20 -0
index 7ec742fd4c6b..086b0efc989a 100644
@@ -638,6 +638,7 @@ 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);
 int iecm_vport_queues_alloc(struct iecm_vport *vport);
+void iecm_rx_post_buf_refill(struct iecm_sw_queue *refillq, u16 buf_id);
 void iecm_vport_queues_rel(struct iecm_vport *vport);
 void iecm_vport_calc_num_q_vec(struct iecm_vport *vport);
 void iecm_vport_intr_rel(struct iecm_vport *vport);
@@ -650,14 +651,33 @@ int iecm_vport_intr_init(struct iecm_vport *vport);
 irqreturn_t
 iecm_vport_intr_clean_queues(int __always_unused irq, void *data);
 void iecm_vport_intr_ena_irq_all(struct iecm_vport *vport);
+enum
+pkt_hash_types iecm_ptype_to_htype(struct iecm_rx_ptype_decoded *decoded);
 int iecm_config_rss(struct iecm_vport *vport);
 void iecm_fill_dflt_rss_lut(struct iecm_vport *vport);
 int iecm_init_rss(struct iecm_vport *vport);
 void iecm_deinit_rss(struct iecm_vport *vport);
+bool iecm_rx_can_reuse_page(struct iecm_rx_buf *rx_buf);
+void iecm_rx_buf_adjust_pg(struct iecm_rx_buf *rx_buf, unsigned int size);
+void iecm_rx_add_frag(struct iecm_rx_buf *rx_buf, struct sk_buff *skb,
+		      unsigned int size);
+struct sk_buff *iecm_rx_construct_skb(struct iecm_queue *rxq,
+				      struct iecm_rx_buf *rx_buf,
+				      unsigned int size);
+void iecm_rx_skb(struct iecm_queue *rxq, struct sk_buff *skb, u16 vlan_tag);
 bool iecm_init_rx_buf_hw_alloc(struct iecm_queue *rxq, struct iecm_rx_buf *buf);
 void iecm_rx_buf_hw_update(struct iecm_queue *rxq, u32 val);
 void iecm_tx_buf_hw_update(struct iecm_queue *tx_q, u32 val,
 			   bool xmit_more);
+void iecm_rx_splitq_put_bufs(struct iecm_queue *rx_bufq,
+			     struct iecm_rx_buf *hdr_buf,
+			     struct iecm_rx_buf *rx_buf);
+bool iecm_rx_splitq_test_staterr(u8 stat_err_field, const u8 stat_err_bits);
+int iecm_rx_process_skb_fields(struct iecm_queue *rxq, struct sk_buff *skb,
+			       struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc);
+bool iecm_rx_splitq_extract_vlan_tag(struct virtchnl2_rx_flex_desc_adv_nic_3 *desc,
+				     struct iecm_queue *rxq, u16 *vlan_tag);
+void iecm_rx_bump_ntc(struct iecm_queue *q);
 void iecm_tx_buf_rel(struct iecm_queue *tx_q, struct iecm_tx_buf *tx_buf);
 unsigned int iecm_size_to_txd_count(unsigned int size);
 unsigned int iecm_tx_desc_count_required(struct sk_buff *skb);
Signature · 1 line
2.33.0
#52 lore raw

[Intel-wired-lan] [PATCH net-next 13/19] iecm: implement splitq napi_poll

Thank you for the patch! Yet something to improve:

Hi Alan,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Alan-Brady/Add-iecm-and-idpf/20220128-085513
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git e2cf07654efb0fd7bbcb475c6f74be7b5755a8fd
config: arc-allyesconfig (https://download.01.org/0day-ci/archive/20220128/202201281316.ZdiaZw6q-lkp at intel.com/config)
compiler: arceb-elf-gcc (GCC) 11.2.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/8e9b2451747f81363327cf5a4e07aaf88af52397
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Alan-Brady/Add-iecm-and-idpf/20220128-085513
git checkout 8e9b2451747f81363327cf5a4e07aaf88af52397
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=arc SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

drivers/net/ethernet/intel/iecm/iecm_txrx.c: In function 'iecm_rx_can_reuse_page':

>> drivers/net/ethernet/intel/iecm/iecm_txrx.c:3132:19: error: 'struct iecm_rx_buf' has no member named 'page_offset'
    3132 |         if (rx_buf->page_offset > last_offset)
         |                   ^~

vim +3132 drivers/net/ethernet/intel/iecm/iecm_txrx.c

3103
3104 /**
3105 * iecm_rx_can_reuse_page - Determine if page can be reused for another rx
3106 * @rx_buf: buffer containing the page
3107 *
3108 * If page is reusable, we have a green light for calling iecm_reuse_rx_page,
3109 * which will assign the current buffer to the buffer that next_to_alloc is
3110 * pointing to; otherwise, the dma mapping needs to be destroyed and
3111 * page freed
3112 */
3113 bool iecm_rx_can_reuse_page(struct iecm_rx_buf *rx_buf)
3114 {
3115 struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf->page_indx];
3116
3117 #if (PAGE_SIZE >= 8192)
3118 unsigned int last_offset = PAGE_SIZE - rx_buf->buf_size;
3119 #endif /* PAGE_SIZE < 8192) */
3120 unsigned int pagecnt_bias = page_info->pagecnt_bias;
3121 struct page *page = page_info->page;
3122
3123 /* avoid re-using remote pages */
3124 if (unlikely(iecm_rx_page_is_reserved(page)))
3125 return false;
3126
3127 #if (PAGE_SIZE < 8192)
3128 /* if we are only owner of page we can reuse it */
3129 if (unlikely((page_count(page) - pagecnt_bias) > 1))
3130 return false;
3131 #else

> 3132		if (rx_buf->page_offset > last_offset)

3133 return false;
3134 #endif /* PAGE_SIZE < 8192) */
3135
3136 /* If we have drained the page fragment pool we need to update
3137 * the pagecnt_bias and page count so that we fully restock the
3138 * number of references the driver holds.
3139 */
3140 if (unlikely(pagecnt_bias == 1)) {
3141 page_ref_add(page, USHRT_MAX - 1);
3142 page_info->pagecnt_bias = USHRT_MAX;
3143 }
3144
3145 return true;
3146 }
3147

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all at lists.01.org

#53 lore raw

PATCH 13/19 iecm: implement splitq napi_poll

From: kernel test robot <[email protected]>
Date: Fri, 28 Jan 2022 13:21:42 +0800

Quoted 22 lines

Hi Alan,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Alan-Brady/Add-iecm-and-idpf/20220128-085513
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git e2cf07654efb0fd7bbcb475c6f74be7b5755a8fd
config: arc-allyesconfig (https://download.01.org/0day-ci/archive/20220128/202201281316.ZdiaZw6q-lkp at intel.com/config)
compiler: arceb-elf-gcc (GCC) 11.2.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/8e9b2451747f81363327cf5a4e07aaf88af52397
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Alan-Brady/Add-iecm-and-idpf/20220128-085513
git checkout 8e9b2451747f81363327cf5a4e07aaf88af52397
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=arc SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate

Quoted 8 lines

All errors (new ones prefixed by >>):

drivers/net/ethernet/intel/iecm/iecm_txrx.c: In function 'iecm_rx_can_reuse_page':

Quoted 1 line
Quoted 1 line

drivers/net/ethernet/intel/iecm/iecm_txrx.c:3132:19: error: 'struct iecm_rx_buf' has no member named 'page_offset'

    3132 |         if (rx_buf->page_offset > last_offset)
         |                   ^~

So these series wasn't even compile-tested properly. x86 has only 4k pages, but lots of other architectures have much more. If ARC is not relevant enough to MEV, then I say that ARM64 has 4-64 Kb pages, and PowerPC64 has up to 256 Kb.

Quoted 50 lines

vim +3132 drivers/net/ethernet/intel/iecm/iecm_txrx.c

3103
3104 /**
3105 * iecm_rx_can_reuse_page - Determine if page can be reused for another rx
3106 * @rx_buf: buffer containing the page
3107 *
3108 * If page is reusable, we have a green light for calling iecm_reuse_rx_page,
3109 * which will assign the current buffer to the buffer that next_to_alloc is
3110 * pointing to; otherwise, the dma mapping needs to be destroyed and
3111 * page freed
3112 */
3113 bool iecm_rx_can_reuse_page(struct iecm_rx_buf *rx_buf)
3114 {
3115 struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf->page_indx];
3116
3117 #if (PAGE_SIZE >= 8192)
3118 unsigned int last_offset = PAGE_SIZE - rx_buf->buf_size;
3119 #endif /* PAGE_SIZE < 8192) */
3120 unsigned int pagecnt_bias = page_info->pagecnt_bias;
3121 struct page *page = page_info->page;
3122
3123 /* avoid re-using remote pages */
3124 if (unlikely(iecm_rx_page_is_reserved(page)))
3125 return false;
3126
3127 #if (PAGE_SIZE < 8192)
3128 /* if we are only owner of page we can reuse it */
3129 if (unlikely((page_count(page) - pagecnt_bias) > 1))
3130 return false;
3131 #else

Quoted 1 line

3132 if (rx_buf->page_offset > last_offset)

3133 return false;
3134 #endif /* PAGE_SIZE < 8192) */
3135
3136 /* If we have drained the page fragment pool we need to update
3137 * the pagecnt_bias and page count so that we fully restock the
3138 * number of references the driver holds.
3139 */
3140 if (unlikely(pagecnt_bias == 1)) {
3141 page_ref_add(page, USHRT_MAX - 1);
3142 page_info->pagecnt_bias = USHRT_MAX;
3143 }
3144
3145 return true;
3146 }
3147

Quoted 3 lines

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all at lists.01.org

Al

#54 lore raw

PATCH 13/19 iecm: implement splitq napi_poll

Quoted 51 lines

-----Original Message-----
From: Lobakin, Alexandr <[email protected]>
Sent: Friday, January 28, 2022 9:44 AM
To: Brady, Alan <[email protected]>
Cc: Lobakin, Alexandr <[email protected]>; lkp <[email protected]>; intel-wired-lan at lists.osuosl.org; Burra, Phani R <[email protected]>; Chittim, Madhu <[email protected]>; kbuild-all at lists.01.org; Linga, Pavan Kumar <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net-next 13/19] iecm: implement splitq napi_poll

From: kernel test robot <[email protected]>
Date: Fri, 28 Jan 2022 13:21:42 +0800

Quoted 7 lines

Hi Alan,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net-next/master]

url: https://github.com/0day-ci/linux/commits/Alan-Brady/Add-iecm-and-

idpf/20220128-085513

Quoted 1 line

base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git

e2cf07654efb0fd7bbcb475c6f74be7b5755a8fd

Quoted 6 lines

config: arc-allyesconfig
(https://download.01.org/0day-ci/archive/20220128/202201281316.ZdiaZw6
q-lkp at intel.com/config)
compiler: arceb-elf-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-

tests/master/sbin/make.cross -O ~/bin/make.cross

Quoted 2 lines

chmod +x ~/bin/make.cross
# https://github.com/0day-

ci/linux/commit/8e9b2451747f81363327cf5a4e07aaf88af52397

Quoted 2 lines

git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Alan-Brady/Add-iecm-and-idpf/20220128-

085513

Quoted 4 lines
        git checkout 8e9b2451747f81363327cf5a4e07aaf88af52397
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0
Quoted 8 lines

make.cross O=build_dir ARCH=arc SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

drivers/net/ethernet/intel/iecm/iecm_txrx.c: In function

'iecm_rx_can_reuse_page':

Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/net/ethernet/intel/iecm/iecm_txrx.c:3132:19: error: 'struct

Quoted 9 lines

iecm_rx_buf' has no member named 'page_offset'

Quoted 2 lines
    3132 |         if (rx_buf->page_offset > last_offset)
         |                   ^~

So these series wasn't even compile-tested properly.
x86 has only 4k pages, but lots of other architectures have much more. If ARC is not relevant enough to MEV, then I say that
ARM64 has 4-64 Kb pages, and PowerPC64 has up to 256 Kb.

It definitely was compile tested, but juggling around 30k lines of code gets tricky and a mistake or two was inevitable. This should be a trivial fix.

Quoted 59 lines
Quoted 7 lines

vim +3132 drivers/net/ethernet/intel/iecm/iecm_txrx.c

3103
3104 /**
3105 * iecm_rx_can_reuse_page - Determine if page can be reused for

another rx

Quoted 3 lines

3106 * @rx_buf: buffer containing the page
3107 *
3108 * If page is reusable, we have a green light for calling

iecm_reuse_rx_page,

Quoted 24 lines

3109 * which will assign the current buffer to the buffer that next_to_alloc is
3110 * pointing to; otherwise, the dma mapping needs to be destroyed and
3111 * page freed
3112 */
3113 bool iecm_rx_can_reuse_page(struct iecm_rx_buf *rx_buf)
3114 {
3115 struct iecm_page_info *page_info = &rx_buf-
page_info[rx_buf->page_indx];
3116
3117 #if (PAGE_SIZE >= 8192)
3118 unsigned int last_offset = PAGE_SIZE - rx_buf->buf_size;
3119 #endif /* PAGE_SIZE < 8192) */
3120 unsigned int pagecnt_bias = page_info->pagecnt_bias;
3121 struct page *page = page_info->page;
3122
3123 /* avoid re-using remote pages */
3124 if (unlikely(iecm_rx_page_is_reserved(page)))
3125 return false;
3126
3127 #if (PAGE_SIZE < 8192)
3128 /* if we are only owner of page we can reuse it */
3129 if (unlikely((page_count(page) - pagecnt_bias) > 1))
3130 return false;
3131 #else

Quoted 5 lines
Quoted 1 line

3132 if (rx_buf->page_offset > last_offset)

3133 return false;
3134 #endif /* PAGE_SIZE < 8192) */
3135
3136 /* If we have drained the page fragment pool we need to

update

Quoted 12 lines
  3137		 * the pagecnt_bias and page count so that we fully restock the
  3138		 * number of references the driver holds.
  3139		 */
  3140		if (unlikely(pagecnt_bias == 1)) {
  3141			page_ref_add(page, USHRT_MAX - 1);
  3142			page_info->pagecnt_bias = USHRT_MAX;
  3143		}
  3144
  3145		return true;
  3146	}
  3147
Quoted 3 lines

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all at lists.01.org

Al

#55 lore raw

PATCH 13/19 iecm: implement splitq napi_poll

In reply to Alan Brady

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

Quoted 27 lines

This adds everything we need to actually receive packets and process spent buffers using the splitq model. This contrasts to more traditional queueing models by essentially splitting a normal queue of descriptors and mapped buffers into separate queues. This allows us to deal with both more efficiently and also allows us to implement asymmetric queuing setups where you have multiple completion queues associated with a single buffer queue.

---
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   | 1468 ++++++++++++++++-
 drivers/net/ethernet/intel/include/iecm.h     |    4 +
 .../net/ethernet/intel/include/iecm_txrx.h    |   20 +
 3 files changed, 1490 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
index 4b9288e1c254..85a82b58525a 100644
@@ -218,6 +218,36 @@ const struct iecm_rx_ptype_decoded iecm_ptype_lookup[IECM_RX_MAX_PTYPE] = {
 };
 EXPORT_SYMBOL(iecm_ptype_lookup);
 
+/**

drivers/net/ethernet/intel/iecm/iecm_txrx.c const struct iecm_rx_ptype_decoded iecm_ptype_lookup[IECM_RX_MAX_PTYPE] = { · line 231

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+ * iecm_buf_lifo_push - push a buffer pointer onto stack
+ * @stack: pointer to stack struct
+ * @buf: pointer to buf to push
+ *
+ * Returns 0 on success, negative on failure
+ **/
+static int iecm_buf_lifo_push(struct iecm_buf_lifo *stack,
+			      struct iecm_tx_buf *buf)
+{
+	if (stack->top == stack->size)

How frequent is this? A candidate for unlikely() maybe?

Quoted 31 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +24 -0
+		return -ENOSPC;
+
+	stack->bufs[stack->top++] = buf;
+
+	return 0;
+}
+
+/**
+ * iecm_buf_lifo_pop - pop a buffer pointer from stack
+ * @stack: pointer to stack struct
+ **/
+static struct iecm_tx_buf *iecm_buf_lifo_pop(struct iecm_buf_lifo *stack)
+{
+	if (!stack->top)
+		return NULL;
+
+	return stack->bufs[--stack->top];
+}
+
 /**
  * iecm_get_stats64 - get statistics for network device structure
  * @netdev: network interface device structure
@@ -812,6 +842,30 @@ iecm_rx_buf_hw_alloc_all(struct iecm_queue *rxbufq, u16 alloc_count)
 	return !!alloc_count;
 }
 
+/**
+ * iecm_rx_post_buf_refill - Post buffer id to refill queue
+ * @refillq: refill queue to post to
+ * @buf_id: buffer id to post
+ */

drivers/net/ethernet/intel/iecm/iecm_txrx.c iecm_rx_buf_hw_alloc_all(struct iecm_queue *rxbufq, u16 alloc_count) · line 859

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+void iecm_rx_post_buf_refill(struct iecm_sw_queue *refillq, u16 buf_id)
+{
+	u16 nta = refillq->next_to_alloc;
+	u16 *bi;
+
+	bi = IECM_SPLITQ_RX_BI_DESC(refillq, nta);
+	/* store the buffer ID and the SW maintained GEN bit to the refillq */
+	*bi = ((buf_id << IECM_RX_BI_BUFID_S) & IECM_RX_BI_BUFID_M) |
+	      (!!(test_bit(__IECM_Q_GEN_CHK, refillq->flags)) <<
+	       IECM_RX_BI_GEN_S);

Please use FIELD_GET() and FIELD_PREP() for masks. This won't pass the maintainers.

drivers/net/ethernet/intel/iecm/iecm_txrx.c iecm_rx_buf_hw_alloc_all(struct iecm_queue *rxbufq, u16 alloc_count) · line 862

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
+
+	nta++;
+	if (unlikely(nta == refillq->desc_count)) {

Could be compressed into one line.

Quoted 21 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +14 -0
+		nta = 0;
+		change_bit(__IECM_Q_GEN_CHK, refillq->flags);
+	}
+	refillq->next_to_alloc = nta;
+}
+
 /**
  * iecm_rx_post_buf_desc - Post buffer to bufq descriptor ring
  * @bufq: buffer queue to post to
@@ -1670,6 +1724,398 @@ int iecm_vport_queues_alloc(struct iecm_vport *vport)
 	return err;
 }
 
+/**
+ * iecm_tx_find_q - Find the tx q based on q id
+ * @vport: the vport we care about
+ * @q_id: Id of the queue
+ *
+ * Returns queue ptr if found else returns NULL
+ */
+static struct iecm_queue *

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 1744

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+iecm_tx_find_q(struct iecm_vport *vport, int q_id)
+{
+	int i;
+
+	for (i = 0; i < vport->num_txq; i++) {
+		struct iecm_queue *tx_q = vport->txqs[i];
+
+		if (tx_q->q_id == q_id)
+			return tx_q;
+	}
	for (i = ...)
		if (vport->txqs[i].q_id == q_id)
			return tx_q;

No need to create a variable.

Quoted 31 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +31 -0
+
+	return NULL;
+}
+
+/**
+ * iecm_tx_handle_sw_marker - Handle queue marker packet
+ * @tx_q: tx queue to handle software marker
+ */
+static void iecm_tx_handle_sw_marker(struct iecm_queue *tx_q)
+{
+	struct iecm_vport *vport = tx_q->vport;
+	bool drain_complete = true;
+	int i;
+
+	clear_bit(__IECM_Q_SW_MARKER, tx_q->flags);
+	/* Hardware must write marker packets to all queues associated with
+	 * completion queues. So check if all queues received marker packets
+	 */
+	for (i = 0; i < vport->num_txq; i++) {
+		if (test_bit(__IECM_Q_SW_MARKER, vport->txqs[i]->flags))
+			drain_complete = false;
+	}
+	if (drain_complete) {
+		set_bit(__IECM_SW_MARKER, vport->adapter->flags);
+		wake_up(&vport->adapter->sw_marker_wq);
+	}
+}
+
+/**
+ * iecm_tx_splitq_clean_buf - Clean TX buffer resources
+ * @tx_q: tx queue to clean buffer from

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 1785

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+ * @tx_buf: buffer to be cleaned
+ * @napi_budget: Used to determine if we are in netpoll
+ */
+static void
+iecm_tx_splitq_clean_buf(struct iecm_queue *tx_q, struct iecm_tx_buf *tx_buf,
+			 int napi_budget)
+{
+	/* unmap skb header data */
+	dma_unmap_single(tx_q->dev,
+			 dma_unmap_addr(tx_buf, dma),

These two lines can fit into 79 without wrapping.

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 1787

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +2 -0
+			 dma_unmap_len(tx_buf, len),
+			 DMA_TO_DEVICE);

These two as well.

Quoted 99 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +99 -0
+
+	napi_consume_skb(tx_buf->skb, napi_budget);
+
+	/* clear tx_buf data */
+	tx_buf->skb = NULL;
+	dma_unmap_len_set(tx_buf, len, 0);
+}
+
+/**
+ * iecm_stash_flow_sch_buffers - store buffere parameter info to be freed at a
+ * later time (only relevant for flow scheduling mode)
+ * @txq: Tx queue to clean
+ * @tx_buf: buffer to store
+ */
+static int
+iecm_stash_flow_sch_buffers(struct iecm_queue *txq, struct iecm_tx_buf *tx_buf)
+{
+	struct iecm_adapter *adapter = txq->vport->adapter;
+	struct iecm_tx_buf *shadow_buf;
+
+	shadow_buf = iecm_buf_lifo_pop(&txq->buf_stack);
+	if (!shadow_buf) {
+		dev_err(&adapter->pdev->dev,
+			"No out-of-order TX buffers left!\n");
+		return -ENOMEM;
+	}
+
+	/* Store buffer params in shadow buffer */
+	shadow_buf->skb = tx_buf->skb;
+	shadow_buf->bytecount = tx_buf->bytecount;
+	shadow_buf->gso_segs = tx_buf->gso_segs;
+	dma_unmap_addr_set(shadow_buf, dma, dma_unmap_addr(tx_buf, dma));
+	dma_unmap_len_set(shadow_buf, len, dma_unmap_len(tx_buf, len));
+	shadow_buf->compl_tag = tx_buf->compl_tag;
+
+	/* Add buffer to buf_hash table to be freed
+	 * later
+	 */
+	hash_add(txq->sched_buf_hash, &shadow_buf->hlist,
+		 shadow_buf->compl_tag);
+
+	memset(tx_buf, 0, sizeof(struct iecm_tx_buf));
+
+	return 0;
+}
+
+/**
+ * iecm_tx_splitq_clean - Reclaim resources from buffer queue
+ * @tx_q: Tx queue to clean
+ * @end: queue index until which it should be cleaned
+ * @napi_budget: Used to determine if we are in netpoll
+ * @descs_only: true if queue is using flow-based scheduling and should
+ * not clean buffers at this time
+ *
+ * Cleans the queue descriptor ring. If the queue is using queue-based
+ * scheduling, the buffers will be cleaned as well and this function will
+ * return the number of bytes/packets cleaned. If the queue is using flow-based
+ * scheduling, only the descriptors are cleaned at this time. Separate packet
+ * completion events will be reported on the completion queue, and the buffers
+ * will be cleaned separately. The stats returned from this function when using
+ * flow-based scheduling are irrelevant.
+ */
+static struct iecm_tx_queue_stats
+iecm_tx_splitq_clean(struct iecm_queue *tx_q, u16 end, int napi_budget,
+		     bool descs_only)
+{
+	union iecm_tx_flex_desc *next_pending_desc = NULL;
+	struct iecm_tx_queue_stats cleaned_stats = {0};
+	union iecm_tx_flex_desc *tx_desc;
+	s16 ntc = tx_q->next_to_clean;
+	struct iecm_tx_buf *tx_buf;
+	unsigned short gso_segs = 0;
+	unsigned int bytecount = 0;
+	struct netdev_queue *nq;
+
+	tx_desc = IECM_FLEX_TX_DESC(tx_q, ntc);
+	next_pending_desc = IECM_FLEX_TX_DESC(tx_q, end);
+	tx_buf = &tx_q->tx_buf[ntc];
+	ntc -= tx_q->desc_count;
+
+	while (tx_desc != next_pending_desc) {
+		union iecm_tx_flex_desc *eop_desc =
+			(union iecm_tx_flex_desc *)tx_buf->next_to_watch;
+
+		/* clear next_to_watch to prevent false hangs */
+		tx_buf->next_to_watch = NULL;
+
+		bytecount += tx_buf->bytecount;
+		gso_segs += tx_buf->gso_segs;
+
+		if (descs_only) {
+			if (iecm_stash_flow_sch_buffers(tx_q, tx_buf))
+				goto tx_splitq_clean_out;
+
+			while (tx_desc != eop_desc) {
+				tx_buf++;
+				tx_desc++;
+				ntc++;
+				if (unlikely(!ntc)) {

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 1896

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+					ntc -= tx_q->desc_count;
+					tx_buf = tx_q->tx_buf;
+					tx_desc = IECM_FLEX_TX_DESC(tx_q, 0);
+				}
+
+				if (dma_unmap_len(tx_buf, len)) {
+					if (iecm_stash_flow_sch_buffers(tx_q,
+									tx_buf))
+						goto tx_splitq_clean_out;
+				}

Redundant braces, redundant nested ifs.

Also, it's actually an error, since dma_unmap_len() always equals 0 for architectures which don't select NEED_DMA_MAP_STATE. So this should either check for any other signs of mapped buffer or field len should be present and defined with correct values unconditionally.

Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +11 -0
+			}
+		} else {
+			/* update the statistics for this packet */
+			cleaned_stats.bytes += tx_buf->bytecount;
+			cleaned_stats.packets += tx_buf->gso_segs;
+
+			iecm_tx_splitq_clean_buf(tx_q, tx_buf, napi_budget);
+
+			/* unmap remaining buffers */
+			while (tx_desc != eop_desc) {
+				tx_buf++;

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 1917

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+				tx_desc++;
+				ntc++;
+				if (unlikely(!ntc)) {
+					ntc -= tx_q->desc_count;
+					tx_buf = tx_q->tx_buf;
+					tx_desc = IECM_FLEX_TX_DESC(tx_q, 0);
+				}
+
+				/* unmap any remaining paged data */
+				if (dma_unmap_len(tx_buf, len)) {

Same here.

Quoted 47 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +47 -0
+					dma_unmap_page(tx_q->dev,
+						       dma_unmap_addr(tx_buf, dma),
+						       dma_unmap_len(tx_buf, len),
+						       DMA_TO_DEVICE);
+					dma_unmap_len_set(tx_buf, len, 0);
+				}
+			}
+		}
+
+		tx_buf++;
+		tx_desc++;
+		ntc++;
+		if (unlikely(!ntc)) {
+			ntc -= tx_q->desc_count;
+			tx_buf = tx_q->tx_buf;
+			tx_desc = IECM_FLEX_TX_DESC(tx_q, 0);
+		}
+	}
+
+tx_splitq_clean_out:
+	ntc += tx_q->desc_count;
+	tx_q->next_to_clean = ntc;
+
+	nq = netdev_get_tx_queue(tx_q->vport->netdev, tx_q->idx);
+	netdev_tx_completed_queue(nq, gso_segs, bytecount);
+
+	return cleaned_stats;
+}
+
+/**
+ * iecm_tx_clean_flow_sch_bufs - clean bufs that were stored for
+ * out of order completions
+ * @txq: queue to clean
+ * @compl_tag: completion tag of packet to clean (from completion descriptor)
+ * @budget: Used to determine if we are in netpoll
+ */
+static struct iecm_tx_queue_stats
+iecm_tx_clean_flow_sch_bufs(struct iecm_queue *txq, u16 compl_tag,
+			    int budget)
+{
+	struct iecm_tx_queue_stats cleaned_stats = {0};
+	struct hlist_node *tmp_buf = NULL;
+	struct iecm_tx_buf *tx_buf = NULL;
+
+	/* Buffer completion */
+	hash_for_each_possible_safe(txq->sched_buf_hash, tx_buf, tmp_buf,
+				    hlist, compl_tag) {

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 1974

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+		if (tx_buf->compl_tag != compl_tag)
+			continue;
+
+		if (likely(tx_buf->skb)) {
+			/* update the statistics for this packet */
+			cleaned_stats.bytes += tx_buf->bytecount;
+			cleaned_stats.packets += tx_buf->gso_segs;
+
+			iecm_tx_splitq_clean_buf(txq, tx_buf, budget);
+		} else if (dma_unmap_len(tx_buf, len)) {

Here as well.

Quoted 36 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +36 -0
+			dma_unmap_page(txq->dev,
+				       dma_unmap_addr(tx_buf, dma),
+				       dma_unmap_len(tx_buf, len),
+				       DMA_TO_DEVICE);
+			dma_unmap_len_set(tx_buf, len, 0);
+		}
+		/* Push shadow buf back onto stack */
+		iecm_buf_lifo_push(&txq->buf_stack, tx_buf);
+
+		hash_del(&tx_buf->hlist);
+	}
+
+	return cleaned_stats;
+}
+
+/**
+ * iecm_tx_clean_complq - Reclaim resources on completion queue
+ * @complq: Tx ring to clean
+ * @budget: Used to determine if we are in netpoll
+ *
+ * Returns true if there's any budget left (e.g. the clean is finished)
+ */
+static bool
+iecm_tx_clean_complq(struct iecm_queue *complq, int budget)
+{
+	struct iecm_splitq_tx_compl_desc *tx_desc;
+	struct iecm_vport *vport = complq->vport;
+	s16 ntc = complq->next_to_clean;
+	bool clean_completed = false;
+	unsigned int complq_budget;
+
+	complq_budget = vport->compln_clean_budget;
+	tx_desc = IECM_SPLITQ_TX_COMPLQ_DESC(complq, ntc);
+	ntc -= complq->desc_count;
+
+	do {

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 2020

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+		struct iecm_tx_queue_stats cleaned_stats = {0};
+		struct iecm_queue *tx_q;
+		u16 compl_tag, hw_head;
+		int tx_qid;
+		u8 ctype;	/* completion type */
+		u16 gen;
+
+		/* if the descriptor isn't done, no work yet to do */
+		gen = (le16_to_cpu(tx_desc->qid_comptype_gen) &
+		      IECM_TXD_COMPLQ_GEN_M) >> IECM_TXD_COMPLQ_GEN_S;

Same stuff about FIELD_{GET,PREP}().

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 2026

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+		if (test_bit(__IECM_Q_GEN_CHK, complq->flags) != gen)
+			break;
+
+		/* Find necessary info of TX queue to clean buffers */
+		tx_qid = (le16_to_cpu(tx_desc->qid_comptype_gen) &
+			 IECM_TXD_COMPLQ_QID_M) >> IECM_TXD_COMPLQ_QID_S;

Here as well, and in other places I missed.

Quoted 329 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +322 -0
+		tx_q = iecm_tx_find_q(vport, tx_qid);
+		if (!tx_q) {
+			dev_err(&complq->vport->adapter->pdev->dev,
+				"TxQ #%d not found\n", tx_qid);
+			goto fetch_next_desc;
+		}
+
+		/* Determine completion type */
+		ctype = (le16_to_cpu(tx_desc->qid_comptype_gen) &
+			IECM_TXD_COMPLQ_COMPL_TYPE_M) >>
+			IECM_TXD_COMPLQ_COMPL_TYPE_S;
+		switch (ctype) {
+		case IECM_TXD_COMPLT_RE:
+			hw_head = le16_to_cpu(tx_desc->q_head_compl_tag.q_head);
+
+			cleaned_stats = iecm_tx_splitq_clean(tx_q, hw_head,
+							     budget, true);
+			break;
+		case IECM_TXD_COMPLT_RS:
+			if (test_bit(__IECM_Q_FLOW_SCH_EN, tx_q->flags)) {
+				compl_tag =
+				le16_to_cpu(tx_desc->q_head_compl_tag.compl_tag);
+
+				cleaned_stats =
+					iecm_tx_clean_flow_sch_bufs(tx_q,
+								    compl_tag,
+								    budget);
+			} else {
+				hw_head =
+				le16_to_cpu(tx_desc->q_head_compl_tag.q_head);
+
+				cleaned_stats = iecm_tx_splitq_clean(tx_q,
+								     hw_head,
+								     budget,
+								     false);
+			}
+
+			break;
+		case IECM_TXD_COMPLT_SW_MARKER:
+			iecm_tx_handle_sw_marker(tx_q);
+			break;
+		default:
+			dev_err(&tx_q->vport->adapter->pdev->dev,
+				"Unknown TX completion type: %d\n",
+				ctype);
+			goto fetch_next_desc;
+		}
+
+		u64_stats_update_begin(&tx_q->stats_sync);
+		tx_q->q_stats.tx.packets += cleaned_stats.packets;
+		tx_q->q_stats.tx.bytes += cleaned_stats.bytes;
+		u64_stats_update_end(&tx_q->stats_sync);
+
+		if (unlikely(cleaned_stats.packets &&
+			     netif_carrier_ok(tx_q->vport->netdev) &&
+			     (IECM_DESC_UNUSED(tx_q) >= IECM_TX_WAKE_THRESH) &&
+			     (IECM_TX_BUF_UNUSED(tx_q) >= tx_q->desc_count >> 2))) {
+			/* Make sure any other threads stopping queue after
+			 * this see new next_to_clean.
+			 */
+			smp_mb();
+			if (tx_q->vport->adapter->state == __IECM_UP &&
+			    __netif_subqueue_stopped(tx_q->vport->netdev,
+						     tx_q->idx)) {
+				netif_wake_subqueue(tx_q->vport->netdev,
+						    tx_q->idx);
+			}
+		}
+
+fetch_next_desc:
+		tx_desc++;
+		ntc++;
+		if (unlikely(!ntc)) {
+			ntc -= complq->desc_count;
+			tx_desc = IECM_SPLITQ_TX_COMPLQ_DESC(complq, 0);
+			change_bit(__IECM_Q_GEN_CHK, complq->flags);
+		}
+
+		prefetch(tx_desc);
+
+		/* update budget accounting */
+		complq_budget--;
+	} while (likely(complq_budget));
+
+	ntc += complq->desc_count;
+	complq->next_to_clean = ntc;
+
+	clean_completed = !!complq_budget;
+
+	return clean_completed;
+}
+
 /**
  * iecm_tx_splitq_build_ctb - populate command tag and size for queue
  * based scheduling descriptors
@@ -2337,6 +2783,940 @@ netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,
 	return iecm_tx_splitq_frame(skb, tx_q);
 }
 
+/**
+ * iecm_ptype_to_htype - get a hash type
+ * @decoded: Decoded Rx packet type related fields
+ *
+ * Returns appropriate hash type (such as PKT_HASH_TYPE_L2/L3/L4) to be used by
+ * skb_set_hash based on PTYPE as parsed by HW Rx pipeline and is part of
+ * Rx desc.
+ */
+enum
+pkt_hash_types iecm_ptype_to_htype(struct iecm_rx_ptype_decoded *decoded)
+{
+	if (!decoded->known)
+		return PKT_HASH_TYPE_NONE;
+	if (decoded->payload_layer == IECM_RX_PTYPE_PAYLOAD_LAYER_PAY2 &&
+	    decoded->inner_prot)
+		return PKT_HASH_TYPE_L4;
+	if (decoded->payload_layer == IECM_RX_PTYPE_PAYLOAD_LAYER_PAY2 &&
+	    decoded->outer_ip)
+		return PKT_HASH_TYPE_L3;
+	if (decoded->outer_ip == IECM_RX_PTYPE_OUTER_L2)
+		return PKT_HASH_TYPE_L2;
+
+	return PKT_HASH_TYPE_NONE;
+}
+
+/**
+ * iecm_rx_hash - set the hash value in the skb
+ * @rxq: Rx descriptor ring packet is being transacted on
+ * @skb: pointer to current skb being populated
+ * @rx_desc: Receive descriptor
+ * @decoded: Decoded Rx packet type related fields
+ */
+static void
+iecm_rx_hash(struct iecm_queue *rxq, struct sk_buff *skb,
+	     struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc,
+	     struct iecm_rx_ptype_decoded *decoded)
+{
+	u32 hash;
+
+	if (!iecm_is_feature_ena(rxq->vport, NETIF_F_RXHASH))
+		return;
+
+	hash = le16_to_cpu(rx_desc->hash1) |
+	       (rx_desc->ff2_mirrid_hash2.hash2 << 16) |
+	       (rx_desc->hash3 << 24);
+
+	skb_set_hash(skb, hash, iecm_ptype_to_htype(decoded));
+}
+
+/**
+ * iecm_rx_csum - Indicate in skb if checksum is good
+ * @rxq: Rx descriptor ring packet is being transacted on
+ * @skb: pointer to current skb being populated
+ * @csum_bits: checksum fields extracted from the descriptor
+ * @decoded: Decoded Rx packet type related fields
+ *
+ * skb->protocol must be set before this function is called
+ */
+static void iecm_rx_csum(struct iecm_queue *rxq, struct sk_buff *skb,
+			 struct iecm_rx_csum_decoded *csum_bits,
+			 struct iecm_rx_ptype_decoded *decoded)
+{
+	bool ipv4, ipv6;
+
+	/* Start with CHECKSUM_NONE and by default csum_level = 0 */
+	skb->ip_summed = CHECKSUM_NONE;
+
+	/* check if Rx checksum is enabled */
+	if (!iecm_is_feature_ena(rxq->vport, NETIF_F_RXCSUM))
+		return;
+
+	/* check if HW has decoded the packet and checksum */
+	if (!(csum_bits->l3l4p))
+		return;
+
+	ipv4 = (decoded->outer_ip == IECM_RX_PTYPE_OUTER_IP) &&
+	       (decoded->outer_ip_ver == IECM_RX_PTYPE_OUTER_IPV4);
+	ipv6 = (decoded->outer_ip == IECM_RX_PTYPE_OUTER_IP) &&
+	       (decoded->outer_ip_ver == IECM_RX_PTYPE_OUTER_IPV6);
+
+	if (ipv4 && (csum_bits->ipe || csum_bits->eipe))
+		goto checksum_fail;
+
+	if (ipv6 && csum_bits->ipv6exadd)
+		return;
+
+	/* HW checksum will be invalid if vlan stripping is not enabled and
+	 * packet has an outer vlan tag. raw_csum_inv will also not be set
+	 * even though it's invalid.
+	 */
+	if (skb_vlan_tag_present(skb))
+		return;
+
+	/* check for L4 errors and handle packets that were not able to be
+	 * checksummed
+	 */
+	if (csum_bits->l4e)
+		goto checksum_fail;
+
+	/* Only report checksum unnecessary for ICMP, TCP, UDP, or SCTP */
+	switch (decoded->inner_prot) {
+	case IECM_RX_PTYPE_INNER_PROT_ICMP:
+	case IECM_RX_PTYPE_INNER_PROT_TCP:
+	case IECM_RX_PTYPE_INNER_PROT_UDP:
+	case IECM_RX_PTYPE_INNER_PROT_SCTP:
+		skb->ip_summed = CHECKSUM_UNNECESSARY;
+	default:
+		break;
+	}
+	return;
+
+checksum_fail:
+	rxq->vport->port_stats.rx_hw_csum_err++;
+}
+
+/**
+ * iecm_rx_splitq_extract_csum_bits - Extract checksum bits from descriptor
+ * @rx_desc: receive descriptor
+ * @csum: structure to extract checksum fields
+ *
+ **/
+static void
+iecm_rx_splitq_extract_csum_bits(struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc,
+				 struct iecm_rx_csum_decoded *csum)
+{
+	u8 qword0, qword1;
+
+	qword0 = rx_desc->status_err0_qw0;
+	qword1 = rx_desc->status_err0_qw1;
+
+	csum->ipe = !!(qword1 &
+		       BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_XSUM_IPE_S));
+	csum->eipe = !!(qword1 &
+			BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_XSUM_EIPE_S));
+	csum->l4e = !!(qword1 &
+		       BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_XSUM_L4E_S));
+	csum->l3l4p = !!(qword1 &
+			 BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_L3L4P_S));
+	csum->ipv6exadd =
+			!!(qword0 &
+			   BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_IPV6EXADD_S));
+	csum->rsc = !!(le16_to_cpu(rx_desc->hdrlen_flags) &
+		       VIRTCHNL2_RX_FLEX_DESC_ADV_RSC_M);
+	csum->raw_csum_inv = !!(le16_to_cpu(rx_desc->ptype_err_fflags0) &
+				BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_FF0_S));
+	csum->raw_csum = le16_to_cpu(rx_desc->misc.raw_cs);
+	csum->pprs = 0;
+}
+
+/**
+ * iecm_rx_rsc - Set the RSC fields in the skb
+ * @rxq : Rx descriptor ring packet is being transacted on
+ * @skb : pointer to current skb being populated
+ * @rx_desc: Receive descriptor
+ * @decoded: Decoded Rx packet type related fields
+ *
+ * Return 0 on success and error code on failure
+ *
+ * Populate the skb fields with the total number of RSC segments, RSC payload
+ * length and packet type.
+ */
+static int iecm_rx_rsc(struct iecm_queue *rxq, struct sk_buff *skb,
+		       struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc,
+		       struct iecm_rx_ptype_decoded *decoded)
+{
+	u16 rsc_segments, rsc_payload_len;
+	struct tcphdr *tcph;
+	bool ipv4, ipv6;
+
+	if (!decoded->outer_ip)
+		return -EINVAL;
+
+	rsc_payload_len = le16_to_cpu(rx_desc->misc.rscseglen);
+	if (!rsc_payload_len)
+		return -EINVAL;
+
+	ipv4 = (decoded->outer_ip == IECM_RX_PTYPE_OUTER_IP) &&
+		(decoded->outer_ip_ver == IECM_RX_PTYPE_OUTER_IPV4);
+	ipv6 = (decoded->outer_ip == IECM_RX_PTYPE_OUTER_IP) &&
+		(decoded->outer_ip_ver == IECM_RX_PTYPE_OUTER_IPV6);
+
+	if (!(ipv4 ^ ipv6))
+		return -EINVAL;
+
+	rsc_segments = DIV_ROUND_UP(skb->data_len, rsc_payload_len);
+
+	NAPI_GRO_CB(skb)->count = rsc_segments;
+	skb_shinfo(skb)->gso_size = rsc_payload_len;
+
+	skb_reset_network_header(skb);
+
+	if (ipv4) {
+		struct iphdr *ipv4h = ip_hdr(skb);
+
+		skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
+
+		/* Reset and set transport header offset in skb */
+		skb_set_transport_header(skb, sizeof(struct iphdr));
+		tcph = tcp_hdr(skb);
+
+		/* Compute the TCP pseudo header checksum*/
+		tcph->check =
+			~tcp_v4_check(skb->len - skb_transport_offset(skb),
+				      ipv4h->saddr, ipv4h->daddr, 0);
+	} else {
+		struct ipv6hdr *ipv6h = ipv6_hdr(skb);
+
+		skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
+		skb_set_transport_header(skb, sizeof(struct ipv6hdr));
+		tcph = tcp_hdr(skb);
+		tcph->check =
+			~tcp_v6_check(skb->len - skb_transport_offset(skb),
+				      &ipv6h->saddr, &ipv6h->daddr, 0);
+	}
+
+	tcp_gro_complete(skb);
+
+	u64_stats_update_begin(&rxq->stats_sync);
+	rxq->q_stats.rx.rsc_pkts++;
+	u64_stats_update_end(&rxq->stats_sync);
+
+	return 0;
+}
+
+/**
+ * iecm_rx_process_skb_fields - Populate skb header fields from Rx descriptor
+ * @rxq: Rx descriptor ring packet is being transacted on
+ * @skb: pointer to current skb being populated
+ * @rx_desc: Receive descriptor
+ *

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3025

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+ * This function checks the ring, descriptor, and packet information in
+ * order to populate the hash, checksum, VLAN, protocol, and
+ * other fields within the skb.
+ */
+int
+iecm_rx_process_skb_fields(struct iecm_queue *rxq, struct sk_buff *skb,
+			   struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc)
+{
+	struct iecm_rx_ptype_decoded decoded;
+	struct iecm_rx_csum_decoded csum_bits;

Please follow RCT.

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3037

Quoted 12 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +12 -0
+	u16 rx_ptype;
+	int err = 0;
+
+	rx_ptype = le16_to_cpu(rx_desc->ptype_err_fflags0) &
+				VIRTCHNL2_RX_FLEX_DESC_ADV_PTYPE_M;
+
+	decoded = rxq->vport->rx_ptype_lkup[rx_ptype];
+	if (!decoded.known)
+		return -EINVAL;
+
+	/* modifies the skb - consumes the enet header */
+	skb->protocol = eth_type_trans(skb, rxq->vport->netdev);

eth_type_trans() should generally be called *right* before napi_gro_receive() to still have caches warm.

Quoted 15 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +15 -0
+	iecm_rx_splitq_extract_csum_bits(rx_desc, &csum_bits);
+	iecm_rx_csum(rxq, skb, &csum_bits, &decoded);
+	/* process RSS/hash */
+	iecm_rx_hash(rxq, skb, rx_desc, &decoded);
+
+	if (csum_bits.rsc)
+		err = iecm_rx_rsc(rxq, skb, rx_desc, &decoded);
+
+	return err;
+}
+
+/**
+ * iecm_rx_skb - Send a completed packet up the stack
+ * @rxq: Rx ring in play
+ * @skb: packet to send up

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3062

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+ * @vlan_tag: packet vlan tag
+ *
+ * This function sends the completed packet (via. skb) up the stack using
+ * gro receive functions
+ */
+void iecm_rx_skb(struct iecm_queue *rxq, struct sk_buff *skb, u16 vlan_tag)
+{
+	/* Adding HW VLAN tag to skb must occur after processing csum */
+	if (vlan_tag & VLAN_VID_MASK)
+		__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlan_tag);

Why can't this be placed into process_skb_fields()? This function becomes redundant then, and you could call napi_gro_receive() directly instead.

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3074

Quoted 12 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +12 -0
+
+	napi_gro_receive(&rxq->q_vector->napi, skb);
+}
+
+/**
+ * iecm_rx_page_is_reserved - check if reuse is possible
+ * @page: page struct to check
+ */
+static bool iecm_rx_page_is_reserved(struct page *page)
+{
+	return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page);
+}

Please check generic dev_page_is_reusable(), it's almost the same (a bit more optimized).

Quoted 17 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +17 -0
+
+/**
+ * iecm_rx_buf_adjust_pg - Prepare rx buffer for reuse
+ * @rx_buf: Rx buffer to adjust
+ * @size: Size of adjustment
+ *
+ * Update the offset within page so that rx buf will be ready to be reused.
+ * For systems with PAGE_SIZE < 8192 this function will flip the page offset
+ * so the second half of page assigned to rx buffer will be used, otherwise
+ * the offset is moved by the @size bytes
+ */
+void
+iecm_rx_buf_adjust_pg(struct iecm_rx_buf *rx_buf, unsigned int size)
+{
+	struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf->page_indx];
+
+#if (PAGE_SIZE < 8192)

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3101

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+	if (rx_buf->buf_size > IECM_RX_BUF_2048)
+		/* flip to second page */
+		rx_buf->page_indx = !rx_buf->page_indx;
+	else
+		/* flip page offset to other buffer */
+		page_info->page_offset ^= size;
+#else
+	/* move offset up to the next cache line */
+	page_info->page_offset += size;
+#endif

Again, no need for ifdeffery, PAGE_SIZE check can be placed into an if statement.

Quoted 23 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +23 -0
+}
+
+/**
+ * iecm_rx_can_reuse_page - Determine if page can be reused for another rx
+ * @rx_buf: buffer containing the page
+ *
+ * If page is reusable, we have a green light for calling iecm_reuse_rx_page,
+ * which will assign the current buffer to the buffer that next_to_alloc is
+ * pointing to; otherwise, the dma mapping needs to be destroyed and
+ * page freed
+ */
+bool iecm_rx_can_reuse_page(struct iecm_rx_buf *rx_buf)
+{
+	struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf->page_indx];
+
+#if (PAGE_SIZE >= 8192)
+	unsigned int last_offset = PAGE_SIZE - rx_buf->buf_size;
+#endif /* PAGE_SIZE < 8192) */
+	unsigned int pagecnt_bias = page_info->pagecnt_bias;
+	struct page *page = page_info->page;
+
+	/* avoid re-using remote pages */
+	if (unlikely(iecm_rx_page_is_reserved(page)))

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3134

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+		return false;
+
+#if (PAGE_SIZE < 8192)
+	/* if we are only owner of page we can reuse it */
+	if (unlikely((page_count(page) - pagecnt_bias) > 1))
+		return false;
+#else
+	if (rx_buf->page_offset > last_offset)
+		return false;
+#endif /* PAGE_SIZE < 8192) */

Same here 2 times.

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3140

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+
+	/* If we have drained the page fragment pool we need to update
+	 * the pagecnt_bias and page count so that we fully restock the
+	 * number of references the driver holds.
+	 */
+	if (unlikely(pagecnt_bias == 1)) {

With 1532 byte frames, this condition will be hit 50% of times. It's definitely not a good place for unlkely().

Quoted 17 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +17 -0
+		page_ref_add(page, USHRT_MAX - 1);
+		page_info->pagecnt_bias = USHRT_MAX;
+	}
+
+	return true;
+}
+
+/**
+ * iecm_rx_add_frag - Add contents of Rx buffer to sk_buff as a frag
+ * @rx_buf: buffer containing page to add
+ * @skb: sk_buff to place the data into
+ * @size: packet length from rx_desc
+ *
+ * This function will add the data contained in rx_buf->page to the skb.
+ * It will just attach the page as a frag to the skb.
+ * The function will then update the page offset.
+ */

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3167

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+void iecm_rx_add_frag(struct iecm_rx_buf *rx_buf, struct sk_buff *skb,
+		      unsigned int size)
+{
+	struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf->page_indx];
+
+#if (PAGE_SIZE >= 8192)
+	unsigned int truesize = SKB_DATA_ALIGN(size);
+#else
+	unsigned int truesize = rx_buf->buf_size;
+#endif

Same.

Quoted 48 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +48 -0
+
+	skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page_info->page,
+			page_info->page_offset, size, truesize);
+
+	iecm_rx_buf_adjust_pg(rx_buf, truesize);
+}
+
+/**
+ * iecm_rx_get_buf_page - Fetch Rx buffer page and synchronize data for use
+ * @dev: device struct
+ * @rx_buf: Rx buf to fetch page for
+ * @size: size of buffer to add to skb
+ *
+ * This function will pull an Rx buffer page from the ring and synchronize it
+ * for use by the CPU.
+ */
+static void
+iecm_rx_get_buf_page(struct device *dev, struct iecm_rx_buf *rx_buf,
+		     const unsigned int size)
+{
+	struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf->page_indx];
+
+	prefetch(page_info->page);
+
+	/* we are reusing so sync this buffer for CPU use */
+	dma_sync_single_range_for_cpu(dev, page_info->dma,
+				      page_info->page_offset, size,
+				      DMA_FROM_DEVICE);
+
+	/* We have pulled a buffer for use, so decrement pagecnt_bias */
+	page_info->pagecnt_bias--;
+}
+
+/**
+ * iecm_rx_construct_skb - Allocate skb and populate it
+ * @rxq: Rx descriptor queue
+ * @rx_buf: Rx buffer to pull data from
+ * @size: the length of the packet
+ *
+ * This function allocates an skb. It then populates it with the page
+ * data from the current receive descriptor, taking care to set up the
+ * skb correctly.
+ */
+struct sk_buff *
+iecm_rx_construct_skb(struct iecm_queue *rxq, struct iecm_rx_buf *rx_buf,
+		      unsigned int size)
+{
+	struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf->page_indx];

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3225

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+
+	void *va = page_address(page_info->page) + page_info->page_offset;
+	unsigned int headlen;
+	struct sk_buff *skb;
+
+	/* prefetch first cache line of first page */
+	prefetch(va);
+#if L1_CACHE_BYTES < 128
+	prefetch((u8 *)va + L1_CACHE_BYTES);
+#endif /* L1_CACHE_BYTES */

Here's open-coded net_prefetch().

Quoted 14 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +14 -0
+	/* allocate a skb to store the frags */
+	skb = __napi_alloc_skb(&rxq->q_vector->napi, IECM_RX_HDR_SIZE,
+			       GFP_ATOMIC | __GFP_NOWARN);
+	if (unlikely(!skb))
+		return NULL;
+
+	skb_record_rx_queue(skb, rxq->idx);
+
+	/* Determine available headroom for copy */
+	headlen = size;
+	if (headlen > IECM_RX_HDR_SIZE)
+		headlen = eth_get_headlen(skb->dev, va, IECM_RX_HDR_SIZE);
+
+	/* align pull length to size of long to optimize memcpy performance */

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3249

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+	memcpy(__skb_put(skb, headlen), va, ALIGN(headlen, sizeof(long)));
+
+	/* if we exhaust the linear part then add what is left as a frag */
+	size -= headlen;
+	if (size) {
+#if (PAGE_SIZE >= 8192)
+		unsigned int truesize = SKB_DATA_ALIGN(size);
+#else
+		unsigned int truesize = rx_buf->buf_size;
+#endif

Again.

Quoted 92 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +92 -0
+		skb_add_rx_frag(skb, 0, page_info->page,
+				page_info->page_offset + headlen, size,
+				truesize);
+		/* buffer is used by skb, update page_offset */
+		iecm_rx_buf_adjust_pg(rx_buf, truesize);
+
+	} else {
+		/* buffer is unused, reset bias back to rx_buf; data was copied
+		 * onto skb's linear part so there's no need for adjusting
+		 * page offset and we can reuse this buffer as-is
+		 */
+		page_info->pagecnt_bias++;
+	}
+
+	return skb;
+}
+
+/**
+ * iecm_rx_hdr_construct_skb - Allocate skb and populate it from header buffer
+ * @rxq: Rx descriptor queue
+ * @hdr_buf: Rx buffer to pull data from
+ * @size: the length of the packet
+ *
+ * This function allocates an skb. It then populates it with the page data from
+ * the current receive descriptor, taking care to set up the skb correctly.
+ * This specifcally uses a header buffer to start building the skb.
+ */
+static struct sk_buff *
+iecm_rx_hdr_construct_skb(struct iecm_queue *rxq, struct iecm_dma_mem *hdr_buf,
+			  unsigned int size)
+{
+	struct sk_buff *skb;
+
+	/* allocate a skb to store the frags */
+	skb = __napi_alloc_skb(&rxq->q_vector->napi, IECM_RX_HDR_SIZE,
+			       GFP_ATOMIC | __GFP_NOWARN);
+	if (unlikely(!skb))
+		return NULL;
+
+	skb_record_rx_queue(skb, rxq->idx);
+
+	memcpy(__skb_put(skb, size), hdr_buf->va, size);
+
+	return skb;
+}
+
+/**
+ * iecm_rx_splitq_test_staterr - tests bits in Rx descriptor
+ * status and error fields
+ * @stat_err_field: field from descriptor to test bits in
+ * @stat_err_bits: value to mask
+ *
+ */
+bool
+iecm_rx_splitq_test_staterr(u8 stat_err_field, const u8 stat_err_bits)
+{
+	return !!(stat_err_field & stat_err_bits);
+}
+
+/**
+ * iecm_rx_splitq_extract_vlan_tag - Extract vlan tag from the descriptor
+ * @desc: Rx flex descriptor
+ * @rxq: rxq to check the vlan flags
+ * @vlan_tag: vlan tag to fill in
+ *
+ * Return true if error bit is set in the descriptor, else return false and
+ * store the vlan_tag in the variable passed in the function parameters
+ */
+bool iecm_rx_splitq_extract_vlan_tag(struct virtchnl2_rx_flex_desc_adv_nic_3 *desc,
+				     struct iecm_queue *rxq, u16 *vlan_tag)
+{
+	u8 stat_err0_qw0, stat_err_bits, stat_err1;
+
+	stat_err_bits = BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_RXE_S);
+	stat_err0_qw0 = desc->status_err0_qw0;
+	if (unlikely(iecm_rx_splitq_test_staterr(stat_err0_qw0, stat_err_bits)))
+		return true;
+
+	stat_err1 = desc->status_err1;
+
+	if (stat_err0_qw0 & BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_L2TAG1P_S) &&
+	    test_bit(__IECM_Q_VLAN_TAG_LOC_L2TAG1, rxq->flags))
+		*vlan_tag = le16_to_cpu(desc->l2tag1);
+	if (stat_err1 & BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS1_L2TAG2P_S) &&
+	    test_bit(__IECM_Q_VLAN_TAG_LOC_L2TAG2, rxq->flags))
+		*vlan_tag = le16_to_cpu(desc->l2tag2);
+
+	return false;
+}
+
+/**
+ * iecm_rx_splitq_is_non_eop - process handling of non-EOP buffers

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3351

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+ * @rx_desc: Rx descriptor for current buffer
+ *
+ * If the buffer is an EOP buffer, this function exits returning false,
+ * otherwise return true indicating that this is in fact a non-EOP buffer.
+ */
+static bool
+iecm_rx_splitq_is_non_eop(struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc)
+{
+	/* if we are the last buffer then there is nothing else to do */
+#define IECM_RXD_EOF BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_EOF_S)

This is a wrong place to define anything, it can be easily overlooked.

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3356

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +5 -0
+	if (likely(iecm_rx_splitq_test_staterr(rx_desc->status_err0_qw1,
+					       IECM_RXD_EOF)))
+		return false;
+
+	return true;

This can be converted to an one-liner

	return likely(...);
Quoted 42 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +42 -0
+}
+
+/**
+ * iecm_rx_splitq_recycle_buf - Attempt to recycle or realloc buffer
+ * @rxbufq: receive queue
+ * @rx_buf: Rx buffer to pull data from
+ *
+ * This function will clean up the contents of the rx_buf. It will either
+ * recycle the buffer or unmap it and free the associated resources. The buffer
+ * will then be placed on a refillq where it will later be reclaimed by the
+ * corresponding bufq.
+ *
+ * This works based on page flipping. If we assume e.g., a 4k page, it will be
+ * divided into two 2k buffers. We post the first half to hardware and, after
+ * using it, flip to second half of the page with iecm_adjust_pg_offset and
+ * post that to hardware. The third time through we'll flip back to first half
+ * of page and check if stack is still using it, if not we can reuse the buffer
+ * as is, otherwise we'll drain it and get a new page.
+ */
+static void iecm_rx_splitq_recycle_buf(struct iecm_queue *rxbufq,
+				       struct iecm_rx_buf *rx_buf)
+{
+	struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf->page_indx];
+
+	if (!iecm_rx_can_reuse_page(rx_buf)) {
+		/* we are not reusing the buffer so unmap it */
+		dma_unmap_page_attrs(rxbufq->dev, page_info->dma, PAGE_SIZE,
+				     DMA_FROM_DEVICE, IECM_RX_DMA_ATTR);
+		__page_frag_cache_drain(page_info->page,
+					page_info->pagecnt_bias);
+
+		/* clear contents of buffer_info */
+		page_info->page = NULL;
+		rx_buf->skb = NULL;
+
+		/* It's possible the alloc can fail here but there's not much
+		 * we can do, bufq will have to try and realloc to fill the
+		 * hole.
+		 */
+		iecm_alloc_page(rxbufq, page_info);
+	}
+

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3408

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+	/* We sync the memory back to hardware now to do as much work in this
+	 * context as feasible.  Hardware won't actually know about the buffer
+	 * until it's reclaimed off the refillq and put back into the bufq.
+	 */
+	if (likely(page_info->page)) {
+		dma_sync_single_range_for_device(rxbufq->dev, page_info->dma,
+						 page_info->page_offset,
+						 rxbufq->rx_buf_size,
+						 DMA_FROM_DEVICE);
+	}

One-liner, braces are redundant.

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3409

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

Here you set page_info->page to NULL in the first condition branch and check for it in the second.
So it's equivalent to

	if (iecm_rx_can_reuse_page(rx_buf)) {
		dma_sync_single_range();
		return;
	}

	/* we are not reusing the buffer ... */
	...

but saves 1 indent level and generally more readable.

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3417

Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +8 -0
+
+/**
+ * iecm_rx_bump_ntc - Bump and wrap q->next_to_clean value
+ * @q: queue to bump
+ */
+void iecm_rx_bump_ntc(struct iecm_queue *q)
+{
+	u16 ntc = q->next_to_clean + 1;

There should be an empty line (between variable declarations and function body). checkpatch should've mentioned this.

Quoted 117 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +117 -0
+	/* fetch, update, and store next to clean */
+	if (ntc < q->desc_count) {
+		q->next_to_clean = ntc;
+	} else {
+		q->next_to_clean = 0;
+		change_bit(__IECM_Q_GEN_CHK, q->flags);
+	}
+}
+
+/**
+ * iecm_rx_splitq_clean - Clean completed descriptors from Rx queue
+ * @rxq: Rx descriptor queue to retrieve receive buffer queue
+ * @budget: Total limit on number of packets to process
+ *
+ * This function provides a "bounce buffer" approach to Rx interrupt
+ * processing. The advantage to this is that on systems that have
+ * expensive overhead for IOMMU access this provides a means of avoiding
+ * it by maintaining the mapping of the page to the system.
+ *
+ * Returns amount of work completed
+ */
+static int iecm_rx_splitq_clean(struct iecm_queue *rxq, int budget)
+{
+	int total_rx_bytes = 0, total_rx_pkts = 0;
+	struct iecm_queue *rx_bufq = NULL;
+	struct sk_buff *skb = rxq->skb;
+	bool failure = false;
+
+	/* Process Rx packets bounded by budget */
+	while (likely(total_rx_pkts < budget)) {
+		struct virtchnl2_rx_flex_desc_adv_nic_3 *splitq_flex_rx_desc;
+		struct iecm_sw_queue *refillq = NULL;
+		struct iecm_dma_mem *hdr_buf = NULL;
+		struct iecm_rxq_set *rxq_set = NULL;
+		struct iecm_rx_buf *rx_buf = NULL;
+		u16 gen_id, buf_id, vlan_tag = 0;
+		union virtchnl2_rx_desc *rx_desc;
+		unsigned int pkt_len = 0;
+		unsigned int hdr_len = 0;
+		 /* Header buffer overflow only valid for header split */
+		bool hbo = false;
+		int bufq_id;
+
+		/* get the Rx desc from Rx queue based on 'next_to_clean' */
+		rx_desc = IECM_RX_DESC(rxq, rxq->next_to_clean);
+		splitq_flex_rx_desc = (struct virtchnl2_rx_flex_desc_adv_nic_3 *)rx_desc;
+
+		/* This memory barrier is needed to keep us from reading
+		 * any other fields out of the rx_desc
+		 */
+		dma_rmb();
+
+		/* if the descriptor isn't done, no work yet to do */
+		gen_id = le16_to_cpu(splitq_flex_rx_desc->pktlen_gen_bufq_id);
+		gen_id = (gen_id & VIRTCHNL2_RX_FLEX_DESC_ADV_GEN_M) >>
+						VIRTCHNL2_RX_FLEX_DESC_ADV_GEN_S;
+		if (test_bit(__IECM_Q_GEN_CHK, rxq->flags) != gen_id)
+			break;
+
+		if ((splitq_flex_rx_desc->rxdid_ucast &
+		    VIRTCHNL2_RX_FLEX_DESC_ADV_RXDID_M) != VIRTCHNL2_RXDID_1_FLEX_SPLITQ) {
+			iecm_rx_bump_ntc(rxq);
+			rxq->vport->port_stats.rx_bad_descs++;
+			continue;
+		}
+
+		pkt_len = le16_to_cpu(splitq_flex_rx_desc->pktlen_gen_bufq_id) &
+			  VIRTCHNL2_RX_FLEX_DESC_ADV_LEN_PBUF_M;
+
+		hbo = splitq_flex_rx_desc->status_err0_qw1 &
+		      BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_HBO_S);
+
+		if (unlikely(hbo)) {
+			rxq->vport->port_stats.rx_hsplit_hbo++;
+			goto bypass_hsplit;
+		}
+
+		hdr_len =
+			le16_to_cpu(splitq_flex_rx_desc->hdrlen_flags) &
+			VIRTCHNL2_RX_FLEX_DESC_ADV_LEN_HDR_M;
+
+bypass_hsplit:
+		bufq_id = le16_to_cpu(splitq_flex_rx_desc->pktlen_gen_bufq_id);
+		bufq_id = (bufq_id & VIRTCHNL2_RX_FLEX_DESC_ADV_BUFQ_ID_M) >>
+			  VIRTCHNL2_RX_FLEX_DESC_ADV_BUFQ_ID_S;
+
+		rxq_set = container_of(rxq, struct iecm_rxq_set, rxq);
+		if (!bufq_id)
+			refillq = rxq_set->refillq0;
+		else
+			refillq = rxq_set->refillq1;
+
+		/* retrieve buffer from the rxq */
+		rx_bufq = &rxq->rxq_grp->splitq.bufq_sets[bufq_id].bufq;
+
+		buf_id = le16_to_cpu(splitq_flex_rx_desc->buf_id);
+
+		if (pkt_len) {
+			rx_buf = &rx_bufq->rx_buf.buf[buf_id];
+			iecm_rx_get_buf_page(rx_bufq->dev, rx_buf, pkt_len);
+		}
+
+		if (hdr_len) {
+			hdr_buf = rx_bufq->rx_buf.hdr_buf[buf_id];
+
+			dma_sync_single_for_cpu(rxq->dev, hdr_buf->pa, hdr_buf->size,
+						DMA_FROM_DEVICE);
+
+			skb = iecm_rx_hdr_construct_skb(rxq, hdr_buf, hdr_len);
+			rxq->vport->port_stats.rx_hsplit++;
+		}
+
+		if (pkt_len) {
+			if (skb)
+				iecm_rx_add_frag(rx_buf, skb, pkt_len);
+			else
+				skb = iecm_rx_construct_skb(rxq, rx_buf,

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3544

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+							    pkt_len);
+		}
+
+		/* exit if we failed to retrieve a buffer */
+		if (!skb) {
+			/* If we fetched a buffer, but didn't use it
+			 * undo pagecnt_bias decrement
+			 */
+			if (rx_buf)
+				rx_buf->page_info[rx_buf->page_indx].pagecnt_bias++;

Line of 85 cols here.

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +5 -0
+			break;
+		}
+
+		if (rx_buf)
+			iecm_rx_splitq_recycle_buf(rx_bufq, rx_buf);

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3559

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+		iecm_rx_post_buf_refill(refillq, buf_id);
+
+		iecm_rx_bump_ntc(rxq);
+		/* skip if it is non EOP desc */
+		if (iecm_rx_splitq_is_non_eop(splitq_flex_rx_desc))
+			continue;
+
+		/* extract vlan tag from the descriptor */
+		if (unlikely(iecm_rx_splitq_extract_vlan_tag(splitq_flex_rx_desc,
+							     rxq, &vlan_tag))) {

81 and 81 respectively.

Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +7 -0
+			dev_kfree_skb_any(skb);
+			skb = NULL;
+			continue;
+		}
+
+		/* pad skb if needed (to make valid ethernet frame) */
+		if (eth_skb_pad(skb)) {

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3576

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+			skb = NULL;
+			continue;
+		}
+
+		/* probably a little skewed due to removing CRC */
+		total_rx_bytes += skb->len;
+
+		/* protocol */
+		if (unlikely(iecm_rx_process_skb_fields(rxq, skb,
+							splitq_flex_rx_desc))) {

You can define variables with shorter names to avoid this.

Quoted 28 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +28 -0
+			dev_kfree_skb_any(skb);
+			skb = NULL;
+			continue;
+		}
+
+		/* send completed skb up the stack */
+		iecm_rx_skb(rxq, skb, vlan_tag);
+		skb = NULL;
+
+		/* update budget accounting */
+		total_rx_pkts++;
+	}
+	rxq->skb = skb;
+	u64_stats_update_begin(&rxq->stats_sync);
+	rxq->q_stats.rx.packets += total_rx_pkts;
+	rxq->q_stats.rx.bytes += total_rx_bytes;
+	u64_stats_update_end(&rxq->stats_sync);
+
+	/* guarantee a trip back through this routine if there was a failure */
+	return unlikely(failure) ? budget : total_rx_pkts;
+}
+
+/**
+ * iecm_rx_update_bufq_desc - Update buffer queue descriptor
+ * @bufq: Pointer to the buffer queue
+ * @desc: Refill queue descriptor
+ * @buf_desc: Buffer queue descriptor
+ *

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3614

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+ * Return 0 on success and negative on failure.
+ */
+static int iecm_rx_update_bufq_desc(struct iecm_queue *bufq, u16 *desc,
+				    struct virtchnl2_splitq_rx_buf_desc *buf_desc)
+{
+	struct iecm_page_info *page_info;
+	struct iecm_rx_buf *buf;
+	u16 buf_id;
+
+	buf_id = ((*desc) & IECM_RX_BI_BUFID_M) >> IECM_RX_BI_BUFID_S;

FIELD_GET().

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3625

Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +11 -0
+
+	buf = &bufq->rx_buf.buf[buf_id];
+	page_info = &buf->page_info[buf->page_indx];
+
+	/* It's possible page alloc failed during rxq clean, try to
+	 * recover here.
+	 */
+	if (unlikely(!page_info->page)) {
+		if (iecm_alloc_page(bufq, page_info))
+			return -ENOMEM;
+	}

if (1 && 2).

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3635

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+	buf_desc->pkt_addr = cpu_to_le64(page_info->dma + page_info->page_offset);
+	buf_desc->qword0.buf_id = cpu_to_le16(buf_id);
+
+	if (bufq->rx_hsplit_en) {
+		struct iecm_dma_mem *hdr_buf = bufq->rx_buf.hdr_buf[buf_id];
+
+		buf_desc->hdr_addr = cpu_to_le64(hdr_buf->pa);
+		dma_sync_single_for_device(bufq->dev, hdr_buf->pa,
+					   hdr_buf->size, DMA_FROM_DEVICE);
+	}
	if (!hsplit_en)
		return 0;

	hdr_buf = ...
Quoted 19 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +19 -0
+
+	return 0;
+}
+
+/**
+ * iecm_rx_clean_refillq - Clean refill queue buffers
+ * @bufq: buffer queue to post buffers back to
+ * @refillq: refill queue to clean
+ *
+ * This function takes care of the buffer refill management
+ */
+static void iecm_rx_clean_refillq(struct iecm_queue *bufq,
+				  struct iecm_sw_queue *refillq)
+{
+	struct virtchnl2_splitq_rx_buf_desc *buf_desc;
+	u16 refillq_ntc = refillq->next_to_clean;
+	u16 bufq_nta = bufq->next_to_alloc;
+	u16 *refill_desc;
+	int cleaned = 0;

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3664

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+	u16 gen;
+
+	refill_desc = IECM_SPLITQ_RX_BI_DESC(refillq, refillq_ntc);
+	buf_desc = IECM_SPLITQ_RX_BUF_DESC(bufq, bufq_nta);
+
+	/* make sure we stop at ring wrap in the unlikely case ring is full */
+	while (likely(cleaned < refillq->desc_count)) {
+		bool failure;
+
+		gen = ((*refill_desc) & IECM_RX_BI_GEN_M) >> IECM_RX_BI_GEN_S;

FIELD_GET().

Quoted 20 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +20 -0
+		if (test_bit(__IECM_RFLQ_GEN_CHK, refillq->flags) != gen)
+			break;
+
+		failure = iecm_rx_update_bufq_desc(bufq, refill_desc,
+						   buf_desc);
+		if (failure)
+			break;
+
+		refillq_ntc++;
+		refill_desc++;
+		bufq_nta++;
+		buf_desc++;
+		cleaned++;
+
+		if (unlikely(refillq_ntc == refillq->desc_count)) {
+			change_bit(__IECM_RFLQ_GEN_CHK, refillq->flags);
+			refill_desc = IECM_SPLITQ_RX_BI_DESC(refillq, 0);
+			refillq_ntc = 0;
+		}
+		if (unlikely(bufq_nta == bufq->desc_count)) {

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3694

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+			buf_desc = IECM_SPLITQ_RX_BUF_DESC(bufq, 0);
+			bufq_nta = 0;
+		}
+	}
+
+	if (cleaned) {
+		/* only update hardware tail in strides */
+		if (((bufq->next_to_use <= bufq_nta ? 0 : bufq->desc_count) +
+		    bufq_nta - bufq->next_to_use) >= bufq->rx_buf_stride)
+			iecm_rx_buf_hw_update(bufq, bufq_nta & ~(bufq->rx_buf_stride - 1));

92 chars.

Quoted 94 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +83 -0
+
+		/* update next to alloc since we have filled the ring */
+		refillq->next_to_clean = refillq_ntc;
+		bufq->next_to_alloc = bufq_nta;
+	}
+}
+
+/**
+ * iecm_rx_clean_refillq_all - Clean all refill queues
+ * @bufq: bufq with refillqs to clean
+ *
+ * Iterates through all refill queues assigned to the buffer queue assigned to
+ * this vector.  Returns true if clean is complete within budget, false
+ * otherwise.
+ */
+static void iecm_rx_clean_refillq_all(struct iecm_queue *bufq)
+{
+	struct iecm_bufq_set *bufq_set;
+	int i = 0;
+
+	bufq_set = container_of(bufq, struct iecm_bufq_set, bufq);
+	for (i = 0; i < bufq_set->num_refillqs; i++)
+		iecm_rx_clean_refillq(bufq, &bufq_set->refillqs[i]);
+}
+
 /**
  * iecm_vport_intr_clean_queues - MSIX mode Interrupt Handler
  * @irq: interrupt number
@@ -2742,6 +4122,64 @@ iecm_vport_intr_napi_ena_all(struct iecm_vport *vport)
 	}
 }
 
+/**
+ * iecm_tx_splitq_clean_all- Clean completetion queues
+ * @q_vec: queue vector
+ * @budget: Used to determine if we are in netpoll
+ *
+ * Returns false if clean is not complete else returns true
+ */
+static bool
+iecm_tx_splitq_clean_all(struct iecm_q_vector *q_vec, int budget)
+{
+	bool clean_complete = true;
+	int i, budget_per_q;
+
+	budget_per_q = max(budget / q_vec->num_txq, 1);
+	for (i = 0; i < q_vec->num_txq; i++) {
+		if (!iecm_tx_clean_complq(q_vec->tx[i], budget_per_q))
+			clean_complete = false;
+	}
+	return clean_complete;
+}
+
+/**
+ * iecm_rx_splitq_clean_all- Clean completetion queues
+ * @q_vec: queue vector
+ * @budget: Used to determine if we are in netpoll
+ * @cleaned: returns number of packets cleaned
+ *
+ * Returns false if clean is not complete else returns true
+ */
+static bool
+iecm_rx_splitq_clean_all(struct iecm_q_vector *q_vec, int budget,
+			 int *cleaned)
+{
+	bool clean_complete = true;
+	int pkts_cleaned = 0;
+	int i, budget_per_q;
+
+	budget_per_q = max(budget / q_vec->num_rxq, 1);
+	for (i = 0; i < q_vec->num_rxq; i++) {
+		struct iecm_queue *rxq = q_vec->rx[i];
+		int pkts_cleaned_per_q;
+
+		pkts_cleaned_per_q = iecm_rx_splitq_clean(rxq, budget_per_q);
+		/* if we clean as many as budgeted, we must not
+		 * be done
+		 */
+		if (pkts_cleaned_per_q >= budget_per_q)
+			clean_complete = false;
+		pkts_cleaned += pkts_cleaned_per_q;
+	}
+	*cleaned = pkts_cleaned;
+
+	for (i = 0; i < q_vec->num_bufq; i++)
+		iecm_rx_clean_refillq_all(q_vec->bufq[i]);
+
+	return clean_complete;
+}
+
 /**
  * iecm_vport_splitq_napi_poll - NAPI handler
  * @napi: struct from which you get q_vector

drivers/net/ethernet/intel/iecm/iecm_txrx.c iecm_vport_intr_napi_ena_all(struct iecm_vport *vport) · line 4191

Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +2 -2
@@ -2749,8 +4187,34 @@ iecm_vport_intr_napi_ena_all(struct iecm_vport *vport)
  */
 static int iecm_vport_splitq_napi_poll(struct napi_struct *napi, int budget)
 {
-	/* stub */
-	return 0;
+	struct iecm_q_vector *q_vector =
+				container_of(napi, struct iecm_q_vector, napi);

You can assign it later (before clean_complete assignment) to avoid this.

Quoted 92 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +26 -0
+	bool clean_complete;
+	int work_done = 0;
+
+	clean_complete = iecm_tx_splitq_clean_all(q_vector, budget);
+
+	/* Handle case where we are called by netpoll with a budget of 0 */
+	if (budget <= 0)
+		return budget;
+
+	/* We attempt to distribute budget to each Rx queue fairly, but don't
+	 * allow the budget to go below 1 because that would exit polling early.
+	 */
+	clean_complete |= iecm_rx_splitq_clean_all(q_vector, budget,
+						   &work_done);
+
+	/* If work not completed, return budget and polling will return */
+	if (!clean_complete)
+		return budget;
+
+	/* Exit the polling mode, but don't re-enable interrupts if stack might
+	 * poll us due to busy-polling
+	 */
+	if (likely(napi_complete_done(napi, work_done)))
+		iecm_vport_intr_update_itr_ena_irq(q_vector);
+
+	return min_t(int, work_done, budget - 1);
 }
 
 /**
drivers/net/ethernet/intel/include/iecm.h +4 -0
index a655e797f457..3cf2a2f0cb0f 100644
@@ -12,6 +12,10 @@
 #include <linux/etherdevice.h>
 #include <linux/ethtool.h>
 #include <net/tcp.h>
+#include <net/ip6_checksum.h>
+#include <net/ipv6.h>
+#include <net/sch_generic.h>
+#include <net/gro.h>
 #include <linux/version.h>
 #include <linux/dim.h>
 
drivers/net/ethernet/intel/include/iecm_txrx.h +20 -0
index 7ec742fd4c6b..086b0efc989a 100644
@@ -638,6 +638,7 @@ 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);
 int iecm_vport_queues_alloc(struct iecm_vport *vport);
+void iecm_rx_post_buf_refill(struct iecm_sw_queue *refillq, u16 buf_id);
 void iecm_vport_queues_rel(struct iecm_vport *vport);
 void iecm_vport_calc_num_q_vec(struct iecm_vport *vport);
 void iecm_vport_intr_rel(struct iecm_vport *vport);
@@ -650,14 +651,33 @@ int iecm_vport_intr_init(struct iecm_vport *vport);
 irqreturn_t
 iecm_vport_intr_clean_queues(int __always_unused irq, void *data);
 void iecm_vport_intr_ena_irq_all(struct iecm_vport *vport);
+enum
+pkt_hash_types iecm_ptype_to_htype(struct iecm_rx_ptype_decoded *decoded);
 int iecm_config_rss(struct iecm_vport *vport);
 void iecm_fill_dflt_rss_lut(struct iecm_vport *vport);
 int iecm_init_rss(struct iecm_vport *vport);
 void iecm_deinit_rss(struct iecm_vport *vport);
+bool iecm_rx_can_reuse_page(struct iecm_rx_buf *rx_buf);
+void iecm_rx_buf_adjust_pg(struct iecm_rx_buf *rx_buf, unsigned int size);
+void iecm_rx_add_frag(struct iecm_rx_buf *rx_buf, struct sk_buff *skb,
+		      unsigned int size);
+struct sk_buff *iecm_rx_construct_skb(struct iecm_queue *rxq,
+				      struct iecm_rx_buf *rx_buf,
+				      unsigned int size);
+void iecm_rx_skb(struct iecm_queue *rxq, struct sk_buff *skb, u16 vlan_tag);
 bool iecm_init_rx_buf_hw_alloc(struct iecm_queue *rxq, struct iecm_rx_buf *buf);
 void iecm_rx_buf_hw_update(struct iecm_queue *rxq, u32 val);
 void iecm_tx_buf_hw_update(struct iecm_queue *tx_q, u32 val,
 			   bool xmit_more);
+void iecm_rx_splitq_put_bufs(struct iecm_queue *rx_bufq,
+			     struct iecm_rx_buf *hdr_buf,
+			     struct iecm_rx_buf *rx_buf);
+bool iecm_rx_splitq_test_staterr(u8 stat_err_field, const u8 stat_err_bits);
+int iecm_rx_process_skb_fields(struct iecm_queue *rxq, struct sk_buff *skb,
+			       struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc);
+bool iecm_rx_splitq_extract_vlan_tag(struct virtchnl2_rx_flex_desc_adv_nic_3 *desc,
+				     struct iecm_queue *rxq, u16 *vlan_tag);
+void iecm_rx_bump_ntc(struct iecm_queue *q);
 void iecm_tx_buf_rel(struct iecm_queue *tx_q, struct iecm_tx_buf *tx_buf);
 unsigned int iecm_size_to_txd_count(unsigned int size);
 unsigned int iecm_tx_desc_count_required(struct sk_buff *skb);
Signature · 1 line
2.33.0

Thanks,
Al

#56 lore raw

PATCH 13/19 iecm: implement splitq napi_poll

Quoted 42 lines

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

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

Quoted 12 lines

This adds everything we need to actually receive packets and process spent buffers using the splitq model. This contrasts to more traditional queueing models by essentially splitting a normal queue of descriptors and mapped buffers into separate queues. This allows us to deal with both more efficiently and also allows us to implement asymmetric queuing setups where you have multiple completion queues associated with a single buffer queue.

Review

Quoted 7 lines
---
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   | 1468 ++++++++++++++++-
 drivers/net/ethernet/intel/include/iecm.h     |    4 +
 .../net/ethernet/intel/include/iecm_txrx.h    |   20 +
 3 files changed, 1490 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

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

drivers/net/ethernet/intel/iecm/iecm_txrx.c const struct iecm_rx_ptype_decoded

Quoted 4 lines

index 4b9288e1c254..85a82b58525a 100644

drivers/net/ethernet/intel/iecm/iecm_txrx.c +0 -0
@@ -218,6 +218,36 @@ const struct iecm_rx_ptype_decoded

iecm_ptype_lookup[IECM_RX_MAX_PTYPE] = {

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +0 -0
 };
 EXPORT_SYMBOL(iecm_ptype_lookup);
 
Quoted 14 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c const struct iecm_rx_ptype_decoded iecm_ptype_lookup[IECM_RX_MAX_PTYPE] = { · line 231

Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +11 -0
+/**
+ * iecm_buf_lifo_push - push a buffer pointer onto stack
+ * @stack: pointer to stack struct
+ * @buf: pointer to buf to push
+ *
+ * Returns 0 on success, negative on failure
+ **/
+static int iecm_buf_lifo_push(struct iecm_buf_lifo *stack,
+			      struct iecm_tx_buf *buf)
+{
+	if (stack->top == stack->size)

How frequent is this? A candidate for unlikely() maybe?

Sure seems reasonable.

Quoted 37 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c iecm_rx_buf_hw_alloc_all(struct iecm_queue

Quoted 23 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +19 -0
+		return -ENOSPC;
+
+	stack->bufs[stack->top++] = buf;
+
+	return 0;
+}
+
+/**
+ * iecm_buf_lifo_pop - pop a buffer pointer from stack
+ * @stack: pointer to stack struct
+ **/
+static struct iecm_tx_buf *iecm_buf_lifo_pop(struct iecm_buf_lifo *stack)
+{
+	if (!stack->top)
+		return NULL;
+
+	return stack->bufs[--stack->top];
+}
+
 /**
  * iecm_get_stats64 - get statistics for network device structure
  * @netdev: network interface device structure
@@ -812,6 +842,30 @@ iecm_rx_buf_hw_alloc_all(struct iecm_queue

*rxbufq, u16 alloc_count)

Quoted 13 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
 	return !!alloc_count;
 }
 
+/**
+ * iecm_rx_post_buf_refill - Post buffer id to refill queue
+ * @refillq: refill queue to post to
+ * @buf_id: buffer id to post
+ */
+void iecm_rx_post_buf_refill(struct iecm_sw_queue *refillq, u16 buf_id)
+{
+	u16 nta = refillq->next_to_alloc;
+	u16 *bi;
+
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c iecm_rx_buf_hw_alloc_all(struct iecm_queue *rxbufq, u16 alloc_count) · line 859

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +5 -0
+	bi = IECM_SPLITQ_RX_BI_DESC(refillq, nta);
+	/* store the buffer ID and the SW maintained GEN bit to the refillq */
+	*bi = ((buf_id << IECM_RX_BI_BUFID_S) & IECM_RX_BI_BUFID_M) |
+	      (!!(test_bit(__IECM_Q_GEN_CHK, refillq->flags)) <<
+	       IECM_RX_BI_GEN_S);

Please use FIELD_GET() and FIELD_PREP() for masks. This won't pass the maintainers.

We've never had a problem before, I'm assuming these are new? Will check.

Quoted 6 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c iecm_rx_buf_hw_alloc_all(struct iecm_queue *rxbufq, u16 alloc_count) · line 862

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
+
+	nta++;
+	if (unlikely(nta == refillq->desc_count)) {

Could be compressed into one line.

Could be, but we'd prefer not to.

Quoted 37 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+		nta = 0;
+		change_bit(__IECM_Q_GEN_CHK, refillq->flags);
+	}
+	refillq->next_to_alloc = nta;
+}
+
 /**
  * iecm_rx_post_buf_desc - Post buffer to bufq descriptor ring
  * @bufq: buffer queue to post to
@@ -1670,6 +1724,398 @@ int iecm_vport_queues_alloc(struct iecm_vport

*vport)

Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +8 -0
 	return err;
 }
 
+/**
+ * iecm_tx_find_q - Find the tx q based on q id
+ * @vport: the vport we care about
+ * @q_id: Id of the queue
+ *
+ * Returns queue ptr if found else returns NULL
+ */
+static struct iecm_queue *

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 1744

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+iecm_tx_find_q(struct iecm_vport *vport, int q_id)
+{
+	int i;
+
+	for (i = 0; i < vport->num_txq; i++) {
+		struct iecm_queue *tx_q = vport->txqs[i];
+
+		if (tx_q->q_id == q_id)
+			return tx_q;
+	}
	for (i = ...)
		if (vport->txqs[i].q_id == q_id)
			return tx_q;
Quoted 2 lines

No need to create a variable.

It would actually look like

for (i = ...)
if (vport->txqs[i]->q_id == q_id)
return vport->txqs[i];

You had another comment about adding a vc_ops variable where it was being used twice. I'm not seeing a huge difference here and seems like splitting hairs. I think we would prefer to keep this.

Quoted 45 lines
Quoted 26 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +26 -0
+
+	return NULL;
+}
+
+/**
+ * iecm_tx_handle_sw_marker - Handle queue marker packet
+ * @tx_q: tx queue to handle software marker
+ */
+static void iecm_tx_handle_sw_marker(struct iecm_queue *tx_q)
+{
+	struct iecm_vport *vport = tx_q->vport;
+	bool drain_complete = true;
+	int i;
+
+	clear_bit(__IECM_Q_SW_MARKER, tx_q->flags);
+	/* Hardware must write marker packets to all queues associated with
+	 * completion queues. So check if all queues received marker packets
+	 */
+	for (i = 0; i < vport->num_txq; i++) {
+		if (test_bit(__IECM_Q_SW_MARKER, vport->txqs[i]->flags))
+			drain_complete = false;
+	}
+	if (drain_complete) {
+		set_bit(__IECM_SW_MARKER, vport->adapter->flags);
+		wake_up(&vport->adapter->sw_marker_wq);
+	}

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+}
+
+/**
+ * iecm_tx_splitq_clean_buf - Clean TX buffer resources
+ * @tx_q: tx queue to clean buffer from
+ * @tx_buf: buffer to be cleaned
+ * @napi_budget: Used to determine if we are in netpoll
+ */
+static void
+iecm_tx_splitq_clean_buf(struct iecm_queue *tx_q, struct iecm_tx_buf

*tx_buf,

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 1785

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +5 -0
+			 int napi_budget)
+{
+	/* unmap skb header data */
+	dma_unmap_single(tx_q->dev,
+			 dma_unmap_addr(tx_buf, dma),

These two lines can fit into 79 without wrapping.

Quoted 5 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport · line 1787

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +2 -0
+			 dma_unmap_len(tx_buf, len),
+			 DMA_TO_DEVICE);

These two as well.

Will fix.

Quoted 120 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+
+	napi_consume_skb(tx_buf->skb, napi_budget);
+
+	/* clear tx_buf data */
+	tx_buf->skb = NULL;
+	dma_unmap_len_set(tx_buf, len, 0);
+}
+
+/**
+ * iecm_stash_flow_sch_buffers - store buffere parameter info to be freed at

a

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport)

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+ * later time (only relevant for flow scheduling mode)
+ * @txq: Tx queue to clean
+ * @tx_buf: buffer to store
+ */
+static int
+iecm_stash_flow_sch_buffers(struct iecm_queue *txq, struct iecm_tx_buf

*tx_buf)

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+{
+	struct iecm_adapter *adapter = txq->vport->adapter;
+	struct iecm_tx_buf *shadow_buf;
+
+	shadow_buf = iecm_buf_lifo_pop(&txq->buf_stack);
+	if (!shadow_buf) {

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+		dev_err(&adapter->pdev->dev,
+			"No out-of-order TX buffers left!\n");
+		return -ENOMEM;
+	}
+
+	/* Store buffer params in shadow buffer */
+	shadow_buf->skb = tx_buf->skb;
+	shadow_buf->bytecount = tx_buf->bytecount;
+	shadow_buf->gso_segs = tx_buf->gso_segs;
+	dma_unmap_addr_set(shadow_buf, dma, dma_unmap_addr(tx_buf,

dma));

Quoted 15 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +15 -0
+	dma_unmap_len_set(shadow_buf, len, dma_unmap_len(tx_buf, len));
+	shadow_buf->compl_tag = tx_buf->compl_tag;
+
+	/* Add buffer to buf_hash table to be freed
+	 * later
+	 */
+	hash_add(txq->sched_buf_hash, &shadow_buf->hlist,
+		 shadow_buf->compl_tag);
+
+	memset(tx_buf, 0, sizeof(struct iecm_tx_buf));
+
+	return 0;
+}
+
+/**

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+ * iecm_tx_splitq_clean - Reclaim resources from buffer queue
+ * @tx_q: Tx queue to clean
+ * @end: queue index until which it should be cleaned
+ * @napi_budget: Used to determine if we are in netpoll
+ * @descs_only: true if queue is using flow-based scheduling and should
+ * not clean buffers at this time
+ *
+ * Cleans the queue descriptor ring. If the queue is using queue-based
+ * scheduling, the buffers will be cleaned as well and this function will
+ * return the number of bytes/packets cleaned. If the queue is using flow-

based

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport · line 1846

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +2 -0
+ * scheduling, only the descriptors are cleaned at this time. Separate packet
+ * completion events will be reported on the completion queue, and the

buffers

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport · line 1847

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+ * will be cleaned separately. The stats returned from this function when

using

Quoted 32 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +32 -0
+ * flow-based scheduling are irrelevant.
+ */
+static struct iecm_tx_queue_stats
+iecm_tx_splitq_clean(struct iecm_queue *tx_q, u16 end, int napi_budget,
+		     bool descs_only)
+{
+	union iecm_tx_flex_desc *next_pending_desc = NULL;
+	struct iecm_tx_queue_stats cleaned_stats = {0};
+	union iecm_tx_flex_desc *tx_desc;
+	s16 ntc = tx_q->next_to_clean;
+	struct iecm_tx_buf *tx_buf;
+	unsigned short gso_segs = 0;
+	unsigned int bytecount = 0;
+	struct netdev_queue *nq;
+
+	tx_desc = IECM_FLEX_TX_DESC(tx_q, ntc);
+	next_pending_desc = IECM_FLEX_TX_DESC(tx_q, end);
+	tx_buf = &tx_q->tx_buf[ntc];
+	ntc -= tx_q->desc_count;
+
+	while (tx_desc != next_pending_desc) {
+		union iecm_tx_flex_desc *eop_desc =
+			(union iecm_tx_flex_desc *)tx_buf->next_to_watch;
+
+		/* clear next_to_watch to prevent false hangs */
+		tx_buf->next_to_watch = NULL;
+
+		bytecount += tx_buf->bytecount;
+		gso_segs += tx_buf->gso_segs;
+
+		if (descs_only) {
+			if (iecm_stash_flow_sch_buffers(tx_q, tx_buf))

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+				goto tx_splitq_clean_out;
+
+			while (tx_desc != eop_desc) {
+				tx_buf++;
+				tx_desc++;
+				ntc++;
+				if (unlikely(!ntc)) {
+					ntc -= tx_q->desc_count;
+					tx_buf = tx_q->tx_buf;
+					tx_desc = IECM_FLEX_TX_DESC(tx_q,

0);

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 1902

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +5 -0
+				}
+
+				if (dma_unmap_len(tx_buf, len)) {
+					if (iecm_stash_flow_sch_buffers(tx_q,
+
	tx_buf))

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport · line 1896

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +2 -0
+						goto tx_splitq_clean_out;
+				}

Redundant braces, redundant nested ifs.

Quoted 6 lines

Also, it's actually an error, since dma_unmap_len() always equals 0 for architectures which don't select NEED_DMA_MAP_STATE. So this should either check for any other signs of mapped buffer or field len should be present and defined with correct values unconditionally.

We'll take a look.

Quoted 498 lines
Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +7 -0
+			}
+		} else {
+			/* update the statistics for this packet */
+			cleaned_stats.bytes += tx_buf->bytecount;
+			cleaned_stats.packets += tx_buf->gso_segs;
+
+			iecm_tx_splitq_clean_buf(tx_q, tx_buf, napi_budget);

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+
+			/* unmap remaining buffers */
+			while (tx_desc != eop_desc) {
+				tx_buf++;
+				tx_desc++;
+				ntc++;
+				if (unlikely(!ntc)) {
+					ntc -= tx_q->desc_count;
+					tx_buf = tx_q->tx_buf;
+					tx_desc = IECM_FLEX_TX_DESC(tx_q,

0);

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 1917

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +4 -0
+				}
+
+				/* unmap any remaining paged data */
+				if (dma_unmap_len(tx_buf, len)) {

Same here.

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport · line 1919

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +2 -0
+					dma_unmap_page(tx_q->dev,
+						       dma_unmap_addr(tx_buf,

dma),

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport · line 1920

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+						       dma_unmap_len(tx_buf,

len),

Quoted 21 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +21 -0
+						       DMA_TO_DEVICE);
+					dma_unmap_len_set(tx_buf, len, 0);
+				}
+			}
+		}
+
+		tx_buf++;
+		tx_desc++;
+		ntc++;
+		if (unlikely(!ntc)) {
+			ntc -= tx_q->desc_count;
+			tx_buf = tx_q->tx_buf;
+			tx_desc = IECM_FLEX_TX_DESC(tx_q, 0);
+		}
+	}
+
+tx_splitq_clean_out:
+	ntc += tx_q->desc_count;
+	tx_q->next_to_clean = ntc;
+
+	nq = netdev_get_tx_queue(tx_q->vport->netdev, tx_q->idx);

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+	netdev_tx_completed_queue(nq, gso_segs, bytecount);
+
+	return cleaned_stats;
+}
+
+/**
+ * iecm_tx_clean_flow_sch_bufs - clean bufs that were stored for
+ * out of order completions
+ * @txq: queue to clean
+ * @compl_tag: completion tag of packet to clean (from completion

descriptor)

Quoted 13 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +13 -0
+ * @budget: Used to determine if we are in netpoll
+ */
+static struct iecm_tx_queue_stats
+iecm_tx_clean_flow_sch_bufs(struct iecm_queue *txq, u16 compl_tag,
+			    int budget)
+{
+	struct iecm_tx_queue_stats cleaned_stats = {0};
+	struct hlist_node *tmp_buf = NULL;
+	struct iecm_tx_buf *tx_buf = NULL;
+
+	/* Buffer completion */
+	hash_for_each_possible_safe(txq->sched_buf_hash, tx_buf, tmp_buf,
+				    hlist, compl_tag) {

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 1974

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+		if (tx_buf->compl_tag != compl_tag)
+			continue;
+
+		if (likely(tx_buf->skb)) {
+			/* update the statistics for this packet */
+			cleaned_stats.bytes += tx_buf->bytecount;
+			cleaned_stats.packets += tx_buf->gso_segs;
+
+			iecm_tx_splitq_clean_buf(txq, tx_buf, budget);
+		} else if (dma_unmap_len(tx_buf, len)) {

Here as well.

Quoted 36 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +36 -0
+			dma_unmap_page(txq->dev,
+				       dma_unmap_addr(tx_buf, dma),
+				       dma_unmap_len(tx_buf, len),
+				       DMA_TO_DEVICE);
+			dma_unmap_len_set(tx_buf, len, 0);
+		}
+		/* Push shadow buf back onto stack */
+		iecm_buf_lifo_push(&txq->buf_stack, tx_buf);
+
+		hash_del(&tx_buf->hlist);
+	}
+
+	return cleaned_stats;
+}
+
+/**
+ * iecm_tx_clean_complq - Reclaim resources on completion queue
+ * @complq: Tx ring to clean
+ * @budget: Used to determine if we are in netpoll
+ *
+ * Returns true if there's any budget left (e.g. the clean is finished)
+ */
+static bool
+iecm_tx_clean_complq(struct iecm_queue *complq, int budget)
+{
+	struct iecm_splitq_tx_compl_desc *tx_desc;
+	struct iecm_vport *vport = complq->vport;
+	s16 ntc = complq->next_to_clean;
+	bool clean_completed = false;
+	unsigned int complq_budget;
+
+	complq_budget = vport->compln_clean_budget;
+	tx_desc = IECM_SPLITQ_TX_COMPLQ_DESC(complq, ntc);
+	ntc -= complq->desc_count;
+
+	do {

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+		struct iecm_tx_queue_stats cleaned_stats = {0};
+		struct iecm_queue *tx_q;
+		u16 compl_tag, hw_head;
+		int tx_qid;
+		u8 ctype;	/* completion type */
+		u16 gen;
+
+		/* if the descriptor isn't done, no work yet to do */
+		gen = (le16_to_cpu(tx_desc->qid_comptype_gen) &
+		      IECM_TXD_COMPLQ_GEN_M) >>

IECM_TXD_COMPLQ_GEN_S;

Same stuff about FIELD_{GET,PREP}().

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport)

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+		if (test_bit(__IECM_Q_GEN_CHK, complq->flags) != gen)
+			break;
+
+		/* Find necessary info of TX queue to clean buffers */
+		tx_qid = (le16_to_cpu(tx_desc->qid_comptype_gen) &
+			 IECM_TXD_COMPLQ_QID_M) >>

IECM_TXD_COMPLQ_QID_S;

Here as well, and in other places I missed.

Quoted 49 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +46 -0
+		tx_q = iecm_tx_find_q(vport, tx_qid);
+		if (!tx_q) {
+			dev_err(&complq->vport->adapter->pdev->dev,
+				"TxQ #%d not found\n", tx_qid);
+			goto fetch_next_desc;
+		}
+
+		/* Determine completion type */
+		ctype = (le16_to_cpu(tx_desc->qid_comptype_gen) &
+			IECM_TXD_COMPLQ_COMPL_TYPE_M) >>
+			IECM_TXD_COMPLQ_COMPL_TYPE_S;
+		switch (ctype) {
+		case IECM_TXD_COMPLT_RE:
+			hw_head = le16_to_cpu(tx_desc-
 q_head_compl_tag.q_head);
+
+			cleaned_stats = iecm_tx_splitq_clean(tx_q, hw_head,
+							     budget, true);
+			break;
+		case IECM_TXD_COMPLT_RS:
+			if (test_bit(__IECM_Q_FLOW_SCH_EN, tx_q->flags)) {
+				compl_tag =
+				le16_to_cpu(tx_desc-
 q_head_compl_tag.compl_tag);
+
+				cleaned_stats =
+					iecm_tx_clean_flow_sch_bufs(tx_q,
+								    compl_tag,
+								    budget);
+			} else {
+				hw_head =
+				le16_to_cpu(tx_desc-
 q_head_compl_tag.q_head);
+
+				cleaned_stats = iecm_tx_splitq_clean(tx_q,
+								     hw_head,
+								     budget,
+								     false);
+			}
+
+			break;
+		case IECM_TXD_COMPLT_SW_MARKER:
+			iecm_tx_handle_sw_marker(tx_q);
+			break;
+		default:
+			dev_err(&tx_q->vport->adapter->pdev->dev,
+				"Unknown TX completion type: %d\n",
+				ctype);
+			goto fetch_next_desc;

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport)

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+		}
+
+		u64_stats_update_begin(&tx_q->stats_sync);
+		tx_q->q_stats.tx.packets += cleaned_stats.packets;
+		tx_q->q_stats.tx.bytes += cleaned_stats.bytes;
+		u64_stats_update_end(&tx_q->stats_sync);
+
+		if (unlikely(cleaned_stats.packets &&
+			     netif_carrier_ok(tx_q->vport->netdev) &&
+			     (IECM_DESC_UNUSED(tx_q) >=

IECM_TX_WAKE_THRESH) &&

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff

Quoted 41 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+			     (IECM_TX_BUF_UNUSED(tx_q) >= tx_q->desc_count
Quoted 1 line

2))) {

drivers/net/ethernet/intel/iecm/iecm_txrx.c +35 -0
+			/* Make sure any other threads stopping queue after
+			 * this see new next_to_clean.
+			 */
+			smp_mb();
+			if (tx_q->vport->adapter->state == __IECM_UP &&
+			    __netif_subqueue_stopped(tx_q->vport->netdev,
+						     tx_q->idx)) {
+				netif_wake_subqueue(tx_q->vport->netdev,
+						    tx_q->idx);
+			}
+		}
+
+fetch_next_desc:
+		tx_desc++;
+		ntc++;
+		if (unlikely(!ntc)) {
+			ntc -= complq->desc_count;
+			tx_desc = IECM_SPLITQ_TX_COMPLQ_DESC(complq, 0);
+			change_bit(__IECM_Q_GEN_CHK, complq->flags);
+		}
+
+		prefetch(tx_desc);
+
+		/* update budget accounting */
+		complq_budget--;
+	} while (likely(complq_budget));
+
+	ntc += complq->desc_count;
+	complq->next_to_clean = ntc;
+
+	clean_completed = !!complq_budget;
+
+	return clean_completed;
+}
+
 /**
  * iecm_tx_splitq_build_ctb - populate command tag and size for queue
  * based scheduling descriptors
@@ -2337,6 +2783,940 @@ netdev_tx_t iecm_tx_splitq_start(struct sk_buff

*skb,

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,

Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +5 -0
 	return iecm_tx_splitq_frame(skb, tx_q);
 }
 
+/**
+ * iecm_ptype_to_htype - get a hash type
+ * @decoded: Decoded Rx packet type related fields
+ *
+ * Returns appropriate hash type (such as PKT_HASH_TYPE_L2/L3/L4) to be

used by

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +5 -0
+ * skb_set_hash based on PTYPE as parsed by HW Rx pipeline and is part of
+ * Rx desc.
+ */
+enum
+pkt_hash_types iecm_ptype_to_htype(struct iecm_rx_ptype_decoded

*decoded)

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +4 -0
+{
+	if (!decoded->known)
+		return PKT_HASH_TYPE_NONE;
+	if (decoded->payload_layer == IECM_RX_PTYPE_PAYLOAD_LAYER_PAY2

&&

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
+	    decoded->inner_prot)
+		return PKT_HASH_TYPE_L4;
+	if (decoded->payload_layer == IECM_RX_PTYPE_PAYLOAD_LAYER_PAY2

&&

Quoted 96 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +96 -0
+	    decoded->outer_ip)
+		return PKT_HASH_TYPE_L3;
+	if (decoded->outer_ip == IECM_RX_PTYPE_OUTER_L2)
+		return PKT_HASH_TYPE_L2;
+
+	return PKT_HASH_TYPE_NONE;
+}
+
+/**
+ * iecm_rx_hash - set the hash value in the skb
+ * @rxq: Rx descriptor ring packet is being transacted on
+ * @skb: pointer to current skb being populated
+ * @rx_desc: Receive descriptor
+ * @decoded: Decoded Rx packet type related fields
+ */
+static void
+iecm_rx_hash(struct iecm_queue *rxq, struct sk_buff *skb,
+	     struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc,
+	     struct iecm_rx_ptype_decoded *decoded)
+{
+	u32 hash;
+
+	if (!iecm_is_feature_ena(rxq->vport, NETIF_F_RXHASH))
+		return;
+
+	hash = le16_to_cpu(rx_desc->hash1) |
+	       (rx_desc->ff2_mirrid_hash2.hash2 << 16) |
+	       (rx_desc->hash3 << 24);
+
+	skb_set_hash(skb, hash, iecm_ptype_to_htype(decoded));
+}
+
+/**
+ * iecm_rx_csum - Indicate in skb if checksum is good
+ * @rxq: Rx descriptor ring packet is being transacted on
+ * @skb: pointer to current skb being populated
+ * @csum_bits: checksum fields extracted from the descriptor
+ * @decoded: Decoded Rx packet type related fields
+ *
+ * skb->protocol must be set before this function is called
+ */
+static void iecm_rx_csum(struct iecm_queue *rxq, struct sk_buff *skb,
+			 struct iecm_rx_csum_decoded *csum_bits,
+			 struct iecm_rx_ptype_decoded *decoded)
+{
+	bool ipv4, ipv6;
+
+	/* Start with CHECKSUM_NONE and by default csum_level = 0 */
+	skb->ip_summed = CHECKSUM_NONE;
+
+	/* check if Rx checksum is enabled */
+	if (!iecm_is_feature_ena(rxq->vport, NETIF_F_RXCSUM))
+		return;
+
+	/* check if HW has decoded the packet and checksum */
+	if (!(csum_bits->l3l4p))
+		return;
+
+	ipv4 = (decoded->outer_ip == IECM_RX_PTYPE_OUTER_IP) &&
+	       (decoded->outer_ip_ver == IECM_RX_PTYPE_OUTER_IPV4);
+	ipv6 = (decoded->outer_ip == IECM_RX_PTYPE_OUTER_IP) &&
+	       (decoded->outer_ip_ver == IECM_RX_PTYPE_OUTER_IPV6);
+
+	if (ipv4 && (csum_bits->ipe || csum_bits->eipe))
+		goto checksum_fail;
+
+	if (ipv6 && csum_bits->ipv6exadd)
+		return;
+
+	/* HW checksum will be invalid if vlan stripping is not enabled and
+	 * packet has an outer vlan tag. raw_csum_inv will also not be set
+	 * even though it's invalid.
+	 */
+	if (skb_vlan_tag_present(skb))
+		return;
+
+	/* check for L4 errors and handle packets that were not able to be
+	 * checksummed
+	 */
+	if (csum_bits->l4e)
+		goto checksum_fail;
+
+	/* Only report checksum unnecessary for ICMP, TCP, UDP, or SCTP */
+	switch (decoded->inner_prot) {
+	case IECM_RX_PTYPE_INNER_PROT_ICMP:
+	case IECM_RX_PTYPE_INNER_PROT_TCP:
+	case IECM_RX_PTYPE_INNER_PROT_UDP:
+	case IECM_RX_PTYPE_INNER_PROT_SCTP:
+		skb->ip_summed = CHECKSUM_UNNECESSARY;
+	default:
+		break;
+	}
+	return;
+
+checksum_fail:
+	rxq->vport->port_stats.rx_hw_csum_err++;

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+}
+
+/**
+ * iecm_rx_splitq_extract_csum_bits - Extract checksum bits from descriptor
+ * @rx_desc: receive descriptor
+ * @csum: structure to extract checksum fields
+ *
+ **/
+static void
+iecm_rx_splitq_extract_csum_bits(struct virtchnl2_rx_flex_desc_adv_nic_3

*rx_desc,

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 2934

Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +9 -0
+				 struct iecm_rx_csum_decoded *csum)
+{
+	u8 qword0, qword1;
+
+	qword0 = rx_desc->status_err0_qw0;
+	qword1 = rx_desc->status_err0_qw1;
+
+	csum->ipe = !!(qword1 &
+

BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_XSUM_IPE_S));

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 2934

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +2 -0
+	csum->eipe = !!(qword1 &
+
	BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_XSUM_EIPE_S));

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 2934

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +2 -0
+	csum->l4e = !!(qword1 &
+

BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_XSUM_L4E_S));

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 2934

Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +2 -0
+	csum->l3l4p = !!(qword1 &
+

BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_L3L4P_S));

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 2934

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
+	csum->ipv6exadd =
+			!!(qword0 &
+

BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_IPV6EXADD_S));

Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +8 -0
+	csum->rsc = !!(le16_to_cpu(rx_desc->hdrlen_flags) &
+		       VIRTCHNL2_RX_FLEX_DESC_ADV_RSC_M);
+	csum->raw_csum_inv = !!(le16_to_cpu(rx_desc->ptype_err_fflags0) &
+				BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_FF0_S));
+	csum->raw_csum = le16_to_cpu(rx_desc->misc.raw_cs);
+	csum->pprs = 0;
+}
+

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+/**
+ * iecm_rx_rsc - Set the RSC fields in the skb
+ * @rxq : Rx descriptor ring packet is being transacted on
+ * @skb : pointer to current skb being populated
+ * @rx_desc: Receive descriptor
+ * @decoded: Decoded Rx packet type related fields
+ *
+ * Return 0 on success and error code on failure
+ *
+ * Populate the skb fields with the total number of RSC segments, RSC

payload

Quoted 75 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +75 -0
+ * length and packet type.
+ */
+static int iecm_rx_rsc(struct iecm_queue *rxq, struct sk_buff *skb,
+		       struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc,
+		       struct iecm_rx_ptype_decoded *decoded)
+{
+	u16 rsc_segments, rsc_payload_len;
+	struct tcphdr *tcph;
+	bool ipv4, ipv6;
+
+	if (!decoded->outer_ip)
+		return -EINVAL;
+
+	rsc_payload_len = le16_to_cpu(rx_desc->misc.rscseglen);
+	if (!rsc_payload_len)
+		return -EINVAL;
+
+	ipv4 = (decoded->outer_ip == IECM_RX_PTYPE_OUTER_IP) &&
+		(decoded->outer_ip_ver == IECM_RX_PTYPE_OUTER_IPV4);
+	ipv6 = (decoded->outer_ip == IECM_RX_PTYPE_OUTER_IP) &&
+		(decoded->outer_ip_ver == IECM_RX_PTYPE_OUTER_IPV6);
+
+	if (!(ipv4 ^ ipv6))
+		return -EINVAL;
+
+	rsc_segments = DIV_ROUND_UP(skb->data_len, rsc_payload_len);
+
+	NAPI_GRO_CB(skb)->count = rsc_segments;
+	skb_shinfo(skb)->gso_size = rsc_payload_len;
+
+	skb_reset_network_header(skb);
+
+	if (ipv4) {
+		struct iphdr *ipv4h = ip_hdr(skb);
+
+		skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
+
+		/* Reset and set transport header offset in skb */
+		skb_set_transport_header(skb, sizeof(struct iphdr));
+		tcph = tcp_hdr(skb);
+
+		/* Compute the TCP pseudo header checksum*/
+		tcph->check =
+			~tcp_v4_check(skb->len - skb_transport_offset(skb),
+				      ipv4h->saddr, ipv4h->daddr, 0);
+	} else {
+		struct ipv6hdr *ipv6h = ipv6_hdr(skb);
+
+		skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
+		skb_set_transport_header(skb, sizeof(struct ipv6hdr));
+		tcph = tcp_hdr(skb);
+		tcph->check =
+			~tcp_v6_check(skb->len - skb_transport_offset(skb),
+				      &ipv6h->saddr, &ipv6h->daddr, 0);
+	}
+
+	tcp_gro_complete(skb);
+
+	u64_stats_update_begin(&rxq->stats_sync);
+	rxq->q_stats.rx.rsc_pkts++;
+	u64_stats_update_end(&rxq->stats_sync);
+
+	return 0;
+}
+
+/**
+ * iecm_rx_process_skb_fields - Populate skb header fields from Rx descriptor
+ * @rxq: Rx descriptor ring packet is being transacted on
+ * @skb: pointer to current skb being populated
+ * @rx_desc: Receive descriptor
+ *
+ * This function checks the ring, descriptor, and packet information in
+ * order to populate the hash, checksum, VLAN, protocol, and
+ * other fields within the skb.
+ */
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3025

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+int
+iecm_rx_process_skb_fields(struct iecm_queue *rxq, struct sk_buff *skb,
+			   struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc)
+{
+	struct iecm_rx_ptype_decoded decoded;
+	struct iecm_rx_csum_decoded csum_bits;

Please follow RCT.

Sure will fix.

Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +7 -0
+	u16 rx_ptype;
+	int err = 0;
+
+	rx_ptype = le16_to_cpu(rx_desc->ptype_err_fflags0) &
+				VIRTCHNL2_RX_FLEX_DESC_ADV_PTYPE_M;
+
+	decoded = rxq->vport->rx_ptype_lkup[rx_ptype];
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3037

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +5 -0
+	if (!decoded.known)
+		return -EINVAL;
+
+	/* modifies the skb - consumes the enet header */
+	skb->protocol = eth_type_trans(skb, rxq->vport->netdev);

eth_type_trans() should generally be called *right* before napi_gro_receive() to still have caches warm.

I'm pretty sure this happening here because we need to consume header before messing with checksum stuff but I'll have to dig deeper. Will check.

Quoted 21 lines
Quoted 21 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +21 -0
+	iecm_rx_splitq_extract_csum_bits(rx_desc, &csum_bits);
+	iecm_rx_csum(rxq, skb, &csum_bits, &decoded);
+	/* process RSS/hash */
+	iecm_rx_hash(rxq, skb, rx_desc, &decoded);
+
+	if (csum_bits.rsc)
+		err = iecm_rx_rsc(rxq, skb, rx_desc, &decoded);
+
+	return err;
+}
+
+/**
+ * iecm_rx_skb - Send a completed packet up the stack
+ * @rxq: Rx ring in play
+ * @skb: packet to send up
+ * @vlan_tag: packet vlan tag
+ *
+ * This function sends the completed packet (via. skb) up the stack using
+ * gro receive functions
+ */
+void iecm_rx_skb(struct iecm_queue *rxq, struct sk_buff *skb, u16 vlan_tag)
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3062

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +4 -0
+{
+	/* Adding HW VLAN tag to skb must occur after processing csum */
+	if (vlan_tag & VLAN_VID_MASK)
+		__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlan_tag);

Why can't this be placed into process_skb_fields()? This function becomes redundant then, and you could call napi_gro_receive() directly instead.

Seems reasonable, will try.

Quoted 12 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,

Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +11 -0
+
+	napi_gro_receive(&rxq->q_vector->napi, skb);
+}
+
+/**
+ * iecm_rx_page_is_reserved - check if reuse is possible
+ * @page: page struct to check
+ */
+static bool iecm_rx_page_is_reserved(struct page *page)
+{
+	return (page_to_nid(page) != numa_mem_id()) ||

page_is_pfmemalloc(page);

Quoted 5 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff · line 3074

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

Please check generic dev_page_is_reusable(), it's almost the same (a bit more optimized).

Will check and see if it does what we need.

Quoted 23 lines
Quoted 23 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +22 -0
+
+/**
+ * iecm_rx_buf_adjust_pg - Prepare rx buffer for reuse
+ * @rx_buf: Rx buffer to adjust
+ * @size: Size of adjustment
+ *
+ * Update the offset within page so that rx buf will be ready to be reused.
+ * For systems with PAGE_SIZE < 8192 this function will flip the page offset
+ * so the second half of page assigned to rx buffer will be used, otherwise
+ * the offset is moved by the @size bytes
+ */
+void
+iecm_rx_buf_adjust_pg(struct iecm_rx_buf *rx_buf, unsigned int size)
+{
+	struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf-
 page_indx];
+
+#if (PAGE_SIZE < 8192)
+	if (rx_buf->buf_size > IECM_RX_BUF_2048)
+		/* flip to second page */
+		rx_buf->page_indx = !rx_buf->page_indx;
+	else
+		/* flip page offset to other buffer */
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3101

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +5 -0
+		page_info->page_offset ^= size;
+#else
+	/* move offset up to the next cache line */
+	page_info->page_offset += size;
+#endif

Again, no need for ifdeffery, PAGE_SIZE check can be placed into an if statement.

Sure will fix.

Quoted 37 lines
Quoted 24 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +23 -0
+}
+
+/**
+ * iecm_rx_can_reuse_page - Determine if page can be reused for another rx
+ * @rx_buf: buffer containing the page
+ *
+ * If page is reusable, we have a green light for calling iecm_reuse_rx_page,
+ * which will assign the current buffer to the buffer that next_to_alloc is
+ * pointing to; otherwise, the dma mapping needs to be destroyed and
+ * page freed
+ */
+bool iecm_rx_can_reuse_page(struct iecm_rx_buf *rx_buf)
+{
+	struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf-
 page_indx];
+
+#if (PAGE_SIZE >= 8192)
+	unsigned int last_offset = PAGE_SIZE - rx_buf->buf_size;
+#endif /* PAGE_SIZE < 8192) */
+	unsigned int pagecnt_bias = page_info->pagecnt_bias;
+	struct page *page = page_info->page;
+
+	/* avoid re-using remote pages */
+	if (unlikely(iecm_rx_page_is_reserved(page)))

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3134

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+		return false;
+
+#if (PAGE_SIZE < 8192)
+	/* if we are only owner of page we can reuse it */
+	if (unlikely((page_count(page) - pagecnt_bias) > 1))
+		return false;
+#else
+	if (rx_buf->page_offset > last_offset)
+		return false;
+#endif /* PAGE_SIZE < 8192) */

Same here 2 times.

Quoted 10 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3140

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+
+	/* If we have drained the page fragment pool we need to update
+	 * the pagecnt_bias and page count so that we fully restock the
+	 * number of references the driver holds.
+	 */
+	if (unlikely(pagecnt_bias == 1)) {

With 1532 byte frames, this condition will be hit 50% of times. It's definitely not a good place for unlkely().

I'm afraid I'm not following here, mind elaborating? Keep in mind the buffer is 4k not 2k on MEV.

Quoted 85 lines
Quoted 18 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +18 -0
+		page_ref_add(page, USHRT_MAX - 1);
+		page_info->pagecnt_bias = USHRT_MAX;
+	}
+
+	return true;
+}
+
+/**
+ * iecm_rx_add_frag - Add contents of Rx buffer to sk_buff as a frag
+ * @rx_buf: buffer containing page to add
+ * @skb: sk_buff to place the data into
+ * @size: packet length from rx_desc
+ *
+ * This function will add the data contained in rx_buf->page to the skb.
+ * It will just attach the page as a frag to the skb.
+ * The function will then update the page offset.
+ */
+void iecm_rx_add_frag(struct iecm_rx_buf *rx_buf, struct sk_buff *skb,

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3167

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +9 -0
+		      unsigned int size)
+{
+	struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf-
 page_indx];
+
+#if (PAGE_SIZE >= 8192)
+	unsigned int truesize = SKB_DATA_ALIGN(size);
+#else
+	unsigned int truesize = rx_buf->buf_size;
+#endif

Same.

Quoted 54 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +21 -0
+
+	skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page_info->page,
+			page_info->page_offset, size, truesize);
+
+	iecm_rx_buf_adjust_pg(rx_buf, truesize);
+}
+
+/**
+ * iecm_rx_get_buf_page - Fetch Rx buffer page and synchronize data for use
+ * @dev: device struct
+ * @rx_buf: Rx buf to fetch page for
+ * @size: size of buffer to add to skb
+ *
+ * This function will pull an Rx buffer page from the ring and synchronize it
+ * for use by the CPU.
+ */
+static void
+iecm_rx_get_buf_page(struct device *dev, struct iecm_rx_buf *rx_buf,
+		     const unsigned int size)
+{
+	struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf-

page_indx];

drivers/net/ethernet/intel/iecm/iecm_txrx.c +27 -0
+
+	prefetch(page_info->page);
+
+	/* we are reusing so sync this buffer for CPU use */
+	dma_sync_single_range_for_cpu(dev, page_info->dma,
+				      page_info->page_offset, size,
+				      DMA_FROM_DEVICE);
+
+	/* We have pulled a buffer for use, so decrement pagecnt_bias */
+	page_info->pagecnt_bias--;
+}
+
+/**
+ * iecm_rx_construct_skb - Allocate skb and populate it
+ * @rxq: Rx descriptor queue
+ * @rx_buf: Rx buffer to pull data from
+ * @size: the length of the packet
+ *
+ * This function allocates an skb. It then populates it with the page
+ * data from the current receive descriptor, taking care to set up the
+ * skb correctly.
+ */
+struct sk_buff *
+iecm_rx_construct_skb(struct iecm_queue *rxq, struct iecm_rx_buf *rx_buf,
+		      unsigned int size)
+{
+	struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf-

page_indx];

drivers/net/ethernet/intel/iecm/iecm_txrx.c +4 -0
+
+	void *va = page_address(page_info->page) + page_info->page_offset;
+	unsigned int headlen;
+	struct sk_buff *skb;
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3225

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+
+	/* prefetch first cache line of first page */
+	prefetch(va);
+#if L1_CACHE_BYTES < 128
+	prefetch((u8 *)va + L1_CACHE_BYTES);
+#endif /* L1_CACHE_BYTES */

Here's open-coded net_prefetch().

Will fix.

Quoted 132 lines
Quoted 14 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +14 -0
+	/* allocate a skb to store the frags */
+	skb = __napi_alloc_skb(&rxq->q_vector->napi, IECM_RX_HDR_SIZE,
+			       GFP_ATOMIC | __GFP_NOWARN);
+	if (unlikely(!skb))
+		return NULL;
+
+	skb_record_rx_queue(skb, rxq->idx);
+
+	/* Determine available headroom for copy */
+	headlen = size;
+	if (headlen > IECM_RX_HDR_SIZE)
+		headlen = eth_get_headlen(skb->dev, va, IECM_RX_HDR_SIZE);
+
+	/* align pull length to size of long to optimize memcpy performance */

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3249

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+	memcpy(__skb_put(skb, headlen), va, ALIGN(headlen, sizeof(long)));
+
+	/* if we exhaust the linear part then add what is left as a frag */
+	size -= headlen;
+	if (size) {
+#if (PAGE_SIZE >= 8192)
+		unsigned int truesize = SKB_DATA_ALIGN(size);
+#else
+		unsigned int truesize = rx_buf->buf_size;
+#endif

Again.

Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +9 -0
+		skb_add_rx_frag(skb, 0, page_info->page,
+				page_info->page_offset + headlen, size,
+				truesize);
+		/* buffer is used by skb, update page_offset */
+		iecm_rx_buf_adjust_pg(rx_buf, truesize);
+
+	} else {
+		/* buffer is unused, reset bias back to rx_buf; data was copied
+		 * onto skb's linear part so there's no need for adjusting

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+		 * page offset and we can reuse this buffer as-is
+		 */
+		page_info->pagecnt_bias++;
+	}
+
+	return skb;
+}
+
+/**
+ * iecm_rx_hdr_construct_skb - Allocate skb and populate it from header

buffer

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

Quoted 10 lines

+ * @rxq: Rx descriptor queue
+ * @hdr_buf: Rx buffer to pull data from
+ * @size: the length of the packet
+ *
+ * This function allocates an skb. It then populates it with the page data from
+ * the current receive descriptor, taking care to set up the skb correctly.
+ * This specifcally uses a header buffer to start building the skb.
+ */

drivers/net/ethernet/intel/iecm/iecm_txrx.c +2 -0
+static struct sk_buff *
+iecm_rx_hdr_construct_skb(struct iecm_queue *rxq, struct iecm_dma_mem

*hdr_buf,

Quoted 30 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +30 -0
+			  unsigned int size)
+{
+	struct sk_buff *skb;
+
+	/* allocate a skb to store the frags */
+	skb = __napi_alloc_skb(&rxq->q_vector->napi, IECM_RX_HDR_SIZE,
+			       GFP_ATOMIC | __GFP_NOWARN);
+	if (unlikely(!skb))
+		return NULL;
+
+	skb_record_rx_queue(skb, rxq->idx);
+
+	memcpy(__skb_put(skb, size), hdr_buf->va, size);
+
+	return skb;
+}
+
+/**
+ * iecm_rx_splitq_test_staterr - tests bits in Rx descriptor
+ * status and error fields
+ * @stat_err_field: field from descriptor to test bits in
+ * @stat_err_bits: value to mask
+ *
+ */
+bool
+iecm_rx_splitq_test_staterr(u8 stat_err_field, const u8 stat_err_bits)
+{
+	return !!(stat_err_field & stat_err_bits);
+}
+

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+/**
+ * iecm_rx_splitq_extract_vlan_tag - Extract vlan tag from the descriptor
+ * @desc: Rx flex descriptor
+ * @rxq: rxq to check the vlan flags
+ * @vlan_tag: vlan tag to fill in
+ *
+ * Return true if error bit is set in the descriptor, else return false and
+ * store the vlan_tag in the variable passed in the function parameters
+ */
+bool iecm_rx_splitq_extract_vlan_tag(struct

virtchnl2_rx_flex_desc_adv_nic_3 *desc,

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,

Quoted 12 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +12 -0
+				     struct iecm_queue *rxq, u16 *vlan_tag)
+{
+	u8 stat_err0_qw0, stat_err_bits, stat_err1;
+
+	stat_err_bits = BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_RXE_S);
+	stat_err0_qw0 = desc->status_err0_qw0;
+	if (unlikely(iecm_rx_splitq_test_staterr(stat_err0_qw0, stat_err_bits)))
+		return true;
+
+	stat_err1 = desc->status_err1;
+
+	if (stat_err0_qw0 &

BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_L2TAG1P_S) &&

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
+	    test_bit(__IECM_Q_VLAN_TAG_LOC_L2TAG1, rxq->flags))
+		*vlan_tag = le16_to_cpu(desc->l2tag1);
+	if (stat_err1 &

BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS1_L2TAG2P_S) &&

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +5 -0
+	    test_bit(__IECM_Q_VLAN_TAG_LOC_L2TAG2, rxq->flags))
+		*vlan_tag = le16_to_cpu(desc->l2tag2);
+
+	return false;
+}

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+
+/**
+ * iecm_rx_splitq_is_non_eop - process handling of non-EOP buffers
+ * @rx_desc: Rx descriptor for current buffer
+ *
+ * If the buffer is an EOP buffer, this function exits returning false,
+ * otherwise return true indicating that this is in fact a non-EOP buffer.
+ */
+static bool
+iecm_rx_splitq_is_non_eop(struct virtchnl2_rx_flex_desc_adv_nic_3

*rx_desc)

Quoted 8 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
+{
+	/* if we are the last buffer then there is nothing else to do */
+#define IECM_RXD_EOF

BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_EOF_S)

This is a wrong place to define anything, it can be easily overlooked.

Sure will fix.

Quoted 10 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3356

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +5 -0
+	if (likely(iecm_rx_splitq_test_staterr(rx_desc->status_err0_qw1,
+					       IECM_RXD_EOF)))
+		return false;
+
+	return true;

This can be converted to an one-liner

	return likely(...);

Will fix.

Quoted 48 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,

Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +9 -0
+}
+
+/**
+ * iecm_rx_splitq_recycle_buf - Attempt to recycle or realloc buffer
+ * @rxbufq: receive queue
+ * @rx_buf: Rx buffer to pull data from
+ *
+ * This function will clean up the contents of the rx_buf. It will either
+ * recycle the buffer or unmap it and free the associated resources. The

buffer

Quoted 15 lines

+ * will then be placed on a refillq where it will later be reclaimed by the
+ * corresponding bufq.
+ *
+ * This works based on page flipping. If we assume e.g., a 4k page, it will be
+ * divided into two 2k buffers. We post the first half to hardware and, after
+ * using it, flip to second half of the page with iecm_adjust_pg_offset and
+ * post that to hardware. The third time through we'll flip back to first half
+ * of page and check if stack is still using it, if not we can reuse the buffer
+ * as is, otherwise we'll drain it and get a new page.
+ */

drivers/net/ethernet/intel/iecm/iecm_txrx.c +4 -0
+static void iecm_rx_splitq_recycle_buf(struct iecm_queue *rxbufq,
+				       struct iecm_rx_buf *rx_buf)
+{
+	struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf-

page_indx];

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +4 -0
+
+	if (!iecm_rx_can_reuse_page(rx_buf)) {
+		/* we are not reusing the buffer so unmap it */
+		dma_unmap_page_attrs(rxbufq->dev, page_info->dma,

PAGE_SIZE,

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

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+				     DMA_FROM_DEVICE,

IECM_RX_DMA_ATTR);

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +5 -0
+		__page_frag_cache_drain(page_info->page,
+					page_info->pagecnt_bias);
+
+		/* clear contents of buffer_info */
+		page_info->page = NULL;

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+		rx_buf->skb = NULL;
+
+		/* It's possible the alloc can fail here but there's not much
+		 * we can do, bufq will have to try and realloc to fill the
+		 * hole.
+		 */
+		iecm_alloc_page(rxbufq, page_info);
+	}
+
+	/* We sync the memory back to hardware now to do as much work in

this

Quoted 13 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3408

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +5 -0
+	 * context as feasible.  Hardware won't actually know about the buffer
+	 * until it's reclaimed off the refillq and put back into the bufq.
+	 */
+	if (likely(page_info->page)) {
+		dma_sync_single_range_for_device(rxbufq->dev, page_info-

dma,

drivers/net/ethernet/intel/iecm/iecm_txrx.c +4 -0
+						 page_info->page_offset,
+						 rxbufq->rx_buf_size,
+						 DMA_FROM_DEVICE);
+	}

One-liner, braces are redundant.

Will not fix.

Quoted 14 lines
Quoted 1 line

+}

Here you set page_info->page to NULL in the first condition branch and check for it in the second.
So it's equivalent to

	if (iecm_rx_can_reuse_page(rx_buf)) {
		dma_sync_single_range();
		return;
	}

	/* we are not reusing the buffer ... */
	...
Quoted 2 lines

but saves 1 indent level and generally more readable.

Will fix.

Quoted 182 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3417

Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +8 -0
+
+/**
+ * iecm_rx_bump_ntc - Bump and wrap q->next_to_clean value
+ * @q: queue to bump
+ */
+void iecm_rx_bump_ntc(struct iecm_queue *q)
+{
+	u16 ntc = q->next_to_clean + 1;

There should be an empty line (between variable declarations and function body). checkpatch should've mentioned this.

Quoted 36 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +36 -0
+	/* fetch, update, and store next to clean */
+	if (ntc < q->desc_count) {
+		q->next_to_clean = ntc;
+	} else {
+		q->next_to_clean = 0;
+		change_bit(__IECM_Q_GEN_CHK, q->flags);
+	}
+}
+
+/**
+ * iecm_rx_splitq_clean - Clean completed descriptors from Rx queue
+ * @rxq: Rx descriptor queue to retrieve receive buffer queue
+ * @budget: Total limit on number of packets to process
+ *
+ * This function provides a "bounce buffer" approach to Rx interrupt
+ * processing. The advantage to this is that on systems that have
+ * expensive overhead for IOMMU access this provides a means of avoiding
+ * it by maintaining the mapping of the page to the system.
+ *
+ * Returns amount of work completed
+ */
+static int iecm_rx_splitq_clean(struct iecm_queue *rxq, int budget)
+{
+	int total_rx_bytes = 0, total_rx_pkts = 0;
+	struct iecm_queue *rx_bufq = NULL;
+	struct sk_buff *skb = rxq->skb;
+	bool failure = false;
+
+	/* Process Rx packets bounded by budget */
+	while (likely(total_rx_pkts < budget)) {
+		struct virtchnl2_rx_flex_desc_adv_nic_3 *splitq_flex_rx_desc;
+		struct iecm_sw_queue *refillq = NULL;
+		struct iecm_dma_mem *hdr_buf = NULL;
+		struct iecm_rxq_set *rxq_set = NULL;
+		struct iecm_rx_buf *rx_buf = NULL;
+		u16 gen_id, buf_id, vlan_tag = 0;

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+		union virtchnl2_rx_desc *rx_desc;
+		unsigned int pkt_len = 0;
+		unsigned int hdr_len = 0;
+		 /* Header buffer overflow only valid for header split */
+		bool hbo = false;
+		int bufq_id;
+
+		/* get the Rx desc from Rx queue based on 'next_to_clean' */
+		rx_desc = IECM_RX_DESC(rxq, rxq->next_to_clean);
+		splitq_flex_rx_desc = (struct virtchnl2_rx_flex_desc_adv_nic_3

*)rx_desc;

Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +8 -0
+
+		/* This memory barrier is needed to keep us from reading
+		 * any other fields out of the rx_desc
+		 */
+		dma_rmb();
+
+		/* if the descriptor isn't done, no work yet to do */
+		gen_id = le16_to_cpu(splitq_flex_rx_desc-

pktlen_gen_bufq_id);

drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+		gen_id = (gen_id & VIRTCHNL2_RX_FLEX_DESC_ADV_GEN_M)
Quoted 1 line
Quoted 1 line

+

	VIRTCHNL2_RX_FLEX_DESC_ADV_GEN_S;

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +5 -0
+		if (test_bit(__IECM_Q_GEN_CHK, rxq->flags) != gen_id)
+			break;
+
+		if ((splitq_flex_rx_desc->rxdid_ucast &
+		    VIRTCHNL2_RX_FLEX_DESC_ADV_RXDID_M) !=

VIRTCHNL2_RXDID_1_FLEX_SPLITQ) {

Quoted 24 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+			iecm_rx_bump_ntc(rxq);
+			rxq->vport->port_stats.rx_bad_descs++;
+			continue;
+		}
+
+		pkt_len = le16_to_cpu(splitq_flex_rx_desc-

pktlen_gen_bufq_id) &

drivers/net/ethernet/intel/iecm/iecm_txrx.c +16 -0
+			  VIRTCHNL2_RX_FLEX_DESC_ADV_LEN_PBUF_M;
+
+		hbo = splitq_flex_rx_desc->status_err0_qw1 &
+		      BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_HBO_S);
+
+		if (unlikely(hbo)) {
+			rxq->vport->port_stats.rx_hsplit_hbo++;
+			goto bypass_hsplit;
+		}
+
+		hdr_len =
+			le16_to_cpu(splitq_flex_rx_desc->hdrlen_flags) &
+			VIRTCHNL2_RX_FLEX_DESC_ADV_LEN_HDR_M;
+
+bypass_hsplit:
+		bufq_id = le16_to_cpu(splitq_flex_rx_desc-

pktlen_gen_bufq_id);

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

Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+		bufq_id = (bufq_id &

VIRTCHNL2_RX_FLEX_DESC_ADV_BUFQ_ID_M) >>

Quoted 12 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +12 -0
+			  VIRTCHNL2_RX_FLEX_DESC_ADV_BUFQ_ID_S;
+
+		rxq_set = container_of(rxq, struct iecm_rxq_set, rxq);
+		if (!bufq_id)
+			refillq = rxq_set->refillq0;
+		else
+			refillq = rxq_set->refillq1;
+
+		/* retrieve buffer from the rxq */
+		rx_bufq = &rxq->rxq_grp->splitq.bufq_sets[bufq_id].bufq;
+
+		buf_id = le16_to_cpu(splitq_flex_rx_desc->buf_id);

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+
+		if (pkt_len) {
+			rx_buf = &rx_bufq->rx_buf.buf[buf_id];
+			iecm_rx_get_buf_page(rx_bufq->dev, rx_buf, pkt_len);
+		}
+
+		if (hdr_len) {
+			hdr_buf = rx_bufq->rx_buf.hdr_buf[buf_id];
+
+			dma_sync_single_for_cpu(rxq->dev, hdr_buf->pa,

hdr_buf->size,

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
+						DMA_FROM_DEVICE);
+
+			skb = iecm_rx_hdr_construct_skb(rxq, hdr_buf,

hdr_len);

Quoted 18 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +18 -0
+			rxq->vport->port_stats.rx_hsplit++;
+		}
+
+		if (pkt_len) {
+			if (skb)
+				iecm_rx_add_frag(rx_buf, skb, pkt_len);
+			else
+				skb = iecm_rx_construct_skb(rxq, rx_buf,
+							    pkt_len);
+		}
+
+		/* exit if we failed to retrieve a buffer */
+		if (!skb) {
+			/* If we fetched a buffer, but didn't use it
+			 * undo pagecnt_bias decrement
+			 */
+			if (rx_buf)
+				rx_buf->page_info[rx_buf-
Quoted 1 line

page_indx].pagecnt_bias++;

Line of 85 cols here.

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +5 -0
+			break;
+		}
+
+		if (rx_buf)
+			iecm_rx_splitq_recycle_buf(rx_bufq, rx_buf);

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3559

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+		iecm_rx_post_buf_refill(refillq, buf_id);
+
+		iecm_rx_bump_ntc(rxq);
+		/* skip if it is non EOP desc */
+		if (iecm_rx_splitq_is_non_eop(splitq_flex_rx_desc))
+			continue;
+
+		/* extract vlan tag from the descriptor */
+		if (unlikely(iecm_rx_splitq_extract_vlan_tag(splitq_flex_rx_desc,
+							     rxq, &vlan_tag))) {

81 and 81 respectively.

Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +11 -0
+			dev_kfree_skb_any(skb);
+			skb = NULL;
+			continue;
+		}
+
+		/* pad skb if needed (to make valid ethernet frame) */
+		if (eth_skb_pad(skb)) {
+			skb = NULL;
+			continue;
+		}
+
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3576

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+		/* probably a little skewed due to removing CRC */
+		total_rx_bytes += skb->len;
+
+		/* protocol */
+		if (unlikely(iecm_rx_process_skb_fields(rxq, skb,
+							splitq_flex_rx_desc))) {

You can define variables with shorter names to avoid this.

The only variable I see here with a questionably long name is splitq_flex_rx_desc but I don't see a way to shorten it without losing information. Note 'rx_desc' is also a variable that exists in this context and splitq_base_rx_desc could conceivably also exist so splitq_rx_desc doesn't work.

Quoted 42 lines
Quoted 22 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +22 -0
+			dev_kfree_skb_any(skb);
+			skb = NULL;
+			continue;
+		}
+
+		/* send completed skb up the stack */
+		iecm_rx_skb(rxq, skb, vlan_tag);
+		skb = NULL;
+
+		/* update budget accounting */
+		total_rx_pkts++;
+	}
+	rxq->skb = skb;
+	u64_stats_update_begin(&rxq->stats_sync);
+	rxq->q_stats.rx.packets += total_rx_pkts;
+	rxq->q_stats.rx.bytes += total_rx_bytes;
+	u64_stats_update_end(&rxq->stats_sync);
+
+	/* guarantee a trip back through this routine if there was a failure */
+	return unlikely(failure) ? budget : total_rx_pkts;
+}
+

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+/**
+ * iecm_rx_update_bufq_desc - Update buffer queue descriptor
+ * @bufq: Pointer to the buffer queue
+ * @desc: Refill queue descriptor
+ * @buf_desc: Buffer queue descriptor
+ *
+ * Return 0 on success and negative on failure.
+ */
+static int iecm_rx_update_bufq_desc(struct iecm_queue *bufq, u16 *desc,
+				    struct virtchnl2_splitq_rx_buf_desc

*buf_desc)

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3614

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+{
+	struct iecm_page_info *page_info;
+	struct iecm_rx_buf *buf;
+	u16 buf_id;
+
+	buf_id = ((*desc) & IECM_RX_BI_BUFID_M) >> IECM_RX_BI_BUFID_S;

FIELD_GET().

Quoted 14 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3625

Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +11 -0
+
+	buf = &bufq->rx_buf.buf[buf_id];
+	page_info = &buf->page_info[buf->page_indx];
+
+	/* It's possible page alloc failed during rxq clean, try to
+	 * recover here.
+	 */
+	if (unlikely(!page_info->page)) {
+		if (iecm_alloc_page(bufq, page_info))
+			return -ENOMEM;
+	}

if (1 && 2).

Will fix

Quoted 9 lines
Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1 -0
+	buf_desc->pkt_addr = cpu_to_le64(page_info->dma + page_info-

page_offset);

drivers/net/ethernet/intel/iecm/iecm_txrx.c +4 -0
+	buf_desc->qword0.buf_id = cpu_to_le16(buf_id);
+
+	if (bufq->rx_hsplit_en) {
+		struct iecm_dma_mem *hdr_buf = bufq-

rx_buf.hdr_buf[buf_id];

drivers/net/ethernet/intel/iecm/iecm_txrx.c +2 -0
+
+		buf_desc->hdr_addr = cpu_to_le64(hdr_buf->pa);
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3635

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
+		dma_sync_single_for_device(bufq->dev, hdr_buf->pa,
+					   hdr_buf->size, DMA_FROM_DEVICE);
+	}
	if (!hsplit_en)
		return 0;

	hdr_buf = ...

Will fix

Quoted 163 lines
Quoted 19 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +19 -0
+
+	return 0;
+}
+
+/**
+ * iecm_rx_clean_refillq - Clean refill queue buffers
+ * @bufq: buffer queue to post buffers back to
+ * @refillq: refill queue to clean
+ *
+ * This function takes care of the buffer refill management
+ */
+static void iecm_rx_clean_refillq(struct iecm_queue *bufq,
+				  struct iecm_sw_queue *refillq)
+{
+	struct virtchnl2_splitq_rx_buf_desc *buf_desc;
+	u16 refillq_ntc = refillq->next_to_clean;
+	u16 bufq_nta = bufq->next_to_alloc;
+	u16 *refill_desc;
+	int cleaned = 0;

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+	u16 gen;
+
+	refill_desc = IECM_SPLITQ_RX_BI_DESC(refillq, refillq_ntc);
+	buf_desc = IECM_SPLITQ_RX_BUF_DESC(bufq, bufq_nta);
+
+	/* make sure we stop at ring wrap in the unlikely case ring is full */
+	while (likely(cleaned < refillq->desc_count)) {
+		bool failure;
+
+		gen = ((*refill_desc) & IECM_RX_BI_GEN_M) >>

IECM_RX_BI_GEN_S;

FIELD_GET().

Quoted 30 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +30 -0
+		if (test_bit(__IECM_RFLQ_GEN_CHK, refillq->flags) != gen)
+			break;
+
+		failure = iecm_rx_update_bufq_desc(bufq, refill_desc,
+						   buf_desc);
+		if (failure)
+			break;
+
+		refillq_ntc++;
+		refill_desc++;
+		bufq_nta++;
+		buf_desc++;
+		cleaned++;
+
+		if (unlikely(refillq_ntc == refillq->desc_count)) {
+			change_bit(__IECM_RFLQ_GEN_CHK, refillq->flags);
+			refill_desc = IECM_SPLITQ_RX_BI_DESC(refillq, 0);
+			refillq_ntc = 0;
+		}
+		if (unlikely(bufq_nta == bufq->desc_count)) {
+			buf_desc = IECM_SPLITQ_RX_BUF_DESC(bufq, 0);
+			bufq_nta = 0;
+		}
+	}
+
+	if (cleaned) {
+		/* only update hardware tail in strides */
+		if (((bufq->next_to_use <= bufq_nta ? 0 : bufq->desc_count) +
+		    bufq_nta - bufq->next_to_use) >= bufq->rx_buf_stride)
+			iecm_rx_buf_hw_update(bufq, bufq_nta & ~(bufq-
Quoted 1 line

rx_buf_stride - 1));

92 chars.

drivers/net/ethernet/intel/iecm/iecm_txrx.c iecm_vport_intr_napi_ena_all(struct iecm_vport

Quoted 29 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +25 -0
+
+		/* update next to alloc since we have filled the ring */
+		refillq->next_to_clean = refillq_ntc;
+		bufq->next_to_alloc = bufq_nta;
+	}
+}
+
+/**
+ * iecm_rx_clean_refillq_all - Clean all refill queues
+ * @bufq: bufq with refillqs to clean
+ *
+ * Iterates through all refill queues assigned to the buffer queue assigned to
+ * this vector.  Returns true if clean is complete within budget, false
+ * otherwise.
+ */
+static void iecm_rx_clean_refillq_all(struct iecm_queue *bufq)
+{
+	struct iecm_bufq_set *bufq_set;
+	int i = 0;
+
+	bufq_set = container_of(bufq, struct iecm_bufq_set, bufq);
+	for (i = 0; i < bufq_set->num_refillqs; i++)
+		iecm_rx_clean_refillq(bufq, &bufq_set->refillqs[i]);
+}
+
 /**
  * iecm_vport_intr_clean_queues - MSIX mode Interrupt Handler
  * @irq: interrupt number
@@ -2742,6 +4122,64 @@ iecm_vport_intr_napi_ena_all(struct iecm_vport

*vport)

drivers/net/ethernet/intel/iecm/iecm_txrx.c iecm_vport_intr_napi_ena_all(struct iecm_vport

Quoted 65 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +58 -0
 	}
 }
 
+/**
+ * iecm_tx_splitq_clean_all- Clean completetion queues
+ * @q_vec: queue vector
+ * @budget: Used to determine if we are in netpoll
+ *
+ * Returns false if clean is not complete else returns true
+ */
+static bool
+iecm_tx_splitq_clean_all(struct iecm_q_vector *q_vec, int budget)
+{
+	bool clean_complete = true;
+	int i, budget_per_q;
+
+	budget_per_q = max(budget / q_vec->num_txq, 1);
+	for (i = 0; i < q_vec->num_txq; i++) {
+		if (!iecm_tx_clean_complq(q_vec->tx[i], budget_per_q))
+			clean_complete = false;
+	}
+	return clean_complete;
+}
+
+/**
+ * iecm_rx_splitq_clean_all- Clean completetion queues
+ * @q_vec: queue vector
+ * @budget: Used to determine if we are in netpoll
+ * @cleaned: returns number of packets cleaned
+ *
+ * Returns false if clean is not complete else returns true
+ */
+static bool
+iecm_rx_splitq_clean_all(struct iecm_q_vector *q_vec, int budget,
+			 int *cleaned)
+{
+	bool clean_complete = true;
+	int pkts_cleaned = 0;
+	int i, budget_per_q;
+
+	budget_per_q = max(budget / q_vec->num_rxq, 1);
+	for (i = 0; i < q_vec->num_rxq; i++) {
+		struct iecm_queue *rxq = q_vec->rx[i];
+		int pkts_cleaned_per_q;
+
+		pkts_cleaned_per_q = iecm_rx_splitq_clean(rxq, budget_per_q);
+		/* if we clean as many as budgeted, we must not
+		 * be done
+		 */
+		if (pkts_cleaned_per_q >= budget_per_q)
+			clean_complete = false;
+		pkts_cleaned += pkts_cleaned_per_q;
+	}
+	*cleaned = pkts_cleaned;
+
+	for (i = 0; i < q_vec->num_bufq; i++)
+		iecm_rx_clean_refillq_all(q_vec->bufq[i]);
+
+	return clean_complete;
+}
+
 /**
  * iecm_vport_splitq_napi_poll - NAPI handler
  * @napi: struct from which you get q_vector
@@ -2749,8 +4187,34 @@ iecm_vport_intr_napi_ena_all(struct iecm_vport

*vport)

Quoted 11 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c iecm_vport_intr_napi_ena_all(struct iecm_vport *vport) · line 4191

Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +2 -2
  */
 static int iecm_vport_splitq_napi_poll(struct napi_struct *napi, int budget)
 {
-	/* stub */
-	return 0;
+	struct iecm_q_vector *q_vector =
+				container_of(napi, struct iecm_q_vector, napi);

You can assign it later (before clean_complete assignment) to avoid this.

To avoid the word wrap? I'm not sure I see the difference between letting it wrap and assigning it on it's own line.

Quoted 101 lines

Review

Quoted 30 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +26 -0
+	bool clean_complete;
+	int work_done = 0;
+
+	clean_complete = iecm_tx_splitq_clean_all(q_vector, budget);
+
+	/* Handle case where we are called by netpoll with a budget of 0 */
+	if (budget <= 0)
+		return budget;
+
+	/* We attempt to distribute budget to each Rx queue fairly, but don't
+	 * allow the budget to go below 1 because that would exit polling early.
+	 */
+	clean_complete |= iecm_rx_splitq_clean_all(q_vector, budget,
+						   &work_done);
+
+	/* If work not completed, return budget and polling will return */
+	if (!clean_complete)
+		return budget;
+
+	/* Exit the polling mode, but don't re-enable interrupts if stack might
+	 * poll us due to busy-polling
+	 */
+	if (likely(napi_complete_done(napi, work_done)))
+		iecm_vport_intr_update_itr_ena_irq(q_vector);
+
+	return min_t(int, work_done, budget - 1);
 }
 
 /**
(quoted diff) +0 -0

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

Review

Quoted 15 lines

index a655e797f457..3cf2a2f0cb0f 100644

drivers/net/ethernet/intel/include/iecm.h +4 -0
@@ -12,6 +12,10 @@
 #include <linux/etherdevice.h>
 #include <linux/ethtool.h>
 #include <net/tcp.h>
+#include <net/ip6_checksum.h>
+#include <net/ipv6.h>
+#include <net/sch_generic.h>
+#include <net/gro.h>
 #include <linux/version.h>
 #include <linux/dim.h>
 
(quoted diff) +0 -0

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

drivers/net/ethernet/intel/include/iecm_txrx.h void iecm_vport_calc_total_qs(struct iecm_adapter

Quoted 4 lines

index 7ec742fd4c6b..086b0efc989a 100644

drivers/net/ethernet/intel/include/iecm_txrx.h +0 -0
@@ -638,6 +638,7 @@ void iecm_vport_calc_total_qs(struct iecm_adapter

*adapter,

drivers/net/ethernet/intel/include/iecm_txrx.h int iecm_vport_intr_init(struct iecm_vport *vport); · line 655

Quoted 13 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +3 -0
 			      struct virtchnl2_create_vport *vport_msg);
 void iecm_vport_calc_num_q_groups(struct iecm_vport *vport);
 int iecm_vport_queues_alloc(struct iecm_vport *vport);
+void iecm_rx_post_buf_refill(struct iecm_sw_queue *refillq, u16 buf_id);
 void iecm_vport_queues_rel(struct iecm_vport *vport);
 void iecm_vport_calc_num_q_vec(struct iecm_vport *vport);
 void iecm_vport_intr_rel(struct iecm_vport *vport);
@@ -650,14 +651,33 @@ int iecm_vport_intr_init(struct iecm_vport *vport);
 irqreturn_t
 iecm_vport_intr_clean_queues(int __always_unused irq, void *data);
 void iecm_vport_intr_ena_irq_all(struct iecm_vport *vport);
+enum
+pkt_hash_types iecm_ptype_to_htype(struct iecm_rx_ptype_decoded

*decoded);

drivers/net/ethernet/intel/include/iecm_txrx.h int iecm_vport_intr_init(struct iecm_vport *vport);

Quoted 13 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +8 -0
 int iecm_config_rss(struct iecm_vport *vport);
 void iecm_fill_dflt_rss_lut(struct iecm_vport *vport);
 int iecm_init_rss(struct iecm_vport *vport);
 void iecm_deinit_rss(struct iecm_vport *vport);
+bool iecm_rx_can_reuse_page(struct iecm_rx_buf *rx_buf);
+void iecm_rx_buf_adjust_pg(struct iecm_rx_buf *rx_buf, unsigned int size);
+void iecm_rx_add_frag(struct iecm_rx_buf *rx_buf, struct sk_buff *skb,
+		      unsigned int size);
+struct sk_buff *iecm_rx_construct_skb(struct iecm_queue *rxq,
+				      struct iecm_rx_buf *rx_buf,
+				      unsigned int size);
+void iecm_rx_skb(struct iecm_queue *rxq, struct sk_buff *skb, u16 vlan_tag);
 bool iecm_init_rx_buf_hw_alloc(struct iecm_queue *rxq, struct iecm_rx_buf

*buf);

drivers/net/ethernet/intel/include/iecm_txrx.h int iecm_vport_intr_init(struct iecm_vport *vport);

Quoted 10 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +7 -0
 void iecm_rx_buf_hw_update(struct iecm_queue *rxq, u32 val);
 void iecm_tx_buf_hw_update(struct iecm_queue *tx_q, u32 val,
 			   bool xmit_more);
+void iecm_rx_splitq_put_bufs(struct iecm_queue *rx_bufq,
+			     struct iecm_rx_buf *hdr_buf,
+			     struct iecm_rx_buf *rx_buf);
+bool iecm_rx_splitq_test_staterr(u8 stat_err_field, const u8 stat_err_bits);
+int iecm_rx_process_skb_fields(struct iecm_queue *rxq, struct sk_buff *skb,
+			       struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc);
+bool iecm_rx_splitq_extract_vlan_tag(struct

virtchnl2_rx_flex_desc_adv_nic_3 *desc,

Quoted 7 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +2 -1
+				     struct iecm_queue *rxq, u16 *vlan_tag);
+void iecm_rx_bump_ntc(struct iecm_queue *q);
 void iecm_tx_buf_rel(struct iecm_queue *tx_q, struct iecm_tx_buf *tx_buf);
 unsigned int iecm_size_to_txd_count(unsigned int size);
 unsigned int iecm_tx_desc_count_required(struct sk_buff *skb);
--

2.33.0

Thanks,
Al

#57 lore raw

PATCH 13/19 iecm: implement splitq napi_poll

From: Alan Brady <[email protected]>
Date: Thu, 3 Feb 2022 02:07:08 +0100

Quoted 21 lines
Quoted 21 lines

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

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

Quoted 7 lines

This adds everything we need to actually receive packets and process spent buffers using the splitq model. This contrasts to more traditional queueing models by essentially splitting a normal queue of descriptors and mapped buffers into separate queues. This allows us to deal with both more efficiently and also allows us to implement asymmetric queuing setups where you have multiple completion queues associated with a single buffer queue.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
---
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   | 1468 ++++++++++++++++-
 drivers/net/ethernet/intel/include/iecm.h     |    4 +
 .../net/ethernet/intel/include/iecm_txrx.h    |   20 +
 3 files changed, 1490 insertions(+), 2 deletions(-)

--- 8< ---

Quoted 11 lines
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c iecm_rx_buf_hw_alloc_all(struct iecm_queue *rxbufq, u16 alloc_count) · line 859

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +5 -0
+	bi = IECM_SPLITQ_RX_BI_DESC(refillq, nta);
+	/* store the buffer ID and the SW maintained GEN bit to the refillq */
+	*bi = ((buf_id << IECM_RX_BI_BUFID_S) & IECM_RX_BI_BUFID_M) |
+	      (!!(test_bit(__IECM_Q_GEN_CHK, refillq->flags)) <<
+	       IECM_RX_BI_GEN_S);

Please use FIELD_GET() and FIELD_PREP() for masks. This won't pass the maintainers.

We've never had a problem before, I'm assuming these are new? Will check.

Ok, maybe "won't pass" is not quite correct, but at least "can provoke questions". It depends on a reviewer, e.g. I generally discourage those when it coule be just

	*bi = FIELD_PREP(IECM_RX_BI_BUFID_M, buf_id) |
	      FIELD_PREP(IECM_RX_BI_GEN_M,
			 test_bit(__IECM_Q_GEN_CHK, refillq->flags));

or even

(somewhere near the _M/_S definitions)

#define iecm_rx_bi_prep(gen, id)	\
	(FIELD_PREP(IECM_RX_BI_BUFID_M, id) | FIELD_PREP(IECM_RX_BI_GEN_M, gen))

(inside the function itself)

	*bi = iecm_rx_bi_prep(test_bit(__IECM_Q_GEN_CHK, refillq->flags),
			      buf_id);

Note that there's no !! before test_bit() since it's boolean already.
There's nothing bad in introducing macros and/or static inlines to make the functions themselves more compact and readable. Those (value << SOME_KIND_OF_A_FIELD_S) & SOME_KIND_OF_A_FIELD_M each time we need to load or store from/to registers or descriptors don't make any sense to me.

Quoted 9 lines
Quoted 7 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c iecm_rx_buf_hw_alloc_all(struct iecm_queue *rxbufq, u16 alloc_count) · line 862

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
+
+	nta++;
+	if (unlikely(nta == refillq->desc_count)) {

Could be compressed into one line.

Could be, but we'd prefer not to.

Just a personal preference to consider, no pressure at all.

Quoted 3 lines
Quoted 3 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c iecm_rx_buf_hw_alloc_all(struct iecm_queue *rxbufq, u16 alloc_count) · line 864

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +2 -0
+		nta = 0;
+		change_bit(__IECM_Q_GEN_CHK, refillq->flags);

--- 8< ---

Quoted 14 lines
Quoted 6 lines
	for (i = ...)
		if (vport->txqs[i].q_id == q_id)
			return tx_q;

No need to create a variable.

It would actually look like

(quoted diff) +0 -0
 	for (i = ...)
 		if (vport->txqs[i]->q_id == q_id)
 			return vport->txqs[i];
Quoted 1 line

You had another comment about adding a vc_ops variable where it was being used twice. I'm not seeing a huge difference here and seems like splitting hairs. I think we would prefer to keep this.

I'm usually ok with using something not stored locally up to three times, so please quote me if I really did that somewhere. Creating a variable is really pointless here, it involves, apart from growing the stack, braces and a newline which can be easily avoided for no cost.

Quoted 7 lines
Quoted 7 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c int iecm_vport_queues_alloc(struct iecm_vport *vport) · line 1750

Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+
+	return NULL;
+}
+
+/**
+ * iecm_tx_handle_sw_marker - Handle queue marker packet

--- 8< ---

Quoted 9 lines
Quoted 7 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3037

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
+
+	/* modifies the skb - consumes the enet header */
+	skb->protocol = eth_type_trans(skb, rxq->vport->netdev);

eth_type_trans() should generally be called *right* before napi_gro_receive() to still have caches warm.

I'm pretty sure this happening here because we need to consume header before messing with checksum stuff but I'll have to dig deeper. Will check.

You can always do skb_pull_inline() or skb_pull() or __skb_pull() to shift skb->data to the right by ETH_HLEN, and then skb_push() (or its inline variant) right before eth_type_trans(). They're all +/- one operation (ptr increment/decrement) and are much cheaper than the cache misses (esp. on DMA buffers).
Or even just use skb->data + ETH_HLEN, skb->len - ETH_HLEN if there are not much places using them.

Quoted 4 lines
Quoted 4 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3040

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
+	iecm_rx_splitq_extract_csum_bits(rx_desc, &csum_bits);
+	iecm_rx_csum(rxq, skb, &csum_bits, &decoded);
+	/* process RSS/hash */

--- 8< ---

Quoted 11 lines
Quoted 9 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,

Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
+static bool iecm_rx_page_is_reserved(struct page *page)
+{
+	return (page_to_nid(page) != numa_mem_id()) ||

page_is_pfmemalloc(page);

Quoted 1 line

+}

Please check generic dev_page_is_reusable(), it's almost the same (a bit more optimized).

Will check and see if it does what we need.

I introduced it upstream exactly for that purpose and switched all Intel drivers (and in general all the drivers which use such a construct) to it, so it *does*.

Quoted 4 lines
Quoted 4 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3077

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +3 -0
+
+/**
+ * iecm_rx_buf_adjust_pg - Prepare rx buffer for reuse

--- 8< ---

Quoted 10 lines
Quoted 10 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3113

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+/**
+ * iecm_rx_can_reuse_page - Determine if page can be reused for another rx
+ * @rx_buf: buffer containing the page
+ *
+ * If page is reusable, we have a green light for calling iecm_reuse_rx_page,
+ * which will assign the current buffer to the buffer that next_to_alloc is
+ * pointing to; otherwise, the dma mapping needs to be destroyed and
+ * page freed
+ */
+bool iecm_rx_can_reuse_page(struct iecm_rx_buf *rx_buf)

BTW, this is a relatively small, but very hotpath function, please consider making it static inline. Compilers can uninline it then if they find it big enough.

Quoted 36 lines
Quoted 25 lines
Quoted 12 lines
(quoted diff) +2 -0
+{
+	struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf-

page_indx];

drivers/net/ethernet/intel/iecm/iecm_txrx.c +9 -0
+
+#if (PAGE_SIZE >= 8192)
+	unsigned int last_offset = PAGE_SIZE - rx_buf->buf_size;
+#endif /* PAGE_SIZE < 8192) */
+	unsigned int pagecnt_bias = page_info->pagecnt_bias;
+	struct page *page = page_info->page;
+
+	/* avoid re-using remote pages */
+	if (unlikely(iecm_rx_page_is_reserved(page)))

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3134

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +10 -0
+		return false;
+
+#if (PAGE_SIZE < 8192)
+	/* if we are only owner of page we can reuse it */
+	if (unlikely((page_count(page) - pagecnt_bias) > 1))
+		return false;
+#else
+	if (rx_buf->page_offset > last_offset)
+		return false;
+#endif /* PAGE_SIZE < 8192) */

Same here 2 times.

Quoted 10 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3140

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+
+	/* If we have drained the page fragment pool we need to update
+	 * the pagecnt_bias and page count so that we fully restock the
+	 * number of references the driver holds.
+	 */
+	if (unlikely(pagecnt_bias == 1)) {

With 1532 byte frames, this condition will be hit 50% of times. It's definitely not a good place for unlkely().

Quoted 1 line

I'm afraid I'm not following here, mind elaborating? Keep in mind the buffer is 4k not 2k on MEV.

4k doesn't make any difference, but I confused reaching the bottom of the @pagecnt_bias with reaching the end of the page, nevermind.

Quoted 10 lines
Quoted 10 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3149

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +9 -0
+		page_ref_add(page, USHRT_MAX - 1);
+		page_info->pagecnt_bias = USHRT_MAX;
+	}
+
+	return true;
+}
+
+/**
+ * iecm_rx_add_frag - Add contents of Rx buffer to sk_buff as a frag

--- 8< ---

Quoted 9 lines
Quoted 7 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3576

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +4 -0
+
+		/* protocol */
+		if (unlikely(iecm_rx_process_skb_fields(rxq, skb,
+							splitq_flex_rx_desc))) {

You can define variables with shorter names to avoid this.

The only variable I see here with a questionably long name is splitq_flex_rx_desc but I don't see a way to shorten it without losing information. Note 'rx_desc' is also a variable that exists in this context and splitq_base_rx_desc could conceivably also exist so splitq_rx_desc doesn't work.

You don't actually need all that information. SplitQ model has its own separate file, and it's reflected in the name of this function. Rx processing is reflected as well. "flexd" ("flex_desc" after all) is enough to get it all.
@rxq is named "rxq", not "splitq_rx_queue", right?

Quoted 5 lines
Quoted 5 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb, · line 3563

Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +4 -0
+			dev_kfree_skb_any(skb);
+			skb = NULL;
+			continue;
+		}

--- 8< ---

Quoted 11 lines
Quoted 10 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c iecm_vport_intr_napi_ena_all(struct iecm_vport *vport) · line 4191

Quoted 6 lines

static int iecm_vport_splitq_napi_poll(struct napi_struct *napi, int budget) {

drivers/net/ethernet/intel/iecm/iecm_txrx.c +2 -2
-	/* stub */
-	return 0;
+	struct iecm_q_vector *q_vector =
+				container_of(napi, struct iecm_q_vector, napi);

You can assign it later (before clean_complete assignment) to avoid this.

Quoted 1 line

To avoid the word wrap? I'm not sure I see the difference between letting it wrap and assigning it on it's own line.

Yes. As I mentioned in one of my previous replies, declaration and assignment which have their own lines is a regular occasion, and a line wrap of an assignment is an exception *only* for the cases when there's no other way.

I can't get why people are fighting so hardly for not splitting the declarations + assignments. Like, you do

	clean_complete = iecm_tx_splitq_clean_all(q_vector, budget);

right after the declaration block, why don't you try to merge it with the declaration itself? Because it's a non-read-only operation? What is the actual problem with

	struct iecm_q_vector *q_vector;
	bool clean_complete;
	int work_done = 0;

	q_vector = container_of(napi, typeof(*q_vector), napi);
	clean_complete = iecm_tx_splitq_clean_all(q_vector, budget);

then? Is it less readable? To me it is actually more. Is it less logical? Probably a newline between them will help if needed.

And also, if you have a really good reason for keeping it that way, you should've wrapped it by arguments actually, not by operation.

	struct iecm_q_vector *q_vector = container_of(napi, typeof(*q_vector,
						      napi);

Wrapping by operation takes place *only* when there's no other way, and here are at least two now.

Quoted 7 lines
Quoted 7 lines

drivers/net/ethernet/intel/iecm/iecm_txrx.c iecm_vport_intr_napi_ena_all(struct iecm_vport *vport) · line 4197

Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_txrx.c +6 -0
+	bool clean_complete;
+	int work_done = 0;
+
+	clean_complete = iecm_tx_splitq_clean_all(q_vector, budget);
+
+	/* Handle case where we are called by netpoll with a budget of 0 */

--- 8< ---

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

--
2.33.0

Thanks,
Al

Thanks,
Al

author
#58 lore raw

PATCH 14/19 iecm: implement singleq napi_poll

In reply to Alan Brady

This adds everything we do the more traditional singleq model data path.

---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    |    2 +-
 .../ethernet/intel/iecm/iecm_singleq_txrx.c   | 1208 ++++++++++++++++-
 drivers/net/ethernet/intel/include/iecm.h     |    1 +
 .../net/ethernet/intel/include/iecm_txrx.h    |   31 +
 4 files changed, 1237 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/iecm/iecm_lib.c +1 -1
index cc82e665dfaf..cbde65f1c523 100644
@@ -2723,7 +2723,7 @@ static const struct net_device_ops iecm_netdev_ops_splitq = {
 static const struct net_device_ops iecm_netdev_ops_singleq = {
 	.ndo_open = iecm_open,
 	.ndo_stop = iecm_stop,
-	.ndo_start_xmit = NULL,
+	.ndo_start_xmit = iecm_tx_singleq_start,
 	.ndo_set_rx_mode = iecm_set_rx_mode,
 	.ndo_validate_addr = eth_validate_addr,
 	.ndo_set_mac_address = iecm_set_mac,
drivers/net/ethernet/intel/iecm/iecm_singleq_txrx.c +1204 -4

1,224 lines not on this page · raw message

drivers/net/ethernet/intel/include/iecm.h +1 -0
index 3cf2a2f0cb0f..97c9935b832d 100644
@@ -8,6 +8,7 @@
 #include <net/pkt_cls.h>
 #include <linux/aer.h>
 #include <linux/pci.h>
+#include <linux/sctp.h>
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
 #include <linux/ethtool.h>
drivers/net/ethernet/intel/include/iecm_txrx.h +31 -0
index 086b0efc989a..4dba4f52be98 100644
@@ -624,6 +624,26 @@ struct iecm_txq_group {
 
 struct iecm_adapter;
 
+/**
+ * iecm_tx_singleq_build_ctob - populate command tag offset and size
+ * @td_cmd: Command to be filled in desc
+ * @td_offset: Offset to be filled in desc
+ * @size: Size of the buffer
+ * @td_tag: vlan tag to be filled
+ *
+ * Returns the 64 bit value populated with the input parameters
+ */
+static inline __le64
+iecm_tx_singleq_build_ctob(u64 td_cmd, u64 td_offset, unsigned int size,
+			   u64 td_tag)
+{
+	return cpu_to_le64(IECM_TX_DESC_DTYPE_DATA |
+			   (td_cmd    << IECM_TXD_QW1_CMD_S) |
+			   (td_offset << IECM_TXD_QW1_OFFSET_S) |
+			   ((u64)size << IECM_TXD_QW1_TX_BUF_SZ_S) |
+			   (td_tag    << IECM_TXD_QW1_L2TAG1_S));
+}
+
 void iecm_tx_splitq_build_ctb(union iecm_tx_flex_desc *desc,
 			      struct iecm_tx_splitq_params *parms,
 			      u16 td_cmd, u16 size);
@@ -673,8 +693,19 @@ void iecm_rx_splitq_put_bufs(struct iecm_queue *rx_bufq,
 			     struct iecm_rx_buf *hdr_buf,
 			     struct iecm_rx_buf *rx_buf);
 bool iecm_rx_splitq_test_staterr(u8 stat_err_field, const u8 stat_err_bits);
+bool iecm_rx_singleq_test_staterr(union virtchnl2_rx_desc *rx_desc,
+				  const u64 stat_err_bits);
 int iecm_rx_process_skb_fields(struct iecm_queue *rxq, struct sk_buff *skb,
 			       struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc);
+void iecm_rx_singleq_process_skb_fields(struct iecm_queue *rx_q, struct sk_buff *skb,
+					union virtchnl2_rx_desc *rx_desc, u16 ptype);
+void iecm_rx_singleq_extract_fields(struct iecm_queue *rx_q,
+				    union virtchnl2_rx_desc *rx_desc,
+				    struct iecm_rx_extracted *fields);
+void iecm_rx_singleq_bump_ntc(struct iecm_queue *q);
+bool iecm_rx_singleq_is_non_eop(struct iecm_queue *rxq,
+				union virtchnl2_rx_desc *rx_desc,
+				struct sk_buff *skb);
 bool iecm_rx_splitq_extract_vlan_tag(struct virtchnl2_rx_flex_desc_adv_nic_3 *desc,
 				     struct iecm_queue *rxq, u16 *vlan_tag);
 void iecm_rx_bump_ntc(struct iecm_queue *q);
Signature · 1 line
2.33.0