nic.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /****************************************************************************
  3. * Driver for Solarflare network controllers and boards
  4. * Copyright 2005-2006 Fen Systems Ltd.
  5. * Copyright 2006-2013 Solarflare Communications Inc.
  6. */
  7. #ifndef EFX_NIC_H
  8. #define EFX_NIC_H
  9. #include <linux/net_tstamp.h>
  10. #include <linux/i2c-algo-bit.h>
  11. #include "net_driver.h"
  12. #include "efx.h"
  13. #include "mcdi.h"
  14. enum {
  15. /* Revisions 0-2 were Falcon A0, A1 and B0 respectively.
  16. * They are not supported by this driver but these revision numbers
  17. * form part of the ethtool API for register dumping.
  18. */
  19. EFX_REV_SIENA_A0 = 3,
  20. EFX_REV_HUNT_A0 = 4,
  21. };
  22. static inline int efx_nic_rev(struct efx_nic *efx)
  23. {
  24. return efx->type->revision;
  25. }
  26. u32 efx_farch_fpga_ver(struct efx_nic *efx);
  27. /* Read the current event from the event queue */
  28. static inline efx_qword_t *efx_event(struct efx_channel *channel,
  29. unsigned int index)
  30. {
  31. return ((efx_qword_t *) (channel->eventq.buf.addr)) +
  32. (index & channel->eventq_mask);
  33. }
  34. /* See if an event is present
  35. *
  36. * We check both the high and low dword of the event for all ones. We
  37. * wrote all ones when we cleared the event, and no valid event can
  38. * have all ones in either its high or low dwords. This approach is
  39. * robust against reordering.
  40. *
  41. * Note that using a single 64-bit comparison is incorrect; even
  42. * though the CPU read will be atomic, the DMA write may not be.
  43. */
  44. static inline int efx_event_present(efx_qword_t *event)
  45. {
  46. return !(EFX_DWORD_IS_ALL_ONES(event->dword[0]) |
  47. EFX_DWORD_IS_ALL_ONES(event->dword[1]));
  48. }
  49. /* Returns a pointer to the specified transmit descriptor in the TX
  50. * descriptor queue belonging to the specified channel.
  51. */
  52. static inline efx_qword_t *
  53. efx_tx_desc(struct efx_tx_queue *tx_queue, unsigned int index)
  54. {
  55. return ((efx_qword_t *) (tx_queue->txd.buf.addr)) + index;
  56. }
  57. /* Get partner of a TX queue, seen as part of the same net core queue */
  58. static struct efx_tx_queue *efx_tx_queue_partner(struct efx_tx_queue *tx_queue)
  59. {
  60. if (tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD)
  61. return tx_queue - EFX_TXQ_TYPE_OFFLOAD;
  62. else
  63. return tx_queue + EFX_TXQ_TYPE_OFFLOAD;
  64. }
  65. /* Report whether this TX queue would be empty for the given write_count.
  66. * May return false negative.
  67. */
  68. static inline bool __efx_nic_tx_is_empty(struct efx_tx_queue *tx_queue,
  69. unsigned int write_count)
  70. {
  71. unsigned int empty_read_count = READ_ONCE(tx_queue->empty_read_count);
  72. if (empty_read_count == 0)
  73. return false;
  74. return ((empty_read_count ^ write_count) & ~EFX_EMPTY_COUNT_VALID) == 0;
  75. }
  76. /* Report whether the NIC considers this TX queue empty, using
  77. * packet_write_count (the write count recorded for the last completable
  78. * doorbell push). May return false negative. EF10 only, which is OK
  79. * because only EF10 supports PIO.
  80. */
  81. static inline bool efx_nic_tx_is_empty(struct efx_tx_queue *tx_queue)
  82. {
  83. EFX_WARN_ON_ONCE_PARANOID(!tx_queue->efx->type->option_descriptors);
  84. return __efx_nic_tx_is_empty(tx_queue, tx_queue->packet_write_count);
  85. }
  86. /* Decide whether we can use TX PIO, ie. write packet data directly into
  87. * a buffer on the device. This can reduce latency at the expense of
  88. * throughput, so we only do this if both hardware and software TX rings
  89. * are empty. This also ensures that only one packet at a time can be
  90. * using the PIO buffer.
  91. */
  92. static inline bool efx_nic_may_tx_pio(struct efx_tx_queue *tx_queue)
  93. {
  94. struct efx_tx_queue *partner = efx_tx_queue_partner(tx_queue);
  95. return tx_queue->piobuf && efx_nic_tx_is_empty(tx_queue) &&
  96. efx_nic_tx_is_empty(partner);
  97. }
  98. /* Decide whether to push a TX descriptor to the NIC vs merely writing
  99. * the doorbell. This can reduce latency when we are adding a single
  100. * descriptor to an empty queue, but is otherwise pointless. Further,
  101. * Falcon and Siena have hardware bugs (SF bug 33851) that may be
  102. * triggered if we don't check this.
  103. * We use the write_count used for the last doorbell push, to get the
  104. * NIC's view of the tx queue.
  105. */
  106. static inline bool efx_nic_may_push_tx_desc(struct efx_tx_queue *tx_queue,
  107. unsigned int write_count)
  108. {
  109. bool was_empty = __efx_nic_tx_is_empty(tx_queue, write_count);
  110. tx_queue->empty_read_count = 0;
  111. return was_empty && tx_queue->write_count - write_count == 1;
  112. }
  113. /* Returns a pointer to the specified descriptor in the RX descriptor queue */
  114. static inline efx_qword_t *
  115. efx_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
  116. {
  117. return ((efx_qword_t *) (rx_queue->rxd.buf.addr)) + index;
  118. }
  119. enum {
  120. PHY_TYPE_NONE = 0,
  121. PHY_TYPE_TXC43128 = 1,
  122. PHY_TYPE_88E1111 = 2,
  123. PHY_TYPE_SFX7101 = 3,
  124. PHY_TYPE_QT2022C2 = 4,
  125. PHY_TYPE_PM8358 = 6,
  126. PHY_TYPE_SFT9001A = 8,
  127. PHY_TYPE_QT2025C = 9,
  128. PHY_TYPE_SFT9001B = 10,
  129. };
  130. /* Alignment of PCIe DMA boundaries (4KB) */
  131. #define EFX_PAGE_SIZE 4096
  132. /* Size and alignment of buffer table entries (same) */
  133. #define EFX_BUF_SIZE EFX_PAGE_SIZE
  134. /* NIC-generic software stats */
  135. enum {
  136. GENERIC_STAT_rx_noskb_drops,
  137. GENERIC_STAT_rx_nodesc_trunc,
  138. GENERIC_STAT_COUNT
  139. };
  140. enum {
  141. SIENA_STAT_tx_bytes = GENERIC_STAT_COUNT,
  142. SIENA_STAT_tx_good_bytes,
  143. SIENA_STAT_tx_bad_bytes,
  144. SIENA_STAT_tx_packets,
  145. SIENA_STAT_tx_bad,
  146. SIENA_STAT_tx_pause,
  147. SIENA_STAT_tx_control,
  148. SIENA_STAT_tx_unicast,
  149. SIENA_STAT_tx_multicast,
  150. SIENA_STAT_tx_broadcast,
  151. SIENA_STAT_tx_lt64,
  152. SIENA_STAT_tx_64,
  153. SIENA_STAT_tx_65_to_127,
  154. SIENA_STAT_tx_128_to_255,
  155. SIENA_STAT_tx_256_to_511,
  156. SIENA_STAT_tx_512_to_1023,
  157. SIENA_STAT_tx_1024_to_15xx,
  158. SIENA_STAT_tx_15xx_to_jumbo,
  159. SIENA_STAT_tx_gtjumbo,
  160. SIENA_STAT_tx_collision,
  161. SIENA_STAT_tx_single_collision,
  162. SIENA_STAT_tx_multiple_collision,
  163. SIENA_STAT_tx_excessive_collision,
  164. SIENA_STAT_tx_deferred,
  165. SIENA_STAT_tx_late_collision,
  166. SIENA_STAT_tx_excessive_deferred,
  167. SIENA_STAT_tx_non_tcpudp,
  168. SIENA_STAT_tx_mac_src_error,
  169. SIENA_STAT_tx_ip_src_error,
  170. SIENA_STAT_rx_bytes,
  171. SIENA_STAT_rx_good_bytes,
  172. SIENA_STAT_rx_bad_bytes,
  173. SIENA_STAT_rx_packets,
  174. SIENA_STAT_rx_good,
  175. SIENA_STAT_rx_bad,
  176. SIENA_STAT_rx_pause,
  177. SIENA_STAT_rx_control,
  178. SIENA_STAT_rx_unicast,
  179. SIENA_STAT_rx_multicast,
  180. SIENA_STAT_rx_broadcast,
  181. SIENA_STAT_rx_lt64,
  182. SIENA_STAT_rx_64,
  183. SIENA_STAT_rx_65_to_127,
  184. SIENA_STAT_rx_128_to_255,
  185. SIENA_STAT_rx_256_to_511,
  186. SIENA_STAT_rx_512_to_1023,
  187. SIENA_STAT_rx_1024_to_15xx,
  188. SIENA_STAT_rx_15xx_to_jumbo,
  189. SIENA_STAT_rx_gtjumbo,
  190. SIENA_STAT_rx_bad_gtjumbo,
  191. SIENA_STAT_rx_overflow,
  192. SIENA_STAT_rx_false_carrier,
  193. SIENA_STAT_rx_symbol_error,
  194. SIENA_STAT_rx_align_error,
  195. SIENA_STAT_rx_length_error,
  196. SIENA_STAT_rx_internal_error,
  197. SIENA_STAT_rx_nodesc_drop_cnt,
  198. SIENA_STAT_COUNT
  199. };
  200. /**
  201. * struct siena_nic_data - Siena NIC state
  202. * @efx: Pointer back to main interface structure
  203. * @wol_filter_id: Wake-on-LAN packet filter id
  204. * @stats: Hardware statistics
  205. * @vf: Array of &struct siena_vf objects
  206. * @vf_buftbl_base: The zeroth buffer table index used to back VF queues.
  207. * @vfdi_status: Common VFDI status page to be dmad to VF address space.
  208. * @local_addr_list: List of local addresses. Protected by %local_lock.
  209. * @local_page_list: List of DMA addressable pages used to broadcast
  210. * %local_addr_list. Protected by %local_lock.
  211. * @local_lock: Mutex protecting %local_addr_list and %local_page_list.
  212. * @peer_work: Work item to broadcast peer addresses to VMs.
  213. */
  214. struct siena_nic_data {
  215. struct efx_nic *efx;
  216. int wol_filter_id;
  217. u64 stats[SIENA_STAT_COUNT];
  218. #ifdef CONFIG_SFC_SRIOV
  219. struct siena_vf *vf;
  220. struct efx_channel *vfdi_channel;
  221. unsigned vf_buftbl_base;
  222. struct efx_buffer vfdi_status;
  223. struct list_head local_addr_list;
  224. struct list_head local_page_list;
  225. struct mutex local_lock;
  226. struct work_struct peer_work;
  227. #endif
  228. };
  229. enum {
  230. EF10_STAT_port_tx_bytes = GENERIC_STAT_COUNT,
  231. EF10_STAT_port_tx_packets,
  232. EF10_STAT_port_tx_pause,
  233. EF10_STAT_port_tx_control,
  234. EF10_STAT_port_tx_unicast,
  235. EF10_STAT_port_tx_multicast,
  236. EF10_STAT_port_tx_broadcast,
  237. EF10_STAT_port_tx_lt64,
  238. EF10_STAT_port_tx_64,
  239. EF10_STAT_port_tx_65_to_127,
  240. EF10_STAT_port_tx_128_to_255,
  241. EF10_STAT_port_tx_256_to_511,
  242. EF10_STAT_port_tx_512_to_1023,
  243. EF10_STAT_port_tx_1024_to_15xx,
  244. EF10_STAT_port_tx_15xx_to_jumbo,
  245. EF10_STAT_port_rx_bytes,
  246. EF10_STAT_port_rx_bytes_minus_good_bytes,
  247. EF10_STAT_port_rx_good_bytes,
  248. EF10_STAT_port_rx_bad_bytes,
  249. EF10_STAT_port_rx_packets,
  250. EF10_STAT_port_rx_good,
  251. EF10_STAT_port_rx_bad,
  252. EF10_STAT_port_rx_pause,
  253. EF10_STAT_port_rx_control,
  254. EF10_STAT_port_rx_unicast,
  255. EF10_STAT_port_rx_multicast,
  256. EF10_STAT_port_rx_broadcast,
  257. EF10_STAT_port_rx_lt64,
  258. EF10_STAT_port_rx_64,
  259. EF10_STAT_port_rx_65_to_127,
  260. EF10_STAT_port_rx_128_to_255,
  261. EF10_STAT_port_rx_256_to_511,
  262. EF10_STAT_port_rx_512_to_1023,
  263. EF10_STAT_port_rx_1024_to_15xx,
  264. EF10_STAT_port_rx_15xx_to_jumbo,
  265. EF10_STAT_port_rx_gtjumbo,
  266. EF10_STAT_port_rx_bad_gtjumbo,
  267. EF10_STAT_port_rx_overflow,
  268. EF10_STAT_port_rx_align_error,
  269. EF10_STAT_port_rx_length_error,
  270. EF10_STAT_port_rx_nodesc_drops,
  271. EF10_STAT_port_rx_pm_trunc_bb_overflow,
  272. EF10_STAT_port_rx_pm_discard_bb_overflow,
  273. EF10_STAT_port_rx_pm_trunc_vfifo_full,
  274. EF10_STAT_port_rx_pm_discard_vfifo_full,
  275. EF10_STAT_port_rx_pm_trunc_qbb,
  276. EF10_STAT_port_rx_pm_discard_qbb,
  277. EF10_STAT_port_rx_pm_discard_mapping,
  278. EF10_STAT_port_rx_dp_q_disabled_packets,
  279. EF10_STAT_port_rx_dp_di_dropped_packets,
  280. EF10_STAT_port_rx_dp_streaming_packets,
  281. EF10_STAT_port_rx_dp_hlb_fetch,
  282. EF10_STAT_port_rx_dp_hlb_wait,
  283. EF10_STAT_rx_unicast,
  284. EF10_STAT_rx_unicast_bytes,
  285. EF10_STAT_rx_multicast,
  286. EF10_STAT_rx_multicast_bytes,
  287. EF10_STAT_rx_broadcast,
  288. EF10_STAT_rx_broadcast_bytes,
  289. EF10_STAT_rx_bad,
  290. EF10_STAT_rx_bad_bytes,
  291. EF10_STAT_rx_overflow,
  292. EF10_STAT_tx_unicast,
  293. EF10_STAT_tx_unicast_bytes,
  294. EF10_STAT_tx_multicast,
  295. EF10_STAT_tx_multicast_bytes,
  296. EF10_STAT_tx_broadcast,
  297. EF10_STAT_tx_broadcast_bytes,
  298. EF10_STAT_tx_bad,
  299. EF10_STAT_tx_bad_bytes,
  300. EF10_STAT_tx_overflow,
  301. EF10_STAT_V1_COUNT,
  302. EF10_STAT_fec_uncorrected_errors = EF10_STAT_V1_COUNT,
  303. EF10_STAT_fec_corrected_errors,
  304. EF10_STAT_fec_corrected_symbols_lane0,
  305. EF10_STAT_fec_corrected_symbols_lane1,
  306. EF10_STAT_fec_corrected_symbols_lane2,
  307. EF10_STAT_fec_corrected_symbols_lane3,
  308. EF10_STAT_ctpio_vi_busy_fallback,
  309. EF10_STAT_ctpio_long_write_success,
  310. EF10_STAT_ctpio_missing_dbell_fail,
  311. EF10_STAT_ctpio_overflow_fail,
  312. EF10_STAT_ctpio_underflow_fail,
  313. EF10_STAT_ctpio_timeout_fail,
  314. EF10_STAT_ctpio_noncontig_wr_fail,
  315. EF10_STAT_ctpio_frm_clobber_fail,
  316. EF10_STAT_ctpio_invalid_wr_fail,
  317. EF10_STAT_ctpio_vi_clobber_fallback,
  318. EF10_STAT_ctpio_unqualified_fallback,
  319. EF10_STAT_ctpio_runt_fallback,
  320. EF10_STAT_ctpio_success,
  321. EF10_STAT_ctpio_fallback,
  322. EF10_STAT_ctpio_poison,
  323. EF10_STAT_ctpio_erase,
  324. EF10_STAT_COUNT
  325. };
  326. /* Maximum number of TX PIO buffers we may allocate to a function.
  327. * This matches the total number of buffers on each SFC9100-family
  328. * controller.
  329. */
  330. #define EF10_TX_PIOBUF_COUNT 16
  331. /**
  332. * struct efx_ef10_nic_data - EF10 architecture NIC state
  333. * @mcdi_buf: DMA buffer for MCDI
  334. * @warm_boot_count: Last seen MC warm boot count
  335. * @vi_base: Absolute index of first VI in this function
  336. * @n_allocated_vis: Number of VIs allocated to this function
  337. * @must_realloc_vis: Flag: VIs have yet to be reallocated after MC reboot
  338. * @must_restore_rss_contexts: Flag: RSS contexts have yet to be restored after
  339. * MC reboot
  340. * @must_restore_filters: Flag: filters have yet to be restored after MC reboot
  341. * @n_piobufs: Number of PIO buffers allocated to this function
  342. * @wc_membase: Base address of write-combining mapping of the memory BAR
  343. * @pio_write_base: Base address for writing PIO buffers
  344. * @pio_write_vi_base: Relative VI number for @pio_write_base
  345. * @piobuf_handle: Handle of each PIO buffer allocated
  346. * @piobuf_size: size of a single PIO buffer
  347. * @must_restore_piobufs: Flag: PIO buffers have yet to be restored after MC
  348. * reboot
  349. * @rx_rss_context_exclusive: Whether our RSS context is exclusive or shared
  350. * @stats: Hardware statistics
  351. * @workaround_35388: Flag: firmware supports workaround for bug 35388
  352. * @workaround_26807: Flag: firmware supports workaround for bug 26807
  353. * @workaround_61265: Flag: firmware supports workaround for bug 61265
  354. * @must_check_datapath_caps: Flag: @datapath_caps needs to be revalidated
  355. * after MC reboot
  356. * @datapath_caps: Capabilities of datapath firmware (FLAGS1 field of
  357. * %MC_CMD_GET_CAPABILITIES response)
  358. * @datapath_caps2: Further Capabilities of datapath firmware (FLAGS2 field of
  359. * %MC_CMD_GET_CAPABILITIES response)
  360. * @rx_dpcpu_fw_id: Firmware ID of the RxDPCPU
  361. * @tx_dpcpu_fw_id: Firmware ID of the TxDPCPU
  362. * @vport_id: The function's vport ID, only relevant for PFs
  363. * @must_probe_vswitching: Flag: vswitching has yet to be setup after MC reboot
  364. * @pf_index: The number for this PF, or the parent PF if this is a VF
  365. #ifdef CONFIG_SFC_SRIOV
  366. * @vf: Pointer to VF data structure
  367. #endif
  368. * @vport_mac: The MAC address on the vport, only for PFs; VFs will be zero
  369. * @vlan_list: List of VLANs added over the interface. Serialised by vlan_lock.
  370. * @vlan_lock: Lock to serialize access to vlan_list.
  371. * @udp_tunnels: UDP tunnel port numbers and types.
  372. * @udp_tunnels_dirty: flag indicating a reboot occurred while pushing
  373. * @udp_tunnels to hardware and thus the push must be re-done.
  374. * @udp_tunnels_lock: Serialises writes to @udp_tunnels and @udp_tunnels_dirty.
  375. */
  376. struct efx_ef10_nic_data {
  377. struct efx_buffer mcdi_buf;
  378. u16 warm_boot_count;
  379. unsigned int vi_base;
  380. unsigned int n_allocated_vis;
  381. bool must_realloc_vis;
  382. bool must_restore_rss_contexts;
  383. bool must_restore_filters;
  384. unsigned int n_piobufs;
  385. void __iomem *wc_membase, *pio_write_base;
  386. unsigned int pio_write_vi_base;
  387. unsigned int piobuf_handle[EF10_TX_PIOBUF_COUNT];
  388. u16 piobuf_size;
  389. bool must_restore_piobufs;
  390. bool rx_rss_context_exclusive;
  391. u64 stats[EF10_STAT_COUNT];
  392. bool workaround_35388;
  393. bool workaround_26807;
  394. bool workaround_61265;
  395. bool must_check_datapath_caps;
  396. u32 datapath_caps;
  397. u32 datapath_caps2;
  398. unsigned int rx_dpcpu_fw_id;
  399. unsigned int tx_dpcpu_fw_id;
  400. unsigned int vport_id;
  401. bool must_probe_vswitching;
  402. unsigned int pf_index;
  403. u8 port_id[ETH_ALEN];
  404. #ifdef CONFIG_SFC_SRIOV
  405. unsigned int vf_index;
  406. struct ef10_vf *vf;
  407. #endif
  408. u8 vport_mac[ETH_ALEN];
  409. struct list_head vlan_list;
  410. struct mutex vlan_lock;
  411. struct efx_udp_tunnel udp_tunnels[16];
  412. bool udp_tunnels_dirty;
  413. struct mutex udp_tunnels_lock;
  414. u64 licensed_features;
  415. };
  416. int efx_init_sriov(void);
  417. void efx_fini_sriov(void);
  418. struct ethtool_ts_info;
  419. int efx_ptp_probe(struct efx_nic *efx, struct efx_channel *channel);
  420. void efx_ptp_defer_probe_with_channel(struct efx_nic *efx);
  421. struct efx_channel *efx_ptp_channel(struct efx_nic *efx);
  422. void efx_ptp_remove(struct efx_nic *efx);
  423. int efx_ptp_set_ts_config(struct efx_nic *efx, struct ifreq *ifr);
  424. int efx_ptp_get_ts_config(struct efx_nic *efx, struct ifreq *ifr);
  425. void efx_ptp_get_ts_info(struct efx_nic *efx, struct ethtool_ts_info *ts_info);
  426. bool efx_ptp_is_ptp_tx(struct efx_nic *efx, struct sk_buff *skb);
  427. int efx_ptp_get_mode(struct efx_nic *efx);
  428. int efx_ptp_change_mode(struct efx_nic *efx, bool enable_wanted,
  429. unsigned int new_mode);
  430. int efx_ptp_tx(struct efx_nic *efx, struct sk_buff *skb);
  431. void efx_ptp_event(struct efx_nic *efx, efx_qword_t *ev);
  432. size_t efx_ptp_describe_stats(struct efx_nic *efx, u8 *strings);
  433. size_t efx_ptp_update_stats(struct efx_nic *efx, u64 *stats);
  434. void efx_time_sync_event(struct efx_channel *channel, efx_qword_t *ev);
  435. void __efx_rx_skb_attach_timestamp(struct efx_channel *channel,
  436. struct sk_buff *skb);
  437. static inline void efx_rx_skb_attach_timestamp(struct efx_channel *channel,
  438. struct sk_buff *skb)
  439. {
  440. if (channel->sync_events_state == SYNC_EVENTS_VALID)
  441. __efx_rx_skb_attach_timestamp(channel, skb);
  442. }
  443. void efx_ptp_start_datapath(struct efx_nic *efx);
  444. void efx_ptp_stop_datapath(struct efx_nic *efx);
  445. bool efx_ptp_use_mac_tx_timestamps(struct efx_nic *efx);
  446. ktime_t efx_ptp_nic_to_kernel_time(struct efx_tx_queue *tx_queue);
  447. extern const struct efx_nic_type falcon_a1_nic_type;
  448. extern const struct efx_nic_type falcon_b0_nic_type;
  449. extern const struct efx_nic_type siena_a0_nic_type;
  450. extern const struct efx_nic_type efx_hunt_a0_nic_type;
  451. extern const struct efx_nic_type efx_hunt_a0_vf_nic_type;
  452. /**************************************************************************
  453. *
  454. * Externs
  455. *
  456. **************************************************************************
  457. */
  458. int falcon_probe_board(struct efx_nic *efx, u16 revision_info);
  459. /* TX data path */
  460. static inline int efx_nic_probe_tx(struct efx_tx_queue *tx_queue)
  461. {
  462. return tx_queue->efx->type->tx_probe(tx_queue);
  463. }
  464. static inline void efx_nic_init_tx(struct efx_tx_queue *tx_queue)
  465. {
  466. tx_queue->efx->type->tx_init(tx_queue);
  467. }
  468. static inline void efx_nic_remove_tx(struct efx_tx_queue *tx_queue)
  469. {
  470. tx_queue->efx->type->tx_remove(tx_queue);
  471. }
  472. static inline void efx_nic_push_buffers(struct efx_tx_queue *tx_queue)
  473. {
  474. tx_queue->efx->type->tx_write(tx_queue);
  475. }
  476. /* RX data path */
  477. static inline int efx_nic_probe_rx(struct efx_rx_queue *rx_queue)
  478. {
  479. return rx_queue->efx->type->rx_probe(rx_queue);
  480. }
  481. static inline void efx_nic_init_rx(struct efx_rx_queue *rx_queue)
  482. {
  483. rx_queue->efx->type->rx_init(rx_queue);
  484. }
  485. static inline void efx_nic_remove_rx(struct efx_rx_queue *rx_queue)
  486. {
  487. rx_queue->efx->type->rx_remove(rx_queue);
  488. }
  489. static inline void efx_nic_notify_rx_desc(struct efx_rx_queue *rx_queue)
  490. {
  491. rx_queue->efx->type->rx_write(rx_queue);
  492. }
  493. static inline void efx_nic_generate_fill_event(struct efx_rx_queue *rx_queue)
  494. {
  495. rx_queue->efx->type->rx_defer_refill(rx_queue);
  496. }
  497. /* Event data path */
  498. static inline int efx_nic_probe_eventq(struct efx_channel *channel)
  499. {
  500. return channel->efx->type->ev_probe(channel);
  501. }
  502. static inline int efx_nic_init_eventq(struct efx_channel *channel)
  503. {
  504. return channel->efx->type->ev_init(channel);
  505. }
  506. static inline void efx_nic_fini_eventq(struct efx_channel *channel)
  507. {
  508. channel->efx->type->ev_fini(channel);
  509. }
  510. static inline void efx_nic_remove_eventq(struct efx_channel *channel)
  511. {
  512. channel->efx->type->ev_remove(channel);
  513. }
  514. static inline int
  515. efx_nic_process_eventq(struct efx_channel *channel, int quota)
  516. {
  517. return channel->efx->type->ev_process(channel, quota);
  518. }
  519. static inline void efx_nic_eventq_read_ack(struct efx_channel *channel)
  520. {
  521. channel->efx->type->ev_read_ack(channel);
  522. }
  523. void efx_nic_event_test_start(struct efx_channel *channel);
  524. /* Falcon/Siena queue operations */
  525. int efx_farch_tx_probe(struct efx_tx_queue *tx_queue);
  526. void efx_farch_tx_init(struct efx_tx_queue *tx_queue);
  527. void efx_farch_tx_fini(struct efx_tx_queue *tx_queue);
  528. void efx_farch_tx_remove(struct efx_tx_queue *tx_queue);
  529. void efx_farch_tx_write(struct efx_tx_queue *tx_queue);
  530. unsigned int efx_farch_tx_limit_len(struct efx_tx_queue *tx_queue,
  531. dma_addr_t dma_addr, unsigned int len);
  532. int efx_farch_rx_probe(struct efx_rx_queue *rx_queue);
  533. void efx_farch_rx_init(struct efx_rx_queue *rx_queue);
  534. void efx_farch_rx_fini(struct efx_rx_queue *rx_queue);
  535. void efx_farch_rx_remove(struct efx_rx_queue *rx_queue);
  536. void efx_farch_rx_write(struct efx_rx_queue *rx_queue);
  537. void efx_farch_rx_defer_refill(struct efx_rx_queue *rx_queue);
  538. int efx_farch_ev_probe(struct efx_channel *channel);
  539. int efx_farch_ev_init(struct efx_channel *channel);
  540. void efx_farch_ev_fini(struct efx_channel *channel);
  541. void efx_farch_ev_remove(struct efx_channel *channel);
  542. int efx_farch_ev_process(struct efx_channel *channel, int quota);
  543. void efx_farch_ev_read_ack(struct efx_channel *channel);
  544. void efx_farch_ev_test_generate(struct efx_channel *channel);
  545. /* Falcon/Siena filter operations */
  546. int efx_farch_filter_table_probe(struct efx_nic *efx);
  547. void efx_farch_filter_table_restore(struct efx_nic *efx);
  548. void efx_farch_filter_table_remove(struct efx_nic *efx);
  549. void efx_farch_filter_update_rx_scatter(struct efx_nic *efx);
  550. s32 efx_farch_filter_insert(struct efx_nic *efx, struct efx_filter_spec *spec,
  551. bool replace);
  552. int efx_farch_filter_remove_safe(struct efx_nic *efx,
  553. enum efx_filter_priority priority,
  554. u32 filter_id);
  555. int efx_farch_filter_get_safe(struct efx_nic *efx,
  556. enum efx_filter_priority priority, u32 filter_id,
  557. struct efx_filter_spec *);
  558. int efx_farch_filter_clear_rx(struct efx_nic *efx,
  559. enum efx_filter_priority priority);
  560. u32 efx_farch_filter_count_rx_used(struct efx_nic *efx,
  561. enum efx_filter_priority priority);
  562. u32 efx_farch_filter_get_rx_id_limit(struct efx_nic *efx);
  563. s32 efx_farch_filter_get_rx_ids(struct efx_nic *efx,
  564. enum efx_filter_priority priority, u32 *buf,
  565. u32 size);
  566. #ifdef CONFIG_RFS_ACCEL
  567. bool efx_farch_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
  568. unsigned int index);
  569. #endif
  570. void efx_farch_filter_sync_rx_mode(struct efx_nic *efx);
  571. bool efx_nic_event_present(struct efx_channel *channel);
  572. /* Some statistics are computed as A - B where A and B each increase
  573. * linearly with some hardware counter(s) and the counters are read
  574. * asynchronously. If the counters contributing to B are always read
  575. * after those contributing to A, the computed value may be lower than
  576. * the true value by some variable amount, and may decrease between
  577. * subsequent computations.
  578. *
  579. * We should never allow statistics to decrease or to exceed the true
  580. * value. Since the computed value will never be greater than the
  581. * true value, we can achieve this by only storing the computed value
  582. * when it increases.
  583. */
  584. static inline void efx_update_diff_stat(u64 *stat, u64 diff)
  585. {
  586. if ((s64)(diff - *stat) > 0)
  587. *stat = diff;
  588. }
  589. /* Interrupts */
  590. int efx_nic_init_interrupt(struct efx_nic *efx);
  591. int efx_nic_irq_test_start(struct efx_nic *efx);
  592. void efx_nic_fini_interrupt(struct efx_nic *efx);
  593. /* Falcon/Siena interrupts */
  594. void efx_farch_irq_enable_master(struct efx_nic *efx);
  595. int efx_farch_irq_test_generate(struct efx_nic *efx);
  596. void efx_farch_irq_disable_master(struct efx_nic *efx);
  597. irqreturn_t efx_farch_msi_interrupt(int irq, void *dev_id);
  598. irqreturn_t efx_farch_legacy_interrupt(int irq, void *dev_id);
  599. irqreturn_t efx_farch_fatal_interrupt(struct efx_nic *efx);
  600. static inline int efx_nic_event_test_irq_cpu(struct efx_channel *channel)
  601. {
  602. return READ_ONCE(channel->event_test_cpu);
  603. }
  604. static inline int efx_nic_irq_test_irq_cpu(struct efx_nic *efx)
  605. {
  606. return READ_ONCE(efx->last_irq_cpu);
  607. }
  608. /* Global Resources */
  609. int efx_nic_flush_queues(struct efx_nic *efx);
  610. void siena_prepare_flush(struct efx_nic *efx);
  611. int efx_farch_fini_dmaq(struct efx_nic *efx);
  612. void efx_farch_finish_flr(struct efx_nic *efx);
  613. void siena_finish_flush(struct efx_nic *efx);
  614. void falcon_start_nic_stats(struct efx_nic *efx);
  615. void falcon_stop_nic_stats(struct efx_nic *efx);
  616. int falcon_reset_xaui(struct efx_nic *efx);
  617. void efx_farch_dimension_resources(struct efx_nic *efx, unsigned sram_lim_qw);
  618. void efx_farch_init_common(struct efx_nic *efx);
  619. void efx_ef10_handle_drain_event(struct efx_nic *efx);
  620. void efx_farch_rx_push_indir_table(struct efx_nic *efx);
  621. void efx_farch_rx_pull_indir_table(struct efx_nic *efx);
  622. int efx_nic_alloc_buffer(struct efx_nic *efx, struct efx_buffer *buffer,
  623. unsigned int len, gfp_t gfp_flags);
  624. void efx_nic_free_buffer(struct efx_nic *efx, struct efx_buffer *buffer);
  625. /* Tests */
  626. struct efx_farch_register_test {
  627. unsigned address;
  628. efx_oword_t mask;
  629. };
  630. int efx_farch_test_registers(struct efx_nic *efx,
  631. const struct efx_farch_register_test *regs,
  632. size_t n_regs);
  633. size_t efx_nic_get_regs_len(struct efx_nic *efx);
  634. void efx_nic_get_regs(struct efx_nic *efx, void *buf);
  635. size_t efx_nic_describe_stats(const struct efx_hw_stat_desc *desc, size_t count,
  636. const unsigned long *mask, u8 *names);
  637. void efx_nic_update_stats(const struct efx_hw_stat_desc *desc, size_t count,
  638. const unsigned long *mask, u64 *stats,
  639. const void *dma_buf, bool accumulate);
  640. void efx_nic_fix_nodesc_drop_stat(struct efx_nic *efx, u64 *stat);
  641. #define EFX_MAX_FLUSH_TIME 5000
  642. void efx_farch_generate_event(struct efx_nic *efx, unsigned int evq,
  643. efx_qword_t *event);
  644. #endif /* EFX_NIC_H */