nic.h 26 KB

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