cxgb3i_ddp.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. #include <linux/vmalloc.h>
  15. /**
  16. * struct cxgb3i_tag_format - cxgb3i ulp tag format for an iscsi entity
  17. *
  18. * @sw_bits: # of bits used by iscsi software layer
  19. * @rsvd_bits: # of bits used by h/w
  20. * @rsvd_shift: h/w bits shift left
  21. * @rsvd_mask: reserved bit mask
  22. */
  23. struct cxgb3i_tag_format {
  24. unsigned char sw_bits;
  25. unsigned char rsvd_bits;
  26. unsigned char rsvd_shift;
  27. unsigned char filler[1];
  28. u32 rsvd_mask;
  29. };
  30. /**
  31. * struct cxgb3i_gather_list - cxgb3i direct data placement memory
  32. *
  33. * @tag: ddp tag
  34. * @length: total data buffer length
  35. * @offset: initial offset to the 1st page
  36. * @nelem: # of pages
  37. * @pages: page pointers
  38. * @phys_addr: physical address
  39. */
  40. struct cxgb3i_gather_list {
  41. u32 tag;
  42. unsigned int length;
  43. unsigned int offset;
  44. unsigned int nelem;
  45. struct page **pages;
  46. dma_addr_t phys_addr[0];
  47. };
  48. /**
  49. * struct cxgb3i_ddp_info - cxgb3i direct data placement for pdu payload
  50. *
  51. * @list: list head to link elements
  52. * @tdev: pointer to t3cdev used by cxgb3 driver
  53. * @max_txsz: max tx packet size for ddp
  54. * @max_rxsz: max rx packet size for ddp
  55. * @llimit: lower bound of the page pod memory
  56. * @ulimit: upper bound of the page pod memory
  57. * @nppods: # of page pod entries
  58. * @idx_last: page pod entry last used
  59. * @idx_bits: # of bits the pagepod index would take
  60. * @idx_mask: pagepod index mask
  61. * @rsvd_tag_mask: tag mask
  62. * @map_lock: lock to synchonize access to the page pod map
  63. * @gl_map: ddp memory gather list
  64. * @gl_skb: skb used to program the pagepod
  65. */
  66. struct cxgb3i_ddp_info {
  67. struct list_head list;
  68. struct t3cdev *tdev;
  69. struct pci_dev *pdev;
  70. unsigned int max_txsz;
  71. unsigned int max_rxsz;
  72. unsigned int llimit;
  73. unsigned int ulimit;
  74. unsigned int nppods;
  75. unsigned int idx_last;
  76. unsigned char idx_bits;
  77. unsigned char filler[3];
  78. u32 idx_mask;
  79. u32 rsvd_tag_mask;
  80. spinlock_t map_lock;
  81. struct cxgb3i_gather_list **gl_map;
  82. struct sk_buff **gl_skb;
  83. };
  84. #define ISCSI_PDU_NONPAYLOAD_LEN 312 /* bhs(48) + ahs(256) + digest(8) */
  85. #define ULP2_MAX_PKT_SIZE 16224
  86. #define ULP2_MAX_PDU_PAYLOAD (ULP2_MAX_PKT_SIZE - ISCSI_PDU_NONPAYLOAD_LEN)
  87. #define PPOD_PAGES_MAX 4
  88. #define PPOD_PAGES_SHIFT 2 /* 4 pages per pod */
  89. /*
  90. * struct pagepod_hdr, pagepod - pagepod format
  91. */
  92. struct pagepod_hdr {
  93. u32 vld_tid;
  94. u32 pgsz_tag_clr;
  95. u32 maxoffset;
  96. u32 pgoffset;
  97. u64 rsvd;
  98. };
  99. struct pagepod {
  100. struct pagepod_hdr hdr;
  101. u64 addr[PPOD_PAGES_MAX + 1];
  102. };
  103. #define PPOD_SIZE sizeof(struct pagepod) /* 64 */
  104. #define PPOD_SIZE_SHIFT 6
  105. #define PPOD_COLOR_SHIFT 0
  106. #define PPOD_COLOR_SIZE 6
  107. #define PPOD_COLOR_MASK ((1 << PPOD_COLOR_SIZE) - 1)
  108. #define PPOD_IDX_SHIFT PPOD_COLOR_SIZE
  109. #define PPOD_IDX_MAX_SIZE 24
  110. #define S_PPOD_TID 0
  111. #define M_PPOD_TID 0xFFFFFF
  112. #define V_PPOD_TID(x) ((x) << S_PPOD_TID)
  113. #define S_PPOD_VALID 24
  114. #define V_PPOD_VALID(x) ((x) << S_PPOD_VALID)
  115. #define F_PPOD_VALID V_PPOD_VALID(1U)
  116. #define S_PPOD_COLOR 0
  117. #define M_PPOD_COLOR 0x3F
  118. #define V_PPOD_COLOR(x) ((x) << S_PPOD_COLOR)
  119. #define S_PPOD_TAG 6
  120. #define M_PPOD_TAG 0xFFFFFF
  121. #define V_PPOD_TAG(x) ((x) << S_PPOD_TAG)
  122. #define S_PPOD_PGSZ 30
  123. #define M_PPOD_PGSZ 0x3
  124. #define V_PPOD_PGSZ(x) ((x) << S_PPOD_PGSZ)
  125. /*
  126. * large memory chunk allocation/release
  127. * use vmalloc() if kmalloc() fails
  128. */
  129. static inline void *cxgb3i_alloc_big_mem(unsigned int size,
  130. gfp_t gfp)
  131. {
  132. void *p = kmalloc(size, gfp);
  133. if (!p)
  134. p = vmalloc(size);
  135. if (p)
  136. memset(p, 0, size);
  137. return p;
  138. }
  139. static inline void cxgb3i_free_big_mem(void *addr)
  140. {
  141. if (is_vmalloc_addr(addr))
  142. vfree(addr);
  143. else
  144. kfree(addr);
  145. }
  146. /*
  147. * cxgb3i ddp tag are 32 bits, it consists of reserved bits used by h/w and
  148. * non-reserved bits that can be used by the iscsi s/w.
  149. * The reserved bits are identified by the rsvd_bits and rsvd_shift fields
  150. * in struct cxgb3i_tag_format.
  151. *
  152. * The upper most reserved bit can be used to check if a tag is ddp tag or not:
  153. * if the bit is 0, the tag is a valid ddp tag
  154. */
  155. /**
  156. * cxgb3i_is_ddp_tag - check if a given tag is a hw/ddp tag
  157. * @tformat: tag format information
  158. * @tag: tag to be checked
  159. *
  160. * return true if the tag is a ddp tag, false otherwise.
  161. */
  162. static inline int cxgb3i_is_ddp_tag(struct cxgb3i_tag_format *tformat, u32 tag)
  163. {
  164. return !(tag & (1 << (tformat->rsvd_bits + tformat->rsvd_shift - 1)));
  165. }
  166. /**
  167. * cxgb3i_sw_tag_usable - check if s/w tag has enough bits left for hw bits
  168. * @tformat: tag format information
  169. * @sw_tag: s/w tag to be checked
  170. *
  171. * return true if the tag can be used for hw ddp tag, false otherwise.
  172. */
  173. static inline int cxgb3i_sw_tag_usable(struct cxgb3i_tag_format *tformat,
  174. u32 sw_tag)
  175. {
  176. sw_tag >>= (32 - tformat->rsvd_bits);
  177. return !sw_tag;
  178. }
  179. /**
  180. * cxgb3i_set_non_ddp_tag - mark a given s/w tag as an invalid ddp tag
  181. * @tformat: tag format information
  182. * @sw_tag: s/w tag to be checked
  183. *
  184. * insert 1 at the upper most reserved bit to mark it as an invalid ddp tag.
  185. */
  186. static inline u32 cxgb3i_set_non_ddp_tag(struct cxgb3i_tag_format *tformat,
  187. u32 sw_tag)
  188. {
  189. unsigned char shift = tformat->rsvd_bits + tformat->rsvd_shift - 1;
  190. u32 mask = (1 << shift) - 1;
  191. if (sw_tag && (sw_tag & ~mask)) {
  192. u32 v1 = sw_tag & ((1 << shift) - 1);
  193. u32 v2 = (sw_tag >> (shift - 1)) << shift;
  194. return v2 | v1 | 1 << shift;
  195. }
  196. return sw_tag | 1 << shift;
  197. }
  198. /**
  199. * cxgb3i_ddp_tag_base - shift s/w tag bits so that reserved bits are not 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_info(struct t3cdev *, struct cxgb3i_tag_format *,
  271. unsigned int *txsz, unsigned int *rxsz);
  272. void cxgb3i_ddp_init(struct t3cdev *);
  273. void cxgb3i_ddp_cleanup(struct t3cdev *);
  274. #endif