iw_cxgb4.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  1. /*
  2. * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. * - Redistributions in binary form must reproduce the above
  18. * copyright notice, this list of conditions and the following
  19. * disclaimer in the documentation and/or other materials
  20. * provided with the distribution.
  21. *
  22. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  26. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  27. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  28. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  29. * SOFTWARE.
  30. */
  31. #ifndef __IW_CXGB4_H__
  32. #define __IW_CXGB4_H__
  33. #include <linux/mutex.h>
  34. #include <linux/list.h>
  35. #include <linux/spinlock.h>
  36. #include <linux/idr.h>
  37. #include <linux/completion.h>
  38. #include <linux/netdevice.h>
  39. #include <linux/sched.h>
  40. #include <linux/pci.h>
  41. #include <linux/dma-mapping.h>
  42. #include <linux/inet.h>
  43. #include <linux/wait.h>
  44. #include <linux/kref.h>
  45. #include <linux/timer.h>
  46. #include <linux/io.h>
  47. #include <linux/kfifo.h>
  48. #include <asm/byteorder.h>
  49. #include <net/net_namespace.h>
  50. #include <rdma/ib_verbs.h>
  51. #include <rdma/iw_cm.h>
  52. #include "cxgb4.h"
  53. #include "cxgb4_uld.h"
  54. #include "l2t.h"
  55. #include "user.h"
  56. #define DRV_NAME "iw_cxgb4"
  57. #define MOD DRV_NAME ":"
  58. extern int c4iw_debug;
  59. #define PDBG(fmt, args...) \
  60. do { \
  61. if (c4iw_debug) \
  62. printk(MOD fmt, ## args); \
  63. } while (0)
  64. #include "t4.h"
  65. #define PBL_OFF(rdev_p, a) ((a) - (rdev_p)->lldi.vr->pbl.start)
  66. #define RQT_OFF(rdev_p, a) ((a) - (rdev_p)->lldi.vr->rq.start)
  67. static inline void *cplhdr(struct sk_buff *skb)
  68. {
  69. return skb->data;
  70. }
  71. struct c4iw_resource {
  72. struct kfifo tpt_fifo;
  73. spinlock_t tpt_fifo_lock;
  74. struct kfifo qid_fifo;
  75. spinlock_t qid_fifo_lock;
  76. struct kfifo pdid_fifo;
  77. spinlock_t pdid_fifo_lock;
  78. };
  79. struct c4iw_qid_list {
  80. struct list_head entry;
  81. u32 qid;
  82. };
  83. struct c4iw_dev_ucontext {
  84. struct list_head qpids;
  85. struct list_head cqids;
  86. struct mutex lock;
  87. };
  88. enum c4iw_rdev_flags {
  89. T4_FATAL_ERROR = (1<<0),
  90. };
  91. struct c4iw_rdev {
  92. struct c4iw_resource resource;
  93. unsigned long qpshift;
  94. u32 qpmask;
  95. unsigned long cqshift;
  96. u32 cqmask;
  97. struct c4iw_dev_ucontext uctx;
  98. struct gen_pool *pbl_pool;
  99. struct gen_pool *rqt_pool;
  100. struct gen_pool *ocqp_pool;
  101. u32 flags;
  102. struct cxgb4_lld_info lldi;
  103. unsigned long oc_mw_pa;
  104. void __iomem *oc_mw_kva;
  105. };
  106. static inline int c4iw_fatal_error(struct c4iw_rdev *rdev)
  107. {
  108. return rdev->flags & T4_FATAL_ERROR;
  109. }
  110. static inline int c4iw_num_stags(struct c4iw_rdev *rdev)
  111. {
  112. return min((int)T4_MAX_NUM_STAG, (int)(rdev->lldi.vr->stag.size >> 5));
  113. }
  114. #define C4IW_WR_TO (10*HZ)
  115. struct c4iw_wr_wait {
  116. struct completion completion;
  117. int ret;
  118. };
  119. static inline void c4iw_init_wr_wait(struct c4iw_wr_wait *wr_waitp)
  120. {
  121. wr_waitp->ret = 0;
  122. init_completion(&wr_waitp->completion);
  123. }
  124. static inline void c4iw_wake_up(struct c4iw_wr_wait *wr_waitp, int ret)
  125. {
  126. wr_waitp->ret = ret;
  127. complete(&wr_waitp->completion);
  128. }
  129. static inline int c4iw_wait_for_reply(struct c4iw_rdev *rdev,
  130. struct c4iw_wr_wait *wr_waitp,
  131. u32 hwtid, u32 qpid,
  132. const char *func)
  133. {
  134. unsigned to = C4IW_WR_TO;
  135. int ret;
  136. do {
  137. ret = wait_for_completion_timeout(&wr_waitp->completion, to);
  138. if (!ret) {
  139. printk(KERN_ERR MOD "%s - Device %s not responding - "
  140. "tid %u qpid %u\n", func,
  141. pci_name(rdev->lldi.pdev), hwtid, qpid);
  142. if (c4iw_fatal_error(rdev)) {
  143. wr_waitp->ret = -EIO;
  144. break;
  145. }
  146. to = to << 2;
  147. }
  148. } while (!ret);
  149. if (wr_waitp->ret)
  150. PDBG("%s: FW reply %d tid %u qpid %u\n",
  151. pci_name(rdev->lldi.pdev), wr_waitp->ret, hwtid, qpid);
  152. return wr_waitp->ret;
  153. }
  154. struct c4iw_dev {
  155. struct ib_device ibdev;
  156. struct c4iw_rdev rdev;
  157. u32 device_cap_flags;
  158. struct idr cqidr;
  159. struct idr qpidr;
  160. struct idr mmidr;
  161. spinlock_t lock;
  162. struct dentry *debugfs_root;
  163. };
  164. static inline struct c4iw_dev *to_c4iw_dev(struct ib_device *ibdev)
  165. {
  166. return container_of(ibdev, struct c4iw_dev, ibdev);
  167. }
  168. static inline struct c4iw_dev *rdev_to_c4iw_dev(struct c4iw_rdev *rdev)
  169. {
  170. return container_of(rdev, struct c4iw_dev, rdev);
  171. }
  172. static inline struct c4iw_cq *get_chp(struct c4iw_dev *rhp, u32 cqid)
  173. {
  174. return idr_find(&rhp->cqidr, cqid);
  175. }
  176. static inline struct c4iw_qp *get_qhp(struct c4iw_dev *rhp, u32 qpid)
  177. {
  178. return idr_find(&rhp->qpidr, qpid);
  179. }
  180. static inline struct c4iw_mr *get_mhp(struct c4iw_dev *rhp, u32 mmid)
  181. {
  182. return idr_find(&rhp->mmidr, mmid);
  183. }
  184. static inline int insert_handle(struct c4iw_dev *rhp, struct idr *idr,
  185. void *handle, u32 id)
  186. {
  187. int ret;
  188. int newid;
  189. do {
  190. if (!idr_pre_get(idr, GFP_KERNEL))
  191. return -ENOMEM;
  192. spin_lock_irq(&rhp->lock);
  193. ret = idr_get_new_above(idr, handle, id, &newid);
  194. BUG_ON(newid != id);
  195. spin_unlock_irq(&rhp->lock);
  196. } while (ret == -EAGAIN);
  197. return ret;
  198. }
  199. static inline void remove_handle(struct c4iw_dev *rhp, struct idr *idr, u32 id)
  200. {
  201. spin_lock_irq(&rhp->lock);
  202. idr_remove(idr, id);
  203. spin_unlock_irq(&rhp->lock);
  204. }
  205. struct c4iw_pd {
  206. struct ib_pd ibpd;
  207. u32 pdid;
  208. struct c4iw_dev *rhp;
  209. };
  210. static inline struct c4iw_pd *to_c4iw_pd(struct ib_pd *ibpd)
  211. {
  212. return container_of(ibpd, struct c4iw_pd, ibpd);
  213. }
  214. struct tpt_attributes {
  215. u64 len;
  216. u64 va_fbo;
  217. enum fw_ri_mem_perms perms;
  218. u32 stag;
  219. u32 pdid;
  220. u32 qpid;
  221. u32 pbl_addr;
  222. u32 pbl_size;
  223. u32 state:1;
  224. u32 type:2;
  225. u32 rsvd:1;
  226. u32 remote_invaliate_disable:1;
  227. u32 zbva:1;
  228. u32 mw_bind_enable:1;
  229. u32 page_size:5;
  230. };
  231. struct c4iw_mr {
  232. struct ib_mr ibmr;
  233. struct ib_umem *umem;
  234. struct c4iw_dev *rhp;
  235. u64 kva;
  236. struct tpt_attributes attr;
  237. };
  238. static inline struct c4iw_mr *to_c4iw_mr(struct ib_mr *ibmr)
  239. {
  240. return container_of(ibmr, struct c4iw_mr, ibmr);
  241. }
  242. struct c4iw_mw {
  243. struct ib_mw ibmw;
  244. struct c4iw_dev *rhp;
  245. u64 kva;
  246. struct tpt_attributes attr;
  247. };
  248. static inline struct c4iw_mw *to_c4iw_mw(struct ib_mw *ibmw)
  249. {
  250. return container_of(ibmw, struct c4iw_mw, ibmw);
  251. }
  252. struct c4iw_fr_page_list {
  253. struct ib_fast_reg_page_list ibpl;
  254. DEFINE_DMA_UNMAP_ADDR(mapping);
  255. dma_addr_t dma_addr;
  256. struct c4iw_dev *dev;
  257. int size;
  258. };
  259. static inline struct c4iw_fr_page_list *to_c4iw_fr_page_list(
  260. struct ib_fast_reg_page_list *ibpl)
  261. {
  262. return container_of(ibpl, struct c4iw_fr_page_list, ibpl);
  263. }
  264. struct c4iw_cq {
  265. struct ib_cq ibcq;
  266. struct c4iw_dev *rhp;
  267. struct t4_cq cq;
  268. spinlock_t lock;
  269. spinlock_t comp_handler_lock;
  270. atomic_t refcnt;
  271. wait_queue_head_t wait;
  272. };
  273. static inline struct c4iw_cq *to_c4iw_cq(struct ib_cq *ibcq)
  274. {
  275. return container_of(ibcq, struct c4iw_cq, ibcq);
  276. }
  277. struct c4iw_mpa_attributes {
  278. u8 initiator;
  279. u8 recv_marker_enabled;
  280. u8 xmit_marker_enabled;
  281. u8 crc_enabled;
  282. u8 enhanced_rdma_conn;
  283. u8 version;
  284. u8 p2p_type;
  285. };
  286. struct c4iw_qp_attributes {
  287. u32 scq;
  288. u32 rcq;
  289. u32 sq_num_entries;
  290. u32 rq_num_entries;
  291. u32 sq_max_sges;
  292. u32 sq_max_sges_rdma_write;
  293. u32 rq_max_sges;
  294. u32 state;
  295. u8 enable_rdma_read;
  296. u8 enable_rdma_write;
  297. u8 enable_bind;
  298. u8 enable_mmid0_fastreg;
  299. u32 max_ord;
  300. u32 max_ird;
  301. u32 pd;
  302. u32 next_state;
  303. char terminate_buffer[52];
  304. u32 terminate_msg_len;
  305. u8 is_terminate_local;
  306. struct c4iw_mpa_attributes mpa_attr;
  307. struct c4iw_ep *llp_stream_handle;
  308. u8 layer_etype;
  309. u8 ecode;
  310. };
  311. struct c4iw_qp {
  312. struct ib_qp ibqp;
  313. struct c4iw_dev *rhp;
  314. struct c4iw_ep *ep;
  315. struct c4iw_qp_attributes attr;
  316. struct t4_wq wq;
  317. spinlock_t lock;
  318. struct mutex mutex;
  319. atomic_t refcnt;
  320. wait_queue_head_t wait;
  321. struct timer_list timer;
  322. };
  323. static inline struct c4iw_qp *to_c4iw_qp(struct ib_qp *ibqp)
  324. {
  325. return container_of(ibqp, struct c4iw_qp, ibqp);
  326. }
  327. struct c4iw_ucontext {
  328. struct ib_ucontext ibucontext;
  329. struct c4iw_dev_ucontext uctx;
  330. u32 key;
  331. spinlock_t mmap_lock;
  332. struct list_head mmaps;
  333. };
  334. static inline struct c4iw_ucontext *to_c4iw_ucontext(struct ib_ucontext *c)
  335. {
  336. return container_of(c, struct c4iw_ucontext, ibucontext);
  337. }
  338. struct c4iw_mm_entry {
  339. struct list_head entry;
  340. u64 addr;
  341. u32 key;
  342. unsigned len;
  343. };
  344. static inline struct c4iw_mm_entry *remove_mmap(struct c4iw_ucontext *ucontext,
  345. u32 key, unsigned len)
  346. {
  347. struct list_head *pos, *nxt;
  348. struct c4iw_mm_entry *mm;
  349. spin_lock(&ucontext->mmap_lock);
  350. list_for_each_safe(pos, nxt, &ucontext->mmaps) {
  351. mm = list_entry(pos, struct c4iw_mm_entry, entry);
  352. if (mm->key == key && mm->len == len) {
  353. list_del_init(&mm->entry);
  354. spin_unlock(&ucontext->mmap_lock);
  355. PDBG("%s key 0x%x addr 0x%llx len %d\n", __func__,
  356. key, (unsigned long long) mm->addr, mm->len);
  357. return mm;
  358. }
  359. }
  360. spin_unlock(&ucontext->mmap_lock);
  361. return NULL;
  362. }
  363. static inline void insert_mmap(struct c4iw_ucontext *ucontext,
  364. struct c4iw_mm_entry *mm)
  365. {
  366. spin_lock(&ucontext->mmap_lock);
  367. PDBG("%s key 0x%x addr 0x%llx len %d\n", __func__,
  368. mm->key, (unsigned long long) mm->addr, mm->len);
  369. list_add_tail(&mm->entry, &ucontext->mmaps);
  370. spin_unlock(&ucontext->mmap_lock);
  371. }
  372. enum c4iw_qp_attr_mask {
  373. C4IW_QP_ATTR_NEXT_STATE = 1 << 0,
  374. C4IW_QP_ATTR_ENABLE_RDMA_READ = 1 << 7,
  375. C4IW_QP_ATTR_ENABLE_RDMA_WRITE = 1 << 8,
  376. C4IW_QP_ATTR_ENABLE_RDMA_BIND = 1 << 9,
  377. C4IW_QP_ATTR_MAX_ORD = 1 << 11,
  378. C4IW_QP_ATTR_MAX_IRD = 1 << 12,
  379. C4IW_QP_ATTR_LLP_STREAM_HANDLE = 1 << 22,
  380. C4IW_QP_ATTR_STREAM_MSG_BUFFER = 1 << 23,
  381. C4IW_QP_ATTR_MPA_ATTR = 1 << 24,
  382. C4IW_QP_ATTR_QP_CONTEXT_ACTIVATE = 1 << 25,
  383. C4IW_QP_ATTR_VALID_MODIFY = (C4IW_QP_ATTR_ENABLE_RDMA_READ |
  384. C4IW_QP_ATTR_ENABLE_RDMA_WRITE |
  385. C4IW_QP_ATTR_MAX_ORD |
  386. C4IW_QP_ATTR_MAX_IRD |
  387. C4IW_QP_ATTR_LLP_STREAM_HANDLE |
  388. C4IW_QP_ATTR_STREAM_MSG_BUFFER |
  389. C4IW_QP_ATTR_MPA_ATTR |
  390. C4IW_QP_ATTR_QP_CONTEXT_ACTIVATE)
  391. };
  392. int c4iw_modify_qp(struct c4iw_dev *rhp,
  393. struct c4iw_qp *qhp,
  394. enum c4iw_qp_attr_mask mask,
  395. struct c4iw_qp_attributes *attrs,
  396. int internal);
  397. enum c4iw_qp_state {
  398. C4IW_QP_STATE_IDLE,
  399. C4IW_QP_STATE_RTS,
  400. C4IW_QP_STATE_ERROR,
  401. C4IW_QP_STATE_TERMINATE,
  402. C4IW_QP_STATE_CLOSING,
  403. C4IW_QP_STATE_TOT
  404. };
  405. static inline int c4iw_convert_state(enum ib_qp_state ib_state)
  406. {
  407. switch (ib_state) {
  408. case IB_QPS_RESET:
  409. case IB_QPS_INIT:
  410. return C4IW_QP_STATE_IDLE;
  411. case IB_QPS_RTS:
  412. return C4IW_QP_STATE_RTS;
  413. case IB_QPS_SQD:
  414. return C4IW_QP_STATE_CLOSING;
  415. case IB_QPS_SQE:
  416. return C4IW_QP_STATE_TERMINATE;
  417. case IB_QPS_ERR:
  418. return C4IW_QP_STATE_ERROR;
  419. default:
  420. return -1;
  421. }
  422. }
  423. static inline u32 c4iw_ib_to_tpt_access(int a)
  424. {
  425. return (a & IB_ACCESS_REMOTE_WRITE ? FW_RI_MEM_ACCESS_REM_WRITE : 0) |
  426. (a & IB_ACCESS_REMOTE_READ ? FW_RI_MEM_ACCESS_REM_READ : 0) |
  427. (a & IB_ACCESS_LOCAL_WRITE ? FW_RI_MEM_ACCESS_LOCAL_WRITE : 0) |
  428. FW_RI_MEM_ACCESS_LOCAL_READ;
  429. }
  430. static inline u32 c4iw_ib_to_tpt_bind_access(int acc)
  431. {
  432. return (acc & IB_ACCESS_REMOTE_WRITE ? FW_RI_MEM_ACCESS_REM_WRITE : 0) |
  433. (acc & IB_ACCESS_REMOTE_READ ? FW_RI_MEM_ACCESS_REM_READ : 0);
  434. }
  435. enum c4iw_mmid_state {
  436. C4IW_STAG_STATE_VALID,
  437. C4IW_STAG_STATE_INVALID
  438. };
  439. #define C4IW_NODE_DESC "cxgb4 Chelsio Communications"
  440. #define MPA_KEY_REQ "MPA ID Req Frame"
  441. #define MPA_KEY_REP "MPA ID Rep Frame"
  442. #define MPA_MAX_PRIVATE_DATA 256
  443. #define MPA_ENHANCED_RDMA_CONN 0x10
  444. #define MPA_REJECT 0x20
  445. #define MPA_CRC 0x40
  446. #define MPA_MARKERS 0x80
  447. #define MPA_FLAGS_MASK 0xE0
  448. #define MPA_V2_PEER2PEER_MODEL 0x8000
  449. #define MPA_V2_ZERO_LEN_FPDU_RTR 0x4000
  450. #define MPA_V2_RDMA_WRITE_RTR 0x8000
  451. #define MPA_V2_RDMA_READ_RTR 0x4000
  452. #define MPA_V2_IRD_ORD_MASK 0x3FFF
  453. #define c4iw_put_ep(ep) { \
  454. PDBG("put_ep (via %s:%u) ep %p refcnt %d\n", __func__, __LINE__, \
  455. ep, atomic_read(&((ep)->kref.refcount))); \
  456. WARN_ON(atomic_read(&((ep)->kref.refcount)) < 1); \
  457. kref_put(&((ep)->kref), _c4iw_free_ep); \
  458. }
  459. #define c4iw_get_ep(ep) { \
  460. PDBG("get_ep (via %s:%u) ep %p, refcnt %d\n", __func__, __LINE__, \
  461. ep, atomic_read(&((ep)->kref.refcount))); \
  462. kref_get(&((ep)->kref)); \
  463. }
  464. void _c4iw_free_ep(struct kref *kref);
  465. struct mpa_message {
  466. u8 key[16];
  467. u8 flags;
  468. u8 revision;
  469. __be16 private_data_size;
  470. u8 private_data[0];
  471. };
  472. struct mpa_v2_conn_params {
  473. __be16 ird;
  474. __be16 ord;
  475. };
  476. struct terminate_message {
  477. u8 layer_etype;
  478. u8 ecode;
  479. __be16 hdrct_rsvd;
  480. u8 len_hdrs[0];
  481. };
  482. #define TERM_MAX_LENGTH (sizeof(struct terminate_message) + 2 + 18 + 28)
  483. enum c4iw_layers_types {
  484. LAYER_RDMAP = 0x00,
  485. LAYER_DDP = 0x10,
  486. LAYER_MPA = 0x20,
  487. RDMAP_LOCAL_CATA = 0x00,
  488. RDMAP_REMOTE_PROT = 0x01,
  489. RDMAP_REMOTE_OP = 0x02,
  490. DDP_LOCAL_CATA = 0x00,
  491. DDP_TAGGED_ERR = 0x01,
  492. DDP_UNTAGGED_ERR = 0x02,
  493. DDP_LLP = 0x03
  494. };
  495. enum c4iw_rdma_ecodes {
  496. RDMAP_INV_STAG = 0x00,
  497. RDMAP_BASE_BOUNDS = 0x01,
  498. RDMAP_ACC_VIOL = 0x02,
  499. RDMAP_STAG_NOT_ASSOC = 0x03,
  500. RDMAP_TO_WRAP = 0x04,
  501. RDMAP_INV_VERS = 0x05,
  502. RDMAP_INV_OPCODE = 0x06,
  503. RDMAP_STREAM_CATA = 0x07,
  504. RDMAP_GLOBAL_CATA = 0x08,
  505. RDMAP_CANT_INV_STAG = 0x09,
  506. RDMAP_UNSPECIFIED = 0xff
  507. };
  508. enum c4iw_ddp_ecodes {
  509. DDPT_INV_STAG = 0x00,
  510. DDPT_BASE_BOUNDS = 0x01,
  511. DDPT_STAG_NOT_ASSOC = 0x02,
  512. DDPT_TO_WRAP = 0x03,
  513. DDPT_INV_VERS = 0x04,
  514. DDPU_INV_QN = 0x01,
  515. DDPU_INV_MSN_NOBUF = 0x02,
  516. DDPU_INV_MSN_RANGE = 0x03,
  517. DDPU_INV_MO = 0x04,
  518. DDPU_MSG_TOOBIG = 0x05,
  519. DDPU_INV_VERS = 0x06
  520. };
  521. enum c4iw_mpa_ecodes {
  522. MPA_CRC_ERR = 0x02,
  523. MPA_MARKER_ERR = 0x03,
  524. MPA_LOCAL_CATA = 0x05,
  525. MPA_INSUFF_IRD = 0x06,
  526. MPA_NOMATCH_RTR = 0x07,
  527. };
  528. enum c4iw_ep_state {
  529. IDLE = 0,
  530. LISTEN,
  531. CONNECTING,
  532. MPA_REQ_WAIT,
  533. MPA_REQ_SENT,
  534. MPA_REQ_RCVD,
  535. MPA_REP_SENT,
  536. FPDU_MODE,
  537. ABORTING,
  538. CLOSING,
  539. MORIBUND,
  540. DEAD,
  541. };
  542. enum c4iw_ep_flags {
  543. PEER_ABORT_IN_PROGRESS = 0,
  544. ABORT_REQ_IN_PROGRESS = 1,
  545. RELEASE_RESOURCES = 2,
  546. CLOSE_SENT = 3,
  547. };
  548. struct c4iw_ep_common {
  549. struct iw_cm_id *cm_id;
  550. struct c4iw_qp *qp;
  551. struct c4iw_dev *dev;
  552. enum c4iw_ep_state state;
  553. struct kref kref;
  554. struct mutex mutex;
  555. struct sockaddr_in local_addr;
  556. struct sockaddr_in remote_addr;
  557. struct c4iw_wr_wait wr_wait;
  558. unsigned long flags;
  559. };
  560. struct c4iw_listen_ep {
  561. struct c4iw_ep_common com;
  562. unsigned int stid;
  563. int backlog;
  564. };
  565. struct c4iw_ep {
  566. struct c4iw_ep_common com;
  567. struct c4iw_ep *parent_ep;
  568. struct timer_list timer;
  569. struct list_head entry;
  570. unsigned int atid;
  571. u32 hwtid;
  572. u32 snd_seq;
  573. u32 rcv_seq;
  574. struct l2t_entry *l2t;
  575. struct dst_entry *dst;
  576. struct sk_buff *mpa_skb;
  577. struct c4iw_mpa_attributes mpa_attr;
  578. u8 mpa_pkt[sizeof(struct mpa_message) + MPA_MAX_PRIVATE_DATA];
  579. unsigned int mpa_pkt_len;
  580. u32 ird;
  581. u32 ord;
  582. u32 smac_idx;
  583. u32 tx_chan;
  584. u32 mtu;
  585. u16 mss;
  586. u16 emss;
  587. u16 plen;
  588. u16 rss_qid;
  589. u16 txq_idx;
  590. u16 ctrlq_idx;
  591. u8 tos;
  592. u8 retry_with_mpa_v1;
  593. u8 tried_with_mpa_v1;
  594. };
  595. static inline struct c4iw_ep *to_ep(struct iw_cm_id *cm_id)
  596. {
  597. return cm_id->provider_data;
  598. }
  599. static inline struct c4iw_listen_ep *to_listen_ep(struct iw_cm_id *cm_id)
  600. {
  601. return cm_id->provider_data;
  602. }
  603. static inline int compute_wscale(int win)
  604. {
  605. int wscale = 0;
  606. while (wscale < 14 && (65535<<wscale) < win)
  607. wscale++;
  608. return wscale;
  609. }
  610. typedef int (*c4iw_handler_func)(struct c4iw_dev *dev, struct sk_buff *skb);
  611. int c4iw_ep_redirect(void *ctx, struct dst_entry *old, struct dst_entry *new,
  612. struct l2t_entry *l2t);
  613. void c4iw_put_qpid(struct c4iw_rdev *rdev, u32 qpid,
  614. struct c4iw_dev_ucontext *uctx);
  615. u32 c4iw_get_resource(struct kfifo *fifo, spinlock_t *lock);
  616. void c4iw_put_resource(struct kfifo *fifo, u32 entry, spinlock_t *lock);
  617. int c4iw_init_resource(struct c4iw_rdev *rdev, u32 nr_tpt, u32 nr_pdid);
  618. int c4iw_init_ctrl_qp(struct c4iw_rdev *rdev);
  619. int c4iw_pblpool_create(struct c4iw_rdev *rdev);
  620. int c4iw_rqtpool_create(struct c4iw_rdev *rdev);
  621. int c4iw_ocqp_pool_create(struct c4iw_rdev *rdev);
  622. void c4iw_pblpool_destroy(struct c4iw_rdev *rdev);
  623. void c4iw_rqtpool_destroy(struct c4iw_rdev *rdev);
  624. void c4iw_ocqp_pool_destroy(struct c4iw_rdev *rdev);
  625. void c4iw_destroy_resource(struct c4iw_resource *rscp);
  626. int c4iw_destroy_ctrl_qp(struct c4iw_rdev *rdev);
  627. int c4iw_register_device(struct c4iw_dev *dev);
  628. void c4iw_unregister_device(struct c4iw_dev *dev);
  629. int __init c4iw_cm_init(void);
  630. void __exit c4iw_cm_term(void);
  631. void c4iw_release_dev_ucontext(struct c4iw_rdev *rdev,
  632. struct c4iw_dev_ucontext *uctx);
  633. void c4iw_init_dev_ucontext(struct c4iw_rdev *rdev,
  634. struct c4iw_dev_ucontext *uctx);
  635. int c4iw_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
  636. int c4iw_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
  637. struct ib_send_wr **bad_wr);
  638. int c4iw_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
  639. struct ib_recv_wr **bad_wr);
  640. int c4iw_bind_mw(struct ib_qp *qp, struct ib_mw *mw,
  641. struct ib_mw_bind *mw_bind);
  642. int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param);
  643. int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog);
  644. int c4iw_destroy_listen(struct iw_cm_id *cm_id);
  645. int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param);
  646. int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len);
  647. void c4iw_qp_add_ref(struct ib_qp *qp);
  648. void c4iw_qp_rem_ref(struct ib_qp *qp);
  649. void c4iw_free_fastreg_pbl(struct ib_fast_reg_page_list *page_list);
  650. struct ib_fast_reg_page_list *c4iw_alloc_fastreg_pbl(
  651. struct ib_device *device,
  652. int page_list_len);
  653. struct ib_mr *c4iw_alloc_fast_reg_mr(struct ib_pd *pd, int pbl_depth);
  654. int c4iw_dealloc_mw(struct ib_mw *mw);
  655. struct ib_mw *c4iw_alloc_mw(struct ib_pd *pd);
  656. struct ib_mr *c4iw_reg_user_mr(struct ib_pd *pd, u64 start,
  657. u64 length, u64 virt, int acc,
  658. struct ib_udata *udata);
  659. struct ib_mr *c4iw_get_dma_mr(struct ib_pd *pd, int acc);
  660. struct ib_mr *c4iw_register_phys_mem(struct ib_pd *pd,
  661. struct ib_phys_buf *buffer_list,
  662. int num_phys_buf,
  663. int acc,
  664. u64 *iova_start);
  665. int c4iw_reregister_phys_mem(struct ib_mr *mr,
  666. int mr_rereg_mask,
  667. struct ib_pd *pd,
  668. struct ib_phys_buf *buffer_list,
  669. int num_phys_buf,
  670. int acc, u64 *iova_start);
  671. int c4iw_dereg_mr(struct ib_mr *ib_mr);
  672. int c4iw_destroy_cq(struct ib_cq *ib_cq);
  673. struct ib_cq *c4iw_create_cq(struct ib_device *ibdev, int entries,
  674. int vector,
  675. struct ib_ucontext *ib_context,
  676. struct ib_udata *udata);
  677. int c4iw_resize_cq(struct ib_cq *cq, int cqe, struct ib_udata *udata);
  678. int c4iw_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags);
  679. int c4iw_destroy_qp(struct ib_qp *ib_qp);
  680. struct ib_qp *c4iw_create_qp(struct ib_pd *pd,
  681. struct ib_qp_init_attr *attrs,
  682. struct ib_udata *udata);
  683. int c4iw_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
  684. int attr_mask, struct ib_udata *udata);
  685. struct ib_qp *c4iw_get_qp(struct ib_device *dev, int qpn);
  686. u32 c4iw_rqtpool_alloc(struct c4iw_rdev *rdev, int size);
  687. void c4iw_rqtpool_free(struct c4iw_rdev *rdev, u32 addr, int size);
  688. u32 c4iw_pblpool_alloc(struct c4iw_rdev *rdev, int size);
  689. void c4iw_pblpool_free(struct c4iw_rdev *rdev, u32 addr, int size);
  690. u32 c4iw_ocqp_pool_alloc(struct c4iw_rdev *rdev, int size);
  691. void c4iw_ocqp_pool_free(struct c4iw_rdev *rdev, u32 addr, int size);
  692. int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb);
  693. void c4iw_flush_hw_cq(struct t4_cq *cq);
  694. void c4iw_count_rcqes(struct t4_cq *cq, struct t4_wq *wq, int *count);
  695. void c4iw_count_scqes(struct t4_cq *cq, struct t4_wq *wq, int *count);
  696. int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp);
  697. int c4iw_flush_rq(struct t4_wq *wq, struct t4_cq *cq, int count);
  698. int c4iw_flush_sq(struct t4_wq *wq, struct t4_cq *cq, int count);
  699. int c4iw_ev_handler(struct c4iw_dev *rnicp, u32 qid);
  700. u16 c4iw_rqes_posted(struct c4iw_qp *qhp);
  701. int c4iw_post_terminate(struct c4iw_qp *qhp, struct t4_cqe *err_cqe);
  702. u32 c4iw_get_cqid(struct c4iw_rdev *rdev, struct c4iw_dev_ucontext *uctx);
  703. void c4iw_put_cqid(struct c4iw_rdev *rdev, u32 qid,
  704. struct c4iw_dev_ucontext *uctx);
  705. u32 c4iw_get_qpid(struct c4iw_rdev *rdev, struct c4iw_dev_ucontext *uctx);
  706. void c4iw_put_qpid(struct c4iw_rdev *rdev, u32 qid,
  707. struct c4iw_dev_ucontext *uctx);
  708. void c4iw_ev_dispatch(struct c4iw_dev *dev, struct t4_cqe *err_cqe);
  709. extern struct cxgb4_client t4c_client;
  710. extern c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS];
  711. extern int c4iw_max_read_depth;
  712. #endif