nicvf_queues.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. /*
  2. * Copyright (C) 2015 Cavium, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of version 2 of the GNU General Public License
  6. * as published by the Free Software Foundation.
  7. */
  8. #ifndef NICVF_QUEUES_H
  9. #define NICVF_QUEUES_H
  10. #include <linux/netdevice.h>
  11. #include "q_struct.h"
  12. #define MAX_QUEUE_SET 128
  13. #define MAX_RCV_QUEUES_PER_QS 8
  14. #define MAX_RCV_BUF_DESC_RINGS_PER_QS 2
  15. #define MAX_SND_QUEUES_PER_QS 8
  16. #define MAX_CMP_QUEUES_PER_QS 8
  17. /* VF's queue interrupt ranges */
  18. #define NICVF_INTR_ID_CQ 0
  19. #define NICVF_INTR_ID_SQ 8
  20. #define NICVF_INTR_ID_RBDR 16
  21. #define NICVF_INTR_ID_MISC 18
  22. #define NICVF_INTR_ID_QS_ERR 19
  23. #define for_each_cq_irq(irq) \
  24. for (irq = NICVF_INTR_ID_CQ; irq < NICVF_INTR_ID_SQ; irq++)
  25. #define for_each_sq_irq(irq) \
  26. for (irq = NICVF_INTR_ID_SQ; irq < NICVF_INTR_ID_RBDR; irq++)
  27. #define for_each_rbdr_irq(irq) \
  28. for (irq = NICVF_INTR_ID_RBDR; irq < NICVF_INTR_ID_MISC; irq++)
  29. #define RBDR_SIZE0 0ULL /* 8K entries */
  30. #define RBDR_SIZE1 1ULL /* 16K entries */
  31. #define RBDR_SIZE2 2ULL /* 32K entries */
  32. #define RBDR_SIZE3 3ULL /* 64K entries */
  33. #define RBDR_SIZE4 4ULL /* 126K entries */
  34. #define RBDR_SIZE5 5ULL /* 256K entries */
  35. #define RBDR_SIZE6 6ULL /* 512K entries */
  36. #define SND_QUEUE_SIZE0 0ULL /* 1K entries */
  37. #define SND_QUEUE_SIZE1 1ULL /* 2K entries */
  38. #define SND_QUEUE_SIZE2 2ULL /* 4K entries */
  39. #define SND_QUEUE_SIZE3 3ULL /* 8K entries */
  40. #define SND_QUEUE_SIZE4 4ULL /* 16K entries */
  41. #define SND_QUEUE_SIZE5 5ULL /* 32K entries */
  42. #define SND_QUEUE_SIZE6 6ULL /* 64K entries */
  43. #define CMP_QUEUE_SIZE0 0ULL /* 1K entries */
  44. #define CMP_QUEUE_SIZE1 1ULL /* 2K entries */
  45. #define CMP_QUEUE_SIZE2 2ULL /* 4K entries */
  46. #define CMP_QUEUE_SIZE3 3ULL /* 8K entries */
  47. #define CMP_QUEUE_SIZE4 4ULL /* 16K entries */
  48. #define CMP_QUEUE_SIZE5 5ULL /* 32K entries */
  49. #define CMP_QUEUE_SIZE6 6ULL /* 64K entries */
  50. /* Default queue count per QS, its lengths and threshold values */
  51. #define DEFAULT_RBDR_CNT 1
  52. #define SND_QSIZE SND_QUEUE_SIZE0
  53. #define SND_QUEUE_LEN (1ULL << (SND_QSIZE + 10))
  54. #define MIN_SND_QUEUE_LEN (1ULL << (SND_QUEUE_SIZE0 + 10))
  55. #define MAX_SND_QUEUE_LEN (1ULL << (SND_QUEUE_SIZE6 + 10))
  56. #define SND_QUEUE_THRESH 2ULL
  57. #define MIN_SQ_DESC_PER_PKT_XMIT 2
  58. /* Since timestamp not enabled, otherwise 2 */
  59. #define MAX_CQE_PER_PKT_XMIT 1
  60. /* Keep CQ and SQ sizes same, if timestamping
  61. * is enabled this equation will change.
  62. */
  63. #define CMP_QSIZE CMP_QUEUE_SIZE0
  64. #define CMP_QUEUE_LEN (1ULL << (CMP_QSIZE + 10))
  65. #define MIN_CMP_QUEUE_LEN (1ULL << (CMP_QUEUE_SIZE0 + 10))
  66. #define MAX_CMP_QUEUE_LEN (1ULL << (CMP_QUEUE_SIZE6 + 10))
  67. #define CMP_QUEUE_CQE_THRESH (NAPI_POLL_WEIGHT / 2)
  68. #define CMP_QUEUE_TIMER_THRESH 80 /* ~2usec */
  69. /* No of CQEs that might anyway gets used by HW due to pipelining
  70. * effects irrespective of PASS/DROP/LEVELS being configured
  71. */
  72. #define CMP_QUEUE_PIPELINE_RSVD 544
  73. #define RBDR_SIZE RBDR_SIZE0
  74. #define RCV_BUF_COUNT (1ULL << (RBDR_SIZE + 13))
  75. #define MAX_RCV_BUF_COUNT (1ULL << (RBDR_SIZE6 + 13))
  76. #define RBDR_THRESH (RCV_BUF_COUNT / 2)
  77. #define DMA_BUFFER_LEN 1536 /* In multiples of 128bytes */
  78. #define RCV_FRAG_LEN (SKB_DATA_ALIGN(DMA_BUFFER_LEN + NET_SKB_PAD) + \
  79. SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
  80. #define MAX_CQES_FOR_TX ((SND_QUEUE_LEN / MIN_SQ_DESC_PER_PKT_XMIT) * \
  81. MAX_CQE_PER_PKT_XMIT)
  82. /* RED and Backpressure levels of CQ for pkt reception
  83. * For CQ, level is a measure of emptiness i.e 0x0 means full
  84. * eg: For CQ of size 4K, and for pass/drop levels of 160/144
  85. * HW accepts pkt if unused CQE >= 2560
  86. * RED accepts pkt if unused CQE < 2304 & >= 2560
  87. * DROPs pkts if unused CQE < 2304
  88. */
  89. #define RQ_PASS_CQ_LVL 192ULL
  90. #define RQ_DROP_CQ_LVL 184ULL
  91. /* RED and Backpressure levels of RBDR for pkt reception
  92. * For RBDR, level is a measure of fullness i.e 0x0 means empty
  93. * eg: For RBDR of size 8K, and for pass/drop levels of 4/0
  94. * HW accepts pkt if unused RBs >= 256
  95. * RED accepts pkt if unused RBs < 256 & >= 0
  96. * DROPs pkts if unused RBs < 0
  97. */
  98. #define RQ_PASS_RBDR_LVL 8ULL
  99. #define RQ_DROP_RBDR_LVL 0ULL
  100. /* Descriptor size in bytes */
  101. #define SND_QUEUE_DESC_SIZE 16
  102. #define CMP_QUEUE_DESC_SIZE 512
  103. /* Buffer / descriptor alignments */
  104. #define NICVF_RCV_BUF_ALIGN 7
  105. #define NICVF_RCV_BUF_ALIGN_BYTES (1ULL << NICVF_RCV_BUF_ALIGN)
  106. #define NICVF_CQ_BASE_ALIGN_BYTES 512 /* 9 bits */
  107. #define NICVF_SQ_BASE_ALIGN_BYTES 128 /* 7 bits */
  108. #define NICVF_ALIGNED_ADDR(ADDR, ALIGN_BYTES) ALIGN(ADDR, ALIGN_BYTES)
  109. /* Queue enable/disable */
  110. #define NICVF_SQ_EN BIT_ULL(19)
  111. /* Queue reset */
  112. #define NICVF_CQ_RESET BIT_ULL(41)
  113. #define NICVF_SQ_RESET BIT_ULL(17)
  114. #define NICVF_RBDR_RESET BIT_ULL(43)
  115. enum CQ_RX_ERRLVL_E {
  116. CQ_ERRLVL_MAC,
  117. CQ_ERRLVL_L2,
  118. CQ_ERRLVL_L3,
  119. CQ_ERRLVL_L4,
  120. };
  121. enum CQ_RX_ERROP_E {
  122. CQ_RX_ERROP_RE_NONE = 0x0,
  123. CQ_RX_ERROP_RE_PARTIAL = 0x1,
  124. CQ_RX_ERROP_RE_JABBER = 0x2,
  125. CQ_RX_ERROP_RE_FCS = 0x7,
  126. CQ_RX_ERROP_RE_TERMINATE = 0x9,
  127. CQ_RX_ERROP_RE_RX_CTL = 0xb,
  128. CQ_RX_ERROP_PREL2_ERR = 0x1f,
  129. CQ_RX_ERROP_L2_FRAGMENT = 0x20,
  130. CQ_RX_ERROP_L2_OVERRUN = 0x21,
  131. CQ_RX_ERROP_L2_PFCS = 0x22,
  132. CQ_RX_ERROP_L2_PUNY = 0x23,
  133. CQ_RX_ERROP_L2_MAL = 0x24,
  134. CQ_RX_ERROP_L2_OVERSIZE = 0x25,
  135. CQ_RX_ERROP_L2_UNDERSIZE = 0x26,
  136. CQ_RX_ERROP_L2_LENMISM = 0x27,
  137. CQ_RX_ERROP_L2_PCLP = 0x28,
  138. CQ_RX_ERROP_IP_NOT = 0x41,
  139. CQ_RX_ERROP_IP_CSUM_ERR = 0x42,
  140. CQ_RX_ERROP_IP_MAL = 0x43,
  141. CQ_RX_ERROP_IP_MALD = 0x44,
  142. CQ_RX_ERROP_IP_HOP = 0x45,
  143. CQ_RX_ERROP_L3_ICRC = 0x46,
  144. CQ_RX_ERROP_L3_PCLP = 0x47,
  145. CQ_RX_ERROP_L4_MAL = 0x61,
  146. CQ_RX_ERROP_L4_CHK = 0x62,
  147. CQ_RX_ERROP_UDP_LEN = 0x63,
  148. CQ_RX_ERROP_L4_PORT = 0x64,
  149. CQ_RX_ERROP_TCP_FLAG = 0x65,
  150. CQ_RX_ERROP_TCP_OFFSET = 0x66,
  151. CQ_RX_ERROP_L4_PCLP = 0x67,
  152. CQ_RX_ERROP_RBDR_TRUNC = 0x70,
  153. };
  154. enum CQ_TX_ERROP_E {
  155. CQ_TX_ERROP_GOOD = 0x0,
  156. CQ_TX_ERROP_DESC_FAULT = 0x10,
  157. CQ_TX_ERROP_HDR_CONS_ERR = 0x11,
  158. CQ_TX_ERROP_SUBDC_ERR = 0x12,
  159. CQ_TX_ERROP_MAX_SIZE_VIOL = 0x13,
  160. CQ_TX_ERROP_IMM_SIZE_OFLOW = 0x80,
  161. CQ_TX_ERROP_DATA_SEQUENCE_ERR = 0x81,
  162. CQ_TX_ERROP_MEM_SEQUENCE_ERR = 0x82,
  163. CQ_TX_ERROP_LOCK_VIOL = 0x83,
  164. CQ_TX_ERROP_DATA_FAULT = 0x84,
  165. CQ_TX_ERROP_TSTMP_CONFLICT = 0x85,
  166. CQ_TX_ERROP_TSTMP_TIMEOUT = 0x86,
  167. CQ_TX_ERROP_MEM_FAULT = 0x87,
  168. CQ_TX_ERROP_CK_OVERLAP = 0x88,
  169. CQ_TX_ERROP_CK_OFLOW = 0x89,
  170. CQ_TX_ERROP_ENUM_LAST = 0x8a,
  171. };
  172. enum RQ_SQ_STATS {
  173. RQ_SQ_STATS_OCTS,
  174. RQ_SQ_STATS_PKTS,
  175. };
  176. struct rx_tx_queue_stats {
  177. u64 bytes;
  178. u64 pkts;
  179. } ____cacheline_aligned_in_smp;
  180. struct q_desc_mem {
  181. dma_addr_t dma;
  182. u64 size;
  183. u16 q_len;
  184. dma_addr_t phys_base;
  185. void *base;
  186. void *unalign_base;
  187. };
  188. struct rbdr {
  189. bool enable;
  190. u32 dma_size;
  191. u32 frag_len;
  192. u32 thresh; /* Threshold level for interrupt */
  193. void *desc;
  194. u32 head;
  195. u32 tail;
  196. struct q_desc_mem dmem;
  197. } ____cacheline_aligned_in_smp;
  198. struct rcv_queue {
  199. bool enable;
  200. struct rbdr *rbdr_start;
  201. struct rbdr *rbdr_cont;
  202. bool en_tcp_reassembly;
  203. u8 cq_qs; /* CQ's QS to which this RQ is assigned */
  204. u8 cq_idx; /* CQ index (0 to 7) in the QS */
  205. u8 cont_rbdr_qs; /* Continue buffer ptrs - QS num */
  206. u8 cont_qs_rbdr_idx; /* RBDR idx in the cont QS */
  207. u8 start_rbdr_qs; /* First buffer ptrs - QS num */
  208. u8 start_qs_rbdr_idx; /* RBDR idx in the above QS */
  209. u8 caching;
  210. struct rx_tx_queue_stats stats;
  211. } ____cacheline_aligned_in_smp;
  212. struct cmp_queue {
  213. bool enable;
  214. u16 thresh;
  215. spinlock_t lock; /* lock to serialize processing CQEs */
  216. void *desc;
  217. struct q_desc_mem dmem;
  218. int irq;
  219. } ____cacheline_aligned_in_smp;
  220. struct snd_queue {
  221. bool enable;
  222. u8 cq_qs; /* CQ's QS to which this SQ is pointing */
  223. u8 cq_idx; /* CQ index (0 to 7) in the above QS */
  224. u16 thresh;
  225. atomic_t free_cnt;
  226. u32 head;
  227. u32 tail;
  228. u64 *skbuff;
  229. void *desc;
  230. #define TSO_HEADER_SIZE 128
  231. /* For TSO segment's header */
  232. char *tso_hdrs;
  233. dma_addr_t tso_hdrs_phys;
  234. cpumask_t affinity_mask;
  235. struct q_desc_mem dmem;
  236. struct rx_tx_queue_stats stats;
  237. } ____cacheline_aligned_in_smp;
  238. struct queue_set {
  239. bool enable;
  240. bool be_en;
  241. u8 vnic_id;
  242. u8 rq_cnt;
  243. u8 cq_cnt;
  244. u64 cq_len;
  245. u8 sq_cnt;
  246. u64 sq_len;
  247. u8 rbdr_cnt;
  248. u64 rbdr_len;
  249. struct rcv_queue rq[MAX_RCV_QUEUES_PER_QS];
  250. struct cmp_queue cq[MAX_CMP_QUEUES_PER_QS];
  251. struct snd_queue sq[MAX_SND_QUEUES_PER_QS];
  252. struct rbdr rbdr[MAX_RCV_BUF_DESC_RINGS_PER_QS];
  253. } ____cacheline_aligned_in_smp;
  254. #define GET_RBDR_DESC(RING, idx)\
  255. (&(((struct rbdr_entry_t *)((RING)->desc))[idx]))
  256. #define GET_SQ_DESC(RING, idx)\
  257. (&(((struct sq_hdr_subdesc *)((RING)->desc))[idx]))
  258. #define GET_CQ_DESC(RING, idx)\
  259. (&(((union cq_desc_t *)((RING)->desc))[idx]))
  260. /* CQ status bits */
  261. #define CQ_WR_FULL BIT(26)
  262. #define CQ_WR_DISABLE BIT(25)
  263. #define CQ_WR_FAULT BIT(24)
  264. #define CQ_CQE_COUNT (0xFFFF << 0)
  265. #define CQ_ERR_MASK (CQ_WR_FULL | CQ_WR_DISABLE | CQ_WR_FAULT)
  266. void nicvf_unmap_sndq_buffers(struct nicvf *nic, struct snd_queue *sq,
  267. int hdr_sqe, u8 subdesc_cnt);
  268. void nicvf_config_vlan_stripping(struct nicvf *nic,
  269. netdev_features_t features);
  270. int nicvf_set_qset_resources(struct nicvf *nic);
  271. int nicvf_config_data_transfer(struct nicvf *nic, bool enable);
  272. void nicvf_qset_config(struct nicvf *nic, bool enable);
  273. void nicvf_cmp_queue_config(struct nicvf *nic, struct queue_set *qs,
  274. int qidx, bool enable);
  275. void nicvf_sq_enable(struct nicvf *nic, struct snd_queue *sq, int qidx);
  276. void nicvf_sq_disable(struct nicvf *nic, int qidx);
  277. void nicvf_put_sq_desc(struct snd_queue *sq, int desc_cnt);
  278. void nicvf_sq_free_used_descs(struct net_device *netdev,
  279. struct snd_queue *sq, int qidx);
  280. int nicvf_sq_append_skb(struct nicvf *nic, struct snd_queue *sq,
  281. struct sk_buff *skb, u8 sq_num);
  282. struct sk_buff *nicvf_get_rcv_skb(struct nicvf *nic, struct cqe_rx_t *cqe_rx);
  283. void nicvf_rbdr_task(unsigned long data);
  284. void nicvf_rbdr_work(struct work_struct *work);
  285. void nicvf_enable_intr(struct nicvf *nic, int int_type, int q_idx);
  286. void nicvf_disable_intr(struct nicvf *nic, int int_type, int q_idx);
  287. void nicvf_clear_intr(struct nicvf *nic, int int_type, int q_idx);
  288. int nicvf_is_intr_enabled(struct nicvf *nic, int int_type, int q_idx);
  289. /* Register access APIs */
  290. void nicvf_reg_write(struct nicvf *nic, u64 offset, u64 val);
  291. u64 nicvf_reg_read(struct nicvf *nic, u64 offset);
  292. void nicvf_qset_reg_write(struct nicvf *nic, u64 offset, u64 val);
  293. u64 nicvf_qset_reg_read(struct nicvf *nic, u64 offset);
  294. void nicvf_queue_reg_write(struct nicvf *nic, u64 offset,
  295. u64 qidx, u64 val);
  296. u64 nicvf_queue_reg_read(struct nicvf *nic,
  297. u64 offset, u64 qidx);
  298. /* Stats */
  299. void nicvf_update_rq_stats(struct nicvf *nic, int rq_idx);
  300. void nicvf_update_sq_stats(struct nicvf *nic, int sq_idx);
  301. int nicvf_check_cqe_rx_errs(struct nicvf *nic, struct cqe_rx_t *cqe_rx);
  302. int nicvf_check_cqe_tx_errs(struct nicvf *nic, struct cqe_send_t *cqe_tx);
  303. #endif /* NICVF_QUEUES_H */