1 /* SPDX-License-Identifier: GPL-2.0 */
5 * Header file for zfcp qdio interface
7 * Copyright IBM Corp. 2010
15 #define ZFCP_QDIO_SBALE_LEN PAGE_SIZE
17 /* Max SBALS for chaining */
18 #define ZFCP_QDIO_MAX_SBALS_PER_REQ 36
21 * struct zfcp_qdio - basic qdio data structure
22 * @res_q: response queue
23 * @req_q: request queue
24 * @req_q_idx: index of next free buffer
25 * @req_q_free: number of free buffers in queue
26 * @stat_lock: lock to protect req_q_util and req_q_time
27 * @req_q_lock: lock to serialize access to request queue
28 * @req_q_time: time of last fill level change
29 * @req_q_util: used for accounting
30 * @req_q_full: queue full incidents
31 * @req_q_wq: used to wait for SBAL availability
32 * @adapter: adapter used in conjunction with this qdio structure
35 struct qdio_buffer
*res_q
[QDIO_MAX_BUFFERS_PER_Q
];
36 struct qdio_buffer
*req_q
[QDIO_MAX_BUFFERS_PER_Q
];
40 spinlock_t req_q_lock
;
41 unsigned long long req_q_time
;
44 wait_queue_head_t req_q_wq
;
45 struct zfcp_adapter
*adapter
;
46 u16 max_sbale_per_sbal
;
47 u16 max_sbale_per_req
;
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 * @qdio_outb_usage: usage of outbound queue
60 struct zfcp_qdio_req
{
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
76 static inline struct qdio_buffer_element
*
77 zfcp_qdio_sbale_req(struct zfcp_qdio
*qdio
, struct zfcp_qdio_req
*q_req
)
79 return &qdio
->req_q
[q_req
->sbal_last
]->element
[0];
83 * zfcp_qdio_sbale_curr - return current sbale on req_q for a request
84 * @qdio: pointer to struct zfcp_qdio
85 * @fsf_req: pointer to struct zfcp_fsf_req
86 * Returns: pointer to qdio_buffer_element (sbale) structure
88 static inline struct qdio_buffer_element
*
89 zfcp_qdio_sbale_curr(struct zfcp_qdio
*qdio
, struct zfcp_qdio_req
*q_req
)
91 return &qdio
->req_q
[q_req
->sbal_last
]->element
[q_req
->sbale_curr
];
95 * zfcp_qdio_req_init - initialize qdio request
96 * @qdio: request queue where to start putting the request
97 * @q_req: the qdio request to start
98 * @req_id: The request id
99 * @sbtype: type flags to set for all sbals
100 * @data: First data block
101 * @len: Length of first data block
103 * This is the start of putting the request into the queue, the last
104 * step is passing the request to zfcp_qdio_send. The request queue
105 * lock must be held during the whole process from init to send.
108 void zfcp_qdio_req_init(struct zfcp_qdio
*qdio
, struct zfcp_qdio_req
*q_req
,
109 unsigned long req_id
, u8 sbtype
, void *data
, u32 len
)
111 struct qdio_buffer_element
*sbale
;
112 int count
= min(atomic_read(&qdio
->req_q_free
),
113 ZFCP_QDIO_MAX_SBALS_PER_REQ
);
115 q_req
->sbal_first
= q_req
->sbal_last
= qdio
->req_q_idx
;
116 q_req
->sbal_number
= 1;
117 q_req
->sbtype
= sbtype
;
118 q_req
->sbale_curr
= 1;
119 q_req
->sbal_limit
= (q_req
->sbal_first
+ count
- 1)
120 % QDIO_MAX_BUFFERS_PER_Q
;
122 sbale
= zfcp_qdio_sbale_req(qdio
, q_req
);
123 sbale
->addr
= (void *) req_id
;
125 sbale
->sflags
= SBAL_SFLAGS0_COMMAND
| sbtype
;
135 * zfcp_qdio_fill_next - Fill next sbale, only for single sbal requests
136 * @qdio: pointer to struct zfcp_qdio
137 * @q_req: pointer to struct zfcp_queue_req
139 * This is only required for single sbal requests, calling it when
140 * wrapping around to the next sbal is a bug.
143 void zfcp_qdio_fill_next(struct zfcp_qdio
*qdio
, struct zfcp_qdio_req
*q_req
,
146 struct qdio_buffer_element
*sbale
;
148 BUG_ON(q_req
->sbale_curr
== qdio
->max_sbale_per_sbal
- 1);
150 sbale
= zfcp_qdio_sbale_curr(qdio
, q_req
);
156 * zfcp_qdio_set_sbale_last - set last entry flag in current sbale
157 * @qdio: pointer to struct zfcp_qdio
158 * @q_req: pointer to struct zfcp_queue_req
161 void zfcp_qdio_set_sbale_last(struct zfcp_qdio
*qdio
,
162 struct zfcp_qdio_req
*q_req
)
164 struct qdio_buffer_element
*sbale
;
166 sbale
= zfcp_qdio_sbale_curr(qdio
, q_req
);
167 sbale
->eflags
|= SBAL_EFLAGS_LAST_ENTRY
;
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
174 * Returns: 1 when one sbale is enough for the data in the scatterlist,
178 int zfcp_qdio_sg_one_sbale(struct scatterlist
*sg
)
180 return sg_is_last(sg
) && sg
->length
<= ZFCP_QDIO_SBALE_LEN
;
184 * zfcp_qdio_skip_to_last_sbale - skip to last sbale in sbal
185 * @q_req: The current zfcp_qdio_req
188 void zfcp_qdio_skip_to_last_sbale(struct zfcp_qdio
*qdio
,
189 struct zfcp_qdio_req
*q_req
)
191 q_req
->sbale_curr
= qdio
->max_sbale_per_sbal
- 1;
195 * zfcp_qdio_sbal_limit - set the sbal limit for a request in q_req
196 * @qdio: pointer to struct zfcp_qdio
197 * @q_req: The current zfcp_qdio_req
198 * @max_sbals: maximum number of SBALs allowed
201 void zfcp_qdio_sbal_limit(struct zfcp_qdio
*qdio
,
202 struct zfcp_qdio_req
*q_req
, int max_sbals
)
204 int count
= min(atomic_read(&qdio
->req_q_free
), max_sbals
);
206 q_req
->sbal_limit
= (q_req
->sbal_first
+ count
- 1) %
207 QDIO_MAX_BUFFERS_PER_Q
;
211 * zfcp_qdio_set_data_div - set data division count
212 * @qdio: pointer to struct zfcp_qdio
213 * @q_req: The current zfcp_qdio_req
214 * @count: The data division count
217 void zfcp_qdio_set_data_div(struct zfcp_qdio
*qdio
,
218 struct zfcp_qdio_req
*q_req
, u32 count
)
220 struct qdio_buffer_element
*sbale
;
222 sbale
= qdio
->req_q
[q_req
->sbal_first
]->element
;
223 sbale
->length
= count
;
227 * zfcp_qdio_real_bytes - count bytes used
228 * @sg: pointer to struct scatterlist
231 unsigned int zfcp_qdio_real_bytes(struct scatterlist
*sg
)
233 unsigned int real_bytes
= 0;
235 for (; sg
; sg
= sg_next(sg
))
236 real_bytes
+= sg
->length
;
242 * zfcp_qdio_set_scount - set SBAL count value
243 * @qdio: pointer to struct zfcp_qdio
244 * @q_req: The current zfcp_qdio_req
247 void zfcp_qdio_set_scount(struct zfcp_qdio
*qdio
, struct zfcp_qdio_req
*q_req
)
249 struct qdio_buffer_element
*sbale
;
251 sbale
= qdio
->req_q
[q_req
->sbal_first
]->element
;
252 sbale
->scount
= q_req
->sbal_number
- 1;
255 #endif /* ZFCP_QDIO_H */