cxgb4_uld.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. /*
  2. * This file is part of the Chelsio T4 Ethernet driver for Linux.
  3. *
  4. * Copyright (c) 2003-2016 Chelsio Communications, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #ifndef __CXGB4_ULD_H
  35. #define __CXGB4_ULD_H
  36. #include <linux/cache.h>
  37. #include <linux/spinlock.h>
  38. #include <linux/skbuff.h>
  39. #include <linux/inetdevice.h>
  40. #include <linux/atomic.h>
  41. #include "cxgb4.h"
  42. #define MAX_ULD_QSETS 16
  43. /* CPL message priority levels */
  44. enum {
  45. CPL_PRIORITY_DATA = 0, /* data messages */
  46. CPL_PRIORITY_SETUP = 1, /* connection setup messages */
  47. CPL_PRIORITY_TEARDOWN = 0, /* connection teardown messages */
  48. CPL_PRIORITY_LISTEN = 1, /* listen start/stop messages */
  49. CPL_PRIORITY_ACK = 1, /* RX ACK messages */
  50. CPL_PRIORITY_CONTROL = 1 /* control messages */
  51. };
  52. #define INIT_TP_WR(w, tid) do { \
  53. (w)->wr.wr_hi = htonl(FW_WR_OP_V(FW_TP_WR) | \
  54. FW_WR_IMMDLEN_V(sizeof(*w) - sizeof(w->wr))); \
  55. (w)->wr.wr_mid = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*w), 16)) | \
  56. FW_WR_FLOWID_V(tid)); \
  57. (w)->wr.wr_lo = cpu_to_be64(0); \
  58. } while (0)
  59. #define INIT_TP_WR_CPL(w, cpl, tid) do { \
  60. INIT_TP_WR(w, tid); \
  61. OPCODE_TID(w) = htonl(MK_OPCODE_TID(cpl, tid)); \
  62. } while (0)
  63. #define INIT_ULPTX_WR(w, wrlen, atomic, tid) do { \
  64. (w)->wr.wr_hi = htonl(FW_WR_OP_V(FW_ULPTX_WR) | \
  65. FW_WR_ATOMIC_V(atomic)); \
  66. (w)->wr.wr_mid = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(wrlen, 16)) | \
  67. FW_WR_FLOWID_V(tid)); \
  68. (w)->wr.wr_lo = cpu_to_be64(0); \
  69. } while (0)
  70. /* Special asynchronous notification message */
  71. #define CXGB4_MSG_AN ((void *)1)
  72. #define TX_ULD(uld)(((uld) != CXGB4_ULD_CRYPTO) ? CXGB4_TX_OFLD :\
  73. CXGB4_TX_CRYPTO)
  74. struct serv_entry {
  75. void *data;
  76. };
  77. union aopen_entry {
  78. void *data;
  79. union aopen_entry *next;
  80. };
  81. /*
  82. * Holds the size, base address, free list start, etc of the TID, server TID,
  83. * and active-open TID tables. The tables themselves are allocated dynamically.
  84. */
  85. struct tid_info {
  86. void **tid_tab;
  87. unsigned int ntids;
  88. struct serv_entry *stid_tab;
  89. unsigned long *stid_bmap;
  90. unsigned int nstids;
  91. unsigned int stid_base;
  92. unsigned int hash_base;
  93. union aopen_entry *atid_tab;
  94. unsigned int natids;
  95. unsigned int atid_base;
  96. struct filter_entry *ftid_tab;
  97. unsigned long *ftid_bmap;
  98. unsigned int nftids;
  99. unsigned int ftid_base;
  100. unsigned int aftid_base;
  101. unsigned int aftid_end;
  102. /* Server filter region */
  103. unsigned int sftid_base;
  104. unsigned int nsftids;
  105. spinlock_t atid_lock ____cacheline_aligned_in_smp;
  106. union aopen_entry *afree;
  107. unsigned int atids_in_use;
  108. spinlock_t stid_lock;
  109. unsigned int stids_in_use;
  110. unsigned int v6_stids_in_use;
  111. unsigned int sftids_in_use;
  112. /* TIDs in the TCAM */
  113. atomic_t tids_in_use;
  114. /* TIDs in the HASH */
  115. atomic_t hash_tids_in_use;
  116. atomic_t conns_in_use;
  117. /* lock for setting/clearing filter bitmap */
  118. spinlock_t ftid_lock;
  119. };
  120. static inline void *lookup_tid(const struct tid_info *t, unsigned int tid)
  121. {
  122. return tid < t->ntids ? t->tid_tab[tid] : NULL;
  123. }
  124. static inline void *lookup_atid(const struct tid_info *t, unsigned int atid)
  125. {
  126. return atid < t->natids ? t->atid_tab[atid].data : NULL;
  127. }
  128. static inline void *lookup_stid(const struct tid_info *t, unsigned int stid)
  129. {
  130. /* Is it a server filter TID? */
  131. if (t->nsftids && (stid >= t->sftid_base)) {
  132. stid -= t->sftid_base;
  133. stid += t->nstids;
  134. } else {
  135. stid -= t->stid_base;
  136. }
  137. return stid < (t->nstids + t->nsftids) ? t->stid_tab[stid].data : NULL;
  138. }
  139. static inline void cxgb4_insert_tid(struct tid_info *t, void *data,
  140. unsigned int tid, unsigned short family)
  141. {
  142. t->tid_tab[tid] = data;
  143. if (t->hash_base && (tid >= t->hash_base)) {
  144. if (family == AF_INET6)
  145. atomic_add(2, &t->hash_tids_in_use);
  146. else
  147. atomic_inc(&t->hash_tids_in_use);
  148. } else {
  149. if (family == AF_INET6)
  150. atomic_add(2, &t->tids_in_use);
  151. else
  152. atomic_inc(&t->tids_in_use);
  153. }
  154. atomic_inc(&t->conns_in_use);
  155. }
  156. int cxgb4_alloc_atid(struct tid_info *t, void *data);
  157. int cxgb4_alloc_stid(struct tid_info *t, int family, void *data);
  158. int cxgb4_alloc_sftid(struct tid_info *t, int family, void *data);
  159. void cxgb4_free_atid(struct tid_info *t, unsigned int atid);
  160. void cxgb4_free_stid(struct tid_info *t, unsigned int stid, int family);
  161. void cxgb4_remove_tid(struct tid_info *t, unsigned int qid, unsigned int tid,
  162. unsigned short family);
  163. struct in6_addr;
  164. int cxgb4_create_server(const struct net_device *dev, unsigned int stid,
  165. __be32 sip, __be16 sport, __be16 vlan,
  166. unsigned int queue);
  167. int cxgb4_create_server6(const struct net_device *dev, unsigned int stid,
  168. const struct in6_addr *sip, __be16 sport,
  169. unsigned int queue);
  170. int cxgb4_remove_server(const struct net_device *dev, unsigned int stid,
  171. unsigned int queue, bool ipv6);
  172. int cxgb4_create_server_filter(const struct net_device *dev, unsigned int stid,
  173. __be32 sip, __be16 sport, __be16 vlan,
  174. unsigned int queue,
  175. unsigned char port, unsigned char mask);
  176. int cxgb4_remove_server_filter(const struct net_device *dev, unsigned int stid,
  177. unsigned int queue, bool ipv6);
  178. /* Filter operation context to allow callers of cxgb4_set_filter() and
  179. * cxgb4_del_filter() to wait for an asynchronous completion.
  180. */
  181. struct filter_ctx {
  182. struct completion completion; /* completion rendezvous */
  183. void *closure; /* caller's opaque information */
  184. int result; /* result of operation */
  185. u32 tid; /* to store tid */
  186. };
  187. struct ch_filter_specification;
  188. int cxgb4_get_free_ftid(struct net_device *dev, int family);
  189. int __cxgb4_set_filter(struct net_device *dev, int filter_id,
  190. struct ch_filter_specification *fs,
  191. struct filter_ctx *ctx);
  192. int __cxgb4_del_filter(struct net_device *dev, int filter_id,
  193. struct ch_filter_specification *fs,
  194. struct filter_ctx *ctx);
  195. int cxgb4_set_filter(struct net_device *dev, int filter_id,
  196. struct ch_filter_specification *fs);
  197. int cxgb4_del_filter(struct net_device *dev, int filter_id,
  198. struct ch_filter_specification *fs);
  199. int cxgb4_get_filter_counters(struct net_device *dev, unsigned int fidx,
  200. u64 *hitcnt, u64 *bytecnt, bool hash);
  201. static inline void set_wr_txq(struct sk_buff *skb, int prio, int queue)
  202. {
  203. skb_set_queue_mapping(skb, (queue << 1) | prio);
  204. }
  205. enum cxgb4_uld {
  206. CXGB4_ULD_INIT,
  207. CXGB4_ULD_RDMA,
  208. CXGB4_ULD_ISCSI,
  209. CXGB4_ULD_ISCSIT,
  210. CXGB4_ULD_CRYPTO,
  211. CXGB4_ULD_TLS,
  212. CXGB4_ULD_MAX
  213. };
  214. enum cxgb4_tx_uld {
  215. CXGB4_TX_OFLD,
  216. CXGB4_TX_CRYPTO,
  217. CXGB4_TX_MAX
  218. };
  219. enum cxgb4_txq_type {
  220. CXGB4_TXQ_ETH,
  221. CXGB4_TXQ_ULD,
  222. CXGB4_TXQ_CTRL,
  223. CXGB4_TXQ_MAX
  224. };
  225. enum cxgb4_state {
  226. CXGB4_STATE_UP,
  227. CXGB4_STATE_START_RECOVERY,
  228. CXGB4_STATE_DOWN,
  229. CXGB4_STATE_DETACH,
  230. CXGB4_STATE_FATAL_ERROR
  231. };
  232. enum cxgb4_control {
  233. CXGB4_CONTROL_DB_FULL,
  234. CXGB4_CONTROL_DB_EMPTY,
  235. CXGB4_CONTROL_DB_DROP,
  236. };
  237. struct pci_dev;
  238. struct l2t_data;
  239. struct net_device;
  240. struct pkt_gl;
  241. struct tp_tcp_stats;
  242. struct t4_lro_mgr;
  243. struct cxgb4_range {
  244. unsigned int start;
  245. unsigned int size;
  246. };
  247. struct cxgb4_virt_res { /* virtualized HW resources */
  248. struct cxgb4_range ddp;
  249. struct cxgb4_range iscsi;
  250. struct cxgb4_range stag;
  251. struct cxgb4_range rq;
  252. struct cxgb4_range srq;
  253. struct cxgb4_range pbl;
  254. struct cxgb4_range qp;
  255. struct cxgb4_range cq;
  256. struct cxgb4_range ocq;
  257. struct cxgb4_range key;
  258. unsigned int ncrypto_fc;
  259. };
  260. struct chcr_stats_debug {
  261. atomic_t cipher_rqst;
  262. atomic_t digest_rqst;
  263. atomic_t aead_rqst;
  264. atomic_t complete;
  265. atomic_t error;
  266. atomic_t fallback;
  267. atomic_t ipsec_cnt;
  268. atomic_t tls_pdu_tx;
  269. atomic_t tls_pdu_rx;
  270. atomic_t tls_key;
  271. };
  272. #define OCQ_WIN_OFFSET(pdev, vres) \
  273. (pci_resource_len((pdev), 2) - roundup_pow_of_two((vres)->ocq.size))
  274. /*
  275. * Block of information the LLD provides to ULDs attaching to a device.
  276. */
  277. struct cxgb4_lld_info {
  278. struct pci_dev *pdev; /* associated PCI device */
  279. struct l2t_data *l2t; /* L2 table */
  280. struct tid_info *tids; /* TID table */
  281. struct net_device **ports; /* device ports */
  282. const struct cxgb4_virt_res *vr; /* assorted HW resources */
  283. const unsigned short *mtus; /* MTU table */
  284. const unsigned short *rxq_ids; /* the ULD's Rx queue ids */
  285. const unsigned short *ciq_ids; /* the ULD's concentrator IQ ids */
  286. unsigned short nrxq; /* # of Rx queues */
  287. unsigned short ntxq; /* # of Tx queues */
  288. unsigned short nciq; /* # of concentrator IQ */
  289. unsigned char nchan:4; /* # of channels */
  290. unsigned char nports:4; /* # of ports */
  291. unsigned char wr_cred; /* WR 16-byte credits */
  292. unsigned char adapter_type; /* type of adapter */
  293. unsigned char fw_api_ver; /* FW API version */
  294. unsigned char crypto; /* crypto support */
  295. unsigned int fw_vers; /* FW version */
  296. unsigned int iscsi_iolen; /* iSCSI max I/O length */
  297. unsigned int cclk_ps; /* Core clock period in psec */
  298. unsigned short udb_density; /* # of user DB/page */
  299. unsigned short ucq_density; /* # of user CQs/page */
  300. unsigned short filt_mode; /* filter optional components */
  301. unsigned short tx_modq[NCHAN]; /* maps each tx channel to a */
  302. /* scheduler queue */
  303. void __iomem *gts_reg; /* address of GTS register */
  304. void __iomem *db_reg; /* address of kernel doorbell */
  305. int dbfifo_int_thresh; /* doorbell fifo int threshold */
  306. unsigned int sge_ingpadboundary; /* SGE ingress padding boundary */
  307. unsigned int sge_egrstatuspagesize; /* SGE egress status page size */
  308. unsigned int sge_pktshift; /* Padding between CPL and */
  309. /* packet data */
  310. unsigned int pf; /* Physical Function we're using */
  311. bool enable_fw_ofld_conn; /* Enable connection through fw */
  312. /* WR */
  313. unsigned int max_ordird_qp; /* Max ORD/IRD depth per RDMA QP */
  314. unsigned int max_ird_adapter; /* Max IRD memory per adapter */
  315. bool ulptx_memwrite_dsgl; /* use of T5 DSGL allowed */
  316. unsigned int iscsi_tagmask; /* iscsi ddp tag mask */
  317. unsigned int iscsi_pgsz_order; /* iscsi ddp page size orders */
  318. unsigned int iscsi_llimit; /* chip's iscsi region llimit */
  319. unsigned int ulp_crypto; /* crypto lookaside support */
  320. void **iscsi_ppm; /* iscsi page pod manager */
  321. int nodeid; /* device numa node id */
  322. bool fr_nsmr_tpte_wr_support; /* FW supports FR_NSMR_TPTE_WR */
  323. bool write_w_imm_support; /* FW supports WRITE_WITH_IMMEDIATE */
  324. bool write_cmpl_support; /* FW supports WRITE_CMPL WR */
  325. };
  326. struct cxgb4_uld_info {
  327. char name[IFNAMSIZ];
  328. void *handle;
  329. unsigned int nrxq;
  330. unsigned int rxq_size;
  331. unsigned int ntxq;
  332. bool ciq;
  333. bool lro;
  334. void *(*add)(const struct cxgb4_lld_info *p);
  335. int (*rx_handler)(void *handle, const __be64 *rsp,
  336. const struct pkt_gl *gl);
  337. int (*state_change)(void *handle, enum cxgb4_state new_state);
  338. int (*control)(void *handle, enum cxgb4_control control, ...);
  339. int (*lro_rx_handler)(void *handle, const __be64 *rsp,
  340. const struct pkt_gl *gl,
  341. struct t4_lro_mgr *lro_mgr,
  342. struct napi_struct *napi);
  343. void (*lro_flush)(struct t4_lro_mgr *);
  344. int (*tx_handler)(struct sk_buff *skb, struct net_device *dev);
  345. };
  346. int cxgb4_register_uld(enum cxgb4_uld type, const struct cxgb4_uld_info *p);
  347. int cxgb4_unregister_uld(enum cxgb4_uld type);
  348. int cxgb4_ofld_send(struct net_device *dev, struct sk_buff *skb);
  349. int cxgb4_immdata_send(struct net_device *dev, unsigned int idx,
  350. const void *src, unsigned int len);
  351. int cxgb4_crypto_send(struct net_device *dev, struct sk_buff *skb);
  352. unsigned int cxgb4_dbfifo_count(const struct net_device *dev, int lpfifo);
  353. unsigned int cxgb4_port_chan(const struct net_device *dev);
  354. unsigned int cxgb4_port_viid(const struct net_device *dev);
  355. unsigned int cxgb4_tp_smt_idx(enum chip_type chip, unsigned int viid);
  356. unsigned int cxgb4_port_idx(const struct net_device *dev);
  357. unsigned int cxgb4_best_mtu(const unsigned short *mtus, unsigned short mtu,
  358. unsigned int *idx);
  359. unsigned int cxgb4_best_aligned_mtu(const unsigned short *mtus,
  360. unsigned short header_size,
  361. unsigned short data_size_max,
  362. unsigned short data_size_align,
  363. unsigned int *mtu_idxp);
  364. void cxgb4_get_tcp_stats(struct pci_dev *pdev, struct tp_tcp_stats *v4,
  365. struct tp_tcp_stats *v6);
  366. void cxgb4_iscsi_init(struct net_device *dev, unsigned int tag_mask,
  367. const unsigned int *pgsz_order);
  368. struct sk_buff *cxgb4_pktgl_to_skb(const struct pkt_gl *gl,
  369. unsigned int skb_len, unsigned int pull_len);
  370. int cxgb4_sync_txq_pidx(struct net_device *dev, u16 qid, u16 pidx, u16 size);
  371. int cxgb4_flush_eq_cache(struct net_device *dev);
  372. int cxgb4_read_tpte(struct net_device *dev, u32 stag, __be32 *tpte);
  373. u64 cxgb4_read_sge_timestamp(struct net_device *dev);
  374. enum cxgb4_bar2_qtype { CXGB4_BAR2_QTYPE_EGRESS, CXGB4_BAR2_QTYPE_INGRESS };
  375. int cxgb4_bar2_sge_qregs(struct net_device *dev,
  376. unsigned int qid,
  377. enum cxgb4_bar2_qtype qtype,
  378. int user,
  379. u64 *pbar2_qoffset,
  380. unsigned int *pbar2_qid);
  381. #endif /* !__CXGB4_ULD_H */