1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2021 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
23 #include <linux/pci.h>
24 #include <linux/slab.h>
25 #include <linux/interrupt.h>
26 #include <linux/export.h>
27 #include <linux/delay.h>
28 #include <asm/unaligned.h>
29 #include <linux/t10-pi.h>
30 #include <linux/crc-t10dif.h>
31 #include <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);
91 lpfc_put_vmid_in_hashtable(struct lpfc_vport *vport, u32 hash,
92 struct lpfc_vmid *vmp);
93 static void lpfc_vmid_update_entry(struct lpfc_vport *vport, struct scsi_cmnd
94 *cmd, struct lpfc_vmid *vmp,
95 union lpfc_vmid_io_tag *tag);
96 static void lpfc_vmid_assign_cs_ctl(struct lpfc_vport *vport,
97 struct lpfc_vmid *vmid);
100 * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge.
101 * @phba: Pointer to HBA object.
102 * @lpfc_cmd: lpfc scsi command object pointer.
104 * This function is called from the lpfc_prep_task_mgmt_cmd function to
105 * set the last bit in the response sge entry.
108 lpfc_sli4_set_rsp_sgl_last(struct lpfc_hba *phba,
109 struct lpfc_io_buf *lpfc_cmd)
111 struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
114 sgl->word2 = le32_to_cpu(sgl->word2);
115 bf_set(lpfc_sli4_sge_last, sgl, 1);
116 sgl->word2 = cpu_to_le32(sgl->word2);
120 #define LPFC_INVALID_REFTAG ((u32)-1)
123 * lpfc_update_stats - Update statistical data for the command completion
124 * @vport: The virtual port on which this call is executing.
125 * @lpfc_cmd: lpfc scsi command object pointer.
127 * This function is called when there is a command completion and this
128 * function updates the statistical data for the command completion.
131 lpfc_update_stats(struct lpfc_vport *vport, struct lpfc_io_buf *lpfc_cmd)
133 struct lpfc_hba *phba = vport->phba;
134 struct lpfc_rport_data *rdata;
135 struct lpfc_nodelist *pnode;
136 struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
138 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
139 unsigned long latency;
142 if (!vport->stat_data_enabled ||
143 vport->stat_data_blocked ||
147 latency = jiffies_to_msecs((long)jiffies - (long)lpfc_cmd->start_time);
148 rdata = lpfc_cmd->rdata;
149 pnode = rdata->pnode;
151 spin_lock_irqsave(shost->host_lock, flags);
154 (phba->bucket_type == LPFC_NO_BUCKET)) {
155 spin_unlock_irqrestore(shost->host_lock, flags);
159 if (phba->bucket_type == LPFC_LINEAR_BUCKET) {
160 i = (latency + phba->bucket_step - 1 - phba->bucket_base)/
162 /* check array subscript bounds */
165 else if (i >= LPFC_MAX_BUCKET_COUNT)
166 i = LPFC_MAX_BUCKET_COUNT - 1;
168 for (i = 0; i < LPFC_MAX_BUCKET_COUNT-1; i++)
169 if (latency <= (phba->bucket_base +
170 ((1<<i)*phba->bucket_step)))
174 pnode->lat_data[i].cmd_count++;
175 spin_unlock_irqrestore(shost->host_lock, flags);
179 * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread
180 * @phba: The Hba for which this call is being executed.
182 * This routine is called when there is resource error in driver or firmware.
183 * This routine posts WORKER_RAMP_DOWN_QUEUE event for @phba. This routine
184 * posts at most 1 event each second. This routine wakes up worker thread of
185 * @phba to process WORKER_RAM_DOWN_EVENT event.
187 * This routine should be called with no lock held.
190 lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
194 unsigned long expires;
196 spin_lock_irqsave(&phba->hbalock, flags);
197 atomic_inc(&phba->num_rsrc_err);
198 phba->last_rsrc_error_time = jiffies;
200 expires = phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL;
201 if (time_after(expires, jiffies)) {
202 spin_unlock_irqrestore(&phba->hbalock, flags);
206 phba->last_ramp_down_time = jiffies;
208 spin_unlock_irqrestore(&phba->hbalock, flags);
210 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
211 evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE;
213 phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE;
214 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
217 lpfc_worker_wake_up(phba);
222 * lpfc_ramp_down_queue_handler - WORKER_RAMP_DOWN_QUEUE event handler
223 * @phba: The Hba for which this call is being executed.
225 * This routine is called to process WORKER_RAMP_DOWN_QUEUE event for worker
226 * thread.This routine reduces queue depth for all scsi device on each vport
227 * associated with @phba.
230 lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
232 struct lpfc_vport **vports;
233 struct Scsi_Host *shost;
234 struct scsi_device *sdev;
235 unsigned long new_queue_depth;
236 unsigned long num_rsrc_err, num_cmd_success;
239 num_rsrc_err = atomic_read(&phba->num_rsrc_err);
240 num_cmd_success = atomic_read(&phba->num_cmd_success);
243 * The error and success command counters are global per
244 * driver instance. If another handler has already
245 * operated on this error event, just exit.
247 if (num_rsrc_err == 0)
250 vports = lpfc_create_vport_work_array(phba);
252 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
253 shost = lpfc_shost_from_vport(vports[i]);
254 shost_for_each_device(sdev, shost) {
256 sdev->queue_depth * num_rsrc_err /
257 (num_rsrc_err + num_cmd_success);
258 if (!new_queue_depth)
259 new_queue_depth = sdev->queue_depth - 1;
261 new_queue_depth = sdev->queue_depth -
263 scsi_change_queue_depth(sdev, new_queue_depth);
266 lpfc_destroy_vport_work_array(phba, vports);
267 atomic_set(&phba->num_rsrc_err, 0);
268 atomic_set(&phba->num_cmd_success, 0);
272 * lpfc_scsi_dev_block - set all scsi hosts to block state
273 * @phba: Pointer to HBA context object.
275 * This function walks vport list and set each SCSI host to block state
276 * by invoking fc_remote_port_delete() routine. This function is invoked
277 * with EEH when device's PCI slot has been permanently disabled.
280 lpfc_scsi_dev_block(struct lpfc_hba *phba)
282 struct lpfc_vport **vports;
283 struct Scsi_Host *shost;
284 struct scsi_device *sdev;
285 struct fc_rport *rport;
288 vports = lpfc_create_vport_work_array(phba);
290 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
291 shost = lpfc_shost_from_vport(vports[i]);
292 shost_for_each_device(sdev, shost) {
293 rport = starget_to_rport(scsi_target(sdev));
294 fc_remote_port_delete(rport);
297 lpfc_destroy_vport_work_array(phba, vports);
301 * lpfc_new_scsi_buf_s3 - Scsi buffer allocator for HBA with SLI3 IF spec
302 * @vport: The virtual port for which this call being executed.
303 * @num_to_alloc: The requested number of buffers to allocate.
305 * This routine allocates a scsi buffer for device with SLI-3 interface spec,
306 * the scsi buffer contains all the necessary information needed to initiate
307 * a SCSI I/O. The non-DMAable buffer region contains information to build
308 * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP,
309 * and the initial BPL. In addition to allocating memory, the FCP CMND and
310 * FCP RSP BDEs are setup in the BPL and the BPL BDE is setup in the IOCB.
313 * int - number of scsi buffers that were allocated.
314 * 0 = failure, less than num_to_alloc is a partial failure.
317 lpfc_new_scsi_buf_s3(struct lpfc_vport *vport, int num_to_alloc)
319 struct lpfc_hba *phba = vport->phba;
320 struct lpfc_io_buf *psb;
321 struct ulp_bde64 *bpl;
323 dma_addr_t pdma_phys_fcp_cmd;
324 dma_addr_t pdma_phys_fcp_rsp;
325 dma_addr_t pdma_phys_sgl;
329 bpl_size = phba->cfg_sg_dma_buf_size -
330 (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp));
332 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
333 "9067 ALLOC %d scsi_bufs: %d (%d + %d + %d)\n",
334 num_to_alloc, phba->cfg_sg_dma_buf_size,
335 (int)sizeof(struct fcp_cmnd),
336 (int)sizeof(struct fcp_rsp), bpl_size);
338 for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
339 psb = kzalloc(sizeof(struct lpfc_io_buf), GFP_KERNEL);
344 * Get memory from the pci pool to map the virt space to pci
345 * bus space for an I/O. The DMA buffer includes space for the
346 * struct fcp_cmnd, struct fcp_rsp and the number of bde's
347 * necessary to support the sg_tablesize.
349 psb->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool,
350 GFP_KERNEL, &psb->dma_handle);
357 /* Allocate iotag for psb->cur_iocbq. */
358 iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq);
360 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
361 psb->data, psb->dma_handle);
365 psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP;
367 psb->fcp_cmnd = psb->data;
368 psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd);
369 psb->dma_sgl = psb->data + sizeof(struct fcp_cmnd) +
370 sizeof(struct fcp_rsp);
372 /* Initialize local short-hand pointers. */
373 bpl = (struct ulp_bde64 *)psb->dma_sgl;
374 pdma_phys_fcp_cmd = psb->dma_handle;
375 pdma_phys_fcp_rsp = psb->dma_handle + sizeof(struct fcp_cmnd);
376 pdma_phys_sgl = psb->dma_handle + sizeof(struct fcp_cmnd) +
377 sizeof(struct fcp_rsp);
380 * The first two bdes are the FCP_CMD and FCP_RSP. The balance
381 * are sg list bdes. Initialize the first two and leave the
382 * rest for queuecommand.
384 bpl[0].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd));
385 bpl[0].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd));
386 bpl[0].tus.f.bdeSize = sizeof(struct fcp_cmnd);
387 bpl[0].tus.f.bdeFlags = BUFF_TYPE_BDE_64;
388 bpl[0].tus.w = le32_to_cpu(bpl[0].tus.w);
390 /* Setup the physical region for the FCP RSP */
391 bpl[1].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp));
392 bpl[1].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp));
393 bpl[1].tus.f.bdeSize = sizeof(struct fcp_rsp);
394 bpl[1].tus.f.bdeFlags = BUFF_TYPE_BDE_64;
395 bpl[1].tus.w = le32_to_cpu(bpl[1].tus.w);
398 * Since the IOCB for the FCP I/O is built into this
399 * lpfc_scsi_buf, initialize it with all known data now.
401 iocb = &psb->cur_iocbq.iocb;
402 iocb->un.fcpi64.bdl.ulpIoTag32 = 0;
403 if ((phba->sli_rev == 3) &&
404 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) {
405 /* fill in immediate fcp command BDE */
406 iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_IMMED;
407 iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd);
408 iocb->un.fcpi64.bdl.addrLow = offsetof(IOCB_t,
410 iocb->un.fcpi64.bdl.addrHigh = 0;
411 iocb->ulpBdeCount = 0;
413 /* fill in response BDE */
414 iocb->unsli3.fcp_ext.rbde.tus.f.bdeFlags =
416 iocb->unsli3.fcp_ext.rbde.tus.f.bdeSize =
417 sizeof(struct fcp_rsp);
418 iocb->unsli3.fcp_ext.rbde.addrLow =
419 putPaddrLow(pdma_phys_fcp_rsp);
420 iocb->unsli3.fcp_ext.rbde.addrHigh =
421 putPaddrHigh(pdma_phys_fcp_rsp);
423 iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
424 iocb->un.fcpi64.bdl.bdeSize =
425 (2 * sizeof(struct ulp_bde64));
426 iocb->un.fcpi64.bdl.addrLow =
427 putPaddrLow(pdma_phys_sgl);
428 iocb->un.fcpi64.bdl.addrHigh =
429 putPaddrHigh(pdma_phys_sgl);
430 iocb->ulpBdeCount = 1;
433 iocb->ulpClass = CLASS3;
434 psb->status = IOSTAT_SUCCESS;
435 /* Put it back into the SCSI buffer list */
436 psb->cur_iocbq.context1 = psb;
437 spin_lock_init(&psb->buf_lock);
438 lpfc_release_scsi_buf_s3(phba, psb);
446 * lpfc_sli4_vport_delete_fcp_xri_aborted -Remove all ndlp references for vport
447 * @vport: pointer to lpfc vport data structure.
449 * This routine is invoked by the vport cleanup for deletions and the cleanup
450 * for an ndlp on removal.
453 lpfc_sli4_vport_delete_fcp_xri_aborted(struct lpfc_vport *vport)
455 struct lpfc_hba *phba = vport->phba;
456 struct lpfc_io_buf *psb, *next_psb;
457 struct lpfc_sli4_hdw_queue *qp;
458 unsigned long iflag = 0;
461 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
464 spin_lock_irqsave(&phba->hbalock, iflag);
465 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
466 qp = &phba->sli4_hba.hdwq[idx];
468 spin_lock(&qp->abts_io_buf_list_lock);
469 list_for_each_entry_safe(psb, next_psb,
470 &qp->lpfc_abts_io_buf_list, list) {
471 if (psb->cur_iocbq.iocb_flag & LPFC_IO_NVME)
474 if (psb->rdata && psb->rdata->pnode &&
475 psb->rdata->pnode->vport == vport)
478 spin_unlock(&qp->abts_io_buf_list_lock);
480 spin_unlock_irqrestore(&phba->hbalock, iflag);
484 * lpfc_sli4_io_xri_aborted - Fast-path process of fcp xri abort
485 * @phba: pointer to lpfc hba data structure.
486 * @axri: pointer to the fcp xri abort wcqe structure.
487 * @idx: index into hdwq
489 * This routine is invoked by the worker thread to process a SLI4 fast-path
490 * FCP or NVME aborted xri.
493 lpfc_sli4_io_xri_aborted(struct lpfc_hba *phba,
494 struct sli4_wcqe_xri_aborted *axri, int idx)
496 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
497 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
498 struct lpfc_io_buf *psb, *next_psb;
499 struct lpfc_sli4_hdw_queue *qp;
500 unsigned long iflag = 0;
501 struct lpfc_iocbq *iocbq;
503 struct lpfc_nodelist *ndlp;
505 struct lpfc_sli_ring *pring = phba->sli4_hba.els_wq->pring;
506 struct scsi_cmnd *cmd;
508 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
511 qp = &phba->sli4_hba.hdwq[idx];
512 spin_lock_irqsave(&phba->hbalock, iflag);
513 spin_lock(&qp->abts_io_buf_list_lock);
514 list_for_each_entry_safe(psb, next_psb,
515 &qp->lpfc_abts_io_buf_list, list) {
516 if (psb->cur_iocbq.sli4_xritag == xri) {
517 list_del_init(&psb->list);
518 psb->flags &= ~LPFC_SBUF_XBUSY;
519 psb->status = IOSTAT_SUCCESS;
520 if (psb->cur_iocbq.iocb_flag & LPFC_IO_NVME) {
521 qp->abts_nvme_io_bufs--;
522 spin_unlock(&qp->abts_io_buf_list_lock);
523 spin_unlock_irqrestore(&phba->hbalock, iflag);
524 lpfc_sli4_nvme_xri_aborted(phba, axri, psb);
527 qp->abts_scsi_io_bufs--;
528 spin_unlock(&qp->abts_io_buf_list_lock);
530 if (psb->rdata && psb->rdata->pnode)
531 ndlp = psb->rdata->pnode;
535 rrq_empty = list_empty(&phba->active_rrq_list);
536 spin_unlock_irqrestore(&phba->hbalock, iflag);
538 lpfc_set_rrq_active(phba, ndlp,
539 psb->cur_iocbq.sli4_lxritag, rxid, 1);
540 lpfc_sli4_abts_err_handler(phba, ndlp, axri);
543 if (phba->cfg_fcp_wait_abts_rsp) {
544 spin_lock_irqsave(&psb->buf_lock, iflag);
547 spin_unlock_irqrestore(&psb->buf_lock, iflag);
549 /* The sdev is not guaranteed to be valid post
556 * We expect there is an abort thread waiting
557 * for command completion wake up the thread.
559 spin_lock_irqsave(&psb->buf_lock, iflag);
560 psb->cur_iocbq.iocb_flag &=
561 ~LPFC_DRIVER_ABORTED;
564 spin_unlock_irqrestore(&psb->buf_lock, iflag);
567 lpfc_release_scsi_buf_s4(phba, psb);
569 lpfc_worker_wake_up(phba);
573 spin_unlock(&qp->abts_io_buf_list_lock);
574 for (i = 1; i <= phba->sli.last_iotag; i++) {
575 iocbq = phba->sli.iocbq_lookup[i];
577 if (!(iocbq->iocb_flag & LPFC_IO_FCP) ||
578 (iocbq->iocb_flag & LPFC_IO_LIBDFC))
580 if (iocbq->sli4_xritag != xri)
582 psb = container_of(iocbq, struct lpfc_io_buf, cur_iocbq);
583 psb->flags &= ~LPFC_SBUF_XBUSY;
584 spin_unlock_irqrestore(&phba->hbalock, iflag);
585 if (!list_empty(&pring->txq))
586 lpfc_worker_wake_up(phba);
590 spin_unlock_irqrestore(&phba->hbalock, iflag);
594 * lpfc_get_scsi_buf_s3 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
595 * @phba: The HBA for which this call is being executed.
596 * @ndlp: pointer to a node-list data structure.
597 * @cmnd: Pointer to scsi_cmnd data structure.
599 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
600 * and returns to caller.
604 * Pointer to lpfc_scsi_buf - Success
606 static struct lpfc_io_buf *
607 lpfc_get_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
608 struct scsi_cmnd *cmnd)
610 struct lpfc_io_buf *lpfc_cmd = NULL;
611 struct list_head *scsi_buf_list_get = &phba->lpfc_scsi_buf_list_get;
612 unsigned long iflag = 0;
614 spin_lock_irqsave(&phba->scsi_buf_list_get_lock, iflag);
615 list_remove_head(scsi_buf_list_get, lpfc_cmd, struct lpfc_io_buf,
618 spin_lock(&phba->scsi_buf_list_put_lock);
619 list_splice(&phba->lpfc_scsi_buf_list_put,
620 &phba->lpfc_scsi_buf_list_get);
621 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
622 list_remove_head(scsi_buf_list_get, lpfc_cmd,
623 struct lpfc_io_buf, list);
624 spin_unlock(&phba->scsi_buf_list_put_lock);
626 spin_unlock_irqrestore(&phba->scsi_buf_list_get_lock, iflag);
628 if (lpfc_ndlp_check_qdepth(phba, ndlp) && lpfc_cmd) {
629 atomic_inc(&ndlp->cmd_pending);
630 lpfc_cmd->flags |= LPFC_SBUF_BUMP_QDEPTH;
635 * lpfc_get_scsi_buf_s4 - Get a scsi buffer from io_buf_list of the HBA
636 * @phba: The HBA for which this call is being executed.
637 * @ndlp: pointer to a node-list data structure.
638 * @cmnd: Pointer to scsi_cmnd data structure.
640 * This routine removes a scsi buffer from head of @hdwq io_buf_list
641 * and returns to caller.
645 * Pointer to lpfc_scsi_buf - Success
647 static struct lpfc_io_buf *
648 lpfc_get_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
649 struct scsi_cmnd *cmnd)
651 struct lpfc_io_buf *lpfc_cmd;
652 struct lpfc_sli4_hdw_queue *qp;
653 struct sli4_sge *sgl;
654 dma_addr_t pdma_phys_fcp_rsp;
655 dma_addr_t pdma_phys_fcp_cmd;
658 struct fcp_cmd_rsp_buf *tmp = NULL;
660 cpu = raw_smp_processor_id();
661 if (cmnd && phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_HDWQ) {
662 tag = blk_mq_unique_tag(scsi_cmd_to_rq(cmnd));
663 idx = blk_mq_unique_tag_to_hwq(tag);
665 idx = phba->sli4_hba.cpu_map[cpu].hdwq;
668 lpfc_cmd = lpfc_get_io_buf(phba, ndlp, idx,
669 !phba->cfg_xri_rebalancing);
671 qp = &phba->sli4_hba.hdwq[idx];
676 /* Setup key fields in buffer that may have been changed
677 * if other protocols used this buffer.
679 lpfc_cmd->cur_iocbq.iocb_flag = LPFC_IO_FCP;
680 lpfc_cmd->prot_seg_cnt = 0;
681 lpfc_cmd->seg_cnt = 0;
682 lpfc_cmd->timeout = 0;
684 lpfc_cmd->start_time = jiffies;
685 lpfc_cmd->waitq = NULL;
687 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
688 lpfc_cmd->prot_data_type = 0;
690 tmp = lpfc_get_cmd_rsp_buf_per_hdwq(phba, lpfc_cmd);
692 lpfc_release_io_buf(phba, lpfc_cmd, lpfc_cmd->hdwq);
696 lpfc_cmd->fcp_cmnd = tmp->fcp_cmnd;
697 lpfc_cmd->fcp_rsp = tmp->fcp_rsp;
700 * The first two SGEs are the FCP_CMD and FCP_RSP.
701 * The balance are sg list bdes. Initialize the
702 * first two and leave the rest for queuecommand.
704 sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
705 pdma_phys_fcp_cmd = tmp->fcp_cmd_rsp_dma_handle;
706 sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd));
707 sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd));
708 sgl->word2 = le32_to_cpu(sgl->word2);
709 bf_set(lpfc_sli4_sge_last, sgl, 0);
710 sgl->word2 = cpu_to_le32(sgl->word2);
711 sgl->sge_len = cpu_to_le32(sizeof(struct fcp_cmnd));
714 /* Setup the physical region for the FCP RSP */
715 pdma_phys_fcp_rsp = pdma_phys_fcp_cmd + sizeof(struct fcp_cmnd);
716 sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp));
717 sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp));
718 sgl->word2 = le32_to_cpu(sgl->word2);
719 bf_set(lpfc_sli4_sge_last, sgl, 1);
720 sgl->word2 = cpu_to_le32(sgl->word2);
721 sgl->sge_len = cpu_to_le32(sizeof(struct fcp_rsp));
723 if (lpfc_ndlp_check_qdepth(phba, ndlp)) {
724 atomic_inc(&ndlp->cmd_pending);
725 lpfc_cmd->flags |= LPFC_SBUF_BUMP_QDEPTH;
730 * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
731 * @phba: The HBA for which this call is being executed.
732 * @ndlp: pointer to a node-list data structure.
733 * @cmnd: Pointer to scsi_cmnd data structure.
735 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
736 * and returns to caller.
740 * Pointer to lpfc_scsi_buf - Success
742 static struct lpfc_io_buf*
743 lpfc_get_scsi_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
744 struct scsi_cmnd *cmnd)
746 return phba->lpfc_get_scsi_buf(phba, ndlp, cmnd);
750 * lpfc_release_scsi_buf_s3 - Return a scsi buffer back to hba scsi buf list
751 * @phba: The Hba for which this call is being executed.
752 * @psb: The scsi buffer which is being released.
754 * This routine releases @psb scsi buffer by adding it to tail of @phba
755 * lpfc_scsi_buf_list list.
758 lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_io_buf *psb)
760 unsigned long iflag = 0;
763 psb->prot_seg_cnt = 0;
765 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
767 psb->cur_iocbq.iocb_flag = LPFC_IO_FCP;
768 list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list_put);
769 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
773 * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list.
774 * @phba: The Hba for which this call is being executed.
775 * @psb: The scsi buffer which is being released.
777 * This routine releases @psb scsi buffer by adding it to tail of @hdwq
778 * io_buf_list list. For SLI4 XRI's are tied to the scsi buffer
779 * and cannot be reused for at least RA_TOV amount of time if it was
783 lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_io_buf *psb)
785 struct lpfc_sli4_hdw_queue *qp;
786 unsigned long iflag = 0;
789 psb->prot_seg_cnt = 0;
792 if (psb->flags & LPFC_SBUF_XBUSY) {
793 spin_lock_irqsave(&qp->abts_io_buf_list_lock, iflag);
794 if (!phba->cfg_fcp_wait_abts_rsp)
796 list_add_tail(&psb->list, &qp->lpfc_abts_io_buf_list);
797 qp->abts_scsi_io_bufs++;
798 spin_unlock_irqrestore(&qp->abts_io_buf_list_lock, iflag);
800 lpfc_release_io_buf(phba, (struct lpfc_io_buf *)psb, qp);
805 * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list.
806 * @phba: The Hba for which this call is being executed.
807 * @psb: The scsi buffer which is being released.
809 * This routine releases @psb scsi buffer by adding it to tail of @phba
810 * lpfc_scsi_buf_list list.
813 lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_io_buf *psb)
815 if ((psb->flags & LPFC_SBUF_BUMP_QDEPTH) && psb->ndlp)
816 atomic_dec(&psb->ndlp->cmd_pending);
818 psb->flags &= ~LPFC_SBUF_BUMP_QDEPTH;
819 phba->lpfc_release_scsi_buf(phba, psb);
823 * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB
824 * @data: A pointer to the immediate command data portion of the IOCB.
825 * @fcp_cmnd: The FCP Command that is provided by the SCSI layer.
827 * The routine copies the entire FCP command from @fcp_cmnd to @data while
828 * byte swapping the data to big endian format for transmission on the wire.
831 lpfc_fcpcmd_to_iocb(u8 *data, struct fcp_cmnd *fcp_cmnd)
835 for (i = 0, j = 0; i < sizeof(struct fcp_cmnd);
836 i += sizeof(uint32_t), j++) {
837 ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]);
842 * lpfc_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
843 * @phba: The Hba for which this call is being executed.
844 * @lpfc_cmd: The scsi buffer which is going to be mapped.
846 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
847 * field of @lpfc_cmd for device with SLI-3 interface spec. This routine scans
848 * through sg elements and format the bde. This routine also initializes all
849 * IOCB fields which are dependent on scsi command request buffer.
856 lpfc_scsi_prep_dma_buf_s3(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
858 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
859 struct scatterlist *sgel = NULL;
860 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
861 struct ulp_bde64 *bpl = (struct ulp_bde64 *)lpfc_cmd->dma_sgl;
862 struct lpfc_iocbq *iocbq = &lpfc_cmd->cur_iocbq;
863 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
864 struct ulp_bde64 *data_bde = iocb_cmd->unsli3.fcp_ext.dbde;
866 uint32_t num_bde = 0;
867 int nseg, datadir = scsi_cmnd->sc_data_direction;
870 * There are three possibilities here - use scatter-gather segment, use
871 * the single mapping, or neither. Start the lpfc command prep by
872 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
876 if (scsi_sg_count(scsi_cmnd)) {
878 * The driver stores the segment count returned from pci_map_sg
879 * because this a count of dma-mappings used to map the use_sg
880 * pages. They are not guaranteed to be the same for those
881 * architectures that implement an IOMMU.
884 nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd),
885 scsi_sg_count(scsi_cmnd), datadir);
889 lpfc_cmd->seg_cnt = nseg;
890 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
891 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
892 "9064 BLKGRD: %s: Too many sg segments"
893 " from dma_map_sg. Config %d, seg_cnt"
894 " %d\n", __func__, phba->cfg_sg_seg_cnt,
896 WARN_ON_ONCE(lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt);
897 lpfc_cmd->seg_cnt = 0;
898 scsi_dma_unmap(scsi_cmnd);
903 * The driver established a maximum scatter-gather segment count
904 * during probe that limits the number of sg elements in any
905 * single scsi command. Just run through the seg_cnt and format
907 * When using SLI-3 the driver will try to fit all the BDEs into
908 * the IOCB. If it can't then the BDEs get added to a BPL as it
909 * does for SLI-2 mode.
911 scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) {
912 physaddr = sg_dma_address(sgel);
913 if (phba->sli_rev == 3 &&
914 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
915 !(iocbq->iocb_flag & DSS_SECURITY_OP) &&
916 nseg <= LPFC_EXT_DATA_BDE_COUNT) {
917 data_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
918 data_bde->tus.f.bdeSize = sg_dma_len(sgel);
919 data_bde->addrLow = putPaddrLow(physaddr);
920 data_bde->addrHigh = putPaddrHigh(physaddr);
923 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
924 bpl->tus.f.bdeSize = sg_dma_len(sgel);
925 bpl->tus.w = le32_to_cpu(bpl->tus.w);
927 le32_to_cpu(putPaddrLow(physaddr));
929 le32_to_cpu(putPaddrHigh(physaddr));
936 * Finish initializing those IOCB fields that are dependent on the
937 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
938 * explicitly reinitialized and for SLI-3 the extended bde count is
939 * explicitly reinitialized since all iocb memory resources are reused.
941 if (phba->sli_rev == 3 &&
942 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
943 !(iocbq->iocb_flag & DSS_SECURITY_OP)) {
944 if (num_bde > LPFC_EXT_DATA_BDE_COUNT) {
946 * The extended IOCB format can only fit 3 BDE or a BPL.
947 * This I/O has more than 3 BDE so the 1st data bde will
948 * be a BPL that is filled in here.
950 physaddr = lpfc_cmd->dma_handle;
951 data_bde->tus.f.bdeFlags = BUFF_TYPE_BLP_64;
952 data_bde->tus.f.bdeSize = (num_bde *
953 sizeof(struct ulp_bde64));
954 physaddr += (sizeof(struct fcp_cmnd) +
955 sizeof(struct fcp_rsp) +
956 (2 * sizeof(struct ulp_bde64)));
957 data_bde->addrHigh = putPaddrHigh(physaddr);
958 data_bde->addrLow = putPaddrLow(physaddr);
959 /* ebde count includes the response bde and data bpl */
960 iocb_cmd->unsli3.fcp_ext.ebde_count = 2;
962 /* ebde count includes the response bde and data bdes */
963 iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1);
966 iocb_cmd->un.fcpi64.bdl.bdeSize =
967 ((num_bde + 2) * sizeof(struct ulp_bde64));
968 iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1);
970 fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd));
973 * Due to difference in data length between DIF/non-DIF paths,
974 * we need to set word 4 of IOCB here
976 iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd);
977 lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd);
981 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
983 /* Return BG_ERR_INIT if error injection is detected by Initiator */
984 #define BG_ERR_INIT 0x1
985 /* Return BG_ERR_TGT if error injection is detected by Target */
986 #define BG_ERR_TGT 0x2
987 /* Return BG_ERR_SWAP if swapping CSUM<-->CRC is required for error injection */
988 #define BG_ERR_SWAP 0x10
990 * Return BG_ERR_CHECK if disabling Guard/Ref/App checking is required for
993 #define BG_ERR_CHECK 0x20
996 * lpfc_bg_err_inject - Determine if we should inject an error
997 * @phba: The Hba for which this call is being executed.
998 * @sc: The SCSI command to examine
999 * @reftag: (out) BlockGuard reference tag for transmitted data
1000 * @apptag: (out) BlockGuard application tag for transmitted data
1001 * @new_guard: (in) Value to replace CRC with if needed
1003 * Returns BG_ERR_* bit mask or 0 if request ignored
1006 lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1007 uint32_t *reftag, uint16_t *apptag, uint32_t new_guard)
1009 struct scatterlist *sgpe; /* s/g prot entry */
1010 struct lpfc_io_buf *lpfc_cmd = NULL;
1011 struct scsi_dif_tuple *src = NULL;
1012 struct lpfc_nodelist *ndlp;
1013 struct lpfc_rport_data *rdata;
1014 uint32_t op = scsi_get_prot_op(sc);
1021 if (op == SCSI_PROT_NORMAL)
1024 sgpe = scsi_prot_sglist(sc);
1025 lba = scsi_prot_ref_tag(sc);
1026 if (lba == LPFC_INVALID_REFTAG)
1029 /* First check if we need to match the LBA */
1030 if (phba->lpfc_injerr_lba != LPFC_INJERR_LBA_OFF) {
1031 blksize = scsi_prot_interval(sc);
1032 numblks = (scsi_bufflen(sc) + blksize - 1) / blksize;
1034 /* Make sure we have the right LBA if one is specified */
1035 if (phba->lpfc_injerr_lba < (u64)lba ||
1036 (phba->lpfc_injerr_lba >= (u64)(lba + numblks)))
1039 blockoff = phba->lpfc_injerr_lba - (u64)lba;
1040 numblks = sg_dma_len(sgpe) /
1041 sizeof(struct scsi_dif_tuple);
1042 if (numblks < blockoff)
1047 /* Next check if we need to match the remote NPortID or WWPN */
1048 rdata = lpfc_rport_data_from_scsi_device(sc->device);
1049 if (rdata && rdata->pnode) {
1050 ndlp = rdata->pnode;
1052 /* Make sure we have the right NPortID if one is specified */
1053 if (phba->lpfc_injerr_nportid &&
1054 (phba->lpfc_injerr_nportid != ndlp->nlp_DID))
1058 * Make sure we have the right WWPN if one is specified.
1059 * wwn[0] should be a non-zero NAA in a good WWPN.
1061 if (phba->lpfc_injerr_wwpn.u.wwn[0] &&
1062 (memcmp(&ndlp->nlp_portname, &phba->lpfc_injerr_wwpn,
1063 sizeof(struct lpfc_name)) != 0))
1067 /* Setup a ptr to the protection data if the SCSI host provides it */
1069 src = (struct scsi_dif_tuple *)sg_virt(sgpe);
1071 lpfc_cmd = (struct lpfc_io_buf *)sc->host_scribble;
1074 /* Should we change the Reference Tag */
1076 if (phba->lpfc_injerr_wref_cnt) {
1078 case SCSI_PROT_WRITE_PASS:
1081 * For WRITE_PASS, force the error
1082 * to be sent on the wire. It should
1083 * be detected by the Target.
1084 * If blockoff != 0 error will be
1085 * inserted in middle of the IO.
1088 lpfc_printf_log(phba, KERN_ERR,
1090 "9076 BLKGRD: Injecting reftag error: "
1091 "write lba x%lx + x%x oldrefTag x%x\n",
1092 (unsigned long)lba, blockoff,
1093 be32_to_cpu(src->ref_tag));
1096 * Save the old ref_tag so we can
1097 * restore it on completion.
1100 lpfc_cmd->prot_data_type =
1102 lpfc_cmd->prot_data_segment =
1104 lpfc_cmd->prot_data =
1107 src->ref_tag = cpu_to_be32(0xDEADBEEF);
1108 phba->lpfc_injerr_wref_cnt--;
1109 if (phba->lpfc_injerr_wref_cnt == 0) {
1110 phba->lpfc_injerr_nportid = 0;
1111 phba->lpfc_injerr_lba =
1112 LPFC_INJERR_LBA_OFF;
1113 memset(&phba->lpfc_injerr_wwpn,
1114 0, sizeof(struct lpfc_name));
1116 rc = BG_ERR_TGT | BG_ERR_CHECK;
1121 case SCSI_PROT_WRITE_INSERT:
1123 * For WRITE_INSERT, force the error
1124 * to be sent on the wire. It should be
1125 * detected by the Target.
1127 /* DEADBEEF will be the reftag on the wire */
1128 *reftag = 0xDEADBEEF;
1129 phba->lpfc_injerr_wref_cnt--;
1130 if (phba->lpfc_injerr_wref_cnt == 0) {
1131 phba->lpfc_injerr_nportid = 0;
1132 phba->lpfc_injerr_lba =
1133 LPFC_INJERR_LBA_OFF;
1134 memset(&phba->lpfc_injerr_wwpn,
1135 0, sizeof(struct lpfc_name));
1137 rc = BG_ERR_TGT | BG_ERR_CHECK;
1139 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1140 "9078 BLKGRD: Injecting reftag error: "
1141 "write lba x%lx\n", (unsigned long)lba);
1143 case SCSI_PROT_WRITE_STRIP:
1145 * For WRITE_STRIP and WRITE_PASS,
1146 * force the error on data
1147 * being copied from SLI-Host to SLI-Port.
1149 *reftag = 0xDEADBEEF;
1150 phba->lpfc_injerr_wref_cnt--;
1151 if (phba->lpfc_injerr_wref_cnt == 0) {
1152 phba->lpfc_injerr_nportid = 0;
1153 phba->lpfc_injerr_lba =
1154 LPFC_INJERR_LBA_OFF;
1155 memset(&phba->lpfc_injerr_wwpn,
1156 0, sizeof(struct lpfc_name));
1160 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1161 "9077 BLKGRD: Injecting reftag error: "
1162 "write lba x%lx\n", (unsigned long)lba);
1166 if (phba->lpfc_injerr_rref_cnt) {
1168 case SCSI_PROT_READ_INSERT:
1169 case SCSI_PROT_READ_STRIP:
1170 case SCSI_PROT_READ_PASS:
1172 * For READ_STRIP and READ_PASS, force the
1173 * error on data being read off the wire. It
1174 * should force an IO error to the driver.
1176 *reftag = 0xDEADBEEF;
1177 phba->lpfc_injerr_rref_cnt--;
1178 if (phba->lpfc_injerr_rref_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));
1187 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1188 "9079 BLKGRD: Injecting reftag error: "
1189 "read lba x%lx\n", (unsigned long)lba);
1195 /* Should we change the Application Tag */
1197 if (phba->lpfc_injerr_wapp_cnt) {
1199 case SCSI_PROT_WRITE_PASS:
1202 * For WRITE_PASS, force the error
1203 * to be sent on the wire. It should
1204 * be detected by the Target.
1205 * If blockoff != 0 error will be
1206 * inserted in middle of the IO.
1209 lpfc_printf_log(phba, KERN_ERR,
1211 "9080 BLKGRD: Injecting apptag error: "
1212 "write lba x%lx + x%x oldappTag x%x\n",
1213 (unsigned long)lba, blockoff,
1214 be16_to_cpu(src->app_tag));
1217 * Save the old app_tag so we can
1218 * restore it on completion.
1221 lpfc_cmd->prot_data_type =
1223 lpfc_cmd->prot_data_segment =
1225 lpfc_cmd->prot_data =
1228 src->app_tag = cpu_to_be16(0xDEAD);
1229 phba->lpfc_injerr_wapp_cnt--;
1230 if (phba->lpfc_injerr_wapp_cnt == 0) {
1231 phba->lpfc_injerr_nportid = 0;
1232 phba->lpfc_injerr_lba =
1233 LPFC_INJERR_LBA_OFF;
1234 memset(&phba->lpfc_injerr_wwpn,
1235 0, sizeof(struct lpfc_name));
1237 rc = BG_ERR_TGT | BG_ERR_CHECK;
1241 case SCSI_PROT_WRITE_INSERT:
1243 * For WRITE_INSERT, force the
1244 * error to be sent on the wire. It should be
1245 * detected by the Target.
1247 /* DEAD will be the apptag on the wire */
1249 phba->lpfc_injerr_wapp_cnt--;
1250 if (phba->lpfc_injerr_wapp_cnt == 0) {
1251 phba->lpfc_injerr_nportid = 0;
1252 phba->lpfc_injerr_lba =
1253 LPFC_INJERR_LBA_OFF;
1254 memset(&phba->lpfc_injerr_wwpn,
1255 0, sizeof(struct lpfc_name));
1257 rc = BG_ERR_TGT | BG_ERR_CHECK;
1259 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1260 "0813 BLKGRD: Injecting apptag error: "
1261 "write lba x%lx\n", (unsigned long)lba);
1263 case SCSI_PROT_WRITE_STRIP:
1265 * For WRITE_STRIP and WRITE_PASS,
1266 * force the error on data
1267 * being copied from SLI-Host to SLI-Port.
1270 phba->lpfc_injerr_wapp_cnt--;
1271 if (phba->lpfc_injerr_wapp_cnt == 0) {
1272 phba->lpfc_injerr_nportid = 0;
1273 phba->lpfc_injerr_lba =
1274 LPFC_INJERR_LBA_OFF;
1275 memset(&phba->lpfc_injerr_wwpn,
1276 0, sizeof(struct lpfc_name));
1280 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1281 "0812 BLKGRD: Injecting apptag error: "
1282 "write lba x%lx\n", (unsigned long)lba);
1286 if (phba->lpfc_injerr_rapp_cnt) {
1288 case SCSI_PROT_READ_INSERT:
1289 case SCSI_PROT_READ_STRIP:
1290 case SCSI_PROT_READ_PASS:
1292 * For READ_STRIP and READ_PASS, force the
1293 * error on data being read off the wire. It
1294 * should force an IO error to the driver.
1297 phba->lpfc_injerr_rapp_cnt--;
1298 if (phba->lpfc_injerr_rapp_cnt == 0) {
1299 phba->lpfc_injerr_nportid = 0;
1300 phba->lpfc_injerr_lba =
1301 LPFC_INJERR_LBA_OFF;
1302 memset(&phba->lpfc_injerr_wwpn,
1303 0, sizeof(struct lpfc_name));
1307 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1308 "0814 BLKGRD: Injecting apptag error: "
1309 "read lba x%lx\n", (unsigned long)lba);
1316 /* Should we change the Guard Tag */
1318 if (phba->lpfc_injerr_wgrd_cnt) {
1320 case SCSI_PROT_WRITE_PASS:
1324 case SCSI_PROT_WRITE_INSERT:
1326 * For WRITE_INSERT, force the
1327 * error to be sent on the wire. It should be
1328 * detected by the Target.
1330 phba->lpfc_injerr_wgrd_cnt--;
1331 if (phba->lpfc_injerr_wgrd_cnt == 0) {
1332 phba->lpfc_injerr_nportid = 0;
1333 phba->lpfc_injerr_lba =
1334 LPFC_INJERR_LBA_OFF;
1335 memset(&phba->lpfc_injerr_wwpn,
1336 0, sizeof(struct lpfc_name));
1339 rc |= BG_ERR_TGT | BG_ERR_SWAP;
1340 /* Signals the caller to swap CRC->CSUM */
1342 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1343 "0817 BLKGRD: Injecting guard error: "
1344 "write lba x%lx\n", (unsigned long)lba);
1346 case SCSI_PROT_WRITE_STRIP:
1348 * For WRITE_STRIP and WRITE_PASS,
1349 * force the error on data
1350 * being copied from SLI-Host to SLI-Port.
1352 phba->lpfc_injerr_wgrd_cnt--;
1353 if (phba->lpfc_injerr_wgrd_cnt == 0) {
1354 phba->lpfc_injerr_nportid = 0;
1355 phba->lpfc_injerr_lba =
1356 LPFC_INJERR_LBA_OFF;
1357 memset(&phba->lpfc_injerr_wwpn,
1358 0, sizeof(struct lpfc_name));
1361 rc = BG_ERR_INIT | BG_ERR_SWAP;
1362 /* Signals the caller to swap CRC->CSUM */
1364 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1365 "0816 BLKGRD: Injecting guard error: "
1366 "write lba x%lx\n", (unsigned long)lba);
1370 if (phba->lpfc_injerr_rgrd_cnt) {
1372 case SCSI_PROT_READ_INSERT:
1373 case SCSI_PROT_READ_STRIP:
1374 case SCSI_PROT_READ_PASS:
1376 * For READ_STRIP and READ_PASS, force the
1377 * error on data being read off the wire. It
1378 * should force an IO error to the driver.
1380 phba->lpfc_injerr_rgrd_cnt--;
1381 if (phba->lpfc_injerr_rgrd_cnt == 0) {
1382 phba->lpfc_injerr_nportid = 0;
1383 phba->lpfc_injerr_lba =
1384 LPFC_INJERR_LBA_OFF;
1385 memset(&phba->lpfc_injerr_wwpn,
1386 0, sizeof(struct lpfc_name));
1389 rc = BG_ERR_INIT | BG_ERR_SWAP;
1390 /* Signals the caller to swap CRC->CSUM */
1392 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1393 "0818 BLKGRD: Injecting guard error: "
1394 "read lba x%lx\n", (unsigned long)lba);
1404 * lpfc_sc_to_bg_opcodes - Determine the BlockGuard opcodes to be used with
1405 * the specified SCSI command.
1406 * @phba: The Hba for which this call is being executed.
1407 * @sc: The SCSI command to examine
1408 * @txop: (out) BlockGuard operation for transmitted data
1409 * @rxop: (out) BlockGuard operation for received data
1411 * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
1415 lpfc_sc_to_bg_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1416 uint8_t *txop, uint8_t *rxop)
1420 if (sc->prot_flags & SCSI_PROT_IP_CHECKSUM) {
1421 switch (scsi_get_prot_op(sc)) {
1422 case SCSI_PROT_READ_INSERT:
1423 case SCSI_PROT_WRITE_STRIP:
1424 *rxop = BG_OP_IN_NODIF_OUT_CSUM;
1425 *txop = BG_OP_IN_CSUM_OUT_NODIF;
1428 case SCSI_PROT_READ_STRIP:
1429 case SCSI_PROT_WRITE_INSERT:
1430 *rxop = BG_OP_IN_CRC_OUT_NODIF;
1431 *txop = BG_OP_IN_NODIF_OUT_CRC;
1434 case SCSI_PROT_READ_PASS:
1435 case SCSI_PROT_WRITE_PASS:
1436 *rxop = BG_OP_IN_CRC_OUT_CSUM;
1437 *txop = BG_OP_IN_CSUM_OUT_CRC;
1440 case SCSI_PROT_NORMAL:
1442 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1443 "9063 BLKGRD: Bad op/guard:%d/IP combination\n",
1444 scsi_get_prot_op(sc));
1450 switch (scsi_get_prot_op(sc)) {
1451 case SCSI_PROT_READ_STRIP:
1452 case SCSI_PROT_WRITE_INSERT:
1453 *rxop = BG_OP_IN_CRC_OUT_NODIF;
1454 *txop = BG_OP_IN_NODIF_OUT_CRC;
1457 case SCSI_PROT_READ_PASS:
1458 case SCSI_PROT_WRITE_PASS:
1459 *rxop = BG_OP_IN_CRC_OUT_CRC;
1460 *txop = BG_OP_IN_CRC_OUT_CRC;
1463 case SCSI_PROT_READ_INSERT:
1464 case SCSI_PROT_WRITE_STRIP:
1465 *rxop = BG_OP_IN_NODIF_OUT_CRC;
1466 *txop = BG_OP_IN_CRC_OUT_NODIF;
1469 case SCSI_PROT_NORMAL:
1471 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1472 "9075 BLKGRD: Bad op/guard:%d/CRC combination\n",
1473 scsi_get_prot_op(sc));
1482 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1484 * lpfc_bg_err_opcodes - reDetermine the BlockGuard opcodes to be used with
1485 * the specified SCSI command in order to force a guard tag error.
1486 * @phba: The Hba for which this call is being executed.
1487 * @sc: The SCSI command to examine
1488 * @txop: (out) BlockGuard operation for transmitted data
1489 * @rxop: (out) BlockGuard operation for received data
1491 * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
1495 lpfc_bg_err_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1496 uint8_t *txop, uint8_t *rxop)
1499 if (sc->prot_flags & SCSI_PROT_IP_CHECKSUM) {
1500 switch (scsi_get_prot_op(sc)) {
1501 case SCSI_PROT_READ_INSERT:
1502 case SCSI_PROT_WRITE_STRIP:
1503 *rxop = BG_OP_IN_NODIF_OUT_CRC;
1504 *txop = BG_OP_IN_CRC_OUT_NODIF;
1507 case SCSI_PROT_READ_STRIP:
1508 case SCSI_PROT_WRITE_INSERT:
1509 *rxop = BG_OP_IN_CSUM_OUT_NODIF;
1510 *txop = BG_OP_IN_NODIF_OUT_CSUM;
1513 case SCSI_PROT_READ_PASS:
1514 case SCSI_PROT_WRITE_PASS:
1515 *rxop = BG_OP_IN_CSUM_OUT_CRC;
1516 *txop = BG_OP_IN_CRC_OUT_CSUM;
1519 case SCSI_PROT_NORMAL:
1525 switch (scsi_get_prot_op(sc)) {
1526 case SCSI_PROT_READ_STRIP:
1527 case SCSI_PROT_WRITE_INSERT:
1528 *rxop = BG_OP_IN_CSUM_OUT_NODIF;
1529 *txop = BG_OP_IN_NODIF_OUT_CSUM;
1532 case SCSI_PROT_READ_PASS:
1533 case SCSI_PROT_WRITE_PASS:
1534 *rxop = BG_OP_IN_CSUM_OUT_CSUM;
1535 *txop = BG_OP_IN_CSUM_OUT_CSUM;
1538 case SCSI_PROT_READ_INSERT:
1539 case SCSI_PROT_WRITE_STRIP:
1540 *rxop = BG_OP_IN_NODIF_OUT_CSUM;
1541 *txop = BG_OP_IN_CSUM_OUT_NODIF;
1544 case SCSI_PROT_NORMAL:
1555 * lpfc_bg_setup_bpl - Setup BlockGuard BPL with no protection data
1556 * @phba: The Hba for which this call is being executed.
1557 * @sc: pointer to scsi command we're working on
1558 * @bpl: pointer to buffer list for protection groups
1559 * @datasegcnt: number of segments of data that have been dma mapped
1561 * This function sets up BPL buffer list for protection groups of
1562 * type LPFC_PG_TYPE_NO_DIF
1564 * This is usually used when the HBA is instructed to generate
1565 * DIFs and insert them into data stream (or strip DIF from
1566 * incoming data stream)
1568 * The buffer list consists of just one protection group described
1570 * +-------------------------+
1571 * start of prot group --> | PDE_5 |
1572 * +-------------------------+
1574 * +-------------------------+
1576 * +-------------------------+
1577 * |more Data BDE's ... (opt)|
1578 * +-------------------------+
1581 * Note: Data s/g buffers have been dma mapped
1583 * Returns the number of BDEs added to the BPL.
1586 lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1587 struct ulp_bde64 *bpl, int datasegcnt)
1589 struct scatterlist *sgde = NULL; /* s/g data entry */
1590 struct lpfc_pde5 *pde5 = NULL;
1591 struct lpfc_pde6 *pde6 = NULL;
1592 dma_addr_t physaddr;
1593 int i = 0, num_bde = 0, status;
1594 int datadir = sc->sc_data_direction;
1595 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1598 uint32_t checking = 1;
1602 status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
1606 /* extract some info from the scsi command for pde*/
1607 reftag = scsi_prot_ref_tag(sc);
1608 if (reftag == LPFC_INVALID_REFTAG)
1611 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1612 rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
1614 if (rc & BG_ERR_SWAP)
1615 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
1616 if (rc & BG_ERR_CHECK)
1621 /* setup PDE5 with what we have */
1622 pde5 = (struct lpfc_pde5 *) bpl;
1623 memset(pde5, 0, sizeof(struct lpfc_pde5));
1624 bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR);
1626 /* Endianness conversion if necessary for PDE5 */
1627 pde5->word0 = cpu_to_le32(pde5->word0);
1628 pde5->reftag = cpu_to_le32(reftag);
1630 /* advance bpl and increment bde count */
1633 pde6 = (struct lpfc_pde6 *) bpl;
1635 /* setup PDE6 with the rest of the info */
1636 memset(pde6, 0, sizeof(struct lpfc_pde6));
1637 bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR);
1638 bf_set(pde6_optx, pde6, txop);
1639 bf_set(pde6_oprx, pde6, rxop);
1642 * We only need to check the data on READs, for WRITEs
1643 * protection data is automatically generated, not checked.
1645 if (datadir == DMA_FROM_DEVICE) {
1646 if (sc->prot_flags & SCSI_PROT_GUARD_CHECK)
1647 bf_set(pde6_ce, pde6, checking);
1649 bf_set(pde6_ce, pde6, 0);
1651 if (sc->prot_flags & SCSI_PROT_REF_CHECK)
1652 bf_set(pde6_re, pde6, checking);
1654 bf_set(pde6_re, pde6, 0);
1656 bf_set(pde6_ai, pde6, 1);
1657 bf_set(pde6_ae, pde6, 0);
1658 bf_set(pde6_apptagval, pde6, 0);
1660 /* Endianness conversion if necessary for PDE6 */
1661 pde6->word0 = cpu_to_le32(pde6->word0);
1662 pde6->word1 = cpu_to_le32(pde6->word1);
1663 pde6->word2 = cpu_to_le32(pde6->word2);
1665 /* advance bpl and increment bde count */
1669 /* assumption: caller has already run dma_map_sg on command data */
1670 scsi_for_each_sg(sc, sgde, datasegcnt, i) {
1671 physaddr = sg_dma_address(sgde);
1672 bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr));
1673 bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
1674 bpl->tus.f.bdeSize = sg_dma_len(sgde);
1675 if (datadir == DMA_TO_DEVICE)
1676 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1678 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
1679 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1689 * lpfc_bg_setup_bpl_prot - Setup BlockGuard BPL with protection data
1690 * @phba: The Hba for which this call is being executed.
1691 * @sc: pointer to scsi command we're working on
1692 * @bpl: pointer to buffer list for protection groups
1693 * @datacnt: number of segments of data that have been dma mapped
1694 * @protcnt: number of segment of protection data that have been dma mapped
1696 * This function sets up BPL buffer list for protection groups of
1697 * type LPFC_PG_TYPE_DIF
1699 * This is usually used when DIFs are in their own buffers,
1700 * separate from the data. The HBA can then by instructed
1701 * to place the DIFs in the outgoing stream. For read operations,
1702 * The HBA could extract the DIFs and place it in DIF buffers.
1704 * The buffer list for this type consists of one or more of the
1705 * protection groups described below:
1706 * +-------------------------+
1707 * start of first prot group --> | PDE_5 |
1708 * +-------------------------+
1710 * +-------------------------+
1711 * | PDE_7 (Prot BDE) |
1712 * +-------------------------+
1714 * +-------------------------+
1715 * |more Data BDE's ... (opt)|
1716 * +-------------------------+
1717 * start of new prot group --> | PDE_5 |
1718 * +-------------------------+
1720 * +-------------------------+
1722 * Note: It is assumed that both data and protection s/g buffers have been
1725 * Returns the number of BDEs added to the BPL.
1728 lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1729 struct ulp_bde64 *bpl, int datacnt, int protcnt)
1731 struct scatterlist *sgde = NULL; /* s/g data entry */
1732 struct scatterlist *sgpe = NULL; /* s/g prot entry */
1733 struct lpfc_pde5 *pde5 = NULL;
1734 struct lpfc_pde6 *pde6 = NULL;
1735 struct lpfc_pde7 *pde7 = NULL;
1736 dma_addr_t dataphysaddr, protphysaddr;
1737 unsigned short curr_data = 0, curr_prot = 0;
1738 unsigned int split_offset;
1739 unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder;
1740 unsigned int protgrp_blks, protgrp_bytes;
1741 unsigned int remainder, subtotal;
1743 int datadir = sc->sc_data_direction;
1744 unsigned char pgdone = 0, alldone = 0;
1746 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1749 uint32_t checking = 1;
1754 sgpe = scsi_prot_sglist(sc);
1755 sgde = scsi_sglist(sc);
1757 if (!sgpe || !sgde) {
1758 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1759 "9020 Invalid s/g entry: data=x%px prot=x%px\n",
1764 status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
1768 /* extract some info from the scsi command */
1769 blksize = scsi_prot_interval(sc);
1770 reftag = scsi_prot_ref_tag(sc);
1771 if (reftag == LPFC_INVALID_REFTAG)
1774 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1775 rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
1777 if (rc & BG_ERR_SWAP)
1778 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
1779 if (rc & BG_ERR_CHECK)
1786 /* Check to see if we ran out of space */
1787 if (num_bde >= (phba->cfg_total_seg_cnt - 2))
1790 /* setup PDE5 with what we have */
1791 pde5 = (struct lpfc_pde5 *) bpl;
1792 memset(pde5, 0, sizeof(struct lpfc_pde5));
1793 bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR);
1795 /* Endianness conversion if necessary for PDE5 */
1796 pde5->word0 = cpu_to_le32(pde5->word0);
1797 pde5->reftag = cpu_to_le32(reftag);
1799 /* advance bpl and increment bde count */
1802 pde6 = (struct lpfc_pde6 *) bpl;
1804 /* setup PDE6 with the rest of the info */
1805 memset(pde6, 0, sizeof(struct lpfc_pde6));
1806 bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR);
1807 bf_set(pde6_optx, pde6, txop);
1808 bf_set(pde6_oprx, pde6, rxop);
1810 if (sc->prot_flags & SCSI_PROT_GUARD_CHECK)
1811 bf_set(pde6_ce, pde6, checking);
1813 bf_set(pde6_ce, pde6, 0);
1815 if (sc->prot_flags & SCSI_PROT_REF_CHECK)
1816 bf_set(pde6_re, pde6, checking);
1818 bf_set(pde6_re, pde6, 0);
1820 bf_set(pde6_ai, pde6, 1);
1821 bf_set(pde6_ae, pde6, 0);
1822 bf_set(pde6_apptagval, pde6, 0);
1824 /* Endianness conversion if necessary for PDE6 */
1825 pde6->word0 = cpu_to_le32(pde6->word0);
1826 pde6->word1 = cpu_to_le32(pde6->word1);
1827 pde6->word2 = cpu_to_le32(pde6->word2);
1829 /* advance bpl and increment bde count */
1833 /* setup the first BDE that points to protection buffer */
1834 protphysaddr = sg_dma_address(sgpe) + protgroup_offset;
1835 protgroup_len = sg_dma_len(sgpe) - protgroup_offset;
1837 /* must be integer multiple of the DIF block length */
1838 BUG_ON(protgroup_len % 8);
1840 pde7 = (struct lpfc_pde7 *) bpl;
1841 memset(pde7, 0, sizeof(struct lpfc_pde7));
1842 bf_set(pde7_type, pde7, LPFC_PDE7_DESCRIPTOR);
1844 pde7->addrHigh = le32_to_cpu(putPaddrHigh(protphysaddr));
1845 pde7->addrLow = le32_to_cpu(putPaddrLow(protphysaddr));
1847 protgrp_blks = protgroup_len / 8;
1848 protgrp_bytes = protgrp_blks * blksize;
1850 /* check if this pde is crossing the 4K boundary; if so split */
1851 if ((pde7->addrLow & 0xfff) + protgroup_len > 0x1000) {
1852 protgroup_remainder = 0x1000 - (pde7->addrLow & 0xfff);
1853 protgroup_offset += protgroup_remainder;
1854 protgrp_blks = protgroup_remainder / 8;
1855 protgrp_bytes = protgrp_blks * blksize;
1857 protgroup_offset = 0;
1863 /* setup BDE's for data blocks associated with DIF data */
1865 subtotal = 0; /* total bytes processed for current prot grp */
1867 /* Check to see if we ran out of space */
1868 if (num_bde >= phba->cfg_total_seg_cnt)
1872 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1873 "9065 BLKGRD:%s Invalid data segment\n",
1878 dataphysaddr = sg_dma_address(sgde) + split_offset;
1879 bpl->addrLow = le32_to_cpu(putPaddrLow(dataphysaddr));
1880 bpl->addrHigh = le32_to_cpu(putPaddrHigh(dataphysaddr));
1882 remainder = sg_dma_len(sgde) - split_offset;
1884 if ((subtotal + remainder) <= protgrp_bytes) {
1885 /* we can use this whole buffer */
1886 bpl->tus.f.bdeSize = remainder;
1889 if ((subtotal + remainder) == protgrp_bytes)
1892 /* must split this buffer with next prot grp */
1893 bpl->tus.f.bdeSize = protgrp_bytes - subtotal;
1894 split_offset += bpl->tus.f.bdeSize;
1897 subtotal += bpl->tus.f.bdeSize;
1899 if (datadir == DMA_TO_DEVICE)
1900 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1902 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
1903 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1911 /* Move to the next s/g segment if possible */
1912 sgde = sg_next(sgde);
1916 if (protgroup_offset) {
1917 /* update the reference tag */
1918 reftag += protgrp_blks;
1924 if (curr_prot == protcnt) {
1926 } else if (curr_prot < protcnt) {
1927 /* advance to next prot buffer */
1928 sgpe = sg_next(sgpe);
1931 /* update the reference tag */
1932 reftag += protgrp_blks;
1934 /* if we're here, we have a bug */
1935 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1936 "9054 BLKGRD: bug in %s\n", __func__);
1946 * lpfc_bg_setup_sgl - Setup BlockGuard SGL with no protection data
1947 * @phba: The Hba for which this call is being executed.
1948 * @sc: pointer to scsi command we're working on
1949 * @sgl: pointer to buffer list for protection groups
1950 * @datasegcnt: number of segments of data that have been dma mapped
1951 * @lpfc_cmd: lpfc scsi command object pointer.
1953 * This function sets up SGL buffer list for protection groups of
1954 * type LPFC_PG_TYPE_NO_DIF
1956 * This is usually used when the HBA is instructed to generate
1957 * DIFs and insert them into data stream (or strip DIF from
1958 * incoming data stream)
1960 * The buffer list consists of just one protection group described
1962 * +-------------------------+
1963 * start of prot group --> | DI_SEED |
1964 * +-------------------------+
1966 * +-------------------------+
1967 * |more Data SGE's ... (opt)|
1968 * +-------------------------+
1971 * Note: Data s/g buffers have been dma mapped
1973 * Returns the number of SGEs added to the SGL.
1976 lpfc_bg_setup_sgl(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1977 struct sli4_sge *sgl, int datasegcnt,
1978 struct lpfc_io_buf *lpfc_cmd)
1980 struct scatterlist *sgde = NULL; /* s/g data entry */
1981 struct sli4_sge_diseed *diseed = NULL;
1982 dma_addr_t physaddr;
1983 int i = 0, num_sge = 0, status;
1986 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1989 uint32_t checking = 1;
1991 uint32_t dma_offset = 0;
1992 struct sli4_hybrid_sgl *sgl_xtra = NULL;
1994 bool lsp_just_set = false;
1996 status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
2000 /* extract some info from the scsi command for pde*/
2001 reftag = scsi_prot_ref_tag(sc);
2002 if (reftag == LPFC_INVALID_REFTAG)
2005 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2006 rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
2008 if (rc & BG_ERR_SWAP)
2009 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
2010 if (rc & BG_ERR_CHECK)
2015 /* setup DISEED with what we have */
2016 diseed = (struct sli4_sge_diseed *) sgl;
2017 memset(diseed, 0, sizeof(struct sli4_sge_diseed));
2018 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED);
2020 /* Endianness conversion if necessary */
2021 diseed->ref_tag = cpu_to_le32(reftag);
2022 diseed->ref_tag_tran = diseed->ref_tag;
2025 * We only need to check the data on READs, for WRITEs
2026 * protection data is automatically generated, not checked.
2028 if (sc->sc_data_direction == DMA_FROM_DEVICE) {
2029 if (sc->prot_flags & SCSI_PROT_GUARD_CHECK)
2030 bf_set(lpfc_sli4_sge_dif_ce, diseed, checking);
2032 bf_set(lpfc_sli4_sge_dif_ce, diseed, 0);
2034 if (sc->prot_flags & SCSI_PROT_REF_CHECK)
2035 bf_set(lpfc_sli4_sge_dif_re, diseed, checking);
2037 bf_set(lpfc_sli4_sge_dif_re, diseed, 0);
2040 /* setup DISEED with the rest of the info */
2041 bf_set(lpfc_sli4_sge_dif_optx, diseed, txop);
2042 bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop);
2044 bf_set(lpfc_sli4_sge_dif_ai, diseed, 1);
2045 bf_set(lpfc_sli4_sge_dif_me, diseed, 0);
2047 /* Endianness conversion if necessary for DISEED */
2048 diseed->word2 = cpu_to_le32(diseed->word2);
2049 diseed->word3 = cpu_to_le32(diseed->word3);
2051 /* advance bpl and increment sge count */
2055 /* assumption: caller has already run dma_map_sg on command data */
2056 sgde = scsi_sglist(sc);
2058 for (i = 0; i < datasegcnt; i++) {
2062 /* do we need to expand the segment */
2063 if (!lsp_just_set && !((j + 1) % phba->border_sge_num) &&
2064 ((datasegcnt - 1) != i)) {
2066 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_LSP);
2068 sgl_xtra = lpfc_get_sgl_per_hdwq(phba, lpfc_cmd);
2070 if (unlikely(!sgl_xtra)) {
2071 lpfc_cmd->seg_cnt = 0;
2074 sgl->addr_lo = cpu_to_le32(putPaddrLow(
2075 sgl_xtra->dma_phys_sgl));
2076 sgl->addr_hi = cpu_to_le32(putPaddrHigh(
2077 sgl_xtra->dma_phys_sgl));
2080 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA);
2083 if (!(bf_get(lpfc_sli4_sge_type, sgl) & LPFC_SGE_TYPE_LSP)) {
2084 if ((datasegcnt - 1) == i)
2085 bf_set(lpfc_sli4_sge_last, sgl, 1);
2086 physaddr = sg_dma_address(sgde);
2087 dma_len = sg_dma_len(sgde);
2088 sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr));
2089 sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr));
2091 bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
2092 sgl->word2 = cpu_to_le32(sgl->word2);
2093 sgl->sge_len = cpu_to_le32(dma_len);
2095 dma_offset += dma_len;
2096 sgde = sg_next(sgde);
2100 lsp_just_set = false;
2103 sgl->word2 = cpu_to_le32(sgl->word2);
2104 sgl->sge_len = cpu_to_le32(phba->cfg_sg_dma_buf_size);
2106 sgl = (struct sli4_sge *)sgl_xtra->dma_sgl;
2109 lsp_just_set = true;
2121 * lpfc_bg_setup_sgl_prot - Setup BlockGuard SGL with protection data
2122 * @phba: The Hba for which this call is being executed.
2123 * @sc: pointer to scsi command we're working on
2124 * @sgl: pointer to buffer list for protection groups
2125 * @datacnt: number of segments of data that have been dma mapped
2126 * @protcnt: number of segment of protection data that have been dma mapped
2127 * @lpfc_cmd: lpfc scsi command object pointer.
2129 * This function sets up SGL buffer list for protection groups of
2130 * type LPFC_PG_TYPE_DIF
2132 * This is usually used when DIFs are in their own buffers,
2133 * separate from the data. The HBA can then by instructed
2134 * to place the DIFs in the outgoing stream. For read operations,
2135 * The HBA could extract the DIFs and place it in DIF buffers.
2137 * The buffer list for this type consists of one or more of the
2138 * protection groups described below:
2139 * +-------------------------+
2140 * start of first prot group --> | DISEED |
2141 * +-------------------------+
2142 * | DIF (Prot SGE) |
2143 * +-------------------------+
2145 * +-------------------------+
2146 * |more Data SGE's ... (opt)|
2147 * +-------------------------+
2148 * start of new prot group --> | DISEED |
2149 * +-------------------------+
2151 * +-------------------------+
2153 * Note: It is assumed that both data and protection s/g buffers have been
2156 * Returns the number of SGEs added to the SGL.
2159 lpfc_bg_setup_sgl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc,
2160 struct sli4_sge *sgl, int datacnt, int protcnt,
2161 struct lpfc_io_buf *lpfc_cmd)
2163 struct scatterlist *sgde = NULL; /* s/g data entry */
2164 struct scatterlist *sgpe = NULL; /* s/g prot entry */
2165 struct sli4_sge_diseed *diseed = NULL;
2166 dma_addr_t dataphysaddr, protphysaddr;
2167 unsigned short curr_data = 0, curr_prot = 0;
2168 unsigned int split_offset;
2169 unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder;
2170 unsigned int protgrp_blks, protgrp_bytes;
2171 unsigned int remainder, subtotal;
2173 unsigned char pgdone = 0, alldone = 0;
2178 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2181 uint32_t checking = 1;
2182 uint32_t dma_offset = 0;
2183 int num_sge = 0, j = 2;
2184 struct sli4_hybrid_sgl *sgl_xtra = NULL;
2186 sgpe = scsi_prot_sglist(sc);
2187 sgde = scsi_sglist(sc);
2189 if (!sgpe || !sgde) {
2190 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2191 "9082 Invalid s/g entry: data=x%px prot=x%px\n",
2196 status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
2200 /* extract some info from the scsi command */
2201 blksize = scsi_prot_interval(sc);
2202 reftag = scsi_prot_ref_tag(sc);
2203 if (reftag == LPFC_INVALID_REFTAG)
2206 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2207 rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
2209 if (rc & BG_ERR_SWAP)
2210 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
2211 if (rc & BG_ERR_CHECK)
2218 /* Check to see if we ran out of space */
2219 if ((num_sge >= (phba->cfg_total_seg_cnt - 2)) &&
2223 /* DISEED and DIF have to be together */
2224 if (!((j + 1) % phba->border_sge_num) ||
2225 !((j + 2) % phba->border_sge_num) ||
2226 !((j + 3) % phba->border_sge_num)) {
2230 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_LSP);
2232 sgl_xtra = lpfc_get_sgl_per_hdwq(phba, lpfc_cmd);
2234 if (unlikely(!sgl_xtra)) {
2237 sgl->addr_lo = cpu_to_le32(putPaddrLow(
2238 sgl_xtra->dma_phys_sgl));
2239 sgl->addr_hi = cpu_to_le32(putPaddrHigh(
2240 sgl_xtra->dma_phys_sgl));
2243 sgl->word2 = cpu_to_le32(sgl->word2);
2244 sgl->sge_len = cpu_to_le32(phba->cfg_sg_dma_buf_size);
2246 sgl = (struct sli4_sge *)sgl_xtra->dma_sgl;
2250 /* setup DISEED with what we have */
2251 diseed = (struct sli4_sge_diseed *) sgl;
2252 memset(diseed, 0, sizeof(struct sli4_sge_diseed));
2253 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED);
2255 /* Endianness conversion if necessary */
2256 diseed->ref_tag = cpu_to_le32(reftag);
2257 diseed->ref_tag_tran = diseed->ref_tag;
2259 if (sc->prot_flags & SCSI_PROT_GUARD_CHECK) {
2260 bf_set(lpfc_sli4_sge_dif_ce, diseed, checking);
2262 bf_set(lpfc_sli4_sge_dif_ce, diseed, 0);
2264 * When in this mode, the hardware will replace
2265 * the guard tag from the host with a
2266 * newly generated good CRC for the wire.
2267 * Switch to raw mode here to avoid this
2268 * behavior. What the host sends gets put on the wire.
2270 if (txop == BG_OP_IN_CRC_OUT_CRC) {
2271 txop = BG_OP_RAW_MODE;
2272 rxop = BG_OP_RAW_MODE;
2277 if (sc->prot_flags & SCSI_PROT_REF_CHECK)
2278 bf_set(lpfc_sli4_sge_dif_re, diseed, checking);
2280 bf_set(lpfc_sli4_sge_dif_re, diseed, 0);
2282 /* setup DISEED with the rest of the info */
2283 bf_set(lpfc_sli4_sge_dif_optx, diseed, txop);
2284 bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop);
2286 bf_set(lpfc_sli4_sge_dif_ai, diseed, 1);
2287 bf_set(lpfc_sli4_sge_dif_me, diseed, 0);
2289 /* Endianness conversion if necessary for DISEED */
2290 diseed->word2 = cpu_to_le32(diseed->word2);
2291 diseed->word3 = cpu_to_le32(diseed->word3);
2293 /* advance sgl and increment bde count */
2299 /* setup the first BDE that points to protection buffer */
2300 protphysaddr = sg_dma_address(sgpe) + protgroup_offset;
2301 protgroup_len = sg_dma_len(sgpe) - protgroup_offset;
2303 /* must be integer multiple of the DIF block length */
2304 BUG_ON(protgroup_len % 8);
2306 /* Now setup DIF SGE */
2308 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DIF);
2309 sgl->addr_hi = le32_to_cpu(putPaddrHigh(protphysaddr));
2310 sgl->addr_lo = le32_to_cpu(putPaddrLow(protphysaddr));
2311 sgl->word2 = cpu_to_le32(sgl->word2);
2314 protgrp_blks = protgroup_len / 8;
2315 protgrp_bytes = protgrp_blks * blksize;
2317 /* check if DIF SGE is crossing the 4K boundary; if so split */
2318 if ((sgl->addr_lo & 0xfff) + protgroup_len > 0x1000) {
2319 protgroup_remainder = 0x1000 - (sgl->addr_lo & 0xfff);
2320 protgroup_offset += protgroup_remainder;
2321 protgrp_blks = protgroup_remainder / 8;
2322 protgrp_bytes = protgrp_blks * blksize;
2324 protgroup_offset = 0;
2330 /* setup SGE's for data blocks associated with DIF data */
2332 subtotal = 0; /* total bytes processed for current prot grp */
2338 /* Check to see if we ran out of space */
2339 if ((num_sge >= phba->cfg_total_seg_cnt) &&
2344 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2345 "9086 BLKGRD:%s Invalid data segment\n",
2350 if (!((j + 1) % phba->border_sge_num)) {
2354 bf_set(lpfc_sli4_sge_type, sgl,
2357 sgl_xtra = lpfc_get_sgl_per_hdwq(phba,
2360 if (unlikely(!sgl_xtra)) {
2363 sgl->addr_lo = cpu_to_le32(
2364 putPaddrLow(sgl_xtra->dma_phys_sgl));
2365 sgl->addr_hi = cpu_to_le32(
2366 putPaddrHigh(sgl_xtra->dma_phys_sgl));
2369 sgl->word2 = cpu_to_le32(sgl->word2);
2370 sgl->sge_len = cpu_to_le32(
2371 phba->cfg_sg_dma_buf_size);
2373 sgl = (struct sli4_sge *)sgl_xtra->dma_sgl;
2375 dataphysaddr = sg_dma_address(sgde) +
2378 remainder = sg_dma_len(sgde) - split_offset;
2380 if ((subtotal + remainder) <= protgrp_bytes) {
2381 /* we can use this whole buffer */
2382 dma_len = remainder;
2385 if ((subtotal + remainder) ==
2389 /* must split this buffer with next
2392 dma_len = protgrp_bytes - subtotal;
2393 split_offset += dma_len;
2396 subtotal += dma_len;
2399 sgl->addr_lo = cpu_to_le32(putPaddrLow(
2401 sgl->addr_hi = cpu_to_le32(putPaddrHigh(
2403 bf_set(lpfc_sli4_sge_last, sgl, 0);
2404 bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
2405 bf_set(lpfc_sli4_sge_type, sgl,
2406 LPFC_SGE_TYPE_DATA);
2408 sgl->sge_len = cpu_to_le32(dma_len);
2409 dma_offset += dma_len;
2420 /* Move to the next s/g segment if possible */
2421 sgde = sg_next(sgde);
2429 if (protgroup_offset) {
2430 /* update the reference tag */
2431 reftag += protgrp_blks;
2436 if (curr_prot == protcnt) {
2437 /* mark the last SGL */
2439 bf_set(lpfc_sli4_sge_last, sgl, 1);
2441 } else if (curr_prot < protcnt) {
2442 /* advance to next prot buffer */
2443 sgpe = sg_next(sgpe);
2445 /* update the reference tag */
2446 reftag += protgrp_blks;
2448 /* if we're here, we have a bug */
2449 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2450 "9085 BLKGRD: bug in %s\n", __func__);
2461 * lpfc_prot_group_type - Get prtotection group type of SCSI command
2462 * @phba: The Hba for which this call is being executed.
2463 * @sc: pointer to scsi command we're working on
2465 * Given a SCSI command that supports DIF, determine composition of protection
2466 * groups involved in setting up buffer lists
2468 * Returns: Protection group type (with or without DIF)
2472 lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc)
2474 int ret = LPFC_PG_TYPE_INVALID;
2475 unsigned char op = scsi_get_prot_op(sc);
2478 case SCSI_PROT_READ_STRIP:
2479 case SCSI_PROT_WRITE_INSERT:
2480 ret = LPFC_PG_TYPE_NO_DIF;
2482 case SCSI_PROT_READ_INSERT:
2483 case SCSI_PROT_WRITE_STRIP:
2484 case SCSI_PROT_READ_PASS:
2485 case SCSI_PROT_WRITE_PASS:
2486 ret = LPFC_PG_TYPE_DIF_BUF;
2490 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2491 "9021 Unsupported protection op:%d\n",
2499 * lpfc_bg_scsi_adjust_dl - Adjust SCSI data length for BlockGuard
2500 * @phba: The Hba for which this call is being executed.
2501 * @lpfc_cmd: The scsi buffer which is going to be adjusted.
2503 * Adjust the data length to account for how much data
2504 * is actually on the wire.
2506 * returns the adjusted data length
2509 lpfc_bg_scsi_adjust_dl(struct lpfc_hba *phba,
2510 struct lpfc_io_buf *lpfc_cmd)
2512 struct scsi_cmnd *sc = lpfc_cmd->pCmd;
2515 fcpdl = scsi_bufflen(sc);
2517 /* Check if there is protection data on the wire */
2518 if (sc->sc_data_direction == DMA_FROM_DEVICE) {
2519 /* Read check for protection data */
2520 if (scsi_get_prot_op(sc) == SCSI_PROT_READ_INSERT)
2524 /* Write check for protection data */
2525 if (scsi_get_prot_op(sc) == SCSI_PROT_WRITE_STRIP)
2530 * If we are in DIF Type 1 mode every data block has a 8 byte
2531 * DIF (trailer) attached to it. Must ajust FCP data length
2532 * to account for the protection data.
2534 fcpdl += (fcpdl / scsi_prot_interval(sc)) * 8;
2540 * lpfc_bg_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
2541 * @phba: The Hba for which this call is being executed.
2542 * @lpfc_cmd: The scsi buffer which is going to be prep'ed.
2544 * This is the protection/DIF aware version of
2545 * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the
2546 * two functions eventually, but for now, it's here.
2547 * RETURNS 0 - SUCCESS,
2548 * 1 - Failed DMA map, retry.
2549 * 2 - Invalid scsi cmd or prot-type. Do not rety.
2552 lpfc_bg_scsi_prep_dma_buf_s3(struct lpfc_hba *phba,
2553 struct lpfc_io_buf *lpfc_cmd)
2555 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
2556 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
2557 struct ulp_bde64 *bpl = (struct ulp_bde64 *)lpfc_cmd->dma_sgl;
2558 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
2559 uint32_t num_bde = 0;
2560 int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction;
2561 int prot_group_type = 0;
2564 struct lpfc_vport *vport = phba->pport;
2567 * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd
2568 * fcp_rsp regions to the first data bde entry
2571 if (scsi_sg_count(scsi_cmnd)) {
2573 * The driver stores the segment count returned from pci_map_sg
2574 * because this a count of dma-mappings used to map the use_sg
2575 * pages. They are not guaranteed to be the same for those
2576 * architectures that implement an IOMMU.
2578 datasegcnt = dma_map_sg(&phba->pcidev->dev,
2579 scsi_sglist(scsi_cmnd),
2580 scsi_sg_count(scsi_cmnd), datadir);
2581 if (unlikely(!datasegcnt))
2584 lpfc_cmd->seg_cnt = datasegcnt;
2586 /* First check if data segment count from SCSI Layer is good */
2587 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
2588 WARN_ON_ONCE(lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt);
2593 prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd);
2595 switch (prot_group_type) {
2596 case LPFC_PG_TYPE_NO_DIF:
2598 /* Here we need to add a PDE5 and PDE6 to the count */
2599 if ((lpfc_cmd->seg_cnt + 2) > phba->cfg_total_seg_cnt) {
2604 num_bde = lpfc_bg_setup_bpl(phba, scsi_cmnd, bpl,
2606 /* we should have 2 or more entries in buffer list */
2613 case LPFC_PG_TYPE_DIF_BUF:
2615 * This type indicates that protection buffers are
2616 * passed to the driver, so that needs to be prepared
2619 protsegcnt = dma_map_sg(&phba->pcidev->dev,
2620 scsi_prot_sglist(scsi_cmnd),
2621 scsi_prot_sg_count(scsi_cmnd), datadir);
2622 if (unlikely(!protsegcnt)) {
2623 scsi_dma_unmap(scsi_cmnd);
2627 lpfc_cmd->prot_seg_cnt = protsegcnt;
2630 * There is a minimun of 4 BPLs used for every
2631 * protection data segment.
2633 if ((lpfc_cmd->prot_seg_cnt * 4) >
2634 (phba->cfg_total_seg_cnt - 2)) {
2639 num_bde = lpfc_bg_setup_bpl_prot(phba, scsi_cmnd, bpl,
2640 datasegcnt, protsegcnt);
2641 /* we should have 3 or more entries in buffer list */
2642 if ((num_bde < 3) ||
2643 (num_bde > phba->cfg_total_seg_cnt)) {
2649 case LPFC_PG_TYPE_INVALID:
2651 scsi_dma_unmap(scsi_cmnd);
2652 lpfc_cmd->seg_cnt = 0;
2654 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2655 "9022 Unexpected protection group %i\n",
2662 * Finish initializing those IOCB fields that are dependent on the
2663 * scsi_cmnd request_buffer. Note that the bdeSize is explicitly
2664 * reinitialized since all iocb memory resources are used many times
2665 * for transmit, receive, and continuation bpl's.
2667 iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
2668 iocb_cmd->un.fcpi64.bdl.bdeSize += (num_bde * sizeof(struct ulp_bde64));
2669 iocb_cmd->ulpBdeCount = 1;
2670 iocb_cmd->ulpLe = 1;
2672 fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd);
2673 fcp_cmnd->fcpDl = be32_to_cpu(fcpdl);
2676 * Due to difference in data length between DIF/non-DIF paths,
2677 * we need to set word 4 of IOCB here
2679 iocb_cmd->un.fcpi.fcpi_parm = fcpdl;
2682 * For First burst, we may need to adjust the initial transfer
2685 if (iocb_cmd->un.fcpi.fcpi_XRdy &&
2686 (fcpdl < vport->cfg_first_burst_size))
2687 iocb_cmd->un.fcpi.fcpi_XRdy = fcpdl;
2691 if (lpfc_cmd->seg_cnt)
2692 scsi_dma_unmap(scsi_cmnd);
2693 if (lpfc_cmd->prot_seg_cnt)
2694 dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd),
2695 scsi_prot_sg_count(scsi_cmnd),
2696 scsi_cmnd->sc_data_direction);
2698 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2699 "9023 Cannot setup S/G List for HBA"
2700 "IO segs %d/%d BPL %d SCSI %d: %d %d\n",
2701 lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt,
2702 phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt,
2703 prot_group_type, num_bde);
2705 lpfc_cmd->seg_cnt = 0;
2706 lpfc_cmd->prot_seg_cnt = 0;
2711 * This function calcuates the T10 DIF guard tag
2712 * on the specified data using a CRC algorithmn
2716 lpfc_bg_crc(uint8_t *data, int count)
2721 crc = crc_t10dif(data, count);
2722 x = cpu_to_be16(crc);
2727 * This function calcuates the T10 DIF guard tag
2728 * on the specified data using a CSUM algorithmn
2729 * using ip_compute_csum.
2732 lpfc_bg_csum(uint8_t *data, int count)
2736 ret = ip_compute_csum(data, count);
2741 * This function examines the protection data to try to determine
2742 * what type of T10-DIF error occurred.
2745 lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
2747 struct scatterlist *sgpe; /* s/g prot entry */
2748 struct scatterlist *sgde; /* s/g data entry */
2749 struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
2750 struct scsi_dif_tuple *src = NULL;
2751 uint8_t *data_src = NULL;
2753 uint16_t start_app_tag, app_tag;
2754 uint32_t start_ref_tag, ref_tag;
2755 int prot, protsegcnt;
2756 int err_type, len, data_len;
2757 int chk_ref, chk_app, chk_guard;
2761 err_type = BGS_GUARD_ERR_MASK;
2765 /* First check to see if there is protection data to examine */
2766 prot = scsi_get_prot_op(cmd);
2767 if ((prot == SCSI_PROT_READ_STRIP) ||
2768 (prot == SCSI_PROT_WRITE_INSERT) ||
2769 (prot == SCSI_PROT_NORMAL))
2772 /* Currently the driver just supports ref_tag and guard_tag checking */
2777 /* Setup a ptr to the protection data provided by the SCSI host */
2778 sgpe = scsi_prot_sglist(cmd);
2779 protsegcnt = lpfc_cmd->prot_seg_cnt;
2781 if (sgpe && protsegcnt) {
2784 * We will only try to verify guard tag if the segment
2785 * data length is a multiple of the blksize.
2787 sgde = scsi_sglist(cmd);
2788 blksize = scsi_prot_interval(cmd);
2789 data_src = (uint8_t *)sg_virt(sgde);
2790 data_len = sgde->length;
2791 if ((data_len & (blksize - 1)) == 0)
2794 src = (struct scsi_dif_tuple *)sg_virt(sgpe);
2795 start_ref_tag = scsi_prot_ref_tag(cmd);
2796 if (start_ref_tag == LPFC_INVALID_REFTAG)
2798 start_app_tag = src->app_tag;
2800 while (src && protsegcnt) {
2804 * First check to see if a protection data
2807 if ((src->ref_tag == T10_PI_REF_ESCAPE) ||
2808 (src->app_tag == T10_PI_APP_ESCAPE)) {
2813 /* First Guard Tag checking */
2815 guard_tag = src->guard_tag;
2817 & SCSI_PROT_IP_CHECKSUM)
2818 sum = lpfc_bg_csum(data_src,
2821 sum = lpfc_bg_crc(data_src,
2823 if ((guard_tag != sum)) {
2824 err_type = BGS_GUARD_ERR_MASK;
2829 /* Reference Tag checking */
2830 ref_tag = be32_to_cpu(src->ref_tag);
2831 if (chk_ref && (ref_tag != start_ref_tag)) {
2832 err_type = BGS_REFTAG_ERR_MASK;
2837 /* App Tag checking */
2838 app_tag = src->app_tag;
2839 if (chk_app && (app_tag != start_app_tag)) {
2840 err_type = BGS_APPTAG_ERR_MASK;
2844 len -= sizeof(struct scsi_dif_tuple);
2849 data_src += blksize;
2850 data_len -= blksize;
2853 * Are we at the end of the Data segment?
2854 * The data segment is only used for Guard
2857 if (chk_guard && (data_len == 0)) {
2859 sgde = sg_next(sgde);
2863 data_src = (uint8_t *)sg_virt(sgde);
2864 data_len = sgde->length;
2865 if ((data_len & (blksize - 1)) == 0)
2870 /* Goto the next Protection data segment */
2871 sgpe = sg_next(sgpe);
2873 src = (struct scsi_dif_tuple *)sg_virt(sgpe);
2882 if (err_type == BGS_GUARD_ERR_MASK) {
2883 scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x1);
2884 set_host_byte(cmd, DID_ABORT);
2885 phba->bg_guard_err_cnt++;
2886 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
2887 "9069 BLKGRD: reftag %x grd_tag err %x != %x\n",
2888 scsi_prot_ref_tag(cmd),
2891 } else if (err_type == BGS_REFTAG_ERR_MASK) {
2892 scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x3);
2893 set_host_byte(cmd, DID_ABORT);
2895 phba->bg_reftag_err_cnt++;
2896 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
2897 "9066 BLKGRD: reftag %x ref_tag err %x != %x\n",
2898 scsi_prot_ref_tag(cmd),
2899 ref_tag, start_ref_tag);
2901 } else if (err_type == BGS_APPTAG_ERR_MASK) {
2902 scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x2);
2903 set_host_byte(cmd, DID_ABORT);
2905 phba->bg_apptag_err_cnt++;
2906 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
2907 "9041 BLKGRD: reftag %x app_tag err %x != %x\n",
2908 scsi_prot_ref_tag(cmd),
2909 app_tag, start_app_tag);
2914 * This function checks for BlockGuard errors detected by
2915 * the HBA. In case of errors, the ASC/ASCQ fields in the
2916 * sense buffer will be set accordingly, paired with
2917 * ILLEGAL_REQUEST to signal to the kernel that the HBA
2918 * detected corruption.
2921 * 0 - No error found
2922 * 1 - BlockGuard error found
2923 * -1 - Internal error (bad profile, ...etc)
2926 lpfc_sli4_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
2927 struct lpfc_wcqe_complete *wcqe)
2929 struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
2931 u32 status = bf_get(lpfc_wcqe_c_status, wcqe);
2934 u64 failing_sector = 0;
2936 if (status == CQE_STATUS_DI_ERROR) {
2937 if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */
2938 bgstat |= BGS_GUARD_ERR_MASK;
2939 if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* AppTag Check failed */
2940 bgstat |= BGS_APPTAG_ERR_MASK;
2941 if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* RefTag Check failed */
2942 bgstat |= BGS_REFTAG_ERR_MASK;
2944 /* Check to see if there was any good data before the error */
2945 if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) {
2946 bgstat |= BGS_HI_WATER_MARK_PRESENT_MASK;
2947 bghm = wcqe->total_data_placed;
2951 * Set ALL the error bits to indicate we don't know what
2952 * type of error it is.
2955 bgstat |= (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK |
2956 BGS_GUARD_ERR_MASK);
2959 if (lpfc_bgs_get_guard_err(bgstat)) {
2962 scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x1);
2963 set_host_byte(cmd, DID_ABORT);
2964 phba->bg_guard_err_cnt++;
2965 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
2966 "9059 BLKGRD: Guard Tag error in cmd"
2967 " 0x%x lba 0x%llx blk cnt 0x%x "
2968 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
2969 (unsigned long long)scsi_get_lba(cmd),
2970 scsi_logical_block_count(cmd), bgstat, bghm);
2973 if (lpfc_bgs_get_reftag_err(bgstat)) {
2976 scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x3);
2977 set_host_byte(cmd, DID_ABORT);
2979 phba->bg_reftag_err_cnt++;
2980 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
2981 "9060 BLKGRD: Ref Tag error in cmd"
2982 " 0x%x lba 0x%llx blk cnt 0x%x "
2983 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
2984 (unsigned long long)scsi_get_lba(cmd),
2985 scsi_logical_block_count(cmd), bgstat, bghm);
2988 if (lpfc_bgs_get_apptag_err(bgstat)) {
2991 scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x2);
2992 set_host_byte(cmd, DID_ABORT);
2994 phba->bg_apptag_err_cnt++;
2995 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
2996 "9062 BLKGRD: App Tag error in cmd"
2997 " 0x%x lba 0x%llx blk cnt 0x%x "
2998 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
2999 (unsigned long long)scsi_get_lba(cmd),
3000 scsi_logical_block_count(cmd), bgstat, bghm);
3003 if (lpfc_bgs_get_hi_water_mark_present(bgstat)) {
3005 * setup sense data descriptor 0 per SPC-4 as an information
3006 * field, and put the failing LBA in it.
3007 * This code assumes there was also a guard/app/ref tag error
3010 cmd->sense_buffer[7] = 0xc; /* Additional sense length */
3011 cmd->sense_buffer[8] = 0; /* Information descriptor type */
3012 cmd->sense_buffer[9] = 0xa; /* Additional descriptor length */
3013 cmd->sense_buffer[10] = 0x80; /* Validity bit */
3015 /* bghm is a "on the wire" FC frame based count */
3016 switch (scsi_get_prot_op(cmd)) {
3017 case SCSI_PROT_READ_INSERT:
3018 case SCSI_PROT_WRITE_STRIP:
3019 bghm /= cmd->device->sector_size;
3021 case SCSI_PROT_READ_STRIP:
3022 case SCSI_PROT_WRITE_INSERT:
3023 case SCSI_PROT_READ_PASS:
3024 case SCSI_PROT_WRITE_PASS:
3025 bghm /= (cmd->device->sector_size +
3026 sizeof(struct scsi_dif_tuple));
3030 failing_sector = scsi_get_lba(cmd);
3031 failing_sector += bghm;
3033 /* Descriptor Information */
3034 put_unaligned_be64(failing_sector, &cmd->sense_buffer[12]);
3038 /* No error was reported - problem in FW? */
3039 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
3040 "9068 BLKGRD: Unknown error in cmd"
3041 " 0x%x lba 0x%llx blk cnt 0x%x "
3042 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
3043 (unsigned long long)scsi_get_lba(cmd),
3044 scsi_logical_block_count(cmd), bgstat, bghm);
3046 /* Calculate what type of error it was */
3047 lpfc_calc_bg_err(phba, lpfc_cmd);
3053 * This function checks for BlockGuard errors detected by
3054 * the HBA. In case of errors, the ASC/ASCQ fields in the
3055 * sense buffer will be set accordingly, paired with
3056 * ILLEGAL_REQUEST to signal to the kernel that the HBA
3057 * detected corruption.
3060 * 0 - No error found
3061 * 1 - BlockGuard error found
3062 * -1 - Internal error (bad profile, ...etc)
3065 lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
3066 struct lpfc_iocbq *pIocbOut)
3068 struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
3069 struct sli3_bg_fields *bgf = &pIocbOut->iocb.unsli3.sli3_bg;
3071 uint32_t bghm = bgf->bghm;
3072 uint32_t bgstat = bgf->bgstat;
3073 uint64_t failing_sector = 0;
3075 if (lpfc_bgs_get_invalid_prof(bgstat)) {
3076 cmd->result = DID_ERROR << 16;
3077 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
3078 "9072 BLKGRD: Invalid BG Profile in cmd "
3079 "0x%x reftag 0x%x blk cnt 0x%x "
3080 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
3081 scsi_prot_ref_tag(cmd),
3082 scsi_logical_block_count(cmd), bgstat, bghm);
3087 if (lpfc_bgs_get_uninit_dif_block(bgstat)) {
3088 cmd->result = DID_ERROR << 16;
3089 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
3090 "9073 BLKGRD: Invalid BG PDIF Block in cmd "
3091 "0x%x reftag 0x%x blk cnt 0x%x "
3092 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
3093 scsi_prot_ref_tag(cmd),
3094 scsi_logical_block_count(cmd), bgstat, bghm);
3099 if (lpfc_bgs_get_guard_err(bgstat)) {
3102 scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x1);
3103 set_host_byte(cmd, DID_ABORT);
3104 phba->bg_guard_err_cnt++;
3105 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
3106 "9055 BLKGRD: Guard Tag error in cmd "
3107 "0x%x reftag 0x%x blk cnt 0x%x "
3108 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
3109 scsi_prot_ref_tag(cmd),
3110 scsi_logical_block_count(cmd), bgstat, bghm);
3113 if (lpfc_bgs_get_reftag_err(bgstat)) {
3116 scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x3);
3117 set_host_byte(cmd, DID_ABORT);
3119 phba->bg_reftag_err_cnt++;
3120 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
3121 "9056 BLKGRD: Ref Tag error in cmd "
3122 "0x%x reftag 0x%x blk cnt 0x%x "
3123 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
3124 scsi_prot_ref_tag(cmd),
3125 scsi_logical_block_count(cmd), bgstat, bghm);
3128 if (lpfc_bgs_get_apptag_err(bgstat)) {
3131 scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x2);
3132 set_host_byte(cmd, DID_ABORT);
3134 phba->bg_apptag_err_cnt++;
3135 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
3136 "9061 BLKGRD: App Tag error in cmd "
3137 "0x%x reftag 0x%x blk cnt 0x%x "
3138 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
3139 scsi_prot_ref_tag(cmd),
3140 scsi_logical_block_count(cmd), bgstat, bghm);
3143 if (lpfc_bgs_get_hi_water_mark_present(bgstat)) {
3145 * setup sense data descriptor 0 per SPC-4 as an information
3146 * field, and put the failing LBA in it.
3147 * This code assumes there was also a guard/app/ref tag error
3150 cmd->sense_buffer[7] = 0xc; /* Additional sense length */
3151 cmd->sense_buffer[8] = 0; /* Information descriptor type */
3152 cmd->sense_buffer[9] = 0xa; /* Additional descriptor length */
3153 cmd->sense_buffer[10] = 0x80; /* Validity bit */
3155 /* bghm is a "on the wire" FC frame based count */
3156 switch (scsi_get_prot_op(cmd)) {
3157 case SCSI_PROT_READ_INSERT:
3158 case SCSI_PROT_WRITE_STRIP:
3159 bghm /= cmd->device->sector_size;
3161 case SCSI_PROT_READ_STRIP:
3162 case SCSI_PROT_WRITE_INSERT:
3163 case SCSI_PROT_READ_PASS:
3164 case SCSI_PROT_WRITE_PASS:
3165 bghm /= (cmd->device->sector_size +
3166 sizeof(struct scsi_dif_tuple));
3170 failing_sector = scsi_get_lba(cmd);
3171 failing_sector += bghm;
3173 /* Descriptor Information */
3174 put_unaligned_be64(failing_sector, &cmd->sense_buffer[12]);
3178 /* No error was reported - problem in FW? */
3179 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
3180 "9057 BLKGRD: Unknown error in cmd "
3181 "0x%x reftag 0x%x blk cnt 0x%x "
3182 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
3183 scsi_prot_ref_tag(cmd),
3184 scsi_logical_block_count(cmd), bgstat, bghm);
3186 /* Calculate what type of error it was */
3187 lpfc_calc_bg_err(phba, lpfc_cmd);
3194 * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
3195 * @phba: The Hba for which this call is being executed.
3196 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3198 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
3199 * field of @lpfc_cmd for device with SLI-4 interface spec.
3202 * 2 - Error - Do not retry
3207 lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
3209 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
3210 struct scatterlist *sgel = NULL;
3211 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
3212 struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
3213 struct sli4_sge *first_data_sgl;
3214 struct lpfc_iocbq *pwqeq = &lpfc_cmd->cur_iocbq;
3215 struct lpfc_vport *vport = phba->pport;
3216 union lpfc_wqe128 *wqe = &pwqeq->wqe;
3217 dma_addr_t physaddr;
3218 uint32_t num_bde = 0;
3220 uint32_t dma_offset = 0;
3222 struct ulp_bde64 *bde;
3223 bool lsp_just_set = false;
3224 struct sli4_hybrid_sgl *sgl_xtra = NULL;
3227 * There are three possibilities here - use scatter-gather segment, use
3228 * the single mapping, or neither. Start the lpfc command prep by
3229 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
3232 if (scsi_sg_count(scsi_cmnd)) {
3234 * The driver stores the segment count returned from pci_map_sg
3235 * because this a count of dma-mappings used to map the use_sg
3236 * pages. They are not guaranteed to be the same for those
3237 * architectures that implement an IOMMU.
3240 nseg = scsi_dma_map(scsi_cmnd);
3241 if (unlikely(nseg <= 0))
3244 /* clear the last flag in the fcp_rsp map entry */
3245 sgl->word2 = le32_to_cpu(sgl->word2);
3246 bf_set(lpfc_sli4_sge_last, sgl, 0);
3247 sgl->word2 = cpu_to_le32(sgl->word2);
3249 first_data_sgl = sgl;
3250 lpfc_cmd->seg_cnt = nseg;
3251 if (!phba->cfg_xpsgl &&
3252 lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
3253 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3255 " %s: Too many sg segments from "
3256 "dma_map_sg. Config %d, seg_cnt %d\n",
3257 __func__, phba->cfg_sg_seg_cnt,
3259 WARN_ON_ONCE(lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt);
3260 lpfc_cmd->seg_cnt = 0;
3261 scsi_dma_unmap(scsi_cmnd);
3266 * The driver established a maximum scatter-gather segment count
3267 * during probe that limits the number of sg elements in any
3268 * single scsi command. Just run through the seg_cnt and format
3270 * When using SLI-3 the driver will try to fit all the BDEs into
3271 * the IOCB. If it can't then the BDEs get added to a BPL as it
3272 * does for SLI-2 mode.
3275 /* for tracking segment boundaries */
3276 sgel = scsi_sglist(scsi_cmnd);
3278 for (i = 0; i < nseg; i++) {
3280 if ((num_bde + 1) == nseg) {
3281 bf_set(lpfc_sli4_sge_last, sgl, 1);
3282 bf_set(lpfc_sli4_sge_type, sgl,
3283 LPFC_SGE_TYPE_DATA);
3285 bf_set(lpfc_sli4_sge_last, sgl, 0);
3287 /* do we need to expand the segment */
3288 if (!lsp_just_set &&
3289 !((j + 1) % phba->border_sge_num) &&
3290 ((nseg - 1) != i)) {
3292 bf_set(lpfc_sli4_sge_type, sgl,
3295 sgl_xtra = lpfc_get_sgl_per_hdwq(
3298 if (unlikely(!sgl_xtra)) {
3299 lpfc_cmd->seg_cnt = 0;
3300 scsi_dma_unmap(scsi_cmnd);
3303 sgl->addr_lo = cpu_to_le32(putPaddrLow(
3304 sgl_xtra->dma_phys_sgl));
3305 sgl->addr_hi = cpu_to_le32(putPaddrHigh(
3306 sgl_xtra->dma_phys_sgl));
3309 bf_set(lpfc_sli4_sge_type, sgl,
3310 LPFC_SGE_TYPE_DATA);
3314 if (!(bf_get(lpfc_sli4_sge_type, sgl) &
3315 LPFC_SGE_TYPE_LSP)) {
3316 if ((nseg - 1) == i)
3317 bf_set(lpfc_sli4_sge_last, sgl, 1);
3319 physaddr = sg_dma_address(sgel);
3320 dma_len = sg_dma_len(sgel);
3321 sgl->addr_lo = cpu_to_le32(putPaddrLow(
3323 sgl->addr_hi = cpu_to_le32(putPaddrHigh(
3326 bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
3327 sgl->word2 = cpu_to_le32(sgl->word2);
3328 sgl->sge_len = cpu_to_le32(dma_len);
3330 dma_offset += dma_len;
3331 sgel = sg_next(sgel);
3334 lsp_just_set = false;
3337 sgl->word2 = cpu_to_le32(sgl->word2);
3338 sgl->sge_len = cpu_to_le32(
3339 phba->cfg_sg_dma_buf_size);
3341 sgl = (struct sli4_sge *)sgl_xtra->dma_sgl;
3344 lsp_just_set = true;
3350 * Setup the first Payload BDE. For FCoE we just key off
3351 * Performance Hints, for FC we use lpfc_enable_pbde.
3352 * We populate words 13-15 of IOCB/WQE.
3354 if ((phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) ||
3355 phba->cfg_enable_pbde) {
3356 bde = (struct ulp_bde64 *)
3358 bde->addrLow = first_data_sgl->addr_lo;
3359 bde->addrHigh = first_data_sgl->addr_hi;
3360 bde->tus.f.bdeSize =
3361 le32_to_cpu(first_data_sgl->sge_len);
3362 bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
3363 bde->tus.w = cpu_to_le32(bde->tus.w);
3366 memset(&wqe->words[13], 0, (sizeof(uint32_t) * 3));
3370 /* clear the last flag in the fcp_rsp map entry */
3371 sgl->word2 = le32_to_cpu(sgl->word2);
3372 bf_set(lpfc_sli4_sge_last, sgl, 1);
3373 sgl->word2 = cpu_to_le32(sgl->word2);
3375 if ((phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) ||
3376 phba->cfg_enable_pbde) {
3377 bde = (struct ulp_bde64 *)
3379 memset(bde, 0, (sizeof(uint32_t) * 3));
3384 if (phba->cfg_enable_pbde)
3385 bf_set(wqe_pbde, &wqe->generic.wqe_com, 1);
3388 * Finish initializing those IOCB fields that are dependent on the
3389 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
3390 * explicitly reinitialized.
3391 * all iocb memory resources are reused.
3393 fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd));
3394 /* Set first-burst provided it was successfully negotiated */
3395 if (!(phba->hba_flag & HBA_FCOE_MODE) &&
3396 vport->cfg_first_burst_size &&
3397 scsi_cmnd->sc_data_direction == DMA_TO_DEVICE) {
3398 u32 init_len, total_len;
3400 total_len = be32_to_cpu(fcp_cmnd->fcpDl);
3401 init_len = min(total_len, vport->cfg_first_burst_size);
3404 wqe->fcp_iwrite.initial_xfer_len = init_len;
3405 wqe->fcp_iwrite.total_xfer_len = total_len;
3408 wqe->fcp_iwrite.total_xfer_len =
3409 be32_to_cpu(fcp_cmnd->fcpDl);
3413 * If the OAS driver feature is enabled and the lun is enabled for
3414 * OAS, set the oas iocb related flags.
3416 if ((phba->cfg_fof) && ((struct lpfc_device_data *)
3417 scsi_cmnd->device->hostdata)->oas_enabled) {
3418 lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF);
3419 lpfc_cmd->cur_iocbq.priority = ((struct lpfc_device_data *)
3420 scsi_cmnd->device->hostdata)->priority;
3423 bf_set(wqe_oas, &wqe->generic.wqe_com, 1);
3424 bf_set(wqe_ccpe, &wqe->generic.wqe_com, 1);
3426 if (lpfc_cmd->cur_iocbq.priority)
3427 bf_set(wqe_ccp, &wqe->generic.wqe_com,
3428 (lpfc_cmd->cur_iocbq.priority << 1));
3430 bf_set(wqe_ccp, &wqe->generic.wqe_com,
3431 (phba->cfg_XLanePriority << 1));
3438 * lpfc_bg_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
3439 * @phba: The Hba for which this call is being executed.
3440 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3442 * This is the protection/DIF aware version of
3443 * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the
3444 * two functions eventually, but for now, it's here
3446 * 2 - Error - Do not retry
3451 lpfc_bg_scsi_prep_dma_buf_s4(struct lpfc_hba *phba,
3452 struct lpfc_io_buf *lpfc_cmd)
3454 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
3455 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
3456 struct sli4_sge *sgl = (struct sli4_sge *)(lpfc_cmd->dma_sgl);
3457 struct lpfc_iocbq *pwqeq = &lpfc_cmd->cur_iocbq;
3458 union lpfc_wqe128 *wqe = &pwqeq->wqe;
3459 uint32_t num_sge = 0;
3460 int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction;
3461 int prot_group_type = 0;
3464 struct lpfc_vport *vport = phba->pport;
3467 * Start the lpfc command prep by bumping the sgl beyond fcp_cmnd
3468 * fcp_rsp regions to the first data sge entry
3470 if (scsi_sg_count(scsi_cmnd)) {
3472 * The driver stores the segment count returned from pci_map_sg
3473 * because this a count of dma-mappings used to map the use_sg
3474 * pages. They are not guaranteed to be the same for those
3475 * architectures that implement an IOMMU.
3477 datasegcnt = dma_map_sg(&phba->pcidev->dev,
3478 scsi_sglist(scsi_cmnd),
3479 scsi_sg_count(scsi_cmnd), datadir);
3480 if (unlikely(!datasegcnt))
3484 /* clear the last flag in the fcp_rsp map entry */
3485 sgl->word2 = le32_to_cpu(sgl->word2);
3486 bf_set(lpfc_sli4_sge_last, sgl, 0);
3487 sgl->word2 = cpu_to_le32(sgl->word2);
3490 lpfc_cmd->seg_cnt = datasegcnt;
3492 /* First check if data segment count from SCSI Layer is good */
3493 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt &&
3495 WARN_ON_ONCE(lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt);
3500 prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd);
3502 switch (prot_group_type) {
3503 case LPFC_PG_TYPE_NO_DIF:
3504 /* Here we need to add a DISEED to the count */
3505 if (((lpfc_cmd->seg_cnt + 1) >
3506 phba->cfg_total_seg_cnt) &&
3512 num_sge = lpfc_bg_setup_sgl(phba, scsi_cmnd, sgl,
3513 datasegcnt, lpfc_cmd);
3515 /* we should have 2 or more entries in buffer list */
3522 case LPFC_PG_TYPE_DIF_BUF:
3524 * This type indicates that protection buffers are
3525 * passed to the driver, so that needs to be prepared
3528 protsegcnt = dma_map_sg(&phba->pcidev->dev,
3529 scsi_prot_sglist(scsi_cmnd),
3530 scsi_prot_sg_count(scsi_cmnd), datadir);
3531 if (unlikely(!protsegcnt)) {
3532 scsi_dma_unmap(scsi_cmnd);
3536 lpfc_cmd->prot_seg_cnt = protsegcnt;
3538 * There is a minimun of 3 SGEs used for every
3539 * protection data segment.
3541 if (((lpfc_cmd->prot_seg_cnt * 3) >
3542 (phba->cfg_total_seg_cnt - 2)) &&
3548 num_sge = lpfc_bg_setup_sgl_prot(phba, scsi_cmnd, sgl,
3549 datasegcnt, protsegcnt, lpfc_cmd);
3551 /* we should have 3 or more entries in buffer list */
3553 (num_sge > phba->cfg_total_seg_cnt &&
3554 !phba->cfg_xpsgl)) {
3560 case LPFC_PG_TYPE_INVALID:
3562 scsi_dma_unmap(scsi_cmnd);
3563 lpfc_cmd->seg_cnt = 0;
3565 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3566 "9083 Unexpected protection group %i\n",
3572 switch (scsi_get_prot_op(scsi_cmnd)) {
3573 case SCSI_PROT_WRITE_STRIP:
3574 case SCSI_PROT_READ_STRIP:
3575 lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_STRIP;
3577 case SCSI_PROT_WRITE_INSERT:
3578 case SCSI_PROT_READ_INSERT:
3579 lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_INSERT;
3581 case SCSI_PROT_WRITE_PASS:
3582 case SCSI_PROT_READ_PASS:
3583 lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_PASS;
3587 fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd);
3588 fcp_cmnd->fcpDl = be32_to_cpu(fcpdl);
3590 /* Set first-burst provided it was successfully negotiated */
3591 if (!(phba->hba_flag & HBA_FCOE_MODE) &&
3592 vport->cfg_first_burst_size &&
3593 scsi_cmnd->sc_data_direction == DMA_TO_DEVICE) {
3594 u32 init_len, total_len;
3596 total_len = be32_to_cpu(fcp_cmnd->fcpDl);
3597 init_len = min(total_len, vport->cfg_first_burst_size);
3600 wqe->fcp_iwrite.initial_xfer_len = init_len;
3601 wqe->fcp_iwrite.total_xfer_len = total_len;
3604 wqe->fcp_iwrite.total_xfer_len =
3605 be32_to_cpu(fcp_cmnd->fcpDl);
3609 * If the OAS driver feature is enabled and the lun is enabled for
3610 * OAS, set the oas iocb related flags.
3612 if ((phba->cfg_fof) && ((struct lpfc_device_data *)
3613 scsi_cmnd->device->hostdata)->oas_enabled) {
3614 lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF);
3617 bf_set(wqe_oas, &wqe->generic.wqe_com, 1);
3618 bf_set(wqe_ccpe, &wqe->generic.wqe_com, 1);
3619 bf_set(wqe_ccp, &wqe->generic.wqe_com,
3620 (phba->cfg_XLanePriority << 1));
3623 /* Word 7. DIF Flags */
3624 if (lpfc_cmd->cur_iocbq.iocb_flag & LPFC_IO_DIF_PASS)
3625 bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU);
3626 else if (lpfc_cmd->cur_iocbq.iocb_flag & LPFC_IO_DIF_STRIP)
3627 bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP);
3628 else if (lpfc_cmd->cur_iocbq.iocb_flag & LPFC_IO_DIF_INSERT)
3629 bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT);
3631 lpfc_cmd->cur_iocbq.iocb_flag &= ~(LPFC_IO_DIF_PASS |
3632 LPFC_IO_DIF_STRIP | LPFC_IO_DIF_INSERT);
3636 if (lpfc_cmd->seg_cnt)
3637 scsi_dma_unmap(scsi_cmnd);
3638 if (lpfc_cmd->prot_seg_cnt)
3639 dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd),
3640 scsi_prot_sg_count(scsi_cmnd),
3641 scsi_cmnd->sc_data_direction);
3643 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3644 "9084 Cannot setup S/G List for HBA"
3645 "IO segs %d/%d SGL %d SCSI %d: %d %d\n",
3646 lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt,
3647 phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt,
3648 prot_group_type, num_sge);
3650 lpfc_cmd->seg_cnt = 0;
3651 lpfc_cmd->prot_seg_cnt = 0;
3656 * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
3657 * @phba: The Hba for which this call is being executed.
3658 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3660 * This routine wraps the actual DMA mapping function pointer from the
3668 lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
3670 return phba->lpfc_scsi_prep_dma_buf(phba, lpfc_cmd);
3674 * lpfc_bg_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
3676 * @phba: The Hba for which this call is being executed.
3677 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3679 * This routine wraps the actual DMA mapping function pointer from the
3687 lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
3689 return phba->lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd);
3693 * lpfc_scsi_prep_cmnd_buf - Wrapper function for IOCB/WQE mapping of scsi
3695 * @vport: Pointer to vport object.
3696 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3697 * @tmo: Timeout value for IO
3699 * This routine initializes IOCB/WQE data structure from scsi command
3706 lpfc_scsi_prep_cmnd_buf(struct lpfc_vport *vport, struct lpfc_io_buf *lpfc_cmd,
3709 return vport->phba->lpfc_scsi_prep_cmnd_buf(vport, lpfc_cmd, tmo);
3713 * lpfc_send_scsi_error_event - Posts an event when there is SCSI error
3714 * @phba: Pointer to hba context object.
3715 * @vport: Pointer to vport object.
3716 * @lpfc_cmd: Pointer to lpfc scsi command which reported the error.
3717 * @fcpi_parm: FCP Initiator parameter.
3719 * This function posts an event when there is a SCSI command reporting
3720 * error from the scsi device.
3723 lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport,
3724 struct lpfc_io_buf *lpfc_cmd, uint32_t fcpi_parm) {
3725 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
3726 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
3727 uint32_t resp_info = fcprsp->rspStatus2;
3728 uint32_t scsi_status = fcprsp->rspStatus3;
3729 struct lpfc_fast_path_event *fast_path_evt = NULL;
3730 struct lpfc_nodelist *pnode = lpfc_cmd->rdata->pnode;
3731 unsigned long flags;
3736 /* If there is queuefull or busy condition send a scsi event */
3737 if ((cmnd->result == SAM_STAT_TASK_SET_FULL) ||
3738 (cmnd->result == SAM_STAT_BUSY)) {
3739 fast_path_evt = lpfc_alloc_fast_evt(phba);
3742 fast_path_evt->un.scsi_evt.event_type =
3744 fast_path_evt->un.scsi_evt.subcategory =
3745 (cmnd->result == SAM_STAT_TASK_SET_FULL) ?
3746 LPFC_EVENT_QFULL : LPFC_EVENT_DEVBSY;
3747 fast_path_evt->un.scsi_evt.lun = cmnd->device->lun;
3748 memcpy(&fast_path_evt->un.scsi_evt.wwpn,
3749 &pnode->nlp_portname, sizeof(struct lpfc_name));
3750 memcpy(&fast_path_evt->un.scsi_evt.wwnn,
3751 &pnode->nlp_nodename, sizeof(struct lpfc_name));
3752 } else if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen &&
3753 ((cmnd->cmnd[0] == READ_10) || (cmnd->cmnd[0] == WRITE_10))) {
3754 fast_path_evt = lpfc_alloc_fast_evt(phba);
3757 fast_path_evt->un.check_cond_evt.scsi_event.event_type =
3759 fast_path_evt->un.check_cond_evt.scsi_event.subcategory =
3760 LPFC_EVENT_CHECK_COND;
3761 fast_path_evt->un.check_cond_evt.scsi_event.lun =
3763 memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwpn,
3764 &pnode->nlp_portname, sizeof(struct lpfc_name));
3765 memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwnn,
3766 &pnode->nlp_nodename, sizeof(struct lpfc_name));
3767 fast_path_evt->un.check_cond_evt.sense_key =
3768 cmnd->sense_buffer[2] & 0xf;
3769 fast_path_evt->un.check_cond_evt.asc = cmnd->sense_buffer[12];
3770 fast_path_evt->un.check_cond_evt.ascq = cmnd->sense_buffer[13];
3771 } else if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) &&
3773 ((be32_to_cpu(fcprsp->rspResId) != fcpi_parm) ||
3774 ((scsi_status == SAM_STAT_GOOD) &&
3775 !(resp_info & (RESID_UNDER | RESID_OVER))))) {
3777 * If status is good or resid does not match with fcp_param and
3778 * there is valid fcpi_parm, then there is a read_check error
3780 fast_path_evt = lpfc_alloc_fast_evt(phba);
3783 fast_path_evt->un.read_check_error.header.event_type =
3784 FC_REG_FABRIC_EVENT;
3785 fast_path_evt->un.read_check_error.header.subcategory =
3786 LPFC_EVENT_FCPRDCHKERR;
3787 memcpy(&fast_path_evt->un.read_check_error.header.wwpn,
3788 &pnode->nlp_portname, sizeof(struct lpfc_name));
3789 memcpy(&fast_path_evt->un.read_check_error.header.wwnn,
3790 &pnode->nlp_nodename, sizeof(struct lpfc_name));
3791 fast_path_evt->un.read_check_error.lun = cmnd->device->lun;
3792 fast_path_evt->un.read_check_error.opcode = cmnd->cmnd[0];
3793 fast_path_evt->un.read_check_error.fcpiparam =
3798 fast_path_evt->vport = vport;
3799 spin_lock_irqsave(&phba->hbalock, flags);
3800 list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list);
3801 spin_unlock_irqrestore(&phba->hbalock, flags);
3802 lpfc_worker_wake_up(phba);
3807 * lpfc_scsi_unprep_dma_buf - Un-map DMA mapping of SG-list for dev
3808 * @phba: The HBA for which this call is being executed.
3809 * @psb: The scsi buffer which is going to be un-mapped.
3811 * This routine does DMA un-mapping of scatter gather list of scsi command
3812 * field of @lpfc_cmd for device with SLI-3 interface spec.
3815 lpfc_scsi_unprep_dma_buf(struct lpfc_hba *phba, struct lpfc_io_buf *psb)
3818 * There are only two special cases to consider. (1) the scsi command
3819 * requested scatter-gather usage or (2) the scsi command allocated
3820 * a request buffer, but did not request use_sg. There is a third
3821 * case, but it does not require resource deallocation.
3823 if (psb->seg_cnt > 0)
3824 scsi_dma_unmap(psb->pCmd);
3825 if (psb->prot_seg_cnt > 0)
3826 dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(psb->pCmd),
3827 scsi_prot_sg_count(psb->pCmd),
3828 psb->pCmd->sc_data_direction);
3832 * lpfc_unblock_requests - allow further commands to be queued.
3833 * @phba: pointer to phba object
3835 * For single vport, just call scsi_unblock_requests on physical port.
3836 * For multiple vports, send scsi_unblock_requests for all the vports.
3839 lpfc_unblock_requests(struct lpfc_hba *phba)
3841 struct lpfc_vport **vports;
3842 struct Scsi_Host *shost;
3845 if (phba->sli_rev == LPFC_SLI_REV4 &&
3846 !phba->sli4_hba.max_cfg_param.vpi_used) {
3847 shost = lpfc_shost_from_vport(phba->pport);
3848 scsi_unblock_requests(shost);
3852 vports = lpfc_create_vport_work_array(phba);
3854 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3855 shost = lpfc_shost_from_vport(vports[i]);
3856 scsi_unblock_requests(shost);
3858 lpfc_destroy_vport_work_array(phba, vports);
3862 * lpfc_block_requests - prevent further commands from being queued.
3863 * @phba: pointer to phba object
3865 * For single vport, just call scsi_block_requests on physical port.
3866 * For multiple vports, send scsi_block_requests for all the vports.
3869 lpfc_block_requests(struct lpfc_hba *phba)
3871 struct lpfc_vport **vports;
3872 struct Scsi_Host *shost;
3875 if (atomic_read(&phba->cmf_stop_io))
3878 if (phba->sli_rev == LPFC_SLI_REV4 &&
3879 !phba->sli4_hba.max_cfg_param.vpi_used) {
3880 shost = lpfc_shost_from_vport(phba->pport);
3881 scsi_block_requests(shost);
3885 vports = lpfc_create_vport_work_array(phba);
3887 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3888 shost = lpfc_shost_from_vport(vports[i]);
3889 scsi_block_requests(shost);
3891 lpfc_destroy_vport_work_array(phba, vports);
3895 * lpfc_update_cmf_cmpl - Adjust CMF counters for IO completion
3896 * @phba: The HBA for which this call is being executed.
3897 * @time: The latency of the IO that completed (in ns)
3898 * @size: The size of the IO that completed
3899 * @shost: SCSI host the IO completed on (NULL for a NVME IO)
3901 * The routine adjusts the various Burst and Bandwidth counters used in
3902 * Congestion management and E2E. If time is set to LPFC_CGN_NOT_SENT,
3903 * that means the IO was never issued to the HBA, so this routine is
3904 * just being called to cleanup the counter from a previous
3905 * lpfc_update_cmf_cmd call.
3908 lpfc_update_cmf_cmpl(struct lpfc_hba *phba,
3909 uint64_t time, uint32_t size, struct Scsi_Host *shost)
3911 struct lpfc_cgn_stat *cgs;
3913 if (time != LPFC_CGN_NOT_SENT) {
3914 /* lat is ns coming in, save latency in us */
3918 time = div_u64(time + 500, 1000); /* round it */
3920 cgs = this_cpu_ptr(phba->cmf_stat);
3921 atomic64_add(size, &cgs->rcv_bytes);
3922 atomic64_add(time, &cgs->rx_latency);
3923 atomic_inc(&cgs->rx_io_cnt);
3929 * lpfc_update_cmf_cmd - Adjust CMF counters for IO submission
3930 * @phba: The HBA for which this call is being executed.
3931 * @size: The size of the IO that will be issued
3933 * The routine adjusts the various Burst and Bandwidth counters used in
3934 * Congestion management and E2E.
3937 lpfc_update_cmf_cmd(struct lpfc_hba *phba, uint32_t size)
3940 struct lpfc_cgn_stat *cgs;
3943 /* At this point we are either LPFC_CFG_MANAGED or LPFC_CFG_MONITOR */
3944 if (phba->cmf_active_mode == LPFC_CFG_MANAGED) {
3946 for_each_present_cpu(cpu) {
3947 cgs = per_cpu_ptr(phba->cmf_stat, cpu);
3948 total += atomic64_read(&cgs->total_bytes);
3950 if (total >= phba->cmf_max_bytes_per_interval) {
3951 if (!atomic_xchg(&phba->cmf_bw_wait, 1)) {
3952 lpfc_block_requests(phba);
3954 lpfc_calc_cmf_latency(phba);
3956 atomic_inc(&phba->cmf_busy);
3959 if (size > atomic_read(&phba->rx_max_read_cnt))
3960 atomic_set(&phba->rx_max_read_cnt, size);
3963 cgs = this_cpu_ptr(phba->cmf_stat);
3964 atomic64_add(size, &cgs->total_bytes);
3969 * lpfc_handle_fcp_err - FCP response handler
3970 * @vport: The virtual port for which this call is being executed.
3971 * @lpfc_cmd: Pointer to lpfc_io_buf data structure.
3972 * @fcpi_parm: FCP Initiator parameter.
3974 * This routine is called to process response IOCB with status field
3975 * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command
3976 * based upon SCSI and FCP error.
3979 lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_io_buf *lpfc_cmd,
3982 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
3983 struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd;
3984 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
3985 uint32_t resp_info = fcprsp->rspStatus2;
3986 uint32_t scsi_status = fcprsp->rspStatus3;
3988 uint32_t host_status = DID_OK;
3989 uint32_t rsplen = 0;
3991 uint32_t logit = LOG_FCP | LOG_FCP_ERROR;
3995 * If this is a task management command, there is no
3996 * scsi packet associated with this lpfc_cmd. The driver
3999 if (fcpcmd->fcpCntl2) {
4004 if (resp_info & RSP_LEN_VALID) {
4005 rsplen = be32_to_cpu(fcprsp->rspRspLen);
4006 if (rsplen != 0 && rsplen != 4 && rsplen != 8) {
4007 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4008 "2719 Invalid response length: "
4009 "tgt x%x lun x%llx cmnd x%x rsplen "
4010 "x%x\n", cmnd->device->id,
4011 cmnd->device->lun, cmnd->cmnd[0],
4013 host_status = DID_ERROR;
4016 if (fcprsp->rspInfo3 != RSP_NO_FAILURE) {
4017 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4018 "2757 Protocol failure detected during "
4019 "processing of FCP I/O op: "
4020 "tgt x%x lun x%llx cmnd x%x rspInfo3 x%x\n",
4022 cmnd->device->lun, cmnd->cmnd[0],
4024 host_status = DID_ERROR;
4029 if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) {
4030 uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen);
4031 if (snslen > SCSI_SENSE_BUFFERSIZE)
4032 snslen = SCSI_SENSE_BUFFERSIZE;
4034 if (resp_info & RSP_LEN_VALID)
4035 rsplen = be32_to_cpu(fcprsp->rspRspLen);
4036 memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen);
4038 lp = (uint32_t *)cmnd->sense_buffer;
4040 /* special handling for under run conditions */
4041 if (!scsi_status && (resp_info & RESID_UNDER)) {
4042 /* don't log under runs if fcp set... */
4043 if (vport->cfg_log_verbose & LOG_FCP)
4044 logit = LOG_FCP_ERROR;
4045 /* unless operator says so */
4046 if (vport->cfg_log_verbose & LOG_FCP_UNDER)
4047 logit = LOG_FCP_UNDER;
4050 lpfc_printf_vlog(vport, KERN_WARNING, logit,
4051 "9024 FCP command x%x failed: x%x SNS x%x x%x "
4052 "Data: x%x x%x x%x x%x x%x\n",
4053 cmnd->cmnd[0], scsi_status,
4054 be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info,
4055 be32_to_cpu(fcprsp->rspResId),
4056 be32_to_cpu(fcprsp->rspSnsLen),
4057 be32_to_cpu(fcprsp->rspRspLen),
4060 scsi_set_resid(cmnd, 0);
4061 fcpDl = be32_to_cpu(fcpcmd->fcpDl);
4062 if (resp_info & RESID_UNDER) {
4063 scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId));
4065 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_UNDER,
4066 "9025 FCP Underrun, expected %d, "
4067 "residual %d Data: x%x x%x x%x\n",
4069 scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0],
4073 * If there is an under run, check if under run reported by
4074 * storage array is same as the under run reported by HBA.
4075 * If this is not same, there is a dropped frame.
4077 if (fcpi_parm && (scsi_get_resid(cmnd) != fcpi_parm)) {
4078 lpfc_printf_vlog(vport, KERN_WARNING,
4079 LOG_FCP | LOG_FCP_ERROR,
4080 "9026 FCP Read Check Error "
4081 "and Underrun Data: x%x x%x x%x x%x\n",
4083 scsi_get_resid(cmnd), fcpi_parm,
4085 scsi_set_resid(cmnd, scsi_bufflen(cmnd));
4086 host_status = DID_ERROR;
4089 * The cmnd->underflow is the minimum number of bytes that must
4090 * be transferred for this command. Provided a sense condition
4091 * is not present, make sure the actual amount transferred is at
4092 * least the underflow value or fail.
4094 if (!(resp_info & SNS_LEN_VALID) &&
4095 (scsi_status == SAM_STAT_GOOD) &&
4096 (scsi_bufflen(cmnd) - scsi_get_resid(cmnd)
4097 < cmnd->underflow)) {
4098 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4099 "9027 FCP command x%x residual "
4100 "underrun converted to error "
4101 "Data: x%x x%x x%x\n",
4102 cmnd->cmnd[0], scsi_bufflen(cmnd),
4103 scsi_get_resid(cmnd), cmnd->underflow);
4104 host_status = DID_ERROR;
4106 } else if (resp_info & RESID_OVER) {
4107 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4108 "9028 FCP command x%x residual overrun error. "
4109 "Data: x%x x%x\n", cmnd->cmnd[0],
4110 scsi_bufflen(cmnd), scsi_get_resid(cmnd));
4111 host_status = DID_ERROR;
4114 * Check SLI validation that all the transfer was actually done
4115 * (fcpi_parm should be zero). Apply check only to reads.
4117 } else if (fcpi_parm) {
4118 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR,
4119 "9029 FCP %s Check Error Data: "
4120 "x%x x%x x%x x%x x%x\n",
4121 ((cmnd->sc_data_direction == DMA_FROM_DEVICE) ?
4123 fcpDl, be32_to_cpu(fcprsp->rspResId),
4124 fcpi_parm, cmnd->cmnd[0], scsi_status);
4126 /* There is some issue with the LPe12000 that causes it
4127 * to miscalculate the fcpi_parm and falsely trip this
4128 * recovery logic. Detect this case and don't error when true.
4130 if (fcpi_parm > fcpDl)
4133 switch (scsi_status) {
4135 case SAM_STAT_CHECK_CONDITION:
4136 /* Fabric dropped a data frame. Fail any successful
4137 * command in which we detected dropped frames.
4138 * A status of good or some check conditions could
4139 * be considered a successful command.
4141 host_status = DID_ERROR;
4144 scsi_set_resid(cmnd, scsi_bufflen(cmnd));
4148 cmnd->result = host_status << 16 | scsi_status;
4149 lpfc_send_scsi_error_event(vport->phba, vport, lpfc_cmd, fcpi_parm);
4153 * lpfc_fcp_io_cmd_wqe_cmpl - Complete a FCP IO
4154 * @phba: The hba for which this call is being executed.
4155 * @pwqeIn: The command WQE for the scsi cmnd.
4156 * @wcqe: Pointer to driver response CQE object.
4158 * This routine assigns scsi command result by looking into response WQE
4159 * status field appropriately. This routine handles QUEUE FULL condition as
4160 * well by ramping down device queue depth.
4163 lpfc_fcp_io_cmd_wqe_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeIn,
4164 struct lpfc_wcqe_complete *wcqe)
4166 struct lpfc_io_buf *lpfc_cmd =
4167 (struct lpfc_io_buf *)pwqeIn->context1;
4168 struct lpfc_vport *vport = pwqeIn->vport;
4169 struct lpfc_rport_data *rdata;
4170 struct lpfc_nodelist *ndlp;
4171 struct scsi_cmnd *cmd;
4172 unsigned long flags;
4173 struct lpfc_fast_path_event *fast_path_evt;
4174 struct Scsi_Host *shost;
4175 u32 logit = LOG_FCP;
4177 unsigned long iflags = 0;
4181 /* Sanity check on return of outstanding command */
4183 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4184 "9032 Null lpfc_cmd pointer. No "
4185 "release, skip completion\n");
4189 rdata = lpfc_cmd->rdata;
4190 ndlp = rdata->pnode;
4192 if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
4193 /* TOREMOVE - currently this flag is checked during
4194 * the release of lpfc_iocbq. Remove once we move
4195 * to lpfc_wqe_job construct.
4197 * This needs to be done outside buf_lock
4199 spin_lock_irqsave(&phba->hbalock, iflags);
4200 lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_EXCHANGE_BUSY;
4201 spin_unlock_irqrestore(&phba->hbalock, iflags);
4204 /* Guard against abort handler being called at same time */
4205 spin_lock(&lpfc_cmd->buf_lock);
4207 /* Sanity check on return of outstanding command */
4208 cmd = lpfc_cmd->pCmd;
4210 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4211 "9042 I/O completion: Not an active IO\n");
4212 spin_unlock(&lpfc_cmd->buf_lock);
4213 lpfc_release_scsi_buf(phba, lpfc_cmd);
4216 idx = lpfc_cmd->cur_iocbq.hba_wqidx;
4217 if (phba->sli4_hba.hdwq)
4218 phba->sli4_hba.hdwq[idx].scsi_cstat.io_cmpls++;
4220 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4221 if (unlikely(phba->hdwqstat_on & LPFC_CHECK_SCSI_IO))
4222 this_cpu_inc(phba->sli4_hba.c_stat->cmpl_io);
4224 shost = cmd->device->host;
4226 status = bf_get(lpfc_wcqe_c_status, wcqe);
4227 lpfc_cmd->status = (status & LPFC_IOCB_STATUS_MASK);
4228 lpfc_cmd->result = (wcqe->parameter & IOERR_PARAM_MASK);
4230 lpfc_cmd->flags &= ~LPFC_SBUF_XBUSY;
4231 if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
4232 lpfc_cmd->flags |= LPFC_SBUF_XBUSY;
4233 if (phba->cfg_fcp_wait_abts_rsp)
4237 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4238 if (lpfc_cmd->prot_data_type) {
4239 struct scsi_dif_tuple *src = NULL;
4241 src = (struct scsi_dif_tuple *)lpfc_cmd->prot_data_segment;
4243 * Used to restore any changes to protection
4244 * data for error injection.
4246 switch (lpfc_cmd->prot_data_type) {
4247 case LPFC_INJERR_REFTAG:
4249 lpfc_cmd->prot_data;
4251 case LPFC_INJERR_APPTAG:
4253 (uint16_t)lpfc_cmd->prot_data;
4255 case LPFC_INJERR_GUARD:
4257 (uint16_t)lpfc_cmd->prot_data;
4263 lpfc_cmd->prot_data = 0;
4264 lpfc_cmd->prot_data_type = 0;
4265 lpfc_cmd->prot_data_segment = NULL;
4268 if (unlikely(lpfc_cmd->status)) {
4269 if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT &&
4270 (lpfc_cmd->result & IOERR_DRVR_MASK))
4271 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
4272 else if (lpfc_cmd->status >= IOSTAT_CNT)
4273 lpfc_cmd->status = IOSTAT_DEFAULT;
4274 if (lpfc_cmd->status == IOSTAT_FCP_RSP_ERROR &&
4275 !lpfc_cmd->fcp_rsp->rspStatus3 &&
4276 (lpfc_cmd->fcp_rsp->rspStatus2 & RESID_UNDER) &&
4277 !(vport->cfg_log_verbose & LOG_FCP_UNDER))
4280 logit = LOG_FCP | LOG_FCP_UNDER;
4281 lpfc_printf_vlog(vport, KERN_WARNING, logit,
4282 "9034 FCP cmd x%x failed <%d/%lld> "
4283 "status: x%x result: x%x "
4284 "sid: x%x did: x%x oxid: x%x "
4285 "Data: x%x x%x x%x\n",
4287 cmd->device ? cmd->device->id : 0xffff,
4288 cmd->device ? cmd->device->lun : 0xffff,
4289 lpfc_cmd->status, lpfc_cmd->result,
4291 (ndlp) ? ndlp->nlp_DID : 0,
4292 lpfc_cmd->cur_iocbq.sli4_xritag,
4293 wcqe->parameter, wcqe->total_data_placed,
4294 lpfc_cmd->cur_iocbq.iotag);
4297 switch (lpfc_cmd->status) {
4298 case IOSTAT_SUCCESS:
4299 cmd->result = DID_OK << 16;
4301 case IOSTAT_FCP_RSP_ERROR:
4302 lpfc_handle_fcp_err(vport, lpfc_cmd,
4303 pwqeIn->wqe.fcp_iread.total_xfer_len -
4304 wcqe->total_data_placed);
4306 case IOSTAT_NPORT_BSY:
4307 case IOSTAT_FABRIC_BSY:
4308 cmd->result = DID_TRANSPORT_DISRUPTED << 16;
4309 fast_path_evt = lpfc_alloc_fast_evt(phba);
4312 fast_path_evt->un.fabric_evt.event_type =
4313 FC_REG_FABRIC_EVENT;
4314 fast_path_evt->un.fabric_evt.subcategory =
4315 (lpfc_cmd->status == IOSTAT_NPORT_BSY) ?
4316 LPFC_EVENT_PORT_BUSY : LPFC_EVENT_FABRIC_BUSY;
4318 memcpy(&fast_path_evt->un.fabric_evt.wwpn,
4319 &ndlp->nlp_portname,
4320 sizeof(struct lpfc_name));
4321 memcpy(&fast_path_evt->un.fabric_evt.wwnn,
4322 &ndlp->nlp_nodename,
4323 sizeof(struct lpfc_name));
4325 fast_path_evt->vport = vport;
4326 fast_path_evt->work_evt.evt =
4327 LPFC_EVT_FASTPATH_MGMT_EVT;
4328 spin_lock_irqsave(&phba->hbalock, flags);
4329 list_add_tail(&fast_path_evt->work_evt.evt_listp,
4331 spin_unlock_irqrestore(&phba->hbalock, flags);
4332 lpfc_worker_wake_up(phba);
4333 lpfc_printf_vlog(vport, KERN_WARNING, logit,
4334 "9035 Fabric/Node busy FCP cmd x%x failed"
4336 "status: x%x result: x%x "
4337 "sid: x%x did: x%x oxid: x%x "
4338 "Data: x%x x%x x%x\n",
4340 cmd->device ? cmd->device->id : 0xffff,
4341 cmd->device ? cmd->device->lun : 0xffff,
4342 lpfc_cmd->status, lpfc_cmd->result,
4344 (ndlp) ? ndlp->nlp_DID : 0,
4345 lpfc_cmd->cur_iocbq.sli4_xritag,
4347 wcqe->total_data_placed,
4348 lpfc_cmd->cur_iocbq.iocb.ulpIoTag);
4350 case IOSTAT_REMOTE_STOP:
4352 /* This I/O was aborted by the target, we don't
4353 * know the rxid and because we did not send the
4354 * ABTS we cannot generate and RRQ.
4356 lpfc_set_rrq_active(phba, ndlp,
4357 lpfc_cmd->cur_iocbq.sli4_lxritag,
4361 case IOSTAT_LOCAL_REJECT:
4362 if (lpfc_cmd->result & IOERR_DRVR_MASK)
4363 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
4364 if (lpfc_cmd->result == IOERR_ELXSEC_KEY_UNWRAP_ERROR ||
4366 IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR ||
4367 lpfc_cmd->result == IOERR_ELXSEC_CRYPTO_ERROR ||
4369 IOERR_ELXSEC_CRYPTO_COMPARE_ERROR) {
4370 cmd->result = DID_NO_CONNECT << 16;
4373 if (lpfc_cmd->result == IOERR_INVALID_RPI ||
4374 lpfc_cmd->result == IOERR_NO_RESOURCES ||
4375 lpfc_cmd->result == IOERR_ABORT_REQUESTED ||
4376 lpfc_cmd->result == IOERR_SLER_CMD_RCV_FAILURE) {
4377 cmd->result = DID_REQUEUE << 16;
4380 if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED ||
4381 lpfc_cmd->result == IOERR_TX_DMA_FAILED) &&
4382 status == CQE_STATUS_DI_ERROR) {
4383 if (scsi_get_prot_op(cmd) !=
4386 * This is a response for a BG enabled
4387 * cmd. Parse BG error
4389 lpfc_sli4_parse_bg_err(phba, lpfc_cmd,
4393 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
4394 "9040 non-zero BGSTAT on unprotected cmd\n");
4396 lpfc_printf_vlog(vport, KERN_WARNING, logit,
4397 "9036 Local Reject FCP cmd x%x failed"
4399 "status: x%x result: x%x "
4400 "sid: x%x did: x%x oxid: x%x "
4401 "Data: x%x x%x x%x\n",
4403 cmd->device ? cmd->device->id : 0xffff,
4404 cmd->device ? cmd->device->lun : 0xffff,
4405 lpfc_cmd->status, lpfc_cmd->result,
4407 (ndlp) ? ndlp->nlp_DID : 0,
4408 lpfc_cmd->cur_iocbq.sli4_xritag,
4410 wcqe->total_data_placed,
4411 lpfc_cmd->cur_iocbq.iocb.ulpIoTag);
4414 if (lpfc_cmd->status >= IOSTAT_CNT)
4415 lpfc_cmd->status = IOSTAT_DEFAULT;
4416 cmd->result = DID_ERROR << 16;
4417 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
4418 "9037 FCP Completion Error: xri %x "
4419 "status x%x result x%x [x%x] "
4421 lpfc_cmd->cur_iocbq.sli4_xritag,
4422 lpfc_cmd->status, lpfc_cmd->result,
4424 wcqe->total_data_placed);
4426 if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) {
4427 u32 *lp = (u32 *)cmd->sense_buffer;
4429 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4430 "9039 Iodone <%d/%llu> cmd x%px, error "
4431 "x%x SNS x%x x%x Data: x%x x%x\n",
4432 cmd->device->id, cmd->device->lun, cmd,
4433 cmd->result, *lp, *(lp + 3), cmd->retries,
4434 scsi_get_resid(cmd));
4437 lpfc_update_stats(vport, lpfc_cmd);
4439 if (vport->cfg_max_scsicmpl_time &&
4440 time_after(jiffies, lpfc_cmd->start_time +
4441 msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) {
4442 spin_lock_irqsave(shost->host_lock, flags);
4444 if (ndlp->cmd_qdepth >
4445 atomic_read(&ndlp->cmd_pending) &&
4446 (atomic_read(&ndlp->cmd_pending) >
4447 LPFC_MIN_TGT_QDEPTH) &&
4448 (cmd->cmnd[0] == READ_10 ||
4449 cmd->cmnd[0] == WRITE_10))
4451 atomic_read(&ndlp->cmd_pending);
4453 ndlp->last_change_time = jiffies;
4455 spin_unlock_irqrestore(shost->host_lock, flags);
4457 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
4459 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4460 if (lpfc_cmd->ts_cmd_start) {
4461 lpfc_cmd->ts_isr_cmpl = lpfc_cmd->cur_iocbq.isr_timestamp;
4462 lpfc_cmd->ts_data_io = ktime_get_ns();
4463 phba->ktime_last_cmd = lpfc_cmd->ts_data_io;
4464 lpfc_io_ktime(phba, lpfc_cmd);
4467 if (likely(!wait_xb_clr))
4468 lpfc_cmd->pCmd = NULL;
4469 spin_unlock(&lpfc_cmd->buf_lock);
4471 /* Check if IO qualified for CMF */
4472 if (phba->cmf_active_mode != LPFC_CFG_OFF &&
4473 cmd->sc_data_direction == DMA_FROM_DEVICE &&
4474 (scsi_sg_count(cmd))) {
4475 /* Used when calculating average latency */
4476 lat = ktime_get_ns() - lpfc_cmd->rx_cmd_start;
4477 lpfc_update_cmf_cmpl(phba, lat, scsi_bufflen(cmd), shost);
4483 /* The sdev is not guaranteed to be valid post scsi_done upcall. */
4484 cmd->scsi_done(cmd);
4487 * If there is an abort thread waiting for command completion
4488 * wake up the thread.
4490 spin_lock(&lpfc_cmd->buf_lock);
4491 lpfc_cmd->cur_iocbq.iocb_flag &= ~LPFC_DRIVER_ABORTED;
4492 if (lpfc_cmd->waitq)
4493 wake_up(lpfc_cmd->waitq);
4494 spin_unlock(&lpfc_cmd->buf_lock);
4496 lpfc_release_scsi_buf(phba, lpfc_cmd);
4500 * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine
4501 * @phba: The Hba for which this call is being executed.
4502 * @pIocbIn: The command IOCBQ for the scsi cmnd.
4503 * @pIocbOut: The response IOCBQ for the scsi cmnd.
4505 * This routine assigns scsi command result by looking into response IOCB
4506 * status field appropriately. This routine handles QUEUE FULL condition as
4507 * well by ramping down device queue depth.
4510 lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
4511 struct lpfc_iocbq *pIocbOut)
4513 struct lpfc_io_buf *lpfc_cmd =
4514 (struct lpfc_io_buf *) pIocbIn->context1;
4515 struct lpfc_vport *vport = pIocbIn->vport;
4516 struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
4517 struct lpfc_nodelist *pnode = rdata->pnode;
4518 struct scsi_cmnd *cmd;
4519 unsigned long flags;
4520 struct lpfc_fast_path_event *fast_path_evt;
4521 struct Scsi_Host *shost;
4523 uint32_t logit = LOG_FCP;
4525 /* Guard against abort handler being called at same time */
4526 spin_lock(&lpfc_cmd->buf_lock);
4528 /* Sanity check on return of outstanding command */
4529 cmd = lpfc_cmd->pCmd;
4530 if (!cmd || !phba) {
4531 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4532 "2621 IO completion: Not an active IO\n");
4533 spin_unlock(&lpfc_cmd->buf_lock);
4537 idx = lpfc_cmd->cur_iocbq.hba_wqidx;
4538 if (phba->sli4_hba.hdwq)
4539 phba->sli4_hba.hdwq[idx].scsi_cstat.io_cmpls++;
4541 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4542 if (unlikely(phba->hdwqstat_on & LPFC_CHECK_SCSI_IO))
4543 this_cpu_inc(phba->sli4_hba.c_stat->cmpl_io);
4545 shost = cmd->device->host;
4547 lpfc_cmd->result = (pIocbOut->iocb.un.ulpWord[4] & IOERR_PARAM_MASK);
4548 lpfc_cmd->status = pIocbOut->iocb.ulpStatus;
4549 /* pick up SLI4 exchange busy status from HBA */
4550 lpfc_cmd->flags &= ~LPFC_SBUF_XBUSY;
4551 if (pIocbOut->iocb_flag & LPFC_EXCHANGE_BUSY)
4552 lpfc_cmd->flags |= LPFC_SBUF_XBUSY;
4554 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4555 if (lpfc_cmd->prot_data_type) {
4556 struct scsi_dif_tuple *src = NULL;
4558 src = (struct scsi_dif_tuple *)lpfc_cmd->prot_data_segment;
4560 * Used to restore any changes to protection
4561 * data for error injection.
4563 switch (lpfc_cmd->prot_data_type) {
4564 case LPFC_INJERR_REFTAG:
4566 lpfc_cmd->prot_data;
4568 case LPFC_INJERR_APPTAG:
4570 (uint16_t)lpfc_cmd->prot_data;
4572 case LPFC_INJERR_GUARD:
4574 (uint16_t)lpfc_cmd->prot_data;
4580 lpfc_cmd->prot_data = 0;
4581 lpfc_cmd->prot_data_type = 0;
4582 lpfc_cmd->prot_data_segment = NULL;
4586 if (unlikely(lpfc_cmd->status)) {
4587 if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT &&
4588 (lpfc_cmd->result & IOERR_DRVR_MASK))
4589 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
4590 else if (lpfc_cmd->status >= IOSTAT_CNT)
4591 lpfc_cmd->status = IOSTAT_DEFAULT;
4592 if (lpfc_cmd->status == IOSTAT_FCP_RSP_ERROR &&
4593 !lpfc_cmd->fcp_rsp->rspStatus3 &&
4594 (lpfc_cmd->fcp_rsp->rspStatus2 & RESID_UNDER) &&
4595 !(vport->cfg_log_verbose & LOG_FCP_UNDER))
4598 logit = LOG_FCP | LOG_FCP_UNDER;
4599 lpfc_printf_vlog(vport, KERN_WARNING, logit,
4600 "9030 FCP cmd x%x failed <%d/%lld> "
4601 "status: x%x result: x%x "
4602 "sid: x%x did: x%x oxid: x%x "
4605 cmd->device ? cmd->device->id : 0xffff,
4606 cmd->device ? cmd->device->lun : 0xffff,
4607 lpfc_cmd->status, lpfc_cmd->result,
4609 (pnode) ? pnode->nlp_DID : 0,
4610 phba->sli_rev == LPFC_SLI_REV4 ?
4611 lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff,
4612 pIocbOut->iocb.ulpContext,
4613 lpfc_cmd->cur_iocbq.iocb.ulpIoTag);
4615 switch (lpfc_cmd->status) {
4616 case IOSTAT_FCP_RSP_ERROR:
4617 /* Call FCP RSP handler to determine result */
4618 lpfc_handle_fcp_err(vport, lpfc_cmd,
4619 pIocbOut->iocb.un.fcpi.fcpi_parm);
4621 case IOSTAT_NPORT_BSY:
4622 case IOSTAT_FABRIC_BSY:
4623 cmd->result = DID_TRANSPORT_DISRUPTED << 16;
4624 fast_path_evt = lpfc_alloc_fast_evt(phba);
4627 fast_path_evt->un.fabric_evt.event_type =
4628 FC_REG_FABRIC_EVENT;
4629 fast_path_evt->un.fabric_evt.subcategory =
4630 (lpfc_cmd->status == IOSTAT_NPORT_BSY) ?
4631 LPFC_EVENT_PORT_BUSY : LPFC_EVENT_FABRIC_BUSY;
4633 memcpy(&fast_path_evt->un.fabric_evt.wwpn,
4634 &pnode->nlp_portname,
4635 sizeof(struct lpfc_name));
4636 memcpy(&fast_path_evt->un.fabric_evt.wwnn,
4637 &pnode->nlp_nodename,
4638 sizeof(struct lpfc_name));
4640 fast_path_evt->vport = vport;
4641 fast_path_evt->work_evt.evt =
4642 LPFC_EVT_FASTPATH_MGMT_EVT;
4643 spin_lock_irqsave(&phba->hbalock, flags);
4644 list_add_tail(&fast_path_evt->work_evt.evt_listp,
4646 spin_unlock_irqrestore(&phba->hbalock, flags);
4647 lpfc_worker_wake_up(phba);
4649 case IOSTAT_LOCAL_REJECT:
4650 case IOSTAT_REMOTE_STOP:
4651 if (lpfc_cmd->result == IOERR_ELXSEC_KEY_UNWRAP_ERROR ||
4653 IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR ||
4654 lpfc_cmd->result == IOERR_ELXSEC_CRYPTO_ERROR ||
4656 IOERR_ELXSEC_CRYPTO_COMPARE_ERROR) {
4657 cmd->result = DID_NO_CONNECT << 16;
4660 if (lpfc_cmd->result == IOERR_INVALID_RPI ||
4661 lpfc_cmd->result == IOERR_NO_RESOURCES ||
4662 lpfc_cmd->result == IOERR_ABORT_REQUESTED ||
4663 lpfc_cmd->result == IOERR_SLER_CMD_RCV_FAILURE) {
4664 cmd->result = DID_REQUEUE << 16;
4667 if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED ||
4668 lpfc_cmd->result == IOERR_TX_DMA_FAILED) &&
4669 pIocbOut->iocb.unsli3.sli3_bg.bgstat) {
4670 if (scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
4672 * This is a response for a BG enabled
4673 * cmd. Parse BG error
4675 lpfc_parse_bg_err(phba, lpfc_cmd,
4679 lpfc_printf_vlog(vport, KERN_WARNING,
4681 "9031 non-zero BGSTAT "
4682 "on unprotected cmd\n");
4685 if ((lpfc_cmd->status == IOSTAT_REMOTE_STOP)
4686 && (phba->sli_rev == LPFC_SLI_REV4)
4688 /* This IO was aborted by the target, we don't
4689 * know the rxid and because we did not send the
4690 * ABTS we cannot generate and RRQ.
4692 lpfc_set_rrq_active(phba, pnode,
4693 lpfc_cmd->cur_iocbq.sli4_lxritag,
4698 cmd->result = DID_ERROR << 16;
4702 if (!pnode || (pnode->nlp_state != NLP_STE_MAPPED_NODE))
4703 cmd->result = DID_TRANSPORT_DISRUPTED << 16 |
4706 cmd->result = DID_OK << 16;
4708 if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) {
4709 uint32_t *lp = (uint32_t *)cmd->sense_buffer;
4711 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4712 "0710 Iodone <%d/%llu> cmd x%px, error "
4713 "x%x SNS x%x x%x Data: x%x x%x\n",
4714 cmd->device->id, cmd->device->lun, cmd,
4715 cmd->result, *lp, *(lp + 3), cmd->retries,
4716 scsi_get_resid(cmd));
4719 lpfc_update_stats(vport, lpfc_cmd);
4720 if (vport->cfg_max_scsicmpl_time &&
4721 time_after(jiffies, lpfc_cmd->start_time +
4722 msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) {
4723 spin_lock_irqsave(shost->host_lock, flags);
4725 if (pnode->cmd_qdepth >
4726 atomic_read(&pnode->cmd_pending) &&
4727 (atomic_read(&pnode->cmd_pending) >
4728 LPFC_MIN_TGT_QDEPTH) &&
4729 ((cmd->cmnd[0] == READ_10) ||
4730 (cmd->cmnd[0] == WRITE_10)))
4732 atomic_read(&pnode->cmd_pending);
4734 pnode->last_change_time = jiffies;
4736 spin_unlock_irqrestore(shost->host_lock, flags);
4738 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
4740 lpfc_cmd->pCmd = NULL;
4741 spin_unlock(&lpfc_cmd->buf_lock);
4743 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4744 if (lpfc_cmd->ts_cmd_start) {
4745 lpfc_cmd->ts_isr_cmpl = pIocbIn->isr_timestamp;
4746 lpfc_cmd->ts_data_io = ktime_get_ns();
4747 phba->ktime_last_cmd = lpfc_cmd->ts_data_io;
4748 lpfc_io_ktime(phba, lpfc_cmd);
4752 /* The sdev is not guaranteed to be valid post scsi_done upcall. */
4753 cmd->scsi_done(cmd);
4756 * If there is an abort thread waiting for command completion
4757 * wake up the thread.
4759 spin_lock(&lpfc_cmd->buf_lock);
4760 lpfc_cmd->cur_iocbq.iocb_flag &= ~LPFC_DRIVER_ABORTED;
4761 if (lpfc_cmd->waitq)
4762 wake_up(lpfc_cmd->waitq);
4763 spin_unlock(&lpfc_cmd->buf_lock);
4765 lpfc_release_scsi_buf(phba, lpfc_cmd);
4769 * lpfc_scsi_prep_cmnd_buf_s3 - SLI-3 IOCB init for the IO
4770 * @vport: Pointer to vport object.
4771 * @lpfc_cmd: The scsi buffer which is going to be prep'ed.
4772 * @tmo: timeout value for the IO
4774 * Based on the data-direction of the command, initialize IOCB
4775 * in the I/O buffer. Fill in the IOCB fields which are independent
4776 * of the scsi buffer
4778 * RETURNS 0 - SUCCESS,
4780 static int lpfc_scsi_prep_cmnd_buf_s3(struct lpfc_vport *vport,
4781 struct lpfc_io_buf *lpfc_cmd,
4784 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
4785 struct lpfc_iocbq *piocbq = &lpfc_cmd->cur_iocbq;
4786 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
4787 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
4788 struct lpfc_nodelist *pnode = lpfc_cmd->ndlp;
4789 int datadir = scsi_cmnd->sc_data_direction;
4792 piocbq->iocb.un.fcpi.fcpi_XRdy = 0;
4795 * There are three possibilities here - use scatter-gather segment, use
4796 * the single mapping, or neither. Start the lpfc command prep by
4797 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
4800 if (scsi_sg_count(scsi_cmnd)) {
4801 if (datadir == DMA_TO_DEVICE) {
4802 iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR;
4803 iocb_cmd->ulpPU = PARM_READ_CHECK;
4804 if (vport->cfg_first_burst_size &&
4805 (pnode->nlp_flag & NLP_FIRSTBURST)) {
4808 fcpdl = scsi_bufflen(scsi_cmnd);
4809 xrdy_len = min(fcpdl,
4810 vport->cfg_first_burst_size);
4811 piocbq->iocb.un.fcpi.fcpi_XRdy = xrdy_len;
4813 fcp_cmnd->fcpCntl3 = WRITE_DATA;
4815 iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR;
4816 iocb_cmd->ulpPU = PARM_READ_CHECK;
4817 fcp_cmnd->fcpCntl3 = READ_DATA;
4820 iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR;
4821 iocb_cmd->un.fcpi.fcpi_parm = 0;
4822 iocb_cmd->ulpPU = 0;
4823 fcp_cmnd->fcpCntl3 = 0;
4827 * Finish initializing those IOCB fields that are independent
4828 * of the scsi_cmnd request_buffer
4830 piocbq->iocb.ulpContext = pnode->nlp_rpi;
4831 if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE)
4832 piocbq->iocb.ulpFCP2Rcvy = 1;
4834 piocbq->iocb.ulpFCP2Rcvy = 0;
4836 piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f);
4837 piocbq->context1 = lpfc_cmd;
4838 if (!piocbq->iocb_cmpl)
4839 piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
4840 piocbq->iocb.ulpTimeout = tmo;
4841 piocbq->vport = vport;
4846 * lpfc_scsi_prep_cmnd_buf_s4 - SLI-4 WQE init for the IO
4847 * @vport: Pointer to vport object.
4848 * @lpfc_cmd: The scsi buffer which is going to be prep'ed.
4849 * @tmo: timeout value for the IO
4851 * Based on the data-direction of the command copy WQE template
4852 * to I/O buffer WQE. Fill in the WQE fields which are independent
4853 * of the scsi buffer
4855 * RETURNS 0 - SUCCESS,
4857 static int lpfc_scsi_prep_cmnd_buf_s4(struct lpfc_vport *vport,
4858 struct lpfc_io_buf *lpfc_cmd,
4861 struct lpfc_hba *phba = vport->phba;
4862 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
4863 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
4864 struct lpfc_sli4_hdw_queue *hdwq = NULL;
4865 struct lpfc_iocbq *pwqeq = &lpfc_cmd->cur_iocbq;
4866 struct lpfc_nodelist *pnode = lpfc_cmd->ndlp;
4867 union lpfc_wqe128 *wqe = &pwqeq->wqe;
4868 u16 idx = lpfc_cmd->hdwq_no;
4869 int datadir = scsi_cmnd->sc_data_direction;
4871 hdwq = &phba->sli4_hba.hdwq[idx];
4873 /* Initialize 64 bytes only */
4874 memset(wqe, 0, sizeof(union lpfc_wqe128));
4877 * There are three possibilities here - use scatter-gather segment, use
4878 * the single mapping, or neither.
4880 if (scsi_sg_count(scsi_cmnd)) {
4881 if (datadir == DMA_TO_DEVICE) {
4882 /* From the iwrite template, initialize words 7 - 11 */
4883 memcpy(&wqe->words[7],
4884 &lpfc_iwrite_cmd_template.words[7],
4885 sizeof(uint32_t) * 5);
4887 fcp_cmnd->fcpCntl3 = WRITE_DATA;
4889 hdwq->scsi_cstat.output_requests++;
4891 /* From the iread template, initialize words 7 - 11 */
4892 memcpy(&wqe->words[7],
4893 &lpfc_iread_cmd_template.words[7],
4894 sizeof(uint32_t) * 5);
4897 bf_set(wqe_tmo, &wqe->fcp_iread.wqe_com, tmo);
4899 fcp_cmnd->fcpCntl3 = READ_DATA;
4901 hdwq->scsi_cstat.input_requests++;
4903 /* For a CMF Managed port, iod must be zero'ed */
4904 if (phba->cmf_active_mode == LPFC_CFG_MANAGED)
4905 bf_set(wqe_iod, &wqe->fcp_iread.wqe_com,
4909 /* From the icmnd template, initialize words 4 - 11 */
4910 memcpy(&wqe->words[4], &lpfc_icmnd_cmd_template.words[4],
4911 sizeof(uint32_t) * 8);
4914 bf_set(wqe_tmo, &wqe->fcp_icmd.wqe_com, tmo);
4916 fcp_cmnd->fcpCntl3 = 0;
4918 hdwq->scsi_cstat.control_requests++;
4922 * Finish initializing those WQE fields that are independent
4923 * of the request_buffer
4927 bf_set(payload_offset_len, &wqe->fcp_icmd,
4928 sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp));
4931 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
4932 phba->sli4_hba.rpi_ids[pnode->nlp_rpi]);
4933 bf_set(wqe_xri_tag, &wqe->generic.wqe_com, pwqeq->sli4_xritag);
4936 if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE)
4937 bf_set(wqe_erp, &wqe->generic.wqe_com, 1);
4939 bf_set(wqe_class, &wqe->generic.wqe_com,
4940 (pnode->nlp_fcp_info & 0x0f));
4943 wqe->generic.wqe_com.abort_tag = pwqeq->iotag;
4946 bf_set(wqe_reqtag, &wqe->generic.wqe_com, pwqeq->iotag);
4948 pwqeq->vport = vport;
4949 pwqeq->vport = vport;
4950 pwqeq->context1 = lpfc_cmd;
4951 pwqeq->hba_wqidx = lpfc_cmd->hdwq_no;
4952 pwqeq->wqe_cmpl = lpfc_fcp_io_cmd_wqe_cmpl;
4958 * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit
4959 * @vport: The virtual port for which this call is being executed.
4960 * @lpfc_cmd: The scsi command which needs to send.
4961 * @pnode: Pointer to lpfc_nodelist.
4963 * This routine initializes fcp_cmnd and iocb data structure from scsi command
4964 * to transfer for device with SLI3 interface spec.
4967 lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_io_buf *lpfc_cmd,
4968 struct lpfc_nodelist *pnode)
4970 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
4971 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
4977 lpfc_cmd->fcp_rsp->rspSnsLen = 0;
4978 /* clear task management bits */
4979 lpfc_cmd->fcp_cmnd->fcpCntl2 = 0;
4981 int_to_scsilun(lpfc_cmd->pCmd->device->lun,
4982 &lpfc_cmd->fcp_cmnd->fcp_lun);
4984 ptr = &fcp_cmnd->fcpCdb[0];
4985 memcpy(ptr, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
4986 if (scsi_cmnd->cmd_len < LPFC_FCP_CDB_LEN) {
4987 ptr += scsi_cmnd->cmd_len;
4988 memset(ptr, 0, (LPFC_FCP_CDB_LEN - scsi_cmnd->cmd_len));
4991 fcp_cmnd->fcpCntl1 = SIMPLE_Q;
4993 lpfc_scsi_prep_cmnd_buf(vport, lpfc_cmd, lpfc_cmd->timeout);
4999 * lpfc_scsi_prep_task_mgmt_cmd - Convert SLI3 scsi TM cmd to FCP info unit
5000 * @vport: The virtual port for which this call is being executed.
5001 * @lpfc_cmd: Pointer to lpfc_io_buf data structure.
5002 * @lun: Logical unit number.
5003 * @task_mgmt_cmd: SCSI task management command.
5005 * This routine creates FCP information unit corresponding to @task_mgmt_cmd
5006 * for device with SLI-3 interface spec.
5013 lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport,
5014 struct lpfc_io_buf *lpfc_cmd,
5016 uint8_t task_mgmt_cmd)
5018 struct lpfc_iocbq *piocbq;
5020 struct fcp_cmnd *fcp_cmnd;
5021 struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
5022 struct lpfc_nodelist *ndlp = rdata->pnode;
5024 if (!ndlp || ndlp->nlp_state != NLP_STE_MAPPED_NODE)
5027 piocbq = &(lpfc_cmd->cur_iocbq);
5028 piocbq->vport = vport;
5030 piocb = &piocbq->iocb;
5032 fcp_cmnd = lpfc_cmd->fcp_cmnd;
5033 /* Clear out any old data in the FCP command area */
5034 memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd));
5035 int_to_scsilun(lun, &fcp_cmnd->fcp_lun);
5036 fcp_cmnd->fcpCntl2 = task_mgmt_cmd;
5037 if (vport->phba->sli_rev == 3 &&
5038 !(vport->phba->sli3_options & LPFC_SLI3_BG_ENABLED))
5039 lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd);
5040 piocb->ulpCommand = CMD_FCP_ICMND64_CR;
5041 piocb->ulpContext = ndlp->nlp_rpi;
5042 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
5044 vport->phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
5046 piocb->ulpFCP2Rcvy = (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) ? 1 : 0;
5047 piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f);
5049 piocb->un.fcpi.fcpi_parm = 0;
5051 /* ulpTimeout is only one byte */
5052 if (lpfc_cmd->timeout > 0xff) {
5054 * Do not timeout the command at the firmware level.
5055 * The driver will provide the timeout mechanism.
5057 piocb->ulpTimeout = 0;
5059 piocb->ulpTimeout = lpfc_cmd->timeout;
5061 if (vport->phba->sli_rev == LPFC_SLI_REV4)
5062 lpfc_sli4_set_rsp_sgl_last(vport->phba, lpfc_cmd);
5068 * lpfc_scsi_api_table_setup - Set up scsi api function jump table
5069 * @phba: The hba struct for which this call is being executed.
5070 * @dev_grp: The HBA PCI-Device group number.
5072 * This routine sets up the SCSI interface API function jump table in @phba
5074 * Returns: 0 - success, -ENODEV - failure.
5077 lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
5080 phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf;
5083 case LPFC_PCI_DEV_LP:
5084 phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3;
5085 phba->lpfc_bg_scsi_prep_dma_buf = lpfc_bg_scsi_prep_dma_buf_s3;
5086 phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3;
5087 phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s3;
5088 phba->lpfc_scsi_prep_cmnd_buf = lpfc_scsi_prep_cmnd_buf_s3;
5090 case LPFC_PCI_DEV_OC:
5091 phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s4;
5092 phba->lpfc_bg_scsi_prep_dma_buf = lpfc_bg_scsi_prep_dma_buf_s4;
5093 phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s4;
5094 phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s4;
5095 phba->lpfc_scsi_prep_cmnd_buf = lpfc_scsi_prep_cmnd_buf_s4;
5098 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5099 "1418 Invalid HBA PCI-device group: 0x%x\n",
5103 phba->lpfc_rampdown_queue_depth = lpfc_rampdown_queue_depth;
5104 phba->lpfc_scsi_cmd_iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
5109 * lpfc_tskmgmt_def_cmpl - IOCB completion routine for task management command
5110 * @phba: The Hba for which this call is being executed.
5111 * @cmdiocbq: Pointer to lpfc_iocbq data structure.
5112 * @rspiocbq: Pointer to lpfc_iocbq data structure.
5114 * This routine is IOCB completion routine for device reset and target reset
5115 * routine. This routine release scsi buffer associated with lpfc_cmd.
5118 lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba,
5119 struct lpfc_iocbq *cmdiocbq,
5120 struct lpfc_iocbq *rspiocbq)
5122 struct lpfc_io_buf *lpfc_cmd =
5123 (struct lpfc_io_buf *) cmdiocbq->context1;
5125 lpfc_release_scsi_buf(phba, lpfc_cmd);
5130 * lpfc_check_pci_resettable - Walks list of devices on pci_dev's bus to check
5131 * if issuing a pci_bus_reset is possibly unsafe
5132 * @phba: lpfc_hba pointer.
5135 * Walks the bus_list to ensure only PCI devices with Emulex
5136 * vendor id, device ids that support hot reset, and only one occurrence
5140 * -EBADSLT, detected invalid device
5144 lpfc_check_pci_resettable(struct lpfc_hba *phba)
5146 const struct pci_dev *pdev = phba->pcidev;
5147 struct pci_dev *ptr = NULL;
5150 /* Walk the list of devices on the pci_dev's bus */
5151 list_for_each_entry(ptr, &pdev->bus->devices, bus_list) {
5152 /* Check for Emulex Vendor ID */
5153 if (ptr->vendor != PCI_VENDOR_ID_EMULEX) {
5154 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5155 "8346 Non-Emulex vendor found: "
5156 "0x%04x\n", ptr->vendor);
5160 /* Check for valid Emulex Device ID */
5161 if (phba->sli_rev != LPFC_SLI_REV4 ||
5162 phba->hba_flag & HBA_FCOE_MODE) {
5163 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5164 "8347 Incapable PCI reset device: "
5165 "0x%04x\n", ptr->device);
5169 /* Check for only one function 0 ID to ensure only one HBA on
5172 if (ptr->devfn == 0) {
5173 if (++counter > 1) {
5174 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5175 "8348 More than one device on "
5176 "secondary bus found\n");
5186 * lpfc_info - Info entry point of scsi_host_template data structure
5187 * @host: The scsi host for which this call is being executed.
5189 * This routine provides module information about hba.
5192 * Pointer to char - Success.
5195 lpfc_info(struct Scsi_Host *host)
5197 struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata;
5198 struct lpfc_hba *phba = vport->phba;
5200 static char lpfcinfobuf[384];
5201 char tmp[384] = {0};
5203 memset(lpfcinfobuf, 0, sizeof(lpfcinfobuf));
5204 if (phba && phba->pcidev){
5205 /* Model Description */
5206 scnprintf(tmp, sizeof(tmp), phba->ModelDesc);
5207 if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >=
5208 sizeof(lpfcinfobuf))
5212 scnprintf(tmp, sizeof(tmp),
5213 " on PCI bus %02x device %02x irq %d",
5214 phba->pcidev->bus->number, phba->pcidev->devfn,
5216 if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >=
5217 sizeof(lpfcinfobuf))
5221 if (phba->Port[0]) {
5222 scnprintf(tmp, sizeof(tmp), " port %s", phba->Port);
5223 if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >=
5224 sizeof(lpfcinfobuf))
5229 link_speed = lpfc_sli_port_speed_get(phba);
5230 if (link_speed != 0) {
5231 scnprintf(tmp, sizeof(tmp),
5232 " Logical Link Speed: %d Mbps", link_speed);
5233 if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >=
5234 sizeof(lpfcinfobuf))
5238 /* PCI resettable */
5239 if (!lpfc_check_pci_resettable(phba)) {
5240 scnprintf(tmp, sizeof(tmp), " PCI resettable");
5241 strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf));
5250 * lpfc_poll_rearm_timer - Routine to modify fcp_poll timer of hba
5251 * @phba: The Hba for which this call is being executed.
5253 * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo.
5254 * The default value of cfg_poll_tmo is 10 milliseconds.
5256 static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba)
5258 unsigned long poll_tmo_expires =
5259 (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo));
5261 if (!list_empty(&phba->sli.sli3_ring[LPFC_FCP_RING].txcmplq))
5262 mod_timer(&phba->fcp_poll_timer,
5267 * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA
5268 * @phba: The Hba for which this call is being executed.
5270 * This routine starts the fcp_poll_timer of @phba.
5272 void lpfc_poll_start_timer(struct lpfc_hba * phba)
5274 lpfc_poll_rearm_timer(phba);
5278 * lpfc_poll_timeout - Restart polling timer
5279 * @t: Timer construct where lpfc_hba data structure pointer is obtained.
5281 * This routine restarts fcp_poll timer, when FCP ring polling is enable
5282 * and FCP Ring interrupt is disable.
5284 void lpfc_poll_timeout(struct timer_list *t)
5286 struct lpfc_hba *phba = from_timer(phba, t, fcp_poll_timer);
5288 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
5289 lpfc_sli_handle_fast_ring_event(phba,
5290 &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ);
5292 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
5293 lpfc_poll_rearm_timer(phba);
5298 * lpfc_get_vmid_from_hashtable - search the UUID in the hash table
5299 * @vport: The virtual port for which this call is being executed.
5300 * @hash: calculated hash value
5301 * @buf: uuid associated with the VE
5302 * Return the VMID entry associated with the UUID
5303 * Make sure to acquire the appropriate lock before invoking this routine.
5305 struct lpfc_vmid *lpfc_get_vmid_from_hashtable(struct lpfc_vport *vport,
5308 struct lpfc_vmid *vmp;
5310 hash_for_each_possible(vport->hash_table, vmp, hnode, hash) {
5311 if (memcmp(&vmp->host_vmid[0], buf, 16) == 0)
5318 * lpfc_put_vmid_in_hashtable - put the VMID in the hash table
5319 * @vport: The virtual port for which this call is being executed.
5320 * @hash - calculated hash value
5321 * @vmp: Pointer to a VMID entry representing a VM sending I/O
5323 * This routine will insert the newly acquired VMID entity in the hash table.
5324 * Make sure to acquire the appropriate lock before invoking this routine.
5327 lpfc_put_vmid_in_hashtable(struct lpfc_vport *vport, u32 hash,
5328 struct lpfc_vmid *vmp)
5330 hash_add(vport->hash_table, &vmp->hnode, hash);
5334 * lpfc_vmid_hash_fn - create a hash value of the UUID
5335 * @vmid: uuid associated with the VE
5336 * @len: length of the VMID string
5337 * Returns the calculated hash value
5339 int lpfc_vmid_hash_fn(const char *vmid, int len)
5348 if (c >= 'A' && c <= 'Z')
5351 hash = (hash + (c << LPFC_VMID_HASH_SHIFT) +
5352 (c >> LPFC_VMID_HASH_SHIFT)) * 19;
5355 return hash & LPFC_VMID_HASH_MASK;
5359 * lpfc_vmid_update_entry - update the vmid entry in the hash table
5360 * @vport: The virtual port for which this call is being executed.
5361 * @cmd: address of scsi cmd descriptor
5362 * @vmp: Pointer to a VMID entry representing a VM sending I/O
5365 static void lpfc_vmid_update_entry(struct lpfc_vport *vport, struct scsi_cmnd
5366 *cmd, struct lpfc_vmid *vmp,
5367 union lpfc_vmid_io_tag *tag)
5371 if (vport->vmid_priority_tagging)
5372 tag->cs_ctl_vmid = vmp->un.cs_ctl_vmid;
5374 tag->app_id = vmp->un.app_id;
5376 if (cmd->sc_data_direction == DMA_TO_DEVICE)
5381 /* update the last access timestamp in the table */
5382 lta = per_cpu_ptr(vmp->last_io_time, raw_smp_processor_id());
5386 static void lpfc_vmid_assign_cs_ctl(struct lpfc_vport *vport,
5387 struct lpfc_vmid *vmid)
5390 struct lpfc_vmid *pvmid;
5392 if (vport->port_type == LPFC_PHYSICAL_PORT) {
5393 vmid->un.cs_ctl_vmid = lpfc_vmid_get_cs_ctl(vport);
5395 hash = lpfc_vmid_hash_fn(vmid->host_vmid, vmid->vmid_len);
5397 lpfc_get_vmid_from_hashtable(vport->phba->pport, hash,
5400 vmid->un.cs_ctl_vmid = pvmid->un.cs_ctl_vmid;
5402 vmid->un.cs_ctl_vmid = lpfc_vmid_get_cs_ctl(vport);
5407 * lpfc_vmid_get_appid - get the VMID associated with the UUID
5408 * @vport: The virtual port for which this call is being executed.
5409 * @uuid: UUID associated with the VE
5410 * @cmd: address of scsi_cmd descriptor
5412 * Returns status of the function
5414 static int lpfc_vmid_get_appid(struct lpfc_vport *vport, char *uuid, struct
5415 scsi_cmnd * cmd, union lpfc_vmid_io_tag *tag)
5417 struct lpfc_vmid *vmp = NULL;
5418 int hash, len, rc, i;
5420 /* check if QFPA is complete */
5421 if (lpfc_vmid_is_type_priority_tag(vport) && !(vport->vmid_flag &
5422 LPFC_VMID_QFPA_CMPL)) {
5423 vport->work_port_events |= WORKER_CHECK_VMID_ISSUE_QFPA;
5427 /* search if the UUID has already been mapped to the VMID */
5429 hash = lpfc_vmid_hash_fn(uuid, len);
5431 /* search for the VMID in the table */
5432 read_lock(&vport->vmid_lock);
5433 vmp = lpfc_get_vmid_from_hashtable(vport, hash, uuid);
5435 /* if found, check if its already registered */
5436 if (vmp && vmp->flag & LPFC_VMID_REGISTERED) {
5437 read_unlock(&vport->vmid_lock);
5438 lpfc_vmid_update_entry(vport, cmd, vmp, tag);
5440 } else if (vmp && (vmp->flag & LPFC_VMID_REQ_REGISTER ||
5441 vmp->flag & LPFC_VMID_DE_REGISTER)) {
5442 /* else if register or dereg request has already been sent */
5443 /* Hence VMID tag will not be added for this I/O */
5444 read_unlock(&vport->vmid_lock);
5447 /* The VMID was not found in the hashtable. At this point, */
5448 /* drop the read lock first before proceeding further */
5449 read_unlock(&vport->vmid_lock);
5450 /* start the process to obtain one as per the */
5451 /* type of the VMID indicated */
5452 write_lock(&vport->vmid_lock);
5453 vmp = lpfc_get_vmid_from_hashtable(vport, hash, uuid);
5455 /* while the read lock was released, in case the entry was */
5456 /* added by other context or is in process of being added */
5457 if (vmp && vmp->flag & LPFC_VMID_REGISTERED) {
5458 lpfc_vmid_update_entry(vport, cmd, vmp, tag);
5459 write_unlock(&vport->vmid_lock);
5461 } else if (vmp && vmp->flag & LPFC_VMID_REQ_REGISTER) {
5462 write_unlock(&vport->vmid_lock);
5466 /* else search and allocate a free slot in the hash table */
5467 if (vport->cur_vmid_cnt < vport->max_vmid) {
5468 for (i = 0; i < vport->max_vmid; i++) {
5469 vmp = vport->vmid + i;
5470 if (vmp->flag == LPFC_VMID_SLOT_FREE)
5473 if (i == vport->max_vmid)
5480 write_unlock(&vport->vmid_lock);
5484 /* Add the vmid and register */
5485 lpfc_put_vmid_in_hashtable(vport, hash, vmp);
5486 vmp->vmid_len = len;
5487 memcpy(vmp->host_vmid, uuid, vmp->vmid_len);
5490 vmp->flag = LPFC_VMID_SLOT_USED;
5492 vmp->delete_inactive =
5493 vport->vmid_inactivity_timeout ? 1 : 0;
5495 /* if type priority tag, get next available VMID */
5496 if (lpfc_vmid_is_type_priority_tag(vport))
5497 lpfc_vmid_assign_cs_ctl(vport, vmp);
5499 /* allocate the per cpu variable for holding */
5500 /* the last access time stamp only if VMID is enabled */
5501 if (!vmp->last_io_time)
5502 vmp->last_io_time = __alloc_percpu(sizeof(u64),
5505 if (!vmp->last_io_time) {
5506 hash_del(&vmp->hnode);
5507 vmp->flag = LPFC_VMID_SLOT_FREE;
5508 write_unlock(&vport->vmid_lock);
5512 write_unlock(&vport->vmid_lock);
5514 /* complete transaction with switch */
5515 if (lpfc_vmid_is_type_priority_tag(vport))
5516 rc = lpfc_vmid_uvem(vport, vmp, true);
5518 rc = lpfc_vmid_cmd(vport, SLI_CTAS_RAPP_IDENT, vmp);
5520 write_lock(&vport->vmid_lock);
5521 vport->cur_vmid_cnt++;
5522 vmp->flag |= LPFC_VMID_REQ_REGISTER;
5523 write_unlock(&vport->vmid_lock);
5525 write_lock(&vport->vmid_lock);
5526 hash_del(&vmp->hnode);
5527 vmp->flag = LPFC_VMID_SLOT_FREE;
5528 free_percpu(vmp->last_io_time);
5529 write_unlock(&vport->vmid_lock);
5533 /* finally, enable the idle timer once */
5534 if (!(vport->phba->pport->vmid_flag & LPFC_VMID_TIMER_ENBLD)) {
5535 mod_timer(&vport->phba->inactive_vmid_poll,
5537 msecs_to_jiffies(1000 * LPFC_VMID_TIMER));
5538 vport->phba->pport->vmid_flag |= LPFC_VMID_TIMER_ENBLD;
5545 * lpfc_is_command_vm_io - get the UUID from blk cgroup
5546 * @cmd: Pointer to scsi_cmnd data structure
5547 * Returns UUID if present, otherwise NULL
5549 static char *lpfc_is_command_vm_io(struct scsi_cmnd *cmd)
5551 struct bio *bio = scsi_cmd_to_rq(cmd)->bio;
5553 return bio ? blkcg_get_fc_appid(bio) : NULL;
5557 * lpfc_queuecommand - scsi_host_template queuecommand entry point
5558 * @shost: kernel scsi host pointer.
5559 * @cmnd: Pointer to scsi_cmnd data structure.
5561 * Driver registers this routine to scsi midlayer to submit a @cmd to process.
5562 * This routine prepares an IOCB from scsi command and provides to firmware.
5563 * The @done callback is invoked after driver finished processing the command.
5567 * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily.
5570 lpfc_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *cmnd)
5572 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5573 struct lpfc_hba *phba = vport->phba;
5574 struct lpfc_rport_data *rdata;
5575 struct lpfc_nodelist *ndlp;
5576 struct lpfc_io_buf *lpfc_cmd;
5577 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
5582 start = ktime_get_ns();
5583 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
5585 /* sanity check on references */
5586 if (unlikely(!rdata) || unlikely(!rport))
5587 goto out_fail_command;
5589 err = fc_remote_port_chkready(rport);
5592 goto out_fail_command;
5594 ndlp = rdata->pnode;
5596 if ((scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) &&
5597 (!(phba->sli3_options & LPFC_SLI3_BG_ENABLED))) {
5599 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5600 "9058 BLKGRD: ERROR: rcvd protected cmd:%02x"
5601 " op:%02x str=%s without registering for"
5602 " BlockGuard - Rejecting command\n",
5603 cmnd->cmnd[0], scsi_get_prot_op(cmnd),
5604 dif_op_str[scsi_get_prot_op(cmnd)]);
5605 goto out_fail_command;
5609 * Catch race where our node has transitioned, but the
5610 * transport is still transitioning.
5615 /* Check if IO qualifies for CMF */
5616 if (phba->cmf_active_mode != LPFC_CFG_OFF &&
5617 cmnd->sc_data_direction == DMA_FROM_DEVICE &&
5618 (scsi_sg_count(cmnd))) {
5619 /* Latency start time saved in rx_cmd_start later in routine */
5620 err = lpfc_update_cmf_cmd(phba, scsi_bufflen(cmnd));
5625 if (lpfc_ndlp_check_qdepth(phba, ndlp)) {
5626 if (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth) {
5627 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_ERROR,
5628 "3377 Target Queue Full, scsi Id:%d "
5629 "Qdepth:%d Pending command:%d"
5630 " WWNN:%02x:%02x:%02x:%02x:"
5631 "%02x:%02x:%02x:%02x, "
5632 " WWPN:%02x:%02x:%02x:%02x:"
5633 "%02x:%02x:%02x:%02x",
5634 ndlp->nlp_sid, ndlp->cmd_qdepth,
5635 atomic_read(&ndlp->cmd_pending),
5636 ndlp->nlp_nodename.u.wwn[0],
5637 ndlp->nlp_nodename.u.wwn[1],
5638 ndlp->nlp_nodename.u.wwn[2],
5639 ndlp->nlp_nodename.u.wwn[3],
5640 ndlp->nlp_nodename.u.wwn[4],
5641 ndlp->nlp_nodename.u.wwn[5],
5642 ndlp->nlp_nodename.u.wwn[6],
5643 ndlp->nlp_nodename.u.wwn[7],
5644 ndlp->nlp_portname.u.wwn[0],
5645 ndlp->nlp_portname.u.wwn[1],
5646 ndlp->nlp_portname.u.wwn[2],
5647 ndlp->nlp_portname.u.wwn[3],
5648 ndlp->nlp_portname.u.wwn[4],
5649 ndlp->nlp_portname.u.wwn[5],
5650 ndlp->nlp_portname.u.wwn[6],
5651 ndlp->nlp_portname.u.wwn[7]);
5656 lpfc_cmd = lpfc_get_scsi_buf(phba, ndlp, cmnd);
5657 if (lpfc_cmd == NULL) {
5658 lpfc_rampdown_queue_depth(phba);
5660 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_ERROR,
5661 "0707 driver's buffer pool is empty, "
5665 lpfc_cmd->rx_cmd_start = start;
5668 * Store the midlayer's command structure for the completion phase
5669 * and complete the command initialization.
5671 lpfc_cmd->pCmd = cmnd;
5672 lpfc_cmd->rdata = rdata;
5673 lpfc_cmd->ndlp = ndlp;
5674 lpfc_cmd->cur_iocbq.iocb_cmpl = NULL;
5675 cmnd->host_scribble = (unsigned char *)lpfc_cmd;
5677 err = lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp);
5679 goto out_host_busy_release_buf;
5681 if (scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) {
5682 if (vport->phba->cfg_enable_bg) {
5683 lpfc_printf_vlog(vport,
5684 KERN_INFO, LOG_SCSI_CMD,
5685 "9033 BLKGRD: rcvd %s cmd:x%x "
5686 "reftag x%x cnt %u pt %x\n",
5687 dif_op_str[scsi_get_prot_op(cmnd)],
5689 scsi_prot_ref_tag(cmnd),
5690 scsi_logical_block_count(cmnd),
5691 (cmnd->cmnd[1]>>5));
5693 err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd);
5695 if (vport->phba->cfg_enable_bg) {
5696 lpfc_printf_vlog(vport,
5697 KERN_INFO, LOG_SCSI_CMD,
5698 "9038 BLKGRD: rcvd PROT_NORMAL cmd: "
5699 "x%x reftag x%x cnt %u pt %x\n",
5701 scsi_prot_ref_tag(cmnd),
5702 scsi_logical_block_count(cmnd),
5703 (cmnd->cmnd[1]>>5));
5705 err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd);
5708 if (unlikely(err)) {
5710 cmnd->result = DID_ERROR << 16;
5711 goto out_fail_command_release_buf;
5713 goto out_host_busy_free_buf;
5717 /* check the necessary and sufficient condition to support VMID */
5718 if (lpfc_is_vmid_enabled(phba) &&
5719 (ndlp->vmid_support ||
5720 phba->pport->vmid_priority_tagging ==
5721 LPFC_VMID_PRIO_TAG_ALL_TARGETS)) {
5722 /* is the I/O generated by a VM, get the associated virtual */
5724 uuid = lpfc_is_command_vm_io(cmnd);
5727 err = lpfc_vmid_get_appid(vport, uuid, cmnd,
5728 (union lpfc_vmid_io_tag *)
5729 &lpfc_cmd->cur_iocbq.vmid_tag);
5731 lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_VMID;
5735 atomic_inc(&ndlp->cmd_pending);
5736 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5737 if (unlikely(phba->hdwqstat_on & LPFC_CHECK_SCSI_IO))
5738 this_cpu_inc(phba->sli4_hba.c_stat->xmt_io);
5740 /* Issue I/O to adapter */
5741 err = lpfc_sli_issue_fcp_io(phba, LPFC_FCP_RING,
5742 &lpfc_cmd->cur_iocbq,
5744 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5746 lpfc_cmd->ts_cmd_start = start;
5747 lpfc_cmd->ts_last_cmd = phba->ktime_last_cmd;
5748 lpfc_cmd->ts_cmd_wqput = ktime_get_ns();
5750 lpfc_cmd->ts_cmd_start = 0;
5754 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
5755 "3376 FCP could not issue IOCB err %x "
5756 "FCP cmd x%x <%d/%llu> "
5757 "sid: x%x did: x%x oxid: x%x "
5758 "Data: x%x x%x x%x x%x\n",
5760 cmnd->device ? cmnd->device->id : 0xffff,
5761 cmnd->device ? cmnd->device->lun : (u64)-1,
5762 vport->fc_myDID, ndlp->nlp_DID,
5763 phba->sli_rev == LPFC_SLI_REV4 ?
5764 lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff,
5765 phba->sli_rev == LPFC_SLI_REV4 ?
5766 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi] :
5767 lpfc_cmd->cur_iocbq.iocb.ulpContext,
5768 lpfc_cmd->cur_iocbq.iotag,
5769 phba->sli_rev == LPFC_SLI_REV4 ?
5771 &lpfc_cmd->cur_iocbq.wqe.generic.wqe_com) :
5772 lpfc_cmd->cur_iocbq.iocb.ulpTimeout,
5773 (uint32_t)(scsi_cmd_to_rq(cmnd)->timeout / 1000));
5775 goto out_host_busy_free_buf;
5778 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
5779 lpfc_sli_handle_fast_ring_event(phba,
5780 &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ);
5782 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
5783 lpfc_poll_rearm_timer(phba);
5786 if (phba->cfg_xri_rebalancing)
5787 lpfc_keep_pvt_pool_above_lowwm(phba, lpfc_cmd->hdwq_no);
5791 out_host_busy_free_buf:
5792 idx = lpfc_cmd->hdwq_no;
5793 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
5794 if (phba->sli4_hba.hdwq) {
5795 switch (lpfc_cmd->fcp_cmnd->fcpCntl3) {
5797 phba->sli4_hba.hdwq[idx].scsi_cstat.output_requests--;
5800 phba->sli4_hba.hdwq[idx].scsi_cstat.input_requests--;
5803 phba->sli4_hba.hdwq[idx].scsi_cstat.control_requests--;
5806 out_host_busy_release_buf:
5807 lpfc_release_scsi_buf(phba, lpfc_cmd);
5809 lpfc_update_cmf_cmpl(phba, LPFC_CGN_NOT_SENT, scsi_bufflen(cmnd),
5811 return SCSI_MLQUEUE_HOST_BUSY;
5814 lpfc_update_cmf_cmpl(phba, LPFC_CGN_NOT_SENT, scsi_bufflen(cmnd),
5817 return SCSI_MLQUEUE_TARGET_BUSY;
5819 out_fail_command_release_buf:
5820 lpfc_release_scsi_buf(phba, lpfc_cmd);
5821 lpfc_update_cmf_cmpl(phba, LPFC_CGN_NOT_SENT, scsi_bufflen(cmnd),
5825 cmnd->scsi_done(cmnd);
5830 * lpfc_vmid_vport_cleanup - cleans up the resources associated with a vport
5831 * @vport: The virtual port for which this call is being executed.
5833 void lpfc_vmid_vport_cleanup(struct lpfc_vport *vport)
5836 struct lpfc_vmid *cur;
5838 if (vport->port_type == LPFC_PHYSICAL_PORT)
5839 del_timer_sync(&vport->phba->inactive_vmid_poll);
5841 kfree(vport->qfpa_res);
5842 kfree(vport->vmid_priority.vmid_range);
5845 if (!hash_empty(vport->hash_table))
5846 hash_for_each(vport->hash_table, bucket, cur, hnode)
5847 hash_del(&cur->hnode);
5849 vport->qfpa_res = NULL;
5850 vport->vmid_priority.vmid_range = NULL;
5852 vport->cur_vmid_cnt = 0;
5856 * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point
5857 * @cmnd: Pointer to scsi_cmnd data structure.
5859 * This routine aborts @cmnd pending in base driver.
5866 lpfc_abort_handler(struct scsi_cmnd *cmnd)
5868 struct Scsi_Host *shost = cmnd->device->host;
5869 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5870 struct lpfc_hba *phba = vport->phba;
5871 struct lpfc_iocbq *iocb;
5872 struct lpfc_io_buf *lpfc_cmd;
5873 int ret = SUCCESS, status = 0;
5874 struct lpfc_sli_ring *pring_s4 = NULL;
5875 struct lpfc_sli_ring *pring = NULL;
5877 unsigned long flags;
5878 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq);
5880 status = fc_block_scsi_eh(cmnd);
5881 if (status != 0 && status != SUCCESS)
5884 lpfc_cmd = (struct lpfc_io_buf *)cmnd->host_scribble;
5888 spin_lock_irqsave(&phba->hbalock, flags);
5889 /* driver queued commands are in process of being flushed */
5890 if (phba->hba_flag & HBA_IOQ_FLUSH) {
5891 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
5892 "3168 SCSI Layer abort requested I/O has been "
5893 "flushed by LLD.\n");
5898 /* Guard against IO completion being called at same time */
5899 spin_lock(&lpfc_cmd->buf_lock);
5901 if (!lpfc_cmd->pCmd) {
5902 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
5903 "2873 SCSI Layer I/O Abort Request IO CMPL Status "
5904 "x%x ID %d LUN %llu\n",
5905 SUCCESS, cmnd->device->id, cmnd->device->lun);
5906 goto out_unlock_buf;
5909 iocb = &lpfc_cmd->cur_iocbq;
5910 if (phba->sli_rev == LPFC_SLI_REV4) {
5911 pring_s4 = phba->sli4_hba.hdwq[iocb->hba_wqidx].io_wq->pring;
5914 goto out_unlock_buf;
5916 spin_lock(&pring_s4->ring_lock);
5918 /* the command is in process of being cancelled */
5919 if (!(iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ)) {
5920 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
5921 "3169 SCSI Layer abort requested I/O has been "
5922 "cancelled by LLD.\n");
5924 goto out_unlock_ring;
5927 * If pCmd field of the corresponding lpfc_io_buf structure
5928 * points to a different SCSI command, then the driver has
5929 * already completed this command, but the midlayer did not
5930 * see the completion before the eh fired. Just return SUCCESS.
5932 if (lpfc_cmd->pCmd != cmnd) {
5933 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
5934 "3170 SCSI Layer abort requested I/O has been "
5935 "completed by LLD.\n");
5936 goto out_unlock_ring;
5939 BUG_ON(iocb->context1 != lpfc_cmd);
5941 /* abort issued in recovery is still in progress */
5942 if (iocb->iocb_flag & LPFC_DRIVER_ABORTED) {
5943 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
5944 "3389 SCSI Layer I/O Abort Request is pending\n");
5945 if (phba->sli_rev == LPFC_SLI_REV4)
5946 spin_unlock(&pring_s4->ring_lock);
5947 spin_unlock(&lpfc_cmd->buf_lock);
5948 spin_unlock_irqrestore(&phba->hbalock, flags);
5952 lpfc_cmd->waitq = &waitq;
5953 if (phba->sli_rev == LPFC_SLI_REV4) {
5954 spin_unlock(&pring_s4->ring_lock);
5955 ret_val = lpfc_sli4_issue_abort_iotag(phba, iocb,
5956 lpfc_sli4_abort_fcp_cmpl);
5958 pring = &phba->sli.sli3_ring[LPFC_FCP_RING];
5959 ret_val = lpfc_sli_issue_abort_iotag(phba, pring, iocb,
5960 lpfc_sli_abort_fcp_cmpl);
5963 /* Make sure HBA is alive */
5964 lpfc_issue_hb_tmo(phba);
5966 if (ret_val != IOCB_SUCCESS) {
5967 /* Indicate the IO is not being aborted by the driver. */
5968 lpfc_cmd->waitq = NULL;
5969 spin_unlock(&lpfc_cmd->buf_lock);
5970 spin_unlock_irqrestore(&phba->hbalock, flags);
5975 /* no longer need the lock after this point */
5976 spin_unlock(&lpfc_cmd->buf_lock);
5977 spin_unlock_irqrestore(&phba->hbalock, flags);
5979 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
5980 lpfc_sli_handle_fast_ring_event(phba,
5981 &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ);
5985 * iocb_flag is set to LPFC_DRIVER_ABORTED before we wait
5986 * for abort to complete.
5988 wait_event_timeout(waitq,
5989 (lpfc_cmd->pCmd != cmnd),
5990 msecs_to_jiffies(2*vport->cfg_devloss_tmo*1000));
5992 spin_lock(&lpfc_cmd->buf_lock);
5994 if (lpfc_cmd->pCmd == cmnd) {
5996 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5997 "0748 abort handler timed out waiting "
5998 "for aborting I/O (xri:x%x) to complete: "
5999 "ret %#x, ID %d, LUN %llu\n",
6000 iocb->sli4_xritag, ret,
6001 cmnd->device->id, cmnd->device->lun);
6004 lpfc_cmd->waitq = NULL;
6006 spin_unlock(&lpfc_cmd->buf_lock);
6010 if (phba->sli_rev == LPFC_SLI_REV4)
6011 spin_unlock(&pring_s4->ring_lock);
6013 spin_unlock(&lpfc_cmd->buf_lock);
6015 spin_unlock_irqrestore(&phba->hbalock, flags);
6017 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
6018 "0749 SCSI Layer I/O Abort Request Status x%x ID %d "
6019 "LUN %llu\n", ret, cmnd->device->id,
6025 lpfc_taskmgmt_name(uint8_t task_mgmt_cmd)
6027 switch (task_mgmt_cmd) {
6028 case FCP_ABORT_TASK_SET:
6029 return "ABORT_TASK_SET";
6030 case FCP_CLEAR_TASK_SET:
6031 return "FCP_CLEAR_TASK_SET";
6033 return "FCP_BUS_RESET";
6035 return "FCP_LUN_RESET";
6036 case FCP_TARGET_RESET:
6037 return "FCP_TARGET_RESET";
6039 return "FCP_CLEAR_ACA";
6040 case FCP_TERMINATE_TASK:
6041 return "FCP_TERMINATE_TASK";
6049 * lpfc_check_fcp_rsp - check the returned fcp_rsp to see if task failed
6050 * @vport: The virtual port for which this call is being executed.
6051 * @lpfc_cmd: Pointer to lpfc_io_buf data structure.
6053 * This routine checks the FCP RSP INFO to see if the tsk mgmt command succeded
6060 lpfc_check_fcp_rsp(struct lpfc_vport *vport, struct lpfc_io_buf *lpfc_cmd)
6062 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
6065 uint8_t rsp_info_code;
6070 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
6071 "0703 fcp_rsp is missing\n");
6073 rsp_info = fcprsp->rspStatus2;
6074 rsp_len = be32_to_cpu(fcprsp->rspRspLen);
6075 rsp_info_code = fcprsp->rspInfo3;
6078 lpfc_printf_vlog(vport, KERN_INFO,
6080 "0706 fcp_rsp valid 0x%x,"
6081 " rsp len=%d code 0x%x\n",
6083 rsp_len, rsp_info_code);
6085 /* If FCP_RSP_LEN_VALID bit is one, then the FCP_RSP_LEN
6086 * field specifies the number of valid bytes of FCP_RSP_INFO.
6087 * The FCP_RSP_LEN field shall be set to 0x04 or 0x08
6089 if ((fcprsp->rspStatus2 & RSP_LEN_VALID) &&
6090 ((rsp_len == 8) || (rsp_len == 4))) {
6091 switch (rsp_info_code) {
6092 case RSP_NO_FAILURE:
6093 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
6094 "0715 Task Mgmt No Failure\n");
6097 case RSP_TM_NOT_SUPPORTED: /* TM rejected */
6098 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
6099 "0716 Task Mgmt Target "
6102 case RSP_TM_NOT_COMPLETED: /* TM failed */
6103 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
6104 "0717 Task Mgmt Target "
6107 case RSP_TM_INVALID_LU: /* TM to invalid LU! */
6108 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
6109 "0718 Task Mgmt to invalid "
6120 * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler
6121 * @vport: The virtual port for which this call is being executed.
6122 * @cmnd: Pointer to scsi_cmnd data structure.
6123 * @tgt_id: Target ID of remote device.
6124 * @lun_id: Lun number for the TMF
6125 * @task_mgmt_cmd: type of TMF to send
6127 * This routine builds and sends a TMF (SCSI Task Mgmt Function) to
6135 lpfc_send_taskmgmt(struct lpfc_vport *vport, struct scsi_cmnd *cmnd,
6136 unsigned int tgt_id, uint64_t lun_id,
6137 uint8_t task_mgmt_cmd)
6139 struct lpfc_hba *phba = vport->phba;
6140 struct lpfc_io_buf *lpfc_cmd;
6141 struct lpfc_iocbq *iocbq;
6142 struct lpfc_iocbq *iocbqrsp;
6143 struct lpfc_rport_data *rdata;
6144 struct lpfc_nodelist *pnode;
6148 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
6149 if (!rdata || !rdata->pnode)
6151 pnode = rdata->pnode;
6153 lpfc_cmd = lpfc_get_scsi_buf(phba, pnode, NULL);
6154 if (lpfc_cmd == NULL)
6156 lpfc_cmd->timeout = phba->cfg_task_mgmt_tmo;
6157 lpfc_cmd->rdata = rdata;
6158 lpfc_cmd->pCmd = cmnd;
6159 lpfc_cmd->ndlp = pnode;
6161 status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun_id,
6164 lpfc_release_scsi_buf(phba, lpfc_cmd);
6168 iocbq = &lpfc_cmd->cur_iocbq;
6169 iocbqrsp = lpfc_sli_get_iocbq(phba);
6170 if (iocbqrsp == NULL) {
6171 lpfc_release_scsi_buf(phba, lpfc_cmd);
6174 iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
6176 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
6177 "0702 Issue %s to TGT %d LUN %llu "
6178 "rpi x%x nlp_flag x%x Data: x%x x%x\n",
6179 lpfc_taskmgmt_name(task_mgmt_cmd), tgt_id, lun_id,
6180 pnode->nlp_rpi, pnode->nlp_flag, iocbq->sli4_xritag,
6183 status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING,
6184 iocbq, iocbqrsp, lpfc_cmd->timeout);
6185 if ((status != IOCB_SUCCESS) ||
6186 (iocbqrsp->iocb.ulpStatus != IOSTAT_SUCCESS)) {
6187 if (status != IOCB_SUCCESS ||
6188 iocbqrsp->iocb.ulpStatus != IOSTAT_FCP_RSP_ERROR)
6189 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
6190 "0727 TMF %s to TGT %d LUN %llu "
6191 "failed (%d, %d) iocb_flag x%x\n",
6192 lpfc_taskmgmt_name(task_mgmt_cmd),
6194 iocbqrsp->iocb.ulpStatus,
6195 iocbqrsp->iocb.un.ulpWord[4],
6197 /* if ulpStatus != IOCB_SUCCESS, then status == IOCB_SUCCESS */
6198 if (status == IOCB_SUCCESS) {
6199 if (iocbqrsp->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
6200 /* Something in the FCP_RSP was invalid.
6201 * Check conditions */
6202 ret = lpfc_check_fcp_rsp(vport, lpfc_cmd);
6205 } else if (status == IOCB_TIMEDOUT) {
6206 ret = TIMEOUT_ERROR;
6213 lpfc_sli_release_iocbq(phba, iocbqrsp);
6215 if (ret != TIMEOUT_ERROR)
6216 lpfc_release_scsi_buf(phba, lpfc_cmd);
6222 * lpfc_chk_tgt_mapped -
6223 * @vport: The virtual port to check on
6224 * @cmnd: Pointer to scsi_cmnd data structure.
6226 * This routine delays until the scsi target (aka rport) for the
6227 * command exists (is present and logged in) or we declare it non-existent.
6234 lpfc_chk_tgt_mapped(struct lpfc_vport *vport, struct scsi_cmnd *cmnd)
6236 struct lpfc_rport_data *rdata;
6237 struct lpfc_nodelist *pnode;
6238 unsigned long later;
6240 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
6242 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
6243 "0797 Tgt Map rport failure: rdata x%px\n", rdata);
6246 pnode = rdata->pnode;
6248 * If target is not in a MAPPED state, delay until
6249 * target is rediscovered or devloss timeout expires.
6251 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
6252 while (time_after(later, jiffies)) {
6255 if (pnode->nlp_state == NLP_STE_MAPPED_NODE)
6257 schedule_timeout_uninterruptible(msecs_to_jiffies(500));
6258 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
6261 pnode = rdata->pnode;
6263 if (!pnode || (pnode->nlp_state != NLP_STE_MAPPED_NODE))
6269 * lpfc_reset_flush_io_context -
6270 * @vport: The virtual port (scsi_host) for the flush context
6271 * @tgt_id: If aborting by Target contect - specifies the target id
6272 * @lun_id: If aborting by Lun context - specifies the lun id
6273 * @context: specifies the context level to flush at.
6275 * After a reset condition via TMF, we need to flush orphaned i/o
6276 * contexts from the adapter. This routine aborts any contexts
6277 * outstanding, then waits for their completions. The wait is
6278 * bounded by devloss_tmo though.
6285 lpfc_reset_flush_io_context(struct lpfc_vport *vport, uint16_t tgt_id,
6286 uint64_t lun_id, lpfc_ctx_cmd context)
6288 struct lpfc_hba *phba = vport->phba;
6289 unsigned long later;
6292 cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context);
6294 lpfc_sli_abort_taskmgmt(vport,
6295 &phba->sli.sli3_ring[LPFC_FCP_RING],
6296 tgt_id, lun_id, context);
6297 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
6298 while (time_after(later, jiffies) && cnt) {
6299 schedule_timeout_uninterruptible(msecs_to_jiffies(20));
6300 cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context);
6303 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
6304 "0724 I/O flush failure for context %s : cnt x%x\n",
6305 ((context == LPFC_CTX_LUN) ? "LUN" :
6306 ((context == LPFC_CTX_TGT) ? "TGT" :
6307 ((context == LPFC_CTX_HOST) ? "HOST" : "Unknown"))),
6315 * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point
6316 * @cmnd: Pointer to scsi_cmnd data structure.
6318 * This routine does a device reset by sending a LUN_RESET task management
6326 lpfc_device_reset_handler(struct scsi_cmnd *cmnd)
6328 struct Scsi_Host *shost = cmnd->device->host;
6329 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6330 struct lpfc_rport_data *rdata;
6331 struct lpfc_nodelist *pnode;
6332 unsigned tgt_id = cmnd->device->id;
6333 uint64_t lun_id = cmnd->device->lun;
6334 struct lpfc_scsi_event_header scsi_event;
6336 u32 logit = LOG_FCP;
6338 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
6339 if (!rdata || !rdata->pnode) {
6340 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
6341 "0798 Device Reset rdata failure: rdata x%px\n",
6345 pnode = rdata->pnode;
6346 status = fc_block_scsi_eh(cmnd);
6347 if (status != 0 && status != SUCCESS)
6350 status = lpfc_chk_tgt_mapped(vport, cmnd);
6351 if (status == FAILED) {
6352 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
6353 "0721 Device Reset rport failure: rdata x%px\n", rdata);
6357 scsi_event.event_type = FC_REG_SCSI_EVENT;
6358 scsi_event.subcategory = LPFC_EVENT_LUNRESET;
6359 scsi_event.lun = lun_id;
6360 memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name));
6361 memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name));
6363 fc_host_post_vendor_event(shost, fc_get_event_number(),
6364 sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
6366 status = lpfc_send_taskmgmt(vport, cmnd, tgt_id, lun_id,
6368 if (status != SUCCESS)
6369 logit = LOG_TRACE_EVENT;
6371 lpfc_printf_vlog(vport, KERN_ERR, logit,
6372 "0713 SCSI layer issued Device Reset (%d, %llu) "
6373 "return x%x\n", tgt_id, lun_id, status);
6376 * We have to clean up i/o as : they may be orphaned by the TMF;
6377 * or if the TMF failed, they may be in an indeterminate state.
6379 * We will report success if all the i/o aborts successfully.
6381 if (status == SUCCESS)
6382 status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
6389 * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point
6390 * @cmnd: Pointer to scsi_cmnd data structure.
6392 * This routine does a target reset by sending a TARGET_RESET task management
6400 lpfc_target_reset_handler(struct scsi_cmnd *cmnd)
6402 struct Scsi_Host *shost = cmnd->device->host;
6403 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6404 struct lpfc_rport_data *rdata;
6405 struct lpfc_nodelist *pnode;
6406 unsigned tgt_id = cmnd->device->id;
6407 uint64_t lun_id = cmnd->device->lun;
6408 struct lpfc_scsi_event_header scsi_event;
6410 u32 logit = LOG_FCP;
6411 u32 dev_loss_tmo = vport->cfg_devloss_tmo;
6412 unsigned long flags;
6413 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq);
6415 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
6416 if (!rdata || !rdata->pnode) {
6417 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
6418 "0799 Target Reset rdata failure: rdata x%px\n",
6422 pnode = rdata->pnode;
6423 status = fc_block_scsi_eh(cmnd);
6424 if (status != 0 && status != SUCCESS)
6427 status = lpfc_chk_tgt_mapped(vport, cmnd);
6428 if (status == FAILED) {
6429 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
6430 "0722 Target Reset rport failure: rdata x%px\n", rdata);
6432 spin_lock_irqsave(&pnode->lock, flags);
6433 pnode->nlp_flag &= ~NLP_NPR_ADISC;
6434 pnode->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
6435 spin_unlock_irqrestore(&pnode->lock, flags);
6437 lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
6439 return FAST_IO_FAIL;
6442 scsi_event.event_type = FC_REG_SCSI_EVENT;
6443 scsi_event.subcategory = LPFC_EVENT_TGTRESET;
6445 memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name));
6446 memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name));
6448 fc_host_post_vendor_event(shost, fc_get_event_number(),
6449 sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
6451 status = lpfc_send_taskmgmt(vport, cmnd, tgt_id, lun_id,
6453 if (status != SUCCESS) {
6454 logit = LOG_TRACE_EVENT;
6456 /* Issue LOGO, if no LOGO is outstanding */
6457 spin_lock_irqsave(&pnode->lock, flags);
6458 if (!(pnode->upcall_flags & NLP_WAIT_FOR_LOGO) &&
6459 !pnode->logo_waitq) {
6460 pnode->logo_waitq = &waitq;
6461 pnode->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
6462 pnode->nlp_flag |= NLP_ISSUE_LOGO;
6463 pnode->upcall_flags |= NLP_WAIT_FOR_LOGO;
6464 spin_unlock_irqrestore(&pnode->lock, flags);
6465 lpfc_unreg_rpi(vport, pnode);
6466 wait_event_timeout(waitq,
6467 (!(pnode->upcall_flags &
6468 NLP_WAIT_FOR_LOGO)),
6469 msecs_to_jiffies(dev_loss_tmo *
6472 if (pnode->upcall_flags & NLP_WAIT_FOR_LOGO) {
6473 lpfc_printf_vlog(vport, KERN_ERR, logit,
6474 "0725 SCSI layer TGTRST "
6475 "failed & LOGO TMO (%d, %llu) "
6477 tgt_id, lun_id, status);
6478 spin_lock_irqsave(&pnode->lock, flags);
6479 pnode->upcall_flags &= ~NLP_WAIT_FOR_LOGO;
6481 spin_lock_irqsave(&pnode->lock, flags);
6483 pnode->logo_waitq = NULL;
6484 spin_unlock_irqrestore(&pnode->lock, flags);
6488 spin_unlock_irqrestore(&pnode->lock, flags);
6493 lpfc_printf_vlog(vport, KERN_ERR, logit,
6494 "0723 SCSI layer issued Target Reset (%d, %llu) "
6495 "return x%x\n", tgt_id, lun_id, status);
6498 * We have to clean up i/o as : they may be orphaned by the TMF;
6499 * or if the TMF failed, they may be in an indeterminate state.
6501 * We will report success if all the i/o aborts successfully.
6503 if (status == SUCCESS)
6504 status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
6510 * lpfc_bus_reset_handler - scsi_host_template eh_bus_reset_handler entry point
6511 * @cmnd: Pointer to scsi_cmnd data structure.
6513 * This routine does target reset to all targets on @cmnd->device->host.
6514 * This emulates Parallel SCSI Bus Reset Semantics.
6521 lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
6523 struct Scsi_Host *shost = cmnd->device->host;
6524 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6525 struct lpfc_nodelist *ndlp = NULL;
6526 struct lpfc_scsi_event_header scsi_event;
6528 int ret = SUCCESS, status, i;
6529 u32 logit = LOG_FCP;
6531 scsi_event.event_type = FC_REG_SCSI_EVENT;
6532 scsi_event.subcategory = LPFC_EVENT_BUSRESET;
6534 memcpy(scsi_event.wwpn, &vport->fc_portname, sizeof(struct lpfc_name));
6535 memcpy(scsi_event.wwnn, &vport->fc_nodename, sizeof(struct lpfc_name));
6537 fc_host_post_vendor_event(shost, fc_get_event_number(),
6538 sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
6540 status = fc_block_scsi_eh(cmnd);
6541 if (status != 0 && status != SUCCESS)
6545 * Since the driver manages a single bus device, reset all
6546 * targets known to the driver. Should any target reset
6547 * fail, this routine returns failure to the midlayer.
6549 for (i = 0; i < LPFC_MAX_TARGET; i++) {
6550 /* Search for mapped node by target ID */
6552 spin_lock_irq(shost->host_lock);
6553 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6555 if (vport->phba->cfg_fcp2_no_tgt_reset &&
6556 (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE))
6558 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
6559 ndlp->nlp_sid == i &&
6561 ndlp->nlp_type & NLP_FCP_TARGET) {
6566 spin_unlock_irq(shost->host_lock);
6570 status = lpfc_send_taskmgmt(vport, cmnd,
6571 i, 0, FCP_TARGET_RESET);
6573 if (status != SUCCESS) {
6574 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
6575 "0700 Bus Reset on target %d failed\n",
6581 * We have to clean up i/o as : they may be orphaned by the TMFs
6582 * above; or if any of the TMFs failed, they may be in an
6583 * indeterminate state.
6584 * We will report success if all the i/o aborts successfully.
6587 status = lpfc_reset_flush_io_context(vport, 0, 0, LPFC_CTX_HOST);
6588 if (status != SUCCESS)
6591 logit = LOG_TRACE_EVENT;
6593 lpfc_printf_vlog(vport, KERN_ERR, logit,
6594 "0714 SCSI layer issued Bus Reset Data: x%x\n", ret);
6599 * lpfc_host_reset_handler - scsi_host_template eh_host_reset_handler entry pt
6600 * @cmnd: Pointer to scsi_cmnd data structure.
6602 * This routine does host reset to the adaptor port. It brings the HBA
6603 * offline, performs a board restart, and then brings the board back online.
6604 * The lpfc_offline calls lpfc_sli_hba_down which will abort and local
6605 * reject all outstanding SCSI commands to the host and error returned
6606 * back to SCSI mid-level. As this will be SCSI mid-level's last resort
6607 * of error handling, it will only return error if resetting of the adapter
6608 * is not successful; in all other cases, will return success.
6615 lpfc_host_reset_handler(struct scsi_cmnd *cmnd)
6617 struct Scsi_Host *shost = cmnd->device->host;
6618 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6619 struct lpfc_hba *phba = vport->phba;
6620 int rc, ret = SUCCESS;
6622 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
6623 "3172 SCSI layer issued Host Reset Data:\n");
6625 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
6627 rc = lpfc_sli_brdrestart(phba);
6631 rc = lpfc_online(phba);
6635 lpfc_unblock_mgmt_io(phba);
6639 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
6640 "3323 Failed host reset\n");
6641 lpfc_unblock_mgmt_io(phba);
6646 * lpfc_slave_alloc - scsi_host_template slave_alloc entry point
6647 * @sdev: Pointer to scsi_device.
6649 * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's
6650 * globally available list of scsi buffers. This routine also makes sure scsi
6651 * buffer is not allocated more than HBA limit conveyed to midlayer. This list
6652 * of scsi buffer exists for the lifetime of the driver.
6659 lpfc_slave_alloc(struct scsi_device *sdev)
6661 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
6662 struct lpfc_hba *phba = vport->phba;
6663 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
6665 uint32_t num_to_alloc = 0;
6666 int num_allocated = 0;
6668 struct lpfc_device_data *device_data;
6669 unsigned long flags;
6670 struct lpfc_name target_wwpn;
6672 if (!rport || fc_remote_port_chkready(rport))
6675 if (phba->cfg_fof) {
6678 * Check to see if the device data structure for the lun
6679 * exists. If not, create one.
6682 u64_to_wwn(rport->port_name, target_wwpn.u.wwn);
6683 spin_lock_irqsave(&phba->devicelock, flags);
6684 device_data = __lpfc_get_device_data(phba,
6686 &vport->fc_portname,
6690 spin_unlock_irqrestore(&phba->devicelock, flags);
6691 device_data = lpfc_create_device_data(phba,
6692 &vport->fc_portname,
6695 phba->cfg_XLanePriority,
6699 spin_lock_irqsave(&phba->devicelock, flags);
6700 list_add_tail(&device_data->listentry, &phba->luns);
6702 device_data->rport_data = rport->dd_data;
6703 device_data->available = true;
6704 spin_unlock_irqrestore(&phba->devicelock, flags);
6705 sdev->hostdata = device_data;
6707 sdev->hostdata = rport->dd_data;
6709 sdev_cnt = atomic_inc_return(&phba->sdev_cnt);
6711 /* For SLI4, all IO buffers are pre-allocated */
6712 if (phba->sli_rev == LPFC_SLI_REV4)
6715 /* This code path is now ONLY for SLI3 adapters */
6718 * Populate the cmds_per_lun count scsi_bufs into this host's globally
6719 * available list of scsi buffers. Don't allocate more than the
6720 * HBA limit conveyed to the midlayer via the host structure. The
6721 * formula accounts for the lun_queue_depth + error handlers + 1
6722 * extra. This list of scsi bufs exists for the lifetime of the driver.
6724 total = phba->total_scsi_bufs;
6725 num_to_alloc = vport->cfg_lun_queue_depth + 2;
6727 /* If allocated buffers are enough do nothing */
6728 if ((sdev_cnt * (vport->cfg_lun_queue_depth + 2)) < total)
6731 /* Allow some exchanges to be available always to complete discovery */
6732 if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
6733 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
6734 "0704 At limitation of %d preallocated "
6735 "command buffers\n", total);
6737 /* Allow some exchanges to be available always to complete discovery */
6738 } else if (total + num_to_alloc >
6739 phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
6740 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
6741 "0705 Allocation request of %d "
6742 "command buffers will exceed max of %d. "
6743 "Reducing allocation request to %d.\n",
6744 num_to_alloc, phba->cfg_hba_queue_depth,
6745 (phba->cfg_hba_queue_depth - total));
6746 num_to_alloc = phba->cfg_hba_queue_depth - total;
6748 num_allocated = lpfc_new_scsi_buf_s3(vport, num_to_alloc);
6749 if (num_to_alloc != num_allocated) {
6750 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
6751 "0708 Allocation request of %d "
6752 "command buffers did not succeed. "
6753 "Allocated %d buffers.\n",
6754 num_to_alloc, num_allocated);
6756 if (num_allocated > 0)
6757 phba->total_scsi_bufs += num_allocated;
6762 * lpfc_slave_configure - scsi_host_template slave_configure entry point
6763 * @sdev: Pointer to scsi_device.
6765 * This routine configures following items
6766 * - Tag command queuing support for @sdev if supported.
6767 * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set.
6773 lpfc_slave_configure(struct scsi_device *sdev)
6775 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
6776 struct lpfc_hba *phba = vport->phba;
6778 scsi_change_queue_depth(sdev, vport->cfg_lun_queue_depth);
6780 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
6781 lpfc_sli_handle_fast_ring_event(phba,
6782 &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ);
6783 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
6784 lpfc_poll_rearm_timer(phba);
6791 * lpfc_slave_destroy - slave_destroy entry point of SHT data structure
6792 * @sdev: Pointer to scsi_device.
6794 * This routine sets @sdev hostatdata filed to null.
6797 lpfc_slave_destroy(struct scsi_device *sdev)
6799 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
6800 struct lpfc_hba *phba = vport->phba;
6801 unsigned long flags;
6802 struct lpfc_device_data *device_data = sdev->hostdata;
6804 atomic_dec(&phba->sdev_cnt);
6805 if ((phba->cfg_fof) && (device_data)) {
6806 spin_lock_irqsave(&phba->devicelock, flags);
6807 device_data->available = false;
6808 if (!device_data->oas_enabled)
6809 lpfc_delete_device_data(phba, device_data);
6810 spin_unlock_irqrestore(&phba->devicelock, flags);
6812 sdev->hostdata = NULL;
6817 * lpfc_create_device_data - creates and initializes device data structure for OAS
6818 * @phba: Pointer to host bus adapter structure.
6819 * @vport_wwpn: Pointer to vport's wwpn information
6820 * @target_wwpn: Pointer to target's wwpn information
6821 * @lun: Lun on target
6823 * @atomic_create: Flag to indicate if memory should be allocated using the
6824 * GFP_ATOMIC flag or not.
6826 * This routine creates a device data structure which will contain identifying
6827 * information for the device (host wwpn, target wwpn, lun), state of OAS,
6828 * whether or not the corresponding lun is available by the system,
6829 * and pointer to the rport data.
6833 * Pointer to lpfc_device_data - Success
6835 struct lpfc_device_data*
6836 lpfc_create_device_data(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn,
6837 struct lpfc_name *target_wwpn, uint64_t lun,
6838 uint32_t pri, bool atomic_create)
6841 struct lpfc_device_data *lun_info;
6844 if (unlikely(!phba) || !vport_wwpn || !target_wwpn ||
6848 /* Attempt to create the device data to contain lun info */
6851 memory_flags = GFP_ATOMIC;
6853 memory_flags = GFP_KERNEL;
6854 lun_info = mempool_alloc(phba->device_data_mem_pool, memory_flags);
6857 INIT_LIST_HEAD(&lun_info->listentry);
6858 lun_info->rport_data = NULL;
6859 memcpy(&lun_info->device_id.vport_wwpn, vport_wwpn,
6860 sizeof(struct lpfc_name));
6861 memcpy(&lun_info->device_id.target_wwpn, target_wwpn,
6862 sizeof(struct lpfc_name));
6863 lun_info->device_id.lun = lun;
6864 lun_info->oas_enabled = false;
6865 lun_info->priority = pri;
6866 lun_info->available = false;
6871 * lpfc_delete_device_data - frees a device data structure for OAS
6872 * @phba: Pointer to host bus adapter structure.
6873 * @lun_info: Pointer to device data structure to free.
6875 * This routine frees the previously allocated device data structure passed.
6879 lpfc_delete_device_data(struct lpfc_hba *phba,
6880 struct lpfc_device_data *lun_info)
6883 if (unlikely(!phba) || !lun_info ||
6887 if (!list_empty(&lun_info->listentry))
6888 list_del(&lun_info->listentry);
6889 mempool_free(lun_info, phba->device_data_mem_pool);
6894 * __lpfc_get_device_data - returns the device data for the specified lun
6895 * @phba: Pointer to host bus adapter structure.
6896 * @list: Point to list to search.
6897 * @vport_wwpn: Pointer to vport's wwpn information
6898 * @target_wwpn: Pointer to target's wwpn information
6899 * @lun: Lun on target
6901 * This routine searches the list passed for the specified lun's device data.
6902 * This function does not hold locks, it is the responsibility of the caller
6903 * to ensure the proper lock is held before calling the function.
6907 * Pointer to lpfc_device_data - Success
6909 struct lpfc_device_data*
6910 __lpfc_get_device_data(struct lpfc_hba *phba, struct list_head *list,
6911 struct lpfc_name *vport_wwpn,
6912 struct lpfc_name *target_wwpn, uint64_t lun)
6915 struct lpfc_device_data *lun_info;
6917 if (unlikely(!phba) || !list || !vport_wwpn || !target_wwpn ||
6921 /* Check to see if the lun is already enabled for OAS. */
6923 list_for_each_entry(lun_info, list, listentry) {
6924 if ((memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn,
6925 sizeof(struct lpfc_name)) == 0) &&
6926 (memcmp(&lun_info->device_id.target_wwpn, target_wwpn,
6927 sizeof(struct lpfc_name)) == 0) &&
6928 (lun_info->device_id.lun == lun))
6936 * lpfc_find_next_oas_lun - searches for the next oas lun
6937 * @phba: Pointer to host bus adapter structure.
6938 * @vport_wwpn: Pointer to vport's wwpn information
6939 * @target_wwpn: Pointer to target's wwpn information
6940 * @starting_lun: Pointer to the lun to start searching for
6941 * @found_vport_wwpn: Pointer to the found lun's vport wwpn information
6942 * @found_target_wwpn: Pointer to the found lun's target wwpn information
6943 * @found_lun: Pointer to the found lun.
6944 * @found_lun_status: Pointer to status of the found lun.
6945 * @found_lun_pri: Pointer to priority of the found lun.
6947 * This routine searches the luns list for the specified lun
6948 * or the first lun for the vport/target. If the vport wwpn contains
6949 * a zero value then a specific vport is not specified. In this case
6950 * any vport which contains the lun will be considered a match. If the
6951 * target wwpn contains a zero value then a specific target is not specified.
6952 * In this case any target which contains the lun will be considered a
6953 * match. If the lun is found, the lun, vport wwpn, target wwpn and lun status
6954 * are returned. The function will also return the next lun if available.
6955 * If the next lun is not found, starting_lun parameter will be set to
6963 lpfc_find_next_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn,
6964 struct lpfc_name *target_wwpn, uint64_t *starting_lun,
6965 struct lpfc_name *found_vport_wwpn,
6966 struct lpfc_name *found_target_wwpn,
6967 uint64_t *found_lun,
6968 uint32_t *found_lun_status,
6969 uint32_t *found_lun_pri)
6972 unsigned long flags;
6973 struct lpfc_device_data *lun_info;
6974 struct lpfc_device_id *device_id;
6978 if (unlikely(!phba) || !vport_wwpn || !target_wwpn ||
6979 !starting_lun || !found_vport_wwpn ||
6980 !found_target_wwpn || !found_lun || !found_lun_status ||
6981 (*starting_lun == NO_MORE_OAS_LUN) ||
6985 lun = *starting_lun;
6986 *found_lun = NO_MORE_OAS_LUN;
6987 *starting_lun = NO_MORE_OAS_LUN;
6989 /* Search for lun or the lun closet in value */
6991 spin_lock_irqsave(&phba->devicelock, flags);
6992 list_for_each_entry(lun_info, &phba->luns, listentry) {
6993 if (((wwn_to_u64(vport_wwpn->u.wwn) == 0) ||
6994 (memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn,
6995 sizeof(struct lpfc_name)) == 0)) &&
6996 ((wwn_to_u64(target_wwpn->u.wwn) == 0) ||
6997 (memcmp(&lun_info->device_id.target_wwpn, target_wwpn,
6998 sizeof(struct lpfc_name)) == 0)) &&
6999 (lun_info->oas_enabled)) {
7000 device_id = &lun_info->device_id;
7002 ((lun == FIND_FIRST_OAS_LUN) ||
7003 (device_id->lun == lun))) {
7004 *found_lun = device_id->lun;
7005 memcpy(found_vport_wwpn,
7006 &device_id->vport_wwpn,
7007 sizeof(struct lpfc_name));
7008 memcpy(found_target_wwpn,
7009 &device_id->target_wwpn,
7010 sizeof(struct lpfc_name));
7011 if (lun_info->available)
7013 OAS_LUN_STATUS_EXISTS;
7015 *found_lun_status = 0;
7016 *found_lun_pri = lun_info->priority;
7017 if (phba->cfg_oas_flags & OAS_FIND_ANY_VPORT)
7018 memset(vport_wwpn, 0x0,
7019 sizeof(struct lpfc_name));
7020 if (phba->cfg_oas_flags & OAS_FIND_ANY_TARGET)
7021 memset(target_wwpn, 0x0,
7022 sizeof(struct lpfc_name));
7025 *starting_lun = device_id->lun;
7026 memcpy(vport_wwpn, &device_id->vport_wwpn,
7027 sizeof(struct lpfc_name));
7028 memcpy(target_wwpn, &device_id->target_wwpn,
7029 sizeof(struct lpfc_name));
7034 spin_unlock_irqrestore(&phba->devicelock, flags);
7039 * lpfc_enable_oas_lun - enables a lun for OAS operations
7040 * @phba: Pointer to host bus adapter structure.
7041 * @vport_wwpn: Pointer to vport's wwpn information
7042 * @target_wwpn: Pointer to target's wwpn information
7046 * This routine enables a lun for oas operations. The routines does so by
7047 * doing the following :
7049 * 1) Checks to see if the device data for the lun has been created.
7050 * 2) If found, sets the OAS enabled flag if not set and returns.
7051 * 3) Otherwise, creates a device data structure.
7052 * 4) If successfully created, indicates the device data is for an OAS lun,
7053 * indicates the lun is not available and add to the list of luns.
7060 lpfc_enable_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn,
7061 struct lpfc_name *target_wwpn, uint64_t lun, uint8_t pri)
7064 struct lpfc_device_data *lun_info;
7065 unsigned long flags;
7067 if (unlikely(!phba) || !vport_wwpn || !target_wwpn ||
7071 spin_lock_irqsave(&phba->devicelock, flags);
7073 /* Check to see if the device data for the lun has been created */
7074 lun_info = __lpfc_get_device_data(phba, &phba->luns, vport_wwpn,
7077 if (!lun_info->oas_enabled)
7078 lun_info->oas_enabled = true;
7079 lun_info->priority = pri;
7080 spin_unlock_irqrestore(&phba->devicelock, flags);
7084 /* Create an lun info structure and add to list of luns */
7085 lun_info = lpfc_create_device_data(phba, vport_wwpn, target_wwpn, lun,
7088 lun_info->oas_enabled = true;
7089 lun_info->priority = pri;
7090 lun_info->available = false;
7091 list_add_tail(&lun_info->listentry, &phba->luns);
7092 spin_unlock_irqrestore(&phba->devicelock, flags);
7095 spin_unlock_irqrestore(&phba->devicelock, flags);
7100 * lpfc_disable_oas_lun - disables a lun for OAS operations
7101 * @phba: Pointer to host bus adapter structure.
7102 * @vport_wwpn: Pointer to vport's wwpn information
7103 * @target_wwpn: Pointer to target's wwpn information
7107 * This routine disables a lun for oas operations. The routines does so by
7108 * doing the following :
7110 * 1) Checks to see if the device data for the lun is created.
7111 * 2) If present, clears the flag indicating this lun is for OAS.
7112 * 3) If the lun is not available by the system, the device data is
7120 lpfc_disable_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn,
7121 struct lpfc_name *target_wwpn, uint64_t lun, uint8_t pri)
7124 struct lpfc_device_data *lun_info;
7125 unsigned long flags;
7127 if (unlikely(!phba) || !vport_wwpn || !target_wwpn ||
7131 spin_lock_irqsave(&phba->devicelock, flags);
7133 /* Check to see if the lun is available. */
7134 lun_info = __lpfc_get_device_data(phba,
7135 &phba->luns, vport_wwpn,
7138 lun_info->oas_enabled = false;
7139 lun_info->priority = pri;
7140 if (!lun_info->available)
7141 lpfc_delete_device_data(phba, lun_info);
7142 spin_unlock_irqrestore(&phba->devicelock, flags);
7146 spin_unlock_irqrestore(&phba->devicelock, flags);
7151 lpfc_no_command(struct Scsi_Host *shost, struct scsi_cmnd *cmnd)
7153 return SCSI_MLQUEUE_HOST_BUSY;
7157 lpfc_no_handler(struct scsi_cmnd *cmnd)
7163 lpfc_no_slave(struct scsi_device *sdev)
7168 struct scsi_host_template lpfc_template_nvme = {
7169 .module = THIS_MODULE,
7170 .name = LPFC_DRIVER_NAME,
7171 .proc_name = LPFC_DRIVER_NAME,
7173 .queuecommand = lpfc_no_command,
7174 .eh_abort_handler = lpfc_no_handler,
7175 .eh_device_reset_handler = lpfc_no_handler,
7176 .eh_target_reset_handler = lpfc_no_handler,
7177 .eh_bus_reset_handler = lpfc_no_handler,
7178 .eh_host_reset_handler = lpfc_no_handler,
7179 .slave_alloc = lpfc_no_slave,
7180 .slave_configure = lpfc_no_slave,
7181 .scan_finished = lpfc_scan_finished,
7185 .shost_attrs = lpfc_hba_attrs,
7186 .max_sectors = 0xFFFFFFFF,
7187 .vendor_id = LPFC_NL_VENDOR_ID,
7188 .track_queue_depth = 0,
7191 struct scsi_host_template lpfc_template = {
7192 .module = THIS_MODULE,
7193 .name = LPFC_DRIVER_NAME,
7194 .proc_name = LPFC_DRIVER_NAME,
7196 .queuecommand = lpfc_queuecommand,
7197 .eh_timed_out = fc_eh_timed_out,
7198 .eh_should_retry_cmd = fc_eh_should_retry_cmd,
7199 .eh_abort_handler = lpfc_abort_handler,
7200 .eh_device_reset_handler = lpfc_device_reset_handler,
7201 .eh_target_reset_handler = lpfc_target_reset_handler,
7202 .eh_bus_reset_handler = lpfc_bus_reset_handler,
7203 .eh_host_reset_handler = lpfc_host_reset_handler,
7204 .slave_alloc = lpfc_slave_alloc,
7205 .slave_configure = lpfc_slave_configure,
7206 .slave_destroy = lpfc_slave_destroy,
7207 .scan_finished = lpfc_scan_finished,
7209 .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
7210 .cmd_per_lun = LPFC_CMD_PER_LUN,
7211 .shost_attrs = lpfc_hba_attrs,
7212 .max_sectors = 0xFFFFFFFF,
7213 .vendor_id = LPFC_NL_VENDOR_ID,
7214 .change_queue_depth = scsi_change_queue_depth,
7215 .track_queue_depth = 1,