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.
32 #define ZFCP_QDIO_C_REVISION "$Revision: 1.20 $"
36 static inline void zfcp_qdio_sbal_limit(struct zfcp_fsf_req *, int);
37 static inline volatile struct qdio_buffer_element *zfcp_qdio_sbale_get
38 (struct zfcp_qdio_queue *, int, int);
39 static inline volatile struct qdio_buffer_element *zfcp_qdio_sbale_resp
40 (struct zfcp_fsf_req *, int, int);
41 static inline volatile struct qdio_buffer_element *zfcp_qdio_sbal_chain
42 (struct zfcp_fsf_req *, unsigned long);
43 static inline volatile struct qdio_buffer_element *zfcp_qdio_sbale_next
44 (struct zfcp_fsf_req *, unsigned long);
45 static inline int zfcp_qdio_sbals_zero(struct zfcp_qdio_queue *, int, int);
46 static inline int zfcp_qdio_sbals_wipe(struct zfcp_fsf_req *);
47 static inline void zfcp_qdio_sbale_fill
48 (struct zfcp_fsf_req *, unsigned long, void *, int);
49 static inline int zfcp_qdio_sbals_from_segment
50 (struct zfcp_fsf_req *, unsigned long, void *, unsigned long);
51 static inline int zfcp_qdio_sbals_from_buffer
52 (struct zfcp_fsf_req *, unsigned long, void *, unsigned long, int);
54 static qdio_handler_t zfcp_qdio_request_handler;
55 static qdio_handler_t zfcp_qdio_response_handler;
56 static int zfcp_qdio_handler_error_check(struct zfcp_adapter *,
57 unsigned int, unsigned int, unsigned int, int, int);
59 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_QDIO
62 * Allocates BUFFER memory to each of the pointers of the qdio_buffer_t
63 * array in the adapter struct.
64 * Cur_buf is the pointer array and count can be any number of required
65 * buffers, the page-fitting arithmetic is done entirely within this funciton.
67 * returns: number of buffers allocated
68 * locks: must only be called with zfcp_data.config_sema taken
71 zfcp_qdio_buffers_enqueue(struct qdio_buffer **cur_buf, int count)
74 int qdio_buffers_per_page;
76 struct qdio_buffer *first_in_page = NULL;
78 qdio_buffers_per_page = PAGE_SIZE / sizeof (struct qdio_buffer);
79 ZFCP_LOG_TRACE("buffers_per_page=%d\n", qdio_buffers_per_page);
81 for (buf_pos = 0; buf_pos < count; buf_pos++) {
83 cur_buf[buf_pos] = (struct qdio_buffer *)
84 get_zeroed_page(GFP_KERNEL);
85 if (cur_buf[buf_pos] == NULL) {
86 ZFCP_LOG_INFO("error: allocation of "
87 "QDIO buffer failed \n");
90 first_in_page = cur_buf[buf_pos];
92 cur_buf[buf_pos] = first_in_page + page_pos;
95 /* was initialised to zero */
97 page_pos %= qdio_buffers_per_page;
104 * Frees BUFFER memory for each of the pointers of the struct qdio_buffer array
105 * in the adapter struct cur_buf is the pointer array and count can be any
106 * number of buffers in the array that should be freed starting from buffer 0
108 * locks: must only be called with zfcp_data.config_sema taken
111 zfcp_qdio_buffers_dequeue(struct qdio_buffer **cur_buf, int count)
114 int qdio_buffers_per_page;
116 qdio_buffers_per_page = PAGE_SIZE / sizeof (struct qdio_buffer);
117 ZFCP_LOG_TRACE("buffers_per_page=%d\n", qdio_buffers_per_page);
119 for (buf_pos = 0; buf_pos < count; buf_pos += qdio_buffers_per_page)
120 free_page((unsigned long) cur_buf[buf_pos]);
124 /* locks: must only be called with zfcp_data.config_sema taken */
126 zfcp_qdio_allocate_queues(struct zfcp_adapter *adapter)
132 zfcp_qdio_buffers_enqueue(&(adapter->request_queue.buffer[0]),
133 QDIO_MAX_BUFFERS_PER_Q);
134 if (buffer_count < QDIO_MAX_BUFFERS_PER_Q) {
135 ZFCP_LOG_DEBUG("only %d QDIO buffers allocated for request "
136 "queue\n", buffer_count);
137 zfcp_qdio_buffers_dequeue(&(adapter->request_queue.buffer[0]),
144 zfcp_qdio_buffers_enqueue(&(adapter->response_queue.buffer[0]),
145 QDIO_MAX_BUFFERS_PER_Q);
146 if (buffer_count < QDIO_MAX_BUFFERS_PER_Q) {
147 ZFCP_LOG_DEBUG("only %d QDIO buffers allocated for response "
148 "queue", buffer_count);
149 zfcp_qdio_buffers_dequeue(&(adapter->response_queue.buffer[0]),
151 ZFCP_LOG_TRACE("freeing request_queue buffers\n");
152 zfcp_qdio_buffers_dequeue(&(adapter->request_queue.buffer[0]),
153 QDIO_MAX_BUFFERS_PER_Q);
161 /* locks: must only be called with zfcp_data.config_sema taken */
163 zfcp_qdio_free_queues(struct zfcp_adapter *adapter)
165 ZFCP_LOG_TRACE("freeing request_queue buffers\n");
166 zfcp_qdio_buffers_dequeue(&(adapter->request_queue.buffer[0]),
167 QDIO_MAX_BUFFERS_PER_Q);
169 ZFCP_LOG_TRACE("freeing response_queue buffers\n");
170 zfcp_qdio_buffers_dequeue(&(adapter->response_queue.buffer[0]),
171 QDIO_MAX_BUFFERS_PER_Q);
175 zfcp_qdio_allocate(struct zfcp_adapter *adapter)
177 struct qdio_initialize *init_data;
179 init_data = &adapter->qdio_init_data;
181 init_data->cdev = adapter->ccw_device;
182 init_data->q_format = QDIO_SCSI_QFMT;
183 memcpy(init_data->adapter_name, &adapter->name, 8);
184 init_data->qib_param_field_format = 0;
185 init_data->qib_param_field = NULL;
186 init_data->input_slib_elements = NULL;
187 init_data->output_slib_elements = NULL;
188 init_data->min_input_threshold = ZFCP_MIN_INPUT_THRESHOLD;
189 init_data->max_input_threshold = ZFCP_MAX_INPUT_THRESHOLD;
190 init_data->min_output_threshold = ZFCP_MIN_OUTPUT_THRESHOLD;
191 init_data->max_output_threshold = ZFCP_MAX_OUTPUT_THRESHOLD;
192 init_data->no_input_qs = 1;
193 init_data->no_output_qs = 1;
194 init_data->input_handler = zfcp_qdio_response_handler;
195 init_data->output_handler = zfcp_qdio_request_handler;
196 init_data->int_parm = (unsigned long) adapter;
197 init_data->flags = QDIO_INBOUND_0COPY_SBALS |
198 QDIO_OUTBOUND_0COPY_SBALS | QDIO_USE_OUTBOUND_PCIS;
199 init_data->input_sbal_addr_array =
200 (void **) (adapter->response_queue.buffer);
201 init_data->output_sbal_addr_array =
202 (void **) (adapter->request_queue.buffer);
204 return qdio_allocate(init_data);
208 * function: zfcp_qdio_handler_error_check
210 * purpose: called by the response handler to determine error condition
212 * returns: error flag
216 zfcp_qdio_handler_error_check(struct zfcp_adapter *adapter, unsigned int status,
217 unsigned int qdio_error, unsigned int siga_error,
218 int first_element, int elements_processed)
222 if (unlikely(status & QDIO_STATUS_LOOK_FOR_ERROR)) {
225 ZFCP_LOG_INFO("QDIO problem occurred (status=0x%x, "
226 "qdio_error=0x%x, siga_error=0x%x)\n",
227 status, qdio_error, siga_error);
229 zfcp_hba_dbf_event_qdio(adapter, status, qdio_error, siga_error,
230 first_element, elements_processed);
232 * Restarting IO on the failed adapter from scratch.
233 * Since we have been using this adapter, it is save to assume
234 * that it is not failed but recoverable. The card seems to
235 * report link-up events by self-initiated queue shutdown.
236 * That is why we need to clear the the link-down flag
237 * which is set again in case we have missed by a mile.
239 zfcp_erp_adapter_reopen(
241 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
242 ZFCP_STATUS_COMMON_ERP_FAILED);
248 * function: zfcp_qdio_request_handler
250 * purpose: is called by QDIO layer for completed SBALs in request queue
255 zfcp_qdio_request_handler(struct ccw_device *ccw_device,
257 unsigned int qdio_error,
258 unsigned int siga_error,
259 unsigned int queue_number,
261 int elements_processed,
262 unsigned long int_parm)
264 struct zfcp_adapter *adapter;
265 struct zfcp_qdio_queue *queue;
267 adapter = (struct zfcp_adapter *) int_parm;
268 queue = &adapter->request_queue;
270 ZFCP_LOG_DEBUG("adapter %s, first=%d, elements_processed=%d\n",
271 zfcp_get_busid_by_adapter(adapter),
272 first_element, elements_processed);
274 if (unlikely(zfcp_qdio_handler_error_check(adapter, status, qdio_error,
275 siga_error, first_element,
276 elements_processed)))
279 * we stored address of struct zfcp_adapter data structure
280 * associated with irq in int_parm
283 /* cleanup all SBALs being program-owned now */
284 zfcp_qdio_zero_sbals(queue->buffer, first_element, elements_processed);
286 /* increase free space in outbound queue */
287 atomic_add(elements_processed, &queue->free_count);
288 ZFCP_LOG_DEBUG("free_count=%d\n", atomic_read(&queue->free_count));
289 wake_up(&adapter->request_wq);
290 ZFCP_LOG_DEBUG("elements_processed=%d, free count=%d\n",
291 elements_processed, atomic_read(&queue->free_count));
297 * function: zfcp_qdio_response_handler
299 * purpose: is called by QDIO layer for completed SBALs in response queue
304 zfcp_qdio_response_handler(struct ccw_device *ccw_device,
306 unsigned int qdio_error,
307 unsigned int siga_error,
308 unsigned int queue_number,
310 int elements_processed,
311 unsigned long int_parm)
313 struct zfcp_adapter *adapter;
314 struct zfcp_qdio_queue *queue;
317 struct qdio_buffer *buffer;
321 volatile struct qdio_buffer_element *buffere = NULL;
324 adapter = (struct zfcp_adapter *) int_parm;
325 queue = &adapter->response_queue;
327 if (unlikely(zfcp_qdio_handler_error_check(adapter, status, qdio_error,
328 siga_error, first_element,
329 elements_processed)))
333 * we stored address of struct zfcp_adapter data structure
334 * associated with irq in int_parm
337 buffere = &(queue->buffer[first_element]->element[0]);
338 ZFCP_LOG_DEBUG("first BUFFERE flags=0x%x\n", buffere->flags);
340 * go through all SBALs from input queue currently
341 * returned by QDIO layer
344 for (i = 0; i < elements_processed; i++) {
346 buffer_index = first_element + i;
347 buffer_index %= QDIO_MAX_BUFFERS_PER_Q;
348 buffer = queue->buffer[buffer_index];
350 /* go through all SBALEs of SBAL */
351 for (buffere_index = 0;
352 buffere_index < QDIO_MAX_ELEMENTS_PER_BUFFER;
355 /* look for QDIO request identifiers in SB */
356 buffere = &buffer->element[buffere_index];
357 retval = zfcp_qdio_reqid_check(adapter,
358 (void *) buffere->addr);
361 ZFCP_LOG_NORMAL("bug: unexpected inbound "
362 "packet on adapter %s "
365 "elements_processed=%d)\n",
366 zfcp_get_busid_by_adapter(adapter),
367 (unsigned long) buffere->addr,
370 ZFCP_LOG_NORMAL("hex dump of inbound buffer "
373 "buffere_index=%d)\n", buffer,
374 buffer_index, buffere_index);
375 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
376 (char *) buffer, SBAL_SIZE);
379 * A single used SBALE per inbound SBALE has been
380 * implemented by QDIO so far. Hope they will
381 * do some optimisation. Will need to change to
384 if (likely(buffere->flags & SBAL_FLAGS_LAST_ENTRY))
388 if (unlikely(!(buffere->flags & SBAL_FLAGS_LAST_ENTRY))) {
389 ZFCP_LOG_NORMAL("bug: End of inbound data "
395 * put range of SBALs back to response queue
396 * (including SBALs which have already been free before)
398 count = atomic_read(&queue->free_count) + elements_processed;
399 start = queue->free_index;
401 ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
402 "queue_no=%i, index_in_queue=%i, count=%i, "
404 zfcp_get_busid_by_adapter(adapter),
405 QDIO_FLAG_SYNC_INPUT | QDIO_FLAG_UNDER_INTERRUPT,
406 0, start, count, (unsigned long) &queue->buffer[start]);
408 retval = do_QDIO(ccw_device,
409 QDIO_FLAG_SYNC_INPUT | QDIO_FLAG_UNDER_INTERRUPT,
410 0, start, count, NULL);
412 if (unlikely(retval)) {
413 atomic_set(&queue->free_count, count);
414 ZFCP_LOG_DEBUG("clearing of inbound data regions failed, "
415 "queues may be down "
416 "(count=%d, start=%d, retval=%d)\n",
417 count, start, retval);
419 queue->free_index += count;
420 queue->free_index %= QDIO_MAX_BUFFERS_PER_Q;
421 atomic_set(&queue->free_count, 0);
422 ZFCP_LOG_TRACE("%i buffers enqueued to response "
423 "queue at position %i\n", count, start);
430 * function: zfcp_qdio_reqid_check
432 * purpose: checks for valid reqids or unsolicited status
434 * returns: 0 - valid request id or unsolicited status
438 zfcp_qdio_reqid_check(struct zfcp_adapter *adapter, void *sbale_addr)
440 struct zfcp_fsf_req *fsf_req;
442 /* invalid (per convention used in this driver) */
443 if (unlikely(!sbale_addr)) {
444 ZFCP_LOG_NORMAL("bug: invalid reqid\n");
448 /* valid request id and thus (hopefully :) valid fsf_req address */
449 fsf_req = (struct zfcp_fsf_req *) sbale_addr;
451 /* serialize with zfcp_fsf_req_dismiss_all */
452 spin_lock(&adapter->fsf_req_list_lock);
453 if (list_empty(&adapter->fsf_req_list_head)) {
454 spin_unlock(&adapter->fsf_req_list_lock);
457 list_del(&fsf_req->list);
458 atomic_dec(&adapter->fsf_reqs_active);
459 spin_unlock(&adapter->fsf_req_list_lock);
461 if (unlikely(adapter != fsf_req->adapter)) {
462 ZFCP_LOG_NORMAL("bug: invalid reqid (fsf_req=%p, "
463 "fsf_req->adapter=%p, adapter=%p)\n",
464 fsf_req, fsf_req->adapter, adapter);
468 /* finish the FSF request */
469 zfcp_fsf_req_complete(fsf_req);
475 * zfcp_qdio_sbale_get - return pointer to SBALE of qdio_queue
476 * @queue: queue from which SBALE should be returned
477 * @sbal: specifies number of SBAL in queue
478 * @sbale: specifes number of SBALE in SBAL
480 static inline volatile struct qdio_buffer_element *
481 zfcp_qdio_sbale_get(struct zfcp_qdio_queue *queue, int sbal, int sbale)
483 return &queue->buffer[sbal]->element[sbale];
487 * zfcp_qdio_sbale_req - return pointer to SBALE of request_queue for
488 * a struct zfcp_fsf_req
490 inline volatile struct qdio_buffer_element *
491 zfcp_qdio_sbale_req(struct zfcp_fsf_req *fsf_req, int sbal, int sbale)
493 return zfcp_qdio_sbale_get(&fsf_req->adapter->request_queue,
498 * zfcp_qdio_sbale_resp - return pointer to SBALE of response_queue for
499 * a struct zfcp_fsf_req
501 static inline volatile struct qdio_buffer_element *
502 zfcp_qdio_sbale_resp(struct zfcp_fsf_req *fsf_req, int sbal, int sbale)
504 return zfcp_qdio_sbale_get(&fsf_req->adapter->response_queue,
509 * zfcp_qdio_sbale_curr - return current SBALE on request_queue for
510 * a struct zfcp_fsf_req
512 inline volatile struct qdio_buffer_element *
513 zfcp_qdio_sbale_curr(struct zfcp_fsf_req *fsf_req)
515 return zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr,
516 fsf_req->sbale_curr);
520 * zfcp_qdio_sbal_limit - determine maximum number of SBALs that can be used
521 * on the request_queue for a struct zfcp_fsf_req
522 * @fsf_req: the number of the last SBAL that can be used is stored herein
523 * @max_sbals: used to pass an upper limit for the number of SBALs
525 * Note: We can assume at least one free SBAL in the request_queue when called.
528 zfcp_qdio_sbal_limit(struct zfcp_fsf_req *fsf_req, int max_sbals)
530 int count = atomic_read(&fsf_req->adapter->request_queue.free_count);
531 count = min(count, max_sbals);
532 fsf_req->sbal_last = fsf_req->sbal_first;
533 fsf_req->sbal_last += (count - 1);
534 fsf_req->sbal_last %= QDIO_MAX_BUFFERS_PER_Q;
538 * zfcp_qdio_sbal_chain - chain SBALs if more than one SBAL is needed for a
540 * @fsf_req: zfcp_fsf_req to be processed
541 * @sbtype: SBAL flags which have to be set in first SBALE of new SBAL
543 * This function changes sbal_curr, sbale_curr, sbal_number of fsf_req.
545 static inline volatile struct qdio_buffer_element *
546 zfcp_qdio_sbal_chain(struct zfcp_fsf_req *fsf_req, unsigned long sbtype)
548 volatile struct qdio_buffer_element *sbale;
550 /* set last entry flag in current SBALE of current SBAL */
551 sbale = zfcp_qdio_sbale_curr(fsf_req);
552 sbale->flags |= SBAL_FLAGS_LAST_ENTRY;
554 /* don't exceed last allowed SBAL */
555 if (fsf_req->sbal_curr == fsf_req->sbal_last)
558 /* set chaining flag in first SBALE of current SBAL */
559 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
560 sbale->flags |= SBAL_FLAGS0_MORE_SBALS;
562 /* calculate index of next SBAL */
563 fsf_req->sbal_curr++;
564 fsf_req->sbal_curr %= QDIO_MAX_BUFFERS_PER_Q;
566 /* keep this requests number of SBALs up-to-date */
567 fsf_req->sbal_number++;
569 /* start at first SBALE of new SBAL */
570 fsf_req->sbale_curr = 0;
572 /* set storage-block type for new SBAL */
573 sbale = zfcp_qdio_sbale_curr(fsf_req);
574 sbale->flags |= sbtype;
580 * zfcp_qdio_sbale_next - switch to next SBALE, chain SBALs if needed
582 static inline volatile struct qdio_buffer_element *
583 zfcp_qdio_sbale_next(struct zfcp_fsf_req *fsf_req, unsigned long sbtype)
585 if (fsf_req->sbale_curr == ZFCP_LAST_SBALE_PER_SBAL)
586 return zfcp_qdio_sbal_chain(fsf_req, sbtype);
588 fsf_req->sbale_curr++;
590 return zfcp_qdio_sbale_curr(fsf_req);
594 * zfcp_qdio_sbals_zero - initialize SBALs between first and last in queue
598 zfcp_qdio_sbals_zero(struct zfcp_qdio_queue *queue, int first, int last)
600 struct qdio_buffer **buf = queue->buffer;
605 curr %= QDIO_MAX_BUFFERS_PER_Q;
607 memset(buf[curr], 0, sizeof(struct qdio_buffer));
617 * zfcp_qdio_sbals_wipe - reset all changes in SBALs for an fsf_req
620 zfcp_qdio_sbals_wipe(struct zfcp_fsf_req *fsf_req)
622 return zfcp_qdio_sbals_zero(&fsf_req->adapter->request_queue,
623 fsf_req->sbal_first, fsf_req->sbal_curr);
628 * zfcp_qdio_sbale_fill - set address and lenght in current SBALE
632 zfcp_qdio_sbale_fill(struct zfcp_fsf_req *fsf_req, unsigned long sbtype,
633 void *addr, int length)
635 volatile struct qdio_buffer_element *sbale;
637 sbale = zfcp_qdio_sbale_curr(fsf_req);
639 sbale->length = length;
643 * zfcp_qdio_sbals_from_segment - map memory segment to SBALE(s)
644 * @fsf_req: request to be processed
645 * @sbtype: SBALE flags
646 * @start_addr: address of memory segment
647 * @total_length: length of memory segment
649 * Alignment and length of the segment determine how many SBALEs are needed
650 * for the memory segment.
653 zfcp_qdio_sbals_from_segment(struct zfcp_fsf_req *fsf_req, unsigned long sbtype,
654 void *start_addr, unsigned long total_length)
656 unsigned long remaining, length;
659 /* split segment up heeding page boundaries */
660 for (addr = start_addr, remaining = total_length; remaining > 0;
661 addr += length, remaining -= length) {
662 /* get next free SBALE for new piece */
663 if (NULL == zfcp_qdio_sbale_next(fsf_req, sbtype)) {
664 /* no SBALE left, clean up and leave */
665 zfcp_qdio_sbals_wipe(fsf_req);
668 /* calculate length of new piece */
669 length = min(remaining,
670 (PAGE_SIZE - ((unsigned long) addr &
672 /* fill current SBALE with calculated piece */
673 zfcp_qdio_sbale_fill(fsf_req, sbtype, addr, length);
680 * zfcp_qdio_sbals_from_sg - fill SBALs from scatter-gather list
681 * @fsf_req: request to be processed
682 * @sbtype: SBALE flags
683 * @sg: scatter-gather list
684 * @sg_count: number of elements in scatter-gather list
685 * @max_sbals: upper bound for number of SBALs to be used
688 zfcp_qdio_sbals_from_sg(struct zfcp_fsf_req *fsf_req, unsigned long sbtype,
689 struct scatterlist *sg, int sg_count, int max_sbals)
692 struct scatterlist *sg_segment;
694 volatile struct qdio_buffer_element *sbale;
697 /* figure out last allowed SBAL */
698 zfcp_qdio_sbal_limit(fsf_req, max_sbals);
700 /* set storage-block type for current SBAL */
701 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
702 sbale->flags |= sbtype;
704 /* process all segements of scatter-gather list */
705 for (sg_index = 0, sg_segment = sg, bytes = 0;
707 sg_index++, sg_segment++) {
708 retval = zfcp_qdio_sbals_from_segment(
711 zfcp_sg_to_address(sg_segment),
719 /* assume that no other SBALEs are to follow in the same SBAL */
720 sbale = zfcp_qdio_sbale_curr(fsf_req);
721 sbale->flags |= SBAL_FLAGS_LAST_ENTRY;
728 * zfcp_qdio_sbals_from_buffer - fill SBALs from buffer
729 * @fsf_req: request to be processed
730 * @sbtype: SBALE flags
731 * @buffer: data buffer
732 * @length: length of buffer
733 * @max_sbals: upper bound for number of SBALs to be used
736 zfcp_qdio_sbals_from_buffer(struct zfcp_fsf_req *fsf_req, unsigned long sbtype,
737 void *buffer, unsigned long length, int max_sbals)
739 struct scatterlist sg_segment;
741 zfcp_address_to_sg(buffer, &sg_segment);
742 sg_segment.length = length;
744 return zfcp_qdio_sbals_from_sg(fsf_req, sbtype, &sg_segment, 1,
750 * zfcp_qdio_sbals_from_scsicmnd - fill SBALs from scsi command
751 * @fsf_req: request to be processed
752 * @sbtype: SBALE flags
753 * @scsi_cmnd: either scatter-gather list or buffer contained herein is used
757 zfcp_qdio_sbals_from_scsicmnd(struct zfcp_fsf_req *fsf_req,
758 unsigned long sbtype, struct scsi_cmnd *scsi_cmnd)
760 if (scsi_cmnd->use_sg) {
761 return zfcp_qdio_sbals_from_sg(fsf_req, sbtype,
762 (struct scatterlist *)
763 scsi_cmnd->request_buffer,
765 ZFCP_MAX_SBALS_PER_REQ);
767 return zfcp_qdio_sbals_from_buffer(fsf_req, sbtype,
768 scsi_cmnd->request_buffer,
769 scsi_cmnd->request_bufflen,
770 ZFCP_MAX_SBALS_PER_REQ);
775 * zfcp_qdio_determine_pci - set PCI flag in first SBALE on qdio queue if needed
778 zfcp_qdio_determine_pci(struct zfcp_qdio_queue *req_queue,
779 struct zfcp_fsf_req *fsf_req)
781 int new_distance_from_int;
783 volatile struct qdio_buffer_element *sbale;
785 new_distance_from_int = req_queue->distance_from_int +
786 fsf_req->sbal_number;
788 if (unlikely(new_distance_from_int >= ZFCP_QDIO_PCI_INTERVAL)) {
789 new_distance_from_int %= ZFCP_QDIO_PCI_INTERVAL;
790 pci_pos = fsf_req->sbal_first;
791 pci_pos += fsf_req->sbal_number;
792 pci_pos -= new_distance_from_int;
794 pci_pos %= QDIO_MAX_BUFFERS_PER_Q;
795 sbale = zfcp_qdio_sbale_req(fsf_req, pci_pos, 0);
796 sbale->flags |= SBAL_FLAGS0_PCI;
798 return new_distance_from_int;
802 * function: zfcp_zero_sbals
804 * purpose: zeros specified range of SBALs
809 zfcp_qdio_zero_sbals(struct qdio_buffer *buf[], int first, int clean_count)
814 for (cur_pos = first; cur_pos < (first + clean_count); cur_pos++) {
815 index = cur_pos % QDIO_MAX_BUFFERS_PER_Q;
816 memset(buf[index], 0, sizeof (struct qdio_buffer));
817 ZFCP_LOG_TRACE("zeroing BUFFER %d at address %p\n",