2 * linux/drivers/s390/scsi/zfcp_qdio.c
4 * FCP adapter driver for IBM eServer zSeries
6 * QDIO related routines
8 * (C) Copyright IBM Corp. 2002, 2004
11 * Martin Peschke <mpeschke@de.ibm.com>
12 * Raimund Schroeder <raimund.schroeder@de.ibm.com>
14 * Heiko Carstens <heiko.carstens@de.ibm.com>
15 * Andreas Herrmann <aherrman@de.ibm.com>
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2, or (at your option)
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
34 static inline void zfcp_qdio_sbal_limit(struct zfcp_fsf_req *, int);
35 static inline volatile struct qdio_buffer_element *zfcp_qdio_sbale_get
36 (struct zfcp_qdio_queue *, int, int);
37 static inline volatile struct qdio_buffer_element *zfcp_qdio_sbale_resp
38 (struct zfcp_fsf_req *, int, int);
39 static inline volatile struct qdio_buffer_element *zfcp_qdio_sbal_chain
40 (struct zfcp_fsf_req *, unsigned long);
41 static inline volatile struct qdio_buffer_element *zfcp_qdio_sbale_next
42 (struct zfcp_fsf_req *, unsigned long);
43 static inline int zfcp_qdio_sbals_zero(struct zfcp_qdio_queue *, int, int);
44 static inline int zfcp_qdio_sbals_wipe(struct zfcp_fsf_req *);
45 static inline void zfcp_qdio_sbale_fill
46 (struct zfcp_fsf_req *, unsigned long, void *, int);
47 static inline int zfcp_qdio_sbals_from_segment
48 (struct zfcp_fsf_req *, unsigned long, void *, unsigned long);
49 static inline int zfcp_qdio_sbals_from_buffer
50 (struct zfcp_fsf_req *, unsigned long, void *, unsigned long, int);
52 static qdio_handler_t zfcp_qdio_request_handler;
53 static qdio_handler_t zfcp_qdio_response_handler;
54 static int zfcp_qdio_handler_error_check(struct zfcp_adapter *,
55 unsigned int, unsigned int, unsigned int, int, int);
57 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_QDIO
60 * Allocates BUFFER memory to each of the pointers of the qdio_buffer_t
61 * array in the adapter struct.
62 * Cur_buf is the pointer array and count can be any number of required
63 * buffers, the page-fitting arithmetic is done entirely within this funciton.
65 * returns: number of buffers allocated
66 * locks: must only be called with zfcp_data.config_sema taken
69 zfcp_qdio_buffers_enqueue(struct qdio_buffer **cur_buf, int count)
72 int qdio_buffers_per_page;
74 struct qdio_buffer *first_in_page = NULL;
76 qdio_buffers_per_page = PAGE_SIZE / sizeof (struct qdio_buffer);
77 ZFCP_LOG_TRACE("buffers_per_page=%d\n", qdio_buffers_per_page);
79 for (buf_pos = 0; buf_pos < count; buf_pos++) {
81 cur_buf[buf_pos] = (struct qdio_buffer *)
82 get_zeroed_page(GFP_KERNEL);
83 if (cur_buf[buf_pos] == NULL) {
84 ZFCP_LOG_INFO("error: allocation of "
85 "QDIO buffer failed \n");
88 first_in_page = cur_buf[buf_pos];
90 cur_buf[buf_pos] = first_in_page + page_pos;
93 /* was initialised to zero */
95 page_pos %= qdio_buffers_per_page;
102 * Frees BUFFER memory for each of the pointers of the struct qdio_buffer array
103 * in the adapter struct cur_buf is the pointer array and count can be any
104 * number of buffers in the array that should be freed starting from buffer 0
106 * locks: must only be called with zfcp_data.config_sema taken
109 zfcp_qdio_buffers_dequeue(struct qdio_buffer **cur_buf, int count)
112 int qdio_buffers_per_page;
114 qdio_buffers_per_page = PAGE_SIZE / sizeof (struct qdio_buffer);
115 ZFCP_LOG_TRACE("buffers_per_page=%d\n", qdio_buffers_per_page);
117 for (buf_pos = 0; buf_pos < count; buf_pos += qdio_buffers_per_page)
118 free_page((unsigned long) cur_buf[buf_pos]);
122 /* locks: must only be called with zfcp_data.config_sema taken */
124 zfcp_qdio_allocate_queues(struct zfcp_adapter *adapter)
130 zfcp_qdio_buffers_enqueue(&(adapter->request_queue.buffer[0]),
131 QDIO_MAX_BUFFERS_PER_Q);
132 if (buffer_count < QDIO_MAX_BUFFERS_PER_Q) {
133 ZFCP_LOG_DEBUG("only %d QDIO buffers allocated for request "
134 "queue\n", buffer_count);
135 zfcp_qdio_buffers_dequeue(&(adapter->request_queue.buffer[0]),
142 zfcp_qdio_buffers_enqueue(&(adapter->response_queue.buffer[0]),
143 QDIO_MAX_BUFFERS_PER_Q);
144 if (buffer_count < QDIO_MAX_BUFFERS_PER_Q) {
145 ZFCP_LOG_DEBUG("only %d QDIO buffers allocated for response "
146 "queue", buffer_count);
147 zfcp_qdio_buffers_dequeue(&(adapter->response_queue.buffer[0]),
149 ZFCP_LOG_TRACE("freeing request_queue buffers\n");
150 zfcp_qdio_buffers_dequeue(&(adapter->request_queue.buffer[0]),
151 QDIO_MAX_BUFFERS_PER_Q);
159 /* locks: must only be called with zfcp_data.config_sema taken */
161 zfcp_qdio_free_queues(struct zfcp_adapter *adapter)
163 ZFCP_LOG_TRACE("freeing request_queue buffers\n");
164 zfcp_qdio_buffers_dequeue(&(adapter->request_queue.buffer[0]),
165 QDIO_MAX_BUFFERS_PER_Q);
167 ZFCP_LOG_TRACE("freeing response_queue buffers\n");
168 zfcp_qdio_buffers_dequeue(&(adapter->response_queue.buffer[0]),
169 QDIO_MAX_BUFFERS_PER_Q);
173 zfcp_qdio_allocate(struct zfcp_adapter *adapter)
175 struct qdio_initialize *init_data;
177 init_data = &adapter->qdio_init_data;
179 init_data->cdev = adapter->ccw_device;
180 init_data->q_format = QDIO_SCSI_QFMT;
181 memcpy(init_data->adapter_name, &adapter->name, 8);
182 init_data->qib_param_field_format = 0;
183 init_data->qib_param_field = NULL;
184 init_data->input_slib_elements = NULL;
185 init_data->output_slib_elements = NULL;
186 init_data->min_input_threshold = ZFCP_MIN_INPUT_THRESHOLD;
187 init_data->max_input_threshold = ZFCP_MAX_INPUT_THRESHOLD;
188 init_data->min_output_threshold = ZFCP_MIN_OUTPUT_THRESHOLD;
189 init_data->max_output_threshold = ZFCP_MAX_OUTPUT_THRESHOLD;
190 init_data->no_input_qs = 1;
191 init_data->no_output_qs = 1;
192 init_data->input_handler = zfcp_qdio_response_handler;
193 init_data->output_handler = zfcp_qdio_request_handler;
194 init_data->int_parm = (unsigned long) adapter;
195 init_data->flags = QDIO_INBOUND_0COPY_SBALS |
196 QDIO_OUTBOUND_0COPY_SBALS | QDIO_USE_OUTBOUND_PCIS;
197 init_data->input_sbal_addr_array =
198 (void **) (adapter->response_queue.buffer);
199 init_data->output_sbal_addr_array =
200 (void **) (adapter->request_queue.buffer);
202 return qdio_allocate(init_data);
206 * function: zfcp_qdio_handler_error_check
208 * purpose: called by the response handler to determine error condition
210 * returns: error flag
214 zfcp_qdio_handler_error_check(struct zfcp_adapter *adapter, unsigned int status,
215 unsigned int qdio_error, unsigned int siga_error,
216 int first_element, int elements_processed)
220 if (unlikely(status & QDIO_STATUS_LOOK_FOR_ERROR)) {
223 ZFCP_LOG_INFO("QDIO problem occurred (status=0x%x, "
224 "qdio_error=0x%x, siga_error=0x%x)\n",
225 status, qdio_error, siga_error);
227 zfcp_hba_dbf_event_qdio(adapter, status, qdio_error, siga_error,
228 first_element, elements_processed);
230 * Restarting IO on the failed adapter from scratch.
231 * Since we have been using this adapter, it is save to assume
232 * that it is not failed but recoverable. The card seems to
233 * report link-up events by self-initiated queue shutdown.
234 * That is why we need to clear the the link-down flag
235 * which is set again in case we have missed by a mile.
237 zfcp_erp_adapter_reopen(
239 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
240 ZFCP_STATUS_COMMON_ERP_FAILED);
246 * function: zfcp_qdio_request_handler
248 * purpose: is called by QDIO layer for completed SBALs in request queue
253 zfcp_qdio_request_handler(struct ccw_device *ccw_device,
255 unsigned int qdio_error,
256 unsigned int siga_error,
257 unsigned int queue_number,
259 int elements_processed,
260 unsigned long int_parm)
262 struct zfcp_adapter *adapter;
263 struct zfcp_qdio_queue *queue;
265 adapter = (struct zfcp_adapter *) int_parm;
266 queue = &adapter->request_queue;
268 ZFCP_LOG_DEBUG("adapter %s, first=%d, elements_processed=%d\n",
269 zfcp_get_busid_by_adapter(adapter),
270 first_element, elements_processed);
272 if (unlikely(zfcp_qdio_handler_error_check(adapter, status, qdio_error,
273 siga_error, first_element,
274 elements_processed)))
277 * we stored address of struct zfcp_adapter data structure
278 * associated with irq in int_parm
281 /* cleanup all SBALs being program-owned now */
282 zfcp_qdio_zero_sbals(queue->buffer, first_element, elements_processed);
284 /* increase free space in outbound queue */
285 atomic_add(elements_processed, &queue->free_count);
286 ZFCP_LOG_DEBUG("free_count=%d\n", atomic_read(&queue->free_count));
287 wake_up(&adapter->request_wq);
288 ZFCP_LOG_DEBUG("elements_processed=%d, free count=%d\n",
289 elements_processed, atomic_read(&queue->free_count));
295 * function: zfcp_qdio_response_handler
297 * purpose: is called by QDIO layer for completed SBALs in response queue
302 zfcp_qdio_response_handler(struct ccw_device *ccw_device,
304 unsigned int qdio_error,
305 unsigned int siga_error,
306 unsigned int queue_number,
308 int elements_processed,
309 unsigned long int_parm)
311 struct zfcp_adapter *adapter;
312 struct zfcp_qdio_queue *queue;
315 struct qdio_buffer *buffer;
319 volatile struct qdio_buffer_element *buffere = NULL;
322 adapter = (struct zfcp_adapter *) int_parm;
323 queue = &adapter->response_queue;
325 if (unlikely(zfcp_qdio_handler_error_check(adapter, status, qdio_error,
326 siga_error, first_element,
327 elements_processed)))
331 * we stored address of struct zfcp_adapter data structure
332 * associated with irq in int_parm
335 buffere = &(queue->buffer[first_element]->element[0]);
336 ZFCP_LOG_DEBUG("first BUFFERE flags=0x%x\n", buffere->flags);
338 * go through all SBALs from input queue currently
339 * returned by QDIO layer
342 for (i = 0; i < elements_processed; i++) {
344 buffer_index = first_element + i;
345 buffer_index %= QDIO_MAX_BUFFERS_PER_Q;
346 buffer = queue->buffer[buffer_index];
348 /* go through all SBALEs of SBAL */
349 for (buffere_index = 0;
350 buffere_index < QDIO_MAX_ELEMENTS_PER_BUFFER;
353 /* look for QDIO request identifiers in SB */
354 buffere = &buffer->element[buffere_index];
355 retval = zfcp_qdio_reqid_check(adapter,
356 (void *) buffere->addr);
359 ZFCP_LOG_NORMAL("bug: unexpected inbound "
360 "packet on adapter %s "
363 "elements_processed=%d)\n",
364 zfcp_get_busid_by_adapter(adapter),
365 (unsigned long) buffere->addr,
368 ZFCP_LOG_NORMAL("hex dump of inbound buffer "
371 "buffere_index=%d)\n", buffer,
372 buffer_index, buffere_index);
373 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
374 (char *) buffer, SBAL_SIZE);
377 * A single used SBALE per inbound SBALE has been
378 * implemented by QDIO so far. Hope they will
379 * do some optimisation. Will need to change to
382 if (likely(buffere->flags & SBAL_FLAGS_LAST_ENTRY))
386 if (unlikely(!(buffere->flags & SBAL_FLAGS_LAST_ENTRY))) {
387 ZFCP_LOG_NORMAL("bug: End of inbound data "
393 * put range of SBALs back to response queue
394 * (including SBALs which have already been free before)
396 count = atomic_read(&queue->free_count) + elements_processed;
397 start = queue->free_index;
399 ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
400 "queue_no=%i, index_in_queue=%i, count=%i, "
402 zfcp_get_busid_by_adapter(adapter),
403 QDIO_FLAG_SYNC_INPUT | QDIO_FLAG_UNDER_INTERRUPT,
404 0, start, count, (unsigned long) &queue->buffer[start]);
406 retval = do_QDIO(ccw_device,
407 QDIO_FLAG_SYNC_INPUT | QDIO_FLAG_UNDER_INTERRUPT,
408 0, start, count, NULL);
410 if (unlikely(retval)) {
411 atomic_set(&queue->free_count, count);
412 ZFCP_LOG_DEBUG("clearing of inbound data regions failed, "
413 "queues may be down "
414 "(count=%d, start=%d, retval=%d)\n",
415 count, start, retval);
417 queue->free_index += count;
418 queue->free_index %= QDIO_MAX_BUFFERS_PER_Q;
419 atomic_set(&queue->free_count, 0);
420 ZFCP_LOG_TRACE("%i buffers enqueued to response "
421 "queue at position %i\n", count, start);
428 * function: zfcp_qdio_reqid_check
430 * purpose: checks for valid reqids or unsolicited status
432 * returns: 0 - valid request id or unsolicited status
436 zfcp_qdio_reqid_check(struct zfcp_adapter *adapter, void *sbale_addr)
438 struct zfcp_fsf_req *fsf_req;
440 /* invalid (per convention used in this driver) */
441 if (unlikely(!sbale_addr)) {
442 ZFCP_LOG_NORMAL("bug: invalid reqid\n");
446 /* valid request id and thus (hopefully :) valid fsf_req address */
447 fsf_req = (struct zfcp_fsf_req *) sbale_addr;
449 /* serialize with zfcp_fsf_req_dismiss_all */
450 spin_lock(&adapter->fsf_req_list_lock);
451 if (list_empty(&adapter->fsf_req_list_head)) {
452 spin_unlock(&adapter->fsf_req_list_lock);
455 list_del(&fsf_req->list);
456 atomic_dec(&adapter->fsf_reqs_active);
457 spin_unlock(&adapter->fsf_req_list_lock);
459 if (unlikely(adapter != fsf_req->adapter)) {
460 ZFCP_LOG_NORMAL("bug: invalid reqid (fsf_req=%p, "
461 "fsf_req->adapter=%p, adapter=%p)\n",
462 fsf_req, fsf_req->adapter, adapter);
466 /* finish the FSF request */
467 zfcp_fsf_req_complete(fsf_req);
473 * zfcp_qdio_sbale_get - return pointer to SBALE of qdio_queue
474 * @queue: queue from which SBALE should be returned
475 * @sbal: specifies number of SBAL in queue
476 * @sbale: specifes number of SBALE in SBAL
478 static inline volatile struct qdio_buffer_element *
479 zfcp_qdio_sbale_get(struct zfcp_qdio_queue *queue, int sbal, int sbale)
481 return &queue->buffer[sbal]->element[sbale];
485 * zfcp_qdio_sbale_req - return pointer to SBALE of request_queue for
486 * a struct zfcp_fsf_req
488 inline volatile struct qdio_buffer_element *
489 zfcp_qdio_sbale_req(struct zfcp_fsf_req *fsf_req, int sbal, int sbale)
491 return zfcp_qdio_sbale_get(&fsf_req->adapter->request_queue,
496 * zfcp_qdio_sbale_resp - return pointer to SBALE of response_queue for
497 * a struct zfcp_fsf_req
499 static inline volatile struct qdio_buffer_element *
500 zfcp_qdio_sbale_resp(struct zfcp_fsf_req *fsf_req, int sbal, int sbale)
502 return zfcp_qdio_sbale_get(&fsf_req->adapter->response_queue,
507 * zfcp_qdio_sbale_curr - return current SBALE on request_queue for
508 * a struct zfcp_fsf_req
510 inline volatile struct qdio_buffer_element *
511 zfcp_qdio_sbale_curr(struct zfcp_fsf_req *fsf_req)
513 return zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr,
514 fsf_req->sbale_curr);
518 * zfcp_qdio_sbal_limit - determine maximum number of SBALs that can be used
519 * on the request_queue for a struct zfcp_fsf_req
520 * @fsf_req: the number of the last SBAL that can be used is stored herein
521 * @max_sbals: used to pass an upper limit for the number of SBALs
523 * Note: We can assume at least one free SBAL in the request_queue when called.
526 zfcp_qdio_sbal_limit(struct zfcp_fsf_req *fsf_req, int max_sbals)
528 int count = atomic_read(&fsf_req->adapter->request_queue.free_count);
529 count = min(count, max_sbals);
530 fsf_req->sbal_last = fsf_req->sbal_first;
531 fsf_req->sbal_last += (count - 1);
532 fsf_req->sbal_last %= QDIO_MAX_BUFFERS_PER_Q;
536 * zfcp_qdio_sbal_chain - chain SBALs if more than one SBAL is needed for a
538 * @fsf_req: zfcp_fsf_req to be processed
539 * @sbtype: SBAL flags which have to be set in first SBALE of new SBAL
541 * This function changes sbal_curr, sbale_curr, sbal_number of fsf_req.
543 static inline volatile struct qdio_buffer_element *
544 zfcp_qdio_sbal_chain(struct zfcp_fsf_req *fsf_req, unsigned long sbtype)
546 volatile struct qdio_buffer_element *sbale;
548 /* set last entry flag in current SBALE of current SBAL */
549 sbale = zfcp_qdio_sbale_curr(fsf_req);
550 sbale->flags |= SBAL_FLAGS_LAST_ENTRY;
552 /* don't exceed last allowed SBAL */
553 if (fsf_req->sbal_curr == fsf_req->sbal_last)
556 /* set chaining flag in first SBALE of current SBAL */
557 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
558 sbale->flags |= SBAL_FLAGS0_MORE_SBALS;
560 /* calculate index of next SBAL */
561 fsf_req->sbal_curr++;
562 fsf_req->sbal_curr %= QDIO_MAX_BUFFERS_PER_Q;
564 /* keep this requests number of SBALs up-to-date */
565 fsf_req->sbal_number++;
567 /* start at first SBALE of new SBAL */
568 fsf_req->sbale_curr = 0;
570 /* set storage-block type for new SBAL */
571 sbale = zfcp_qdio_sbale_curr(fsf_req);
572 sbale->flags |= sbtype;
578 * zfcp_qdio_sbale_next - switch to next SBALE, chain SBALs if needed
580 static inline volatile struct qdio_buffer_element *
581 zfcp_qdio_sbale_next(struct zfcp_fsf_req *fsf_req, unsigned long sbtype)
583 if (fsf_req->sbale_curr == ZFCP_LAST_SBALE_PER_SBAL)
584 return zfcp_qdio_sbal_chain(fsf_req, sbtype);
586 fsf_req->sbale_curr++;
588 return zfcp_qdio_sbale_curr(fsf_req);
592 * zfcp_qdio_sbals_zero - initialize SBALs between first and last in queue
596 zfcp_qdio_sbals_zero(struct zfcp_qdio_queue *queue, int first, int last)
598 struct qdio_buffer **buf = queue->buffer;
603 curr %= QDIO_MAX_BUFFERS_PER_Q;
605 memset(buf[curr], 0, sizeof(struct qdio_buffer));
615 * zfcp_qdio_sbals_wipe - reset all changes in SBALs for an fsf_req
618 zfcp_qdio_sbals_wipe(struct zfcp_fsf_req *fsf_req)
620 return zfcp_qdio_sbals_zero(&fsf_req->adapter->request_queue,
621 fsf_req->sbal_first, fsf_req->sbal_curr);
626 * zfcp_qdio_sbale_fill - set address and lenght in current SBALE
630 zfcp_qdio_sbale_fill(struct zfcp_fsf_req *fsf_req, unsigned long sbtype,
631 void *addr, int length)
633 volatile struct qdio_buffer_element *sbale;
635 sbale = zfcp_qdio_sbale_curr(fsf_req);
637 sbale->length = length;
641 * zfcp_qdio_sbals_from_segment - map memory segment to SBALE(s)
642 * @fsf_req: request to be processed
643 * @sbtype: SBALE flags
644 * @start_addr: address of memory segment
645 * @total_length: length of memory segment
647 * Alignment and length of the segment determine how many SBALEs are needed
648 * for the memory segment.
651 zfcp_qdio_sbals_from_segment(struct zfcp_fsf_req *fsf_req, unsigned long sbtype,
652 void *start_addr, unsigned long total_length)
654 unsigned long remaining, length;
657 /* split segment up heeding page boundaries */
658 for (addr = start_addr, remaining = total_length; remaining > 0;
659 addr += length, remaining -= length) {
660 /* get next free SBALE for new piece */
661 if (NULL == zfcp_qdio_sbale_next(fsf_req, sbtype)) {
662 /* no SBALE left, clean up and leave */
663 zfcp_qdio_sbals_wipe(fsf_req);
666 /* calculate length of new piece */
667 length = min(remaining,
668 (PAGE_SIZE - ((unsigned long) addr &
670 /* fill current SBALE with calculated piece */
671 zfcp_qdio_sbale_fill(fsf_req, sbtype, addr, length);
678 * zfcp_qdio_sbals_from_sg - fill SBALs from scatter-gather list
679 * @fsf_req: request to be processed
680 * @sbtype: SBALE flags
681 * @sg: scatter-gather list
682 * @sg_count: number of elements in scatter-gather list
683 * @max_sbals: upper bound for number of SBALs to be used
686 zfcp_qdio_sbals_from_sg(struct zfcp_fsf_req *fsf_req, unsigned long sbtype,
687 struct scatterlist *sg, int sg_count, int max_sbals)
690 struct scatterlist *sg_segment;
692 volatile struct qdio_buffer_element *sbale;
695 /* figure out last allowed SBAL */
696 zfcp_qdio_sbal_limit(fsf_req, max_sbals);
698 /* set storage-block type for current SBAL */
699 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
700 sbale->flags |= sbtype;
702 /* process all segements of scatter-gather list */
703 for (sg_index = 0, sg_segment = sg, bytes = 0;
705 sg_index++, sg_segment++) {
706 retval = zfcp_qdio_sbals_from_segment(
709 zfcp_sg_to_address(sg_segment),
717 /* assume that no other SBALEs are to follow in the same SBAL */
718 sbale = zfcp_qdio_sbale_curr(fsf_req);
719 sbale->flags |= SBAL_FLAGS_LAST_ENTRY;
726 * zfcp_qdio_sbals_from_buffer - fill SBALs from buffer
727 * @fsf_req: request to be processed
728 * @sbtype: SBALE flags
729 * @buffer: data buffer
730 * @length: length of buffer
731 * @max_sbals: upper bound for number of SBALs to be used
734 zfcp_qdio_sbals_from_buffer(struct zfcp_fsf_req *fsf_req, unsigned long sbtype,
735 void *buffer, unsigned long length, int max_sbals)
737 struct scatterlist sg_segment;
739 zfcp_address_to_sg(buffer, &sg_segment);
740 sg_segment.length = length;
742 return zfcp_qdio_sbals_from_sg(fsf_req, sbtype, &sg_segment, 1,
748 * zfcp_qdio_sbals_from_scsicmnd - fill SBALs from scsi command
749 * @fsf_req: request to be processed
750 * @sbtype: SBALE flags
751 * @scsi_cmnd: either scatter-gather list or buffer contained herein is used
755 zfcp_qdio_sbals_from_scsicmnd(struct zfcp_fsf_req *fsf_req,
756 unsigned long sbtype, struct scsi_cmnd *scsi_cmnd)
758 if (scsi_cmnd->use_sg) {
759 return zfcp_qdio_sbals_from_sg(fsf_req, sbtype,
760 (struct scatterlist *)
761 scsi_cmnd->request_buffer,
763 ZFCP_MAX_SBALS_PER_REQ);
765 return zfcp_qdio_sbals_from_buffer(fsf_req, sbtype,
766 scsi_cmnd->request_buffer,
767 scsi_cmnd->request_bufflen,
768 ZFCP_MAX_SBALS_PER_REQ);
773 * zfcp_qdio_determine_pci - set PCI flag in first SBALE on qdio queue if needed
776 zfcp_qdio_determine_pci(struct zfcp_qdio_queue *req_queue,
777 struct zfcp_fsf_req *fsf_req)
779 int new_distance_from_int;
781 volatile struct qdio_buffer_element *sbale;
783 new_distance_from_int = req_queue->distance_from_int +
784 fsf_req->sbal_number;
786 if (unlikely(new_distance_from_int >= ZFCP_QDIO_PCI_INTERVAL)) {
787 new_distance_from_int %= ZFCP_QDIO_PCI_INTERVAL;
788 pci_pos = fsf_req->sbal_first;
789 pci_pos += fsf_req->sbal_number;
790 pci_pos -= new_distance_from_int;
792 pci_pos %= QDIO_MAX_BUFFERS_PER_Q;
793 sbale = zfcp_qdio_sbale_req(fsf_req, pci_pos, 0);
794 sbale->flags |= SBAL_FLAGS0_PCI;
796 return new_distance_from_int;
800 * function: zfcp_zero_sbals
802 * purpose: zeros specified range of SBALs
807 zfcp_qdio_zero_sbals(struct qdio_buffer *buf[], int first, int clean_count)
812 for (cur_pos = first; cur_pos < (first + clean_count); cur_pos++) {
813 index = cur_pos % QDIO_MAX_BUFFERS_PER_Q;
814 memset(buf[index], 0, sizeof (struct qdio_buffer));
815 ZFCP_LOG_TRACE("zeroing BUFFER %d at address %p\n",