iw_cxgb4.h 23 KB

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