iw_cxgb4.h 27 KB

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