nic.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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/i2c-algo-bit.h>
  13. #include "net_driver.h"
  14. #include "efx.h"
  15. #include "mcdi.h"
  16. #include "spi.h"
  17. /*
  18. * Falcon hardware control
  19. */
  20. enum {
  21. EFX_REV_FALCON_A0 = 0,
  22. EFX_REV_FALCON_A1 = 1,
  23. EFX_REV_FALCON_B0 = 2,
  24. EFX_REV_SIENA_A0 = 3,
  25. };
  26. static inline int efx_nic_rev(struct efx_nic *efx)
  27. {
  28. return efx->type->revision;
  29. }
  30. extern u32 efx_nic_fpga_ver(struct efx_nic *efx);
  31. /* NIC has two interlinked PCI functions for the same port. */
  32. static inline bool efx_nic_is_dual_func(struct efx_nic *efx)
  33. {
  34. return efx_nic_rev(efx) < EFX_REV_FALCON_B0;
  35. }
  36. enum {
  37. PHY_TYPE_NONE = 0,
  38. PHY_TYPE_TXC43128 = 1,
  39. PHY_TYPE_88E1111 = 2,
  40. PHY_TYPE_SFX7101 = 3,
  41. PHY_TYPE_QT2022C2 = 4,
  42. PHY_TYPE_PM8358 = 6,
  43. PHY_TYPE_SFT9001A = 8,
  44. PHY_TYPE_QT2025C = 9,
  45. PHY_TYPE_SFT9001B = 10,
  46. };
  47. #define FALCON_XMAC_LOOPBACKS \
  48. ((1 << LOOPBACK_XGMII) | \
  49. (1 << LOOPBACK_XGXS) | \
  50. (1 << LOOPBACK_XAUI))
  51. #define FALCON_GMAC_LOOPBACKS \
  52. (1 << LOOPBACK_GMAC)
  53. /* Alignment of PCIe DMA boundaries (4KB) */
  54. #define EFX_PAGE_SIZE 4096
  55. /* Size and alignment of buffer table entries (same) */
  56. #define EFX_BUF_SIZE EFX_PAGE_SIZE
  57. /**
  58. * struct falcon_board_type - board operations and type information
  59. * @id: Board type id, as found in NVRAM
  60. * @ref_model: Model number of Solarflare reference design
  61. * @gen_type: Generic board type description
  62. * @init: Allocate resources and initialise peripheral hardware
  63. * @init_phy: Do board-specific PHY initialisation
  64. * @fini: Shut down hardware and free resources
  65. * @set_id_led: Set state of identifying LED or revert to automatic function
  66. * @monitor: Board-specific health check function
  67. */
  68. struct falcon_board_type {
  69. u8 id;
  70. const char *ref_model;
  71. const char *gen_type;
  72. int (*init) (struct efx_nic *nic);
  73. void (*init_phy) (struct efx_nic *efx);
  74. void (*fini) (struct efx_nic *nic);
  75. void (*set_id_led) (struct efx_nic *efx, enum efx_led_mode mode);
  76. int (*monitor) (struct efx_nic *nic);
  77. };
  78. /**
  79. * struct falcon_board - board information
  80. * @type: Type of board
  81. * @major: Major rev. ('A', 'B' ...)
  82. * @minor: Minor rev. (0, 1, ...)
  83. * @i2c_adap: I2C adapter for on-board peripherals
  84. * @i2c_data: Data for bit-banging algorithm
  85. * @hwmon_client: I2C client for hardware monitor
  86. * @ioexp_client: I2C client for power/port control
  87. */
  88. struct falcon_board {
  89. const struct falcon_board_type *type;
  90. int major;
  91. int minor;
  92. struct i2c_adapter i2c_adap;
  93. struct i2c_algo_bit_data i2c_data;
  94. struct i2c_client *hwmon_client, *ioexp_client;
  95. };
  96. /**
  97. * struct falcon_nic_data - Falcon NIC state
  98. * @pci_dev2: Secondary function of Falcon A
  99. * @board: Board state and functions
  100. * @stats_disable_count: Nest count for disabling statistics fetches
  101. * @stats_pending: Is there a pending DMA of MAC statistics.
  102. * @stats_timer: A timer for regularly fetching MAC statistics.
  103. * @stats_dma_done: Pointer to the flag which indicates DMA completion.
  104. * @spi_flash: SPI flash device
  105. * @spi_eeprom: SPI EEPROM device
  106. * @spi_lock: SPI bus lock
  107. * @mdio_lock: MDIO bus lock
  108. * @xmac_poll_required: XMAC link state needs polling
  109. */
  110. struct falcon_nic_data {
  111. struct pci_dev *pci_dev2;
  112. struct falcon_board board;
  113. unsigned int stats_disable_count;
  114. bool stats_pending;
  115. struct timer_list stats_timer;
  116. u32 *stats_dma_done;
  117. struct efx_spi_device spi_flash;
  118. struct efx_spi_device spi_eeprom;
  119. struct mutex spi_lock;
  120. struct mutex mdio_lock;
  121. bool xmac_poll_required;
  122. };
  123. static inline struct falcon_board *falcon_board(struct efx_nic *efx)
  124. {
  125. struct falcon_nic_data *data = efx->nic_data;
  126. return &data->board;
  127. }
  128. /**
  129. * struct siena_nic_data - Siena NIC state
  130. * @mcdi: Management-Controller-to-Driver Interface
  131. * @wol_filter_id: Wake-on-LAN packet filter id
  132. * @hwmon: Hardware monitor state
  133. */
  134. struct siena_nic_data {
  135. struct efx_mcdi_iface mcdi;
  136. int wol_filter_id;
  137. #ifdef CONFIG_SFC_MCDI_MON
  138. struct efx_mcdi_mon hwmon;
  139. #endif
  140. };
  141. #ifdef CONFIG_SFC_MCDI_MON
  142. static inline struct efx_mcdi_mon *efx_mcdi_mon(struct efx_nic *efx)
  143. {
  144. struct siena_nic_data *nic_data;
  145. EFX_BUG_ON_PARANOID(efx_nic_rev(efx) < EFX_REV_SIENA_A0);
  146. nic_data = efx->nic_data;
  147. return &nic_data->hwmon;
  148. }
  149. #endif
  150. /*
  151. * On the SFC9000 family each port is associated with 1 PCI physical
  152. * function (PF) handled by sfc and a configurable number of virtual
  153. * functions (VFs) that may be handled by some other driver, often in
  154. * a VM guest. The queue pointer registers are mapped in both PF and
  155. * VF BARs such that an 8K region provides access to a single RX, TX
  156. * and event queue (collectively a Virtual Interface, VI or VNIC).
  157. *
  158. * The PF has access to all 1024 VIs while VFs are mapped to VIs
  159. * according to VI_BASE and VI_SCALE: VF i has access to VIs numbered
  160. * in range [VI_BASE + i << VI_SCALE, VI_BASE + i + 1 << VI_SCALE).
  161. * The number of VIs and the VI_SCALE value are configurable but must
  162. * be established at boot time by firmware.
  163. */
  164. /* Maximum VI_SCALE parameter supported by Siena */
  165. #define EFX_VI_SCALE_MAX 6
  166. /* Base VI to use for SR-IOV. Must be aligned to (1 << EFX_VI_SCALE_MAX),
  167. * so this is the smallest allowed value. */
  168. #define EFX_VI_BASE 128U
  169. /* Maximum number of VFs allowed */
  170. #define EFX_VF_COUNT_MAX 127
  171. /* Limit EVQs on VFs to be only 8k to reduce buffer table reservation */
  172. #define EFX_MAX_VF_EVQ_SIZE 8192UL
  173. /* The number of buffer table entries reserved for each VI on a VF */
  174. #define EFX_VF_BUFTBL_PER_VI \
  175. ((EFX_MAX_VF_EVQ_SIZE + 2 * EFX_MAX_DMAQ_SIZE) * \
  176. sizeof(efx_qword_t) / EFX_BUF_SIZE)
  177. #ifdef CONFIG_SFC_SRIOV
  178. static inline bool efx_sriov_wanted(struct efx_nic *efx)
  179. {
  180. return efx->vf_count != 0;
  181. }
  182. static inline bool efx_sriov_enabled(struct efx_nic *efx)
  183. {
  184. return efx->vf_init_count != 0;
  185. }
  186. static inline unsigned int efx_vf_size(struct efx_nic *efx)
  187. {
  188. return 1 << efx->vi_scale;
  189. }
  190. extern int efx_init_sriov(void);
  191. extern void efx_sriov_probe(struct efx_nic *efx);
  192. extern int efx_sriov_init(struct efx_nic *efx);
  193. extern void efx_sriov_mac_address_changed(struct efx_nic *efx);
  194. extern void efx_sriov_tx_flush_done(struct efx_nic *efx, efx_qword_t *event);
  195. extern void efx_sriov_rx_flush_done(struct efx_nic *efx, efx_qword_t *event);
  196. extern void efx_sriov_event(struct efx_channel *channel, efx_qword_t *event);
  197. extern void efx_sriov_desc_fetch_err(struct efx_nic *efx, unsigned dmaq);
  198. extern void efx_sriov_flr(struct efx_nic *efx, unsigned flr);
  199. extern void efx_sriov_reset(struct efx_nic *efx);
  200. extern void efx_sriov_fini(struct efx_nic *efx);
  201. extern void efx_fini_sriov(void);
  202. #else
  203. static inline bool efx_sriov_wanted(struct efx_nic *efx) { return false; }
  204. static inline bool efx_sriov_enabled(struct efx_nic *efx) { return false; }
  205. static inline unsigned int efx_vf_size(struct efx_nic *efx) { return 0; }
  206. static inline int efx_init_sriov(void) { return 0; }
  207. static inline void efx_sriov_probe(struct efx_nic *efx) {}
  208. static inline int efx_sriov_init(struct efx_nic *efx) { return -EOPNOTSUPP; }
  209. static inline void efx_sriov_mac_address_changed(struct efx_nic *efx) {}
  210. static inline void efx_sriov_tx_flush_done(struct efx_nic *efx,
  211. efx_qword_t *event) {}
  212. static inline void efx_sriov_rx_flush_done(struct efx_nic *efx,
  213. efx_qword_t *event) {}
  214. static inline void efx_sriov_event(struct efx_channel *channel,
  215. efx_qword_t *event) {}
  216. static inline void efx_sriov_desc_fetch_err(struct efx_nic *efx, unsigned dmaq) {}
  217. static inline void efx_sriov_flr(struct efx_nic *efx, unsigned flr) {}
  218. static inline void efx_sriov_reset(struct efx_nic *efx) {}
  219. static inline void efx_sriov_fini(struct efx_nic *efx) {}
  220. static inline void efx_fini_sriov(void) {}
  221. #endif
  222. extern int efx_sriov_set_vf_mac(struct net_device *dev, int vf, u8 *mac);
  223. extern int efx_sriov_set_vf_vlan(struct net_device *dev, int vf,
  224. u16 vlan, u8 qos);
  225. extern int efx_sriov_get_vf_config(struct net_device *dev, int vf,
  226. struct ifla_vf_info *ivf);
  227. extern int efx_sriov_set_vf_spoofchk(struct net_device *net_dev, int vf,
  228. bool spoofchk);
  229. extern const struct efx_nic_type falcon_a1_nic_type;
  230. extern const struct efx_nic_type falcon_b0_nic_type;
  231. extern const struct efx_nic_type siena_a0_nic_type;
  232. /**************************************************************************
  233. *
  234. * Externs
  235. *
  236. **************************************************************************
  237. */
  238. extern int falcon_probe_board(struct efx_nic *efx, u16 revision_info);
  239. /* TX data path */
  240. extern int efx_nic_probe_tx(struct efx_tx_queue *tx_queue);
  241. extern void efx_nic_init_tx(struct efx_tx_queue *tx_queue);
  242. extern void efx_nic_fini_tx(struct efx_tx_queue *tx_queue);
  243. extern void efx_nic_remove_tx(struct efx_tx_queue *tx_queue);
  244. extern void efx_nic_push_buffers(struct efx_tx_queue *tx_queue);
  245. /* RX data path */
  246. extern int efx_nic_probe_rx(struct efx_rx_queue *rx_queue);
  247. extern void efx_nic_init_rx(struct efx_rx_queue *rx_queue);
  248. extern void efx_nic_fini_rx(struct efx_rx_queue *rx_queue);
  249. extern void efx_nic_remove_rx(struct efx_rx_queue *rx_queue);
  250. extern void efx_nic_notify_rx_desc(struct efx_rx_queue *rx_queue);
  251. extern void efx_nic_generate_fill_event(struct efx_rx_queue *rx_queue);
  252. /* Event data path */
  253. extern int efx_nic_probe_eventq(struct efx_channel *channel);
  254. extern void efx_nic_init_eventq(struct efx_channel *channel);
  255. extern void efx_nic_fini_eventq(struct efx_channel *channel);
  256. extern void efx_nic_remove_eventq(struct efx_channel *channel);
  257. extern int efx_nic_process_eventq(struct efx_channel *channel, int rx_quota);
  258. extern void efx_nic_eventq_read_ack(struct efx_channel *channel);
  259. extern bool efx_nic_event_present(struct efx_channel *channel);
  260. /* MAC/PHY */
  261. extern void falcon_drain_tx_fifo(struct efx_nic *efx);
  262. extern void falcon_reconfigure_mac_wrapper(struct efx_nic *efx);
  263. extern bool falcon_xmac_check_fault(struct efx_nic *efx);
  264. extern int falcon_reconfigure_xmac(struct efx_nic *efx);
  265. extern void falcon_update_stats_xmac(struct efx_nic *efx);
  266. /* Interrupts and test events */
  267. extern int efx_nic_init_interrupt(struct efx_nic *efx);
  268. extern void efx_nic_enable_interrupts(struct efx_nic *efx);
  269. extern void efx_nic_event_test_start(struct efx_channel *channel);
  270. extern void efx_nic_irq_test_start(struct efx_nic *efx);
  271. extern void efx_nic_disable_interrupts(struct efx_nic *efx);
  272. extern void efx_nic_fini_interrupt(struct efx_nic *efx);
  273. extern irqreturn_t efx_nic_fatal_interrupt(struct efx_nic *efx);
  274. extern irqreturn_t falcon_legacy_interrupt_a1(int irq, void *dev_id);
  275. extern void falcon_irq_ack_a1(struct efx_nic *efx);
  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 falcon_start_nic_stats(struct efx_nic *efx);
  287. extern void falcon_stop_nic_stats(struct efx_nic *efx);
  288. extern void falcon_setup_xaui(struct efx_nic *efx);
  289. extern int falcon_reset_xaui(struct efx_nic *efx);
  290. extern void
  291. efx_nic_dimension_resources(struct efx_nic *efx, unsigned sram_lim_qw);
  292. extern void efx_nic_init_common(struct efx_nic *efx);
  293. extern void efx_nic_push_rx_indir_table(struct efx_nic *efx);
  294. int efx_nic_alloc_buffer(struct efx_nic *efx, struct efx_buffer *buffer,
  295. unsigned int len);
  296. void efx_nic_free_buffer(struct efx_nic *efx, struct efx_buffer *buffer);
  297. /* Tests */
  298. struct efx_nic_register_test {
  299. unsigned address;
  300. efx_oword_t mask;
  301. };
  302. extern int efx_nic_test_registers(struct efx_nic *efx,
  303. const struct efx_nic_register_test *regs,
  304. size_t n_regs);
  305. extern size_t efx_nic_get_regs_len(struct efx_nic *efx);
  306. extern void efx_nic_get_regs(struct efx_nic *efx, void *buf);
  307. /**************************************************************************
  308. *
  309. * Falcon MAC stats
  310. *
  311. **************************************************************************
  312. */
  313. #define FALCON_STAT_OFFSET(falcon_stat) EFX_VAL(falcon_stat, offset)
  314. #define FALCON_STAT_WIDTH(falcon_stat) EFX_VAL(falcon_stat, WIDTH)
  315. /* Retrieve statistic from statistics block */
  316. #define FALCON_STAT(efx, falcon_stat, efx_stat) do { \
  317. if (FALCON_STAT_WIDTH(falcon_stat) == 16) \
  318. (efx)->mac_stats.efx_stat += le16_to_cpu( \
  319. *((__force __le16 *) \
  320. (efx->stats_buffer.addr + \
  321. FALCON_STAT_OFFSET(falcon_stat)))); \
  322. else if (FALCON_STAT_WIDTH(falcon_stat) == 32) \
  323. (efx)->mac_stats.efx_stat += le32_to_cpu( \
  324. *((__force __le32 *) \
  325. (efx->stats_buffer.addr + \
  326. FALCON_STAT_OFFSET(falcon_stat)))); \
  327. else \
  328. (efx)->mac_stats.efx_stat += le64_to_cpu( \
  329. *((__force __le64 *) \
  330. (efx->stats_buffer.addr + \
  331. FALCON_STAT_OFFSET(falcon_stat)))); \
  332. } while (0)
  333. #define FALCON_MAC_STATS_SIZE 0x100
  334. #define MAC_DATA_LBN 0
  335. #define MAC_DATA_WIDTH 32
  336. extern void efx_generate_event(struct efx_nic *efx, unsigned int evq,
  337. efx_qword_t *event);
  338. extern void falcon_poll_xmac(struct efx_nic *efx);
  339. #endif /* EFX_NIC_H */