Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

efx_common.h 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /**************************************************************************
  2. *
  3. * GPL common net driver for Solarflare network cards
  4. *
  5. * Written by Michael Brown <mbrown@fensystems.co.uk>
  6. *
  7. * Copyright Fen Systems Ltd. 2005
  8. * Copyright Level 5 Networks Inc. 2005
  9. * Copyright Solarflare Communications Inc. 2013-2017
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of the
  14. * License, or any later version.
  15. *
  16. * You can also choose to distribute this program under the terms of
  17. * the Unmodified Binary Distribution Licence (as given in the file
  18. * COPYING.UBDL), provided that you have satisfied its requirements.
  19. *
  20. ***************************************************************************/
  21. #ifndef EFX_COMMON_H
  22. #define EFX_COMMON_H
  23. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. #define __packed __attribute__((__packed__))
  25. #define __force /*nothing*/
  26. typedef uint16_t __le16;
  27. typedef uint32_t __le32;
  28. typedef uint64_t __le64;
  29. #define BUILD_BUG_ON_ZERO(e) (sizeof(struct{int: -!!(e); }))
  30. #define BUILD_BUG_ON(e) ((void)BUILD_BUG_ON_ZERO(e))
  31. #include <stdbool.h>
  32. #include <ipxe/io.h>
  33. #include <ipxe/netdevice.h>
  34. #include "efx_bitfield.h"
  35. #include "mcdi.h"
  36. #ifndef ARRAY_SIZE
  37. #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
  38. #endif
  39. /**************************************************************************
  40. *
  41. * Hardware data structures and sizing
  42. *
  43. ***************************************************************************/
  44. typedef efx_qword_t efx_rx_desc_t;
  45. typedef efx_qword_t efx_tx_desc_t;
  46. typedef efx_qword_t efx_event_t;
  47. #define EFX_BUF_ALIGN 4096
  48. #define EFX_RXD_SIZE 512
  49. #define EFX_RXD_MASK (EFX_RXD_SIZE - 1)
  50. #define EFX_TXD_SIZE 512
  51. #define EFX_TXD_MASK (EFX_TXD_SIZE - 1)
  52. #define EFX_EVQ_SIZE 512
  53. #define EFX_EVQ_MASK (EFX_EVQ_SIZE - 1)
  54. /* There is space for 512 rx descriptors available. This number can be
  55. * anything between 1 and 512 in powers of 2. This value will affect the
  56. * network performance. During a test we were able to push 239 descriptors
  57. * before we ran out of space.
  58. */
  59. #define EFX_NUM_RX_DESC 64
  60. #define EFX_NUM_RX_DESC_MASK (EFX_NUM_RX_DESC - 1)
  61. /* The packet size is usually 1500 bytes hence we choose 1600 as the buf size,
  62. * which is (1500+metadata)
  63. */
  64. #define EFX_RX_BUF_SIZE 1600
  65. /* Settings for the state field in efx_nic.
  66. */
  67. #define EFX_STATE_POLLING 1
  68. typedef unsigned long long dma_addr_t;
  69. /** A buffer table allocation backing a tx dma, rx dma or eventq */
  70. struct efx_special_buffer {
  71. dma_addr_t dma_addr;
  72. int id;
  73. };
  74. /** A transmit queue */
  75. struct efx_tx_queue {
  76. /* The hardware ring */
  77. efx_tx_desc_t *ring;
  78. /* The software ring storing io_buffers. */
  79. struct io_buffer *buf[EFX_TXD_SIZE];
  80. /* The buffer table reservation pushed to hardware */
  81. struct efx_special_buffer entry;
  82. /* Software descriptor write ptr */
  83. unsigned int write_ptr;
  84. /* Hardware descriptor read ptr */
  85. unsigned int read_ptr;
  86. };
  87. /** A receive queue */
  88. struct efx_rx_queue {
  89. /* The hardware ring */
  90. efx_rx_desc_t *ring;
  91. /* The software ring storing io_buffers */
  92. struct io_buffer *buf[EFX_NUM_RX_DESC];
  93. /* The buffer table reservation pushed to hardware */
  94. struct efx_special_buffer entry;
  95. /* Descriptor write ptr, into both the hardware and software rings */
  96. unsigned int write_ptr;
  97. /* Hardware completion ptr */
  98. unsigned int read_ptr;
  99. /* The value of RX_CONT in the previous RX event */
  100. unsigned int rx_cont_prev;
  101. };
  102. /** An event queue */
  103. struct efx_ev_queue {
  104. /* The hardware ring to push to hardware.
  105. * Must be the first entry in the structure.
  106. */
  107. efx_event_t *ring;
  108. /* The buffer table reservation pushed to hardware */
  109. struct efx_special_buffer entry;
  110. /* Pointers into the ring */
  111. unsigned int read_ptr;
  112. };
  113. /* Hardware revisions */
  114. enum efx_revision {
  115. EFX_HUNTINGTON,
  116. };
  117. /** Hardware access */
  118. struct efx_nic {
  119. struct net_device *netdev;
  120. enum efx_revision revision;
  121. const struct efx_nic_type *type;
  122. int port;
  123. u32 state;
  124. /** Memory and IO base */
  125. void *membase;
  126. unsigned long mmio_start;
  127. unsigned long mmio_len;
  128. /* Buffer table allocation head */
  129. int buffer_head;
  130. /* Queues */
  131. struct efx_rx_queue rxq;
  132. struct efx_tx_queue txq;
  133. struct efx_ev_queue evq;
  134. unsigned int rx_prefix_size;
  135. /** INT_REG_KER */
  136. int int_en;
  137. efx_oword_t int_ker __aligned;
  138. /* Set to true if firmware supports the workaround for bug35388 */
  139. bool workaround_35388;
  140. };
  141. /** Efx device type definition */
  142. struct efx_nic_type {
  143. int (*mcdi_rpc)(struct efx_nic *efx, unsigned int cmd,
  144. const efx_dword_t *inbuf, size_t inlen,
  145. efx_dword_t *outbuf, size_t outlen,
  146. size_t *outlen_actual, bool quiet);
  147. };
  148. extern const struct efx_nic_type hunt_nic_type;
  149. #define EFX_MAC_FRAME_LEN(_mtu) \
  150. (((_mtu) \
  151. + /* EtherII already included */ \
  152. + 4 /* FCS */ \
  153. /* No VLAN supported */ \
  154. + 16 /* bug16772 */ \
  155. + 7) & ~7)
  156. /*******************************************************************************
  157. *
  158. *
  159. * Hardware API
  160. *
  161. *
  162. ******************************************************************************/
  163. static inline void _efx_writel(struct efx_nic *efx, uint32_t value,
  164. unsigned int reg)
  165. {
  166. writel((value), (efx)->membase + (reg));
  167. }
  168. static inline uint32_t _efx_readl(struct efx_nic *efx, unsigned int reg)
  169. {
  170. return readl((efx)->membase + (reg));
  171. }
  172. #define efx_writel_table(efx, value, index, reg) \
  173. efx_writel(efx, value, (reg) + ((index) * reg##_STEP))
  174. #define efx_writel_page(efx, value, index, reg) \
  175. efx_writel(efx, value, (reg) + ((index) * 0x2000))
  176. /* Hardware access */
  177. extern void efx_writel(struct efx_nic *efx, efx_dword_t *value,
  178. unsigned int reg);
  179. extern void efx_readl(struct efx_nic *efx, efx_dword_t *value,
  180. unsigned int reg);
  181. /* Initialisation */
  182. extern void efx_probe(struct net_device *netdev, enum efx_revision rev);
  183. extern void efx_remove(struct net_device *netdev);
  184. #endif /* EFX_COMMON_H */