zfcp_qdio.h 6.6 KB

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