iw_cxgb4.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  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_stat {
  92. u64 total;
  93. u64 cur;
  94. u64 max;
  95. };
  96. struct c4iw_stats {
  97. struct mutex lock;
  98. struct c4iw_stat qid;
  99. struct c4iw_stat pd;
  100. struct c4iw_stat stag;
  101. struct c4iw_stat pbl;
  102. struct c4iw_stat rqt;
  103. struct c4iw_stat ocqp;
  104. u64 db_full;
  105. u64 db_empty;
  106. u64 db_drop;
  107. };
  108. struct c4iw_rdev {
  109. struct c4iw_resource resource;
  110. unsigned long qpshift;
  111. u32 qpmask;
  112. unsigned long cqshift;
  113. u32 cqmask;
  114. struct c4iw_dev_ucontext uctx;
  115. struct gen_pool *pbl_pool;
  116. struct gen_pool *rqt_pool;
  117. struct gen_pool *ocqp_pool;
  118. u32 flags;
  119. struct cxgb4_lld_info lldi;
  120. unsigned long oc_mw_pa;
  121. void __iomem *oc_mw_kva;
  122. struct c4iw_stats stats;
  123. };
  124. static inline int c4iw_fatal_error(struct c4iw_rdev *rdev)
  125. {
  126. return rdev->flags & T4_FATAL_ERROR;
  127. }
  128. static inline int c4iw_num_stags(struct c4iw_rdev *rdev)
  129. {
  130. return min((int)T4_MAX_NUM_STAG, (int)(rdev->lldi.vr->stag.size >> 5));
  131. }
  132. #define C4IW_WR_TO (10*HZ)
  133. struct c4iw_wr_wait {
  134. struct completion completion;
  135. int ret;
  136. };
  137. static inline void c4iw_init_wr_wait(struct c4iw_wr_wait *wr_waitp)
  138. {
  139. wr_waitp->ret = 0;
  140. init_completion(&wr_waitp->completion);
  141. }
  142. static inline void c4iw_wake_up(struct c4iw_wr_wait *wr_waitp, int ret)
  143. {
  144. wr_waitp->ret = ret;
  145. complete(&wr_waitp->completion);
  146. }
  147. static inline int c4iw_wait_for_reply(struct c4iw_rdev *rdev,
  148. struct c4iw_wr_wait *wr_waitp,
  149. u32 hwtid, u32 qpid,
  150. const char *func)
  151. {
  152. unsigned to = C4IW_WR_TO;
  153. int ret;
  154. do {
  155. ret = wait_for_completion_timeout(&wr_waitp->completion, to);
  156. if (!ret) {
  157. printk(KERN_ERR MOD "%s - Device %s not responding - "
  158. "tid %u qpid %u\n", func,
  159. pci_name(rdev->lldi.pdev), hwtid, qpid);
  160. if (c4iw_fatal_error(rdev)) {
  161. wr_waitp->ret = -EIO;
  162. break;
  163. }
  164. to = to << 2;
  165. }
  166. } while (!ret);
  167. if (wr_waitp->ret)
  168. PDBG("%s: FW reply %d tid %u qpid %u\n",
  169. pci_name(rdev->lldi.pdev), wr_waitp->ret, hwtid, qpid);
  170. return wr_waitp->ret;
  171. }
  172. enum db_state {
  173. NORMAL = 0,
  174. FLOW_CONTROL = 1,
  175. RECOVERY = 2
  176. };
  177. struct c4iw_dev {
  178. struct ib_device ibdev;
  179. struct c4iw_rdev rdev;
  180. u32 device_cap_flags;
  181. struct idr cqidr;
  182. struct idr qpidr;
  183. struct idr mmidr;
  184. spinlock_t lock;
  185. struct mutex db_mutex;
  186. struct dentry *debugfs_root;
  187. enum db_state db_state;
  188. };
  189. static inline struct c4iw_dev *to_c4iw_dev(struct ib_device *ibdev)
  190. {
  191. return container_of(ibdev, struct c4iw_dev, ibdev);
  192. }
  193. static inline struct c4iw_dev *rdev_to_c4iw_dev(struct c4iw_rdev *rdev)
  194. {
  195. return container_of(rdev, struct c4iw_dev, rdev);
  196. }
  197. static inline struct c4iw_cq *get_chp(struct c4iw_dev *rhp, u32 cqid)
  198. {
  199. return idr_find(&rhp->cqidr, cqid);
  200. }
  201. static inline struct c4iw_qp *get_qhp(struct c4iw_dev *rhp, u32 qpid)
  202. {
  203. return idr_find(&rhp->qpidr, qpid);
  204. }
  205. static inline struct c4iw_mr *get_mhp(struct c4iw_dev *rhp, u32 mmid)
  206. {
  207. return idr_find(&rhp->mmidr, mmid);
  208. }
  209. static inline int _insert_handle(struct c4iw_dev *rhp, struct idr *idr,
  210. void *handle, u32 id, int lock)
  211. {
  212. int ret;
  213. int newid;
  214. do {
  215. if (!idr_pre_get(idr, lock ? GFP_KERNEL : GFP_ATOMIC))
  216. return -ENOMEM;
  217. if (lock)
  218. spin_lock_irq(&rhp->lock);
  219. ret = idr_get_new_above(idr, handle, id, &newid);
  220. BUG_ON(newid != id);
  221. if (lock)
  222. spin_unlock_irq(&rhp->lock);
  223. } while (ret == -EAGAIN);
  224. return ret;
  225. }
  226. static inline int insert_handle(struct c4iw_dev *rhp, struct idr *idr,
  227. void *handle, u32 id)
  228. {
  229. return _insert_handle(rhp, idr, handle, id, 1);
  230. }
  231. static inline int insert_handle_nolock(struct c4iw_dev *rhp, struct idr *idr,
  232. void *handle, u32 id)
  233. {
  234. return _insert_handle(rhp, idr, handle, id, 0);
  235. }
  236. static inline void remove_handle(struct c4iw_dev *rhp, struct idr *idr, u32 id)
  237. {
  238. spin_lock_irq(&rhp->lock);
  239. idr_remove(idr, id);
  240. spin_unlock_irq(&rhp->lock);
  241. }
  242. struct c4iw_pd {
  243. struct ib_pd ibpd;
  244. u32 pdid;
  245. struct c4iw_dev *rhp;
  246. };
  247. static inline struct c4iw_pd *to_c4iw_pd(struct ib_pd *ibpd)
  248. {
  249. return container_of(ibpd, struct c4iw_pd, ibpd);
  250. }
  251. struct tpt_attributes {
  252. u64 len;
  253. u64 va_fbo;
  254. enum fw_ri_mem_perms perms;
  255. u32 stag;
  256. u32 pdid;
  257. u32 qpid;
  258. u32 pbl_addr;
  259. u32 pbl_size;
  260. u32 state:1;
  261. u32 type:2;
  262. u32 rsvd:1;
  263. u32 remote_invaliate_disable:1;
  264. u32 zbva:1;
  265. u32 mw_bind_enable:1;
  266. u32 page_size:5;
  267. };
  268. struct c4iw_mr {
  269. struct ib_mr ibmr;
  270. struct ib_umem *umem;
  271. struct c4iw_dev *rhp;
  272. u64 kva;
  273. struct tpt_attributes attr;
  274. };
  275. static inline struct c4iw_mr *to_c4iw_mr(struct ib_mr *ibmr)
  276. {
  277. return container_of(ibmr, struct c4iw_mr, ibmr);
  278. }
  279. struct c4iw_mw {
  280. struct ib_mw ibmw;
  281. struct c4iw_dev *rhp;
  282. u64 kva;
  283. struct tpt_attributes attr;
  284. };
  285. static inline struct c4iw_mw *to_c4iw_mw(struct ib_mw *ibmw)
  286. {
  287. return container_of(ibmw, struct c4iw_mw, ibmw);
  288. }
  289. struct c4iw_fr_page_list {
  290. struct ib_fast_reg_page_list ibpl;
  291. DEFINE_DMA_UNMAP_ADDR(mapping);
  292. dma_addr_t dma_addr;
  293. struct c4iw_dev *dev;
  294. int size;
  295. };
  296. static inline struct c4iw_fr_page_list *to_c4iw_fr_page_list(
  297. struct ib_fast_reg_page_list *ibpl)
  298. {
  299. return container_of(ibpl, struct c4iw_fr_page_list, ibpl);
  300. }
  301. struct c4iw_cq {
  302. struct ib_cq ibcq;
  303. struct c4iw_dev *rhp;
  304. struct t4_cq cq;
  305. spinlock_t lock;
  306. spinlock_t comp_handler_lock;
  307. atomic_t refcnt;
  308. wait_queue_head_t wait;
  309. };
  310. static inline struct c4iw_cq *to_c4iw_cq(struct ib_cq *ibcq)
  311. {
  312. return container_of(ibcq, struct c4iw_cq, ibcq);
  313. }
  314. struct c4iw_mpa_attributes {
  315. u8 initiator;
  316. u8 recv_marker_enabled;
  317. u8 xmit_marker_enabled;
  318. u8 crc_enabled;
  319. u8 enhanced_rdma_conn;
  320. u8 version;
  321. u8 p2p_type;
  322. };
  323. struct c4iw_qp_attributes {
  324. u32 scq;
  325. u32 rcq;
  326. u32 sq_num_entries;
  327. u32 rq_num_entries;
  328. u32 sq_max_sges;
  329. u32 sq_max_sges_rdma_write;
  330. u32 rq_max_sges;
  331. u32 state;
  332. u8 enable_rdma_read;
  333. u8 enable_rdma_write;
  334. u8 enable_bind;
  335. u8 enable_mmid0_fastreg;
  336. u32 max_ord;
  337. u32 max_ird;
  338. u32 pd;
  339. u32 next_state;
  340. char terminate_buffer[52];
  341. u32 terminate_msg_len;
  342. u8 is_terminate_local;
  343. struct c4iw_mpa_attributes mpa_attr;
  344. struct c4iw_ep *llp_stream_handle;
  345. u8 layer_etype;
  346. u8 ecode;
  347. u16 sq_db_inc;
  348. u16 rq_db_inc;
  349. };
  350. struct c4iw_qp {
  351. struct ib_qp ibqp;
  352. struct c4iw_dev *rhp;
  353. struct c4iw_ep *ep;
  354. struct c4iw_qp_attributes attr;
  355. struct t4_wq wq;
  356. spinlock_t lock;
  357. struct mutex mutex;
  358. atomic_t refcnt;
  359. wait_queue_head_t wait;
  360. struct timer_list timer;
  361. };
  362. static inline struct c4iw_qp *to_c4iw_qp(struct ib_qp *ibqp)
  363. {
  364. return container_of(ibqp, struct c4iw_qp, ibqp);
  365. }
  366. struct c4iw_ucontext {
  367. struct ib_ucontext ibucontext;
  368. struct c4iw_dev_ucontext uctx;
  369. u32 key;
  370. spinlock_t mmap_lock;
  371. struct list_head mmaps;
  372. };
  373. static inline struct c4iw_ucontext *to_c4iw_ucontext(struct ib_ucontext *c)
  374. {
  375. return container_of(c, struct c4iw_ucontext, ibucontext);
  376. }
  377. struct c4iw_mm_entry {
  378. struct list_head entry;
  379. u64 addr;
  380. u32 key;
  381. unsigned len;
  382. };
  383. static inline struct c4iw_mm_entry *remove_mmap(struct c4iw_ucontext *ucontext,
  384. u32 key, unsigned len)
  385. {
  386. struct list_head *pos, *nxt;
  387. struct c4iw_mm_entry *mm;
  388. spin_lock(&ucontext->mmap_lock);
  389. list_for_each_safe(pos, nxt, &ucontext->mmaps) {
  390. mm = list_entry(pos, struct c4iw_mm_entry, entry);
  391. if (mm->key == key && mm->len == len) {
  392. list_del_init(&mm->entry);
  393. spin_unlock(&ucontext->mmap_lock);
  394. PDBG("%s key 0x%x addr 0x%llx len %d\n", __func__,
  395. key, (unsigned long long) mm->addr, mm->len);
  396. return mm;
  397. }
  398. }
  399. spin_unlock(&ucontext->mmap_lock);
  400. return NULL;
  401. }
  402. static inline void insert_mmap(struct c4iw_ucontext *ucontext,
  403. struct c4iw_mm_entry *mm)
  404. {
  405. spin_lock(&ucontext->mmap_lock);
  406. PDBG("%s key 0x%x addr 0x%llx len %d\n", __func__,
  407. mm->key, (unsigned long long) mm->addr, mm->len);
  408. list_add_tail(&mm->entry, &ucontext->mmaps);
  409. spin_unlock(&ucontext->mmap_lock);
  410. }
  411. enum c4iw_qp_attr_mask {
  412. C4IW_QP_ATTR_NEXT_STATE = 1 << 0,
  413. C4IW_QP_ATTR_SQ_DB = 1<<1,
  414. C4IW_QP_ATTR_RQ_DB = 1<<2,
  415. C4IW_QP_ATTR_ENABLE_RDMA_READ = 1 << 7,
  416. C4IW_QP_ATTR_ENABLE_RDMA_WRITE = 1 << 8,
  417. C4IW_QP_ATTR_ENABLE_RDMA_BIND = 1 << 9,
  418. C4IW_QP_ATTR_MAX_ORD = 1 << 11,
  419. C4IW_QP_ATTR_MAX_IRD = 1 << 12,
  420. C4IW_QP_ATTR_LLP_STREAM_HANDLE = 1 << 22,
  421. C4IW_QP_ATTR_STREAM_MSG_BUFFER = 1 << 23,
  422. C4IW_QP_ATTR_MPA_ATTR = 1 << 24,
  423. C4IW_QP_ATTR_QP_CONTEXT_ACTIVATE = 1 << 25,
  424. C4IW_QP_ATTR_VALID_MODIFY = (C4IW_QP_ATTR_ENABLE_RDMA_READ |
  425. C4IW_QP_ATTR_ENABLE_RDMA_WRITE |
  426. C4IW_QP_ATTR_MAX_ORD |
  427. C4IW_QP_ATTR_MAX_IRD |
  428. C4IW_QP_ATTR_LLP_STREAM_HANDLE |
  429. C4IW_QP_ATTR_STREAM_MSG_BUFFER |
  430. C4IW_QP_ATTR_MPA_ATTR |
  431. C4IW_QP_ATTR_QP_CONTEXT_ACTIVATE)
  432. };
  433. int c4iw_modify_qp(struct c4iw_dev *rhp,
  434. struct c4iw_qp *qhp,
  435. enum c4iw_qp_attr_mask mask,
  436. struct c4iw_qp_attributes *attrs,
  437. int internal);
  438. enum c4iw_qp_state {
  439. C4IW_QP_STATE_IDLE,
  440. C4IW_QP_STATE_RTS,
  441. C4IW_QP_STATE_ERROR,
  442. C4IW_QP_STATE_TERMINATE,
  443. C4IW_QP_STATE_CLOSING,
  444. C4IW_QP_STATE_TOT
  445. };
  446. static inline int c4iw_convert_state(enum ib_qp_state ib_state)
  447. {
  448. switch (ib_state) {
  449. case IB_QPS_RESET:
  450. case IB_QPS_INIT:
  451. return C4IW_QP_STATE_IDLE;
  452. case IB_QPS_RTS:
  453. return C4IW_QP_STATE_RTS;
  454. case IB_QPS_SQD:
  455. return C4IW_QP_STATE_CLOSING;
  456. case IB_QPS_SQE:
  457. return C4IW_QP_STATE_TERMINATE;
  458. case IB_QPS_ERR:
  459. return C4IW_QP_STATE_ERROR;
  460. default:
  461. return -1;
  462. }
  463. }
  464. static inline u32 c4iw_ib_to_tpt_access(int a)
  465. {
  466. return (a & IB_ACCESS_REMOTE_WRITE ? FW_RI_MEM_ACCESS_REM_WRITE : 0) |
  467. (a & IB_ACCESS_REMOTE_READ ? FW_RI_MEM_ACCESS_REM_READ : 0) |
  468. (a & IB_ACCESS_LOCAL_WRITE ? FW_RI_MEM_ACCESS_LOCAL_WRITE : 0) |
  469. FW_RI_MEM_ACCESS_LOCAL_READ;
  470. }
  471. static inline u32 c4iw_ib_to_tpt_bind_access(int acc)
  472. {
  473. return (acc & IB_ACCESS_REMOTE_WRITE ? FW_RI_MEM_ACCESS_REM_WRITE : 0) |
  474. (acc & IB_ACCESS_REMOTE_READ ? FW_RI_MEM_ACCESS_REM_READ : 0);
  475. }
  476. enum c4iw_mmid_state {
  477. C4IW_STAG_STATE_VALID,
  478. C4IW_STAG_STATE_INVALID
  479. };
  480. #define C4IW_NODE_DESC "cxgb4 Chelsio Communications"
  481. #define MPA_KEY_REQ "MPA ID Req Frame"
  482. #define MPA_KEY_REP "MPA ID Rep Frame"
  483. #define MPA_MAX_PRIVATE_DATA 256
  484. #define MPA_ENHANCED_RDMA_CONN 0x10
  485. #define MPA_REJECT 0x20
  486. #define MPA_CRC 0x40
  487. #define MPA_MARKERS 0x80
  488. #define MPA_FLAGS_MASK 0xE0
  489. #define MPA_V2_PEER2PEER_MODEL 0x8000
  490. #define MPA_V2_ZERO_LEN_FPDU_RTR 0x4000
  491. #define MPA_V2_RDMA_WRITE_RTR 0x8000
  492. #define MPA_V2_RDMA_READ_RTR 0x4000
  493. #define MPA_V2_IRD_ORD_MASK 0x3FFF
  494. #define c4iw_put_ep(ep) { \
  495. PDBG("put_ep (via %s:%u) ep %p refcnt %d\n", __func__, __LINE__, \
  496. ep, atomic_read(&((ep)->kref.refcount))); \
  497. WARN_ON(atomic_read(&((ep)->kref.refcount)) < 1); \
  498. kref_put(&((ep)->kref), _c4iw_free_ep); \
  499. }
  500. #define c4iw_get_ep(ep) { \
  501. PDBG("get_ep (via %s:%u) ep %p, refcnt %d\n", __func__, __LINE__, \
  502. ep, atomic_read(&((ep)->kref.refcount))); \
  503. kref_get(&((ep)->kref)); \
  504. }
  505. void _c4iw_free_ep(struct kref *kref);
  506. struct mpa_message {
  507. u8 key[16];
  508. u8 flags;
  509. u8 revision;
  510. __be16 private_data_size;
  511. u8 private_data[0];
  512. };
  513. struct mpa_v2_conn_params {
  514. __be16 ird;
  515. __be16 ord;
  516. };
  517. struct terminate_message {
  518. u8 layer_etype;
  519. u8 ecode;
  520. __be16 hdrct_rsvd;
  521. u8 len_hdrs[0];
  522. };
  523. #define TERM_MAX_LENGTH (sizeof(struct terminate_message) + 2 + 18 + 28)
  524. enum c4iw_layers_types {
  525. LAYER_RDMAP = 0x00,
  526. LAYER_DDP = 0x10,
  527. LAYER_MPA = 0x20,
  528. RDMAP_LOCAL_CATA = 0x00,
  529. RDMAP_REMOTE_PROT = 0x01,
  530. RDMAP_REMOTE_OP = 0x02,
  531. DDP_LOCAL_CATA = 0x00,
  532. DDP_TAGGED_ERR = 0x01,
  533. DDP_UNTAGGED_ERR = 0x02,
  534. DDP_LLP = 0x03
  535. };
  536. enum c4iw_rdma_ecodes {
  537. RDMAP_INV_STAG = 0x00,
  538. RDMAP_BASE_BOUNDS = 0x01,
  539. RDMAP_ACC_VIOL = 0x02,
  540. RDMAP_STAG_NOT_ASSOC = 0x03,
  541. RDMAP_TO_WRAP = 0x04,
  542. RDMAP_INV_VERS = 0x05,
  543. RDMAP_INV_OPCODE = 0x06,
  544. RDMAP_STREAM_CATA = 0x07,
  545. RDMAP_GLOBAL_CATA = 0x08,
  546. RDMAP_CANT_INV_STAG = 0x09,
  547. RDMAP_UNSPECIFIED = 0xff
  548. };
  549. enum c4iw_ddp_ecodes {
  550. DDPT_INV_STAG = 0x00,
  551. DDPT_BASE_BOUNDS = 0x01,
  552. DDPT_STAG_NOT_ASSOC = 0x02,
  553. DDPT_TO_WRAP = 0x03,
  554. DDPT_INV_VERS = 0x04,
  555. DDPU_INV_QN = 0x01,
  556. DDPU_INV_MSN_NOBUF = 0x02,
  557. DDPU_INV_MSN_RANGE = 0x03,
  558. DDPU_INV_MO = 0x04,
  559. DDPU_MSG_TOOBIG = 0x05,
  560. DDPU_INV_VERS = 0x06
  561. };
  562. enum c4iw_mpa_ecodes {
  563. MPA_CRC_ERR = 0x02,
  564. MPA_MARKER_ERR = 0x03,
  565. MPA_LOCAL_CATA = 0x05,
  566. MPA_INSUFF_IRD = 0x06,
  567. MPA_NOMATCH_RTR = 0x07,
  568. };
  569. enum c4iw_ep_state {
  570. IDLE = 0,
  571. LISTEN,
  572. CONNECTING,
  573. MPA_REQ_WAIT,
  574. MPA_REQ_SENT,
  575. MPA_REQ_RCVD,
  576. MPA_REP_SENT,
  577. FPDU_MODE,
  578. ABORTING,
  579. CLOSING,
  580. MORIBUND,
  581. DEAD,
  582. };
  583. enum c4iw_ep_flags {
  584. PEER_ABORT_IN_PROGRESS = 0,
  585. ABORT_REQ_IN_PROGRESS = 1,
  586. RELEASE_RESOURCES = 2,
  587. CLOSE_SENT = 3,
  588. };
  589. struct c4iw_ep_common {
  590. struct iw_cm_id *cm_id;
  591. struct c4iw_qp *qp;
  592. struct c4iw_dev *dev;
  593. enum c4iw_ep_state state;
  594. struct kref kref;
  595. struct mutex mutex;
  596. struct sockaddr_in local_addr;
  597. struct sockaddr_in remote_addr;
  598. struct c4iw_wr_wait wr_wait;
  599. unsigned long flags;
  600. };
  601. struct c4iw_listen_ep {
  602. struct c4iw_ep_common com;
  603. unsigned int stid;
  604. int backlog;
  605. };
  606. struct c4iw_ep {
  607. struct c4iw_ep_common com;
  608. struct c4iw_ep *parent_ep;
  609. struct timer_list timer;
  610. struct list_head entry;
  611. unsigned int atid;
  612. u32 hwtid;
  613. u32 snd_seq;
  614. u32 rcv_seq;
  615. struct l2t_entry *l2t;
  616. struct dst_entry *dst;
  617. struct sk_buff *mpa_skb;
  618. struct c4iw_mpa_attributes mpa_attr;
  619. u8 mpa_pkt[sizeof(struct mpa_message) + MPA_MAX_PRIVATE_DATA];
  620. unsigned int mpa_pkt_len;
  621. u32 ird;
  622. u32 ord;
  623. u32 smac_idx;
  624. u32 tx_chan;
  625. u32 mtu;
  626. u16 mss;
  627. u16 emss;
  628. u16 plen;
  629. u16 rss_qid;
  630. u16 txq_idx;
  631. u16 ctrlq_idx;
  632. u8 tos;
  633. u8 retry_with_mpa_v1;
  634. u8 tried_with_mpa_v1;
  635. };
  636. static inline struct c4iw_ep *to_ep(struct iw_cm_id *cm_id)
  637. {
  638. return cm_id->provider_data;
  639. }
  640. static inline struct c4iw_listen_ep *to_listen_ep(struct iw_cm_id *cm_id)
  641. {
  642. return cm_id->provider_data;
  643. }
  644. static inline int compute_wscale(int win)
  645. {
  646. int wscale = 0;
  647. while (wscale < 14 && (65535<<wscale) < win)
  648. wscale++;
  649. return wscale;
  650. }
  651. typedef int (*c4iw_handler_func)(struct c4iw_dev *dev, struct sk_buff *skb);
  652. int c4iw_ep_redirect(void *ctx, struct dst_entry *old, struct dst_entry *new,
  653. struct l2t_entry *l2t);
  654. void c4iw_put_qpid(struct c4iw_rdev *rdev, u32 qpid,
  655. struct c4iw_dev_ucontext *uctx);
  656. u32 c4iw_get_resource(struct kfifo *fifo, spinlock_t *lock);
  657. void c4iw_put_resource(struct kfifo *fifo, u32 entry, spinlock_t *lock);
  658. int c4iw_init_resource(struct c4iw_rdev *rdev, u32 nr_tpt, u32 nr_pdid);
  659. int c4iw_init_ctrl_qp(struct c4iw_rdev *rdev);
  660. int c4iw_pblpool_create(struct c4iw_rdev *rdev);
  661. int c4iw_rqtpool_create(struct c4iw_rdev *rdev);
  662. int c4iw_ocqp_pool_create(struct c4iw_rdev *rdev);
  663. void c4iw_pblpool_destroy(struct c4iw_rdev *rdev);
  664. void c4iw_rqtpool_destroy(struct c4iw_rdev *rdev);
  665. void c4iw_ocqp_pool_destroy(struct c4iw_rdev *rdev);
  666. void c4iw_destroy_resource(struct c4iw_resource *rscp);
  667. int c4iw_destroy_ctrl_qp(struct c4iw_rdev *rdev);
  668. int c4iw_register_device(struct c4iw_dev *dev);
  669. void c4iw_unregister_device(struct c4iw_dev *dev);
  670. int __init c4iw_cm_init(void);
  671. void __exit c4iw_cm_term(void);
  672. void c4iw_release_dev_ucontext(struct c4iw_rdev *rdev,
  673. struct c4iw_dev_ucontext *uctx);
  674. void c4iw_init_dev_ucontext(struct c4iw_rdev *rdev,
  675. struct c4iw_dev_ucontext *uctx);
  676. int c4iw_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
  677. int c4iw_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
  678. struct ib_send_wr **bad_wr);
  679. int c4iw_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
  680. struct ib_recv_wr **bad_wr);
  681. int c4iw_bind_mw(struct ib_qp *qp, struct ib_mw *mw,
  682. struct ib_mw_bind *mw_bind);
  683. int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param);
  684. int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog);
  685. int c4iw_destroy_listen(struct iw_cm_id *cm_id);
  686. int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param);
  687. int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len);
  688. void c4iw_qp_add_ref(struct ib_qp *qp);
  689. void c4iw_qp_rem_ref(struct ib_qp *qp);
  690. void c4iw_free_fastreg_pbl(struct ib_fast_reg_page_list *page_list);
  691. struct ib_fast_reg_page_list *c4iw_alloc_fastreg_pbl(
  692. struct ib_device *device,
  693. int page_list_len);
  694. struct ib_mr *c4iw_alloc_fast_reg_mr(struct ib_pd *pd, int pbl_depth);
  695. int c4iw_dealloc_mw(struct ib_mw *mw);
  696. struct ib_mw *c4iw_alloc_mw(struct ib_pd *pd);
  697. struct ib_mr *c4iw_reg_user_mr(struct ib_pd *pd, u64 start,
  698. u64 length, u64 virt, int acc,
  699. struct ib_udata *udata);
  700. struct ib_mr *c4iw_get_dma_mr(struct ib_pd *pd, int acc);
  701. struct ib_mr *c4iw_register_phys_mem(struct ib_pd *pd,
  702. struct ib_phys_buf *buffer_list,
  703. int num_phys_buf,
  704. int acc,
  705. u64 *iova_start);
  706. int c4iw_reregister_phys_mem(struct ib_mr *mr,
  707. int mr_rereg_mask,
  708. struct ib_pd *pd,
  709. struct ib_phys_buf *buffer_list,
  710. int num_phys_buf,
  711. int acc, u64 *iova_start);
  712. int c4iw_dereg_mr(struct ib_mr *ib_mr);
  713. int c4iw_destroy_cq(struct ib_cq *ib_cq);
  714. struct ib_cq *c4iw_create_cq(struct ib_device *ibdev, int entries,
  715. int vector,
  716. struct ib_ucontext *ib_context,
  717. struct ib_udata *udata);
  718. int c4iw_resize_cq(struct ib_cq *cq, int cqe, struct ib_udata *udata);
  719. int c4iw_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags);
  720. int c4iw_destroy_qp(struct ib_qp *ib_qp);
  721. struct ib_qp *c4iw_create_qp(struct ib_pd *pd,
  722. struct ib_qp_init_attr *attrs,
  723. struct ib_udata *udata);
  724. int c4iw_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
  725. int attr_mask, struct ib_udata *udata);
  726. struct ib_qp *c4iw_get_qp(struct ib_device *dev, int qpn);
  727. u32 c4iw_rqtpool_alloc(struct c4iw_rdev *rdev, int size);
  728. void c4iw_rqtpool_free(struct c4iw_rdev *rdev, u32 addr, int size);
  729. u32 c4iw_pblpool_alloc(struct c4iw_rdev *rdev, int size);
  730. void c4iw_pblpool_free(struct c4iw_rdev *rdev, u32 addr, int size);
  731. u32 c4iw_ocqp_pool_alloc(struct c4iw_rdev *rdev, int size);
  732. void c4iw_ocqp_pool_free(struct c4iw_rdev *rdev, u32 addr, int size);
  733. int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb);
  734. void c4iw_flush_hw_cq(struct t4_cq *cq);
  735. void c4iw_count_rcqes(struct t4_cq *cq, struct t4_wq *wq, int *count);
  736. void c4iw_count_scqes(struct t4_cq *cq, struct t4_wq *wq, int *count);
  737. int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp);
  738. int c4iw_flush_rq(struct t4_wq *wq, struct t4_cq *cq, int count);
  739. int c4iw_flush_sq(struct t4_wq *wq, struct t4_cq *cq, int count);
  740. int c4iw_ev_handler(struct c4iw_dev *rnicp, u32 qid);
  741. u16 c4iw_rqes_posted(struct c4iw_qp *qhp);
  742. int c4iw_post_terminate(struct c4iw_qp *qhp, struct t4_cqe *err_cqe);
  743. u32 c4iw_get_cqid(struct c4iw_rdev *rdev, struct c4iw_dev_ucontext *uctx);
  744. void c4iw_put_cqid(struct c4iw_rdev *rdev, u32 qid,
  745. struct c4iw_dev_ucontext *uctx);
  746. u32 c4iw_get_qpid(struct c4iw_rdev *rdev, struct c4iw_dev_ucontext *uctx);
  747. void c4iw_put_qpid(struct c4iw_rdev *rdev, u32 qid,
  748. struct c4iw_dev_ucontext *uctx);
  749. void c4iw_ev_dispatch(struct c4iw_dev *dev, struct t4_cqe *err_cqe);
  750. extern struct cxgb4_client t4c_client;
  751. extern c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS];
  752. extern int c4iw_max_read_depth;
  753. #endif