zfcp_qdio.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. * zfcp device driver
  3. *
  4. * Header file for zfcp qdio interface
  5. *
  6. * Copyright IBM Corp. 2010
  7. */
  8. #ifndef ZFCP_QDIO_H
  9. #define ZFCP_QDIO_H
  10. #include <asm/qdio.h>
  11. #define ZFCP_QDIO_SBALE_LEN PAGE_SIZE
  12. /* Max SBALS for chaining */
  13. #define ZFCP_QDIO_MAX_SBALS_PER_REQ 36
  14. /**
  15. * struct zfcp_qdio - basic qdio data structure
  16. * @res_q: response queue
  17. * @req_q: request queue
  18. * @req_q_idx: index of next free buffer
  19. * @req_q_free: number of free buffers in queue
  20. * @stat_lock: lock to protect req_q_util and req_q_time
  21. * @req_q_lock: lock to serialize access to request queue
  22. * @req_q_time: time of last fill level change
  23. * @req_q_util: used for accounting
  24. * @req_q_full: queue full incidents
  25. * @req_q_wq: used to wait for SBAL availability
  26. * @adapter: adapter used in conjunction with this qdio structure
  27. */
  28. struct zfcp_qdio {
  29. struct qdio_buffer *res_q[QDIO_MAX_BUFFERS_PER_Q];
  30. struct qdio_buffer *req_q[QDIO_MAX_BUFFERS_PER_Q];
  31. u8 req_q_idx;
  32. atomic_t req_q_free;
  33. spinlock_t stat_lock;
  34. spinlock_t req_q_lock;
  35. unsigned long long req_q_time;
  36. u64 req_q_util;
  37. atomic_t req_q_full;
  38. wait_queue_head_t req_q_wq;
  39. struct zfcp_adapter *adapter;
  40. u16 max_sbale_per_sbal;
  41. u16 max_sbale_per_req;
  42. };
  43. /**
  44. * struct zfcp_qdio_req - qdio queue related values for a request
  45. * @sbtype: sbal type flags for sbale 0
  46. * @sbal_number: number of free sbals
  47. * @sbal_first: first sbal for this request
  48. * @sbal_last: last sbal for this request
  49. * @sbal_limit: last possible sbal for this request
  50. * @sbale_curr: current sbale at creation of this request
  51. * @sbal_response: sbal used in interrupt
  52. * @qdio_outb_usage: usage of outbound queue
  53. */
  54. struct zfcp_qdio_req {
  55. u8 sbtype;
  56. u8 sbal_number;
  57. u8 sbal_first;
  58. u8 sbal_last;
  59. u8 sbal_limit;
  60. u8 sbale_curr;
  61. u8 sbal_response;
  62. u16 qdio_outb_usage;
  63. };
  64. /**
  65. * zfcp_qdio_sbale_req - return pointer to sbale on req_q for a request
  66. * @qdio: pointer to struct zfcp_qdio
  67. * @q_rec: pointer to struct zfcp_qdio_req
  68. * Returns: pointer to qdio_buffer_element (sbale) structure
  69. */
  70. static inline struct qdio_buffer_element *
  71. zfcp_qdio_sbale_req(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)
  72. {
  73. return &qdio->req_q[q_req->sbal_last]->element[0];
  74. }
  75. /**
  76. * zfcp_qdio_sbale_curr - return current sbale on req_q for a request
  77. * @qdio: pointer to struct zfcp_qdio
  78. * @fsf_req: pointer to struct zfcp_fsf_req
  79. * Returns: pointer to qdio_buffer_element (sbale) structure
  80. */
  81. static inline struct qdio_buffer_element *
  82. zfcp_qdio_sbale_curr(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)
  83. {
  84. return &qdio->req_q[q_req->sbal_last]->element[q_req->sbale_curr];
  85. }
  86. /**
  87. * zfcp_qdio_req_init - initialize qdio request
  88. * @qdio: request queue where to start putting the request
  89. * @q_req: the qdio request to start
  90. * @req_id: The request id
  91. * @sbtype: type flags to set for all sbals
  92. * @data: First data block
  93. * @len: Length of first data block
  94. *
  95. * This is the start of putting the request into the queue, the last
  96. * step is passing the request to zfcp_qdio_send. The request queue
  97. * lock must be held during the whole process from init to send.
  98. */
  99. static inline
  100. void zfcp_qdio_req_init(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req,
  101. unsigned long req_id, u8 sbtype, void *data, u32 len)
  102. {
  103. struct qdio_buffer_element *sbale;
  104. int count = min(atomic_read(&qdio->req_q_free),
  105. ZFCP_QDIO_MAX_SBALS_PER_REQ);
  106. q_req->sbal_first = q_req->sbal_last = qdio->req_q_idx;
  107. q_req->sbal_number = 1;
  108. q_req->sbtype = sbtype;
  109. q_req->sbale_curr = 1;
  110. q_req->sbal_limit = (q_req->sbal_first + count - 1)
  111. % QDIO_MAX_BUFFERS_PER_Q;
  112. sbale = zfcp_qdio_sbale_req(qdio, q_req);
  113. sbale->addr = (void *) req_id;
  114. sbale->eflags = 0;
  115. sbale->sflags = SBAL_SFLAGS0_COMMAND | sbtype;
  116. if (unlikely(!data))
  117. return;
  118. sbale++;
  119. sbale->addr = data;
  120. sbale->length = len;
  121. }
  122. /**
  123. * zfcp_qdio_fill_next - Fill next sbale, only for single sbal requests
  124. * @qdio: pointer to struct zfcp_qdio
  125. * @q_req: pointer to struct zfcp_queue_req
  126. *
  127. * This is only required for single sbal requests, calling it when
  128. * wrapping around to the next sbal is a bug.
  129. */
  130. static inline
  131. void zfcp_qdio_fill_next(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req,
  132. void *data, u32 len)
  133. {
  134. struct qdio_buffer_element *sbale;
  135. BUG_ON(q_req->sbale_curr == qdio->max_sbale_per_sbal - 1);
  136. q_req->sbale_curr++;
  137. sbale = zfcp_qdio_sbale_curr(qdio, q_req);
  138. sbale->addr = data;
  139. sbale->length = len;
  140. }
  141. /**
  142. * zfcp_qdio_set_sbale_last - set last entry flag in current sbale
  143. * @qdio: pointer to struct zfcp_qdio
  144. * @q_req: pointer to struct zfcp_queue_req
  145. */
  146. static inline
  147. void zfcp_qdio_set_sbale_last(struct zfcp_qdio *qdio,
  148. struct zfcp_qdio_req *q_req)
  149. {
  150. struct qdio_buffer_element *sbale;
  151. sbale = zfcp_qdio_sbale_curr(qdio, q_req);
  152. sbale->eflags |= SBAL_EFLAGS_LAST_ENTRY;
  153. }
  154. /**
  155. * zfcp_qdio_sg_one_sbal - check if one sbale is enough for sg data
  156. * @sg: The scatterlist where to check the data size
  157. *
  158. * Returns: 1 when one sbale is enough for the data in the scatterlist,
  159. * 0 if not.
  160. */
  161. static inline
  162. int zfcp_qdio_sg_one_sbale(struct scatterlist *sg)
  163. {
  164. return sg_is_last(sg) && sg->length <= ZFCP_QDIO_SBALE_LEN;
  165. }
  166. /**
  167. * zfcp_qdio_skip_to_last_sbale - skip to last sbale in sbal
  168. * @q_req: The current zfcp_qdio_req
  169. */
  170. static inline
  171. void zfcp_qdio_skip_to_last_sbale(struct zfcp_qdio *qdio,
  172. struct zfcp_qdio_req *q_req)
  173. {
  174. q_req->sbale_curr = qdio->max_sbale_per_sbal - 1;
  175. }
  176. /**
  177. * zfcp_qdio_sbal_limit - set the sbal limit for a request in q_req
  178. * @qdio: pointer to struct zfcp_qdio
  179. * @q_req: The current zfcp_qdio_req
  180. * @max_sbals: maximum number of SBALs allowed
  181. */
  182. static inline
  183. void zfcp_qdio_sbal_limit(struct zfcp_qdio *qdio,
  184. struct zfcp_qdio_req *q_req, int max_sbals)
  185. {
  186. int count = min(atomic_read(&qdio->req_q_free), max_sbals);
  187. q_req->sbal_limit = (q_req->sbal_first + count - 1) %
  188. QDIO_MAX_BUFFERS_PER_Q;
  189. }
  190. /**
  191. * zfcp_qdio_set_data_div - set data division count
  192. * @qdio: pointer to struct zfcp_qdio
  193. * @q_req: The current zfcp_qdio_req
  194. * @count: The data division count
  195. */
  196. static inline
  197. void zfcp_qdio_set_data_div(struct zfcp_qdio *qdio,
  198. struct zfcp_qdio_req *q_req, u32 count)
  199. {
  200. struct qdio_buffer_element *sbale;
  201. sbale = qdio->req_q[q_req->sbal_first]->element;
  202. sbale->length = count;
  203. }
  204. /**
  205. * zfcp_qdio_sbale_count - count sbale used
  206. * @sg: pointer to struct scatterlist
  207. */
  208. static inline
  209. unsigned int zfcp_qdio_sbale_count(struct scatterlist *sg)
  210. {
  211. unsigned int count = 0;
  212. for (; sg; sg = sg_next(sg))
  213. count++;
  214. return count;
  215. }
  216. /**
  217. * zfcp_qdio_real_bytes - count bytes used
  218. * @sg: pointer to struct scatterlist
  219. */
  220. static inline
  221. unsigned int zfcp_qdio_real_bytes(struct scatterlist *sg)
  222. {
  223. unsigned int real_bytes = 0;
  224. for (; sg; sg = sg_next(sg))
  225. real_bytes += sg->length;
  226. return real_bytes;
  227. }
  228. /**
  229. * zfcp_qdio_set_scount - set SBAL count value
  230. * @qdio: pointer to struct zfcp_qdio
  231. * @q_req: The current zfcp_qdio_req
  232. */
  233. static inline
  234. void zfcp_qdio_set_scount(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)
  235. {
  236. struct qdio_buffer_element *sbale;
  237. sbale = qdio->req_q[q_req->sbal_first]->element;
  238. sbale->scount = q_req->sbal_number - 1;
  239. }
  240. #endif /* ZFCP_QDIO_H */