1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
23 #include <linux/pci.h>
24 #include <linux/slab.h>
25 #include <linux/interrupt.h>
26 #include <linux/export.h>
27 #include <linux/delay.h>
28 #include <asm/unaligned.h>
29 #include <linux/t10-pi.h>
30 #include <linux/crc-t10dif.h>
31 #include <net/checksum.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_eh.h>
36 #include <scsi/scsi_host.h>
37 #include <scsi/scsi_tcq.h>
38 #include <scsi/scsi_transport_fc.h>
40 #include "lpfc_version.h"
44 #include "lpfc_sli4.h"
46 #include "lpfc_disc.h"
48 #include "lpfc_scsi.h"
49 #include "lpfc_logmsg.h"
50 #include "lpfc_crtn.h"
51 #include "lpfc_vport.h"
53 #define LPFC_RESET_WAIT 2
54 #define LPFC_ABORT_WAIT 2
56 int _dump_buf_done
= 1;
58 static char *dif_op_str
[] = {
68 struct scsi_dif_tuple
{
69 __be16 guard_tag
; /* Checksum */
70 __be16 app_tag
; /* Opaque storage */
71 __be32 ref_tag
; /* Target LBA or indirect LBA */
74 static struct lpfc_rport_data
*
75 lpfc_rport_data_from_scsi_device(struct scsi_device
*sdev
)
77 struct lpfc_vport
*vport
= (struct lpfc_vport
*)sdev
->host
->hostdata
;
79 if (vport
->phba
->cfg_fof
)
80 return ((struct lpfc_device_data
*)sdev
->hostdata
)->rport_data
;
82 return (struct lpfc_rport_data
*)sdev
->hostdata
;
86 lpfc_release_scsi_buf_s4(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
);
88 lpfc_release_scsi_buf_s3(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
);
90 lpfc_prot_group_type(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
);
93 lpfc_debug_save_data(struct lpfc_hba
*phba
, struct scsi_cmnd
*cmnd
)
96 struct scatterlist
*sgde
= scsi_sglist(cmnd
);
98 if (!_dump_buf_data
) {
99 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
100 "9050 BLKGRD: ERROR %s _dump_buf_data is NULL\n",
107 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
108 "9051 BLKGRD: ERROR: data scatterlist is null\n");
112 dst
= (void *) _dump_buf_data
;
115 memcpy(dst
, src
, sgde
->length
);
117 sgde
= sg_next(sgde
);
122 lpfc_debug_save_dif(struct lpfc_hba
*phba
, struct scsi_cmnd
*cmnd
)
125 struct scatterlist
*sgde
= scsi_prot_sglist(cmnd
);
127 if (!_dump_buf_dif
) {
128 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
129 "9052 BLKGRD: ERROR %s _dump_buf_data is NULL\n",
135 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
136 "9053 BLKGRD: ERROR: prot scatterlist is null\n");
143 memcpy(dst
, src
, sgde
->length
);
145 sgde
= sg_next(sgde
);
149 static inline unsigned
150 lpfc_cmd_blksize(struct scsi_cmnd
*sc
)
152 return sc
->device
->sector_size
;
155 #define LPFC_CHECK_PROTECT_GUARD 1
156 #define LPFC_CHECK_PROTECT_REF 2
157 static inline unsigned
158 lpfc_cmd_protect(struct scsi_cmnd
*sc
, int flag
)
163 static inline unsigned
164 lpfc_cmd_guard_csum(struct scsi_cmnd
*sc
)
166 if (lpfc_prot_group_type(NULL
, sc
) == LPFC_PG_TYPE_NO_DIF
)
168 if (scsi_host_get_guard(sc
->device
->host
) == SHOST_DIX_GUARD_IP
)
174 * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge.
175 * @phba: Pointer to HBA object.
176 * @lpfc_cmd: lpfc scsi command object pointer.
178 * This function is called from the lpfc_prep_task_mgmt_cmd function to
179 * set the last bit in the response sge entry.
182 lpfc_sli4_set_rsp_sgl_last(struct lpfc_hba
*phba
,
183 struct lpfc_scsi_buf
*lpfc_cmd
)
185 struct sli4_sge
*sgl
= (struct sli4_sge
*)lpfc_cmd
->fcp_bpl
;
188 sgl
->word2
= le32_to_cpu(sgl
->word2
);
189 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
190 sgl
->word2
= cpu_to_le32(sgl
->word2
);
195 * lpfc_update_stats - Update statistical data for the command completion
196 * @phba: Pointer to HBA object.
197 * @lpfc_cmd: lpfc scsi command object pointer.
199 * This function is called when there is a command completion and this
200 * function updates the statistical data for the command completion.
203 lpfc_update_stats(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
)
205 struct lpfc_rport_data
*rdata
= lpfc_cmd
->rdata
;
206 struct lpfc_nodelist
*pnode
= rdata
->pnode
;
207 struct scsi_cmnd
*cmd
= lpfc_cmd
->pCmd
;
209 struct Scsi_Host
*shost
= cmd
->device
->host
;
210 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
211 unsigned long latency
;
217 latency
= jiffies_to_msecs((long)jiffies
- (long)lpfc_cmd
->start_time
);
219 spin_lock_irqsave(shost
->host_lock
, flags
);
220 if (!vport
->stat_data_enabled
||
221 vport
->stat_data_blocked
||
224 (phba
->bucket_type
== LPFC_NO_BUCKET
)) {
225 spin_unlock_irqrestore(shost
->host_lock
, flags
);
229 if (phba
->bucket_type
== LPFC_LINEAR_BUCKET
) {
230 i
= (latency
+ phba
->bucket_step
- 1 - phba
->bucket_base
)/
232 /* check array subscript bounds */
235 else if (i
>= LPFC_MAX_BUCKET_COUNT
)
236 i
= LPFC_MAX_BUCKET_COUNT
- 1;
238 for (i
= 0; i
< LPFC_MAX_BUCKET_COUNT
-1; i
++)
239 if (latency
<= (phba
->bucket_base
+
240 ((1<<i
)*phba
->bucket_step
)))
244 pnode
->lat_data
[i
].cmd_count
++;
245 spin_unlock_irqrestore(shost
->host_lock
, flags
);
249 * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread
250 * @phba: The Hba for which this call is being executed.
252 * This routine is called when there is resource error in driver or firmware.
253 * This routine posts WORKER_RAMP_DOWN_QUEUE event for @phba. This routine
254 * posts at most 1 event each second. This routine wakes up worker thread of
255 * @phba to process WORKER_RAM_DOWN_EVENT event.
257 * This routine should be called with no lock held.
260 lpfc_rampdown_queue_depth(struct lpfc_hba
*phba
)
264 unsigned long expires
;
266 spin_lock_irqsave(&phba
->hbalock
, flags
);
267 atomic_inc(&phba
->num_rsrc_err
);
268 phba
->last_rsrc_error_time
= jiffies
;
270 expires
= phba
->last_ramp_down_time
+ QUEUE_RAMP_DOWN_INTERVAL
;
271 if (time_after(expires
, jiffies
)) {
272 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
276 phba
->last_ramp_down_time
= jiffies
;
278 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
280 spin_lock_irqsave(&phba
->pport
->work_port_lock
, flags
);
281 evt_posted
= phba
->pport
->work_port_events
& WORKER_RAMP_DOWN_QUEUE
;
283 phba
->pport
->work_port_events
|= WORKER_RAMP_DOWN_QUEUE
;
284 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, flags
);
287 lpfc_worker_wake_up(phba
);
292 * lpfc_ramp_down_queue_handler - WORKER_RAMP_DOWN_QUEUE event handler
293 * @phba: The Hba for which this call is being executed.
295 * This routine is called to process WORKER_RAMP_DOWN_QUEUE event for worker
296 * thread.This routine reduces queue depth for all scsi device on each vport
297 * associated with @phba.
300 lpfc_ramp_down_queue_handler(struct lpfc_hba
*phba
)
302 struct lpfc_vport
**vports
;
303 struct Scsi_Host
*shost
;
304 struct scsi_device
*sdev
;
305 unsigned long new_queue_depth
;
306 unsigned long num_rsrc_err
, num_cmd_success
;
309 num_rsrc_err
= atomic_read(&phba
->num_rsrc_err
);
310 num_cmd_success
= atomic_read(&phba
->num_cmd_success
);
313 * The error and success command counters are global per
314 * driver instance. If another handler has already
315 * operated on this error event, just exit.
317 if (num_rsrc_err
== 0)
320 vports
= lpfc_create_vport_work_array(phba
);
322 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
323 shost
= lpfc_shost_from_vport(vports
[i
]);
324 shost_for_each_device(sdev
, shost
) {
326 sdev
->queue_depth
* num_rsrc_err
/
327 (num_rsrc_err
+ num_cmd_success
);
328 if (!new_queue_depth
)
329 new_queue_depth
= sdev
->queue_depth
- 1;
331 new_queue_depth
= sdev
->queue_depth
-
333 scsi_change_queue_depth(sdev
, new_queue_depth
);
336 lpfc_destroy_vport_work_array(phba
, vports
);
337 atomic_set(&phba
->num_rsrc_err
, 0);
338 atomic_set(&phba
->num_cmd_success
, 0);
342 * lpfc_scsi_dev_block - set all scsi hosts to block state
343 * @phba: Pointer to HBA context object.
345 * This function walks vport list and set each SCSI host to block state
346 * by invoking fc_remote_port_delete() routine. This function is invoked
347 * with EEH when device's PCI slot has been permanently disabled.
350 lpfc_scsi_dev_block(struct lpfc_hba
*phba
)
352 struct lpfc_vport
**vports
;
353 struct Scsi_Host
*shost
;
354 struct scsi_device
*sdev
;
355 struct fc_rport
*rport
;
358 vports
= lpfc_create_vport_work_array(phba
);
360 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
361 shost
= lpfc_shost_from_vport(vports
[i
]);
362 shost_for_each_device(sdev
, shost
) {
363 rport
= starget_to_rport(scsi_target(sdev
));
364 fc_remote_port_delete(rport
);
367 lpfc_destroy_vport_work_array(phba
, vports
);
371 * lpfc_new_scsi_buf_s3 - Scsi buffer allocator for HBA with SLI3 IF spec
372 * @vport: The virtual port for which this call being executed.
373 * @num_to_allocate: The requested number of buffers to allocate.
375 * This routine allocates a scsi buffer for device with SLI-3 interface spec,
376 * the scsi buffer contains all the necessary information needed to initiate
377 * a SCSI I/O. The non-DMAable buffer region contains information to build
378 * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP,
379 * and the initial BPL. In addition to allocating memory, the FCP CMND and
380 * FCP RSP BDEs are setup in the BPL and the BPL BDE is setup in the IOCB.
383 * int - number of scsi buffers that were allocated.
384 * 0 = failure, less than num_to_alloc is a partial failure.
387 lpfc_new_scsi_buf_s3(struct lpfc_vport
*vport
, int num_to_alloc
)
389 struct lpfc_hba
*phba
= vport
->phba
;
390 struct lpfc_scsi_buf
*psb
;
391 struct ulp_bde64
*bpl
;
393 dma_addr_t pdma_phys_fcp_cmd
;
394 dma_addr_t pdma_phys_fcp_rsp
;
395 dma_addr_t pdma_phys_bpl
;
399 bpl_size
= phba
->cfg_sg_dma_buf_size
-
400 (sizeof(struct fcp_cmnd
) + sizeof(struct fcp_rsp
));
402 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
403 "9067 ALLOC %d scsi_bufs: %d (%d + %d + %d)\n",
404 num_to_alloc
, phba
->cfg_sg_dma_buf_size
,
405 (int)sizeof(struct fcp_cmnd
),
406 (int)sizeof(struct fcp_rsp
), bpl_size
);
408 for (bcnt
= 0; bcnt
< num_to_alloc
; bcnt
++) {
409 psb
= kzalloc(sizeof(struct lpfc_scsi_buf
), GFP_KERNEL
);
414 * Get memory from the pci pool to map the virt space to pci
415 * bus space for an I/O. The DMA buffer includes space for the
416 * struct fcp_cmnd, struct fcp_rsp and the number of bde's
417 * necessary to support the sg_tablesize.
419 psb
->data
= dma_pool_zalloc(phba
->lpfc_sg_dma_buf_pool
,
420 GFP_KERNEL
, &psb
->dma_handle
);
427 /* Allocate iotag for psb->cur_iocbq. */
428 iotag
= lpfc_sli_next_iotag(phba
, &psb
->cur_iocbq
);
430 dma_pool_free(phba
->lpfc_sg_dma_buf_pool
,
431 psb
->data
, psb
->dma_handle
);
435 psb
->cur_iocbq
.iocb_flag
|= LPFC_IO_FCP
;
437 psb
->fcp_cmnd
= psb
->data
;
438 psb
->fcp_rsp
= psb
->data
+ sizeof(struct fcp_cmnd
);
439 psb
->fcp_bpl
= psb
->data
+ sizeof(struct fcp_cmnd
) +
440 sizeof(struct fcp_rsp
);
442 /* Initialize local short-hand pointers. */
444 pdma_phys_fcp_cmd
= psb
->dma_handle
;
445 pdma_phys_fcp_rsp
= psb
->dma_handle
+ sizeof(struct fcp_cmnd
);
446 pdma_phys_bpl
= psb
->dma_handle
+ sizeof(struct fcp_cmnd
) +
447 sizeof(struct fcp_rsp
);
450 * The first two bdes are the FCP_CMD and FCP_RSP. The balance
451 * are sg list bdes. Initialize the first two and leave the
452 * rest for queuecommand.
454 bpl
[0].addrHigh
= le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd
));
455 bpl
[0].addrLow
= le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd
));
456 bpl
[0].tus
.f
.bdeSize
= sizeof(struct fcp_cmnd
);
457 bpl
[0].tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
458 bpl
[0].tus
.w
= le32_to_cpu(bpl
[0].tus
.w
);
460 /* Setup the physical region for the FCP RSP */
461 bpl
[1].addrHigh
= le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp
));
462 bpl
[1].addrLow
= le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp
));
463 bpl
[1].tus
.f
.bdeSize
= sizeof(struct fcp_rsp
);
464 bpl
[1].tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
465 bpl
[1].tus
.w
= le32_to_cpu(bpl
[1].tus
.w
);
468 * Since the IOCB for the FCP I/O is built into this
469 * lpfc_scsi_buf, initialize it with all known data now.
471 iocb
= &psb
->cur_iocbq
.iocb
;
472 iocb
->un
.fcpi64
.bdl
.ulpIoTag32
= 0;
473 if ((phba
->sli_rev
== 3) &&
474 !(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
)) {
475 /* fill in immediate fcp command BDE */
476 iocb
->un
.fcpi64
.bdl
.bdeFlags
= BUFF_TYPE_BDE_IMMED
;
477 iocb
->un
.fcpi64
.bdl
.bdeSize
= sizeof(struct fcp_cmnd
);
478 iocb
->un
.fcpi64
.bdl
.addrLow
= offsetof(IOCB_t
,
480 iocb
->un
.fcpi64
.bdl
.addrHigh
= 0;
481 iocb
->ulpBdeCount
= 0;
483 /* fill in response BDE */
484 iocb
->unsli3
.fcp_ext
.rbde
.tus
.f
.bdeFlags
=
486 iocb
->unsli3
.fcp_ext
.rbde
.tus
.f
.bdeSize
=
487 sizeof(struct fcp_rsp
);
488 iocb
->unsli3
.fcp_ext
.rbde
.addrLow
=
489 putPaddrLow(pdma_phys_fcp_rsp
);
490 iocb
->unsli3
.fcp_ext
.rbde
.addrHigh
=
491 putPaddrHigh(pdma_phys_fcp_rsp
);
493 iocb
->un
.fcpi64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
494 iocb
->un
.fcpi64
.bdl
.bdeSize
=
495 (2 * sizeof(struct ulp_bde64
));
496 iocb
->un
.fcpi64
.bdl
.addrLow
=
497 putPaddrLow(pdma_phys_bpl
);
498 iocb
->un
.fcpi64
.bdl
.addrHigh
=
499 putPaddrHigh(pdma_phys_bpl
);
500 iocb
->ulpBdeCount
= 1;
503 iocb
->ulpClass
= CLASS3
;
504 psb
->status
= IOSTAT_SUCCESS
;
505 /* Put it back into the SCSI buffer list */
506 psb
->cur_iocbq
.context1
= psb
;
507 lpfc_release_scsi_buf_s3(phba
, psb
);
515 * lpfc_sli4_vport_delete_fcp_xri_aborted -Remove all ndlp references for vport
516 * @vport: pointer to lpfc vport data structure.
518 * This routine is invoked by the vport cleanup for deletions and the cleanup
519 * for an ndlp on removal.
522 lpfc_sli4_vport_delete_fcp_xri_aborted(struct lpfc_vport
*vport
)
524 struct lpfc_hba
*phba
= vport
->phba
;
525 struct lpfc_scsi_buf
*psb
, *next_psb
;
526 unsigned long iflag
= 0;
528 if (!(phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
))
530 spin_lock_irqsave(&phba
->hbalock
, iflag
);
531 spin_lock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
532 list_for_each_entry_safe(psb
, next_psb
,
533 &phba
->sli4_hba
.lpfc_abts_scsi_buf_list
, list
) {
534 if (psb
->rdata
&& psb
->rdata
->pnode
535 && psb
->rdata
->pnode
->vport
== vport
)
538 spin_unlock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
539 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
543 * lpfc_sli4_fcp_xri_aborted - Fast-path process of fcp xri abort
544 * @phba: pointer to lpfc hba data structure.
545 * @axri: pointer to the fcp xri abort wcqe structure.
547 * This routine is invoked by the worker thread to process a SLI4 fast-path
551 lpfc_sli4_fcp_xri_aborted(struct lpfc_hba
*phba
,
552 struct sli4_wcqe_xri_aborted
*axri
)
554 uint16_t xri
= bf_get(lpfc_wcqe_xa_xri
, axri
);
555 uint16_t rxid
= bf_get(lpfc_wcqe_xa_remote_xid
, axri
);
556 struct lpfc_scsi_buf
*psb
, *next_psb
;
557 unsigned long iflag
= 0;
558 struct lpfc_iocbq
*iocbq
;
560 struct lpfc_nodelist
*ndlp
;
562 struct lpfc_sli_ring
*pring
= phba
->sli4_hba
.els_wq
->pring
;
564 if (!(phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
))
566 spin_lock_irqsave(&phba
->hbalock
, iflag
);
567 spin_lock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
568 list_for_each_entry_safe(psb
, next_psb
,
569 &phba
->sli4_hba
.lpfc_abts_scsi_buf_list
, list
) {
570 if (psb
->cur_iocbq
.sli4_xritag
== xri
) {
571 list_del(&psb
->list
);
573 psb
->status
= IOSTAT_SUCCESS
;
575 &phba
->sli4_hba
.abts_scsi_buf_list_lock
);
576 if (psb
->rdata
&& psb
->rdata
->pnode
)
577 ndlp
= psb
->rdata
->pnode
;
581 rrq_empty
= list_empty(&phba
->active_rrq_list
);
582 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
584 lpfc_set_rrq_active(phba
, ndlp
,
585 psb
->cur_iocbq
.sli4_lxritag
, rxid
, 1);
586 lpfc_sli4_abts_err_handler(phba
, ndlp
, axri
);
588 lpfc_release_scsi_buf_s4(phba
, psb
);
590 lpfc_worker_wake_up(phba
);
594 spin_unlock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
595 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
596 iocbq
= phba
->sli
.iocbq_lookup
[i
];
598 if (!(iocbq
->iocb_flag
& LPFC_IO_FCP
) ||
599 (iocbq
->iocb_flag
& LPFC_IO_LIBDFC
))
601 if (iocbq
->sli4_xritag
!= xri
)
603 psb
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
605 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
606 if (!list_empty(&pring
->txq
))
607 lpfc_worker_wake_up(phba
);
611 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
615 * lpfc_sli4_post_scsi_sgl_list - Post blocks of scsi buffer sgls from a list
616 * @phba: pointer to lpfc hba data structure.
617 * @post_sblist: pointer to the scsi buffer list.
619 * This routine walks a list of scsi buffers that was passed in. It attempts
620 * to construct blocks of scsi buffer sgls which contains contiguous xris and
621 * uses the non-embedded SGL block post mailbox commands to post to the port.
622 * For single SCSI buffer sgl with non-contiguous xri, if any, it shall use
623 * embedded SGL post mailbox command for posting. The @post_sblist passed in
624 * must be local list, thus no lock is needed when manipulate the list.
626 * Returns: 0 = failure, non-zero number of successfully posted buffers.
629 lpfc_sli4_post_scsi_sgl_list(struct lpfc_hba
*phba
,
630 struct list_head
*post_sblist
, int sb_count
)
632 struct lpfc_scsi_buf
*psb
, *psb_next
;
633 int status
, sgl_size
;
634 int post_cnt
= 0, block_cnt
= 0, num_posting
= 0, num_posted
= 0;
635 dma_addr_t pdma_phys_bpl1
;
636 int last_xritag
= NO_XRI
;
637 LIST_HEAD(prep_sblist
);
638 LIST_HEAD(blck_sblist
);
639 LIST_HEAD(scsi_sblist
);
645 sgl_size
= phba
->cfg_sg_dma_buf_size
-
646 (sizeof(struct fcp_cmnd
) + sizeof(struct fcp_rsp
));
648 list_for_each_entry_safe(psb
, psb_next
, post_sblist
, list
) {
649 list_del_init(&psb
->list
);
651 if ((last_xritag
!= NO_XRI
) &&
652 (psb
->cur_iocbq
.sli4_xritag
!= last_xritag
+ 1)) {
653 /* a hole in xri block, form a sgl posting block */
654 list_splice_init(&prep_sblist
, &blck_sblist
);
655 post_cnt
= block_cnt
- 1;
656 /* prepare list for next posting block */
657 list_add_tail(&psb
->list
, &prep_sblist
);
660 /* prepare list for next posting block */
661 list_add_tail(&psb
->list
, &prep_sblist
);
662 /* enough sgls for non-embed sgl mbox command */
663 if (block_cnt
== LPFC_NEMBED_MBOX_SGL_CNT
) {
664 list_splice_init(&prep_sblist
, &blck_sblist
);
665 post_cnt
= block_cnt
;
670 last_xritag
= psb
->cur_iocbq
.sli4_xritag
;
672 /* end of repost sgl list condition for SCSI buffers */
673 if (num_posting
== sb_count
) {
675 /* last sgl posting block */
676 list_splice_init(&prep_sblist
, &blck_sblist
);
677 post_cnt
= block_cnt
;
678 } else if (block_cnt
== 1) {
679 /* last single sgl with non-contiguous xri */
680 if (sgl_size
> SGL_PAGE_SIZE
)
681 pdma_phys_bpl1
= psb
->dma_phys_bpl
+
685 status
= lpfc_sli4_post_sgl(phba
,
688 psb
->cur_iocbq
.sli4_xritag
);
690 /* failure, put on abort scsi list */
693 /* success, put on SCSI buffer list */
695 psb
->status
= IOSTAT_SUCCESS
;
698 /* success, put on SCSI buffer sgl list */
699 list_add_tail(&psb
->list
, &scsi_sblist
);
703 /* continue until a nembed page worth of sgls */
707 /* post block of SCSI buffer list sgls */
708 status
= lpfc_sli4_post_scsi_sgl_block(phba
, &blck_sblist
,
711 /* don't reset xirtag due to hole in xri block */
713 last_xritag
= NO_XRI
;
715 /* reset SCSI buffer post count for next round of posting */
718 /* put posted SCSI buffer-sgl posted on SCSI buffer sgl list */
719 while (!list_empty(&blck_sblist
)) {
720 list_remove_head(&blck_sblist
, psb
,
721 struct lpfc_scsi_buf
, list
);
723 /* failure, put on abort scsi list */
726 /* success, put on SCSI buffer list */
728 psb
->status
= IOSTAT_SUCCESS
;
731 list_add_tail(&psb
->list
, &scsi_sblist
);
734 /* Push SCSI buffers with sgl posted to the availble list */
735 while (!list_empty(&scsi_sblist
)) {
736 list_remove_head(&scsi_sblist
, psb
,
737 struct lpfc_scsi_buf
, list
);
738 lpfc_release_scsi_buf_s4(phba
, psb
);
744 * lpfc_sli4_repost_scsi_sgl_list - Repost all the allocated scsi buffer sgls
745 * @phba: pointer to lpfc hba data structure.
747 * This routine walks the list of scsi buffers that have been allocated and
748 * repost them to the port by using SGL block post. This is needed after a
749 * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine
750 * is responsible for moving all scsi buffers on the lpfc_abts_scsi_sgl_list
751 * to the lpfc_scsi_buf_list. If the repost fails, reject all scsi buffers.
753 * Returns: 0 = success, non-zero failure.
756 lpfc_sli4_repost_scsi_sgl_list(struct lpfc_hba
*phba
)
758 LIST_HEAD(post_sblist
);
759 int num_posted
, rc
= 0;
761 /* get all SCSI buffers need to repost to a local list */
762 spin_lock_irq(&phba
->scsi_buf_list_get_lock
);
763 spin_lock(&phba
->scsi_buf_list_put_lock
);
764 list_splice_init(&phba
->lpfc_scsi_buf_list_get
, &post_sblist
);
765 list_splice(&phba
->lpfc_scsi_buf_list_put
, &post_sblist
);
766 spin_unlock(&phba
->scsi_buf_list_put_lock
);
767 spin_unlock_irq(&phba
->scsi_buf_list_get_lock
);
769 /* post the list of scsi buffer sgls to port if available */
770 if (!list_empty(&post_sblist
)) {
771 num_posted
= lpfc_sli4_post_scsi_sgl_list(phba
, &post_sblist
,
772 phba
->sli4_hba
.scsi_xri_cnt
);
773 /* failed to post any scsi buffer, return error */
781 * lpfc_new_scsi_buf_s4 - Scsi buffer allocator for HBA with SLI4 IF spec
782 * @vport: The virtual port for which this call being executed.
783 * @num_to_allocate: The requested number of buffers to allocate.
785 * This routine allocates scsi buffers for device with SLI-4 interface spec,
786 * the scsi buffer contains all the necessary information needed to initiate
787 * a SCSI I/O. After allocating up to @num_to_allocate SCSI buffers and put
788 * them on a list, it post them to the port by using SGL block post.
791 * int - number of scsi buffers that were allocated and posted.
792 * 0 = failure, less than num_to_alloc is a partial failure.
795 lpfc_new_scsi_buf_s4(struct lpfc_vport
*vport
, int num_to_alloc
)
797 struct lpfc_hba
*phba
= vport
->phba
;
798 struct lpfc_scsi_buf
*psb
;
799 struct sli4_sge
*sgl
;
801 dma_addr_t pdma_phys_fcp_cmd
;
802 dma_addr_t pdma_phys_fcp_rsp
;
803 dma_addr_t pdma_phys_bpl
;
804 uint16_t iotag
, lxri
= 0;
805 int bcnt
, num_posted
, sgl_size
;
806 LIST_HEAD(prep_sblist
);
807 LIST_HEAD(post_sblist
);
808 LIST_HEAD(scsi_sblist
);
810 sgl_size
= phba
->cfg_sg_dma_buf_size
-
811 (sizeof(struct fcp_cmnd
) + sizeof(struct fcp_rsp
));
813 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
814 "9068 ALLOC %d scsi_bufs: %d (%d + %d + %d)\n",
815 num_to_alloc
, phba
->cfg_sg_dma_buf_size
, sgl_size
,
816 (int)sizeof(struct fcp_cmnd
),
817 (int)sizeof(struct fcp_rsp
));
819 for (bcnt
= 0; bcnt
< num_to_alloc
; bcnt
++) {
820 psb
= kzalloc(sizeof(struct lpfc_scsi_buf
), GFP_KERNEL
);
824 * Get memory from the pci pool to map the virt space to
825 * pci bus space for an I/O. The DMA buffer includes space
826 * for the struct fcp_cmnd, struct fcp_rsp and the number
827 * of bde's necessary to support the sg_tablesize.
829 psb
->data
= dma_pool_zalloc(phba
->lpfc_sg_dma_buf_pool
,
830 GFP_KERNEL
, &psb
->dma_handle
);
837 * 4K Page alignment is CRITICAL to BlockGuard, double check
840 if ((phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
) &&
841 (((unsigned long)(psb
->data
) &
842 (unsigned long)(SLI4_PAGE_SIZE
- 1)) != 0)) {
843 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
844 "3369 Memory alignment error "
846 (unsigned long)psb
->data
);
847 dma_pool_free(phba
->lpfc_sg_dma_buf_pool
,
848 psb
->data
, psb
->dma_handle
);
854 lxri
= lpfc_sli4_next_xritag(phba
);
855 if (lxri
== NO_XRI
) {
856 dma_pool_free(phba
->lpfc_sg_dma_buf_pool
,
857 psb
->data
, psb
->dma_handle
);
862 /* Allocate iotag for psb->cur_iocbq. */
863 iotag
= lpfc_sli_next_iotag(phba
, &psb
->cur_iocbq
);
865 dma_pool_free(phba
->lpfc_sg_dma_buf_pool
,
866 psb
->data
, psb
->dma_handle
);
868 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
869 "3368 Failed to allocate IOTAG for"
870 " XRI:0x%x\n", lxri
);
871 lpfc_sli4_free_xri(phba
, lxri
);
874 psb
->cur_iocbq
.sli4_lxritag
= lxri
;
875 psb
->cur_iocbq
.sli4_xritag
= phba
->sli4_hba
.xri_ids
[lxri
];
876 psb
->cur_iocbq
.iocb_flag
|= LPFC_IO_FCP
;
877 psb
->fcp_bpl
= psb
->data
;
878 psb
->fcp_cmnd
= (psb
->data
+ sgl_size
);
879 psb
->fcp_rsp
= (struct fcp_rsp
*)((uint8_t *)psb
->fcp_cmnd
+
880 sizeof(struct fcp_cmnd
));
882 /* Initialize local short-hand pointers. */
883 sgl
= (struct sli4_sge
*)psb
->fcp_bpl
;
884 pdma_phys_bpl
= psb
->dma_handle
;
885 pdma_phys_fcp_cmd
= (psb
->dma_handle
+ sgl_size
);
886 pdma_phys_fcp_rsp
= pdma_phys_fcp_cmd
+ sizeof(struct fcp_cmnd
);
889 * The first two bdes are the FCP_CMD and FCP_RSP.
890 * The balance are sg list bdes. Initialize the
891 * first two and leave the rest for queuecommand.
893 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd
));
894 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd
));
895 sgl
->word2
= le32_to_cpu(sgl
->word2
);
896 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
897 sgl
->word2
= cpu_to_le32(sgl
->word2
);
898 sgl
->sge_len
= cpu_to_le32(sizeof(struct fcp_cmnd
));
901 /* Setup the physical region for the FCP RSP */
902 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp
));
903 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp
));
904 sgl
->word2
= le32_to_cpu(sgl
->word2
);
905 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
906 sgl
->word2
= cpu_to_le32(sgl
->word2
);
907 sgl
->sge_len
= cpu_to_le32(sizeof(struct fcp_rsp
));
910 * Since the IOCB for the FCP I/O is built into this
911 * lpfc_scsi_buf, initialize it with all known data now.
913 iocb
= &psb
->cur_iocbq
.iocb
;
914 iocb
->un
.fcpi64
.bdl
.ulpIoTag32
= 0;
915 iocb
->un
.fcpi64
.bdl
.bdeFlags
= BUFF_TYPE_BDE_64
;
916 /* setting the BLP size to 2 * sizeof BDE may not be correct.
917 * We are setting the bpl to point to out sgl. An sgl's
918 * entries are 16 bytes, a bpl entries are 12 bytes.
920 iocb
->un
.fcpi64
.bdl
.bdeSize
= sizeof(struct fcp_cmnd
);
921 iocb
->un
.fcpi64
.bdl
.addrLow
= putPaddrLow(pdma_phys_fcp_cmd
);
922 iocb
->un
.fcpi64
.bdl
.addrHigh
= putPaddrHigh(pdma_phys_fcp_cmd
);
923 iocb
->ulpBdeCount
= 1;
925 iocb
->ulpClass
= CLASS3
;
926 psb
->cur_iocbq
.context1
= psb
;
927 psb
->dma_phys_bpl
= pdma_phys_bpl
;
929 /* add the scsi buffer to a post list */
930 list_add_tail(&psb
->list
, &post_sblist
);
931 spin_lock_irq(&phba
->scsi_buf_list_get_lock
);
932 phba
->sli4_hba
.scsi_xri_cnt
++;
933 spin_unlock_irq(&phba
->scsi_buf_list_get_lock
);
935 lpfc_printf_log(phba
, KERN_INFO
, LOG_BG
| LOG_FCP
,
936 "3021 Allocate %d out of %d requested new SCSI "
937 "buffers\n", bcnt
, num_to_alloc
);
939 /* post the list of scsi buffer sgls to port if available */
940 if (!list_empty(&post_sblist
))
941 num_posted
= lpfc_sli4_post_scsi_sgl_list(phba
,
950 * lpfc_new_scsi_buf - Wrapper funciton for scsi buffer allocator
951 * @vport: The virtual port for which this call being executed.
952 * @num_to_allocate: The requested number of buffers to allocate.
954 * This routine wraps the actual SCSI buffer allocator function pointer from
955 * the lpfc_hba struct.
958 * int - number of scsi buffers that were allocated.
959 * 0 = failure, less than num_to_alloc is a partial failure.
962 lpfc_new_scsi_buf(struct lpfc_vport
*vport
, int num_to_alloc
)
964 return vport
->phba
->lpfc_new_scsi_buf(vport
, num_to_alloc
);
968 * lpfc_get_scsi_buf_s3 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
969 * @phba: The HBA for which this call is being executed.
971 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
972 * and returns to caller.
976 * Pointer to lpfc_scsi_buf - Success
978 static struct lpfc_scsi_buf
*
979 lpfc_get_scsi_buf_s3(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
981 struct lpfc_scsi_buf
* lpfc_cmd
= NULL
;
982 struct list_head
*scsi_buf_list_get
= &phba
->lpfc_scsi_buf_list_get
;
983 unsigned long iflag
= 0;
985 spin_lock_irqsave(&phba
->scsi_buf_list_get_lock
, iflag
);
986 list_remove_head(scsi_buf_list_get
, lpfc_cmd
, struct lpfc_scsi_buf
,
989 spin_lock(&phba
->scsi_buf_list_put_lock
);
990 list_splice(&phba
->lpfc_scsi_buf_list_put
,
991 &phba
->lpfc_scsi_buf_list_get
);
992 INIT_LIST_HEAD(&phba
->lpfc_scsi_buf_list_put
);
993 list_remove_head(scsi_buf_list_get
, lpfc_cmd
,
994 struct lpfc_scsi_buf
, list
);
995 spin_unlock(&phba
->scsi_buf_list_put_lock
);
997 spin_unlock_irqrestore(&phba
->scsi_buf_list_get_lock
, iflag
);
1001 * lpfc_get_scsi_buf_s4 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
1002 * @phba: The HBA for which this call is being executed.
1004 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
1005 * and returns to caller.
1009 * Pointer to lpfc_scsi_buf - Success
1011 static struct lpfc_scsi_buf
*
1012 lpfc_get_scsi_buf_s4(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
1014 struct lpfc_scsi_buf
*lpfc_cmd
, *lpfc_cmd_next
;
1015 unsigned long iflag
= 0;
1018 spin_lock_irqsave(&phba
->scsi_buf_list_get_lock
, iflag
);
1019 list_for_each_entry_safe(lpfc_cmd
, lpfc_cmd_next
,
1020 &phba
->lpfc_scsi_buf_list_get
, list
) {
1021 if (lpfc_test_rrq_active(phba
, ndlp
,
1022 lpfc_cmd
->cur_iocbq
.sli4_lxritag
))
1024 list_del_init(&lpfc_cmd
->list
);
1029 spin_lock(&phba
->scsi_buf_list_put_lock
);
1030 list_splice(&phba
->lpfc_scsi_buf_list_put
,
1031 &phba
->lpfc_scsi_buf_list_get
);
1032 INIT_LIST_HEAD(&phba
->lpfc_scsi_buf_list_put
);
1033 spin_unlock(&phba
->scsi_buf_list_put_lock
);
1034 list_for_each_entry_safe(lpfc_cmd
, lpfc_cmd_next
,
1035 &phba
->lpfc_scsi_buf_list_get
, list
) {
1036 if (lpfc_test_rrq_active(
1037 phba
, ndlp
, lpfc_cmd
->cur_iocbq
.sli4_lxritag
))
1039 list_del_init(&lpfc_cmd
->list
);
1044 spin_unlock_irqrestore(&phba
->scsi_buf_list_get_lock
, iflag
);
1050 * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
1051 * @phba: The HBA for which this call is being executed.
1053 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
1054 * and returns to caller.
1058 * Pointer to lpfc_scsi_buf - Success
1060 static struct lpfc_scsi_buf
*
1061 lpfc_get_scsi_buf(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
1063 return phba
->lpfc_get_scsi_buf(phba
, ndlp
);
1067 * lpfc_release_scsi_buf - Return a scsi buffer back to hba scsi buf list
1068 * @phba: The Hba for which this call is being executed.
1069 * @psb: The scsi buffer which is being released.
1071 * This routine releases @psb scsi buffer by adding it to tail of @phba
1072 * lpfc_scsi_buf_list list.
1075 lpfc_release_scsi_buf_s3(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
)
1077 unsigned long iflag
= 0;
1080 psb
->nonsg_phys
= 0;
1081 psb
->prot_seg_cnt
= 0;
1083 spin_lock_irqsave(&phba
->scsi_buf_list_put_lock
, iflag
);
1085 psb
->cur_iocbq
.iocb_flag
= LPFC_IO_FCP
;
1086 list_add_tail(&psb
->list
, &phba
->lpfc_scsi_buf_list_put
);
1087 spin_unlock_irqrestore(&phba
->scsi_buf_list_put_lock
, iflag
);
1091 * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list.
1092 * @phba: The Hba for which this call is being executed.
1093 * @psb: The scsi buffer which is being released.
1095 * This routine releases @psb scsi buffer by adding it to tail of @phba
1096 * lpfc_scsi_buf_list list. For SLI4 XRI's are tied to the scsi buffer
1097 * and cannot be reused for at least RA_TOV amount of time if it was
1101 lpfc_release_scsi_buf_s4(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
)
1103 unsigned long iflag
= 0;
1106 psb
->nonsg_phys
= 0;
1107 psb
->prot_seg_cnt
= 0;
1109 if (psb
->exch_busy
) {
1110 spin_lock_irqsave(&phba
->sli4_hba
.abts_scsi_buf_list_lock
,
1113 list_add_tail(&psb
->list
,
1114 &phba
->sli4_hba
.lpfc_abts_scsi_buf_list
);
1115 spin_unlock_irqrestore(&phba
->sli4_hba
.abts_scsi_buf_list_lock
,
1119 psb
->cur_iocbq
.iocb_flag
= LPFC_IO_FCP
;
1120 spin_lock_irqsave(&phba
->scsi_buf_list_put_lock
, iflag
);
1121 list_add_tail(&psb
->list
, &phba
->lpfc_scsi_buf_list_put
);
1122 spin_unlock_irqrestore(&phba
->scsi_buf_list_put_lock
, iflag
);
1127 * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list.
1128 * @phba: The Hba for which this call is being executed.
1129 * @psb: The scsi buffer which is being released.
1131 * This routine releases @psb scsi buffer by adding it to tail of @phba
1132 * lpfc_scsi_buf_list list.
1135 lpfc_release_scsi_buf(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
)
1138 phba
->lpfc_release_scsi_buf(phba
, psb
);
1142 * lpfc_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
1143 * @phba: The Hba for which this call is being executed.
1144 * @lpfc_cmd: The scsi buffer which is going to be mapped.
1146 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
1147 * field of @lpfc_cmd for device with SLI-3 interface spec. This routine scans
1148 * through sg elements and format the bde. This routine also initializes all
1149 * IOCB fields which are dependent on scsi command request buffer.
1156 lpfc_scsi_prep_dma_buf_s3(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
)
1158 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
1159 struct scatterlist
*sgel
= NULL
;
1160 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
1161 struct ulp_bde64
*bpl
= lpfc_cmd
->fcp_bpl
;
1162 struct lpfc_iocbq
*iocbq
= &lpfc_cmd
->cur_iocbq
;
1163 IOCB_t
*iocb_cmd
= &lpfc_cmd
->cur_iocbq
.iocb
;
1164 struct ulp_bde64
*data_bde
= iocb_cmd
->unsli3
.fcp_ext
.dbde
;
1165 dma_addr_t physaddr
;
1166 uint32_t num_bde
= 0;
1167 int nseg
, datadir
= scsi_cmnd
->sc_data_direction
;
1170 * There are three possibilities here - use scatter-gather segment, use
1171 * the single mapping, or neither. Start the lpfc command prep by
1172 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
1176 if (scsi_sg_count(scsi_cmnd
)) {
1178 * The driver stores the segment count returned from pci_map_sg
1179 * because this a count of dma-mappings used to map the use_sg
1180 * pages. They are not guaranteed to be the same for those
1181 * architectures that implement an IOMMU.
1184 nseg
= dma_map_sg(&phba
->pcidev
->dev
, scsi_sglist(scsi_cmnd
),
1185 scsi_sg_count(scsi_cmnd
), datadir
);
1186 if (unlikely(!nseg
))
1189 lpfc_cmd
->seg_cnt
= nseg
;
1190 if (lpfc_cmd
->seg_cnt
> phba
->cfg_sg_seg_cnt
) {
1191 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1192 "9064 BLKGRD: %s: Too many sg segments from "
1193 "dma_map_sg. Config %d, seg_cnt %d\n",
1194 __func__
, phba
->cfg_sg_seg_cnt
,
1196 lpfc_cmd
->seg_cnt
= 0;
1197 scsi_dma_unmap(scsi_cmnd
);
1202 * The driver established a maximum scatter-gather segment count
1203 * during probe that limits the number of sg elements in any
1204 * single scsi command. Just run through the seg_cnt and format
1206 * When using SLI-3 the driver will try to fit all the BDEs into
1207 * the IOCB. If it can't then the BDEs get added to a BPL as it
1208 * does for SLI-2 mode.
1210 scsi_for_each_sg(scsi_cmnd
, sgel
, nseg
, num_bde
) {
1211 physaddr
= sg_dma_address(sgel
);
1212 if (phba
->sli_rev
== 3 &&
1213 !(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
) &&
1214 !(iocbq
->iocb_flag
& DSS_SECURITY_OP
) &&
1215 nseg
<= LPFC_EXT_DATA_BDE_COUNT
) {
1216 data_bde
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
1217 data_bde
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
1218 data_bde
->addrLow
= putPaddrLow(physaddr
);
1219 data_bde
->addrHigh
= putPaddrHigh(physaddr
);
1222 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
1223 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
1224 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
1226 le32_to_cpu(putPaddrLow(physaddr
));
1228 le32_to_cpu(putPaddrHigh(physaddr
));
1235 * Finish initializing those IOCB fields that are dependent on the
1236 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
1237 * explicitly reinitialized and for SLI-3 the extended bde count is
1238 * explicitly reinitialized since all iocb memory resources are reused.
1240 if (phba
->sli_rev
== 3 &&
1241 !(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
) &&
1242 !(iocbq
->iocb_flag
& DSS_SECURITY_OP
)) {
1243 if (num_bde
> LPFC_EXT_DATA_BDE_COUNT
) {
1245 * The extended IOCB format can only fit 3 BDE or a BPL.
1246 * This I/O has more than 3 BDE so the 1st data bde will
1247 * be a BPL that is filled in here.
1249 physaddr
= lpfc_cmd
->dma_handle
;
1250 data_bde
->tus
.f
.bdeFlags
= BUFF_TYPE_BLP_64
;
1251 data_bde
->tus
.f
.bdeSize
= (num_bde
*
1252 sizeof(struct ulp_bde64
));
1253 physaddr
+= (sizeof(struct fcp_cmnd
) +
1254 sizeof(struct fcp_rsp
) +
1255 (2 * sizeof(struct ulp_bde64
)));
1256 data_bde
->addrHigh
= putPaddrHigh(physaddr
);
1257 data_bde
->addrLow
= putPaddrLow(physaddr
);
1258 /* ebde count includes the response bde and data bpl */
1259 iocb_cmd
->unsli3
.fcp_ext
.ebde_count
= 2;
1261 /* ebde count includes the response bde and data bdes */
1262 iocb_cmd
->unsli3
.fcp_ext
.ebde_count
= (num_bde
+ 1);
1265 iocb_cmd
->un
.fcpi64
.bdl
.bdeSize
=
1266 ((num_bde
+ 2) * sizeof(struct ulp_bde64
));
1267 iocb_cmd
->unsli3
.fcp_ext
.ebde_count
= (num_bde
+ 1);
1269 fcp_cmnd
->fcpDl
= cpu_to_be32(scsi_bufflen(scsi_cmnd
));
1272 * Due to difference in data length between DIF/non-DIF paths,
1273 * we need to set word 4 of IOCB here
1275 iocb_cmd
->un
.fcpi
.fcpi_parm
= scsi_bufflen(scsi_cmnd
);
1279 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1281 /* Return BG_ERR_INIT if error injection is detected by Initiator */
1282 #define BG_ERR_INIT 0x1
1283 /* Return BG_ERR_TGT if error injection is detected by Target */
1284 #define BG_ERR_TGT 0x2
1285 /* Return BG_ERR_SWAP if swapping CSUM<-->CRC is required for error injection */
1286 #define BG_ERR_SWAP 0x10
1288 * Return BG_ERR_CHECK if disabling Guard/Ref/App checking is required for
1291 #define BG_ERR_CHECK 0x20
1294 * lpfc_bg_err_inject - Determine if we should inject an error
1295 * @phba: The Hba for which this call is being executed.
1296 * @sc: The SCSI command to examine
1297 * @reftag: (out) BlockGuard reference tag for transmitted data
1298 * @apptag: (out) BlockGuard application tag for transmitted data
1299 * @new_guard (in) Value to replace CRC with if needed
1301 * Returns BG_ERR_* bit mask or 0 if request ignored
1304 lpfc_bg_err_inject(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
1305 uint32_t *reftag
, uint16_t *apptag
, uint32_t new_guard
)
1307 struct scatterlist
*sgpe
; /* s/g prot entry */
1308 struct lpfc_scsi_buf
*lpfc_cmd
= NULL
;
1309 struct scsi_dif_tuple
*src
= NULL
;
1310 struct lpfc_nodelist
*ndlp
;
1311 struct lpfc_rport_data
*rdata
;
1312 uint32_t op
= scsi_get_prot_op(sc
);
1319 if (op
== SCSI_PROT_NORMAL
)
1322 sgpe
= scsi_prot_sglist(sc
);
1323 lba
= scsi_get_lba(sc
);
1325 /* First check if we need to match the LBA */
1326 if (phba
->lpfc_injerr_lba
!= LPFC_INJERR_LBA_OFF
) {
1327 blksize
= lpfc_cmd_blksize(sc
);
1328 numblks
= (scsi_bufflen(sc
) + blksize
- 1) / blksize
;
1330 /* Make sure we have the right LBA if one is specified */
1331 if ((phba
->lpfc_injerr_lba
< lba
) ||
1332 (phba
->lpfc_injerr_lba
>= (lba
+ numblks
)))
1335 blockoff
= phba
->lpfc_injerr_lba
- lba
;
1336 numblks
= sg_dma_len(sgpe
) /
1337 sizeof(struct scsi_dif_tuple
);
1338 if (numblks
< blockoff
)
1343 /* Next check if we need to match the remote NPortID or WWPN */
1344 rdata
= lpfc_rport_data_from_scsi_device(sc
->device
);
1345 if (rdata
&& rdata
->pnode
) {
1346 ndlp
= rdata
->pnode
;
1348 /* Make sure we have the right NPortID if one is specified */
1349 if (phba
->lpfc_injerr_nportid
&&
1350 (phba
->lpfc_injerr_nportid
!= ndlp
->nlp_DID
))
1354 * Make sure we have the right WWPN if one is specified.
1355 * wwn[0] should be a non-zero NAA in a good WWPN.
1357 if (phba
->lpfc_injerr_wwpn
.u
.wwn
[0] &&
1358 (memcmp(&ndlp
->nlp_portname
, &phba
->lpfc_injerr_wwpn
,
1359 sizeof(struct lpfc_name
)) != 0))
1363 /* Setup a ptr to the protection data if the SCSI host provides it */
1365 src
= (struct scsi_dif_tuple
*)sg_virt(sgpe
);
1367 lpfc_cmd
= (struct lpfc_scsi_buf
*)sc
->host_scribble
;
1370 /* Should we change the Reference Tag */
1372 if (phba
->lpfc_injerr_wref_cnt
) {
1374 case SCSI_PROT_WRITE_PASS
:
1377 * For WRITE_PASS, force the error
1378 * to be sent on the wire. It should
1379 * be detected by the Target.
1380 * If blockoff != 0 error will be
1381 * inserted in middle of the IO.
1384 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1385 "9076 BLKGRD: Injecting reftag error: "
1386 "write lba x%lx + x%x oldrefTag x%x\n",
1387 (unsigned long)lba
, blockoff
,
1388 be32_to_cpu(src
->ref_tag
));
1391 * Save the old ref_tag so we can
1392 * restore it on completion.
1395 lpfc_cmd
->prot_data_type
=
1397 lpfc_cmd
->prot_data_segment
=
1399 lpfc_cmd
->prot_data
=
1402 src
->ref_tag
= cpu_to_be32(0xDEADBEEF);
1403 phba
->lpfc_injerr_wref_cnt
--;
1404 if (phba
->lpfc_injerr_wref_cnt
== 0) {
1405 phba
->lpfc_injerr_nportid
= 0;
1406 phba
->lpfc_injerr_lba
=
1407 LPFC_INJERR_LBA_OFF
;
1408 memset(&phba
->lpfc_injerr_wwpn
,
1409 0, sizeof(struct lpfc_name
));
1411 rc
= BG_ERR_TGT
| BG_ERR_CHECK
;
1416 case SCSI_PROT_WRITE_INSERT
:
1418 * For WRITE_INSERT, force the error
1419 * to be sent on the wire. It should be
1420 * detected by the Target.
1422 /* DEADBEEF will be the reftag on the wire */
1423 *reftag
= 0xDEADBEEF;
1424 phba
->lpfc_injerr_wref_cnt
--;
1425 if (phba
->lpfc_injerr_wref_cnt
== 0) {
1426 phba
->lpfc_injerr_nportid
= 0;
1427 phba
->lpfc_injerr_lba
=
1428 LPFC_INJERR_LBA_OFF
;
1429 memset(&phba
->lpfc_injerr_wwpn
,
1430 0, sizeof(struct lpfc_name
));
1432 rc
= BG_ERR_TGT
| BG_ERR_CHECK
;
1434 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1435 "9078 BLKGRD: Injecting reftag error: "
1436 "write lba x%lx\n", (unsigned long)lba
);
1438 case SCSI_PROT_WRITE_STRIP
:
1440 * For WRITE_STRIP and WRITE_PASS,
1441 * force the error on data
1442 * being copied from SLI-Host to SLI-Port.
1444 *reftag
= 0xDEADBEEF;
1445 phba
->lpfc_injerr_wref_cnt
--;
1446 if (phba
->lpfc_injerr_wref_cnt
== 0) {
1447 phba
->lpfc_injerr_nportid
= 0;
1448 phba
->lpfc_injerr_lba
=
1449 LPFC_INJERR_LBA_OFF
;
1450 memset(&phba
->lpfc_injerr_wwpn
,
1451 0, sizeof(struct lpfc_name
));
1455 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1456 "9077 BLKGRD: Injecting reftag error: "
1457 "write lba x%lx\n", (unsigned long)lba
);
1461 if (phba
->lpfc_injerr_rref_cnt
) {
1463 case SCSI_PROT_READ_INSERT
:
1464 case SCSI_PROT_READ_STRIP
:
1465 case SCSI_PROT_READ_PASS
:
1467 * For READ_STRIP and READ_PASS, force the
1468 * error on data being read off the wire. It
1469 * should force an IO error to the driver.
1471 *reftag
= 0xDEADBEEF;
1472 phba
->lpfc_injerr_rref_cnt
--;
1473 if (phba
->lpfc_injerr_rref_cnt
== 0) {
1474 phba
->lpfc_injerr_nportid
= 0;
1475 phba
->lpfc_injerr_lba
=
1476 LPFC_INJERR_LBA_OFF
;
1477 memset(&phba
->lpfc_injerr_wwpn
,
1478 0, sizeof(struct lpfc_name
));
1482 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1483 "9079 BLKGRD: Injecting reftag error: "
1484 "read lba x%lx\n", (unsigned long)lba
);
1490 /* Should we change the Application Tag */
1492 if (phba
->lpfc_injerr_wapp_cnt
) {
1494 case SCSI_PROT_WRITE_PASS
:
1497 * For WRITE_PASS, force the error
1498 * to be sent on the wire. It should
1499 * be detected by the Target.
1500 * If blockoff != 0 error will be
1501 * inserted in middle of the IO.
1504 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1505 "9080 BLKGRD: Injecting apptag error: "
1506 "write lba x%lx + x%x oldappTag x%x\n",
1507 (unsigned long)lba
, blockoff
,
1508 be16_to_cpu(src
->app_tag
));
1511 * Save the old app_tag so we can
1512 * restore it on completion.
1515 lpfc_cmd
->prot_data_type
=
1517 lpfc_cmd
->prot_data_segment
=
1519 lpfc_cmd
->prot_data
=
1522 src
->app_tag
= cpu_to_be16(0xDEAD);
1523 phba
->lpfc_injerr_wapp_cnt
--;
1524 if (phba
->lpfc_injerr_wapp_cnt
== 0) {
1525 phba
->lpfc_injerr_nportid
= 0;
1526 phba
->lpfc_injerr_lba
=
1527 LPFC_INJERR_LBA_OFF
;
1528 memset(&phba
->lpfc_injerr_wwpn
,
1529 0, sizeof(struct lpfc_name
));
1531 rc
= BG_ERR_TGT
| BG_ERR_CHECK
;
1535 case SCSI_PROT_WRITE_INSERT
:
1537 * For WRITE_INSERT, force the
1538 * error to be sent on the wire. It should be
1539 * detected by the Target.
1541 /* DEAD will be the apptag on the wire */
1543 phba
->lpfc_injerr_wapp_cnt
--;
1544 if (phba
->lpfc_injerr_wapp_cnt
== 0) {
1545 phba
->lpfc_injerr_nportid
= 0;
1546 phba
->lpfc_injerr_lba
=
1547 LPFC_INJERR_LBA_OFF
;
1548 memset(&phba
->lpfc_injerr_wwpn
,
1549 0, sizeof(struct lpfc_name
));
1551 rc
= BG_ERR_TGT
| BG_ERR_CHECK
;
1553 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1554 "0813 BLKGRD: Injecting apptag error: "
1555 "write lba x%lx\n", (unsigned long)lba
);
1557 case SCSI_PROT_WRITE_STRIP
:
1559 * For WRITE_STRIP and WRITE_PASS,
1560 * force the error on data
1561 * being copied from SLI-Host to SLI-Port.
1564 phba
->lpfc_injerr_wapp_cnt
--;
1565 if (phba
->lpfc_injerr_wapp_cnt
== 0) {
1566 phba
->lpfc_injerr_nportid
= 0;
1567 phba
->lpfc_injerr_lba
=
1568 LPFC_INJERR_LBA_OFF
;
1569 memset(&phba
->lpfc_injerr_wwpn
,
1570 0, sizeof(struct lpfc_name
));
1574 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1575 "0812 BLKGRD: Injecting apptag error: "
1576 "write lba x%lx\n", (unsigned long)lba
);
1580 if (phba
->lpfc_injerr_rapp_cnt
) {
1582 case SCSI_PROT_READ_INSERT
:
1583 case SCSI_PROT_READ_STRIP
:
1584 case SCSI_PROT_READ_PASS
:
1586 * For READ_STRIP and READ_PASS, force the
1587 * error on data being read off the wire. It
1588 * should force an IO error to the driver.
1591 phba
->lpfc_injerr_rapp_cnt
--;
1592 if (phba
->lpfc_injerr_rapp_cnt
== 0) {
1593 phba
->lpfc_injerr_nportid
= 0;
1594 phba
->lpfc_injerr_lba
=
1595 LPFC_INJERR_LBA_OFF
;
1596 memset(&phba
->lpfc_injerr_wwpn
,
1597 0, sizeof(struct lpfc_name
));
1601 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1602 "0814 BLKGRD: Injecting apptag error: "
1603 "read lba x%lx\n", (unsigned long)lba
);
1610 /* Should we change the Guard Tag */
1612 if (phba
->lpfc_injerr_wgrd_cnt
) {
1614 case SCSI_PROT_WRITE_PASS
:
1618 case SCSI_PROT_WRITE_INSERT
:
1620 * For WRITE_INSERT, force the
1621 * error to be sent on the wire. It should be
1622 * detected by the Target.
1624 phba
->lpfc_injerr_wgrd_cnt
--;
1625 if (phba
->lpfc_injerr_wgrd_cnt
== 0) {
1626 phba
->lpfc_injerr_nportid
= 0;
1627 phba
->lpfc_injerr_lba
=
1628 LPFC_INJERR_LBA_OFF
;
1629 memset(&phba
->lpfc_injerr_wwpn
,
1630 0, sizeof(struct lpfc_name
));
1633 rc
|= BG_ERR_TGT
| BG_ERR_SWAP
;
1634 /* Signals the caller to swap CRC->CSUM */
1636 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1637 "0817 BLKGRD: Injecting guard error: "
1638 "write lba x%lx\n", (unsigned long)lba
);
1640 case SCSI_PROT_WRITE_STRIP
:
1642 * For WRITE_STRIP and WRITE_PASS,
1643 * force the error on data
1644 * being copied from SLI-Host to SLI-Port.
1646 phba
->lpfc_injerr_wgrd_cnt
--;
1647 if (phba
->lpfc_injerr_wgrd_cnt
== 0) {
1648 phba
->lpfc_injerr_nportid
= 0;
1649 phba
->lpfc_injerr_lba
=
1650 LPFC_INJERR_LBA_OFF
;
1651 memset(&phba
->lpfc_injerr_wwpn
,
1652 0, sizeof(struct lpfc_name
));
1655 rc
= BG_ERR_INIT
| BG_ERR_SWAP
;
1656 /* Signals the caller to swap CRC->CSUM */
1658 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1659 "0816 BLKGRD: Injecting guard error: "
1660 "write lba x%lx\n", (unsigned long)lba
);
1664 if (phba
->lpfc_injerr_rgrd_cnt
) {
1666 case SCSI_PROT_READ_INSERT
:
1667 case SCSI_PROT_READ_STRIP
:
1668 case SCSI_PROT_READ_PASS
:
1670 * For READ_STRIP and READ_PASS, force the
1671 * error on data being read off the wire. It
1672 * should force an IO error to the driver.
1674 phba
->lpfc_injerr_rgrd_cnt
--;
1675 if (phba
->lpfc_injerr_rgrd_cnt
== 0) {
1676 phba
->lpfc_injerr_nportid
= 0;
1677 phba
->lpfc_injerr_lba
=
1678 LPFC_INJERR_LBA_OFF
;
1679 memset(&phba
->lpfc_injerr_wwpn
,
1680 0, sizeof(struct lpfc_name
));
1683 rc
= BG_ERR_INIT
| BG_ERR_SWAP
;
1684 /* Signals the caller to swap CRC->CSUM */
1686 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1687 "0818 BLKGRD: Injecting guard error: "
1688 "read lba x%lx\n", (unsigned long)lba
);
1698 * lpfc_sc_to_bg_opcodes - Determine the BlockGuard opcodes to be used with
1699 * the specified SCSI command.
1700 * @phba: The Hba for which this call is being executed.
1701 * @sc: The SCSI command to examine
1702 * @txopt: (out) BlockGuard operation for transmitted data
1703 * @rxopt: (out) BlockGuard operation for received data
1705 * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
1709 lpfc_sc_to_bg_opcodes(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
1710 uint8_t *txop
, uint8_t *rxop
)
1714 if (lpfc_cmd_guard_csum(sc
)) {
1715 switch (scsi_get_prot_op(sc
)) {
1716 case SCSI_PROT_READ_INSERT
:
1717 case SCSI_PROT_WRITE_STRIP
:
1718 *rxop
= BG_OP_IN_NODIF_OUT_CSUM
;
1719 *txop
= BG_OP_IN_CSUM_OUT_NODIF
;
1722 case SCSI_PROT_READ_STRIP
:
1723 case SCSI_PROT_WRITE_INSERT
:
1724 *rxop
= BG_OP_IN_CRC_OUT_NODIF
;
1725 *txop
= BG_OP_IN_NODIF_OUT_CRC
;
1728 case SCSI_PROT_READ_PASS
:
1729 case SCSI_PROT_WRITE_PASS
:
1730 *rxop
= BG_OP_IN_CRC_OUT_CSUM
;
1731 *txop
= BG_OP_IN_CSUM_OUT_CRC
;
1734 case SCSI_PROT_NORMAL
:
1736 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1737 "9063 BLKGRD: Bad op/guard:%d/IP combination\n",
1738 scsi_get_prot_op(sc
));
1744 switch (scsi_get_prot_op(sc
)) {
1745 case SCSI_PROT_READ_STRIP
:
1746 case SCSI_PROT_WRITE_INSERT
:
1747 *rxop
= BG_OP_IN_CRC_OUT_NODIF
;
1748 *txop
= BG_OP_IN_NODIF_OUT_CRC
;
1751 case SCSI_PROT_READ_PASS
:
1752 case SCSI_PROT_WRITE_PASS
:
1753 *rxop
= BG_OP_IN_CRC_OUT_CRC
;
1754 *txop
= BG_OP_IN_CRC_OUT_CRC
;
1757 case SCSI_PROT_READ_INSERT
:
1758 case SCSI_PROT_WRITE_STRIP
:
1759 *rxop
= BG_OP_IN_NODIF_OUT_CRC
;
1760 *txop
= BG_OP_IN_CRC_OUT_NODIF
;
1763 case SCSI_PROT_NORMAL
:
1765 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
1766 "9075 BLKGRD: Bad op/guard:%d/CRC combination\n",
1767 scsi_get_prot_op(sc
));
1776 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1778 * lpfc_bg_err_opcodes - reDetermine the BlockGuard opcodes to be used with
1779 * the specified SCSI command in order to force a guard tag error.
1780 * @phba: The Hba for which this call is being executed.
1781 * @sc: The SCSI command to examine
1782 * @txopt: (out) BlockGuard operation for transmitted data
1783 * @rxopt: (out) BlockGuard operation for received data
1785 * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
1789 lpfc_bg_err_opcodes(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
1790 uint8_t *txop
, uint8_t *rxop
)
1794 if (lpfc_cmd_guard_csum(sc
)) {
1795 switch (scsi_get_prot_op(sc
)) {
1796 case SCSI_PROT_READ_INSERT
:
1797 case SCSI_PROT_WRITE_STRIP
:
1798 *rxop
= BG_OP_IN_NODIF_OUT_CRC
;
1799 *txop
= BG_OP_IN_CRC_OUT_NODIF
;
1802 case SCSI_PROT_READ_STRIP
:
1803 case SCSI_PROT_WRITE_INSERT
:
1804 *rxop
= BG_OP_IN_CSUM_OUT_NODIF
;
1805 *txop
= BG_OP_IN_NODIF_OUT_CSUM
;
1808 case SCSI_PROT_READ_PASS
:
1809 case SCSI_PROT_WRITE_PASS
:
1810 *rxop
= BG_OP_IN_CSUM_OUT_CRC
;
1811 *txop
= BG_OP_IN_CRC_OUT_CSUM
;
1814 case SCSI_PROT_NORMAL
:
1820 switch (scsi_get_prot_op(sc
)) {
1821 case SCSI_PROT_READ_STRIP
:
1822 case SCSI_PROT_WRITE_INSERT
:
1823 *rxop
= BG_OP_IN_CSUM_OUT_NODIF
;
1824 *txop
= BG_OP_IN_NODIF_OUT_CSUM
;
1827 case SCSI_PROT_READ_PASS
:
1828 case SCSI_PROT_WRITE_PASS
:
1829 *rxop
= BG_OP_IN_CSUM_OUT_CSUM
;
1830 *txop
= BG_OP_IN_CSUM_OUT_CSUM
;
1833 case SCSI_PROT_READ_INSERT
:
1834 case SCSI_PROT_WRITE_STRIP
:
1835 *rxop
= BG_OP_IN_NODIF_OUT_CSUM
;
1836 *txop
= BG_OP_IN_CSUM_OUT_NODIF
;
1839 case SCSI_PROT_NORMAL
:
1850 * lpfc_bg_setup_bpl - Setup BlockGuard BPL with no protection data
1851 * @phba: The Hba for which this call is being executed.
1852 * @sc: pointer to scsi command we're working on
1853 * @bpl: pointer to buffer list for protection groups
1854 * @datacnt: number of segments of data that have been dma mapped
1856 * This function sets up BPL buffer list for protection groups of
1857 * type LPFC_PG_TYPE_NO_DIF
1859 * This is usually used when the HBA is instructed to generate
1860 * DIFs and insert them into data stream (or strip DIF from
1861 * incoming data stream)
1863 * The buffer list consists of just one protection group described
1865 * +-------------------------+
1866 * start of prot group --> | PDE_5 |
1867 * +-------------------------+
1869 * +-------------------------+
1871 * +-------------------------+
1872 * |more Data BDE's ... (opt)|
1873 * +-------------------------+
1876 * Note: Data s/g buffers have been dma mapped
1878 * Returns the number of BDEs added to the BPL.
1881 lpfc_bg_setup_bpl(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
1882 struct ulp_bde64
*bpl
, int datasegcnt
)
1884 struct scatterlist
*sgde
= NULL
; /* s/g data entry */
1885 struct lpfc_pde5
*pde5
= NULL
;
1886 struct lpfc_pde6
*pde6
= NULL
;
1887 dma_addr_t physaddr
;
1888 int i
= 0, num_bde
= 0, status
;
1889 int datadir
= sc
->sc_data_direction
;
1890 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1893 uint32_t checking
= 1;
1897 status
= lpfc_sc_to_bg_opcodes(phba
, sc
, &txop
, &rxop
);
1901 /* extract some info from the scsi command for pde*/
1902 reftag
= (uint32_t)scsi_get_lba(sc
); /* Truncate LBA */
1904 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1905 rc
= lpfc_bg_err_inject(phba
, sc
, &reftag
, NULL
, 1);
1907 if (rc
& BG_ERR_SWAP
)
1908 lpfc_bg_err_opcodes(phba
, sc
, &txop
, &rxop
);
1909 if (rc
& BG_ERR_CHECK
)
1914 /* setup PDE5 with what we have */
1915 pde5
= (struct lpfc_pde5
*) bpl
;
1916 memset(pde5
, 0, sizeof(struct lpfc_pde5
));
1917 bf_set(pde5_type
, pde5
, LPFC_PDE5_DESCRIPTOR
);
1919 /* Endianness conversion if necessary for PDE5 */
1920 pde5
->word0
= cpu_to_le32(pde5
->word0
);
1921 pde5
->reftag
= cpu_to_le32(reftag
);
1923 /* advance bpl and increment bde count */
1926 pde6
= (struct lpfc_pde6
*) bpl
;
1928 /* setup PDE6 with the rest of the info */
1929 memset(pde6
, 0, sizeof(struct lpfc_pde6
));
1930 bf_set(pde6_type
, pde6
, LPFC_PDE6_DESCRIPTOR
);
1931 bf_set(pde6_optx
, pde6
, txop
);
1932 bf_set(pde6_oprx
, pde6
, rxop
);
1935 * We only need to check the data on READs, for WRITEs
1936 * protection data is automatically generated, not checked.
1938 if (datadir
== DMA_FROM_DEVICE
) {
1939 if (lpfc_cmd_protect(sc
, LPFC_CHECK_PROTECT_GUARD
))
1940 bf_set(pde6_ce
, pde6
, checking
);
1942 bf_set(pde6_ce
, pde6
, 0);
1944 if (lpfc_cmd_protect(sc
, LPFC_CHECK_PROTECT_REF
))
1945 bf_set(pde6_re
, pde6
, checking
);
1947 bf_set(pde6_re
, pde6
, 0);
1949 bf_set(pde6_ai
, pde6
, 1);
1950 bf_set(pde6_ae
, pde6
, 0);
1951 bf_set(pde6_apptagval
, pde6
, 0);
1953 /* Endianness conversion if necessary for PDE6 */
1954 pde6
->word0
= cpu_to_le32(pde6
->word0
);
1955 pde6
->word1
= cpu_to_le32(pde6
->word1
);
1956 pde6
->word2
= cpu_to_le32(pde6
->word2
);
1958 /* advance bpl and increment bde count */
1962 /* assumption: caller has already run dma_map_sg on command data */
1963 scsi_for_each_sg(sc
, sgde
, datasegcnt
, i
) {
1964 physaddr
= sg_dma_address(sgde
);
1965 bpl
->addrLow
= le32_to_cpu(putPaddrLow(physaddr
));
1966 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(physaddr
));
1967 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgde
);
1968 if (datadir
== DMA_TO_DEVICE
)
1969 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
1971 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
1972 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
1982 * lpfc_bg_setup_bpl_prot - Setup BlockGuard BPL with protection data
1983 * @phba: The Hba for which this call is being executed.
1984 * @sc: pointer to scsi command we're working on
1985 * @bpl: pointer to buffer list for protection groups
1986 * @datacnt: number of segments of data that have been dma mapped
1987 * @protcnt: number of segment of protection data that have been dma mapped
1989 * This function sets up BPL buffer list for protection groups of
1990 * type LPFC_PG_TYPE_DIF
1992 * This is usually used when DIFs are in their own buffers,
1993 * separate from the data. The HBA can then by instructed
1994 * to place the DIFs in the outgoing stream. For read operations,
1995 * The HBA could extract the DIFs and place it in DIF buffers.
1997 * The buffer list for this type consists of one or more of the
1998 * protection groups described below:
1999 * +-------------------------+
2000 * start of first prot group --> | PDE_5 |
2001 * +-------------------------+
2003 * +-------------------------+
2004 * | PDE_7 (Prot BDE) |
2005 * +-------------------------+
2007 * +-------------------------+
2008 * |more Data BDE's ... (opt)|
2009 * +-------------------------+
2010 * start of new prot group --> | PDE_5 |
2011 * +-------------------------+
2013 * +-------------------------+
2015 * Note: It is assumed that both data and protection s/g buffers have been
2018 * Returns the number of BDEs added to the BPL.
2021 lpfc_bg_setup_bpl_prot(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
2022 struct ulp_bde64
*bpl
, int datacnt
, int protcnt
)
2024 struct scatterlist
*sgde
= NULL
; /* s/g data entry */
2025 struct scatterlist
*sgpe
= NULL
; /* s/g prot entry */
2026 struct lpfc_pde5
*pde5
= NULL
;
2027 struct lpfc_pde6
*pde6
= NULL
;
2028 struct lpfc_pde7
*pde7
= NULL
;
2029 dma_addr_t dataphysaddr
, protphysaddr
;
2030 unsigned short curr_data
= 0, curr_prot
= 0;
2031 unsigned int split_offset
;
2032 unsigned int protgroup_len
, protgroup_offset
= 0, protgroup_remainder
;
2033 unsigned int protgrp_blks
, protgrp_bytes
;
2034 unsigned int remainder
, subtotal
;
2036 int datadir
= sc
->sc_data_direction
;
2037 unsigned char pgdone
= 0, alldone
= 0;
2039 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2042 uint32_t checking
= 1;
2047 sgpe
= scsi_prot_sglist(sc
);
2048 sgde
= scsi_sglist(sc
);
2050 if (!sgpe
|| !sgde
) {
2051 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
2052 "9020 Invalid s/g entry: data=0x%p prot=0x%p\n",
2057 status
= lpfc_sc_to_bg_opcodes(phba
, sc
, &txop
, &rxop
);
2061 /* extract some info from the scsi command */
2062 blksize
= lpfc_cmd_blksize(sc
);
2063 reftag
= (uint32_t)scsi_get_lba(sc
); /* Truncate LBA */
2065 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2066 rc
= lpfc_bg_err_inject(phba
, sc
, &reftag
, NULL
, 1);
2068 if (rc
& BG_ERR_SWAP
)
2069 lpfc_bg_err_opcodes(phba
, sc
, &txop
, &rxop
);
2070 if (rc
& BG_ERR_CHECK
)
2077 /* Check to see if we ran out of space */
2078 if (num_bde
>= (phba
->cfg_total_seg_cnt
- 2))
2081 /* setup PDE5 with what we have */
2082 pde5
= (struct lpfc_pde5
*) bpl
;
2083 memset(pde5
, 0, sizeof(struct lpfc_pde5
));
2084 bf_set(pde5_type
, pde5
, LPFC_PDE5_DESCRIPTOR
);
2086 /* Endianness conversion if necessary for PDE5 */
2087 pde5
->word0
= cpu_to_le32(pde5
->word0
);
2088 pde5
->reftag
= cpu_to_le32(reftag
);
2090 /* advance bpl and increment bde count */
2093 pde6
= (struct lpfc_pde6
*) bpl
;
2095 /* setup PDE6 with the rest of the info */
2096 memset(pde6
, 0, sizeof(struct lpfc_pde6
));
2097 bf_set(pde6_type
, pde6
, LPFC_PDE6_DESCRIPTOR
);
2098 bf_set(pde6_optx
, pde6
, txop
);
2099 bf_set(pde6_oprx
, pde6
, rxop
);
2101 if (lpfc_cmd_protect(sc
, LPFC_CHECK_PROTECT_GUARD
))
2102 bf_set(pde6_ce
, pde6
, checking
);
2104 bf_set(pde6_ce
, pde6
, 0);
2106 if (lpfc_cmd_protect(sc
, LPFC_CHECK_PROTECT_REF
))
2107 bf_set(pde6_re
, pde6
, checking
);
2109 bf_set(pde6_re
, pde6
, 0);
2111 bf_set(pde6_ai
, pde6
, 1);
2112 bf_set(pde6_ae
, pde6
, 0);
2113 bf_set(pde6_apptagval
, pde6
, 0);
2115 /* Endianness conversion if necessary for PDE6 */
2116 pde6
->word0
= cpu_to_le32(pde6
->word0
);
2117 pde6
->word1
= cpu_to_le32(pde6
->word1
);
2118 pde6
->word2
= cpu_to_le32(pde6
->word2
);
2120 /* advance bpl and increment bde count */
2124 /* setup the first BDE that points to protection buffer */
2125 protphysaddr
= sg_dma_address(sgpe
) + protgroup_offset
;
2126 protgroup_len
= sg_dma_len(sgpe
) - protgroup_offset
;
2128 /* must be integer multiple of the DIF block length */
2129 BUG_ON(protgroup_len
% 8);
2131 pde7
= (struct lpfc_pde7
*) bpl
;
2132 memset(pde7
, 0, sizeof(struct lpfc_pde7
));
2133 bf_set(pde7_type
, pde7
, LPFC_PDE7_DESCRIPTOR
);
2135 pde7
->addrHigh
= le32_to_cpu(putPaddrHigh(protphysaddr
));
2136 pde7
->addrLow
= le32_to_cpu(putPaddrLow(protphysaddr
));
2138 protgrp_blks
= protgroup_len
/ 8;
2139 protgrp_bytes
= protgrp_blks
* blksize
;
2141 /* check if this pde is crossing the 4K boundary; if so split */
2142 if ((pde7
->addrLow
& 0xfff) + protgroup_len
> 0x1000) {
2143 protgroup_remainder
= 0x1000 - (pde7
->addrLow
& 0xfff);
2144 protgroup_offset
+= protgroup_remainder
;
2145 protgrp_blks
= protgroup_remainder
/ 8;
2146 protgrp_bytes
= protgrp_blks
* blksize
;
2148 protgroup_offset
= 0;
2154 /* setup BDE's for data blocks associated with DIF data */
2156 subtotal
= 0; /* total bytes processed for current prot grp */
2158 /* Check to see if we ran out of space */
2159 if (num_bde
>= phba
->cfg_total_seg_cnt
)
2163 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2164 "9065 BLKGRD:%s Invalid data segment\n",
2169 dataphysaddr
= sg_dma_address(sgde
) + split_offset
;
2170 bpl
->addrLow
= le32_to_cpu(putPaddrLow(dataphysaddr
));
2171 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(dataphysaddr
));
2173 remainder
= sg_dma_len(sgde
) - split_offset
;
2175 if ((subtotal
+ remainder
) <= protgrp_bytes
) {
2176 /* we can use this whole buffer */
2177 bpl
->tus
.f
.bdeSize
= remainder
;
2180 if ((subtotal
+ remainder
) == protgrp_bytes
)
2183 /* must split this buffer with next prot grp */
2184 bpl
->tus
.f
.bdeSize
= protgrp_bytes
- subtotal
;
2185 split_offset
+= bpl
->tus
.f
.bdeSize
;
2188 subtotal
+= bpl
->tus
.f
.bdeSize
;
2190 if (datadir
== DMA_TO_DEVICE
)
2191 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
2193 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
2194 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
2202 /* Move to the next s/g segment if possible */
2203 sgde
= sg_next(sgde
);
2207 if (protgroup_offset
) {
2208 /* update the reference tag */
2209 reftag
+= protgrp_blks
;
2215 if (curr_prot
== protcnt
) {
2217 } else if (curr_prot
< protcnt
) {
2218 /* advance to next prot buffer */
2219 sgpe
= sg_next(sgpe
);
2222 /* update the reference tag */
2223 reftag
+= protgrp_blks
;
2225 /* if we're here, we have a bug */
2226 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2227 "9054 BLKGRD: bug in %s\n", __func__
);
2237 * lpfc_bg_setup_sgl - Setup BlockGuard SGL with no protection data
2238 * @phba: The Hba for which this call is being executed.
2239 * @sc: pointer to scsi command we're working on
2240 * @sgl: pointer to buffer list for protection groups
2241 * @datacnt: number of segments of data that have been dma mapped
2243 * This function sets up SGL buffer list for protection groups of
2244 * type LPFC_PG_TYPE_NO_DIF
2246 * This is usually used when the HBA is instructed to generate
2247 * DIFs and insert them into data stream (or strip DIF from
2248 * incoming data stream)
2250 * The buffer list consists of just one protection group described
2252 * +-------------------------+
2253 * start of prot group --> | DI_SEED |
2254 * +-------------------------+
2256 * +-------------------------+
2257 * |more Data SGE's ... (opt)|
2258 * +-------------------------+
2261 * Note: Data s/g buffers have been dma mapped
2263 * Returns the number of SGEs added to the SGL.
2266 lpfc_bg_setup_sgl(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
2267 struct sli4_sge
*sgl
, int datasegcnt
)
2269 struct scatterlist
*sgde
= NULL
; /* s/g data entry */
2270 struct sli4_sge_diseed
*diseed
= NULL
;
2271 dma_addr_t physaddr
;
2272 int i
= 0, num_sge
= 0, status
;
2275 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2278 uint32_t checking
= 1;
2280 uint32_t dma_offset
= 0;
2282 status
= lpfc_sc_to_bg_opcodes(phba
, sc
, &txop
, &rxop
);
2286 /* extract some info from the scsi command for pde*/
2287 reftag
= (uint32_t)scsi_get_lba(sc
); /* Truncate LBA */
2289 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2290 rc
= lpfc_bg_err_inject(phba
, sc
, &reftag
, NULL
, 1);
2292 if (rc
& BG_ERR_SWAP
)
2293 lpfc_bg_err_opcodes(phba
, sc
, &txop
, &rxop
);
2294 if (rc
& BG_ERR_CHECK
)
2299 /* setup DISEED with what we have */
2300 diseed
= (struct sli4_sge_diseed
*) sgl
;
2301 memset(diseed
, 0, sizeof(struct sli4_sge_diseed
));
2302 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DISEED
);
2304 /* Endianness conversion if necessary */
2305 diseed
->ref_tag
= cpu_to_le32(reftag
);
2306 diseed
->ref_tag_tran
= diseed
->ref_tag
;
2309 * We only need to check the data on READs, for WRITEs
2310 * protection data is automatically generated, not checked.
2312 if (sc
->sc_data_direction
== DMA_FROM_DEVICE
) {
2313 if (lpfc_cmd_protect(sc
, LPFC_CHECK_PROTECT_GUARD
))
2314 bf_set(lpfc_sli4_sge_dif_ce
, diseed
, checking
);
2316 bf_set(lpfc_sli4_sge_dif_ce
, diseed
, 0);
2318 if (lpfc_cmd_protect(sc
, LPFC_CHECK_PROTECT_REF
))
2319 bf_set(lpfc_sli4_sge_dif_re
, diseed
, checking
);
2321 bf_set(lpfc_sli4_sge_dif_re
, diseed
, 0);
2324 /* setup DISEED with the rest of the info */
2325 bf_set(lpfc_sli4_sge_dif_optx
, diseed
, txop
);
2326 bf_set(lpfc_sli4_sge_dif_oprx
, diseed
, rxop
);
2328 bf_set(lpfc_sli4_sge_dif_ai
, diseed
, 1);
2329 bf_set(lpfc_sli4_sge_dif_me
, diseed
, 0);
2331 /* Endianness conversion if necessary for DISEED */
2332 diseed
->word2
= cpu_to_le32(diseed
->word2
);
2333 diseed
->word3
= cpu_to_le32(diseed
->word3
);
2335 /* advance bpl and increment sge count */
2339 /* assumption: caller has already run dma_map_sg on command data */
2340 scsi_for_each_sg(sc
, sgde
, datasegcnt
, i
) {
2341 physaddr
= sg_dma_address(sgde
);
2342 dma_len
= sg_dma_len(sgde
);
2343 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(physaddr
));
2344 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(physaddr
));
2345 if ((i
+ 1) == datasegcnt
)
2346 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
2348 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
2349 bf_set(lpfc_sli4_sge_offset
, sgl
, dma_offset
);
2350 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DATA
);
2352 sgl
->sge_len
= cpu_to_le32(dma_len
);
2353 dma_offset
+= dma_len
;
2364 * lpfc_bg_setup_sgl_prot - Setup BlockGuard SGL with protection data
2365 * @phba: The Hba for which this call is being executed.
2366 * @sc: pointer to scsi command we're working on
2367 * @sgl: pointer to buffer list for protection groups
2368 * @datacnt: number of segments of data that have been dma mapped
2369 * @protcnt: number of segment of protection data that have been dma mapped
2371 * This function sets up SGL buffer list for protection groups of
2372 * type LPFC_PG_TYPE_DIF
2374 * This is usually used when DIFs are in their own buffers,
2375 * separate from the data. The HBA can then by instructed
2376 * to place the DIFs in the outgoing stream. For read operations,
2377 * The HBA could extract the DIFs and place it in DIF buffers.
2379 * The buffer list for this type consists of one or more of the
2380 * protection groups described below:
2381 * +-------------------------+
2382 * start of first prot group --> | DISEED |
2383 * +-------------------------+
2384 * | DIF (Prot SGE) |
2385 * +-------------------------+
2387 * +-------------------------+
2388 * |more Data SGE's ... (opt)|
2389 * +-------------------------+
2390 * start of new prot group --> | DISEED |
2391 * +-------------------------+
2393 * +-------------------------+
2395 * Note: It is assumed that both data and protection s/g buffers have been
2398 * Returns the number of SGEs added to the SGL.
2401 lpfc_bg_setup_sgl_prot(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
2402 struct sli4_sge
*sgl
, int datacnt
, int protcnt
)
2404 struct scatterlist
*sgde
= NULL
; /* s/g data entry */
2405 struct scatterlist
*sgpe
= NULL
; /* s/g prot entry */
2406 struct sli4_sge_diseed
*diseed
= NULL
;
2407 dma_addr_t dataphysaddr
, protphysaddr
;
2408 unsigned short curr_data
= 0, curr_prot
= 0;
2409 unsigned int split_offset
;
2410 unsigned int protgroup_len
, protgroup_offset
= 0, protgroup_remainder
;
2411 unsigned int protgrp_blks
, protgrp_bytes
;
2412 unsigned int remainder
, subtotal
;
2414 unsigned char pgdone
= 0, alldone
= 0;
2419 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2422 uint32_t checking
= 1;
2423 uint32_t dma_offset
= 0;
2426 sgpe
= scsi_prot_sglist(sc
);
2427 sgde
= scsi_sglist(sc
);
2429 if (!sgpe
|| !sgde
) {
2430 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
2431 "9082 Invalid s/g entry: data=0x%p prot=0x%p\n",
2436 status
= lpfc_sc_to_bg_opcodes(phba
, sc
, &txop
, &rxop
);
2440 /* extract some info from the scsi command */
2441 blksize
= lpfc_cmd_blksize(sc
);
2442 reftag
= (uint32_t)scsi_get_lba(sc
); /* Truncate LBA */
2444 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2445 rc
= lpfc_bg_err_inject(phba
, sc
, &reftag
, NULL
, 1);
2447 if (rc
& BG_ERR_SWAP
)
2448 lpfc_bg_err_opcodes(phba
, sc
, &txop
, &rxop
);
2449 if (rc
& BG_ERR_CHECK
)
2456 /* Check to see if we ran out of space */
2457 if (num_sge
>= (phba
->cfg_total_seg_cnt
- 2))
2460 /* setup DISEED with what we have */
2461 diseed
= (struct sli4_sge_diseed
*) sgl
;
2462 memset(diseed
, 0, sizeof(struct sli4_sge_diseed
));
2463 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DISEED
);
2465 /* Endianness conversion if necessary */
2466 diseed
->ref_tag
= cpu_to_le32(reftag
);
2467 diseed
->ref_tag_tran
= diseed
->ref_tag
;
2469 if (lpfc_cmd_protect(sc
, LPFC_CHECK_PROTECT_GUARD
)) {
2470 bf_set(lpfc_sli4_sge_dif_ce
, diseed
, checking
);
2473 bf_set(lpfc_sli4_sge_dif_ce
, diseed
, 0);
2475 * When in this mode, the hardware will replace
2476 * the guard tag from the host with a
2477 * newly generated good CRC for the wire.
2478 * Switch to raw mode here to avoid this
2479 * behavior. What the host sends gets put on the wire.
2481 if (txop
== BG_OP_IN_CRC_OUT_CRC
) {
2482 txop
= BG_OP_RAW_MODE
;
2483 rxop
= BG_OP_RAW_MODE
;
2488 if (lpfc_cmd_protect(sc
, LPFC_CHECK_PROTECT_REF
))
2489 bf_set(lpfc_sli4_sge_dif_re
, diseed
, checking
);
2491 bf_set(lpfc_sli4_sge_dif_re
, diseed
, 0);
2493 /* setup DISEED with the rest of the info */
2494 bf_set(lpfc_sli4_sge_dif_optx
, diseed
, txop
);
2495 bf_set(lpfc_sli4_sge_dif_oprx
, diseed
, rxop
);
2497 bf_set(lpfc_sli4_sge_dif_ai
, diseed
, 1);
2498 bf_set(lpfc_sli4_sge_dif_me
, diseed
, 0);
2500 /* Endianness conversion if necessary for DISEED */
2501 diseed
->word2
= cpu_to_le32(diseed
->word2
);
2502 diseed
->word3
= cpu_to_le32(diseed
->word3
);
2504 /* advance sgl and increment bde count */
2508 /* setup the first BDE that points to protection buffer */
2509 protphysaddr
= sg_dma_address(sgpe
) + protgroup_offset
;
2510 protgroup_len
= sg_dma_len(sgpe
) - protgroup_offset
;
2512 /* must be integer multiple of the DIF block length */
2513 BUG_ON(protgroup_len
% 8);
2515 /* Now setup DIF SGE */
2517 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DIF
);
2518 sgl
->addr_hi
= le32_to_cpu(putPaddrHigh(protphysaddr
));
2519 sgl
->addr_lo
= le32_to_cpu(putPaddrLow(protphysaddr
));
2520 sgl
->word2
= cpu_to_le32(sgl
->word2
);
2522 protgrp_blks
= protgroup_len
/ 8;
2523 protgrp_bytes
= protgrp_blks
* blksize
;
2525 /* check if DIF SGE is crossing the 4K boundary; if so split */
2526 if ((sgl
->addr_lo
& 0xfff) + protgroup_len
> 0x1000) {
2527 protgroup_remainder
= 0x1000 - (sgl
->addr_lo
& 0xfff);
2528 protgroup_offset
+= protgroup_remainder
;
2529 protgrp_blks
= protgroup_remainder
/ 8;
2530 protgrp_bytes
= protgrp_blks
* blksize
;
2532 protgroup_offset
= 0;
2538 /* setup SGE's for data blocks associated with DIF data */
2540 subtotal
= 0; /* total bytes processed for current prot grp */
2542 /* Check to see if we ran out of space */
2543 if (num_sge
>= phba
->cfg_total_seg_cnt
)
2547 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2548 "9086 BLKGRD:%s Invalid data segment\n",
2553 dataphysaddr
= sg_dma_address(sgde
) + split_offset
;
2555 remainder
= sg_dma_len(sgde
) - split_offset
;
2557 if ((subtotal
+ remainder
) <= protgrp_bytes
) {
2558 /* we can use this whole buffer */
2559 dma_len
= remainder
;
2562 if ((subtotal
+ remainder
) == protgrp_bytes
)
2565 /* must split this buffer with next prot grp */
2566 dma_len
= protgrp_bytes
- subtotal
;
2567 split_offset
+= dma_len
;
2570 subtotal
+= dma_len
;
2572 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(dataphysaddr
));
2573 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(dataphysaddr
));
2574 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
2575 bf_set(lpfc_sli4_sge_offset
, sgl
, dma_offset
);
2576 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DATA
);
2578 sgl
->sge_len
= cpu_to_le32(dma_len
);
2579 dma_offset
+= dma_len
;
2587 /* Move to the next s/g segment if possible */
2588 sgde
= sg_next(sgde
);
2591 if (protgroup_offset
) {
2592 /* update the reference tag */
2593 reftag
+= protgrp_blks
;
2599 if (curr_prot
== protcnt
) {
2600 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
2602 } else if (curr_prot
< protcnt
) {
2603 /* advance to next prot buffer */
2604 sgpe
= sg_next(sgpe
);
2607 /* update the reference tag */
2608 reftag
+= protgrp_blks
;
2610 /* if we're here, we have a bug */
2611 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
2612 "9085 BLKGRD: bug in %s\n", __func__
);
2623 * lpfc_prot_group_type - Get prtotection group type of SCSI command
2624 * @phba: The Hba for which this call is being executed.
2625 * @sc: pointer to scsi command we're working on
2627 * Given a SCSI command that supports DIF, determine composition of protection
2628 * groups involved in setting up buffer lists
2630 * Returns: Protection group type (with or without DIF)
2634 lpfc_prot_group_type(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
)
2636 int ret
= LPFC_PG_TYPE_INVALID
;
2637 unsigned char op
= scsi_get_prot_op(sc
);
2640 case SCSI_PROT_READ_STRIP
:
2641 case SCSI_PROT_WRITE_INSERT
:
2642 ret
= LPFC_PG_TYPE_NO_DIF
;
2644 case SCSI_PROT_READ_INSERT
:
2645 case SCSI_PROT_WRITE_STRIP
:
2646 case SCSI_PROT_READ_PASS
:
2647 case SCSI_PROT_WRITE_PASS
:
2648 ret
= LPFC_PG_TYPE_DIF_BUF
;
2652 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
2653 "9021 Unsupported protection op:%d\n",
2661 * lpfc_bg_scsi_adjust_dl - Adjust SCSI data length for BlockGuard
2662 * @phba: The Hba for which this call is being executed.
2663 * @lpfc_cmd: The scsi buffer which is going to be adjusted.
2665 * Adjust the data length to account for how much data
2666 * is actually on the wire.
2668 * returns the adjusted data length
2671 lpfc_bg_scsi_adjust_dl(struct lpfc_hba
*phba
,
2672 struct lpfc_scsi_buf
*lpfc_cmd
)
2674 struct scsi_cmnd
*sc
= lpfc_cmd
->pCmd
;
2677 fcpdl
= scsi_bufflen(sc
);
2679 /* Check if there is protection data on the wire */
2680 if (sc
->sc_data_direction
== DMA_FROM_DEVICE
) {
2681 /* Read check for protection data */
2682 if (scsi_get_prot_op(sc
) == SCSI_PROT_READ_INSERT
)
2686 /* Write check for protection data */
2687 if (scsi_get_prot_op(sc
) == SCSI_PROT_WRITE_STRIP
)
2692 * If we are in DIF Type 1 mode every data block has a 8 byte
2693 * DIF (trailer) attached to it. Must ajust FCP data length
2694 * to account for the protection data.
2696 fcpdl
+= (fcpdl
/ lpfc_cmd_blksize(sc
)) * 8;
2702 * lpfc_bg_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
2703 * @phba: The Hba for which this call is being executed.
2704 * @lpfc_cmd: The scsi buffer which is going to be prep'ed.
2706 * This is the protection/DIF aware version of
2707 * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the
2708 * two functions eventually, but for now, it's here
2711 lpfc_bg_scsi_prep_dma_buf_s3(struct lpfc_hba
*phba
,
2712 struct lpfc_scsi_buf
*lpfc_cmd
)
2714 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
2715 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
2716 struct ulp_bde64
*bpl
= lpfc_cmd
->fcp_bpl
;
2717 IOCB_t
*iocb_cmd
= &lpfc_cmd
->cur_iocbq
.iocb
;
2718 uint32_t num_bde
= 0;
2719 int datasegcnt
, protsegcnt
, datadir
= scsi_cmnd
->sc_data_direction
;
2720 int prot_group_type
= 0;
2724 * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd
2725 * fcp_rsp regions to the first data bde entry
2728 if (scsi_sg_count(scsi_cmnd
)) {
2730 * The driver stores the segment count returned from pci_map_sg
2731 * because this a count of dma-mappings used to map the use_sg
2732 * pages. They are not guaranteed to be the same for those
2733 * architectures that implement an IOMMU.
2735 datasegcnt
= dma_map_sg(&phba
->pcidev
->dev
,
2736 scsi_sglist(scsi_cmnd
),
2737 scsi_sg_count(scsi_cmnd
), datadir
);
2738 if (unlikely(!datasegcnt
))
2741 lpfc_cmd
->seg_cnt
= datasegcnt
;
2743 /* First check if data segment count from SCSI Layer is good */
2744 if (lpfc_cmd
->seg_cnt
> phba
->cfg_sg_seg_cnt
)
2747 prot_group_type
= lpfc_prot_group_type(phba
, scsi_cmnd
);
2749 switch (prot_group_type
) {
2750 case LPFC_PG_TYPE_NO_DIF
:
2752 /* Here we need to add a PDE5 and PDE6 to the count */
2753 if ((lpfc_cmd
->seg_cnt
+ 2) > phba
->cfg_total_seg_cnt
)
2756 num_bde
= lpfc_bg_setup_bpl(phba
, scsi_cmnd
, bpl
,
2758 /* we should have 2 or more entries in buffer list */
2763 case LPFC_PG_TYPE_DIF_BUF
:
2765 * This type indicates that protection buffers are
2766 * passed to the driver, so that needs to be prepared
2769 protsegcnt
= dma_map_sg(&phba
->pcidev
->dev
,
2770 scsi_prot_sglist(scsi_cmnd
),
2771 scsi_prot_sg_count(scsi_cmnd
), datadir
);
2772 if (unlikely(!protsegcnt
)) {
2773 scsi_dma_unmap(scsi_cmnd
);
2777 lpfc_cmd
->prot_seg_cnt
= protsegcnt
;
2780 * There is a minimun of 4 BPLs used for every
2781 * protection data segment.
2783 if ((lpfc_cmd
->prot_seg_cnt
* 4) >
2784 (phba
->cfg_total_seg_cnt
- 2))
2787 num_bde
= lpfc_bg_setup_bpl_prot(phba
, scsi_cmnd
, bpl
,
2788 datasegcnt
, protsegcnt
);
2789 /* we should have 3 or more entries in buffer list */
2790 if ((num_bde
< 3) ||
2791 (num_bde
> phba
->cfg_total_seg_cnt
))
2795 case LPFC_PG_TYPE_INVALID
:
2797 scsi_dma_unmap(scsi_cmnd
);
2798 lpfc_cmd
->seg_cnt
= 0;
2800 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
2801 "9022 Unexpected protection group %i\n",
2808 * Finish initializing those IOCB fields that are dependent on the
2809 * scsi_cmnd request_buffer. Note that the bdeSize is explicitly
2810 * reinitialized since all iocb memory resources are used many times
2811 * for transmit, receive, and continuation bpl's.
2813 iocb_cmd
->un
.fcpi64
.bdl
.bdeSize
= (2 * sizeof(struct ulp_bde64
));
2814 iocb_cmd
->un
.fcpi64
.bdl
.bdeSize
+= (num_bde
* sizeof(struct ulp_bde64
));
2815 iocb_cmd
->ulpBdeCount
= 1;
2816 iocb_cmd
->ulpLe
= 1;
2818 fcpdl
= lpfc_bg_scsi_adjust_dl(phba
, lpfc_cmd
);
2819 fcp_cmnd
->fcpDl
= be32_to_cpu(fcpdl
);
2822 * Due to difference in data length between DIF/non-DIF paths,
2823 * we need to set word 4 of IOCB here
2825 iocb_cmd
->un
.fcpi
.fcpi_parm
= fcpdl
;
2829 if (lpfc_cmd
->seg_cnt
)
2830 scsi_dma_unmap(scsi_cmnd
);
2831 if (lpfc_cmd
->prot_seg_cnt
)
2832 dma_unmap_sg(&phba
->pcidev
->dev
, scsi_prot_sglist(scsi_cmnd
),
2833 scsi_prot_sg_count(scsi_cmnd
),
2834 scsi_cmnd
->sc_data_direction
);
2836 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
2837 "9023 Cannot setup S/G List for HBA"
2838 "IO segs %d/%d BPL %d SCSI %d: %d %d\n",
2839 lpfc_cmd
->seg_cnt
, lpfc_cmd
->prot_seg_cnt
,
2840 phba
->cfg_total_seg_cnt
, phba
->cfg_sg_seg_cnt
,
2841 prot_group_type
, num_bde
);
2843 lpfc_cmd
->seg_cnt
= 0;
2844 lpfc_cmd
->prot_seg_cnt
= 0;
2849 * This function calcuates the T10 DIF guard tag
2850 * on the specified data using a CRC algorithmn
2854 lpfc_bg_crc(uint8_t *data
, int count
)
2859 crc
= crc_t10dif(data
, count
);
2860 x
= cpu_to_be16(crc
);
2865 * This function calcuates the T10 DIF guard tag
2866 * on the specified data using a CSUM algorithmn
2867 * using ip_compute_csum.
2870 lpfc_bg_csum(uint8_t *data
, int count
)
2874 ret
= ip_compute_csum(data
, count
);
2879 * This function examines the protection data to try to determine
2880 * what type of T10-DIF error occurred.
2883 lpfc_calc_bg_err(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
)
2885 struct scatterlist
*sgpe
; /* s/g prot entry */
2886 struct scatterlist
*sgde
; /* s/g data entry */
2887 struct scsi_cmnd
*cmd
= lpfc_cmd
->pCmd
;
2888 struct scsi_dif_tuple
*src
= NULL
;
2889 uint8_t *data_src
= NULL
;
2891 uint16_t start_app_tag
, app_tag
;
2892 uint32_t start_ref_tag
, ref_tag
;
2893 int prot
, protsegcnt
;
2894 int err_type
, len
, data_len
;
2895 int chk_ref
, chk_app
, chk_guard
;
2899 err_type
= BGS_GUARD_ERR_MASK
;
2903 /* First check to see if there is protection data to examine */
2904 prot
= scsi_get_prot_op(cmd
);
2905 if ((prot
== SCSI_PROT_READ_STRIP
) ||
2906 (prot
== SCSI_PROT_WRITE_INSERT
) ||
2907 (prot
== SCSI_PROT_NORMAL
))
2910 /* Currently the driver just supports ref_tag and guard_tag checking */
2915 /* Setup a ptr to the protection data provided by the SCSI host */
2916 sgpe
= scsi_prot_sglist(cmd
);
2917 protsegcnt
= lpfc_cmd
->prot_seg_cnt
;
2919 if (sgpe
&& protsegcnt
) {
2922 * We will only try to verify guard tag if the segment
2923 * data length is a multiple of the blksize.
2925 sgde
= scsi_sglist(cmd
);
2926 blksize
= lpfc_cmd_blksize(cmd
);
2927 data_src
= (uint8_t *)sg_virt(sgde
);
2928 data_len
= sgde
->length
;
2929 if ((data_len
& (blksize
- 1)) == 0)
2932 src
= (struct scsi_dif_tuple
*)sg_virt(sgpe
);
2933 start_ref_tag
= (uint32_t)scsi_get_lba(cmd
); /* Truncate LBA */
2934 start_app_tag
= src
->app_tag
;
2936 while (src
&& protsegcnt
) {
2940 * First check to see if a protection data
2943 if ((src
->ref_tag
== T10_PI_REF_ESCAPE
) ||
2944 (src
->app_tag
== T10_PI_APP_ESCAPE
)) {
2949 /* First Guard Tag checking */
2951 guard_tag
= src
->guard_tag
;
2952 if (lpfc_cmd_guard_csum(cmd
))
2953 sum
= lpfc_bg_csum(data_src
,
2956 sum
= lpfc_bg_crc(data_src
,
2958 if ((guard_tag
!= sum
)) {
2959 err_type
= BGS_GUARD_ERR_MASK
;
2964 /* Reference Tag checking */
2965 ref_tag
= be32_to_cpu(src
->ref_tag
);
2966 if (chk_ref
&& (ref_tag
!= start_ref_tag
)) {
2967 err_type
= BGS_REFTAG_ERR_MASK
;
2972 /* App Tag checking */
2973 app_tag
= src
->app_tag
;
2974 if (chk_app
&& (app_tag
!= start_app_tag
)) {
2975 err_type
= BGS_APPTAG_ERR_MASK
;
2979 len
-= sizeof(struct scsi_dif_tuple
);
2984 data_src
+= blksize
;
2985 data_len
-= blksize
;
2988 * Are we at the end of the Data segment?
2989 * The data segment is only used for Guard
2992 if (chk_guard
&& (data_len
== 0)) {
2994 sgde
= sg_next(sgde
);
2998 data_src
= (uint8_t *)sg_virt(sgde
);
2999 data_len
= sgde
->length
;
3000 if ((data_len
& (blksize
- 1)) == 0)
3005 /* Goto the next Protection data segment */
3006 sgpe
= sg_next(sgpe
);
3008 src
= (struct scsi_dif_tuple
*)sg_virt(sgpe
);
3017 if (err_type
== BGS_GUARD_ERR_MASK
) {
3018 scsi_build_sense_buffer(1, cmd
->sense_buffer
, ILLEGAL_REQUEST
,
3020 cmd
->result
= DRIVER_SENSE
<< 24
3021 | ScsiResult(DID_ABORT
, SAM_STAT_CHECK_CONDITION
);
3022 phba
->bg_guard_err_cnt
++;
3023 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FCP
| LOG_BG
,
3024 "9069 BLKGRD: LBA %lx grd_tag error %x != %x\n",
3025 (unsigned long)scsi_get_lba(cmd
),
3028 } else if (err_type
== BGS_REFTAG_ERR_MASK
) {
3029 scsi_build_sense_buffer(1, cmd
->sense_buffer
, ILLEGAL_REQUEST
,
3031 cmd
->result
= DRIVER_SENSE
<< 24
3032 | ScsiResult(DID_ABORT
, SAM_STAT_CHECK_CONDITION
);
3034 phba
->bg_reftag_err_cnt
++;
3035 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FCP
| LOG_BG
,
3036 "9066 BLKGRD: LBA %lx ref_tag error %x != %x\n",
3037 (unsigned long)scsi_get_lba(cmd
),
3038 ref_tag
, start_ref_tag
);
3040 } else if (err_type
== BGS_APPTAG_ERR_MASK
) {
3041 scsi_build_sense_buffer(1, cmd
->sense_buffer
, ILLEGAL_REQUEST
,
3043 cmd
->result
= DRIVER_SENSE
<< 24
3044 | ScsiResult(DID_ABORT
, SAM_STAT_CHECK_CONDITION
);
3046 phba
->bg_apptag_err_cnt
++;
3047 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FCP
| LOG_BG
,
3048 "9041 BLKGRD: LBA %lx app_tag error %x != %x\n",
3049 (unsigned long)scsi_get_lba(cmd
),
3050 app_tag
, start_app_tag
);
3056 * This function checks for BlockGuard errors detected by
3057 * the HBA. In case of errors, the ASC/ASCQ fields in the
3058 * sense buffer will be set accordingly, paired with
3059 * ILLEGAL_REQUEST to signal to the kernel that the HBA
3060 * detected corruption.
3063 * 0 - No error found
3064 * 1 - BlockGuard error found
3065 * -1 - Internal error (bad profile, ...etc)
3068 lpfc_parse_bg_err(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
,
3069 struct lpfc_iocbq
*pIocbOut
)
3071 struct scsi_cmnd
*cmd
= lpfc_cmd
->pCmd
;
3072 struct sli3_bg_fields
*bgf
= &pIocbOut
->iocb
.unsli3
.sli3_bg
;
3074 uint32_t bghm
= bgf
->bghm
;
3075 uint32_t bgstat
= bgf
->bgstat
;
3076 uint64_t failing_sector
= 0;
3078 spin_lock(&_dump_buf_lock
);
3079 if (!_dump_buf_done
) {
3080 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
, "9070 BLKGRD: Saving"
3081 " Data for %u blocks to debugfs\n",
3082 (cmd
->cmnd
[7] << 8 | cmd
->cmnd
[8]));
3083 lpfc_debug_save_data(phba
, cmd
);
3085 /* If we have a prot sgl, save the DIF buffer */
3086 if (lpfc_prot_group_type(phba
, cmd
) ==
3087 LPFC_PG_TYPE_DIF_BUF
) {
3088 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
, "9071 BLKGRD: "
3089 "Saving DIF for %u blocks to debugfs\n",
3090 (cmd
->cmnd
[7] << 8 | cmd
->cmnd
[8]));
3091 lpfc_debug_save_dif(phba
, cmd
);
3096 spin_unlock(&_dump_buf_lock
);
3098 if (lpfc_bgs_get_invalid_prof(bgstat
)) {
3099 cmd
->result
= ScsiResult(DID_ERROR
, 0);
3100 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FCP
| LOG_BG
,
3101 "9072 BLKGRD: Invalid BG Profile in cmd"
3102 " 0x%x lba 0x%llx blk cnt 0x%x "
3103 "bgstat=x%x bghm=x%x\n", cmd
->cmnd
[0],
3104 (unsigned long long)scsi_get_lba(cmd
),
3105 blk_rq_sectors(cmd
->request
), bgstat
, bghm
);
3110 if (lpfc_bgs_get_uninit_dif_block(bgstat
)) {
3111 cmd
->result
= ScsiResult(DID_ERROR
, 0);
3112 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FCP
| LOG_BG
,
3113 "9073 BLKGRD: Invalid BG PDIF Block in cmd"
3114 " 0x%x lba 0x%llx blk cnt 0x%x "
3115 "bgstat=x%x bghm=x%x\n", cmd
->cmnd
[0],
3116 (unsigned long long)scsi_get_lba(cmd
),
3117 blk_rq_sectors(cmd
->request
), bgstat
, bghm
);
3122 if (lpfc_bgs_get_guard_err(bgstat
)) {
3125 scsi_build_sense_buffer(1, cmd
->sense_buffer
, ILLEGAL_REQUEST
,
3127 cmd
->result
= DRIVER_SENSE
<< 24
3128 | ScsiResult(DID_ABORT
, SAM_STAT_CHECK_CONDITION
);
3129 phba
->bg_guard_err_cnt
++;
3130 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FCP
| LOG_BG
,
3131 "9055 BLKGRD: Guard Tag error in cmd"
3132 " 0x%x lba 0x%llx blk cnt 0x%x "
3133 "bgstat=x%x bghm=x%x\n", cmd
->cmnd
[0],
3134 (unsigned long long)scsi_get_lba(cmd
),
3135 blk_rq_sectors(cmd
->request
), bgstat
, bghm
);
3138 if (lpfc_bgs_get_reftag_err(bgstat
)) {
3141 scsi_build_sense_buffer(1, cmd
->sense_buffer
, ILLEGAL_REQUEST
,
3143 cmd
->result
= DRIVER_SENSE
<< 24
3144 | ScsiResult(DID_ABORT
, SAM_STAT_CHECK_CONDITION
);
3146 phba
->bg_reftag_err_cnt
++;
3147 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FCP
| LOG_BG
,
3148 "9056 BLKGRD: Ref Tag error in cmd"
3149 " 0x%x lba 0x%llx blk cnt 0x%x "
3150 "bgstat=x%x bghm=x%x\n", cmd
->cmnd
[0],
3151 (unsigned long long)scsi_get_lba(cmd
),
3152 blk_rq_sectors(cmd
->request
), bgstat
, bghm
);
3155 if (lpfc_bgs_get_apptag_err(bgstat
)) {
3158 scsi_build_sense_buffer(1, cmd
->sense_buffer
, ILLEGAL_REQUEST
,
3160 cmd
->result
= DRIVER_SENSE
<< 24
3161 | ScsiResult(DID_ABORT
, SAM_STAT_CHECK_CONDITION
);
3163 phba
->bg_apptag_err_cnt
++;
3164 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FCP
| LOG_BG
,
3165 "9061 BLKGRD: App Tag error in cmd"
3166 " 0x%x lba 0x%llx blk cnt 0x%x "
3167 "bgstat=x%x bghm=x%x\n", cmd
->cmnd
[0],
3168 (unsigned long long)scsi_get_lba(cmd
),
3169 blk_rq_sectors(cmd
->request
), bgstat
, bghm
);
3172 if (lpfc_bgs_get_hi_water_mark_present(bgstat
)) {
3174 * setup sense data descriptor 0 per SPC-4 as an information
3175 * field, and put the failing LBA in it.
3176 * This code assumes there was also a guard/app/ref tag error
3179 cmd
->sense_buffer
[7] = 0xc; /* Additional sense length */
3180 cmd
->sense_buffer
[8] = 0; /* Information descriptor type */
3181 cmd
->sense_buffer
[9] = 0xa; /* Additional descriptor length */
3182 cmd
->sense_buffer
[10] = 0x80; /* Validity bit */
3184 /* bghm is a "on the wire" FC frame based count */
3185 switch (scsi_get_prot_op(cmd
)) {
3186 case SCSI_PROT_READ_INSERT
:
3187 case SCSI_PROT_WRITE_STRIP
:
3188 bghm
/= cmd
->device
->sector_size
;
3190 case SCSI_PROT_READ_STRIP
:
3191 case SCSI_PROT_WRITE_INSERT
:
3192 case SCSI_PROT_READ_PASS
:
3193 case SCSI_PROT_WRITE_PASS
:
3194 bghm
/= (cmd
->device
->sector_size
+
3195 sizeof(struct scsi_dif_tuple
));
3199 failing_sector
= scsi_get_lba(cmd
);
3200 failing_sector
+= bghm
;
3202 /* Descriptor Information */
3203 put_unaligned_be64(failing_sector
, &cmd
->sense_buffer
[12]);
3207 /* No error was reported - problem in FW? */
3208 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FCP
| LOG_BG
,
3209 "9057 BLKGRD: Unknown error in cmd"
3210 " 0x%x lba 0x%llx blk cnt 0x%x "
3211 "bgstat=x%x bghm=x%x\n", cmd
->cmnd
[0],
3212 (unsigned long long)scsi_get_lba(cmd
),
3213 blk_rq_sectors(cmd
->request
), bgstat
, bghm
);
3215 /* Calcuate what type of error it was */
3216 lpfc_calc_bg_err(phba
, lpfc_cmd
);
3223 * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
3224 * @phba: The Hba for which this call is being executed.
3225 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3227 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
3228 * field of @lpfc_cmd for device with SLI-4 interface spec.
3235 lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
)
3237 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
3238 struct scatterlist
*sgel
= NULL
;
3239 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
3240 struct sli4_sge
*sgl
= (struct sli4_sge
*)lpfc_cmd
->fcp_bpl
;
3241 struct sli4_sge
*first_data_sgl
;
3242 IOCB_t
*iocb_cmd
= &lpfc_cmd
->cur_iocbq
.iocb
;
3243 dma_addr_t physaddr
;
3244 uint32_t num_bde
= 0;
3246 uint32_t dma_offset
= 0;
3248 struct ulp_bde64
*bde
;
3251 * There are three possibilities here - use scatter-gather segment, use
3252 * the single mapping, or neither. Start the lpfc command prep by
3253 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
3256 if (scsi_sg_count(scsi_cmnd
)) {
3258 * The driver stores the segment count returned from pci_map_sg
3259 * because this a count of dma-mappings used to map the use_sg
3260 * pages. They are not guaranteed to be the same for those
3261 * architectures that implement an IOMMU.
3264 nseg
= scsi_dma_map(scsi_cmnd
);
3265 if (unlikely(nseg
<= 0))
3268 /* clear the last flag in the fcp_rsp map entry */
3269 sgl
->word2
= le32_to_cpu(sgl
->word2
);
3270 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
3271 sgl
->word2
= cpu_to_le32(sgl
->word2
);
3273 first_data_sgl
= sgl
;
3274 lpfc_cmd
->seg_cnt
= nseg
;
3275 if (lpfc_cmd
->seg_cnt
> phba
->cfg_sg_seg_cnt
) {
3276 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
, "9074 BLKGRD:"
3277 " %s: Too many sg segments from "
3278 "dma_map_sg. Config %d, seg_cnt %d\n",
3279 __func__
, phba
->cfg_sg_seg_cnt
,
3281 lpfc_cmd
->seg_cnt
= 0;
3282 scsi_dma_unmap(scsi_cmnd
);
3287 * The driver established a maximum scatter-gather segment count
3288 * during probe that limits the number of sg elements in any
3289 * single scsi command. Just run through the seg_cnt and format
3291 * When using SLI-3 the driver will try to fit all the BDEs into
3292 * the IOCB. If it can't then the BDEs get added to a BPL as it
3293 * does for SLI-2 mode.
3295 scsi_for_each_sg(scsi_cmnd
, sgel
, nseg
, num_bde
) {
3296 physaddr
= sg_dma_address(sgel
);
3297 dma_len
= sg_dma_len(sgel
);
3298 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(physaddr
));
3299 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(physaddr
));
3300 sgl
->word2
= le32_to_cpu(sgl
->word2
);
3301 if ((num_bde
+ 1) == nseg
)
3302 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
3304 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
3305 bf_set(lpfc_sli4_sge_offset
, sgl
, dma_offset
);
3306 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DATA
);
3307 sgl
->word2
= cpu_to_le32(sgl
->word2
);
3308 sgl
->sge_len
= cpu_to_le32(dma_len
);
3309 dma_offset
+= dma_len
;
3313 * Setup the first Payload BDE. For FCoE we just key off
3314 * Performance Hints, for FC we utilize fcp_embed_pbde.
3316 if ((phba
->sli3_options
& LPFC_SLI4_PERFH_ENABLED
) ||
3317 phba
->fcp_embed_pbde
) {
3318 bde
= (struct ulp_bde64
*)
3319 &(iocb_cmd
->unsli3
.sli3Words
[5]);
3320 bde
->addrLow
= first_data_sgl
->addr_lo
;
3321 bde
->addrHigh
= first_data_sgl
->addr_hi
;
3322 bde
->tus
.f
.bdeSize
=
3323 le32_to_cpu(first_data_sgl
->sge_len
);
3324 bde
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
3325 bde
->tus
.w
= cpu_to_le32(bde
->tus
.w
);
3329 /* clear the last flag in the fcp_rsp map entry */
3330 sgl
->word2
= le32_to_cpu(sgl
->word2
);
3331 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
3332 sgl
->word2
= cpu_to_le32(sgl
->word2
);
3336 * Finish initializing those IOCB fields that are dependent on the
3337 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
3338 * explicitly reinitialized.
3339 * all iocb memory resources are reused.
3341 fcp_cmnd
->fcpDl
= cpu_to_be32(scsi_bufflen(scsi_cmnd
));
3344 * Due to difference in data length between DIF/non-DIF paths,
3345 * we need to set word 4 of IOCB here
3347 iocb_cmd
->un
.fcpi
.fcpi_parm
= scsi_bufflen(scsi_cmnd
);
3350 * If the OAS driver feature is enabled and the lun is enabled for
3351 * OAS, set the oas iocb related flags.
3353 if ((phba
->cfg_fof
) && ((struct lpfc_device_data
*)
3354 scsi_cmnd
->device
->hostdata
)->oas_enabled
) {
3355 lpfc_cmd
->cur_iocbq
.iocb_flag
|= (LPFC_IO_OAS
| LPFC_IO_FOF
);
3356 lpfc_cmd
->cur_iocbq
.priority
= ((struct lpfc_device_data
*)
3357 scsi_cmnd
->device
->hostdata
)->priority
;
3363 * lpfc_bg_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
3364 * @phba: The Hba for which this call is being executed.
3365 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3367 * This is the protection/DIF aware version of
3368 * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the
3369 * two functions eventually, but for now, it's here
3372 lpfc_bg_scsi_prep_dma_buf_s4(struct lpfc_hba
*phba
,
3373 struct lpfc_scsi_buf
*lpfc_cmd
)
3375 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
3376 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
3377 struct sli4_sge
*sgl
= (struct sli4_sge
*)(lpfc_cmd
->fcp_bpl
);
3378 IOCB_t
*iocb_cmd
= &lpfc_cmd
->cur_iocbq
.iocb
;
3379 uint32_t num_sge
= 0;
3380 int datasegcnt
, protsegcnt
, datadir
= scsi_cmnd
->sc_data_direction
;
3381 int prot_group_type
= 0;
3385 * Start the lpfc command prep by bumping the sgl beyond fcp_cmnd
3386 * fcp_rsp regions to the first data sge entry
3388 if (scsi_sg_count(scsi_cmnd
)) {
3390 * The driver stores the segment count returned from pci_map_sg
3391 * because this a count of dma-mappings used to map the use_sg
3392 * pages. They are not guaranteed to be the same for those
3393 * architectures that implement an IOMMU.
3395 datasegcnt
= dma_map_sg(&phba
->pcidev
->dev
,
3396 scsi_sglist(scsi_cmnd
),
3397 scsi_sg_count(scsi_cmnd
), datadir
);
3398 if (unlikely(!datasegcnt
))
3402 /* clear the last flag in the fcp_rsp map entry */
3403 sgl
->word2
= le32_to_cpu(sgl
->word2
);
3404 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
3405 sgl
->word2
= cpu_to_le32(sgl
->word2
);
3408 lpfc_cmd
->seg_cnt
= datasegcnt
;
3410 /* First check if data segment count from SCSI Layer is good */
3411 if (lpfc_cmd
->seg_cnt
> phba
->cfg_sg_seg_cnt
)
3414 prot_group_type
= lpfc_prot_group_type(phba
, scsi_cmnd
);
3416 switch (prot_group_type
) {
3417 case LPFC_PG_TYPE_NO_DIF
:
3418 /* Here we need to add a DISEED to the count */
3419 if ((lpfc_cmd
->seg_cnt
+ 1) > phba
->cfg_total_seg_cnt
)
3422 num_sge
= lpfc_bg_setup_sgl(phba
, scsi_cmnd
, sgl
,
3425 /* we should have 2 or more entries in buffer list */
3430 case LPFC_PG_TYPE_DIF_BUF
:
3432 * This type indicates that protection buffers are
3433 * passed to the driver, so that needs to be prepared
3436 protsegcnt
= dma_map_sg(&phba
->pcidev
->dev
,
3437 scsi_prot_sglist(scsi_cmnd
),
3438 scsi_prot_sg_count(scsi_cmnd
), datadir
);
3439 if (unlikely(!protsegcnt
)) {
3440 scsi_dma_unmap(scsi_cmnd
);
3444 lpfc_cmd
->prot_seg_cnt
= protsegcnt
;
3446 * There is a minimun of 3 SGEs used for every
3447 * protection data segment.
3449 if ((lpfc_cmd
->prot_seg_cnt
* 3) >
3450 (phba
->cfg_total_seg_cnt
- 2))
3453 num_sge
= lpfc_bg_setup_sgl_prot(phba
, scsi_cmnd
, sgl
,
3454 datasegcnt
, protsegcnt
);
3456 /* we should have 3 or more entries in buffer list */
3457 if ((num_sge
< 3) ||
3458 (num_sge
> phba
->cfg_total_seg_cnt
))
3462 case LPFC_PG_TYPE_INVALID
:
3464 scsi_dma_unmap(scsi_cmnd
);
3465 lpfc_cmd
->seg_cnt
= 0;
3467 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
3468 "9083 Unexpected protection group %i\n",
3474 switch (scsi_get_prot_op(scsi_cmnd
)) {
3475 case SCSI_PROT_WRITE_STRIP
:
3476 case SCSI_PROT_READ_STRIP
:
3477 lpfc_cmd
->cur_iocbq
.iocb_flag
|= LPFC_IO_DIF_STRIP
;
3479 case SCSI_PROT_WRITE_INSERT
:
3480 case SCSI_PROT_READ_INSERT
:
3481 lpfc_cmd
->cur_iocbq
.iocb_flag
|= LPFC_IO_DIF_INSERT
;
3483 case SCSI_PROT_WRITE_PASS
:
3484 case SCSI_PROT_READ_PASS
:
3485 lpfc_cmd
->cur_iocbq
.iocb_flag
|= LPFC_IO_DIF_PASS
;
3489 fcpdl
= lpfc_bg_scsi_adjust_dl(phba
, lpfc_cmd
);
3490 fcp_cmnd
->fcpDl
= be32_to_cpu(fcpdl
);
3493 * Due to difference in data length between DIF/non-DIF paths,
3494 * we need to set word 4 of IOCB here
3496 iocb_cmd
->un
.fcpi
.fcpi_parm
= fcpdl
;
3499 * If the OAS driver feature is enabled and the lun is enabled for
3500 * OAS, set the oas iocb related flags.
3502 if ((phba
->cfg_fof
) && ((struct lpfc_device_data
*)
3503 scsi_cmnd
->device
->hostdata
)->oas_enabled
)
3504 lpfc_cmd
->cur_iocbq
.iocb_flag
|= (LPFC_IO_OAS
| LPFC_IO_FOF
);
3508 if (lpfc_cmd
->seg_cnt
)
3509 scsi_dma_unmap(scsi_cmnd
);
3510 if (lpfc_cmd
->prot_seg_cnt
)
3511 dma_unmap_sg(&phba
->pcidev
->dev
, scsi_prot_sglist(scsi_cmnd
),
3512 scsi_prot_sg_count(scsi_cmnd
),
3513 scsi_cmnd
->sc_data_direction
);
3515 lpfc_printf_log(phba
, KERN_ERR
, LOG_FCP
,
3516 "9084 Cannot setup S/G List for HBA"
3517 "IO segs %d/%d SGL %d SCSI %d: %d %d\n",
3518 lpfc_cmd
->seg_cnt
, lpfc_cmd
->prot_seg_cnt
,
3519 phba
->cfg_total_seg_cnt
, phba
->cfg_sg_seg_cnt
,
3520 prot_group_type
, num_sge
);
3522 lpfc_cmd
->seg_cnt
= 0;
3523 lpfc_cmd
->prot_seg_cnt
= 0;
3528 * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
3529 * @phba: The Hba for which this call is being executed.
3530 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3532 * This routine wraps the actual DMA mapping function pointer from the
3540 lpfc_scsi_prep_dma_buf(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
)
3542 return phba
->lpfc_scsi_prep_dma_buf(phba
, lpfc_cmd
);
3546 * lpfc_bg_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
3548 * @phba: The Hba for which this call is being executed.
3549 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3551 * This routine wraps the actual DMA mapping function pointer from the
3559 lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*lpfc_cmd
)
3561 return phba
->lpfc_bg_scsi_prep_dma_buf(phba
, lpfc_cmd
);
3565 * lpfc_send_scsi_error_event - Posts an event when there is SCSI error
3566 * @phba: Pointer to hba context object.
3567 * @vport: Pointer to vport object.
3568 * @lpfc_cmd: Pointer to lpfc scsi command which reported the error.
3569 * @rsp_iocb: Pointer to response iocb object which reported error.
3571 * This function posts an event when there is a SCSI command reporting
3572 * error from the scsi device.
3575 lpfc_send_scsi_error_event(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
,
3576 struct lpfc_scsi_buf
*lpfc_cmd
, struct lpfc_iocbq
*rsp_iocb
) {
3577 struct scsi_cmnd
*cmnd
= lpfc_cmd
->pCmd
;
3578 struct fcp_rsp
*fcprsp
= lpfc_cmd
->fcp_rsp
;
3579 uint32_t resp_info
= fcprsp
->rspStatus2
;
3580 uint32_t scsi_status
= fcprsp
->rspStatus3
;
3581 uint32_t fcpi_parm
= rsp_iocb
->iocb
.un
.fcpi
.fcpi_parm
;
3582 struct lpfc_fast_path_event
*fast_path_evt
= NULL
;
3583 struct lpfc_nodelist
*pnode
= lpfc_cmd
->rdata
->pnode
;
3584 unsigned long flags
;
3586 if (!pnode
|| !NLP_CHK_NODE_ACT(pnode
))
3589 /* If there is queuefull or busy condition send a scsi event */
3590 if ((cmnd
->result
== SAM_STAT_TASK_SET_FULL
) ||
3591 (cmnd
->result
== SAM_STAT_BUSY
)) {
3592 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
3595 fast_path_evt
->un
.scsi_evt
.event_type
=
3597 fast_path_evt
->un
.scsi_evt
.subcategory
=
3598 (cmnd
->result
== SAM_STAT_TASK_SET_FULL
) ?
3599 LPFC_EVENT_QFULL
: LPFC_EVENT_DEVBSY
;
3600 fast_path_evt
->un
.scsi_evt
.lun
= cmnd
->device
->lun
;
3601 memcpy(&fast_path_evt
->un
.scsi_evt
.wwpn
,
3602 &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
3603 memcpy(&fast_path_evt
->un
.scsi_evt
.wwnn
,
3604 &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
3605 } else if ((resp_info
& SNS_LEN_VALID
) && fcprsp
->rspSnsLen
&&
3606 ((cmnd
->cmnd
[0] == READ_10
) || (cmnd
->cmnd
[0] == WRITE_10
))) {
3607 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
3610 fast_path_evt
->un
.check_cond_evt
.scsi_event
.event_type
=
3612 fast_path_evt
->un
.check_cond_evt
.scsi_event
.subcategory
=
3613 LPFC_EVENT_CHECK_COND
;
3614 fast_path_evt
->un
.check_cond_evt
.scsi_event
.lun
=
3616 memcpy(&fast_path_evt
->un
.check_cond_evt
.scsi_event
.wwpn
,
3617 &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
3618 memcpy(&fast_path_evt
->un
.check_cond_evt
.scsi_event
.wwnn
,
3619 &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
3620 fast_path_evt
->un
.check_cond_evt
.sense_key
=
3621 cmnd
->sense_buffer
[2] & 0xf;
3622 fast_path_evt
->un
.check_cond_evt
.asc
= cmnd
->sense_buffer
[12];
3623 fast_path_evt
->un
.check_cond_evt
.ascq
= cmnd
->sense_buffer
[13];
3624 } else if ((cmnd
->sc_data_direction
== DMA_FROM_DEVICE
) &&
3626 ((be32_to_cpu(fcprsp
->rspResId
) != fcpi_parm
) ||
3627 ((scsi_status
== SAM_STAT_GOOD
) &&
3628 !(resp_info
& (RESID_UNDER
| RESID_OVER
))))) {
3630 * If status is good or resid does not match with fcp_param and
3631 * there is valid fcpi_parm, then there is a read_check error
3633 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
3636 fast_path_evt
->un
.read_check_error
.header
.event_type
=
3637 FC_REG_FABRIC_EVENT
;
3638 fast_path_evt
->un
.read_check_error
.header
.subcategory
=
3639 LPFC_EVENT_FCPRDCHKERR
;
3640 memcpy(&fast_path_evt
->un
.read_check_error
.header
.wwpn
,
3641 &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
3642 memcpy(&fast_path_evt
->un
.read_check_error
.header
.wwnn
,
3643 &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
3644 fast_path_evt
->un
.read_check_error
.lun
= cmnd
->device
->lun
;
3645 fast_path_evt
->un
.read_check_error
.opcode
= cmnd
->cmnd
[0];
3646 fast_path_evt
->un
.read_check_error
.fcpiparam
=
3651 fast_path_evt
->vport
= vport
;
3652 spin_lock_irqsave(&phba
->hbalock
, flags
);
3653 list_add_tail(&fast_path_evt
->work_evt
.evt_listp
, &phba
->work_list
);
3654 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
3655 lpfc_worker_wake_up(phba
);
3660 * lpfc_scsi_unprep_dma_buf - Un-map DMA mapping of SG-list for dev
3661 * @phba: The HBA for which this call is being executed.
3662 * @psb: The scsi buffer which is going to be un-mapped.
3664 * This routine does DMA un-mapping of scatter gather list of scsi command
3665 * field of @lpfc_cmd for device with SLI-3 interface spec.
3668 lpfc_scsi_unprep_dma_buf(struct lpfc_hba
*phba
, struct lpfc_scsi_buf
*psb
)
3671 * There are only two special cases to consider. (1) the scsi command
3672 * requested scatter-gather usage or (2) the scsi command allocated
3673 * a request buffer, but did not request use_sg. There is a third
3674 * case, but it does not require resource deallocation.
3676 if (psb
->seg_cnt
> 0)
3677 scsi_dma_unmap(psb
->pCmd
);
3678 if (psb
->prot_seg_cnt
> 0)
3679 dma_unmap_sg(&phba
->pcidev
->dev
, scsi_prot_sglist(psb
->pCmd
),
3680 scsi_prot_sg_count(psb
->pCmd
),
3681 psb
->pCmd
->sc_data_direction
);
3685 * lpfc_handler_fcp_err - FCP response handler
3686 * @vport: The virtual port for which this call is being executed.
3687 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
3688 * @rsp_iocb: The response IOCB which contains FCP error.
3690 * This routine is called to process response IOCB with status field
3691 * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command
3692 * based upon SCSI and FCP error.
3695 lpfc_handle_fcp_err(struct lpfc_vport
*vport
, struct lpfc_scsi_buf
*lpfc_cmd
,
3696 struct lpfc_iocbq
*rsp_iocb
)
3698 struct lpfc_hba
*phba
= vport
->phba
;
3699 struct scsi_cmnd
*cmnd
= lpfc_cmd
->pCmd
;
3700 struct fcp_cmnd
*fcpcmd
= lpfc_cmd
->fcp_cmnd
;
3701 struct fcp_rsp
*fcprsp
= lpfc_cmd
->fcp_rsp
;
3702 uint32_t fcpi_parm
= rsp_iocb
->iocb
.un
.fcpi
.fcpi_parm
;
3703 uint32_t resp_info
= fcprsp
->rspStatus2
;
3704 uint32_t scsi_status
= fcprsp
->rspStatus3
;
3706 uint32_t host_status
= DID_OK
;
3707 uint32_t rsplen
= 0;
3709 uint32_t logit
= LOG_FCP
| LOG_FCP_ERROR
;
3713 * If this is a task management command, there is no
3714 * scsi packet associated with this lpfc_cmd. The driver
3717 if (fcpcmd
->fcpCntl2
) {
3722 if (resp_info
& RSP_LEN_VALID
) {
3723 rsplen
= be32_to_cpu(fcprsp
->rspRspLen
);
3724 if (rsplen
!= 0 && rsplen
!= 4 && rsplen
!= 8) {
3725 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
3726 "2719 Invalid response length: "
3727 "tgt x%x lun x%llx cmnd x%x rsplen x%x\n",
3729 cmnd
->device
->lun
, cmnd
->cmnd
[0],
3731 host_status
= DID_ERROR
;
3734 if (fcprsp
->rspInfo3
!= RSP_NO_FAILURE
) {
3735 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
3736 "2757 Protocol failure detected during "
3737 "processing of FCP I/O op: "
3738 "tgt x%x lun x%llx cmnd x%x rspInfo3 x%x\n",
3740 cmnd
->device
->lun
, cmnd
->cmnd
[0],
3742 host_status
= DID_ERROR
;
3747 if ((resp_info
& SNS_LEN_VALID
) && fcprsp
->rspSnsLen
) {
3748 uint32_t snslen
= be32_to_cpu(fcprsp
->rspSnsLen
);
3749 if (snslen
> SCSI_SENSE_BUFFERSIZE
)
3750 snslen
= SCSI_SENSE_BUFFERSIZE
;
3752 if (resp_info
& RSP_LEN_VALID
)
3753 rsplen
= be32_to_cpu(fcprsp
->rspRspLen
);
3754 memcpy(cmnd
->sense_buffer
, &fcprsp
->rspInfo0
+ rsplen
, snslen
);
3756 lp
= (uint32_t *)cmnd
->sense_buffer
;
3758 /* special handling for under run conditions */
3759 if (!scsi_status
&& (resp_info
& RESID_UNDER
)) {
3760 /* don't log under runs if fcp set... */
3761 if (vport
->cfg_log_verbose
& LOG_FCP
)
3762 logit
= LOG_FCP_ERROR
;
3763 /* unless operator says so */
3764 if (vport
->cfg_log_verbose
& LOG_FCP_UNDER
)
3765 logit
= LOG_FCP_UNDER
;
3768 lpfc_printf_vlog(vport
, KERN_WARNING
, logit
,
3769 "9024 FCP command x%x failed: x%x SNS x%x x%x "
3770 "Data: x%x x%x x%x x%x x%x\n",
3771 cmnd
->cmnd
[0], scsi_status
,
3772 be32_to_cpu(*lp
), be32_to_cpu(*(lp
+ 3)), resp_info
,
3773 be32_to_cpu(fcprsp
->rspResId
),
3774 be32_to_cpu(fcprsp
->rspSnsLen
),
3775 be32_to_cpu(fcprsp
->rspRspLen
),
3778 scsi_set_resid(cmnd
, 0);
3779 fcpDl
= be32_to_cpu(fcpcmd
->fcpDl
);
3780 if (resp_info
& RESID_UNDER
) {
3781 scsi_set_resid(cmnd
, be32_to_cpu(fcprsp
->rspResId
));
3783 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP_UNDER
,
3784 "9025 FCP Underrun, expected %d, "
3785 "residual %d Data: x%x x%x x%x\n",
3787 scsi_get_resid(cmnd
), fcpi_parm
, cmnd
->cmnd
[0],
3791 * If there is an under run, check if under run reported by
3792 * storage array is same as the under run reported by HBA.
3793 * If this is not same, there is a dropped frame.
3795 if (fcpi_parm
&& (scsi_get_resid(cmnd
) != fcpi_parm
)) {
3796 lpfc_printf_vlog(vport
, KERN_WARNING
,
3797 LOG_FCP
| LOG_FCP_ERROR
,
3798 "9026 FCP Read Check Error "
3799 "and Underrun Data: x%x x%x x%x x%x\n",
3801 scsi_get_resid(cmnd
), fcpi_parm
,
3803 scsi_set_resid(cmnd
, scsi_bufflen(cmnd
));
3804 host_status
= DID_ERROR
;
3807 * The cmnd->underflow is the minimum number of bytes that must
3808 * be transferred for this command. Provided a sense condition
3809 * is not present, make sure the actual amount transferred is at
3810 * least the underflow value or fail.
3812 if (!(resp_info
& SNS_LEN_VALID
) &&
3813 (scsi_status
== SAM_STAT_GOOD
) &&
3814 (scsi_bufflen(cmnd
) - scsi_get_resid(cmnd
)
3815 < cmnd
->underflow
)) {
3816 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
3817 "9027 FCP command x%x residual "
3818 "underrun converted to error "
3819 "Data: x%x x%x x%x\n",
3820 cmnd
->cmnd
[0], scsi_bufflen(cmnd
),
3821 scsi_get_resid(cmnd
), cmnd
->underflow
);
3822 host_status
= DID_ERROR
;
3824 } else if (resp_info
& RESID_OVER
) {
3825 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
3826 "9028 FCP command x%x residual overrun error. "
3827 "Data: x%x x%x\n", cmnd
->cmnd
[0],
3828 scsi_bufflen(cmnd
), scsi_get_resid(cmnd
));
3829 host_status
= DID_ERROR
;
3832 * Check SLI validation that all the transfer was actually done
3833 * (fcpi_parm should be zero). Apply check only to reads.
3835 } else if (fcpi_parm
) {
3836 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
| LOG_FCP_ERROR
,
3837 "9029 FCP %s Check Error xri x%x Data: "
3838 "x%x x%x x%x x%x x%x\n",
3839 ((cmnd
->sc_data_direction
== DMA_FROM_DEVICE
) ?
3841 ((phba
->sli_rev
== LPFC_SLI_REV4
) ?
3842 lpfc_cmd
->cur_iocbq
.sli4_xritag
:
3843 rsp_iocb
->iocb
.ulpContext
),
3844 fcpDl
, be32_to_cpu(fcprsp
->rspResId
),
3845 fcpi_parm
, cmnd
->cmnd
[0], scsi_status
);
3847 /* There is some issue with the LPe12000 that causes it
3848 * to miscalculate the fcpi_parm and falsely trip this
3849 * recovery logic. Detect this case and don't error when true.
3851 if (fcpi_parm
> fcpDl
)
3854 switch (scsi_status
) {
3856 case SAM_STAT_CHECK_CONDITION
:
3857 /* Fabric dropped a data frame. Fail any successful
3858 * command in which we detected dropped frames.
3859 * A status of good or some check conditions could
3860 * be considered a successful command.
3862 host_status
= DID_ERROR
;
3865 scsi_set_resid(cmnd
, scsi_bufflen(cmnd
));
3869 cmnd
->result
= ScsiResult(host_status
, scsi_status
);
3870 lpfc_send_scsi_error_event(vport
->phba
, vport
, lpfc_cmd
, rsp_iocb
);
3874 * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
3875 * @phba: Pointer to HBA context object.
3877 * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
3878 * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
3880 * If scsi-mq is enabled, get the default block layer mapping of software queues
3881 * to hardware queues. This information is saved in request tag.
3883 * Return: index into SLI4 fast-path FCP queue index.
3885 int lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba
*phba
,
3886 struct lpfc_scsi_buf
*lpfc_cmd
)
3888 struct scsi_cmnd
*cmnd
= lpfc_cmd
->pCmd
;
3889 struct lpfc_vector_map_info
*cpup
;
3894 if (cmnd
&& shost_use_blk_mq(cmnd
->device
->host
)) {
3895 tag
= blk_mq_unique_tag(cmnd
->request
);
3896 hwq
= blk_mq_unique_tag_to_hwq(tag
);
3901 if (phba
->cfg_fcp_io_sched
== LPFC_FCP_SCHED_BY_CPU
3902 && phba
->cfg_fcp_io_channel
> 1) {
3903 cpu
= smp_processor_id();
3904 if (cpu
< phba
->sli4_hba
.num_present_cpu
) {
3905 cpup
= phba
->sli4_hba
.cpu_map
;
3907 return cpup
->channel_id
;
3910 chann
= atomic_add_return(1, &phba
->fcp_qidx
);
3911 chann
= chann
% phba
->cfg_fcp_io_channel
;
3917 * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine
3918 * @phba: The Hba for which this call is being executed.
3919 * @pIocbIn: The command IOCBQ for the scsi cmnd.
3920 * @pIocbOut: The response IOCBQ for the scsi cmnd.
3922 * This routine assigns scsi command result by looking into response IOCB
3923 * status field appropriately. This routine handles QUEUE FULL condition as
3924 * well by ramping down device queue depth.
3927 lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*pIocbIn
,
3928 struct lpfc_iocbq
*pIocbOut
)
3930 struct lpfc_scsi_buf
*lpfc_cmd
=
3931 (struct lpfc_scsi_buf
*) pIocbIn
->context1
;
3932 struct lpfc_vport
*vport
= pIocbIn
->vport
;
3933 struct lpfc_rport_data
*rdata
= lpfc_cmd
->rdata
;
3934 struct lpfc_nodelist
*pnode
= rdata
->pnode
;
3935 struct scsi_cmnd
*cmd
;
3936 unsigned long flags
;
3937 struct lpfc_fast_path_event
*fast_path_evt
;
3938 struct Scsi_Host
*shost
;
3939 uint32_t logit
= LOG_FCP
;
3941 atomic_inc(&phba
->fc4ScsiIoCmpls
);
3943 /* Sanity check on return of outstanding command */
3944 cmd
= lpfc_cmd
->pCmd
;
3947 shost
= cmd
->device
->host
;
3949 lpfc_cmd
->result
= (pIocbOut
->iocb
.un
.ulpWord
[4] & IOERR_PARAM_MASK
);
3950 lpfc_cmd
->status
= pIocbOut
->iocb
.ulpStatus
;
3951 /* pick up SLI4 exhange busy status from HBA */
3952 lpfc_cmd
->exch_busy
= pIocbOut
->iocb_flag
& LPFC_EXCHANGE_BUSY
;
3954 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3955 if (lpfc_cmd
->prot_data_type
) {
3956 struct scsi_dif_tuple
*src
= NULL
;
3958 src
= (struct scsi_dif_tuple
*)lpfc_cmd
->prot_data_segment
;
3960 * Used to restore any changes to protection
3961 * data for error injection.
3963 switch (lpfc_cmd
->prot_data_type
) {
3964 case LPFC_INJERR_REFTAG
:
3966 lpfc_cmd
->prot_data
;
3968 case LPFC_INJERR_APPTAG
:
3970 (uint16_t)lpfc_cmd
->prot_data
;
3972 case LPFC_INJERR_GUARD
:
3974 (uint16_t)lpfc_cmd
->prot_data
;
3980 lpfc_cmd
->prot_data
= 0;
3981 lpfc_cmd
->prot_data_type
= 0;
3982 lpfc_cmd
->prot_data_segment
= NULL
;
3986 if (lpfc_cmd
->status
) {
3987 if (lpfc_cmd
->status
== IOSTAT_LOCAL_REJECT
&&
3988 (lpfc_cmd
->result
& IOERR_DRVR_MASK
))
3989 lpfc_cmd
->status
= IOSTAT_DRIVER_REJECT
;
3990 else if (lpfc_cmd
->status
>= IOSTAT_CNT
)
3991 lpfc_cmd
->status
= IOSTAT_DEFAULT
;
3992 if (lpfc_cmd
->status
== IOSTAT_FCP_RSP_ERROR
&&
3993 !lpfc_cmd
->fcp_rsp
->rspStatus3
&&
3994 (lpfc_cmd
->fcp_rsp
->rspStatus2
& RESID_UNDER
) &&
3995 !(vport
->cfg_log_verbose
& LOG_FCP_UNDER
))
3998 logit
= LOG_FCP
| LOG_FCP_UNDER
;
3999 lpfc_printf_vlog(vport
, KERN_WARNING
, logit
,
4000 "9030 FCP cmd x%x failed <%d/%lld> "
4001 "status: x%x result: x%x "
4002 "sid: x%x did: x%x oxid: x%x "
4005 cmd
->device
? cmd
->device
->id
: 0xffff,
4006 cmd
->device
? cmd
->device
->lun
: 0xffff,
4007 lpfc_cmd
->status
, lpfc_cmd
->result
,
4009 (pnode
) ? pnode
->nlp_DID
: 0,
4010 phba
->sli_rev
== LPFC_SLI_REV4
?
4011 lpfc_cmd
->cur_iocbq
.sli4_xritag
: 0xffff,
4012 pIocbOut
->iocb
.ulpContext
,
4013 lpfc_cmd
->cur_iocbq
.iocb
.ulpIoTag
);
4015 switch (lpfc_cmd
->status
) {
4016 case IOSTAT_FCP_RSP_ERROR
:
4017 /* Call FCP RSP handler to determine result */
4018 lpfc_handle_fcp_err(vport
, lpfc_cmd
, pIocbOut
);
4020 case IOSTAT_NPORT_BSY
:
4021 case IOSTAT_FABRIC_BSY
:
4022 cmd
->result
= ScsiResult(DID_TRANSPORT_DISRUPTED
, 0);
4023 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
4026 fast_path_evt
->un
.fabric_evt
.event_type
=
4027 FC_REG_FABRIC_EVENT
;
4028 fast_path_evt
->un
.fabric_evt
.subcategory
=
4029 (lpfc_cmd
->status
== IOSTAT_NPORT_BSY
) ?
4030 LPFC_EVENT_PORT_BUSY
: LPFC_EVENT_FABRIC_BUSY
;
4031 if (pnode
&& NLP_CHK_NODE_ACT(pnode
)) {
4032 memcpy(&fast_path_evt
->un
.fabric_evt
.wwpn
,
4033 &pnode
->nlp_portname
,
4034 sizeof(struct lpfc_name
));
4035 memcpy(&fast_path_evt
->un
.fabric_evt
.wwnn
,
4036 &pnode
->nlp_nodename
,
4037 sizeof(struct lpfc_name
));
4039 fast_path_evt
->vport
= vport
;
4040 fast_path_evt
->work_evt
.evt
=
4041 LPFC_EVT_FASTPATH_MGMT_EVT
;
4042 spin_lock_irqsave(&phba
->hbalock
, flags
);
4043 list_add_tail(&fast_path_evt
->work_evt
.evt_listp
,
4045 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
4046 lpfc_worker_wake_up(phba
);
4048 case IOSTAT_LOCAL_REJECT
:
4049 case IOSTAT_REMOTE_STOP
:
4050 if (lpfc_cmd
->result
== IOERR_ELXSEC_KEY_UNWRAP_ERROR
||
4052 IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR
||
4053 lpfc_cmd
->result
== IOERR_ELXSEC_CRYPTO_ERROR
||
4055 IOERR_ELXSEC_CRYPTO_COMPARE_ERROR
) {
4056 cmd
->result
= ScsiResult(DID_NO_CONNECT
, 0);
4059 if (lpfc_cmd
->result
== IOERR_INVALID_RPI
||
4060 lpfc_cmd
->result
== IOERR_NO_RESOURCES
||
4061 lpfc_cmd
->result
== IOERR_ABORT_REQUESTED
||
4062 lpfc_cmd
->result
== IOERR_SLER_CMD_RCV_FAILURE
) {
4063 cmd
->result
= ScsiResult(DID_REQUEUE
, 0);
4066 if ((lpfc_cmd
->result
== IOERR_RX_DMA_FAILED
||
4067 lpfc_cmd
->result
== IOERR_TX_DMA_FAILED
) &&
4068 pIocbOut
->iocb
.unsli3
.sli3_bg
.bgstat
) {
4069 if (scsi_get_prot_op(cmd
) != SCSI_PROT_NORMAL
) {
4071 * This is a response for a BG enabled
4072 * cmd. Parse BG error
4074 lpfc_parse_bg_err(phba
, lpfc_cmd
,
4078 lpfc_printf_vlog(vport
, KERN_WARNING
,
4080 "9031 non-zero BGSTAT "
4081 "on unprotected cmd\n");
4084 if ((lpfc_cmd
->status
== IOSTAT_REMOTE_STOP
)
4085 && (phba
->sli_rev
== LPFC_SLI_REV4
)
4086 && (pnode
&& NLP_CHK_NODE_ACT(pnode
))) {
4087 /* This IO was aborted by the target, we don't
4088 * know the rxid and because we did not send the
4089 * ABTS we cannot generate and RRQ.
4091 lpfc_set_rrq_active(phba
, pnode
,
4092 lpfc_cmd
->cur_iocbq
.sli4_lxritag
,
4095 /* else: fall through */
4097 cmd
->result
= ScsiResult(DID_ERROR
, 0);
4101 if (!pnode
|| !NLP_CHK_NODE_ACT(pnode
)
4102 || (pnode
->nlp_state
!= NLP_STE_MAPPED_NODE
))
4103 cmd
->result
= ScsiResult(DID_TRANSPORT_DISRUPTED
,
4106 cmd
->result
= ScsiResult(DID_OK
, 0);
4108 if (cmd
->result
|| lpfc_cmd
->fcp_rsp
->rspSnsLen
) {
4109 uint32_t *lp
= (uint32_t *)cmd
->sense_buffer
;
4111 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
4112 "0710 Iodone <%d/%llu> cmd %p, error "
4113 "x%x SNS x%x x%x Data: x%x x%x\n",
4114 cmd
->device
->id
, cmd
->device
->lun
, cmd
,
4115 cmd
->result
, *lp
, *(lp
+ 3), cmd
->retries
,
4116 scsi_get_resid(cmd
));
4119 lpfc_update_stats(phba
, lpfc_cmd
);
4120 if (vport
->cfg_max_scsicmpl_time
&&
4121 time_after(jiffies
, lpfc_cmd
->start_time
+
4122 msecs_to_jiffies(vport
->cfg_max_scsicmpl_time
))) {
4123 spin_lock_irqsave(shost
->host_lock
, flags
);
4124 if (pnode
&& NLP_CHK_NODE_ACT(pnode
)) {
4125 atomic_dec(&pnode
->cmd_pending
);
4126 if (pnode
->cmd_qdepth
>
4127 atomic_read(&pnode
->cmd_pending
) &&
4128 (atomic_read(&pnode
->cmd_pending
) >
4129 LPFC_MIN_TGT_QDEPTH
) &&
4130 ((cmd
->cmnd
[0] == READ_10
) ||
4131 (cmd
->cmnd
[0] == WRITE_10
)))
4133 atomic_read(&pnode
->cmd_pending
);
4135 pnode
->last_change_time
= jiffies
;
4137 spin_unlock_irqrestore(shost
->host_lock
, flags
);
4138 } else if (pnode
&& NLP_CHK_NODE_ACT(pnode
)) {
4139 atomic_dec(&pnode
->cmd_pending
);
4141 lpfc_scsi_unprep_dma_buf(phba
, lpfc_cmd
);
4143 spin_lock_irqsave(&phba
->hbalock
, flags
);
4144 lpfc_cmd
->pCmd
= NULL
;
4145 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
4147 /* The sdev is not guaranteed to be valid post scsi_done upcall. */
4148 cmd
->scsi_done(cmd
);
4151 * If there is a thread waiting for command completion
4152 * wake up the thread.
4154 spin_lock_irqsave(shost
->host_lock
, flags
);
4155 if (lpfc_cmd
->waitq
)
4156 wake_up(lpfc_cmd
->waitq
);
4157 spin_unlock_irqrestore(shost
->host_lock
, flags
);
4159 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
4163 * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB
4164 * @data: A pointer to the immediate command data portion of the IOCB.
4165 * @fcp_cmnd: The FCP Command that is provided by the SCSI layer.
4167 * The routine copies the entire FCP command from @fcp_cmnd to @data while
4168 * byte swapping the data to big endian format for transmission on the wire.
4171 lpfc_fcpcmd_to_iocb(uint8_t *data
, struct fcp_cmnd
*fcp_cmnd
)
4174 for (i
= 0, j
= 0; i
< sizeof(struct fcp_cmnd
);
4175 i
+= sizeof(uint32_t), j
++) {
4176 ((uint32_t *)data
)[j
] = cpu_to_be32(((uint32_t *)fcp_cmnd
)[j
]);
4181 * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit
4182 * @vport: The virtual port for which this call is being executed.
4183 * @lpfc_cmd: The scsi command which needs to send.
4184 * @pnode: Pointer to lpfc_nodelist.
4186 * This routine initializes fcp_cmnd and iocb data structure from scsi command
4187 * to transfer for device with SLI3 interface spec.
4190 lpfc_scsi_prep_cmnd(struct lpfc_vport
*vport
, struct lpfc_scsi_buf
*lpfc_cmd
,
4191 struct lpfc_nodelist
*pnode
)
4193 struct lpfc_hba
*phba
= vport
->phba
;
4194 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
4195 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
4196 IOCB_t
*iocb_cmd
= &lpfc_cmd
->cur_iocbq
.iocb
;
4197 struct lpfc_iocbq
*piocbq
= &(lpfc_cmd
->cur_iocbq
);
4198 int datadir
= scsi_cmnd
->sc_data_direction
;
4203 if (!pnode
|| !NLP_CHK_NODE_ACT(pnode
))
4206 lpfc_cmd
->fcp_rsp
->rspSnsLen
= 0;
4207 /* clear task management bits */
4208 lpfc_cmd
->fcp_cmnd
->fcpCntl2
= 0;
4210 int_to_scsilun(lpfc_cmd
->pCmd
->device
->lun
,
4211 &lpfc_cmd
->fcp_cmnd
->fcp_lun
);
4213 ptr
= &fcp_cmnd
->fcpCdb
[0];
4214 memcpy(ptr
, scsi_cmnd
->cmnd
, scsi_cmnd
->cmd_len
);
4215 if (scsi_cmnd
->cmd_len
< LPFC_FCP_CDB_LEN
) {
4216 ptr
+= scsi_cmnd
->cmd_len
;
4217 memset(ptr
, 0, (LPFC_FCP_CDB_LEN
- scsi_cmnd
->cmd_len
));
4220 fcp_cmnd
->fcpCntl1
= SIMPLE_Q
;
4222 sli4
= (phba
->sli_rev
== LPFC_SLI_REV4
);
4223 piocbq
->iocb
.un
.fcpi
.fcpi_XRdy
= 0;
4226 * There are three possibilities here - use scatter-gather segment, use
4227 * the single mapping, or neither. Start the lpfc command prep by
4228 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
4231 if (scsi_sg_count(scsi_cmnd
)) {
4232 if (datadir
== DMA_TO_DEVICE
) {
4233 iocb_cmd
->ulpCommand
= CMD_FCP_IWRITE64_CR
;
4234 iocb_cmd
->ulpPU
= PARM_READ_CHECK
;
4235 if (vport
->cfg_first_burst_size
&&
4236 (pnode
->nlp_flag
& NLP_FIRSTBURST
)) {
4237 fcpdl
= scsi_bufflen(scsi_cmnd
);
4238 if (fcpdl
< vport
->cfg_first_burst_size
)
4239 piocbq
->iocb
.un
.fcpi
.fcpi_XRdy
= fcpdl
;
4241 piocbq
->iocb
.un
.fcpi
.fcpi_XRdy
=
4242 vport
->cfg_first_burst_size
;
4244 fcp_cmnd
->fcpCntl3
= WRITE_DATA
;
4245 atomic_inc(&phba
->fc4ScsiOutputRequests
);
4247 iocb_cmd
->ulpCommand
= CMD_FCP_IREAD64_CR
;
4248 iocb_cmd
->ulpPU
= PARM_READ_CHECK
;
4249 fcp_cmnd
->fcpCntl3
= READ_DATA
;
4250 atomic_inc(&phba
->fc4ScsiInputRequests
);
4253 iocb_cmd
->ulpCommand
= CMD_FCP_ICMND64_CR
;
4254 iocb_cmd
->un
.fcpi
.fcpi_parm
= 0;
4255 iocb_cmd
->ulpPU
= 0;
4256 fcp_cmnd
->fcpCntl3
= 0;
4257 atomic_inc(&phba
->fc4ScsiControlRequests
);
4259 if (phba
->sli_rev
== 3 &&
4260 !(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
))
4261 lpfc_fcpcmd_to_iocb(iocb_cmd
->unsli3
.fcp_ext
.icd
, fcp_cmnd
);
4263 * Finish initializing those IOCB fields that are independent
4264 * of the scsi_cmnd request_buffer
4266 piocbq
->iocb
.ulpContext
= pnode
->nlp_rpi
;
4268 piocbq
->iocb
.ulpContext
=
4269 phba
->sli4_hba
.rpi_ids
[pnode
->nlp_rpi
];
4270 if (pnode
->nlp_fcp_info
& NLP_FCP_2_DEVICE
)
4271 piocbq
->iocb
.ulpFCP2Rcvy
= 1;
4273 piocbq
->iocb
.ulpFCP2Rcvy
= 0;
4275 piocbq
->iocb
.ulpClass
= (pnode
->nlp_fcp_info
& 0x0f);
4276 piocbq
->context1
= lpfc_cmd
;
4277 piocbq
->iocb_cmpl
= lpfc_scsi_cmd_iocb_cmpl
;
4278 piocbq
->iocb
.ulpTimeout
= lpfc_cmd
->timeout
;
4279 piocbq
->vport
= vport
;
4283 * lpfc_scsi_prep_task_mgmt_cmd - Convert SLI3 scsi TM cmd to FCP info unit
4284 * @vport: The virtual port for which this call is being executed.
4285 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
4286 * @lun: Logical unit number.
4287 * @task_mgmt_cmd: SCSI task management command.
4289 * This routine creates FCP information unit corresponding to @task_mgmt_cmd
4290 * for device with SLI-3 interface spec.
4297 lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport
*vport
,
4298 struct lpfc_scsi_buf
*lpfc_cmd
,
4300 uint8_t task_mgmt_cmd
)
4302 struct lpfc_iocbq
*piocbq
;
4304 struct fcp_cmnd
*fcp_cmnd
;
4305 struct lpfc_rport_data
*rdata
= lpfc_cmd
->rdata
;
4306 struct lpfc_nodelist
*ndlp
= rdata
->pnode
;
4308 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
) ||
4309 ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
)
4312 piocbq
= &(lpfc_cmd
->cur_iocbq
);
4313 piocbq
->vport
= vport
;
4315 piocb
= &piocbq
->iocb
;
4317 fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
4318 /* Clear out any old data in the FCP command area */
4319 memset(fcp_cmnd
, 0, sizeof(struct fcp_cmnd
));
4320 int_to_scsilun(lun
, &fcp_cmnd
->fcp_lun
);
4321 fcp_cmnd
->fcpCntl2
= task_mgmt_cmd
;
4322 if (vport
->phba
->sli_rev
== 3 &&
4323 !(vport
->phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
))
4324 lpfc_fcpcmd_to_iocb(piocb
->unsli3
.fcp_ext
.icd
, fcp_cmnd
);
4325 piocb
->ulpCommand
= CMD_FCP_ICMND64_CR
;
4326 piocb
->ulpContext
= ndlp
->nlp_rpi
;
4327 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
) {
4329 vport
->phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
4331 piocb
->ulpFCP2Rcvy
= (ndlp
->nlp_fcp_info
& NLP_FCP_2_DEVICE
) ? 1 : 0;
4332 piocb
->ulpClass
= (ndlp
->nlp_fcp_info
& 0x0f);
4334 piocb
->un
.fcpi
.fcpi_parm
= 0;
4336 /* ulpTimeout is only one byte */
4337 if (lpfc_cmd
->timeout
> 0xff) {
4339 * Do not timeout the command at the firmware level.
4340 * The driver will provide the timeout mechanism.
4342 piocb
->ulpTimeout
= 0;
4344 piocb
->ulpTimeout
= lpfc_cmd
->timeout
;
4346 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
)
4347 lpfc_sli4_set_rsp_sgl_last(vport
->phba
, lpfc_cmd
);
4353 * lpfc_scsi_api_table_setup - Set up scsi api function jump table
4354 * @phba: The hba struct for which this call is being executed.
4355 * @dev_grp: The HBA PCI-Device group number.
4357 * This routine sets up the SCSI interface API function jump table in @phba
4359 * Returns: 0 - success, -ENODEV - failure.
4362 lpfc_scsi_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
4365 phba
->lpfc_scsi_unprep_dma_buf
= lpfc_scsi_unprep_dma_buf
;
4366 phba
->lpfc_scsi_prep_cmnd
= lpfc_scsi_prep_cmnd
;
4369 case LPFC_PCI_DEV_LP
:
4370 phba
->lpfc_new_scsi_buf
= lpfc_new_scsi_buf_s3
;
4371 phba
->lpfc_scsi_prep_dma_buf
= lpfc_scsi_prep_dma_buf_s3
;
4372 phba
->lpfc_bg_scsi_prep_dma_buf
= lpfc_bg_scsi_prep_dma_buf_s3
;
4373 phba
->lpfc_release_scsi_buf
= lpfc_release_scsi_buf_s3
;
4374 phba
->lpfc_get_scsi_buf
= lpfc_get_scsi_buf_s3
;
4376 case LPFC_PCI_DEV_OC
:
4377 phba
->lpfc_new_scsi_buf
= lpfc_new_scsi_buf_s4
;
4378 phba
->lpfc_scsi_prep_dma_buf
= lpfc_scsi_prep_dma_buf_s4
;
4379 phba
->lpfc_bg_scsi_prep_dma_buf
= lpfc_bg_scsi_prep_dma_buf_s4
;
4380 phba
->lpfc_release_scsi_buf
= lpfc_release_scsi_buf_s4
;
4381 phba
->lpfc_get_scsi_buf
= lpfc_get_scsi_buf_s4
;
4384 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4385 "1418 Invalid HBA PCI-device group: 0x%x\n",
4390 phba
->lpfc_rampdown_queue_depth
= lpfc_rampdown_queue_depth
;
4391 phba
->lpfc_scsi_cmd_iocb_cmpl
= lpfc_scsi_cmd_iocb_cmpl
;
4396 * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command
4397 * @phba: The Hba for which this call is being executed.
4398 * @cmdiocbq: Pointer to lpfc_iocbq data structure.
4399 * @rspiocbq: Pointer to lpfc_iocbq data structure.
4401 * This routine is IOCB completion routine for device reset and target reset
4402 * routine. This routine release scsi buffer associated with lpfc_cmd.
4405 lpfc_tskmgmt_def_cmpl(struct lpfc_hba
*phba
,
4406 struct lpfc_iocbq
*cmdiocbq
,
4407 struct lpfc_iocbq
*rspiocbq
)
4409 struct lpfc_scsi_buf
*lpfc_cmd
=
4410 (struct lpfc_scsi_buf
*) cmdiocbq
->context1
;
4412 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
4417 * lpfc_info - Info entry point of scsi_host_template data structure
4418 * @host: The scsi host for which this call is being executed.
4420 * This routine provides module information about hba.
4423 * Pointer to char - Success.
4426 lpfc_info(struct Scsi_Host
*host
)
4428 struct lpfc_vport
*vport
= (struct lpfc_vport
*) host
->hostdata
;
4429 struct lpfc_hba
*phba
= vport
->phba
;
4430 int len
, link_speed
= 0;
4431 static char lpfcinfobuf
[384];
4433 memset(lpfcinfobuf
,0,384);
4434 if (phba
&& phba
->pcidev
){
4435 strncpy(lpfcinfobuf
, phba
->ModelDesc
, 256);
4436 len
= strlen(lpfcinfobuf
);
4437 snprintf(lpfcinfobuf
+ len
,
4439 " on PCI bus %02x device %02x irq %d",
4440 phba
->pcidev
->bus
->number
,
4441 phba
->pcidev
->devfn
,
4443 len
= strlen(lpfcinfobuf
);
4444 if (phba
->Port
[0]) {
4445 snprintf(lpfcinfobuf
+ len
,
4450 len
= strlen(lpfcinfobuf
);
4451 link_speed
= lpfc_sli_port_speed_get(phba
);
4452 if (link_speed
!= 0)
4453 snprintf(lpfcinfobuf
+ len
, 384-len
,
4454 " Logical Link Speed: %d Mbps", link_speed
);
4460 * lpfc_poll_rearm_time - Routine to modify fcp_poll timer of hba
4461 * @phba: The Hba for which this call is being executed.
4463 * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo.
4464 * The default value of cfg_poll_tmo is 10 milliseconds.
4466 static __inline__
void lpfc_poll_rearm_timer(struct lpfc_hba
* phba
)
4468 unsigned long poll_tmo_expires
=
4469 (jiffies
+ msecs_to_jiffies(phba
->cfg_poll_tmo
));
4471 if (!list_empty(&phba
->sli
.sli3_ring
[LPFC_FCP_RING
].txcmplq
))
4472 mod_timer(&phba
->fcp_poll_timer
,
4477 * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA
4478 * @phba: The Hba for which this call is being executed.
4480 * This routine starts the fcp_poll_timer of @phba.
4482 void lpfc_poll_start_timer(struct lpfc_hba
* phba
)
4484 lpfc_poll_rearm_timer(phba
);
4488 * lpfc_poll_timeout - Restart polling timer
4489 * @ptr: Map to lpfc_hba data structure pointer.
4491 * This routine restarts fcp_poll timer, when FCP ring polling is enable
4492 * and FCP Ring interrupt is disable.
4495 void lpfc_poll_timeout(struct timer_list
*t
)
4497 struct lpfc_hba
*phba
= from_timer(phba
, t
, fcp_poll_timer
);
4499 if (phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) {
4500 lpfc_sli_handle_fast_ring_event(phba
,
4501 &phba
->sli
.sli3_ring
[LPFC_FCP_RING
], HA_R0RE_REQ
);
4503 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
)
4504 lpfc_poll_rearm_timer(phba
);
4509 * lpfc_queuecommand - scsi_host_template queuecommand entry point
4510 * @cmnd: Pointer to scsi_cmnd data structure.
4511 * @done: Pointer to done routine.
4513 * Driver registers this routine to scsi midlayer to submit a @cmd to process.
4514 * This routine prepares an IOCB from scsi command and provides to firmware.
4515 * The @done callback is invoked after driver finished processing the command.
4519 * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily.
4522 lpfc_queuecommand(struct Scsi_Host
*shost
, struct scsi_cmnd
*cmnd
)
4524 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4525 struct lpfc_hba
*phba
= vport
->phba
;
4526 struct lpfc_rport_data
*rdata
;
4527 struct lpfc_nodelist
*ndlp
;
4528 struct lpfc_scsi_buf
*lpfc_cmd
;
4529 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmnd
->device
));
4532 rdata
= lpfc_rport_data_from_scsi_device(cmnd
->device
);
4533 err
= fc_remote_port_chkready(rport
);
4536 goto out_fail_command
;
4538 ndlp
= rdata
->pnode
;
4540 if ((scsi_get_prot_op(cmnd
) != SCSI_PROT_NORMAL
) &&
4541 (!(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
))) {
4543 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
4544 "9058 BLKGRD: ERROR: rcvd protected cmd:%02x"
4545 " op:%02x str=%s without registering for"
4546 " BlockGuard - Rejecting command\n",
4547 cmnd
->cmnd
[0], scsi_get_prot_op(cmnd
),
4548 dif_op_str
[scsi_get_prot_op(cmnd
)]);
4549 goto out_fail_command
;
4553 * Catch race where our node has transitioned, but the
4554 * transport is still transitioning.
4556 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
4558 if (atomic_read(&ndlp
->cmd_pending
) >= ndlp
->cmd_qdepth
) {
4559 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP_ERROR
,
4560 "3377 Target Queue Full, scsi Id:%d Qdepth:%d"
4561 " Pending command:%d"
4562 " WWNN:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x, "
4563 " WWPN:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
4564 ndlp
->nlp_sid
, ndlp
->cmd_qdepth
,
4565 atomic_read(&ndlp
->cmd_pending
),
4566 ndlp
->nlp_nodename
.u
.wwn
[0],
4567 ndlp
->nlp_nodename
.u
.wwn
[1],
4568 ndlp
->nlp_nodename
.u
.wwn
[2],
4569 ndlp
->nlp_nodename
.u
.wwn
[3],
4570 ndlp
->nlp_nodename
.u
.wwn
[4],
4571 ndlp
->nlp_nodename
.u
.wwn
[5],
4572 ndlp
->nlp_nodename
.u
.wwn
[6],
4573 ndlp
->nlp_nodename
.u
.wwn
[7],
4574 ndlp
->nlp_portname
.u
.wwn
[0],
4575 ndlp
->nlp_portname
.u
.wwn
[1],
4576 ndlp
->nlp_portname
.u
.wwn
[2],
4577 ndlp
->nlp_portname
.u
.wwn
[3],
4578 ndlp
->nlp_portname
.u
.wwn
[4],
4579 ndlp
->nlp_portname
.u
.wwn
[5],
4580 ndlp
->nlp_portname
.u
.wwn
[6],
4581 ndlp
->nlp_portname
.u
.wwn
[7]);
4584 atomic_inc(&ndlp
->cmd_pending
);
4586 lpfc_cmd
= lpfc_get_scsi_buf(phba
, ndlp
);
4587 if (lpfc_cmd
== NULL
) {
4588 lpfc_rampdown_queue_depth(phba
);
4590 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP_ERROR
,
4591 "0707 driver's buffer pool is empty, "
4597 * Store the midlayer's command structure for the completion phase
4598 * and complete the command initialization.
4600 lpfc_cmd
->pCmd
= cmnd
;
4601 lpfc_cmd
->rdata
= rdata
;
4602 lpfc_cmd
->timeout
= 0;
4603 lpfc_cmd
->start_time
= jiffies
;
4604 cmnd
->host_scribble
= (unsigned char *)lpfc_cmd
;
4606 if (scsi_get_prot_op(cmnd
) != SCSI_PROT_NORMAL
) {
4607 if (vport
->phba
->cfg_enable_bg
) {
4608 lpfc_printf_vlog(vport
,
4609 KERN_INFO
, LOG_SCSI_CMD
,
4610 "9033 BLKGRD: rcvd %s cmd:x%x "
4611 "sector x%llx cnt %u pt %x\n",
4612 dif_op_str
[scsi_get_prot_op(cmnd
)],
4614 (unsigned long long)scsi_get_lba(cmnd
),
4615 blk_rq_sectors(cmnd
->request
),
4616 (cmnd
->cmnd
[1]>>5));
4618 err
= lpfc_bg_scsi_prep_dma_buf(phba
, lpfc_cmd
);
4620 if (vport
->phba
->cfg_enable_bg
) {
4621 lpfc_printf_vlog(vport
,
4622 KERN_INFO
, LOG_SCSI_CMD
,
4623 "9038 BLKGRD: rcvd PROT_NORMAL cmd: "
4624 "x%x sector x%llx cnt %u pt %x\n",
4626 (unsigned long long)scsi_get_lba(cmnd
),
4627 blk_rq_sectors(cmnd
->request
),
4628 (cmnd
->cmnd
[1]>>5));
4630 err
= lpfc_scsi_prep_dma_buf(phba
, lpfc_cmd
);
4634 goto out_host_busy_free_buf
;
4636 lpfc_scsi_prep_cmnd(vport
, lpfc_cmd
, ndlp
);
4638 err
= lpfc_sli_issue_iocb(phba
, LPFC_FCP_RING
,
4639 &lpfc_cmd
->cur_iocbq
, SLI_IOCB_RET_IOCB
);
4641 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
4642 "3376 FCP could not issue IOCB err %x"
4643 "FCP cmd x%x <%d/%llu> "
4644 "sid: x%x did: x%x oxid: x%x "
4645 "Data: x%x x%x x%x x%x\n",
4647 cmnd
->device
? cmnd
->device
->id
: 0xffff,
4648 cmnd
->device
? cmnd
->device
->lun
: (u64
) -1,
4649 vport
->fc_myDID
, ndlp
->nlp_DID
,
4650 phba
->sli_rev
== LPFC_SLI_REV4
?
4651 lpfc_cmd
->cur_iocbq
.sli4_xritag
: 0xffff,
4652 lpfc_cmd
->cur_iocbq
.iocb
.ulpContext
,
4653 lpfc_cmd
->cur_iocbq
.iocb
.ulpIoTag
,
4654 lpfc_cmd
->cur_iocbq
.iocb
.ulpTimeout
,
4656 (cmnd
->request
->timeout
/ 1000));
4658 switch (lpfc_cmd
->fcp_cmnd
->fcpCntl3
) {
4660 atomic_dec(&phba
->fc4ScsiOutputRequests
);
4663 atomic_dec(&phba
->fc4ScsiInputRequests
);
4666 atomic_dec(&phba
->fc4ScsiControlRequests
);
4668 goto out_host_busy_free_buf
;
4670 if (phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) {
4671 lpfc_sli_handle_fast_ring_event(phba
,
4672 &phba
->sli
.sli3_ring
[LPFC_FCP_RING
], HA_R0RE_REQ
);
4674 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
)
4675 lpfc_poll_rearm_timer(phba
);
4680 out_host_busy_free_buf
:
4681 lpfc_scsi_unprep_dma_buf(phba
, lpfc_cmd
);
4682 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
4684 atomic_dec(&ndlp
->cmd_pending
);
4685 return SCSI_MLQUEUE_HOST_BUSY
;
4688 return SCSI_MLQUEUE_TARGET_BUSY
;
4691 cmnd
->scsi_done(cmnd
);
4697 * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point
4698 * @cmnd: Pointer to scsi_cmnd data structure.
4700 * This routine aborts @cmnd pending in base driver.
4707 lpfc_abort_handler(struct scsi_cmnd
*cmnd
)
4709 struct Scsi_Host
*shost
= cmnd
->device
->host
;
4710 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4711 struct lpfc_hba
*phba
= vport
->phba
;
4712 struct lpfc_iocbq
*iocb
;
4713 struct lpfc_iocbq
*abtsiocb
;
4714 struct lpfc_scsi_buf
*lpfc_cmd
;
4716 int ret
= SUCCESS
, status
= 0;
4717 struct lpfc_sli_ring
*pring_s4
;
4719 unsigned long flags
;
4720 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq
);
4722 status
= fc_block_scsi_eh(cmnd
);
4723 if (status
!= 0 && status
!= SUCCESS
)
4726 spin_lock_irqsave(&phba
->hbalock
, flags
);
4727 /* driver queued commands are in process of being flushed */
4728 if (phba
->hba_flag
& HBA_FCP_IOQ_FLUSH
) {
4729 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
4730 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
4731 "3168 SCSI Layer abort requested I/O has been "
4732 "flushed by LLD.\n");
4736 lpfc_cmd
= (struct lpfc_scsi_buf
*)cmnd
->host_scribble
;
4737 if (!lpfc_cmd
|| !lpfc_cmd
->pCmd
) {
4738 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
4739 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
4740 "2873 SCSI Layer I/O Abort Request IO CMPL Status "
4741 "x%x ID %d LUN %llu\n",
4742 SUCCESS
, cmnd
->device
->id
, cmnd
->device
->lun
);
4746 iocb
= &lpfc_cmd
->cur_iocbq
;
4747 /* the command is in process of being cancelled */
4748 if (!(iocb
->iocb_flag
& LPFC_IO_ON_TXCMPLQ
)) {
4749 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
4750 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
4751 "3169 SCSI Layer abort requested I/O has been "
4752 "cancelled by LLD.\n");
4756 * If pCmd field of the corresponding lpfc_scsi_buf structure
4757 * points to a different SCSI command, then the driver has
4758 * already completed this command, but the midlayer did not
4759 * see the completion before the eh fired. Just return SUCCESS.
4761 if (lpfc_cmd
->pCmd
!= cmnd
) {
4762 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
4763 "3170 SCSI Layer abort requested I/O has been "
4764 "completed by LLD.\n");
4768 BUG_ON(iocb
->context1
!= lpfc_cmd
);
4770 /* abort issued in recovery is still in progress */
4771 if (iocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) {
4772 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
4773 "3389 SCSI Layer I/O Abort Request is pending\n");
4774 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
4778 abtsiocb
= __lpfc_sli_get_iocbq(phba
);
4779 if (abtsiocb
== NULL
) {
4784 /* Indicate the IO is being aborted by the driver. */
4785 iocb
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
4788 * The scsi command can not be in txq and it is in flight because the
4789 * pCmd is still pointig at the SCSI command we have to abort. There
4790 * is no need to search the txcmplq. Just send an abort to the FW.
4794 icmd
= &abtsiocb
->iocb
;
4795 icmd
->un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
4796 icmd
->un
.acxri
.abortContextTag
= cmd
->ulpContext
;
4797 if (phba
->sli_rev
== LPFC_SLI_REV4
)
4798 icmd
->un
.acxri
.abortIoTag
= iocb
->sli4_xritag
;
4800 icmd
->un
.acxri
.abortIoTag
= cmd
->ulpIoTag
;
4803 icmd
->ulpClass
= cmd
->ulpClass
;
4805 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
4806 abtsiocb
->hba_wqidx
= iocb
->hba_wqidx
;
4807 abtsiocb
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
4808 if (iocb
->iocb_flag
& LPFC_IO_FOF
)
4809 abtsiocb
->iocb_flag
|= LPFC_IO_FOF
;
4811 if (lpfc_is_link_up(phba
))
4812 icmd
->ulpCommand
= CMD_ABORT_XRI_CN
;
4814 icmd
->ulpCommand
= CMD_CLOSE_XRI_CN
;
4816 abtsiocb
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
4817 abtsiocb
->vport
= vport
;
4818 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
4819 pring_s4
= lpfc_sli4_calc_ring(phba
, abtsiocb
);
4820 if (pring_s4
== NULL
) {
4824 /* Note: both hbalock and ring_lock must be set here */
4825 spin_lock(&pring_s4
->ring_lock
);
4826 ret_val
= __lpfc_sli_issue_iocb(phba
, pring_s4
->ringno
,
4828 spin_unlock(&pring_s4
->ring_lock
);
4830 ret_val
= __lpfc_sli_issue_iocb(phba
, LPFC_FCP_RING
,
4833 /* no longer need the lock after this point */
4834 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
4837 if (ret_val
== IOCB_ERROR
) {
4838 lpfc_sli_release_iocbq(phba
, abtsiocb
);
4843 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
)
4844 lpfc_sli_handle_fast_ring_event(phba
,
4845 &phba
->sli
.sli3_ring
[LPFC_FCP_RING
], HA_R0RE_REQ
);
4848 lpfc_cmd
->waitq
= &waitq
;
4849 /* Wait for abort to complete */
4850 wait_event_timeout(waitq
,
4851 (lpfc_cmd
->pCmd
!= cmnd
),
4852 msecs_to_jiffies(2*vport
->cfg_devloss_tmo
*1000));
4854 spin_lock_irqsave(shost
->host_lock
, flags
);
4855 lpfc_cmd
->waitq
= NULL
;
4856 spin_unlock_irqrestore(shost
->host_lock
, flags
);
4858 if (lpfc_cmd
->pCmd
== cmnd
) {
4860 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
4861 "0748 abort handler timed out waiting "
4862 "for aborting I/O (xri:x%x) to complete: "
4863 "ret %#x, ID %d, LUN %llu\n",
4864 iocb
->sli4_xritag
, ret
,
4865 cmnd
->device
->id
, cmnd
->device
->lun
);
4870 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
4872 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
4873 "0749 SCSI Layer I/O Abort Request Status x%x ID %d "
4874 "LUN %llu\n", ret
, cmnd
->device
->id
,
4880 lpfc_taskmgmt_name(uint8_t task_mgmt_cmd
)
4882 switch (task_mgmt_cmd
) {
4883 case FCP_ABORT_TASK_SET
:
4884 return "ABORT_TASK_SET";
4885 case FCP_CLEAR_TASK_SET
:
4886 return "FCP_CLEAR_TASK_SET";
4888 return "FCP_BUS_RESET";
4890 return "FCP_LUN_RESET";
4891 case FCP_TARGET_RESET
:
4892 return "FCP_TARGET_RESET";
4894 return "FCP_CLEAR_ACA";
4895 case FCP_TERMINATE_TASK
:
4896 return "FCP_TERMINATE_TASK";
4904 * lpfc_check_fcp_rsp - check the returned fcp_rsp to see if task failed
4905 * @vport: The virtual port for which this call is being executed.
4906 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
4908 * This routine checks the FCP RSP INFO to see if the tsk mgmt command succeded
4915 lpfc_check_fcp_rsp(struct lpfc_vport
*vport
, struct lpfc_scsi_buf
*lpfc_cmd
)
4917 struct fcp_rsp
*fcprsp
= lpfc_cmd
->fcp_rsp
;
4920 uint8_t rsp_info_code
;
4925 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
4926 "0703 fcp_rsp is missing\n");
4928 rsp_info
= fcprsp
->rspStatus2
;
4929 rsp_len
= be32_to_cpu(fcprsp
->rspRspLen
);
4930 rsp_info_code
= fcprsp
->rspInfo3
;
4933 lpfc_printf_vlog(vport
, KERN_INFO
,
4935 "0706 fcp_rsp valid 0x%x,"
4936 " rsp len=%d code 0x%x\n",
4938 rsp_len
, rsp_info_code
);
4940 if ((fcprsp
->rspStatus2
&RSP_LEN_VALID
) && (rsp_len
== 8)) {
4941 switch (rsp_info_code
) {
4942 case RSP_NO_FAILURE
:
4943 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
4944 "0715 Task Mgmt No Failure\n");
4947 case RSP_TM_NOT_SUPPORTED
: /* TM rejected */
4948 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
4949 "0716 Task Mgmt Target "
4952 case RSP_TM_NOT_COMPLETED
: /* TM failed */
4953 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
4954 "0717 Task Mgmt Target "
4957 case RSP_TM_INVALID_LU
: /* TM to invalid LU! */
4958 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
4959 "0718 Task Mgmt to invalid "
4970 * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler
4971 * @vport: The virtual port for which this call is being executed.
4972 * @rdata: Pointer to remote port local data
4973 * @tgt_id: Target ID of remote device.
4974 * @lun_id: Lun number for the TMF
4975 * @task_mgmt_cmd: type of TMF to send
4977 * This routine builds and sends a TMF (SCSI Task Mgmt Function) to
4985 lpfc_send_taskmgmt(struct lpfc_vport
*vport
, struct scsi_cmnd
*cmnd
,
4986 unsigned int tgt_id
, uint64_t lun_id
,
4987 uint8_t task_mgmt_cmd
)
4989 struct lpfc_hba
*phba
= vport
->phba
;
4990 struct lpfc_scsi_buf
*lpfc_cmd
;
4991 struct lpfc_iocbq
*iocbq
;
4992 struct lpfc_iocbq
*iocbqrsp
;
4993 struct lpfc_rport_data
*rdata
;
4994 struct lpfc_nodelist
*pnode
;
4998 rdata
= lpfc_rport_data_from_scsi_device(cmnd
->device
);
4999 if (!rdata
|| !rdata
->pnode
|| !NLP_CHK_NODE_ACT(rdata
->pnode
))
5001 pnode
= rdata
->pnode
;
5003 lpfc_cmd
= lpfc_get_scsi_buf(phba
, pnode
);
5004 if (lpfc_cmd
== NULL
)
5006 lpfc_cmd
->timeout
= phba
->cfg_task_mgmt_tmo
;
5007 lpfc_cmd
->rdata
= rdata
;
5008 lpfc_cmd
->pCmd
= cmnd
;
5010 status
= lpfc_scsi_prep_task_mgmt_cmd(vport
, lpfc_cmd
, lun_id
,
5013 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
5017 iocbq
= &lpfc_cmd
->cur_iocbq
;
5018 iocbqrsp
= lpfc_sli_get_iocbq(phba
);
5019 if (iocbqrsp
== NULL
) {
5020 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
5023 iocbq
->iocb_cmpl
= lpfc_tskmgmt_def_cmpl
;
5025 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
5026 "0702 Issue %s to TGT %d LUN %llu "
5027 "rpi x%x nlp_flag x%x Data: x%x x%x\n",
5028 lpfc_taskmgmt_name(task_mgmt_cmd
), tgt_id
, lun_id
,
5029 pnode
->nlp_rpi
, pnode
->nlp_flag
, iocbq
->sli4_xritag
,
5032 status
= lpfc_sli_issue_iocb_wait(phba
, LPFC_FCP_RING
,
5033 iocbq
, iocbqrsp
, lpfc_cmd
->timeout
);
5034 if ((status
!= IOCB_SUCCESS
) ||
5035 (iocbqrsp
->iocb
.ulpStatus
!= IOSTAT_SUCCESS
)) {
5036 if (status
!= IOCB_SUCCESS
||
5037 iocbqrsp
->iocb
.ulpStatus
!= IOSTAT_FCP_RSP_ERROR
)
5038 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
5039 "0727 TMF %s to TGT %d LUN %llu "
5040 "failed (%d, %d) iocb_flag x%x\n",
5041 lpfc_taskmgmt_name(task_mgmt_cmd
),
5043 iocbqrsp
->iocb
.ulpStatus
,
5044 iocbqrsp
->iocb
.un
.ulpWord
[4],
5046 /* if ulpStatus != IOCB_SUCCESS, then status == IOCB_SUCCESS */
5047 if (status
== IOCB_SUCCESS
) {
5048 if (iocbqrsp
->iocb
.ulpStatus
== IOSTAT_FCP_RSP_ERROR
)
5049 /* Something in the FCP_RSP was invalid.
5050 * Check conditions */
5051 ret
= lpfc_check_fcp_rsp(vport
, lpfc_cmd
);
5054 } else if (status
== IOCB_TIMEDOUT
) {
5055 ret
= TIMEOUT_ERROR
;
5062 lpfc_sli_release_iocbq(phba
, iocbqrsp
);
5064 if (ret
!= TIMEOUT_ERROR
)
5065 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
5071 * lpfc_chk_tgt_mapped -
5072 * @vport: The virtual port to check on
5073 * @cmnd: Pointer to scsi_cmnd data structure.
5075 * This routine delays until the scsi target (aka rport) for the
5076 * command exists (is present and logged in) or we declare it non-existent.
5083 lpfc_chk_tgt_mapped(struct lpfc_vport
*vport
, struct scsi_cmnd
*cmnd
)
5085 struct lpfc_rport_data
*rdata
;
5086 struct lpfc_nodelist
*pnode
;
5087 unsigned long later
;
5089 rdata
= lpfc_rport_data_from_scsi_device(cmnd
->device
);
5091 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
5092 "0797 Tgt Map rport failure: rdata x%p\n", rdata
);
5095 pnode
= rdata
->pnode
;
5097 * If target is not in a MAPPED state, delay until
5098 * target is rediscovered or devloss timeout expires.
5100 later
= msecs_to_jiffies(2 * vport
->cfg_devloss_tmo
* 1000) + jiffies
;
5101 while (time_after(later
, jiffies
)) {
5102 if (!pnode
|| !NLP_CHK_NODE_ACT(pnode
))
5104 if (pnode
->nlp_state
== NLP_STE_MAPPED_NODE
)
5106 schedule_timeout_uninterruptible(msecs_to_jiffies(500));
5107 rdata
= lpfc_rport_data_from_scsi_device(cmnd
->device
);
5110 pnode
= rdata
->pnode
;
5112 if (!pnode
|| !NLP_CHK_NODE_ACT(pnode
) ||
5113 (pnode
->nlp_state
!= NLP_STE_MAPPED_NODE
))
5119 * lpfc_reset_flush_io_context -
5120 * @vport: The virtual port (scsi_host) for the flush context
5121 * @tgt_id: If aborting by Target contect - specifies the target id
5122 * @lun_id: If aborting by Lun context - specifies the lun id
5123 * @context: specifies the context level to flush at.
5125 * After a reset condition via TMF, we need to flush orphaned i/o
5126 * contexts from the adapter. This routine aborts any contexts
5127 * outstanding, then waits for their completions. The wait is
5128 * bounded by devloss_tmo though.
5135 lpfc_reset_flush_io_context(struct lpfc_vport
*vport
, uint16_t tgt_id
,
5136 uint64_t lun_id
, lpfc_ctx_cmd context
)
5138 struct lpfc_hba
*phba
= vport
->phba
;
5139 unsigned long later
;
5142 cnt
= lpfc_sli_sum_iocb(vport
, tgt_id
, lun_id
, context
);
5144 lpfc_sli_abort_taskmgmt(vport
,
5145 &phba
->sli
.sli3_ring
[LPFC_FCP_RING
],
5146 tgt_id
, lun_id
, context
);
5147 later
= msecs_to_jiffies(2 * vport
->cfg_devloss_tmo
* 1000) + jiffies
;
5148 while (time_after(later
, jiffies
) && cnt
) {
5149 schedule_timeout_uninterruptible(msecs_to_jiffies(20));
5150 cnt
= lpfc_sli_sum_iocb(vport
, tgt_id
, lun_id
, context
);
5153 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
5154 "0724 I/O flush failure for context %s : cnt x%x\n",
5155 ((context
== LPFC_CTX_LUN
) ? "LUN" :
5156 ((context
== LPFC_CTX_TGT
) ? "TGT" :
5157 ((context
== LPFC_CTX_HOST
) ? "HOST" : "Unknown"))),
5165 * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point
5166 * @cmnd: Pointer to scsi_cmnd data structure.
5168 * This routine does a device reset by sending a LUN_RESET task management
5176 lpfc_device_reset_handler(struct scsi_cmnd
*cmnd
)
5178 struct Scsi_Host
*shost
= cmnd
->device
->host
;
5179 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
5180 struct lpfc_rport_data
*rdata
;
5181 struct lpfc_nodelist
*pnode
;
5182 unsigned tgt_id
= cmnd
->device
->id
;
5183 uint64_t lun_id
= cmnd
->device
->lun
;
5184 struct lpfc_scsi_event_header scsi_event
;
5187 rdata
= lpfc_rport_data_from_scsi_device(cmnd
->device
);
5188 if (!rdata
|| !rdata
->pnode
) {
5189 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
5190 "0798 Device Reset rport failure: rdata x%p\n",
5194 pnode
= rdata
->pnode
;
5195 status
= fc_block_scsi_eh(cmnd
);
5196 if (status
!= 0 && status
!= SUCCESS
)
5199 status
= lpfc_chk_tgt_mapped(vport
, cmnd
);
5200 if (status
== FAILED
) {
5201 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
5202 "0721 Device Reset rport failure: rdata x%p\n", rdata
);
5206 scsi_event
.event_type
= FC_REG_SCSI_EVENT
;
5207 scsi_event
.subcategory
= LPFC_EVENT_LUNRESET
;
5208 scsi_event
.lun
= lun_id
;
5209 memcpy(scsi_event
.wwpn
, &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
5210 memcpy(scsi_event
.wwnn
, &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
5212 fc_host_post_vendor_event(shost
, fc_get_event_number(),
5213 sizeof(scsi_event
), (char *)&scsi_event
, LPFC_NL_VENDOR_ID
);
5215 status
= lpfc_send_taskmgmt(vport
, cmnd
, tgt_id
, lun_id
,
5218 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
5219 "0713 SCSI layer issued Device Reset (%d, %llu) "
5220 "return x%x\n", tgt_id
, lun_id
, status
);
5223 * We have to clean up i/o as : they may be orphaned by the TMF;
5224 * or if the TMF failed, they may be in an indeterminate state.
5226 * We will report success if all the i/o aborts successfully.
5228 if (status
== SUCCESS
)
5229 status
= lpfc_reset_flush_io_context(vport
, tgt_id
, lun_id
,
5236 * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point
5237 * @cmnd: Pointer to scsi_cmnd data structure.
5239 * This routine does a target reset by sending a TARGET_RESET task management
5247 lpfc_target_reset_handler(struct scsi_cmnd
*cmnd
)
5249 struct Scsi_Host
*shost
= cmnd
->device
->host
;
5250 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
5251 struct lpfc_rport_data
*rdata
;
5252 struct lpfc_nodelist
*pnode
;
5253 unsigned tgt_id
= cmnd
->device
->id
;
5254 uint64_t lun_id
= cmnd
->device
->lun
;
5255 struct lpfc_scsi_event_header scsi_event
;
5258 rdata
= lpfc_rport_data_from_scsi_device(cmnd
->device
);
5260 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
5261 "0799 Target Reset rport failure: rdata x%p\n", rdata
);
5264 pnode
= rdata
->pnode
;
5265 status
= fc_block_scsi_eh(cmnd
);
5266 if (status
!= 0 && status
!= SUCCESS
)
5269 status
= lpfc_chk_tgt_mapped(vport
, cmnd
);
5270 if (status
== FAILED
) {
5271 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
5272 "0722 Target Reset rport failure: rdata x%p\n", rdata
);
5274 spin_lock_irq(shost
->host_lock
);
5275 pnode
->nlp_flag
&= ~NLP_NPR_ADISC
;
5276 pnode
->nlp_fcp_info
&= ~NLP_FCP_2_DEVICE
;
5277 spin_unlock_irq(shost
->host_lock
);
5279 lpfc_reset_flush_io_context(vport
, tgt_id
, lun_id
,
5281 return FAST_IO_FAIL
;
5284 scsi_event
.event_type
= FC_REG_SCSI_EVENT
;
5285 scsi_event
.subcategory
= LPFC_EVENT_TGTRESET
;
5287 memcpy(scsi_event
.wwpn
, &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
5288 memcpy(scsi_event
.wwnn
, &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
5290 fc_host_post_vendor_event(shost
, fc_get_event_number(),
5291 sizeof(scsi_event
), (char *)&scsi_event
, LPFC_NL_VENDOR_ID
);
5293 status
= lpfc_send_taskmgmt(vport
, cmnd
, tgt_id
, lun_id
,
5296 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
5297 "0723 SCSI layer issued Target Reset (%d, %llu) "
5298 "return x%x\n", tgt_id
, lun_id
, status
);
5301 * We have to clean up i/o as : they may be orphaned by the TMF;
5302 * or if the TMF failed, they may be in an indeterminate state.
5304 * We will report success if all the i/o aborts successfully.
5306 if (status
== SUCCESS
)
5307 status
= lpfc_reset_flush_io_context(vport
, tgt_id
, lun_id
,
5313 * lpfc_bus_reset_handler - scsi_host_template eh_bus_reset_handler entry point
5314 * @cmnd: Pointer to scsi_cmnd data structure.
5316 * This routine does target reset to all targets on @cmnd->device->host.
5317 * This emulates Parallel SCSI Bus Reset Semantics.
5324 lpfc_bus_reset_handler(struct scsi_cmnd
*cmnd
)
5326 struct Scsi_Host
*shost
= cmnd
->device
->host
;
5327 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
5328 struct lpfc_nodelist
*ndlp
= NULL
;
5329 struct lpfc_scsi_event_header scsi_event
;
5331 int ret
= SUCCESS
, status
, i
;
5333 scsi_event
.event_type
= FC_REG_SCSI_EVENT
;
5334 scsi_event
.subcategory
= LPFC_EVENT_BUSRESET
;
5336 memcpy(scsi_event
.wwpn
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
5337 memcpy(scsi_event
.wwnn
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
5339 fc_host_post_vendor_event(shost
, fc_get_event_number(),
5340 sizeof(scsi_event
), (char *)&scsi_event
, LPFC_NL_VENDOR_ID
);
5342 status
= fc_block_scsi_eh(cmnd
);
5343 if (status
!= 0 && status
!= SUCCESS
)
5347 * Since the driver manages a single bus device, reset all
5348 * targets known to the driver. Should any target reset
5349 * fail, this routine returns failure to the midlayer.
5351 for (i
= 0; i
< LPFC_MAX_TARGET
; i
++) {
5352 /* Search for mapped node by target ID */
5354 spin_lock_irq(shost
->host_lock
);
5355 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
5356 if (!NLP_CHK_NODE_ACT(ndlp
))
5358 if (vport
->phba
->cfg_fcp2_no_tgt_reset
&&
5359 (ndlp
->nlp_fcp_info
& NLP_FCP_2_DEVICE
))
5361 if (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
&&
5362 ndlp
->nlp_sid
== i
&&
5364 ndlp
->nlp_type
& NLP_FCP_TARGET
) {
5369 spin_unlock_irq(shost
->host_lock
);
5373 status
= lpfc_send_taskmgmt(vport
, cmnd
,
5374 i
, 0, FCP_TARGET_RESET
);
5376 if (status
!= SUCCESS
) {
5377 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
5378 "0700 Bus Reset on target %d failed\n",
5384 * We have to clean up i/o as : they may be orphaned by the TMFs
5385 * above; or if any of the TMFs failed, they may be in an
5386 * indeterminate state.
5387 * We will report success if all the i/o aborts successfully.
5390 status
= lpfc_reset_flush_io_context(vport
, 0, 0, LPFC_CTX_HOST
);
5391 if (status
!= SUCCESS
)
5394 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
5395 "0714 SCSI layer issued Bus Reset Data: x%x\n", ret
);
5400 * lpfc_host_reset_handler - scsi_host_template eh_host_reset_handler entry pt
5401 * @cmnd: Pointer to scsi_cmnd data structure.
5403 * This routine does host reset to the adaptor port. It brings the HBA
5404 * offline, performs a board restart, and then brings the board back online.
5405 * The lpfc_offline calls lpfc_sli_hba_down which will abort and local
5406 * reject all outstanding SCSI commands to the host and error returned
5407 * back to SCSI mid-level. As this will be SCSI mid-level's last resort
5408 * of error handling, it will only return error if resetting of the adapter
5409 * is not successful; in all other cases, will return success.
5416 lpfc_host_reset_handler(struct scsi_cmnd
*cmnd
)
5418 struct Scsi_Host
*shost
= cmnd
->device
->host
;
5419 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
5420 struct lpfc_hba
*phba
= vport
->phba
;
5421 int rc
, ret
= SUCCESS
;
5423 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
5424 "3172 SCSI layer issued Host Reset Data:\n");
5426 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
5428 rc
= lpfc_sli_brdrestart(phba
);
5431 rc
= lpfc_online(phba
);
5434 lpfc_unblock_mgmt_io(phba
);
5436 if (ret
== FAILED
) {
5437 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
5438 "3323 Failed host reset, bring it offline\n");
5439 lpfc_sli4_offline_eratt(phba
);
5445 * lpfc_slave_alloc - scsi_host_template slave_alloc entry point
5446 * @sdev: Pointer to scsi_device.
5448 * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's
5449 * globally available list of scsi buffers. This routine also makes sure scsi
5450 * buffer is not allocated more than HBA limit conveyed to midlayer. This list
5451 * of scsi buffer exists for the lifetime of the driver.
5458 lpfc_slave_alloc(struct scsi_device
*sdev
)
5460 struct lpfc_vport
*vport
= (struct lpfc_vport
*) sdev
->host
->hostdata
;
5461 struct lpfc_hba
*phba
= vport
->phba
;
5462 struct fc_rport
*rport
= starget_to_rport(scsi_target(sdev
));
5464 uint32_t num_to_alloc
= 0;
5465 int num_allocated
= 0;
5467 struct lpfc_device_data
*device_data
;
5468 unsigned long flags
;
5469 struct lpfc_name target_wwpn
;
5471 if (!rport
|| fc_remote_port_chkready(rport
))
5474 if (phba
->cfg_fof
) {
5477 * Check to see if the device data structure for the lun
5478 * exists. If not, create one.
5481 u64_to_wwn(rport
->port_name
, target_wwpn
.u
.wwn
);
5482 spin_lock_irqsave(&phba
->devicelock
, flags
);
5483 device_data
= __lpfc_get_device_data(phba
,
5485 &vport
->fc_portname
,
5489 spin_unlock_irqrestore(&phba
->devicelock
, flags
);
5490 device_data
= lpfc_create_device_data(phba
,
5491 &vport
->fc_portname
,
5494 phba
->cfg_XLanePriority
,
5498 spin_lock_irqsave(&phba
->devicelock
, flags
);
5499 list_add_tail(&device_data
->listentry
, &phba
->luns
);
5501 device_data
->rport_data
= rport
->dd_data
;
5502 device_data
->available
= true;
5503 spin_unlock_irqrestore(&phba
->devicelock
, flags
);
5504 sdev
->hostdata
= device_data
;
5506 sdev
->hostdata
= rport
->dd_data
;
5508 sdev_cnt
= atomic_inc_return(&phba
->sdev_cnt
);
5511 * Populate the cmds_per_lun count scsi_bufs into this host's globally
5512 * available list of scsi buffers. Don't allocate more than the
5513 * HBA limit conveyed to the midlayer via the host structure. The
5514 * formula accounts for the lun_queue_depth + error handlers + 1
5515 * extra. This list of scsi bufs exists for the lifetime of the driver.
5517 total
= phba
->total_scsi_bufs
;
5518 num_to_alloc
= vport
->cfg_lun_queue_depth
+ 2;
5520 /* If allocated buffers are enough do nothing */
5521 if ((sdev_cnt
* (vport
->cfg_lun_queue_depth
+ 2)) < total
)
5524 /* Allow some exchanges to be available always to complete discovery */
5525 if (total
>= phba
->cfg_hba_queue_depth
- LPFC_DISC_IOCB_BUFF_COUNT
) {
5526 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
5527 "0704 At limitation of %d preallocated "
5528 "command buffers\n", total
);
5530 /* Allow some exchanges to be available always to complete discovery */
5531 } else if (total
+ num_to_alloc
>
5532 phba
->cfg_hba_queue_depth
- LPFC_DISC_IOCB_BUFF_COUNT
) {
5533 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
5534 "0705 Allocation request of %d "
5535 "command buffers will exceed max of %d. "
5536 "Reducing allocation request to %d.\n",
5537 num_to_alloc
, phba
->cfg_hba_queue_depth
,
5538 (phba
->cfg_hba_queue_depth
- total
));
5539 num_to_alloc
= phba
->cfg_hba_queue_depth
- total
;
5541 num_allocated
= lpfc_new_scsi_buf(vport
, num_to_alloc
);
5542 if (num_to_alloc
!= num_allocated
) {
5543 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
5544 "0708 Allocation request of %d "
5545 "command buffers did not succeed. "
5546 "Allocated %d buffers.\n",
5547 num_to_alloc
, num_allocated
);
5549 if (num_allocated
> 0)
5550 phba
->total_scsi_bufs
+= num_allocated
;
5555 * lpfc_slave_configure - scsi_host_template slave_configure entry point
5556 * @sdev: Pointer to scsi_device.
5558 * This routine configures following items
5559 * - Tag command queuing support for @sdev if supported.
5560 * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set.
5566 lpfc_slave_configure(struct scsi_device
*sdev
)
5568 struct lpfc_vport
*vport
= (struct lpfc_vport
*) sdev
->host
->hostdata
;
5569 struct lpfc_hba
*phba
= vport
->phba
;
5571 scsi_change_queue_depth(sdev
, vport
->cfg_lun_queue_depth
);
5573 if (phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) {
5574 lpfc_sli_handle_fast_ring_event(phba
,
5575 &phba
->sli
.sli3_ring
[LPFC_FCP_RING
], HA_R0RE_REQ
);
5576 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
)
5577 lpfc_poll_rearm_timer(phba
);
5584 * lpfc_slave_destroy - slave_destroy entry point of SHT data structure
5585 * @sdev: Pointer to scsi_device.
5587 * This routine sets @sdev hostatdata filed to null.
5590 lpfc_slave_destroy(struct scsi_device
*sdev
)
5592 struct lpfc_vport
*vport
= (struct lpfc_vport
*) sdev
->host
->hostdata
;
5593 struct lpfc_hba
*phba
= vport
->phba
;
5594 unsigned long flags
;
5595 struct lpfc_device_data
*device_data
= sdev
->hostdata
;
5597 atomic_dec(&phba
->sdev_cnt
);
5598 if ((phba
->cfg_fof
) && (device_data
)) {
5599 spin_lock_irqsave(&phba
->devicelock
, flags
);
5600 device_data
->available
= false;
5601 if (!device_data
->oas_enabled
)
5602 lpfc_delete_device_data(phba
, device_data
);
5603 spin_unlock_irqrestore(&phba
->devicelock
, flags
);
5605 sdev
->hostdata
= NULL
;
5610 * lpfc_create_device_data - creates and initializes device data structure for OAS
5611 * @pha: Pointer to host bus adapter structure.
5612 * @vport_wwpn: Pointer to vport's wwpn information
5613 * @target_wwpn: Pointer to target's wwpn information
5614 * @lun: Lun on target
5615 * @atomic_create: Flag to indicate if memory should be allocated using the
5616 * GFP_ATOMIC flag or not.
5618 * This routine creates a device data structure which will contain identifying
5619 * information for the device (host wwpn, target wwpn, lun), state of OAS,
5620 * whether or not the corresponding lun is available by the system,
5621 * and pointer to the rport data.
5625 * Pointer to lpfc_device_data - Success
5627 struct lpfc_device_data
*
5628 lpfc_create_device_data(struct lpfc_hba
*phba
, struct lpfc_name
*vport_wwpn
,
5629 struct lpfc_name
*target_wwpn
, uint64_t lun
,
5630 uint32_t pri
, bool atomic_create
)
5633 struct lpfc_device_data
*lun_info
;
5636 if (unlikely(!phba
) || !vport_wwpn
|| !target_wwpn
||
5640 /* Attempt to create the device data to contain lun info */
5643 memory_flags
= GFP_ATOMIC
;
5645 memory_flags
= GFP_KERNEL
;
5646 lun_info
= mempool_alloc(phba
->device_data_mem_pool
, memory_flags
);
5649 INIT_LIST_HEAD(&lun_info
->listentry
);
5650 lun_info
->rport_data
= NULL
;
5651 memcpy(&lun_info
->device_id
.vport_wwpn
, vport_wwpn
,
5652 sizeof(struct lpfc_name
));
5653 memcpy(&lun_info
->device_id
.target_wwpn
, target_wwpn
,
5654 sizeof(struct lpfc_name
));
5655 lun_info
->device_id
.lun
= lun
;
5656 lun_info
->oas_enabled
= false;
5657 lun_info
->priority
= pri
;
5658 lun_info
->available
= false;
5663 * lpfc_delete_device_data - frees a device data structure for OAS
5664 * @pha: Pointer to host bus adapter structure.
5665 * @lun_info: Pointer to device data structure to free.
5667 * This routine frees the previously allocated device data structure passed.
5671 lpfc_delete_device_data(struct lpfc_hba
*phba
,
5672 struct lpfc_device_data
*lun_info
)
5675 if (unlikely(!phba
) || !lun_info
||
5679 if (!list_empty(&lun_info
->listentry
))
5680 list_del(&lun_info
->listentry
);
5681 mempool_free(lun_info
, phba
->device_data_mem_pool
);
5686 * __lpfc_get_device_data - returns the device data for the specified lun
5687 * @pha: Pointer to host bus adapter structure.
5688 * @list: Point to list to search.
5689 * @vport_wwpn: Pointer to vport's wwpn information
5690 * @target_wwpn: Pointer to target's wwpn information
5691 * @lun: Lun on target
5693 * This routine searches the list passed for the specified lun's device data.
5694 * This function does not hold locks, it is the responsibility of the caller
5695 * to ensure the proper lock is held before calling the function.
5699 * Pointer to lpfc_device_data - Success
5701 struct lpfc_device_data
*
5702 __lpfc_get_device_data(struct lpfc_hba
*phba
, struct list_head
*list
,
5703 struct lpfc_name
*vport_wwpn
,
5704 struct lpfc_name
*target_wwpn
, uint64_t lun
)
5707 struct lpfc_device_data
*lun_info
;
5709 if (unlikely(!phba
) || !list
|| !vport_wwpn
|| !target_wwpn
||
5713 /* Check to see if the lun is already enabled for OAS. */
5715 list_for_each_entry(lun_info
, list
, listentry
) {
5716 if ((memcmp(&lun_info
->device_id
.vport_wwpn
, vport_wwpn
,
5717 sizeof(struct lpfc_name
)) == 0) &&
5718 (memcmp(&lun_info
->device_id
.target_wwpn
, target_wwpn
,
5719 sizeof(struct lpfc_name
)) == 0) &&
5720 (lun_info
->device_id
.lun
== lun
))
5728 * lpfc_find_next_oas_lun - searches for the next oas lun
5729 * @pha: Pointer to host bus adapter structure.
5730 * @vport_wwpn: Pointer to vport's wwpn information
5731 * @target_wwpn: Pointer to target's wwpn information
5732 * @starting_lun: Pointer to the lun to start searching for
5733 * @found_vport_wwpn: Pointer to the found lun's vport wwpn information
5734 * @found_target_wwpn: Pointer to the found lun's target wwpn information
5735 * @found_lun: Pointer to the found lun.
5736 * @found_lun_status: Pointer to status of the found lun.
5738 * This routine searches the luns list for the specified lun
5739 * or the first lun for the vport/target. If the vport wwpn contains
5740 * a zero value then a specific vport is not specified. In this case
5741 * any vport which contains the lun will be considered a match. If the
5742 * target wwpn contains a zero value then a specific target is not specified.
5743 * In this case any target which contains the lun will be considered a
5744 * match. If the lun is found, the lun, vport wwpn, target wwpn and lun status
5745 * are returned. The function will also return the next lun if available.
5746 * If the next lun is not found, starting_lun parameter will be set to
5754 lpfc_find_next_oas_lun(struct lpfc_hba
*phba
, struct lpfc_name
*vport_wwpn
,
5755 struct lpfc_name
*target_wwpn
, uint64_t *starting_lun
,
5756 struct lpfc_name
*found_vport_wwpn
,
5757 struct lpfc_name
*found_target_wwpn
,
5758 uint64_t *found_lun
,
5759 uint32_t *found_lun_status
,
5760 uint32_t *found_lun_pri
)
5763 unsigned long flags
;
5764 struct lpfc_device_data
*lun_info
;
5765 struct lpfc_device_id
*device_id
;
5769 if (unlikely(!phba
) || !vport_wwpn
|| !target_wwpn
||
5770 !starting_lun
|| !found_vport_wwpn
||
5771 !found_target_wwpn
|| !found_lun
|| !found_lun_status
||
5772 (*starting_lun
== NO_MORE_OAS_LUN
) ||
5776 lun
= *starting_lun
;
5777 *found_lun
= NO_MORE_OAS_LUN
;
5778 *starting_lun
= NO_MORE_OAS_LUN
;
5780 /* Search for lun or the lun closet in value */
5782 spin_lock_irqsave(&phba
->devicelock
, flags
);
5783 list_for_each_entry(lun_info
, &phba
->luns
, listentry
) {
5784 if (((wwn_to_u64(vport_wwpn
->u
.wwn
) == 0) ||
5785 (memcmp(&lun_info
->device_id
.vport_wwpn
, vport_wwpn
,
5786 sizeof(struct lpfc_name
)) == 0)) &&
5787 ((wwn_to_u64(target_wwpn
->u
.wwn
) == 0) ||
5788 (memcmp(&lun_info
->device_id
.target_wwpn
, target_wwpn
,
5789 sizeof(struct lpfc_name
)) == 0)) &&
5790 (lun_info
->oas_enabled
)) {
5791 device_id
= &lun_info
->device_id
;
5793 ((lun
== FIND_FIRST_OAS_LUN
) ||
5794 (device_id
->lun
== lun
))) {
5795 *found_lun
= device_id
->lun
;
5796 memcpy(found_vport_wwpn
,
5797 &device_id
->vport_wwpn
,
5798 sizeof(struct lpfc_name
));
5799 memcpy(found_target_wwpn
,
5800 &device_id
->target_wwpn
,
5801 sizeof(struct lpfc_name
));
5802 if (lun_info
->available
)
5804 OAS_LUN_STATUS_EXISTS
;
5806 *found_lun_status
= 0;
5807 *found_lun_pri
= lun_info
->priority
;
5808 if (phba
->cfg_oas_flags
& OAS_FIND_ANY_VPORT
)
5809 memset(vport_wwpn
, 0x0,
5810 sizeof(struct lpfc_name
));
5811 if (phba
->cfg_oas_flags
& OAS_FIND_ANY_TARGET
)
5812 memset(target_wwpn
, 0x0,
5813 sizeof(struct lpfc_name
));
5816 *starting_lun
= device_id
->lun
;
5817 memcpy(vport_wwpn
, &device_id
->vport_wwpn
,
5818 sizeof(struct lpfc_name
));
5819 memcpy(target_wwpn
, &device_id
->target_wwpn
,
5820 sizeof(struct lpfc_name
));
5825 spin_unlock_irqrestore(&phba
->devicelock
, flags
);
5830 * lpfc_enable_oas_lun - enables a lun for OAS operations
5831 * @pha: Pointer to host bus adapter structure.
5832 * @vport_wwpn: Pointer to vport's wwpn information
5833 * @target_wwpn: Pointer to target's wwpn information
5836 * This routine enables a lun for oas operations. The routines does so by
5837 * doing the following :
5839 * 1) Checks to see if the device data for the lun has been created.
5840 * 2) If found, sets the OAS enabled flag if not set and returns.
5841 * 3) Otherwise, creates a device data structure.
5842 * 4) If successfully created, indicates the device data is for an OAS lun,
5843 * indicates the lun is not available and add to the list of luns.
5850 lpfc_enable_oas_lun(struct lpfc_hba
*phba
, struct lpfc_name
*vport_wwpn
,
5851 struct lpfc_name
*target_wwpn
, uint64_t lun
, uint8_t pri
)
5854 struct lpfc_device_data
*lun_info
;
5855 unsigned long flags
;
5857 if (unlikely(!phba
) || !vport_wwpn
|| !target_wwpn
||
5861 spin_lock_irqsave(&phba
->devicelock
, flags
);
5863 /* Check to see if the device data for the lun has been created */
5864 lun_info
= __lpfc_get_device_data(phba
, &phba
->luns
, vport_wwpn
,
5867 if (!lun_info
->oas_enabled
)
5868 lun_info
->oas_enabled
= true;
5869 lun_info
->priority
= pri
;
5870 spin_unlock_irqrestore(&phba
->devicelock
, flags
);
5874 /* Create an lun info structure and add to list of luns */
5875 lun_info
= lpfc_create_device_data(phba
, vport_wwpn
, target_wwpn
, lun
,
5878 lun_info
->oas_enabled
= true;
5879 lun_info
->priority
= pri
;
5880 lun_info
->available
= false;
5881 list_add_tail(&lun_info
->listentry
, &phba
->luns
);
5882 spin_unlock_irqrestore(&phba
->devicelock
, flags
);
5885 spin_unlock_irqrestore(&phba
->devicelock
, flags
);
5890 * lpfc_disable_oas_lun - disables a lun for OAS operations
5891 * @pha: Pointer to host bus adapter structure.
5892 * @vport_wwpn: Pointer to vport's wwpn information
5893 * @target_wwpn: Pointer to target's wwpn information
5896 * This routine disables a lun for oas operations. The routines does so by
5897 * doing the following :
5899 * 1) Checks to see if the device data for the lun is created.
5900 * 2) If present, clears the flag indicating this lun is for OAS.
5901 * 3) If the lun is not available by the system, the device data is
5909 lpfc_disable_oas_lun(struct lpfc_hba
*phba
, struct lpfc_name
*vport_wwpn
,
5910 struct lpfc_name
*target_wwpn
, uint64_t lun
, uint8_t pri
)
5913 struct lpfc_device_data
*lun_info
;
5914 unsigned long flags
;
5916 if (unlikely(!phba
) || !vport_wwpn
|| !target_wwpn
||
5920 spin_lock_irqsave(&phba
->devicelock
, flags
);
5922 /* Check to see if the lun is available. */
5923 lun_info
= __lpfc_get_device_data(phba
,
5924 &phba
->luns
, vport_wwpn
,
5927 lun_info
->oas_enabled
= false;
5928 lun_info
->priority
= pri
;
5929 if (!lun_info
->available
)
5930 lpfc_delete_device_data(phba
, lun_info
);
5931 spin_unlock_irqrestore(&phba
->devicelock
, flags
);
5935 spin_unlock_irqrestore(&phba
->devicelock
, flags
);
5940 lpfc_no_command(struct Scsi_Host
*shost
, struct scsi_cmnd
*cmnd
)
5942 return SCSI_MLQUEUE_HOST_BUSY
;
5946 lpfc_no_handler(struct scsi_cmnd
*cmnd
)
5952 lpfc_no_slave(struct scsi_device
*sdev
)
5957 struct scsi_host_template lpfc_template_nvme
= {
5958 .module
= THIS_MODULE
,
5959 .name
= LPFC_DRIVER_NAME
,
5960 .proc_name
= LPFC_DRIVER_NAME
,
5962 .queuecommand
= lpfc_no_command
,
5963 .eh_abort_handler
= lpfc_no_handler
,
5964 .eh_device_reset_handler
= lpfc_no_handler
,
5965 .eh_target_reset_handler
= lpfc_no_handler
,
5966 .eh_bus_reset_handler
= lpfc_no_handler
,
5967 .eh_host_reset_handler
= lpfc_no_handler
,
5968 .slave_alloc
= lpfc_no_slave
,
5969 .slave_configure
= lpfc_no_slave
,
5970 .scan_finished
= lpfc_scan_finished
,
5974 .use_clustering
= ENABLE_CLUSTERING
,
5975 .shost_attrs
= lpfc_hba_attrs
,
5976 .max_sectors
= 0xFFFF,
5977 .vendor_id
= LPFC_NL_VENDOR_ID
,
5978 .track_queue_depth
= 0,
5981 struct scsi_host_template lpfc_template_no_hr
= {
5982 .module
= THIS_MODULE
,
5983 .name
= LPFC_DRIVER_NAME
,
5984 .proc_name
= LPFC_DRIVER_NAME
,
5986 .queuecommand
= lpfc_queuecommand
,
5987 .eh_timed_out
= fc_eh_timed_out
,
5988 .eh_abort_handler
= lpfc_abort_handler
,
5989 .eh_device_reset_handler
= lpfc_device_reset_handler
,
5990 .eh_target_reset_handler
= lpfc_target_reset_handler
,
5991 .eh_bus_reset_handler
= lpfc_bus_reset_handler
,
5992 .slave_alloc
= lpfc_slave_alloc
,
5993 .slave_configure
= lpfc_slave_configure
,
5994 .slave_destroy
= lpfc_slave_destroy
,
5995 .scan_finished
= lpfc_scan_finished
,
5997 .sg_tablesize
= LPFC_DEFAULT_SG_SEG_CNT
,
5998 .cmd_per_lun
= LPFC_CMD_PER_LUN
,
5999 .use_clustering
= ENABLE_CLUSTERING
,
6000 .shost_attrs
= lpfc_hba_attrs
,
6001 .max_sectors
= 0xFFFF,
6002 .vendor_id
= LPFC_NL_VENDOR_ID
,
6003 .change_queue_depth
= scsi_change_queue_depth
,
6004 .track_queue_depth
= 1,
6007 struct scsi_host_template lpfc_template
= {
6008 .module
= THIS_MODULE
,
6009 .name
= LPFC_DRIVER_NAME
,
6010 .proc_name
= LPFC_DRIVER_NAME
,
6012 .queuecommand
= lpfc_queuecommand
,
6013 .eh_timed_out
= fc_eh_timed_out
,
6014 .eh_abort_handler
= lpfc_abort_handler
,
6015 .eh_device_reset_handler
= lpfc_device_reset_handler
,
6016 .eh_target_reset_handler
= lpfc_target_reset_handler
,
6017 .eh_bus_reset_handler
= lpfc_bus_reset_handler
,
6018 .eh_host_reset_handler
= lpfc_host_reset_handler
,
6019 .slave_alloc
= lpfc_slave_alloc
,
6020 .slave_configure
= lpfc_slave_configure
,
6021 .slave_destroy
= lpfc_slave_destroy
,
6022 .scan_finished
= lpfc_scan_finished
,
6024 .sg_tablesize
= LPFC_DEFAULT_SG_SEG_CNT
,
6025 .cmd_per_lun
= LPFC_CMD_PER_LUN
,
6026 .use_clustering
= ENABLE_CLUSTERING
,
6027 .shost_attrs
= lpfc_hba_attrs
,
6028 .max_sectors
= 0xFFFF,
6029 .vendor_id
= LPFC_NL_VENDOR_ID
,
6030 .change_queue_depth
= scsi_change_queue_depth
,
6031 .track_queue_depth
= 1,
6034 struct scsi_host_template lpfc_vport_template
= {
6035 .module
= THIS_MODULE
,
6036 .name
= LPFC_DRIVER_NAME
,
6037 .proc_name
= LPFC_DRIVER_NAME
,
6039 .queuecommand
= lpfc_queuecommand
,
6040 .eh_timed_out
= fc_eh_timed_out
,
6041 .eh_abort_handler
= lpfc_abort_handler
,
6042 .eh_device_reset_handler
= lpfc_device_reset_handler
,
6043 .eh_target_reset_handler
= lpfc_target_reset_handler
,
6044 .slave_alloc
= lpfc_slave_alloc
,
6045 .slave_configure
= lpfc_slave_configure
,
6046 .slave_destroy
= lpfc_slave_destroy
,
6047 .scan_finished
= lpfc_scan_finished
,
6049 .sg_tablesize
= LPFC_DEFAULT_SG_SEG_CNT
,
6050 .cmd_per_lun
= LPFC_CMD_PER_LUN
,
6051 .use_clustering
= ENABLE_CLUSTERING
,
6052 .shost_attrs
= lpfc_vport_attrs
,
6053 .max_sectors
= 0xFFFF,
6054 .change_queue_depth
= scsi_change_queue_depth
,
6055 .track_queue_depth
= 1,