iw_cxgb4.h 20 KB

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