iw_cxgb4.h 23 KB

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