nic.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2006-2011 Solarflare Communications Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation, incorporated herein by reference.
  9. */
  10. #ifndef EFX_NIC_H
  11. #define EFX_NIC_H
  12. #include <linux/net_tstamp.h>
  13. #include <linux/i2c-algo-bit.h>
  14. #include "net_driver.h"
  15. #include "efx.h"
  16. #include "mcdi.h"
  17. #include "spi.h"
  18. /*
  19. * Falcon hardware control
  20. */
  21. enum {
  22. EFX_REV_FALCON_A0 = 0,
  23. EFX_REV_FALCON_A1 = 1,
  24. EFX_REV_FALCON_B0 = 2,
  25. EFX_REV_SIENA_A0 = 3,
  26. };
  27. static inline int efx_nic_rev(struct efx_nic *efx)
  28. {
  29. return efx->type->revision;
  30. }
  31. extern u32 efx_nic_fpga_ver(struct efx_nic *efx);
  32. /* NIC has two interlinked PCI functions for the same port. */
  33. static inline bool efx_nic_is_dual_func(struct efx_nic *efx)
  34. {
  35. return efx_nic_rev(efx) < EFX_REV_FALCON_B0;
  36. }
  37. enum {
  38. PHY_TYPE_NONE = 0,
  39. PHY_TYPE_TXC43128 = 1,
  40. PHY_TYPE_88E1111 = 2,
  41. PHY_TYPE_SFX7101 = 3,
  42. PHY_TYPE_QT2022C2 = 4,
  43. PHY_TYPE_PM8358 = 6,
  44. PHY_TYPE_SFT9001A = 8,
  45. PHY_TYPE_QT2025C = 9,
  46. PHY_TYPE_SFT9001B = 10,
  47. };
  48. #define FALCON_XMAC_LOOPBACKS \
  49. ((1 << LOOPBACK_XGMII) | \
  50. (1 << LOOPBACK_XGXS) | \
  51. (1 << LOOPBACK_XAUI))
  52. #define FALCON_GMAC_LOOPBACKS \
  53. (1 << LOOPBACK_GMAC)
  54. /* Alignment of PCIe DMA boundaries (4KB) */
  55. #define EFX_PAGE_SIZE 4096
  56. /* Size and alignment of buffer table entries (same) */
  57. #define EFX_BUF_SIZE EFX_PAGE_SIZE
  58. /**
  59. * struct falcon_board_type - board operations and type information
  60. * @id: Board type id, as found in NVRAM
  61. * @init: Allocate resources and initialise peripheral hardware
  62. * @init_phy: Do board-specific PHY initialisation
  63. * @fini: Shut down hardware and free resources
  64. * @set_id_led: Set state of identifying LED or revert to automatic function
  65. * @monitor: Board-specific health check function
  66. */
  67. struct falcon_board_type {
  68. u8 id;
  69. int (*init) (struct efx_nic *nic);
  70. void (*init_phy) (struct efx_nic *efx);
  71. void (*fini) (struct efx_nic *nic);
  72. void (*set_id_led) (struct efx_nic *efx, enum efx_led_mode mode);
  73. int (*monitor) (struct efx_nic *nic);
  74. };
  75. /**
  76. * struct falcon_board - board information
  77. * @type: Type of board
  78. * @major: Major rev. ('A', 'B' ...)
  79. * @minor: Minor rev. (0, 1, ...)
  80. * @i2c_adap: I2C adapter for on-board peripherals
  81. * @i2c_data: Data for bit-banging algorithm
  82. * @hwmon_client: I2C client for hardware monitor
  83. * @ioexp_client: I2C client for power/port control
  84. */
  85. struct falcon_board {
  86. const struct falcon_board_type *type;
  87. int major;
  88. int minor;
  89. struct i2c_adapter i2c_adap;
  90. struct i2c_algo_bit_data i2c_data;
  91. struct i2c_client *hwmon_client, *ioexp_client;
  92. };
  93. /**
  94. * struct falcon_nic_data - Falcon NIC state
  95. * @pci_dev2: Secondary function of Falcon A
  96. * @board: Board state and functions
  97. * @stats_disable_count: Nest count for disabling statistics fetches
  98. * @stats_pending: Is there a pending DMA of MAC statistics.
  99. * @stats_timer: A timer for regularly fetching MAC statistics.
  100. * @stats_dma_done: Pointer to the flag which indicates DMA completion.
  101. * @spi_flash: SPI flash device
  102. * @spi_eeprom: SPI EEPROM device
  103. * @spi_lock: SPI bus lock
  104. * @mdio_lock: MDIO bus lock
  105. * @xmac_poll_required: XMAC link state needs polling
  106. */
  107. struct falcon_nic_data {
  108. struct pci_dev *pci_dev2;
  109. struct falcon_board board;
  110. unsigned int stats_disable_count;
  111. bool stats_pending;
  112. struct timer_list stats_timer;
  113. u32 *stats_dma_done;
  114. struct efx_spi_device spi_flash;
  115. struct efx_spi_device spi_eeprom;
  116. struct mutex spi_lock;
  117. struct mutex mdio_lock;
  118. bool xmac_poll_required;
  119. };
  120. static inline struct falcon_board *falcon_board(struct efx_nic *efx)
  121. {
  122. struct falcon_nic_data *data = efx->nic_data;
  123. return &data->board;
  124. }
  125. /**
  126. * struct siena_nic_data - Siena NIC state
  127. * @wol_filter_id: Wake-on-LAN packet filter id
  128. */
  129. struct siena_nic_data {
  130. int wol_filter_id;
  131. };
  132. /*
  133. * On the SFC9000 family each port is associated with 1 PCI physical
  134. * function (PF) handled by sfc and a configurable number of virtual
  135. * functions (VFs) that may be handled by some other driver, often in
  136. * a VM guest. The queue pointer registers are mapped in both PF and
  137. * VF BARs such that an 8K region provides access to a single RX, TX
  138. * and event queue (collectively a Virtual Interface, VI or VNIC).
  139. *
  140. * The PF has access to all 1024 VIs while VFs are mapped to VIs
  141. * according to VI_BASE and VI_SCALE: VF i has access to VIs numbered
  142. * in range [VI_BASE + i << VI_SCALE, VI_BASE + i + 1 << VI_SCALE).
  143. * The number of VIs and the VI_SCALE value are configurable but must
  144. * be established at boot time by firmware.
  145. */
  146. /* Maximum VI_SCALE parameter supported by Siena */
  147. #define EFX_VI_SCALE_MAX 6
  148. /* Base VI to use for SR-IOV. Must be aligned to (1 << EFX_VI_SCALE_MAX),
  149. * so this is the smallest allowed value. */
  150. #define EFX_VI_BASE 128U
  151. /* Maximum number of VFs allowed */
  152. #define EFX_VF_COUNT_MAX 127
  153. /* Limit EVQs on VFs to be only 8k to reduce buffer table reservation */
  154. #define EFX_MAX_VF_EVQ_SIZE 8192UL
  155. /* The number of buffer table entries reserved for each VI on a VF */
  156. #define EFX_VF_BUFTBL_PER_VI \
  157. ((EFX_MAX_VF_EVQ_SIZE + 2 * EFX_MAX_DMAQ_SIZE) * \
  158. sizeof(efx_qword_t) / EFX_BUF_SIZE)
  159. #ifdef CONFIG_SFC_SRIOV
  160. static inline bool efx_sriov_wanted(struct efx_nic *efx)
  161. {
  162. return efx->vf_count != 0;
  163. }
  164. static inline bool efx_sriov_enabled(struct efx_nic *efx)
  165. {
  166. return efx->vf_init_count != 0;
  167. }
  168. static inline unsigned int efx_vf_size(struct efx_nic *efx)
  169. {
  170. return 1 << efx->vi_scale;
  171. }
  172. extern int efx_init_sriov(void);
  173. extern void efx_sriov_probe(struct efx_nic *efx);
  174. extern int efx_sriov_init(struct efx_nic *efx);
  175. extern void efx_sriov_mac_address_changed(struct efx_nic *efx);
  176. extern void efx_sriov_tx_flush_done(struct efx_nic *efx, efx_qword_t *event);
  177. extern void efx_sriov_rx_flush_done(struct efx_nic *efx, efx_qword_t *event);
  178. extern void efx_sriov_event(struct efx_channel *channel, efx_qword_t *event);
  179. extern void efx_sriov_desc_fetch_err(struct efx_nic *efx, unsigned dmaq);
  180. extern void efx_sriov_flr(struct efx_nic *efx, unsigned flr);
  181. extern void efx_sriov_reset(struct efx_nic *efx);
  182. extern void efx_sriov_fini(struct efx_nic *efx);
  183. extern void efx_fini_sriov(void);
  184. #else
  185. static inline bool efx_sriov_wanted(struct efx_nic *efx) { return false; }
  186. static inline bool efx_sriov_enabled(struct efx_nic *efx) { return false; }
  187. static inline unsigned int efx_vf_size(struct efx_nic *efx) { return 0; }
  188. static inline int efx_init_sriov(void) { return 0; }
  189. static inline void efx_sriov_probe(struct efx_nic *efx) {}
  190. static inline int efx_sriov_init(struct efx_nic *efx) { return -EOPNOTSUPP; }
  191. static inline void efx_sriov_mac_address_changed(struct efx_nic *efx) {}
  192. static inline void efx_sriov_tx_flush_done(struct efx_nic *efx,
  193. efx_qword_t *event) {}
  194. static inline void efx_sriov_rx_flush_done(struct efx_nic *efx,
  195. efx_qword_t *event) {}
  196. static inline void efx_sriov_event(struct efx_channel *channel,
  197. efx_qword_t *event) {}
  198. static inline void efx_sriov_desc_fetch_err(struct efx_nic *efx, unsigned dmaq) {}
  199. static inline void efx_sriov_flr(struct efx_nic *efx, unsigned flr) {}
  200. static inline void efx_sriov_reset(struct efx_nic *efx) {}
  201. static inline void efx_sriov_fini(struct efx_nic *efx) {}
  202. static inline void efx_fini_sriov(void) {}
  203. #endif
  204. extern int efx_sriov_set_vf_mac(struct net_device *dev, int vf, u8 *mac);
  205. extern int efx_sriov_set_vf_vlan(struct net_device *dev, int vf,
  206. u16 vlan, u8 qos);
  207. extern int efx_sriov_get_vf_config(struct net_device *dev, int vf,
  208. struct ifla_vf_info *ivf);
  209. extern int efx_sriov_set_vf_spoofchk(struct net_device *net_dev, int vf,
  210. bool spoofchk);
  211. struct ethtool_ts_info;
  212. extern void efx_ptp_probe(struct efx_nic *efx);
  213. extern int efx_ptp_ioctl(struct efx_nic *efx, struct ifreq *ifr, int cmd);
  214. extern void efx_ptp_get_ts_info(struct efx_nic *efx,
  215. struct ethtool_ts_info *ts_info);
  216. extern bool efx_ptp_is_ptp_tx(struct efx_nic *efx, struct sk_buff *skb);
  217. extern int efx_ptp_tx(struct efx_nic *efx, struct sk_buff *skb);
  218. extern void efx_ptp_event(struct efx_nic *efx, efx_qword_t *ev);
  219. extern const struct efx_nic_type falcon_a1_nic_type;
  220. extern const struct efx_nic_type falcon_b0_nic_type;
  221. extern const struct efx_nic_type siena_a0_nic_type;
  222. /**************************************************************************
  223. *
  224. * Externs
  225. *
  226. **************************************************************************
  227. */
  228. extern int falcon_probe_board(struct efx_nic *efx, u16 revision_info);
  229. /* TX data path */
  230. extern int efx_nic_probe_tx(struct efx_tx_queue *tx_queue);
  231. extern void efx_nic_init_tx(struct efx_tx_queue *tx_queue);
  232. extern void efx_nic_fini_tx(struct efx_tx_queue *tx_queue);
  233. extern void efx_nic_remove_tx(struct efx_tx_queue *tx_queue);
  234. extern void efx_nic_push_buffers(struct efx_tx_queue *tx_queue);
  235. /* RX data path */
  236. extern int efx_nic_probe_rx(struct efx_rx_queue *rx_queue);
  237. extern void efx_nic_init_rx(struct efx_rx_queue *rx_queue);
  238. extern void efx_nic_fini_rx(struct efx_rx_queue *rx_queue);
  239. extern void efx_nic_remove_rx(struct efx_rx_queue *rx_queue);
  240. extern void efx_nic_notify_rx_desc(struct efx_rx_queue *rx_queue);
  241. extern void efx_nic_generate_fill_event(struct efx_rx_queue *rx_queue);
  242. /* Event data path */
  243. extern int efx_nic_probe_eventq(struct efx_channel *channel);
  244. extern void efx_nic_init_eventq(struct efx_channel *channel);
  245. extern void efx_nic_fini_eventq(struct efx_channel *channel);
  246. extern void efx_nic_remove_eventq(struct efx_channel *channel);
  247. extern int efx_nic_process_eventq(struct efx_channel *channel, int rx_quota);
  248. extern void efx_nic_eventq_read_ack(struct efx_channel *channel);
  249. extern bool efx_nic_event_present(struct efx_channel *channel);
  250. /* Some statistics are computed as A - B where A and B each increase
  251. * linearly with some hardware counter(s) and the counters are read
  252. * asynchronously. If the counters contributing to B are always read
  253. * after those contributing to A, the computed value may be lower than
  254. * the true value by some variable amount, and may decrease between
  255. * subsequent computations.
  256. *
  257. * We should never allow statistics to decrease or to exceed the true
  258. * value. Since the computed value will never be greater than the
  259. * true value, we can achieve this by only storing the computed value
  260. * when it increases.
  261. */
  262. static inline void efx_update_diff_stat(u64 *stat, u64 diff)
  263. {
  264. if ((s64)(diff - *stat) > 0)
  265. *stat = diff;
  266. }
  267. /* Interrupts and test events */
  268. extern int efx_nic_init_interrupt(struct efx_nic *efx);
  269. extern void efx_nic_enable_interrupts(struct efx_nic *efx);
  270. extern void efx_nic_event_test_start(struct efx_channel *channel);
  271. extern void efx_nic_irq_test_start(struct efx_nic *efx);
  272. extern void efx_nic_disable_interrupts(struct efx_nic *efx);
  273. extern void efx_nic_fini_interrupt(struct efx_nic *efx);
  274. extern irqreturn_t efx_nic_fatal_interrupt(struct efx_nic *efx);
  275. extern irqreturn_t falcon_legacy_interrupt_a1(int irq, void *dev_id);
  276. static inline int efx_nic_event_test_irq_cpu(struct efx_channel *channel)
  277. {
  278. return ACCESS_ONCE(channel->event_test_cpu);
  279. }
  280. static inline int efx_nic_irq_test_irq_cpu(struct efx_nic *efx)
  281. {
  282. return ACCESS_ONCE(efx->last_irq_cpu);
  283. }
  284. /* Global Resources */
  285. extern int efx_nic_flush_queues(struct efx_nic *efx);
  286. extern void siena_prepare_flush(struct efx_nic *efx);
  287. extern void siena_finish_flush(struct efx_nic *efx);
  288. extern void falcon_start_nic_stats(struct efx_nic *efx);
  289. extern void falcon_stop_nic_stats(struct efx_nic *efx);
  290. extern int falcon_reset_xaui(struct efx_nic *efx);
  291. extern void
  292. efx_nic_dimension_resources(struct efx_nic *efx, unsigned sram_lim_qw);
  293. extern void efx_nic_init_common(struct efx_nic *efx);
  294. extern void efx_nic_push_rx_indir_table(struct efx_nic *efx);
  295. int efx_nic_alloc_buffer(struct efx_nic *efx, struct efx_buffer *buffer,
  296. unsigned int len, gfp_t gfp_flags);
  297. void efx_nic_free_buffer(struct efx_nic *efx, struct efx_buffer *buffer);
  298. /* Tests */
  299. struct efx_nic_register_test {
  300. unsigned address;
  301. efx_oword_t mask;
  302. };
  303. extern int efx_nic_test_registers(struct efx_nic *efx,
  304. const struct efx_nic_register_test *regs,
  305. size_t n_regs);
  306. extern size_t efx_nic_get_regs_len(struct efx_nic *efx);
  307. extern void efx_nic_get_regs(struct efx_nic *efx, void *buf);
  308. #define EFX_MAX_FLUSH_TIME 5000
  309. extern void efx_generate_event(struct efx_nic *efx, unsigned int evq,
  310. efx_qword_t *event);
  311. #endif /* EFX_NIC_H */