1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
21 #include <linux/pci.h>
22 #include <linux/interrupt.h>
23 #include <linux/delay.h>
24 #include <asm/unaligned.h>
26 #include <scsi/scsi.h>
27 #include <scsi/scsi_device.h>
28 #include <scsi/scsi_eh.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_tcq.h>
31 #include <scsi/scsi_transport_fc.h>
33 #include "lpfc_version.h"
37 #include "lpfc_sli4.h"
39 #include "lpfc_disc.h"
40 #include "lpfc_scsi.h"
42 #include "lpfc_logmsg.h"
43 #include "lpfc_crtn.h"
44 #include "lpfc_vport.h"
46 #define LPFC_RESET_WAIT 2
47 #define LPFC_ABORT_WAIT 2
51 static char *dif_op_str
[] = {
53 "SCSI_PROT_READ_INSERT",
54 "SCSI_PROT_WRITE_STRIP",
55 "SCSI_PROT_READ_STRIP",
56 "SCSI_PROT_WRITE_INSERT",
57 "SCSI_PROT_READ_PASS",
58 "SCSI_PROT_WRITE_PASS",
61 lpfc_release_scsi_buf_s4(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
);
63 lpfc_release_scsi_buf_s3(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
);
66 lpfc_debug_save_data(struct lpfc_hba
*phba
, struct scsi_cmnd
*cmnd
)
69 struct scatterlist
*sgde
= scsi_sglist(cmnd
);
71 if (!_dump_buf_data
) {
72 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
73 "9050 BLKGRD: ERROR %s _dump_buf_data is NULL\n",
80 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
81 "9051 BLKGRD: ERROR: data scatterlist is null\n");
85 dst
= (void *) _dump_buf_data
;
88 memcpy(dst
, src
, sgde
->length
);
95 lpfc_debug_save_dif(struct lpfc_hba
*phba
, struct scsi_cmnd
*cmnd
)
98 struct scatterlist
*sgde
= scsi_prot_sglist(cmnd
);
100 if (!_dump_buf_dif
) {
101 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
102 "9052 BLKGRD: ERROR %s _dump_buf_data is NULL\n",
108 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
109 "9053 BLKGRD: ERROR: prot scatterlist is null\n");
116 memcpy(dst
, src
, sgde
->length
);
118 sgde
= sg_next(sgde
);
123 * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge.
124 * @phba: Pointer to HBA object.
125 * @lpfc_cmd: lpfc scsi command object pointer.
127 * This function is called from the lpfc_prep_task_mgmt_cmd function to
128 * set the last bit in the response sge entry.
131 lpfc_sli4_set_rsp_sgl_last(struct lpfc_hba
*phba
,
132 struct lpfc_scsi_buf
*lpfc_cmd
)
134 struct sli4_sge
*sgl
= (struct sli4_sge
*)lpfc_cmd
->fcp_bpl
;
137 sgl
->word2
= le32_to_cpu(sgl
->word2
);
138 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
139 sgl
->word2
= cpu_to_le32(sgl
->word2
);
144 * lpfc_update_stats - Update statistical data for the command completion
145 * @phba: Pointer to HBA object.
146 * @lpfc_cmd: lpfc scsi command object pointer.
148 * This function is called when there is a command completion and this
149 * function updates the statistical data for the command completion.
152 lpfc_update_stats(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
)
154 struct lpfc_rport_data
*rdata
= lpfc_cmd
->rdata
;
155 struct lpfc_nodelist
*pnode
= rdata
->pnode
;
156 struct scsi_cmnd
*cmd
= lpfc_cmd
->pCmd
;
158 struct Scsi_Host
*shost
= cmd
->device
->host
;
159 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
160 unsigned long latency
;
166 latency
= jiffies_to_msecs((long)jiffies
- (long)lpfc_cmd
->start_time
);
168 spin_lock_irqsave(shost
->host_lock
, flags
);
169 if (!vport
->stat_data_enabled
||
170 vport
->stat_data_blocked
||
172 (phba
->bucket_type
== LPFC_NO_BUCKET
)) {
173 spin_unlock_irqrestore(shost
->host_lock
, flags
);
177 if (phba
->bucket_type
== LPFC_LINEAR_BUCKET
) {
178 i
= (latency
+ phba
->bucket_step
- 1 - phba
->bucket_base
)/
180 /* check array subscript bounds */
183 else if (i
>= LPFC_MAX_BUCKET_COUNT
)
184 i
= LPFC_MAX_BUCKET_COUNT
- 1;
186 for (i
= 0; i
< LPFC_MAX_BUCKET_COUNT
-1; i
++)
187 if (latency
<= (phba
->bucket_base
+
188 ((1<<i
)*phba
->bucket_step
)))
192 pnode
->lat_data
[i
].cmd_count
++;
193 spin_unlock_irqrestore(shost
->host_lock
, flags
);
197 * lpfc_send_sdev_queuedepth_change_event - Posts a queuedepth change event
198 * @phba: Pointer to HBA context object.
199 * @vport: Pointer to vport object.
200 * @ndlp: Pointer to FC node associated with the target.
201 * @lun: Lun number of the scsi device.
202 * @old_val: Old value of the queue depth.
203 * @new_val: New value of the queue depth.
205 * This function sends an event to the mgmt application indicating
206 * there is a change in the scsi device queue depth.
209 lpfc_send_sdev_queuedepth_change_event(struct lpfc_hba
*phba
,
210 struct lpfc_vport
*vport
,
211 struct lpfc_nodelist
*ndlp
,
216 struct lpfc_fast_path_event
*fast_path_evt
;
219 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
223 fast_path_evt
->un
.queue_depth_evt
.scsi_event
.event_type
=
225 fast_path_evt
->un
.queue_depth_evt
.scsi_event
.subcategory
=
226 LPFC_EVENT_VARQUEDEPTH
;
228 /* Report all luns with change in queue depth */
229 fast_path_evt
->un
.queue_depth_evt
.scsi_event
.lun
= lun
;
230 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
231 memcpy(&fast_path_evt
->un
.queue_depth_evt
.scsi_event
.wwpn
,
232 &ndlp
->nlp_portname
, sizeof(struct lpfc_name
));
233 memcpy(&fast_path_evt
->un
.queue_depth_evt
.scsi_event
.wwnn
,
234 &ndlp
->nlp_nodename
, sizeof(struct lpfc_name
));
237 fast_path_evt
->un
.queue_depth_evt
.oldval
= old_val
;
238 fast_path_evt
->un
.queue_depth_evt
.newval
= new_val
;
239 fast_path_evt
->vport
= vport
;
241 fast_path_evt
->work_evt
.evt
= LPFC_EVT_FASTPATH_MGMT_EVT
;
242 spin_lock_irqsave(&phba
->hbalock
, flags
);
243 list_add_tail(&fast_path_evt
->work_evt
.evt_listp
, &phba
->work_list
);
244 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
245 lpfc_worker_wake_up(phba
);
251 * lpfc_change_queue_depth - Alter scsi device queue depth
252 * @sdev: Pointer the scsi device on which to change the queue depth.
253 * @qdepth: New queue depth to set the sdev to.
254 * @reason: The reason for the queue depth change.
256 * This function is called by the midlayer and the LLD to alter the queue
257 * depth for a scsi device. This function sets the queue depth to the new
258 * value and sends an event out to log the queue depth change.
261 lpfc_change_queue_depth(struct scsi_device
*sdev
, int qdepth
, int reason
)
263 struct lpfc_vport
*vport
= (struct lpfc_vport
*) sdev
->host
->hostdata
;
264 struct lpfc_hba
*phba
= vport
->phba
;
265 struct lpfc_rport_data
*rdata
;
266 unsigned long new_queue_depth
, old_queue_depth
;
268 old_queue_depth
= sdev
->queue_depth
;
269 scsi_adjust_queue_depth(sdev
, scsi_get_tag_type(sdev
), qdepth
);
270 new_queue_depth
= sdev
->queue_depth
;
271 rdata
= sdev
->hostdata
;
273 lpfc_send_sdev_queuedepth_change_event(phba
, vport
,
274 rdata
->pnode
, sdev
->lun
,
277 return sdev
->queue_depth
;
281 * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread
282 * @phba: The Hba for which this call is being executed.
284 * This routine is called when there is resource error in driver or firmware.
285 * This routine posts WORKER_RAMP_DOWN_QUEUE event for @phba. This routine
286 * posts at most 1 event each second. This routine wakes up worker thread of
287 * @phba to process WORKER_RAM_DOWN_EVENT event.
289 * This routine should be called with no lock held.
292 lpfc_rampdown_queue_depth(struct lpfc_hba
*phba
)
297 spin_lock_irqsave(&phba
->hbalock
, flags
);
298 atomic_inc(&phba
->num_rsrc_err
);
299 phba
->last_rsrc_error_time
= jiffies
;
301 if ((phba
->last_ramp_down_time
+ QUEUE_RAMP_DOWN_INTERVAL
) > jiffies
) {
302 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
306 phba
->last_ramp_down_time
= jiffies
;
308 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
310 spin_lock_irqsave(&phba
->pport
->work_port_lock
, flags
);
311 evt_posted
= phba
->pport
->work_port_events
& WORKER_RAMP_DOWN_QUEUE
;
313 phba
->pport
->work_port_events
|= WORKER_RAMP_DOWN_QUEUE
;
314 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, flags
);
317 lpfc_worker_wake_up(phba
);
322 * lpfc_rampup_queue_depth - Post RAMP_UP_QUEUE event for worker thread
323 * @phba: The Hba for which this call is being executed.
325 * This routine post WORKER_RAMP_UP_QUEUE event for @phba vport. This routine
326 * post at most 1 event every 5 minute after last_ramp_up_time or
327 * last_rsrc_error_time. This routine wakes up worker thread of @phba
328 * to process WORKER_RAM_DOWN_EVENT event.
330 * This routine should be called with no lock held.
333 lpfc_rampup_queue_depth(struct lpfc_vport
*vport
,
334 uint32_t queue_depth
)
337 struct lpfc_hba
*phba
= vport
->phba
;
339 atomic_inc(&phba
->num_cmd_success
);
341 if (vport
->cfg_lun_queue_depth
<= queue_depth
)
343 spin_lock_irqsave(&phba
->hbalock
, flags
);
344 if (time_before(jiffies
,
345 phba
->last_ramp_up_time
+ QUEUE_RAMP_UP_INTERVAL
) ||
347 phba
->last_rsrc_error_time
+ QUEUE_RAMP_UP_INTERVAL
)) {
348 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
351 phba
->last_ramp_up_time
= jiffies
;
352 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
354 spin_lock_irqsave(&phba
->pport
->work_port_lock
, flags
);
355 evt_posted
= phba
->pport
->work_port_events
& WORKER_RAMP_UP_QUEUE
;
357 phba
->pport
->work_port_events
|= WORKER_RAMP_UP_QUEUE
;
358 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, flags
);
361 lpfc_worker_wake_up(phba
);
366 * lpfc_ramp_down_queue_handler - WORKER_RAMP_DOWN_QUEUE event handler
367 * @phba: The Hba for which this call is being executed.
369 * This routine is called to process WORKER_RAMP_DOWN_QUEUE event for worker
370 * thread.This routine reduces queue depth for all scsi device on each vport
371 * associated with @phba.
374 lpfc_ramp_down_queue_handler(struct lpfc_hba
*phba
)
376 struct lpfc_vport
**vports
;
377 struct Scsi_Host
*shost
;
378 struct scsi_device
*sdev
;
379 unsigned long new_queue_depth
;
380 unsigned long num_rsrc_err
, num_cmd_success
;
383 num_rsrc_err
= atomic_read(&phba
->num_rsrc_err
);
384 num_cmd_success
= atomic_read(&phba
->num_cmd_success
);
386 vports
= lpfc_create_vport_work_array(phba
);
388 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
389 shost
= lpfc_shost_from_vport(vports
[i
]);
390 shost_for_each_device(sdev
, shost
) {
392 sdev
->queue_depth
* num_rsrc_err
/
393 (num_rsrc_err
+ num_cmd_success
);
394 if (!new_queue_depth
)
395 new_queue_depth
= sdev
->queue_depth
- 1;
397 new_queue_depth
= sdev
->queue_depth
-
399 lpfc_change_queue_depth(sdev
, new_queue_depth
,
400 SCSI_QDEPTH_DEFAULT
);
403 lpfc_destroy_vport_work_array(phba
, vports
);
404 atomic_set(&phba
->num_rsrc_err
, 0);
405 atomic_set(&phba
->num_cmd_success
, 0);
409 * lpfc_ramp_up_queue_handler - WORKER_RAMP_UP_QUEUE event handler
410 * @phba: The Hba for which this call is being executed.
412 * This routine is called to process WORKER_RAMP_UP_QUEUE event for worker
413 * thread.This routine increases queue depth for all scsi device on each vport
414 * associated with @phba by 1. This routine also sets @phba num_rsrc_err and
415 * num_cmd_success to zero.
418 lpfc_ramp_up_queue_handler(struct lpfc_hba
*phba
)
420 struct lpfc_vport
**vports
;
421 struct Scsi_Host
*shost
;
422 struct scsi_device
*sdev
;
425 vports
= lpfc_create_vport_work_array(phba
);
427 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
428 shost
= lpfc_shost_from_vport(vports
[i
]);
429 shost_for_each_device(sdev
, shost
) {
430 if (vports
[i
]->cfg_lun_queue_depth
<=
433 lpfc_change_queue_depth(sdev
,
435 SCSI_QDEPTH_RAMP_UP
);
438 lpfc_destroy_vport_work_array(phba
, vports
);
439 atomic_set(&phba
->num_rsrc_err
, 0);
440 atomic_set(&phba
->num_cmd_success
, 0);
444 * lpfc_scsi_dev_block - set all scsi hosts to block state
445 * @phba: Pointer to HBA context object.
447 * This function walks vport list and set each SCSI host to block state
448 * by invoking fc_remote_port_delete() routine. This function is invoked
449 * with EEH when device's PCI slot has been permanently disabled.
452 lpfc_scsi_dev_block(struct lpfc_hba
*phba
)
454 struct lpfc_vport
**vports
;
455 struct Scsi_Host
*shost
;
456 struct scsi_device
*sdev
;
457 struct fc_rport
*rport
;
460 vports
= lpfc_create_vport_work_array(phba
);
462 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
463 shost
= lpfc_shost_from_vport(vports
[i
]);
464 shost_for_each_device(sdev
, shost
) {
465 rport
= starget_to_rport(scsi_target(sdev
));
466 fc_remote_port_delete(rport
);
469 lpfc_destroy_vport_work_array(phba
, vports
);
473 * lpfc_new_scsi_buf_s3 - Scsi buffer allocator for HBA with SLI3 IF spec
474 * @vport: The virtual port for which this call being executed.
475 * @num_to_allocate: The requested number of buffers to allocate.
477 * This routine allocates a scsi buffer for device with SLI-3 interface spec,
478 * the scsi buffer contains all the necessary information needed to initiate
479 * a SCSI I/O. The non-DMAable buffer region contains information to build
480 * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP,
481 * and the initial BPL. In addition to allocating memory, the FCP CMND and
482 * FCP RSP BDEs are setup in the BPL and the BPL BDE is setup in the IOCB.
485 * int - number of scsi buffers that were allocated.
486 * 0 = failure, less than num_to_alloc is a partial failure.
489 lpfc_new_scsi_buf_s3(struct lpfc_vport
*vport
, int num_to_alloc
)
491 struct lpfc_hba
*phba
= vport
->phba
;
492 struct lpfc_scsi_buf
*psb
;
493 struct ulp_bde64
*bpl
;
495 dma_addr_t pdma_phys_fcp_cmd
;
496 dma_addr_t pdma_phys_fcp_rsp
;
497 dma_addr_t pdma_phys_bpl
;
501 for (bcnt
= 0; bcnt
< num_to_alloc
; bcnt
++) {
502 psb
= kzalloc(sizeof(struct lpfc_scsi_buf
), GFP_KERNEL
);
507 * Get memory from the pci pool to map the virt space to pci
508 * bus space for an I/O. The DMA buffer includes space for the
509 * struct fcp_cmnd, struct fcp_rsp and the number of bde's
510 * necessary to support the sg_tablesize.
512 psb
->data
= pci_pool_alloc(phba
->lpfc_scsi_dma_buf_pool
,
513 GFP_KERNEL
, &psb
->dma_handle
);
519 /* Initialize virtual ptrs to dma_buf region. */
520 memset(psb
->data
, 0, phba
->cfg_sg_dma_buf_size
);
522 /* Allocate iotag for psb->cur_iocbq. */
523 iotag
= lpfc_sli_next_iotag(phba
, &psb
->cur_iocbq
);
525 pci_pool_free(phba
->lpfc_scsi_dma_buf_pool
,
526 psb
->data
, psb
->dma_handle
);
530 psb
->cur_iocbq
.iocb_flag
|= LPFC_IO_FCP
;
532 psb
->fcp_cmnd
= psb
->data
;
533 psb
->fcp_rsp
= psb
->data
+ sizeof(struct fcp_cmnd
);
534 psb
->fcp_bpl
= psb
->data
+ sizeof(struct fcp_cmnd
) +
535 sizeof(struct fcp_rsp
);
537 /* Initialize local short-hand pointers. */
539 pdma_phys_fcp_cmd
= psb
->dma_handle
;
540 pdma_phys_fcp_rsp
= psb
->dma_handle
+ sizeof(struct fcp_cmnd
);
541 pdma_phys_bpl
= psb
->dma_handle
+ sizeof(struct fcp_cmnd
) +
542 sizeof(struct fcp_rsp
);
545 * The first two bdes are the FCP_CMD and FCP_RSP. The balance
546 * are sg list bdes. Initialize the first two and leave the
547 * rest for queuecommand.
549 bpl
[0].addrHigh
= le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd
));
550 bpl
[0].addrLow
= le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd
));
551 bpl
[0].tus
.f
.bdeSize
= sizeof(struct fcp_cmnd
);
552 bpl
[0].tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
553 bpl
[0].tus
.w
= le32_to_cpu(bpl
[0].tus
.w
);
555 /* Setup the physical region for the FCP RSP */
556 bpl
[1].addrHigh
= le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp
));
557 bpl
[1].addrLow
= le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp
));
558 bpl
[1].tus
.f
.bdeSize
= sizeof(struct fcp_rsp
);
559 bpl
[1].tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
560 bpl
[1].tus
.w
= le32_to_cpu(bpl
[1].tus
.w
);
563 * Since the IOCB for the FCP I/O is built into this
564 * lpfc_scsi_buf, initialize it with all known data now.
566 iocb
= &psb
->cur_iocbq
.iocb
;
567 iocb
->un
.fcpi64
.bdl
.ulpIoTag32
= 0;
568 if ((phba
->sli_rev
== 3) &&
569 !(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
)) {
570 /* fill in immediate fcp command BDE */
571 iocb
->un
.fcpi64
.bdl
.bdeFlags
= BUFF_TYPE_BDE_IMMED
;
572 iocb
->un
.fcpi64
.bdl
.bdeSize
= sizeof(struct fcp_cmnd
);
573 iocb
->un
.fcpi64
.bdl
.addrLow
= offsetof(IOCB_t
,
575 iocb
->un
.fcpi64
.bdl
.addrHigh
= 0;
576 iocb
->ulpBdeCount
= 0;
578 /* fill in responce BDE */
579 iocb
->unsli3
.fcp_ext
.rbde
.tus
.f
.bdeFlags
=
581 iocb
->unsli3
.fcp_ext
.rbde
.tus
.f
.bdeSize
=
582 sizeof(struct fcp_rsp
);
583 iocb
->unsli3
.fcp_ext
.rbde
.addrLow
=
584 putPaddrLow(pdma_phys_fcp_rsp
);
585 iocb
->unsli3
.fcp_ext
.rbde
.addrHigh
=
586 putPaddrHigh(pdma_phys_fcp_rsp
);
588 iocb
->un
.fcpi64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
589 iocb
->un
.fcpi64
.bdl
.bdeSize
=
590 (2 * sizeof(struct ulp_bde64
));
591 iocb
->un
.fcpi64
.bdl
.addrLow
=
592 putPaddrLow(pdma_phys_bpl
);
593 iocb
->un
.fcpi64
.bdl
.addrHigh
=
594 putPaddrHigh(pdma_phys_bpl
);
595 iocb
->ulpBdeCount
= 1;
598 iocb
->ulpClass
= CLASS3
;
599 psb
->status
= IOSTAT_SUCCESS
;
600 /* Put it back into the SCSI buffer list */
601 lpfc_release_scsi_buf_s3(phba
, psb
);
609 * lpfc_sli4_fcp_xri_aborted - Fast-path process of fcp xri abort
610 * @phba: pointer to lpfc hba data structure.
611 * @axri: pointer to the fcp xri abort wcqe structure.
613 * This routine is invoked by the worker thread to process a SLI4 fast-path
617 lpfc_sli4_fcp_xri_aborted(struct lpfc_hba
*phba
,
618 struct sli4_wcqe_xri_aborted
*axri
)
620 uint16_t xri
= bf_get(lpfc_wcqe_xa_xri
, axri
);
621 struct lpfc_scsi_buf
*psb
, *next_psb
;
622 unsigned long iflag
= 0;
624 spin_lock_irqsave(&phba
->sli4_hba
.abts_scsi_buf_list_lock
, iflag
);
625 list_for_each_entry_safe(psb
, next_psb
,
626 &phba
->sli4_hba
.lpfc_abts_scsi_buf_list
, list
) {
627 if (psb
->cur_iocbq
.sli4_xritag
== xri
) {
628 list_del(&psb
->list
);
630 psb
->status
= IOSTAT_SUCCESS
;
631 spin_unlock_irqrestore(
632 &phba
->sli4_hba
.abts_scsi_buf_list_lock
,
634 lpfc_release_scsi_buf_s4(phba
, psb
);
638 spin_unlock_irqrestore(&phba
->sli4_hba
.abts_scsi_buf_list_lock
,
643 * lpfc_sli4_repost_scsi_sgl_list - Repsot the Scsi buffers sgl pages as block
644 * @phba: pointer to lpfc hba data structure.
646 * This routine walks the list of scsi buffers that have been allocated and
647 * repost them to the HBA by using SGL block post. This is needed after a
648 * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine
649 * is responsible for moving all scsi buffers on the lpfc_abts_scsi_sgl_list
650 * to the lpfc_scsi_buf_list. If the repost fails, reject all scsi buffers.
652 * Returns: 0 = success, non-zero failure.
655 lpfc_sli4_repost_scsi_sgl_list(struct lpfc_hba
*phba
)
657 struct lpfc_scsi_buf
*psb
;
658 int index
, status
, bcnt
= 0, rcnt
= 0, rc
= 0;
661 for (index
= 0; index
< phba
->sli4_hba
.scsi_xri_cnt
; index
++) {
662 psb
= phba
->sli4_hba
.lpfc_scsi_psb_array
[index
];
664 /* Remove from SCSI buffer list */
665 list_del(&psb
->list
);
666 /* Add it to a local SCSI buffer list */
667 list_add_tail(&psb
->list
, &sblist
);
668 if (++rcnt
== LPFC_NEMBED_MBOX_SGL_CNT
) {
673 /* A hole present in the XRI array, need to skip */
676 if (index
== phba
->sli4_hba
.scsi_xri_cnt
- 1)
677 /* End of XRI array for SCSI buffer, complete */
680 /* Continue until collect up to a nembed page worth of sgls */
683 /* Now, post the SCSI buffer list sgls as a block */
684 status
= lpfc_sli4_post_scsi_sgl_block(phba
, &sblist
, bcnt
);
685 /* Reset SCSI buffer count for next round of posting */
687 while (!list_empty(&sblist
)) {
688 list_remove_head(&sblist
, psb
, struct lpfc_scsi_buf
,
691 /* Put this back on the abort scsi list */
696 psb
->status
= IOSTAT_SUCCESS
;
698 /* Put it back into the SCSI buffer list */
699 lpfc_release_scsi_buf_s4(phba
, psb
);
706 * lpfc_new_scsi_buf_s4 - Scsi buffer allocator for HBA with SLI4 IF spec
707 * @vport: The virtual port for which this call being executed.
708 * @num_to_allocate: The requested number of buffers to allocate.
710 * This routine allocates a scsi buffer for device with SLI-4 interface spec,
711 * the scsi buffer contains all the necessary information needed to initiate
715 * int - number of scsi buffers that were allocated.
716 * 0 = failure, less than num_to_alloc is a partial failure.
719 lpfc_new_scsi_buf_s4(struct lpfc_vport
*vport
, int num_to_alloc
)
721 struct lpfc_hba
*phba
= vport
->phba
;
722 struct lpfc_scsi_buf
*psb
;
723 struct sli4_sge
*sgl
;
725 dma_addr_t pdma_phys_fcp_cmd
;
726 dma_addr_t pdma_phys_fcp_rsp
;
727 dma_addr_t pdma_phys_bpl
, pdma_phys_bpl1
;
728 uint16_t iotag
, last_xritag
= NO_XRI
;
729 int status
= 0, index
;
731 int non_sequential_xri
= 0;
735 for (bcnt
= 0; bcnt
< num_to_alloc
; bcnt
++) {
736 psb
= kzalloc(sizeof(struct lpfc_scsi_buf
), GFP_KERNEL
);
741 * Get memory from the pci pool to map the virt space to pci bus
742 * space for an I/O. The DMA buffer includes space for the
743 * struct fcp_cmnd, struct fcp_rsp and the number of bde's
744 * necessary to support the sg_tablesize.
746 psb
->data
= pci_pool_alloc(phba
->lpfc_scsi_dma_buf_pool
,
747 GFP_KERNEL
, &psb
->dma_handle
);
753 /* Initialize virtual ptrs to dma_buf region. */
754 memset(psb
->data
, 0, phba
->cfg_sg_dma_buf_size
);
756 /* Allocate iotag for psb->cur_iocbq. */
757 iotag
= lpfc_sli_next_iotag(phba
, &psb
->cur_iocbq
);
763 psb
->cur_iocbq
.sli4_xritag
= lpfc_sli4_next_xritag(phba
);
764 if (psb
->cur_iocbq
.sli4_xritag
== NO_XRI
) {
765 pci_pool_free(phba
->lpfc_scsi_dma_buf_pool
,
766 psb
->data
, psb
->dma_handle
);
770 if (last_xritag
!= NO_XRI
771 && psb
->cur_iocbq
.sli4_xritag
!= (last_xritag
+1)) {
772 non_sequential_xri
= 1;
774 list_add_tail(&psb
->list
, &sblist
);
775 last_xritag
= psb
->cur_iocbq
.sli4_xritag
;
777 index
= phba
->sli4_hba
.scsi_xri_cnt
++;
778 psb
->cur_iocbq
.iocb_flag
|= LPFC_IO_FCP
;
780 psb
->fcp_bpl
= psb
->data
;
781 psb
->fcp_cmnd
= (psb
->data
+ phba
->cfg_sg_dma_buf_size
)
782 - (sizeof(struct fcp_cmnd
) + sizeof(struct fcp_rsp
));
783 psb
->fcp_rsp
= (struct fcp_rsp
*)((uint8_t *)psb
->fcp_cmnd
+
784 sizeof(struct fcp_cmnd
));
786 /* Initialize local short-hand pointers. */
787 sgl
= (struct sli4_sge
*)psb
->fcp_bpl
;
788 pdma_phys_bpl
= psb
->dma_handle
;
790 (psb
->dma_handle
+ phba
->cfg_sg_dma_buf_size
)
791 - (sizeof(struct fcp_cmnd
) + sizeof(struct fcp_rsp
));
792 pdma_phys_fcp_rsp
= pdma_phys_fcp_cmd
+ sizeof(struct fcp_cmnd
);
795 * The first two bdes are the FCP_CMD and FCP_RSP. The balance
796 * are sg list bdes. Initialize the first two and leave the
797 * rest for queuecommand.
799 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd
));
800 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd
));
801 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
802 sgl
->word2
= cpu_to_le32(sgl
->word2
);
803 sgl
->sge_len
= cpu_to_le32(sizeof(struct fcp_cmnd
));
806 /* Setup the physical region for the FCP RSP */
807 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp
));
808 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp
));
809 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
810 sgl
->word2
= cpu_to_le32(sgl
->word2
);
811 sgl
->sge_len
= cpu_to_le32(sizeof(struct fcp_rsp
));
814 * Since the IOCB for the FCP I/O is built into this
815 * lpfc_scsi_buf, initialize it with all known data now.
817 iocb
= &psb
->cur_iocbq
.iocb
;
818 iocb
->un
.fcpi64
.bdl
.ulpIoTag32
= 0;
819 iocb
->un
.fcpi64
.bdl
.bdeFlags
= BUFF_TYPE_BDE_64
;
820 /* setting the BLP size to 2 * sizeof BDE may not be correct.
821 * We are setting the bpl to point to out sgl. An sgl's
822 * entries are 16 bytes, a bpl entries are 12 bytes.
824 iocb
->un
.fcpi64
.bdl
.bdeSize
= sizeof(struct fcp_cmnd
);
825 iocb
->un
.fcpi64
.bdl
.addrLow
= putPaddrLow(pdma_phys_fcp_cmd
);
826 iocb
->un
.fcpi64
.bdl
.addrHigh
= putPaddrHigh(pdma_phys_fcp_cmd
);
827 iocb
->ulpBdeCount
= 1;
829 iocb
->ulpClass
= CLASS3
;
830 if (phba
->cfg_sg_dma_buf_size
> SGL_PAGE_SIZE
)
831 pdma_phys_bpl1
= pdma_phys_bpl
+ SGL_PAGE_SIZE
;
834 psb
->dma_phys_bpl
= pdma_phys_bpl
;
835 phba
->sli4_hba
.lpfc_scsi_psb_array
[index
] = psb
;
836 if (non_sequential_xri
) {
837 status
= lpfc_sli4_post_sgl(phba
, pdma_phys_bpl
,
839 psb
->cur_iocbq
.sli4_xritag
);
841 /* Put this back on the abort scsi list */
846 psb
->status
= IOSTAT_SUCCESS
;
848 /* Put it back into the SCSI buffer list */
849 lpfc_release_scsi_buf_s4(phba
, psb
);
854 status
= lpfc_sli4_post_scsi_sgl_block(phba
, &sblist
, bcnt
);
855 /* Reset SCSI buffer count for next round of posting */
856 while (!list_empty(&sblist
)) {
857 list_remove_head(&sblist
, psb
, struct lpfc_scsi_buf
,
860 /* Put this back on the abort scsi list */
865 psb
->status
= IOSTAT_SUCCESS
;
867 /* Put it back into the SCSI buffer list */
868 lpfc_release_scsi_buf_s4(phba
, psb
);
872 return bcnt
+ non_sequential_xri
- rc
;
876 * lpfc_new_scsi_buf - Wrapper funciton for scsi buffer allocator
877 * @vport: The virtual port for which this call being executed.
878 * @num_to_allocate: The requested number of buffers to allocate.
880 * This routine wraps the actual SCSI buffer allocator function pointer from
881 * the lpfc_hba struct.
884 * int - number of scsi buffers that were allocated.
885 * 0 = failure, less than num_to_alloc is a partial failure.
888 lpfc_new_scsi_buf(struct lpfc_vport
*vport
, int num_to_alloc
)
890 return vport
->phba
->lpfc_new_scsi_buf(vport
, num_to_alloc
);
894 * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
895 * @phba: The HBA for which this call is being executed.
897 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
898 * and returns to caller.
902 * Pointer to lpfc_scsi_buf - Success
904 static struct lpfc_scsi_buf
*
905 lpfc_get_scsi_buf(struct lpfc_hba
* phba
)
907 struct lpfc_scsi_buf
* lpfc_cmd
= NULL
;
908 struct list_head
*scsi_buf_list
= &phba
->lpfc_scsi_buf_list
;
909 unsigned long iflag
= 0;
911 spin_lock_irqsave(&phba
->scsi_buf_list_lock
, iflag
);
912 list_remove_head(scsi_buf_list
, lpfc_cmd
, struct lpfc_scsi_buf
, list
);
914 lpfc_cmd
->seg_cnt
= 0;
915 lpfc_cmd
->nonsg_phys
= 0;
916 lpfc_cmd
->prot_seg_cnt
= 0;
918 spin_unlock_irqrestore(&phba
->scsi_buf_list_lock
, iflag
);
923 * lpfc_release_scsi_buf - Return a scsi buffer back to hba scsi buf list
924 * @phba: The Hba for which this call is being executed.
925 * @psb: The scsi buffer which is being released.
927 * This routine releases @psb scsi buffer by adding it to tail of @phba
928 * lpfc_scsi_buf_list list.
931 lpfc_release_scsi_buf_s3(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
)
933 unsigned long iflag
= 0;
935 spin_lock_irqsave(&phba
->scsi_buf_list_lock
, iflag
);
937 list_add_tail(&psb
->list
, &phba
->lpfc_scsi_buf_list
);
938 spin_unlock_irqrestore(&phba
->scsi_buf_list_lock
, iflag
);
942 * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list.
943 * @phba: The Hba for which this call is being executed.
944 * @psb: The scsi buffer which is being released.
946 * This routine releases @psb scsi buffer by adding it to tail of @phba
947 * lpfc_scsi_buf_list list. For SLI4 XRI's are tied to the scsi buffer
948 * and cannot be reused for at least RA_TOV amount of time if it was
952 lpfc_release_scsi_buf_s4(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
)
954 unsigned long iflag
= 0;
956 if (psb
->exch_busy
) {
957 spin_lock_irqsave(&phba
->sli4_hba
.abts_scsi_buf_list_lock
,
960 list_add_tail(&psb
->list
,
961 &phba
->sli4_hba
.lpfc_abts_scsi_buf_list
);
962 spin_unlock_irqrestore(&phba
->sli4_hba
.abts_scsi_buf_list_lock
,
966 spin_lock_irqsave(&phba
->scsi_buf_list_lock
, iflag
);
968 list_add_tail(&psb
->list
, &phba
->lpfc_scsi_buf_list
);
969 spin_unlock_irqrestore(&phba
->scsi_buf_list_lock
, iflag
);
974 * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list.
975 * @phba: The Hba for which this call is being executed.
976 * @psb: The scsi buffer which is being released.
978 * This routine releases @psb scsi buffer by adding it to tail of @phba
979 * lpfc_scsi_buf_list list.
982 lpfc_release_scsi_buf(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
)
985 phba
->lpfc_release_scsi_buf(phba
, psb
);
989 * lpfc_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
990 * @phba: The Hba for which this call is being executed.
991 * @lpfc_cmd: The scsi buffer which is going to be mapped.
993 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
994 * field of @lpfc_cmd for device with SLI-3 interface spec. This routine scans
995 * through sg elements and format the bdea. This routine also initializes all
996 * IOCB fields which are dependent on scsi command request buffer.
1003 lpfc_scsi_prep_dma_buf_s3(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
)
1005 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
1006 struct scatterlist
*sgel
= NULL
;
1007 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
1008 struct ulp_bde64
*bpl
= lpfc_cmd
->fcp_bpl
;
1009 IOCB_t
*iocb_cmd
= &lpfc_cmd
->cur_iocbq
.iocb
;
1010 struct ulp_bde64
*data_bde
= iocb_cmd
->unsli3
.fcp_ext
.dbde
;
1011 dma_addr_t physaddr
;
1012 uint32_t num_bde
= 0;
1013 int nseg
, datadir
= scsi_cmnd
->sc_data_direction
;
1016 * There are three possibilities here - use scatter-gather segment, use
1017 * the single mapping, or neither. Start the lpfc command prep by
1018 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
1022 if (scsi_sg_count(scsi_cmnd
)) {
1024 * The driver stores the segment count returned from pci_map_sg
1025 * because this a count of dma-mappings used to map the use_sg
1026 * pages. They are not guaranteed to be the same for those
1027 * architectures that implement an IOMMU.
1030 nseg
= dma_map_sg(&phba
->pcidev
->dev
, scsi_sglist(scsi_cmnd
),
1031 scsi_sg_count(scsi_cmnd
), datadir
);
1032 if (unlikely(!nseg
))
1035 lpfc_cmd
->seg_cnt
= nseg
;
1036 if (lpfc_cmd
->seg_cnt
> phba
->cfg_sg_seg_cnt
) {
1037 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1038 "9064 BLKGRD: %s: Too many sg segments from "
1039 "dma_map_sg. Config %d, seg_cnt %d\n",
1040 __func__
, phba
->cfg_sg_seg_cnt
,
1042 scsi_dma_unmap(scsi_cmnd
);
1047 * The driver established a maximum scatter-gather segment count
1048 * during probe that limits the number of sg elements in any
1049 * single scsi command. Just run through the seg_cnt and format
1051 * When using SLI-3 the driver will try to fit all the BDEs into
1052 * the IOCB. If it can't then the BDEs get added to a BPL as it
1053 * does for SLI-2 mode.
1055 scsi_for_each_sg(scsi_cmnd
, sgel
, nseg
, num_bde
) {
1056 physaddr
= sg_dma_address(sgel
);
1057 if (phba
->sli_rev
== 3 &&
1058 !(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
) &&
1059 nseg
<= LPFC_EXT_DATA_BDE_COUNT
) {
1060 data_bde
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
1061 data_bde
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
1062 data_bde
->addrLow
= putPaddrLow(physaddr
);
1063 data_bde
->addrHigh
= putPaddrHigh(physaddr
);
1066 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
1067 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
1068 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
1070 le32_to_cpu(putPaddrLow(physaddr
));
1072 le32_to_cpu(putPaddrHigh(physaddr
));
1079 * Finish initializing those IOCB fields that are dependent on the
1080 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
1081 * explicitly reinitialized and for SLI-3 the extended bde count is
1082 * explicitly reinitialized since all iocb memory resources are reused.
1084 if (phba
->sli_rev
== 3 &&
1085 !(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
)) {
1086 if (num_bde
> LPFC_EXT_DATA_BDE_COUNT
) {
1088 * The extended IOCB format can only fit 3 BDE or a BPL.
1089 * This I/O has more than 3 BDE so the 1st data bde will
1090 * be a BPL that is filled in here.
1092 physaddr
= lpfc_cmd
->dma_handle
;
1093 data_bde
->tus
.f
.bdeFlags
= BUFF_TYPE_BLP_64
;
1094 data_bde
->tus
.f
.bdeSize
= (num_bde
*
1095 sizeof(struct ulp_bde64
));
1096 physaddr
+= (sizeof(struct fcp_cmnd
) +
1097 sizeof(struct fcp_rsp
) +
1098 (2 * sizeof(struct ulp_bde64
)));
1099 data_bde
->addrHigh
= putPaddrHigh(physaddr
);
1100 data_bde
->addrLow
= putPaddrLow(physaddr
);
1101 /* ebde count includes the responce bde and data bpl */
1102 iocb_cmd
->unsli3
.fcp_ext
.ebde_count
= 2;
1104 /* ebde count includes the responce bde and data bdes */
1105 iocb_cmd
->unsli3
.fcp_ext
.ebde_count
= (num_bde
+ 1);
1108 iocb_cmd
->un
.fcpi64
.bdl
.bdeSize
=
1109 ((num_bde
+ 2) * sizeof(struct ulp_bde64
));
1111 fcp_cmnd
->fcpDl
= cpu_to_be32(scsi_bufflen(scsi_cmnd
));
1114 * Due to difference in data length between DIF/non-DIF paths,
1115 * we need to set word 4 of IOCB here
1117 iocb_cmd
->un
.fcpi
.fcpi_parm
= scsi_bufflen(scsi_cmnd
);
1122 * Given a scsi cmnd, determine the BlockGuard profile to be used
1126 lpfc_sc_to_sli_prof(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
)
1128 uint8_t guard_type
= scsi_host_get_guard(sc
->device
->host
);
1129 uint8_t ret_prof
= LPFC_PROF_INVALID
;
1131 if (guard_type
== SHOST_DIX_GUARD_IP
) {
1132 switch (scsi_get_prot_op(sc
)) {
1133 case SCSI_PROT_READ_INSERT
:
1134 case SCSI_PROT_WRITE_STRIP
:
1135 ret_prof
= LPFC_PROF_AST2
;
1138 case SCSI_PROT_READ_STRIP
:
1139 case SCSI_PROT_WRITE_INSERT
:
1140 ret_prof
= LPFC_PROF_A1
;
1143 case SCSI_PROT_READ_PASS
:
1144 case SCSI_PROT_WRITE_PASS
:
1145 ret_prof
= LPFC_PROF_AST1
;
1148 case SCSI_PROT_NORMAL
:
1150 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1151 "9063 BLKGRD:Bad op/guard:%d/%d combination\n",
1152 scsi_get_prot_op(sc
), guard_type
);
1156 } else if (guard_type
== SHOST_DIX_GUARD_CRC
) {
1157 switch (scsi_get_prot_op(sc
)) {
1158 case SCSI_PROT_READ_STRIP
:
1159 case SCSI_PROT_WRITE_INSERT
:
1160 ret_prof
= LPFC_PROF_A1
;
1163 case SCSI_PROT_READ_PASS
:
1164 case SCSI_PROT_WRITE_PASS
:
1165 ret_prof
= LPFC_PROF_C1
;
1168 case SCSI_PROT_READ_INSERT
:
1169 case SCSI_PROT_WRITE_STRIP
:
1170 case SCSI_PROT_NORMAL
:
1172 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1173 "9075 BLKGRD: Bad op/guard:%d/%d combination\n",
1174 scsi_get_prot_op(sc
), guard_type
);
1178 /* unsupported format */
1185 struct scsi_dif_tuple
{
1186 __be16 guard_tag
; /* Checksum */
1187 __be16 app_tag
; /* Opaque storage */
1188 __be32 ref_tag
; /* Target LBA or indirect LBA */
1191 static inline unsigned
1192 lpfc_cmd_blksize(struct scsi_cmnd
*sc
)
1194 return sc
->device
->sector_size
;
1198 * lpfc_get_cmd_dif_parms - Extract DIF parameters from SCSI command
1199 * @sc: in: SCSI command
1200 * @apptagmask: out: app tag mask
1201 * @apptagval: out: app tag value
1202 * @reftag: out: ref tag (reference tag)
1205 * Extract DIF parameters from the command if possible. Otherwise,
1206 * use default parameters.
1210 lpfc_get_cmd_dif_parms(struct scsi_cmnd
*sc
, uint16_t *apptagmask
,
1211 uint16_t *apptagval
, uint32_t *reftag
)
1213 struct scsi_dif_tuple
*spt
;
1214 unsigned char op
= scsi_get_prot_op(sc
);
1215 unsigned int protcnt
= scsi_prot_sg_count(sc
);
1218 if (protcnt
&& (op
== SCSI_PROT_WRITE_STRIP
||
1219 op
== SCSI_PROT_WRITE_PASS
)) {
1222 spt
= page_address(sg_page(scsi_prot_sglist(sc
))) +
1223 scsi_prot_sglist(sc
)[0].offset
;
1226 *reftag
= cpu_to_be32(spt
->ref_tag
);
1229 /* SBC defines ref tag to be lower 32bits of LBA */
1230 *reftag
= (uint32_t) (0xffffffff & scsi_get_lba(sc
));
1237 * This function sets up buffer list for protection groups of
1238 * type LPFC_PG_TYPE_NO_DIF
1240 * This is usually used when the HBA is instructed to generate
1241 * DIFs and insert them into data stream (or strip DIF from
1242 * incoming data stream)
1244 * The buffer list consists of just one protection group described
1246 * +-------------------------+
1247 * start of prot group --> | PDE_1 |
1248 * +-------------------------+
1250 * +-------------------------+
1251 * |more Data BDE's ... (opt)|
1252 * +-------------------------+
1254 * @sc: pointer to scsi command we're working on
1255 * @bpl: pointer to buffer list for protection groups
1256 * @datacnt: number of segments of data that have been dma mapped
1258 * Note: Data s/g buffers have been dma mapped
1261 lpfc_bg_setup_bpl(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
1262 struct ulp_bde64
*bpl
, int datasegcnt
)
1264 struct scatterlist
*sgde
= NULL
; /* s/g data entry */
1265 struct lpfc_pde
*pde1
= NULL
;
1266 dma_addr_t physaddr
;
1267 int i
= 0, num_bde
= 0;
1268 int datadir
= sc
->sc_data_direction
;
1269 int prof
= LPFC_PROF_INVALID
;
1272 uint16_t apptagmask
, apptagval
;
1274 pde1
= (struct lpfc_pde
*) bpl
;
1275 prof
= lpfc_sc_to_sli_prof(phba
, sc
);
1277 if (prof
== LPFC_PROF_INVALID
)
1280 /* extract some info from the scsi command for PDE1*/
1281 blksize
= lpfc_cmd_blksize(sc
);
1282 lpfc_get_cmd_dif_parms(sc
, &apptagmask
, &apptagval
, &reftag
);
1284 /* setup PDE1 with what we have */
1285 lpfc_pde_set_bg_parms(pde1
, LPFC_PDE1_DESCRIPTOR
, prof
, blksize
,
1287 lpfc_pde_set_dif_parms(pde1
, apptagmask
, apptagval
, reftag
);
1292 /* assumption: caller has already run dma_map_sg on command data */
1293 scsi_for_each_sg(sc
, sgde
, datasegcnt
, i
) {
1294 physaddr
= sg_dma_address(sgde
);
1295 bpl
->addrLow
= le32_to_cpu(putPaddrLow(physaddr
));
1296 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(physaddr
));
1297 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgde
);
1298 if (datadir
== DMA_TO_DEVICE
)
1299 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
1301 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
1302 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
1312 * This function sets up buffer list for protection groups of
1313 * type LPFC_PG_TYPE_DIF_BUF
1315 * This is usually used when DIFs are in their own buffers,
1316 * separate from the data. The HBA can then by instructed
1317 * to place the DIFs in the outgoing stream. For read operations,
1318 * The HBA could extract the DIFs and place it in DIF buffers.
1320 * The buffer list for this type consists of one or more of the
1321 * protection groups described below:
1322 * +-------------------------+
1323 * start of first prot group --> | PDE_1 |
1324 * +-------------------------+
1325 * | PDE_3 (Prot BDE) |
1326 * +-------------------------+
1328 * +-------------------------+
1329 * |more Data BDE's ... (opt)|
1330 * +-------------------------+
1331 * start of new prot group --> | PDE_1 |
1332 * +-------------------------+
1334 * +-------------------------+
1336 * @sc: pointer to scsi command we're working on
1337 * @bpl: pointer to buffer list for protection groups
1338 * @datacnt: number of segments of data that have been dma mapped
1339 * @protcnt: number of segment of protection data that have been dma mapped
1341 * Note: It is assumed that both data and protection s/g buffers have been
1345 lpfc_bg_setup_bpl_prot(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
1346 struct ulp_bde64
*bpl
, int datacnt
, int protcnt
)
1348 struct scatterlist
*sgde
= NULL
; /* s/g data entry */
1349 struct scatterlist
*sgpe
= NULL
; /* s/g prot entry */
1350 struct lpfc_pde
*pde1
= NULL
;
1351 struct ulp_bde64
*prot_bde
= NULL
;
1352 dma_addr_t dataphysaddr
, protphysaddr
;
1353 unsigned short curr_data
= 0, curr_prot
= 0;
1354 unsigned int split_offset
, protgroup_len
;
1355 unsigned int protgrp_blks
, protgrp_bytes
;
1356 unsigned int remainder
, subtotal
;
1357 int prof
= LPFC_PROF_INVALID
;
1358 int datadir
= sc
->sc_data_direction
;
1359 unsigned char pgdone
= 0, alldone
= 0;
1362 uint16_t apptagmask
, apptagval
;
1365 sgpe
= scsi_prot_sglist(sc
);
1366 sgde
= scsi_sglist(sc
);
1368 if (!sgpe
|| !sgde
) {
1369 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
1370 "9020 Invalid s/g entry: data=0x%p prot=0x%p\n",
1375 prof
= lpfc_sc_to_sli_prof(phba
, sc
);
1376 if (prof
== LPFC_PROF_INVALID
)
1379 /* extract some info from the scsi command for PDE1*/
1380 blksize
= lpfc_cmd_blksize(sc
);
1381 lpfc_get_cmd_dif_parms(sc
, &apptagmask
, &apptagval
, &reftag
);
1385 /* setup the first PDE_1 */
1386 pde1
= (struct lpfc_pde
*) bpl
;
1388 lpfc_pde_set_bg_parms(pde1
, LPFC_PDE1_DESCRIPTOR
, prof
, blksize
,
1390 lpfc_pde_set_dif_parms(pde1
, apptagmask
, apptagval
, reftag
);
1395 /* setup the first BDE that points to protection buffer */
1396 prot_bde
= (struct ulp_bde64
*) bpl
;
1397 protphysaddr
= sg_dma_address(sgpe
);
1398 prot_bde
->addrLow
= le32_to_cpu(putPaddrLow(protphysaddr
));
1399 prot_bde
->addrHigh
= le32_to_cpu(putPaddrHigh(protphysaddr
));
1400 protgroup_len
= sg_dma_len(sgpe
);
1403 /* must be integer multiple of the DIF block length */
1404 BUG_ON(protgroup_len
% 8);
1406 protgrp_blks
= protgroup_len
/ 8;
1407 protgrp_bytes
= protgrp_blks
* blksize
;
1409 prot_bde
->tus
.f
.bdeSize
= protgroup_len
;
1410 if (datadir
== DMA_TO_DEVICE
)
1411 prot_bde
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
1413 prot_bde
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
1414 prot_bde
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
1419 /* setup BDE's for data blocks associated with DIF data */
1421 subtotal
= 0; /* total bytes processed for current prot grp */
1424 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1425 "9065 BLKGRD:%s Invalid data segment\n",
1430 dataphysaddr
= sg_dma_address(sgde
) + split_offset
;
1431 bpl
->addrLow
= le32_to_cpu(putPaddrLow(dataphysaddr
));
1432 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(dataphysaddr
));
1434 remainder
= sg_dma_len(sgde
) - split_offset
;
1436 if ((subtotal
+ remainder
) <= protgrp_bytes
) {
1437 /* we can use this whole buffer */
1438 bpl
->tus
.f
.bdeSize
= remainder
;
1441 if ((subtotal
+ remainder
) == protgrp_bytes
)
1444 /* must split this buffer with next prot grp */
1445 bpl
->tus
.f
.bdeSize
= protgrp_bytes
- subtotal
;
1446 split_offset
+= bpl
->tus
.f
.bdeSize
;
1449 subtotal
+= bpl
->tus
.f
.bdeSize
;
1451 if (datadir
== DMA_TO_DEVICE
)
1452 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
1454 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
1455 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
1463 /* Move to the next s/g segment if possible */
1464 sgde
= sg_next(sgde
);
1468 if (curr_prot
== protcnt
) {
1470 } else if (curr_prot
< protcnt
) {
1471 /* advance to next prot buffer */
1472 sgpe
= sg_next(sgpe
);
1475 /* update the reference tag */
1476 reftag
+= protgrp_blks
;
1478 /* if we're here, we have a bug */
1479 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1480 "9054 BLKGRD: bug in %s\n", __func__
);
1491 * Given a SCSI command that supports DIF, determine composition of protection
1492 * groups involved in setting up buffer lists
1495 * for DIF (for both read and write)
1498 lpfc_prot_group_type(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
)
1500 int ret
= LPFC_PG_TYPE_INVALID
;
1501 unsigned char op
= scsi_get_prot_op(sc
);
1504 case SCSI_PROT_READ_STRIP
:
1505 case SCSI_PROT_WRITE_INSERT
:
1506 ret
= LPFC_PG_TYPE_NO_DIF
;
1508 case SCSI_PROT_READ_INSERT
:
1509 case SCSI_PROT_WRITE_STRIP
:
1510 case SCSI_PROT_READ_PASS
:
1511 case SCSI_PROT_WRITE_PASS
:
1512 ret
= LPFC_PG_TYPE_DIF_BUF
;
1515 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
1516 "9021 Unsupported protection op:%d\n", op
);
1524 * This is the protection/DIF aware version of
1525 * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the
1526 * two functions eventually, but for now, it's here
1529 lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba
*phba
,
1530 struct lpfc_scsi_buf
*lpfc_cmd
)
1532 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
1533 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
1534 struct ulp_bde64
*bpl
= lpfc_cmd
->fcp_bpl
;
1535 IOCB_t
*iocb_cmd
= &lpfc_cmd
->cur_iocbq
.iocb
;
1536 uint32_t num_bde
= 0;
1537 int datasegcnt
, protsegcnt
, datadir
= scsi_cmnd
->sc_data_direction
;
1538 int prot_group_type
= 0;
1543 * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd
1544 * fcp_rsp regions to the first data bde entry
1547 if (scsi_sg_count(scsi_cmnd
)) {
1549 * The driver stores the segment count returned from pci_map_sg
1550 * because this a count of dma-mappings used to map the use_sg
1551 * pages. They are not guaranteed to be the same for those
1552 * architectures that implement an IOMMU.
1554 datasegcnt
= dma_map_sg(&phba
->pcidev
->dev
,
1555 scsi_sglist(scsi_cmnd
),
1556 scsi_sg_count(scsi_cmnd
), datadir
);
1557 if (unlikely(!datasegcnt
))
1560 lpfc_cmd
->seg_cnt
= datasegcnt
;
1561 if (lpfc_cmd
->seg_cnt
> phba
->cfg_sg_seg_cnt
) {
1562 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1563 "9067 BLKGRD: %s: Too many sg segments"
1564 " from dma_map_sg. Config %d, seg_cnt"
1566 __func__
, phba
->cfg_sg_seg_cnt
,
1568 scsi_dma_unmap(scsi_cmnd
);
1572 prot_group_type
= lpfc_prot_group_type(phba
, scsi_cmnd
);
1574 switch (prot_group_type
) {
1575 case LPFC_PG_TYPE_NO_DIF
:
1576 num_bde
= lpfc_bg_setup_bpl(phba
, scsi_cmnd
, bpl
,
1578 /* we should have 2 or more entries in buffer list */
1582 case LPFC_PG_TYPE_DIF_BUF
:{
1584 * This type indicates that protection buffers are
1585 * passed to the driver, so that needs to be prepared
1588 protsegcnt
= dma_map_sg(&phba
->pcidev
->dev
,
1589 scsi_prot_sglist(scsi_cmnd
),
1590 scsi_prot_sg_count(scsi_cmnd
), datadir
);
1591 if (unlikely(!protsegcnt
)) {
1592 scsi_dma_unmap(scsi_cmnd
);
1596 lpfc_cmd
->prot_seg_cnt
= protsegcnt
;
1597 if (lpfc_cmd
->prot_seg_cnt
1598 > phba
->cfg_prot_sg_seg_cnt
) {
1599 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1600 "9068 BLKGRD: %s: Too many prot sg "
1601 "segments from dma_map_sg. Config %d,"
1602 "prot_seg_cnt %d\n", __func__
,
1603 phba
->cfg_prot_sg_seg_cnt
,
1604 lpfc_cmd
->prot_seg_cnt
);
1605 dma_unmap_sg(&phba
->pcidev
->dev
,
1606 scsi_prot_sglist(scsi_cmnd
),
1607 scsi_prot_sg_count(scsi_cmnd
),
1609 scsi_dma_unmap(scsi_cmnd
);
1613 num_bde
= lpfc_bg_setup_bpl_prot(phba
, scsi_cmnd
, bpl
,
1614 datasegcnt
, protsegcnt
);
1615 /* we should have 3 or more entries in buffer list */
1620 case LPFC_PG_TYPE_INVALID
:
1622 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
1623 "9022 Unexpected protection group %i\n",
1630 * Finish initializing those IOCB fields that are dependent on the
1631 * scsi_cmnd request_buffer. Note that the bdeSize is explicitly
1632 * reinitialized since all iocb memory resources are used many times
1633 * for transmit, receive, and continuation bpl's.
1635 iocb_cmd
->un
.fcpi64
.bdl
.bdeSize
= (2 * sizeof(struct ulp_bde64
));
1636 iocb_cmd
->un
.fcpi64
.bdl
.bdeSize
+= (num_bde
* sizeof(struct ulp_bde64
));
1637 iocb_cmd
->ulpBdeCount
= 1;
1638 iocb_cmd
->ulpLe
= 1;
1640 fcpdl
= scsi_bufflen(scsi_cmnd
);
1642 if (scsi_get_prot_type(scsi_cmnd
) == SCSI_PROT_DIF_TYPE1
) {
1644 * We are in DIF Type 1 mode
1645 * Every data block has a 8 byte DIF (trailer)
1646 * attached to it. Must ajust FCP data length
1648 blksize
= lpfc_cmd_blksize(scsi_cmnd
);
1649 diflen
= (fcpdl
/ blksize
) * 8;
1652 fcp_cmnd
->fcpDl
= be32_to_cpu(fcpdl
);
1655 * Due to difference in data length between DIF/non-DIF paths,
1656 * we need to set word 4 of IOCB here
1658 iocb_cmd
->un
.fcpi
.fcpi_parm
= fcpdl
;
1662 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
1663 "9023 Could not setup all needed BDE's"
1664 "prot_group_type=%d, num_bde=%d\n",
1665 prot_group_type
, num_bde
);
1670 * This function checks for BlockGuard errors detected by
1671 * the HBA. In case of errors, the ASC/ASCQ fields in the
1672 * sense buffer will be set accordingly, paired with
1673 * ILLEGAL_REQUEST to signal to the kernel that the HBA
1674 * detected corruption.
1677 * 0 - No error found
1678 * 1 - BlockGuard error found
1679 * -1 - Internal error (bad profile, ...etc)
1682 lpfc_parse_bg_err(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
,
1683 struct lpfc_iocbq
*pIocbOut
)
1685 struct scsi_cmnd
*cmd
= lpfc_cmd
->pCmd
;
1686 struct sli3_bg_fields
*bgf
= &pIocbOut
->iocb
.unsli3
.sli3_bg
;
1688 uint32_t bghm
= bgf
->bghm
;
1689 uint32_t bgstat
= bgf
->bgstat
;
1690 uint64_t failing_sector
= 0;
1692 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
, "9069 BLKGRD: BG ERROR in cmd"
1693 " 0x%x lba 0x%llx blk cnt 0x%x "
1694 "bgstat=0x%x bghm=0x%x\n",
1695 cmd
->cmnd
[0], (unsigned long long)scsi_get_lba(cmd
),
1696 blk_rq_sectors(cmd
->request
), bgstat
, bghm
);
1698 spin_lock(&_dump_buf_lock
);
1699 if (!_dump_buf_done
) {
1700 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
, "9070 BLKGRD: Saving"
1701 " Data for %u blocks to debugfs\n",
1702 (cmd
->cmnd
[7] << 8 | cmd
->cmnd
[8]));
1703 lpfc_debug_save_data(phba
, cmd
);
1705 /* If we have a prot sgl, save the DIF buffer */
1706 if (lpfc_prot_group_type(phba
, cmd
) ==
1707 LPFC_PG_TYPE_DIF_BUF
) {
1708 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
, "9071 BLKGRD: "
1709 "Saving DIF for %u blocks to debugfs\n",
1710 (cmd
->cmnd
[7] << 8 | cmd
->cmnd
[8]));
1711 lpfc_debug_save_dif(phba
, cmd
);
1716 spin_unlock(&_dump_buf_lock
);
1718 if (lpfc_bgs_get_invalid_prof(bgstat
)) {
1719 cmd
->result
= ScsiResult(DID_ERROR
, 0);
1720 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
, "9072 BLKGRD: Invalid"
1721 " BlockGuard profile. bgstat:0x%x\n",
1727 if (lpfc_bgs_get_uninit_dif_block(bgstat
)) {
1728 cmd
->result
= ScsiResult(DID_ERROR
, 0);
1729 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
, "9073 BLKGRD: "
1730 "Invalid BlockGuard DIF Block. bgstat:0x%x\n",
1736 if (lpfc_bgs_get_guard_err(bgstat
)) {
1739 scsi_build_sense_buffer(1, cmd
->sense_buffer
, ILLEGAL_REQUEST
,
1741 cmd
->result
= DRIVER_SENSE
<< 24
1742 | ScsiResult(DID_ABORT
, SAM_STAT_CHECK_CONDITION
);
1743 phba
->bg_guard_err_cnt
++;
1744 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1745 "9055 BLKGRD: guard_tag error\n");
1748 if (lpfc_bgs_get_reftag_err(bgstat
)) {
1751 scsi_build_sense_buffer(1, cmd
->sense_buffer
, ILLEGAL_REQUEST
,
1753 cmd
->result
= DRIVER_SENSE
<< 24
1754 | ScsiResult(DID_ABORT
, SAM_STAT_CHECK_CONDITION
);
1756 phba
->bg_reftag_err_cnt
++;
1757 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1758 "9056 BLKGRD: ref_tag error\n");
1761 if (lpfc_bgs_get_apptag_err(bgstat
)) {
1764 scsi_build_sense_buffer(1, cmd
->sense_buffer
, ILLEGAL_REQUEST
,
1766 cmd
->result
= DRIVER_SENSE
<< 24
1767 | ScsiResult(DID_ABORT
, SAM_STAT_CHECK_CONDITION
);
1769 phba
->bg_apptag_err_cnt
++;
1770 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1771 "9061 BLKGRD: app_tag error\n");
1774 if (lpfc_bgs_get_hi_water_mark_present(bgstat
)) {
1776 * setup sense data descriptor 0 per SPC-4 as an information
1777 * field, and put the failing LBA in it
1779 cmd
->sense_buffer
[8] = 0; /* Information */
1780 cmd
->sense_buffer
[9] = 0xa; /* Add. length */
1781 bghm
/= cmd
->device
->sector_size
;
1783 failing_sector
= scsi_get_lba(cmd
);
1784 failing_sector
+= bghm
;
1786 put_unaligned_be64(failing_sector
, &cmd
->sense_buffer
[10]);
1790 /* No error was reported - problem in FW? */
1791 cmd
->result
= ScsiResult(DID_ERROR
, 0);
1792 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1793 "9057 BLKGRD: no errors reported!\n");
1801 * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
1802 * @phba: The Hba for which this call is being executed.
1803 * @lpfc_cmd: The scsi buffer which is going to be mapped.
1805 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
1806 * field of @lpfc_cmd for device with SLI-4 interface spec.
1813 lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
)
1815 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
1816 struct scatterlist
*sgel
= NULL
;
1817 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
1818 struct sli4_sge
*sgl
= (struct sli4_sge
*)lpfc_cmd
->fcp_bpl
;
1819 IOCB_t
*iocb_cmd
= &lpfc_cmd
->cur_iocbq
.iocb
;
1820 dma_addr_t physaddr
;
1821 uint32_t num_bde
= 0;
1823 uint32_t dma_offset
= 0;
1827 * There are three possibilities here - use scatter-gather segment, use
1828 * the single mapping, or neither. Start the lpfc command prep by
1829 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
1832 if (scsi_sg_count(scsi_cmnd
)) {
1834 * The driver stores the segment count returned from pci_map_sg
1835 * because this a count of dma-mappings used to map the use_sg
1836 * pages. They are not guaranteed to be the same for those
1837 * architectures that implement an IOMMU.
1840 nseg
= scsi_dma_map(scsi_cmnd
);
1841 if (unlikely(!nseg
))
1844 /* clear the last flag in the fcp_rsp map entry */
1845 sgl
->word2
= le32_to_cpu(sgl
->word2
);
1846 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
1847 sgl
->word2
= cpu_to_le32(sgl
->word2
);
1850 lpfc_cmd
->seg_cnt
= nseg
;
1851 if (lpfc_cmd
->seg_cnt
> phba
->cfg_sg_seg_cnt
) {
1852 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
, "9074 BLKGRD:"
1853 " %s: Too many sg segments from "
1854 "dma_map_sg. Config %d, seg_cnt %d\n",
1855 __func__
, phba
->cfg_sg_seg_cnt
,
1857 scsi_dma_unmap(scsi_cmnd
);
1862 * The driver established a maximum scatter-gather segment count
1863 * during probe that limits the number of sg elements in any
1864 * single scsi command. Just run through the seg_cnt and format
1866 * When using SLI-3 the driver will try to fit all the BDEs into
1867 * the IOCB. If it can't then the BDEs get added to a BPL as it
1868 * does for SLI-2 mode.
1870 scsi_for_each_sg(scsi_cmnd
, sgel
, nseg
, num_bde
) {
1871 physaddr
= sg_dma_address(sgel
);
1872 dma_len
= sg_dma_len(sgel
);
1873 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(physaddr
));
1874 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(physaddr
));
1875 if ((num_bde
+ 1) == nseg
)
1876 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
1878 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
1879 bf_set(lpfc_sli4_sge_offset
, sgl
, dma_offset
);
1880 sgl
->word2
= cpu_to_le32(sgl
->word2
);
1881 sgl
->sge_len
= cpu_to_le32(dma_len
);
1882 dma_offset
+= dma_len
;
1887 /* clear the last flag in the fcp_rsp map entry */
1888 sgl
->word2
= le32_to_cpu(sgl
->word2
);
1889 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
1890 sgl
->word2
= cpu_to_le32(sgl
->word2
);
1894 * Finish initializing those IOCB fields that are dependent on the
1895 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
1896 * explicitly reinitialized.
1897 * all iocb memory resources are reused.
1899 fcp_cmnd
->fcpDl
= cpu_to_be32(scsi_bufflen(scsi_cmnd
));
1902 * Due to difference in data length between DIF/non-DIF paths,
1903 * we need to set word 4 of IOCB here
1905 iocb_cmd
->un
.fcpi
.fcpi_parm
= scsi_bufflen(scsi_cmnd
);
1910 * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
1911 * @phba: The Hba for which this call is being executed.
1912 * @lpfc_cmd: The scsi buffer which is going to be mapped.
1914 * This routine wraps the actual DMA mapping function pointer from the
1922 lpfc_scsi_prep_dma_buf(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
)
1924 return phba
->lpfc_scsi_prep_dma_buf(phba
, lpfc_cmd
);
1928 * lpfc_send_scsi_error_event - Posts an event when there is SCSI error
1929 * @phba: Pointer to hba context object.
1930 * @vport: Pointer to vport object.
1931 * @lpfc_cmd: Pointer to lpfc scsi command which reported the error.
1932 * @rsp_iocb: Pointer to response iocb object which reported error.
1934 * This function posts an event when there is a SCSI command reporting
1935 * error from the scsi device.
1938 lpfc_send_scsi_error_event(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
,
1939 struct lpfc_scsi_buf
*lpfc_cmd
, struct lpfc_iocbq
*rsp_iocb
) {
1940 struct scsi_cmnd
*cmnd
= lpfc_cmd
->pCmd
;
1941 struct fcp_rsp
*fcprsp
= lpfc_cmd
->fcp_rsp
;
1942 uint32_t resp_info
= fcprsp
->rspStatus2
;
1943 uint32_t scsi_status
= fcprsp
->rspStatus3
;
1944 uint32_t fcpi_parm
= rsp_iocb
->iocb
.un
.fcpi
.fcpi_parm
;
1945 struct lpfc_fast_path_event
*fast_path_evt
= NULL
;
1946 struct lpfc_nodelist
*pnode
= lpfc_cmd
->rdata
->pnode
;
1947 unsigned long flags
;
1949 /* If there is queuefull or busy condition send a scsi event */
1950 if ((cmnd
->result
== SAM_STAT_TASK_SET_FULL
) ||
1951 (cmnd
->result
== SAM_STAT_BUSY
)) {
1952 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
1955 fast_path_evt
->un
.scsi_evt
.event_type
=
1957 fast_path_evt
->un
.scsi_evt
.subcategory
=
1958 (cmnd
->result
== SAM_STAT_TASK_SET_FULL
) ?
1959 LPFC_EVENT_QFULL
: LPFC_EVENT_DEVBSY
;
1960 fast_path_evt
->un
.scsi_evt
.lun
= cmnd
->device
->lun
;
1961 memcpy(&fast_path_evt
->un
.scsi_evt
.wwpn
,
1962 &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
1963 memcpy(&fast_path_evt
->un
.scsi_evt
.wwnn
,
1964 &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
1965 } else if ((resp_info
& SNS_LEN_VALID
) && fcprsp
->rspSnsLen
&&
1966 ((cmnd
->cmnd
[0] == READ_10
) || (cmnd
->cmnd
[0] == WRITE_10
))) {
1967 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
1970 fast_path_evt
->un
.check_cond_evt
.scsi_event
.event_type
=
1972 fast_path_evt
->un
.check_cond_evt
.scsi_event
.subcategory
=
1973 LPFC_EVENT_CHECK_COND
;
1974 fast_path_evt
->un
.check_cond_evt
.scsi_event
.lun
=
1976 memcpy(&fast_path_evt
->un
.check_cond_evt
.scsi_event
.wwpn
,
1977 &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
1978 memcpy(&fast_path_evt
->un
.check_cond_evt
.scsi_event
.wwnn
,
1979 &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
1980 fast_path_evt
->un
.check_cond_evt
.sense_key
=
1981 cmnd
->sense_buffer
[2] & 0xf;
1982 fast_path_evt
->un
.check_cond_evt
.asc
= cmnd
->sense_buffer
[12];
1983 fast_path_evt
->un
.check_cond_evt
.ascq
= cmnd
->sense_buffer
[13];
1984 } else if ((cmnd
->sc_data_direction
== DMA_FROM_DEVICE
) &&
1986 ((be32_to_cpu(fcprsp
->rspResId
) != fcpi_parm
) ||
1987 ((scsi_status
== SAM_STAT_GOOD
) &&
1988 !(resp_info
& (RESID_UNDER
| RESID_OVER
))))) {
1990 * If status is good or resid does not match with fcp_param and
1991 * there is valid fcpi_parm, then there is a read_check error
1993 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
1996 fast_path_evt
->un
.read_check_error
.header
.event_type
=
1997 FC_REG_FABRIC_EVENT
;
1998 fast_path_evt
->un
.read_check_error
.header
.subcategory
=
1999 LPFC_EVENT_FCPRDCHKERR
;
2000 memcpy(&fast_path_evt
->un
.read_check_error
.header
.wwpn
,
2001 &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
2002 memcpy(&fast_path_evt
->un
.read_check_error
.header
.wwnn
,
2003 &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
2004 fast_path_evt
->un
.read_check_error
.lun
= cmnd
->device
->lun
;
2005 fast_path_evt
->un
.read_check_error
.opcode
= cmnd
->cmnd
[0];
2006 fast_path_evt
->un
.read_check_error
.fcpiparam
=
2011 fast_path_evt
->vport
= vport
;
2012 spin_lock_irqsave(&phba
->hbalock
, flags
);
2013 list_add_tail(&fast_path_evt
->work_evt
.evt_listp
, &phba
->work_list
);
2014 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
2015 lpfc_worker_wake_up(phba
);
2020 * lpfc_scsi_unprep_dma_buf - Un-map DMA mapping of SG-list for dev
2021 * @phba: The HBA for which this call is being executed.
2022 * @psb: The scsi buffer which is going to be un-mapped.
2024 * This routine does DMA un-mapping of scatter gather list of scsi command
2025 * field of @lpfc_cmd for device with SLI-3 interface spec.
2028 lpfc_scsi_unprep_dma_buf(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
)
2031 * There are only two special cases to consider. (1) the scsi command
2032 * requested scatter-gather usage or (2) the scsi command allocated
2033 * a request buffer, but did not request use_sg. There is a third
2034 * case, but it does not require resource deallocation.
2036 if (psb
->seg_cnt
> 0)
2037 scsi_dma_unmap(psb
->pCmd
);
2038 if (psb
->prot_seg_cnt
> 0)
2039 dma_unmap_sg(&phba
->pcidev
->dev
, scsi_prot_sglist(psb
->pCmd
),
2040 scsi_prot_sg_count(psb
->pCmd
),
2041 psb
->pCmd
->sc_data_direction
);
2045 * lpfc_handler_fcp_err - FCP response handler
2046 * @vport: The virtual port for which this call is being executed.
2047 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
2048 * @rsp_iocb: The response IOCB which contains FCP error.
2050 * This routine is called to process response IOCB with status field
2051 * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command
2052 * based upon SCSI and FCP error.
2055 lpfc_handle_fcp_err(struct lpfc_vport
*vport
, struct lpfc_scsi_buf
*lpfc_cmd
,
2056 struct lpfc_iocbq
*rsp_iocb
)
2058 struct scsi_cmnd
*cmnd
= lpfc_cmd
->pCmd
;
2059 struct fcp_cmnd
*fcpcmd
= lpfc_cmd
->fcp_cmnd
;
2060 struct fcp_rsp
*fcprsp
= lpfc_cmd
->fcp_rsp
;
2061 uint32_t fcpi_parm
= rsp_iocb
->iocb
.un
.fcpi
.fcpi_parm
;
2062 uint32_t resp_info
= fcprsp
->rspStatus2
;
2063 uint32_t scsi_status
= fcprsp
->rspStatus3
;
2065 uint32_t host_status
= DID_OK
;
2066 uint32_t rsplen
= 0;
2067 uint32_t logit
= LOG_FCP
| LOG_FCP_ERROR
;
2071 * If this is a task management command, there is no
2072 * scsi packet associated with this lpfc_cmd. The driver
2075 if (fcpcmd
->fcpCntl2
) {
2080 if (resp_info
& RSP_LEN_VALID
) {
2081 rsplen
= be32_to_cpu(fcprsp
->rspRspLen
);
2082 if ((rsplen
!= 0 && rsplen
!= 4 && rsplen
!= 8) ||
2083 (fcprsp
->rspInfo3
!= RSP_NO_FAILURE
)) {
2084 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
2085 "2719 Invalid response length: "
2086 "tgt x%x lun x%x cmnd x%x rsplen x%x\n",
2088 cmnd
->device
->lun
, cmnd
->cmnd
[0],
2090 host_status
= DID_ERROR
;
2095 if ((resp_info
& SNS_LEN_VALID
) && fcprsp
->rspSnsLen
) {
2096 uint32_t snslen
= be32_to_cpu(fcprsp
->rspSnsLen
);
2097 if (snslen
> SCSI_SENSE_BUFFERSIZE
)
2098 snslen
= SCSI_SENSE_BUFFERSIZE
;
2100 if (resp_info
& RSP_LEN_VALID
)
2101 rsplen
= be32_to_cpu(fcprsp
->rspRspLen
);
2102 memcpy(cmnd
->sense_buffer
, &fcprsp
->rspInfo0
+ rsplen
, snslen
);
2104 lp
= (uint32_t *)cmnd
->sense_buffer
;
2106 if (!scsi_status
&& (resp_info
& RESID_UNDER
))
2109 lpfc_printf_vlog(vport
, KERN_WARNING
, logit
,
2110 "9024 FCP command x%x failed: x%x SNS x%x x%x "
2111 "Data: x%x x%x x%x x%x x%x\n",
2112 cmnd
->cmnd
[0], scsi_status
,
2113 be32_to_cpu(*lp
), be32_to_cpu(*(lp
+ 3)), resp_info
,
2114 be32_to_cpu(fcprsp
->rspResId
),
2115 be32_to_cpu(fcprsp
->rspSnsLen
),
2116 be32_to_cpu(fcprsp
->rspRspLen
),
2119 scsi_set_resid(cmnd
, 0);
2120 if (resp_info
& RESID_UNDER
) {
2121 scsi_set_resid(cmnd
, be32_to_cpu(fcprsp
->rspResId
));
2123 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
2124 "9025 FCP Read Underrun, expected %d, "
2125 "residual %d Data: x%x x%x x%x\n",
2126 be32_to_cpu(fcpcmd
->fcpDl
),
2127 scsi_get_resid(cmnd
), fcpi_parm
, cmnd
->cmnd
[0],
2131 * If there is an under run check if under run reported by
2132 * storage array is same as the under run reported by HBA.
2133 * If this is not same, there is a dropped frame.
2135 if ((cmnd
->sc_data_direction
== DMA_FROM_DEVICE
) &&
2137 (scsi_get_resid(cmnd
) != fcpi_parm
)) {
2138 lpfc_printf_vlog(vport
, KERN_WARNING
,
2139 LOG_FCP
| LOG_FCP_ERROR
,
2140 "9026 FCP Read Check Error "
2141 "and Underrun Data: x%x x%x x%x x%x\n",
2142 be32_to_cpu(fcpcmd
->fcpDl
),
2143 scsi_get_resid(cmnd
), fcpi_parm
,
2145 scsi_set_resid(cmnd
, scsi_bufflen(cmnd
));
2146 host_status
= DID_ERROR
;
2149 * The cmnd->underflow is the minimum number of bytes that must
2150 * be transfered for this command. Provided a sense condition
2151 * is not present, make sure the actual amount transferred is at
2152 * least the underflow value or fail.
2154 if (!(resp_info
& SNS_LEN_VALID
) &&
2155 (scsi_status
== SAM_STAT_GOOD
) &&
2156 (scsi_bufflen(cmnd
) - scsi_get_resid(cmnd
)
2157 < cmnd
->underflow
)) {
2158 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
2159 "9027 FCP command x%x residual "
2160 "underrun converted to error "
2161 "Data: x%x x%x x%x\n",
2162 cmnd
->cmnd
[0], scsi_bufflen(cmnd
),
2163 scsi_get_resid(cmnd
), cmnd
->underflow
);
2164 host_status
= DID_ERROR
;
2166 } else if (resp_info
& RESID_OVER
) {
2167 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
2168 "9028 FCP command x%x residual overrun error. "
2169 "Data: x%x x%x\n", cmnd
->cmnd
[0],
2170 scsi_bufflen(cmnd
), scsi_get_resid(cmnd
));
2171 host_status
= DID_ERROR
;
2174 * Check SLI validation that all the transfer was actually done
2175 * (fcpi_parm should be zero). Apply check only to reads.
2177 } else if ((scsi_status
== SAM_STAT_GOOD
) && fcpi_parm
&&
2178 (cmnd
->sc_data_direction
== DMA_FROM_DEVICE
)) {
2179 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
| LOG_FCP_ERROR
,
2180 "9029 FCP Read Check Error Data: "
2181 "x%x x%x x%x x%x\n",
2182 be32_to_cpu(fcpcmd
->fcpDl
),
2183 be32_to_cpu(fcprsp
->rspResId
),
2184 fcpi_parm
, cmnd
->cmnd
[0]);
2185 host_status
= DID_ERROR
;
2186 scsi_set_resid(cmnd
, scsi_bufflen(cmnd
));
2190 cmnd
->result
= ScsiResult(host_status
, scsi_status
);
2191 lpfc_send_scsi_error_event(vport
->phba
, vport
, lpfc_cmd
, rsp_iocb
);
2195 * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine
2196 * @phba: The Hba for which this call is being executed.
2197 * @pIocbIn: The command IOCBQ for the scsi cmnd.
2198 * @pIocbOut: The response IOCBQ for the scsi cmnd.
2200 * This routine assigns scsi command result by looking into response IOCB
2201 * status field appropriately. This routine handles QUEUE FULL condition as
2202 * well by ramping down device queue depth.
2205 lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*pIocbIn
,
2206 struct lpfc_iocbq
*pIocbOut
)
2208 struct lpfc_scsi_buf
*lpfc_cmd
=
2209 (struct lpfc_scsi_buf
*) pIocbIn
->context1
;
2210 struct lpfc_vport
*vport
= pIocbIn
->vport
;
2211 struct lpfc_rport_data
*rdata
= lpfc_cmd
->rdata
;
2212 struct lpfc_nodelist
*pnode
= rdata
->pnode
;
2213 struct scsi_cmnd
*cmd
= lpfc_cmd
->pCmd
;
2215 struct scsi_device
*tmp_sdev
;
2217 unsigned long flags
;
2218 struct lpfc_fast_path_event
*fast_path_evt
;
2219 struct Scsi_Host
*shost
= cmd
->device
->host
;
2220 uint32_t queue_depth
, scsi_id
;
2222 lpfc_cmd
->result
= pIocbOut
->iocb
.un
.ulpWord
[4];
2223 lpfc_cmd
->status
= pIocbOut
->iocb
.ulpStatus
;
2224 /* pick up SLI4 exhange busy status from HBA */
2225 lpfc_cmd
->exch_busy
= pIocbOut
->iocb_flag
& LPFC_EXCHANGE_BUSY
;
2227 if (pnode
&& NLP_CHK_NODE_ACT(pnode
))
2228 atomic_dec(&pnode
->cmd_pending
);
2230 if (lpfc_cmd
->status
) {
2231 if (lpfc_cmd
->status
== IOSTAT_LOCAL_REJECT
&&
2232 (lpfc_cmd
->result
& IOERR_DRVR_MASK
))
2233 lpfc_cmd
->status
= IOSTAT_DRIVER_REJECT
;
2234 else if (lpfc_cmd
->status
>= IOSTAT_CNT
)
2235 lpfc_cmd
->status
= IOSTAT_DEFAULT
;
2237 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
2238 "9030 FCP cmd x%x failed <%d/%d> "
2239 "status: x%x result: x%x Data: x%x x%x\n",
2241 cmd
->device
? cmd
->device
->id
: 0xffff,
2242 cmd
->device
? cmd
->device
->lun
: 0xffff,
2243 lpfc_cmd
->status
, lpfc_cmd
->result
,
2244 pIocbOut
->iocb
.ulpContext
,
2245 lpfc_cmd
->cur_iocbq
.iocb
.ulpIoTag
);
2247 switch (lpfc_cmd
->status
) {
2248 case IOSTAT_FCP_RSP_ERROR
:
2249 /* Call FCP RSP handler to determine result */
2250 lpfc_handle_fcp_err(vport
, lpfc_cmd
, pIocbOut
);
2252 case IOSTAT_NPORT_BSY
:
2253 case IOSTAT_FABRIC_BSY
:
2254 cmd
->result
= ScsiResult(DID_TRANSPORT_DISRUPTED
, 0);
2255 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
2258 fast_path_evt
->un
.fabric_evt
.event_type
=
2259 FC_REG_FABRIC_EVENT
;
2260 fast_path_evt
->un
.fabric_evt
.subcategory
=
2261 (lpfc_cmd
->status
== IOSTAT_NPORT_BSY
) ?
2262 LPFC_EVENT_PORT_BUSY
: LPFC_EVENT_FABRIC_BUSY
;
2263 if (pnode
&& NLP_CHK_NODE_ACT(pnode
)) {
2264 memcpy(&fast_path_evt
->un
.fabric_evt
.wwpn
,
2265 &pnode
->nlp_portname
,
2266 sizeof(struct lpfc_name
));
2267 memcpy(&fast_path_evt
->un
.fabric_evt
.wwnn
,
2268 &pnode
->nlp_nodename
,
2269 sizeof(struct lpfc_name
));
2271 fast_path_evt
->vport
= vport
;
2272 fast_path_evt
->work_evt
.evt
=
2273 LPFC_EVT_FASTPATH_MGMT_EVT
;
2274 spin_lock_irqsave(&phba
->hbalock
, flags
);
2275 list_add_tail(&fast_path_evt
->work_evt
.evt_listp
,
2277 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
2278 lpfc_worker_wake_up(phba
);
2280 case IOSTAT_LOCAL_REJECT
:
2281 if (lpfc_cmd
->result
== IOERR_INVALID_RPI
||
2282 lpfc_cmd
->result
== IOERR_NO_RESOURCES
||
2283 lpfc_cmd
->result
== IOERR_ABORT_REQUESTED
) {
2284 cmd
->result
= ScsiResult(DID_REQUEUE
, 0);
2288 if ((lpfc_cmd
->result
== IOERR_RX_DMA_FAILED
||
2289 lpfc_cmd
->result
== IOERR_TX_DMA_FAILED
) &&
2290 pIocbOut
->iocb
.unsli3
.sli3_bg
.bgstat
) {
2291 if (scsi_get_prot_op(cmd
) != SCSI_PROT_NORMAL
) {
2293 * This is a response for a BG enabled
2294 * cmd. Parse BG error
2296 lpfc_parse_bg_err(phba
, lpfc_cmd
,
2300 lpfc_printf_vlog(vport
, KERN_WARNING
,
2302 "9031 non-zero BGSTAT "
2303 "on unprotected cmd\n");
2307 /* else: fall through */
2309 cmd
->result
= ScsiResult(DID_ERROR
, 0);
2313 if (!pnode
|| !NLP_CHK_NODE_ACT(pnode
)
2314 || (pnode
->nlp_state
!= NLP_STE_MAPPED_NODE
))
2315 cmd
->result
= ScsiResult(DID_TRANSPORT_DISRUPTED
,
2318 cmd
->result
= ScsiResult(DID_OK
, 0);
2321 if (cmd
->result
|| lpfc_cmd
->fcp_rsp
->rspSnsLen
) {
2322 uint32_t *lp
= (uint32_t *)cmd
->sense_buffer
;
2324 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
2325 "0710 Iodone <%d/%d> cmd %p, error "
2326 "x%x SNS x%x x%x Data: x%x x%x\n",
2327 cmd
->device
->id
, cmd
->device
->lun
, cmd
,
2328 cmd
->result
, *lp
, *(lp
+ 3), cmd
->retries
,
2329 scsi_get_resid(cmd
));
2332 lpfc_update_stats(phba
, lpfc_cmd
);
2333 result
= cmd
->result
;
2334 if (vport
->cfg_max_scsicmpl_time
&&
2335 time_after(jiffies
, lpfc_cmd
->start_time
+
2336 msecs_to_jiffies(vport
->cfg_max_scsicmpl_time
))) {
2337 spin_lock_irqsave(shost
->host_lock
, flags
);
2338 if (pnode
&& NLP_CHK_NODE_ACT(pnode
)) {
2339 if (pnode
->cmd_qdepth
>
2340 atomic_read(&pnode
->cmd_pending
) &&
2341 (atomic_read(&pnode
->cmd_pending
) >
2342 LPFC_MIN_TGT_QDEPTH
) &&
2343 ((cmd
->cmnd
[0] == READ_10
) ||
2344 (cmd
->cmnd
[0] == WRITE_10
)))
2346 atomic_read(&pnode
->cmd_pending
);
2348 pnode
->last_change_time
= jiffies
;
2350 spin_unlock_irqrestore(shost
->host_lock
, flags
);
2351 } else if (pnode
&& NLP_CHK_NODE_ACT(pnode
)) {
2352 if ((pnode
->cmd_qdepth
< LPFC_MAX_TGT_QDEPTH
) &&
2353 time_after(jiffies
, pnode
->last_change_time
+
2354 msecs_to_jiffies(LPFC_TGTQ_INTERVAL
))) {
2355 spin_lock_irqsave(shost
->host_lock
, flags
);
2356 pnode
->cmd_qdepth
+= pnode
->cmd_qdepth
*
2357 LPFC_TGTQ_RAMPUP_PCENT
/ 100;
2358 if (pnode
->cmd_qdepth
> LPFC_MAX_TGT_QDEPTH
)
2359 pnode
->cmd_qdepth
= LPFC_MAX_TGT_QDEPTH
;
2360 pnode
->last_change_time
= jiffies
;
2361 spin_unlock_irqrestore(shost
->host_lock
, flags
);
2365 lpfc_scsi_unprep_dma_buf(phba
, lpfc_cmd
);
2367 /* The sdev is not guaranteed to be valid post scsi_done upcall. */
2368 queue_depth
= cmd
->device
->queue_depth
;
2369 scsi_id
= cmd
->device
->id
;
2370 cmd
->scsi_done(cmd
);
2372 if (phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) {
2374 * If there is a thread waiting for command completion
2375 * wake up the thread.
2377 spin_lock_irqsave(shost
->host_lock
, flags
);
2378 lpfc_cmd
->pCmd
= NULL
;
2379 if (lpfc_cmd
->waitq
)
2380 wake_up(lpfc_cmd
->waitq
);
2381 spin_unlock_irqrestore(shost
->host_lock
, flags
);
2382 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
2387 lpfc_rampup_queue_depth(vport
, queue_depth
);
2390 * Check for queue full. If the lun is reporting queue full, then
2391 * back off the lun queue depth to prevent target overloads.
2393 if (result
== SAM_STAT_TASK_SET_FULL
&& pnode
&&
2394 NLP_CHK_NODE_ACT(pnode
)) {
2395 shost_for_each_device(tmp_sdev
, shost
) {
2396 if (tmp_sdev
->id
!= scsi_id
)
2398 depth
= scsi_track_queue_full(tmp_sdev
,
2399 tmp_sdev
->queue_depth
-1);
2402 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
2403 "0711 detected queue full - lun queue "
2404 "depth adjusted to %d.\n", depth
);
2405 lpfc_send_sdev_queuedepth_change_event(phba
, vport
,
2413 * If there is a thread waiting for command completion
2414 * wake up the thread.
2416 spin_lock_irqsave(shost
->host_lock
, flags
);
2417 lpfc_cmd
->pCmd
= NULL
;
2418 if (lpfc_cmd
->waitq
)
2419 wake_up(lpfc_cmd
->waitq
);
2420 spin_unlock_irqrestore(shost
->host_lock
, flags
);
2422 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
2426 * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB
2427 * @data: A pointer to the immediate command data portion of the IOCB.
2428 * @fcp_cmnd: The FCP Command that is provided by the SCSI layer.
2430 * The routine copies the entire FCP command from @fcp_cmnd to @data while
2431 * byte swapping the data to big endian format for transmission on the wire.
2434 lpfc_fcpcmd_to_iocb(uint8_t *data
, struct fcp_cmnd
*fcp_cmnd
)
2437 for (i
= 0, j
= 0; i
< sizeof(struct fcp_cmnd
);
2438 i
+= sizeof(uint32_t), j
++) {
2439 ((uint32_t *)data
)[j
] = cpu_to_be32(((uint32_t *)fcp_cmnd
)[j
]);
2444 * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit
2445 * @vport: The virtual port for which this call is being executed.
2446 * @lpfc_cmd: The scsi command which needs to send.
2447 * @pnode: Pointer to lpfc_nodelist.
2449 * This routine initializes fcp_cmnd and iocb data structure from scsi command
2450 * to transfer for device with SLI3 interface spec.
2453 lpfc_scsi_prep_cmnd(struct lpfc_vport
*vport
, struct lpfc_scsi_buf
*lpfc_cmd
,
2454 struct lpfc_nodelist
*pnode
)
2456 struct lpfc_hba
*phba
= vport
->phba
;
2457 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
2458 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
2459 IOCB_t
*iocb_cmd
= &lpfc_cmd
->cur_iocbq
.iocb
;
2460 struct lpfc_iocbq
*piocbq
= &(lpfc_cmd
->cur_iocbq
);
2461 int datadir
= scsi_cmnd
->sc_data_direction
;
2464 if (!pnode
|| !NLP_CHK_NODE_ACT(pnode
))
2467 lpfc_cmd
->fcp_rsp
->rspSnsLen
= 0;
2468 /* clear task management bits */
2469 lpfc_cmd
->fcp_cmnd
->fcpCntl2
= 0;
2471 int_to_scsilun(lpfc_cmd
->pCmd
->device
->lun
,
2472 &lpfc_cmd
->fcp_cmnd
->fcp_lun
);
2474 memcpy(&fcp_cmnd
->fcpCdb
[0], scsi_cmnd
->cmnd
, 16);
2476 if (scsi_populate_tag_msg(scsi_cmnd
, tag
)) {
2478 case HEAD_OF_QUEUE_TAG
:
2479 fcp_cmnd
->fcpCntl1
= HEAD_OF_Q
;
2481 case ORDERED_QUEUE_TAG
:
2482 fcp_cmnd
->fcpCntl1
= ORDERED_Q
;
2485 fcp_cmnd
->fcpCntl1
= SIMPLE_Q
;
2489 fcp_cmnd
->fcpCntl1
= 0;
2492 * There are three possibilities here - use scatter-gather segment, use
2493 * the single mapping, or neither. Start the lpfc command prep by
2494 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
2497 if (scsi_sg_count(scsi_cmnd
)) {
2498 if (datadir
== DMA_TO_DEVICE
) {
2499 iocb_cmd
->ulpCommand
= CMD_FCP_IWRITE64_CR
;
2500 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
2501 iocb_cmd
->un
.fcpi
.fcpi_parm
= 0;
2502 iocb_cmd
->ulpPU
= 0;
2504 iocb_cmd
->ulpPU
= PARM_READ_CHECK
;
2505 fcp_cmnd
->fcpCntl3
= WRITE_DATA
;
2506 phba
->fc4OutputRequests
++;
2508 iocb_cmd
->ulpCommand
= CMD_FCP_IREAD64_CR
;
2509 iocb_cmd
->ulpPU
= PARM_READ_CHECK
;
2510 fcp_cmnd
->fcpCntl3
= READ_DATA
;
2511 phba
->fc4InputRequests
++;
2514 iocb_cmd
->ulpCommand
= CMD_FCP_ICMND64_CR
;
2515 iocb_cmd
->un
.fcpi
.fcpi_parm
= 0;
2516 iocb_cmd
->ulpPU
= 0;
2517 fcp_cmnd
->fcpCntl3
= 0;
2518 phba
->fc4ControlRequests
++;
2520 if (phba
->sli_rev
== 3 &&
2521 !(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
))
2522 lpfc_fcpcmd_to_iocb(iocb_cmd
->unsli3
.fcp_ext
.icd
, fcp_cmnd
);
2524 * Finish initializing those IOCB fields that are independent
2525 * of the scsi_cmnd request_buffer
2527 piocbq
->iocb
.ulpContext
= pnode
->nlp_rpi
;
2528 if (pnode
->nlp_fcp_info
& NLP_FCP_2_DEVICE
)
2529 piocbq
->iocb
.ulpFCP2Rcvy
= 1;
2531 piocbq
->iocb
.ulpFCP2Rcvy
= 0;
2533 piocbq
->iocb
.ulpClass
= (pnode
->nlp_fcp_info
& 0x0f);
2534 piocbq
->context1
= lpfc_cmd
;
2535 piocbq
->iocb_cmpl
= lpfc_scsi_cmd_iocb_cmpl
;
2536 piocbq
->iocb
.ulpTimeout
= lpfc_cmd
->timeout
;
2537 piocbq
->vport
= vport
;
2541 * lpfc_scsi_prep_task_mgmt_cmnd - Convert SLI3 scsi TM cmd to FCP info unit
2542 * @vport: The virtual port for which this call is being executed.
2543 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
2544 * @lun: Logical unit number.
2545 * @task_mgmt_cmd: SCSI task management command.
2547 * This routine creates FCP information unit corresponding to @task_mgmt_cmd
2548 * for device with SLI-3 interface spec.
2555 lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport
*vport
,
2556 struct lpfc_scsi_buf
*lpfc_cmd
,
2558 uint8_t task_mgmt_cmd
)
2560 struct lpfc_iocbq
*piocbq
;
2562 struct fcp_cmnd
*fcp_cmnd
;
2563 struct lpfc_rport_data
*rdata
= lpfc_cmd
->rdata
;
2564 struct lpfc_nodelist
*ndlp
= rdata
->pnode
;
2566 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
) ||
2567 ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
)
2570 piocbq
= &(lpfc_cmd
->cur_iocbq
);
2571 piocbq
->vport
= vport
;
2573 piocb
= &piocbq
->iocb
;
2575 fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
2576 /* Clear out any old data in the FCP command area */
2577 memset(fcp_cmnd
, 0, sizeof(struct fcp_cmnd
));
2578 int_to_scsilun(lun
, &fcp_cmnd
->fcp_lun
);
2579 fcp_cmnd
->fcpCntl2
= task_mgmt_cmd
;
2580 if (vport
->phba
->sli_rev
== 3 &&
2581 !(vport
->phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
))
2582 lpfc_fcpcmd_to_iocb(piocb
->unsli3
.fcp_ext
.icd
, fcp_cmnd
);
2583 piocb
->ulpCommand
= CMD_FCP_ICMND64_CR
;
2584 piocb
->ulpContext
= ndlp
->nlp_rpi
;
2585 if (ndlp
->nlp_fcp_info
& NLP_FCP_2_DEVICE
) {
2586 piocb
->ulpFCP2Rcvy
= 1;
2588 piocb
->ulpClass
= (ndlp
->nlp_fcp_info
& 0x0f);
2590 /* ulpTimeout is only one byte */
2591 if (lpfc_cmd
->timeout
> 0xff) {
2593 * Do not timeout the command at the firmware level.
2594 * The driver will provide the timeout mechanism.
2596 piocb
->ulpTimeout
= 0;
2598 piocb
->ulpTimeout
= lpfc_cmd
->timeout
;
2600 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
)
2601 lpfc_sli4_set_rsp_sgl_last(vport
->phba
, lpfc_cmd
);
2607 * lpfc_scsi_api_table_setup - Set up scsi api fucntion jump table
2608 * @phba: The hba struct for which this call is being executed.
2609 * @dev_grp: The HBA PCI-Device group number.
2611 * This routine sets up the SCSI interface API function jump table in @phba
2613 * Returns: 0 - success, -ENODEV - failure.
2616 lpfc_scsi_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
2619 phba
->lpfc_scsi_unprep_dma_buf
= lpfc_scsi_unprep_dma_buf
;
2620 phba
->lpfc_scsi_prep_cmnd
= lpfc_scsi_prep_cmnd
;
2621 phba
->lpfc_get_scsi_buf
= lpfc_get_scsi_buf
;
2624 case LPFC_PCI_DEV_LP
:
2625 phba
->lpfc_new_scsi_buf
= lpfc_new_scsi_buf_s3
;
2626 phba
->lpfc_scsi_prep_dma_buf
= lpfc_scsi_prep_dma_buf_s3
;
2627 phba
->lpfc_release_scsi_buf
= lpfc_release_scsi_buf_s3
;
2629 case LPFC_PCI_DEV_OC
:
2630 phba
->lpfc_new_scsi_buf
= lpfc_new_scsi_buf_s4
;
2631 phba
->lpfc_scsi_prep_dma_buf
= lpfc_scsi_prep_dma_buf_s4
;
2632 phba
->lpfc_release_scsi_buf
= lpfc_release_scsi_buf_s4
;
2635 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2636 "1418 Invalid HBA PCI-device group: 0x%x\n",
2641 phba
->lpfc_get_scsi_buf
= lpfc_get_scsi_buf
;
2642 phba
->lpfc_rampdown_queue_depth
= lpfc_rampdown_queue_depth
;
2643 phba
->lpfc_scsi_cmd_iocb_cmpl
= lpfc_scsi_cmd_iocb_cmpl
;
2648 * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command
2649 * @phba: The Hba for which this call is being executed.
2650 * @cmdiocbq: Pointer to lpfc_iocbq data structure.
2651 * @rspiocbq: Pointer to lpfc_iocbq data structure.
2653 * This routine is IOCB completion routine for device reset and target reset
2654 * routine. This routine release scsi buffer associated with lpfc_cmd.
2657 lpfc_tskmgmt_def_cmpl(struct lpfc_hba
*phba
,
2658 struct lpfc_iocbq
*cmdiocbq
,
2659 struct lpfc_iocbq
*rspiocbq
)
2661 struct lpfc_scsi_buf
*lpfc_cmd
=
2662 (struct lpfc_scsi_buf
*) cmdiocbq
->context1
;
2664 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
2669 * lpfc_info - Info entry point of scsi_host_template data structure
2670 * @host: The scsi host for which this call is being executed.
2672 * This routine provides module information about hba.
2675 * Pointer to char - Success.
2678 lpfc_info(struct Scsi_Host
*host
)
2680 struct lpfc_vport
*vport
= (struct lpfc_vport
*) host
->hostdata
;
2681 struct lpfc_hba
*phba
= vport
->phba
;
2683 static char lpfcinfobuf
[384];
2685 memset(lpfcinfobuf
,0,384);
2686 if (phba
&& phba
->pcidev
){
2687 strncpy(lpfcinfobuf
, phba
->ModelDesc
, 256);
2688 len
= strlen(lpfcinfobuf
);
2689 snprintf(lpfcinfobuf
+ len
,
2691 " on PCI bus %02x device %02x irq %d",
2692 phba
->pcidev
->bus
->number
,
2693 phba
->pcidev
->devfn
,
2695 len
= strlen(lpfcinfobuf
);
2696 if (phba
->Port
[0]) {
2697 snprintf(lpfcinfobuf
+ len
,
2702 len
= strlen(lpfcinfobuf
);
2703 if (phba
->sli4_hba
.link_state
.logical_speed
) {
2704 snprintf(lpfcinfobuf
+ len
,
2706 " Logical Link Speed: %d Mbps",
2707 phba
->sli4_hba
.link_state
.logical_speed
* 10);
2714 * lpfc_poll_rearm_time - Routine to modify fcp_poll timer of hba
2715 * @phba: The Hba for which this call is being executed.
2717 * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo.
2718 * The default value of cfg_poll_tmo is 10 milliseconds.
2720 static __inline__
void lpfc_poll_rearm_timer(struct lpfc_hba
* phba
)
2722 unsigned long poll_tmo_expires
=
2723 (jiffies
+ msecs_to_jiffies(phba
->cfg_poll_tmo
));
2725 if (phba
->sli
.ring
[LPFC_FCP_RING
].txcmplq_cnt
)
2726 mod_timer(&phba
->fcp_poll_timer
,
2731 * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA
2732 * @phba: The Hba for which this call is being executed.
2734 * This routine starts the fcp_poll_timer of @phba.
2736 void lpfc_poll_start_timer(struct lpfc_hba
* phba
)
2738 lpfc_poll_rearm_timer(phba
);
2742 * lpfc_poll_timeout - Restart polling timer
2743 * @ptr: Map to lpfc_hba data structure pointer.
2745 * This routine restarts fcp_poll timer, when FCP ring polling is enable
2746 * and FCP Ring interrupt is disable.
2749 void lpfc_poll_timeout(unsigned long ptr
)
2751 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
2753 if (phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) {
2754 lpfc_sli_handle_fast_ring_event(phba
,
2755 &phba
->sli
.ring
[LPFC_FCP_RING
], HA_R0RE_REQ
);
2757 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
)
2758 lpfc_poll_rearm_timer(phba
);
2763 * lpfc_queuecommand - scsi_host_template queuecommand entry point
2764 * @cmnd: Pointer to scsi_cmnd data structure.
2765 * @done: Pointer to done routine.
2767 * Driver registers this routine to scsi midlayer to submit a @cmd to process.
2768 * This routine prepares an IOCB from scsi command and provides to firmware.
2769 * The @done callback is invoked after driver finished processing the command.
2773 * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily.
2776 lpfc_queuecommand(struct scsi_cmnd
*cmnd
, void (*done
) (struct scsi_cmnd
*))
2778 struct Scsi_Host
*shost
= cmnd
->device
->host
;
2779 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2780 struct lpfc_hba
*phba
= vport
->phba
;
2781 struct lpfc_rport_data
*rdata
= cmnd
->device
->hostdata
;
2782 struct lpfc_nodelist
*ndlp
;
2783 struct lpfc_scsi_buf
*lpfc_cmd
;
2784 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmnd
->device
));
2787 err
= fc_remote_port_chkready(rport
);
2790 goto out_fail_command
;
2792 ndlp
= rdata
->pnode
;
2794 if (!(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
) &&
2795 scsi_get_prot_op(cmnd
) != SCSI_PROT_NORMAL
) {
2797 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2798 "9058 BLKGRD: ERROR: rcvd protected cmd:%02x"
2799 " op:%02x str=%s without registering for"
2800 " BlockGuard - Rejecting command\n",
2801 cmnd
->cmnd
[0], scsi_get_prot_op(cmnd
),
2802 dif_op_str
[scsi_get_prot_op(cmnd
)]);
2803 goto out_fail_command
;
2807 * Catch race where our node has transitioned, but the
2808 * transport is still transitioning.
2810 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
2811 cmnd
->result
= ScsiResult(DID_TRANSPORT_DISRUPTED
, 0);
2812 goto out_fail_command
;
2814 if (vport
->cfg_max_scsicmpl_time
&&
2815 (atomic_read(&ndlp
->cmd_pending
) >= ndlp
->cmd_qdepth
))
2818 lpfc_cmd
= lpfc_get_scsi_buf(phba
);
2819 if (lpfc_cmd
== NULL
) {
2820 lpfc_rampdown_queue_depth(phba
);
2822 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
2823 "0707 driver's buffer pool is empty, "
2829 * Store the midlayer's command structure for the completion phase
2830 * and complete the command initialization.
2832 lpfc_cmd
->pCmd
= cmnd
;
2833 lpfc_cmd
->rdata
= rdata
;
2834 lpfc_cmd
->timeout
= 0;
2835 lpfc_cmd
->start_time
= jiffies
;
2836 cmnd
->host_scribble
= (unsigned char *)lpfc_cmd
;
2837 cmnd
->scsi_done
= done
;
2839 if (scsi_get_prot_op(cmnd
) != SCSI_PROT_NORMAL
) {
2840 if (vport
->phba
->cfg_enable_bg
) {
2841 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_BG
,
2842 "9033 BLKGRD: rcvd protected cmd:%02x op:%02x "
2844 cmnd
->cmnd
[0], scsi_get_prot_op(cmnd
),
2845 dif_op_str
[scsi_get_prot_op(cmnd
)]);
2846 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_BG
,
2847 "9034 BLKGRD: CDB: %02x %02x %02x %02x %02x "
2848 "%02x %02x %02x %02x %02x\n",
2849 cmnd
->cmnd
[0], cmnd
->cmnd
[1], cmnd
->cmnd
[2],
2850 cmnd
->cmnd
[3], cmnd
->cmnd
[4], cmnd
->cmnd
[5],
2851 cmnd
->cmnd
[6], cmnd
->cmnd
[7], cmnd
->cmnd
[8],
2853 if (cmnd
->cmnd
[0] == READ_10
)
2854 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_BG
,
2855 "9035 BLKGRD: READ @ sector %llu, "
2857 (unsigned long long)scsi_get_lba(cmnd
),
2858 blk_rq_sectors(cmnd
->request
));
2859 else if (cmnd
->cmnd
[0] == WRITE_10
)
2860 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_BG
,
2861 "9036 BLKGRD: WRITE @ sector %llu, "
2862 "count %u cmd=%p\n",
2863 (unsigned long long)scsi_get_lba(cmnd
),
2864 blk_rq_sectors(cmnd
->request
),
2868 err
= lpfc_bg_scsi_prep_dma_buf(phba
, lpfc_cmd
);
2870 if (vport
->phba
->cfg_enable_bg
) {
2871 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_BG
,
2872 "9038 BLKGRD: rcvd unprotected cmd:"
2873 "%02x op:%02x str=%s\n",
2874 cmnd
->cmnd
[0], scsi_get_prot_op(cmnd
),
2875 dif_op_str
[scsi_get_prot_op(cmnd
)]);
2876 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_BG
,
2877 "9039 BLKGRD: CDB: %02x %02x %02x "
2878 "%02x %02x %02x %02x %02x %02x %02x\n",
2879 cmnd
->cmnd
[0], cmnd
->cmnd
[1],
2880 cmnd
->cmnd
[2], cmnd
->cmnd
[3],
2881 cmnd
->cmnd
[4], cmnd
->cmnd
[5],
2882 cmnd
->cmnd
[6], cmnd
->cmnd
[7],
2883 cmnd
->cmnd
[8], cmnd
->cmnd
[9]);
2884 if (cmnd
->cmnd
[0] == READ_10
)
2885 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_BG
,
2886 "9040 dbg: READ @ sector %llu, "
2888 (unsigned long long)scsi_get_lba(cmnd
),
2889 blk_rq_sectors(cmnd
->request
));
2890 else if (cmnd
->cmnd
[0] == WRITE_10
)
2891 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_BG
,
2892 "9041 dbg: WRITE @ sector %llu, "
2893 "count %u cmd=%p\n",
2894 (unsigned long long)scsi_get_lba(cmnd
),
2895 blk_rq_sectors(cmnd
->request
), cmnd
);
2897 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_BG
,
2898 "9042 dbg: parser not implemented\n");
2900 err
= lpfc_scsi_prep_dma_buf(phba
, lpfc_cmd
);
2904 goto out_host_busy_free_buf
;
2906 lpfc_scsi_prep_cmnd(vport
, lpfc_cmd
, ndlp
);
2908 atomic_inc(&ndlp
->cmd_pending
);
2909 err
= lpfc_sli_issue_iocb(phba
, LPFC_FCP_RING
,
2910 &lpfc_cmd
->cur_iocbq
, SLI_IOCB_RET_IOCB
);
2912 atomic_dec(&ndlp
->cmd_pending
);
2913 goto out_host_busy_free_buf
;
2915 if (phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) {
2916 spin_unlock(shost
->host_lock
);
2917 lpfc_sli_handle_fast_ring_event(phba
,
2918 &phba
->sli
.ring
[LPFC_FCP_RING
], HA_R0RE_REQ
);
2920 spin_lock(shost
->host_lock
);
2921 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
)
2922 lpfc_poll_rearm_timer(phba
);
2927 out_host_busy_free_buf
:
2928 lpfc_scsi_unprep_dma_buf(phba
, lpfc_cmd
);
2929 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
2931 return SCSI_MLQUEUE_HOST_BUSY
;
2939 * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point
2940 * @cmnd: Pointer to scsi_cmnd data structure.
2942 * This routine aborts @cmnd pending in base driver.
2949 lpfc_abort_handler(struct scsi_cmnd
*cmnd
)
2951 struct Scsi_Host
*shost
= cmnd
->device
->host
;
2952 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2953 struct lpfc_hba
*phba
= vport
->phba
;
2954 struct lpfc_iocbq
*iocb
;
2955 struct lpfc_iocbq
*abtsiocb
;
2956 struct lpfc_scsi_buf
*lpfc_cmd
;
2959 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq
);
2961 fc_block_scsi_eh(cmnd
);
2962 lpfc_cmd
= (struct lpfc_scsi_buf
*)cmnd
->host_scribble
;
2966 * If pCmd field of the corresponding lpfc_scsi_buf structure
2967 * points to a different SCSI command, then the driver has
2968 * already completed this command, but the midlayer did not
2969 * see the completion before the eh fired. Just return
2972 iocb
= &lpfc_cmd
->cur_iocbq
;
2973 if (lpfc_cmd
->pCmd
!= cmnd
)
2976 BUG_ON(iocb
->context1
!= lpfc_cmd
);
2978 abtsiocb
= lpfc_sli_get_iocbq(phba
);
2979 if (abtsiocb
== NULL
) {
2985 * The scsi command can not be in txq and it is in flight because the
2986 * pCmd is still pointig at the SCSI command we have to abort. There
2987 * is no need to search the txcmplq. Just send an abort to the FW.
2991 icmd
= &abtsiocb
->iocb
;
2992 icmd
->un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
2993 icmd
->un
.acxri
.abortContextTag
= cmd
->ulpContext
;
2994 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2995 icmd
->un
.acxri
.abortIoTag
= iocb
->sli4_xritag
;
2997 icmd
->un
.acxri
.abortIoTag
= cmd
->ulpIoTag
;
3000 icmd
->ulpClass
= cmd
->ulpClass
;
3002 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
3003 abtsiocb
->fcp_wqidx
= iocb
->fcp_wqidx
;
3004 abtsiocb
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
3006 if (lpfc_is_link_up(phba
))
3007 icmd
->ulpCommand
= CMD_ABORT_XRI_CN
;
3009 icmd
->ulpCommand
= CMD_CLOSE_XRI_CN
;
3011 abtsiocb
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
3012 abtsiocb
->vport
= vport
;
3013 if (lpfc_sli_issue_iocb(phba
, LPFC_FCP_RING
, abtsiocb
, 0) ==
3015 lpfc_sli_release_iocbq(phba
, abtsiocb
);
3020 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
)
3021 lpfc_sli_handle_fast_ring_event(phba
,
3022 &phba
->sli
.ring
[LPFC_FCP_RING
], HA_R0RE_REQ
);
3024 lpfc_cmd
->waitq
= &waitq
;
3025 /* Wait for abort to complete */
3026 wait_event_timeout(waitq
,
3027 (lpfc_cmd
->pCmd
!= cmnd
),
3028 (2*vport
->cfg_devloss_tmo
*HZ
));
3030 spin_lock_irq(shost
->host_lock
);
3031 lpfc_cmd
->waitq
= NULL
;
3032 spin_unlock_irq(shost
->host_lock
);
3034 if (lpfc_cmd
->pCmd
== cmnd
) {
3036 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
3037 "0748 abort handler timed out waiting "
3038 "for abort to complete: ret %#x, ID %d, "
3039 "LUN %d, snum %#lx\n",
3040 ret
, cmnd
->device
->id
, cmnd
->device
->lun
,
3041 cmnd
->serial_number
);
3045 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
3046 "0749 SCSI Layer I/O Abort Request Status x%x ID %d "
3047 "LUN %d snum %#lx\n", ret
, cmnd
->device
->id
,
3048 cmnd
->device
->lun
, cmnd
->serial_number
);
3053 lpfc_taskmgmt_name(uint8_t task_mgmt_cmd
)
3055 switch (task_mgmt_cmd
) {
3056 case FCP_ABORT_TASK_SET
:
3057 return "ABORT_TASK_SET";
3058 case FCP_CLEAR_TASK_SET
:
3059 return "FCP_CLEAR_TASK_SET";
3061 return "FCP_BUS_RESET";
3063 return "FCP_LUN_RESET";
3064 case FCP_TARGET_RESET
:
3065 return "FCP_TARGET_RESET";
3067 return "FCP_CLEAR_ACA";
3068 case FCP_TERMINATE_TASK
:
3069 return "FCP_TERMINATE_TASK";
3076 * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler
3077 * @vport: The virtual port for which this call is being executed.
3078 * @rdata: Pointer to remote port local data
3079 * @tgt_id: Target ID of remote device.
3080 * @lun_id: Lun number for the TMF
3081 * @task_mgmt_cmd: type of TMF to send
3083 * This routine builds and sends a TMF (SCSI Task Mgmt Function) to
3091 lpfc_send_taskmgmt(struct lpfc_vport
*vport
, struct lpfc_rport_data
*rdata
,
3092 unsigned tgt_id
, unsigned int lun_id
,
3093 uint8_t task_mgmt_cmd
)
3095 struct lpfc_hba
*phba
= vport
->phba
;
3096 struct lpfc_scsi_buf
*lpfc_cmd
;
3097 struct lpfc_iocbq
*iocbq
;
3098 struct lpfc_iocbq
*iocbqrsp
;
3102 if (!rdata
->pnode
|| !NLP_CHK_NODE_ACT(rdata
->pnode
))
3105 lpfc_cmd
= lpfc_get_scsi_buf(phba
);
3106 if (lpfc_cmd
== NULL
)
3108 lpfc_cmd
->timeout
= 60;
3109 lpfc_cmd
->rdata
= rdata
;
3111 status
= lpfc_scsi_prep_task_mgmt_cmd(vport
, lpfc_cmd
, lun_id
,
3114 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
3118 iocbq
= &lpfc_cmd
->cur_iocbq
;
3119 iocbqrsp
= lpfc_sli_get_iocbq(phba
);
3120 if (iocbqrsp
== NULL
) {
3121 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
3125 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
3126 "0702 Issue %s to TGT %d LUN %d "
3127 "rpi x%x nlp_flag x%x\n",
3128 lpfc_taskmgmt_name(task_mgmt_cmd
), tgt_id
, lun_id
,
3129 rdata
->pnode
->nlp_rpi
, rdata
->pnode
->nlp_flag
);
3131 status
= lpfc_sli_issue_iocb_wait(phba
, LPFC_FCP_RING
,
3132 iocbq
, iocbqrsp
, lpfc_cmd
->timeout
);
3133 if (status
!= IOCB_SUCCESS
) {
3134 if (status
== IOCB_TIMEDOUT
) {
3135 iocbq
->iocb_cmpl
= lpfc_tskmgmt_def_cmpl
;
3136 ret
= TIMEOUT_ERROR
;
3139 lpfc_cmd
->status
= IOSTAT_DRIVER_REJECT
;
3140 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
3141 "0727 TMF %s to TGT %d LUN %d failed (%d, %d)\n",
3142 lpfc_taskmgmt_name(task_mgmt_cmd
),
3143 tgt_id
, lun_id
, iocbqrsp
->iocb
.ulpStatus
,
3144 iocbqrsp
->iocb
.un
.ulpWord
[4]);
3148 lpfc_sli_release_iocbq(phba
, iocbqrsp
);
3150 if (ret
!= TIMEOUT_ERROR
)
3151 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
3157 * lpfc_chk_tgt_mapped -
3158 * @vport: The virtual port to check on
3159 * @cmnd: Pointer to scsi_cmnd data structure.
3161 * This routine delays until the scsi target (aka rport) for the
3162 * command exists (is present and logged in) or we declare it non-existent.
3169 lpfc_chk_tgt_mapped(struct lpfc_vport
*vport
, struct scsi_cmnd
*cmnd
)
3171 struct lpfc_rport_data
*rdata
= cmnd
->device
->hostdata
;
3172 struct lpfc_nodelist
*pnode
;
3173 unsigned long later
;
3176 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
3177 "0797 Tgt Map rport failure: rdata x%p\n", rdata
);
3180 pnode
= rdata
->pnode
;
3182 * If target is not in a MAPPED state, delay until
3183 * target is rediscovered or devloss timeout expires.
3185 later
= msecs_to_jiffies(2 * vport
->cfg_devloss_tmo
* 1000) + jiffies
;
3186 while (time_after(later
, jiffies
)) {
3187 if (!pnode
|| !NLP_CHK_NODE_ACT(pnode
))
3189 if (pnode
->nlp_state
== NLP_STE_MAPPED_NODE
)
3191 schedule_timeout_uninterruptible(msecs_to_jiffies(500));
3192 rdata
= cmnd
->device
->hostdata
;
3195 pnode
= rdata
->pnode
;
3197 if (!pnode
|| !NLP_CHK_NODE_ACT(pnode
) ||
3198 (pnode
->nlp_state
!= NLP_STE_MAPPED_NODE
))
3204 * lpfc_reset_flush_io_context -
3205 * @vport: The virtual port (scsi_host) for the flush context
3206 * @tgt_id: If aborting by Target contect - specifies the target id
3207 * @lun_id: If aborting by Lun context - specifies the lun id
3208 * @context: specifies the context level to flush at.
3210 * After a reset condition via TMF, we need to flush orphaned i/o
3211 * contexts from the adapter. This routine aborts any contexts
3212 * outstanding, then waits for their completions. The wait is
3213 * bounded by devloss_tmo though.
3220 lpfc_reset_flush_io_context(struct lpfc_vport
*vport
, uint16_t tgt_id
,
3221 uint64_t lun_id
, lpfc_ctx_cmd context
)
3223 struct lpfc_hba
*phba
= vport
->phba
;
3224 unsigned long later
;
3227 cnt
= lpfc_sli_sum_iocb(vport
, tgt_id
, lun_id
, context
);
3229 lpfc_sli_abort_iocb(vport
, &phba
->sli
.ring
[phba
->sli
.fcp_ring
],
3230 tgt_id
, lun_id
, context
);
3231 later
= msecs_to_jiffies(2 * vport
->cfg_devloss_tmo
* 1000) + jiffies
;
3232 while (time_after(later
, jiffies
) && cnt
) {
3233 schedule_timeout_uninterruptible(msecs_to_jiffies(20));
3234 cnt
= lpfc_sli_sum_iocb(vport
, tgt_id
, lun_id
, context
);
3237 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
3238 "0724 I/O flush failure for context %s : cnt x%x\n",
3239 ((context
== LPFC_CTX_LUN
) ? "LUN" :
3240 ((context
== LPFC_CTX_TGT
) ? "TGT" :
3241 ((context
== LPFC_CTX_HOST
) ? "HOST" : "Unknown"))),
3249 * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point
3250 * @cmnd: Pointer to scsi_cmnd data structure.
3252 * This routine does a device reset by sending a LUN_RESET task management
3260 lpfc_device_reset_handler(struct scsi_cmnd
*cmnd
)
3262 struct Scsi_Host
*shost
= cmnd
->device
->host
;
3263 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3264 struct lpfc_rport_data
*rdata
= cmnd
->device
->hostdata
;
3265 struct lpfc_nodelist
*pnode
;
3266 unsigned tgt_id
= cmnd
->device
->id
;
3267 unsigned int lun_id
= cmnd
->device
->lun
;
3268 struct lpfc_scsi_event_header scsi_event
;
3272 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
3273 "0798 Device Reset rport failure: rdata x%p\n", rdata
);
3276 pnode
= rdata
->pnode
;
3277 fc_block_scsi_eh(cmnd
);
3279 status
= lpfc_chk_tgt_mapped(vport
, cmnd
);
3280 if (status
== FAILED
) {
3281 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
3282 "0721 Device Reset rport failure: rdata x%p\n", rdata
);
3286 scsi_event
.event_type
= FC_REG_SCSI_EVENT
;
3287 scsi_event
.subcategory
= LPFC_EVENT_LUNRESET
;
3288 scsi_event
.lun
= lun_id
;
3289 memcpy(scsi_event
.wwpn
, &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
3290 memcpy(scsi_event
.wwnn
, &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
3292 fc_host_post_vendor_event(shost
, fc_get_event_number(),
3293 sizeof(scsi_event
), (char *)&scsi_event
, LPFC_NL_VENDOR_ID
);
3295 status
= lpfc_send_taskmgmt(vport
, rdata
, tgt_id
, lun_id
,
3298 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
3299 "0713 SCSI layer issued Device Reset (%d, %d) "
3300 "return x%x\n", tgt_id
, lun_id
, status
);
3303 * We have to clean up i/o as : they may be orphaned by the TMF;
3304 * or if the TMF failed, they may be in an indeterminate state.
3306 * We will report success if all the i/o aborts successfully.
3308 status
= lpfc_reset_flush_io_context(vport
, tgt_id
, lun_id
,
3314 * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point
3315 * @cmnd: Pointer to scsi_cmnd data structure.
3317 * This routine does a target reset by sending a TARGET_RESET task management
3325 lpfc_target_reset_handler(struct scsi_cmnd
*cmnd
)
3327 struct Scsi_Host
*shost
= cmnd
->device
->host
;
3328 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3329 struct lpfc_rport_data
*rdata
= cmnd
->device
->hostdata
;
3330 struct lpfc_nodelist
*pnode
;
3331 unsigned tgt_id
= cmnd
->device
->id
;
3332 unsigned int lun_id
= cmnd
->device
->lun
;
3333 struct lpfc_scsi_event_header scsi_event
;
3337 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
3338 "0799 Target Reset rport failure: rdata x%p\n", rdata
);
3341 pnode
= rdata
->pnode
;
3342 fc_block_scsi_eh(cmnd
);
3344 status
= lpfc_chk_tgt_mapped(vport
, cmnd
);
3345 if (status
== FAILED
) {
3346 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
3347 "0722 Target Reset rport failure: rdata x%p\n", rdata
);
3351 scsi_event
.event_type
= FC_REG_SCSI_EVENT
;
3352 scsi_event
.subcategory
= LPFC_EVENT_TGTRESET
;
3354 memcpy(scsi_event
.wwpn
, &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
3355 memcpy(scsi_event
.wwnn
, &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
3357 fc_host_post_vendor_event(shost
, fc_get_event_number(),
3358 sizeof(scsi_event
), (char *)&scsi_event
, LPFC_NL_VENDOR_ID
);
3360 status
= lpfc_send_taskmgmt(vport
, rdata
, tgt_id
, lun_id
,
3363 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
3364 "0723 SCSI layer issued Target Reset (%d, %d) "
3365 "return x%x\n", tgt_id
, lun_id
, status
);
3368 * We have to clean up i/o as : they may be orphaned by the TMF;
3369 * or if the TMF failed, they may be in an indeterminate state.
3371 * We will report success if all the i/o aborts successfully.
3373 status
= lpfc_reset_flush_io_context(vport
, tgt_id
, lun_id
,
3379 * lpfc_bus_reset_handler - scsi_host_template eh_bus_reset_handler entry point
3380 * @cmnd: Pointer to scsi_cmnd data structure.
3382 * This routine does target reset to all targets on @cmnd->device->host.
3383 * This emulates Parallel SCSI Bus Reset Semantics.
3390 lpfc_bus_reset_handler(struct scsi_cmnd
*cmnd
)
3392 struct Scsi_Host
*shost
= cmnd
->device
->host
;
3393 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3394 struct lpfc_nodelist
*ndlp
= NULL
;
3395 struct lpfc_scsi_event_header scsi_event
;
3397 int ret
= SUCCESS
, status
, i
;
3399 scsi_event
.event_type
= FC_REG_SCSI_EVENT
;
3400 scsi_event
.subcategory
= LPFC_EVENT_BUSRESET
;
3402 memcpy(scsi_event
.wwpn
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
3403 memcpy(scsi_event
.wwnn
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
3405 fc_host_post_vendor_event(shost
, fc_get_event_number(),
3406 sizeof(scsi_event
), (char *)&scsi_event
, LPFC_NL_VENDOR_ID
);
3408 fc_block_scsi_eh(cmnd
);
3411 * Since the driver manages a single bus device, reset all
3412 * targets known to the driver. Should any target reset
3413 * fail, this routine returns failure to the midlayer.
3415 for (i
= 0; i
< LPFC_MAX_TARGET
; i
++) {
3416 /* Search for mapped node by target ID */
3418 spin_lock_irq(shost
->host_lock
);
3419 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
3420 if (!NLP_CHK_NODE_ACT(ndlp
))
3422 if (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
&&
3423 ndlp
->nlp_sid
== i
&&
3429 spin_unlock_irq(shost
->host_lock
);
3433 status
= lpfc_send_taskmgmt(vport
, ndlp
->rport
->dd_data
,
3434 i
, 0, FCP_TARGET_RESET
);
3436 if (status
!= SUCCESS
) {
3437 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
3438 "0700 Bus Reset on target %d failed\n",
3444 * We have to clean up i/o as : they may be orphaned by the TMFs
3445 * above; or if any of the TMFs failed, they may be in an
3446 * indeterminate state.
3447 * We will report success if all the i/o aborts successfully.
3450 status
= lpfc_reset_flush_io_context(vport
, 0, 0, LPFC_CTX_HOST
);
3451 if (status
!= SUCCESS
)
3454 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
3455 "0714 SCSI layer issued Bus Reset Data: x%x\n", ret
);
3460 * lpfc_slave_alloc - scsi_host_template slave_alloc entry point
3461 * @sdev: Pointer to scsi_device.
3463 * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's
3464 * globally available list of scsi buffers. This routine also makes sure scsi
3465 * buffer is not allocated more than HBA limit conveyed to midlayer. This list
3466 * of scsi buffer exists for the lifetime of the driver.
3473 lpfc_slave_alloc(struct scsi_device
*sdev
)
3475 struct lpfc_vport
*vport
= (struct lpfc_vport
*) sdev
->host
->hostdata
;
3476 struct lpfc_hba
*phba
= vport
->phba
;
3477 struct fc_rport
*rport
= starget_to_rport(scsi_target(sdev
));
3479 uint32_t num_to_alloc
= 0;
3480 int num_allocated
= 0;
3482 if (!rport
|| fc_remote_port_chkready(rport
))
3485 sdev
->hostdata
= rport
->dd_data
;
3488 * Populate the cmds_per_lun count scsi_bufs into this host's globally
3489 * available list of scsi buffers. Don't allocate more than the
3490 * HBA limit conveyed to the midlayer via the host structure. The
3491 * formula accounts for the lun_queue_depth + error handlers + 1
3492 * extra. This list of scsi bufs exists for the lifetime of the driver.
3494 total
= phba
->total_scsi_bufs
;
3495 num_to_alloc
= vport
->cfg_lun_queue_depth
+ 2;
3497 /* Allow some exchanges to be available always to complete discovery */
3498 if (total
>= phba
->cfg_hba_queue_depth
- LPFC_DISC_IOCB_BUFF_COUNT
) {
3499 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
3500 "0704 At limitation of %d preallocated "
3501 "command buffers\n", total
);
3503 /* Allow some exchanges to be available always to complete discovery */
3504 } else if (total
+ num_to_alloc
>
3505 phba
->cfg_hba_queue_depth
- LPFC_DISC_IOCB_BUFF_COUNT
) {
3506 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
3507 "0705 Allocation request of %d "
3508 "command buffers will exceed max of %d. "
3509 "Reducing allocation request to %d.\n",
3510 num_to_alloc
, phba
->cfg_hba_queue_depth
,
3511 (phba
->cfg_hba_queue_depth
- total
));
3512 num_to_alloc
= phba
->cfg_hba_queue_depth
- total
;
3514 num_allocated
= lpfc_new_scsi_buf(vport
, num_to_alloc
);
3515 if (num_to_alloc
!= num_allocated
) {
3516 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
3517 "0708 Allocation request of %d "
3518 "command buffers did not succeed. "
3519 "Allocated %d buffers.\n",
3520 num_to_alloc
, num_allocated
);
3522 if (num_allocated
> 0)
3523 phba
->total_scsi_bufs
+= num_allocated
;
3528 * lpfc_slave_configure - scsi_host_template slave_configure entry point
3529 * @sdev: Pointer to scsi_device.
3531 * This routine configures following items
3532 * - Tag command queuing support for @sdev if supported.
3533 * - Dev loss time out value of fc_rport.
3534 * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set.
3540 lpfc_slave_configure(struct scsi_device
*sdev
)
3542 struct lpfc_vport
*vport
= (struct lpfc_vport
*) sdev
->host
->hostdata
;
3543 struct lpfc_hba
*phba
= vport
->phba
;
3544 struct fc_rport
*rport
= starget_to_rport(sdev
->sdev_target
);
3546 if (sdev
->tagged_supported
)
3547 scsi_activate_tcq(sdev
, vport
->cfg_lun_queue_depth
);
3549 scsi_deactivate_tcq(sdev
, vport
->cfg_lun_queue_depth
);
3552 * Initialize the fc transport attributes for the target
3553 * containing this scsi device. Also note that the driver's
3554 * target pointer is stored in the starget_data for the
3555 * driver's sysfs entry point functions.
3557 rport
->dev_loss_tmo
= vport
->cfg_devloss_tmo
;
3559 if (phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) {
3560 lpfc_sli_handle_fast_ring_event(phba
,
3561 &phba
->sli
.ring
[LPFC_FCP_RING
], HA_R0RE_REQ
);
3562 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
)
3563 lpfc_poll_rearm_timer(phba
);
3570 * lpfc_slave_destroy - slave_destroy entry point of SHT data structure
3571 * @sdev: Pointer to scsi_device.
3573 * This routine sets @sdev hostatdata filed to null.
3576 lpfc_slave_destroy(struct scsi_device
*sdev
)
3578 sdev
->hostdata
= NULL
;
3583 struct scsi_host_template lpfc_template
= {
3584 .module
= THIS_MODULE
,
3585 .name
= LPFC_DRIVER_NAME
,
3587 .queuecommand
= lpfc_queuecommand
,
3588 .eh_abort_handler
= lpfc_abort_handler
,
3589 .eh_device_reset_handler
= lpfc_device_reset_handler
,
3590 .eh_target_reset_handler
= lpfc_target_reset_handler
,
3591 .eh_bus_reset_handler
= lpfc_bus_reset_handler
,
3592 .slave_alloc
= lpfc_slave_alloc
,
3593 .slave_configure
= lpfc_slave_configure
,
3594 .slave_destroy
= lpfc_slave_destroy
,
3595 .scan_finished
= lpfc_scan_finished
,
3597 .sg_tablesize
= LPFC_DEFAULT_SG_SEG_CNT
,
3598 .cmd_per_lun
= LPFC_CMD_PER_LUN
,
3599 .use_clustering
= ENABLE_CLUSTERING
,
3600 .shost_attrs
= lpfc_hba_attrs
,
3601 .max_sectors
= 0xFFFF,
3602 .vendor_id
= LPFC_NL_VENDOR_ID
,
3603 .change_queue_depth
= lpfc_change_queue_depth
,
3606 struct scsi_host_template lpfc_vport_template
= {
3607 .module
= THIS_MODULE
,
3608 .name
= LPFC_DRIVER_NAME
,
3610 .queuecommand
= lpfc_queuecommand
,
3611 .eh_abort_handler
= lpfc_abort_handler
,
3612 .eh_device_reset_handler
= lpfc_device_reset_handler
,
3613 .eh_target_reset_handler
= lpfc_target_reset_handler
,
3614 .eh_bus_reset_handler
= lpfc_bus_reset_handler
,
3615 .slave_alloc
= lpfc_slave_alloc
,
3616 .slave_configure
= lpfc_slave_configure
,
3617 .slave_destroy
= lpfc_slave_destroy
,
3618 .scan_finished
= lpfc_scan_finished
,
3620 .sg_tablesize
= LPFC_DEFAULT_SG_SEG_CNT
,
3621 .cmd_per_lun
= LPFC_CMD_PER_LUN
,
3622 .use_clustering
= ENABLE_CLUSTERING
,
3623 .shost_attrs
= lpfc_vport_attrs
,
3624 .max_sectors
= 0xFFFF,
3625 .change_queue_depth
= lpfc_change_queue_depth
,