nic.h 26 KB

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