nic.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2006-2009 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. /*
  17. * Falcon hardware control
  18. */
  19. enum {
  20. EFX_REV_FALCON_A0 = 0,
  21. EFX_REV_FALCON_A1 = 1,
  22. EFX_REV_FALCON_B0 = 2,
  23. EFX_REV_SIENA_A0 = 3,
  24. };
  25. static inline int efx_nic_rev(struct efx_nic *efx)
  26. {
  27. return efx->type->revision;
  28. }
  29. extern u32 efx_nic_fpga_ver(struct efx_nic *efx);
  30. static inline bool efx_nic_has_mc(struct efx_nic *efx)
  31. {
  32. return efx_nic_rev(efx) >= EFX_REV_SIENA_A0;
  33. }
  34. /* NIC has two interlinked PCI functions for the same port. */
  35. static inline bool efx_nic_is_dual_func(struct efx_nic *efx)
  36. {
  37. return efx_nic_rev(efx) < EFX_REV_FALCON_B0;
  38. }
  39. enum {
  40. PHY_TYPE_NONE = 0,
  41. PHY_TYPE_TXC43128 = 1,
  42. PHY_TYPE_88E1111 = 2,
  43. PHY_TYPE_SFX7101 = 3,
  44. PHY_TYPE_QT2022C2 = 4,
  45. PHY_TYPE_PM8358 = 6,
  46. PHY_TYPE_SFT9001A = 8,
  47. PHY_TYPE_QT2025C = 9,
  48. PHY_TYPE_SFT9001B = 10,
  49. };
  50. #define FALCON_XMAC_LOOPBACKS \
  51. ((1 << LOOPBACK_XGMII) | \
  52. (1 << LOOPBACK_XGXS) | \
  53. (1 << LOOPBACK_XAUI))
  54. #define FALCON_GMAC_LOOPBACKS \
  55. (1 << LOOPBACK_GMAC)
  56. /**
  57. * struct falcon_board_type - board operations and type information
  58. * @id: Board type id, as found in NVRAM
  59. * @ref_model: Model number of Solarflare reference design
  60. * @gen_type: Generic board type description
  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. const char *ref_model;
  70. const char *gen_type;
  71. int (*init) (struct efx_nic *nic);
  72. void (*init_phy) (struct efx_nic *efx);
  73. void (*fini) (struct efx_nic *nic);
  74. void (*set_id_led) (struct efx_nic *efx, enum efx_led_mode mode);
  75. int (*monitor) (struct efx_nic *nic);
  76. };
  77. /**
  78. * struct falcon_board - board information
  79. * @type: Type of board
  80. * @major: Major rev. ('A', 'B' ...)
  81. * @minor: Minor rev. (0, 1, ...)
  82. * @i2c_adap: I2C adapter for on-board peripherals
  83. * @i2c_data: Data for bit-banging algorithm
  84. * @hwmon_client: I2C client for hardware monitor
  85. * @ioexp_client: I2C client for power/port control
  86. */
  87. struct falcon_board {
  88. const struct falcon_board_type *type;
  89. int major;
  90. int minor;
  91. struct i2c_adapter i2c_adap;
  92. struct i2c_algo_bit_data i2c_data;
  93. struct i2c_client *hwmon_client, *ioexp_client;
  94. };
  95. /**
  96. * struct falcon_nic_data - Falcon NIC state
  97. * @pci_dev2: Secondary function of Falcon A
  98. * @board: Board state and functions
  99. * @stats_disable_count: Nest count for disabling statistics fetches
  100. * @stats_pending: Is there a pending DMA of MAC statistics.
  101. * @stats_timer: A timer for regularly fetching MAC statistics.
  102. * @stats_dma_done: Pointer to the flag which indicates DMA completion.
  103. */
  104. struct falcon_nic_data {
  105. struct pci_dev *pci_dev2;
  106. struct falcon_board board;
  107. unsigned int stats_disable_count;
  108. bool stats_pending;
  109. struct timer_list stats_timer;
  110. u32 *stats_dma_done;
  111. };
  112. static inline struct falcon_board *falcon_board(struct efx_nic *efx)
  113. {
  114. struct falcon_nic_data *data = efx->nic_data;
  115. return &data->board;
  116. }
  117. /**
  118. * struct siena_nic_data - Siena NIC state
  119. * @fw_version: Management controller firmware version
  120. * @fw_build: Firmware build number
  121. * @mcdi: Management-Controller-to-Driver Interface
  122. * @wol_filter_id: Wake-on-LAN packet filter id
  123. * @ipv6_rss_key: Toeplitz hash key for IPv6 RSS
  124. */
  125. struct siena_nic_data {
  126. u64 fw_version;
  127. u32 fw_build;
  128. struct efx_mcdi_iface mcdi;
  129. int wol_filter_id;
  130. };
  131. extern void siena_print_fwver(struct efx_nic *efx, char *buf, size_t len);
  132. extern struct efx_nic_type falcon_a1_nic_type;
  133. extern struct efx_nic_type falcon_b0_nic_type;
  134. extern struct efx_nic_type siena_a0_nic_type;
  135. /**************************************************************************
  136. *
  137. * Externs
  138. *
  139. **************************************************************************
  140. */
  141. extern int falcon_probe_board(struct efx_nic *efx, u16 revision_info);
  142. /* TX data path */
  143. extern int efx_nic_probe_tx(struct efx_tx_queue *tx_queue);
  144. extern void efx_nic_init_tx(struct efx_tx_queue *tx_queue);
  145. extern void efx_nic_fini_tx(struct efx_tx_queue *tx_queue);
  146. extern void efx_nic_remove_tx(struct efx_tx_queue *tx_queue);
  147. extern void efx_nic_push_buffers(struct efx_tx_queue *tx_queue);
  148. /* RX data path */
  149. extern int efx_nic_probe_rx(struct efx_rx_queue *rx_queue);
  150. extern void efx_nic_init_rx(struct efx_rx_queue *rx_queue);
  151. extern void efx_nic_fini_rx(struct efx_rx_queue *rx_queue);
  152. extern void efx_nic_remove_rx(struct efx_rx_queue *rx_queue);
  153. extern void efx_nic_notify_rx_desc(struct efx_rx_queue *rx_queue);
  154. /* Event data path */
  155. extern int efx_nic_probe_eventq(struct efx_channel *channel);
  156. extern void efx_nic_init_eventq(struct efx_channel *channel);
  157. extern void efx_nic_fini_eventq(struct efx_channel *channel);
  158. extern void efx_nic_remove_eventq(struct efx_channel *channel);
  159. extern int efx_nic_process_eventq(struct efx_channel *channel, int rx_quota);
  160. extern void efx_nic_eventq_read_ack(struct efx_channel *channel);
  161. /* MAC/PHY */
  162. extern void falcon_drain_tx_fifo(struct efx_nic *efx);
  163. extern void falcon_reconfigure_mac_wrapper(struct efx_nic *efx);
  164. extern int efx_nic_rx_xoff_thresh, efx_nic_rx_xon_thresh;
  165. /* Interrupts and test events */
  166. extern int efx_nic_init_interrupt(struct efx_nic *efx);
  167. extern void efx_nic_enable_interrupts(struct efx_nic *efx);
  168. extern void efx_nic_generate_test_event(struct efx_channel *channel);
  169. extern void efx_nic_generate_fill_event(struct efx_channel *channel);
  170. extern void efx_nic_generate_interrupt(struct efx_nic *efx);
  171. extern void efx_nic_disable_interrupts(struct efx_nic *efx);
  172. extern void efx_nic_fini_interrupt(struct efx_nic *efx);
  173. extern irqreturn_t efx_nic_fatal_interrupt(struct efx_nic *efx);
  174. extern irqreturn_t falcon_legacy_interrupt_a1(int irq, void *dev_id);
  175. extern void falcon_irq_ack_a1(struct efx_nic *efx);
  176. #define EFX_IRQ_MOD_RESOLUTION 5
  177. /* Global Resources */
  178. extern int efx_nic_flush_queues(struct efx_nic *efx);
  179. extern void falcon_start_nic_stats(struct efx_nic *efx);
  180. extern void falcon_stop_nic_stats(struct efx_nic *efx);
  181. extern void falcon_setup_xaui(struct efx_nic *efx);
  182. extern int falcon_reset_xaui(struct efx_nic *efx);
  183. extern void efx_nic_init_common(struct efx_nic *efx);
  184. extern void efx_nic_push_rx_indir_table(struct efx_nic *efx);
  185. int efx_nic_alloc_buffer(struct efx_nic *efx, struct efx_buffer *buffer,
  186. unsigned int len);
  187. void efx_nic_free_buffer(struct efx_nic *efx, struct efx_buffer *buffer);
  188. /* Tests */
  189. struct efx_nic_register_test {
  190. unsigned address;
  191. efx_oword_t mask;
  192. };
  193. extern int efx_nic_test_registers(struct efx_nic *efx,
  194. const struct efx_nic_register_test *regs,
  195. size_t n_regs);
  196. extern size_t efx_nic_get_regs_len(struct efx_nic *efx);
  197. extern void efx_nic_get_regs(struct efx_nic *efx, void *buf);
  198. /**************************************************************************
  199. *
  200. * Falcon MAC stats
  201. *
  202. **************************************************************************
  203. */
  204. #define FALCON_STAT_OFFSET(falcon_stat) EFX_VAL(falcon_stat, offset)
  205. #define FALCON_STAT_WIDTH(falcon_stat) EFX_VAL(falcon_stat, WIDTH)
  206. /* Retrieve statistic from statistics block */
  207. #define FALCON_STAT(efx, falcon_stat, efx_stat) do { \
  208. if (FALCON_STAT_WIDTH(falcon_stat) == 16) \
  209. (efx)->mac_stats.efx_stat += le16_to_cpu( \
  210. *((__force __le16 *) \
  211. (efx->stats_buffer.addr + \
  212. FALCON_STAT_OFFSET(falcon_stat)))); \
  213. else if (FALCON_STAT_WIDTH(falcon_stat) == 32) \
  214. (efx)->mac_stats.efx_stat += le32_to_cpu( \
  215. *((__force __le32 *) \
  216. (efx->stats_buffer.addr + \
  217. FALCON_STAT_OFFSET(falcon_stat)))); \
  218. else \
  219. (efx)->mac_stats.efx_stat += le64_to_cpu( \
  220. *((__force __le64 *) \
  221. (efx->stats_buffer.addr + \
  222. FALCON_STAT_OFFSET(falcon_stat)))); \
  223. } while (0)
  224. #define FALCON_MAC_STATS_SIZE 0x100
  225. #define MAC_DATA_LBN 0
  226. #define MAC_DATA_WIDTH 32
  227. extern void efx_nic_generate_event(struct efx_channel *channel,
  228. efx_qword_t *event);
  229. extern void falcon_poll_xmac(struct efx_nic *efx);
  230. #endif /* EFX_NIC_H */