cxgb3i_ddp.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /*
  2. * cxgb3i_ddp.h: Chelsio S3xx iSCSI DDP Manager.
  3. *
  4. * Copyright (c) 2008 Chelsio Communications, Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation.
  9. *
  10. * Written by: Karen Xie (kxie@chelsio.com)
  11. */
  12. #ifndef __CXGB3I_ULP2_DDP_H__
  13. #define __CXGB3I_ULP2_DDP_H__
  14. /**
  15. * struct cxgb3i_tag_format - cxgb3i ulp tag format for an iscsi entity
  16. *
  17. * @sw_bits: # of bits used by iscsi software layer
  18. * @rsvd_bits: # of bits used by h/w
  19. * @rsvd_shift: h/w bits shift left
  20. * @rsvd_mask: reserved bit mask
  21. */
  22. struct cxgb3i_tag_format {
  23. unsigned char sw_bits;
  24. unsigned char rsvd_bits;
  25. unsigned char rsvd_shift;
  26. unsigned char filler[1];
  27. u32 rsvd_mask;
  28. };
  29. /**
  30. * struct cxgb3i_gather_list - cxgb3i direct data placement memory
  31. *
  32. * @tag: ddp tag
  33. * @length: total data buffer length
  34. * @offset: initial offset to the 1st page
  35. * @nelem: # of pages
  36. * @pages: page pointers
  37. * @phys_addr: physical address
  38. */
  39. struct cxgb3i_gather_list {
  40. u32 tag;
  41. unsigned int length;
  42. unsigned int offset;
  43. unsigned int nelem;
  44. struct page **pages;
  45. dma_addr_t phys_addr[0];
  46. };
  47. /**
  48. * struct cxgb3i_ddp_info - cxgb3i direct data placement for pdu payload
  49. *
  50. * @list: list head to link elements
  51. * @tdev: pointer to t3cdev used by cxgb3 driver
  52. * @max_txsz: max tx packet size for ddp
  53. * @max_rxsz: max rx packet size for ddp
  54. * @llimit: lower bound of the page pod memory
  55. * @ulimit: upper bound of the page pod memory
  56. * @nppods: # of page pod entries
  57. * @idx_last: page pod entry last used
  58. * @idx_bits: # of bits the pagepod index would take
  59. * @idx_mask: pagepod index mask
  60. * @rsvd_tag_mask: tag mask
  61. * @map_lock: lock to synchonize access to the page pod map
  62. * @gl_map: ddp memory gather list
  63. * @gl_skb: skb used to program the pagepod
  64. */
  65. struct cxgb3i_ddp_info {
  66. struct list_head list;
  67. struct t3cdev *tdev;
  68. struct pci_dev *pdev;
  69. unsigned int max_txsz;
  70. unsigned int max_rxsz;
  71. unsigned int llimit;
  72. unsigned int ulimit;
  73. unsigned int nppods;
  74. unsigned int idx_last;
  75. unsigned char idx_bits;
  76. unsigned char filler[3];
  77. u32 idx_mask;
  78. u32 rsvd_tag_mask;
  79. spinlock_t map_lock;
  80. struct cxgb3i_gather_list **gl_map;
  81. struct sk_buff **gl_skb;
  82. };
  83. #define ULP2_MAX_PKT_SIZE 16224
  84. #define ULP2_MAX_PDU_PAYLOAD (ULP2_MAX_PKT_SIZE - ISCSI_PDU_NONPAYLOAD_MAX)
  85. #define PPOD_PAGES_MAX 4
  86. #define PPOD_PAGES_SHIFT 2 /* 4 pages per pod */
  87. /*
  88. * struct pagepod_hdr, pagepod - pagepod format
  89. */
  90. struct pagepod_hdr {
  91. u32 vld_tid;
  92. u32 pgsz_tag_clr;
  93. u32 maxoffset;
  94. u32 pgoffset;
  95. u64 rsvd;
  96. };
  97. struct pagepod {
  98. struct pagepod_hdr hdr;
  99. u64 addr[PPOD_PAGES_MAX + 1];
  100. };
  101. #define PPOD_SIZE sizeof(struct pagepod) /* 64 */
  102. #define PPOD_SIZE_SHIFT 6
  103. #define PPOD_COLOR_SHIFT 0
  104. #define PPOD_COLOR_SIZE 6
  105. #define PPOD_COLOR_MASK ((1 << PPOD_COLOR_SIZE) - 1)
  106. #define PPOD_IDX_SHIFT PPOD_COLOR_SIZE
  107. #define PPOD_IDX_MAX_SIZE 24
  108. #define S_PPOD_TID 0
  109. #define M_PPOD_TID 0xFFFFFF
  110. #define V_PPOD_TID(x) ((x) << S_PPOD_TID)
  111. #define S_PPOD_VALID 24
  112. #define V_PPOD_VALID(x) ((x) << S_PPOD_VALID)
  113. #define F_PPOD_VALID V_PPOD_VALID(1U)
  114. #define S_PPOD_COLOR 0
  115. #define M_PPOD_COLOR 0x3F
  116. #define V_PPOD_COLOR(x) ((x) << S_PPOD_COLOR)
  117. #define S_PPOD_TAG 6
  118. #define M_PPOD_TAG 0xFFFFFF
  119. #define V_PPOD_TAG(x) ((x) << S_PPOD_TAG)
  120. #define S_PPOD_PGSZ 30
  121. #define M_PPOD_PGSZ 0x3
  122. #define V_PPOD_PGSZ(x) ((x) << S_PPOD_PGSZ)
  123. /*
  124. * large memory chunk allocation/release
  125. * use vmalloc() if kmalloc() fails
  126. */
  127. static inline void *cxgb3i_alloc_big_mem(unsigned int size,
  128. gfp_t gfp)
  129. {
  130. void *p = kmalloc(size, gfp);
  131. if (!p)
  132. p = vmalloc(size);
  133. if (p)
  134. memset(p, 0, size);
  135. return p;
  136. }
  137. static inline void cxgb3i_free_big_mem(void *addr)
  138. {
  139. if (is_vmalloc_addr(addr))
  140. vfree(addr);
  141. else
  142. kfree(addr);
  143. }
  144. /*
  145. * cxgb3i ddp tag are 32 bits, it consists of reserved bits used by h/w and
  146. * non-reserved bits that can be used by the iscsi s/w.
  147. * The reserved bits are identified by the rsvd_bits and rsvd_shift fields
  148. * in struct cxgb3i_tag_format.
  149. *
  150. * The upper most reserved bit can be used to check if a tag is ddp tag or not:
  151. * if the bit is 0, the tag is a valid ddp tag
  152. */
  153. /**
  154. * cxgb3i_is_ddp_tag - check if a given tag is a hw/ddp tag
  155. * @tformat: tag format information
  156. * @tag: tag to be checked
  157. *
  158. * return true if the tag is a ddp tag, false otherwise.
  159. */
  160. static inline int cxgb3i_is_ddp_tag(struct cxgb3i_tag_format *tformat, u32 tag)
  161. {
  162. return !(tag & (1 << (tformat->rsvd_bits + tformat->rsvd_shift - 1)));
  163. }
  164. /**
  165. * cxgb3i_sw_tag_usable - check if a given s/w tag has enough bits left for
  166. * the reserved/hw bits
  167. * @tformat: tag format information
  168. * @sw_tag: s/w tag to be checked
  169. *
  170. * return true if the tag is a ddp tag, false otherwise.
  171. */
  172. static inline int cxgb3i_sw_tag_usable(struct cxgb3i_tag_format *tformat,
  173. u32 sw_tag)
  174. {
  175. sw_tag >>= (32 - tformat->rsvd_bits);
  176. return !sw_tag;
  177. }
  178. /**
  179. * cxgb3i_set_non_ddp_tag - mark a given s/w tag as an invalid ddp tag
  180. * @tformat: tag format information
  181. * @sw_tag: s/w tag to be checked
  182. *
  183. * insert 1 at the upper most reserved bit to mark it as an invalid ddp tag.
  184. */
  185. static inline u32 cxgb3i_set_non_ddp_tag(struct cxgb3i_tag_format *tformat,
  186. u32 sw_tag)
  187. {
  188. unsigned char shift = tformat->rsvd_bits + tformat->rsvd_shift - 1;
  189. u32 mask = (1 << shift) - 1;
  190. if (sw_tag && (sw_tag & ~mask)) {
  191. u32 v1 = sw_tag & ((1 << shift) - 1);
  192. u32 v2 = (sw_tag >> (shift - 1)) << shift;
  193. return v2 | v1 | 1 << shift;
  194. }
  195. return sw_tag | 1 << shift;
  196. }
  197. /**
  198. * cxgb3i_ddp_tag_base - shift the s/w tag bits so that reserved bits are not
  199. * used.
  200. * @tformat: tag format information
  201. * @sw_tag: s/w tag to be checked
  202. */
  203. static inline u32 cxgb3i_ddp_tag_base(struct cxgb3i_tag_format *tformat,
  204. u32 sw_tag)
  205. {
  206. u32 mask = (1 << tformat->rsvd_shift) - 1;
  207. if (sw_tag && (sw_tag & ~mask)) {
  208. u32 v1 = sw_tag & mask;
  209. u32 v2 = sw_tag >> tformat->rsvd_shift;
  210. v2 <<= tformat->rsvd_shift + tformat->rsvd_bits;
  211. return v2 | v1;
  212. }
  213. return sw_tag;
  214. }
  215. /**
  216. * cxgb3i_tag_rsvd_bits - get the reserved bits used by the h/w
  217. * @tformat: tag format information
  218. * @tag: tag to be checked
  219. *
  220. * return the reserved bits in the tag
  221. */
  222. static inline u32 cxgb3i_tag_rsvd_bits(struct cxgb3i_tag_format *tformat,
  223. u32 tag)
  224. {
  225. if (cxgb3i_is_ddp_tag(tformat, tag))
  226. return (tag >> tformat->rsvd_shift) & tformat->rsvd_mask;
  227. return 0;
  228. }
  229. /**
  230. * cxgb3i_tag_nonrsvd_bits - get the non-reserved bits used by the s/w
  231. * @tformat: tag format information
  232. * @tag: tag to be checked
  233. *
  234. * return the non-reserved bits in the tag.
  235. */
  236. static inline u32 cxgb3i_tag_nonrsvd_bits(struct cxgb3i_tag_format *tformat,
  237. u32 tag)
  238. {
  239. unsigned char shift = tformat->rsvd_bits + tformat->rsvd_shift - 1;
  240. u32 v1, v2;
  241. if (cxgb3i_is_ddp_tag(tformat, tag)) {
  242. v1 = tag & ((1 << tformat->rsvd_shift) - 1);
  243. v2 = (tag >> (shift + 1)) << tformat->rsvd_shift;
  244. } else {
  245. u32 mask = (1 << shift) - 1;
  246. tag &= ~(1 << shift);
  247. v1 = tag & mask;
  248. v2 = (tag >> 1) & ~mask;
  249. }
  250. return v1 | v2;
  251. }
  252. int cxgb3i_ddp_tag_reserve(struct t3cdev *, unsigned int tid,
  253. struct cxgb3i_tag_format *, u32 *tag,
  254. struct cxgb3i_gather_list *, gfp_t gfp);
  255. void cxgb3i_ddp_tag_release(struct t3cdev *, u32 tag);
  256. struct cxgb3i_gather_list *cxgb3i_ddp_make_gl(unsigned int xferlen,
  257. struct scatterlist *sgl,
  258. unsigned int sgcnt,
  259. struct pci_dev *pdev,
  260. gfp_t gfp);
  261. void cxgb3i_ddp_release_gl(struct cxgb3i_gather_list *gl,
  262. struct pci_dev *pdev);
  263. int cxgb3i_setup_conn_host_pagesize(struct t3cdev *, unsigned int tid,
  264. int reply);
  265. int cxgb3i_setup_conn_pagesize(struct t3cdev *, unsigned int tid, int reply,
  266. unsigned long pgsz);
  267. int cxgb3i_setup_conn_digest(struct t3cdev *, unsigned int tid,
  268. int hcrc, int dcrc, int reply);
  269. int cxgb3i_ddp_find_page_index(unsigned long pgsz);
  270. int cxgb3i_adapter_ddp_init(struct t3cdev *, struct cxgb3i_tag_format *,
  271. unsigned int *txsz, unsigned int *rxsz);
  272. void cxgb3i_adapter_ddp_cleanup(struct t3cdev *);
  273. #endif