nic.h 23 KB

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