zfcp_qdio.h 6.8 KB

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