1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2024 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 <linux/unaligned.h>
29 #include <linux/t10-pi.h>
30 #include <linux/crc-t10dif.h>
31 #include <linux/blk-cgroup.h>
32 #include <net/checksum.h>
34 #include <scsi/scsi.h>
35 #include <scsi/scsi_device.h>
36 #include <scsi/scsi_eh.h>
37 #include <scsi/scsi_host.h>
38 #include <scsi/scsi_tcq.h>
39 #include <scsi/scsi_transport_fc.h>
41 #include "lpfc_version.h"
45 #include "lpfc_sli4.h"
47 #include "lpfc_disc.h"
49 #include "lpfc_scsi.h"
50 #include "lpfc_logmsg.h"
51 #include "lpfc_crtn.h"
52 #include "lpfc_vport.h"
54 #define LPFC_RESET_WAIT 2
55 #define LPFC_ABORT_WAIT 2
57 static char *dif_op_str
[] = {
67 struct scsi_dif_tuple
{
68 __be16 guard_tag
; /* Checksum */
69 __be16 app_tag
; /* Opaque storage */
70 __be32 ref_tag
; /* Target LBA or indirect LBA */
73 static struct lpfc_rport_data
*
74 lpfc_rport_data_from_scsi_device(struct scsi_device
*sdev
)
76 struct lpfc_vport
*vport
= (struct lpfc_vport
*)sdev
->host
->hostdata
;
78 if (vport
->phba
->cfg_fof
)
79 return ((struct lpfc_device_data
*)sdev
->hostdata
)->rport_data
;
81 return (struct lpfc_rport_data
*)sdev
->hostdata
;
85 lpfc_release_scsi_buf_s4(struct lpfc_hba
*phba
, struct lpfc_io_buf
*psb
);
87 lpfc_release_scsi_buf_s3(struct lpfc_hba
*phba
, struct lpfc_io_buf
*psb
);
89 lpfc_prot_group_type(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
);
92 * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge.
93 * @phba: Pointer to HBA object.
94 * @lpfc_cmd: lpfc scsi command object pointer.
96 * This function is called from the lpfc_prep_task_mgmt_cmd function to
97 * set the last bit in the response sge entry.
100 lpfc_sli4_set_rsp_sgl_last(struct lpfc_hba
*phba
,
101 struct lpfc_io_buf
*lpfc_cmd
)
103 struct sli4_sge
*sgl
= (struct sli4_sge
*)lpfc_cmd
->dma_sgl
;
106 sgl
->word2
= le32_to_cpu(sgl
->word2
);
107 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
108 sgl
->word2
= cpu_to_le32(sgl
->word2
);
113 * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread
114 * @phba: The Hba for which this call is being executed.
116 * This routine is called when there is resource error in driver or firmware.
117 * This routine posts WORKER_RAMP_DOWN_QUEUE event for @phba. This routine
118 * posts at most 1 event each second. This routine wakes up worker thread of
119 * @phba to process WORKER_RAM_DOWN_EVENT event.
121 * This routine should be called with no lock held.
124 lpfc_rampdown_queue_depth(struct lpfc_hba
*phba
)
128 unsigned long expires
;
130 spin_lock_irqsave(&phba
->hbalock
, flags
);
131 atomic_inc(&phba
->num_rsrc_err
);
132 phba
->last_rsrc_error_time
= jiffies
;
134 expires
= phba
->last_ramp_down_time
+ QUEUE_RAMP_DOWN_INTERVAL
;
135 if (time_after(expires
, jiffies
)) {
136 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
140 phba
->last_ramp_down_time
= jiffies
;
142 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
144 spin_lock_irqsave(&phba
->pport
->work_port_lock
, flags
);
145 evt_posted
= phba
->pport
->work_port_events
& WORKER_RAMP_DOWN_QUEUE
;
147 phba
->pport
->work_port_events
|= WORKER_RAMP_DOWN_QUEUE
;
148 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, flags
);
151 lpfc_worker_wake_up(phba
);
156 * lpfc_ramp_down_queue_handler - WORKER_RAMP_DOWN_QUEUE event handler
157 * @phba: The Hba for which this call is being executed.
159 * This routine is called to process WORKER_RAMP_DOWN_QUEUE event for worker
160 * thread.This routine reduces queue depth for all scsi device on each vport
161 * associated with @phba.
164 lpfc_ramp_down_queue_handler(struct lpfc_hba
*phba
)
166 struct lpfc_vport
**vports
;
167 struct Scsi_Host
*shost
;
168 struct scsi_device
*sdev
;
169 unsigned long new_queue_depth
;
170 unsigned long num_rsrc_err
;
173 num_rsrc_err
= atomic_read(&phba
->num_rsrc_err
);
176 * The error and success command counters are global per
177 * driver instance. If another handler has already
178 * operated on this error event, just exit.
180 if (num_rsrc_err
== 0)
183 vports
= lpfc_create_vport_work_array(phba
);
185 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
186 shost
= lpfc_shost_from_vport(vports
[i
]);
187 shost_for_each_device(sdev
, shost
) {
188 if (num_rsrc_err
>= sdev
->queue_depth
)
191 new_queue_depth
= sdev
->queue_depth
-
193 scsi_change_queue_depth(sdev
, new_queue_depth
);
196 lpfc_destroy_vport_work_array(phba
, vports
);
197 atomic_set(&phba
->num_rsrc_err
, 0);
201 * lpfc_scsi_dev_block - set all scsi hosts to block state
202 * @phba: Pointer to HBA context object.
204 * This function walks vport list and set each SCSI host to block state
205 * by invoking fc_remote_port_delete() routine. This function is invoked
206 * with EEH when device's PCI slot has been permanently disabled.
209 lpfc_scsi_dev_block(struct lpfc_hba
*phba
)
211 struct lpfc_vport
**vports
;
212 struct Scsi_Host
*shost
;
213 struct scsi_device
*sdev
;
214 struct fc_rport
*rport
;
217 vports
= lpfc_create_vport_work_array(phba
);
219 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
220 shost
= lpfc_shost_from_vport(vports
[i
]);
221 shost_for_each_device(sdev
, shost
) {
222 rport
= starget_to_rport(scsi_target(sdev
));
223 fc_remote_port_delete(rport
);
226 lpfc_destroy_vport_work_array(phba
, vports
);
230 * lpfc_new_scsi_buf_s3 - Scsi buffer allocator for HBA with SLI3 IF spec
231 * @vport: The virtual port for which this call being executed.
232 * @num_to_alloc: The requested number of buffers to allocate.
234 * This routine allocates a scsi buffer for device with SLI-3 interface spec,
235 * the scsi buffer contains all the necessary information needed to initiate
236 * a SCSI I/O. The non-DMAable buffer region contains information to build
237 * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP,
238 * and the initial BPL. In addition to allocating memory, the FCP CMND and
239 * FCP RSP BDEs are setup in the BPL and the BPL BDE is setup in the IOCB.
242 * int - number of scsi buffers that were allocated.
243 * 0 = failure, less than num_to_alloc is a partial failure.
246 lpfc_new_scsi_buf_s3(struct lpfc_vport
*vport
, int num_to_alloc
)
248 struct lpfc_hba
*phba
= vport
->phba
;
249 struct lpfc_io_buf
*psb
;
250 struct ulp_bde64
*bpl
;
252 dma_addr_t pdma_phys_fcp_cmd
;
253 dma_addr_t pdma_phys_fcp_rsp
;
254 dma_addr_t pdma_phys_sgl
;
258 bpl_size
= phba
->cfg_sg_dma_buf_size
-
259 (sizeof(struct fcp_cmnd
) + sizeof(struct fcp_rsp
));
261 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
262 "9067 ALLOC %d scsi_bufs: %d (%d + %d + %d)\n",
263 num_to_alloc
, phba
->cfg_sg_dma_buf_size
,
264 (int)sizeof(struct fcp_cmnd
),
265 (int)sizeof(struct fcp_rsp
), bpl_size
);
267 for (bcnt
= 0; bcnt
< num_to_alloc
; bcnt
++) {
268 psb
= kzalloc(sizeof(struct lpfc_io_buf
), GFP_KERNEL
);
273 * Get memory from the pci pool to map the virt space to pci
274 * bus space for an I/O. The DMA buffer includes space for the
275 * struct fcp_cmnd, struct fcp_rsp and the number of bde's
276 * necessary to support the sg_tablesize.
278 psb
->data
= dma_pool_zalloc(phba
->lpfc_sg_dma_buf_pool
,
279 GFP_KERNEL
, &psb
->dma_handle
);
286 /* Allocate iotag for psb->cur_iocbq. */
287 iotag
= lpfc_sli_next_iotag(phba
, &psb
->cur_iocbq
);
289 dma_pool_free(phba
->lpfc_sg_dma_buf_pool
,
290 psb
->data
, psb
->dma_handle
);
294 psb
->cur_iocbq
.cmd_flag
|= LPFC_IO_FCP
;
296 psb
->fcp_cmnd
= psb
->data
;
297 psb
->fcp_rsp
= psb
->data
+ sizeof(struct fcp_cmnd
);
298 psb
->dma_sgl
= psb
->data
+ sizeof(struct fcp_cmnd
) +
299 sizeof(struct fcp_rsp
);
301 /* Initialize local short-hand pointers. */
302 bpl
= (struct ulp_bde64
*)psb
->dma_sgl
;
303 pdma_phys_fcp_cmd
= psb
->dma_handle
;
304 pdma_phys_fcp_rsp
= psb
->dma_handle
+ sizeof(struct fcp_cmnd
);
305 pdma_phys_sgl
= psb
->dma_handle
+ sizeof(struct fcp_cmnd
) +
306 sizeof(struct fcp_rsp
);
309 * The first two bdes are the FCP_CMD and FCP_RSP. The balance
310 * are sg list bdes. Initialize the first two and leave the
311 * rest for queuecommand.
313 bpl
[0].addrHigh
= le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd
));
314 bpl
[0].addrLow
= le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd
));
315 bpl
[0].tus
.f
.bdeSize
= sizeof(struct fcp_cmnd
);
316 bpl
[0].tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
317 bpl
[0].tus
.w
= le32_to_cpu(bpl
[0].tus
.w
);
319 /* Setup the physical region for the FCP RSP */
320 bpl
[1].addrHigh
= le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp
));
321 bpl
[1].addrLow
= le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp
));
322 bpl
[1].tus
.f
.bdeSize
= sizeof(struct fcp_rsp
);
323 bpl
[1].tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
324 bpl
[1].tus
.w
= le32_to_cpu(bpl
[1].tus
.w
);
327 * Since the IOCB for the FCP I/O is built into this
328 * lpfc_scsi_buf, initialize it with all known data now.
330 iocb
= &psb
->cur_iocbq
.iocb
;
331 iocb
->un
.fcpi64
.bdl
.ulpIoTag32
= 0;
332 if ((phba
->sli_rev
== 3) &&
333 !(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
)) {
334 /* fill in immediate fcp command BDE */
335 iocb
->un
.fcpi64
.bdl
.bdeFlags
= BUFF_TYPE_BDE_IMMED
;
336 iocb
->un
.fcpi64
.bdl
.bdeSize
= sizeof(struct fcp_cmnd
);
337 iocb
->un
.fcpi64
.bdl
.addrLow
= offsetof(IOCB_t
,
339 iocb
->un
.fcpi64
.bdl
.addrHigh
= 0;
340 iocb
->ulpBdeCount
= 0;
342 /* fill in response BDE */
343 iocb
->unsli3
.fcp_ext
.rbde
.tus
.f
.bdeFlags
=
345 iocb
->unsli3
.fcp_ext
.rbde
.tus
.f
.bdeSize
=
346 sizeof(struct fcp_rsp
);
347 iocb
->unsli3
.fcp_ext
.rbde
.addrLow
=
348 putPaddrLow(pdma_phys_fcp_rsp
);
349 iocb
->unsli3
.fcp_ext
.rbde
.addrHigh
=
350 putPaddrHigh(pdma_phys_fcp_rsp
);
352 iocb
->un
.fcpi64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
353 iocb
->un
.fcpi64
.bdl
.bdeSize
=
354 (2 * sizeof(struct ulp_bde64
));
355 iocb
->un
.fcpi64
.bdl
.addrLow
=
356 putPaddrLow(pdma_phys_sgl
);
357 iocb
->un
.fcpi64
.bdl
.addrHigh
=
358 putPaddrHigh(pdma_phys_sgl
);
359 iocb
->ulpBdeCount
= 1;
362 iocb
->ulpClass
= CLASS3
;
363 psb
->status
= IOSTAT_SUCCESS
;
364 /* Put it back into the SCSI buffer list */
365 psb
->cur_iocbq
.io_buf
= psb
;
366 spin_lock_init(&psb
->buf_lock
);
367 lpfc_release_scsi_buf_s3(phba
, psb
);
375 * lpfc_sli4_vport_delete_fcp_xri_aborted -Remove all ndlp references for vport
376 * @vport: pointer to lpfc vport data structure.
378 * This routine is invoked by the vport cleanup for deletions and the cleanup
379 * for an ndlp on removal.
382 lpfc_sli4_vport_delete_fcp_xri_aborted(struct lpfc_vport
*vport
)
384 struct lpfc_hba
*phba
= vport
->phba
;
385 struct lpfc_io_buf
*psb
, *next_psb
;
386 struct lpfc_sli4_hdw_queue
*qp
;
387 unsigned long iflag
= 0;
390 if (!(vport
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
))
393 spin_lock_irqsave(&phba
->hbalock
, iflag
);
394 for (idx
= 0; idx
< phba
->cfg_hdw_queue
; idx
++) {
395 qp
= &phba
->sli4_hba
.hdwq
[idx
];
397 spin_lock(&qp
->abts_io_buf_list_lock
);
398 list_for_each_entry_safe(psb
, next_psb
,
399 &qp
->lpfc_abts_io_buf_list
, list
) {
400 if (psb
->cur_iocbq
.cmd_flag
& LPFC_IO_NVME
)
403 if (psb
->rdata
&& psb
->rdata
->pnode
&&
404 psb
->rdata
->pnode
->vport
== vport
)
407 spin_unlock(&qp
->abts_io_buf_list_lock
);
409 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
413 * lpfc_sli4_io_xri_aborted - Fast-path process of fcp xri abort
414 * @phba: pointer to lpfc hba data structure.
415 * @axri: pointer to the fcp xri abort wcqe structure.
416 * @idx: index into hdwq
418 * This routine is invoked by the worker thread to process a SLI4 fast-path
419 * FCP or NVME aborted xri.
422 lpfc_sli4_io_xri_aborted(struct lpfc_hba
*phba
,
423 struct sli4_wcqe_xri_aborted
*axri
, int idx
)
427 struct lpfc_io_buf
*psb
, *next_psb
;
428 struct lpfc_sli4_hdw_queue
*qp
;
429 unsigned long iflag
= 0;
430 struct lpfc_iocbq
*iocbq
;
432 struct lpfc_nodelist
*ndlp
;
434 struct lpfc_sli_ring
*pring
= phba
->sli4_hba
.els_wq
->pring
;
435 struct scsi_cmnd
*cmd
;
438 if (!(phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
))
440 offline
= pci_channel_offline(phba
->pcidev
);
442 xri
= bf_get(lpfc_wcqe_xa_xri
, axri
);
443 rxid
= bf_get(lpfc_wcqe_xa_remote_xid
, axri
);
445 qp
= &phba
->sli4_hba
.hdwq
[idx
];
446 spin_lock_irqsave(&phba
->hbalock
, iflag
);
447 spin_lock(&qp
->abts_io_buf_list_lock
);
448 list_for_each_entry_safe(psb
, next_psb
,
449 &qp
->lpfc_abts_io_buf_list
, list
) {
451 xri
= psb
->cur_iocbq
.sli4_xritag
;
452 if (psb
->cur_iocbq
.sli4_xritag
== xri
) {
453 list_del_init(&psb
->list
);
454 psb
->flags
&= ~LPFC_SBUF_XBUSY
;
455 psb
->status
= IOSTAT_SUCCESS
;
456 if (psb
->cur_iocbq
.cmd_flag
& LPFC_IO_NVME
) {
457 qp
->abts_nvme_io_bufs
--;
458 spin_unlock(&qp
->abts_io_buf_list_lock
);
459 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
461 lpfc_sli4_nvme_xri_aborted(phba
, axri
,
465 lpfc_sli4_nvme_pci_offline_aborted(phba
, psb
);
466 spin_lock_irqsave(&phba
->hbalock
, iflag
);
467 spin_lock(&qp
->abts_io_buf_list_lock
);
470 qp
->abts_scsi_io_bufs
--;
471 spin_unlock(&qp
->abts_io_buf_list_lock
);
473 if (psb
->rdata
&& psb
->rdata
->pnode
)
474 ndlp
= psb
->rdata
->pnode
;
477 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
479 spin_lock_irqsave(&phba
->rrq_list_lock
, iflag
);
480 rrq_empty
= list_empty(&phba
->active_rrq_list
);
481 spin_unlock_irqrestore(&phba
->rrq_list_lock
, iflag
);
482 if (ndlp
&& !offline
) {
483 lpfc_set_rrq_active(phba
, ndlp
,
484 psb
->cur_iocbq
.sli4_lxritag
, rxid
, 1);
485 lpfc_sli4_abts_err_handler(phba
, ndlp
, axri
);
488 if (phba
->cfg_fcp_wait_abts_rsp
|| offline
) {
489 spin_lock_irqsave(&psb
->buf_lock
, iflag
);
492 spin_unlock_irqrestore(&psb
->buf_lock
, iflag
);
494 /* The sdev is not guaranteed to be valid post
501 * We expect there is an abort thread waiting
502 * for command completion wake up the thread.
504 spin_lock_irqsave(&psb
->buf_lock
, iflag
);
505 psb
->cur_iocbq
.cmd_flag
&=
506 ~LPFC_DRIVER_ABORTED
;
509 spin_unlock_irqrestore(&psb
->buf_lock
, iflag
);
512 lpfc_release_scsi_buf_s4(phba
, psb
);
514 lpfc_worker_wake_up(phba
);
517 spin_lock_irqsave(&phba
->hbalock
, iflag
);
518 spin_lock(&qp
->abts_io_buf_list_lock
);
522 spin_unlock(&qp
->abts_io_buf_list_lock
);
524 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
525 iocbq
= phba
->sli
.iocbq_lookup
[i
];
527 if (!(iocbq
->cmd_flag
& LPFC_IO_FCP
) ||
528 (iocbq
->cmd_flag
& LPFC_IO_LIBDFC
))
530 if (iocbq
->sli4_xritag
!= xri
)
532 psb
= container_of(iocbq
, struct lpfc_io_buf
, cur_iocbq
);
533 psb
->flags
&= ~LPFC_SBUF_XBUSY
;
534 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
535 if (!list_empty(&pring
->txq
))
536 lpfc_worker_wake_up(phba
);
540 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
544 * lpfc_get_scsi_buf_s3 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
545 * @phba: The HBA for which this call is being executed.
546 * @ndlp: pointer to a node-list data structure.
547 * @cmnd: Pointer to scsi_cmnd data structure.
549 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
550 * and returns to caller.
554 * Pointer to lpfc_scsi_buf - Success
556 static struct lpfc_io_buf
*
557 lpfc_get_scsi_buf_s3(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
558 struct scsi_cmnd
*cmnd
)
560 struct lpfc_io_buf
*lpfc_cmd
= NULL
;
561 struct list_head
*scsi_buf_list_get
= &phba
->lpfc_scsi_buf_list_get
;
562 unsigned long iflag
= 0;
564 spin_lock_irqsave(&phba
->scsi_buf_list_get_lock
, iflag
);
565 list_remove_head(scsi_buf_list_get
, lpfc_cmd
, struct lpfc_io_buf
,
568 spin_lock(&phba
->scsi_buf_list_put_lock
);
569 list_splice(&phba
->lpfc_scsi_buf_list_put
,
570 &phba
->lpfc_scsi_buf_list_get
);
571 INIT_LIST_HEAD(&phba
->lpfc_scsi_buf_list_put
);
572 list_remove_head(scsi_buf_list_get
, lpfc_cmd
,
573 struct lpfc_io_buf
, list
);
574 spin_unlock(&phba
->scsi_buf_list_put_lock
);
576 spin_unlock_irqrestore(&phba
->scsi_buf_list_get_lock
, iflag
);
578 if (lpfc_ndlp_check_qdepth(phba
, ndlp
) && lpfc_cmd
) {
579 atomic_inc(&ndlp
->cmd_pending
);
580 lpfc_cmd
->flags
|= LPFC_SBUF_BUMP_QDEPTH
;
585 * lpfc_get_scsi_buf_s4 - Get a scsi buffer from io_buf_list of the HBA
586 * @phba: The HBA for which this call is being executed.
587 * @ndlp: pointer to a node-list data structure.
588 * @cmnd: Pointer to scsi_cmnd data structure.
590 * This routine removes a scsi buffer from head of @hdwq io_buf_list
591 * and returns to caller.
595 * Pointer to lpfc_scsi_buf - Success
597 static struct lpfc_io_buf
*
598 lpfc_get_scsi_buf_s4(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
599 struct scsi_cmnd
*cmnd
)
601 struct lpfc_io_buf
*lpfc_cmd
;
602 struct lpfc_sli4_hdw_queue
*qp
;
603 struct sli4_sge_le
*sgl
;
604 dma_addr_t pdma_phys_fcp_rsp
;
605 dma_addr_t pdma_phys_fcp_cmd
;
608 struct fcp_cmd_rsp_buf
*tmp
= NULL
;
610 cpu
= raw_smp_processor_id();
611 if (cmnd
&& phba
->cfg_fcp_io_sched
== LPFC_FCP_SCHED_BY_HDWQ
) {
612 tag
= blk_mq_unique_tag(scsi_cmd_to_rq(cmnd
));
613 idx
= blk_mq_unique_tag_to_hwq(tag
);
615 idx
= phba
->sli4_hba
.cpu_map
[cpu
].hdwq
;
618 lpfc_cmd
= lpfc_get_io_buf(phba
, ndlp
, idx
,
619 !phba
->cfg_xri_rebalancing
);
621 qp
= &phba
->sli4_hba
.hdwq
[idx
];
626 /* Setup key fields in buffer that may have been changed
627 * if other protocols used this buffer.
629 lpfc_cmd
->cur_iocbq
.cmd_flag
= LPFC_IO_FCP
;
630 lpfc_cmd
->prot_seg_cnt
= 0;
631 lpfc_cmd
->seg_cnt
= 0;
632 lpfc_cmd
->timeout
= 0;
634 lpfc_cmd
->start_time
= jiffies
;
635 lpfc_cmd
->waitq
= NULL
;
637 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
638 lpfc_cmd
->prot_data_type
= 0;
640 tmp
= lpfc_get_cmd_rsp_buf_per_hdwq(phba
, lpfc_cmd
);
642 lpfc_release_io_buf(phba
, lpfc_cmd
, lpfc_cmd
->hdwq
);
646 lpfc_cmd
->fcp_cmnd
= tmp
->fcp_cmnd
;
647 lpfc_cmd
->fcp_rsp
= tmp
->fcp_rsp
;
650 * The first two SGEs are the FCP_CMD and FCP_RSP.
651 * The balance are sg list bdes. Initialize the
652 * first two and leave the rest for queuecommand.
654 sgl
= (struct sli4_sge_le
*)lpfc_cmd
->dma_sgl
;
655 pdma_phys_fcp_cmd
= tmp
->fcp_cmd_rsp_dma_handle
;
656 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd
));
657 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd
));
658 bf_set_le32(lpfc_sli4_sge_last
, sgl
, 0);
659 if (cmnd
&& cmnd
->cmd_len
> LPFC_FCP_CDB_LEN
)
660 sgl
->sge_len
= cpu_to_le32(sizeof(struct fcp_cmnd32
));
662 sgl
->sge_len
= cpu_to_le32(sizeof(struct fcp_cmnd
));
666 /* Setup the physical region for the FCP RSP */
667 pdma_phys_fcp_rsp
= pdma_phys_fcp_cmd
+ sizeof(struct fcp_cmnd32
);
668 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp
));
669 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp
));
670 bf_set_le32(lpfc_sli4_sge_last
, sgl
, 1);
671 sgl
->sge_len
= cpu_to_le32(sizeof(struct fcp_rsp
));
673 if (lpfc_ndlp_check_qdepth(phba
, ndlp
)) {
674 atomic_inc(&ndlp
->cmd_pending
);
675 lpfc_cmd
->flags
|= LPFC_SBUF_BUMP_QDEPTH
;
680 * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
681 * @phba: The HBA for which this call is being executed.
682 * @ndlp: pointer to a node-list data structure.
683 * @cmnd: Pointer to scsi_cmnd data structure.
685 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
686 * and returns to caller.
690 * Pointer to lpfc_scsi_buf - Success
692 static struct lpfc_io_buf
*
693 lpfc_get_scsi_buf(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
694 struct scsi_cmnd
*cmnd
)
696 return phba
->lpfc_get_scsi_buf(phba
, ndlp
, cmnd
);
700 * lpfc_release_scsi_buf_s3 - Return a scsi buffer back to hba scsi buf list
701 * @phba: The Hba for which this call is being executed.
702 * @psb: The scsi buffer which is being released.
704 * This routine releases @psb scsi buffer by adding it to tail of @phba
705 * lpfc_scsi_buf_list list.
708 lpfc_release_scsi_buf_s3(struct lpfc_hba
*phba
, struct lpfc_io_buf
*psb
)
710 unsigned long iflag
= 0;
713 psb
->prot_seg_cnt
= 0;
715 spin_lock_irqsave(&phba
->scsi_buf_list_put_lock
, iflag
);
717 psb
->cur_iocbq
.cmd_flag
= LPFC_IO_FCP
;
718 list_add_tail(&psb
->list
, &phba
->lpfc_scsi_buf_list_put
);
719 spin_unlock_irqrestore(&phba
->scsi_buf_list_put_lock
, iflag
);
723 * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list.
724 * @phba: The Hba for which this call is being executed.
725 * @psb: The scsi buffer which is being released.
727 * This routine releases @psb scsi buffer by adding it to tail of @hdwq
728 * io_buf_list list. For SLI4 XRI's are tied to the scsi buffer
729 * and cannot be reused for at least RA_TOV amount of time if it was
733 lpfc_release_scsi_buf_s4(struct lpfc_hba
*phba
, struct lpfc_io_buf
*psb
)
735 struct lpfc_sli4_hdw_queue
*qp
;
736 unsigned long iflag
= 0;
739 psb
->prot_seg_cnt
= 0;
742 if (psb
->flags
& LPFC_SBUF_XBUSY
) {
743 spin_lock_irqsave(&qp
->abts_io_buf_list_lock
, iflag
);
744 if (!phba
->cfg_fcp_wait_abts_rsp
)
746 list_add_tail(&psb
->list
, &qp
->lpfc_abts_io_buf_list
);
747 qp
->abts_scsi_io_bufs
++;
748 spin_unlock_irqrestore(&qp
->abts_io_buf_list_lock
, iflag
);
750 lpfc_release_io_buf(phba
, (struct lpfc_io_buf
*)psb
, qp
);
755 * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list.
756 * @phba: The Hba for which this call is being executed.
757 * @psb: The scsi buffer which is being released.
759 * This routine releases @psb scsi buffer by adding it to tail of @phba
760 * lpfc_scsi_buf_list list.
763 lpfc_release_scsi_buf(struct lpfc_hba
*phba
, struct lpfc_io_buf
*psb
)
765 if ((psb
->flags
& LPFC_SBUF_BUMP_QDEPTH
) && psb
->ndlp
)
766 atomic_dec(&psb
->ndlp
->cmd_pending
);
768 psb
->flags
&= ~LPFC_SBUF_BUMP_QDEPTH
;
769 phba
->lpfc_release_scsi_buf(phba
, psb
);
773 * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB
774 * @data: A pointer to the immediate command data portion of the IOCB.
775 * @fcp_cmnd: The FCP Command that is provided by the SCSI layer.
777 * The routine copies the entire FCP command from @fcp_cmnd to @data while
778 * byte swapping the data to big endian format for transmission on the wire.
781 lpfc_fcpcmd_to_iocb(u8
*data
, struct fcp_cmnd
*fcp_cmnd
)
785 for (i
= 0, j
= 0; i
< sizeof(struct fcp_cmnd
);
786 i
+= sizeof(uint32_t), j
++) {
787 ((uint32_t *)data
)[j
] = cpu_to_be32(((uint32_t *)fcp_cmnd
)[j
]);
792 * lpfc_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
793 * @phba: The Hba for which this call is being executed.
794 * @lpfc_cmd: The scsi buffer which is going to be mapped.
796 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
797 * field of @lpfc_cmd for device with SLI-3 interface spec. This routine scans
798 * through sg elements and format the bde. This routine also initializes all
799 * IOCB fields which are dependent on scsi command request buffer.
806 lpfc_scsi_prep_dma_buf_s3(struct lpfc_hba
*phba
, struct lpfc_io_buf
*lpfc_cmd
)
808 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
809 struct scatterlist
*sgel
= NULL
;
810 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
811 struct ulp_bde64
*bpl
= (struct ulp_bde64
*)lpfc_cmd
->dma_sgl
;
812 struct lpfc_iocbq
*iocbq
= &lpfc_cmd
->cur_iocbq
;
813 IOCB_t
*iocb_cmd
= &lpfc_cmd
->cur_iocbq
.iocb
;
814 struct ulp_bde64
*data_bde
= iocb_cmd
->unsli3
.fcp_ext
.dbde
;
816 uint32_t num_bde
= 0;
817 int nseg
, datadir
= scsi_cmnd
->sc_data_direction
;
820 * There are three possibilities here - use scatter-gather segment, use
821 * the single mapping, or neither. Start the lpfc command prep by
822 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
826 if (scsi_sg_count(scsi_cmnd
)) {
828 * The driver stores the segment count returned from dma_map_sg
829 * because this a count of dma-mappings used to map the use_sg
830 * pages. They are not guaranteed to be the same for those
831 * architectures that implement an IOMMU.
834 nseg
= dma_map_sg(&phba
->pcidev
->dev
, scsi_sglist(scsi_cmnd
),
835 scsi_sg_count(scsi_cmnd
), datadir
);
839 lpfc_cmd
->seg_cnt
= nseg
;
840 if (lpfc_cmd
->seg_cnt
> phba
->cfg_sg_seg_cnt
) {
841 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
842 "9064 BLKGRD: %s: Too many sg segments"
843 " from dma_map_sg. Config %d, seg_cnt"
844 " %d\n", __func__
, phba
->cfg_sg_seg_cnt
,
846 WARN_ON_ONCE(lpfc_cmd
->seg_cnt
> phba
->cfg_sg_seg_cnt
);
847 lpfc_cmd
->seg_cnt
= 0;
848 scsi_dma_unmap(scsi_cmnd
);
853 * The driver established a maximum scatter-gather segment count
854 * during probe that limits the number of sg elements in any
855 * single scsi command. Just run through the seg_cnt and format
857 * When using SLI-3 the driver will try to fit all the BDEs into
858 * the IOCB. If it can't then the BDEs get added to a BPL as it
859 * does for SLI-2 mode.
861 scsi_for_each_sg(scsi_cmnd
, sgel
, nseg
, num_bde
) {
862 physaddr
= sg_dma_address(sgel
);
863 if (phba
->sli_rev
== 3 &&
864 !(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
) &&
865 !(iocbq
->cmd_flag
& DSS_SECURITY_OP
) &&
866 nseg
<= LPFC_EXT_DATA_BDE_COUNT
) {
867 data_bde
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
868 data_bde
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
869 data_bde
->addrLow
= putPaddrLow(physaddr
);
870 data_bde
->addrHigh
= putPaddrHigh(physaddr
);
873 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
874 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
875 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
877 le32_to_cpu(putPaddrLow(physaddr
));
879 le32_to_cpu(putPaddrHigh(physaddr
));
886 * Finish initializing those IOCB fields that are dependent on the
887 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
888 * explicitly reinitialized and for SLI-3 the extended bde count is
889 * explicitly reinitialized since all iocb memory resources are reused.
891 if (phba
->sli_rev
== 3 &&
892 !(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
) &&
893 !(iocbq
->cmd_flag
& DSS_SECURITY_OP
)) {
894 if (num_bde
> LPFC_EXT_DATA_BDE_COUNT
) {
896 * The extended IOCB format can only fit 3 BDE or a BPL.
897 * This I/O has more than 3 BDE so the 1st data bde will
898 * be a BPL that is filled in here.
900 physaddr
= lpfc_cmd
->dma_handle
;
901 data_bde
->tus
.f
.bdeFlags
= BUFF_TYPE_BLP_64
;
902 data_bde
->tus
.f
.bdeSize
= (num_bde
*
903 sizeof(struct ulp_bde64
));
904 physaddr
+= (sizeof(struct fcp_cmnd
) +
905 sizeof(struct fcp_rsp
) +
906 (2 * sizeof(struct ulp_bde64
)));
907 data_bde
->addrHigh
= putPaddrHigh(physaddr
);
908 data_bde
->addrLow
= putPaddrLow(physaddr
);
909 /* ebde count includes the response bde and data bpl */
910 iocb_cmd
->unsli3
.fcp_ext
.ebde_count
= 2;
912 /* ebde count includes the response bde and data bdes */
913 iocb_cmd
->unsli3
.fcp_ext
.ebde_count
= (num_bde
+ 1);
916 iocb_cmd
->un
.fcpi64
.bdl
.bdeSize
=
917 ((num_bde
+ 2) * sizeof(struct ulp_bde64
));
918 iocb_cmd
->unsli3
.fcp_ext
.ebde_count
= (num_bde
+ 1);
920 fcp_cmnd
->fcpDl
= cpu_to_be32(scsi_bufflen(scsi_cmnd
));
923 * Due to difference in data length between DIF/non-DIF paths,
924 * we need to set word 4 of IOCB here
926 iocb_cmd
->un
.fcpi
.fcpi_parm
= scsi_bufflen(scsi_cmnd
);
927 lpfc_fcpcmd_to_iocb(iocb_cmd
->unsli3
.fcp_ext
.icd
, fcp_cmnd
);
931 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
933 /* Return BG_ERR_INIT if error injection is detected by Initiator */
934 #define BG_ERR_INIT 0x1
935 /* Return BG_ERR_TGT if error injection is detected by Target */
936 #define BG_ERR_TGT 0x2
937 /* Return BG_ERR_SWAP if swapping CSUM<-->CRC is required for error injection */
938 #define BG_ERR_SWAP 0x10
940 * Return BG_ERR_CHECK if disabling Guard/Ref/App checking is required for
943 #define BG_ERR_CHECK 0x20
946 * lpfc_bg_err_inject - Determine if we should inject an error
947 * @phba: The Hba for which this call is being executed.
948 * @sc: The SCSI command to examine
949 * @reftag: (out) BlockGuard reference tag for transmitted data
950 * @apptag: (out) BlockGuard application tag for transmitted data
951 * @new_guard: (in) Value to replace CRC with if needed
953 * Returns BG_ERR_* bit mask or 0 if request ignored
956 lpfc_bg_err_inject(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
957 uint32_t *reftag
, uint16_t *apptag
, uint32_t new_guard
)
959 struct scatterlist
*sgpe
; /* s/g prot entry */
960 struct lpfc_io_buf
*lpfc_cmd
= NULL
;
961 struct scsi_dif_tuple
*src
= NULL
;
962 struct lpfc_nodelist
*ndlp
;
963 struct lpfc_rport_data
*rdata
;
964 uint32_t op
= scsi_get_prot_op(sc
);
971 if (op
== SCSI_PROT_NORMAL
)
974 sgpe
= scsi_prot_sglist(sc
);
975 lba
= scsi_prot_ref_tag(sc
);
977 /* First check if we need to match the LBA */
978 if (phba
->lpfc_injerr_lba
!= LPFC_INJERR_LBA_OFF
) {
979 blksize
= scsi_prot_interval(sc
);
980 numblks
= (scsi_bufflen(sc
) + blksize
- 1) / blksize
;
982 /* Make sure we have the right LBA if one is specified */
983 if (phba
->lpfc_injerr_lba
< (u64
)lba
||
984 (phba
->lpfc_injerr_lba
>= (u64
)(lba
+ numblks
)))
987 blockoff
= phba
->lpfc_injerr_lba
- (u64
)lba
;
988 numblks
= sg_dma_len(sgpe
) /
989 sizeof(struct scsi_dif_tuple
);
990 if (numblks
< blockoff
)
995 /* Next check if we need to match the remote NPortID or WWPN */
996 rdata
= lpfc_rport_data_from_scsi_device(sc
->device
);
997 if (rdata
&& rdata
->pnode
) {
1000 /* Make sure we have the right NPortID if one is specified */
1001 if (phba
->lpfc_injerr_nportid
&&
1002 (phba
->lpfc_injerr_nportid
!= ndlp
->nlp_DID
))
1006 * Make sure we have the right WWPN if one is specified.
1007 * wwn[0] should be a non-zero NAA in a good WWPN.
1009 if (phba
->lpfc_injerr_wwpn
.u
.wwn
[0] &&
1010 (memcmp(&ndlp
->nlp_portname
, &phba
->lpfc_injerr_wwpn
,
1011 sizeof(struct lpfc_name
)) != 0))
1015 /* Setup a ptr to the protection data if the SCSI host provides it */
1017 src
= (struct scsi_dif_tuple
*)sg_virt(sgpe
);
1019 lpfc_cmd
= (struct lpfc_io_buf
*)sc
->host_scribble
;
1022 /* Should we change the Reference Tag */
1024 if (phba
->lpfc_injerr_wref_cnt
) {
1026 case SCSI_PROT_WRITE_PASS
:
1029 * For WRITE_PASS, force the error
1030 * to be sent on the wire. It should
1031 * be detected by the Target.
1032 * If blockoff != 0 error will be
1033 * inserted in middle of the IO.
1036 lpfc_printf_log(phba
, KERN_ERR
,
1038 "9076 BLKGRD: Injecting reftag error: "
1039 "write lba x%lx + x%x oldrefTag x%x\n",
1040 (unsigned long)lba
, blockoff
,
1041 be32_to_cpu(src
->ref_tag
));
1044 * Save the old ref_tag so we can
1045 * restore it on completion.
1048 lpfc_cmd
->prot_data_type
=
1050 lpfc_cmd
->prot_data_segment
=
1052 lpfc_cmd
->prot_data
=
1055 src
->ref_tag
= cpu_to_be32(0xDEADBEEF);
1056 phba
->lpfc_injerr_wref_cnt
--;
1057 if (phba
->lpfc_injerr_wref_cnt
== 0) {
1058 phba
->lpfc_injerr_nportid
= 0;
1059 phba
->lpfc_injerr_lba
=
1060 LPFC_INJERR_LBA_OFF
;
1061 memset(&phba
->lpfc_injerr_wwpn
,
1062 0, sizeof(struct lpfc_name
));
1064 rc
= BG_ERR_TGT
| BG_ERR_CHECK
;
1069 case SCSI_PROT_WRITE_INSERT
:
1071 * For WRITE_INSERT, force the error
1072 * to be sent on the wire. It should be
1073 * detected by the Target.
1075 /* DEADBEEF will be the reftag on the wire */
1076 *reftag
= 0xDEADBEEF;
1077 phba
->lpfc_injerr_wref_cnt
--;
1078 if (phba
->lpfc_injerr_wref_cnt
== 0) {
1079 phba
->lpfc_injerr_nportid
= 0;
1080 phba
->lpfc_injerr_lba
=
1081 LPFC_INJERR_LBA_OFF
;
1082 memset(&phba
->lpfc_injerr_wwpn
,
1083 0, sizeof(struct lpfc_name
));
1085 rc
= BG_ERR_TGT
| BG_ERR_CHECK
;
1087 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1088 "9078 BLKGRD: Injecting reftag error: "
1089 "write lba x%lx\n", (unsigned long)lba
);
1091 case SCSI_PROT_WRITE_STRIP
:
1093 * For WRITE_STRIP and WRITE_PASS,
1094 * force the error on data
1095 * being copied from SLI-Host to SLI-Port.
1097 *reftag
= 0xDEADBEEF;
1098 phba
->lpfc_injerr_wref_cnt
--;
1099 if (phba
->lpfc_injerr_wref_cnt
== 0) {
1100 phba
->lpfc_injerr_nportid
= 0;
1101 phba
->lpfc_injerr_lba
=
1102 LPFC_INJERR_LBA_OFF
;
1103 memset(&phba
->lpfc_injerr_wwpn
,
1104 0, sizeof(struct lpfc_name
));
1108 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1109 "9077 BLKGRD: Injecting reftag error: "
1110 "write lba x%lx\n", (unsigned long)lba
);
1114 if (phba
->lpfc_injerr_rref_cnt
) {
1116 case SCSI_PROT_READ_INSERT
:
1117 case SCSI_PROT_READ_STRIP
:
1118 case SCSI_PROT_READ_PASS
:
1120 * For READ_STRIP and READ_PASS, force the
1121 * error on data being read off the wire. It
1122 * should force an IO error to the driver.
1124 *reftag
= 0xDEADBEEF;
1125 phba
->lpfc_injerr_rref_cnt
--;
1126 if (phba
->lpfc_injerr_rref_cnt
== 0) {
1127 phba
->lpfc_injerr_nportid
= 0;
1128 phba
->lpfc_injerr_lba
=
1129 LPFC_INJERR_LBA_OFF
;
1130 memset(&phba
->lpfc_injerr_wwpn
,
1131 0, sizeof(struct lpfc_name
));
1135 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1136 "9079 BLKGRD: Injecting reftag error: "
1137 "read lba x%lx\n", (unsigned long)lba
);
1143 /* Should we change the Application Tag */
1145 if (phba
->lpfc_injerr_wapp_cnt
) {
1147 case SCSI_PROT_WRITE_PASS
:
1150 * For WRITE_PASS, force the error
1151 * to be sent on the wire. It should
1152 * be detected by the Target.
1153 * If blockoff != 0 error will be
1154 * inserted in middle of the IO.
1157 lpfc_printf_log(phba
, KERN_ERR
,
1159 "9080 BLKGRD: Injecting apptag error: "
1160 "write lba x%lx + x%x oldappTag x%x\n",
1161 (unsigned long)lba
, blockoff
,
1162 be16_to_cpu(src
->app_tag
));
1165 * Save the old app_tag so we can
1166 * restore it on completion.
1169 lpfc_cmd
->prot_data_type
=
1171 lpfc_cmd
->prot_data_segment
=
1173 lpfc_cmd
->prot_data
=
1176 src
->app_tag
= cpu_to_be16(0xDEAD);
1177 phba
->lpfc_injerr_wapp_cnt
--;
1178 if (phba
->lpfc_injerr_wapp_cnt
== 0) {
1179 phba
->lpfc_injerr_nportid
= 0;
1180 phba
->lpfc_injerr_lba
=
1181 LPFC_INJERR_LBA_OFF
;
1182 memset(&phba
->lpfc_injerr_wwpn
,
1183 0, sizeof(struct lpfc_name
));
1185 rc
= BG_ERR_TGT
| BG_ERR_CHECK
;
1189 case SCSI_PROT_WRITE_INSERT
:
1191 * For WRITE_INSERT, force the
1192 * error to be sent on the wire. It should be
1193 * detected by the Target.
1195 /* DEAD will be the apptag on the wire */
1197 phba
->lpfc_injerr_wapp_cnt
--;
1198 if (phba
->lpfc_injerr_wapp_cnt
== 0) {
1199 phba
->lpfc_injerr_nportid
= 0;
1200 phba
->lpfc_injerr_lba
=
1201 LPFC_INJERR_LBA_OFF
;
1202 memset(&phba
->lpfc_injerr_wwpn
,
1203 0, sizeof(struct lpfc_name
));
1205 rc
= BG_ERR_TGT
| BG_ERR_CHECK
;
1207 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1208 "0813 BLKGRD: Injecting apptag error: "
1209 "write lba x%lx\n", (unsigned long)lba
);
1211 case SCSI_PROT_WRITE_STRIP
:
1213 * For WRITE_STRIP and WRITE_PASS,
1214 * force the error on data
1215 * being copied from SLI-Host to SLI-Port.
1218 phba
->lpfc_injerr_wapp_cnt
--;
1219 if (phba
->lpfc_injerr_wapp_cnt
== 0) {
1220 phba
->lpfc_injerr_nportid
= 0;
1221 phba
->lpfc_injerr_lba
=
1222 LPFC_INJERR_LBA_OFF
;
1223 memset(&phba
->lpfc_injerr_wwpn
,
1224 0, sizeof(struct lpfc_name
));
1228 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1229 "0812 BLKGRD: Injecting apptag error: "
1230 "write lba x%lx\n", (unsigned long)lba
);
1234 if (phba
->lpfc_injerr_rapp_cnt
) {
1236 case SCSI_PROT_READ_INSERT
:
1237 case SCSI_PROT_READ_STRIP
:
1238 case SCSI_PROT_READ_PASS
:
1240 * For READ_STRIP and READ_PASS, force the
1241 * error on data being read off the wire. It
1242 * should force an IO error to the driver.
1245 phba
->lpfc_injerr_rapp_cnt
--;
1246 if (phba
->lpfc_injerr_rapp_cnt
== 0) {
1247 phba
->lpfc_injerr_nportid
= 0;
1248 phba
->lpfc_injerr_lba
=
1249 LPFC_INJERR_LBA_OFF
;
1250 memset(&phba
->lpfc_injerr_wwpn
,
1251 0, sizeof(struct lpfc_name
));
1255 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1256 "0814 BLKGRD: Injecting apptag error: "
1257 "read lba x%lx\n", (unsigned long)lba
);
1264 /* Should we change the Guard Tag */
1266 if (phba
->lpfc_injerr_wgrd_cnt
) {
1268 case SCSI_PROT_WRITE_PASS
:
1272 case SCSI_PROT_WRITE_INSERT
:
1274 * For WRITE_INSERT, force the
1275 * error to be sent on the wire. It should be
1276 * detected by the Target.
1278 phba
->lpfc_injerr_wgrd_cnt
--;
1279 if (phba
->lpfc_injerr_wgrd_cnt
== 0) {
1280 phba
->lpfc_injerr_nportid
= 0;
1281 phba
->lpfc_injerr_lba
=
1282 LPFC_INJERR_LBA_OFF
;
1283 memset(&phba
->lpfc_injerr_wwpn
,
1284 0, sizeof(struct lpfc_name
));
1287 rc
|= BG_ERR_TGT
| BG_ERR_SWAP
;
1288 /* Signals the caller to swap CRC->CSUM */
1290 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1291 "0817 BLKGRD: Injecting guard error: "
1292 "write lba x%lx\n", (unsigned long)lba
);
1294 case SCSI_PROT_WRITE_STRIP
:
1296 * For WRITE_STRIP and WRITE_PASS,
1297 * force the error on data
1298 * being copied from SLI-Host to SLI-Port.
1300 phba
->lpfc_injerr_wgrd_cnt
--;
1301 if (phba
->lpfc_injerr_wgrd_cnt
== 0) {
1302 phba
->lpfc_injerr_nportid
= 0;
1303 phba
->lpfc_injerr_lba
=
1304 LPFC_INJERR_LBA_OFF
;
1305 memset(&phba
->lpfc_injerr_wwpn
,
1306 0, sizeof(struct lpfc_name
));
1309 rc
= BG_ERR_INIT
| BG_ERR_SWAP
;
1310 /* Signals the caller to swap CRC->CSUM */
1312 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1313 "0816 BLKGRD: Injecting guard error: "
1314 "write lba x%lx\n", (unsigned long)lba
);
1318 if (phba
->lpfc_injerr_rgrd_cnt
) {
1320 case SCSI_PROT_READ_INSERT
:
1321 case SCSI_PROT_READ_STRIP
:
1322 case SCSI_PROT_READ_PASS
:
1324 * For READ_STRIP and READ_PASS, force the
1325 * error on data being read off the wire. It
1326 * should force an IO error to the driver.
1328 phba
->lpfc_injerr_rgrd_cnt
--;
1329 if (phba
->lpfc_injerr_rgrd_cnt
== 0) {
1330 phba
->lpfc_injerr_nportid
= 0;
1331 phba
->lpfc_injerr_lba
=
1332 LPFC_INJERR_LBA_OFF
;
1333 memset(&phba
->lpfc_injerr_wwpn
,
1334 0, sizeof(struct lpfc_name
));
1337 rc
= BG_ERR_INIT
| BG_ERR_SWAP
;
1338 /* Signals the caller to swap CRC->CSUM */
1340 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1341 "0818 BLKGRD: Injecting guard error: "
1342 "read lba x%lx\n", (unsigned long)lba
);
1352 * lpfc_sc_to_bg_opcodes - Determine the BlockGuard opcodes to be used with
1353 * the specified SCSI command.
1354 * @phba: The Hba for which this call is being executed.
1355 * @sc: The SCSI command to examine
1356 * @txop: (out) BlockGuard operation for transmitted data
1357 * @rxop: (out) BlockGuard operation for received data
1359 * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
1363 lpfc_sc_to_bg_opcodes(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
1364 uint8_t *txop
, uint8_t *rxop
)
1368 if (sc
->prot_flags
& SCSI_PROT_IP_CHECKSUM
) {
1369 switch (scsi_get_prot_op(sc
)) {
1370 case SCSI_PROT_READ_INSERT
:
1371 case SCSI_PROT_WRITE_STRIP
:
1372 *rxop
= BG_OP_IN_NODIF_OUT_CSUM
;
1373 *txop
= BG_OP_IN_CSUM_OUT_NODIF
;
1376 case SCSI_PROT_READ_STRIP
:
1377 case SCSI_PROT_WRITE_INSERT
:
1378 *rxop
= BG_OP_IN_CRC_OUT_NODIF
;
1379 *txop
= BG_OP_IN_NODIF_OUT_CRC
;
1382 case SCSI_PROT_READ_PASS
:
1383 case SCSI_PROT_WRITE_PASS
:
1384 *rxop
= BG_OP_IN_CRC_OUT_CSUM
;
1385 *txop
= BG_OP_IN_CSUM_OUT_CRC
;
1388 case SCSI_PROT_NORMAL
:
1390 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1391 "9063 BLKGRD: Bad op/guard:%d/IP combination\n",
1392 scsi_get_prot_op(sc
));
1398 switch (scsi_get_prot_op(sc
)) {
1399 case SCSI_PROT_READ_STRIP
:
1400 case SCSI_PROT_WRITE_INSERT
:
1401 *rxop
= BG_OP_IN_CRC_OUT_NODIF
;
1402 *txop
= BG_OP_IN_NODIF_OUT_CRC
;
1405 case SCSI_PROT_READ_PASS
:
1406 case SCSI_PROT_WRITE_PASS
:
1407 *rxop
= BG_OP_IN_CRC_OUT_CRC
;
1408 *txop
= BG_OP_IN_CRC_OUT_CRC
;
1411 case SCSI_PROT_READ_INSERT
:
1412 case SCSI_PROT_WRITE_STRIP
:
1413 *rxop
= BG_OP_IN_NODIF_OUT_CRC
;
1414 *txop
= BG_OP_IN_CRC_OUT_NODIF
;
1417 case SCSI_PROT_NORMAL
:
1419 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1420 "9075 BLKGRD: Bad op/guard:%d/CRC combination\n",
1421 scsi_get_prot_op(sc
));
1430 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1432 * lpfc_bg_err_opcodes - reDetermine the BlockGuard opcodes to be used with
1433 * the specified SCSI command in order to force a guard tag error.
1434 * @phba: The Hba for which this call is being executed.
1435 * @sc: The SCSI command to examine
1436 * @txop: (out) BlockGuard operation for transmitted data
1437 * @rxop: (out) BlockGuard operation for received data
1439 * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
1443 lpfc_bg_err_opcodes(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
1444 uint8_t *txop
, uint8_t *rxop
)
1447 if (sc
->prot_flags
& SCSI_PROT_IP_CHECKSUM
) {
1448 switch (scsi_get_prot_op(sc
)) {
1449 case SCSI_PROT_READ_INSERT
:
1450 case SCSI_PROT_WRITE_STRIP
:
1451 *rxop
= BG_OP_IN_NODIF_OUT_CRC
;
1452 *txop
= BG_OP_IN_CRC_OUT_NODIF
;
1455 case SCSI_PROT_READ_STRIP
:
1456 case SCSI_PROT_WRITE_INSERT
:
1457 *rxop
= BG_OP_IN_CSUM_OUT_NODIF
;
1458 *txop
= BG_OP_IN_NODIF_OUT_CSUM
;
1461 case SCSI_PROT_READ_PASS
:
1462 case SCSI_PROT_WRITE_PASS
:
1463 *rxop
= BG_OP_IN_CSUM_OUT_CRC
;
1464 *txop
= BG_OP_IN_CRC_OUT_CSUM
;
1467 case SCSI_PROT_NORMAL
:
1473 switch (scsi_get_prot_op(sc
)) {
1474 case SCSI_PROT_READ_STRIP
:
1475 case SCSI_PROT_WRITE_INSERT
:
1476 *rxop
= BG_OP_IN_CSUM_OUT_NODIF
;
1477 *txop
= BG_OP_IN_NODIF_OUT_CSUM
;
1480 case SCSI_PROT_READ_PASS
:
1481 case SCSI_PROT_WRITE_PASS
:
1482 *rxop
= BG_OP_IN_CSUM_OUT_CSUM
;
1483 *txop
= BG_OP_IN_CSUM_OUT_CSUM
;
1486 case SCSI_PROT_READ_INSERT
:
1487 case SCSI_PROT_WRITE_STRIP
:
1488 *rxop
= BG_OP_IN_NODIF_OUT_CSUM
;
1489 *txop
= BG_OP_IN_CSUM_OUT_NODIF
;
1492 case SCSI_PROT_NORMAL
:
1503 * lpfc_bg_setup_bpl - Setup BlockGuard BPL with no protection data
1504 * @phba: The Hba for which this call is being executed.
1505 * @sc: pointer to scsi command we're working on
1506 * @bpl: pointer to buffer list for protection groups
1507 * @datasegcnt: number of segments of data that have been dma mapped
1509 * This function sets up BPL buffer list for protection groups of
1510 * type LPFC_PG_TYPE_NO_DIF
1512 * This is usually used when the HBA is instructed to generate
1513 * DIFs and insert them into data stream (or strip DIF from
1514 * incoming data stream)
1516 * The buffer list consists of just one protection group described
1518 * +-------------------------+
1519 * start of prot group --> | PDE_5 |
1520 * +-------------------------+
1522 * +-------------------------+
1524 * +-------------------------+
1525 * |more Data BDE's ... (opt)|
1526 * +-------------------------+
1529 * Note: Data s/g buffers have been dma mapped
1531 * Returns the number of BDEs added to the BPL.
1534 lpfc_bg_setup_bpl(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
1535 struct ulp_bde64
*bpl
, int datasegcnt
)
1537 struct scatterlist
*sgde
= NULL
; /* s/g data entry */
1538 struct lpfc_pde5
*pde5
= NULL
;
1539 struct lpfc_pde6
*pde6
= NULL
;
1540 dma_addr_t physaddr
;
1541 int i
= 0, num_bde
= 0, status
;
1542 int datadir
= sc
->sc_data_direction
;
1543 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1546 uint32_t checking
= 1;
1550 status
= lpfc_sc_to_bg_opcodes(phba
, sc
, &txop
, &rxop
);
1554 /* extract some info from the scsi command for pde*/
1555 reftag
= scsi_prot_ref_tag(sc
);
1557 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1558 rc
= lpfc_bg_err_inject(phba
, sc
, &reftag
, NULL
, 1);
1560 if (rc
& BG_ERR_SWAP
)
1561 lpfc_bg_err_opcodes(phba
, sc
, &txop
, &rxop
);
1562 if (rc
& BG_ERR_CHECK
)
1567 /* setup PDE5 with what we have */
1568 pde5
= (struct lpfc_pde5
*) bpl
;
1569 memset(pde5
, 0, sizeof(struct lpfc_pde5
));
1570 bf_set(pde5_type
, pde5
, LPFC_PDE5_DESCRIPTOR
);
1572 /* Endianness conversion if necessary for PDE5 */
1573 pde5
->word0
= cpu_to_le32(pde5
->word0
);
1574 pde5
->reftag
= cpu_to_le32(reftag
);
1576 /* advance bpl and increment bde count */
1579 pde6
= (struct lpfc_pde6
*) bpl
;
1581 /* setup PDE6 with the rest of the info */
1582 memset(pde6
, 0, sizeof(struct lpfc_pde6
));
1583 bf_set(pde6_type
, pde6
, LPFC_PDE6_DESCRIPTOR
);
1584 bf_set(pde6_optx
, pde6
, txop
);
1585 bf_set(pde6_oprx
, pde6
, rxop
);
1588 * We only need to check the data on READs, for WRITEs
1589 * protection data is automatically generated, not checked.
1591 if (datadir
== DMA_FROM_DEVICE
) {
1592 if (sc
->prot_flags
& SCSI_PROT_GUARD_CHECK
)
1593 bf_set(pde6_ce
, pde6
, checking
);
1595 bf_set(pde6_ce
, pde6
, 0);
1597 if (sc
->prot_flags
& SCSI_PROT_REF_CHECK
)
1598 bf_set(pde6_re
, pde6
, checking
);
1600 bf_set(pde6_re
, pde6
, 0);
1602 bf_set(pde6_ai
, pde6
, 1);
1603 bf_set(pde6_ae
, pde6
, 0);
1604 bf_set(pde6_apptagval
, pde6
, 0);
1606 /* Endianness conversion if necessary for PDE6 */
1607 pde6
->word0
= cpu_to_le32(pde6
->word0
);
1608 pde6
->word1
= cpu_to_le32(pde6
->word1
);
1609 pde6
->word2
= cpu_to_le32(pde6
->word2
);
1611 /* advance bpl and increment bde count */
1615 /* assumption: caller has already run dma_map_sg on command data */
1616 scsi_for_each_sg(sc
, sgde
, datasegcnt
, i
) {
1617 physaddr
= sg_dma_address(sgde
);
1618 bpl
->addrLow
= le32_to_cpu(putPaddrLow(physaddr
));
1619 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(physaddr
));
1620 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgde
);
1621 if (datadir
== DMA_TO_DEVICE
)
1622 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
1624 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
1625 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
1635 * lpfc_bg_setup_bpl_prot - Setup BlockGuard BPL with protection data
1636 * @phba: The Hba for which this call is being executed.
1637 * @sc: pointer to scsi command we're working on
1638 * @bpl: pointer to buffer list for protection groups
1639 * @datacnt: number of segments of data that have been dma mapped
1640 * @protcnt: number of segment of protection data that have been dma mapped
1642 * This function sets up BPL buffer list for protection groups of
1643 * type LPFC_PG_TYPE_DIF
1645 * This is usually used when DIFs are in their own buffers,
1646 * separate from the data. The HBA can then by instructed
1647 * to place the DIFs in the outgoing stream. For read operations,
1648 * The HBA could extract the DIFs and place it in DIF buffers.
1650 * The buffer list for this type consists of one or more of the
1651 * protection groups described below:
1652 * +-------------------------+
1653 * start of first prot group --> | PDE_5 |
1654 * +-------------------------+
1656 * +-------------------------+
1657 * | PDE_7 (Prot BDE) |
1658 * +-------------------------+
1660 * +-------------------------+
1661 * |more Data BDE's ... (opt)|
1662 * +-------------------------+
1663 * start of new prot group --> | PDE_5 |
1664 * +-------------------------+
1666 * +-------------------------+
1668 * Note: It is assumed that both data and protection s/g buffers have been
1671 * Returns the number of BDEs added to the BPL.
1674 lpfc_bg_setup_bpl_prot(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
1675 struct ulp_bde64
*bpl
, int datacnt
, int protcnt
)
1677 struct scatterlist
*sgde
= NULL
; /* s/g data entry */
1678 struct scatterlist
*sgpe
= NULL
; /* s/g prot entry */
1679 struct lpfc_pde5
*pde5
= NULL
;
1680 struct lpfc_pde6
*pde6
= NULL
;
1681 struct lpfc_pde7
*pde7
= NULL
;
1682 dma_addr_t dataphysaddr
, protphysaddr
;
1683 unsigned short curr_prot
= 0;
1684 unsigned int split_offset
;
1685 unsigned int protgroup_len
, protgroup_offset
= 0, protgroup_remainder
;
1686 unsigned int protgrp_blks
, protgrp_bytes
;
1687 unsigned int remainder
, subtotal
;
1689 int datadir
= sc
->sc_data_direction
;
1690 unsigned char pgdone
= 0, alldone
= 0;
1692 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1695 uint32_t checking
= 1;
1700 sgpe
= scsi_prot_sglist(sc
);
1701 sgde
= scsi_sglist(sc
);
1703 if (!sgpe
|| !sgde
) {
1704 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1705 "9020 Invalid s/g entry: data=x%px prot=x%px\n",
1710 status
= lpfc_sc_to_bg_opcodes(phba
, sc
, &txop
, &rxop
);
1714 /* extract some info from the scsi command */
1715 blksize
= scsi_prot_interval(sc
);
1716 reftag
= scsi_prot_ref_tag(sc
);
1718 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1719 rc
= lpfc_bg_err_inject(phba
, sc
, &reftag
, NULL
, 1);
1721 if (rc
& BG_ERR_SWAP
)
1722 lpfc_bg_err_opcodes(phba
, sc
, &txop
, &rxop
);
1723 if (rc
& BG_ERR_CHECK
)
1730 /* Check to see if we ran out of space */
1731 if (num_bde
>= (phba
->cfg_total_seg_cnt
- 2))
1734 /* setup PDE5 with what we have */
1735 pde5
= (struct lpfc_pde5
*) bpl
;
1736 memset(pde5
, 0, sizeof(struct lpfc_pde5
));
1737 bf_set(pde5_type
, pde5
, LPFC_PDE5_DESCRIPTOR
);
1739 /* Endianness conversion if necessary for PDE5 */
1740 pde5
->word0
= cpu_to_le32(pde5
->word0
);
1741 pde5
->reftag
= cpu_to_le32(reftag
);
1743 /* advance bpl and increment bde count */
1746 pde6
= (struct lpfc_pde6
*) bpl
;
1748 /* setup PDE6 with the rest of the info */
1749 memset(pde6
, 0, sizeof(struct lpfc_pde6
));
1750 bf_set(pde6_type
, pde6
, LPFC_PDE6_DESCRIPTOR
);
1751 bf_set(pde6_optx
, pde6
, txop
);
1752 bf_set(pde6_oprx
, pde6
, rxop
);
1754 if (sc
->prot_flags
& SCSI_PROT_GUARD_CHECK
)
1755 bf_set(pde6_ce
, pde6
, checking
);
1757 bf_set(pde6_ce
, pde6
, 0);
1759 if (sc
->prot_flags
& SCSI_PROT_REF_CHECK
)
1760 bf_set(pde6_re
, pde6
, checking
);
1762 bf_set(pde6_re
, pde6
, 0);
1764 bf_set(pde6_ai
, pde6
, 1);
1765 bf_set(pde6_ae
, pde6
, 0);
1766 bf_set(pde6_apptagval
, pde6
, 0);
1768 /* Endianness conversion if necessary for PDE6 */
1769 pde6
->word0
= cpu_to_le32(pde6
->word0
);
1770 pde6
->word1
= cpu_to_le32(pde6
->word1
);
1771 pde6
->word2
= cpu_to_le32(pde6
->word2
);
1773 /* advance bpl and increment bde count */
1777 /* setup the first BDE that points to protection buffer */
1778 protphysaddr
= sg_dma_address(sgpe
) + protgroup_offset
;
1779 protgroup_len
= sg_dma_len(sgpe
) - protgroup_offset
;
1781 /* must be integer multiple of the DIF block length */
1782 BUG_ON(protgroup_len
% 8);
1784 pde7
= (struct lpfc_pde7
*) bpl
;
1785 memset(pde7
, 0, sizeof(struct lpfc_pde7
));
1786 bf_set(pde7_type
, pde7
, LPFC_PDE7_DESCRIPTOR
);
1788 pde7
->addrHigh
= le32_to_cpu(putPaddrHigh(protphysaddr
));
1789 pde7
->addrLow
= le32_to_cpu(putPaddrLow(protphysaddr
));
1791 protgrp_blks
= protgroup_len
/ 8;
1792 protgrp_bytes
= protgrp_blks
* blksize
;
1794 /* check if this pde is crossing the 4K boundary; if so split */
1795 if ((pde7
->addrLow
& 0xfff) + protgroup_len
> 0x1000) {
1796 protgroup_remainder
= 0x1000 - (pde7
->addrLow
& 0xfff);
1797 protgroup_offset
+= protgroup_remainder
;
1798 protgrp_blks
= protgroup_remainder
/ 8;
1799 protgrp_bytes
= protgrp_blks
* blksize
;
1801 protgroup_offset
= 0;
1807 /* setup BDE's for data blocks associated with DIF data */
1809 subtotal
= 0; /* total bytes processed for current prot grp */
1811 /* Check to see if we ran out of space */
1812 if (num_bde
>= phba
->cfg_total_seg_cnt
)
1816 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1817 "9065 BLKGRD:%s Invalid data segment\n",
1822 dataphysaddr
= sg_dma_address(sgde
) + split_offset
;
1823 bpl
->addrLow
= le32_to_cpu(putPaddrLow(dataphysaddr
));
1824 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(dataphysaddr
));
1826 remainder
= sg_dma_len(sgde
) - split_offset
;
1828 if ((subtotal
+ remainder
) <= protgrp_bytes
) {
1829 /* we can use this whole buffer */
1830 bpl
->tus
.f
.bdeSize
= remainder
;
1833 if ((subtotal
+ remainder
) == protgrp_bytes
)
1836 /* must split this buffer with next prot grp */
1837 bpl
->tus
.f
.bdeSize
= protgrp_bytes
- subtotal
;
1838 split_offset
+= bpl
->tus
.f
.bdeSize
;
1841 subtotal
+= bpl
->tus
.f
.bdeSize
;
1843 if (datadir
== DMA_TO_DEVICE
)
1844 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
1846 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
1847 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
1854 /* Move to the next s/g segment if possible */
1855 sgde
= sg_next(sgde
);
1859 if (protgroup_offset
) {
1860 /* update the reference tag */
1861 reftag
+= protgrp_blks
;
1867 if (curr_prot
== protcnt
) {
1869 } else if (curr_prot
< protcnt
) {
1870 /* advance to next prot buffer */
1871 sgpe
= sg_next(sgpe
);
1874 /* update the reference tag */
1875 reftag
+= protgrp_blks
;
1877 /* if we're here, we have a bug */
1878 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1879 "9054 BLKGRD: bug in %s\n", __func__
);
1889 * lpfc_bg_setup_sgl - Setup BlockGuard SGL with no protection data
1890 * @phba: The Hba for which this call is being executed.
1891 * @sc: pointer to scsi command we're working on
1892 * @sgl: pointer to buffer list for protection groups
1893 * @datasegcnt: number of segments of data that have been dma mapped
1894 * @lpfc_cmd: lpfc scsi command object pointer.
1896 * This function sets up SGL buffer list for protection groups of
1897 * type LPFC_PG_TYPE_NO_DIF
1899 * This is usually used when the HBA is instructed to generate
1900 * DIFs and insert them into data stream (or strip DIF from
1901 * incoming data stream)
1903 * The buffer list consists of just one protection group described
1905 * +-------------------------+
1906 * start of prot group --> | DI_SEED |
1907 * +-------------------------+
1909 * +-------------------------+
1910 * |more Data SGE's ... (opt)|
1911 * +-------------------------+
1914 * Note: Data s/g buffers have been dma mapped
1916 * Returns the number of SGEs added to the SGL.
1919 lpfc_bg_setup_sgl(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
1920 struct sli4_sge
*sgl
, int datasegcnt
,
1921 struct lpfc_io_buf
*lpfc_cmd
)
1923 struct scatterlist
*sgde
= NULL
; /* s/g data entry */
1924 struct sli4_sge_diseed
*diseed
= NULL
;
1925 dma_addr_t physaddr
;
1927 uint32_t reftag
, num_sge
= 0;
1929 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1932 uint32_t checking
= 1;
1934 uint32_t dma_offset
= 0;
1935 struct sli4_hybrid_sgl
*sgl_xtra
= NULL
;
1937 bool lsp_just_set
= false;
1939 status
= lpfc_sc_to_bg_opcodes(phba
, sc
, &txop
, &rxop
);
1943 /* extract some info from the scsi command for pde*/
1944 reftag
= scsi_prot_ref_tag(sc
);
1946 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1947 rc
= lpfc_bg_err_inject(phba
, sc
, &reftag
, NULL
, 1);
1949 if (rc
& BG_ERR_SWAP
)
1950 lpfc_bg_err_opcodes(phba
, sc
, &txop
, &rxop
);
1951 if (rc
& BG_ERR_CHECK
)
1956 /* setup DISEED with what we have */
1957 diseed
= (struct sli4_sge_diseed
*) sgl
;
1958 memset(diseed
, 0, sizeof(struct sli4_sge_diseed
));
1959 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DISEED
);
1961 /* Endianness conversion if necessary */
1962 diseed
->ref_tag
= cpu_to_le32(reftag
);
1963 diseed
->ref_tag_tran
= diseed
->ref_tag
;
1966 * We only need to check the data on READs, for WRITEs
1967 * protection data is automatically generated, not checked.
1969 if (sc
->sc_data_direction
== DMA_FROM_DEVICE
) {
1970 if (sc
->prot_flags
& SCSI_PROT_GUARD_CHECK
)
1971 bf_set(lpfc_sli4_sge_dif_ce
, diseed
, checking
);
1973 bf_set(lpfc_sli4_sge_dif_ce
, diseed
, 0);
1975 if (sc
->prot_flags
& SCSI_PROT_REF_CHECK
)
1976 bf_set(lpfc_sli4_sge_dif_re
, diseed
, checking
);
1978 bf_set(lpfc_sli4_sge_dif_re
, diseed
, 0);
1981 /* setup DISEED with the rest of the info */
1982 bf_set(lpfc_sli4_sge_dif_optx
, diseed
, txop
);
1983 bf_set(lpfc_sli4_sge_dif_oprx
, diseed
, rxop
);
1985 bf_set(lpfc_sli4_sge_dif_ai
, diseed
, 1);
1986 bf_set(lpfc_sli4_sge_dif_me
, diseed
, 0);
1988 /* Endianness conversion if necessary for DISEED */
1989 diseed
->word2
= cpu_to_le32(diseed
->word2
);
1990 diseed
->word3
= cpu_to_le32(diseed
->word3
);
1992 /* advance bpl and increment sge count */
1996 /* assumption: caller has already run dma_map_sg on command data */
1997 sgde
= scsi_sglist(sc
);
1999 for (i
= 0; i
< datasegcnt
; i
++) {
2003 /* do we need to expand the segment */
2004 if (!lsp_just_set
&& !((j
+ 1) % phba
->border_sge_num
) &&
2005 ((datasegcnt
- 1) != i
)) {
2007 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_LSP
);
2009 sgl_xtra
= lpfc_get_sgl_per_hdwq(phba
, lpfc_cmd
);
2011 if (unlikely(!sgl_xtra
)) {
2012 lpfc_cmd
->seg_cnt
= 0;
2015 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(
2016 sgl_xtra
->dma_phys_sgl
));
2017 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(
2018 sgl_xtra
->dma_phys_sgl
));
2021 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DATA
);
2024 if (!(bf_get(lpfc_sli4_sge_type
, sgl
) & LPFC_SGE_TYPE_LSP
)) {
2025 if ((datasegcnt
- 1) == i
)
2026 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
2027 physaddr
= sg_dma_address(sgde
);
2028 dma_len
= sg_dma_len(sgde
);
2029 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(physaddr
));
2030 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(physaddr
));
2032 bf_set(lpfc_sli4_sge_offset
, sgl
, dma_offset
);
2033 sgl
->word2
= cpu_to_le32(sgl
->word2
);
2034 sgl
->sge_len
= cpu_to_le32(dma_len
);
2036 dma_offset
+= dma_len
;
2037 sgde
= sg_next(sgde
);
2041 lsp_just_set
= false;
2044 sgl
->word2
= cpu_to_le32(sgl
->word2
);
2045 sgl
->sge_len
= cpu_to_le32(phba
->cfg_sg_dma_buf_size
);
2047 sgl
= (struct sli4_sge
*)sgl_xtra
->dma_sgl
;
2050 lsp_just_set
= true;
2062 * lpfc_bg_setup_sgl_prot - Setup BlockGuard SGL with protection data
2063 * @phba: The Hba for which this call is being executed.
2064 * @sc: pointer to scsi command we're working on
2065 * @sgl: pointer to buffer list for protection groups
2066 * @datacnt: number of segments of data that have been dma mapped
2067 * @protcnt: number of segment of protection data that have been dma mapped
2068 * @lpfc_cmd: lpfc scsi command object pointer.
2070 * This function sets up SGL buffer list for protection groups of
2071 * type LPFC_PG_TYPE_DIF
2073 * This is usually used when DIFs are in their own buffers,
2074 * separate from the data. The HBA can then by instructed
2075 * to place the DIFs in the outgoing stream. For read operations,
2076 * The HBA could extract the DIFs and place it in DIF buffers.
2078 * The buffer list for this type consists of one or more of the
2079 * protection groups described below:
2080 * +-------------------------+
2081 * start of first prot group --> | DISEED |
2082 * +-------------------------+
2083 * | DIF (Prot SGE) |
2084 * +-------------------------+
2086 * +-------------------------+
2087 * |more Data SGE's ... (opt)|
2088 * +-------------------------+
2089 * start of new prot group --> | DISEED |
2090 * +-------------------------+
2092 * +-------------------------+
2094 * Note: It is assumed that both data and protection s/g buffers have been
2097 * Returns the number of SGEs added to the SGL.
2100 lpfc_bg_setup_sgl_prot(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
,
2101 struct sli4_sge
*sgl
, int datacnt
, int protcnt
,
2102 struct lpfc_io_buf
*lpfc_cmd
)
2104 struct scatterlist
*sgde
= NULL
; /* s/g data entry */
2105 struct scatterlist
*sgpe
= NULL
; /* s/g prot entry */
2106 struct sli4_sge_diseed
*diseed
= NULL
;
2107 dma_addr_t dataphysaddr
, protphysaddr
;
2108 unsigned short curr_prot
= 0;
2109 unsigned int split_offset
;
2110 unsigned int protgroup_len
, protgroup_offset
= 0, protgroup_remainder
;
2111 unsigned int protgrp_blks
, protgrp_bytes
;
2112 unsigned int remainder
, subtotal
;
2114 unsigned char pgdone
= 0, alldone
= 0;
2119 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2122 uint32_t checking
= 1;
2123 uint32_t dma_offset
= 0, num_sge
= 0;
2125 struct sli4_hybrid_sgl
*sgl_xtra
= NULL
;
2127 sgpe
= scsi_prot_sglist(sc
);
2128 sgde
= scsi_sglist(sc
);
2130 if (!sgpe
|| !sgde
) {
2131 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
2132 "9082 Invalid s/g entry: data=x%px prot=x%px\n",
2137 status
= lpfc_sc_to_bg_opcodes(phba
, sc
, &txop
, &rxop
);
2141 /* extract some info from the scsi command */
2142 blksize
= scsi_prot_interval(sc
);
2143 reftag
= scsi_prot_ref_tag(sc
);
2145 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2146 rc
= lpfc_bg_err_inject(phba
, sc
, &reftag
, NULL
, 1);
2148 if (rc
& BG_ERR_SWAP
)
2149 lpfc_bg_err_opcodes(phba
, sc
, &txop
, &rxop
);
2150 if (rc
& BG_ERR_CHECK
)
2157 /* Check to see if we ran out of space */
2158 if ((num_sge
>= (phba
->cfg_total_seg_cnt
- 2)) &&
2162 /* DISEED and DIF have to be together */
2163 if (!((j
+ 1) % phba
->border_sge_num
) ||
2164 !((j
+ 2) % phba
->border_sge_num
) ||
2165 !((j
+ 3) % phba
->border_sge_num
)) {
2169 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_LSP
);
2171 sgl_xtra
= lpfc_get_sgl_per_hdwq(phba
, lpfc_cmd
);
2173 if (unlikely(!sgl_xtra
)) {
2176 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(
2177 sgl_xtra
->dma_phys_sgl
));
2178 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(
2179 sgl_xtra
->dma_phys_sgl
));
2182 sgl
->word2
= cpu_to_le32(sgl
->word2
);
2183 sgl
->sge_len
= cpu_to_le32(phba
->cfg_sg_dma_buf_size
);
2185 sgl
= (struct sli4_sge
*)sgl_xtra
->dma_sgl
;
2189 /* setup DISEED with what we have */
2190 diseed
= (struct sli4_sge_diseed
*) sgl
;
2191 memset(diseed
, 0, sizeof(struct sli4_sge_diseed
));
2192 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DISEED
);
2194 /* Endianness conversion if necessary */
2195 diseed
->ref_tag
= cpu_to_le32(reftag
);
2196 diseed
->ref_tag_tran
= diseed
->ref_tag
;
2198 if (sc
->prot_flags
& SCSI_PROT_GUARD_CHECK
) {
2199 bf_set(lpfc_sli4_sge_dif_ce
, diseed
, checking
);
2201 bf_set(lpfc_sli4_sge_dif_ce
, diseed
, 0);
2203 * When in this mode, the hardware will replace
2204 * the guard tag from the host with a
2205 * newly generated good CRC for the wire.
2206 * Switch to raw mode here to avoid this
2207 * behavior. What the host sends gets put on the wire.
2209 if (txop
== BG_OP_IN_CRC_OUT_CRC
) {
2210 txop
= BG_OP_RAW_MODE
;
2211 rxop
= BG_OP_RAW_MODE
;
2216 if (sc
->prot_flags
& SCSI_PROT_REF_CHECK
)
2217 bf_set(lpfc_sli4_sge_dif_re
, diseed
, checking
);
2219 bf_set(lpfc_sli4_sge_dif_re
, diseed
, 0);
2221 /* setup DISEED with the rest of the info */
2222 bf_set(lpfc_sli4_sge_dif_optx
, diseed
, txop
);
2223 bf_set(lpfc_sli4_sge_dif_oprx
, diseed
, rxop
);
2225 bf_set(lpfc_sli4_sge_dif_ai
, diseed
, 1);
2226 bf_set(lpfc_sli4_sge_dif_me
, diseed
, 0);
2228 /* Endianness conversion if necessary for DISEED */
2229 diseed
->word2
= cpu_to_le32(diseed
->word2
);
2230 diseed
->word3
= cpu_to_le32(diseed
->word3
);
2232 /* advance sgl and increment bde count */
2238 /* setup the first BDE that points to protection buffer */
2239 protphysaddr
= sg_dma_address(sgpe
) + protgroup_offset
;
2240 protgroup_len
= sg_dma_len(sgpe
) - protgroup_offset
;
2242 /* must be integer multiple of the DIF block length */
2243 BUG_ON(protgroup_len
% 8);
2245 /* Now setup DIF SGE */
2247 bf_set(lpfc_sli4_sge_type
, sgl
, LPFC_SGE_TYPE_DIF
);
2248 sgl
->addr_hi
= le32_to_cpu(putPaddrHigh(protphysaddr
));
2249 sgl
->addr_lo
= le32_to_cpu(putPaddrLow(protphysaddr
));
2250 sgl
->word2
= cpu_to_le32(sgl
->word2
);
2253 protgrp_blks
= protgroup_len
/ 8;
2254 protgrp_bytes
= protgrp_blks
* blksize
;
2256 /* check if DIF SGE is crossing the 4K boundary; if so split */
2257 if ((sgl
->addr_lo
& 0xfff) + protgroup_len
> 0x1000) {
2258 protgroup_remainder
= 0x1000 - (sgl
->addr_lo
& 0xfff);
2259 protgroup_offset
+= protgroup_remainder
;
2260 protgrp_blks
= protgroup_remainder
/ 8;
2261 protgrp_bytes
= protgrp_blks
* blksize
;
2263 protgroup_offset
= 0;
2269 /* setup SGE's for data blocks associated with DIF data */
2271 subtotal
= 0; /* total bytes processed for current prot grp */
2277 /* Check to see if we ran out of space */
2278 if ((num_sge
>= phba
->cfg_total_seg_cnt
) &&
2283 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
2284 "9086 BLKGRD:%s Invalid data segment\n",
2289 if (!((j
+ 1) % phba
->border_sge_num
)) {
2293 bf_set(lpfc_sli4_sge_type
, sgl
,
2296 sgl_xtra
= lpfc_get_sgl_per_hdwq(phba
,
2299 if (unlikely(!sgl_xtra
)) {
2302 sgl
->addr_lo
= cpu_to_le32(
2303 putPaddrLow(sgl_xtra
->dma_phys_sgl
));
2304 sgl
->addr_hi
= cpu_to_le32(
2305 putPaddrHigh(sgl_xtra
->dma_phys_sgl
));
2308 sgl
->word2
= cpu_to_le32(sgl
->word2
);
2309 sgl
->sge_len
= cpu_to_le32(
2310 phba
->cfg_sg_dma_buf_size
);
2312 sgl
= (struct sli4_sge
*)sgl_xtra
->dma_sgl
;
2314 dataphysaddr
= sg_dma_address(sgde
) +
2317 remainder
= sg_dma_len(sgde
) - split_offset
;
2319 if ((subtotal
+ remainder
) <= protgrp_bytes
) {
2320 /* we can use this whole buffer */
2321 dma_len
= remainder
;
2324 if ((subtotal
+ remainder
) ==
2328 /* must split this buffer with next
2331 dma_len
= protgrp_bytes
- subtotal
;
2332 split_offset
+= dma_len
;
2335 subtotal
+= dma_len
;
2338 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(
2340 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(
2342 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
2343 bf_set(lpfc_sli4_sge_offset
, sgl
, dma_offset
);
2344 bf_set(lpfc_sli4_sge_type
, sgl
,
2345 LPFC_SGE_TYPE_DATA
);
2347 sgl
->sge_len
= cpu_to_le32(dma_len
);
2348 dma_offset
+= dma_len
;
2358 /* Move to the next s/g segment if possible */
2359 sgde
= sg_next(sgde
);
2367 if (protgroup_offset
) {
2368 /* update the reference tag */
2369 reftag
+= protgrp_blks
;
2374 if (curr_prot
== protcnt
) {
2375 /* mark the last SGL */
2377 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
2379 } else if (curr_prot
< protcnt
) {
2380 /* advance to next prot buffer */
2381 sgpe
= sg_next(sgpe
);
2383 /* update the reference tag */
2384 reftag
+= protgrp_blks
;
2386 /* if we're here, we have a bug */
2387 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
2388 "9085 BLKGRD: bug in %s\n", __func__
);
2399 * lpfc_prot_group_type - Get prtotection group type of SCSI command
2400 * @phba: The Hba for which this call is being executed.
2401 * @sc: pointer to scsi command we're working on
2403 * Given a SCSI command that supports DIF, determine composition of protection
2404 * groups involved in setting up buffer lists
2406 * Returns: Protection group type (with or without DIF)
2410 lpfc_prot_group_type(struct lpfc_hba
*phba
, struct scsi_cmnd
*sc
)
2412 int ret
= LPFC_PG_TYPE_INVALID
;
2413 unsigned char op
= scsi_get_prot_op(sc
);
2416 case SCSI_PROT_READ_STRIP
:
2417 case SCSI_PROT_WRITE_INSERT
:
2418 ret
= LPFC_PG_TYPE_NO_DIF
;
2420 case SCSI_PROT_READ_INSERT
:
2421 case SCSI_PROT_WRITE_STRIP
:
2422 case SCSI_PROT_READ_PASS
:
2423 case SCSI_PROT_WRITE_PASS
:
2424 ret
= LPFC_PG_TYPE_DIF_BUF
;
2428 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
2429 "9021 Unsupported protection op:%d\n",
2437 * lpfc_bg_scsi_adjust_dl - Adjust SCSI data length for BlockGuard
2438 * @phba: The Hba for which this call is being executed.
2439 * @lpfc_cmd: The scsi buffer which is going to be adjusted.
2441 * Adjust the data length to account for how much data
2442 * is actually on the wire.
2444 * returns the adjusted data length
2447 lpfc_bg_scsi_adjust_dl(struct lpfc_hba
*phba
,
2448 struct lpfc_io_buf
*lpfc_cmd
)
2450 struct scsi_cmnd
*sc
= lpfc_cmd
->pCmd
;
2453 fcpdl
= scsi_bufflen(sc
);
2455 /* Check if there is protection data on the wire */
2456 if (sc
->sc_data_direction
== DMA_FROM_DEVICE
) {
2457 /* Read check for protection data */
2458 if (scsi_get_prot_op(sc
) == SCSI_PROT_READ_INSERT
)
2462 /* Write check for protection data */
2463 if (scsi_get_prot_op(sc
) == SCSI_PROT_WRITE_STRIP
)
2468 * If we are in DIF Type 1 mode every data block has a 8 byte
2469 * DIF (trailer) attached to it. Must ajust FCP data length
2470 * to account for the protection data.
2472 fcpdl
+= (fcpdl
/ scsi_prot_interval(sc
)) * 8;
2478 * lpfc_bg_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
2479 * @phba: The Hba for which this call is being executed.
2480 * @lpfc_cmd: The scsi buffer which is going to be prep'ed.
2482 * This is the protection/DIF aware version of
2483 * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the
2484 * two functions eventually, but for now, it's here.
2485 * RETURNS 0 - SUCCESS,
2486 * 1 - Failed DMA map, retry.
2487 * 2 - Invalid scsi cmd or prot-type. Do not rety.
2490 lpfc_bg_scsi_prep_dma_buf_s3(struct lpfc_hba
*phba
,
2491 struct lpfc_io_buf
*lpfc_cmd
)
2493 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
2494 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
2495 struct ulp_bde64
*bpl
= (struct ulp_bde64
*)lpfc_cmd
->dma_sgl
;
2496 IOCB_t
*iocb_cmd
= &lpfc_cmd
->cur_iocbq
.iocb
;
2497 uint32_t num_bde
= 0;
2498 int datasegcnt
, protsegcnt
, datadir
= scsi_cmnd
->sc_data_direction
;
2499 int prot_group_type
= 0;
2502 struct lpfc_vport
*vport
= phba
->pport
;
2505 * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd
2506 * fcp_rsp regions to the first data bde entry
2509 if (scsi_sg_count(scsi_cmnd
)) {
2511 * The driver stores the segment count returned from dma_map_sg
2512 * because this a count of dma-mappings used to map the use_sg
2513 * pages. They are not guaranteed to be the same for those
2514 * architectures that implement an IOMMU.
2516 datasegcnt
= dma_map_sg(&phba
->pcidev
->dev
,
2517 scsi_sglist(scsi_cmnd
),
2518 scsi_sg_count(scsi_cmnd
), datadir
);
2519 if (unlikely(!datasegcnt
))
2522 lpfc_cmd
->seg_cnt
= datasegcnt
;
2524 /* First check if data segment count from SCSI Layer is good */
2525 if (lpfc_cmd
->seg_cnt
> phba
->cfg_sg_seg_cnt
) {
2526 WARN_ON_ONCE(lpfc_cmd
->seg_cnt
> phba
->cfg_sg_seg_cnt
);
2531 prot_group_type
= lpfc_prot_group_type(phba
, scsi_cmnd
);
2533 switch (prot_group_type
) {
2534 case LPFC_PG_TYPE_NO_DIF
:
2536 /* Here we need to add a PDE5 and PDE6 to the count */
2537 if ((lpfc_cmd
->seg_cnt
+ 2) > phba
->cfg_total_seg_cnt
) {
2542 num_bde
= lpfc_bg_setup_bpl(phba
, scsi_cmnd
, bpl
,
2544 /* we should have 2 or more entries in buffer list */
2551 case LPFC_PG_TYPE_DIF_BUF
:
2553 * This type indicates that protection buffers are
2554 * passed to the driver, so that needs to be prepared
2557 protsegcnt
= dma_map_sg(&phba
->pcidev
->dev
,
2558 scsi_prot_sglist(scsi_cmnd
),
2559 scsi_prot_sg_count(scsi_cmnd
), datadir
);
2560 if (unlikely(!protsegcnt
)) {
2561 scsi_dma_unmap(scsi_cmnd
);
2565 lpfc_cmd
->prot_seg_cnt
= protsegcnt
;
2568 * There is a minimun of 4 BPLs used for every
2569 * protection data segment.
2571 if ((lpfc_cmd
->prot_seg_cnt
* 4) >
2572 (phba
->cfg_total_seg_cnt
- 2)) {
2577 num_bde
= lpfc_bg_setup_bpl_prot(phba
, scsi_cmnd
, bpl
,
2578 datasegcnt
, protsegcnt
);
2579 /* we should have 3 or more entries in buffer list */
2580 if ((num_bde
< 3) ||
2581 (num_bde
> phba
->cfg_total_seg_cnt
)) {
2587 case LPFC_PG_TYPE_INVALID
:
2589 scsi_dma_unmap(scsi_cmnd
);
2590 lpfc_cmd
->seg_cnt
= 0;
2592 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
2593 "9022 Unexpected protection group %i\n",
2600 * Finish initializing those IOCB fields that are dependent on the
2601 * scsi_cmnd request_buffer. Note that the bdeSize is explicitly
2602 * reinitialized since all iocb memory resources are used many times
2603 * for transmit, receive, and continuation bpl's.
2605 iocb_cmd
->un
.fcpi64
.bdl
.bdeSize
= (2 * sizeof(struct ulp_bde64
));
2606 iocb_cmd
->un
.fcpi64
.bdl
.bdeSize
+= (num_bde
* sizeof(struct ulp_bde64
));
2607 iocb_cmd
->ulpBdeCount
= 1;
2608 iocb_cmd
->ulpLe
= 1;
2610 fcpdl
= lpfc_bg_scsi_adjust_dl(phba
, lpfc_cmd
);
2611 fcp_cmnd
->fcpDl
= cpu_to_be32(fcpdl
);
2614 * Due to difference in data length between DIF/non-DIF paths,
2615 * we need to set word 4 of IOCB here
2617 iocb_cmd
->un
.fcpi
.fcpi_parm
= fcpdl
;
2620 * For First burst, we may need to adjust the initial transfer
2623 if (iocb_cmd
->un
.fcpi
.fcpi_XRdy
&&
2624 (fcpdl
< vport
->cfg_first_burst_size
))
2625 iocb_cmd
->un
.fcpi
.fcpi_XRdy
= fcpdl
;
2629 if (lpfc_cmd
->seg_cnt
)
2630 scsi_dma_unmap(scsi_cmnd
);
2631 if (lpfc_cmd
->prot_seg_cnt
)
2632 dma_unmap_sg(&phba
->pcidev
->dev
, scsi_prot_sglist(scsi_cmnd
),
2633 scsi_prot_sg_count(scsi_cmnd
),
2634 scsi_cmnd
->sc_data_direction
);
2636 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
2637 "9023 Cannot setup S/G List for HBA"
2638 "IO segs %d/%d BPL %d SCSI %d: %d %d\n",
2639 lpfc_cmd
->seg_cnt
, lpfc_cmd
->prot_seg_cnt
,
2640 phba
->cfg_total_seg_cnt
, phba
->cfg_sg_seg_cnt
,
2641 prot_group_type
, num_bde
);
2643 lpfc_cmd
->seg_cnt
= 0;
2644 lpfc_cmd
->prot_seg_cnt
= 0;
2649 * This function calcuates the T10 DIF guard tag
2650 * on the specified data using a CRC algorithmn
2654 lpfc_bg_crc(uint8_t *data
, int count
)
2659 crc
= crc_t10dif(data
, count
);
2660 x
= cpu_to_be16(crc
);
2665 * This function calcuates the T10 DIF guard tag
2666 * on the specified data using a CSUM algorithmn
2667 * using ip_compute_csum.
2670 lpfc_bg_csum(uint8_t *data
, int count
)
2674 ret
= ip_compute_csum(data
, count
);
2679 * This function examines the protection data to try to determine
2680 * what type of T10-DIF error occurred.
2683 lpfc_calc_bg_err(struct lpfc_hba
*phba
, struct lpfc_io_buf
*lpfc_cmd
)
2685 struct scatterlist
*sgpe
; /* s/g prot entry */
2686 struct scatterlist
*sgde
; /* s/g data entry */
2687 struct scsi_cmnd
*cmd
= lpfc_cmd
->pCmd
;
2688 struct scsi_dif_tuple
*src
= NULL
;
2689 uint8_t *data_src
= NULL
;
2691 uint16_t start_app_tag
, app_tag
;
2692 uint32_t start_ref_tag
, ref_tag
;
2693 int prot
, protsegcnt
;
2694 int err_type
, len
, data_len
;
2695 int chk_ref
, chk_app
, chk_guard
;
2699 err_type
= BGS_GUARD_ERR_MASK
;
2703 /* First check to see if there is protection data to examine */
2704 prot
= scsi_get_prot_op(cmd
);
2705 if ((prot
== SCSI_PROT_READ_STRIP
) ||
2706 (prot
== SCSI_PROT_WRITE_INSERT
) ||
2707 (prot
== SCSI_PROT_NORMAL
))
2710 /* Currently the driver just supports ref_tag and guard_tag checking */
2715 /* Setup a ptr to the protection data provided by the SCSI host */
2716 sgpe
= scsi_prot_sglist(cmd
);
2717 protsegcnt
= lpfc_cmd
->prot_seg_cnt
;
2719 if (sgpe
&& protsegcnt
) {
2722 * We will only try to verify guard tag if the segment
2723 * data length is a multiple of the blksize.
2725 sgde
= scsi_sglist(cmd
);
2726 blksize
= scsi_prot_interval(cmd
);
2727 data_src
= (uint8_t *)sg_virt(sgde
);
2728 data_len
= sg_dma_len(sgde
);
2729 if ((data_len
& (blksize
- 1)) == 0)
2732 src
= (struct scsi_dif_tuple
*)sg_virt(sgpe
);
2733 start_ref_tag
= scsi_prot_ref_tag(cmd
);
2734 start_app_tag
= src
->app_tag
;
2735 len
= sg_dma_len(sgpe
);
2736 while (src
&& protsegcnt
) {
2740 * First check to see if a protection data
2743 if ((src
->ref_tag
== T10_PI_REF_ESCAPE
) ||
2744 (src
->app_tag
== T10_PI_APP_ESCAPE
)) {
2749 /* First Guard Tag checking */
2751 guard_tag
= src
->guard_tag
;
2753 & SCSI_PROT_IP_CHECKSUM
)
2754 sum
= lpfc_bg_csum(data_src
,
2757 sum
= lpfc_bg_crc(data_src
,
2759 if ((guard_tag
!= sum
)) {
2760 err_type
= BGS_GUARD_ERR_MASK
;
2765 /* Reference Tag checking */
2766 ref_tag
= be32_to_cpu(src
->ref_tag
);
2767 if (chk_ref
&& (ref_tag
!= start_ref_tag
)) {
2768 err_type
= BGS_REFTAG_ERR_MASK
;
2773 /* App Tag checking */
2774 app_tag
= src
->app_tag
;
2775 if (chk_app
&& (app_tag
!= start_app_tag
)) {
2776 err_type
= BGS_APPTAG_ERR_MASK
;
2780 len
-= sizeof(struct scsi_dif_tuple
);
2785 data_src
+= blksize
;
2786 data_len
-= blksize
;
2789 * Are we at the end of the Data segment?
2790 * The data segment is only used for Guard
2793 if (chk_guard
&& (data_len
== 0)) {
2795 sgde
= sg_next(sgde
);
2799 data_src
= (uint8_t *)sg_virt(sgde
);
2800 data_len
= sg_dma_len(sgde
);
2801 if ((data_len
& (blksize
- 1)) == 0)
2806 /* Goto the next Protection data segment */
2807 sgpe
= sg_next(sgpe
);
2809 src
= (struct scsi_dif_tuple
*)sg_virt(sgpe
);
2810 len
= sg_dma_len(sgpe
);
2818 if (err_type
== BGS_GUARD_ERR_MASK
) {
2819 scsi_build_sense(cmd
, 1, ILLEGAL_REQUEST
, 0x10, 0x1);
2820 set_host_byte(cmd
, DID_ABORT
);
2821 phba
->bg_guard_err_cnt
++;
2822 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FCP
| LOG_BG
,
2823 "9069 BLKGRD: reftag %x grd_tag err %x != %x\n",
2824 scsi_prot_ref_tag(cmd
),
2827 } else if (err_type
== BGS_REFTAG_ERR_MASK
) {
2828 scsi_build_sense(cmd
, 1, ILLEGAL_REQUEST
, 0x10, 0x3);
2829 set_host_byte(cmd
, DID_ABORT
);
2831 phba
->bg_reftag_err_cnt
++;
2832 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FCP
| LOG_BG
,
2833 "9066 BLKGRD: reftag %x ref_tag err %x != %x\n",
2834 scsi_prot_ref_tag(cmd
),
2835 ref_tag
, start_ref_tag
);
2837 } else if (err_type
== BGS_APPTAG_ERR_MASK
) {
2838 scsi_build_sense(cmd
, 1, ILLEGAL_REQUEST
, 0x10, 0x2);
2839 set_host_byte(cmd
, DID_ABORT
);
2841 phba
->bg_apptag_err_cnt
++;
2842 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FCP
| LOG_BG
,
2843 "9041 BLKGRD: reftag %x app_tag err %x != %x\n",
2844 scsi_prot_ref_tag(cmd
),
2845 app_tag
, start_app_tag
);
2850 * This function checks for BlockGuard errors detected by
2851 * the HBA. In case of errors, the ASC/ASCQ fields in the
2852 * sense buffer will be set accordingly, paired with
2853 * ILLEGAL_REQUEST to signal to the kernel that the HBA
2854 * detected corruption.
2857 * 0 - No error found
2858 * 1 - BlockGuard error found
2859 * -1 - Internal error (bad profile, ...etc)
2862 lpfc_parse_bg_err(struct lpfc_hba
*phba
, struct lpfc_io_buf
*lpfc_cmd
,
2863 struct lpfc_iocbq
*pIocbOut
)
2865 struct scsi_cmnd
*cmd
= lpfc_cmd
->pCmd
;
2866 struct sli3_bg_fields
*bgf
;
2868 struct lpfc_wcqe_complete
*wcqe
;
2872 u64 failing_sector
= 0;
2874 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2875 wcqe
= &pIocbOut
->wcqe_cmpl
;
2876 status
= bf_get(lpfc_wcqe_c_status
, wcqe
);
2878 if (status
== CQE_STATUS_DI_ERROR
) {
2879 /* Guard Check failed */
2880 if (bf_get(lpfc_wcqe_c_bg_ge
, wcqe
))
2881 bgstat
|= BGS_GUARD_ERR_MASK
;
2883 /* AppTag Check failed */
2884 if (bf_get(lpfc_wcqe_c_bg_ae
, wcqe
))
2885 bgstat
|= BGS_APPTAG_ERR_MASK
;
2887 /* RefTag Check failed */
2888 if (bf_get(lpfc_wcqe_c_bg_re
, wcqe
))
2889 bgstat
|= BGS_REFTAG_ERR_MASK
;
2891 /* Check to see if there was any good data before the
2894 if (bf_get(lpfc_wcqe_c_bg_tdpv
, wcqe
)) {
2895 bgstat
|= BGS_HI_WATER_MARK_PRESENT_MASK
;
2896 bghm
= wcqe
->total_data_placed
;
2900 * Set ALL the error bits to indicate we don't know what
2901 * type of error it is.
2904 bgstat
|= (BGS_REFTAG_ERR_MASK
|
2905 BGS_APPTAG_ERR_MASK
|
2906 BGS_GUARD_ERR_MASK
);
2910 bgf
= &pIocbOut
->iocb
.unsli3
.sli3_bg
;
2912 bgstat
= bgf
->bgstat
;
2915 if (lpfc_bgs_get_invalid_prof(bgstat
)) {
2916 cmd
->result
= DID_ERROR
<< 16;
2917 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FCP
| LOG_BG
,
2918 "9072 BLKGRD: Invalid BG Profile in cmd "
2919 "0x%x reftag 0x%x blk cnt 0x%x "
2920 "bgstat=x%x bghm=x%x\n", cmd
->cmnd
[0],
2921 scsi_prot_ref_tag(cmd
),
2922 scsi_logical_block_count(cmd
), bgstat
, bghm
);
2927 if (lpfc_bgs_get_uninit_dif_block(bgstat
)) {
2928 cmd
->result
= DID_ERROR
<< 16;
2929 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FCP
| LOG_BG
,
2930 "9073 BLKGRD: Invalid BG PDIF Block in cmd "
2931 "0x%x reftag 0x%x blk cnt 0x%x "
2932 "bgstat=x%x bghm=x%x\n", cmd
->cmnd
[0],
2933 scsi_prot_ref_tag(cmd
),
2934 scsi_logical_block_count(cmd
), bgstat
, bghm
);
2939 if (lpfc_bgs_get_guard_err(bgstat
)) {
2941 scsi_build_sense(cmd
, 1, ILLEGAL_REQUEST
, 0x10, 0x1);
2942 set_host_byte(cmd
, DID_ABORT
);
2943 phba
->bg_guard_err_cnt
++;
2944 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FCP
| LOG_BG
,
2945 "9055 BLKGRD: Guard Tag error in cmd "
2946 "0x%x reftag 0x%x blk cnt 0x%x "
2947 "bgstat=x%x bghm=x%x\n", cmd
->cmnd
[0],
2948 scsi_prot_ref_tag(cmd
),
2949 scsi_logical_block_count(cmd
), bgstat
, bghm
);
2952 if (lpfc_bgs_get_reftag_err(bgstat
)) {
2954 scsi_build_sense(cmd
, 1, ILLEGAL_REQUEST
, 0x10, 0x3);
2955 set_host_byte(cmd
, DID_ABORT
);
2956 phba
->bg_reftag_err_cnt
++;
2957 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FCP
| LOG_BG
,
2958 "9056 BLKGRD: Ref Tag error in cmd "
2959 "0x%x reftag 0x%x blk cnt 0x%x "
2960 "bgstat=x%x bghm=x%x\n", cmd
->cmnd
[0],
2961 scsi_prot_ref_tag(cmd
),
2962 scsi_logical_block_count(cmd
), bgstat
, bghm
);
2965 if (lpfc_bgs_get_apptag_err(bgstat
)) {
2967 scsi_build_sense(cmd
, 1, ILLEGAL_REQUEST
, 0x10, 0x2);
2968 set_host_byte(cmd
, DID_ABORT
);
2969 phba
->bg_apptag_err_cnt
++;
2970 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FCP
| LOG_BG
,
2971 "9061 BLKGRD: App Tag error in cmd "
2972 "0x%x reftag 0x%x blk cnt 0x%x "
2973 "bgstat=x%x bghm=x%x\n", cmd
->cmnd
[0],
2974 scsi_prot_ref_tag(cmd
),
2975 scsi_logical_block_count(cmd
), bgstat
, bghm
);
2978 if (lpfc_bgs_get_hi_water_mark_present(bgstat
)) {
2980 * setup sense data descriptor 0 per SPC-4 as an information
2981 * field, and put the failing LBA in it.
2982 * This code assumes there was also a guard/app/ref tag error
2985 cmd
->sense_buffer
[7] = 0xc; /* Additional sense length */
2986 cmd
->sense_buffer
[8] = 0; /* Information descriptor type */
2987 cmd
->sense_buffer
[9] = 0xa; /* Additional descriptor length */
2988 cmd
->sense_buffer
[10] = 0x80; /* Validity bit */
2990 /* bghm is a "on the wire" FC frame based count */
2991 switch (scsi_get_prot_op(cmd
)) {
2992 case SCSI_PROT_READ_INSERT
:
2993 case SCSI_PROT_WRITE_STRIP
:
2994 bghm
/= cmd
->device
->sector_size
;
2996 case SCSI_PROT_READ_STRIP
:
2997 case SCSI_PROT_WRITE_INSERT
:
2998 case SCSI_PROT_READ_PASS
:
2999 case SCSI_PROT_WRITE_PASS
:
3000 bghm
/= (cmd
->device
->sector_size
+
3001 sizeof(struct scsi_dif_tuple
));
3005 failing_sector
= scsi_get_lba(cmd
);
3006 failing_sector
+= bghm
;
3008 /* Descriptor Information */
3009 put_unaligned_be64(failing_sector
, &cmd
->sense_buffer
[12]);
3013 /* No error was reported - problem in FW? */
3014 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FCP
| LOG_BG
,
3015 "9057 BLKGRD: Unknown error in cmd "
3016 "0x%x reftag 0x%x blk cnt 0x%x "
3017 "bgstat=x%x bghm=x%x\n", cmd
->cmnd
[0],
3018 scsi_prot_ref_tag(cmd
),
3019 scsi_logical_block_count(cmd
), bgstat
, bghm
);
3021 /* Calculate what type of error it was */
3022 lpfc_calc_bg_err(phba
, lpfc_cmd
);
3029 * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
3030 * @phba: The Hba for which this call is being executed.
3031 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3033 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
3034 * field of @lpfc_cmd for device with SLI-4 interface spec.
3037 * 2 - Error - Do not retry
3042 lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba
*phba
, struct lpfc_io_buf
*lpfc_cmd
)
3044 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
3045 struct scatterlist
*sgel
= NULL
;
3046 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
3047 struct sli4_sge
*sgl
= (struct sli4_sge
*)lpfc_cmd
->dma_sgl
;
3048 struct sli4_sge
*first_data_sgl
;
3049 struct lpfc_iocbq
*pwqeq
= &lpfc_cmd
->cur_iocbq
;
3050 struct lpfc_vport
*vport
= phba
->pport
;
3051 union lpfc_wqe128
*wqe
= &pwqeq
->wqe
;
3052 dma_addr_t physaddr
;
3054 uint32_t dma_offset
= 0;
3056 struct ulp_bde64
*bde
;
3057 bool lsp_just_set
= false;
3058 struct sli4_hybrid_sgl
*sgl_xtra
= NULL
;
3061 * There are three possibilities here - use scatter-gather segment, use
3062 * the single mapping, or neither. Start the lpfc command prep by
3063 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
3066 if (scsi_sg_count(scsi_cmnd
)) {
3068 * The driver stores the segment count returned from dma_map_sg
3069 * because this a count of dma-mappings used to map the use_sg
3070 * pages. They are not guaranteed to be the same for those
3071 * architectures that implement an IOMMU.
3074 nseg
= scsi_dma_map(scsi_cmnd
);
3075 if (unlikely(nseg
<= 0))
3078 /* clear the last flag in the fcp_rsp map entry */
3079 sgl
->word2
= le32_to_cpu(sgl
->word2
);
3080 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
3081 sgl
->word2
= cpu_to_le32(sgl
->word2
);
3083 first_data_sgl
= sgl
;
3084 lpfc_cmd
->seg_cnt
= nseg
;
3085 if (!phba
->cfg_xpsgl
&&
3086 lpfc_cmd
->seg_cnt
> phba
->cfg_sg_seg_cnt
) {
3087 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
3089 " %s: Too many sg segments from "
3090 "dma_map_sg. Config %d, seg_cnt %d\n",
3091 __func__
, phba
->cfg_sg_seg_cnt
,
3093 WARN_ON_ONCE(lpfc_cmd
->seg_cnt
> phba
->cfg_sg_seg_cnt
);
3094 lpfc_cmd
->seg_cnt
= 0;
3095 scsi_dma_unmap(scsi_cmnd
);
3100 * The driver established a maximum scatter-gather segment count
3101 * during probe that limits the number of sg elements in any
3102 * single scsi command. Just run through the seg_cnt and format
3104 * When using SLI-3 the driver will try to fit all the BDEs into
3105 * the IOCB. If it can't then the BDEs get added to a BPL as it
3106 * does for SLI-2 mode.
3109 /* for tracking segment boundaries */
3110 sgel
= scsi_sglist(scsi_cmnd
);
3112 for (i
= 0; i
< nseg
; i
++) {
3115 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
3116 bf_set(lpfc_sli4_sge_type
, sgl
,
3117 LPFC_SGE_TYPE_DATA
);
3119 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
3121 /* do we need to expand the segment */
3122 if (!lsp_just_set
&&
3123 !((j
+ 1) % phba
->border_sge_num
) &&
3124 ((nseg
- 1) != i
)) {
3126 bf_set(lpfc_sli4_sge_type
, sgl
,
3129 sgl_xtra
= lpfc_get_sgl_per_hdwq(
3132 if (unlikely(!sgl_xtra
)) {
3133 lpfc_cmd
->seg_cnt
= 0;
3134 scsi_dma_unmap(scsi_cmnd
);
3137 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(
3138 sgl_xtra
->dma_phys_sgl
));
3139 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(
3140 sgl_xtra
->dma_phys_sgl
));
3143 bf_set(lpfc_sli4_sge_type
, sgl
,
3144 LPFC_SGE_TYPE_DATA
);
3148 if (!(bf_get(lpfc_sli4_sge_type
, sgl
) &
3149 LPFC_SGE_TYPE_LSP
)) {
3150 if ((nseg
- 1) == i
)
3151 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
3153 physaddr
= sg_dma_address(sgel
);
3154 dma_len
= sg_dma_len(sgel
);
3155 sgl
->addr_lo
= cpu_to_le32(putPaddrLow(
3157 sgl
->addr_hi
= cpu_to_le32(putPaddrHigh(
3160 bf_set(lpfc_sli4_sge_offset
, sgl
, dma_offset
);
3161 sgl
->word2
= cpu_to_le32(sgl
->word2
);
3162 sgl
->sge_len
= cpu_to_le32(dma_len
);
3164 dma_offset
+= dma_len
;
3165 sgel
= sg_next(sgel
);
3168 lsp_just_set
= false;
3171 sgl
->word2
= cpu_to_le32(sgl
->word2
);
3172 sgl
->sge_len
= cpu_to_le32(
3173 phba
->cfg_sg_dma_buf_size
);
3175 sgl
= (struct sli4_sge
*)sgl_xtra
->dma_sgl
;
3178 lsp_just_set
= true;
3184 /* PBDE support for first data SGE only.
3185 * For FCoE, we key off Performance Hints.
3186 * For FC, we key off lpfc_enable_pbde.
3189 ((phba
->sli3_options
& LPFC_SLI4_PERFH_ENABLED
) ||
3190 phba
->cfg_enable_pbde
)) {
3192 bde
= (struct ulp_bde64
*)
3194 bde
->addrLow
= first_data_sgl
->addr_lo
;
3195 bde
->addrHigh
= first_data_sgl
->addr_hi
;
3196 bde
->tus
.f
.bdeSize
=
3197 le32_to_cpu(first_data_sgl
->sge_len
);
3198 bde
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
3199 bde
->tus
.w
= cpu_to_le32(bde
->tus
.w
);
3201 /* Word 11 - set PBDE bit */
3202 bf_set(wqe_pbde
, &wqe
->generic
.wqe_com
, 1);
3204 memset(&wqe
->words
[13], 0, (sizeof(uint32_t) * 3));
3205 /* Word 11 - PBDE bit disabled by default template */
3209 /* set the last flag in the fcp_rsp map entry */
3210 sgl
->word2
= le32_to_cpu(sgl
->word2
);
3211 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
3212 sgl
->word2
= cpu_to_le32(sgl
->word2
);
3214 if ((phba
->sli3_options
& LPFC_SLI4_PERFH_ENABLED
) ||
3215 phba
->cfg_enable_pbde
) {
3216 bde
= (struct ulp_bde64
*)
3218 memset(bde
, 0, (sizeof(uint32_t) * 3));
3223 * Finish initializing those IOCB fields that are dependent on the
3224 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
3225 * explicitly reinitialized.
3226 * all iocb memory resources are reused.
3228 if (scsi_cmnd
->cmd_len
> LPFC_FCP_CDB_LEN
)
3229 ((struct fcp_cmnd32
*)fcp_cmnd
)->fcpDl
=
3230 cpu_to_be32(scsi_bufflen(scsi_cmnd
));
3232 fcp_cmnd
->fcpDl
= cpu_to_be32(scsi_bufflen(scsi_cmnd
));
3233 /* Set first-burst provided it was successfully negotiated */
3234 if (!test_bit(HBA_FCOE_MODE
, &phba
->hba_flag
) &&
3235 vport
->cfg_first_burst_size
&&
3236 scsi_cmnd
->sc_data_direction
== DMA_TO_DEVICE
) {
3237 u32 init_len
, total_len
;
3239 total_len
= scsi_bufflen(scsi_cmnd
);
3240 init_len
= min(total_len
, vport
->cfg_first_burst_size
);
3243 wqe
->fcp_iwrite
.initial_xfer_len
= init_len
;
3244 wqe
->fcp_iwrite
.total_xfer_len
= total_len
;
3247 wqe
->fcp_iwrite
.total_xfer_len
=
3248 be32_to_cpu(fcp_cmnd
->fcpDl
);
3252 * If the OAS driver feature is enabled and the lun is enabled for
3253 * OAS, set the oas iocb related flags.
3255 if ((phba
->cfg_fof
) && ((struct lpfc_device_data
*)
3256 scsi_cmnd
->device
->hostdata
)->oas_enabled
) {
3257 lpfc_cmd
->cur_iocbq
.cmd_flag
|= (LPFC_IO_OAS
| LPFC_IO_FOF
);
3258 lpfc_cmd
->cur_iocbq
.priority
= ((struct lpfc_device_data
*)
3259 scsi_cmnd
->device
->hostdata
)->priority
;
3262 bf_set(wqe_oas
, &wqe
->generic
.wqe_com
, 1);
3263 bf_set(wqe_ccpe
, &wqe
->generic
.wqe_com
, 1);
3265 if (lpfc_cmd
->cur_iocbq
.priority
)
3266 bf_set(wqe_ccp
, &wqe
->generic
.wqe_com
,
3267 (lpfc_cmd
->cur_iocbq
.priority
<< 1));
3269 bf_set(wqe_ccp
, &wqe
->generic
.wqe_com
,
3270 (phba
->cfg_XLanePriority
<< 1));
3277 * lpfc_bg_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
3278 * @phba: The Hba for which this call is being executed.
3279 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3281 * This is the protection/DIF aware version of
3282 * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the
3283 * two functions eventually, but for now, it's here
3285 * 2 - Error - Do not retry
3290 lpfc_bg_scsi_prep_dma_buf_s4(struct lpfc_hba
*phba
,
3291 struct lpfc_io_buf
*lpfc_cmd
)
3293 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
3294 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
3295 struct sli4_sge
*sgl
= (struct sli4_sge
*)(lpfc_cmd
->dma_sgl
);
3296 struct lpfc_iocbq
*pwqeq
= &lpfc_cmd
->cur_iocbq
;
3297 union lpfc_wqe128
*wqe
= &pwqeq
->wqe
;
3298 uint32_t num_sge
= 0;
3299 int datasegcnt
, protsegcnt
, datadir
= scsi_cmnd
->sc_data_direction
;
3300 int prot_group_type
= 0;
3303 struct lpfc_vport
*vport
= phba
->pport
;
3306 * Start the lpfc command prep by bumping the sgl beyond fcp_cmnd
3307 * fcp_rsp regions to the first data sge entry
3309 if (scsi_sg_count(scsi_cmnd
)) {
3311 * The driver stores the segment count returned from dma_map_sg
3312 * because this a count of dma-mappings used to map the use_sg
3313 * pages. They are not guaranteed to be the same for those
3314 * architectures that implement an IOMMU.
3316 datasegcnt
= dma_map_sg(&phba
->pcidev
->dev
,
3317 scsi_sglist(scsi_cmnd
),
3318 scsi_sg_count(scsi_cmnd
), datadir
);
3319 if (unlikely(!datasegcnt
))
3323 /* clear the last flag in the fcp_rsp map entry */
3324 sgl
->word2
= le32_to_cpu(sgl
->word2
);
3325 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
3326 sgl
->word2
= cpu_to_le32(sgl
->word2
);
3329 lpfc_cmd
->seg_cnt
= datasegcnt
;
3331 /* First check if data segment count from SCSI Layer is good */
3332 if (lpfc_cmd
->seg_cnt
> phba
->cfg_sg_seg_cnt
&&
3334 WARN_ON_ONCE(lpfc_cmd
->seg_cnt
> phba
->cfg_sg_seg_cnt
);
3339 prot_group_type
= lpfc_prot_group_type(phba
, scsi_cmnd
);
3341 switch (prot_group_type
) {
3342 case LPFC_PG_TYPE_NO_DIF
:
3343 /* Here we need to add a DISEED to the count */
3344 if (((lpfc_cmd
->seg_cnt
+ 1) >
3345 phba
->cfg_total_seg_cnt
) &&
3351 num_sge
= lpfc_bg_setup_sgl(phba
, scsi_cmnd
, sgl
,
3352 datasegcnt
, lpfc_cmd
);
3354 /* we should have 2 or more entries in buffer list */
3361 case LPFC_PG_TYPE_DIF_BUF
:
3363 * This type indicates that protection buffers are
3364 * passed to the driver, so that needs to be prepared
3367 protsegcnt
= dma_map_sg(&phba
->pcidev
->dev
,
3368 scsi_prot_sglist(scsi_cmnd
),
3369 scsi_prot_sg_count(scsi_cmnd
), datadir
);
3370 if (unlikely(!protsegcnt
)) {
3371 scsi_dma_unmap(scsi_cmnd
);
3375 lpfc_cmd
->prot_seg_cnt
= protsegcnt
;
3377 * There is a minimun of 3 SGEs used for every
3378 * protection data segment.
3380 if (((lpfc_cmd
->prot_seg_cnt
* 3) >
3381 (phba
->cfg_total_seg_cnt
- 2)) &&
3387 num_sge
= lpfc_bg_setup_sgl_prot(phba
, scsi_cmnd
, sgl
,
3388 datasegcnt
, protsegcnt
, lpfc_cmd
);
3390 /* we should have 3 or more entries in buffer list */
3392 (num_sge
> phba
->cfg_total_seg_cnt
&&
3393 !phba
->cfg_xpsgl
)) {
3399 case LPFC_PG_TYPE_INVALID
:
3401 scsi_dma_unmap(scsi_cmnd
);
3402 lpfc_cmd
->seg_cnt
= 0;
3404 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
3405 "9083 Unexpected protection group %i\n",
3411 switch (scsi_get_prot_op(scsi_cmnd
)) {
3412 case SCSI_PROT_WRITE_STRIP
:
3413 case SCSI_PROT_READ_STRIP
:
3414 lpfc_cmd
->cur_iocbq
.cmd_flag
|= LPFC_IO_DIF_STRIP
;
3416 case SCSI_PROT_WRITE_INSERT
:
3417 case SCSI_PROT_READ_INSERT
:
3418 lpfc_cmd
->cur_iocbq
.cmd_flag
|= LPFC_IO_DIF_INSERT
;
3420 case SCSI_PROT_WRITE_PASS
:
3421 case SCSI_PROT_READ_PASS
:
3422 lpfc_cmd
->cur_iocbq
.cmd_flag
|= LPFC_IO_DIF_PASS
;
3426 fcpdl
= lpfc_bg_scsi_adjust_dl(phba
, lpfc_cmd
);
3427 if (lpfc_cmd
->pCmd
->cmd_len
> LPFC_FCP_CDB_LEN
)
3428 ((struct fcp_cmnd32
*)fcp_cmnd
)->fcpDl
= cpu_to_be32(fcpdl
);
3430 fcp_cmnd
->fcpDl
= cpu_to_be32(fcpdl
);
3432 /* Set first-burst provided it was successfully negotiated */
3433 if (!test_bit(HBA_FCOE_MODE
, &phba
->hba_flag
) &&
3434 vport
->cfg_first_burst_size
&&
3435 scsi_cmnd
->sc_data_direction
== DMA_TO_DEVICE
) {
3436 u32 init_len
, total_len
;
3439 init_len
= min(total_len
, vport
->cfg_first_burst_size
);
3442 wqe
->fcp_iwrite
.initial_xfer_len
= init_len
;
3443 wqe
->fcp_iwrite
.total_xfer_len
= total_len
;
3446 wqe
->fcp_iwrite
.total_xfer_len
= fcpdl
;
3450 * If the OAS driver feature is enabled and the lun is enabled for
3451 * OAS, set the oas iocb related flags.
3453 if ((phba
->cfg_fof
) && ((struct lpfc_device_data
*)
3454 scsi_cmnd
->device
->hostdata
)->oas_enabled
) {
3455 lpfc_cmd
->cur_iocbq
.cmd_flag
|= (LPFC_IO_OAS
| LPFC_IO_FOF
);
3458 bf_set(wqe_oas
, &wqe
->generic
.wqe_com
, 1);
3459 bf_set(wqe_ccpe
, &wqe
->generic
.wqe_com
, 1);
3460 bf_set(wqe_ccp
, &wqe
->generic
.wqe_com
,
3461 (phba
->cfg_XLanePriority
<< 1));
3464 /* Word 7. DIF Flags */
3465 if (lpfc_cmd
->cur_iocbq
.cmd_flag
& LPFC_IO_DIF_PASS
)
3466 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, LPFC_WQE_DIF_PASSTHRU
);
3467 else if (lpfc_cmd
->cur_iocbq
.cmd_flag
& LPFC_IO_DIF_STRIP
)
3468 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, LPFC_WQE_DIF_STRIP
);
3469 else if (lpfc_cmd
->cur_iocbq
.cmd_flag
& LPFC_IO_DIF_INSERT
)
3470 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, LPFC_WQE_DIF_INSERT
);
3472 lpfc_cmd
->cur_iocbq
.cmd_flag
&= ~(LPFC_IO_DIF_PASS
|
3473 LPFC_IO_DIF_STRIP
| LPFC_IO_DIF_INSERT
);
3477 if (lpfc_cmd
->seg_cnt
)
3478 scsi_dma_unmap(scsi_cmnd
);
3479 if (lpfc_cmd
->prot_seg_cnt
)
3480 dma_unmap_sg(&phba
->pcidev
->dev
, scsi_prot_sglist(scsi_cmnd
),
3481 scsi_prot_sg_count(scsi_cmnd
),
3482 scsi_cmnd
->sc_data_direction
);
3484 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
3485 "9084 Cannot setup S/G List for HBA "
3486 "IO segs %d/%d SGL %d SCSI %d: %d %d %d\n",
3487 lpfc_cmd
->seg_cnt
, lpfc_cmd
->prot_seg_cnt
,
3488 phba
->cfg_total_seg_cnt
, phba
->cfg_sg_seg_cnt
,
3489 prot_group_type
, num_sge
, ret
);
3491 lpfc_cmd
->seg_cnt
= 0;
3492 lpfc_cmd
->prot_seg_cnt
= 0;
3497 * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
3498 * @phba: The Hba for which this call is being executed.
3499 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3501 * This routine wraps the actual DMA mapping function pointer from the
3509 lpfc_scsi_prep_dma_buf(struct lpfc_hba
*phba
, struct lpfc_io_buf
*lpfc_cmd
)
3511 return phba
->lpfc_scsi_prep_dma_buf(phba
, lpfc_cmd
);
3515 * lpfc_bg_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
3517 * @phba: The Hba for which this call is being executed.
3518 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3520 * This routine wraps the actual DMA mapping function pointer from the
3528 lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba
*phba
, struct lpfc_io_buf
*lpfc_cmd
)
3530 return phba
->lpfc_bg_scsi_prep_dma_buf(phba
, lpfc_cmd
);
3534 * lpfc_scsi_prep_cmnd_buf - Wrapper function for IOCB/WQE mapping of scsi
3536 * @vport: Pointer to vport object.
3537 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3538 * @tmo: Timeout value for IO
3540 * This routine initializes IOCB/WQE data structure from scsi command
3547 lpfc_scsi_prep_cmnd_buf(struct lpfc_vport
*vport
, struct lpfc_io_buf
*lpfc_cmd
,
3550 return vport
->phba
->lpfc_scsi_prep_cmnd_buf(vport
, lpfc_cmd
, tmo
);
3554 * lpfc_send_scsi_error_event - Posts an event when there is SCSI error
3555 * @phba: Pointer to hba context object.
3556 * @vport: Pointer to vport object.
3557 * @lpfc_cmd: Pointer to lpfc scsi command which reported the error.
3558 * @fcpi_parm: FCP Initiator parameter.
3560 * This function posts an event when there is a SCSI command reporting
3561 * error from the scsi device.
3564 lpfc_send_scsi_error_event(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
,
3565 struct lpfc_io_buf
*lpfc_cmd
, uint32_t fcpi_parm
) {
3566 struct scsi_cmnd
*cmnd
= lpfc_cmd
->pCmd
;
3567 struct fcp_rsp
*fcprsp
= lpfc_cmd
->fcp_rsp
;
3568 uint32_t resp_info
= fcprsp
->rspStatus2
;
3569 uint32_t scsi_status
= fcprsp
->rspStatus3
;
3570 struct lpfc_fast_path_event
*fast_path_evt
= NULL
;
3571 struct lpfc_nodelist
*pnode
= lpfc_cmd
->rdata
->pnode
;
3572 unsigned long flags
;
3577 /* If there is queuefull or busy condition send a scsi event */
3578 if ((cmnd
->result
== SAM_STAT_TASK_SET_FULL
) ||
3579 (cmnd
->result
== SAM_STAT_BUSY
)) {
3580 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
3583 fast_path_evt
->un
.scsi_evt
.event_type
=
3585 fast_path_evt
->un
.scsi_evt
.subcategory
=
3586 (cmnd
->result
== SAM_STAT_TASK_SET_FULL
) ?
3587 LPFC_EVENT_QFULL
: LPFC_EVENT_DEVBSY
;
3588 fast_path_evt
->un
.scsi_evt
.lun
= cmnd
->device
->lun
;
3589 memcpy(&fast_path_evt
->un
.scsi_evt
.wwpn
,
3590 &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
3591 memcpy(&fast_path_evt
->un
.scsi_evt
.wwnn
,
3592 &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
3593 } else if ((resp_info
& SNS_LEN_VALID
) && fcprsp
->rspSnsLen
&&
3594 ((cmnd
->cmnd
[0] == READ_10
) || (cmnd
->cmnd
[0] == WRITE_10
))) {
3595 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
3598 fast_path_evt
->un
.check_cond_evt
.scsi_event
.event_type
=
3600 fast_path_evt
->un
.check_cond_evt
.scsi_event
.subcategory
=
3601 LPFC_EVENT_CHECK_COND
;
3602 fast_path_evt
->un
.check_cond_evt
.scsi_event
.lun
=
3604 memcpy(&fast_path_evt
->un
.check_cond_evt
.scsi_event
.wwpn
,
3605 &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
3606 memcpy(&fast_path_evt
->un
.check_cond_evt
.scsi_event
.wwnn
,
3607 &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
3608 fast_path_evt
->un
.check_cond_evt
.sense_key
=
3609 cmnd
->sense_buffer
[2] & 0xf;
3610 fast_path_evt
->un
.check_cond_evt
.asc
= cmnd
->sense_buffer
[12];
3611 fast_path_evt
->un
.check_cond_evt
.ascq
= cmnd
->sense_buffer
[13];
3612 } else if ((cmnd
->sc_data_direction
== DMA_FROM_DEVICE
) &&
3614 ((be32_to_cpu(fcprsp
->rspResId
) != fcpi_parm
) ||
3615 ((scsi_status
== SAM_STAT_GOOD
) &&
3616 !(resp_info
& (RESID_UNDER
| RESID_OVER
))))) {
3618 * If status is good or resid does not match with fcp_param and
3619 * there is valid fcpi_parm, then there is a read_check error
3621 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
3624 fast_path_evt
->un
.read_check_error
.header
.event_type
=
3625 FC_REG_FABRIC_EVENT
;
3626 fast_path_evt
->un
.read_check_error
.header
.subcategory
=
3627 LPFC_EVENT_FCPRDCHKERR
;
3628 memcpy(&fast_path_evt
->un
.read_check_error
.header
.wwpn
,
3629 &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
3630 memcpy(&fast_path_evt
->un
.read_check_error
.header
.wwnn
,
3631 &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
3632 fast_path_evt
->un
.read_check_error
.lun
= cmnd
->device
->lun
;
3633 fast_path_evt
->un
.read_check_error
.opcode
= cmnd
->cmnd
[0];
3634 fast_path_evt
->un
.read_check_error
.fcpiparam
=
3639 fast_path_evt
->vport
= vport
;
3640 spin_lock_irqsave(&phba
->hbalock
, flags
);
3641 list_add_tail(&fast_path_evt
->work_evt
.evt_listp
, &phba
->work_list
);
3642 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
3643 lpfc_worker_wake_up(phba
);
3648 * lpfc_scsi_unprep_dma_buf - Un-map DMA mapping of SG-list for dev
3649 * @phba: The HBA for which this call is being executed.
3650 * @psb: The scsi buffer which is going to be un-mapped.
3652 * This routine does DMA un-mapping of scatter gather list of scsi command
3653 * field of @lpfc_cmd for device with SLI-3 interface spec.
3656 lpfc_scsi_unprep_dma_buf(struct lpfc_hba
*phba
, struct lpfc_io_buf
*psb
)
3659 * There are only two special cases to consider. (1) the scsi command
3660 * requested scatter-gather usage or (2) the scsi command allocated
3661 * a request buffer, but did not request use_sg. There is a third
3662 * case, but it does not require resource deallocation.
3664 if (psb
->seg_cnt
> 0)
3665 scsi_dma_unmap(psb
->pCmd
);
3666 if (psb
->prot_seg_cnt
> 0)
3667 dma_unmap_sg(&phba
->pcidev
->dev
, scsi_prot_sglist(psb
->pCmd
),
3668 scsi_prot_sg_count(psb
->pCmd
),
3669 psb
->pCmd
->sc_data_direction
);
3673 * lpfc_unblock_requests - allow further commands to be queued.
3674 * @phba: pointer to phba object
3676 * For single vport, just call scsi_unblock_requests on physical port.
3677 * For multiple vports, send scsi_unblock_requests for all the vports.
3680 lpfc_unblock_requests(struct lpfc_hba
*phba
)
3682 struct lpfc_vport
**vports
;
3683 struct Scsi_Host
*shost
;
3686 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
3687 !phba
->sli4_hba
.max_cfg_param
.vpi_used
) {
3688 shost
= lpfc_shost_from_vport(phba
->pport
);
3689 scsi_unblock_requests(shost
);
3693 vports
= lpfc_create_vport_work_array(phba
);
3695 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
3696 shost
= lpfc_shost_from_vport(vports
[i
]);
3697 scsi_unblock_requests(shost
);
3699 lpfc_destroy_vport_work_array(phba
, vports
);
3703 * lpfc_block_requests - prevent further commands from being queued.
3704 * @phba: pointer to phba object
3706 * For single vport, just call scsi_block_requests on physical port.
3707 * For multiple vports, send scsi_block_requests for all the vports.
3710 lpfc_block_requests(struct lpfc_hba
*phba
)
3712 struct lpfc_vport
**vports
;
3713 struct Scsi_Host
*shost
;
3716 if (atomic_read(&phba
->cmf_stop_io
))
3719 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
3720 !phba
->sli4_hba
.max_cfg_param
.vpi_used
) {
3721 shost
= lpfc_shost_from_vport(phba
->pport
);
3722 scsi_block_requests(shost
);
3726 vports
= lpfc_create_vport_work_array(phba
);
3728 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
3729 shost
= lpfc_shost_from_vport(vports
[i
]);
3730 scsi_block_requests(shost
);
3732 lpfc_destroy_vport_work_array(phba
, vports
);
3736 * lpfc_update_cmf_cmpl - Adjust CMF counters for IO completion
3737 * @phba: The HBA for which this call is being executed.
3738 * @time: The latency of the IO that completed (in ns)
3739 * @size: The size of the IO that completed
3740 * @shost: SCSI host the IO completed on (NULL for a NVME IO)
3742 * The routine adjusts the various Burst and Bandwidth counters used in
3743 * Congestion management and E2E. If time is set to LPFC_CGN_NOT_SENT,
3744 * that means the IO was never issued to the HBA, so this routine is
3745 * just being called to cleanup the counter from a previous
3746 * lpfc_update_cmf_cmd call.
3749 lpfc_update_cmf_cmpl(struct lpfc_hba
*phba
,
3750 uint64_t time
, uint32_t size
, struct Scsi_Host
*shost
)
3752 struct lpfc_cgn_stat
*cgs
;
3754 if (time
!= LPFC_CGN_NOT_SENT
) {
3755 /* lat is ns coming in, save latency in us */
3759 time
= div_u64(time
+ 500, 1000); /* round it */
3761 cgs
= per_cpu_ptr(phba
->cmf_stat
, raw_smp_processor_id());
3762 atomic64_add(size
, &cgs
->rcv_bytes
);
3763 atomic64_add(time
, &cgs
->rx_latency
);
3764 atomic_inc(&cgs
->rx_io_cnt
);
3770 * lpfc_update_cmf_cmd - Adjust CMF counters for IO submission
3771 * @phba: The HBA for which this call is being executed.
3772 * @size: The size of the IO that will be issued
3774 * The routine adjusts the various Burst and Bandwidth counters used in
3775 * Congestion management and E2E.
3778 lpfc_update_cmf_cmd(struct lpfc_hba
*phba
, uint32_t size
)
3781 struct lpfc_cgn_stat
*cgs
;
3784 /* At this point we are either LPFC_CFG_MANAGED or LPFC_CFG_MONITOR */
3785 if (phba
->cmf_active_mode
== LPFC_CFG_MANAGED
&&
3786 phba
->cmf_max_bytes_per_interval
) {
3788 for_each_present_cpu(cpu
) {
3789 cgs
= per_cpu_ptr(phba
->cmf_stat
, cpu
);
3790 total
+= atomic64_read(&cgs
->total_bytes
);
3792 if (total
>= phba
->cmf_max_bytes_per_interval
) {
3793 if (!atomic_xchg(&phba
->cmf_bw_wait
, 1)) {
3794 lpfc_block_requests(phba
);
3796 lpfc_calc_cmf_latency(phba
);
3798 atomic_inc(&phba
->cmf_busy
);
3801 if (size
> atomic_read(&phba
->rx_max_read_cnt
))
3802 atomic_set(&phba
->rx_max_read_cnt
, size
);
3805 cgs
= per_cpu_ptr(phba
->cmf_stat
, raw_smp_processor_id());
3806 atomic64_add(size
, &cgs
->total_bytes
);
3811 * lpfc_handle_fcp_err - FCP response handler
3812 * @vport: The virtual port for which this call is being executed.
3813 * @lpfc_cmd: Pointer to lpfc_io_buf data structure.
3814 * @fcpi_parm: FCP Initiator parameter.
3816 * This routine is called to process response IOCB with status field
3817 * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command
3818 * based upon SCSI and FCP error.
3821 lpfc_handle_fcp_err(struct lpfc_vport
*vport
, struct lpfc_io_buf
*lpfc_cmd
,
3824 struct scsi_cmnd
*cmnd
= lpfc_cmd
->pCmd
;
3825 struct fcp_cmnd
*fcpcmd
= lpfc_cmd
->fcp_cmnd
;
3826 struct fcp_rsp
*fcprsp
= lpfc_cmd
->fcp_rsp
;
3827 uint32_t resp_info
= fcprsp
->rspStatus2
;
3828 uint32_t scsi_status
= fcprsp
->rspStatus3
;
3830 uint32_t host_status
= DID_OK
;
3831 uint32_t rsplen
= 0;
3833 uint32_t logit
= LOG_FCP
| LOG_FCP_ERROR
;
3837 * If this is a task management command, there is no
3838 * scsi packet associated with this lpfc_cmd. The driver
3841 if (fcpcmd
->fcpCntl2
) {
3846 if (resp_info
& RSP_LEN_VALID
) {
3847 rsplen
= be32_to_cpu(fcprsp
->rspRspLen
);
3848 if (rsplen
!= 0 && rsplen
!= 4 && rsplen
!= 8) {
3849 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
3850 "2719 Invalid response length: "
3851 "tgt x%x lun x%llx cmnd x%x rsplen "
3852 "x%x\n", cmnd
->device
->id
,
3853 cmnd
->device
->lun
, cmnd
->cmnd
[0],
3855 host_status
= DID_ERROR
;
3858 if (fcprsp
->rspInfo3
!= RSP_NO_FAILURE
) {
3859 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
3860 "2757 Protocol failure detected during "
3861 "processing of FCP I/O op: "
3862 "tgt x%x lun x%llx cmnd x%x rspInfo3 x%x\n",
3864 cmnd
->device
->lun
, cmnd
->cmnd
[0],
3866 host_status
= DID_ERROR
;
3871 if ((resp_info
& SNS_LEN_VALID
) && fcprsp
->rspSnsLen
) {
3872 uint32_t snslen
= be32_to_cpu(fcprsp
->rspSnsLen
);
3873 if (snslen
> SCSI_SENSE_BUFFERSIZE
)
3874 snslen
= SCSI_SENSE_BUFFERSIZE
;
3876 if (resp_info
& RSP_LEN_VALID
)
3877 rsplen
= be32_to_cpu(fcprsp
->rspRspLen
);
3878 memcpy(cmnd
->sense_buffer
, &fcprsp
->rspInfo0
+ rsplen
, snslen
);
3880 lp
= (uint32_t *)cmnd
->sense_buffer
;
3882 /* special handling for under run conditions */
3883 if (!scsi_status
&& (resp_info
& RESID_UNDER
)) {
3884 /* don't log under runs if fcp set... */
3885 if (vport
->cfg_log_verbose
& LOG_FCP
)
3886 logit
= LOG_FCP_ERROR
;
3887 /* unless operator says so */
3888 if (vport
->cfg_log_verbose
& LOG_FCP_UNDER
)
3889 logit
= LOG_FCP_UNDER
;
3892 lpfc_printf_vlog(vport
, KERN_WARNING
, logit
,
3893 "9024 FCP command x%x failed: x%x SNS x%x x%x "
3894 "Data: x%x x%x x%x x%x x%x\n",
3895 cmnd
->cmnd
[0], scsi_status
,
3896 be32_to_cpu(*lp
), be32_to_cpu(*(lp
+ 3)), resp_info
,
3897 be32_to_cpu(fcprsp
->rspResId
),
3898 be32_to_cpu(fcprsp
->rspSnsLen
),
3899 be32_to_cpu(fcprsp
->rspRspLen
),
3902 scsi_set_resid(cmnd
, 0);
3903 if (cmnd
->cmd_len
> LPFC_FCP_CDB_LEN
)
3904 fcpDl
= be32_to_cpu(((struct fcp_cmnd32
*)fcpcmd
)->fcpDl
);
3906 fcpDl
= be32_to_cpu(fcpcmd
->fcpDl
);
3907 if (resp_info
& RESID_UNDER
) {
3908 scsi_set_resid(cmnd
, be32_to_cpu(fcprsp
->rspResId
));
3910 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP_UNDER
,
3911 "9025 FCP Underrun, expected %d, "
3912 "residual %d Data: x%x x%x x%x\n",
3914 scsi_get_resid(cmnd
), fcpi_parm
, cmnd
->cmnd
[0],
3918 * If there is an under run, check if under run reported by
3919 * storage array is same as the under run reported by HBA.
3920 * If this is not same, there is a dropped frame.
3922 if (fcpi_parm
&& (scsi_get_resid(cmnd
) != fcpi_parm
)) {
3923 lpfc_printf_vlog(vport
, KERN_WARNING
,
3924 LOG_FCP
| LOG_FCP_ERROR
,
3925 "9026 FCP Read Check Error "
3926 "and Underrun Data: x%x x%x x%x x%x\n",
3928 scsi_get_resid(cmnd
), fcpi_parm
,
3930 scsi_set_resid(cmnd
, scsi_bufflen(cmnd
));
3931 host_status
= DID_ERROR
;
3934 * The cmnd->underflow is the minimum number of bytes that must
3935 * be transferred for this command. Provided a sense condition
3936 * is not present, make sure the actual amount transferred is at
3937 * least the underflow value or fail.
3939 if (!(resp_info
& SNS_LEN_VALID
) &&
3940 (scsi_status
== SAM_STAT_GOOD
) &&
3941 (scsi_bufflen(cmnd
) - scsi_get_resid(cmnd
)
3942 < cmnd
->underflow
)) {
3943 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
3944 "9027 FCP command x%x residual "
3945 "underrun converted to error "
3946 "Data: x%x x%x x%x\n",
3947 cmnd
->cmnd
[0], scsi_bufflen(cmnd
),
3948 scsi_get_resid(cmnd
), cmnd
->underflow
);
3949 host_status
= DID_ERROR
;
3951 } else if (resp_info
& RESID_OVER
) {
3952 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
3953 "9028 FCP command x%x residual overrun error. "
3954 "Data: x%x x%x\n", cmnd
->cmnd
[0],
3955 scsi_bufflen(cmnd
), scsi_get_resid(cmnd
));
3956 host_status
= DID_ERROR
;
3959 * Check SLI validation that all the transfer was actually done
3960 * (fcpi_parm should be zero). Apply check only to reads.
3962 } else if (fcpi_parm
) {
3963 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
| LOG_FCP_ERROR
,
3964 "9029 FCP %s Check Error Data: "
3965 "x%x x%x x%x x%x x%x\n",
3966 ((cmnd
->sc_data_direction
== DMA_FROM_DEVICE
) ?
3968 fcpDl
, be32_to_cpu(fcprsp
->rspResId
),
3969 fcpi_parm
, cmnd
->cmnd
[0], scsi_status
);
3971 /* There is some issue with the LPe12000 that causes it
3972 * to miscalculate the fcpi_parm and falsely trip this
3973 * recovery logic. Detect this case and don't error when true.
3975 if (fcpi_parm
> fcpDl
)
3978 switch (scsi_status
) {
3980 case SAM_STAT_CHECK_CONDITION
:
3981 /* Fabric dropped a data frame. Fail any successful
3982 * command in which we detected dropped frames.
3983 * A status of good or some check conditions could
3984 * be considered a successful command.
3986 host_status
= DID_ERROR
;
3989 scsi_set_resid(cmnd
, scsi_bufflen(cmnd
));
3993 cmnd
->result
= host_status
<< 16 | scsi_status
;
3994 lpfc_send_scsi_error_event(vport
->phba
, vport
, lpfc_cmd
, fcpi_parm
);
3998 * lpfc_fcp_io_cmd_wqe_cmpl - Complete a FCP IO
3999 * @phba: The hba for which this call is being executed.
4000 * @pwqeIn: The command WQE for the scsi cmnd.
4001 * @pwqeOut: Pointer to driver response WQE object.
4003 * This routine assigns scsi command result by looking into response WQE
4004 * status field appropriately. This routine handles QUEUE FULL condition as
4005 * well by ramping down device queue depth.
4008 lpfc_fcp_io_cmd_wqe_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*pwqeIn
,
4009 struct lpfc_iocbq
*pwqeOut
)
4011 struct lpfc_io_buf
*lpfc_cmd
= pwqeIn
->io_buf
;
4012 struct lpfc_wcqe_complete
*wcqe
= &pwqeOut
->wcqe_cmpl
;
4013 struct lpfc_vport
*vport
= pwqeIn
->vport
;
4014 struct lpfc_rport_data
*rdata
;
4015 struct lpfc_nodelist
*ndlp
;
4016 struct scsi_cmnd
*cmd
;
4017 unsigned long flags
;
4018 struct lpfc_fast_path_event
*fast_path_evt
;
4019 struct Scsi_Host
*shost
;
4020 u32 logit
= LOG_FCP
;
4025 /* Sanity check on return of outstanding command */
4027 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
4028 "9032 Null lpfc_cmd pointer. No "
4029 "release, skip completion\n");
4033 rdata
= lpfc_cmd
->rdata
;
4034 ndlp
= rdata
->pnode
;
4036 /* Sanity check on return of outstanding command */
4037 cmd
= lpfc_cmd
->pCmd
;
4039 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
4040 "9042 I/O completion: Not an active IO\n");
4041 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
4044 /* Guard against abort handler being called at same time */
4045 spin_lock(&lpfc_cmd
->buf_lock
);
4046 idx
= lpfc_cmd
->cur_iocbq
.hba_wqidx
;
4047 if (phba
->sli4_hba
.hdwq
)
4048 phba
->sli4_hba
.hdwq
[idx
].scsi_cstat
.io_cmpls
++;
4050 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4051 if (unlikely(phba
->hdwqstat_on
& LPFC_CHECK_SCSI_IO
))
4052 this_cpu_inc(phba
->sli4_hba
.c_stat
->cmpl_io
);
4054 shost
= cmd
->device
->host
;
4056 lpfc_cmd
->status
= bf_get(lpfc_wcqe_c_status
, wcqe
);
4057 lpfc_cmd
->result
= (wcqe
->parameter
& IOERR_PARAM_MASK
);
4059 lpfc_cmd
->flags
&= ~LPFC_SBUF_XBUSY
;
4060 if (bf_get(lpfc_wcqe_c_xb
, wcqe
)) {
4061 lpfc_cmd
->flags
|= LPFC_SBUF_XBUSY
;
4062 if (phba
->cfg_fcp_wait_abts_rsp
)
4066 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4067 if (lpfc_cmd
->prot_data_type
) {
4068 struct scsi_dif_tuple
*src
= NULL
;
4070 src
= (struct scsi_dif_tuple
*)lpfc_cmd
->prot_data_segment
;
4072 * Used to restore any changes to protection
4073 * data for error injection.
4075 switch (lpfc_cmd
->prot_data_type
) {
4076 case LPFC_INJERR_REFTAG
:
4078 lpfc_cmd
->prot_data
;
4080 case LPFC_INJERR_APPTAG
:
4082 (uint16_t)lpfc_cmd
->prot_data
;
4084 case LPFC_INJERR_GUARD
:
4086 (uint16_t)lpfc_cmd
->prot_data
;
4092 lpfc_cmd
->prot_data
= 0;
4093 lpfc_cmd
->prot_data_type
= 0;
4094 lpfc_cmd
->prot_data_segment
= NULL
;
4097 if (unlikely(lpfc_cmd
->status
)) {
4098 if (lpfc_cmd
->status
== IOSTAT_FCP_RSP_ERROR
&&
4099 !lpfc_cmd
->fcp_rsp
->rspStatus3
&&
4100 (lpfc_cmd
->fcp_rsp
->rspStatus2
& RESID_UNDER
) &&
4101 !(vport
->cfg_log_verbose
& LOG_FCP_UNDER
))
4104 logit
= LOG_FCP
| LOG_FCP_UNDER
;
4105 lpfc_printf_vlog(vport
, KERN_WARNING
, logit
,
4106 "9034 FCP cmd x%x failed <%d/%lld> "
4107 "status: x%x result: x%x "
4108 "sid: x%x did: x%x oxid: x%x "
4109 "Data: x%x x%x x%x\n",
4111 cmd
->device
? cmd
->device
->id
: 0xffff,
4112 cmd
->device
? cmd
->device
->lun
: 0xffff,
4113 lpfc_cmd
->status
, lpfc_cmd
->result
,
4115 (ndlp
) ? ndlp
->nlp_DID
: 0,
4116 lpfc_cmd
->cur_iocbq
.sli4_xritag
,
4117 wcqe
->parameter
, wcqe
->total_data_placed
,
4118 lpfc_cmd
->cur_iocbq
.iotag
);
4121 switch (lpfc_cmd
->status
) {
4122 case CQE_STATUS_SUCCESS
:
4123 cmd
->result
= DID_OK
<< 16;
4125 case CQE_STATUS_FCP_RSP_FAILURE
:
4126 lpfc_handle_fcp_err(vport
, lpfc_cmd
,
4127 pwqeIn
->wqe
.fcp_iread
.total_xfer_len
-
4128 wcqe
->total_data_placed
);
4130 case CQE_STATUS_NPORT_BSY
:
4131 case CQE_STATUS_FABRIC_BSY
:
4132 cmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
4133 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
4136 fast_path_evt
->un
.fabric_evt
.event_type
=
4137 FC_REG_FABRIC_EVENT
;
4138 fast_path_evt
->un
.fabric_evt
.subcategory
=
4139 (lpfc_cmd
->status
== IOSTAT_NPORT_BSY
) ?
4140 LPFC_EVENT_PORT_BUSY
: LPFC_EVENT_FABRIC_BUSY
;
4142 memcpy(&fast_path_evt
->un
.fabric_evt
.wwpn
,
4143 &ndlp
->nlp_portname
,
4144 sizeof(struct lpfc_name
));
4145 memcpy(&fast_path_evt
->un
.fabric_evt
.wwnn
,
4146 &ndlp
->nlp_nodename
,
4147 sizeof(struct lpfc_name
));
4149 fast_path_evt
->vport
= vport
;
4150 fast_path_evt
->work_evt
.evt
=
4151 LPFC_EVT_FASTPATH_MGMT_EVT
;
4152 spin_lock_irqsave(&phba
->hbalock
, flags
);
4153 list_add_tail(&fast_path_evt
->work_evt
.evt_listp
,
4155 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
4156 lpfc_worker_wake_up(phba
);
4157 lpfc_printf_vlog(vport
, KERN_WARNING
, logit
,
4158 "9035 Fabric/Node busy FCP cmd x%x failed"
4160 "status: x%x result: x%x "
4161 "sid: x%x did: x%x oxid: x%x "
4162 "Data: x%x x%x x%x\n",
4164 cmd
->device
? cmd
->device
->id
: 0xffff,
4165 cmd
->device
? cmd
->device
->lun
: 0xffff,
4166 lpfc_cmd
->status
, lpfc_cmd
->result
,
4168 (ndlp
) ? ndlp
->nlp_DID
: 0,
4169 lpfc_cmd
->cur_iocbq
.sli4_xritag
,
4171 wcqe
->total_data_placed
,
4172 lpfc_cmd
->cur_iocbq
.iocb
.ulpIoTag
);
4174 case CQE_STATUS_DI_ERROR
:
4175 if (bf_get(lpfc_wcqe_c_bg_edir
, wcqe
))
4176 lpfc_cmd
->result
= IOERR_RX_DMA_FAILED
;
4178 lpfc_cmd
->result
= IOERR_TX_DMA_FAILED
;
4179 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
| LOG_BG
,
4180 "9048 DI Error xri x%x status x%x DI ext "
4181 "status x%x data placed x%x\n",
4182 lpfc_cmd
->cur_iocbq
.sli4_xritag
,
4183 lpfc_cmd
->status
, wcqe
->parameter
,
4184 wcqe
->total_data_placed
);
4185 if (scsi_get_prot_op(cmd
) != SCSI_PROT_NORMAL
) {
4186 /* BG enabled cmd. Parse BG error */
4187 lpfc_parse_bg_err(phba
, lpfc_cmd
, pwqeOut
);
4190 cmd
->result
= DID_ERROR
<< 16;
4191 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_BG
,
4192 "9040 DI Error on unprotected cmd\n");
4194 case CQE_STATUS_REMOTE_STOP
:
4196 /* This I/O was aborted by the target, we don't
4197 * know the rxid and because we did not send the
4198 * ABTS we cannot generate and RRQ.
4200 lpfc_set_rrq_active(phba
, ndlp
,
4201 lpfc_cmd
->cur_iocbq
.sli4_lxritag
,
4205 case CQE_STATUS_LOCAL_REJECT
:
4206 if (lpfc_cmd
->result
& IOERR_DRVR_MASK
)
4207 lpfc_cmd
->status
= IOSTAT_DRIVER_REJECT
;
4208 if (lpfc_cmd
->result
== IOERR_ELXSEC_KEY_UNWRAP_ERROR
||
4210 IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR
||
4211 lpfc_cmd
->result
== IOERR_ELXSEC_CRYPTO_ERROR
||
4213 IOERR_ELXSEC_CRYPTO_COMPARE_ERROR
) {
4214 cmd
->result
= DID_NO_CONNECT
<< 16;
4217 if (lpfc_cmd
->result
== IOERR_INVALID_RPI
||
4218 lpfc_cmd
->result
== IOERR_LINK_DOWN
||
4219 lpfc_cmd
->result
== IOERR_NO_RESOURCES
||
4220 lpfc_cmd
->result
== IOERR_ABORT_REQUESTED
||
4221 lpfc_cmd
->result
== IOERR_RPI_SUSPENDED
||
4222 lpfc_cmd
->result
== IOERR_SLER_CMD_RCV_FAILURE
) {
4223 cmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
4226 lpfc_printf_vlog(vport
, KERN_WARNING
, logit
,
4227 "9036 Local Reject FCP cmd x%x failed"
4229 "status: x%x result: x%x "
4230 "sid: x%x did: x%x oxid: x%x "
4231 "Data: x%x x%x x%x\n",
4233 cmd
->device
? cmd
->device
->id
: 0xffff,
4234 cmd
->device
? cmd
->device
->lun
: 0xffff,
4235 lpfc_cmd
->status
, lpfc_cmd
->result
,
4237 (ndlp
) ? ndlp
->nlp_DID
: 0,
4238 lpfc_cmd
->cur_iocbq
.sli4_xritag
,
4240 wcqe
->total_data_placed
,
4241 lpfc_cmd
->cur_iocbq
.iocb
.ulpIoTag
);
4244 cmd
->result
= DID_ERROR
<< 16;
4245 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
4246 "9037 FCP Completion Error: xri %x "
4247 "status x%x result x%x [x%x] "
4249 lpfc_cmd
->cur_iocbq
.sli4_xritag
,
4250 lpfc_cmd
->status
, lpfc_cmd
->result
,
4252 wcqe
->total_data_placed
);
4254 if (cmd
->result
|| lpfc_cmd
->fcp_rsp
->rspSnsLen
) {
4255 u32
*lp
= (u32
*)cmd
->sense_buffer
;
4257 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
4258 "9039 Iodone <%d/%llu> cmd x%px, error "
4259 "x%x SNS x%x x%x LBA x%llx Data: x%x x%x\n",
4260 cmd
->device
->id
, cmd
->device
->lun
, cmd
,
4261 cmd
->result
, *lp
, *(lp
+ 3),
4262 (cmd
->device
->sector_size
) ?
4263 (u64
)scsi_get_lba(cmd
) : 0,
4264 cmd
->retries
, scsi_get_resid(cmd
));
4267 if (vport
->cfg_max_scsicmpl_time
&&
4268 time_after(jiffies
, lpfc_cmd
->start_time
+
4269 msecs_to_jiffies(vport
->cfg_max_scsicmpl_time
))) {
4270 spin_lock_irqsave(shost
->host_lock
, flags
);
4272 if (ndlp
->cmd_qdepth
>
4273 atomic_read(&ndlp
->cmd_pending
) &&
4274 (atomic_read(&ndlp
->cmd_pending
) >
4275 LPFC_MIN_TGT_QDEPTH
) &&
4276 (cmd
->cmnd
[0] == READ_10
||
4277 cmd
->cmnd
[0] == WRITE_10
))
4279 atomic_read(&ndlp
->cmd_pending
);
4281 ndlp
->last_change_time
= jiffies
;
4283 spin_unlock_irqrestore(shost
->host_lock
, flags
);
4285 lpfc_scsi_unprep_dma_buf(phba
, lpfc_cmd
);
4287 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4288 if (lpfc_cmd
->ts_cmd_start
) {
4289 lpfc_cmd
->ts_isr_cmpl
= lpfc_cmd
->cur_iocbq
.isr_timestamp
;
4290 lpfc_cmd
->ts_data_io
= ktime_get_ns();
4291 phba
->ktime_last_cmd
= lpfc_cmd
->ts_data_io
;
4292 lpfc_io_ktime(phba
, lpfc_cmd
);
4295 if (likely(!wait_xb_clr
))
4296 lpfc_cmd
->pCmd
= NULL
;
4297 spin_unlock(&lpfc_cmd
->buf_lock
);
4299 /* Check if IO qualified for CMF */
4300 if (phba
->cmf_active_mode
!= LPFC_CFG_OFF
&&
4301 cmd
->sc_data_direction
== DMA_FROM_DEVICE
&&
4302 (scsi_sg_count(cmd
))) {
4303 /* Used when calculating average latency */
4304 lat
= ktime_get_ns() - lpfc_cmd
->rx_cmd_start
;
4305 lpfc_update_cmf_cmpl(phba
, lat
, scsi_bufflen(cmd
), shost
);
4311 /* The sdev is not guaranteed to be valid post scsi_done upcall. */
4315 * If there is an abort thread waiting for command completion
4316 * wake up the thread.
4318 spin_lock(&lpfc_cmd
->buf_lock
);
4319 lpfc_cmd
->cur_iocbq
.cmd_flag
&= ~LPFC_DRIVER_ABORTED
;
4320 if (lpfc_cmd
->waitq
)
4321 wake_up(lpfc_cmd
->waitq
);
4322 spin_unlock(&lpfc_cmd
->buf_lock
);
4324 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
4328 * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine
4329 * @phba: The Hba for which this call is being executed.
4330 * @pIocbIn: The command IOCBQ for the scsi cmnd.
4331 * @pIocbOut: The response IOCBQ for the scsi cmnd.
4333 * This routine assigns scsi command result by looking into response IOCB
4334 * status field appropriately. This routine handles QUEUE FULL condition as
4335 * well by ramping down device queue depth.
4338 lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*pIocbIn
,
4339 struct lpfc_iocbq
*pIocbOut
)
4341 struct lpfc_io_buf
*lpfc_cmd
=
4342 (struct lpfc_io_buf
*) pIocbIn
->io_buf
;
4343 struct lpfc_vport
*vport
= pIocbIn
->vport
;
4344 struct lpfc_rport_data
*rdata
= lpfc_cmd
->rdata
;
4345 struct lpfc_nodelist
*pnode
= rdata
->pnode
;
4346 struct scsi_cmnd
*cmd
;
4347 unsigned long flags
;
4348 struct lpfc_fast_path_event
*fast_path_evt
;
4349 struct Scsi_Host
*shost
;
4351 uint32_t logit
= LOG_FCP
;
4353 /* Guard against abort handler being called at same time */
4354 spin_lock(&lpfc_cmd
->buf_lock
);
4356 /* Sanity check on return of outstanding command */
4357 cmd
= lpfc_cmd
->pCmd
;
4358 if (!cmd
|| !phba
) {
4359 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
4360 "2621 IO completion: Not an active IO\n");
4361 spin_unlock(&lpfc_cmd
->buf_lock
);
4365 idx
= lpfc_cmd
->cur_iocbq
.hba_wqidx
;
4366 if (phba
->sli4_hba
.hdwq
)
4367 phba
->sli4_hba
.hdwq
[idx
].scsi_cstat
.io_cmpls
++;
4369 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4370 if (unlikely(phba
->hdwqstat_on
& LPFC_CHECK_SCSI_IO
))
4371 this_cpu_inc(phba
->sli4_hba
.c_stat
->cmpl_io
);
4373 shost
= cmd
->device
->host
;
4375 lpfc_cmd
->result
= (pIocbOut
->iocb
.un
.ulpWord
[4] & IOERR_PARAM_MASK
);
4376 lpfc_cmd
->status
= pIocbOut
->iocb
.ulpStatus
;
4377 /* pick up SLI4 exchange busy status from HBA */
4378 lpfc_cmd
->flags
&= ~LPFC_SBUF_XBUSY
;
4379 if (pIocbOut
->cmd_flag
& LPFC_EXCHANGE_BUSY
)
4380 lpfc_cmd
->flags
|= LPFC_SBUF_XBUSY
;
4382 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4383 if (lpfc_cmd
->prot_data_type
) {
4384 struct scsi_dif_tuple
*src
= NULL
;
4386 src
= (struct scsi_dif_tuple
*)lpfc_cmd
->prot_data_segment
;
4388 * Used to restore any changes to protection
4389 * data for error injection.
4391 switch (lpfc_cmd
->prot_data_type
) {
4392 case LPFC_INJERR_REFTAG
:
4394 lpfc_cmd
->prot_data
;
4396 case LPFC_INJERR_APPTAG
:
4398 (uint16_t)lpfc_cmd
->prot_data
;
4400 case LPFC_INJERR_GUARD
:
4402 (uint16_t)lpfc_cmd
->prot_data
;
4408 lpfc_cmd
->prot_data
= 0;
4409 lpfc_cmd
->prot_data_type
= 0;
4410 lpfc_cmd
->prot_data_segment
= NULL
;
4414 if (unlikely(lpfc_cmd
->status
)) {
4415 if (lpfc_cmd
->status
== IOSTAT_LOCAL_REJECT
&&
4416 (lpfc_cmd
->result
& IOERR_DRVR_MASK
))
4417 lpfc_cmd
->status
= IOSTAT_DRIVER_REJECT
;
4418 else if (lpfc_cmd
->status
>= IOSTAT_CNT
)
4419 lpfc_cmd
->status
= IOSTAT_DEFAULT
;
4420 if (lpfc_cmd
->status
== IOSTAT_FCP_RSP_ERROR
&&
4421 !lpfc_cmd
->fcp_rsp
->rspStatus3
&&
4422 (lpfc_cmd
->fcp_rsp
->rspStatus2
& RESID_UNDER
) &&
4423 !(vport
->cfg_log_verbose
& LOG_FCP_UNDER
))
4426 logit
= LOG_FCP
| LOG_FCP_UNDER
;
4427 lpfc_printf_vlog(vport
, KERN_WARNING
, logit
,
4428 "9030 FCP cmd x%x failed <%d/%lld> "
4429 "status: x%x result: x%x "
4430 "sid: x%x did: x%x oxid: x%x "
4433 cmd
->device
? cmd
->device
->id
: 0xffff,
4434 cmd
->device
? cmd
->device
->lun
: 0xffff,
4435 lpfc_cmd
->status
, lpfc_cmd
->result
,
4437 (pnode
) ? pnode
->nlp_DID
: 0,
4438 phba
->sli_rev
== LPFC_SLI_REV4
?
4439 lpfc_cmd
->cur_iocbq
.sli4_xritag
: 0xffff,
4440 pIocbOut
->iocb
.ulpContext
,
4441 lpfc_cmd
->cur_iocbq
.iocb
.ulpIoTag
);
4443 switch (lpfc_cmd
->status
) {
4444 case IOSTAT_FCP_RSP_ERROR
:
4445 /* Call FCP RSP handler to determine result */
4446 lpfc_handle_fcp_err(vport
, lpfc_cmd
,
4447 pIocbOut
->iocb
.un
.fcpi
.fcpi_parm
);
4449 case IOSTAT_NPORT_BSY
:
4450 case IOSTAT_FABRIC_BSY
:
4451 cmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
4452 fast_path_evt
= lpfc_alloc_fast_evt(phba
);
4455 fast_path_evt
->un
.fabric_evt
.event_type
=
4456 FC_REG_FABRIC_EVENT
;
4457 fast_path_evt
->un
.fabric_evt
.subcategory
=
4458 (lpfc_cmd
->status
== IOSTAT_NPORT_BSY
) ?
4459 LPFC_EVENT_PORT_BUSY
: LPFC_EVENT_FABRIC_BUSY
;
4461 memcpy(&fast_path_evt
->un
.fabric_evt
.wwpn
,
4462 &pnode
->nlp_portname
,
4463 sizeof(struct lpfc_name
));
4464 memcpy(&fast_path_evt
->un
.fabric_evt
.wwnn
,
4465 &pnode
->nlp_nodename
,
4466 sizeof(struct lpfc_name
));
4468 fast_path_evt
->vport
= vport
;
4469 fast_path_evt
->work_evt
.evt
=
4470 LPFC_EVT_FASTPATH_MGMT_EVT
;
4471 spin_lock_irqsave(&phba
->hbalock
, flags
);
4472 list_add_tail(&fast_path_evt
->work_evt
.evt_listp
,
4474 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
4475 lpfc_worker_wake_up(phba
);
4477 case IOSTAT_LOCAL_REJECT
:
4478 case IOSTAT_REMOTE_STOP
:
4479 if (lpfc_cmd
->result
== IOERR_ELXSEC_KEY_UNWRAP_ERROR
||
4481 IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR
||
4482 lpfc_cmd
->result
== IOERR_ELXSEC_CRYPTO_ERROR
||
4484 IOERR_ELXSEC_CRYPTO_COMPARE_ERROR
) {
4485 cmd
->result
= DID_NO_CONNECT
<< 16;
4488 if (lpfc_cmd
->result
== IOERR_INVALID_RPI
||
4489 lpfc_cmd
->result
== IOERR_NO_RESOURCES
||
4490 lpfc_cmd
->result
== IOERR_ABORT_REQUESTED
||
4491 lpfc_cmd
->result
== IOERR_SLER_CMD_RCV_FAILURE
) {
4492 cmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
4495 if ((lpfc_cmd
->result
== IOERR_RX_DMA_FAILED
||
4496 lpfc_cmd
->result
== IOERR_TX_DMA_FAILED
) &&
4497 pIocbOut
->iocb
.unsli3
.sli3_bg
.bgstat
) {
4498 if (scsi_get_prot_op(cmd
) != SCSI_PROT_NORMAL
) {
4500 * This is a response for a BG enabled
4501 * cmd. Parse BG error
4503 lpfc_parse_bg_err(phba
, lpfc_cmd
,
4507 lpfc_printf_vlog(vport
, KERN_WARNING
,
4509 "9031 non-zero BGSTAT "
4510 "on unprotected cmd\n");
4513 if ((lpfc_cmd
->status
== IOSTAT_REMOTE_STOP
)
4514 && (phba
->sli_rev
== LPFC_SLI_REV4
)
4516 /* This IO was aborted by the target, we don't
4517 * know the rxid and because we did not send the
4518 * ABTS we cannot generate and RRQ.
4520 lpfc_set_rrq_active(phba
, pnode
,
4521 lpfc_cmd
->cur_iocbq
.sli4_lxritag
,
4526 cmd
->result
= DID_ERROR
<< 16;
4530 if (!pnode
|| (pnode
->nlp_state
!= NLP_STE_MAPPED_NODE
))
4531 cmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16 |
4534 cmd
->result
= DID_OK
<< 16;
4536 if (cmd
->result
|| lpfc_cmd
->fcp_rsp
->rspSnsLen
) {
4537 uint32_t *lp
= (uint32_t *)cmd
->sense_buffer
;
4539 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
4540 "0710 Iodone <%d/%llu> cmd x%px, error "
4541 "x%x SNS x%x x%x Data: x%x x%x\n",
4542 cmd
->device
->id
, cmd
->device
->lun
, cmd
,
4543 cmd
->result
, *lp
, *(lp
+ 3), cmd
->retries
,
4544 scsi_get_resid(cmd
));
4547 if (vport
->cfg_max_scsicmpl_time
&&
4548 time_after(jiffies
, lpfc_cmd
->start_time
+
4549 msecs_to_jiffies(vport
->cfg_max_scsicmpl_time
))) {
4550 spin_lock_irqsave(shost
->host_lock
, flags
);
4552 if (pnode
->cmd_qdepth
>
4553 atomic_read(&pnode
->cmd_pending
) &&
4554 (atomic_read(&pnode
->cmd_pending
) >
4555 LPFC_MIN_TGT_QDEPTH
) &&
4556 ((cmd
->cmnd
[0] == READ_10
) ||
4557 (cmd
->cmnd
[0] == WRITE_10
)))
4559 atomic_read(&pnode
->cmd_pending
);
4561 pnode
->last_change_time
= jiffies
;
4563 spin_unlock_irqrestore(shost
->host_lock
, flags
);
4565 lpfc_scsi_unprep_dma_buf(phba
, lpfc_cmd
);
4567 lpfc_cmd
->pCmd
= NULL
;
4568 spin_unlock(&lpfc_cmd
->buf_lock
);
4570 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4571 if (lpfc_cmd
->ts_cmd_start
) {
4572 lpfc_cmd
->ts_isr_cmpl
= pIocbIn
->isr_timestamp
;
4573 lpfc_cmd
->ts_data_io
= ktime_get_ns();
4574 phba
->ktime_last_cmd
= lpfc_cmd
->ts_data_io
;
4575 lpfc_io_ktime(phba
, lpfc_cmd
);
4579 /* The sdev is not guaranteed to be valid post scsi_done upcall. */
4583 * If there is an abort thread waiting for command completion
4584 * wake up the thread.
4586 spin_lock(&lpfc_cmd
->buf_lock
);
4587 lpfc_cmd
->cur_iocbq
.cmd_flag
&= ~LPFC_DRIVER_ABORTED
;
4588 if (lpfc_cmd
->waitq
)
4589 wake_up(lpfc_cmd
->waitq
);
4590 spin_unlock(&lpfc_cmd
->buf_lock
);
4592 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
4596 * lpfc_scsi_prep_cmnd_buf_s3 - SLI-3 IOCB init for the IO
4597 * @vport: Pointer to vport object.
4598 * @lpfc_cmd: The scsi buffer which is going to be prep'ed.
4599 * @tmo: timeout value for the IO
4601 * Based on the data-direction of the command, initialize IOCB
4602 * in the I/O buffer. Fill in the IOCB fields which are independent
4603 * of the scsi buffer
4605 * RETURNS 0 - SUCCESS,
4607 static int lpfc_scsi_prep_cmnd_buf_s3(struct lpfc_vport
*vport
,
4608 struct lpfc_io_buf
*lpfc_cmd
,
4611 IOCB_t
*iocb_cmd
= &lpfc_cmd
->cur_iocbq
.iocb
;
4612 struct lpfc_iocbq
*piocbq
= &lpfc_cmd
->cur_iocbq
;
4613 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
4614 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
4615 struct lpfc_nodelist
*pnode
= lpfc_cmd
->ndlp
;
4616 int datadir
= scsi_cmnd
->sc_data_direction
;
4619 piocbq
->iocb
.un
.fcpi
.fcpi_XRdy
= 0;
4622 * There are three possibilities here - use scatter-gather segment, use
4623 * the single mapping, or neither. Start the lpfc command prep by
4624 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
4627 if (scsi_sg_count(scsi_cmnd
)) {
4628 if (datadir
== DMA_TO_DEVICE
) {
4629 iocb_cmd
->ulpCommand
= CMD_FCP_IWRITE64_CR
;
4630 iocb_cmd
->ulpPU
= PARM_READ_CHECK
;
4631 if (vport
->cfg_first_burst_size
&&
4632 test_bit(NLP_FIRSTBURST
, &pnode
->nlp_flag
)) {
4635 fcpdl
= scsi_bufflen(scsi_cmnd
);
4636 xrdy_len
= min(fcpdl
,
4637 vport
->cfg_first_burst_size
);
4638 piocbq
->iocb
.un
.fcpi
.fcpi_XRdy
= xrdy_len
;
4640 fcp_cmnd
->fcpCntl3
= WRITE_DATA
;
4642 iocb_cmd
->ulpCommand
= CMD_FCP_IREAD64_CR
;
4643 iocb_cmd
->ulpPU
= PARM_READ_CHECK
;
4644 fcp_cmnd
->fcpCntl3
= READ_DATA
;
4647 iocb_cmd
->ulpCommand
= CMD_FCP_ICMND64_CR
;
4648 iocb_cmd
->un
.fcpi
.fcpi_parm
= 0;
4649 iocb_cmd
->ulpPU
= 0;
4650 fcp_cmnd
->fcpCntl3
= 0;
4654 * Finish initializing those IOCB fields that are independent
4655 * of the scsi_cmnd request_buffer
4657 piocbq
->iocb
.ulpContext
= pnode
->nlp_rpi
;
4658 if (pnode
->nlp_fcp_info
& NLP_FCP_2_DEVICE
)
4659 piocbq
->iocb
.ulpFCP2Rcvy
= 1;
4661 piocbq
->iocb
.ulpFCP2Rcvy
= 0;
4663 piocbq
->iocb
.ulpClass
= (pnode
->nlp_fcp_info
& 0x0f);
4664 piocbq
->io_buf
= lpfc_cmd
;
4665 if (!piocbq
->cmd_cmpl
)
4666 piocbq
->cmd_cmpl
= lpfc_scsi_cmd_iocb_cmpl
;
4667 piocbq
->iocb
.ulpTimeout
= tmo
;
4668 piocbq
->vport
= vport
;
4673 * lpfc_scsi_prep_cmnd_buf_s4 - SLI-4 WQE init for the IO
4674 * @vport: Pointer to vport object.
4675 * @lpfc_cmd: The scsi buffer which is going to be prep'ed.
4676 * @tmo: timeout value for the IO
4678 * Based on the data-direction of the command copy WQE template
4679 * to I/O buffer WQE. Fill in the WQE fields which are independent
4680 * of the scsi buffer
4682 * RETURNS 0 - SUCCESS,
4684 static int lpfc_scsi_prep_cmnd_buf_s4(struct lpfc_vport
*vport
,
4685 struct lpfc_io_buf
*lpfc_cmd
,
4688 struct lpfc_hba
*phba
= vport
->phba
;
4689 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
4690 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
4691 struct lpfc_sli4_hdw_queue
*hdwq
= NULL
;
4692 struct lpfc_iocbq
*pwqeq
= &lpfc_cmd
->cur_iocbq
;
4693 struct lpfc_nodelist
*pnode
= lpfc_cmd
->ndlp
;
4694 union lpfc_wqe128
*wqe
= &pwqeq
->wqe
;
4695 u16 idx
= lpfc_cmd
->hdwq_no
;
4696 int datadir
= scsi_cmnd
->sc_data_direction
;
4698 hdwq
= &phba
->sli4_hba
.hdwq
[idx
];
4700 /* Initialize 64 bytes only */
4701 memset(wqe
, 0, sizeof(union lpfc_wqe128
));
4704 * There are three possibilities here - use scatter-gather segment, use
4705 * the single mapping, or neither.
4707 if (scsi_sg_count(scsi_cmnd
)) {
4708 if (datadir
== DMA_TO_DEVICE
) {
4709 /* From the iwrite template, initialize words 7 - 11 */
4710 memcpy(&wqe
->words
[7],
4711 &lpfc_iwrite_cmd_template
.words
[7],
4712 sizeof(uint32_t) * 5);
4714 fcp_cmnd
->fcpCntl3
= WRITE_DATA
;
4716 hdwq
->scsi_cstat
.output_requests
++;
4718 /* From the iread template, initialize words 7 - 11 */
4719 memcpy(&wqe
->words
[7],
4720 &lpfc_iread_cmd_template
.words
[7],
4721 sizeof(uint32_t) * 5);
4724 bf_set(wqe_tmo
, &wqe
->fcp_iread
.wqe_com
, tmo
);
4726 fcp_cmnd
->fcpCntl3
= READ_DATA
;
4728 hdwq
->scsi_cstat
.input_requests
++;
4730 /* For a CMF Managed port, iod must be zero'ed */
4731 if (phba
->cmf_active_mode
== LPFC_CFG_MANAGED
)
4732 bf_set(wqe_iod
, &wqe
->fcp_iread
.wqe_com
,
4736 /* Additional fcp cdb length field calculation.
4737 * LPFC_FCP_CDB_LEN_32 - normal 16 byte cdb length,
4738 * then divide by 4 for the word count.
4739 * shift 2 because of the RDDATA/WRDATA.
4741 if (scsi_cmnd
->cmd_len
> LPFC_FCP_CDB_LEN
)
4742 fcp_cmnd
->fcpCntl3
|= 4 << 2;
4744 /* From the icmnd template, initialize words 4 - 11 */
4745 memcpy(&wqe
->words
[4], &lpfc_icmnd_cmd_template
.words
[4],
4746 sizeof(uint32_t) * 8);
4749 bf_set(wqe_tmo
, &wqe
->fcp_icmd
.wqe_com
, tmo
);
4751 fcp_cmnd
->fcpCntl3
= 0;
4753 hdwq
->scsi_cstat
.control_requests
++;
4757 * Finish initializing those WQE fields that are independent
4758 * of the request_buffer
4762 bf_set(payload_offset_len
, &wqe
->fcp_icmd
,
4763 sizeof(struct fcp_cmnd
) + sizeof(struct fcp_rsp
));
4766 bf_set(wqe_ctxt_tag
, &wqe
->generic
.wqe_com
,
4767 phba
->sli4_hba
.rpi_ids
[pnode
->nlp_rpi
]);
4768 bf_set(wqe_xri_tag
, &wqe
->generic
.wqe_com
, pwqeq
->sli4_xritag
);
4771 if (pnode
->nlp_fcp_info
& NLP_FCP_2_DEVICE
)
4772 bf_set(wqe_erp
, &wqe
->generic
.wqe_com
, 1);
4774 bf_set(wqe_class
, &wqe
->generic
.wqe_com
,
4775 (pnode
->nlp_fcp_info
& 0x0f));
4778 wqe
->generic
.wqe_com
.abort_tag
= pwqeq
->iotag
;
4781 bf_set(wqe_reqtag
, &wqe
->generic
.wqe_com
, pwqeq
->iotag
);
4783 pwqeq
->vport
= vport
;
4784 pwqeq
->io_buf
= lpfc_cmd
;
4785 pwqeq
->hba_wqidx
= lpfc_cmd
->hdwq_no
;
4786 pwqeq
->cmd_cmpl
= lpfc_fcp_io_cmd_wqe_cmpl
;
4792 * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit
4793 * @vport: The virtual port for which this call is being executed.
4794 * @lpfc_cmd: The scsi command which needs to send.
4795 * @pnode: Pointer to lpfc_nodelist.
4797 * This routine initializes fcp_cmnd and iocb data structure from scsi command
4798 * to transfer for device with SLI3 interface spec.
4801 lpfc_scsi_prep_cmnd(struct lpfc_vport
*vport
, struct lpfc_io_buf
*lpfc_cmd
,
4802 struct lpfc_nodelist
*pnode
)
4804 struct scsi_cmnd
*scsi_cmnd
= lpfc_cmd
->pCmd
;
4805 struct fcp_cmnd
*fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
4811 lpfc_cmd
->fcp_rsp
->rspSnsLen
= 0;
4812 /* clear task management bits */
4813 lpfc_cmd
->fcp_cmnd
->fcpCntl2
= 0;
4815 int_to_scsilun(lpfc_cmd
->pCmd
->device
->lun
,
4816 &lpfc_cmd
->fcp_cmnd
->fcp_lun
);
4818 ptr
= &((struct fcp_cmnd32
*)fcp_cmnd
)->fcpCdb
[0];
4819 memcpy(ptr
, scsi_cmnd
->cmnd
, scsi_cmnd
->cmd_len
);
4820 if (scsi_cmnd
->cmd_len
< LPFC_FCP_CDB_LEN
) {
4821 ptr
+= scsi_cmnd
->cmd_len
;
4822 memset(ptr
, 0, (LPFC_FCP_CDB_LEN
- scsi_cmnd
->cmd_len
));
4825 fcp_cmnd
->fcpCntl1
= SIMPLE_Q
;
4827 lpfc_scsi_prep_cmnd_buf(vport
, lpfc_cmd
, lpfc_cmd
->timeout
);
4833 * lpfc_scsi_prep_task_mgmt_cmd_s3 - Convert SLI3 scsi TM cmd to FCP info unit
4834 * @vport: The virtual port for which this call is being executed.
4835 * @lpfc_cmd: Pointer to lpfc_io_buf data structure.
4836 * @lun: Logical unit number.
4837 * @task_mgmt_cmd: SCSI task management command.
4839 * This routine creates FCP information unit corresponding to @task_mgmt_cmd
4840 * for device with SLI-3 interface spec.
4847 lpfc_scsi_prep_task_mgmt_cmd_s3(struct lpfc_vport
*vport
,
4848 struct lpfc_io_buf
*lpfc_cmd
,
4849 u64 lun
, u8 task_mgmt_cmd
)
4851 struct lpfc_iocbq
*piocbq
;
4853 struct fcp_cmnd
*fcp_cmnd
;
4854 struct lpfc_rport_data
*rdata
= lpfc_cmd
->rdata
;
4855 struct lpfc_nodelist
*ndlp
= rdata
->pnode
;
4857 if (!ndlp
|| ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
)
4860 piocbq
= &(lpfc_cmd
->cur_iocbq
);
4861 piocbq
->vport
= vport
;
4863 piocb
= &piocbq
->iocb
;
4865 fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
4866 /* Clear out any old data in the FCP command area */
4867 memset(fcp_cmnd
, 0, sizeof(struct fcp_cmnd
));
4868 int_to_scsilun(lun
, &fcp_cmnd
->fcp_lun
);
4869 fcp_cmnd
->fcpCntl2
= task_mgmt_cmd
;
4870 if (!(vport
->phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
))
4871 lpfc_fcpcmd_to_iocb(piocb
->unsli3
.fcp_ext
.icd
, fcp_cmnd
);
4872 piocb
->ulpCommand
= CMD_FCP_ICMND64_CR
;
4873 piocb
->ulpContext
= ndlp
->nlp_rpi
;
4874 piocb
->ulpFCP2Rcvy
= (ndlp
->nlp_fcp_info
& NLP_FCP_2_DEVICE
) ? 1 : 0;
4875 piocb
->ulpClass
= (ndlp
->nlp_fcp_info
& 0x0f);
4877 piocb
->un
.fcpi
.fcpi_parm
= 0;
4879 /* ulpTimeout is only one byte */
4880 if (lpfc_cmd
->timeout
> 0xff) {
4882 * Do not timeout the command at the firmware level.
4883 * The driver will provide the timeout mechanism.
4885 piocb
->ulpTimeout
= 0;
4887 piocb
->ulpTimeout
= lpfc_cmd
->timeout
;
4893 * lpfc_scsi_prep_task_mgmt_cmd_s4 - Convert SLI4 scsi TM cmd to FCP info unit
4894 * @vport: The virtual port for which this call is being executed.
4895 * @lpfc_cmd: Pointer to lpfc_io_buf data structure.
4896 * @lun: Logical unit number.
4897 * @task_mgmt_cmd: SCSI task management command.
4899 * This routine creates FCP information unit corresponding to @task_mgmt_cmd
4900 * for device with SLI-4 interface spec.
4907 lpfc_scsi_prep_task_mgmt_cmd_s4(struct lpfc_vport
*vport
,
4908 struct lpfc_io_buf
*lpfc_cmd
,
4909 u64 lun
, u8 task_mgmt_cmd
)
4911 struct lpfc_iocbq
*pwqeq
= &lpfc_cmd
->cur_iocbq
;
4912 union lpfc_wqe128
*wqe
= &pwqeq
->wqe
;
4913 struct fcp_cmnd
*fcp_cmnd
;
4914 struct lpfc_rport_data
*rdata
= lpfc_cmd
->rdata
;
4915 struct lpfc_nodelist
*ndlp
= rdata
->pnode
;
4917 if (!ndlp
|| ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
)
4920 pwqeq
->vport
= vport
;
4921 /* Initialize 64 bytes only */
4922 memset(wqe
, 0, sizeof(union lpfc_wqe128
));
4924 /* From the icmnd template, initialize words 4 - 11 */
4925 memcpy(&wqe
->words
[4], &lpfc_icmnd_cmd_template
.words
[4],
4926 sizeof(uint32_t) * 8);
4928 fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
4929 /* Clear out any old data in the FCP command area */
4930 memset(fcp_cmnd
, 0, sizeof(struct fcp_cmnd
));
4931 int_to_scsilun(lun
, &fcp_cmnd
->fcp_lun
);
4932 fcp_cmnd
->fcpCntl3
= 0;
4933 fcp_cmnd
->fcpCntl2
= task_mgmt_cmd
;
4935 bf_set(payload_offset_len
, &wqe
->fcp_icmd
,
4936 sizeof(struct fcp_cmnd
) + sizeof(struct fcp_rsp
));
4937 bf_set(cmd_buff_len
, &wqe
->fcp_icmd
, 0);
4938 bf_set(wqe_ctxt_tag
, &wqe
->generic
.wqe_com
, /* ulpContext */
4939 vport
->phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
4940 bf_set(wqe_erp
, &wqe
->fcp_icmd
.wqe_com
,
4941 ((ndlp
->nlp_fcp_info
& NLP_FCP_2_DEVICE
) ? 1 : 0));
4942 bf_set(wqe_class
, &wqe
->fcp_icmd
.wqe_com
,
4943 (ndlp
->nlp_fcp_info
& 0x0f));
4945 /* ulpTimeout is only one byte */
4946 if (lpfc_cmd
->timeout
> 0xff) {
4948 * Do not timeout the command at the firmware level.
4949 * The driver will provide the timeout mechanism.
4951 bf_set(wqe_tmo
, &wqe
->fcp_icmd
.wqe_com
, 0);
4953 bf_set(wqe_tmo
, &wqe
->fcp_icmd
.wqe_com
, lpfc_cmd
->timeout
);
4956 lpfc_prep_embed_io(vport
->phba
, lpfc_cmd
);
4957 bf_set(wqe_xri_tag
, &wqe
->generic
.wqe_com
, pwqeq
->sli4_xritag
);
4958 wqe
->generic
.wqe_com
.abort_tag
= pwqeq
->iotag
;
4959 bf_set(wqe_reqtag
, &wqe
->generic
.wqe_com
, pwqeq
->iotag
);
4961 lpfc_sli4_set_rsp_sgl_last(vport
->phba
, lpfc_cmd
);
4967 * lpfc_scsi_api_table_setup - Set up scsi api function jump table
4968 * @phba: The hba struct for which this call is being executed.
4969 * @dev_grp: The HBA PCI-Device group number.
4971 * This routine sets up the SCSI interface API function jump table in @phba
4973 * Returns: 0 - success, -ENODEV - failure.
4976 lpfc_scsi_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
4979 phba
->lpfc_scsi_unprep_dma_buf
= lpfc_scsi_unprep_dma_buf
;
4982 case LPFC_PCI_DEV_LP
:
4983 phba
->lpfc_scsi_prep_dma_buf
= lpfc_scsi_prep_dma_buf_s3
;
4984 phba
->lpfc_bg_scsi_prep_dma_buf
= lpfc_bg_scsi_prep_dma_buf_s3
;
4985 phba
->lpfc_release_scsi_buf
= lpfc_release_scsi_buf_s3
;
4986 phba
->lpfc_get_scsi_buf
= lpfc_get_scsi_buf_s3
;
4987 phba
->lpfc_scsi_prep_cmnd_buf
= lpfc_scsi_prep_cmnd_buf_s3
;
4988 phba
->lpfc_scsi_prep_task_mgmt_cmd
=
4989 lpfc_scsi_prep_task_mgmt_cmd_s3
;
4991 case LPFC_PCI_DEV_OC
:
4992 phba
->lpfc_scsi_prep_dma_buf
= lpfc_scsi_prep_dma_buf_s4
;
4993 phba
->lpfc_bg_scsi_prep_dma_buf
= lpfc_bg_scsi_prep_dma_buf_s4
;
4994 phba
->lpfc_release_scsi_buf
= lpfc_release_scsi_buf_s4
;
4995 phba
->lpfc_get_scsi_buf
= lpfc_get_scsi_buf_s4
;
4996 phba
->lpfc_scsi_prep_cmnd_buf
= lpfc_scsi_prep_cmnd_buf_s4
;
4997 phba
->lpfc_scsi_prep_task_mgmt_cmd
=
4998 lpfc_scsi_prep_task_mgmt_cmd_s4
;
5001 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5002 "1418 Invalid HBA PCI-device group: 0x%x\n",
5006 phba
->lpfc_rampdown_queue_depth
= lpfc_rampdown_queue_depth
;
5011 * lpfc_tskmgmt_def_cmpl - IOCB completion routine for task management command
5012 * @phba: The Hba for which this call is being executed.
5013 * @cmdiocbq: Pointer to lpfc_iocbq data structure.
5014 * @rspiocbq: Pointer to lpfc_iocbq data structure.
5016 * This routine is IOCB completion routine for device reset and target reset
5017 * routine. This routine release scsi buffer associated with lpfc_cmd.
5020 lpfc_tskmgmt_def_cmpl(struct lpfc_hba
*phba
,
5021 struct lpfc_iocbq
*cmdiocbq
,
5022 struct lpfc_iocbq
*rspiocbq
)
5024 struct lpfc_io_buf
*lpfc_cmd
= cmdiocbq
->io_buf
;
5026 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
5031 * lpfc_check_pci_resettable - Walks list of devices on pci_dev's bus to check
5032 * if issuing a pci_bus_reset is possibly unsafe
5033 * @phba: lpfc_hba pointer.
5036 * Walks the bus_list to ensure only PCI devices with Emulex
5037 * vendor id, device ids that support hot reset, and only one occurrence
5041 * -EBADSLT, detected invalid device
5045 lpfc_check_pci_resettable(struct lpfc_hba
*phba
)
5047 const struct pci_dev
*pdev
= phba
->pcidev
;
5048 struct pci_dev
*ptr
= NULL
;
5051 /* Walk the list of devices on the pci_dev's bus */
5052 list_for_each_entry(ptr
, &pdev
->bus
->devices
, bus_list
) {
5053 /* Check for Emulex Vendor ID */
5054 if (ptr
->vendor
!= PCI_VENDOR_ID_EMULEX
) {
5055 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5056 "8346 Non-Emulex vendor found: "
5057 "0x%04x\n", ptr
->vendor
);
5061 /* Check for valid Emulex Device ID */
5062 if (phba
->sli_rev
!= LPFC_SLI_REV4
||
5063 test_bit(HBA_FCOE_MODE
, &phba
->hba_flag
)) {
5064 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5065 "8347 Incapable PCI reset device: "
5066 "0x%04x\n", ptr
->device
);
5070 /* Check for only one function 0 ID to ensure only one HBA on
5073 if (ptr
->devfn
== 0) {
5074 if (++counter
> 1) {
5075 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5076 "8348 More than one device on "
5077 "secondary bus found\n");
5087 * lpfc_info - Info entry point of scsi_host_template data structure
5088 * @host: The scsi host for which this call is being executed.
5090 * This routine provides module information about hba.
5093 * Pointer to char - Success.
5096 lpfc_info(struct Scsi_Host
*host
)
5098 struct lpfc_vport
*vport
= (struct lpfc_vport
*) host
->hostdata
;
5099 struct lpfc_hba
*phba
= vport
->phba
;
5101 static char lpfcinfobuf
[384];
5102 char tmp
[384] = {0};
5104 memset(lpfcinfobuf
, 0, sizeof(lpfcinfobuf
));
5105 if (phba
&& phba
->pcidev
){
5106 /* Model Description */
5107 scnprintf(tmp
, sizeof(tmp
), phba
->ModelDesc
);
5108 if (strlcat(lpfcinfobuf
, tmp
, sizeof(lpfcinfobuf
)) >=
5109 sizeof(lpfcinfobuf
))
5113 scnprintf(tmp
, sizeof(tmp
),
5114 " on PCI bus %02x device %02x irq %d",
5115 phba
->pcidev
->bus
->number
, phba
->pcidev
->devfn
,
5117 if (strlcat(lpfcinfobuf
, tmp
, sizeof(lpfcinfobuf
)) >=
5118 sizeof(lpfcinfobuf
))
5122 if (phba
->Port
[0]) {
5123 scnprintf(tmp
, sizeof(tmp
), " port %s", phba
->Port
);
5124 if (strlcat(lpfcinfobuf
, tmp
, sizeof(lpfcinfobuf
)) >=
5125 sizeof(lpfcinfobuf
))
5130 link_speed
= lpfc_sli_port_speed_get(phba
);
5131 if (link_speed
!= 0) {
5132 scnprintf(tmp
, sizeof(tmp
),
5133 " Logical Link Speed: %d Mbps", link_speed
);
5134 if (strlcat(lpfcinfobuf
, tmp
, sizeof(lpfcinfobuf
)) >=
5135 sizeof(lpfcinfobuf
))
5139 /* PCI resettable */
5140 if (!lpfc_check_pci_resettable(phba
)) {
5141 scnprintf(tmp
, sizeof(tmp
), " PCI resettable");
5142 strlcat(lpfcinfobuf
, tmp
, sizeof(lpfcinfobuf
));
5151 * lpfc_poll_rearm_timer - Routine to modify fcp_poll timer of hba
5152 * @phba: The Hba for which this call is being executed.
5154 * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo.
5155 * The default value of cfg_poll_tmo is 10 milliseconds.
5157 static __inline__
void lpfc_poll_rearm_timer(struct lpfc_hba
* phba
)
5159 unsigned long poll_tmo_expires
=
5160 (jiffies
+ msecs_to_jiffies(phba
->cfg_poll_tmo
));
5162 if (!list_empty(&phba
->sli
.sli3_ring
[LPFC_FCP_RING
].txcmplq
))
5163 mod_timer(&phba
->fcp_poll_timer
,
5168 * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA
5169 * @phba: The Hba for which this call is being executed.
5171 * This routine starts the fcp_poll_timer of @phba.
5173 void lpfc_poll_start_timer(struct lpfc_hba
* phba
)
5175 lpfc_poll_rearm_timer(phba
);
5179 * lpfc_poll_timeout - Restart polling timer
5180 * @t: Timer construct where lpfc_hba data structure pointer is obtained.
5182 * This routine restarts fcp_poll timer, when FCP ring polling is enable
5183 * and FCP Ring interrupt is disable.
5185 void lpfc_poll_timeout(struct timer_list
*t
)
5187 struct lpfc_hba
*phba
= from_timer(phba
, t
, fcp_poll_timer
);
5189 if (phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) {
5190 lpfc_sli_handle_fast_ring_event(phba
,
5191 &phba
->sli
.sli3_ring
[LPFC_FCP_RING
], HA_R0RE_REQ
);
5193 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
)
5194 lpfc_poll_rearm_timer(phba
);
5199 * lpfc_is_command_vm_io - get the UUID from blk cgroup
5200 * @cmd: Pointer to scsi_cmnd data structure
5201 * Returns UUID if present, otherwise NULL
5203 static char *lpfc_is_command_vm_io(struct scsi_cmnd
*cmd
)
5205 struct bio
*bio
= scsi_cmd_to_rq(cmd
)->bio
;
5207 if (!IS_ENABLED(CONFIG_BLK_CGROUP_FC_APPID
) || !bio
)
5209 return blkcg_get_fc_appid(bio
);
5213 * lpfc_queuecommand - scsi_host_template queuecommand entry point
5214 * @shost: kernel scsi host pointer.
5215 * @cmnd: Pointer to scsi_cmnd data structure.
5217 * Driver registers this routine to scsi midlayer to submit a @cmd to process.
5218 * This routine prepares an IOCB from scsi command and provides to firmware.
5219 * The @done callback is invoked after driver finished processing the command.
5223 * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily.
5226 lpfc_queuecommand(struct Scsi_Host
*shost
, struct scsi_cmnd
*cmnd
)
5228 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
5229 struct lpfc_hba
*phba
= vport
->phba
;
5230 struct lpfc_iocbq
*cur_iocbq
= NULL
;
5231 struct lpfc_rport_data
*rdata
;
5232 struct lpfc_nodelist
*ndlp
;
5233 struct lpfc_io_buf
*lpfc_cmd
;
5234 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmnd
->device
));
5239 start
= ktime_get_ns();
5240 rdata
= lpfc_rport_data_from_scsi_device(cmnd
->device
);
5242 /* sanity check on references */
5243 if (unlikely(!rdata
) || unlikely(!rport
))
5244 goto out_fail_command
;
5246 err
= fc_remote_port_chkready(rport
);
5249 goto out_fail_command
;
5251 ndlp
= rdata
->pnode
;
5253 if ((scsi_get_prot_op(cmnd
) != SCSI_PROT_NORMAL
) &&
5254 (!(phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
))) {
5256 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
5257 "9058 BLKGRD: ERROR: rcvd protected cmd:%02x"
5258 " op:%02x str=%s without registering for"
5259 " BlockGuard - Rejecting command\n",
5260 cmnd
->cmnd
[0], scsi_get_prot_op(cmnd
),
5261 dif_op_str
[scsi_get_prot_op(cmnd
)]);
5262 goto out_fail_command
;
5266 * Catch race where our node has transitioned, but the
5267 * transport is still transitioning.
5272 /* Check if IO qualifies for CMF */
5273 if (phba
->cmf_active_mode
!= LPFC_CFG_OFF
&&
5274 cmnd
->sc_data_direction
== DMA_FROM_DEVICE
&&
5275 (scsi_sg_count(cmnd
))) {
5276 /* Latency start time saved in rx_cmd_start later in routine */
5277 err
= lpfc_update_cmf_cmd(phba
, scsi_bufflen(cmnd
));
5282 if (lpfc_ndlp_check_qdepth(phba
, ndlp
)) {
5283 if (atomic_read(&ndlp
->cmd_pending
) >= ndlp
->cmd_qdepth
) {
5284 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP_ERROR
,
5285 "3377 Target Queue Full, scsi Id:%d "
5286 "Qdepth:%d Pending command:%d"
5287 " WWNN:%02x:%02x:%02x:%02x:"
5288 "%02x:%02x:%02x:%02x, "
5289 " WWPN:%02x:%02x:%02x:%02x:"
5290 "%02x:%02x:%02x:%02x",
5291 ndlp
->nlp_sid
, ndlp
->cmd_qdepth
,
5292 atomic_read(&ndlp
->cmd_pending
),
5293 ndlp
->nlp_nodename
.u
.wwn
[0],
5294 ndlp
->nlp_nodename
.u
.wwn
[1],
5295 ndlp
->nlp_nodename
.u
.wwn
[2],
5296 ndlp
->nlp_nodename
.u
.wwn
[3],
5297 ndlp
->nlp_nodename
.u
.wwn
[4],
5298 ndlp
->nlp_nodename
.u
.wwn
[5],
5299 ndlp
->nlp_nodename
.u
.wwn
[6],
5300 ndlp
->nlp_nodename
.u
.wwn
[7],
5301 ndlp
->nlp_portname
.u
.wwn
[0],
5302 ndlp
->nlp_portname
.u
.wwn
[1],
5303 ndlp
->nlp_portname
.u
.wwn
[2],
5304 ndlp
->nlp_portname
.u
.wwn
[3],
5305 ndlp
->nlp_portname
.u
.wwn
[4],
5306 ndlp
->nlp_portname
.u
.wwn
[5],
5307 ndlp
->nlp_portname
.u
.wwn
[6],
5308 ndlp
->nlp_portname
.u
.wwn
[7]);
5313 lpfc_cmd
= lpfc_get_scsi_buf(phba
, ndlp
, cmnd
);
5314 if (lpfc_cmd
== NULL
) {
5315 lpfc_rampdown_queue_depth(phba
);
5317 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP_ERROR
,
5318 "0707 driver's buffer pool is empty, "
5322 lpfc_cmd
->rx_cmd_start
= start
;
5324 cur_iocbq
= &lpfc_cmd
->cur_iocbq
;
5326 * Store the midlayer's command structure for the completion phase
5327 * and complete the command initialization.
5329 lpfc_cmd
->pCmd
= cmnd
;
5330 lpfc_cmd
->rdata
= rdata
;
5331 lpfc_cmd
->ndlp
= ndlp
;
5332 cur_iocbq
->cmd_cmpl
= NULL
;
5333 cmnd
->host_scribble
= (unsigned char *)lpfc_cmd
;
5335 err
= lpfc_scsi_prep_cmnd(vport
, lpfc_cmd
, ndlp
);
5337 goto out_host_busy_release_buf
;
5339 if (scsi_get_prot_op(cmnd
) != SCSI_PROT_NORMAL
) {
5340 if (vport
->phba
->cfg_enable_bg
) {
5341 lpfc_printf_vlog(vport
,
5342 KERN_INFO
, LOG_SCSI_CMD
,
5343 "9033 BLKGRD: rcvd %s cmd:x%x "
5344 "reftag x%x cnt %u pt %x\n",
5345 dif_op_str
[scsi_get_prot_op(cmnd
)],
5347 scsi_prot_ref_tag(cmnd
),
5348 scsi_logical_block_count(cmnd
),
5349 scsi_get_prot_type(cmnd
));
5351 err
= lpfc_bg_scsi_prep_dma_buf(phba
, lpfc_cmd
);
5353 err
= lpfc_scsi_prep_dma_buf(phba
, lpfc_cmd
);
5356 if (unlikely(err
)) {
5358 cmnd
->result
= DID_ERROR
<< 16;
5359 goto out_fail_command_release_buf
;
5361 goto out_host_busy_free_buf
;
5364 /* check the necessary and sufficient condition to support VMID */
5365 if (lpfc_is_vmid_enabled(phba
) &&
5366 (ndlp
->vmid_support
||
5367 phba
->pport
->vmid_priority_tagging
==
5368 LPFC_VMID_PRIO_TAG_ALL_TARGETS
)) {
5369 /* is the I/O generated by a VM, get the associated virtual */
5371 uuid
= lpfc_is_command_vm_io(cmnd
);
5374 err
= lpfc_vmid_get_appid(vport
, uuid
,
5375 cmnd
->sc_data_direction
,
5376 (union lpfc_vmid_io_tag
*)
5377 &cur_iocbq
->vmid_tag
);
5379 cur_iocbq
->cmd_flag
|= LPFC_IO_VMID
;
5383 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5384 if (unlikely(phba
->hdwqstat_on
& LPFC_CHECK_SCSI_IO
))
5385 this_cpu_inc(phba
->sli4_hba
.c_stat
->xmt_io
);
5387 /* Issue I/O to adapter */
5388 err
= lpfc_sli_issue_fcp_io(phba
, LPFC_FCP_RING
, cur_iocbq
,
5390 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5392 lpfc_cmd
->ts_cmd_start
= start
;
5393 lpfc_cmd
->ts_last_cmd
= phba
->ktime_last_cmd
;
5394 lpfc_cmd
->ts_cmd_wqput
= ktime_get_ns();
5396 lpfc_cmd
->ts_cmd_start
= 0;
5400 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
5401 "3376 FCP could not issue iocb err %x "
5402 "FCP cmd x%x <%d/%llu> "
5403 "sid: x%x did: x%x oxid: x%x "
5404 "Data: x%x x%x x%x x%x\n",
5406 cmnd
->device
? cmnd
->device
->id
: 0xffff,
5407 cmnd
->device
? cmnd
->device
->lun
: (u64
)-1,
5408 vport
->fc_myDID
, ndlp
->nlp_DID
,
5409 phba
->sli_rev
== LPFC_SLI_REV4
?
5410 cur_iocbq
->sli4_xritag
: 0xffff,
5411 phba
->sli_rev
== LPFC_SLI_REV4
?
5412 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
] :
5413 cur_iocbq
->iocb
.ulpContext
,
5415 phba
->sli_rev
== LPFC_SLI_REV4
?
5417 &cur_iocbq
->wqe
.generic
.wqe_com
) :
5418 cur_iocbq
->iocb
.ulpTimeout
,
5419 (uint32_t)(scsi_cmd_to_rq(cmnd
)->timeout
/ 1000));
5421 goto out_host_busy_free_buf
;
5424 if (phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) {
5425 lpfc_sli_handle_fast_ring_event(phba
,
5426 &phba
->sli
.sli3_ring
[LPFC_FCP_RING
], HA_R0RE_REQ
);
5428 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
)
5429 lpfc_poll_rearm_timer(phba
);
5432 if (phba
->cfg_xri_rebalancing
)
5433 lpfc_keep_pvt_pool_above_lowwm(phba
, lpfc_cmd
->hdwq_no
);
5437 out_host_busy_free_buf
:
5438 idx
= lpfc_cmd
->hdwq_no
;
5439 lpfc_scsi_unprep_dma_buf(phba
, lpfc_cmd
);
5440 if (phba
->sli4_hba
.hdwq
) {
5441 switch (lpfc_cmd
->fcp_cmnd
->fcpCntl3
) {
5443 phba
->sli4_hba
.hdwq
[idx
].scsi_cstat
.output_requests
--;
5446 phba
->sli4_hba
.hdwq
[idx
].scsi_cstat
.input_requests
--;
5449 phba
->sli4_hba
.hdwq
[idx
].scsi_cstat
.control_requests
--;
5452 out_host_busy_release_buf
:
5453 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
5455 lpfc_update_cmf_cmpl(phba
, LPFC_CGN_NOT_SENT
, scsi_bufflen(cmnd
),
5457 return SCSI_MLQUEUE_HOST_BUSY
;
5460 lpfc_update_cmf_cmpl(phba
, LPFC_CGN_NOT_SENT
, scsi_bufflen(cmnd
),
5463 return SCSI_MLQUEUE_TARGET_BUSY
;
5465 out_fail_command_release_buf
:
5466 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
5467 lpfc_update_cmf_cmpl(phba
, LPFC_CGN_NOT_SENT
, scsi_bufflen(cmnd
),
5476 * lpfc_vmid_vport_cleanup - cleans up the resources associated with a vport
5477 * @vport: The virtual port for which this call is being executed.
5479 void lpfc_vmid_vport_cleanup(struct lpfc_vport
*vport
)
5482 struct lpfc_vmid
*cur
;
5484 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
5485 del_timer_sync(&vport
->phba
->inactive_vmid_poll
);
5487 kfree(vport
->qfpa_res
);
5488 kfree(vport
->vmid_priority
.vmid_range
);
5491 if (!hash_empty(vport
->hash_table
))
5492 hash_for_each(vport
->hash_table
, bucket
, cur
, hnode
)
5493 hash_del(&cur
->hnode
);
5495 vport
->qfpa_res
= NULL
;
5496 vport
->vmid_priority
.vmid_range
= NULL
;
5498 vport
->cur_vmid_cnt
= 0;
5502 * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point
5503 * @cmnd: Pointer to scsi_cmnd data structure.
5505 * This routine aborts @cmnd pending in base driver.
5512 lpfc_abort_handler(struct scsi_cmnd
*cmnd
)
5514 struct Scsi_Host
*shost
= cmnd
->device
->host
;
5515 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmnd
->device
));
5516 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
5517 struct lpfc_hba
*phba
= vport
->phba
;
5518 struct lpfc_iocbq
*iocb
;
5519 struct lpfc_io_buf
*lpfc_cmd
;
5520 int ret
= SUCCESS
, status
= 0;
5521 struct lpfc_sli_ring
*pring_s4
= NULL
;
5522 struct lpfc_sli_ring
*pring
= NULL
;
5524 unsigned long flags
;
5525 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq
);
5527 status
= fc_block_rport(rport
);
5528 if (status
!= 0 && status
!= SUCCESS
)
5531 lpfc_cmd
= (struct lpfc_io_buf
*)cmnd
->host_scribble
;
5535 /* Guard against IO completion being called at same time */
5536 spin_lock_irqsave(&lpfc_cmd
->buf_lock
, flags
);
5538 spin_lock(&phba
->hbalock
);
5539 /* driver queued commands are in process of being flushed */
5540 if (test_bit(HBA_IOQ_FLUSH
, &phba
->hba_flag
)) {
5541 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
5542 "3168 SCSI Layer abort requested I/O has been "
5543 "flushed by LLD.\n");
5545 goto out_unlock_hba
;
5548 if (!lpfc_cmd
->pCmd
) {
5549 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
5550 "2873 SCSI Layer I/O Abort Request IO CMPL Status "
5551 "x%x ID %d LUN %llu\n",
5552 SUCCESS
, cmnd
->device
->id
, cmnd
->device
->lun
);
5553 goto out_unlock_hba
;
5556 iocb
= &lpfc_cmd
->cur_iocbq
;
5557 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
5558 /* if the io_wq & pring are gone, the port was reset. */
5559 if (!phba
->sli4_hba
.hdwq
[iocb
->hba_wqidx
].io_wq
||
5560 !phba
->sli4_hba
.hdwq
[iocb
->hba_wqidx
].io_wq
->pring
) {
5561 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
5562 "2877 SCSI Layer I/O Abort Request "
5563 "IO CMPL Status x%x ID %d LUN %llu "
5564 "HBA_SETUP %d\n", FAILED
,
5566 (u64
)cmnd
->device
->lun
,
5567 test_bit(HBA_SETUP
, &phba
->hba_flag
));
5569 goto out_unlock_hba
;
5571 pring_s4
= phba
->sli4_hba
.hdwq
[iocb
->hba_wqidx
].io_wq
->pring
;
5572 spin_lock(&pring_s4
->ring_lock
);
5574 /* the command is in process of being cancelled */
5575 if (!(iocb
->cmd_flag
& LPFC_IO_ON_TXCMPLQ
)) {
5576 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
5577 "3169 SCSI Layer abort requested I/O has been "
5578 "cancelled by LLD.\n");
5580 goto out_unlock_ring
;
5583 * If pCmd field of the corresponding lpfc_io_buf structure
5584 * points to a different SCSI command, then the driver has
5585 * already completed this command, but the midlayer did not
5586 * see the completion before the eh fired. Just return SUCCESS.
5588 if (lpfc_cmd
->pCmd
!= cmnd
) {
5589 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
5590 "3170 SCSI Layer abort requested I/O has been "
5591 "completed by LLD.\n");
5592 goto out_unlock_ring
;
5595 WARN_ON(iocb
->io_buf
!= lpfc_cmd
);
5597 /* abort issued in recovery is still in progress */
5598 if (iocb
->cmd_flag
& LPFC_DRIVER_ABORTED
) {
5599 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
5600 "3389 SCSI Layer I/O Abort Request is pending\n");
5601 if (phba
->sli_rev
== LPFC_SLI_REV4
)
5602 spin_unlock(&pring_s4
->ring_lock
);
5603 spin_unlock(&phba
->hbalock
);
5604 spin_unlock_irqrestore(&lpfc_cmd
->buf_lock
, flags
);
5608 lpfc_cmd
->waitq
= &waitq
;
5609 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
5610 spin_unlock(&pring_s4
->ring_lock
);
5611 ret_val
= lpfc_sli4_issue_abort_iotag(phba
, iocb
,
5612 lpfc_sli_abort_fcp_cmpl
);
5614 pring
= &phba
->sli
.sli3_ring
[LPFC_FCP_RING
];
5615 ret_val
= lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
,
5616 lpfc_sli_abort_fcp_cmpl
);
5619 /* Make sure HBA is alive */
5620 lpfc_issue_hb_tmo(phba
);
5622 if (ret_val
!= IOCB_SUCCESS
) {
5623 /* Indicate the IO is not being aborted by the driver. */
5624 lpfc_cmd
->waitq
= NULL
;
5626 goto out_unlock_hba
;
5629 /* no longer need the lock after this point */
5630 spin_unlock(&phba
->hbalock
);
5631 spin_unlock_irqrestore(&lpfc_cmd
->buf_lock
, flags
);
5633 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
)
5634 lpfc_sli_handle_fast_ring_event(phba
,
5635 &phba
->sli
.sli3_ring
[LPFC_FCP_RING
], HA_R0RE_REQ
);
5639 * cmd_flag is set to LPFC_DRIVER_ABORTED before we wait
5640 * for abort to complete.
5642 wait_event_timeout(waitq
,
5643 (lpfc_cmd
->pCmd
!= cmnd
),
5644 msecs_to_jiffies(2*vport
->cfg_devloss_tmo
*1000));
5646 spin_lock(&lpfc_cmd
->buf_lock
);
5648 if (lpfc_cmd
->pCmd
== cmnd
) {
5650 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
5651 "0748 abort handler timed out waiting "
5652 "for aborting I/O (xri:x%x) to complete: "
5653 "ret %#x, ID %d, LUN %llu\n",
5654 iocb
->sli4_xritag
, ret
,
5655 cmnd
->device
->id
, cmnd
->device
->lun
);
5658 lpfc_cmd
->waitq
= NULL
;
5660 spin_unlock(&lpfc_cmd
->buf_lock
);
5664 if (phba
->sli_rev
== LPFC_SLI_REV4
)
5665 spin_unlock(&pring_s4
->ring_lock
);
5667 spin_unlock(&phba
->hbalock
);
5668 spin_unlock_irqrestore(&lpfc_cmd
->buf_lock
, flags
);
5670 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
5671 "0749 SCSI Layer I/O Abort Request Status x%x ID %d "
5672 "LUN %llu\n", ret
, cmnd
->device
->id
,
5678 lpfc_taskmgmt_name(uint8_t task_mgmt_cmd
)
5680 switch (task_mgmt_cmd
) {
5681 case FCP_ABORT_TASK_SET
:
5682 return "ABORT_TASK_SET";
5683 case FCP_CLEAR_TASK_SET
:
5684 return "FCP_CLEAR_TASK_SET";
5686 return "FCP_BUS_RESET";
5688 return "FCP_LUN_RESET";
5689 case FCP_TARGET_RESET
:
5690 return "FCP_TARGET_RESET";
5692 return "FCP_CLEAR_ACA";
5693 case FCP_TERMINATE_TASK
:
5694 return "FCP_TERMINATE_TASK";
5702 * lpfc_check_fcp_rsp - check the returned fcp_rsp to see if task failed
5703 * @vport: The virtual port for which this call is being executed.
5704 * @lpfc_cmd: Pointer to lpfc_io_buf data structure.
5706 * This routine checks the FCP RSP INFO to see if the tsk mgmt command succeded
5713 lpfc_check_fcp_rsp(struct lpfc_vport
*vport
, struct lpfc_io_buf
*lpfc_cmd
)
5715 struct fcp_rsp
*fcprsp
= lpfc_cmd
->fcp_rsp
;
5718 uint8_t rsp_info_code
;
5723 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
5724 "0703 fcp_rsp is missing\n");
5726 rsp_info
= fcprsp
->rspStatus2
;
5727 rsp_len
= be32_to_cpu(fcprsp
->rspRspLen
);
5728 rsp_info_code
= fcprsp
->rspInfo3
;
5731 lpfc_printf_vlog(vport
, KERN_INFO
,
5733 "0706 fcp_rsp valid 0x%x,"
5734 " rsp len=%d code 0x%x\n",
5736 rsp_len
, rsp_info_code
);
5738 /* If FCP_RSP_LEN_VALID bit is one, then the FCP_RSP_LEN
5739 * field specifies the number of valid bytes of FCP_RSP_INFO.
5740 * The FCP_RSP_LEN field shall be set to 0x04 or 0x08
5742 if ((fcprsp
->rspStatus2
& RSP_LEN_VALID
) &&
5743 ((rsp_len
== 8) || (rsp_len
== 4))) {
5744 switch (rsp_info_code
) {
5745 case RSP_NO_FAILURE
:
5746 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
5747 "0715 Task Mgmt No Failure\n");
5750 case RSP_TM_NOT_SUPPORTED
: /* TM rejected */
5751 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
5752 "0716 Task Mgmt Target "
5755 case RSP_TM_NOT_COMPLETED
: /* TM failed */
5756 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
5757 "0717 Task Mgmt Target "
5760 case RSP_TM_INVALID_LU
: /* TM to invalid LU! */
5761 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
5762 "0718 Task Mgmt to invalid "
5773 * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler
5774 * @vport: The virtual port for which this call is being executed.
5775 * @rport: Pointer to remote port
5776 * @tgt_id: Target ID of remote device.
5777 * @lun_id: Lun number for the TMF
5778 * @task_mgmt_cmd: type of TMF to send
5780 * This routine builds and sends a TMF (SCSI Task Mgmt Function) to
5788 lpfc_send_taskmgmt(struct lpfc_vport
*vport
, struct fc_rport
*rport
,
5789 unsigned int tgt_id
, uint64_t lun_id
,
5790 uint8_t task_mgmt_cmd
)
5792 struct lpfc_hba
*phba
= vport
->phba
;
5793 struct lpfc_io_buf
*lpfc_cmd
;
5794 struct lpfc_iocbq
*iocbq
;
5795 struct lpfc_iocbq
*iocbqrsp
;
5796 struct lpfc_rport_data
*rdata
;
5797 struct lpfc_nodelist
*pnode
;
5801 rdata
= rport
->dd_data
;
5802 if (!rdata
|| !rdata
->pnode
)
5804 pnode
= rdata
->pnode
;
5806 lpfc_cmd
= lpfc_get_scsi_buf(phba
, rdata
->pnode
, NULL
);
5807 if (lpfc_cmd
== NULL
)
5809 lpfc_cmd
->timeout
= phba
->cfg_task_mgmt_tmo
;
5810 lpfc_cmd
->rdata
= rdata
;
5811 lpfc_cmd
->pCmd
= NULL
;
5812 lpfc_cmd
->ndlp
= pnode
;
5814 status
= phba
->lpfc_scsi_prep_task_mgmt_cmd(vport
, lpfc_cmd
, lun_id
,
5817 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
5821 iocbq
= &lpfc_cmd
->cur_iocbq
;
5822 iocbqrsp
= lpfc_sli_get_iocbq(phba
);
5823 if (iocbqrsp
== NULL
) {
5824 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
5827 iocbq
->cmd_cmpl
= lpfc_tskmgmt_def_cmpl
;
5828 iocbq
->vport
= vport
;
5830 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
5831 "0702 Issue %s to TGT %d LUN %llu "
5832 "rpi x%x nlp_flag x%lx Data: x%x x%x\n",
5833 lpfc_taskmgmt_name(task_mgmt_cmd
), tgt_id
, lun_id
,
5834 pnode
->nlp_rpi
, pnode
->nlp_flag
, iocbq
->sli4_xritag
,
5837 status
= lpfc_sli_issue_iocb_wait(phba
, LPFC_FCP_RING
,
5838 iocbq
, iocbqrsp
, lpfc_cmd
->timeout
);
5839 if ((status
!= IOCB_SUCCESS
) ||
5840 (get_job_ulpstatus(phba
, iocbqrsp
) != IOSTAT_SUCCESS
)) {
5841 if (status
!= IOCB_SUCCESS
||
5842 get_job_ulpstatus(phba
, iocbqrsp
) != IOSTAT_FCP_RSP_ERROR
)
5843 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
5844 "0727 TMF %s to TGT %d LUN %llu "
5845 "failed (%d, %d) cmd_flag x%x\n",
5846 lpfc_taskmgmt_name(task_mgmt_cmd
),
5848 get_job_ulpstatus(phba
, iocbqrsp
),
5849 get_job_word4(phba
, iocbqrsp
),
5851 /* if ulpStatus != IOCB_SUCCESS, then status == IOCB_SUCCESS */
5852 if (status
== IOCB_SUCCESS
) {
5853 if (get_job_ulpstatus(phba
, iocbqrsp
) ==
5854 IOSTAT_FCP_RSP_ERROR
)
5855 /* Something in the FCP_RSP was invalid.
5856 * Check conditions */
5857 ret
= lpfc_check_fcp_rsp(vport
, lpfc_cmd
);
5860 } else if ((status
== IOCB_TIMEDOUT
) ||
5861 (status
== IOCB_ABORTED
)) {
5862 ret
= TIMEOUT_ERROR
;
5869 lpfc_sli_release_iocbq(phba
, iocbqrsp
);
5871 if (status
!= IOCB_TIMEDOUT
)
5872 lpfc_release_scsi_buf(phba
, lpfc_cmd
);
5878 * lpfc_chk_tgt_mapped -
5879 * @vport: The virtual port to check on
5880 * @rport: Pointer to fc_rport data structure.
5882 * This routine delays until the scsi target (aka rport) for the
5883 * command exists (is present and logged in) or we declare it non-existent.
5890 lpfc_chk_tgt_mapped(struct lpfc_vport
*vport
, struct fc_rport
*rport
)
5892 struct lpfc_rport_data
*rdata
;
5893 struct lpfc_nodelist
*pnode
= NULL
;
5894 unsigned long later
;
5896 rdata
= rport
->dd_data
;
5898 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FCP
,
5899 "0797 Tgt Map rport failure: rdata x%px\n", rdata
);
5902 pnode
= rdata
->pnode
;
5905 * If target is not in a MAPPED state, delay until
5906 * target is rediscovered or devloss timeout expires.
5908 later
= msecs_to_jiffies(2 * vport
->cfg_devloss_tmo
* 1000) + jiffies
;
5909 while (time_after(later
, jiffies
)) {
5912 if (pnode
->nlp_state
== NLP_STE_MAPPED_NODE
)
5914 schedule_timeout_uninterruptible(msecs_to_jiffies(500));
5915 rdata
= rport
->dd_data
;
5918 pnode
= rdata
->pnode
;
5920 if (!pnode
|| (pnode
->nlp_state
!= NLP_STE_MAPPED_NODE
))
5926 * lpfc_reset_flush_io_context -
5927 * @vport: The virtual port (scsi_host) for the flush context
5928 * @tgt_id: If aborting by Target contect - specifies the target id
5929 * @lun_id: If aborting by Lun context - specifies the lun id
5930 * @context: specifies the context level to flush at.
5932 * After a reset condition via TMF, we need to flush orphaned i/o
5933 * contexts from the adapter. This routine aborts any contexts
5934 * outstanding, then waits for their completions. The wait is
5935 * bounded by devloss_tmo though.
5942 lpfc_reset_flush_io_context(struct lpfc_vport
*vport
, uint16_t tgt_id
,
5943 uint64_t lun_id
, lpfc_ctx_cmd context
)
5945 struct lpfc_hba
*phba
= vport
->phba
;
5946 unsigned long later
;
5949 cnt
= lpfc_sli_sum_iocb(vport
, tgt_id
, lun_id
, context
);
5951 lpfc_sli_abort_taskmgmt(vport
,
5952 &phba
->sli
.sli3_ring
[LPFC_FCP_RING
],
5953 tgt_id
, lun_id
, context
);
5954 later
= msecs_to_jiffies(2 * vport
->cfg_devloss_tmo
* 1000) + jiffies
;
5955 while (time_after(later
, jiffies
) && cnt
) {
5956 schedule_timeout_uninterruptible(msecs_to_jiffies(20));
5957 cnt
= lpfc_sli_sum_iocb(vport
, tgt_id
, lun_id
, context
);
5960 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
5961 "0724 I/O flush failure for context %s : cnt x%x\n",
5962 ((context
== LPFC_CTX_LUN
) ? "LUN" :
5963 ((context
== LPFC_CTX_TGT
) ? "TGT" :
5964 ((context
== LPFC_CTX_HOST
) ? "HOST" : "Unknown"))),
5972 * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point
5973 * @cmnd: Pointer to scsi_cmnd data structure.
5975 * This routine does a device reset by sending a LUN_RESET task management
5983 lpfc_device_reset_handler(struct scsi_cmnd
*cmnd
)
5985 struct Scsi_Host
*shost
= cmnd
->device
->host
;
5986 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmnd
->device
));
5987 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
5988 struct lpfc_rport_data
*rdata
;
5989 struct lpfc_nodelist
*pnode
;
5990 unsigned tgt_id
= cmnd
->device
->id
;
5991 uint64_t lun_id
= cmnd
->device
->lun
;
5992 struct lpfc_scsi_event_header scsi_event
;
5994 u32 logit
= LOG_FCP
;
5999 rdata
= rport
->dd_data
;
6000 if (!rdata
|| !rdata
->pnode
) {
6001 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
6002 "0798 Device Reset rdata failure: rdata x%px\n",
6006 pnode
= rdata
->pnode
;
6007 status
= fc_block_rport(rport
);
6008 if (status
!= 0 && status
!= SUCCESS
)
6011 status
= lpfc_chk_tgt_mapped(vport
, rport
);
6012 if (status
== FAILED
) {
6013 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
6014 "0721 Device Reset rport failure: rdata x%px\n", rdata
);
6018 scsi_event
.event_type
= FC_REG_SCSI_EVENT
;
6019 scsi_event
.subcategory
= LPFC_EVENT_LUNRESET
;
6020 scsi_event
.lun
= lun_id
;
6021 memcpy(scsi_event
.wwpn
, &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
6022 memcpy(scsi_event
.wwnn
, &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
6024 fc_host_post_vendor_event(shost
, fc_get_event_number(),
6025 sizeof(scsi_event
), (char *)&scsi_event
, LPFC_NL_VENDOR_ID
);
6027 status
= lpfc_send_taskmgmt(vport
, rport
, tgt_id
, lun_id
,
6029 if (status
!= SUCCESS
)
6030 logit
= LOG_TRACE_EVENT
;
6032 lpfc_printf_vlog(vport
, KERN_ERR
, logit
,
6033 "0713 SCSI layer issued Device Reset (%d, %llu) "
6034 "return x%x\n", tgt_id
, lun_id
, status
);
6037 * We have to clean up i/o as : they may be orphaned by the TMF;
6038 * or if the TMF failed, they may be in an indeterminate state.
6040 * We will report success if all the i/o aborts successfully.
6042 if (status
== SUCCESS
)
6043 status
= lpfc_reset_flush_io_context(vport
, tgt_id
, lun_id
,
6050 * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point
6051 * @cmnd: Pointer to scsi_cmnd data structure.
6053 * This routine does a target reset by sending a TARGET_RESET task management
6061 lpfc_target_reset_handler(struct scsi_cmnd
*cmnd
)
6063 struct Scsi_Host
*shost
= cmnd
->device
->host
;
6064 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmnd
->device
));
6065 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
6066 struct lpfc_rport_data
*rdata
;
6067 struct lpfc_nodelist
*pnode
;
6068 unsigned tgt_id
= cmnd
->device
->id
;
6069 uint64_t lun_id
= cmnd
->device
->lun
;
6070 struct lpfc_scsi_event_header scsi_event
;
6072 u32 logit
= LOG_FCP
;
6073 u32 dev_loss_tmo
= vport
->cfg_devloss_tmo
;
6074 unsigned long flags
;
6075 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq
);
6080 rdata
= rport
->dd_data
;
6081 if (!rdata
|| !rdata
->pnode
) {
6082 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
6083 "0799 Target Reset rdata failure: rdata x%px\n",
6087 pnode
= rdata
->pnode
;
6088 status
= fc_block_rport(rport
);
6089 if (status
!= 0 && status
!= SUCCESS
)
6092 status
= lpfc_chk_tgt_mapped(vport
, rport
);
6093 if (status
== FAILED
) {
6094 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
6095 "0722 Target Reset rport failure: rdata x%px\n", rdata
);
6097 clear_bit(NLP_NPR_ADISC
, &pnode
->nlp_flag
);
6098 spin_lock_irqsave(&pnode
->lock
, flags
);
6099 pnode
->nlp_fcp_info
&= ~NLP_FCP_2_DEVICE
;
6100 spin_unlock_irqrestore(&pnode
->lock
, flags
);
6102 lpfc_reset_flush_io_context(vport
, tgt_id
, lun_id
,
6104 return FAST_IO_FAIL
;
6107 scsi_event
.event_type
= FC_REG_SCSI_EVENT
;
6108 scsi_event
.subcategory
= LPFC_EVENT_TGTRESET
;
6110 memcpy(scsi_event
.wwpn
, &pnode
->nlp_portname
, sizeof(struct lpfc_name
));
6111 memcpy(scsi_event
.wwnn
, &pnode
->nlp_nodename
, sizeof(struct lpfc_name
));
6113 fc_host_post_vendor_event(shost
, fc_get_event_number(),
6114 sizeof(scsi_event
), (char *)&scsi_event
, LPFC_NL_VENDOR_ID
);
6116 status
= lpfc_send_taskmgmt(vport
, rport
, tgt_id
, lun_id
,
6118 if (status
!= SUCCESS
) {
6119 logit
= LOG_TRACE_EVENT
;
6121 /* Issue LOGO, if no LOGO is outstanding */
6122 spin_lock_irqsave(&pnode
->lock
, flags
);
6123 if (!(pnode
->save_flags
& NLP_WAIT_FOR_LOGO
) &&
6124 !pnode
->logo_waitq
) {
6125 pnode
->logo_waitq
= &waitq
;
6126 pnode
->nlp_fcp_info
&= ~NLP_FCP_2_DEVICE
;
6127 set_bit(NLP_ISSUE_LOGO
, &pnode
->nlp_flag
);
6128 pnode
->save_flags
|= NLP_WAIT_FOR_LOGO
;
6129 spin_unlock_irqrestore(&pnode
->lock
, flags
);
6130 lpfc_unreg_rpi(vport
, pnode
);
6131 wait_event_timeout(waitq
,
6132 (!(pnode
->save_flags
&
6133 NLP_WAIT_FOR_LOGO
)),
6134 msecs_to_jiffies(dev_loss_tmo
*
6137 if (pnode
->save_flags
& NLP_WAIT_FOR_LOGO
) {
6138 lpfc_printf_vlog(vport
, KERN_ERR
, logit
,
6139 "0725 SCSI layer TGTRST "
6140 "failed & LOGO TMO (%d, %llu) "
6142 tgt_id
, lun_id
, status
);
6143 spin_lock_irqsave(&pnode
->lock
, flags
);
6144 pnode
->save_flags
&= ~NLP_WAIT_FOR_LOGO
;
6146 spin_lock_irqsave(&pnode
->lock
, flags
);
6148 pnode
->logo_waitq
= NULL
;
6149 spin_unlock_irqrestore(&pnode
->lock
, flags
);
6153 spin_unlock_irqrestore(&pnode
->lock
, flags
);
6158 lpfc_printf_vlog(vport
, KERN_ERR
, logit
,
6159 "0723 SCSI layer issued Target Reset (%d, %llu) "
6160 "return x%x\n", tgt_id
, lun_id
, status
);
6163 * We have to clean up i/o as : they may be orphaned by the TMF;
6164 * or if the TMF failed, they may be in an indeterminate state.
6166 * We will report success if all the i/o aborts successfully.
6168 if (status
== SUCCESS
)
6169 status
= lpfc_reset_flush_io_context(vport
, tgt_id
, lun_id
,
6175 * lpfc_host_reset_handler - scsi_host_template eh_host_reset_handler entry pt
6176 * @cmnd: Pointer to scsi_cmnd data structure.
6178 * This routine does host reset to the adaptor port. It brings the HBA
6179 * offline, performs a board restart, and then brings the board back online.
6180 * The lpfc_offline calls lpfc_sli_hba_down which will abort and local
6181 * reject all outstanding SCSI commands to the host and error returned
6182 * back to SCSI mid-level. As this will be SCSI mid-level's last resort
6183 * of error handling, it will only return error if resetting of the adapter
6184 * is not successful; in all other cases, will return success.
6191 lpfc_host_reset_handler(struct scsi_cmnd
*cmnd
)
6193 struct Scsi_Host
*shost
= cmnd
->device
->host
;
6194 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
6195 struct lpfc_hba
*phba
= vport
->phba
;
6196 int rc
, ret
= SUCCESS
;
6198 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_FCP
,
6199 "3172 SCSI layer issued Host Reset Data:\n");
6201 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
6203 rc
= lpfc_sli_brdrestart(phba
);
6207 /* Wait for successful restart of adapter */
6208 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
6209 rc
= lpfc_sli_chipset_init(phba
);
6214 rc
= lpfc_online(phba
);
6218 lpfc_unblock_mgmt_io(phba
);
6222 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
6223 "3323 Failed host reset\n");
6224 lpfc_unblock_mgmt_io(phba
);
6229 * lpfc_slave_alloc - scsi_host_template slave_alloc entry point
6230 * @sdev: Pointer to scsi_device.
6232 * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's
6233 * globally available list of scsi buffers. This routine also makes sure scsi
6234 * buffer is not allocated more than HBA limit conveyed to midlayer. This list
6235 * of scsi buffer exists for the lifetime of the driver.
6242 lpfc_slave_alloc(struct scsi_device
*sdev
)
6244 struct lpfc_vport
*vport
= (struct lpfc_vport
*) sdev
->host
->hostdata
;
6245 struct lpfc_hba
*phba
= vport
->phba
;
6246 struct fc_rport
*rport
= starget_to_rport(scsi_target(sdev
));
6248 uint32_t num_to_alloc
= 0;
6249 int num_allocated
= 0;
6251 struct lpfc_device_data
*device_data
;
6252 unsigned long flags
;
6253 struct lpfc_name target_wwpn
;
6255 if (!rport
|| fc_remote_port_chkready(rport
))
6258 if (phba
->cfg_fof
) {
6261 * Check to see if the device data structure for the lun
6262 * exists. If not, create one.
6265 u64_to_wwn(rport
->port_name
, target_wwpn
.u
.wwn
);
6266 spin_lock_irqsave(&phba
->devicelock
, flags
);
6267 device_data
= __lpfc_get_device_data(phba
,
6269 &vport
->fc_portname
,
6273 spin_unlock_irqrestore(&phba
->devicelock
, flags
);
6274 device_data
= lpfc_create_device_data(phba
,
6275 &vport
->fc_portname
,
6278 phba
->cfg_XLanePriority
,
6282 spin_lock_irqsave(&phba
->devicelock
, flags
);
6283 list_add_tail(&device_data
->listentry
, &phba
->luns
);
6285 device_data
->rport_data
= rport
->dd_data
;
6286 device_data
->available
= true;
6287 spin_unlock_irqrestore(&phba
->devicelock
, flags
);
6288 sdev
->hostdata
= device_data
;
6290 sdev
->hostdata
= rport
->dd_data
;
6292 sdev_cnt
= atomic_inc_return(&phba
->sdev_cnt
);
6294 /* For SLI4, all IO buffers are pre-allocated */
6295 if (phba
->sli_rev
== LPFC_SLI_REV4
)
6298 /* This code path is now ONLY for SLI3 adapters */
6301 * Populate the cmds_per_lun count scsi_bufs into this host's globally
6302 * available list of scsi buffers. Don't allocate more than the
6303 * HBA limit conveyed to the midlayer via the host structure. The
6304 * formula accounts for the lun_queue_depth + error handlers + 1
6305 * extra. This list of scsi bufs exists for the lifetime of the driver.
6307 total
= phba
->total_scsi_bufs
;
6308 num_to_alloc
= vport
->cfg_lun_queue_depth
+ 2;
6310 /* If allocated buffers are enough do nothing */
6311 if ((sdev_cnt
* (vport
->cfg_lun_queue_depth
+ 2)) < total
)
6314 /* Allow some exchanges to be available always to complete discovery */
6315 if (total
>= phba
->cfg_hba_queue_depth
- LPFC_DISC_IOCB_BUFF_COUNT
) {
6316 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
6317 "0704 At limitation of %d preallocated "
6318 "command buffers\n", total
);
6320 /* Allow some exchanges to be available always to complete discovery */
6321 } else if (total
+ num_to_alloc
>
6322 phba
->cfg_hba_queue_depth
- LPFC_DISC_IOCB_BUFF_COUNT
) {
6323 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_FCP
,
6324 "0705 Allocation request of %d "
6325 "command buffers will exceed max of %d. "
6326 "Reducing allocation request to %d.\n",
6327 num_to_alloc
, phba
->cfg_hba_queue_depth
,
6328 (phba
->cfg_hba_queue_depth
- total
));
6329 num_to_alloc
= phba
->cfg_hba_queue_depth
- total
;
6331 num_allocated
= lpfc_new_scsi_buf_s3(vport
, num_to_alloc
);
6332 if (num_to_alloc
!= num_allocated
) {
6333 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
6334 "0708 Allocation request of %d "
6335 "command buffers did not succeed. "
6336 "Allocated %d buffers.\n",
6337 num_to_alloc
, num_allocated
);
6339 if (num_allocated
> 0)
6340 phba
->total_scsi_bufs
+= num_allocated
;
6345 * lpfc_slave_configure - scsi_host_template slave_configure entry point
6346 * @sdev: Pointer to scsi_device.
6348 * This routine configures following items
6349 * - Tag command queuing support for @sdev if supported.
6350 * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set.
6356 lpfc_slave_configure(struct scsi_device
*sdev
)
6358 struct lpfc_vport
*vport
= (struct lpfc_vport
*) sdev
->host
->hostdata
;
6359 struct lpfc_hba
*phba
= vport
->phba
;
6361 scsi_change_queue_depth(sdev
, vport
->cfg_lun_queue_depth
);
6363 if (phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) {
6364 lpfc_sli_handle_fast_ring_event(phba
,
6365 &phba
->sli
.sli3_ring
[LPFC_FCP_RING
], HA_R0RE_REQ
);
6366 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
)
6367 lpfc_poll_rearm_timer(phba
);
6374 * lpfc_slave_destroy - slave_destroy entry point of SHT data structure
6375 * @sdev: Pointer to scsi_device.
6377 * This routine sets @sdev hostatdata filed to null.
6380 lpfc_slave_destroy(struct scsi_device
*sdev
)
6382 struct lpfc_vport
*vport
= (struct lpfc_vport
*) sdev
->host
->hostdata
;
6383 struct lpfc_hba
*phba
= vport
->phba
;
6384 unsigned long flags
;
6385 struct lpfc_device_data
*device_data
= sdev
->hostdata
;
6387 atomic_dec(&phba
->sdev_cnt
);
6388 if ((phba
->cfg_fof
) && (device_data
)) {
6389 spin_lock_irqsave(&phba
->devicelock
, flags
);
6390 device_data
->available
= false;
6391 if (!device_data
->oas_enabled
)
6392 lpfc_delete_device_data(phba
, device_data
);
6393 spin_unlock_irqrestore(&phba
->devicelock
, flags
);
6395 sdev
->hostdata
= NULL
;
6400 * lpfc_create_device_data - creates and initializes device data structure for OAS
6401 * @phba: Pointer to host bus adapter structure.
6402 * @vport_wwpn: Pointer to vport's wwpn information
6403 * @target_wwpn: Pointer to target's wwpn information
6404 * @lun: Lun on target
6406 * @atomic_create: Flag to indicate if memory should be allocated using the
6407 * GFP_ATOMIC flag or not.
6409 * This routine creates a device data structure which will contain identifying
6410 * information for the device (host wwpn, target wwpn, lun), state of OAS,
6411 * whether or not the corresponding lun is available by the system,
6412 * and pointer to the rport data.
6416 * Pointer to lpfc_device_data - Success
6418 struct lpfc_device_data
*
6419 lpfc_create_device_data(struct lpfc_hba
*phba
, struct lpfc_name
*vport_wwpn
,
6420 struct lpfc_name
*target_wwpn
, uint64_t lun
,
6421 uint32_t pri
, bool atomic_create
)
6424 struct lpfc_device_data
*lun_info
;
6427 if (unlikely(!phba
) || !vport_wwpn
|| !target_wwpn
||
6431 /* Attempt to create the device data to contain lun info */
6434 memory_flags
= GFP_ATOMIC
;
6436 memory_flags
= GFP_KERNEL
;
6437 lun_info
= mempool_alloc(phba
->device_data_mem_pool
, memory_flags
);
6440 INIT_LIST_HEAD(&lun_info
->listentry
);
6441 lun_info
->rport_data
= NULL
;
6442 memcpy(&lun_info
->device_id
.vport_wwpn
, vport_wwpn
,
6443 sizeof(struct lpfc_name
));
6444 memcpy(&lun_info
->device_id
.target_wwpn
, target_wwpn
,
6445 sizeof(struct lpfc_name
));
6446 lun_info
->device_id
.lun
= lun
;
6447 lun_info
->oas_enabled
= false;
6448 lun_info
->priority
= pri
;
6449 lun_info
->available
= false;
6454 * lpfc_delete_device_data - frees a device data structure for OAS
6455 * @phba: Pointer to host bus adapter structure.
6456 * @lun_info: Pointer to device data structure to free.
6458 * This routine frees the previously allocated device data structure passed.
6462 lpfc_delete_device_data(struct lpfc_hba
*phba
,
6463 struct lpfc_device_data
*lun_info
)
6466 if (unlikely(!phba
) || !lun_info
||
6470 if (!list_empty(&lun_info
->listentry
))
6471 list_del(&lun_info
->listentry
);
6472 mempool_free(lun_info
, phba
->device_data_mem_pool
);
6477 * __lpfc_get_device_data - returns the device data for the specified lun
6478 * @phba: Pointer to host bus adapter structure.
6479 * @list: Point to list to search.
6480 * @vport_wwpn: Pointer to vport's wwpn information
6481 * @target_wwpn: Pointer to target's wwpn information
6482 * @lun: Lun on target
6484 * This routine searches the list passed for the specified lun's device data.
6485 * This function does not hold locks, it is the responsibility of the caller
6486 * to ensure the proper lock is held before calling the function.
6490 * Pointer to lpfc_device_data - Success
6492 struct lpfc_device_data
*
6493 __lpfc_get_device_data(struct lpfc_hba
*phba
, struct list_head
*list
,
6494 struct lpfc_name
*vport_wwpn
,
6495 struct lpfc_name
*target_wwpn
, uint64_t lun
)
6498 struct lpfc_device_data
*lun_info
;
6500 if (unlikely(!phba
) || !list
|| !vport_wwpn
|| !target_wwpn
||
6504 /* Check to see if the lun is already enabled for OAS. */
6506 list_for_each_entry(lun_info
, list
, listentry
) {
6507 if ((memcmp(&lun_info
->device_id
.vport_wwpn
, vport_wwpn
,
6508 sizeof(struct lpfc_name
)) == 0) &&
6509 (memcmp(&lun_info
->device_id
.target_wwpn
, target_wwpn
,
6510 sizeof(struct lpfc_name
)) == 0) &&
6511 (lun_info
->device_id
.lun
== lun
))
6519 * lpfc_find_next_oas_lun - searches for the next oas lun
6520 * @phba: Pointer to host bus adapter structure.
6521 * @vport_wwpn: Pointer to vport's wwpn information
6522 * @target_wwpn: Pointer to target's wwpn information
6523 * @starting_lun: Pointer to the lun to start searching for
6524 * @found_vport_wwpn: Pointer to the found lun's vport wwpn information
6525 * @found_target_wwpn: Pointer to the found lun's target wwpn information
6526 * @found_lun: Pointer to the found lun.
6527 * @found_lun_status: Pointer to status of the found lun.
6528 * @found_lun_pri: Pointer to priority of the found lun.
6530 * This routine searches the luns list for the specified lun
6531 * or the first lun for the vport/target. If the vport wwpn contains
6532 * a zero value then a specific vport is not specified. In this case
6533 * any vport which contains the lun will be considered a match. If the
6534 * target wwpn contains a zero value then a specific target is not specified.
6535 * In this case any target which contains the lun will be considered a
6536 * match. If the lun is found, the lun, vport wwpn, target wwpn and lun status
6537 * are returned. The function will also return the next lun if available.
6538 * If the next lun is not found, starting_lun parameter will be set to
6546 lpfc_find_next_oas_lun(struct lpfc_hba
*phba
, struct lpfc_name
*vport_wwpn
,
6547 struct lpfc_name
*target_wwpn
, uint64_t *starting_lun
,
6548 struct lpfc_name
*found_vport_wwpn
,
6549 struct lpfc_name
*found_target_wwpn
,
6550 uint64_t *found_lun
,
6551 uint32_t *found_lun_status
,
6552 uint32_t *found_lun_pri
)
6555 unsigned long flags
;
6556 struct lpfc_device_data
*lun_info
;
6557 struct lpfc_device_id
*device_id
;
6561 if (unlikely(!phba
) || !vport_wwpn
|| !target_wwpn
||
6562 !starting_lun
|| !found_vport_wwpn
||
6563 !found_target_wwpn
|| !found_lun
|| !found_lun_status
||
6564 (*starting_lun
== NO_MORE_OAS_LUN
) ||
6568 lun
= *starting_lun
;
6569 *found_lun
= NO_MORE_OAS_LUN
;
6570 *starting_lun
= NO_MORE_OAS_LUN
;
6572 /* Search for lun or the lun closet in value */
6574 spin_lock_irqsave(&phba
->devicelock
, flags
);
6575 list_for_each_entry(lun_info
, &phba
->luns
, listentry
) {
6576 if (((wwn_to_u64(vport_wwpn
->u
.wwn
) == 0) ||
6577 (memcmp(&lun_info
->device_id
.vport_wwpn
, vport_wwpn
,
6578 sizeof(struct lpfc_name
)) == 0)) &&
6579 ((wwn_to_u64(target_wwpn
->u
.wwn
) == 0) ||
6580 (memcmp(&lun_info
->device_id
.target_wwpn
, target_wwpn
,
6581 sizeof(struct lpfc_name
)) == 0)) &&
6582 (lun_info
->oas_enabled
)) {
6583 device_id
= &lun_info
->device_id
;
6585 ((lun
== FIND_FIRST_OAS_LUN
) ||
6586 (device_id
->lun
== lun
))) {
6587 *found_lun
= device_id
->lun
;
6588 memcpy(found_vport_wwpn
,
6589 &device_id
->vport_wwpn
,
6590 sizeof(struct lpfc_name
));
6591 memcpy(found_target_wwpn
,
6592 &device_id
->target_wwpn
,
6593 sizeof(struct lpfc_name
));
6594 if (lun_info
->available
)
6596 OAS_LUN_STATUS_EXISTS
;
6598 *found_lun_status
= 0;
6599 *found_lun_pri
= lun_info
->priority
;
6600 if (phba
->cfg_oas_flags
& OAS_FIND_ANY_VPORT
)
6601 memset(vport_wwpn
, 0x0,
6602 sizeof(struct lpfc_name
));
6603 if (phba
->cfg_oas_flags
& OAS_FIND_ANY_TARGET
)
6604 memset(target_wwpn
, 0x0,
6605 sizeof(struct lpfc_name
));
6608 *starting_lun
= device_id
->lun
;
6609 memcpy(vport_wwpn
, &device_id
->vport_wwpn
,
6610 sizeof(struct lpfc_name
));
6611 memcpy(target_wwpn
, &device_id
->target_wwpn
,
6612 sizeof(struct lpfc_name
));
6617 spin_unlock_irqrestore(&phba
->devicelock
, flags
);
6622 * lpfc_enable_oas_lun - enables a lun for OAS operations
6623 * @phba: Pointer to host bus adapter structure.
6624 * @vport_wwpn: Pointer to vport's wwpn information
6625 * @target_wwpn: Pointer to target's wwpn information
6629 * This routine enables a lun for oas operations. The routines does so by
6630 * doing the following :
6632 * 1) Checks to see if the device data for the lun has been created.
6633 * 2) If found, sets the OAS enabled flag if not set and returns.
6634 * 3) Otherwise, creates a device data structure.
6635 * 4) If successfully created, indicates the device data is for an OAS lun,
6636 * indicates the lun is not available and add to the list of luns.
6643 lpfc_enable_oas_lun(struct lpfc_hba
*phba
, struct lpfc_name
*vport_wwpn
,
6644 struct lpfc_name
*target_wwpn
, uint64_t lun
, uint8_t pri
)
6647 struct lpfc_device_data
*lun_info
;
6648 unsigned long flags
;
6650 if (unlikely(!phba
) || !vport_wwpn
|| !target_wwpn
||
6654 spin_lock_irqsave(&phba
->devicelock
, flags
);
6656 /* Check to see if the device data for the lun has been created */
6657 lun_info
= __lpfc_get_device_data(phba
, &phba
->luns
, vport_wwpn
,
6660 if (!lun_info
->oas_enabled
)
6661 lun_info
->oas_enabled
= true;
6662 lun_info
->priority
= pri
;
6663 spin_unlock_irqrestore(&phba
->devicelock
, flags
);
6667 /* Create an lun info structure and add to list of luns */
6668 lun_info
= lpfc_create_device_data(phba
, vport_wwpn
, target_wwpn
, lun
,
6671 lun_info
->oas_enabled
= true;
6672 lun_info
->priority
= pri
;
6673 lun_info
->available
= false;
6674 list_add_tail(&lun_info
->listentry
, &phba
->luns
);
6675 spin_unlock_irqrestore(&phba
->devicelock
, flags
);
6678 spin_unlock_irqrestore(&phba
->devicelock
, flags
);
6683 * lpfc_disable_oas_lun - disables a lun for OAS operations
6684 * @phba: Pointer to host bus adapter structure.
6685 * @vport_wwpn: Pointer to vport's wwpn information
6686 * @target_wwpn: Pointer to target's wwpn information
6690 * This routine disables a lun for oas operations. The routines does so by
6691 * doing the following :
6693 * 1) Checks to see if the device data for the lun is created.
6694 * 2) If present, clears the flag indicating this lun is for OAS.
6695 * 3) If the lun is not available by the system, the device data is
6703 lpfc_disable_oas_lun(struct lpfc_hba
*phba
, struct lpfc_name
*vport_wwpn
,
6704 struct lpfc_name
*target_wwpn
, uint64_t lun
, uint8_t pri
)
6707 struct lpfc_device_data
*lun_info
;
6708 unsigned long flags
;
6710 if (unlikely(!phba
) || !vport_wwpn
|| !target_wwpn
||
6714 spin_lock_irqsave(&phba
->devicelock
, flags
);
6716 /* Check to see if the lun is available. */
6717 lun_info
= __lpfc_get_device_data(phba
,
6718 &phba
->luns
, vport_wwpn
,
6721 lun_info
->oas_enabled
= false;
6722 lun_info
->priority
= pri
;
6723 if (!lun_info
->available
)
6724 lpfc_delete_device_data(phba
, lun_info
);
6725 spin_unlock_irqrestore(&phba
->devicelock
, flags
);
6729 spin_unlock_irqrestore(&phba
->devicelock
, flags
);
6734 lpfc_no_command(struct Scsi_Host
*shost
, struct scsi_cmnd
*cmnd
)
6736 return SCSI_MLQUEUE_HOST_BUSY
;
6740 lpfc_no_slave(struct scsi_device
*sdev
)
6745 struct scsi_host_template lpfc_template_nvme
= {
6746 .module
= THIS_MODULE
,
6747 .name
= LPFC_DRIVER_NAME
,
6748 .proc_name
= LPFC_DRIVER_NAME
,
6750 .queuecommand
= lpfc_no_command
,
6751 .slave_alloc
= lpfc_no_slave
,
6752 .slave_configure
= lpfc_no_slave
,
6753 .scan_finished
= lpfc_scan_finished
,
6757 .shost_groups
= lpfc_hba_groups
,
6758 .max_sectors
= 0xFFFFFFFF,
6759 .vendor_id
= LPFC_NL_VENDOR_ID
,
6760 .track_queue_depth
= 0,
6763 struct scsi_host_template lpfc_template
= {
6764 .module
= THIS_MODULE
,
6765 .name
= LPFC_DRIVER_NAME
,
6766 .proc_name
= LPFC_DRIVER_NAME
,
6768 .queuecommand
= lpfc_queuecommand
,
6769 .eh_timed_out
= fc_eh_timed_out
,
6770 .eh_should_retry_cmd
= fc_eh_should_retry_cmd
,
6771 .eh_abort_handler
= lpfc_abort_handler
,
6772 .eh_device_reset_handler
= lpfc_device_reset_handler
,
6773 .eh_target_reset_handler
= lpfc_target_reset_handler
,
6774 .eh_host_reset_handler
= lpfc_host_reset_handler
,
6775 .slave_alloc
= lpfc_slave_alloc
,
6776 .slave_configure
= lpfc_slave_configure
,
6777 .slave_destroy
= lpfc_slave_destroy
,
6778 .scan_finished
= lpfc_scan_finished
,
6780 .sg_tablesize
= LPFC_DEFAULT_SG_SEG_CNT
,
6781 .cmd_per_lun
= LPFC_CMD_PER_LUN
,
6782 .shost_groups
= lpfc_hba_groups
,
6783 .max_sectors
= 0xFFFFFFFF,
6784 .vendor_id
= LPFC_NL_VENDOR_ID
,
6785 .change_queue_depth
= scsi_change_queue_depth
,
6786 .track_queue_depth
= 1,
6789 struct scsi_host_template lpfc_vport_template
= {
6790 .module
= THIS_MODULE
,
6791 .name
= LPFC_DRIVER_NAME
,
6792 .proc_name
= LPFC_DRIVER_NAME
,
6794 .queuecommand
= lpfc_queuecommand
,
6795 .eh_timed_out
= fc_eh_timed_out
,
6796 .eh_should_retry_cmd
= fc_eh_should_retry_cmd
,
6797 .eh_abort_handler
= lpfc_abort_handler
,
6798 .eh_device_reset_handler
= lpfc_device_reset_handler
,
6799 .eh_target_reset_handler
= lpfc_target_reset_handler
,
6800 .eh_bus_reset_handler
= NULL
,
6801 .eh_host_reset_handler
= NULL
,
6802 .slave_alloc
= lpfc_slave_alloc
,
6803 .slave_configure
= lpfc_slave_configure
,
6804 .slave_destroy
= lpfc_slave_destroy
,
6805 .scan_finished
= lpfc_scan_finished
,
6807 .sg_tablesize
= LPFC_DEFAULT_SG_SEG_CNT
,
6808 .cmd_per_lun
= LPFC_CMD_PER_LUN
,
6809 .shost_groups
= lpfc_vport_groups
,
6810 .max_sectors
= 0xFFFFFFFF,
6812 .change_queue_depth
= scsi_change_queue_depth
,
6813 .track_queue_depth
= 1,