Commit 9f329751 authored by Kurt Kanzenbach's avatar Kurt Kanzenbach Committed by Tony Nguyen
Browse files

igc: Add MQPRIO offload support



Add support for offloading MQPRIO. The hardware has four priorities as well
as four queues. Each queue must be a assigned with a unique priority.

However, the priorities are only considered in TSN Tx mode. There are two
TSN Tx modes. In case of MQPRIO the Qbv capability is not required.
Therefore, use the legacy TSN Tx mode, which performs strict priority
arbitration.

Example for mqprio with hardware offload:

|tc qdisc replace dev ${INTERFACE} handle 100 parent root mqprio num_tc 4 \
|   map 0 0 0 0 0 1 2 3 0 0 0 0 0 0 0 0 \
|   queues 1@0 1@1 1@2 1@3 \
|   hw 1

The mqprio Qdisc also allows to configure the `preemptible_tcs'. However,
frame preemption is not supported yet.

Tested on Intel i225 and implemented by following data sheet section 7.5.2,
Transmit Scheduling.

Signed-off-by: default avatarKurt Kanzenbach <kurt@linutronix.de>
Reviewed-by: default avatarWojciech Drewek <wojciech.drewek@intel.com>
Acked-by: default avatarVinicius Costa Gomes <vinicius.gomes@intel.com>
Reviewed-by: default avatarSimon Horman <horms@kernel.org>
Tested-by: default avatarMor Bar-Gabay <morx.bar.gabay@intel.com>
Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
parent fbdaffe4
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -259,6 +259,10 @@ struct igc_adapter {
	 */
	spinlock_t qbv_tx_lock;

	bool strict_priority_enable;
	u8 num_tc;
	u16 queue_per_tc[IGC_MAX_TX_QUEUES];

	/* OS defined structs */
	struct pci_dev *pdev;
	/* lock for statistics */
@@ -382,9 +386,11 @@ extern char igc_driver_name[];
#define IGC_FLAG_RX_LEGACY		BIT(16)
#define IGC_FLAG_TSN_QBV_ENABLED	BIT(17)
#define IGC_FLAG_TSN_QAV_ENABLED	BIT(18)
#define IGC_FLAG_TSN_LEGACY_ENABLED	BIT(19)

#define IGC_FLAG_TSN_ANY_ENABLED				\
	(IGC_FLAG_TSN_QBV_ENABLED | IGC_FLAG_TSN_QAV_ENABLED)
	(IGC_FLAG_TSN_QBV_ENABLED | IGC_FLAG_TSN_QAV_ENABLED |	\
	 IGC_FLAG_TSN_LEGACY_ENABLED)

#define IGC_FLAG_RSS_FIELD_IPV4_UDP	BIT(6)
#define IGC_FLAG_RSS_FIELD_IPV6_UDP	BIT(7)
+11 −0
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@
#ifndef _IGC_DEFINES_H_
#define _IGC_DEFINES_H_

#include <linux/bitfield.h>

/* Number of Transmit and Receive Descriptors must be a multiple of 8 */
#define REQ_TX_DESCRIPTOR_MULTIPLE	8
#define REQ_RX_DESCRIPTOR_MULTIPLE	8
@@ -553,6 +555,15 @@

#define IGC_MAX_SR_QUEUES		2

#define IGC_TXARB_TXQ_PRIO_0_MASK	GENMASK(1, 0)
#define IGC_TXARB_TXQ_PRIO_1_MASK	GENMASK(3, 2)
#define IGC_TXARB_TXQ_PRIO_2_MASK	GENMASK(5, 4)
#define IGC_TXARB_TXQ_PRIO_3_MASK	GENMASK(7, 6)
#define IGC_TXARB_TXQ_PRIO_0(x)		FIELD_PREP(IGC_TXARB_TXQ_PRIO_0_MASK, (x))
#define IGC_TXARB_TXQ_PRIO_1(x)		FIELD_PREP(IGC_TXARB_TXQ_PRIO_1_MASK, (x))
#define IGC_TXARB_TXQ_PRIO_2(x)		FIELD_PREP(IGC_TXARB_TXQ_PRIO_2_MASK, (x))
#define IGC_TXARB_TXQ_PRIO_3(x)		FIELD_PREP(IGC_TXARB_TXQ_PRIO_3_MASK, (x))

/* Receive Checksum Control */
#define IGC_RXCSUM_CRCOFL	0x00000800   /* CRC32 offload enable */
#define IGC_RXCSUM_PCSD		0x00002000   /* packet checksum disabled */
+4 −0
Original line number Diff line number Diff line
@@ -1540,6 +1540,10 @@ static int igc_ethtool_set_channels(struct net_device *netdev,
	if (ch->other_count != NON_Q_VECTORS)
		return -EINVAL;

	/* Do not allow channel reconfiguration when mqprio is enabled */
	if (adapter->strict_priority_enable)
		return -EINVAL;

	/* Verify the number of channels doesn't exceed hw limits */
	max_combined = igc_get_max_rss_queues(adapter);
	if (count > max_combined)
+69 −0
Original line number Diff line number Diff line
@@ -6515,6 +6515,13 @@ static int igc_tc_query_caps(struct igc_adapter *adapter,
	struct igc_hw *hw = &adapter->hw;

	switch (base->type) {
	case TC_SETUP_QDISC_MQPRIO: {
		struct tc_mqprio_caps *caps = base->caps;

		caps->validate_queue_counts = true;

		return 0;
	}
	case TC_SETUP_QDISC_TAPRIO: {
		struct tc_taprio_caps *caps = base->caps;

@@ -6532,6 +6539,65 @@ static int igc_tc_query_caps(struct igc_adapter *adapter,
	}
}

static void igc_save_mqprio_params(struct igc_adapter *adapter, u8 num_tc,
				   u16 *offset)
{
	int i;

	adapter->strict_priority_enable = true;
	adapter->num_tc = num_tc;

	for (i = 0; i < num_tc; i++)
		adapter->queue_per_tc[i] = offset[i];
}

static int igc_tsn_enable_mqprio(struct igc_adapter *adapter,
				 struct tc_mqprio_qopt_offload *mqprio)
{
	struct igc_hw *hw = &adapter->hw;
	int i;

	if (hw->mac.type != igc_i225)
		return -EOPNOTSUPP;

	if (!mqprio->qopt.num_tc) {
		adapter->strict_priority_enable = false;
		goto apply;
	}

	/* There are as many TCs as Tx queues. */
	if (mqprio->qopt.num_tc != adapter->num_tx_queues) {
		NL_SET_ERR_MSG_FMT_MOD(mqprio->extack,
				       "Only %d traffic classes supported",
				       adapter->num_tx_queues);
		return -EOPNOTSUPP;
	}

	/* Only one queue per TC is supported. */
	for (i = 0; i < mqprio->qopt.num_tc; i++) {
		if (mqprio->qopt.count[i] != 1) {
			NL_SET_ERR_MSG_MOD(mqprio->extack,
					   "Only one queue per TC supported");
			return -EOPNOTSUPP;
		}
	}

	/* Preemption is not supported yet. */
	if (mqprio->preemptible_tcs) {
		NL_SET_ERR_MSG_MOD(mqprio->extack,
				   "Preemption is not supported yet");
		return -EOPNOTSUPP;
	}

	igc_save_mqprio_params(adapter, mqprio->qopt.num_tc,
			       mqprio->qopt.offset);

	mqprio->qopt.hw = TC_MQPRIO_HW_OFFLOAD_TCS;

apply:
	return igc_tsn_offload_apply(adapter);
}

static int igc_setup_tc(struct net_device *dev, enum tc_setup_type type,
			void *type_data)
{
@@ -6551,6 +6617,9 @@ static int igc_setup_tc(struct net_device *dev, enum tc_setup_type type,
	case TC_SETUP_QDISC_CBS:
		return igc_tsn_enable_cbs(adapter, type_data);

	case TC_SETUP_QDISC_MQPRIO:
		return igc_tsn_enable_mqprio(adapter, type_data);

	default:
		return -EOPNOTSUPP;
	}
+2 −0
Original line number Diff line number Diff line
@@ -238,6 +238,8 @@
#define IGC_TQAVCC(_n)		(0x3004 + ((_n) * 0x40))
#define IGC_TQAVHC(_n)		(0x300C + ((_n) * 0x40))

#define IGC_TXARB		0x3354 /* Tx Arbitration Control TxARB - RW */

/* System Time Registers */
#define IGC_SYSTIML	0x0B600  /* System time register Low - RO */
#define IGC_SYSTIMH	0x0B604  /* System time register High - RO */
Loading