iw_cxgb4.h 23 KB

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