iw_cxgb4.h 25 KB

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