Skip to content

Commit 2611df7

Browse files
committed
Merge branch 'sfc-support-PTP-on-8000-and-X2000-series-NICs'
Edward Cree says: ==================== sfc: support PTP on 8000 and X2000 series NICs Starting from the 8000-series (Medford 1), SFC NICs can timestamp TX packets sent through an ordinary DMA queue, rather than a special control-plane operation as in the 7000-series. Patches 2-8 implement support for this. The X2000-series (Medford 2) changes the format of timestamps, from seconds+ (2^27)ths to seconds + quarter nanoseconds, as well as changing the shift of the frequency adjustment for increased precision. Patches 9-12 implement support for these changes. Patch #1 is an unrelated fix for NAPI budget handling, needed in order for TX completion changes in the later patches to apply cleanly. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents fb07a82 + 88a4fb5 commit 2611df7

File tree

7 files changed

+489
-120
lines changed

7 files changed

+489
-120
lines changed

drivers/net/ethernet/sfc/ef10.c

Lines changed: 125 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,25 @@ static int efx_ef10_init_datapath_caps(struct efx_nic *efx)
322322
return 0;
323323
}
324324

325+
static void efx_ef10_read_licensed_features(struct efx_nic *efx)
326+
{
327+
MCDI_DECLARE_BUF(inbuf, MC_CMD_LICENSING_V3_IN_LEN);
328+
MCDI_DECLARE_BUF(outbuf, MC_CMD_LICENSING_V3_OUT_LEN);
329+
struct efx_ef10_nic_data *nic_data = efx->nic_data;
330+
size_t outlen;
331+
int rc;
332+
333+
MCDI_SET_DWORD(inbuf, LICENSING_V3_IN_OP,
334+
MC_CMD_LICENSING_V3_IN_OP_REPORT_LICENSE);
335+
rc = efx_mcdi_rpc_quiet(efx, MC_CMD_LICENSING_V3, inbuf, sizeof(inbuf),
336+
outbuf, sizeof(outbuf), &outlen);
337+
if (rc || (outlen < MC_CMD_LICENSING_V3_OUT_LEN))
338+
return;
339+
340+
nic_data->licensed_features = MCDI_QWORD(outbuf,
341+
LICENSING_V3_OUT_LICENSED_FEATURES);
342+
}
343+
325344
static int efx_ef10_get_sysclk_freq(struct efx_nic *efx)
326345
{
327346
MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLOCK_OUT_LEN);
@@ -722,6 +741,8 @@ static int efx_ef10_probe(struct efx_nic *efx)
722741
if (rc < 0)
723742
goto fail5;
724743

744+
efx_ef10_read_licensed_features(efx);
745+
725746
/* We can have one VI for each vi_stride-byte region.
726747
* However, until we use TX option descriptors we need two TX queues
727748
* per channel.
@@ -760,14 +781,7 @@ static int efx_ef10_probe(struct efx_nic *efx)
760781
if (rc && rc != -EPERM)
761782
goto fail5;
762783

763-
rc = efx_ptp_probe(efx, NULL);
764-
/* Failure to probe PTP is not fatal.
765-
* In the case of EPERM, efx_ptp_probe will print its own message (in
766-
* efx_ptp_get_attributes()), so we don't need to.
767-
*/
768-
if (rc && rc != -EPERM)
769-
netif_warn(efx, drv, efx->net_dev,
770-
"Failed to probe PTP, rc=%d\n", rc);
784+
efx_ptp_defer_probe_with_channel(efx);
771785

772786
#ifdef CONFIG_SFC_SRIOV
773787
if ((efx->pci_dev->physfn) && (!efx->pci_dev->is_physfn)) {
@@ -937,6 +951,11 @@ static int efx_ef10_link_piobufs(struct efx_nic *efx)
937951

938952
/* Link a buffer to each TX queue */
939953
efx_for_each_channel(channel, efx) {
954+
/* Extra channels, even those with TXQs (PTP), do not require
955+
* PIO resources.
956+
*/
957+
if (!channel->type->want_pio)
958+
continue;
940959
efx_for_each_channel_tx_queue(tx_queue, channel) {
941960
/* We assign the PIO buffers to queues in
942961
* reverse order to allow for the following
@@ -1284,7 +1303,9 @@ static int efx_ef10_dimension_resources(struct efx_nic *efx)
12841303
void __iomem *membase;
12851304
int rc;
12861305

1287-
channel_vis = max(efx->n_channels, efx->n_tx_channels * EFX_TXQ_TYPES);
1306+
channel_vis = max(efx->n_channels,
1307+
(efx->n_tx_channels + efx->n_extra_tx_channels) *
1308+
EFX_TXQ_TYPES);
12881309

12891310
#ifdef EFX_USE_PIO
12901311
/* Try to allocate PIO buffers if wanted and if the full
@@ -2408,12 +2429,25 @@ static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
24082429
int i;
24092430
BUILD_BUG_ON(MC_CMD_INIT_TXQ_OUT_LEN != 0);
24102431

2432+
/* Only attempt to enable TX timestamping if we have the license for it,
2433+
* otherwise TXQ init will fail
2434+
*/
2435+
if (!(nic_data->licensed_features &
2436+
(1 << LICENSED_V3_FEATURES_TX_TIMESTAMPS_LBN))) {
2437+
tx_queue->timestamping = false;
2438+
/* Disable sync events on this channel. */
2439+
if (efx->type->ptp_set_ts_sync_events)
2440+
efx->type->ptp_set_ts_sync_events(efx, false, false);
2441+
}
2442+
24112443
/* TSOv2 is a limited resource that can only be configured on a limited
24122444
* number of queues. TSO without checksum offload is not really a thing,
24132445
* so we only enable it for those queues.
2446+
* TSOv2 cannot be used with Hardware timestamping.
24142447
*/
24152448
if (csum_offload && (nic_data->datapath_caps2 &
2416-
(1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN))) {
2449+
(1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN)) &&
2450+
!tx_queue->timestamping) {
24172451
tso_v2 = true;
24182452
netif_dbg(efx, hw, efx->net_dev, "Using TSOv2 for channel %u\n",
24192453
channel->channel);
@@ -2439,14 +2473,16 @@ static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
24392473
inlen = MC_CMD_INIT_TXQ_IN_LEN(entries);
24402474

24412475
do {
2442-
MCDI_POPULATE_DWORD_3(inbuf, INIT_TXQ_IN_FLAGS,
2476+
MCDI_POPULATE_DWORD_4(inbuf, INIT_TXQ_IN_FLAGS,
24432477
/* This flag was removed from mcdi_pcol.h for
24442478
* the non-_EXT version of INIT_TXQ. However,
24452479
* firmware still honours it.
24462480
*/
24472481
INIT_TXQ_EXT_IN_FLAG_TSOV2_EN, tso_v2,
24482482
INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload,
2449-
INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload);
2483+
INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload,
2484+
INIT_TXQ_EXT_IN_FLAG_TIMESTAMP,
2485+
tx_queue->timestamping);
24502486

24512487
rc = efx_mcdi_rpc_quiet(efx, MC_CMD_INIT_TXQ, inbuf, inlen,
24522488
NULL, 0, NULL);
@@ -2472,12 +2508,13 @@ static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
24722508
tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION;
24732509
tx_queue->insert_count = 1;
24742510
txd = efx_tx_desc(tx_queue, 0);
2475-
EFX_POPULATE_QWORD_4(*txd,
2511+
EFX_POPULATE_QWORD_5(*txd,
24762512
ESF_DZ_TX_DESC_IS_OPT, true,
24772513
ESF_DZ_TX_OPTION_TYPE,
24782514
ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
24792515
ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload,
2480-
ESF_DZ_TX_OPTION_IP_CSUM, csum_offload);
2516+
ESF_DZ_TX_OPTION_IP_CSUM, csum_offload,
2517+
ESF_DZ_TX_TIMESTAMP, tx_queue->timestamping);
24812518
tx_queue->write_count = 1;
24822519

24832520
if (tso_v2) {
@@ -3572,31 +3609,92 @@ static int efx_ef10_handle_rx_event(struct efx_channel *channel,
35723609
return n_packets;
35733610
}
35743611

3575-
static int
3612+
static u32 efx_ef10_extract_event_ts(efx_qword_t *event)
3613+
{
3614+
u32 tstamp;
3615+
3616+
tstamp = EFX_QWORD_FIELD(*event, TX_TIMESTAMP_EVENT_TSTAMP_DATA_HI);
3617+
tstamp <<= 16;
3618+
tstamp |= EFX_QWORD_FIELD(*event, TX_TIMESTAMP_EVENT_TSTAMP_DATA_LO);
3619+
3620+
return tstamp;
3621+
}
3622+
3623+
static void
35763624
efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
35773625
{
35783626
struct efx_nic *efx = channel->efx;
35793627
struct efx_tx_queue *tx_queue;
35803628
unsigned int tx_ev_desc_ptr;
35813629
unsigned int tx_ev_q_label;
3582-
int tx_descs = 0;
3630+
unsigned int tx_ev_type;
3631+
u64 ts_part;
35833632

35843633
if (unlikely(READ_ONCE(efx->reset_pending)))
3585-
return 0;
3634+
return;
35863635

35873636
if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT)))
3588-
return 0;
3637+
return;
35893638

3590-
/* Transmit completion */
3591-
tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX);
3639+
/* Get the transmit queue */
35923640
tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL);
35933641
tx_queue = efx_channel_get_tx_queue(channel,
35943642
tx_ev_q_label % EFX_TXQ_TYPES);
3595-
tx_descs = ((tx_ev_desc_ptr + 1 - tx_queue->read_count) &
3596-
tx_queue->ptr_mask);
3597-
efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask);
35983643

3599-
return tx_descs;
3644+
if (!tx_queue->timestamping) {
3645+
/* Transmit completion */
3646+
tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX);
3647+
efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask);
3648+
return;
3649+
}
3650+
3651+
/* Transmit timestamps are only available for 8XXX series. They result
3652+
* in three events per packet. These occur in order, and are:
3653+
* - the normal completion event
3654+
* - the low part of the timestamp
3655+
* - the high part of the timestamp
3656+
*
3657+
* Each part of the timestamp is itself split across two 16 bit
3658+
* fields in the event.
3659+
*/
3660+
tx_ev_type = EFX_QWORD_FIELD(*event, ESF_EZ_TX_SOFT1);
3661+
3662+
switch (tx_ev_type) {
3663+
case TX_TIMESTAMP_EVENT_TX_EV_COMPLETION:
3664+
/* In case of Queue flush or FLR, we might have received
3665+
* the previous TX completion event but not the Timestamp
3666+
* events.
3667+
*/
3668+
if (tx_queue->completed_desc_ptr != tx_queue->ptr_mask)
3669+
efx_xmit_done(tx_queue, tx_queue->completed_desc_ptr);
3670+
3671+
tx_ev_desc_ptr = EFX_QWORD_FIELD(*event,
3672+
ESF_DZ_TX_DESCR_INDX);
3673+
tx_queue->completed_desc_ptr =
3674+
tx_ev_desc_ptr & tx_queue->ptr_mask;
3675+
break;
3676+
3677+
case TX_TIMESTAMP_EVENT_TX_EV_TSTAMP_LO:
3678+
ts_part = efx_ef10_extract_event_ts(event);
3679+
tx_queue->completed_timestamp_minor = ts_part;
3680+
break;
3681+
3682+
case TX_TIMESTAMP_EVENT_TX_EV_TSTAMP_HI:
3683+
ts_part = efx_ef10_extract_event_ts(event);
3684+
tx_queue->completed_timestamp_major = ts_part;
3685+
3686+
efx_xmit_done(tx_queue, tx_queue->completed_desc_ptr);
3687+
tx_queue->completed_desc_ptr = tx_queue->ptr_mask;
3688+
break;
3689+
3690+
default:
3691+
netif_err(efx, hw, efx->net_dev,
3692+
"channel %d unknown tx event type %d (data "
3693+
EFX_QWORD_FMT ")\n",
3694+
channel->channel, tx_ev_type,
3695+
EFX_QWORD_VAL(*event));
3696+
break;
3697+
}
36003698
}
36013699

36023700
static void
@@ -3658,7 +3756,6 @@ static int efx_ef10_ev_process(struct efx_channel *channel, int quota)
36583756
efx_qword_t event, *p_event;
36593757
unsigned int read_ptr;
36603758
int ev_code;
3661-
int tx_descs = 0;
36623759
int spent = 0;
36633760

36643761
if (quota <= 0)
@@ -3698,13 +3795,7 @@ static int efx_ef10_ev_process(struct efx_channel *channel, int quota)
36983795
}
36993796
break;
37003797
case ESE_DZ_EV_CODE_TX_EV:
3701-
tx_descs += efx_ef10_handle_tx_event(channel, &event);
3702-
if (tx_descs > efx->txq_entries) {
3703-
spent = quota;
3704-
goto out;
3705-
} else if (++spent == quota) {
3706-
goto out;
3707-
}
3798+
efx_ef10_handle_tx_event(channel, &event);
37083799
break;
37093800
case ESE_DZ_EV_CODE_DRIVER_EV:
37103801
efx_ef10_handle_driver_event(channel, &event);
@@ -6179,7 +6270,8 @@ static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en,
61796270
efx_ef10_rx_enable_timestamping :
61806271
efx_ef10_rx_disable_timestamping;
61816272

6182-
efx_for_each_channel(channel, efx) {
6273+
channel = efx_ptp_channel(efx);
6274+
if (channel) {
61836275
int rc = set(channel, temp);
61846276
if (en && rc != 0) {
61856277
efx_ef10_ptp_set_ts_sync_events(efx, false, temp);

drivers/net/ethernet/sfc/efx.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,12 +896,20 @@ void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue)
896896
mod_timer(&rx_queue->slow_fill, jiffies + msecs_to_jiffies(100));
897897
}
898898

899+
bool efx_default_channel_want_txqs(struct efx_channel *channel)
900+
{
901+
return channel->channel - channel->efx->tx_channel_offset <
902+
channel->efx->n_tx_channels;
903+
}
904+
899905
static const struct efx_channel_type efx_default_channel_type = {
900906
.pre_probe = efx_channel_dummy_op_int,
901907
.post_remove = efx_channel_dummy_op_void,
902908
.get_name = efx_get_channel_name,
903909
.copy = efx_copy_channel,
910+
.want_txqs = efx_default_channel_want_txqs,
904911
.keep_eventq = false,
912+
.want_pio = true,
905913
};
906914

907915
int efx_channel_dummy_op_int(struct efx_channel *channel)
@@ -1501,6 +1509,7 @@ static int efx_probe_interrupts(struct efx_nic *efx)
15011509
}
15021510

15031511
/* Assign extra channels if possible */
1512+
efx->n_extra_tx_channels = 0;
15041513
j = efx->n_channels;
15051514
for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++) {
15061515
if (!efx->extra_channel_type[i])
@@ -1512,6 +1521,8 @@ static int efx_probe_interrupts(struct efx_nic *efx)
15121521
--j;
15131522
efx_get_channel(efx, j)->type =
15141523
efx->extra_channel_type[i];
1524+
if (efx_channel_has_tx_queues(efx_get_channel(efx, j)))
1525+
efx->n_extra_tx_channels++;
15151526
}
15161527
}
15171528

0 commit comments

Comments
 (0)