nic.h 22 KB

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