2 * This file is part of the zfcp device driver for
3 * FCP adapters for IBM System z9 and zSeries.
5 * (C) Copyright IBM Corp. 2002, 2006
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 static inline void zfcp_qdio_sbal_limit(struct zfcp_fsf_req *, int);
25 static inline volatile struct qdio_buffer_element *zfcp_qdio_sbale_get
26 (struct zfcp_qdio_queue *, int, int);
27 static inline volatile struct qdio_buffer_element *zfcp_qdio_sbale_resp
28 (struct zfcp_fsf_req *, int, int);
29 static inline volatile struct qdio_buffer_element *zfcp_qdio_sbal_chain
30 (struct zfcp_fsf_req *, unsigned long);
31 static inline volatile struct qdio_buffer_element *zfcp_qdio_sbale_next
32 (struct zfcp_fsf_req *, unsigned long);
33 static inline int zfcp_qdio_sbals_zero(struct zfcp_qdio_queue *, int, int);
34 static inline int zfcp_qdio_sbals_wipe(struct zfcp_fsf_req *);
35 static inline void zfcp_qdio_sbale_fill
36 (struct zfcp_fsf_req *, unsigned long, void *, int);
37 static inline int zfcp_qdio_sbals_from_segment
38 (struct zfcp_fsf_req *, unsigned long, void *, unsigned long);
39 static inline int zfcp_qdio_sbals_from_buffer
40 (struct zfcp_fsf_req *, unsigned long, void *, unsigned long, int);
42 static qdio_handler_t zfcp_qdio_request_handler;
43 static qdio_handler_t zfcp_qdio_response_handler;
44 static int zfcp_qdio_handler_error_check(struct zfcp_adapter *,
45 unsigned int, unsigned int, unsigned int, int, int);
47 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_QDIO
50 * Allocates BUFFER memory to each of the pointers of the qdio_buffer_t
51 * array in the adapter struct.
52 * Cur_buf is the pointer array and count can be any number of required
53 * buffers, the page-fitting arithmetic is done entirely within this funciton.
55 * returns: number of buffers allocated
56 * locks: must only be called with zfcp_data.config_sema taken
59 zfcp_qdio_buffers_enqueue(struct qdio_buffer **cur_buf, int count)
62 int qdio_buffers_per_page;
64 struct qdio_buffer *first_in_page = NULL;
66 qdio_buffers_per_page = PAGE_SIZE / sizeof (struct qdio_buffer);
67 ZFCP_LOG_TRACE("buffers_per_page=%d\n", qdio_buffers_per_page);
69 for (buf_pos = 0; buf_pos < count; buf_pos++) {
71 cur_buf[buf_pos] = (struct qdio_buffer *)
72 get_zeroed_page(GFP_KERNEL);
73 if (cur_buf[buf_pos] == NULL) {
74 ZFCP_LOG_INFO("error: allocation of "
75 "QDIO buffer failed \n");
78 first_in_page = cur_buf[buf_pos];
80 cur_buf[buf_pos] = first_in_page + page_pos;
83 /* was initialised to zero */
85 page_pos %= qdio_buffers_per_page;
92 * Frees BUFFER memory for each of the pointers of the struct qdio_buffer array
93 * in the adapter struct cur_buf is the pointer array and count can be any
94 * number of buffers in the array that should be freed starting from buffer 0
96 * locks: must only be called with zfcp_data.config_sema taken
99 zfcp_qdio_buffers_dequeue(struct qdio_buffer **cur_buf, int count)
102 int qdio_buffers_per_page;
104 qdio_buffers_per_page = PAGE_SIZE / sizeof (struct qdio_buffer);
105 ZFCP_LOG_TRACE("buffers_per_page=%d\n", qdio_buffers_per_page);
107 for (buf_pos = 0; buf_pos < count; buf_pos += qdio_buffers_per_page)
108 free_page((unsigned long) cur_buf[buf_pos]);
112 /* locks: must only be called with zfcp_data.config_sema taken */
114 zfcp_qdio_allocate_queues(struct zfcp_adapter *adapter)
120 zfcp_qdio_buffers_enqueue(&(adapter->request_queue.buffer[0]),
121 QDIO_MAX_BUFFERS_PER_Q);
122 if (buffer_count < QDIO_MAX_BUFFERS_PER_Q) {
123 ZFCP_LOG_DEBUG("only %d QDIO buffers allocated for request "
124 "queue\n", buffer_count);
125 zfcp_qdio_buffers_dequeue(&(adapter->request_queue.buffer[0]),
132 zfcp_qdio_buffers_enqueue(&(adapter->response_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 response "
136 "queue", buffer_count);
137 zfcp_qdio_buffers_dequeue(&(adapter->response_queue.buffer[0]),
139 ZFCP_LOG_TRACE("freeing request_queue buffers\n");
140 zfcp_qdio_buffers_dequeue(&(adapter->request_queue.buffer[0]),
141 QDIO_MAX_BUFFERS_PER_Q);
149 /* locks: must only be called with zfcp_data.config_sema taken */
151 zfcp_qdio_free_queues(struct zfcp_adapter *adapter)
153 ZFCP_LOG_TRACE("freeing request_queue buffers\n");
154 zfcp_qdio_buffers_dequeue(&(adapter->request_queue.buffer[0]),
155 QDIO_MAX_BUFFERS_PER_Q);
157 ZFCP_LOG_TRACE("freeing response_queue buffers\n");
158 zfcp_qdio_buffers_dequeue(&(adapter->response_queue.buffer[0]),
159 QDIO_MAX_BUFFERS_PER_Q);
163 zfcp_qdio_allocate(struct zfcp_adapter *adapter)
165 struct qdio_initialize *init_data;
167 init_data = &adapter->qdio_init_data;
169 init_data->cdev = adapter->ccw_device;
170 init_data->q_format = QDIO_SCSI_QFMT;
171 memcpy(init_data->adapter_name, zfcp_get_busid_by_adapter(adapter), 8);
172 ASCEBC(init_data->adapter_name, 8);
173 init_data->qib_param_field_format = 0;
174 init_data->qib_param_field = NULL;
175 init_data->input_slib_elements = NULL;
176 init_data->output_slib_elements = NULL;
177 init_data->min_input_threshold = ZFCP_MIN_INPUT_THRESHOLD;
178 init_data->max_input_threshold = ZFCP_MAX_INPUT_THRESHOLD;
179 init_data->min_output_threshold = ZFCP_MIN_OUTPUT_THRESHOLD;
180 init_data->max_output_threshold = ZFCP_MAX_OUTPUT_THRESHOLD;
181 init_data->no_input_qs = 1;
182 init_data->no_output_qs = 1;
183 init_data->input_handler = zfcp_qdio_response_handler;
184 init_data->output_handler = zfcp_qdio_request_handler;
185 init_data->int_parm = (unsigned long) adapter;
186 init_data->flags = QDIO_INBOUND_0COPY_SBALS |
187 QDIO_OUTBOUND_0COPY_SBALS | QDIO_USE_OUTBOUND_PCIS;
188 init_data->input_sbal_addr_array =
189 (void **) (adapter->response_queue.buffer);
190 init_data->output_sbal_addr_array =
191 (void **) (adapter->request_queue.buffer);
193 return qdio_allocate(init_data);
197 * function: zfcp_qdio_handler_error_check
199 * purpose: called by the response handler to determine error condition
201 * returns: error flag
205 zfcp_qdio_handler_error_check(struct zfcp_adapter *adapter, unsigned int status,
206 unsigned int qdio_error, unsigned int siga_error,
207 int first_element, int elements_processed)
211 if (unlikely(status & QDIO_STATUS_LOOK_FOR_ERROR)) {
214 ZFCP_LOG_INFO("QDIO problem occurred (status=0x%x, "
215 "qdio_error=0x%x, siga_error=0x%x)\n",
216 status, qdio_error, siga_error);
218 zfcp_hba_dbf_event_qdio(adapter, status, qdio_error, siga_error,
219 first_element, elements_processed);
221 * Restarting IO on the failed adapter from scratch.
222 * Since we have been using this adapter, it is save to assume
223 * that it is not failed but recoverable. The card seems to
224 * report link-up events by self-initiated queue shutdown.
225 * That is why we need to clear the the link-down flag
226 * which is set again in case we have missed by a mile.
228 zfcp_erp_adapter_reopen(
230 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
231 ZFCP_STATUS_COMMON_ERP_FAILED);
237 * function: zfcp_qdio_request_handler
239 * purpose: is called by QDIO layer for completed SBALs in request queue
244 zfcp_qdio_request_handler(struct ccw_device *ccw_device,
246 unsigned int qdio_error,
247 unsigned int siga_error,
248 unsigned int queue_number,
250 int elements_processed,
251 unsigned long int_parm)
253 struct zfcp_adapter *adapter;
254 struct zfcp_qdio_queue *queue;
256 adapter = (struct zfcp_adapter *) int_parm;
257 queue = &adapter->request_queue;
259 ZFCP_LOG_DEBUG("adapter %s, first=%d, elements_processed=%d\n",
260 zfcp_get_busid_by_adapter(adapter),
261 first_element, elements_processed);
263 if (unlikely(zfcp_qdio_handler_error_check(adapter, status, qdio_error,
264 siga_error, first_element,
265 elements_processed)))
268 * we stored address of struct zfcp_adapter data structure
269 * associated with irq in int_parm
272 /* cleanup all SBALs being program-owned now */
273 zfcp_qdio_zero_sbals(queue->buffer, first_element, elements_processed);
275 /* increase free space in outbound queue */
276 atomic_add(elements_processed, &queue->free_count);
277 ZFCP_LOG_DEBUG("free_count=%d\n", atomic_read(&queue->free_count));
278 wake_up(&adapter->request_wq);
279 ZFCP_LOG_DEBUG("elements_processed=%d, free count=%d\n",
280 elements_processed, atomic_read(&queue->free_count));
286 * zfcp_qdio_reqid_check - checks for valid reqids or unsolicited status
288 static int zfcp_qdio_reqid_check(struct zfcp_adapter *adapter,
289 unsigned long req_id)
291 struct zfcp_fsf_req *fsf_req;
294 debug_long_event(adapter->erp_dbf, 4, req_id);
296 spin_lock_irqsave(&adapter->req_list_lock, flags);
297 fsf_req = zfcp_reqlist_ismember(adapter, req_id);
300 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
301 ZFCP_LOG_NORMAL("error: unknown request id (%ld).\n", req_id);
302 zfcp_erp_adapter_reopen(adapter, 0);
306 zfcp_reqlist_remove(adapter, req_id);
307 atomic_dec(&adapter->reqs_active);
308 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
310 /* finish the FSF request */
311 zfcp_fsf_req_complete(fsf_req);
317 * function: zfcp_qdio_response_handler
319 * purpose: is called by QDIO layer for completed SBALs in response queue
324 zfcp_qdio_response_handler(struct ccw_device *ccw_device,
326 unsigned int qdio_error,
327 unsigned int siga_error,
328 unsigned int queue_number,
330 int elements_processed,
331 unsigned long int_parm)
333 struct zfcp_adapter *adapter;
334 struct zfcp_qdio_queue *queue;
337 struct qdio_buffer *buffer;
341 volatile struct qdio_buffer_element *buffere = NULL;
344 adapter = (struct zfcp_adapter *) int_parm;
345 queue = &adapter->response_queue;
347 if (unlikely(zfcp_qdio_handler_error_check(adapter, status, qdio_error,
348 siga_error, first_element,
349 elements_processed)))
353 * we stored address of struct zfcp_adapter data structure
354 * associated with irq in int_parm
357 buffere = &(queue->buffer[first_element]->element[0]);
358 ZFCP_LOG_DEBUG("first BUFFERE flags=0x%x\n", buffere->flags);
360 * go through all SBALs from input queue currently
361 * returned by QDIO layer
364 for (i = 0; i < elements_processed; i++) {
366 buffer_index = first_element + i;
367 buffer_index %= QDIO_MAX_BUFFERS_PER_Q;
368 buffer = queue->buffer[buffer_index];
370 /* go through all SBALEs of SBAL */
371 for (buffere_index = 0;
372 buffere_index < QDIO_MAX_ELEMENTS_PER_BUFFER;
375 /* look for QDIO request identifiers in SB */
376 buffere = &buffer->element[buffere_index];
377 retval = zfcp_qdio_reqid_check(adapter,
378 (unsigned long) buffere->addr);
381 ZFCP_LOG_NORMAL("bug: unexpected inbound "
382 "packet on adapter %s "
385 "elements_processed=%d)\n",
386 zfcp_get_busid_by_adapter(adapter),
387 (unsigned long) buffere->addr,
390 ZFCP_LOG_NORMAL("hex dump of inbound buffer "
393 "buffere_index=%d)\n", buffer,
394 buffer_index, buffere_index);
395 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
396 (char *) buffer, SBAL_SIZE);
399 * A single used SBALE per inbound SBALE has been
400 * implemented by QDIO so far. Hope they will
401 * do some optimisation. Will need to change to
404 if (likely(buffere->flags & SBAL_FLAGS_LAST_ENTRY))
408 if (unlikely(!(buffere->flags & SBAL_FLAGS_LAST_ENTRY))) {
409 ZFCP_LOG_NORMAL("bug: End of inbound data "
415 * put range of SBALs back to response queue
416 * (including SBALs which have already been free before)
418 count = atomic_read(&queue->free_count) + elements_processed;
419 start = queue->free_index;
421 ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
422 "queue_no=%i, index_in_queue=%i, count=%i, "
424 zfcp_get_busid_by_adapter(adapter),
425 QDIO_FLAG_SYNC_INPUT | QDIO_FLAG_UNDER_INTERRUPT,
426 0, start, count, (unsigned long) &queue->buffer[start]);
428 retval = do_QDIO(ccw_device,
429 QDIO_FLAG_SYNC_INPUT | QDIO_FLAG_UNDER_INTERRUPT,
430 0, start, count, NULL);
432 if (unlikely(retval)) {
433 atomic_set(&queue->free_count, count);
434 ZFCP_LOG_DEBUG("clearing of inbound data regions failed, "
435 "queues may be down "
436 "(count=%d, start=%d, retval=%d)\n",
437 count, start, retval);
439 queue->free_index += count;
440 queue->free_index %= QDIO_MAX_BUFFERS_PER_Q;
441 atomic_set(&queue->free_count, 0);
442 ZFCP_LOG_TRACE("%i buffers enqueued to response "
443 "queue at position %i\n", count, start);
450 * zfcp_qdio_sbale_get - return pointer to SBALE of qdio_queue
451 * @queue: queue from which SBALE should be returned
452 * @sbal: specifies number of SBAL in queue
453 * @sbale: specifes number of SBALE in SBAL
455 static inline volatile struct qdio_buffer_element *
456 zfcp_qdio_sbale_get(struct zfcp_qdio_queue *queue, int sbal, int sbale)
458 return &queue->buffer[sbal]->element[sbale];
462 * zfcp_qdio_sbale_req - return pointer to SBALE of request_queue for
463 * a struct zfcp_fsf_req
465 inline volatile struct qdio_buffer_element *
466 zfcp_qdio_sbale_req(struct zfcp_fsf_req *fsf_req, int sbal, int sbale)
468 return zfcp_qdio_sbale_get(&fsf_req->adapter->request_queue,
473 * zfcp_qdio_sbale_resp - return pointer to SBALE of response_queue for
474 * a struct zfcp_fsf_req
476 static inline volatile struct qdio_buffer_element *
477 zfcp_qdio_sbale_resp(struct zfcp_fsf_req *fsf_req, int sbal, int sbale)
479 return zfcp_qdio_sbale_get(&fsf_req->adapter->response_queue,
484 * zfcp_qdio_sbale_curr - return current SBALE on request_queue for
485 * a struct zfcp_fsf_req
487 inline volatile struct qdio_buffer_element *
488 zfcp_qdio_sbale_curr(struct zfcp_fsf_req *fsf_req)
490 return zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr,
491 fsf_req->sbale_curr);
495 * zfcp_qdio_sbal_limit - determine maximum number of SBALs that can be used
496 * on the request_queue for a struct zfcp_fsf_req
497 * @fsf_req: the number of the last SBAL that can be used is stored herein
498 * @max_sbals: used to pass an upper limit for the number of SBALs
500 * Note: We can assume at least one free SBAL in the request_queue when called.
503 zfcp_qdio_sbal_limit(struct zfcp_fsf_req *fsf_req, int max_sbals)
505 int count = atomic_read(&fsf_req->adapter->request_queue.free_count);
506 count = min(count, max_sbals);
507 fsf_req->sbal_last = fsf_req->sbal_first;
508 fsf_req->sbal_last += (count - 1);
509 fsf_req->sbal_last %= QDIO_MAX_BUFFERS_PER_Q;
513 * zfcp_qdio_sbal_chain - chain SBALs if more than one SBAL is needed for a
515 * @fsf_req: zfcp_fsf_req to be processed
516 * @sbtype: SBAL flags which have to be set in first SBALE of new SBAL
518 * This function changes sbal_curr, sbale_curr, sbal_number of fsf_req.
520 static inline volatile struct qdio_buffer_element *
521 zfcp_qdio_sbal_chain(struct zfcp_fsf_req *fsf_req, unsigned long sbtype)
523 volatile struct qdio_buffer_element *sbale;
525 /* set last entry flag in current SBALE of current SBAL */
526 sbale = zfcp_qdio_sbale_curr(fsf_req);
527 sbale->flags |= SBAL_FLAGS_LAST_ENTRY;
529 /* don't exceed last allowed SBAL */
530 if (fsf_req->sbal_curr == fsf_req->sbal_last)
533 /* set chaining flag in first SBALE of current SBAL */
534 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
535 sbale->flags |= SBAL_FLAGS0_MORE_SBALS;
537 /* calculate index of next SBAL */
538 fsf_req->sbal_curr++;
539 fsf_req->sbal_curr %= QDIO_MAX_BUFFERS_PER_Q;
541 /* keep this requests number of SBALs up-to-date */
542 fsf_req->sbal_number++;
544 /* start at first SBALE of new SBAL */
545 fsf_req->sbale_curr = 0;
547 /* set storage-block type for new SBAL */
548 sbale = zfcp_qdio_sbale_curr(fsf_req);
549 sbale->flags |= sbtype;
555 * zfcp_qdio_sbale_next - switch to next SBALE, chain SBALs if needed
557 static inline volatile struct qdio_buffer_element *
558 zfcp_qdio_sbale_next(struct zfcp_fsf_req *fsf_req, unsigned long sbtype)
560 if (fsf_req->sbale_curr == ZFCP_LAST_SBALE_PER_SBAL)
561 return zfcp_qdio_sbal_chain(fsf_req, sbtype);
563 fsf_req->sbale_curr++;
565 return zfcp_qdio_sbale_curr(fsf_req);
569 * zfcp_qdio_sbals_zero - initialize SBALs between first and last in queue
573 zfcp_qdio_sbals_zero(struct zfcp_qdio_queue *queue, int first, int last)
575 struct qdio_buffer **buf = queue->buffer;
580 curr %= QDIO_MAX_BUFFERS_PER_Q;
582 memset(buf[curr], 0, sizeof(struct qdio_buffer));
592 * zfcp_qdio_sbals_wipe - reset all changes in SBALs for an fsf_req
595 zfcp_qdio_sbals_wipe(struct zfcp_fsf_req *fsf_req)
597 return zfcp_qdio_sbals_zero(&fsf_req->adapter->request_queue,
598 fsf_req->sbal_first, fsf_req->sbal_curr);
603 * zfcp_qdio_sbale_fill - set address and lenght in current SBALE
607 zfcp_qdio_sbale_fill(struct zfcp_fsf_req *fsf_req, unsigned long sbtype,
608 void *addr, int length)
610 volatile struct qdio_buffer_element *sbale;
612 sbale = zfcp_qdio_sbale_curr(fsf_req);
614 sbale->length = length;
618 * zfcp_qdio_sbals_from_segment - map memory segment to SBALE(s)
619 * @fsf_req: request to be processed
620 * @sbtype: SBALE flags
621 * @start_addr: address of memory segment
622 * @total_length: length of memory segment
624 * Alignment and length of the segment determine how many SBALEs are needed
625 * for the memory segment.
628 zfcp_qdio_sbals_from_segment(struct zfcp_fsf_req *fsf_req, unsigned long sbtype,
629 void *start_addr, unsigned long total_length)
631 unsigned long remaining, length;
634 /* split segment up heeding page boundaries */
635 for (addr = start_addr, remaining = total_length; remaining > 0;
636 addr += length, remaining -= length) {
637 /* get next free SBALE for new piece */
638 if (NULL == zfcp_qdio_sbale_next(fsf_req, sbtype)) {
639 /* no SBALE left, clean up and leave */
640 zfcp_qdio_sbals_wipe(fsf_req);
643 /* calculate length of new piece */
644 length = min(remaining,
645 (PAGE_SIZE - ((unsigned long) addr &
647 /* fill current SBALE with calculated piece */
648 zfcp_qdio_sbale_fill(fsf_req, sbtype, addr, length);
655 * zfcp_qdio_sbals_from_sg - fill SBALs from scatter-gather list
656 * @fsf_req: request to be processed
657 * @sbtype: SBALE flags
658 * @sg: scatter-gather list
659 * @sg_count: number of elements in scatter-gather list
660 * @max_sbals: upper bound for number of SBALs to be used
663 zfcp_qdio_sbals_from_sg(struct zfcp_fsf_req *fsf_req, unsigned long sbtype,
664 struct scatterlist *sg, int sg_count, int max_sbals)
667 struct scatterlist *sg_segment;
669 volatile struct qdio_buffer_element *sbale;
672 /* figure out last allowed SBAL */
673 zfcp_qdio_sbal_limit(fsf_req, max_sbals);
675 /* set storage-block type for current SBAL */
676 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
677 sbale->flags |= sbtype;
679 /* process all segements of scatter-gather list */
680 for (sg_index = 0, sg_segment = sg, bytes = 0;
682 sg_index++, sg_segment++) {
683 retval = zfcp_qdio_sbals_from_segment(
686 zfcp_sg_to_address(sg_segment),
694 /* assume that no other SBALEs are to follow in the same SBAL */
695 sbale = zfcp_qdio_sbale_curr(fsf_req);
696 sbale->flags |= SBAL_FLAGS_LAST_ENTRY;
703 * zfcp_qdio_sbals_from_buffer - fill SBALs from buffer
704 * @fsf_req: request to be processed
705 * @sbtype: SBALE flags
706 * @buffer: data buffer
707 * @length: length of buffer
708 * @max_sbals: upper bound for number of SBALs to be used
711 zfcp_qdio_sbals_from_buffer(struct zfcp_fsf_req *fsf_req, unsigned long sbtype,
712 void *buffer, unsigned long length, int max_sbals)
714 struct scatterlist sg_segment;
716 zfcp_address_to_sg(buffer, &sg_segment);
717 sg_segment.length = length;
719 return zfcp_qdio_sbals_from_sg(fsf_req, sbtype, &sg_segment, 1,
725 * zfcp_qdio_sbals_from_scsicmnd - fill SBALs from scsi command
726 * @fsf_req: request to be processed
727 * @sbtype: SBALE flags
728 * @scsi_cmnd: either scatter-gather list or buffer contained herein is used
732 zfcp_qdio_sbals_from_scsicmnd(struct zfcp_fsf_req *fsf_req,
733 unsigned long sbtype, struct scsi_cmnd *scsi_cmnd)
735 if (scsi_cmnd->use_sg) {
736 return zfcp_qdio_sbals_from_sg(fsf_req, sbtype,
737 (struct scatterlist *)
738 scsi_cmnd->request_buffer,
740 ZFCP_MAX_SBALS_PER_REQ);
742 return zfcp_qdio_sbals_from_buffer(fsf_req, sbtype,
743 scsi_cmnd->request_buffer,
744 scsi_cmnd->request_bufflen,
745 ZFCP_MAX_SBALS_PER_REQ);
750 * zfcp_qdio_determine_pci - set PCI flag in first SBALE on qdio queue if needed
753 zfcp_qdio_determine_pci(struct zfcp_qdio_queue *req_queue,
754 struct zfcp_fsf_req *fsf_req)
756 int new_distance_from_int;
758 volatile struct qdio_buffer_element *sbale;
760 new_distance_from_int = req_queue->distance_from_int +
761 fsf_req->sbal_number;
763 if (unlikely(new_distance_from_int >= ZFCP_QDIO_PCI_INTERVAL)) {
764 new_distance_from_int %= ZFCP_QDIO_PCI_INTERVAL;
765 pci_pos = fsf_req->sbal_first;
766 pci_pos += fsf_req->sbal_number;
767 pci_pos -= new_distance_from_int;
769 pci_pos %= QDIO_MAX_BUFFERS_PER_Q;
770 sbale = zfcp_qdio_sbale_req(fsf_req, pci_pos, 0);
771 sbale->flags |= SBAL_FLAGS0_PCI;
773 return new_distance_from_int;
777 * function: zfcp_zero_sbals
779 * purpose: zeros specified range of SBALs
784 zfcp_qdio_zero_sbals(struct qdio_buffer *buf[], int first, int clean_count)
789 for (cur_pos = first; cur_pos < (first + clean_count); cur_pos++) {
790 index = cur_pos % QDIO_MAX_BUFFERS_PER_Q;
791 memset(buf[index], 0, sizeof (struct qdio_buffer));
792 ZFCP_LOG_TRACE("zeroing BUFFER %d at address %p\n",