nic.h 7.5 KB

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