nic.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. static inline bool efx_nic_has_mc(struct efx_nic *efx)
  32. {
  33. return efx_nic_rev(efx) >= EFX_REV_SIENA_A0;
  34. }
  35. /* NIC has two interlinked PCI functions for the same port. */
  36. static inline bool efx_nic_is_dual_func(struct efx_nic *efx)
  37. {
  38. return efx_nic_rev(efx) < EFX_REV_FALCON_B0;
  39. }
  40. enum {
  41. PHY_TYPE_NONE = 0,
  42. PHY_TYPE_TXC43128 = 1,
  43. PHY_TYPE_88E1111 = 2,
  44. PHY_TYPE_SFX7101 = 3,
  45. PHY_TYPE_QT2022C2 = 4,
  46. PHY_TYPE_PM8358 = 6,
  47. PHY_TYPE_SFT9001A = 8,
  48. PHY_TYPE_QT2025C = 9,
  49. PHY_TYPE_SFT9001B = 10,
  50. };
  51. #define FALCON_XMAC_LOOPBACKS \
  52. ((1 << LOOPBACK_XGMII) | \
  53. (1 << LOOPBACK_XGXS) | \
  54. (1 << LOOPBACK_XAUI))
  55. #define FALCON_GMAC_LOOPBACKS \
  56. (1 << LOOPBACK_GMAC)
  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. * @mcdi_smem: MCDI shared memory mapping. The mapping is always uncacheable.
  132. * @wol_filter_id: Wake-on-LAN packet filter id
  133. */
  134. struct siena_nic_data {
  135. struct efx_mcdi_iface mcdi;
  136. void __iomem *mcdi_smem;
  137. int wol_filter_id;
  138. };
  139. extern const struct efx_nic_type falcon_a1_nic_type;
  140. extern const struct efx_nic_type falcon_b0_nic_type;
  141. extern const struct efx_nic_type siena_a0_nic_type;
  142. /**************************************************************************
  143. *
  144. * Externs
  145. *
  146. **************************************************************************
  147. */
  148. extern int falcon_probe_board(struct efx_nic *efx, u16 revision_info);
  149. /* TX data path */
  150. extern int efx_nic_probe_tx(struct efx_tx_queue *tx_queue);
  151. extern void efx_nic_init_tx(struct efx_tx_queue *tx_queue);
  152. extern void efx_nic_fini_tx(struct efx_tx_queue *tx_queue);
  153. extern void efx_nic_remove_tx(struct efx_tx_queue *tx_queue);
  154. extern void efx_nic_push_buffers(struct efx_tx_queue *tx_queue);
  155. /* RX data path */
  156. extern int efx_nic_probe_rx(struct efx_rx_queue *rx_queue);
  157. extern void efx_nic_init_rx(struct efx_rx_queue *rx_queue);
  158. extern void efx_nic_fini_rx(struct efx_rx_queue *rx_queue);
  159. extern void efx_nic_remove_rx(struct efx_rx_queue *rx_queue);
  160. extern void efx_nic_notify_rx_desc(struct efx_rx_queue *rx_queue);
  161. /* Event data path */
  162. extern int efx_nic_probe_eventq(struct efx_channel *channel);
  163. extern void efx_nic_init_eventq(struct efx_channel *channel);
  164. extern void efx_nic_fini_eventq(struct efx_channel *channel);
  165. extern void efx_nic_remove_eventq(struct efx_channel *channel);
  166. extern int efx_nic_process_eventq(struct efx_channel *channel, int rx_quota);
  167. extern void efx_nic_eventq_read_ack(struct efx_channel *channel);
  168. extern bool efx_nic_event_present(struct efx_channel *channel);
  169. /* MAC/PHY */
  170. extern void falcon_drain_tx_fifo(struct efx_nic *efx);
  171. extern void falcon_reconfigure_mac_wrapper(struct efx_nic *efx);
  172. /* Interrupts and test events */
  173. extern int efx_nic_init_interrupt(struct efx_nic *efx);
  174. extern void efx_nic_enable_interrupts(struct efx_nic *efx);
  175. extern void efx_nic_generate_test_event(struct efx_channel *channel);
  176. extern void efx_nic_generate_fill_event(struct efx_channel *channel);
  177. extern void efx_nic_generate_interrupt(struct efx_nic *efx);
  178. extern void efx_nic_disable_interrupts(struct efx_nic *efx);
  179. extern void efx_nic_fini_interrupt(struct efx_nic *efx);
  180. extern irqreturn_t efx_nic_fatal_interrupt(struct efx_nic *efx);
  181. extern irqreturn_t falcon_legacy_interrupt_a1(int irq, void *dev_id);
  182. extern void falcon_irq_ack_a1(struct efx_nic *efx);
  183. #define EFX_IRQ_MOD_RESOLUTION 5
  184. /* Global Resources */
  185. extern int efx_nic_flush_queues(struct efx_nic *efx);
  186. extern void falcon_start_nic_stats(struct efx_nic *efx);
  187. extern void falcon_stop_nic_stats(struct efx_nic *efx);
  188. extern void falcon_setup_xaui(struct efx_nic *efx);
  189. extern int falcon_reset_xaui(struct efx_nic *efx);
  190. extern void efx_nic_init_common(struct efx_nic *efx);
  191. extern void efx_nic_push_rx_indir_table(struct efx_nic *efx);
  192. int efx_nic_alloc_buffer(struct efx_nic *efx, struct efx_buffer *buffer,
  193. unsigned int len);
  194. void efx_nic_free_buffer(struct efx_nic *efx, struct efx_buffer *buffer);
  195. /* Tests */
  196. struct efx_nic_register_test {
  197. unsigned address;
  198. efx_oword_t mask;
  199. };
  200. extern int efx_nic_test_registers(struct efx_nic *efx,
  201. const struct efx_nic_register_test *regs,
  202. size_t n_regs);
  203. extern size_t efx_nic_get_regs_len(struct efx_nic *efx);
  204. extern void efx_nic_get_regs(struct efx_nic *efx, void *buf);
  205. /**************************************************************************
  206. *
  207. * Falcon MAC stats
  208. *
  209. **************************************************************************
  210. */
  211. #define FALCON_STAT_OFFSET(falcon_stat) EFX_VAL(falcon_stat, offset)
  212. #define FALCON_STAT_WIDTH(falcon_stat) EFX_VAL(falcon_stat, WIDTH)
  213. /* Retrieve statistic from statistics block */
  214. #define FALCON_STAT(efx, falcon_stat, efx_stat) do { \
  215. if (FALCON_STAT_WIDTH(falcon_stat) == 16) \
  216. (efx)->mac_stats.efx_stat += le16_to_cpu( \
  217. *((__force __le16 *) \
  218. (efx->stats_buffer.addr + \
  219. FALCON_STAT_OFFSET(falcon_stat)))); \
  220. else if (FALCON_STAT_WIDTH(falcon_stat) == 32) \
  221. (efx)->mac_stats.efx_stat += le32_to_cpu( \
  222. *((__force __le32 *) \
  223. (efx->stats_buffer.addr + \
  224. FALCON_STAT_OFFSET(falcon_stat)))); \
  225. else \
  226. (efx)->mac_stats.efx_stat += le64_to_cpu( \
  227. *((__force __le64 *) \
  228. (efx->stats_buffer.addr + \
  229. FALCON_STAT_OFFSET(falcon_stat)))); \
  230. } while (0)
  231. #define FALCON_MAC_STATS_SIZE 0x100
  232. #define MAC_DATA_LBN 0
  233. #define MAC_DATA_WIDTH 32
  234. extern void efx_nic_generate_event(struct efx_channel *channel,
  235. efx_qword_t *event);
  236. extern void falcon_poll_xmac(struct efx_nic *efx);
  237. #endif /* EFX_NIC_H */