Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
00bab910 | 2 | * zfcp device driver |
1da177e4 | 3 | * |
00bab910 | 4 | * Setup and helper functions to access QDIO. |
1da177e4 | 5 | * |
1674b405 | 6 | * Copyright IBM Corporation 2002, 2010 |
1da177e4 LT |
7 | */ |
8 | ||
ecf39d42 CS |
9 | #define KMSG_COMPONENT "zfcp" |
10 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt | |
11 | ||
5a0e3ad6 | 12 | #include <linux/slab.h> |
1da177e4 | 13 | #include "zfcp_ext.h" |
34c2b712 | 14 | #include "zfcp_qdio.h" |
1da177e4 | 15 | |
5d4e2262 | 16 | #define QBUFF_PER_PAGE (PAGE_SIZE / sizeof(struct qdio_buffer)) |
1da177e4 | 17 | |
00bab910 | 18 | static int zfcp_qdio_buffers_enqueue(struct qdio_buffer **sbal) |
1da177e4 | 19 | { |
b4e44590 | 20 | int pos; |
1da177e4 | 21 | |
b4e44590 | 22 | for (pos = 0; pos < QDIO_MAX_BUFFERS_PER_Q; pos += QBUFF_PER_PAGE) { |
00bab910 SS |
23 | sbal[pos] = (struct qdio_buffer *) get_zeroed_page(GFP_KERNEL); |
24 | if (!sbal[pos]) | |
b4e44590 | 25 | return -ENOMEM; |
b4e44590 SS |
26 | } |
27 | for (pos = 0; pos < QDIO_MAX_BUFFERS_PER_Q; pos++) | |
28 | if (pos % QBUFF_PER_PAGE) | |
00bab910 | 29 | sbal[pos] = sbal[pos - 1] + 1; |
b4e44590 | 30 | return 0; |
1da177e4 LT |
31 | } |
32 | ||
339f4f4e CS |
33 | static void zfcp_qdio_handler_error(struct zfcp_qdio *qdio, char *id, |
34 | unsigned int qdio_err) | |
1da177e4 | 35 | { |
564e1c86 SS |
36 | struct zfcp_adapter *adapter = qdio->adapter; |
37 | ||
ff3b24fa | 38 | dev_warn(&adapter->ccw_device->dev, "A QDIO problem occurred\n"); |
1da177e4 | 39 | |
339f4f4e CS |
40 | if (qdio_err & QDIO_ERROR_SLSB_STATE) |
41 | zfcp_qdio_siosl(adapter); | |
00bab910 SS |
42 | zfcp_erp_adapter_reopen(adapter, |
43 | ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED | | |
44 | ZFCP_STATUS_COMMON_ERP_FAILED, id, NULL); | |
1da177e4 LT |
45 | } |
46 | ||
5d4e2262 CS |
47 | static void zfcp_qdio_zero_sbals(struct qdio_buffer *sbal[], int first, int cnt) |
48 | { | |
49 | int i, sbal_idx; | |
50 | ||
51 | for (i = first; i < first + cnt; i++) { | |
52 | sbal_idx = i % QDIO_MAX_BUFFERS_PER_Q; | |
53 | memset(sbal[sbal_idx], 0, sizeof(struct qdio_buffer)); | |
54 | } | |
55 | } | |
56 | ||
94506fd1 | 57 | /* this needs to be called prior to updating the queue fill level */ |
41e05a12 | 58 | static inline void zfcp_qdio_account(struct zfcp_qdio *qdio) |
94506fd1 | 59 | { |
41e05a12 | 60 | unsigned long long now, span; |
706eca49 | 61 | int used; |
94506fd1 | 62 | |
564e1c86 | 63 | spin_lock(&qdio->stat_lock); |
41e05a12 HC |
64 | now = get_clock_monotonic(); |
65 | span = (now - qdio->req_q_time) >> 12; | |
706eca49 | 66 | used = QDIO_MAX_BUFFERS_PER_Q - atomic_read(&qdio->req_q_free); |
564e1c86 SS |
67 | qdio->req_q_util += used * span; |
68 | qdio->req_q_time = now; | |
69 | spin_unlock(&qdio->stat_lock); | |
94506fd1 MP |
70 | } |
71 | ||
779e6e1c | 72 | static void zfcp_qdio_int_req(struct ccw_device *cdev, unsigned int qdio_err, |
706eca49 | 73 | int queue_no, int idx, int count, |
00bab910 | 74 | unsigned long parm) |
1da177e4 | 75 | { |
564e1c86 | 76 | struct zfcp_qdio *qdio = (struct zfcp_qdio *) parm; |
1da177e4 | 77 | |
779e6e1c | 78 | if (unlikely(qdio_err)) { |
706eca49 | 79 | zfcp_dbf_hba_qdio(qdio->adapter->dbf, qdio_err, idx, count); |
339f4f4e | 80 | zfcp_qdio_handler_error(qdio, "qdireq1", qdio_err); |
00bab910 SS |
81 | return; |
82 | } | |
1da177e4 LT |
83 | |
84 | /* cleanup all SBALs being program-owned now */ | |
706eca49 | 85 | zfcp_qdio_zero_sbals(qdio->req_q, idx, count); |
1da177e4 | 86 | |
564e1c86 | 87 | zfcp_qdio_account(qdio); |
706eca49 | 88 | atomic_add(count, &qdio->req_q_free); |
564e1c86 | 89 | wake_up(&qdio->req_q_wq); |
1da177e4 LT |
90 | } |
91 | ||
779e6e1c | 92 | static void zfcp_qdio_int_resp(struct ccw_device *cdev, unsigned int qdio_err, |
706eca49 | 93 | int queue_no, int idx, int count, |
00bab910 SS |
94 | unsigned long parm) |
95 | { | |
564e1c86 | 96 | struct zfcp_qdio *qdio = (struct zfcp_qdio *) parm; |
bd63eaf4 | 97 | int sbal_idx, sbal_no; |
00bab910 | 98 | |
779e6e1c | 99 | if (unlikely(qdio_err)) { |
706eca49 | 100 | zfcp_dbf_hba_qdio(qdio->adapter->dbf, qdio_err, idx, count); |
339f4f4e | 101 | zfcp_qdio_handler_error(qdio, "qdires1", qdio_err); |
00bab910 SS |
102 | return; |
103 | } | |
1da177e4 | 104 | |
1da177e4 LT |
105 | /* |
106 | * go through all SBALs from input queue currently | |
107 | * returned by QDIO layer | |
108 | */ | |
00bab910 | 109 | for (sbal_no = 0; sbal_no < count; sbal_no++) { |
706eca49 | 110 | sbal_idx = (idx + sbal_no) % QDIO_MAX_BUFFERS_PER_Q; |
1da177e4 | 111 | /* go through all SBALEs of SBAL */ |
564e1c86 | 112 | zfcp_fsf_reqid_check(qdio, sbal_idx); |
1da177e4 LT |
113 | } |
114 | ||
115 | /* | |
706eca49 | 116 | * put SBALs back to response queue |
1da177e4 | 117 | */ |
706eca49 SS |
118 | if (do_QDIO(cdev, QDIO_FLAG_SYNC_INPUT, 0, idx, count)) |
119 | zfcp_erp_adapter_reopen(qdio->adapter, 0, "qdires2", NULL); | |
1da177e4 LT |
120 | } |
121 | ||
44cc76f2 | 122 | static struct qdio_buffer_element * |
1674b405 | 123 | zfcp_qdio_sbal_chain(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req) |
1da177e4 | 124 | { |
44cc76f2 | 125 | struct qdio_buffer_element *sbale; |
1da177e4 LT |
126 | |
127 | /* set last entry flag in current SBALE of current SBAL */ | |
564e1c86 | 128 | sbale = zfcp_qdio_sbale_curr(qdio, q_req); |
1da177e4 LT |
129 | sbale->flags |= SBAL_FLAGS_LAST_ENTRY; |
130 | ||
131 | /* don't exceed last allowed SBAL */ | |
42428f74 | 132 | if (q_req->sbal_last == q_req->sbal_limit) |
1da177e4 LT |
133 | return NULL; |
134 | ||
135 | /* set chaining flag in first SBALE of current SBAL */ | |
564e1c86 | 136 | sbale = zfcp_qdio_sbale_req(qdio, q_req); |
1da177e4 LT |
137 | sbale->flags |= SBAL_FLAGS0_MORE_SBALS; |
138 | ||
139 | /* calculate index of next SBAL */ | |
42428f74 SS |
140 | q_req->sbal_last++; |
141 | q_req->sbal_last %= QDIO_MAX_BUFFERS_PER_Q; | |
1da177e4 LT |
142 | |
143 | /* keep this requests number of SBALs up-to-date */ | |
42428f74 | 144 | q_req->sbal_number++; |
01b04759 | 145 | BUG_ON(q_req->sbal_number > ZFCP_QDIO_MAX_SBALS_PER_REQ); |
1da177e4 LT |
146 | |
147 | /* start at first SBALE of new SBAL */ | |
42428f74 | 148 | q_req->sbale_curr = 0; |
1da177e4 LT |
149 | |
150 | /* set storage-block type for new SBAL */ | |
564e1c86 | 151 | sbale = zfcp_qdio_sbale_curr(qdio, q_req); |
1674b405 | 152 | sbale->flags |= q_req->sbtype; |
1da177e4 LT |
153 | |
154 | return sbale; | |
155 | } | |
156 | ||
44cc76f2 | 157 | static struct qdio_buffer_element * |
1674b405 | 158 | zfcp_qdio_sbale_next(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req) |
1da177e4 | 159 | { |
1674b405 CS |
160 | if (q_req->sbale_curr == ZFCP_QDIO_LAST_SBALE_PER_SBAL) |
161 | return zfcp_qdio_sbal_chain(qdio, q_req); | |
42428f74 | 162 | q_req->sbale_curr++; |
564e1c86 | 163 | return zfcp_qdio_sbale_curr(qdio, q_req); |
1da177e4 LT |
164 | } |
165 | ||
1da177e4 LT |
166 | /** |
167 | * zfcp_qdio_sbals_from_sg - fill SBALs from scatter-gather list | |
1674b405 CS |
168 | * @qdio: pointer to struct zfcp_qdio |
169 | * @q_req: pointer to struct zfcp_qdio_req | |
1da177e4 | 170 | * @sg: scatter-gather list |
1da177e4 | 171 | * @max_sbals: upper bound for number of SBALs to be used |
00bab910 | 172 | * Returns: number of bytes, or error (negativ) |
1da177e4 | 173 | */ |
34c2b712 | 174 | int zfcp_qdio_sbals_from_sg(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req, |
01b04759 | 175 | struct scatterlist *sg) |
1da177e4 | 176 | { |
44cc76f2 | 177 | struct qdio_buffer_element *sbale; |
68322984 | 178 | int bytes = 0; |
1da177e4 | 179 | |
00bab910 | 180 | /* set storage-block type for this request */ |
564e1c86 | 181 | sbale = zfcp_qdio_sbale_req(qdio, q_req); |
1674b405 | 182 | sbale->flags |= q_req->sbtype; |
1da177e4 | 183 | |
00bab910 | 184 | for (; sg; sg = sg_next(sg)) { |
1674b405 | 185 | sbale = zfcp_qdio_sbale_next(qdio, q_req); |
68322984 CS |
186 | if (!sbale) { |
187 | atomic_inc(&qdio->req_q_full); | |
706eca49 SS |
188 | zfcp_qdio_zero_sbals(qdio->req_q, q_req->sbal_first, |
189 | q_req->sbal_number); | |
68322984 CS |
190 | return -EINVAL; |
191 | } | |
192 | ||
193 | sbale->addr = sg_virt(sg); | |
194 | sbale->length = sg->length; | |
195 | ||
00bab910 | 196 | bytes += sg->length; |
1da177e4 | 197 | } |
00bab910 | 198 | |
1da177e4 LT |
199 | return bytes; |
200 | } | |
201 | ||
6b9e1520 CS |
202 | static int zfcp_qdio_sbal_check(struct zfcp_qdio *qdio) |
203 | { | |
6b9e1520 | 204 | spin_lock_bh(&qdio->req_q_lock); |
706eca49 | 205 | if (atomic_read(&qdio->req_q_free) || |
c2af7545 | 206 | !(atomic_read(&qdio->adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) |
6b9e1520 CS |
207 | return 1; |
208 | spin_unlock_bh(&qdio->req_q_lock); | |
209 | return 0; | |
210 | } | |
211 | ||
212 | /** | |
213 | * zfcp_qdio_sbal_get - get free sbal in request queue, wait if necessary | |
214 | * @qdio: pointer to struct zfcp_qdio | |
215 | * | |
216 | * The req_q_lock must be held by the caller of this function, and | |
217 | * this function may only be called from process context; it will | |
218 | * sleep when waiting for a free sbal. | |
219 | * | |
220 | * Returns: 0 on success, -EIO if there is no free sbal after waiting. | |
221 | */ | |
222 | int zfcp_qdio_sbal_get(struct zfcp_qdio *qdio) | |
223 | { | |
224 | long ret; | |
225 | ||
226 | spin_unlock_bh(&qdio->req_q_lock); | |
227 | ret = wait_event_interruptible_timeout(qdio->req_q_wq, | |
228 | zfcp_qdio_sbal_check(qdio), 5 * HZ); | |
c2af7545 CS |
229 | |
230 | if (!(atomic_read(&qdio->adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) | |
231 | return -EIO; | |
232 | ||
6b9e1520 CS |
233 | if (ret > 0) |
234 | return 0; | |
c2af7545 | 235 | |
6b9e1520 CS |
236 | if (!ret) { |
237 | atomic_inc(&qdio->req_q_full); | |
238 | /* assume hanging outbound queue, try queue recovery */ | |
239 | zfcp_erp_adapter_reopen(qdio->adapter, 0, "qdsbg_1", NULL); | |
240 | } | |
241 | ||
242 | spin_lock_bh(&qdio->req_q_lock); | |
243 | return -EIO; | |
244 | } | |
245 | ||
1da177e4 | 246 | /** |
00bab910 | 247 | * zfcp_qdio_send - set PCI flag in first SBALE and send req to QDIO |
564e1c86 | 248 | * @qdio: pointer to struct zfcp_qdio |
34c2b712 | 249 | * @q_req: pointer to struct zfcp_qdio_req |
00bab910 | 250 | * Returns: 0 on success, error otherwise |
1da177e4 | 251 | */ |
34c2b712 | 252 | int zfcp_qdio_send(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req) |
1da177e4 | 253 | { |
21ddaa53 | 254 | int retval; |
706eca49 | 255 | u8 sbal_number = q_req->sbal_number; |
00bab910 | 256 | |
564e1c86 | 257 | zfcp_qdio_account(qdio); |
94506fd1 | 258 | |
706eca49 SS |
259 | retval = do_QDIO(qdio->adapter->ccw_device, QDIO_FLAG_SYNC_OUTPUT, 0, |
260 | q_req->sbal_first, sbal_number); | |
261 | ||
00bab910 | 262 | if (unlikely(retval)) { |
706eca49 SS |
263 | zfcp_qdio_zero_sbals(qdio->req_q, q_req->sbal_first, |
264 | sbal_number); | |
00bab910 SS |
265 | return retval; |
266 | } | |
267 | ||
268 | /* account for transferred buffers */ | |
706eca49 SS |
269 | atomic_sub(sbal_number, &qdio->req_q_free); |
270 | qdio->req_q_idx += sbal_number; | |
271 | qdio->req_q_idx %= QDIO_MAX_BUFFERS_PER_Q; | |
272 | ||
00bab910 | 273 | return 0; |
1da177e4 LT |
274 | } |
275 | ||
564e1c86 SS |
276 | |
277 | static void zfcp_qdio_setup_init_data(struct qdio_initialize *id, | |
278 | struct zfcp_qdio *qdio) | |
279 | { | |
280 | ||
281 | id->cdev = qdio->adapter->ccw_device; | |
282 | id->q_format = QDIO_ZFCP_QFMT; | |
283 | memcpy(id->adapter_name, dev_name(&id->cdev->dev), 8); | |
284 | ASCEBC(id->adapter_name, 8); | |
dcc18f48 | 285 | id->qib_rflags = QIB_RFLAGS_ENABLE_DATA_DIV; |
564e1c86 SS |
286 | id->qib_param_field_format = 0; |
287 | id->qib_param_field = NULL; | |
288 | id->input_slib_elements = NULL; | |
289 | id->output_slib_elements = NULL; | |
290 | id->no_input_qs = 1; | |
291 | id->no_output_qs = 1; | |
292 | id->input_handler = zfcp_qdio_int_resp; | |
293 | id->output_handler = zfcp_qdio_int_req; | |
294 | id->int_parm = (unsigned long) qdio; | |
706eca49 SS |
295 | id->input_sbal_addr_array = (void **) (qdio->res_q); |
296 | id->output_sbal_addr_array = (void **) (qdio->req_q); | |
564e1c86 | 297 | } |
dcc18f48 | 298 | |
00bab910 SS |
299 | /** |
300 | * zfcp_qdio_allocate - allocate queue memory and initialize QDIO data | |
301 | * @adapter: pointer to struct zfcp_adapter | |
302 | * Returns: -ENOMEM on memory allocation error or return value from | |
303 | * qdio_allocate | |
304 | */ | |
d5a282a1 | 305 | static int zfcp_qdio_allocate(struct zfcp_qdio *qdio) |
00bab910 | 306 | { |
564e1c86 | 307 | struct qdio_initialize init_data; |
00bab910 | 308 | |
706eca49 SS |
309 | if (zfcp_qdio_buffers_enqueue(qdio->req_q) || |
310 | zfcp_qdio_buffers_enqueue(qdio->res_q)) | |
00bab910 SS |
311 | return -ENOMEM; |
312 | ||
564e1c86 SS |
313 | zfcp_qdio_setup_init_data(&init_data, qdio); |
314 | ||
315 | return qdio_allocate(&init_data); | |
00bab910 SS |
316 | } |
317 | ||
318 | /** | |
319 | * zfcp_close_qdio - close qdio queues for an adapter | |
564e1c86 | 320 | * @qdio: pointer to structure zfcp_qdio |
1da177e4 | 321 | */ |
564e1c86 | 322 | void zfcp_qdio_close(struct zfcp_qdio *qdio) |
1da177e4 | 323 | { |
706eca49 SS |
324 | struct zfcp_adapter *adapter = qdio->adapter; |
325 | int idx, count; | |
00bab910 | 326 | |
706eca49 | 327 | if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) |
00bab910 SS |
328 | return; |
329 | ||
330 | /* clear QDIOUP flag, thus do_QDIO is not called during qdio_shutdown */ | |
564e1c86 | 331 | spin_lock_bh(&qdio->req_q_lock); |
706eca49 | 332 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status); |
564e1c86 | 333 | spin_unlock_bh(&qdio->req_q_lock); |
00bab910 | 334 | |
c2af7545 CS |
335 | wake_up(&qdio->req_q_wq); |
336 | ||
706eca49 | 337 | qdio_shutdown(adapter->ccw_device, QDIO_FLAG_CLEANUP_USING_CLEAR); |
00bab910 SS |
338 | |
339 | /* cleanup used outbound sbals */ | |
706eca49 | 340 | count = atomic_read(&qdio->req_q_free); |
00bab910 | 341 | if (count < QDIO_MAX_BUFFERS_PER_Q) { |
706eca49 | 342 | idx = (qdio->req_q_idx + count) % QDIO_MAX_BUFFERS_PER_Q; |
00bab910 | 343 | count = QDIO_MAX_BUFFERS_PER_Q - count; |
706eca49 | 344 | zfcp_qdio_zero_sbals(qdio->req_q, idx, count); |
1da177e4 | 345 | } |
706eca49 SS |
346 | qdio->req_q_idx = 0; |
347 | atomic_set(&qdio->req_q_free, 0); | |
1da177e4 LT |
348 | } |
349 | ||
00bab910 SS |
350 | /** |
351 | * zfcp_qdio_open - prepare and initialize response queue | |
564e1c86 | 352 | * @qdio: pointer to struct zfcp_qdio |
00bab910 SS |
353 | * Returns: 0 on success, otherwise -EIO |
354 | */ | |
564e1c86 | 355 | int zfcp_qdio_open(struct zfcp_qdio *qdio) |
00bab910 | 356 | { |
44cc76f2 | 357 | struct qdio_buffer_element *sbale; |
564e1c86 | 358 | struct qdio_initialize init_data; |
706eca49 SS |
359 | struct zfcp_adapter *adapter = qdio->adapter; |
360 | struct ccw_device *cdev = adapter->ccw_device; | |
dcc18f48 | 361 | struct qdio_ssqd_desc ssqd; |
00bab910 SS |
362 | int cc; |
363 | ||
706eca49 | 364 | if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP) |
00bab910 SS |
365 | return -EIO; |
366 | ||
339f4f4e CS |
367 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_SIOSL_ISSUED, |
368 | &qdio->adapter->status); | |
369 | ||
564e1c86 SS |
370 | zfcp_qdio_setup_init_data(&init_data, qdio); |
371 | ||
372 | if (qdio_establish(&init_data)) | |
ff3b24fa | 373 | goto failed_establish; |
00bab910 | 374 | |
dcc18f48 CS |
375 | if (qdio_get_ssqd_desc(init_data.cdev, &ssqd)) |
376 | goto failed_qdio; | |
377 | ||
378 | if (ssqd.qdioac2 & CHSC_AC2_DATA_DIV_ENABLED) | |
379 | atomic_set_mask(ZFCP_STATUS_ADAPTER_DATA_DIV_ENABLED, | |
380 | &qdio->adapter->status); | |
381 | ||
564e1c86 | 382 | if (qdio_activate(cdev)) |
00bab910 | 383 | goto failed_qdio; |
00bab910 SS |
384 | |
385 | for (cc = 0; cc < QDIO_MAX_BUFFERS_PER_Q; cc++) { | |
706eca49 | 386 | sbale = &(qdio->res_q[cc]->element[0]); |
00bab910 SS |
387 | sbale->length = 0; |
388 | sbale->flags = SBAL_FLAGS_LAST_ENTRY; | |
389 | sbale->addr = NULL; | |
390 | } | |
391 | ||
706eca49 | 392 | if (do_QDIO(cdev, QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q)) |
00bab910 | 393 | goto failed_qdio; |
00bab910 SS |
394 | |
395 | /* set index of first avalable SBALS / number of available SBALS */ | |
706eca49 SS |
396 | qdio->req_q_idx = 0; |
397 | atomic_set(&qdio->req_q_free, QDIO_MAX_BUFFERS_PER_Q); | |
00bab910 SS |
398 | |
399 | return 0; | |
400 | ||
401 | failed_qdio: | |
564e1c86 | 402 | qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR); |
ff3b24fa | 403 | failed_establish: |
564e1c86 | 404 | dev_err(&cdev->dev, |
ff3b24fa | 405 | "Setting up the QDIO connection to the FCP adapter failed\n"); |
00bab910 SS |
406 | return -EIO; |
407 | } | |
d5a282a1 SS |
408 | |
409 | void zfcp_qdio_destroy(struct zfcp_qdio *qdio) | |
410 | { | |
d5a282a1 SS |
411 | int p; |
412 | ||
413 | if (!qdio) | |
414 | return; | |
415 | ||
416 | if (qdio->adapter->ccw_device) | |
417 | qdio_free(qdio->adapter->ccw_device); | |
418 | ||
d5a282a1 | 419 | for (p = 0; p < QDIO_MAX_BUFFERS_PER_Q; p += QBUFF_PER_PAGE) { |
706eca49 SS |
420 | free_page((unsigned long) qdio->req_q[p]); |
421 | free_page((unsigned long) qdio->res_q[p]); | |
d5a282a1 SS |
422 | } |
423 | ||
424 | kfree(qdio); | |
425 | } | |
426 | ||
427 | int zfcp_qdio_setup(struct zfcp_adapter *adapter) | |
428 | { | |
429 | struct zfcp_qdio *qdio; | |
430 | ||
431 | qdio = kzalloc(sizeof(struct zfcp_qdio), GFP_KERNEL); | |
432 | if (!qdio) | |
433 | return -ENOMEM; | |
434 | ||
435 | qdio->adapter = adapter; | |
436 | ||
437 | if (zfcp_qdio_allocate(qdio)) { | |
438 | zfcp_qdio_destroy(qdio); | |
439 | return -ENOMEM; | |
440 | } | |
441 | ||
442 | spin_lock_init(&qdio->req_q_lock); | |
443 | spin_lock_init(&qdio->stat_lock); | |
444 | ||
445 | adapter->qdio = qdio; | |
446 | return 0; | |
447 | } | |
448 | ||
339f4f4e CS |
449 | /** |
450 | * zfcp_qdio_siosl - Trigger logging in FCP channel | |
451 | * @adapter: The zfcp_adapter where to trigger logging | |
452 | * | |
453 | * Call the cio siosl function to trigger hardware logging. This | |
454 | * wrapper function sets a flag to ensure hardware logging is only | |
455 | * triggered once before going through qdio shutdown. | |
456 | * | |
457 | * The triggers are always run from qdio tasklet context, so no | |
458 | * additional synchronization is necessary. | |
459 | */ | |
460 | void zfcp_qdio_siosl(struct zfcp_adapter *adapter) | |
461 | { | |
462 | int rc; | |
463 | ||
464 | if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_SIOSL_ISSUED) | |
465 | return; | |
466 | ||
467 | rc = ccw_device_siosl(adapter->ccw_device); | |
468 | if (!rc) | |
469 | atomic_set_mask(ZFCP_STATUS_ADAPTER_SIOSL_ISSUED, | |
470 | &adapter->status); | |
471 | } |