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
*,
58 unsigned int, unsigned int);
60 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_QDIO
63 * Allocates BUFFER memory to each of the pointers of the qdio_buffer_t
64 * array in the adapter struct.
65 * Cur_buf is the pointer array and count can be any number of required
66 * buffers, the page-fitting arithmetic is done entirely within this funciton.
68 * returns: number of buffers allocated
69 * locks: must only be called with zfcp_data.config_sema taken
72 zfcp_qdio_buffers_enqueue(struct qdio_buffer
**cur_buf
, int count
)
75 int qdio_buffers_per_page
;
77 struct qdio_buffer
*first_in_page
= NULL
;
79 qdio_buffers_per_page
= PAGE_SIZE
/ sizeof (struct qdio_buffer
);
80 ZFCP_LOG_TRACE("buffers_per_page=%d\n", qdio_buffers_per_page
);
82 for (buf_pos
= 0; buf_pos
< count
; buf_pos
++) {
84 cur_buf
[buf_pos
] = (struct qdio_buffer
*)
85 get_zeroed_page(GFP_KERNEL
);
86 if (cur_buf
[buf_pos
] == NULL
) {
87 ZFCP_LOG_INFO("error: allocation of "
88 "QDIO buffer failed \n");
91 first_in_page
= cur_buf
[buf_pos
];
93 cur_buf
[buf_pos
] = first_in_page
+ page_pos
;
96 /* was initialised to zero */
98 page_pos
%= qdio_buffers_per_page
;
105 * Frees BUFFER memory for each of the pointers of the struct qdio_buffer array
106 * in the adapter struct cur_buf is the pointer array and count can be any
107 * number of buffers in the array that should be freed starting from buffer 0
109 * locks: must only be called with zfcp_data.config_sema taken
112 zfcp_qdio_buffers_dequeue(struct qdio_buffer
**cur_buf
, int count
)
115 int qdio_buffers_per_page
;
117 qdio_buffers_per_page
= PAGE_SIZE
/ sizeof (struct qdio_buffer
);
118 ZFCP_LOG_TRACE("buffers_per_page=%d\n", qdio_buffers_per_page
);
120 for (buf_pos
= 0; buf_pos
< count
; buf_pos
+= qdio_buffers_per_page
)
121 free_page((unsigned long) cur_buf
[buf_pos
]);
125 /* locks: must only be called with zfcp_data.config_sema taken */
127 zfcp_qdio_allocate_queues(struct zfcp_adapter
*adapter
)
133 zfcp_qdio_buffers_enqueue(&(adapter
->request_queue
.buffer
[0]),
134 QDIO_MAX_BUFFERS_PER_Q
);
135 if (buffer_count
< QDIO_MAX_BUFFERS_PER_Q
) {
136 ZFCP_LOG_DEBUG("only %d QDIO buffers allocated for request "
137 "queue\n", buffer_count
);
138 zfcp_qdio_buffers_dequeue(&(adapter
->request_queue
.buffer
[0]),
145 zfcp_qdio_buffers_enqueue(&(adapter
->response_queue
.buffer
[0]),
146 QDIO_MAX_BUFFERS_PER_Q
);
147 if (buffer_count
< QDIO_MAX_BUFFERS_PER_Q
) {
148 ZFCP_LOG_DEBUG("only %d QDIO buffers allocated for response "
149 "queue", buffer_count
);
150 zfcp_qdio_buffers_dequeue(&(adapter
->response_queue
.buffer
[0]),
152 ZFCP_LOG_TRACE("freeing request_queue buffers\n");
153 zfcp_qdio_buffers_dequeue(&(adapter
->request_queue
.buffer
[0]),
154 QDIO_MAX_BUFFERS_PER_Q
);
162 /* locks: must only be called with zfcp_data.config_sema taken */
164 zfcp_qdio_free_queues(struct zfcp_adapter
*adapter
)
166 ZFCP_LOG_TRACE("freeing request_queue buffers\n");
167 zfcp_qdio_buffers_dequeue(&(adapter
->request_queue
.buffer
[0]),
168 QDIO_MAX_BUFFERS_PER_Q
);
170 ZFCP_LOG_TRACE("freeing response_queue buffers\n");
171 zfcp_qdio_buffers_dequeue(&(adapter
->response_queue
.buffer
[0]),
172 QDIO_MAX_BUFFERS_PER_Q
);
176 zfcp_qdio_allocate(struct zfcp_adapter
*adapter
)
178 struct qdio_initialize
*init_data
;
180 init_data
= &adapter
->qdio_init_data
;
182 init_data
->cdev
= adapter
->ccw_device
;
183 init_data
->q_format
= QDIO_SCSI_QFMT
;
184 memcpy(init_data
->adapter_name
, &adapter
->name
, 8);
185 init_data
->qib_param_field_format
= 0;
186 init_data
->qib_param_field
= NULL
;
187 init_data
->input_slib_elements
= NULL
;
188 init_data
->output_slib_elements
= NULL
;
189 init_data
->min_input_threshold
= ZFCP_MIN_INPUT_THRESHOLD
;
190 init_data
->max_input_threshold
= ZFCP_MAX_INPUT_THRESHOLD
;
191 init_data
->min_output_threshold
= ZFCP_MIN_OUTPUT_THRESHOLD
;
192 init_data
->max_output_threshold
= ZFCP_MAX_OUTPUT_THRESHOLD
;
193 init_data
->no_input_qs
= 1;
194 init_data
->no_output_qs
= 1;
195 init_data
->input_handler
= zfcp_qdio_response_handler
;
196 init_data
->output_handler
= zfcp_qdio_request_handler
;
197 init_data
->int_parm
= (unsigned long) adapter
;
198 init_data
->flags
= QDIO_INBOUND_0COPY_SBALS
|
199 QDIO_OUTBOUND_0COPY_SBALS
| QDIO_USE_OUTBOUND_PCIS
;
200 init_data
->input_sbal_addr_array
=
201 (void **) (adapter
->response_queue
.buffer
);
202 init_data
->output_sbal_addr_array
=
203 (void **) (adapter
->request_queue
.buffer
);
205 return qdio_allocate(init_data
);
209 * function: zfcp_qdio_handler_error_check
211 * purpose: called by the response handler to determine error condition
213 * returns: error flag
217 zfcp_qdio_handler_error_check(struct zfcp_adapter
*adapter
,
219 unsigned int qdio_error
, unsigned int siga_error
)
223 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_TRACE
)) {
224 if (status
& QDIO_STATUS_INBOUND_INT
) {
225 ZFCP_LOG_TRACE("status is"
226 " QDIO_STATUS_INBOUND_INT \n");
228 if (status
& QDIO_STATUS_OUTBOUND_INT
) {
229 ZFCP_LOG_TRACE("status is"
230 " QDIO_STATUS_OUTBOUND_INT \n");
233 if (unlikely(status
& QDIO_STATUS_LOOK_FOR_ERROR
)) {
236 ZFCP_LOG_INFO("QDIO problem occurred (status=0x%x, "
237 "qdio_error=0x%x, siga_error=0x%x)\n",
238 status
, qdio_error
, siga_error
);
240 /* Restarting IO on the failed adapter from scratch */
241 debug_text_event(adapter
->erp_dbf
, 1, "qdio_err");
243 * Since we have been using this adapter, it is save to assume
244 * that it is not failed but recoverable. The card seems to
245 * report link-up events by self-initiated queue shutdown.
246 * That is why we need to clear the the link-down flag
247 * which is set again in case we have missed by a mile.
249 zfcp_erp_adapter_reopen(
251 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
|
252 ZFCP_STATUS_COMMON_ERP_FAILED
);
258 * function: zfcp_qdio_request_handler
260 * purpose: is called by QDIO layer for completed SBALs in request queue
265 zfcp_qdio_request_handler(struct ccw_device
*ccw_device
,
267 unsigned int qdio_error
,
268 unsigned int siga_error
,
269 unsigned int queue_number
,
271 int elements_processed
,
272 unsigned long int_parm
)
274 struct zfcp_adapter
*adapter
;
275 struct zfcp_qdio_queue
*queue
;
277 adapter
= (struct zfcp_adapter
*) int_parm
;
278 queue
= &adapter
->request_queue
;
280 ZFCP_LOG_DEBUG("adapter %s, first=%d, elements_processed=%d\n",
281 zfcp_get_busid_by_adapter(adapter
),
282 first_element
, elements_processed
);
284 if (unlikely(zfcp_qdio_handler_error_check(adapter
, status
, qdio_error
,
288 * we stored address of struct zfcp_adapter data structure
289 * associated with irq in int_parm
292 /* cleanup all SBALs being program-owned now */
293 zfcp_qdio_zero_sbals(queue
->buffer
, first_element
, elements_processed
);
295 /* increase free space in outbound queue */
296 atomic_add(elements_processed
, &queue
->free_count
);
297 ZFCP_LOG_DEBUG("free_count=%d\n", atomic_read(&queue
->free_count
));
298 wake_up(&adapter
->request_wq
);
299 ZFCP_LOG_DEBUG("elements_processed=%d, free count=%d\n",
300 elements_processed
, atomic_read(&queue
->free_count
));
306 * function: zfcp_qdio_response_handler
308 * purpose: is called by QDIO layer for completed SBALs in response queue
313 zfcp_qdio_response_handler(struct ccw_device
*ccw_device
,
315 unsigned int qdio_error
,
316 unsigned int siga_error
,
317 unsigned int queue_number
,
319 int elements_processed
,
320 unsigned long int_parm
)
322 struct zfcp_adapter
*adapter
;
323 struct zfcp_qdio_queue
*queue
;
326 struct qdio_buffer
*buffer
;
330 volatile struct qdio_buffer_element
*buffere
= NULL
;
333 adapter
= (struct zfcp_adapter
*) int_parm
;
334 queue
= &adapter
->response_queue
;
336 if (unlikely(zfcp_qdio_handler_error_check(adapter
, status
, qdio_error
,
341 * we stored address of struct zfcp_adapter data structure
342 * associated with irq in int_parm
345 buffere
= &(queue
->buffer
[first_element
]->element
[0]);
346 ZFCP_LOG_DEBUG("first BUFFERE flags=0x%x\n", buffere
->flags
);
348 * go through all SBALs from input queue currently
349 * returned by QDIO layer
352 for (i
= 0; i
< elements_processed
; i
++) {
354 buffer_index
= first_element
+ i
;
355 buffer_index
%= QDIO_MAX_BUFFERS_PER_Q
;
356 buffer
= queue
->buffer
[buffer_index
];
358 /* go through all SBALEs of SBAL */
359 for (buffere_index
= 0;
360 buffere_index
< QDIO_MAX_ELEMENTS_PER_BUFFER
;
363 /* look for QDIO request identifiers in SB */
364 buffere
= &buffer
->element
[buffere_index
];
365 retval
= zfcp_qdio_reqid_check(adapter
,
366 (void *) buffere
->addr
);
369 ZFCP_LOG_NORMAL("bug: unexpected inbound "
370 "packet on adapter %s "
373 "elements_processed=%d)\n",
374 zfcp_get_busid_by_adapter(adapter
),
375 (unsigned long) buffere
->addr
,
378 ZFCP_LOG_NORMAL("hex dump of inbound buffer "
381 "buffere_index=%d)\n", buffer
,
382 buffer_index
, buffere_index
);
383 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL
,
384 (char *) buffer
, SBAL_SIZE
);
387 * A single used SBALE per inbound SBALE has been
388 * implemented by QDIO so far. Hope they will
389 * do some optimisation. Will need to change to
392 if (likely(buffere
->flags
& SBAL_FLAGS_LAST_ENTRY
))
396 if (unlikely(!(buffere
->flags
& SBAL_FLAGS_LAST_ENTRY
))) {
397 ZFCP_LOG_NORMAL("bug: End of inbound data "
403 * put range of SBALs back to response queue
404 * (including SBALs which have already been free before)
406 count
= atomic_read(&queue
->free_count
) + elements_processed
;
407 start
= queue
->free_index
;
409 ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
410 "queue_no=%i, index_in_queue=%i, count=%i, "
412 zfcp_get_busid_by_adapter(adapter
),
413 QDIO_FLAG_SYNC_INPUT
| QDIO_FLAG_UNDER_INTERRUPT
,
414 0, start
, count
, (unsigned long) &queue
->buffer
[start
]);
416 retval
= do_QDIO(ccw_device
,
417 QDIO_FLAG_SYNC_INPUT
| QDIO_FLAG_UNDER_INTERRUPT
,
418 0, start
, count
, NULL
);
420 if (unlikely(retval
)) {
421 atomic_set(&queue
->free_count
, count
);
422 ZFCP_LOG_DEBUG("clearing of inbound data regions failed, "
423 "queues may be down "
424 "(count=%d, start=%d, retval=%d)\n",
425 count
, start
, retval
);
427 queue
->free_index
+= count
;
428 queue
->free_index
%= QDIO_MAX_BUFFERS_PER_Q
;
429 atomic_set(&queue
->free_count
, 0);
430 ZFCP_LOG_TRACE("%i buffers enqueued to response "
431 "queue at position %i\n", count
, start
);
438 * function: zfcp_qdio_reqid_check
440 * purpose: checks for valid reqids or unsolicited status
442 * returns: 0 - valid request id or unsolicited status
446 zfcp_qdio_reqid_check(struct zfcp_adapter
*adapter
, void *sbale_addr
)
448 struct zfcp_fsf_req
*fsf_req
;
450 /* invalid (per convention used in this driver) */
451 if (unlikely(!sbale_addr
)) {
452 ZFCP_LOG_NORMAL("bug: invalid reqid\n");
456 /* valid request id and thus (hopefully :) valid fsf_req address */
457 fsf_req
= (struct zfcp_fsf_req
*) sbale_addr
;
459 /* serialize with zfcp_fsf_req_dismiss_all */
460 spin_lock(&adapter
->fsf_req_list_lock
);
461 if (list_empty(&adapter
->fsf_req_list_head
)) {
462 spin_unlock(&adapter
->fsf_req_list_lock
);
465 list_del(&fsf_req
->list
);
466 atomic_dec(&adapter
->fsf_reqs_active
);
467 spin_unlock(&adapter
->fsf_req_list_lock
);
469 if (unlikely(adapter
!= fsf_req
->adapter
)) {
470 ZFCP_LOG_NORMAL("bug: invalid reqid (fsf_req=%p, "
471 "fsf_req->adapter=%p, adapter=%p)\n",
472 fsf_req
, fsf_req
->adapter
, adapter
);
476 /* finish the FSF request */
477 zfcp_fsf_req_complete(fsf_req
);
483 * zfcp_qdio_sbale_get - return pointer to SBALE of qdio_queue
484 * @queue: queue from which SBALE should be returned
485 * @sbal: specifies number of SBAL in queue
486 * @sbale: specifes number of SBALE in SBAL
488 static inline volatile struct qdio_buffer_element
*
489 zfcp_qdio_sbale_get(struct zfcp_qdio_queue
*queue
, int sbal
, int sbale
)
491 return &queue
->buffer
[sbal
]->element
[sbale
];
495 * zfcp_qdio_sbale_req - return pointer to SBALE of request_queue for
496 * a struct zfcp_fsf_req
498 inline volatile struct qdio_buffer_element
*
499 zfcp_qdio_sbale_req(struct zfcp_fsf_req
*fsf_req
, int sbal
, int sbale
)
501 return zfcp_qdio_sbale_get(&fsf_req
->adapter
->request_queue
,
506 * zfcp_qdio_sbale_resp - return pointer to SBALE of response_queue for
507 * a struct zfcp_fsf_req
509 static inline volatile struct qdio_buffer_element
*
510 zfcp_qdio_sbale_resp(struct zfcp_fsf_req
*fsf_req
, int sbal
, int sbale
)
512 return zfcp_qdio_sbale_get(&fsf_req
->adapter
->response_queue
,
517 * zfcp_qdio_sbale_curr - return current SBALE on request_queue for
518 * a struct zfcp_fsf_req
520 inline volatile struct qdio_buffer_element
*
521 zfcp_qdio_sbale_curr(struct zfcp_fsf_req
*fsf_req
)
523 return zfcp_qdio_sbale_req(fsf_req
, fsf_req
->sbal_curr
,
524 fsf_req
->sbale_curr
);
528 * zfcp_qdio_sbal_limit - determine maximum number of SBALs that can be used
529 * on the request_queue for a struct zfcp_fsf_req
530 * @fsf_req: the number of the last SBAL that can be used is stored herein
531 * @max_sbals: used to pass an upper limit for the number of SBALs
533 * Note: We can assume at least one free SBAL in the request_queue when called.
536 zfcp_qdio_sbal_limit(struct zfcp_fsf_req
*fsf_req
, int max_sbals
)
538 int count
= atomic_read(&fsf_req
->adapter
->request_queue
.free_count
);
539 count
= min(count
, max_sbals
);
540 fsf_req
->sbal_last
= fsf_req
->sbal_first
;
541 fsf_req
->sbal_last
+= (count
- 1);
542 fsf_req
->sbal_last
%= QDIO_MAX_BUFFERS_PER_Q
;
546 * zfcp_qdio_sbal_chain - chain SBALs if more than one SBAL is needed for a
548 * @fsf_req: zfcp_fsf_req to be processed
549 * @sbtype: SBAL flags which have to be set in first SBALE of new SBAL
551 * This function changes sbal_curr, sbale_curr, sbal_number of fsf_req.
553 static inline volatile struct qdio_buffer_element
*
554 zfcp_qdio_sbal_chain(struct zfcp_fsf_req
*fsf_req
, unsigned long sbtype
)
556 volatile struct qdio_buffer_element
*sbale
;
558 /* set last entry flag in current SBALE of current SBAL */
559 sbale
= zfcp_qdio_sbale_curr(fsf_req
);
560 sbale
->flags
|= SBAL_FLAGS_LAST_ENTRY
;
562 /* don't exceed last allowed SBAL */
563 if (fsf_req
->sbal_curr
== fsf_req
->sbal_last
)
566 /* set chaining flag in first SBALE of current SBAL */
567 sbale
= zfcp_qdio_sbale_req(fsf_req
, fsf_req
->sbal_curr
, 0);
568 sbale
->flags
|= SBAL_FLAGS0_MORE_SBALS
;
570 /* calculate index of next SBAL */
571 fsf_req
->sbal_curr
++;
572 fsf_req
->sbal_curr
%= QDIO_MAX_BUFFERS_PER_Q
;
574 /* keep this requests number of SBALs up-to-date */
575 fsf_req
->sbal_number
++;
577 /* start at first SBALE of new SBAL */
578 fsf_req
->sbale_curr
= 0;
580 /* set storage-block type for new SBAL */
581 sbale
= zfcp_qdio_sbale_curr(fsf_req
);
582 sbale
->flags
|= sbtype
;
588 * zfcp_qdio_sbale_next - switch to next SBALE, chain SBALs if needed
590 static inline volatile struct qdio_buffer_element
*
591 zfcp_qdio_sbale_next(struct zfcp_fsf_req
*fsf_req
, unsigned long sbtype
)
593 if (fsf_req
->sbale_curr
== ZFCP_LAST_SBALE_PER_SBAL
)
594 return zfcp_qdio_sbal_chain(fsf_req
, sbtype
);
596 fsf_req
->sbale_curr
++;
598 return zfcp_qdio_sbale_curr(fsf_req
);
602 * zfcp_qdio_sbals_zero - initialize SBALs between first and last in queue
606 zfcp_qdio_sbals_zero(struct zfcp_qdio_queue
*queue
, int first
, int last
)
608 struct qdio_buffer
**buf
= queue
->buffer
;
613 curr
%= QDIO_MAX_BUFFERS_PER_Q
;
615 memset(buf
[curr
], 0, sizeof(struct qdio_buffer
));
625 * zfcp_qdio_sbals_wipe - reset all changes in SBALs for an fsf_req
628 zfcp_qdio_sbals_wipe(struct zfcp_fsf_req
*fsf_req
)
630 return zfcp_qdio_sbals_zero(&fsf_req
->adapter
->request_queue
,
631 fsf_req
->sbal_first
, fsf_req
->sbal_curr
);
636 * zfcp_qdio_sbale_fill - set address and lenght in current SBALE
640 zfcp_qdio_sbale_fill(struct zfcp_fsf_req
*fsf_req
, unsigned long sbtype
,
641 void *addr
, int length
)
643 volatile struct qdio_buffer_element
*sbale
;
645 sbale
= zfcp_qdio_sbale_curr(fsf_req
);
647 sbale
->length
= length
;
651 * zfcp_qdio_sbals_from_segment - map memory segment to SBALE(s)
652 * @fsf_req: request to be processed
653 * @sbtype: SBALE flags
654 * @start_addr: address of memory segment
655 * @total_length: length of memory segment
657 * Alignment and length of the segment determine how many SBALEs are needed
658 * for the memory segment.
661 zfcp_qdio_sbals_from_segment(struct zfcp_fsf_req
*fsf_req
, unsigned long sbtype
,
662 void *start_addr
, unsigned long total_length
)
664 unsigned long remaining
, length
;
667 /* split segment up heeding page boundaries */
668 for (addr
= start_addr
, remaining
= total_length
; remaining
> 0;
669 addr
+= length
, remaining
-= length
) {
670 /* get next free SBALE for new piece */
671 if (NULL
== zfcp_qdio_sbale_next(fsf_req
, sbtype
)) {
672 /* no SBALE left, clean up and leave */
673 zfcp_qdio_sbals_wipe(fsf_req
);
676 /* calculate length of new piece */
677 length
= min(remaining
,
678 (PAGE_SIZE
- ((unsigned long) addr
&
680 /* fill current SBALE with calculated piece */
681 zfcp_qdio_sbale_fill(fsf_req
, sbtype
, addr
, length
);
688 * zfcp_qdio_sbals_from_sg - fill SBALs from scatter-gather list
689 * @fsf_req: request to be processed
690 * @sbtype: SBALE flags
691 * @sg: scatter-gather list
692 * @sg_count: number of elements in scatter-gather list
693 * @max_sbals: upper bound for number of SBALs to be used
696 zfcp_qdio_sbals_from_sg(struct zfcp_fsf_req
*fsf_req
, unsigned long sbtype
,
697 struct scatterlist
*sg
, int sg_count
, int max_sbals
)
700 struct scatterlist
*sg_segment
;
702 volatile struct qdio_buffer_element
*sbale
;
705 /* figure out last allowed SBAL */
706 zfcp_qdio_sbal_limit(fsf_req
, max_sbals
);
708 /* set storage-block type for current SBAL */
709 sbale
= zfcp_qdio_sbale_req(fsf_req
, fsf_req
->sbal_curr
, 0);
710 sbale
->flags
|= sbtype
;
712 /* process all segements of scatter-gather list */
713 for (sg_index
= 0, sg_segment
= sg
, bytes
= 0;
715 sg_index
++, sg_segment
++) {
716 retval
= zfcp_qdio_sbals_from_segment(
719 zfcp_sg_to_address(sg_segment
),
727 /* assume that no other SBALEs are to follow in the same SBAL */
728 sbale
= zfcp_qdio_sbale_curr(fsf_req
);
729 sbale
->flags
|= SBAL_FLAGS_LAST_ENTRY
;
736 * zfcp_qdio_sbals_from_buffer - fill SBALs from buffer
737 * @fsf_req: request to be processed
738 * @sbtype: SBALE flags
739 * @buffer: data buffer
740 * @length: length of buffer
741 * @max_sbals: upper bound for number of SBALs to be used
744 zfcp_qdio_sbals_from_buffer(struct zfcp_fsf_req
*fsf_req
, unsigned long sbtype
,
745 void *buffer
, unsigned long length
, int max_sbals
)
747 struct scatterlist sg_segment
;
749 zfcp_address_to_sg(buffer
, &sg_segment
);
750 sg_segment
.length
= length
;
752 return zfcp_qdio_sbals_from_sg(fsf_req
, sbtype
, &sg_segment
, 1,
758 * zfcp_qdio_sbals_from_scsicmnd - fill SBALs from scsi command
759 * @fsf_req: request to be processed
760 * @sbtype: SBALE flags
761 * @scsi_cmnd: either scatter-gather list or buffer contained herein is used
765 zfcp_qdio_sbals_from_scsicmnd(struct zfcp_fsf_req
*fsf_req
,
766 unsigned long sbtype
, struct scsi_cmnd
*scsi_cmnd
)
768 if (scsi_cmnd
->use_sg
) {
769 return zfcp_qdio_sbals_from_sg(fsf_req
, sbtype
,
770 (struct scatterlist
*)
771 scsi_cmnd
->request_buffer
,
773 ZFCP_MAX_SBALS_PER_REQ
);
775 return zfcp_qdio_sbals_from_buffer(fsf_req
, sbtype
,
776 scsi_cmnd
->request_buffer
,
777 scsi_cmnd
->request_bufflen
,
778 ZFCP_MAX_SBALS_PER_REQ
);
783 * zfcp_qdio_determine_pci - set PCI flag in first SBALE on qdio queue if needed
786 zfcp_qdio_determine_pci(struct zfcp_qdio_queue
*req_queue
,
787 struct zfcp_fsf_req
*fsf_req
)
789 int new_distance_from_int
;
791 volatile struct qdio_buffer_element
*sbale
;
793 new_distance_from_int
= req_queue
->distance_from_int
+
794 fsf_req
->sbal_number
;
796 if (unlikely(new_distance_from_int
>= ZFCP_QDIO_PCI_INTERVAL
)) {
797 new_distance_from_int
%= ZFCP_QDIO_PCI_INTERVAL
;
798 pci_pos
= fsf_req
->sbal_first
;
799 pci_pos
+= fsf_req
->sbal_number
;
800 pci_pos
-= new_distance_from_int
;
802 pci_pos
%= QDIO_MAX_BUFFERS_PER_Q
;
803 sbale
= zfcp_qdio_sbale_req(fsf_req
, pci_pos
, 0);
804 sbale
->flags
|= SBAL_FLAGS0_PCI
;
806 return new_distance_from_int
;
810 * function: zfcp_zero_sbals
812 * purpose: zeros specified range of SBALs
817 zfcp_qdio_zero_sbals(struct qdio_buffer
*buf
[], int first
, int clean_count
)
822 for (cur_pos
= first
; cur_pos
< (first
+ clean_count
); cur_pos
++) {
823 index
= cur_pos
% QDIO_MAX_BUFFERS_PER_Q
;
824 memset(buf
[index
], 0, sizeof (struct qdio_buffer
));
825 ZFCP_LOG_TRACE("zeroing BUFFER %d at address %p\n",