qede.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /* QLogic qede NIC Driver
  2. * Copyright (c) 2015 QLogic Corporation
  3. *
  4. * This software is available under the terms of the GNU General Public License
  5. * (GPL) Version 2, available from the file COPYING in the main directory of
  6. * this source tree.
  7. */
  8. #ifndef _QEDE_H_
  9. #define _QEDE_H_
  10. #include <linux/compiler.h>
  11. #include <linux/version.h>
  12. #include <linux/workqueue.h>
  13. #include <linux/netdevice.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/bitmap.h>
  16. #include <linux/kernel.h>
  17. #include <linux/mutex.h>
  18. #include <linux/io.h>
  19. #include <linux/qed/common_hsi.h>
  20. #include <linux/qed/eth_common.h>
  21. #include <linux/qed/qed_if.h>
  22. #include <linux/qed/qed_chain.h>
  23. #include <linux/qed/qed_eth_if.h>
  24. #define QEDE_MAJOR_VERSION 8
  25. #define QEDE_MINOR_VERSION 4
  26. #define QEDE_REVISION_VERSION 0
  27. #define QEDE_ENGINEERING_VERSION 0
  28. #define DRV_MODULE_VERSION __stringify(QEDE_MAJOR_VERSION) "." \
  29. __stringify(QEDE_MINOR_VERSION) "." \
  30. __stringify(QEDE_REVISION_VERSION) "." \
  31. __stringify(QEDE_ENGINEERING_VERSION)
  32. #define QEDE_ETH_INTERFACE_VERSION 300
  33. #define DRV_MODULE_SYM qede
  34. struct qede_stats {
  35. u64 no_buff_discards;
  36. u64 rx_ucast_bytes;
  37. u64 rx_mcast_bytes;
  38. u64 rx_bcast_bytes;
  39. u64 rx_ucast_pkts;
  40. u64 rx_mcast_pkts;
  41. u64 rx_bcast_pkts;
  42. u64 mftag_filter_discards;
  43. u64 mac_filter_discards;
  44. u64 tx_ucast_bytes;
  45. u64 tx_mcast_bytes;
  46. u64 tx_bcast_bytes;
  47. u64 tx_ucast_pkts;
  48. u64 tx_mcast_pkts;
  49. u64 tx_bcast_pkts;
  50. u64 tx_err_drop_pkts;
  51. u64 coalesced_pkts;
  52. u64 coalesced_events;
  53. u64 coalesced_aborts_num;
  54. u64 non_coalesced_pkts;
  55. u64 coalesced_bytes;
  56. /* port */
  57. u64 rx_64_byte_packets;
  58. u64 rx_127_byte_packets;
  59. u64 rx_255_byte_packets;
  60. u64 rx_511_byte_packets;
  61. u64 rx_1023_byte_packets;
  62. u64 rx_1518_byte_packets;
  63. u64 rx_1522_byte_packets;
  64. u64 rx_2047_byte_packets;
  65. u64 rx_4095_byte_packets;
  66. u64 rx_9216_byte_packets;
  67. u64 rx_16383_byte_packets;
  68. u64 rx_crc_errors;
  69. u64 rx_mac_crtl_frames;
  70. u64 rx_pause_frames;
  71. u64 rx_pfc_frames;
  72. u64 rx_align_errors;
  73. u64 rx_carrier_errors;
  74. u64 rx_oversize_packets;
  75. u64 rx_jabbers;
  76. u64 rx_undersize_packets;
  77. u64 rx_fragments;
  78. u64 tx_64_byte_packets;
  79. u64 tx_65_to_127_byte_packets;
  80. u64 tx_128_to_255_byte_packets;
  81. u64 tx_256_to_511_byte_packets;
  82. u64 tx_512_to_1023_byte_packets;
  83. u64 tx_1024_to_1518_byte_packets;
  84. u64 tx_1519_to_2047_byte_packets;
  85. u64 tx_2048_to_4095_byte_packets;
  86. u64 tx_4096_to_9216_byte_packets;
  87. u64 tx_9217_to_16383_byte_packets;
  88. u64 tx_pause_frames;
  89. u64 tx_pfc_frames;
  90. u64 tx_lpi_entry_count;
  91. u64 tx_total_collisions;
  92. u64 brb_truncates;
  93. u64 brb_discards;
  94. u64 tx_mac_ctrl_frames;
  95. };
  96. struct qede_dev {
  97. struct qed_dev *cdev;
  98. struct net_device *ndev;
  99. struct pci_dev *pdev;
  100. u32 dp_module;
  101. u8 dp_level;
  102. const struct qed_eth_ops *ops;
  103. struct qed_dev_eth_info dev_info;
  104. #define QEDE_MAX_RSS_CNT(edev) ((edev)->dev_info.num_queues)
  105. #define QEDE_MAX_TSS_CNT(edev) ((edev)->dev_info.num_queues * \
  106. (edev)->dev_info.num_tc)
  107. struct qede_fastpath *fp_array;
  108. u16 num_rss;
  109. u8 num_tc;
  110. #define QEDE_RSS_CNT(edev) ((edev)->num_rss)
  111. #define QEDE_TSS_CNT(edev) ((edev)->num_rss * \
  112. (edev)->num_tc)
  113. #define QEDE_TSS_IDX(edev, txqidx) ((txqidx) % (edev)->num_rss)
  114. #define QEDE_TC_IDX(edev, txqidx) ((txqidx) / (edev)->num_rss)
  115. #define QEDE_TX_QUEUE(edev, txqidx) \
  116. (&(edev)->fp_array[QEDE_TSS_IDX((edev), (txqidx))].txqs[QEDE_TC_IDX( \
  117. (edev), (txqidx))])
  118. struct qed_int_info int_info;
  119. unsigned char primary_mac[ETH_ALEN];
  120. /* Smaller private varaiant of the RTNL lock */
  121. struct mutex qede_lock;
  122. u32 state; /* Protected by qede_lock */
  123. u16 rx_buf_size;
  124. /* L2 header size + 2*VLANs (8 bytes) + LLC SNAP (8 bytes) */
  125. #define ETH_OVERHEAD (ETH_HLEN + 8 + 8)
  126. /* Max supported alignment is 256 (8 shift)
  127. * minimal alignment shift 6 is optimal for 57xxx HW performance
  128. */
  129. #define QEDE_RX_ALIGN_SHIFT max(6, min(8, L1_CACHE_SHIFT))
  130. /* We assume skb_build() uses sizeof(struct skb_shared_info) bytes
  131. * at the end of skb->data, to avoid wasting a full cache line.
  132. * This reduces memory use (skb->truesize).
  133. */
  134. #define QEDE_FW_RX_ALIGN_END \
  135. max_t(u64, 1UL << QEDE_RX_ALIGN_SHIFT, \
  136. SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
  137. struct qede_stats stats;
  138. struct qed_update_vport_rss_params rss_params;
  139. u16 q_num_rx_buffers; /* Must be a power of two */
  140. u16 q_num_tx_buffers; /* Must be a power of two */
  141. struct delayed_work sp_task;
  142. unsigned long sp_flags;
  143. };
  144. enum QEDE_STATE {
  145. QEDE_STATE_CLOSED,
  146. QEDE_STATE_OPEN,
  147. };
  148. #define HILO_U64(hi, lo) ((((u64)(hi)) << 32) + (lo))
  149. #define MAX_NUM_TC 8
  150. #define MAX_NUM_PRI 8
  151. /* The driver supports the new build_skb() API:
  152. * RX ring buffer contains pointer to kmalloc() data only,
  153. * skb are built only after the frame was DMA-ed.
  154. */
  155. struct sw_rx_data {
  156. u8 *data;
  157. DEFINE_DMA_UNMAP_ADDR(mapping);
  158. };
  159. struct qede_rx_queue {
  160. __le16 *hw_cons_ptr;
  161. struct sw_rx_data *sw_rx_ring;
  162. u16 sw_rx_cons;
  163. u16 sw_rx_prod;
  164. struct qed_chain rx_bd_ring;
  165. struct qed_chain rx_comp_ring;
  166. void __iomem *hw_rxq_prod_addr;
  167. int rx_buf_size;
  168. u16 num_rx_buffers;
  169. u16 rxq_id;
  170. u64 rx_hw_errors;
  171. u64 rx_alloc_errors;
  172. };
  173. union db_prod {
  174. struct eth_db_data data;
  175. u32 raw;
  176. };
  177. struct sw_tx_bd {
  178. struct sk_buff *skb;
  179. u8 flags;
  180. /* Set on the first BD descriptor when there is a split BD */
  181. #define QEDE_TSO_SPLIT_BD BIT(0)
  182. };
  183. struct qede_tx_queue {
  184. int index; /* Queue index */
  185. __le16 *hw_cons_ptr;
  186. struct sw_tx_bd *sw_tx_ring;
  187. u16 sw_tx_cons;
  188. u16 sw_tx_prod;
  189. struct qed_chain tx_pbl;
  190. void __iomem *doorbell_addr;
  191. union db_prod tx_db;
  192. u16 num_tx_buffers;
  193. };
  194. #define BD_UNMAP_ADDR(bd) HILO_U64(le32_to_cpu((bd)->addr.hi), \
  195. le32_to_cpu((bd)->addr.lo))
  196. #define BD_SET_UNMAP_ADDR_LEN(bd, maddr, len) \
  197. do { \
  198. (bd)->addr.hi = cpu_to_le32(upper_32_bits(maddr)); \
  199. (bd)->addr.lo = cpu_to_le32(lower_32_bits(maddr)); \
  200. (bd)->nbytes = cpu_to_le16(len); \
  201. } while (0)
  202. #define BD_UNMAP_LEN(bd) (le16_to_cpu((bd)->nbytes))
  203. struct qede_fastpath {
  204. struct qede_dev *edev;
  205. u8 rss_id;
  206. struct napi_struct napi;
  207. struct qed_sb_info *sb_info;
  208. struct qede_rx_queue *rxq;
  209. struct qede_tx_queue *txqs;
  210. #define VEC_NAME_SIZE (sizeof(((struct net_device *)0)->name) + 8)
  211. char name[VEC_NAME_SIZE];
  212. };
  213. /* Debug print definitions */
  214. #define DP_NAME(edev) ((edev)->ndev->name)
  215. #define XMIT_PLAIN 0
  216. #define XMIT_L4_CSUM BIT(0)
  217. #define XMIT_LSO BIT(1)
  218. #define XMIT_ENC BIT(2)
  219. #define QEDE_CSUM_ERROR BIT(0)
  220. #define QEDE_CSUM_UNNECESSARY BIT(1)
  221. #define QEDE_SP_RX_MODE 1
  222. union qede_reload_args {
  223. u16 mtu;
  224. };
  225. void qede_config_debug(uint debug, u32 *p_dp_module, u8 *p_dp_level);
  226. void qede_set_ethtool_ops(struct net_device *netdev);
  227. void qede_reload(struct qede_dev *edev,
  228. void (*func)(struct qede_dev *edev,
  229. union qede_reload_args *args),
  230. union qede_reload_args *args);
  231. int qede_change_mtu(struct net_device *dev, int new_mtu);
  232. void qede_fill_by_demand_stats(struct qede_dev *edev);
  233. #define RX_RING_SIZE_POW 13
  234. #define RX_RING_SIZE BIT(RX_RING_SIZE_POW)
  235. #define NUM_RX_BDS_MAX (RX_RING_SIZE - 1)
  236. #define NUM_RX_BDS_MIN 128
  237. #define NUM_RX_BDS_DEF NUM_RX_BDS_MAX
  238. #define TX_RING_SIZE_POW 13
  239. #define TX_RING_SIZE BIT(TX_RING_SIZE_POW)
  240. #define NUM_TX_BDS_MAX (TX_RING_SIZE - 1)
  241. #define NUM_TX_BDS_MIN 128
  242. #define NUM_TX_BDS_DEF NUM_TX_BDS_MAX
  243. #define for_each_rss(i) for (i = 0; i < edev->num_rss; i++)
  244. #endif /* _QEDE_H_ */