iw_cxgb4.h 26 KB

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