cxio_wr.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  1. /*
  2. * Copyright (c) 2006 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. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #ifndef __CXIO_WR_H__
  33. #define __CXIO_WR_H__
  34. #include <asm/io.h>
  35. #include <linux/pci.h>
  36. #include <linux/timer.h>
  37. #include "firmware_exports.h"
  38. #define T3_MAX_SGE 4
  39. #define T3_MAX_INLINE 64
  40. #define T3_STAG0_PBL_SIZE (2 * T3_MAX_SGE << 3)
  41. #define T3_STAG0_MAX_PBE_LEN (128 * 1024 * 1024)
  42. #define T3_STAG0_PAGE_SHIFT 15
  43. #define Q_EMPTY(rptr,wptr) ((rptr)==(wptr))
  44. #define Q_FULL(rptr,wptr,size_log2) ( (((wptr)-(rptr))>>(size_log2)) && \
  45. ((rptr)!=(wptr)) )
  46. #define Q_GENBIT(ptr,size_log2) (!(((ptr)>>size_log2)&0x1))
  47. #define Q_FREECNT(rptr,wptr,size_log2) ((1UL<<size_log2)-((wptr)-(rptr)))
  48. #define Q_COUNT(rptr,wptr) ((wptr)-(rptr))
  49. #define Q_PTR2IDX(ptr,size_log2) (ptr & ((1UL<<size_log2)-1))
  50. static inline void ring_doorbell(void __iomem *doorbell, u32 qpid)
  51. {
  52. writel(((1<<31) | qpid), doorbell);
  53. }
  54. #define SEQ32_GE(x,y) (!( (((u32) (x)) - ((u32) (y))) & 0x80000000 ))
  55. enum t3_wr_flags {
  56. T3_COMPLETION_FLAG = 0x01,
  57. T3_NOTIFY_FLAG = 0x02,
  58. T3_SOLICITED_EVENT_FLAG = 0x04,
  59. T3_READ_FENCE_FLAG = 0x08,
  60. T3_LOCAL_FENCE_FLAG = 0x10
  61. } __attribute__ ((packed));
  62. enum t3_wr_opcode {
  63. T3_WR_BP = FW_WROPCODE_RI_BYPASS,
  64. T3_WR_SEND = FW_WROPCODE_RI_SEND,
  65. T3_WR_WRITE = FW_WROPCODE_RI_RDMA_WRITE,
  66. T3_WR_READ = FW_WROPCODE_RI_RDMA_READ,
  67. T3_WR_INV_STAG = FW_WROPCODE_RI_LOCAL_INV,
  68. T3_WR_BIND = FW_WROPCODE_RI_BIND_MW,
  69. T3_WR_RCV = FW_WROPCODE_RI_RECEIVE,
  70. T3_WR_INIT = FW_WROPCODE_RI_RDMA_INIT,
  71. T3_WR_QP_MOD = FW_WROPCODE_RI_MODIFY_QP,
  72. T3_WR_FASTREG = FW_WROPCODE_RI_FASTREGISTER_MR
  73. } __attribute__ ((packed));
  74. enum t3_rdma_opcode {
  75. T3_RDMA_WRITE, /* IETF RDMAP v1.0 ... */
  76. T3_READ_REQ,
  77. T3_READ_RESP,
  78. T3_SEND,
  79. T3_SEND_WITH_INV,
  80. T3_SEND_WITH_SE,
  81. T3_SEND_WITH_SE_INV,
  82. T3_TERMINATE,
  83. T3_RDMA_INIT, /* CHELSIO RI specific ... */
  84. T3_BIND_MW,
  85. T3_FAST_REGISTER,
  86. T3_LOCAL_INV,
  87. T3_QP_MOD,
  88. T3_BYPASS,
  89. T3_RDMA_READ_REQ_WITH_INV,
  90. } __attribute__ ((packed));
  91. static inline enum t3_rdma_opcode wr2opcode(enum t3_wr_opcode wrop)
  92. {
  93. switch (wrop) {
  94. case T3_WR_BP: return T3_BYPASS;
  95. case T3_WR_SEND: return T3_SEND;
  96. case T3_WR_WRITE: return T3_RDMA_WRITE;
  97. case T3_WR_READ: return T3_READ_REQ;
  98. case T3_WR_INV_STAG: return T3_LOCAL_INV;
  99. case T3_WR_BIND: return T3_BIND_MW;
  100. case T3_WR_INIT: return T3_RDMA_INIT;
  101. case T3_WR_QP_MOD: return T3_QP_MOD;
  102. case T3_WR_FASTREG: return T3_FAST_REGISTER;
  103. default: break;
  104. }
  105. return -1;
  106. }
  107. /* Work request id */
  108. union t3_wrid {
  109. struct {
  110. u32 hi;
  111. u32 low;
  112. } id0;
  113. u64 id1;
  114. };
  115. #define WRID(wrid) (wrid.id1)
  116. #define WRID_GEN(wrid) (wrid.id0.wr_gen)
  117. #define WRID_IDX(wrid) (wrid.id0.wr_idx)
  118. #define WRID_LO(wrid) (wrid.id0.wr_lo)
  119. struct fw_riwrh {
  120. __be32 op_seop_flags;
  121. __be32 gen_tid_len;
  122. };
  123. #define S_FW_RIWR_OP 24
  124. #define M_FW_RIWR_OP 0xff
  125. #define V_FW_RIWR_OP(x) ((x) << S_FW_RIWR_OP)
  126. #define G_FW_RIWR_OP(x) ((((x) >> S_FW_RIWR_OP)) & M_FW_RIWR_OP)
  127. #define S_FW_RIWR_SOPEOP 22
  128. #define M_FW_RIWR_SOPEOP 0x3
  129. #define V_FW_RIWR_SOPEOP(x) ((x) << S_FW_RIWR_SOPEOP)
  130. #define S_FW_RIWR_FLAGS 8
  131. #define M_FW_RIWR_FLAGS 0x3fffff
  132. #define V_FW_RIWR_FLAGS(x) ((x) << S_FW_RIWR_FLAGS)
  133. #define G_FW_RIWR_FLAGS(x) ((((x) >> S_FW_RIWR_FLAGS)) & M_FW_RIWR_FLAGS)
  134. #define S_FW_RIWR_TID 8
  135. #define V_FW_RIWR_TID(x) ((x) << S_FW_RIWR_TID)
  136. #define S_FW_RIWR_LEN 0
  137. #define V_FW_RIWR_LEN(x) ((x) << S_FW_RIWR_LEN)
  138. #define S_FW_RIWR_GEN 31
  139. #define V_FW_RIWR_GEN(x) ((x) << S_FW_RIWR_GEN)
  140. struct t3_sge {
  141. __be32 stag;
  142. __be32 len;
  143. __be64 to;
  144. };
  145. /* If num_sgle is zero, flit 5+ contains immediate data.*/
  146. struct t3_send_wr {
  147. struct fw_riwrh wrh; /* 0 */
  148. union t3_wrid wrid; /* 1 */
  149. u8 rdmaop; /* 2 */
  150. u8 reserved[3];
  151. __be32 rem_stag;
  152. __be32 plen; /* 3 */
  153. __be32 num_sgle;
  154. struct t3_sge sgl[T3_MAX_SGE]; /* 4+ */
  155. };
  156. #define T3_MAX_FASTREG_DEPTH 10
  157. #define T3_MAX_FASTREG_FRAG 10
  158. struct t3_fastreg_wr {
  159. struct fw_riwrh wrh; /* 0 */
  160. union t3_wrid wrid; /* 1 */
  161. __be32 stag; /* 2 */
  162. __be32 len;
  163. __be32 va_base_hi; /* 3 */
  164. __be32 va_base_lo_fbo;
  165. __be32 page_type_perms; /* 4 */
  166. __be32 reserved1;
  167. __be64 pbl_addrs[0]; /* 5+ */
  168. };
  169. /*
  170. * If a fastreg wr spans multiple wqes, then the 2nd fragment look like this.
  171. */
  172. struct t3_pbl_frag {
  173. struct fw_riwrh wrh; /* 0 */
  174. __be64 pbl_addrs[14]; /* 1..14 */
  175. };
  176. #define S_FR_PAGE_COUNT 24
  177. #define M_FR_PAGE_COUNT 0xff
  178. #define V_FR_PAGE_COUNT(x) ((x) << S_FR_PAGE_COUNT)
  179. #define G_FR_PAGE_COUNT(x) ((((x) >> S_FR_PAGE_COUNT)) & M_FR_PAGE_COUNT)
  180. #define S_FR_PAGE_SIZE 16
  181. #define M_FR_PAGE_SIZE 0x1f
  182. #define V_FR_PAGE_SIZE(x) ((x) << S_FR_PAGE_SIZE)
  183. #define G_FR_PAGE_SIZE(x) ((((x) >> S_FR_PAGE_SIZE)) & M_FR_PAGE_SIZE)
  184. #define S_FR_TYPE 8
  185. #define M_FR_TYPE 0x1
  186. #define V_FR_TYPE(x) ((x) << S_FR_TYPE)
  187. #define G_FR_TYPE(x) ((((x) >> S_FR_TYPE)) & M_FR_TYPE)
  188. #define S_FR_PERMS 0
  189. #define M_FR_PERMS 0xff
  190. #define V_FR_PERMS(x) ((x) << S_FR_PERMS)
  191. #define G_FR_PERMS(x) ((((x) >> S_FR_PERMS)) & M_FR_PERMS)
  192. struct t3_local_inv_wr {
  193. struct fw_riwrh wrh; /* 0 */
  194. union t3_wrid wrid; /* 1 */
  195. __be32 stag; /* 2 */
  196. __be32 reserved;
  197. };
  198. struct t3_rdma_write_wr {
  199. struct fw_riwrh wrh; /* 0 */
  200. union t3_wrid wrid; /* 1 */
  201. u8 rdmaop; /* 2 */
  202. u8 reserved[3];
  203. __be32 stag_sink;
  204. __be64 to_sink; /* 3 */
  205. __be32 plen; /* 4 */
  206. __be32 num_sgle;
  207. struct t3_sge sgl[T3_MAX_SGE]; /* 5+ */
  208. };
  209. struct t3_rdma_read_wr {
  210. struct fw_riwrh wrh; /* 0 */
  211. union t3_wrid wrid; /* 1 */
  212. u8 rdmaop; /* 2 */
  213. u8 local_inv;
  214. u8 reserved[2];
  215. __be32 rem_stag;
  216. __be64 rem_to; /* 3 */
  217. __be32 local_stag; /* 4 */
  218. __be32 local_len;
  219. __be64 local_to; /* 5 */
  220. };
  221. struct t3_bind_mw_wr {
  222. struct fw_riwrh wrh; /* 0 */
  223. union t3_wrid wrid; /* 1 */
  224. u16 reserved; /* 2 */
  225. u8 type;
  226. u8 perms;
  227. __be32 mr_stag;
  228. __be32 mw_stag; /* 3 */
  229. __be32 mw_len;
  230. __be64 mw_va; /* 4 */
  231. __be32 mr_pbl_addr; /* 5 */
  232. u8 reserved2[3];
  233. u8 mr_pagesz;
  234. };
  235. struct t3_receive_wr {
  236. struct fw_riwrh wrh; /* 0 */
  237. union t3_wrid wrid; /* 1 */
  238. u8 pagesz[T3_MAX_SGE];
  239. __be32 num_sgle; /* 2 */
  240. struct t3_sge sgl[T3_MAX_SGE]; /* 3+ */
  241. __be32 pbl_addr[T3_MAX_SGE];
  242. };
  243. struct t3_bypass_wr {
  244. struct fw_riwrh wrh;
  245. union t3_wrid wrid; /* 1 */
  246. };
  247. struct t3_modify_qp_wr {
  248. struct fw_riwrh wrh; /* 0 */
  249. union t3_wrid wrid; /* 1 */
  250. __be32 flags; /* 2 */
  251. __be32 quiesce; /* 2 */
  252. __be32 max_ird; /* 3 */
  253. __be32 max_ord; /* 3 */
  254. __be64 sge_cmd; /* 4 */
  255. __be64 ctx1; /* 5 */
  256. __be64 ctx0; /* 6 */
  257. };
  258. enum t3_modify_qp_flags {
  259. MODQP_QUIESCE = 0x01,
  260. MODQP_MAX_IRD = 0x02,
  261. MODQP_MAX_ORD = 0x04,
  262. MODQP_WRITE_EC = 0x08,
  263. MODQP_READ_EC = 0x10,
  264. };
  265. enum t3_mpa_attrs {
  266. uP_RI_MPA_RX_MARKER_ENABLE = 0x1,
  267. uP_RI_MPA_TX_MARKER_ENABLE = 0x2,
  268. uP_RI_MPA_CRC_ENABLE = 0x4,
  269. uP_RI_MPA_IETF_ENABLE = 0x8
  270. } __attribute__ ((packed));
  271. enum t3_qp_caps {
  272. uP_RI_QP_RDMA_READ_ENABLE = 0x01,
  273. uP_RI_QP_RDMA_WRITE_ENABLE = 0x02,
  274. uP_RI_QP_BIND_ENABLE = 0x04,
  275. uP_RI_QP_FAST_REGISTER_ENABLE = 0x08,
  276. uP_RI_QP_STAG0_ENABLE = 0x10
  277. } __attribute__ ((packed));
  278. enum rdma_init_rtr_types {
  279. RTR_READ = 1,
  280. RTR_WRITE = 2,
  281. RTR_SEND = 3,
  282. };
  283. #define S_RTR_TYPE 2
  284. #define M_RTR_TYPE 0x3
  285. #define V_RTR_TYPE(x) ((x) << S_RTR_TYPE)
  286. #define G_RTR_TYPE(x) ((((x) >> S_RTR_TYPE)) & M_RTR_TYPE)
  287. #define S_CHAN 4
  288. #define M_CHAN 0x3
  289. #define V_CHAN(x) ((x) << S_CHAN)
  290. #define G_CHAN(x) ((((x) >> S_CHAN)) & M_CHAN)
  291. struct t3_rdma_init_attr {
  292. u32 tid;
  293. u32 qpid;
  294. u32 pdid;
  295. u32 scqid;
  296. u32 rcqid;
  297. u32 rq_addr;
  298. u32 rq_size;
  299. enum t3_mpa_attrs mpaattrs;
  300. enum t3_qp_caps qpcaps;
  301. u16 tcp_emss;
  302. u32 ord;
  303. u32 ird;
  304. u64 qp_dma_addr;
  305. u32 qp_dma_size;
  306. enum rdma_init_rtr_types rtr_type;
  307. u16 flags;
  308. u16 rqe_count;
  309. u32 irs;
  310. u32 chan;
  311. };
  312. struct t3_rdma_init_wr {
  313. struct fw_riwrh wrh; /* 0 */
  314. union t3_wrid wrid; /* 1 */
  315. __be32 qpid; /* 2 */
  316. __be32 pdid;
  317. __be32 scqid; /* 3 */
  318. __be32 rcqid;
  319. __be32 rq_addr; /* 4 */
  320. __be32 rq_size;
  321. u8 mpaattrs; /* 5 */
  322. u8 qpcaps;
  323. __be16 ulpdu_size;
  324. __be16 flags_rtr_type;
  325. __be16 rqe_count;
  326. __be32 ord; /* 6 */
  327. __be32 ird;
  328. __be64 qp_dma_addr; /* 7 */
  329. __be32 qp_dma_size; /* 8 */
  330. __be32 irs;
  331. };
  332. struct t3_genbit {
  333. u64 flit[15];
  334. __be64 genbit;
  335. };
  336. struct t3_wq_in_err {
  337. u64 flit[13];
  338. u64 err;
  339. };
  340. enum rdma_init_wr_flags {
  341. MPA_INITIATOR = (1<<0),
  342. PRIV_QP = (1<<1),
  343. };
  344. union t3_wr {
  345. struct t3_send_wr send;
  346. struct t3_rdma_write_wr write;
  347. struct t3_rdma_read_wr read;
  348. struct t3_receive_wr recv;
  349. struct t3_fastreg_wr fastreg;
  350. struct t3_pbl_frag pbl_frag;
  351. struct t3_local_inv_wr local_inv;
  352. struct t3_bind_mw_wr bind;
  353. struct t3_bypass_wr bypass;
  354. struct t3_rdma_init_wr init;
  355. struct t3_modify_qp_wr qp_mod;
  356. struct t3_genbit genbit;
  357. struct t3_wq_in_err wq_in_err;
  358. __be64 flit[16];
  359. };
  360. #define T3_SQ_CQE_FLIT 13
  361. #define T3_SQ_COOKIE_FLIT 14
  362. #define T3_RQ_COOKIE_FLIT 13
  363. #define T3_RQ_CQE_FLIT 14
  364. static inline enum t3_wr_opcode fw_riwrh_opcode(struct fw_riwrh *wqe)
  365. {
  366. return G_FW_RIWR_OP(be32_to_cpu(wqe->op_seop_flags));
  367. }
  368. enum t3_wr_hdr_bits {
  369. T3_EOP = 1,
  370. T3_SOP = 2,
  371. T3_SOPEOP = T3_EOP|T3_SOP,
  372. };
  373. static inline void build_fw_riwrh(struct fw_riwrh *wqe, enum t3_wr_opcode op,
  374. enum t3_wr_flags flags, u8 genbit, u32 tid,
  375. u8 len, u8 sopeop)
  376. {
  377. wqe->op_seop_flags = cpu_to_be32(V_FW_RIWR_OP(op) |
  378. V_FW_RIWR_SOPEOP(sopeop) |
  379. V_FW_RIWR_FLAGS(flags));
  380. wmb();
  381. wqe->gen_tid_len = cpu_to_be32(V_FW_RIWR_GEN(genbit) |
  382. V_FW_RIWR_TID(tid) |
  383. V_FW_RIWR_LEN(len));
  384. /* 2nd gen bit... */
  385. ((union t3_wr *)wqe)->genbit.genbit = cpu_to_be64(genbit);
  386. }
  387. /*
  388. * T3 ULP2_TX commands
  389. */
  390. enum t3_utx_mem_op {
  391. T3_UTX_MEM_READ = 2,
  392. T3_UTX_MEM_WRITE = 3
  393. };
  394. /* T3 MC7 RDMA TPT entry format */
  395. enum tpt_mem_type {
  396. TPT_NON_SHARED_MR = 0x0,
  397. TPT_SHARED_MR = 0x1,
  398. TPT_MW = 0x2,
  399. TPT_MW_RELAXED_PROTECTION = 0x3
  400. };
  401. enum tpt_addr_type {
  402. TPT_ZBTO = 0,
  403. TPT_VATO = 1
  404. };
  405. enum tpt_mem_perm {
  406. TPT_MW_BIND = 0x10,
  407. TPT_LOCAL_READ = 0x8,
  408. TPT_LOCAL_WRITE = 0x4,
  409. TPT_REMOTE_READ = 0x2,
  410. TPT_REMOTE_WRITE = 0x1
  411. };
  412. struct tpt_entry {
  413. __be32 valid_stag_pdid;
  414. __be32 flags_pagesize_qpid;
  415. __be32 rsvd_pbl_addr;
  416. __be32 len;
  417. __be32 va_hi;
  418. __be32 va_low_or_fbo;
  419. __be32 rsvd_bind_cnt_or_pstag;
  420. __be32 rsvd_pbl_size;
  421. };
  422. #define S_TPT_VALID 31
  423. #define V_TPT_VALID(x) ((x) << S_TPT_VALID)
  424. #define F_TPT_VALID V_TPT_VALID(1U)
  425. #define S_TPT_STAG_KEY 23
  426. #define M_TPT_STAG_KEY 0xFF
  427. #define V_TPT_STAG_KEY(x) ((x) << S_TPT_STAG_KEY)
  428. #define G_TPT_STAG_KEY(x) (((x) >> S_TPT_STAG_KEY) & M_TPT_STAG_KEY)
  429. #define S_TPT_STAG_STATE 22
  430. #define V_TPT_STAG_STATE(x) ((x) << S_TPT_STAG_STATE)
  431. #define F_TPT_STAG_STATE V_TPT_STAG_STATE(1U)
  432. #define S_TPT_STAG_TYPE 20
  433. #define M_TPT_STAG_TYPE 0x3
  434. #define V_TPT_STAG_TYPE(x) ((x) << S_TPT_STAG_TYPE)
  435. #define G_TPT_STAG_TYPE(x) (((x) >> S_TPT_STAG_TYPE) & M_TPT_STAG_TYPE)
  436. #define S_TPT_PDID 0
  437. #define M_TPT_PDID 0xFFFFF
  438. #define V_TPT_PDID(x) ((x) << S_TPT_PDID)
  439. #define G_TPT_PDID(x) (((x) >> S_TPT_PDID) & M_TPT_PDID)
  440. #define S_TPT_PERM 28
  441. #define M_TPT_PERM 0xF
  442. #define V_TPT_PERM(x) ((x) << S_TPT_PERM)
  443. #define G_TPT_PERM(x) (((x) >> S_TPT_PERM) & M_TPT_PERM)
  444. #define S_TPT_REM_INV_DIS 27
  445. #define V_TPT_REM_INV_DIS(x) ((x) << S_TPT_REM_INV_DIS)
  446. #define F_TPT_REM_INV_DIS V_TPT_REM_INV_DIS(1U)
  447. #define S_TPT_ADDR_TYPE 26
  448. #define V_TPT_ADDR_TYPE(x) ((x) << S_TPT_ADDR_TYPE)
  449. #define F_TPT_ADDR_TYPE V_TPT_ADDR_TYPE(1U)
  450. #define S_TPT_MW_BIND_ENABLE 25
  451. #define V_TPT_MW_BIND_ENABLE(x) ((x) << S_TPT_MW_BIND_ENABLE)
  452. #define F_TPT_MW_BIND_ENABLE V_TPT_MW_BIND_ENABLE(1U)
  453. #define S_TPT_PAGE_SIZE 20
  454. #define M_TPT_PAGE_SIZE 0x1F
  455. #define V_TPT_PAGE_SIZE(x) ((x) << S_TPT_PAGE_SIZE)
  456. #define G_TPT_PAGE_SIZE(x) (((x) >> S_TPT_PAGE_SIZE) & M_TPT_PAGE_SIZE)
  457. #define S_TPT_PBL_ADDR 0
  458. #define M_TPT_PBL_ADDR 0x1FFFFFFF
  459. #define V_TPT_PBL_ADDR(x) ((x) << S_TPT_PBL_ADDR)
  460. #define G_TPT_PBL_ADDR(x) (((x) >> S_TPT_PBL_ADDR) & M_TPT_PBL_ADDR)
  461. #define S_TPT_QPID 0
  462. #define M_TPT_QPID 0xFFFFF
  463. #define V_TPT_QPID(x) ((x) << S_TPT_QPID)
  464. #define G_TPT_QPID(x) (((x) >> S_TPT_QPID) & M_TPT_QPID)
  465. #define S_TPT_PSTAG 0
  466. #define M_TPT_PSTAG 0xFFFFFF
  467. #define V_TPT_PSTAG(x) ((x) << S_TPT_PSTAG)
  468. #define G_TPT_PSTAG(x) (((x) >> S_TPT_PSTAG) & M_TPT_PSTAG)
  469. #define S_TPT_PBL_SIZE 0
  470. #define M_TPT_PBL_SIZE 0xFFFFF
  471. #define V_TPT_PBL_SIZE(x) ((x) << S_TPT_PBL_SIZE)
  472. #define G_TPT_PBL_SIZE(x) (((x) >> S_TPT_PBL_SIZE) & M_TPT_PBL_SIZE)
  473. /*
  474. * CQE defs
  475. */
  476. struct t3_cqe {
  477. __be32 header;
  478. __be32 len;
  479. union {
  480. struct {
  481. __be32 stag;
  482. __be32 msn;
  483. } rcqe;
  484. struct {
  485. u32 wrid_hi;
  486. u32 wrid_low;
  487. } scqe;
  488. } u;
  489. };
  490. #define S_CQE_OOO 31
  491. #define M_CQE_OOO 0x1
  492. #define G_CQE_OOO(x) ((((x) >> S_CQE_OOO)) & M_CQE_OOO)
  493. #define V_CEQ_OOO(x) ((x)<<S_CQE_OOO)
  494. #define S_CQE_QPID 12
  495. #define M_CQE_QPID 0x7FFFF
  496. #define G_CQE_QPID(x) ((((x) >> S_CQE_QPID)) & M_CQE_QPID)
  497. #define V_CQE_QPID(x) ((x)<<S_CQE_QPID)
  498. #define S_CQE_SWCQE 11
  499. #define M_CQE_SWCQE 0x1
  500. #define G_CQE_SWCQE(x) ((((x) >> S_CQE_SWCQE)) & M_CQE_SWCQE)
  501. #define V_CQE_SWCQE(x) ((x)<<S_CQE_SWCQE)
  502. #define S_CQE_GENBIT 10
  503. #define M_CQE_GENBIT 0x1
  504. #define G_CQE_GENBIT(x) (((x) >> S_CQE_GENBIT) & M_CQE_GENBIT)
  505. #define V_CQE_GENBIT(x) ((x)<<S_CQE_GENBIT)
  506. #define S_CQE_STATUS 5
  507. #define M_CQE_STATUS 0x1F
  508. #define G_CQE_STATUS(x) ((((x) >> S_CQE_STATUS)) & M_CQE_STATUS)
  509. #define V_CQE_STATUS(x) ((x)<<S_CQE_STATUS)
  510. #define S_CQE_TYPE 4
  511. #define M_CQE_TYPE 0x1
  512. #define G_CQE_TYPE(x) ((((x) >> S_CQE_TYPE)) & M_CQE_TYPE)
  513. #define V_CQE_TYPE(x) ((x)<<S_CQE_TYPE)
  514. #define S_CQE_OPCODE 0
  515. #define M_CQE_OPCODE 0xF
  516. #define G_CQE_OPCODE(x) ((((x) >> S_CQE_OPCODE)) & M_CQE_OPCODE)
  517. #define V_CQE_OPCODE(x) ((x)<<S_CQE_OPCODE)
  518. #define SW_CQE(x) (G_CQE_SWCQE(be32_to_cpu((x).header)))
  519. #define CQE_OOO(x) (G_CQE_OOO(be32_to_cpu((x).header)))
  520. #define CQE_QPID(x) (G_CQE_QPID(be32_to_cpu((x).header)))
  521. #define CQE_GENBIT(x) (G_CQE_GENBIT(be32_to_cpu((x).header)))
  522. #define CQE_TYPE(x) (G_CQE_TYPE(be32_to_cpu((x).header)))
  523. #define SQ_TYPE(x) (CQE_TYPE((x)))
  524. #define RQ_TYPE(x) (!CQE_TYPE((x)))
  525. #define CQE_STATUS(x) (G_CQE_STATUS(be32_to_cpu((x).header)))
  526. #define CQE_OPCODE(x) (G_CQE_OPCODE(be32_to_cpu((x).header)))
  527. #define CQE_SEND_OPCODE(x)( \
  528. (G_CQE_OPCODE(be32_to_cpu((x).header)) == T3_SEND) || \
  529. (G_CQE_OPCODE(be32_to_cpu((x).header)) == T3_SEND_WITH_SE) || \
  530. (G_CQE_OPCODE(be32_to_cpu((x).header)) == T3_SEND_WITH_INV) || \
  531. (G_CQE_OPCODE(be32_to_cpu((x).header)) == T3_SEND_WITH_SE_INV))
  532. #define CQE_LEN(x) (be32_to_cpu((x).len))
  533. /* used for RQ completion processing */
  534. #define CQE_WRID_STAG(x) (be32_to_cpu((x).u.rcqe.stag))
  535. #define CQE_WRID_MSN(x) (be32_to_cpu((x).u.rcqe.msn))
  536. /* used for SQ completion processing */
  537. #define CQE_WRID_SQ_WPTR(x) ((x).u.scqe.wrid_hi)
  538. #define CQE_WRID_WPTR(x) ((x).u.scqe.wrid_low)
  539. /* generic accessor macros */
  540. #define CQE_WRID_HI(x) ((x).u.scqe.wrid_hi)
  541. #define CQE_WRID_LOW(x) ((x).u.scqe.wrid_low)
  542. #define TPT_ERR_SUCCESS 0x0
  543. #define TPT_ERR_STAG 0x1 /* STAG invalid: either the */
  544. /* STAG is offlimt, being 0, */
  545. /* or STAG_key mismatch */
  546. #define TPT_ERR_PDID 0x2 /* PDID mismatch */
  547. #define TPT_ERR_QPID 0x3 /* QPID mismatch */
  548. #define TPT_ERR_ACCESS 0x4 /* Invalid access right */
  549. #define TPT_ERR_WRAP 0x5 /* Wrap error */
  550. #define TPT_ERR_BOUND 0x6 /* base and bounds voilation */
  551. #define TPT_ERR_INVALIDATE_SHARED_MR 0x7 /* attempt to invalidate a */
  552. /* shared memory region */
  553. #define TPT_ERR_INVALIDATE_MR_WITH_MW_BOUND 0x8 /* attempt to invalidate a */
  554. /* shared memory region */
  555. #define TPT_ERR_ECC 0x9 /* ECC error detected */
  556. #define TPT_ERR_ECC_PSTAG 0xA /* ECC error detected when */
  557. /* reading PSTAG for a MW */
  558. /* Invalidate */
  559. #define TPT_ERR_PBL_ADDR_BOUND 0xB /* pbl addr out of bounds: */
  560. /* software error */
  561. #define TPT_ERR_SWFLUSH 0xC /* SW FLUSHED */
  562. #define TPT_ERR_CRC 0x10 /* CRC error */
  563. #define TPT_ERR_MARKER 0x11 /* Marker error */
  564. #define TPT_ERR_PDU_LEN_ERR 0x12 /* invalid PDU length */
  565. #define TPT_ERR_OUT_OF_RQE 0x13 /* out of RQE */
  566. #define TPT_ERR_DDP_VERSION 0x14 /* wrong DDP version */
  567. #define TPT_ERR_RDMA_VERSION 0x15 /* wrong RDMA version */
  568. #define TPT_ERR_OPCODE 0x16 /* invalid rdma opcode */
  569. #define TPT_ERR_DDP_QUEUE_NUM 0x17 /* invalid ddp queue number */
  570. #define TPT_ERR_MSN 0x18 /* MSN error */
  571. #define TPT_ERR_TBIT 0x19 /* tag bit not set correctly */
  572. #define TPT_ERR_MO 0x1A /* MO not 0 for TERMINATE */
  573. /* or READ_REQ */
  574. #define TPT_ERR_MSN_GAP 0x1B
  575. #define TPT_ERR_MSN_RANGE 0x1C
  576. #define TPT_ERR_IRD_OVERFLOW 0x1D
  577. #define TPT_ERR_RQE_ADDR_BOUND 0x1E /* RQE addr out of bounds: */
  578. /* software error */
  579. #define TPT_ERR_INTERNAL_ERR 0x1F /* internal error (opcode */
  580. /* mismatch) */
  581. struct t3_swsq {
  582. __u64 wr_id;
  583. struct t3_cqe cqe;
  584. __u32 sq_wptr;
  585. __be32 read_len;
  586. int opcode;
  587. int complete;
  588. int signaled;
  589. };
  590. struct t3_swrq {
  591. __u64 wr_id;
  592. __u32 pbl_addr;
  593. };
  594. /*
  595. * A T3 WQ implements both the SQ and RQ.
  596. */
  597. struct t3_wq {
  598. union t3_wr *queue; /* DMA accessible memory */
  599. dma_addr_t dma_addr; /* DMA address for HW */
  600. DEFINE_DMA_UNMAP_ADDR(mapping); /* unmap kruft */
  601. u32 error; /* 1 once we go to ERROR */
  602. u32 qpid;
  603. u32 wptr; /* idx to next available WR slot */
  604. u32 size_log2; /* total wq size */
  605. struct t3_swsq *sq; /* SW SQ */
  606. struct t3_swsq *oldest_read; /* tracks oldest pending read */
  607. u32 sq_wptr; /* sq_wptr - sq_rptr == count of */
  608. u32 sq_rptr; /* pending wrs */
  609. u32 sq_size_log2; /* sq size */
  610. struct t3_swrq *rq; /* SW RQ (holds consumer wr_ids */
  611. u32 rq_wptr; /* rq_wptr - rq_rptr == count of */
  612. u32 rq_rptr; /* pending wrs */
  613. struct t3_swrq *rq_oldest_wr; /* oldest wr on the SW RQ */
  614. u32 rq_size_log2; /* rq size */
  615. u32 rq_addr; /* rq adapter address */
  616. void __iomem *doorbell; /* kernel db */
  617. u64 udb; /* user db if any */
  618. struct cxio_rdev *rdev;
  619. };
  620. struct t3_cq {
  621. u32 cqid;
  622. u32 rptr;
  623. u32 wptr;
  624. u32 size_log2;
  625. dma_addr_t dma_addr;
  626. DEFINE_DMA_UNMAP_ADDR(mapping);
  627. struct t3_cqe *queue;
  628. struct t3_cqe *sw_queue;
  629. u32 sw_rptr;
  630. u32 sw_wptr;
  631. };
  632. #define CQ_VLD_ENTRY(ptr,size_log2,cqe) (Q_GENBIT(ptr,size_log2) == \
  633. CQE_GENBIT(*cqe))
  634. struct t3_cq_status_page {
  635. u32 cq_err;
  636. };
  637. static inline int cxio_cq_in_error(struct t3_cq *cq)
  638. {
  639. return ((struct t3_cq_status_page *)
  640. &cq->queue[1 << cq->size_log2])->cq_err;
  641. }
  642. static inline void cxio_set_cq_in_error(struct t3_cq *cq)
  643. {
  644. ((struct t3_cq_status_page *)
  645. &cq->queue[1 << cq->size_log2])->cq_err = 1;
  646. }
  647. static inline void cxio_set_wq_in_error(struct t3_wq *wq)
  648. {
  649. wq->queue->wq_in_err.err |= 1;
  650. }
  651. static inline void cxio_disable_wq_db(struct t3_wq *wq)
  652. {
  653. wq->queue->wq_in_err.err |= 2;
  654. }
  655. static inline void cxio_enable_wq_db(struct t3_wq *wq)
  656. {
  657. wq->queue->wq_in_err.err &= ~2;
  658. }
  659. static inline int cxio_wq_db_enabled(struct t3_wq *wq)
  660. {
  661. return !(wq->queue->wq_in_err.err & 2);
  662. }
  663. static inline struct t3_cqe *cxio_next_hw_cqe(struct t3_cq *cq)
  664. {
  665. struct t3_cqe *cqe;
  666. cqe = cq->queue + (Q_PTR2IDX(cq->rptr, cq->size_log2));
  667. if (CQ_VLD_ENTRY(cq->rptr, cq->size_log2, cqe))
  668. return cqe;
  669. return NULL;
  670. }
  671. static inline struct t3_cqe *cxio_next_sw_cqe(struct t3_cq *cq)
  672. {
  673. struct t3_cqe *cqe;
  674. if (!Q_EMPTY(cq->sw_rptr, cq->sw_wptr)) {
  675. cqe = cq->sw_queue + (Q_PTR2IDX(cq->sw_rptr, cq->size_log2));
  676. return cqe;
  677. }
  678. return NULL;
  679. }
  680. static inline struct t3_cqe *cxio_next_cqe(struct t3_cq *cq)
  681. {
  682. struct t3_cqe *cqe;
  683. if (!Q_EMPTY(cq->sw_rptr, cq->sw_wptr)) {
  684. cqe = cq->sw_queue + (Q_PTR2IDX(cq->sw_rptr, cq->size_log2));
  685. return cqe;
  686. }
  687. cqe = cq->queue + (Q_PTR2IDX(cq->rptr, cq->size_log2));
  688. if (CQ_VLD_ENTRY(cq->rptr, cq->size_log2, cqe))
  689. return cqe;
  690. return NULL;
  691. }
  692. #endif