hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/drivers/net/ethernet/sfc/ptp.c
....@@ -1,10 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /****************************************************************************
23 * Driver for Solarflare network controllers and boards
34 * Copyright 2011-2013 Solarflare Communications Inc.
4
- *
5
- * This program is free software; you can redistribute it and/or modify it
6
- * under the terms of the GNU General Public License version 2 as published
7
- * by the Free Software Foundation, incorporated herein by reference.
85 */
96
107 /* Theory of operation:
....@@ -38,7 +35,6 @@
3835 #include <linux/time.h>
3936 #include <linux/ktime.h>
4037 #include <linux/module.h>
41
-#include <linux/net_tstamp.h>
4238 #include <linux/pps_kernel.h>
4339 #include <linux/ptp_clock_kernel.h>
4440 #include "net_driver.h"
....@@ -47,7 +43,9 @@
4743 #include "mcdi_pcol.h"
4844 #include "io.h"
4945 #include "farch_regs.h"
50
-#include "nic.h"
46
+#include "tx.h"
47
+#include "nic.h" /* indirectly includes ptp.h */
48
+#include "efx_channels.h"
5149
5250 /* Maximum number of events expected to make up a PTP event */
5351 #define MAX_EVENT_FRAGS 3
....@@ -176,9 +174,11 @@
176174
177175 /**
178176 * struct efx_ptp_event_rx - A PTP receive event (from MC)
177
+ * @link: list of events
179178 * @seq0: First part of (PTP) UUID
180179 * @seq1: Second part of (PTP) UUID and sequence number
181180 * @hwtimestamp: Event timestamp
181
+ * @expiry: Time which the packet arrived
182182 */
183183 struct efx_ptp_event_rx {
184184 struct list_head link;
....@@ -226,11 +226,13 @@
226226 * reset (disable, enable).
227227 * @rxfilter_event: Receive filter when operating
228228 * @rxfilter_general: Receive filter when operating
229
+ * @rxfilter_installed: Receive filter installed
229230 * @config: Current timestamp configuration
230231 * @enabled: PTP operation enabled
231232 * @mode: Mode in which PTP operating (PTP version)
232233 * @ns_to_nic_time: Function to convert from scalar nanoseconds to NIC time
233234 * @nic_to_kernel_time: Function to convert from NIC to kernel time
235
+ * @nic_time: contains time details
234236 * @nic_time.minor_max: Wrap point for NIC minor times
235237 * @nic_time.sync_event_diff_min: Minimum acceptable difference between time
236238 * in packet prefix and last MCDI time sync event i.e. how much earlier than
....@@ -242,6 +244,7 @@
242244 * field in MCDI time sync event.
243245 * @min_synchronisation_ns: Minimum acceptable corrected sync window
244246 * @capabilities: Capabilities flags from the NIC
247
+ * @ts_corrections: contains corrections details
245248 * @ts_corrections.ptp_tx: Required driver correction of PTP packet transmit
246249 * timestamps
247250 * @ts_corrections.ptp_rx: Required driver correction of PTP packet receive
....@@ -329,7 +332,7 @@
329332 struct work_struct pps_work;
330333 struct workqueue_struct *pps_workwq;
331334 bool nic_ts_enabled;
332
- _MCDI_DECLARE_BUF(txbuf, MC_CMD_PTP_IN_TRANSMIT_LENMAX);
335
+ efx_dword_t txbuf[MCDI_TX_BUF_LEN(MC_CMD_PTP_IN_TRANSMIT_LENMAX)];
333336
334337 unsigned int good_syncs;
335338 unsigned int fast_syncs;
....@@ -355,12 +358,7 @@
355358
356359 bool efx_ptp_use_mac_tx_timestamps(struct efx_nic *efx)
357360 {
358
- struct efx_ef10_nic_data *nic_data = efx->nic_data;
359
-
360
- return ((efx_nic_rev(efx) >= EFX_REV_HUNT_A0) &&
361
- (nic_data->datapath_caps2 &
362
- (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_MAC_TIMESTAMPING_LBN)
363
- ));
361
+ return efx_has_cap(efx, TX_MAC_TIMESTAMPING);
364362 }
365363
366364 /* PTP 'extra' channel is still a traffic channel, but we only create TX queues
....@@ -542,6 +540,12 @@
542540 struct efx_channel *efx_ptp_channel(struct efx_nic *efx)
543541 {
544542 return efx->ptp_data ? efx->ptp_data->channel : NULL;
543
+}
544
+
545
+void efx_ptp_update_channel(struct efx_nic *efx, struct efx_channel *channel)
546
+{
547
+ if (efx->ptp_data)
548
+ efx->ptp_data->channel = channel;
545549 }
546550
547551 static u32 last_sync_timestamp_major(struct efx_nic *efx)
....@@ -1091,12 +1095,34 @@
10911095 static void efx_ptp_xmit_skb_queue(struct efx_nic *efx, struct sk_buff *skb)
10921096 {
10931097 struct efx_ptp_data *ptp_data = efx->ptp_data;
1098
+ u8 type = efx_tx_csum_type_skb(skb);
10941099 struct efx_tx_queue *tx_queue;
1095
- u8 type = skb->ip_summed == CHECKSUM_PARTIAL ? EFX_TXQ_TYPE_OFFLOAD : 0;
10961100
1097
- tx_queue = &ptp_data->channel->tx_queue[type];
1101
+ tx_queue = efx_channel_get_tx_queue(ptp_data->channel, type);
10981102 if (tx_queue && tx_queue->timestamping) {
1103
+ /* This code invokes normal driver TX code which is always
1104
+ * protected from softirqs when called from generic TX code,
1105
+ * which in turn disables preemption. Look at __dev_queue_xmit
1106
+ * which uses rcu_read_lock_bh disabling preemption for RCU
1107
+ * plus disabling softirqs. We do not need RCU reader
1108
+ * protection here.
1109
+ *
1110
+ * Although it is theoretically safe for current PTP TX/RX code
1111
+ * running without disabling softirqs, there are three good
1112
+ * reasond for doing so:
1113
+ *
1114
+ * 1) The code invoked is mainly implemented for non-PTP
1115
+ * packets and it is always executed with softirqs
1116
+ * disabled.
1117
+ * 2) This being a single PTP packet, better to not
1118
+ * interrupt its processing by softirqs which can lead
1119
+ * to high latencies.
1120
+ * 3) netdev_xmit_more checks preemption is disabled and
1121
+ * triggers a BUG_ON if not.
1122
+ */
1123
+ local_bh_disable();
10991124 efx_enqueue_skb(tx_queue, skb);
1125
+ local_bh_enable();
11001126 } else {
11011127 WARN_ONCE(1, "PTP channel has no timestamped tx queue\n");
11021128 dev_kfree_skb_any(skb);
....@@ -1163,17 +1189,15 @@
11631189
11641190 /* Drop time-expired events */
11651191 spin_lock_bh(&ptp->evt_lock);
1166
- if (!list_empty(&ptp->evt_list)) {
1167
- list_for_each_safe(cursor, next, &ptp->evt_list) {
1168
- struct efx_ptp_event_rx *evt;
1192
+ list_for_each_safe(cursor, next, &ptp->evt_list) {
1193
+ struct efx_ptp_event_rx *evt;
11691194
1170
- evt = list_entry(cursor, struct efx_ptp_event_rx,
1171
- link);
1172
- if (time_after(jiffies, evt->expiry)) {
1173
- list_move(&evt->link, &ptp->evt_free_list);
1174
- netif_warn(efx, hw, efx->net_dev,
1175
- "PTP rx event dropped\n");
1176
- }
1195
+ evt = list_entry(cursor, struct efx_ptp_event_rx,
1196
+ link);
1197
+ if (time_after(jiffies, evt->expiry)) {
1198
+ list_move(&evt->link, &ptp->evt_free_list);
1199
+ netif_warn(efx, hw, efx->net_dev,
1200
+ "PTP rx event dropped\n");
11771201 }
11781202 }
11791203 spin_unlock_bh(&ptp->evt_lock);
....@@ -1447,6 +1471,11 @@
14471471 struct efx_ptp_data *ptp;
14481472 int rc = 0;
14491473 unsigned int pos;
1474
+
1475
+ if (efx->ptp_data) {
1476
+ efx->ptp_data->channel = channel;
1477
+ return 0;
1478
+ }
14501479
14511480 ptp = kzalloc(sizeof(struct efx_ptp_data), GFP_KERNEL);
14521481 efx->ptp_data = ptp;
....@@ -2184,7 +2213,7 @@
21842213 .pre_probe = efx_ptp_probe_channel,
21852214 .post_remove = efx_ptp_remove_channel,
21862215 .get_name = efx_ptp_get_channel_name,
2187
- /* no copy operation; there is no need to reallocate this channel */
2216
+ .copy = efx_copy_channel,
21882217 .receive_skb = efx_ptp_rx,
21892218 .want_txqs = efx_ptp_want_txqs,
21902219 .keep_eventq = false,