zfcp_qdio.h 5.8 KB

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