ehea_qmr.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. /*
  2. * linux/drivers/net/ethernet/ibm/ehea/ehea_qmr.h
  3. *
  4. * eHEA ethernet device driver for IBM eServer System p
  5. *
  6. * (C) Copyright IBM Corp. 2006
  7. *
  8. * Authors:
  9. * Christoph Raisch <raisch@de.ibm.com>
  10. * Jan-Bernd Themann <themann@de.ibm.com>
  11. * Thomas Klein <tklein@de.ibm.com>
  12. *
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2, or (at your option)
  17. * any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  27. */
  28. #ifndef __EHEA_QMR_H__
  29. #define __EHEA_QMR_H__
  30. #include <linux/prefetch.h>
  31. #include "ehea.h"
  32. #include "ehea_hw.h"
  33. /*
  34. * page size of ehea hardware queues
  35. */
  36. #define EHEA_PAGESHIFT 12
  37. #define EHEA_PAGESIZE (1UL << EHEA_PAGESHIFT)
  38. #define EHEA_SECTSIZE (1UL << 24)
  39. #define EHEA_PAGES_PER_SECTION (EHEA_SECTSIZE >> EHEA_PAGESHIFT)
  40. #define EHEA_HUGEPAGESHIFT 34
  41. #define EHEA_HUGEPAGE_SIZE (1UL << EHEA_HUGEPAGESHIFT)
  42. #define EHEA_HUGEPAGE_PFN_MASK ((EHEA_HUGEPAGE_SIZE - 1) >> PAGE_SHIFT)
  43. #if ((1UL << SECTION_SIZE_BITS) < EHEA_SECTSIZE)
  44. #error eHEA module cannot work if kernel sectionsize < ehea sectionsize
  45. #endif
  46. /* Some abbreviations used here:
  47. *
  48. * WQE - Work Queue Entry
  49. * SWQE - Send Work Queue Entry
  50. * RWQE - Receive Work Queue Entry
  51. * CQE - Completion Queue Entry
  52. * EQE - Event Queue Entry
  53. * MR - Memory Region
  54. */
  55. /* Use of WR_ID field for EHEA */
  56. #define EHEA_WR_ID_COUNT EHEA_BMASK_IBM(0, 19)
  57. #define EHEA_WR_ID_TYPE EHEA_BMASK_IBM(20, 23)
  58. #define EHEA_SWQE2_TYPE 0x1
  59. #define EHEA_SWQE3_TYPE 0x2
  60. #define EHEA_RWQE2_TYPE 0x3
  61. #define EHEA_RWQE3_TYPE 0x4
  62. #define EHEA_WR_ID_INDEX EHEA_BMASK_IBM(24, 47)
  63. #define EHEA_WR_ID_REFILL EHEA_BMASK_IBM(48, 63)
  64. struct ehea_vsgentry {
  65. u64 vaddr;
  66. u32 l_key;
  67. u32 len;
  68. };
  69. /* maximum number of sg entries allowed in a WQE */
  70. #define EHEA_MAX_WQE_SG_ENTRIES 252
  71. #define SWQE2_MAX_IMM (0xD0 - 0x30)
  72. #define SWQE3_MAX_IMM 224
  73. /* tx control flags for swqe */
  74. #define EHEA_SWQE_CRC 0x8000
  75. #define EHEA_SWQE_IP_CHECKSUM 0x4000
  76. #define EHEA_SWQE_TCP_CHECKSUM 0x2000
  77. #define EHEA_SWQE_TSO 0x1000
  78. #define EHEA_SWQE_SIGNALLED_COMPLETION 0x0800
  79. #define EHEA_SWQE_VLAN_INSERT 0x0400
  80. #define EHEA_SWQE_IMM_DATA_PRESENT 0x0200
  81. #define EHEA_SWQE_DESCRIPTORS_PRESENT 0x0100
  82. #define EHEA_SWQE_WRAP_CTL_REC 0x0080
  83. #define EHEA_SWQE_WRAP_CTL_FORCE 0x0040
  84. #define EHEA_SWQE_BIND 0x0020
  85. #define EHEA_SWQE_PURGE 0x0010
  86. /* sizeof(struct ehea_swqe) less the union */
  87. #define SWQE_HEADER_SIZE 32
  88. struct ehea_swqe {
  89. u64 wr_id;
  90. u16 tx_control;
  91. u16 vlan_tag;
  92. u8 reserved1;
  93. u8 ip_start;
  94. u8 ip_end;
  95. u8 immediate_data_length;
  96. u8 tcp_offset;
  97. u8 reserved2;
  98. u16 reserved2b;
  99. u8 wrap_tag;
  100. u8 descriptors; /* number of valid descriptors in WQE */
  101. u16 reserved3;
  102. u16 reserved4;
  103. u16 mss;
  104. u32 reserved5;
  105. union {
  106. /* Send WQE Format 1 */
  107. struct {
  108. struct ehea_vsgentry sg_list[EHEA_MAX_WQE_SG_ENTRIES];
  109. } no_immediate_data;
  110. /* Send WQE Format 2 */
  111. struct {
  112. struct ehea_vsgentry sg_entry;
  113. /* 0x30 */
  114. u8 immediate_data[SWQE2_MAX_IMM];
  115. /* 0xd0 */
  116. struct ehea_vsgentry sg_list[EHEA_MAX_WQE_SG_ENTRIES-1];
  117. } immdata_desc __packed;
  118. /* Send WQE Format 3 */
  119. struct {
  120. u8 immediate_data[SWQE3_MAX_IMM];
  121. } immdata_nodesc;
  122. } u;
  123. };
  124. struct ehea_rwqe {
  125. u64 wr_id; /* work request ID */
  126. u8 reserved1[5];
  127. u8 data_segments;
  128. u16 reserved2;
  129. u64 reserved3;
  130. u64 reserved4;
  131. struct ehea_vsgentry sg_list[EHEA_MAX_WQE_SG_ENTRIES];
  132. };
  133. #define EHEA_CQE_VLAN_TAG_XTRACT 0x0400
  134. #define EHEA_CQE_TYPE_RQ 0x60
  135. #define EHEA_CQE_STAT_ERR_MASK 0x700F
  136. #define EHEA_CQE_STAT_FAT_ERR_MASK 0xF
  137. #define EHEA_CQE_BLIND_CKSUM 0x8000
  138. #define EHEA_CQE_STAT_ERR_TCP 0x4000
  139. #define EHEA_CQE_STAT_ERR_IP 0x2000
  140. #define EHEA_CQE_STAT_ERR_CRC 0x1000
  141. /* Defines which bad send cqe stati lead to a port reset */
  142. #define EHEA_CQE_STAT_RESET_MASK 0x0002
  143. struct ehea_cqe {
  144. u64 wr_id; /* work request ID from WQE */
  145. u8 type;
  146. u8 valid;
  147. u16 status;
  148. u16 reserved1;
  149. u16 num_bytes_transfered;
  150. u16 vlan_tag;
  151. u16 inet_checksum_value;
  152. u8 reserved2;
  153. u8 header_length;
  154. u16 reserved3;
  155. u16 page_offset;
  156. u16 wqe_count;
  157. u32 qp_token;
  158. u32 timestamp;
  159. u32 reserved4;
  160. u64 reserved5[3];
  161. };
  162. #define EHEA_EQE_VALID EHEA_BMASK_IBM(0, 0)
  163. #define EHEA_EQE_IS_CQE EHEA_BMASK_IBM(1, 1)
  164. #define EHEA_EQE_IDENTIFIER EHEA_BMASK_IBM(2, 7)
  165. #define EHEA_EQE_QP_CQ_NUMBER EHEA_BMASK_IBM(8, 31)
  166. #define EHEA_EQE_QP_TOKEN EHEA_BMASK_IBM(32, 63)
  167. #define EHEA_EQE_CQ_TOKEN EHEA_BMASK_IBM(32, 63)
  168. #define EHEA_EQE_KEY EHEA_BMASK_IBM(32, 63)
  169. #define EHEA_EQE_PORT_NUMBER EHEA_BMASK_IBM(56, 63)
  170. #define EHEA_EQE_EQ_NUMBER EHEA_BMASK_IBM(48, 63)
  171. #define EHEA_EQE_SM_ID EHEA_BMASK_IBM(48, 63)
  172. #define EHEA_EQE_SM_MECH_NUMBER EHEA_BMASK_IBM(48, 55)
  173. #define EHEA_EQE_SM_PORT_NUMBER EHEA_BMASK_IBM(56, 63)
  174. #define EHEA_AER_RESTYPE_QP 0x8
  175. #define EHEA_AER_RESTYPE_CQ 0x4
  176. #define EHEA_AER_RESTYPE_EQ 0x3
  177. /* Defines which affiliated errors lead to a port reset */
  178. #define EHEA_AER_RESET_MASK 0xFFFFFFFFFEFFFFFFULL
  179. #define EHEA_AERR_RESET_MASK 0xFFFFFFFFFFFFFFFFULL
  180. struct ehea_eqe {
  181. u64 entry;
  182. };
  183. #define ERROR_DATA_LENGTH EHEA_BMASK_IBM(52, 63)
  184. #define ERROR_DATA_TYPE EHEA_BMASK_IBM(0, 7)
  185. static inline void *hw_qeit_calc(struct hw_queue *queue, u64 q_offset)
  186. {
  187. struct ehea_page *current_page;
  188. if (q_offset >= queue->queue_length)
  189. q_offset -= queue->queue_length;
  190. current_page = (queue->queue_pages)[q_offset >> EHEA_PAGESHIFT];
  191. return &current_page->entries[q_offset & (EHEA_PAGESIZE - 1)];
  192. }
  193. static inline void *hw_qeit_get(struct hw_queue *queue)
  194. {
  195. return hw_qeit_calc(queue, queue->current_q_offset);
  196. }
  197. static inline void hw_qeit_inc(struct hw_queue *queue)
  198. {
  199. queue->current_q_offset += queue->qe_size;
  200. if (queue->current_q_offset >= queue->queue_length) {
  201. queue->current_q_offset = 0;
  202. /* toggle the valid flag */
  203. queue->toggle_state = (~queue->toggle_state) & 1;
  204. }
  205. }
  206. static inline void *hw_qeit_get_inc(struct hw_queue *queue)
  207. {
  208. void *retvalue = hw_qeit_get(queue);
  209. hw_qeit_inc(queue);
  210. return retvalue;
  211. }
  212. static inline void *hw_qeit_get_inc_valid(struct hw_queue *queue)
  213. {
  214. struct ehea_cqe *retvalue = hw_qeit_get(queue);
  215. u8 valid = retvalue->valid;
  216. void *pref;
  217. if ((valid >> 7) == (queue->toggle_state & 1)) {
  218. /* this is a good one */
  219. hw_qeit_inc(queue);
  220. pref = hw_qeit_calc(queue, queue->current_q_offset);
  221. prefetch(pref);
  222. prefetch(pref + 128);
  223. } else
  224. retvalue = NULL;
  225. return retvalue;
  226. }
  227. static inline void *hw_qeit_get_valid(struct hw_queue *queue)
  228. {
  229. struct ehea_cqe *retvalue = hw_qeit_get(queue);
  230. void *pref;
  231. u8 valid;
  232. pref = hw_qeit_calc(queue, queue->current_q_offset);
  233. prefetch(pref);
  234. prefetch(pref + 128);
  235. prefetch(pref + 256);
  236. valid = retvalue->valid;
  237. if (!((valid >> 7) == (queue->toggle_state & 1)))
  238. retvalue = NULL;
  239. return retvalue;
  240. }
  241. static inline void *hw_qeit_reset(struct hw_queue *queue)
  242. {
  243. queue->current_q_offset = 0;
  244. return hw_qeit_get(queue);
  245. }
  246. static inline void *hw_qeit_eq_get_inc(struct hw_queue *queue)
  247. {
  248. u64 last_entry_in_q = queue->queue_length - queue->qe_size;
  249. void *retvalue;
  250. retvalue = hw_qeit_get(queue);
  251. queue->current_q_offset += queue->qe_size;
  252. if (queue->current_q_offset > last_entry_in_q) {
  253. queue->current_q_offset = 0;
  254. queue->toggle_state = (~queue->toggle_state) & 1;
  255. }
  256. return retvalue;
  257. }
  258. static inline void *hw_eqit_eq_get_inc_valid(struct hw_queue *queue)
  259. {
  260. void *retvalue = hw_qeit_get(queue);
  261. u32 qe = *(u8 *)retvalue;
  262. if ((qe >> 7) == (queue->toggle_state & 1))
  263. hw_qeit_eq_get_inc(queue);
  264. else
  265. retvalue = NULL;
  266. return retvalue;
  267. }
  268. static inline struct ehea_rwqe *ehea_get_next_rwqe(struct ehea_qp *qp,
  269. int rq_nr)
  270. {
  271. struct hw_queue *queue;
  272. if (rq_nr == 1)
  273. queue = &qp->hw_rqueue1;
  274. else if (rq_nr == 2)
  275. queue = &qp->hw_rqueue2;
  276. else
  277. queue = &qp->hw_rqueue3;
  278. return hw_qeit_get_inc(queue);
  279. }
  280. static inline struct ehea_swqe *ehea_get_swqe(struct ehea_qp *my_qp,
  281. int *wqe_index)
  282. {
  283. struct hw_queue *queue = &my_qp->hw_squeue;
  284. struct ehea_swqe *wqe_p;
  285. *wqe_index = (queue->current_q_offset) >> (7 + EHEA_SG_SQ);
  286. wqe_p = hw_qeit_get_inc(&my_qp->hw_squeue);
  287. return wqe_p;
  288. }
  289. static inline void ehea_post_swqe(struct ehea_qp *my_qp, struct ehea_swqe *swqe)
  290. {
  291. iosync();
  292. ehea_update_sqa(my_qp, 1);
  293. }
  294. static inline struct ehea_cqe *ehea_poll_rq1(struct ehea_qp *qp, int *wqe_index)
  295. {
  296. struct hw_queue *queue = &qp->hw_rqueue1;
  297. *wqe_index = (queue->current_q_offset) >> (7 + EHEA_SG_RQ1);
  298. return hw_qeit_get_valid(queue);
  299. }
  300. static inline void ehea_inc_cq(struct ehea_cq *cq)
  301. {
  302. hw_qeit_inc(&cq->hw_queue);
  303. }
  304. static inline void ehea_inc_rq1(struct ehea_qp *qp)
  305. {
  306. hw_qeit_inc(&qp->hw_rqueue1);
  307. }
  308. static inline struct ehea_cqe *ehea_poll_cq(struct ehea_cq *my_cq)
  309. {
  310. return hw_qeit_get_valid(&my_cq->hw_queue);
  311. }
  312. #define EHEA_CQ_REGISTER_ORIG 0
  313. #define EHEA_EQ_REGISTER_ORIG 0
  314. enum ehea_eq_type {
  315. EHEA_EQ = 0, /* event queue */
  316. EHEA_NEQ /* notification event queue */
  317. };
  318. struct ehea_eq *ehea_create_eq(struct ehea_adapter *adapter,
  319. enum ehea_eq_type type,
  320. const u32 length, const u8 eqe_gen);
  321. int ehea_destroy_eq(struct ehea_eq *eq);
  322. struct ehea_eqe *ehea_poll_eq(struct ehea_eq *eq);
  323. struct ehea_cq *ehea_create_cq(struct ehea_adapter *adapter, int cqe,
  324. u64 eq_handle, u32 cq_token);
  325. int ehea_destroy_cq(struct ehea_cq *cq);
  326. struct ehea_qp *ehea_create_qp(struct ehea_adapter *adapter, u32 pd,
  327. struct ehea_qp_init_attr *init_attr);
  328. int ehea_destroy_qp(struct ehea_qp *qp);
  329. int ehea_reg_kernel_mr(struct ehea_adapter *adapter, struct ehea_mr *mr);
  330. int ehea_gen_smr(struct ehea_adapter *adapter, struct ehea_mr *old_mr,
  331. struct ehea_mr *shared_mr);
  332. int ehea_rem_mr(struct ehea_mr *mr);
  333. u64 ehea_error_data(struct ehea_adapter *adapter, u64 res_handle,
  334. u64 *aer, u64 *aerr);
  335. int ehea_add_sect_bmap(unsigned long pfn, unsigned long nr_pages);
  336. int ehea_rem_sect_bmap(unsigned long pfn, unsigned long nr_pages);
  337. int ehea_create_busmap(void);
  338. void ehea_destroy_busmap(void);
  339. u64 ehea_map_vaddr(void *caddr);
  340. #endif /* __EHEA_QMR_H__ */