cxgb3i_ddp.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. * @refcnt: ref. count
  53. * @tdev: pointer to t3cdev used by cxgb3 driver
  54. * @max_txsz: max tx packet size for ddp
  55. * @max_rxsz: max rx packet size for ddp
  56. * @llimit: lower bound of the page pod memory
  57. * @ulimit: upper bound of the page pod memory
  58. * @nppods: # of page pod entries
  59. * @idx_last: page pod entry last used
  60. * @idx_bits: # of bits the pagepod index would take
  61. * @idx_mask: pagepod index mask
  62. * @rsvd_tag_mask: tag mask
  63. * @map_lock: lock to synchonize access to the page pod map
  64. * @gl_map: ddp memory gather list
  65. * @gl_skb: skb used to program the pagepod
  66. */
  67. struct cxgb3i_ddp_info {
  68. struct list_head list;
  69. struct kref refcnt;
  70. struct t3cdev *tdev;
  71. struct pci_dev *pdev;
  72. unsigned int max_txsz;
  73. unsigned int max_rxsz;
  74. unsigned int llimit;
  75. unsigned int ulimit;
  76. unsigned int nppods;
  77. unsigned int idx_last;
  78. unsigned char idx_bits;
  79. unsigned char filler[3];
  80. u32 idx_mask;
  81. u32 rsvd_tag_mask;
  82. spinlock_t map_lock;
  83. struct cxgb3i_gather_list **gl_map;
  84. struct sk_buff **gl_skb;
  85. };
  86. #define ISCSI_PDU_NONPAYLOAD_LEN 312 /* bhs(48) + ahs(256) + digest(8) */
  87. #define ULP2_MAX_PKT_SIZE 16224
  88. #define ULP2_MAX_PDU_PAYLOAD (ULP2_MAX_PKT_SIZE - ISCSI_PDU_NONPAYLOAD_LEN)
  89. #define PPOD_PAGES_MAX 4
  90. #define PPOD_PAGES_SHIFT 2 /* 4 pages per pod */
  91. /*
  92. * struct pagepod_hdr, pagepod - pagepod format
  93. */
  94. struct pagepod_hdr {
  95. u32 vld_tid;
  96. u32 pgsz_tag_clr;
  97. u32 maxoffset;
  98. u32 pgoffset;
  99. u64 rsvd;
  100. };
  101. struct pagepod {
  102. struct pagepod_hdr hdr;
  103. u64 addr[PPOD_PAGES_MAX + 1];
  104. };
  105. #define PPOD_SIZE sizeof(struct pagepod) /* 64 */
  106. #define PPOD_SIZE_SHIFT 6
  107. #define PPOD_COLOR_SHIFT 0
  108. #define PPOD_COLOR_SIZE 6
  109. #define PPOD_COLOR_MASK ((1 << PPOD_COLOR_SIZE) - 1)
  110. #define PPOD_IDX_SHIFT PPOD_COLOR_SIZE
  111. #define PPOD_IDX_MAX_SIZE 24
  112. #define S_PPOD_TID 0
  113. #define M_PPOD_TID 0xFFFFFF
  114. #define V_PPOD_TID(x) ((x) << S_PPOD_TID)
  115. #define S_PPOD_VALID 24
  116. #define V_PPOD_VALID(x) ((x) << S_PPOD_VALID)
  117. #define F_PPOD_VALID V_PPOD_VALID(1U)
  118. #define S_PPOD_COLOR 0
  119. #define M_PPOD_COLOR 0x3F
  120. #define V_PPOD_COLOR(x) ((x) << S_PPOD_COLOR)
  121. #define S_PPOD_TAG 6
  122. #define M_PPOD_TAG 0xFFFFFF
  123. #define V_PPOD_TAG(x) ((x) << S_PPOD_TAG)
  124. #define S_PPOD_PGSZ 30
  125. #define M_PPOD_PGSZ 0x3
  126. #define V_PPOD_PGSZ(x) ((x) << S_PPOD_PGSZ)
  127. /*
  128. * large memory chunk allocation/release
  129. * use vmalloc() if kmalloc() fails
  130. */
  131. static inline void *cxgb3i_alloc_big_mem(unsigned int size,
  132. gfp_t gfp)
  133. {
  134. void *p = kmalloc(size, gfp);
  135. if (!p)
  136. p = vmalloc(size);
  137. if (p)
  138. memset(p, 0, size);
  139. return p;
  140. }
  141. static inline void cxgb3i_free_big_mem(void *addr)
  142. {
  143. if (is_vmalloc_addr(addr))
  144. vfree(addr);
  145. else
  146. kfree(addr);
  147. }
  148. /*
  149. * cxgb3i ddp tag are 32 bits, it consists of reserved bits used by h/w and
  150. * non-reserved bits that can be used by the iscsi s/w.
  151. * The reserved bits are identified by the rsvd_bits and rsvd_shift fields
  152. * in struct cxgb3i_tag_format.
  153. *
  154. * The upper most reserved bit can be used to check if a tag is ddp tag or not:
  155. * if the bit is 0, the tag is a valid ddp tag
  156. */
  157. /**
  158. * cxgb3i_is_ddp_tag - check if a given tag is a hw/ddp tag
  159. * @tformat: tag format information
  160. * @tag: tag to be checked
  161. *
  162. * return true if the tag is a ddp tag, false otherwise.
  163. */
  164. static inline int cxgb3i_is_ddp_tag(struct cxgb3i_tag_format *tformat, u32 tag)
  165. {
  166. return !(tag & (1 << (tformat->rsvd_bits + tformat->rsvd_shift - 1)));
  167. }
  168. /**
  169. * cxgb3i_sw_tag_usable - check if s/w tag has enough bits left for hw bits
  170. * @tformat: tag format information
  171. * @sw_tag: s/w tag to be checked
  172. *
  173. * return true if the tag can be used for hw ddp tag, false otherwise.
  174. */
  175. static inline int cxgb3i_sw_tag_usable(struct cxgb3i_tag_format *tformat,
  176. u32 sw_tag)
  177. {
  178. sw_tag >>= (32 - tformat->rsvd_bits);
  179. return !sw_tag;
  180. }
  181. /**
  182. * cxgb3i_set_non_ddp_tag - mark a given s/w tag as an invalid ddp tag
  183. * @tformat: tag format information
  184. * @sw_tag: s/w tag to be checked
  185. *
  186. * insert 1 at the upper most reserved bit to mark it as an invalid ddp tag.
  187. */
  188. static inline u32 cxgb3i_set_non_ddp_tag(struct cxgb3i_tag_format *tformat,
  189. u32 sw_tag)
  190. {
  191. unsigned char shift = tformat->rsvd_bits + tformat->rsvd_shift - 1;
  192. u32 mask = (1 << shift) - 1;
  193. if (sw_tag && (sw_tag & ~mask)) {
  194. u32 v1 = sw_tag & ((1 << shift) - 1);
  195. u32 v2 = (sw_tag >> (shift - 1)) << shift;
  196. return v2 | v1 | 1 << shift;
  197. }
  198. return sw_tag | 1 << shift;
  199. }
  200. /**
  201. * cxgb3i_ddp_tag_base - shift s/w tag bits so that reserved bits are not used
  202. * @tformat: tag format information
  203. * @sw_tag: s/w tag to be checked
  204. */
  205. static inline u32 cxgb3i_ddp_tag_base(struct cxgb3i_tag_format *tformat,
  206. u32 sw_tag)
  207. {
  208. u32 mask = (1 << tformat->rsvd_shift) - 1;
  209. if (sw_tag && (sw_tag & ~mask)) {
  210. u32 v1 = sw_tag & mask;
  211. u32 v2 = sw_tag >> tformat->rsvd_shift;
  212. v2 <<= tformat->rsvd_shift + tformat->rsvd_bits;
  213. return v2 | v1;
  214. }
  215. return sw_tag;
  216. }
  217. /**
  218. * cxgb3i_tag_rsvd_bits - get the reserved bits used by the h/w
  219. * @tformat: tag format information
  220. * @tag: tag to be checked
  221. *
  222. * return the reserved bits in the tag
  223. */
  224. static inline u32 cxgb3i_tag_rsvd_bits(struct cxgb3i_tag_format *tformat,
  225. u32 tag)
  226. {
  227. if (cxgb3i_is_ddp_tag(tformat, tag))
  228. return (tag >> tformat->rsvd_shift) & tformat->rsvd_mask;
  229. return 0;
  230. }
  231. /**
  232. * cxgb3i_tag_nonrsvd_bits - get the non-reserved bits used by the s/w
  233. * @tformat: tag format information
  234. * @tag: tag to be checked
  235. *
  236. * return the non-reserved bits in the tag.
  237. */
  238. static inline u32 cxgb3i_tag_nonrsvd_bits(struct cxgb3i_tag_format *tformat,
  239. u32 tag)
  240. {
  241. unsigned char shift = tformat->rsvd_bits + tformat->rsvd_shift - 1;
  242. u32 v1, v2;
  243. if (cxgb3i_is_ddp_tag(tformat, tag)) {
  244. v1 = tag & ((1 << tformat->rsvd_shift) - 1);
  245. v2 = (tag >> (shift + 1)) << tformat->rsvd_shift;
  246. } else {
  247. u32 mask = (1 << shift) - 1;
  248. tag &= ~(1 << shift);
  249. v1 = tag & mask;
  250. v2 = (tag >> 1) & ~mask;
  251. }
  252. return v1 | v2;
  253. }
  254. int cxgb3i_ddp_tag_reserve(struct t3cdev *, unsigned int tid,
  255. struct cxgb3i_tag_format *, u32 *tag,
  256. struct cxgb3i_gather_list *, gfp_t gfp);
  257. void cxgb3i_ddp_tag_release(struct t3cdev *, u32 tag);
  258. struct cxgb3i_gather_list *cxgb3i_ddp_make_gl(unsigned int xferlen,
  259. struct scatterlist *sgl,
  260. unsigned int sgcnt,
  261. struct pci_dev *pdev,
  262. gfp_t gfp);
  263. void cxgb3i_ddp_release_gl(struct cxgb3i_gather_list *gl,
  264. struct pci_dev *pdev);
  265. int cxgb3i_setup_conn_host_pagesize(struct t3cdev *, unsigned int tid,
  266. int reply);
  267. int cxgb3i_setup_conn_pagesize(struct t3cdev *, unsigned int tid, int reply,
  268. unsigned long pgsz);
  269. int cxgb3i_setup_conn_digest(struct t3cdev *, unsigned int tid,
  270. int hcrc, int dcrc, int reply);
  271. int cxgb3i_ddp_find_page_index(unsigned long pgsz);
  272. int cxgb3i_adapter_ddp_info(struct t3cdev *, struct cxgb3i_tag_format *,
  273. unsigned int *txsz, unsigned int *rxsz);
  274. void cxgb3i_ddp_init(struct t3cdev *);
  275. void cxgb3i_ddp_cleanup(struct t3cdev *);
  276. #endif