nic.h 24 KB

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