zfcp_qdio.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. * @qdio_outb_usage: usage of outbound queue
  52. */
  53. struct zfcp_qdio_req {
  54. u8 sbtype;
  55. u8 sbal_number;
  56. u8 sbal_first;
  57. u8 sbal_last;
  58. u8 sbal_limit;
  59. u8 sbale_curr;
  60. u16 qdio_outb_usage;
  61. };
  62. /**
  63. * zfcp_qdio_sbale_req - return pointer to sbale on req_q for a request
  64. * @qdio: pointer to struct zfcp_qdio
  65. * @q_rec: pointer to struct zfcp_qdio_req
  66. * Returns: pointer to qdio_buffer_element (sbale) structure
  67. */
  68. static inline struct qdio_buffer_element *
  69. zfcp_qdio_sbale_req(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)
  70. {
  71. return &qdio->req_q[q_req->sbal_last]->element[0];
  72. }
  73. /**
  74. * zfcp_qdio_sbale_curr - return current sbale on req_q for a request
  75. * @qdio: pointer to struct zfcp_qdio
  76. * @fsf_req: pointer to struct zfcp_fsf_req
  77. * Returns: pointer to qdio_buffer_element (sbale) structure
  78. */
  79. static inline struct qdio_buffer_element *
  80. zfcp_qdio_sbale_curr(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)
  81. {
  82. return &qdio->req_q[q_req->sbal_last]->element[q_req->sbale_curr];
  83. }
  84. /**
  85. * zfcp_qdio_req_init - initialize qdio request
  86. * @qdio: request queue where to start putting the request
  87. * @q_req: the qdio request to start
  88. * @req_id: The request id
  89. * @sbtype: type flags to set for all sbals
  90. * @data: First data block
  91. * @len: Length of first data block
  92. *
  93. * This is the start of putting the request into the queue, the last
  94. * step is passing the request to zfcp_qdio_send. The request queue
  95. * lock must be held during the whole process from init to send.
  96. */
  97. static inline
  98. void zfcp_qdio_req_init(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req,
  99. unsigned long req_id, u8 sbtype, void *data, u32 len)
  100. {
  101. struct qdio_buffer_element *sbale;
  102. int count = min(atomic_read(&qdio->req_q_free),
  103. ZFCP_QDIO_MAX_SBALS_PER_REQ);
  104. q_req->sbal_first = q_req->sbal_last = qdio->req_q_idx;
  105. q_req->sbal_number = 1;
  106. q_req->sbtype = sbtype;
  107. q_req->sbale_curr = 1;
  108. q_req->sbal_limit = (q_req->sbal_first + count - 1)
  109. % QDIO_MAX_BUFFERS_PER_Q;
  110. sbale = zfcp_qdio_sbale_req(qdio, q_req);
  111. sbale->addr = (void *) req_id;
  112. sbale->eflags = 0;
  113. sbale->sflags = SBAL_SFLAGS0_COMMAND | sbtype;
  114. if (unlikely(!data))
  115. return;
  116. sbale++;
  117. sbale->addr = data;
  118. sbale->length = len;
  119. }
  120. /**
  121. * zfcp_qdio_fill_next - Fill next sbale, only for single sbal requests
  122. * @qdio: pointer to struct zfcp_qdio
  123. * @q_req: pointer to struct zfcp_queue_req
  124. *
  125. * This is only required for single sbal requests, calling it when
  126. * wrapping around to the next sbal is a bug.
  127. */
  128. static inline
  129. void zfcp_qdio_fill_next(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req,
  130. void *data, u32 len)
  131. {
  132. struct qdio_buffer_element *sbale;
  133. BUG_ON(q_req->sbale_curr == qdio->max_sbale_per_sbal - 1);
  134. q_req->sbale_curr++;
  135. sbale = zfcp_qdio_sbale_curr(qdio, q_req);
  136. sbale->addr = data;
  137. sbale->length = len;
  138. }
  139. /**
  140. * zfcp_qdio_set_sbale_last - set last entry flag in current sbale
  141. * @qdio: pointer to struct zfcp_qdio
  142. * @q_req: pointer to struct zfcp_queue_req
  143. */
  144. static inline
  145. void zfcp_qdio_set_sbale_last(struct zfcp_qdio *qdio,
  146. struct zfcp_qdio_req *q_req)
  147. {
  148. struct qdio_buffer_element *sbale;
  149. sbale = zfcp_qdio_sbale_curr(qdio, q_req);
  150. sbale->eflags |= SBAL_EFLAGS_LAST_ENTRY;
  151. }
  152. /**
  153. * zfcp_qdio_sg_one_sbal - check if one sbale is enough for sg data
  154. * @sg: The scatterlist where to check the data size
  155. *
  156. * Returns: 1 when one sbale is enough for the data in the scatterlist,
  157. * 0 if not.
  158. */
  159. static inline
  160. int zfcp_qdio_sg_one_sbale(struct scatterlist *sg)
  161. {
  162. return sg_is_last(sg) && sg->length <= ZFCP_QDIO_SBALE_LEN;
  163. }
  164. /**
  165. * zfcp_qdio_skip_to_last_sbale - skip to last sbale in sbal
  166. * @q_req: The current zfcp_qdio_req
  167. */
  168. static inline
  169. void zfcp_qdio_skip_to_last_sbale(struct zfcp_qdio *qdio,
  170. struct zfcp_qdio_req *q_req)
  171. {
  172. q_req->sbale_curr = qdio->max_sbale_per_sbal - 1;
  173. }
  174. /**
  175. * zfcp_qdio_sbal_limit - set the sbal limit for a request in q_req
  176. * @qdio: pointer to struct zfcp_qdio
  177. * @q_req: The current zfcp_qdio_req
  178. * @max_sbals: maximum number of SBALs allowed
  179. */
  180. static inline
  181. void zfcp_qdio_sbal_limit(struct zfcp_qdio *qdio,
  182. struct zfcp_qdio_req *q_req, int max_sbals)
  183. {
  184. int count = min(atomic_read(&qdio->req_q_free), max_sbals);
  185. q_req->sbal_limit = (q_req->sbal_first + count - 1) %
  186. QDIO_MAX_BUFFERS_PER_Q;
  187. }
  188. /**
  189. * zfcp_qdio_set_data_div - set data division count
  190. * @qdio: pointer to struct zfcp_qdio
  191. * @q_req: The current zfcp_qdio_req
  192. * @count: The data division count
  193. */
  194. static inline
  195. void zfcp_qdio_set_data_div(struct zfcp_qdio *qdio,
  196. struct zfcp_qdio_req *q_req, u32 count)
  197. {
  198. struct qdio_buffer_element *sbale;
  199. sbale = qdio->req_q[q_req->sbal_first]->element;
  200. sbale->length = count;
  201. }
  202. /**
  203. * zfcp_qdio_real_bytes - count bytes used
  204. * @sg: pointer to struct scatterlist
  205. */
  206. static inline
  207. unsigned int zfcp_qdio_real_bytes(struct scatterlist *sg)
  208. {
  209. unsigned int real_bytes = 0;
  210. for (; sg; sg = sg_next(sg))
  211. real_bytes += sg->length;
  212. return real_bytes;
  213. }
  214. /**
  215. * zfcp_qdio_set_scount - set SBAL count value
  216. * @qdio: pointer to struct zfcp_qdio
  217. * @q_req: The current zfcp_qdio_req
  218. */
  219. static inline
  220. void zfcp_qdio_set_scount(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)
  221. {
  222. struct qdio_buffer_element *sbale;
  223. sbale = qdio->req_q[q_req->sbal_first]->element;
  224. sbale->scount = q_req->sbal_number - 1;
  225. }
  226. #endif /* ZFCP_QDIO_H */