falcon.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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_FALCON_H
  11. #define EFX_FALCON_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 falcon_revision {
  19. FALCON_REV_A0 = 0,
  20. FALCON_REV_A1 = 1,
  21. FALCON_REV_B0 = 2,
  22. };
  23. static inline int falcon_rev(struct efx_nic *efx)
  24. {
  25. return efx->pci_dev->revision;
  26. }
  27. /**
  28. * struct falcon_board_type - board operations and type information
  29. * @id: Board type id, as found in NVRAM
  30. * @ref_model: Model number of Solarflare reference design
  31. * @gen_type: Generic board type description
  32. * @init: Allocate resources and initialise peripheral hardware
  33. * @init_phy: Do board-specific PHY initialisation
  34. * @fini: Shut down hardware and free resources
  35. * @set_id_led: Set state of identifying LED or revert to automatic function
  36. * @monitor: Board-specific health check function
  37. */
  38. struct falcon_board_type {
  39. u8 id;
  40. const char *ref_model;
  41. const char *gen_type;
  42. int (*init) (struct efx_nic *nic);
  43. void (*init_phy) (struct efx_nic *efx);
  44. void (*fini) (struct efx_nic *nic);
  45. void (*set_id_led) (struct efx_nic *efx, enum efx_led_mode mode);
  46. int (*monitor) (struct efx_nic *nic);
  47. };
  48. /**
  49. * struct falcon_board - board information
  50. * @type: Type of board
  51. * @major: Major rev. ('A', 'B' ...)
  52. * @minor: Minor rev. (0, 1, ...)
  53. * @i2c_adap: I2C adapter for on-board peripherals
  54. * @i2c_data: Data for bit-banging algorithm
  55. * @hwmon_client: I2C client for hardware monitor
  56. * @ioexp_client: I2C client for power/port control
  57. */
  58. struct falcon_board {
  59. const struct falcon_board_type *type;
  60. int major;
  61. int minor;
  62. struct i2c_adapter i2c_adap;
  63. struct i2c_algo_bit_data i2c_data;
  64. struct i2c_client *hwmon_client, *ioexp_client;
  65. };
  66. /**
  67. * struct falcon_nic_data - Falcon NIC state
  68. * @pci_dev2: Secondary function of Falcon A
  69. * @board: Board state and functions
  70. * @stats_disable_count: Nest count for disabling statistics fetches
  71. * @stats_pending: Is there a pending DMA of MAC statistics.
  72. * @stats_timer: A timer for regularly fetching MAC statistics.
  73. * @stats_dma_done: Pointer to the flag which indicates DMA completion.
  74. */
  75. struct falcon_nic_data {
  76. struct pci_dev *pci_dev2;
  77. struct falcon_board board;
  78. unsigned int stats_disable_count;
  79. bool stats_pending;
  80. struct timer_list stats_timer;
  81. u32 *stats_dma_done;
  82. };
  83. static inline struct falcon_board *falcon_board(struct efx_nic *efx)
  84. {
  85. struct falcon_nic_data *data = efx->nic_data;
  86. return &data->board;
  87. }
  88. extern struct efx_nic_type falcon_a_nic_type;
  89. extern struct efx_nic_type falcon_b_nic_type;
  90. /**************************************************************************
  91. *
  92. * Externs
  93. *
  94. **************************************************************************
  95. */
  96. extern void falcon_probe_board(struct efx_nic *efx, u16 revision_info);
  97. /* TX data path */
  98. extern int falcon_probe_tx(struct efx_tx_queue *tx_queue);
  99. extern void falcon_init_tx(struct efx_tx_queue *tx_queue);
  100. extern void falcon_fini_tx(struct efx_tx_queue *tx_queue);
  101. extern void falcon_remove_tx(struct efx_tx_queue *tx_queue);
  102. extern void falcon_push_buffers(struct efx_tx_queue *tx_queue);
  103. /* RX data path */
  104. extern int falcon_probe_rx(struct efx_rx_queue *rx_queue);
  105. extern void falcon_init_rx(struct efx_rx_queue *rx_queue);
  106. extern void falcon_fini_rx(struct efx_rx_queue *rx_queue);
  107. extern void falcon_remove_rx(struct efx_rx_queue *rx_queue);
  108. extern void falcon_notify_rx_desc(struct efx_rx_queue *rx_queue);
  109. /* Event data path */
  110. extern int falcon_probe_eventq(struct efx_channel *channel);
  111. extern void falcon_init_eventq(struct efx_channel *channel);
  112. extern void falcon_fini_eventq(struct efx_channel *channel);
  113. extern void falcon_remove_eventq(struct efx_channel *channel);
  114. extern int falcon_process_eventq(struct efx_channel *channel, int rx_quota);
  115. extern void falcon_eventq_read_ack(struct efx_channel *channel);
  116. /* Ports */
  117. extern int falcon_probe_port(struct efx_nic *efx);
  118. extern void falcon_remove_port(struct efx_nic *efx);
  119. /* MAC/PHY */
  120. extern int falcon_switch_mac(struct efx_nic *efx);
  121. extern bool falcon_xaui_link_ok(struct efx_nic *efx);
  122. extern void falcon_drain_tx_fifo(struct efx_nic *efx);
  123. extern void falcon_deconfigure_mac_wrapper(struct efx_nic *efx);
  124. extern void falcon_reconfigure_mac_wrapper(struct efx_nic *efx);
  125. /* Interrupts and test events */
  126. extern int falcon_init_interrupt(struct efx_nic *efx);
  127. extern void falcon_enable_interrupts(struct efx_nic *efx);
  128. extern void falcon_generate_test_event(struct efx_channel *channel,
  129. unsigned int magic);
  130. extern void falcon_sim_phy_event(struct efx_nic *efx);
  131. extern void falcon_generate_interrupt(struct efx_nic *efx);
  132. extern void falcon_set_int_moderation(struct efx_channel *channel);
  133. extern void falcon_disable_interrupts(struct efx_nic *efx);
  134. extern void falcon_fini_interrupt(struct efx_nic *efx);
  135. #define FALCON_IRQ_MOD_RESOLUTION 5
  136. /* Global Resources */
  137. extern int falcon_probe_nic(struct efx_nic *efx);
  138. extern int falcon_init_nic(struct efx_nic *efx);
  139. extern int falcon_flush_queues(struct efx_nic *efx);
  140. extern int falcon_reset_hw(struct efx_nic *efx, enum reset_type method);
  141. extern void falcon_monitor(struct efx_nic *efx);
  142. extern void falcon_remove_nic(struct efx_nic *efx);
  143. extern void falcon_update_nic_stats(struct efx_nic *efx);
  144. extern void falcon_start_nic_stats(struct efx_nic *efx);
  145. extern void falcon_stop_nic_stats(struct efx_nic *efx);
  146. extern void falcon_push_multicast_hash(struct efx_nic *efx);
  147. extern int falcon_reset_xaui(struct efx_nic *efx);
  148. /* Tests */
  149. struct falcon_nvconfig;
  150. extern int falcon_read_nvram(struct efx_nic *efx,
  151. struct falcon_nvconfig *nvconfig);
  152. extern int falcon_test_registers(struct efx_nic *efx);
  153. /**************************************************************************
  154. *
  155. * Falcon MAC stats
  156. *
  157. **************************************************************************
  158. */
  159. #define FALCON_STAT_OFFSET(falcon_stat) EFX_VAL(falcon_stat, offset)
  160. #define FALCON_STAT_WIDTH(falcon_stat) EFX_VAL(falcon_stat, WIDTH)
  161. /* Retrieve statistic from statistics block */
  162. #define FALCON_STAT(efx, falcon_stat, efx_stat) do { \
  163. if (FALCON_STAT_WIDTH(falcon_stat) == 16) \
  164. (efx)->mac_stats.efx_stat += le16_to_cpu( \
  165. *((__force __le16 *) \
  166. (efx->stats_buffer.addr + \
  167. FALCON_STAT_OFFSET(falcon_stat)))); \
  168. else if (FALCON_STAT_WIDTH(falcon_stat) == 32) \
  169. (efx)->mac_stats.efx_stat += le32_to_cpu( \
  170. *((__force __le32 *) \
  171. (efx->stats_buffer.addr + \
  172. FALCON_STAT_OFFSET(falcon_stat)))); \
  173. else \
  174. (efx)->mac_stats.efx_stat += le64_to_cpu( \
  175. *((__force __le64 *) \
  176. (efx->stats_buffer.addr + \
  177. FALCON_STAT_OFFSET(falcon_stat)))); \
  178. } while (0)
  179. #define FALCON_MAC_STATS_SIZE 0x100
  180. #define MAC_DATA_LBN 0
  181. #define MAC_DATA_WIDTH 32
  182. extern void falcon_generate_event(struct efx_channel *channel,
  183. efx_qword_t *event);
  184. extern void falcon_poll_xmac(struct efx_nic *efx);
  185. #endif /* EFX_FALCON_H */