iw_cxgb4.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945
  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 (30*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. };
  321. static inline struct c4iw_fr_page_list *to_c4iw_fr_page_list(
  322. struct ib_fast_reg_page_list *ibpl)
  323. {
  324. return container_of(ibpl, struct c4iw_fr_page_list, ibpl);
  325. }
  326. struct c4iw_cq {
  327. struct ib_cq ibcq;
  328. struct c4iw_dev *rhp;
  329. struct t4_cq cq;
  330. spinlock_t lock;
  331. spinlock_t comp_handler_lock;
  332. atomic_t refcnt;
  333. wait_queue_head_t wait;
  334. };
  335. static inline struct c4iw_cq *to_c4iw_cq(struct ib_cq *ibcq)
  336. {
  337. return container_of(ibcq, struct c4iw_cq, ibcq);
  338. }
  339. struct c4iw_mpa_attributes {
  340. u8 initiator;
  341. u8 recv_marker_enabled;
  342. u8 xmit_marker_enabled;
  343. u8 crc_enabled;
  344. u8 enhanced_rdma_conn;
  345. u8 version;
  346. u8 p2p_type;
  347. };
  348. struct c4iw_qp_attributes {
  349. u32 scq;
  350. u32 rcq;
  351. u32 sq_num_entries;
  352. u32 rq_num_entries;
  353. u32 sq_max_sges;
  354. u32 sq_max_sges_rdma_write;
  355. u32 rq_max_sges;
  356. u32 state;
  357. u8 enable_rdma_read;
  358. u8 enable_rdma_write;
  359. u8 enable_bind;
  360. u8 enable_mmid0_fastreg;
  361. u32 max_ord;
  362. u32 max_ird;
  363. u32 pd;
  364. u32 next_state;
  365. char terminate_buffer[52];
  366. u32 terminate_msg_len;
  367. u8 is_terminate_local;
  368. struct c4iw_mpa_attributes mpa_attr;
  369. struct c4iw_ep *llp_stream_handle;
  370. u8 layer_etype;
  371. u8 ecode;
  372. u16 sq_db_inc;
  373. u16 rq_db_inc;
  374. };
  375. struct c4iw_qp {
  376. struct ib_qp ibqp;
  377. struct c4iw_dev *rhp;
  378. struct c4iw_ep *ep;
  379. struct c4iw_qp_attributes attr;
  380. struct t4_wq wq;
  381. spinlock_t lock;
  382. struct mutex mutex;
  383. atomic_t refcnt;
  384. wait_queue_head_t wait;
  385. struct timer_list timer;
  386. };
  387. static inline struct c4iw_qp *to_c4iw_qp(struct ib_qp *ibqp)
  388. {
  389. return container_of(ibqp, struct c4iw_qp, ibqp);
  390. }
  391. struct c4iw_ucontext {
  392. struct ib_ucontext ibucontext;
  393. struct c4iw_dev_ucontext uctx;
  394. u32 key;
  395. spinlock_t mmap_lock;
  396. struct list_head mmaps;
  397. };
  398. static inline struct c4iw_ucontext *to_c4iw_ucontext(struct ib_ucontext *c)
  399. {
  400. return container_of(c, struct c4iw_ucontext, ibucontext);
  401. }
  402. struct c4iw_mm_entry {
  403. struct list_head entry;
  404. u64 addr;
  405. u32 key;
  406. unsigned len;
  407. };
  408. static inline struct c4iw_mm_entry *remove_mmap(struct c4iw_ucontext *ucontext,
  409. u32 key, unsigned len)
  410. {
  411. struct list_head *pos, *nxt;
  412. struct c4iw_mm_entry *mm;
  413. spin_lock(&ucontext->mmap_lock);
  414. list_for_each_safe(pos, nxt, &ucontext->mmaps) {
  415. mm = list_entry(pos, struct c4iw_mm_entry, entry);
  416. if (mm->key == key && mm->len == len) {
  417. list_del_init(&mm->entry);
  418. spin_unlock(&ucontext->mmap_lock);
  419. PDBG("%s key 0x%x addr 0x%llx len %d\n", __func__,
  420. key, (unsigned long long) mm->addr, mm->len);
  421. return mm;
  422. }
  423. }
  424. spin_unlock(&ucontext->mmap_lock);
  425. return NULL;
  426. }
  427. static inline void insert_mmap(struct c4iw_ucontext *ucontext,
  428. struct c4iw_mm_entry *mm)
  429. {
  430. spin_lock(&ucontext->mmap_lock);
  431. PDBG("%s key 0x%x addr 0x%llx len %d\n", __func__,
  432. mm->key, (unsigned long long) mm->addr, mm->len);
  433. list_add_tail(&mm->entry, &ucontext->mmaps);
  434. spin_unlock(&ucontext->mmap_lock);
  435. }
  436. enum c4iw_qp_attr_mask {
  437. C4IW_QP_ATTR_NEXT_STATE = 1 << 0,
  438. C4IW_QP_ATTR_SQ_DB = 1<<1,
  439. C4IW_QP_ATTR_RQ_DB = 1<<2,
  440. C4IW_QP_ATTR_ENABLE_RDMA_READ = 1 << 7,
  441. C4IW_QP_ATTR_ENABLE_RDMA_WRITE = 1 << 8,
  442. C4IW_QP_ATTR_ENABLE_RDMA_BIND = 1 << 9,
  443. C4IW_QP_ATTR_MAX_ORD = 1 << 11,
  444. C4IW_QP_ATTR_MAX_IRD = 1 << 12,
  445. C4IW_QP_ATTR_LLP_STREAM_HANDLE = 1 << 22,
  446. C4IW_QP_ATTR_STREAM_MSG_BUFFER = 1 << 23,
  447. C4IW_QP_ATTR_MPA_ATTR = 1 << 24,
  448. C4IW_QP_ATTR_QP_CONTEXT_ACTIVATE = 1 << 25,
  449. C4IW_QP_ATTR_VALID_MODIFY = (C4IW_QP_ATTR_ENABLE_RDMA_READ |
  450. C4IW_QP_ATTR_ENABLE_RDMA_WRITE |
  451. C4IW_QP_ATTR_MAX_ORD |
  452. C4IW_QP_ATTR_MAX_IRD |
  453. C4IW_QP_ATTR_LLP_STREAM_HANDLE |
  454. C4IW_QP_ATTR_STREAM_MSG_BUFFER |
  455. C4IW_QP_ATTR_MPA_ATTR |
  456. C4IW_QP_ATTR_QP_CONTEXT_ACTIVATE)
  457. };
  458. int c4iw_modify_qp(struct c4iw_dev *rhp,
  459. struct c4iw_qp *qhp,
  460. enum c4iw_qp_attr_mask mask,
  461. struct c4iw_qp_attributes *attrs,
  462. int internal);
  463. enum c4iw_qp_state {
  464. C4IW_QP_STATE_IDLE,
  465. C4IW_QP_STATE_RTS,
  466. C4IW_QP_STATE_ERROR,
  467. C4IW_QP_STATE_TERMINATE,
  468. C4IW_QP_STATE_CLOSING,
  469. C4IW_QP_STATE_TOT
  470. };
  471. static inline int c4iw_convert_state(enum ib_qp_state ib_state)
  472. {
  473. switch (ib_state) {
  474. case IB_QPS_RESET:
  475. case IB_QPS_INIT:
  476. return C4IW_QP_STATE_IDLE;
  477. case IB_QPS_RTS:
  478. return C4IW_QP_STATE_RTS;
  479. case IB_QPS_SQD:
  480. return C4IW_QP_STATE_CLOSING;
  481. case IB_QPS_SQE:
  482. return C4IW_QP_STATE_TERMINATE;
  483. case IB_QPS_ERR:
  484. return C4IW_QP_STATE_ERROR;
  485. default:
  486. return -1;
  487. }
  488. }
  489. static inline int to_ib_qp_state(int c4iw_qp_state)
  490. {
  491. switch (c4iw_qp_state) {
  492. case C4IW_QP_STATE_IDLE:
  493. return IB_QPS_INIT;
  494. case C4IW_QP_STATE_RTS:
  495. return IB_QPS_RTS;
  496. case C4IW_QP_STATE_CLOSING:
  497. return IB_QPS_SQD;
  498. case C4IW_QP_STATE_TERMINATE:
  499. return IB_QPS_SQE;
  500. case C4IW_QP_STATE_ERROR:
  501. return IB_QPS_ERR;
  502. }
  503. return IB_QPS_ERR;
  504. }
  505. static inline u32 c4iw_ib_to_tpt_access(int a)
  506. {
  507. return (a & IB_ACCESS_REMOTE_WRITE ? FW_RI_MEM_ACCESS_REM_WRITE : 0) |
  508. (a & IB_ACCESS_REMOTE_READ ? FW_RI_MEM_ACCESS_REM_READ : 0) |
  509. (a & IB_ACCESS_LOCAL_WRITE ? FW_RI_MEM_ACCESS_LOCAL_WRITE : 0) |
  510. FW_RI_MEM_ACCESS_LOCAL_READ;
  511. }
  512. static inline u32 c4iw_ib_to_tpt_bind_access(int acc)
  513. {
  514. return (acc & IB_ACCESS_REMOTE_WRITE ? FW_RI_MEM_ACCESS_REM_WRITE : 0) |
  515. (acc & IB_ACCESS_REMOTE_READ ? FW_RI_MEM_ACCESS_REM_READ : 0);
  516. }
  517. enum c4iw_mmid_state {
  518. C4IW_STAG_STATE_VALID,
  519. C4IW_STAG_STATE_INVALID
  520. };
  521. #define C4IW_NODE_DESC "cxgb4 Chelsio Communications"
  522. #define MPA_KEY_REQ "MPA ID Req Frame"
  523. #define MPA_KEY_REP "MPA ID Rep Frame"
  524. #define MPA_MAX_PRIVATE_DATA 256
  525. #define MPA_ENHANCED_RDMA_CONN 0x10
  526. #define MPA_REJECT 0x20
  527. #define MPA_CRC 0x40
  528. #define MPA_MARKERS 0x80
  529. #define MPA_FLAGS_MASK 0xE0
  530. #define MPA_V2_PEER2PEER_MODEL 0x8000
  531. #define MPA_V2_ZERO_LEN_FPDU_RTR 0x4000
  532. #define MPA_V2_RDMA_WRITE_RTR 0x8000
  533. #define MPA_V2_RDMA_READ_RTR 0x4000
  534. #define MPA_V2_IRD_ORD_MASK 0x3FFF
  535. #define c4iw_put_ep(ep) { \
  536. PDBG("put_ep (via %s:%u) ep %p refcnt %d\n", __func__, __LINE__, \
  537. ep, atomic_read(&((ep)->kref.refcount))); \
  538. WARN_ON(atomic_read(&((ep)->kref.refcount)) < 1); \
  539. kref_put(&((ep)->kref), _c4iw_free_ep); \
  540. }
  541. #define c4iw_get_ep(ep) { \
  542. PDBG("get_ep (via %s:%u) ep %p, refcnt %d\n", __func__, __LINE__, \
  543. ep, atomic_read(&((ep)->kref.refcount))); \
  544. kref_get(&((ep)->kref)); \
  545. }
  546. void _c4iw_free_ep(struct kref *kref);
  547. struct mpa_message {
  548. u8 key[16];
  549. u8 flags;
  550. u8 revision;
  551. __be16 private_data_size;
  552. u8 private_data[0];
  553. };
  554. struct mpa_v2_conn_params {
  555. __be16 ird;
  556. __be16 ord;
  557. };
  558. struct terminate_message {
  559. u8 layer_etype;
  560. u8 ecode;
  561. __be16 hdrct_rsvd;
  562. u8 len_hdrs[0];
  563. };
  564. #define TERM_MAX_LENGTH (sizeof(struct terminate_message) + 2 + 18 + 28)
  565. enum c4iw_layers_types {
  566. LAYER_RDMAP = 0x00,
  567. LAYER_DDP = 0x10,
  568. LAYER_MPA = 0x20,
  569. RDMAP_LOCAL_CATA = 0x00,
  570. RDMAP_REMOTE_PROT = 0x01,
  571. RDMAP_REMOTE_OP = 0x02,
  572. DDP_LOCAL_CATA = 0x00,
  573. DDP_TAGGED_ERR = 0x01,
  574. DDP_UNTAGGED_ERR = 0x02,
  575. DDP_LLP = 0x03
  576. };
  577. enum c4iw_rdma_ecodes {
  578. RDMAP_INV_STAG = 0x00,
  579. RDMAP_BASE_BOUNDS = 0x01,
  580. RDMAP_ACC_VIOL = 0x02,
  581. RDMAP_STAG_NOT_ASSOC = 0x03,
  582. RDMAP_TO_WRAP = 0x04,
  583. RDMAP_INV_VERS = 0x05,
  584. RDMAP_INV_OPCODE = 0x06,
  585. RDMAP_STREAM_CATA = 0x07,
  586. RDMAP_GLOBAL_CATA = 0x08,
  587. RDMAP_CANT_INV_STAG = 0x09,
  588. RDMAP_UNSPECIFIED = 0xff
  589. };
  590. enum c4iw_ddp_ecodes {
  591. DDPT_INV_STAG = 0x00,
  592. DDPT_BASE_BOUNDS = 0x01,
  593. DDPT_STAG_NOT_ASSOC = 0x02,
  594. DDPT_TO_WRAP = 0x03,
  595. DDPT_INV_VERS = 0x04,
  596. DDPU_INV_QN = 0x01,
  597. DDPU_INV_MSN_NOBUF = 0x02,
  598. DDPU_INV_MSN_RANGE = 0x03,
  599. DDPU_INV_MO = 0x04,
  600. DDPU_MSG_TOOBIG = 0x05,
  601. DDPU_INV_VERS = 0x06
  602. };
  603. enum c4iw_mpa_ecodes {
  604. MPA_CRC_ERR = 0x02,
  605. MPA_MARKER_ERR = 0x03,
  606. MPA_LOCAL_CATA = 0x05,
  607. MPA_INSUFF_IRD = 0x06,
  608. MPA_NOMATCH_RTR = 0x07,
  609. };
  610. enum c4iw_ep_state {
  611. IDLE = 0,
  612. LISTEN,
  613. CONNECTING,
  614. MPA_REQ_WAIT,
  615. MPA_REQ_SENT,
  616. MPA_REQ_RCVD,
  617. MPA_REP_SENT,
  618. FPDU_MODE,
  619. ABORTING,
  620. CLOSING,
  621. MORIBUND,
  622. DEAD,
  623. };
  624. enum c4iw_ep_flags {
  625. PEER_ABORT_IN_PROGRESS = 0,
  626. ABORT_REQ_IN_PROGRESS = 1,
  627. RELEASE_RESOURCES = 2,
  628. CLOSE_SENT = 3,
  629. TIMEOUT = 4,
  630. QP_REFERENCED = 5,
  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. static inline int ocqp_supported(const struct cxgb4_lld_info *infop)
  721. {
  722. #if defined(__i386__) || defined(__x86_64__) || defined(CONFIG_PPC64)
  723. return infop->vr->ocq.size > 0;
  724. #else
  725. return 0;
  726. #endif
  727. }
  728. u32 c4iw_id_alloc(struct c4iw_id_table *alloc);
  729. void c4iw_id_free(struct c4iw_id_table *alloc, u32 obj);
  730. int c4iw_id_table_alloc(struct c4iw_id_table *alloc, u32 start, u32 num,
  731. u32 reserved, u32 flags);
  732. void c4iw_id_table_free(struct c4iw_id_table *alloc);
  733. typedef int (*c4iw_handler_func)(struct c4iw_dev *dev, struct sk_buff *skb);
  734. int c4iw_ep_redirect(void *ctx, struct dst_entry *old, struct dst_entry *new,
  735. struct l2t_entry *l2t);
  736. void c4iw_put_qpid(struct c4iw_rdev *rdev, u32 qpid,
  737. struct c4iw_dev_ucontext *uctx);
  738. u32 c4iw_get_resource(struct c4iw_id_table *id_table);
  739. void c4iw_put_resource(struct c4iw_id_table *id_table, u32 entry);
  740. int c4iw_init_resource(struct c4iw_rdev *rdev, u32 nr_tpt, u32 nr_pdid);
  741. int c4iw_init_ctrl_qp(struct c4iw_rdev *rdev);
  742. int c4iw_pblpool_create(struct c4iw_rdev *rdev);
  743. int c4iw_rqtpool_create(struct c4iw_rdev *rdev);
  744. int c4iw_ocqp_pool_create(struct c4iw_rdev *rdev);
  745. void c4iw_pblpool_destroy(struct c4iw_rdev *rdev);
  746. void c4iw_rqtpool_destroy(struct c4iw_rdev *rdev);
  747. void c4iw_ocqp_pool_destroy(struct c4iw_rdev *rdev);
  748. void c4iw_destroy_resource(struct c4iw_resource *rscp);
  749. int c4iw_destroy_ctrl_qp(struct c4iw_rdev *rdev);
  750. int c4iw_register_device(struct c4iw_dev *dev);
  751. void c4iw_unregister_device(struct c4iw_dev *dev);
  752. int __init c4iw_cm_init(void);
  753. void __exit c4iw_cm_term(void);
  754. void c4iw_release_dev_ucontext(struct c4iw_rdev *rdev,
  755. struct c4iw_dev_ucontext *uctx);
  756. void c4iw_init_dev_ucontext(struct c4iw_rdev *rdev,
  757. struct c4iw_dev_ucontext *uctx);
  758. int c4iw_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
  759. int c4iw_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
  760. struct ib_send_wr **bad_wr);
  761. int c4iw_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
  762. struct ib_recv_wr **bad_wr);
  763. int c4iw_bind_mw(struct ib_qp *qp, struct ib_mw *mw,
  764. struct ib_mw_bind *mw_bind);
  765. int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param);
  766. int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog);
  767. int c4iw_destroy_listen(struct iw_cm_id *cm_id);
  768. int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param);
  769. int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len);
  770. void c4iw_qp_add_ref(struct ib_qp *qp);
  771. void c4iw_qp_rem_ref(struct ib_qp *qp);
  772. void c4iw_free_fastreg_pbl(struct ib_fast_reg_page_list *page_list);
  773. struct ib_fast_reg_page_list *c4iw_alloc_fastreg_pbl(
  774. struct ib_device *device,
  775. int page_list_len);
  776. struct ib_mr *c4iw_alloc_fast_reg_mr(struct ib_pd *pd, int pbl_depth);
  777. int c4iw_dealloc_mw(struct ib_mw *mw);
  778. struct ib_mw *c4iw_alloc_mw(struct ib_pd *pd, enum ib_mw_type type);
  779. struct ib_mr *c4iw_reg_user_mr(struct ib_pd *pd, u64 start,
  780. u64 length, u64 virt, int acc,
  781. struct ib_udata *udata);
  782. struct ib_mr *c4iw_get_dma_mr(struct ib_pd *pd, int acc);
  783. struct ib_mr *c4iw_register_phys_mem(struct ib_pd *pd,
  784. struct ib_phys_buf *buffer_list,
  785. int num_phys_buf,
  786. int acc,
  787. u64 *iova_start);
  788. int c4iw_reregister_phys_mem(struct ib_mr *mr,
  789. int mr_rereg_mask,
  790. struct ib_pd *pd,
  791. struct ib_phys_buf *buffer_list,
  792. int num_phys_buf,
  793. int acc, u64 *iova_start);
  794. int c4iw_dereg_mr(struct ib_mr *ib_mr);
  795. int c4iw_destroy_cq(struct ib_cq *ib_cq);
  796. struct ib_cq *c4iw_create_cq(struct ib_device *ibdev, int entries,
  797. int vector,
  798. struct ib_ucontext *ib_context,
  799. struct ib_udata *udata);
  800. int c4iw_resize_cq(struct ib_cq *cq, int cqe, struct ib_udata *udata);
  801. int c4iw_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags);
  802. int c4iw_destroy_qp(struct ib_qp *ib_qp);
  803. struct ib_qp *c4iw_create_qp(struct ib_pd *pd,
  804. struct ib_qp_init_attr *attrs,
  805. struct ib_udata *udata);
  806. int c4iw_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
  807. int attr_mask, struct ib_udata *udata);
  808. int c4iw_ib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
  809. int attr_mask, struct ib_qp_init_attr *init_attr);
  810. struct ib_qp *c4iw_get_qp(struct ib_device *dev, int qpn);
  811. u32 c4iw_rqtpool_alloc(struct c4iw_rdev *rdev, int size);
  812. void c4iw_rqtpool_free(struct c4iw_rdev *rdev, u32 addr, int size);
  813. u32 c4iw_pblpool_alloc(struct c4iw_rdev *rdev, int size);
  814. void c4iw_pblpool_free(struct c4iw_rdev *rdev, u32 addr, int size);
  815. u32 c4iw_ocqp_pool_alloc(struct c4iw_rdev *rdev, int size);
  816. void c4iw_ocqp_pool_free(struct c4iw_rdev *rdev, u32 addr, int size);
  817. int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb);
  818. void c4iw_flush_hw_cq(struct t4_cq *cq);
  819. void c4iw_count_rcqes(struct t4_cq *cq, struct t4_wq *wq, int *count);
  820. void c4iw_count_scqes(struct t4_cq *cq, struct t4_wq *wq, int *count);
  821. int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp);
  822. int c4iw_flush_rq(struct t4_wq *wq, struct t4_cq *cq, int count);
  823. int c4iw_flush_sq(struct t4_wq *wq, struct t4_cq *cq, int count);
  824. int c4iw_ev_handler(struct c4iw_dev *rnicp, u32 qid);
  825. u16 c4iw_rqes_posted(struct c4iw_qp *qhp);
  826. int c4iw_post_terminate(struct c4iw_qp *qhp, struct t4_cqe *err_cqe);
  827. u32 c4iw_get_cqid(struct c4iw_rdev *rdev, struct c4iw_dev_ucontext *uctx);
  828. void c4iw_put_cqid(struct c4iw_rdev *rdev, u32 qid,
  829. struct c4iw_dev_ucontext *uctx);
  830. u32 c4iw_get_qpid(struct c4iw_rdev *rdev, struct c4iw_dev_ucontext *uctx);
  831. void c4iw_put_qpid(struct c4iw_rdev *rdev, u32 qid,
  832. struct c4iw_dev_ucontext *uctx);
  833. void c4iw_ev_dispatch(struct c4iw_dev *dev, struct t4_cqe *err_cqe);
  834. extern struct cxgb4_client t4c_client;
  835. extern c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS];
  836. extern int c4iw_max_read_depth;
  837. extern int db_fc_threshold;
  838. extern int db_coalescing_threshold;
  839. extern int use_dsgl;
  840. #endif