nic.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2006-2011 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. /*
  18. * Falcon hardware control
  19. */
  20. enum {
  21. EFX_REV_FALCON_A0 = 0,
  22. EFX_REV_FALCON_A1 = 1,
  23. EFX_REV_FALCON_B0 = 2,
  24. EFX_REV_SIENA_A0 = 3,
  25. };
  26. static inline int efx_nic_rev(struct efx_nic *efx)
  27. {
  28. return efx->type->revision;
  29. }
  30. extern u32 efx_farch_fpga_ver(struct efx_nic *efx);
  31. /* NIC has two interlinked PCI functions for the same port. */
  32. static inline bool efx_nic_is_dual_func(struct efx_nic *efx)
  33. {
  34. return efx_nic_rev(efx) < EFX_REV_FALCON_B0;
  35. }
  36. /* Read the current event from the event queue */
  37. static inline efx_qword_t *efx_event(struct efx_channel *channel,
  38. unsigned int index)
  39. {
  40. return ((efx_qword_t *) (channel->eventq.buf.addr)) +
  41. (index & channel->eventq_mask);
  42. }
  43. /* See if an event is present
  44. *
  45. * We check both the high and low dword of the event for all ones. We
  46. * wrote all ones when we cleared the event, and no valid event can
  47. * have all ones in either its high or low dwords. This approach is
  48. * robust against reordering.
  49. *
  50. * Note that using a single 64-bit comparison is incorrect; even
  51. * though the CPU read will be atomic, the DMA write may not be.
  52. */
  53. static inline int efx_event_present(efx_qword_t *event)
  54. {
  55. return !(EFX_DWORD_IS_ALL_ONES(event->dword[0]) |
  56. EFX_DWORD_IS_ALL_ONES(event->dword[1]));
  57. }
  58. /* Returns a pointer to the specified transmit descriptor in the TX
  59. * descriptor queue belonging to the specified channel.
  60. */
  61. static inline efx_qword_t *
  62. efx_tx_desc(struct efx_tx_queue *tx_queue, unsigned int index)
  63. {
  64. return ((efx_qword_t *) (tx_queue->txd.buf.addr)) + index;
  65. }
  66. /* Decide whether to push a TX descriptor to the NIC vs merely writing
  67. * the doorbell. This can reduce latency when we are adding a single
  68. * descriptor to an empty queue, but is otherwise pointless. Further,
  69. * Falcon and Siena have hardware bugs (SF bug 33851) that may be
  70. * triggered if we don't check this.
  71. */
  72. static inline bool efx_nic_may_push_tx_desc(struct efx_tx_queue *tx_queue,
  73. unsigned int write_count)
  74. {
  75. unsigned empty_read_count = ACCESS_ONCE(tx_queue->empty_read_count);
  76. if (empty_read_count == 0)
  77. return false;
  78. tx_queue->empty_read_count = 0;
  79. return ((empty_read_count ^ write_count) & ~EFX_EMPTY_COUNT_VALID) == 0
  80. && tx_queue->write_count - write_count == 1;
  81. }
  82. /* Returns a pointer to the specified descriptor in the RX descriptor queue */
  83. static inline efx_qword_t *
  84. efx_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
  85. {
  86. return ((efx_qword_t *) (rx_queue->rxd.buf.addr)) + index;
  87. }
  88. enum {
  89. PHY_TYPE_NONE = 0,
  90. PHY_TYPE_TXC43128 = 1,
  91. PHY_TYPE_88E1111 = 2,
  92. PHY_TYPE_SFX7101 = 3,
  93. PHY_TYPE_QT2022C2 = 4,
  94. PHY_TYPE_PM8358 = 6,
  95. PHY_TYPE_SFT9001A = 8,
  96. PHY_TYPE_QT2025C = 9,
  97. PHY_TYPE_SFT9001B = 10,
  98. };
  99. #define FALCON_XMAC_LOOPBACKS \
  100. ((1 << LOOPBACK_XGMII) | \
  101. (1 << LOOPBACK_XGXS) | \
  102. (1 << LOOPBACK_XAUI))
  103. /* Alignment of PCIe DMA boundaries (4KB) */
  104. #define EFX_PAGE_SIZE 4096
  105. /* Size and alignment of buffer table entries (same) */
  106. #define EFX_BUF_SIZE EFX_PAGE_SIZE
  107. /**
  108. * struct falcon_board_type - board operations and type information
  109. * @id: Board type id, as found in NVRAM
  110. * @init: Allocate resources and initialise peripheral hardware
  111. * @init_phy: Do board-specific PHY initialisation
  112. * @fini: Shut down hardware and free resources
  113. * @set_id_led: Set state of identifying LED or revert to automatic function
  114. * @monitor: Board-specific health check function
  115. */
  116. struct falcon_board_type {
  117. u8 id;
  118. int (*init) (struct efx_nic *nic);
  119. void (*init_phy) (struct efx_nic *efx);
  120. void (*fini) (struct efx_nic *nic);
  121. void (*set_id_led) (struct efx_nic *efx, enum efx_led_mode mode);
  122. int (*monitor) (struct efx_nic *nic);
  123. };
  124. /**
  125. * struct falcon_board - board information
  126. * @type: Type of board
  127. * @major: Major rev. ('A', 'B' ...)
  128. * @minor: Minor rev. (0, 1, ...)
  129. * @i2c_adap: I2C adapter for on-board peripherals
  130. * @i2c_data: Data for bit-banging algorithm
  131. * @hwmon_client: I2C client for hardware monitor
  132. * @ioexp_client: I2C client for power/port control
  133. */
  134. struct falcon_board {
  135. const struct falcon_board_type *type;
  136. int major;
  137. int minor;
  138. struct i2c_adapter i2c_adap;
  139. struct i2c_algo_bit_data i2c_data;
  140. struct i2c_client *hwmon_client, *ioexp_client;
  141. };
  142. /**
  143. * struct falcon_spi_device - a Falcon SPI (Serial Peripheral Interface) device
  144. * @device_id: Controller's id for the device
  145. * @size: Size (in bytes)
  146. * @addr_len: Number of address bytes in read/write commands
  147. * @munge_address: Flag whether addresses should be munged.
  148. * Some devices with 9-bit addresses (e.g. AT25040A EEPROM)
  149. * use bit 3 of the command byte as address bit A8, rather
  150. * than having a two-byte address. If this flag is set, then
  151. * commands should be munged in this way.
  152. * @erase_command: Erase command (or 0 if sector erase not needed).
  153. * @erase_size: Erase sector size (in bytes)
  154. * Erase commands affect sectors with this size and alignment.
  155. * This must be a power of two.
  156. * @block_size: Write block size (in bytes).
  157. * Write commands are limited to blocks with this size and alignment.
  158. */
  159. struct falcon_spi_device {
  160. int device_id;
  161. unsigned int size;
  162. unsigned int addr_len;
  163. unsigned int munge_address:1;
  164. u8 erase_command;
  165. unsigned int erase_size;
  166. unsigned int block_size;
  167. };
  168. static inline bool falcon_spi_present(const struct falcon_spi_device *spi)
  169. {
  170. return spi->size != 0;
  171. }
  172. enum {
  173. FALCON_STAT_tx_bytes,
  174. FALCON_STAT_tx_packets,
  175. FALCON_STAT_tx_pause,
  176. FALCON_STAT_tx_control,
  177. FALCON_STAT_tx_unicast,
  178. FALCON_STAT_tx_multicast,
  179. FALCON_STAT_tx_broadcast,
  180. FALCON_STAT_tx_lt64,
  181. FALCON_STAT_tx_64,
  182. FALCON_STAT_tx_65_to_127,
  183. FALCON_STAT_tx_128_to_255,
  184. FALCON_STAT_tx_256_to_511,
  185. FALCON_STAT_tx_512_to_1023,
  186. FALCON_STAT_tx_1024_to_15xx,
  187. FALCON_STAT_tx_15xx_to_jumbo,
  188. FALCON_STAT_tx_gtjumbo,
  189. FALCON_STAT_tx_non_tcpudp,
  190. FALCON_STAT_tx_mac_src_error,
  191. FALCON_STAT_tx_ip_src_error,
  192. FALCON_STAT_rx_bytes,
  193. FALCON_STAT_rx_good_bytes,
  194. FALCON_STAT_rx_bad_bytes,
  195. FALCON_STAT_rx_packets,
  196. FALCON_STAT_rx_good,
  197. FALCON_STAT_rx_bad,
  198. FALCON_STAT_rx_pause,
  199. FALCON_STAT_rx_control,
  200. FALCON_STAT_rx_unicast,
  201. FALCON_STAT_rx_multicast,
  202. FALCON_STAT_rx_broadcast,
  203. FALCON_STAT_rx_lt64,
  204. FALCON_STAT_rx_64,
  205. FALCON_STAT_rx_65_to_127,
  206. FALCON_STAT_rx_128_to_255,
  207. FALCON_STAT_rx_256_to_511,
  208. FALCON_STAT_rx_512_to_1023,
  209. FALCON_STAT_rx_1024_to_15xx,
  210. FALCON_STAT_rx_15xx_to_jumbo,
  211. FALCON_STAT_rx_gtjumbo,
  212. FALCON_STAT_rx_bad_lt64,
  213. FALCON_STAT_rx_bad_gtjumbo,
  214. FALCON_STAT_rx_overflow,
  215. FALCON_STAT_rx_symbol_error,
  216. FALCON_STAT_rx_align_error,
  217. FALCON_STAT_rx_length_error,
  218. FALCON_STAT_rx_internal_error,
  219. FALCON_STAT_rx_nodesc_drop_cnt,
  220. FALCON_STAT_COUNT
  221. };
  222. /**
  223. * struct falcon_nic_data - Falcon NIC state
  224. * @pci_dev2: Secondary function of Falcon A
  225. * @board: Board state and functions
  226. * @stats: Hardware statistics
  227. * @stats_disable_count: Nest count for disabling statistics fetches
  228. * @stats_pending: Is there a pending DMA of MAC statistics.
  229. * @stats_timer: A timer for regularly fetching MAC statistics.
  230. * @spi_flash: SPI flash device
  231. * @spi_eeprom: SPI EEPROM device
  232. * @spi_lock: SPI bus lock
  233. * @mdio_lock: MDIO bus lock
  234. * @xmac_poll_required: XMAC link state needs polling
  235. */
  236. struct falcon_nic_data {
  237. struct pci_dev *pci_dev2;
  238. struct falcon_board board;
  239. u64 stats[FALCON_STAT_COUNT];
  240. unsigned int stats_disable_count;
  241. bool stats_pending;
  242. struct timer_list stats_timer;
  243. struct falcon_spi_device spi_flash;
  244. struct falcon_spi_device spi_eeprom;
  245. struct mutex spi_lock;
  246. struct mutex mdio_lock;
  247. bool xmac_poll_required;
  248. };
  249. static inline struct falcon_board *falcon_board(struct efx_nic *efx)
  250. {
  251. struct falcon_nic_data *data = efx->nic_data;
  252. return &data->board;
  253. }
  254. enum {
  255. SIENA_STAT_tx_bytes,
  256. SIENA_STAT_tx_good_bytes,
  257. SIENA_STAT_tx_bad_bytes,
  258. SIENA_STAT_tx_packets,
  259. SIENA_STAT_tx_bad,
  260. SIENA_STAT_tx_pause,
  261. SIENA_STAT_tx_control,
  262. SIENA_STAT_tx_unicast,
  263. SIENA_STAT_tx_multicast,
  264. SIENA_STAT_tx_broadcast,
  265. SIENA_STAT_tx_lt64,
  266. SIENA_STAT_tx_64,
  267. SIENA_STAT_tx_65_to_127,
  268. SIENA_STAT_tx_128_to_255,
  269. SIENA_STAT_tx_256_to_511,
  270. SIENA_STAT_tx_512_to_1023,
  271. SIENA_STAT_tx_1024_to_15xx,
  272. SIENA_STAT_tx_15xx_to_jumbo,
  273. SIENA_STAT_tx_gtjumbo,
  274. SIENA_STAT_tx_collision,
  275. SIENA_STAT_tx_single_collision,
  276. SIENA_STAT_tx_multiple_collision,
  277. SIENA_STAT_tx_excessive_collision,
  278. SIENA_STAT_tx_deferred,
  279. SIENA_STAT_tx_late_collision,
  280. SIENA_STAT_tx_excessive_deferred,
  281. SIENA_STAT_tx_non_tcpudp,
  282. SIENA_STAT_tx_mac_src_error,
  283. SIENA_STAT_tx_ip_src_error,
  284. SIENA_STAT_rx_bytes,
  285. SIENA_STAT_rx_good_bytes,
  286. SIENA_STAT_rx_bad_bytes,
  287. SIENA_STAT_rx_packets,
  288. SIENA_STAT_rx_good,
  289. SIENA_STAT_rx_bad,
  290. SIENA_STAT_rx_pause,
  291. SIENA_STAT_rx_control,
  292. SIENA_STAT_rx_unicast,
  293. SIENA_STAT_rx_multicast,
  294. SIENA_STAT_rx_broadcast,
  295. SIENA_STAT_rx_lt64,
  296. SIENA_STAT_rx_64,
  297. SIENA_STAT_rx_65_to_127,
  298. SIENA_STAT_rx_128_to_255,
  299. SIENA_STAT_rx_256_to_511,
  300. SIENA_STAT_rx_512_to_1023,
  301. SIENA_STAT_rx_1024_to_15xx,
  302. SIENA_STAT_rx_15xx_to_jumbo,
  303. SIENA_STAT_rx_gtjumbo,
  304. SIENA_STAT_rx_bad_gtjumbo,
  305. SIENA_STAT_rx_overflow,
  306. SIENA_STAT_rx_false_carrier,
  307. SIENA_STAT_rx_symbol_error,
  308. SIENA_STAT_rx_align_error,
  309. SIENA_STAT_rx_length_error,
  310. SIENA_STAT_rx_internal_error,
  311. SIENA_STAT_rx_nodesc_drop_cnt,
  312. SIENA_STAT_COUNT
  313. };
  314. /**
  315. * struct siena_nic_data - Siena NIC state
  316. * @wol_filter_id: Wake-on-LAN packet filter id
  317. * @stats: Hardware statistics
  318. */
  319. struct siena_nic_data {
  320. int wol_filter_id;
  321. u64 stats[SIENA_STAT_COUNT];
  322. };
  323. /*
  324. * On the SFC9000 family each port is associated with 1 PCI physical
  325. * function (PF) handled by sfc and a configurable number of virtual
  326. * functions (VFs) that may be handled by some other driver, often in
  327. * a VM guest. The queue pointer registers are mapped in both PF and
  328. * VF BARs such that an 8K region provides access to a single RX, TX
  329. * and event queue (collectively a Virtual Interface, VI or VNIC).
  330. *
  331. * The PF has access to all 1024 VIs while VFs are mapped to VIs
  332. * according to VI_BASE and VI_SCALE: VF i has access to VIs numbered
  333. * in range [VI_BASE + i << VI_SCALE, VI_BASE + i + 1 << VI_SCALE).
  334. * The number of VIs and the VI_SCALE value are configurable but must
  335. * be established at boot time by firmware.
  336. */
  337. /* Maximum VI_SCALE parameter supported by Siena */
  338. #define EFX_VI_SCALE_MAX 6
  339. /* Base VI to use for SR-IOV. Must be aligned to (1 << EFX_VI_SCALE_MAX),
  340. * so this is the smallest allowed value. */
  341. #define EFX_VI_BASE 128U
  342. /* Maximum number of VFs allowed */
  343. #define EFX_VF_COUNT_MAX 127
  344. /* Limit EVQs on VFs to be only 8k to reduce buffer table reservation */
  345. #define EFX_MAX_VF_EVQ_SIZE 8192UL
  346. /* The number of buffer table entries reserved for each VI on a VF */
  347. #define EFX_VF_BUFTBL_PER_VI \
  348. ((EFX_MAX_VF_EVQ_SIZE + 2 * EFX_MAX_DMAQ_SIZE) * \
  349. sizeof(efx_qword_t) / EFX_BUF_SIZE)
  350. #ifdef CONFIG_SFC_SRIOV
  351. static inline bool efx_sriov_wanted(struct efx_nic *efx)
  352. {
  353. return efx->vf_count != 0;
  354. }
  355. static inline bool efx_sriov_enabled(struct efx_nic *efx)
  356. {
  357. return efx->vf_init_count != 0;
  358. }
  359. static inline unsigned int efx_vf_size(struct efx_nic *efx)
  360. {
  361. return 1 << efx->vi_scale;
  362. }
  363. extern int efx_init_sriov(void);
  364. extern void efx_sriov_probe(struct efx_nic *efx);
  365. extern int efx_sriov_init(struct efx_nic *efx);
  366. extern void efx_sriov_mac_address_changed(struct efx_nic *efx);
  367. extern void efx_sriov_tx_flush_done(struct efx_nic *efx, efx_qword_t *event);
  368. extern void efx_sriov_rx_flush_done(struct efx_nic *efx, efx_qword_t *event);
  369. extern void efx_sriov_event(struct efx_channel *channel, efx_qword_t *event);
  370. extern void efx_sriov_desc_fetch_err(struct efx_nic *efx, unsigned dmaq);
  371. extern void efx_sriov_flr(struct efx_nic *efx, unsigned flr);
  372. extern void efx_sriov_reset(struct efx_nic *efx);
  373. extern void efx_sriov_fini(struct efx_nic *efx);
  374. extern void efx_fini_sriov(void);
  375. #else
  376. static inline bool efx_sriov_wanted(struct efx_nic *efx) { return false; }
  377. static inline bool efx_sriov_enabled(struct efx_nic *efx) { return false; }
  378. static inline unsigned int efx_vf_size(struct efx_nic *efx) { return 0; }
  379. static inline int efx_init_sriov(void) { return 0; }
  380. static inline void efx_sriov_probe(struct efx_nic *efx) {}
  381. static inline int efx_sriov_init(struct efx_nic *efx) { return -EOPNOTSUPP; }
  382. static inline void efx_sriov_mac_address_changed(struct efx_nic *efx) {}
  383. static inline void efx_sriov_tx_flush_done(struct efx_nic *efx,
  384. efx_qword_t *event) {}
  385. static inline void efx_sriov_rx_flush_done(struct efx_nic *efx,
  386. efx_qword_t *event) {}
  387. static inline void efx_sriov_event(struct efx_channel *channel,
  388. efx_qword_t *event) {}
  389. static inline void efx_sriov_desc_fetch_err(struct efx_nic *efx, unsigned dmaq) {}
  390. static inline void efx_sriov_flr(struct efx_nic *efx, unsigned flr) {}
  391. static inline void efx_sriov_reset(struct efx_nic *efx) {}
  392. static inline void efx_sriov_fini(struct efx_nic *efx) {}
  393. static inline void efx_fini_sriov(void) {}
  394. #endif
  395. extern int efx_sriov_set_vf_mac(struct net_device *dev, int vf, u8 *mac);
  396. extern int efx_sriov_set_vf_vlan(struct net_device *dev, int vf,
  397. u16 vlan, u8 qos);
  398. extern int efx_sriov_get_vf_config(struct net_device *dev, int vf,
  399. struct ifla_vf_info *ivf);
  400. extern int efx_sriov_set_vf_spoofchk(struct net_device *net_dev, int vf,
  401. bool spoofchk);
  402. struct ethtool_ts_info;
  403. extern void efx_ptp_probe(struct efx_nic *efx);
  404. extern int efx_ptp_ioctl(struct efx_nic *efx, struct ifreq *ifr, int cmd);
  405. extern void efx_ptp_get_ts_info(struct efx_nic *efx,
  406. struct ethtool_ts_info *ts_info);
  407. extern bool efx_ptp_is_ptp_tx(struct efx_nic *efx, struct sk_buff *skb);
  408. extern int efx_ptp_tx(struct efx_nic *efx, struct sk_buff *skb);
  409. extern void efx_ptp_event(struct efx_nic *efx, efx_qword_t *ev);
  410. extern const struct efx_nic_type falcon_a1_nic_type;
  411. extern const struct efx_nic_type falcon_b0_nic_type;
  412. extern const struct efx_nic_type siena_a0_nic_type;
  413. /**************************************************************************
  414. *
  415. * Externs
  416. *
  417. **************************************************************************
  418. */
  419. extern int falcon_probe_board(struct efx_nic *efx, u16 revision_info);
  420. /* TX data path */
  421. static inline int efx_nic_probe_tx(struct efx_tx_queue *tx_queue)
  422. {
  423. return tx_queue->efx->type->tx_probe(tx_queue);
  424. }
  425. static inline void efx_nic_init_tx(struct efx_tx_queue *tx_queue)
  426. {
  427. tx_queue->efx->type->tx_init(tx_queue);
  428. }
  429. static inline void efx_nic_remove_tx(struct efx_tx_queue *tx_queue)
  430. {
  431. tx_queue->efx->type->tx_remove(tx_queue);
  432. }
  433. static inline void efx_nic_push_buffers(struct efx_tx_queue *tx_queue)
  434. {
  435. tx_queue->efx->type->tx_write(tx_queue);
  436. }
  437. /* RX data path */
  438. static inline int efx_nic_probe_rx(struct efx_rx_queue *rx_queue)
  439. {
  440. return rx_queue->efx->type->rx_probe(rx_queue);
  441. }
  442. static inline void efx_nic_init_rx(struct efx_rx_queue *rx_queue)
  443. {
  444. rx_queue->efx->type->rx_init(rx_queue);
  445. }
  446. static inline void efx_nic_remove_rx(struct efx_rx_queue *rx_queue)
  447. {
  448. rx_queue->efx->type->rx_remove(rx_queue);
  449. }
  450. static inline void efx_nic_notify_rx_desc(struct efx_rx_queue *rx_queue)
  451. {
  452. rx_queue->efx->type->rx_write(rx_queue);
  453. }
  454. static inline void efx_nic_generate_fill_event(struct efx_rx_queue *rx_queue)
  455. {
  456. rx_queue->efx->type->rx_defer_refill(rx_queue);
  457. }
  458. /* Event data path */
  459. static inline int efx_nic_probe_eventq(struct efx_channel *channel)
  460. {
  461. return channel->efx->type->ev_probe(channel);
  462. }
  463. static inline void efx_nic_init_eventq(struct efx_channel *channel)
  464. {
  465. channel->efx->type->ev_init(channel);
  466. }
  467. static inline void efx_nic_fini_eventq(struct efx_channel *channel)
  468. {
  469. channel->efx->type->ev_fini(channel);
  470. }
  471. static inline void efx_nic_remove_eventq(struct efx_channel *channel)
  472. {
  473. channel->efx->type->ev_remove(channel);
  474. }
  475. static inline int
  476. efx_nic_process_eventq(struct efx_channel *channel, int quota)
  477. {
  478. return channel->efx->type->ev_process(channel, quota);
  479. }
  480. static inline void efx_nic_eventq_read_ack(struct efx_channel *channel)
  481. {
  482. channel->efx->type->ev_read_ack(channel);
  483. }
  484. extern void efx_nic_event_test_start(struct efx_channel *channel);
  485. /* Falcon/Siena queue operations */
  486. extern int efx_farch_tx_probe(struct efx_tx_queue *tx_queue);
  487. extern void efx_farch_tx_init(struct efx_tx_queue *tx_queue);
  488. extern void efx_farch_tx_fini(struct efx_tx_queue *tx_queue);
  489. extern void efx_farch_tx_remove(struct efx_tx_queue *tx_queue);
  490. extern void efx_farch_tx_write(struct efx_tx_queue *tx_queue);
  491. extern int efx_farch_rx_probe(struct efx_rx_queue *rx_queue);
  492. extern void efx_farch_rx_init(struct efx_rx_queue *rx_queue);
  493. extern void efx_farch_rx_fini(struct efx_rx_queue *rx_queue);
  494. extern void efx_farch_rx_remove(struct efx_rx_queue *rx_queue);
  495. extern void efx_farch_rx_write(struct efx_rx_queue *rx_queue);
  496. extern void efx_farch_rx_defer_refill(struct efx_rx_queue *rx_queue);
  497. extern int efx_farch_ev_probe(struct efx_channel *channel);
  498. extern void efx_farch_ev_init(struct efx_channel *channel);
  499. extern void efx_farch_ev_fini(struct efx_channel *channel);
  500. extern void efx_farch_ev_remove(struct efx_channel *channel);
  501. extern int efx_farch_ev_process(struct efx_channel *channel, int quota);
  502. extern void efx_farch_ev_read_ack(struct efx_channel *channel);
  503. extern void efx_farch_ev_test_generate(struct efx_channel *channel);
  504. /* Falcon/Siena filter operations */
  505. extern int efx_farch_filter_table_probe(struct efx_nic *efx);
  506. extern void efx_farch_filter_table_restore(struct efx_nic *efx);
  507. extern void efx_farch_filter_table_remove(struct efx_nic *efx);
  508. extern void efx_farch_filter_update_rx_scatter(struct efx_nic *efx);
  509. extern s32 efx_farch_filter_insert(struct efx_nic *efx,
  510. struct efx_filter_spec *spec, bool replace);
  511. extern int efx_farch_filter_remove_safe(struct efx_nic *efx,
  512. enum efx_filter_priority priority,
  513. u32 filter_id);
  514. extern int efx_farch_filter_get_safe(struct efx_nic *efx,
  515. enum efx_filter_priority priority,
  516. u32 filter_id, struct efx_filter_spec *);
  517. extern void efx_farch_filter_clear_rx(struct efx_nic *efx,
  518. enum efx_filter_priority priority);
  519. extern u32 efx_farch_filter_count_rx_used(struct efx_nic *efx,
  520. enum efx_filter_priority priority);
  521. extern u32 efx_farch_filter_get_rx_id_limit(struct efx_nic *efx);
  522. extern s32 efx_farch_filter_get_rx_ids(struct efx_nic *efx,
  523. enum efx_filter_priority priority,
  524. u32 *buf, u32 size);
  525. #ifdef CONFIG_RFS_ACCEL
  526. extern s32 efx_farch_filter_rfs_insert(struct efx_nic *efx,
  527. struct efx_filter_spec *spec);
  528. extern bool efx_farch_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
  529. unsigned int index);
  530. #endif
  531. extern void efx_farch_filter_sync_rx_mode(struct efx_nic *efx);
  532. extern bool efx_nic_event_present(struct efx_channel *channel);
  533. /* Some statistics are computed as A - B where A and B each increase
  534. * linearly with some hardware counter(s) and the counters are read
  535. * asynchronously. If the counters contributing to B are always read
  536. * after those contributing to A, the computed value may be lower than
  537. * the true value by some variable amount, and may decrease between
  538. * subsequent computations.
  539. *
  540. * We should never allow statistics to decrease or to exceed the true
  541. * value. Since the computed value will never be greater than the
  542. * true value, we can achieve this by only storing the computed value
  543. * when it increases.
  544. */
  545. static inline void efx_update_diff_stat(u64 *stat, u64 diff)
  546. {
  547. if ((s64)(diff - *stat) > 0)
  548. *stat = diff;
  549. }
  550. /* Interrupts */
  551. extern int efx_nic_init_interrupt(struct efx_nic *efx);
  552. extern void efx_nic_irq_test_start(struct efx_nic *efx);
  553. extern void efx_nic_fini_interrupt(struct efx_nic *efx);
  554. /* Falcon/Siena interrupts */
  555. extern void efx_farch_irq_enable_master(struct efx_nic *efx);
  556. extern void efx_farch_irq_test_generate(struct efx_nic *efx);
  557. extern void efx_farch_irq_disable_master(struct efx_nic *efx);
  558. extern irqreturn_t efx_farch_msi_interrupt(int irq, void *dev_id);
  559. extern irqreturn_t efx_farch_legacy_interrupt(int irq, void *dev_id);
  560. extern irqreturn_t efx_farch_fatal_interrupt(struct efx_nic *efx);
  561. static inline int efx_nic_event_test_irq_cpu(struct efx_channel *channel)
  562. {
  563. return ACCESS_ONCE(channel->event_test_cpu);
  564. }
  565. static inline int efx_nic_irq_test_irq_cpu(struct efx_nic *efx)
  566. {
  567. return ACCESS_ONCE(efx->last_irq_cpu);
  568. }
  569. /* Global Resources */
  570. extern int efx_nic_flush_queues(struct efx_nic *efx);
  571. extern void siena_prepare_flush(struct efx_nic *efx);
  572. extern int efx_farch_fini_dmaq(struct efx_nic *efx);
  573. extern void siena_finish_flush(struct efx_nic *efx);
  574. extern void falcon_start_nic_stats(struct efx_nic *efx);
  575. extern void falcon_stop_nic_stats(struct efx_nic *efx);
  576. extern int falcon_reset_xaui(struct efx_nic *efx);
  577. extern void efx_farch_dimension_resources(struct efx_nic *efx, unsigned sram_lim_qw);
  578. extern void efx_farch_init_common(struct efx_nic *efx);
  579. static inline void efx_nic_push_rx_indir_table(struct efx_nic *efx)
  580. {
  581. efx->type->rx_push_indir_table(efx);
  582. }
  583. extern void efx_farch_rx_push_indir_table(struct efx_nic *efx);
  584. int efx_nic_alloc_buffer(struct efx_nic *efx, struct efx_buffer *buffer,
  585. unsigned int len, gfp_t gfp_flags);
  586. void efx_nic_free_buffer(struct efx_nic *efx, struct efx_buffer *buffer);
  587. /* Tests */
  588. struct efx_farch_register_test {
  589. unsigned address;
  590. efx_oword_t mask;
  591. };
  592. extern int efx_farch_test_registers(struct efx_nic *efx,
  593. const struct efx_farch_register_test *regs,
  594. size_t n_regs);
  595. extern size_t efx_nic_get_regs_len(struct efx_nic *efx);
  596. extern void efx_nic_get_regs(struct efx_nic *efx, void *buf);
  597. extern size_t
  598. efx_nic_describe_stats(const struct efx_hw_stat_desc *desc, size_t count,
  599. const unsigned long *mask, u8 *names);
  600. extern void
  601. efx_nic_update_stats(const struct efx_hw_stat_desc *desc, size_t count,
  602. const unsigned long *mask,
  603. u64 *stats, const void *dma_buf, bool accumulate);
  604. #define EFX_MAX_FLUSH_TIME 5000
  605. extern void efx_farch_generate_event(struct efx_nic *efx, unsigned int evq,
  606. efx_qword_t *event);
  607. #endif /* EFX_NIC_H */