Skip to content

Commit 3048cf8

Browse files
Jesus Sanchez-Palenciadavem330
authored andcommitted
igb: Add support for ETF offload
Implement HW offload support for SO_TXTIME through igb's Launchtime feature. This is done by extending igb_setup_tc() so it supports TC_SETUP_QDISC_ETF and configuring i210 so time based transmit arbitration is enabled. The FQTSS transmission mode added before is extended so strict priority (SP) queues wait for stream reservation (SR) ones. igb_config_tx_modes() is extended so it can support enabling/disabling Launchtime following the previous approach used for the credit-based shaper (CBS). As the previous flow, FQTSS transmission mode is enabled automatically by the driver once Launchtime (or CBS, as before) is enabled. Similarly, it's automatically disabled when the feature is disabled for the last queue that had it setup on. The driver just consumes the transmit times from the skbuffs directly, so no special handling is done in case an 'invalid' time is provided. We assume this has been handled by the ETF qdisc already. Signed-off-by: Jesus Sanchez-Palencia <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1b9231e commit 3048cf8

File tree

3 files changed

+138
-17
lines changed

3 files changed

+138
-17
lines changed

drivers/net/ethernet/intel/igb/e1000_defines.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,22 @@
10481048
#define E1000_TQAVCTRL_XMIT_MODE BIT(0)
10491049
#define E1000_TQAVCTRL_DATAFETCHARB BIT(4)
10501050
#define E1000_TQAVCTRL_DATATRANARB BIT(8)
1051+
#define E1000_TQAVCTRL_DATATRANTIM BIT(9)
1052+
#define E1000_TQAVCTRL_SP_WAIT_SR BIT(10)
1053+
/* Fetch Time Delta - bits 31:16
1054+
*
1055+
* This field holds the value to be reduced from the launch time for
1056+
* fetch time decision. The FetchTimeDelta value is defined in 32 ns
1057+
* granularity.
1058+
*
1059+
* This field is 16 bits wide, and so the maximum value is:
1060+
*
1061+
* 65535 * 32 = 2097120 ~= 2.1 msec
1062+
*
1063+
* XXX: We are configuring the max value here since we couldn't come up
1064+
* with a reason for not doing so.
1065+
*/
1066+
#define E1000_TQAVCTRL_FETCHTIME_DELTA (0xFFFF << 16)
10511067

10521068
/* TX Qav Credit Control fields */
10531069
#define E1000_TQAVCC_IDLESLOPE_MASK 0xFFFF

drivers/net/ethernet/intel/igb/igb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ struct igb_ring {
262262
u16 count; /* number of desc. in the ring */
263263
u8 queue_index; /* logical index of the ring*/
264264
u8 reg_idx; /* physical index of the ring */
265+
bool launchtime_enable; /* true if LaunchTime is enabled */
265266
bool cbs_enable; /* indicates if CBS is enabled */
266267
s32 idleslope; /* idleSlope in kbps */
267268
s32 sendslope; /* sendSlope in kbps */

drivers/net/ethernet/intel/igb/igb_main.c

Lines changed: 121 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,13 +1666,26 @@ static bool is_any_cbs_enabled(struct igb_adapter *adapter)
16661666
return false;
16671667
}
16681668

1669+
static bool is_any_txtime_enabled(struct igb_adapter *adapter)
1670+
{
1671+
int i;
1672+
1673+
for (i = 0; i < adapter->num_tx_queues; i++) {
1674+
if (adapter->tx_ring[i]->launchtime_enable)
1675+
return true;
1676+
}
1677+
1678+
return false;
1679+
}
1680+
16691681
/**
16701682
* igb_config_tx_modes - Configure "Qav Tx mode" features on igb
16711683
* @adapter: pointer to adapter struct
16721684
* @queue: queue number
16731685
*
1674-
* Configure CBS for a given hardware queue. Parameters are retrieved
1675-
* from the correct Tx ring, so igb_save_cbs_params() should be used
1686+
* Configure CBS and Launchtime for a given hardware queue.
1687+
* Parameters are retrieved from the correct Tx ring, so
1688+
* igb_save_cbs_params() and igb_save_txtime_params() should be used
16761689
* for setting those correctly prior to this function being called.
16771690
**/
16781691
static void igb_config_tx_modes(struct igb_adapter *adapter, int queue)
@@ -1686,6 +1699,19 @@ static void igb_config_tx_modes(struct igb_adapter *adapter, int queue)
16861699
WARN_ON(hw->mac.type != e1000_i210);
16871700
WARN_ON(queue < 0 || queue > 1);
16881701

1702+
/* If any of the Qav features is enabled, configure queues as SR and
1703+
* with HIGH PRIO. If none is, then configure them with LOW PRIO and
1704+
* as SP.
1705+
*/
1706+
if (ring->cbs_enable || ring->launchtime_enable) {
1707+
set_tx_desc_fetch_prio(hw, queue, TX_QUEUE_PRIO_HIGH);
1708+
set_queue_mode(hw, queue, QUEUE_MODE_STREAM_RESERVATION);
1709+
} else {
1710+
set_tx_desc_fetch_prio(hw, queue, TX_QUEUE_PRIO_LOW);
1711+
set_queue_mode(hw, queue, QUEUE_MODE_STRICT_PRIORITY);
1712+
}
1713+
1714+
/* If CBS is enabled, set DataTranARB and config its parameters. */
16891715
if (ring->cbs_enable || queue == 0) {
16901716
/* i210 does not allow the queue 0 to be in the Strict
16911717
* Priority mode while the Qav mode is enabled, so,
@@ -1702,9 +1728,6 @@ static void igb_config_tx_modes(struct igb_adapter *adapter, int queue)
17021728
ring->hicredit = ETH_FRAME_LEN;
17031729
}
17041730

1705-
set_tx_desc_fetch_prio(hw, queue, TX_QUEUE_PRIO_HIGH);
1706-
set_queue_mode(hw, queue, QUEUE_MODE_STREAM_RESERVATION);
1707-
17081731
/* Always set data transfer arbitration to credit-based
17091732
* shaper algorithm on TQAVCTRL if CBS is enabled for any of
17101733
* the queues.
@@ -1780,8 +1803,6 @@ static void igb_config_tx_modes(struct igb_adapter *adapter, int queue)
17801803
wr32(E1000_I210_TQAVHC(queue),
17811804
0x80000000 + ring->hicredit * 0x7735);
17821805
} else {
1783-
set_tx_desc_fetch_prio(hw, queue, TX_QUEUE_PRIO_LOW);
1784-
set_queue_mode(hw, queue, QUEUE_MODE_STRICT_PRIORITY);
17851806

17861807
/* Set idleSlope to zero. */
17871808
tqavcc = rd32(E1000_I210_TQAVCC(queue));
@@ -1802,17 +1823,61 @@ static void igb_config_tx_modes(struct igb_adapter *adapter, int queue)
18021823
}
18031824
}
18041825

1826+
/* If LaunchTime is enabled, set DataTranTIM. */
1827+
if (ring->launchtime_enable) {
1828+
/* Always set DataTranTIM on TQAVCTRL if LaunchTime is enabled
1829+
* for any of the SR queues, and configure fetchtime delta.
1830+
* XXX NOTE:
1831+
* - LaunchTime will be enabled for all SR queues.
1832+
* - A fixed offset can be added relative to the launch
1833+
* time of all packets if configured at reg LAUNCH_OS0.
1834+
* We are keeping it as 0 for now (default value).
1835+
*/
1836+
tqavctrl = rd32(E1000_I210_TQAVCTRL);
1837+
tqavctrl |= E1000_TQAVCTRL_DATATRANTIM |
1838+
E1000_TQAVCTRL_FETCHTIME_DELTA;
1839+
wr32(E1000_I210_TQAVCTRL, tqavctrl);
1840+
} else {
1841+
/* If Launchtime is not enabled for any SR queues anymore,
1842+
* then clear DataTranTIM on TQAVCTRL and clear fetchtime delta,
1843+
* effectively disabling Launchtime.
1844+
*/
1845+
if (!is_any_txtime_enabled(adapter)) {
1846+
tqavctrl = rd32(E1000_I210_TQAVCTRL);
1847+
tqavctrl &= ~E1000_TQAVCTRL_DATATRANTIM;
1848+
tqavctrl &= ~E1000_TQAVCTRL_FETCHTIME_DELTA;
1849+
wr32(E1000_I210_TQAVCTRL, tqavctrl);
1850+
}
1851+
}
1852+
18051853
/* XXX: In i210 controller the sendSlope and loCredit parameters from
18061854
* CBS are not configurable by software so we don't do any 'controller
18071855
* configuration' in respect to these parameters.
18081856
*/
18091857

1810-
netdev_dbg(netdev, "CBS %s: queue %d idleslope %d sendslope %d hiCredit %d locredit %d\n",
1811-
(ring->cbs_enable) ? "enabled" : "disabled", queue,
1858+
netdev_dbg(netdev, "Qav Tx mode: cbs %s, launchtime %s, queue %d \
1859+
idleslope %d sendslope %d hiCredit %d \
1860+
locredit %d\n",
1861+
(ring->cbs_enable) ? "enabled" : "disabled",
1862+
(ring->launchtime_enable) ? "enabled" : "disabled", queue,
18121863
ring->idleslope, ring->sendslope, ring->hicredit,
18131864
ring->locredit);
18141865
}
18151866

1867+
static int igb_save_txtime_params(struct igb_adapter *adapter, int queue,
1868+
bool enable)
1869+
{
1870+
struct igb_ring *ring;
1871+
1872+
if (queue < 0 || queue > adapter->num_tx_queues)
1873+
return -EINVAL;
1874+
1875+
ring = adapter->tx_ring[queue];
1876+
ring->launchtime_enable = enable;
1877+
1878+
return 0;
1879+
}
1880+
18161881
static int igb_save_cbs_params(struct igb_adapter *adapter, int queue,
18171882
bool enable, int idleslope, int sendslope,
18181883
int hicredit, int locredit)
@@ -1856,10 +1921,11 @@ static void igb_setup_tx_mode(struct igb_adapter *adapter)
18561921
int i, max_queue;
18571922

18581923
/* Configure TQAVCTRL register: set transmit mode to 'Qav',
1859-
* set data fetch arbitration to 'round robin'.
1924+
* set data fetch arbitration to 'round robin', set SP_WAIT_SR
1925+
* so SP queues wait for SR ones.
18601926
*/
18611927
val = rd32(E1000_I210_TQAVCTRL);
1862-
val |= E1000_TQAVCTRL_XMIT_MODE;
1928+
val |= E1000_TQAVCTRL_XMIT_MODE | E1000_TQAVCTRL_SP_WAIT_SR;
18631929
val &= ~E1000_TQAVCTRL_DATAFETCHARB;
18641930
wr32(E1000_I210_TQAVCTRL, val);
18651931

@@ -2483,7 +2549,7 @@ static void igb_offload_apply(struct igb_adapter *adapter, s32 queue)
24832549

24842550
igb_config_tx_modes(adapter, queue);
24852551

2486-
if (!is_any_cbs_enabled(adapter))
2552+
if (!is_any_cbs_enabled(adapter) && !is_any_txtime_enabled(adapter))
24872553
enable_fqtss(adapter, false);
24882554
}
24892555

@@ -2756,6 +2822,29 @@ static int igb_setup_tc_block(struct igb_adapter *adapter,
27562822
}
27572823
}
27582824

2825+
static int igb_offload_txtime(struct igb_adapter *adapter,
2826+
struct tc_etf_qopt_offload *qopt)
2827+
{
2828+
struct e1000_hw *hw = &adapter->hw;
2829+
int err;
2830+
2831+
/* Launchtime offloading is only supported by i210 controller. */
2832+
if (hw->mac.type != e1000_i210)
2833+
return -EOPNOTSUPP;
2834+
2835+
/* Launchtime offloading is only supported by queues 0 and 1. */
2836+
if (qopt->queue < 0 || qopt->queue > 1)
2837+
return -EINVAL;
2838+
2839+
err = igb_save_txtime_params(adapter, qopt->queue, qopt->enable);
2840+
if (err)
2841+
return err;
2842+
2843+
igb_offload_apply(adapter, qopt->queue);
2844+
2845+
return 0;
2846+
}
2847+
27592848
static int igb_setup_tc(struct net_device *dev, enum tc_setup_type type,
27602849
void *type_data)
27612850
{
@@ -2766,6 +2855,8 @@ static int igb_setup_tc(struct net_device *dev, enum tc_setup_type type,
27662855
return igb_offload_cbs(adapter, type_data);
27672856
case TC_SETUP_BLOCK:
27682857
return igb_setup_tc_block(adapter, type_data);
2858+
case TC_SETUP_QDISC_ETF:
2859+
return igb_offload_txtime(adapter, type_data);
27692860

27702861
default:
27712862
return -EOPNOTSUPP;
@@ -5586,11 +5677,14 @@ static void igb_set_itr(struct igb_q_vector *q_vector)
55865677
}
55875678
}
55885679

5589-
static void igb_tx_ctxtdesc(struct igb_ring *tx_ring, u32 vlan_macip_lens,
5590-
u32 type_tucmd, u32 mss_l4len_idx)
5680+
static void igb_tx_ctxtdesc(struct igb_ring *tx_ring,
5681+
struct igb_tx_buffer *first,
5682+
u32 vlan_macip_lens, u32 type_tucmd,
5683+
u32 mss_l4len_idx)
55915684
{
55925685
struct e1000_adv_tx_context_desc *context_desc;
55935686
u16 i = tx_ring->next_to_use;
5687+
struct timespec64 ts;
55945688

55955689
context_desc = IGB_TX_CTXTDESC(tx_ring, i);
55965690

@@ -5605,9 +5699,18 @@ static void igb_tx_ctxtdesc(struct igb_ring *tx_ring, u32 vlan_macip_lens,
56055699
mss_l4len_idx |= tx_ring->reg_idx << 4;
56065700

56075701
context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
5608-
context_desc->seqnum_seed = 0;
56095702
context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
56105703
context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
5704+
5705+
/* We assume there is always a valid tx time available. Invalid times
5706+
* should have been handled by the upper layers.
5707+
*/
5708+
if (tx_ring->launchtime_enable) {
5709+
ts = ns_to_timespec64(first->skb->tstamp);
5710+
context_desc->seqnum_seed = cpu_to_le32(ts.tv_nsec / 32);
5711+
} else {
5712+
context_desc->seqnum_seed = 0;
5713+
}
56115714
}
56125715

56135716
static int igb_tso(struct igb_ring *tx_ring,
@@ -5690,7 +5793,8 @@ static int igb_tso(struct igb_ring *tx_ring,
56905793
vlan_macip_lens |= (ip.hdr - skb->data) << E1000_ADVTXD_MACLEN_SHIFT;
56915794
vlan_macip_lens |= first->tx_flags & IGB_TX_FLAGS_VLAN_MASK;
56925795

5693-
igb_tx_ctxtdesc(tx_ring, vlan_macip_lens, type_tucmd, mss_l4len_idx);
5796+
igb_tx_ctxtdesc(tx_ring, first, vlan_macip_lens,
5797+
type_tucmd, mss_l4len_idx);
56945798

56955799
return 1;
56965800
}
@@ -5745,7 +5849,7 @@ static void igb_tx_csum(struct igb_ring *tx_ring, struct igb_tx_buffer *first)
57455849
vlan_macip_lens |= skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT;
57465850
vlan_macip_lens |= first->tx_flags & IGB_TX_FLAGS_VLAN_MASK;
57475851

5748-
igb_tx_ctxtdesc(tx_ring, vlan_macip_lens, type_tucmd, 0);
5852+
igb_tx_ctxtdesc(tx_ring, first, vlan_macip_lens, type_tucmd, 0);
57495853
}
57505854

57515855
#define IGB_SET_FLAG(_input, _flag, _result) \

0 commit comments

Comments
 (0)