1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
23 #include <linux/pci.h>
24 #include <linux/slab.h>
25 #include <linux/interrupt.h>
26 #include <linux/export.h>
27 #include <linux/delay.h>
28 #include <asm/unaligned.h>
29 #include <linux/t10-pi.h>
30 #include <linux/crc-t10dif.h>
31 #include <net/checksum.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_eh.h>
36 #include <scsi/scsi_host.h>
37 #include <scsi/scsi_tcq.h>
38 #include <scsi/scsi_transport_fc.h>
40 #include "lpfc_version.h"
44 #include "lpfc_sli4.h"
46 #include "lpfc_disc.h"
48 #include "lpfc_scsi.h"
49 #include "lpfc_logmsg.h"
50 #include "lpfc_crtn.h"
51 #include "lpfc_vport.h"
53 #define LPFC_RESET_WAIT 2
54 #define LPFC_ABORT_WAIT 2
56 int _dump_buf_done = 1;
58 static char *dif_op_str[] = {
68 struct scsi_dif_tuple {
69 __be16 guard_tag; /* Checksum */
70 __be16 app_tag; /* Opaque storage */
71 __be32 ref_tag; /* Target LBA or indirect LBA */
74 static struct lpfc_rport_data *
75 lpfc_rport_data_from_scsi_device(struct scsi_device *sdev)
77 struct lpfc_vport *vport = (struct lpfc_vport *)sdev->host->hostdata;
79 if (vport->phba->cfg_fof)
80 return ((struct lpfc_device_data *)sdev->hostdata)->rport_data;
82 return (struct lpfc_rport_data *)sdev->hostdata;
86 lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb);
88 lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb);
90 lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc);
93 lpfc_debug_save_data(struct lpfc_hba *phba, struct scsi_cmnd *cmnd)
96 struct scatterlist *sgde = scsi_sglist(cmnd);
98 if (!_dump_buf_data) {
99 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
100 "9050 BLKGRD: ERROR %s _dump_buf_data is NULL\n",
107 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
108 "9051 BLKGRD: ERROR: data scatterlist is null\n");
112 dst = (void *) _dump_buf_data;
115 memcpy(dst, src, sgde->length);
117 sgde = sg_next(sgde);
122 lpfc_debug_save_dif(struct lpfc_hba *phba, struct scsi_cmnd *cmnd)
125 struct scatterlist *sgde = scsi_prot_sglist(cmnd);
127 if (!_dump_buf_dif) {
128 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
129 "9052 BLKGRD: ERROR %s _dump_buf_data is NULL\n",
135 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
136 "9053 BLKGRD: ERROR: prot scatterlist is null\n");
143 memcpy(dst, src, sgde->length);
145 sgde = sg_next(sgde);
149 static inline unsigned
150 lpfc_cmd_blksize(struct scsi_cmnd *sc)
152 return sc->device->sector_size;
155 #define LPFC_CHECK_PROTECT_GUARD 1
156 #define LPFC_CHECK_PROTECT_REF 2
157 static inline unsigned
158 lpfc_cmd_protect(struct scsi_cmnd *sc, int flag)
163 static inline unsigned
164 lpfc_cmd_guard_csum(struct scsi_cmnd *sc)
166 if (lpfc_prot_group_type(NULL, sc) == LPFC_PG_TYPE_NO_DIF)
168 if (scsi_host_get_guard(sc->device->host) == SHOST_DIX_GUARD_IP)
174 * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge.
175 * @phba: Pointer to HBA object.
176 * @lpfc_cmd: lpfc scsi command object pointer.
178 * This function is called from the lpfc_prep_task_mgmt_cmd function to
179 * set the last bit in the response sge entry.
182 lpfc_sli4_set_rsp_sgl_last(struct lpfc_hba *phba,
183 struct lpfc_scsi_buf *lpfc_cmd)
185 struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
188 sgl->word2 = le32_to_cpu(sgl->word2);
189 bf_set(lpfc_sli4_sge_last, sgl, 1);
190 sgl->word2 = cpu_to_le32(sgl->word2);
195 * lpfc_update_stats - Update statistical data for the command completion
196 * @phba: Pointer to HBA object.
197 * @lpfc_cmd: lpfc scsi command object pointer.
199 * This function is called when there is a command completion and this
200 * function updates the statistical data for the command completion.
203 lpfc_update_stats(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
205 struct lpfc_rport_data *rdata;
206 struct lpfc_nodelist *pnode;
207 struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
209 struct Scsi_Host *shost = cmd->device->host;
210 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
211 unsigned long latency;
214 if (!vport->stat_data_enabled ||
215 vport->stat_data_blocked ||
219 latency = jiffies_to_msecs((long)jiffies - (long)lpfc_cmd->start_time);
220 rdata = lpfc_cmd->rdata;
221 pnode = rdata->pnode;
223 spin_lock_irqsave(shost->host_lock, flags);
226 (phba->bucket_type == LPFC_NO_BUCKET)) {
227 spin_unlock_irqrestore(shost->host_lock, flags);
231 if (phba->bucket_type == LPFC_LINEAR_BUCKET) {
232 i = (latency + phba->bucket_step - 1 - phba->bucket_base)/
234 /* check array subscript bounds */
237 else if (i >= LPFC_MAX_BUCKET_COUNT)
238 i = LPFC_MAX_BUCKET_COUNT - 1;
240 for (i = 0; i < LPFC_MAX_BUCKET_COUNT-1; i++)
241 if (latency <= (phba->bucket_base +
242 ((1<<i)*phba->bucket_step)))
246 pnode->lat_data[i].cmd_count++;
247 spin_unlock_irqrestore(shost->host_lock, flags);
251 * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread
252 * @phba: The Hba for which this call is being executed.
254 * This routine is called when there is resource error in driver or firmware.
255 * This routine posts WORKER_RAMP_DOWN_QUEUE event for @phba. This routine
256 * posts at most 1 event each second. This routine wakes up worker thread of
257 * @phba to process WORKER_RAM_DOWN_EVENT event.
259 * This routine should be called with no lock held.
262 lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
266 unsigned long expires;
268 spin_lock_irqsave(&phba->hbalock, flags);
269 atomic_inc(&phba->num_rsrc_err);
270 phba->last_rsrc_error_time = jiffies;
272 expires = phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL;
273 if (time_after(expires, jiffies)) {
274 spin_unlock_irqrestore(&phba->hbalock, flags);
278 phba->last_ramp_down_time = jiffies;
280 spin_unlock_irqrestore(&phba->hbalock, flags);
282 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
283 evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE;
285 phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE;
286 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
289 lpfc_worker_wake_up(phba);
294 * lpfc_ramp_down_queue_handler - WORKER_RAMP_DOWN_QUEUE event handler
295 * @phba: The Hba for which this call is being executed.
297 * This routine is called to process WORKER_RAMP_DOWN_QUEUE event for worker
298 * thread.This routine reduces queue depth for all scsi device on each vport
299 * associated with @phba.
302 lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
304 struct lpfc_vport **vports;
305 struct Scsi_Host *shost;
306 struct scsi_device *sdev;
307 unsigned long new_queue_depth;
308 unsigned long num_rsrc_err, num_cmd_success;
311 num_rsrc_err = atomic_read(&phba->num_rsrc_err);
312 num_cmd_success = atomic_read(&phba->num_cmd_success);
315 * The error and success command counters are global per
316 * driver instance. If another handler has already
317 * operated on this error event, just exit.
319 if (num_rsrc_err == 0)
322 vports = lpfc_create_vport_work_array(phba);
324 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
325 shost = lpfc_shost_from_vport(vports[i]);
326 shost_for_each_device(sdev, shost) {
328 sdev->queue_depth * num_rsrc_err /
329 (num_rsrc_err + num_cmd_success);
330 if (!new_queue_depth)
331 new_queue_depth = sdev->queue_depth - 1;
333 new_queue_depth = sdev->queue_depth -
335 scsi_change_queue_depth(sdev, new_queue_depth);
338 lpfc_destroy_vport_work_array(phba, vports);
339 atomic_set(&phba->num_rsrc_err, 0);
340 atomic_set(&phba->num_cmd_success, 0);
344 * lpfc_scsi_dev_block - set all scsi hosts to block state
345 * @phba: Pointer to HBA context object.
347 * This function walks vport list and set each SCSI host to block state
348 * by invoking fc_remote_port_delete() routine. This function is invoked
349 * with EEH when device's PCI slot has been permanently disabled.
352 lpfc_scsi_dev_block(struct lpfc_hba *phba)
354 struct lpfc_vport **vports;
355 struct Scsi_Host *shost;
356 struct scsi_device *sdev;
357 struct fc_rport *rport;
360 vports = lpfc_create_vport_work_array(phba);
362 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
363 shost = lpfc_shost_from_vport(vports[i]);
364 shost_for_each_device(sdev, shost) {
365 rport = starget_to_rport(scsi_target(sdev));
366 fc_remote_port_delete(rport);
369 lpfc_destroy_vport_work_array(phba, vports);
373 * lpfc_new_scsi_buf_s3 - Scsi buffer allocator for HBA with SLI3 IF spec
374 * @vport: The virtual port for which this call being executed.
375 * @num_to_allocate: The requested number of buffers to allocate.
377 * This routine allocates a scsi buffer for device with SLI-3 interface spec,
378 * the scsi buffer contains all the necessary information needed to initiate
379 * a SCSI I/O. The non-DMAable buffer region contains information to build
380 * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP,
381 * and the initial BPL. In addition to allocating memory, the FCP CMND and
382 * FCP RSP BDEs are setup in the BPL and the BPL BDE is setup in the IOCB.
385 * int - number of scsi buffers that were allocated.
386 * 0 = failure, less than num_to_alloc is a partial failure.
389 lpfc_new_scsi_buf_s3(struct lpfc_vport *vport, int num_to_alloc)
391 struct lpfc_hba *phba = vport->phba;
392 struct lpfc_scsi_buf *psb;
393 struct ulp_bde64 *bpl;
395 dma_addr_t pdma_phys_fcp_cmd;
396 dma_addr_t pdma_phys_fcp_rsp;
397 dma_addr_t pdma_phys_sgl;
401 bpl_size = phba->cfg_sg_dma_buf_size -
402 (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp));
404 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
405 "9067 ALLOC %d scsi_bufs: %d (%d + %d + %d)\n",
406 num_to_alloc, phba->cfg_sg_dma_buf_size,
407 (int)sizeof(struct fcp_cmnd),
408 (int)sizeof(struct fcp_rsp), bpl_size);
410 for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
411 psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL);
416 * Get memory from the pci pool to map the virt space to pci
417 * bus space for an I/O. The DMA buffer includes space for the
418 * struct fcp_cmnd, struct fcp_rsp and the number of bde's
419 * necessary to support the sg_tablesize.
421 psb->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool,
422 GFP_KERNEL, &psb->dma_handle);
429 /* Allocate iotag for psb->cur_iocbq. */
430 iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq);
432 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
433 psb->data, psb->dma_handle);
437 psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP;
439 psb->fcp_cmnd = psb->data;
440 psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd);
441 psb->dma_sgl = psb->data + sizeof(struct fcp_cmnd) +
442 sizeof(struct fcp_rsp);
444 /* Initialize local short-hand pointers. */
446 pdma_phys_fcp_cmd = psb->dma_handle;
447 pdma_phys_fcp_rsp = psb->dma_handle + sizeof(struct fcp_cmnd);
448 pdma_phys_sgl = psb->dma_handle + sizeof(struct fcp_cmnd) +
449 sizeof(struct fcp_rsp);
452 * The first two bdes are the FCP_CMD and FCP_RSP. The balance
453 * are sg list bdes. Initialize the first two and leave the
454 * rest for queuecommand.
456 bpl[0].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd));
457 bpl[0].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd));
458 bpl[0].tus.f.bdeSize = sizeof(struct fcp_cmnd);
459 bpl[0].tus.f.bdeFlags = BUFF_TYPE_BDE_64;
460 bpl[0].tus.w = le32_to_cpu(bpl[0].tus.w);
462 /* Setup the physical region for the FCP RSP */
463 bpl[1].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp));
464 bpl[1].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp));
465 bpl[1].tus.f.bdeSize = sizeof(struct fcp_rsp);
466 bpl[1].tus.f.bdeFlags = BUFF_TYPE_BDE_64;
467 bpl[1].tus.w = le32_to_cpu(bpl[1].tus.w);
470 * Since the IOCB for the FCP I/O is built into this
471 * lpfc_scsi_buf, initialize it with all known data now.
473 iocb = &psb->cur_iocbq.iocb;
474 iocb->un.fcpi64.bdl.ulpIoTag32 = 0;
475 if ((phba->sli_rev == 3) &&
476 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) {
477 /* fill in immediate fcp command BDE */
478 iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_IMMED;
479 iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd);
480 iocb->un.fcpi64.bdl.addrLow = offsetof(IOCB_t,
482 iocb->un.fcpi64.bdl.addrHigh = 0;
483 iocb->ulpBdeCount = 0;
485 /* fill in response BDE */
486 iocb->unsli3.fcp_ext.rbde.tus.f.bdeFlags =
488 iocb->unsli3.fcp_ext.rbde.tus.f.bdeSize =
489 sizeof(struct fcp_rsp);
490 iocb->unsli3.fcp_ext.rbde.addrLow =
491 putPaddrLow(pdma_phys_fcp_rsp);
492 iocb->unsli3.fcp_ext.rbde.addrHigh =
493 putPaddrHigh(pdma_phys_fcp_rsp);
495 iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
496 iocb->un.fcpi64.bdl.bdeSize =
497 (2 * sizeof(struct ulp_bde64));
498 iocb->un.fcpi64.bdl.addrLow =
499 putPaddrLow(pdma_phys_sgl);
500 iocb->un.fcpi64.bdl.addrHigh =
501 putPaddrHigh(pdma_phys_sgl);
502 iocb->ulpBdeCount = 1;
505 iocb->ulpClass = CLASS3;
506 psb->status = IOSTAT_SUCCESS;
507 /* Put it back into the SCSI buffer list */
508 psb->cur_iocbq.context1 = psb;
509 lpfc_release_scsi_buf_s3(phba, psb);
517 * lpfc_sli4_vport_delete_fcp_xri_aborted -Remove all ndlp references for vport
518 * @vport: pointer to lpfc vport data structure.
520 * This routine is invoked by the vport cleanup for deletions and the cleanup
521 * for an ndlp on removal.
524 lpfc_sli4_vport_delete_fcp_xri_aborted(struct lpfc_vport *vport)
526 struct lpfc_hba *phba = vport->phba;
527 struct lpfc_scsi_buf *psb, *next_psb;
528 unsigned long iflag = 0;
530 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
532 spin_lock_irqsave(&phba->hbalock, iflag);
533 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
534 list_for_each_entry_safe(psb, next_psb,
535 &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) {
536 if (psb->rdata && psb->rdata->pnode
537 && psb->rdata->pnode->vport == vport)
540 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
541 spin_unlock_irqrestore(&phba->hbalock, iflag);
545 * lpfc_sli4_fcp_xri_aborted - Fast-path process of fcp xri abort
546 * @phba: pointer to lpfc hba data structure.
547 * @axri: pointer to the fcp xri abort wcqe structure.
549 * This routine is invoked by the worker thread to process a SLI4 fast-path
553 lpfc_sli4_fcp_xri_aborted(struct lpfc_hba *phba,
554 struct sli4_wcqe_xri_aborted *axri)
556 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
557 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
558 struct lpfc_scsi_buf *psb, *next_psb;
559 unsigned long iflag = 0;
560 struct lpfc_iocbq *iocbq;
562 struct lpfc_nodelist *ndlp;
564 struct lpfc_sli_ring *pring = phba->sli4_hba.els_wq->pring;
566 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
568 spin_lock_irqsave(&phba->hbalock, iflag);
569 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
570 list_for_each_entry_safe(psb, next_psb,
571 &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) {
572 if (psb->cur_iocbq.sli4_xritag == xri) {
573 list_del(&psb->list);
575 psb->status = IOSTAT_SUCCESS;
577 &phba->sli4_hba.abts_scsi_buf_list_lock);
578 if (psb->rdata && psb->rdata->pnode)
579 ndlp = psb->rdata->pnode;
583 rrq_empty = list_empty(&phba->active_rrq_list);
584 spin_unlock_irqrestore(&phba->hbalock, iflag);
586 lpfc_set_rrq_active(phba, ndlp,
587 psb->cur_iocbq.sli4_lxritag, rxid, 1);
588 lpfc_sli4_abts_err_handler(phba, ndlp, axri);
590 lpfc_release_scsi_buf_s4(phba, psb);
592 lpfc_worker_wake_up(phba);
596 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
597 for (i = 1; i <= phba->sli.last_iotag; i++) {
598 iocbq = phba->sli.iocbq_lookup[i];
600 if (!(iocbq->iocb_flag & LPFC_IO_FCP) ||
601 (iocbq->iocb_flag & LPFC_IO_LIBDFC))
603 if (iocbq->sli4_xritag != xri)
605 psb = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
607 spin_unlock_irqrestore(&phba->hbalock, iflag);
608 if (!list_empty(&pring->txq))
609 lpfc_worker_wake_up(phba);
613 spin_unlock_irqrestore(&phba->hbalock, iflag);
617 * lpfc_get_scsi_buf_s3 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
618 * @phba: The HBA for which this call is being executed.
620 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
621 * and returns to caller.
625 * Pointer to lpfc_scsi_buf - Success
627 static struct lpfc_scsi_buf*
628 lpfc_get_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
630 struct lpfc_scsi_buf * lpfc_cmd = NULL;
631 struct list_head *scsi_buf_list_get = &phba->lpfc_scsi_buf_list_get;
632 unsigned long iflag = 0;
634 spin_lock_irqsave(&phba->scsi_buf_list_get_lock, iflag);
635 list_remove_head(scsi_buf_list_get, lpfc_cmd, struct lpfc_scsi_buf,
638 spin_lock(&phba->scsi_buf_list_put_lock);
639 list_splice(&phba->lpfc_scsi_buf_list_put,
640 &phba->lpfc_scsi_buf_list_get);
641 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
642 list_remove_head(scsi_buf_list_get, lpfc_cmd,
643 struct lpfc_scsi_buf, list);
644 spin_unlock(&phba->scsi_buf_list_put_lock);
646 spin_unlock_irqrestore(&phba->scsi_buf_list_get_lock, iflag);
648 if (lpfc_ndlp_check_qdepth(phba, ndlp) && lpfc_cmd) {
649 atomic_inc(&ndlp->cmd_pending);
650 lpfc_cmd->flags |= LPFC_SBUF_BUMP_QDEPTH;
655 * lpfc_get_scsi_buf_s4 - Get a scsi buffer from lpfc_common_buf_list of the HBA
656 * @phba: The HBA for which this call is being executed.
658 * This routine removes a scsi buffer from head of @phba lpfc_common_buf_list
659 * and returns to caller.
663 * Pointer to lpfc_scsi_buf - Success
665 static struct lpfc_scsi_buf*
666 lpfc_get_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
668 struct lpfc_scsi_buf *lpfc_cmd, *lpfc_cmd_next;
669 unsigned long iflag = 0;
670 struct sli4_sge *sgl;
672 dma_addr_t pdma_phys_fcp_rsp;
673 dma_addr_t pdma_phys_fcp_cmd;
677 spin_lock_irqsave(&phba->common_buf_list_get_lock, iflag);
678 list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next,
679 &phba->lpfc_common_buf_list_get, list) {
680 if (lpfc_test_rrq_active(phba, ndlp,
681 lpfc_cmd->cur_iocbq.sli4_lxritag))
683 list_del_init(&lpfc_cmd->list);
684 phba->get_common_bufs--;
689 spin_lock(&phba->common_buf_list_put_lock);
690 list_splice(&phba->lpfc_common_buf_list_put,
691 &phba->lpfc_common_buf_list_get);
692 phba->get_common_bufs += phba->put_common_bufs;
693 INIT_LIST_HEAD(&phba->lpfc_common_buf_list_put);
694 phba->put_common_bufs = 0;
695 spin_unlock(&phba->common_buf_list_put_lock);
696 list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next,
697 &phba->lpfc_common_buf_list_get,
699 if (lpfc_test_rrq_active(
700 phba, ndlp, lpfc_cmd->cur_iocbq.sli4_lxritag))
702 list_del_init(&lpfc_cmd->list);
703 phba->get_common_bufs--;
708 spin_unlock_irqrestore(&phba->common_buf_list_get_lock, iflag);
712 sgl_size = phba->cfg_sg_dma_buf_size -
713 (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp));
715 /* Setup key fields in buffer that may have been changed
716 * if other protocols used this buffer.
718 lpfc_cmd->cur_iocbq.iocb_flag = LPFC_IO_FCP;
719 lpfc_cmd->prot_seg_cnt = 0;
720 lpfc_cmd->seg_cnt = 0;
721 lpfc_cmd->waitq = NULL;
722 lpfc_cmd->timeout = 0;
724 lpfc_cmd->start_time = jiffies;
725 lpfc_cmd->waitq = NULL;
726 lpfc_cmd->cpu = smp_processor_id();
727 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
728 lpfc_cmd->prot_data_type = 0;
731 lpfc_cmd->fcp_cmnd = (lpfc_cmd->data + sgl_size);
732 lpfc_cmd->fcp_rsp = (struct fcp_rsp *)((uint8_t *)lpfc_cmd->fcp_cmnd +
733 sizeof(struct fcp_cmnd));
736 * The first two SGEs are the FCP_CMD and FCP_RSP.
737 * The balance are sg list bdes. Initialize the
738 * first two and leave the rest for queuecommand.
740 sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
741 pdma_phys_fcp_cmd = (lpfc_cmd->dma_handle + sgl_size);
742 sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd));
743 sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd));
744 sgl->word2 = le32_to_cpu(sgl->word2);
745 bf_set(lpfc_sli4_sge_last, sgl, 0);
746 sgl->word2 = cpu_to_le32(sgl->word2);
747 sgl->sge_len = cpu_to_le32(sizeof(struct fcp_cmnd));
750 /* Setup the physical region for the FCP RSP */
751 pdma_phys_fcp_rsp = pdma_phys_fcp_cmd + sizeof(struct fcp_cmnd);
752 sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp));
753 sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp));
754 sgl->word2 = le32_to_cpu(sgl->word2);
755 bf_set(lpfc_sli4_sge_last, sgl, 1);
756 sgl->word2 = cpu_to_le32(sgl->word2);
757 sgl->sge_len = cpu_to_le32(sizeof(struct fcp_rsp));
760 * Since the IOCB for the FCP I/O is built into this
761 * lpfc_scsi_buf, initialize it with all known data now.
763 iocb = &lpfc_cmd->cur_iocbq.iocb;
764 iocb->un.fcpi64.bdl.ulpIoTag32 = 0;
765 iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_64;
766 /* setting the BLP size to 2 * sizeof BDE may not be correct.
767 * We are setting the bpl to point to out sgl. An sgl's
768 * entries are 16 bytes, a bpl entries are 12 bytes.
770 iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd);
771 iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys_fcp_cmd);
772 iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys_fcp_cmd);
773 iocb->ulpBdeCount = 1;
775 iocb->ulpClass = CLASS3;
777 if (lpfc_ndlp_check_qdepth(phba, ndlp)) {
778 atomic_inc(&ndlp->cmd_pending);
779 lpfc_cmd->flags |= LPFC_SBUF_BUMP_QDEPTH;
784 * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
785 * @phba: The HBA for which this call is being executed.
787 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
788 * and returns to caller.
792 * Pointer to lpfc_scsi_buf - Success
794 static struct lpfc_scsi_buf*
795 lpfc_get_scsi_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
797 return phba->lpfc_get_scsi_buf(phba, ndlp);
801 * lpfc_release_scsi_buf - Return a scsi buffer back to hba scsi buf list
802 * @phba: The Hba for which this call is being executed.
803 * @psb: The scsi buffer which is being released.
805 * This routine releases @psb scsi buffer by adding it to tail of @phba
806 * lpfc_scsi_buf_list list.
809 lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
811 unsigned long iflag = 0;
814 psb->prot_seg_cnt = 0;
816 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
818 psb->cur_iocbq.iocb_flag = LPFC_IO_FCP;
819 list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list_put);
820 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
824 * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list.
825 * @phba: The Hba for which this call is being executed.
826 * @psb: The scsi buffer which is being released.
828 * This routine releases @psb scsi buffer by adding it to tail of @phba
829 * lpfc_common_buf_list list. For SLI4 XRI's are tied to the scsi buffer
830 * and cannot be reused for at least RA_TOV amount of time if it was
834 lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
836 unsigned long iflag = 0;
839 psb->prot_seg_cnt = 0;
841 if (psb->exch_busy) {
842 spin_lock_irqsave(&phba->sli4_hba.abts_scsi_buf_list_lock,
845 list_add_tail(&psb->list,
846 &phba->sli4_hba.lpfc_abts_scsi_buf_list);
847 spin_unlock_irqrestore(&phba->sli4_hba.abts_scsi_buf_list_lock,
850 /* MUST zero fields if buffer is reused by another protocol */
852 psb->cur_iocbq.iocb_cmpl = NULL;
853 spin_lock_irqsave(&phba->common_buf_list_put_lock, iflag);
854 list_add_tail(&psb->list, &phba->lpfc_common_buf_list_put);
855 phba->put_common_bufs++;
856 spin_unlock_irqrestore(&phba->common_buf_list_put_lock, iflag);
861 * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list.
862 * @phba: The Hba for which this call is being executed.
863 * @psb: The scsi buffer which is being released.
865 * This routine releases @psb scsi buffer by adding it to tail of @phba
866 * lpfc_scsi_buf_list list.
869 lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
871 if ((psb->flags & LPFC_SBUF_BUMP_QDEPTH) && psb->ndlp)
872 atomic_dec(&psb->ndlp->cmd_pending);
874 psb->flags &= ~LPFC_SBUF_BUMP_QDEPTH;
875 phba->lpfc_release_scsi_buf(phba, psb);
879 * lpfc_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
880 * @phba: The Hba for which this call is being executed.
881 * @lpfc_cmd: The scsi buffer which is going to be mapped.
883 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
884 * field of @lpfc_cmd for device with SLI-3 interface spec. This routine scans
885 * through sg elements and format the bde. This routine also initializes all
886 * IOCB fields which are dependent on scsi command request buffer.
893 lpfc_scsi_prep_dma_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
895 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
896 struct scatterlist *sgel = NULL;
897 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
898 struct ulp_bde64 *bpl = lpfc_cmd->dma_sgl;
899 struct lpfc_iocbq *iocbq = &lpfc_cmd->cur_iocbq;
900 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
901 struct ulp_bde64 *data_bde = iocb_cmd->unsli3.fcp_ext.dbde;
903 uint32_t num_bde = 0;
904 int nseg, datadir = scsi_cmnd->sc_data_direction;
907 * There are three possibilities here - use scatter-gather segment, use
908 * the single mapping, or neither. Start the lpfc command prep by
909 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
913 if (scsi_sg_count(scsi_cmnd)) {
915 * The driver stores the segment count returned from pci_map_sg
916 * because this a count of dma-mappings used to map the use_sg
917 * pages. They are not guaranteed to be the same for those
918 * architectures that implement an IOMMU.
921 nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd),
922 scsi_sg_count(scsi_cmnd), datadir);
926 lpfc_cmd->seg_cnt = nseg;
927 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
928 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
929 "9064 BLKGRD: %s: Too many sg segments from "
930 "dma_map_sg. Config %d, seg_cnt %d\n",
931 __func__, phba->cfg_sg_seg_cnt,
933 lpfc_cmd->seg_cnt = 0;
934 scsi_dma_unmap(scsi_cmnd);
939 * The driver established a maximum scatter-gather segment count
940 * during probe that limits the number of sg elements in any
941 * single scsi command. Just run through the seg_cnt and format
943 * When using SLI-3 the driver will try to fit all the BDEs into
944 * the IOCB. If it can't then the BDEs get added to a BPL as it
945 * does for SLI-2 mode.
947 scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) {
948 physaddr = sg_dma_address(sgel);
949 if (phba->sli_rev == 3 &&
950 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
951 !(iocbq->iocb_flag & DSS_SECURITY_OP) &&
952 nseg <= LPFC_EXT_DATA_BDE_COUNT) {
953 data_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
954 data_bde->tus.f.bdeSize = sg_dma_len(sgel);
955 data_bde->addrLow = putPaddrLow(physaddr);
956 data_bde->addrHigh = putPaddrHigh(physaddr);
959 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
960 bpl->tus.f.bdeSize = sg_dma_len(sgel);
961 bpl->tus.w = le32_to_cpu(bpl->tus.w);
963 le32_to_cpu(putPaddrLow(physaddr));
965 le32_to_cpu(putPaddrHigh(physaddr));
972 * Finish initializing those IOCB fields that are dependent on the
973 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
974 * explicitly reinitialized and for SLI-3 the extended bde count is
975 * explicitly reinitialized since all iocb memory resources are reused.
977 if (phba->sli_rev == 3 &&
978 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
979 !(iocbq->iocb_flag & DSS_SECURITY_OP)) {
980 if (num_bde > LPFC_EXT_DATA_BDE_COUNT) {
982 * The extended IOCB format can only fit 3 BDE or a BPL.
983 * This I/O has more than 3 BDE so the 1st data bde will
984 * be a BPL that is filled in here.
986 physaddr = lpfc_cmd->dma_handle;
987 data_bde->tus.f.bdeFlags = BUFF_TYPE_BLP_64;
988 data_bde->tus.f.bdeSize = (num_bde *
989 sizeof(struct ulp_bde64));
990 physaddr += (sizeof(struct fcp_cmnd) +
991 sizeof(struct fcp_rsp) +
992 (2 * sizeof(struct ulp_bde64)));
993 data_bde->addrHigh = putPaddrHigh(physaddr);
994 data_bde->addrLow = putPaddrLow(physaddr);
995 /* ebde count includes the response bde and data bpl */
996 iocb_cmd->unsli3.fcp_ext.ebde_count = 2;
998 /* ebde count includes the response bde and data bdes */
999 iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1);
1002 iocb_cmd->un.fcpi64.bdl.bdeSize =
1003 ((num_bde + 2) * sizeof(struct ulp_bde64));
1004 iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1);
1006 fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd));
1009 * Due to difference in data length between DIF/non-DIF paths,
1010 * we need to set word 4 of IOCB here
1012 iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd);
1016 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1018 /* Return BG_ERR_INIT if error injection is detected by Initiator */
1019 #define BG_ERR_INIT 0x1
1020 /* Return BG_ERR_TGT if error injection is detected by Target */
1021 #define BG_ERR_TGT 0x2
1022 /* Return BG_ERR_SWAP if swapping CSUM<-->CRC is required for error injection */
1023 #define BG_ERR_SWAP 0x10
1025 * Return BG_ERR_CHECK if disabling Guard/Ref/App checking is required for
1028 #define BG_ERR_CHECK 0x20
1031 * lpfc_bg_err_inject - Determine if we should inject an error
1032 * @phba: The Hba for which this call is being executed.
1033 * @sc: The SCSI command to examine
1034 * @reftag: (out) BlockGuard reference tag for transmitted data
1035 * @apptag: (out) BlockGuard application tag for transmitted data
1036 * @new_guard (in) Value to replace CRC with if needed
1038 * Returns BG_ERR_* bit mask or 0 if request ignored
1041 lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1042 uint32_t *reftag, uint16_t *apptag, uint32_t new_guard)
1044 struct scatterlist *sgpe; /* s/g prot entry */
1045 struct lpfc_scsi_buf *lpfc_cmd = NULL;
1046 struct scsi_dif_tuple *src = NULL;
1047 struct lpfc_nodelist *ndlp;
1048 struct lpfc_rport_data *rdata;
1049 uint32_t op = scsi_get_prot_op(sc);
1056 if (op == SCSI_PROT_NORMAL)
1059 sgpe = scsi_prot_sglist(sc);
1060 lba = scsi_get_lba(sc);
1062 /* First check if we need to match the LBA */
1063 if (phba->lpfc_injerr_lba != LPFC_INJERR_LBA_OFF) {
1064 blksize = lpfc_cmd_blksize(sc);
1065 numblks = (scsi_bufflen(sc) + blksize - 1) / blksize;
1067 /* Make sure we have the right LBA if one is specified */
1068 if ((phba->lpfc_injerr_lba < lba) ||
1069 (phba->lpfc_injerr_lba >= (lba + numblks)))
1072 blockoff = phba->lpfc_injerr_lba - lba;
1073 numblks = sg_dma_len(sgpe) /
1074 sizeof(struct scsi_dif_tuple);
1075 if (numblks < blockoff)
1080 /* Next check if we need to match the remote NPortID or WWPN */
1081 rdata = lpfc_rport_data_from_scsi_device(sc->device);
1082 if (rdata && rdata->pnode) {
1083 ndlp = rdata->pnode;
1085 /* Make sure we have the right NPortID if one is specified */
1086 if (phba->lpfc_injerr_nportid &&
1087 (phba->lpfc_injerr_nportid != ndlp->nlp_DID))
1091 * Make sure we have the right WWPN if one is specified.
1092 * wwn[0] should be a non-zero NAA in a good WWPN.
1094 if (phba->lpfc_injerr_wwpn.u.wwn[0] &&
1095 (memcmp(&ndlp->nlp_portname, &phba->lpfc_injerr_wwpn,
1096 sizeof(struct lpfc_name)) != 0))
1100 /* Setup a ptr to the protection data if the SCSI host provides it */
1102 src = (struct scsi_dif_tuple *)sg_virt(sgpe);
1104 lpfc_cmd = (struct lpfc_scsi_buf *)sc->host_scribble;
1107 /* Should we change the Reference Tag */
1109 if (phba->lpfc_injerr_wref_cnt) {
1111 case SCSI_PROT_WRITE_PASS:
1114 * For WRITE_PASS, force the error
1115 * to be sent on the wire. It should
1116 * be detected by the Target.
1117 * If blockoff != 0 error will be
1118 * inserted in middle of the IO.
1121 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1122 "9076 BLKGRD: Injecting reftag error: "
1123 "write lba x%lx + x%x oldrefTag x%x\n",
1124 (unsigned long)lba, blockoff,
1125 be32_to_cpu(src->ref_tag));
1128 * Save the old ref_tag so we can
1129 * restore it on completion.
1132 lpfc_cmd->prot_data_type =
1134 lpfc_cmd->prot_data_segment =
1136 lpfc_cmd->prot_data =
1139 src->ref_tag = cpu_to_be32(0xDEADBEEF);
1140 phba->lpfc_injerr_wref_cnt--;
1141 if (phba->lpfc_injerr_wref_cnt == 0) {
1142 phba->lpfc_injerr_nportid = 0;
1143 phba->lpfc_injerr_lba =
1144 LPFC_INJERR_LBA_OFF;
1145 memset(&phba->lpfc_injerr_wwpn,
1146 0, sizeof(struct lpfc_name));
1148 rc = BG_ERR_TGT | BG_ERR_CHECK;
1153 case SCSI_PROT_WRITE_INSERT:
1155 * For WRITE_INSERT, force the error
1156 * to be sent on the wire. It should be
1157 * detected by the Target.
1159 /* DEADBEEF will be the reftag on the wire */
1160 *reftag = 0xDEADBEEF;
1161 phba->lpfc_injerr_wref_cnt--;
1162 if (phba->lpfc_injerr_wref_cnt == 0) {
1163 phba->lpfc_injerr_nportid = 0;
1164 phba->lpfc_injerr_lba =
1165 LPFC_INJERR_LBA_OFF;
1166 memset(&phba->lpfc_injerr_wwpn,
1167 0, sizeof(struct lpfc_name));
1169 rc = BG_ERR_TGT | BG_ERR_CHECK;
1171 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1172 "9078 BLKGRD: Injecting reftag error: "
1173 "write lba x%lx\n", (unsigned long)lba);
1175 case SCSI_PROT_WRITE_STRIP:
1177 * For WRITE_STRIP and WRITE_PASS,
1178 * force the error on data
1179 * being copied from SLI-Host to SLI-Port.
1181 *reftag = 0xDEADBEEF;
1182 phba->lpfc_injerr_wref_cnt--;
1183 if (phba->lpfc_injerr_wref_cnt == 0) {
1184 phba->lpfc_injerr_nportid = 0;
1185 phba->lpfc_injerr_lba =
1186 LPFC_INJERR_LBA_OFF;
1187 memset(&phba->lpfc_injerr_wwpn,
1188 0, sizeof(struct lpfc_name));
1192 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1193 "9077 BLKGRD: Injecting reftag error: "
1194 "write lba x%lx\n", (unsigned long)lba);
1198 if (phba->lpfc_injerr_rref_cnt) {
1200 case SCSI_PROT_READ_INSERT:
1201 case SCSI_PROT_READ_STRIP:
1202 case SCSI_PROT_READ_PASS:
1204 * For READ_STRIP and READ_PASS, force the
1205 * error on data being read off the wire. It
1206 * should force an IO error to the driver.
1208 *reftag = 0xDEADBEEF;
1209 phba->lpfc_injerr_rref_cnt--;
1210 if (phba->lpfc_injerr_rref_cnt == 0) {
1211 phba->lpfc_injerr_nportid = 0;
1212 phba->lpfc_injerr_lba =
1213 LPFC_INJERR_LBA_OFF;
1214 memset(&phba->lpfc_injerr_wwpn,
1215 0, sizeof(struct lpfc_name));
1219 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1220 "9079 BLKGRD: Injecting reftag error: "
1221 "read lba x%lx\n", (unsigned long)lba);
1227 /* Should we change the Application Tag */
1229 if (phba->lpfc_injerr_wapp_cnt) {
1231 case SCSI_PROT_WRITE_PASS:
1234 * For WRITE_PASS, force the error
1235 * to be sent on the wire. It should
1236 * be detected by the Target.
1237 * If blockoff != 0 error will be
1238 * inserted in middle of the IO.
1241 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1242 "9080 BLKGRD: Injecting apptag error: "
1243 "write lba x%lx + x%x oldappTag x%x\n",
1244 (unsigned long)lba, blockoff,
1245 be16_to_cpu(src->app_tag));
1248 * Save the old app_tag so we can
1249 * restore it on completion.
1252 lpfc_cmd->prot_data_type =
1254 lpfc_cmd->prot_data_segment =
1256 lpfc_cmd->prot_data =
1259 src->app_tag = cpu_to_be16(0xDEAD);
1260 phba->lpfc_injerr_wapp_cnt--;
1261 if (phba->lpfc_injerr_wapp_cnt == 0) {
1262 phba->lpfc_injerr_nportid = 0;
1263 phba->lpfc_injerr_lba =
1264 LPFC_INJERR_LBA_OFF;
1265 memset(&phba->lpfc_injerr_wwpn,
1266 0, sizeof(struct lpfc_name));
1268 rc = BG_ERR_TGT | BG_ERR_CHECK;
1272 case SCSI_PROT_WRITE_INSERT:
1274 * For WRITE_INSERT, force the
1275 * error to be sent on the wire. It should be
1276 * detected by the Target.
1278 /* DEAD will be the apptag on the wire */
1280 phba->lpfc_injerr_wapp_cnt--;
1281 if (phba->lpfc_injerr_wapp_cnt == 0) {
1282 phba->lpfc_injerr_nportid = 0;
1283 phba->lpfc_injerr_lba =
1284 LPFC_INJERR_LBA_OFF;
1285 memset(&phba->lpfc_injerr_wwpn,
1286 0, sizeof(struct lpfc_name));
1288 rc = BG_ERR_TGT | BG_ERR_CHECK;
1290 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1291 "0813 BLKGRD: Injecting apptag error: "
1292 "write lba x%lx\n", (unsigned long)lba);
1294 case SCSI_PROT_WRITE_STRIP:
1296 * For WRITE_STRIP and WRITE_PASS,
1297 * force the error on data
1298 * being copied from SLI-Host to SLI-Port.
1301 phba->lpfc_injerr_wapp_cnt--;
1302 if (phba->lpfc_injerr_wapp_cnt == 0) {
1303 phba->lpfc_injerr_nportid = 0;
1304 phba->lpfc_injerr_lba =
1305 LPFC_INJERR_LBA_OFF;
1306 memset(&phba->lpfc_injerr_wwpn,
1307 0, sizeof(struct lpfc_name));
1311 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1312 "0812 BLKGRD: Injecting apptag error: "
1313 "write lba x%lx\n", (unsigned long)lba);
1317 if (phba->lpfc_injerr_rapp_cnt) {
1319 case SCSI_PROT_READ_INSERT:
1320 case SCSI_PROT_READ_STRIP:
1321 case SCSI_PROT_READ_PASS:
1323 * For READ_STRIP and READ_PASS, force the
1324 * error on data being read off the wire. It
1325 * should force an IO error to the driver.
1328 phba->lpfc_injerr_rapp_cnt--;
1329 if (phba->lpfc_injerr_rapp_cnt == 0) {
1330 phba->lpfc_injerr_nportid = 0;
1331 phba->lpfc_injerr_lba =
1332 LPFC_INJERR_LBA_OFF;
1333 memset(&phba->lpfc_injerr_wwpn,
1334 0, sizeof(struct lpfc_name));
1338 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1339 "0814 BLKGRD: Injecting apptag error: "
1340 "read lba x%lx\n", (unsigned long)lba);
1347 /* Should we change the Guard Tag */
1349 if (phba->lpfc_injerr_wgrd_cnt) {
1351 case SCSI_PROT_WRITE_PASS:
1355 case SCSI_PROT_WRITE_INSERT:
1357 * For WRITE_INSERT, force the
1358 * error to be sent on the wire. It should be
1359 * detected by the Target.
1361 phba->lpfc_injerr_wgrd_cnt--;
1362 if (phba->lpfc_injerr_wgrd_cnt == 0) {
1363 phba->lpfc_injerr_nportid = 0;
1364 phba->lpfc_injerr_lba =
1365 LPFC_INJERR_LBA_OFF;
1366 memset(&phba->lpfc_injerr_wwpn,
1367 0, sizeof(struct lpfc_name));
1370 rc |= BG_ERR_TGT | BG_ERR_SWAP;
1371 /* Signals the caller to swap CRC->CSUM */
1373 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1374 "0817 BLKGRD: Injecting guard error: "
1375 "write lba x%lx\n", (unsigned long)lba);
1377 case SCSI_PROT_WRITE_STRIP:
1379 * For WRITE_STRIP and WRITE_PASS,
1380 * force the error on data
1381 * being copied from SLI-Host to SLI-Port.
1383 phba->lpfc_injerr_wgrd_cnt--;
1384 if (phba->lpfc_injerr_wgrd_cnt == 0) {
1385 phba->lpfc_injerr_nportid = 0;
1386 phba->lpfc_injerr_lba =
1387 LPFC_INJERR_LBA_OFF;
1388 memset(&phba->lpfc_injerr_wwpn,
1389 0, sizeof(struct lpfc_name));
1392 rc = BG_ERR_INIT | BG_ERR_SWAP;
1393 /* Signals the caller to swap CRC->CSUM */
1395 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1396 "0816 BLKGRD: Injecting guard error: "
1397 "write lba x%lx\n", (unsigned long)lba);
1401 if (phba->lpfc_injerr_rgrd_cnt) {
1403 case SCSI_PROT_READ_INSERT:
1404 case SCSI_PROT_READ_STRIP:
1405 case SCSI_PROT_READ_PASS:
1407 * For READ_STRIP and READ_PASS, force the
1408 * error on data being read off the wire. It
1409 * should force an IO error to the driver.
1411 phba->lpfc_injerr_rgrd_cnt--;
1412 if (phba->lpfc_injerr_rgrd_cnt == 0) {
1413 phba->lpfc_injerr_nportid = 0;
1414 phba->lpfc_injerr_lba =
1415 LPFC_INJERR_LBA_OFF;
1416 memset(&phba->lpfc_injerr_wwpn,
1417 0, sizeof(struct lpfc_name));
1420 rc = BG_ERR_INIT | BG_ERR_SWAP;
1421 /* Signals the caller to swap CRC->CSUM */
1423 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1424 "0818 BLKGRD: Injecting guard error: "
1425 "read lba x%lx\n", (unsigned long)lba);
1435 * lpfc_sc_to_bg_opcodes - Determine the BlockGuard opcodes to be used with
1436 * the specified SCSI command.
1437 * @phba: The Hba for which this call is being executed.
1438 * @sc: The SCSI command to examine
1439 * @txopt: (out) BlockGuard operation for transmitted data
1440 * @rxopt: (out) BlockGuard operation for received data
1442 * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
1446 lpfc_sc_to_bg_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1447 uint8_t *txop, uint8_t *rxop)
1451 if (lpfc_cmd_guard_csum(sc)) {
1452 switch (scsi_get_prot_op(sc)) {
1453 case SCSI_PROT_READ_INSERT:
1454 case SCSI_PROT_WRITE_STRIP:
1455 *rxop = BG_OP_IN_NODIF_OUT_CSUM;
1456 *txop = BG_OP_IN_CSUM_OUT_NODIF;
1459 case SCSI_PROT_READ_STRIP:
1460 case SCSI_PROT_WRITE_INSERT:
1461 *rxop = BG_OP_IN_CRC_OUT_NODIF;
1462 *txop = BG_OP_IN_NODIF_OUT_CRC;
1465 case SCSI_PROT_READ_PASS:
1466 case SCSI_PROT_WRITE_PASS:
1467 *rxop = BG_OP_IN_CRC_OUT_CSUM;
1468 *txop = BG_OP_IN_CSUM_OUT_CRC;
1471 case SCSI_PROT_NORMAL:
1473 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1474 "9063 BLKGRD: Bad op/guard:%d/IP combination\n",
1475 scsi_get_prot_op(sc));
1481 switch (scsi_get_prot_op(sc)) {
1482 case SCSI_PROT_READ_STRIP:
1483 case SCSI_PROT_WRITE_INSERT:
1484 *rxop = BG_OP_IN_CRC_OUT_NODIF;
1485 *txop = BG_OP_IN_NODIF_OUT_CRC;
1488 case SCSI_PROT_READ_PASS:
1489 case SCSI_PROT_WRITE_PASS:
1490 *rxop = BG_OP_IN_CRC_OUT_CRC;
1491 *txop = BG_OP_IN_CRC_OUT_CRC;
1494 case SCSI_PROT_READ_INSERT:
1495 case SCSI_PROT_WRITE_STRIP:
1496 *rxop = BG_OP_IN_NODIF_OUT_CRC;
1497 *txop = BG_OP_IN_CRC_OUT_NODIF;
1500 case SCSI_PROT_NORMAL:
1502 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1503 "9075 BLKGRD: Bad op/guard:%d/CRC combination\n",
1504 scsi_get_prot_op(sc));
1513 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1515 * lpfc_bg_err_opcodes - reDetermine the BlockGuard opcodes to be used with
1516 * the specified SCSI command in order to force a guard tag error.
1517 * @phba: The Hba for which this call is being executed.
1518 * @sc: The SCSI command to examine
1519 * @txopt: (out) BlockGuard operation for transmitted data
1520 * @rxopt: (out) BlockGuard operation for received data
1522 * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
1526 lpfc_bg_err_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1527 uint8_t *txop, uint8_t *rxop)
1531 if (lpfc_cmd_guard_csum(sc)) {
1532 switch (scsi_get_prot_op(sc)) {
1533 case SCSI_PROT_READ_INSERT:
1534 case SCSI_PROT_WRITE_STRIP:
1535 *rxop = BG_OP_IN_NODIF_OUT_CRC;
1536 *txop = BG_OP_IN_CRC_OUT_NODIF;
1539 case SCSI_PROT_READ_STRIP:
1540 case SCSI_PROT_WRITE_INSERT:
1541 *rxop = BG_OP_IN_CSUM_OUT_NODIF;
1542 *txop = BG_OP_IN_NODIF_OUT_CSUM;
1545 case SCSI_PROT_READ_PASS:
1546 case SCSI_PROT_WRITE_PASS:
1547 *rxop = BG_OP_IN_CSUM_OUT_CRC;
1548 *txop = BG_OP_IN_CRC_OUT_CSUM;
1551 case SCSI_PROT_NORMAL:
1557 switch (scsi_get_prot_op(sc)) {
1558 case SCSI_PROT_READ_STRIP:
1559 case SCSI_PROT_WRITE_INSERT:
1560 *rxop = BG_OP_IN_CSUM_OUT_NODIF;
1561 *txop = BG_OP_IN_NODIF_OUT_CSUM;
1564 case SCSI_PROT_READ_PASS:
1565 case SCSI_PROT_WRITE_PASS:
1566 *rxop = BG_OP_IN_CSUM_OUT_CSUM;
1567 *txop = BG_OP_IN_CSUM_OUT_CSUM;
1570 case SCSI_PROT_READ_INSERT:
1571 case SCSI_PROT_WRITE_STRIP:
1572 *rxop = BG_OP_IN_NODIF_OUT_CSUM;
1573 *txop = BG_OP_IN_CSUM_OUT_NODIF;
1576 case SCSI_PROT_NORMAL:
1587 * lpfc_bg_setup_bpl - Setup BlockGuard BPL with no protection data
1588 * @phba: The Hba for which this call is being executed.
1589 * @sc: pointer to scsi command we're working on
1590 * @bpl: pointer to buffer list for protection groups
1591 * @datacnt: number of segments of data that have been dma mapped
1593 * This function sets up BPL buffer list for protection groups of
1594 * type LPFC_PG_TYPE_NO_DIF
1596 * This is usually used when the HBA is instructed to generate
1597 * DIFs and insert them into data stream (or strip DIF from
1598 * incoming data stream)
1600 * The buffer list consists of just one protection group described
1602 * +-------------------------+
1603 * start of prot group --> | PDE_5 |
1604 * +-------------------------+
1606 * +-------------------------+
1608 * +-------------------------+
1609 * |more Data BDE's ... (opt)|
1610 * +-------------------------+
1613 * Note: Data s/g buffers have been dma mapped
1615 * Returns the number of BDEs added to the BPL.
1618 lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1619 struct ulp_bde64 *bpl, int datasegcnt)
1621 struct scatterlist *sgde = NULL; /* s/g data entry */
1622 struct lpfc_pde5 *pde5 = NULL;
1623 struct lpfc_pde6 *pde6 = NULL;
1624 dma_addr_t physaddr;
1625 int i = 0, num_bde = 0, status;
1626 int datadir = sc->sc_data_direction;
1627 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1630 uint32_t checking = 1;
1634 status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
1638 /* extract some info from the scsi command for pde*/
1639 reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
1641 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1642 rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
1644 if (rc & BG_ERR_SWAP)
1645 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
1646 if (rc & BG_ERR_CHECK)
1651 /* setup PDE5 with what we have */
1652 pde5 = (struct lpfc_pde5 *) bpl;
1653 memset(pde5, 0, sizeof(struct lpfc_pde5));
1654 bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR);
1656 /* Endianness conversion if necessary for PDE5 */
1657 pde5->word0 = cpu_to_le32(pde5->word0);
1658 pde5->reftag = cpu_to_le32(reftag);
1660 /* advance bpl and increment bde count */
1663 pde6 = (struct lpfc_pde6 *) bpl;
1665 /* setup PDE6 with the rest of the info */
1666 memset(pde6, 0, sizeof(struct lpfc_pde6));
1667 bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR);
1668 bf_set(pde6_optx, pde6, txop);
1669 bf_set(pde6_oprx, pde6, rxop);
1672 * We only need to check the data on READs, for WRITEs
1673 * protection data is automatically generated, not checked.
1675 if (datadir == DMA_FROM_DEVICE) {
1676 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD))
1677 bf_set(pde6_ce, pde6, checking);
1679 bf_set(pde6_ce, pde6, 0);
1681 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF))
1682 bf_set(pde6_re, pde6, checking);
1684 bf_set(pde6_re, pde6, 0);
1686 bf_set(pde6_ai, pde6, 1);
1687 bf_set(pde6_ae, pde6, 0);
1688 bf_set(pde6_apptagval, pde6, 0);
1690 /* Endianness conversion if necessary for PDE6 */
1691 pde6->word0 = cpu_to_le32(pde6->word0);
1692 pde6->word1 = cpu_to_le32(pde6->word1);
1693 pde6->word2 = cpu_to_le32(pde6->word2);
1695 /* advance bpl and increment bde count */
1699 /* assumption: caller has already run dma_map_sg on command data */
1700 scsi_for_each_sg(sc, sgde, datasegcnt, i) {
1701 physaddr = sg_dma_address(sgde);
1702 bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr));
1703 bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
1704 bpl->tus.f.bdeSize = sg_dma_len(sgde);
1705 if (datadir == DMA_TO_DEVICE)
1706 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1708 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
1709 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1719 * lpfc_bg_setup_bpl_prot - Setup BlockGuard BPL with protection data
1720 * @phba: The Hba for which this call is being executed.
1721 * @sc: pointer to scsi command we're working on
1722 * @bpl: pointer to buffer list for protection groups
1723 * @datacnt: number of segments of data that have been dma mapped
1724 * @protcnt: number of segment of protection data that have been dma mapped
1726 * This function sets up BPL buffer list for protection groups of
1727 * type LPFC_PG_TYPE_DIF
1729 * This is usually used when DIFs are in their own buffers,
1730 * separate from the data. The HBA can then by instructed
1731 * to place the DIFs in the outgoing stream. For read operations,
1732 * The HBA could extract the DIFs and place it in DIF buffers.
1734 * The buffer list for this type consists of one or more of the
1735 * protection groups described below:
1736 * +-------------------------+
1737 * start of first prot group --> | PDE_5 |
1738 * +-------------------------+
1740 * +-------------------------+
1741 * | PDE_7 (Prot BDE) |
1742 * +-------------------------+
1744 * +-------------------------+
1745 * |more Data BDE's ... (opt)|
1746 * +-------------------------+
1747 * start of new prot group --> | PDE_5 |
1748 * +-------------------------+
1750 * +-------------------------+
1752 * Note: It is assumed that both data and protection s/g buffers have been
1755 * Returns the number of BDEs added to the BPL.
1758 lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1759 struct ulp_bde64 *bpl, int datacnt, int protcnt)
1761 struct scatterlist *sgde = NULL; /* s/g data entry */
1762 struct scatterlist *sgpe = NULL; /* s/g prot entry */
1763 struct lpfc_pde5 *pde5 = NULL;
1764 struct lpfc_pde6 *pde6 = NULL;
1765 struct lpfc_pde7 *pde7 = NULL;
1766 dma_addr_t dataphysaddr, protphysaddr;
1767 unsigned short curr_data = 0, curr_prot = 0;
1768 unsigned int split_offset;
1769 unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder;
1770 unsigned int protgrp_blks, protgrp_bytes;
1771 unsigned int remainder, subtotal;
1773 int datadir = sc->sc_data_direction;
1774 unsigned char pgdone = 0, alldone = 0;
1776 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1779 uint32_t checking = 1;
1784 sgpe = scsi_prot_sglist(sc);
1785 sgde = scsi_sglist(sc);
1787 if (!sgpe || !sgde) {
1788 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
1789 "9020 Invalid s/g entry: data=0x%p prot=0x%p\n",
1794 status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
1798 /* extract some info from the scsi command */
1799 blksize = lpfc_cmd_blksize(sc);
1800 reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
1802 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1803 rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
1805 if (rc & BG_ERR_SWAP)
1806 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
1807 if (rc & BG_ERR_CHECK)
1814 /* Check to see if we ran out of space */
1815 if (num_bde >= (phba->cfg_total_seg_cnt - 2))
1818 /* setup PDE5 with what we have */
1819 pde5 = (struct lpfc_pde5 *) bpl;
1820 memset(pde5, 0, sizeof(struct lpfc_pde5));
1821 bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR);
1823 /* Endianness conversion if necessary for PDE5 */
1824 pde5->word0 = cpu_to_le32(pde5->word0);
1825 pde5->reftag = cpu_to_le32(reftag);
1827 /* advance bpl and increment bde count */
1830 pde6 = (struct lpfc_pde6 *) bpl;
1832 /* setup PDE6 with the rest of the info */
1833 memset(pde6, 0, sizeof(struct lpfc_pde6));
1834 bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR);
1835 bf_set(pde6_optx, pde6, txop);
1836 bf_set(pde6_oprx, pde6, rxop);
1838 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD))
1839 bf_set(pde6_ce, pde6, checking);
1841 bf_set(pde6_ce, pde6, 0);
1843 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF))
1844 bf_set(pde6_re, pde6, checking);
1846 bf_set(pde6_re, pde6, 0);
1848 bf_set(pde6_ai, pde6, 1);
1849 bf_set(pde6_ae, pde6, 0);
1850 bf_set(pde6_apptagval, pde6, 0);
1852 /* Endianness conversion if necessary for PDE6 */
1853 pde6->word0 = cpu_to_le32(pde6->word0);
1854 pde6->word1 = cpu_to_le32(pde6->word1);
1855 pde6->word2 = cpu_to_le32(pde6->word2);
1857 /* advance bpl and increment bde count */
1861 /* setup the first BDE that points to protection buffer */
1862 protphysaddr = sg_dma_address(sgpe) + protgroup_offset;
1863 protgroup_len = sg_dma_len(sgpe) - protgroup_offset;
1865 /* must be integer multiple of the DIF block length */
1866 BUG_ON(protgroup_len % 8);
1868 pde7 = (struct lpfc_pde7 *) bpl;
1869 memset(pde7, 0, sizeof(struct lpfc_pde7));
1870 bf_set(pde7_type, pde7, LPFC_PDE7_DESCRIPTOR);
1872 pde7->addrHigh = le32_to_cpu(putPaddrHigh(protphysaddr));
1873 pde7->addrLow = le32_to_cpu(putPaddrLow(protphysaddr));
1875 protgrp_blks = protgroup_len / 8;
1876 protgrp_bytes = protgrp_blks * blksize;
1878 /* check if this pde is crossing the 4K boundary; if so split */
1879 if ((pde7->addrLow & 0xfff) + protgroup_len > 0x1000) {
1880 protgroup_remainder = 0x1000 - (pde7->addrLow & 0xfff);
1881 protgroup_offset += protgroup_remainder;
1882 protgrp_blks = protgroup_remainder / 8;
1883 protgrp_bytes = protgrp_blks * blksize;
1885 protgroup_offset = 0;
1891 /* setup BDE's for data blocks associated with DIF data */
1893 subtotal = 0; /* total bytes processed for current prot grp */
1895 /* Check to see if we ran out of space */
1896 if (num_bde >= phba->cfg_total_seg_cnt)
1900 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1901 "9065 BLKGRD:%s Invalid data segment\n",
1906 dataphysaddr = sg_dma_address(sgde) + split_offset;
1907 bpl->addrLow = le32_to_cpu(putPaddrLow(dataphysaddr));
1908 bpl->addrHigh = le32_to_cpu(putPaddrHigh(dataphysaddr));
1910 remainder = sg_dma_len(sgde) - split_offset;
1912 if ((subtotal + remainder) <= protgrp_bytes) {
1913 /* we can use this whole buffer */
1914 bpl->tus.f.bdeSize = remainder;
1917 if ((subtotal + remainder) == protgrp_bytes)
1920 /* must split this buffer with next prot grp */
1921 bpl->tus.f.bdeSize = protgrp_bytes - subtotal;
1922 split_offset += bpl->tus.f.bdeSize;
1925 subtotal += bpl->tus.f.bdeSize;
1927 if (datadir == DMA_TO_DEVICE)
1928 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1930 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
1931 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1939 /* Move to the next s/g segment if possible */
1940 sgde = sg_next(sgde);
1944 if (protgroup_offset) {
1945 /* update the reference tag */
1946 reftag += protgrp_blks;
1952 if (curr_prot == protcnt) {
1954 } else if (curr_prot < protcnt) {
1955 /* advance to next prot buffer */
1956 sgpe = sg_next(sgpe);
1959 /* update the reference tag */
1960 reftag += protgrp_blks;
1962 /* if we're here, we have a bug */
1963 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1964 "9054 BLKGRD: bug in %s\n", __func__);
1974 * lpfc_bg_setup_sgl - Setup BlockGuard SGL with no protection data
1975 * @phba: The Hba for which this call is being executed.
1976 * @sc: pointer to scsi command we're working on
1977 * @sgl: pointer to buffer list for protection groups
1978 * @datacnt: number of segments of data that have been dma mapped
1980 * This function sets up SGL buffer list for protection groups of
1981 * type LPFC_PG_TYPE_NO_DIF
1983 * This is usually used when the HBA is instructed to generate
1984 * DIFs and insert them into data stream (or strip DIF from
1985 * incoming data stream)
1987 * The buffer list consists of just one protection group described
1989 * +-------------------------+
1990 * start of prot group --> | DI_SEED |
1991 * +-------------------------+
1993 * +-------------------------+
1994 * |more Data SGE's ... (opt)|
1995 * +-------------------------+
1998 * Note: Data s/g buffers have been dma mapped
2000 * Returns the number of SGEs added to the SGL.
2003 lpfc_bg_setup_sgl(struct lpfc_hba *phba, struct scsi_cmnd *sc,
2004 struct sli4_sge *sgl, int datasegcnt)
2006 struct scatterlist *sgde = NULL; /* s/g data entry */
2007 struct sli4_sge_diseed *diseed = NULL;
2008 dma_addr_t physaddr;
2009 int i = 0, num_sge = 0, status;
2012 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2015 uint32_t checking = 1;
2017 uint32_t dma_offset = 0;
2019 status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
2023 /* extract some info from the scsi command for pde*/
2024 reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
2026 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2027 rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
2029 if (rc & BG_ERR_SWAP)
2030 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
2031 if (rc & BG_ERR_CHECK)
2036 /* setup DISEED with what we have */
2037 diseed = (struct sli4_sge_diseed *) sgl;
2038 memset(diseed, 0, sizeof(struct sli4_sge_diseed));
2039 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED);
2041 /* Endianness conversion if necessary */
2042 diseed->ref_tag = cpu_to_le32(reftag);
2043 diseed->ref_tag_tran = diseed->ref_tag;
2046 * We only need to check the data on READs, for WRITEs
2047 * protection data is automatically generated, not checked.
2049 if (sc->sc_data_direction == DMA_FROM_DEVICE) {
2050 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD))
2051 bf_set(lpfc_sli4_sge_dif_ce, diseed, checking);
2053 bf_set(lpfc_sli4_sge_dif_ce, diseed, 0);
2055 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF))
2056 bf_set(lpfc_sli4_sge_dif_re, diseed, checking);
2058 bf_set(lpfc_sli4_sge_dif_re, diseed, 0);
2061 /* setup DISEED with the rest of the info */
2062 bf_set(lpfc_sli4_sge_dif_optx, diseed, txop);
2063 bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop);
2065 bf_set(lpfc_sli4_sge_dif_ai, diseed, 1);
2066 bf_set(lpfc_sli4_sge_dif_me, diseed, 0);
2068 /* Endianness conversion if necessary for DISEED */
2069 diseed->word2 = cpu_to_le32(diseed->word2);
2070 diseed->word3 = cpu_to_le32(diseed->word3);
2072 /* advance bpl and increment sge count */
2076 /* assumption: caller has already run dma_map_sg on command data */
2077 scsi_for_each_sg(sc, sgde, datasegcnt, i) {
2078 physaddr = sg_dma_address(sgde);
2079 dma_len = sg_dma_len(sgde);
2080 sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr));
2081 sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr));
2082 if ((i + 1) == datasegcnt)
2083 bf_set(lpfc_sli4_sge_last, sgl, 1);
2085 bf_set(lpfc_sli4_sge_last, sgl, 0);
2086 bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
2087 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA);
2089 sgl->sge_len = cpu_to_le32(dma_len);
2090 dma_offset += dma_len;
2101 * lpfc_bg_setup_sgl_prot - Setup BlockGuard SGL with protection data
2102 * @phba: The Hba for which this call is being executed.
2103 * @sc: pointer to scsi command we're working on
2104 * @sgl: pointer to buffer list for protection groups
2105 * @datacnt: number of segments of data that have been dma mapped
2106 * @protcnt: number of segment of protection data that have been dma mapped
2108 * This function sets up SGL buffer list for protection groups of
2109 * type LPFC_PG_TYPE_DIF
2111 * This is usually used when DIFs are in their own buffers,
2112 * separate from the data. The HBA can then by instructed
2113 * to place the DIFs in the outgoing stream. For read operations,
2114 * The HBA could extract the DIFs and place it in DIF buffers.
2116 * The buffer list for this type consists of one or more of the
2117 * protection groups described below:
2118 * +-------------------------+
2119 * start of first prot group --> | DISEED |
2120 * +-------------------------+
2121 * | DIF (Prot SGE) |
2122 * +-------------------------+
2124 * +-------------------------+
2125 * |more Data SGE's ... (opt)|
2126 * +-------------------------+
2127 * start of new prot group --> | DISEED |
2128 * +-------------------------+
2130 * +-------------------------+
2132 * Note: It is assumed that both data and protection s/g buffers have been
2135 * Returns the number of SGEs added to the SGL.
2138 lpfc_bg_setup_sgl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc,
2139 struct sli4_sge *sgl, int datacnt, int protcnt)
2141 struct scatterlist *sgde = NULL; /* s/g data entry */
2142 struct scatterlist *sgpe = NULL; /* s/g prot entry */
2143 struct sli4_sge_diseed *diseed = NULL;
2144 dma_addr_t dataphysaddr, protphysaddr;
2145 unsigned short curr_data = 0, curr_prot = 0;
2146 unsigned int split_offset;
2147 unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder;
2148 unsigned int protgrp_blks, protgrp_bytes;
2149 unsigned int remainder, subtotal;
2151 unsigned char pgdone = 0, alldone = 0;
2156 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2159 uint32_t checking = 1;
2160 uint32_t dma_offset = 0;
2163 sgpe = scsi_prot_sglist(sc);
2164 sgde = scsi_sglist(sc);
2166 if (!sgpe || !sgde) {
2167 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
2168 "9082 Invalid s/g entry: data=0x%p prot=0x%p\n",
2173 status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
2177 /* extract some info from the scsi command */
2178 blksize = lpfc_cmd_blksize(sc);
2179 reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
2181 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2182 rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
2184 if (rc & BG_ERR_SWAP)
2185 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
2186 if (rc & BG_ERR_CHECK)
2193 /* Check to see if we ran out of space */
2194 if (num_sge >= (phba->cfg_total_seg_cnt - 2))
2197 /* setup DISEED with what we have */
2198 diseed = (struct sli4_sge_diseed *) sgl;
2199 memset(diseed, 0, sizeof(struct sli4_sge_diseed));
2200 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED);
2202 /* Endianness conversion if necessary */
2203 diseed->ref_tag = cpu_to_le32(reftag);
2204 diseed->ref_tag_tran = diseed->ref_tag;
2206 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) {
2207 bf_set(lpfc_sli4_sge_dif_ce, diseed, checking);
2210 bf_set(lpfc_sli4_sge_dif_ce, diseed, 0);
2212 * When in this mode, the hardware will replace
2213 * the guard tag from the host with a
2214 * newly generated good CRC for the wire.
2215 * Switch to raw mode here to avoid this
2216 * behavior. What the host sends gets put on the wire.
2218 if (txop == BG_OP_IN_CRC_OUT_CRC) {
2219 txop = BG_OP_RAW_MODE;
2220 rxop = BG_OP_RAW_MODE;
2225 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF))
2226 bf_set(lpfc_sli4_sge_dif_re, diseed, checking);
2228 bf_set(lpfc_sli4_sge_dif_re, diseed, 0);
2230 /* setup DISEED with the rest of the info */
2231 bf_set(lpfc_sli4_sge_dif_optx, diseed, txop);
2232 bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop);
2234 bf_set(lpfc_sli4_sge_dif_ai, diseed, 1);
2235 bf_set(lpfc_sli4_sge_dif_me, diseed, 0);
2237 /* Endianness conversion if necessary for DISEED */
2238 diseed->word2 = cpu_to_le32(diseed->word2);
2239 diseed->word3 = cpu_to_le32(diseed->word3);
2241 /* advance sgl and increment bde count */
2245 /* setup the first BDE that points to protection buffer */
2246 protphysaddr = sg_dma_address(sgpe) + protgroup_offset;
2247 protgroup_len = sg_dma_len(sgpe) - protgroup_offset;
2249 /* must be integer multiple of the DIF block length */
2250 BUG_ON(protgroup_len % 8);
2252 /* Now setup DIF SGE */
2254 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DIF);
2255 sgl->addr_hi = le32_to_cpu(putPaddrHigh(protphysaddr));
2256 sgl->addr_lo = le32_to_cpu(putPaddrLow(protphysaddr));
2257 sgl->word2 = cpu_to_le32(sgl->word2);
2259 protgrp_blks = protgroup_len / 8;
2260 protgrp_bytes = protgrp_blks * blksize;
2262 /* check if DIF SGE is crossing the 4K boundary; if so split */
2263 if ((sgl->addr_lo & 0xfff) + protgroup_len > 0x1000) {
2264 protgroup_remainder = 0x1000 - (sgl->addr_lo & 0xfff);
2265 protgroup_offset += protgroup_remainder;
2266 protgrp_blks = protgroup_remainder / 8;
2267 protgrp_bytes = protgrp_blks * blksize;
2269 protgroup_offset = 0;
2275 /* setup SGE's for data blocks associated with DIF data */
2277 subtotal = 0; /* total bytes processed for current prot grp */
2279 /* Check to see if we ran out of space */
2280 if (num_sge >= phba->cfg_total_seg_cnt)
2284 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
2285 "9086 BLKGRD:%s Invalid data segment\n",
2290 dataphysaddr = sg_dma_address(sgde) + split_offset;
2292 remainder = sg_dma_len(sgde) - split_offset;
2294 if ((subtotal + remainder) <= protgrp_bytes) {
2295 /* we can use this whole buffer */
2296 dma_len = remainder;
2299 if ((subtotal + remainder) == protgrp_bytes)
2302 /* must split this buffer with next prot grp */
2303 dma_len = protgrp_bytes - subtotal;
2304 split_offset += dma_len;
2307 subtotal += dma_len;
2309 sgl->addr_lo = cpu_to_le32(putPaddrLow(dataphysaddr));
2310 sgl->addr_hi = cpu_to_le32(putPaddrHigh(dataphysaddr));
2311 bf_set(lpfc_sli4_sge_last, sgl, 0);
2312 bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
2313 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA);
2315 sgl->sge_len = cpu_to_le32(dma_len);
2316 dma_offset += dma_len;
2324 /* Move to the next s/g segment if possible */
2325 sgde = sg_next(sgde);
2328 if (protgroup_offset) {
2329 /* update the reference tag */
2330 reftag += protgrp_blks;
2336 if (curr_prot == protcnt) {
2337 bf_set(lpfc_sli4_sge_last, sgl, 1);
2339 } else if (curr_prot < protcnt) {
2340 /* advance to next prot buffer */
2341 sgpe = sg_next(sgpe);
2344 /* update the reference tag */
2345 reftag += protgrp_blks;
2347 /* if we're here, we have a bug */
2348 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
2349 "9085 BLKGRD: bug in %s\n", __func__);
2360 * lpfc_prot_group_type - Get prtotection group type of SCSI command
2361 * @phba: The Hba for which this call is being executed.
2362 * @sc: pointer to scsi command we're working on
2364 * Given a SCSI command that supports DIF, determine composition of protection
2365 * groups involved in setting up buffer lists
2367 * Returns: Protection group type (with or without DIF)
2371 lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc)
2373 int ret = LPFC_PG_TYPE_INVALID;
2374 unsigned char op = scsi_get_prot_op(sc);
2377 case SCSI_PROT_READ_STRIP:
2378 case SCSI_PROT_WRITE_INSERT:
2379 ret = LPFC_PG_TYPE_NO_DIF;
2381 case SCSI_PROT_READ_INSERT:
2382 case SCSI_PROT_WRITE_STRIP:
2383 case SCSI_PROT_READ_PASS:
2384 case SCSI_PROT_WRITE_PASS:
2385 ret = LPFC_PG_TYPE_DIF_BUF;
2389 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
2390 "9021 Unsupported protection op:%d\n",
2398 * lpfc_bg_scsi_adjust_dl - Adjust SCSI data length for BlockGuard
2399 * @phba: The Hba for which this call is being executed.
2400 * @lpfc_cmd: The scsi buffer which is going to be adjusted.
2402 * Adjust the data length to account for how much data
2403 * is actually on the wire.
2405 * returns the adjusted data length
2408 lpfc_bg_scsi_adjust_dl(struct lpfc_hba *phba,
2409 struct lpfc_scsi_buf *lpfc_cmd)
2411 struct scsi_cmnd *sc = lpfc_cmd->pCmd;
2414 fcpdl = scsi_bufflen(sc);
2416 /* Check if there is protection data on the wire */
2417 if (sc->sc_data_direction == DMA_FROM_DEVICE) {
2418 /* Read check for protection data */
2419 if (scsi_get_prot_op(sc) == SCSI_PROT_READ_INSERT)
2423 /* Write check for protection data */
2424 if (scsi_get_prot_op(sc) == SCSI_PROT_WRITE_STRIP)
2429 * If we are in DIF Type 1 mode every data block has a 8 byte
2430 * DIF (trailer) attached to it. Must ajust FCP data length
2431 * to account for the protection data.
2433 fcpdl += (fcpdl / lpfc_cmd_blksize(sc)) * 8;
2439 * lpfc_bg_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
2440 * @phba: The Hba for which this call is being executed.
2441 * @lpfc_cmd: The scsi buffer which is going to be prep'ed.
2443 * This is the protection/DIF aware version of
2444 * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the
2445 * two functions eventually, but for now, it's here
2448 lpfc_bg_scsi_prep_dma_buf_s3(struct lpfc_hba *phba,
2449 struct lpfc_scsi_buf *lpfc_cmd)
2451 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
2452 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
2453 struct ulp_bde64 *bpl = lpfc_cmd->dma_sgl;
2454 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
2455 uint32_t num_bde = 0;
2456 int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction;
2457 int prot_group_type = 0;
2459 struct lpfc_vport *vport = phba->pport;
2462 * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd
2463 * fcp_rsp regions to the first data bde entry
2466 if (scsi_sg_count(scsi_cmnd)) {
2468 * The driver stores the segment count returned from pci_map_sg
2469 * because this a count of dma-mappings used to map the use_sg
2470 * pages. They are not guaranteed to be the same for those
2471 * architectures that implement an IOMMU.
2473 datasegcnt = dma_map_sg(&phba->pcidev->dev,
2474 scsi_sglist(scsi_cmnd),
2475 scsi_sg_count(scsi_cmnd), datadir);
2476 if (unlikely(!datasegcnt))
2479 lpfc_cmd->seg_cnt = datasegcnt;
2481 /* First check if data segment count from SCSI Layer is good */
2482 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt)
2485 prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd);
2487 switch (prot_group_type) {
2488 case LPFC_PG_TYPE_NO_DIF:
2490 /* Here we need to add a PDE5 and PDE6 to the count */
2491 if ((lpfc_cmd->seg_cnt + 2) > phba->cfg_total_seg_cnt)
2494 num_bde = lpfc_bg_setup_bpl(phba, scsi_cmnd, bpl,
2496 /* we should have 2 or more entries in buffer list */
2501 case LPFC_PG_TYPE_DIF_BUF:
2503 * This type indicates that protection buffers are
2504 * passed to the driver, so that needs to be prepared
2507 protsegcnt = dma_map_sg(&phba->pcidev->dev,
2508 scsi_prot_sglist(scsi_cmnd),
2509 scsi_prot_sg_count(scsi_cmnd), datadir);
2510 if (unlikely(!protsegcnt)) {
2511 scsi_dma_unmap(scsi_cmnd);
2515 lpfc_cmd->prot_seg_cnt = protsegcnt;
2518 * There is a minimun of 4 BPLs used for every
2519 * protection data segment.
2521 if ((lpfc_cmd->prot_seg_cnt * 4) >
2522 (phba->cfg_total_seg_cnt - 2))
2525 num_bde = lpfc_bg_setup_bpl_prot(phba, scsi_cmnd, bpl,
2526 datasegcnt, protsegcnt);
2527 /* we should have 3 or more entries in buffer list */
2528 if ((num_bde < 3) ||
2529 (num_bde > phba->cfg_total_seg_cnt))
2533 case LPFC_PG_TYPE_INVALID:
2535 scsi_dma_unmap(scsi_cmnd);
2536 lpfc_cmd->seg_cnt = 0;
2538 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
2539 "9022 Unexpected protection group %i\n",
2546 * Finish initializing those IOCB fields that are dependent on the
2547 * scsi_cmnd request_buffer. Note that the bdeSize is explicitly
2548 * reinitialized since all iocb memory resources are used many times
2549 * for transmit, receive, and continuation bpl's.
2551 iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
2552 iocb_cmd->un.fcpi64.bdl.bdeSize += (num_bde * sizeof(struct ulp_bde64));
2553 iocb_cmd->ulpBdeCount = 1;
2554 iocb_cmd->ulpLe = 1;
2556 fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd);
2557 fcp_cmnd->fcpDl = be32_to_cpu(fcpdl);
2560 * Due to difference in data length between DIF/non-DIF paths,
2561 * we need to set word 4 of IOCB here
2563 iocb_cmd->un.fcpi.fcpi_parm = fcpdl;
2566 * For First burst, we may need to adjust the initial transfer
2569 if (iocb_cmd->un.fcpi.fcpi_XRdy &&
2570 (fcpdl < vport->cfg_first_burst_size))
2571 iocb_cmd->un.fcpi.fcpi_XRdy = fcpdl;
2575 if (lpfc_cmd->seg_cnt)
2576 scsi_dma_unmap(scsi_cmnd);
2577 if (lpfc_cmd->prot_seg_cnt)
2578 dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd),
2579 scsi_prot_sg_count(scsi_cmnd),
2580 scsi_cmnd->sc_data_direction);
2582 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
2583 "9023 Cannot setup S/G List for HBA"
2584 "IO segs %d/%d BPL %d SCSI %d: %d %d\n",
2585 lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt,
2586 phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt,
2587 prot_group_type, num_bde);
2589 lpfc_cmd->seg_cnt = 0;
2590 lpfc_cmd->prot_seg_cnt = 0;
2595 * This function calcuates the T10 DIF guard tag
2596 * on the specified data using a CRC algorithmn
2600 lpfc_bg_crc(uint8_t *data, int count)
2605 crc = crc_t10dif(data, count);
2606 x = cpu_to_be16(crc);
2611 * This function calcuates the T10 DIF guard tag
2612 * on the specified data using a CSUM algorithmn
2613 * using ip_compute_csum.
2616 lpfc_bg_csum(uint8_t *data, int count)
2620 ret = ip_compute_csum(data, count);
2625 * This function examines the protection data to try to determine
2626 * what type of T10-DIF error occurred.
2629 lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
2631 struct scatterlist *sgpe; /* s/g prot entry */
2632 struct scatterlist *sgde; /* s/g data entry */
2633 struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
2634 struct scsi_dif_tuple *src = NULL;
2635 uint8_t *data_src = NULL;
2637 uint16_t start_app_tag, app_tag;
2638 uint32_t start_ref_tag, ref_tag;
2639 int prot, protsegcnt;
2640 int err_type, len, data_len;
2641 int chk_ref, chk_app, chk_guard;
2645 err_type = BGS_GUARD_ERR_MASK;
2649 /* First check to see if there is protection data to examine */
2650 prot = scsi_get_prot_op(cmd);
2651 if ((prot == SCSI_PROT_READ_STRIP) ||
2652 (prot == SCSI_PROT_WRITE_INSERT) ||
2653 (prot == SCSI_PROT_NORMAL))
2656 /* Currently the driver just supports ref_tag and guard_tag checking */
2661 /* Setup a ptr to the protection data provided by the SCSI host */
2662 sgpe = scsi_prot_sglist(cmd);
2663 protsegcnt = lpfc_cmd->prot_seg_cnt;
2665 if (sgpe && protsegcnt) {
2668 * We will only try to verify guard tag if the segment
2669 * data length is a multiple of the blksize.
2671 sgde = scsi_sglist(cmd);
2672 blksize = lpfc_cmd_blksize(cmd);
2673 data_src = (uint8_t *)sg_virt(sgde);
2674 data_len = sgde->length;
2675 if ((data_len & (blksize - 1)) == 0)
2678 src = (struct scsi_dif_tuple *)sg_virt(sgpe);
2679 start_ref_tag = (uint32_t)scsi_get_lba(cmd); /* Truncate LBA */
2680 start_app_tag = src->app_tag;
2682 while (src && protsegcnt) {
2686 * First check to see if a protection data
2689 if ((src->ref_tag == T10_PI_REF_ESCAPE) ||
2690 (src->app_tag == T10_PI_APP_ESCAPE)) {
2695 /* First Guard Tag checking */
2697 guard_tag = src->guard_tag;
2698 if (lpfc_cmd_guard_csum(cmd))
2699 sum = lpfc_bg_csum(data_src,
2702 sum = lpfc_bg_crc(data_src,
2704 if ((guard_tag != sum)) {
2705 err_type = BGS_GUARD_ERR_MASK;
2710 /* Reference Tag checking */
2711 ref_tag = be32_to_cpu(src->ref_tag);
2712 if (chk_ref && (ref_tag != start_ref_tag)) {
2713 err_type = BGS_REFTAG_ERR_MASK;
2718 /* App Tag checking */
2719 app_tag = src->app_tag;
2720 if (chk_app && (app_tag != start_app_tag)) {
2721 err_type = BGS_APPTAG_ERR_MASK;
2725 len -= sizeof(struct scsi_dif_tuple);
2730 data_src += blksize;
2731 data_len -= blksize;
2734 * Are we at the end of the Data segment?
2735 * The data segment is only used for Guard
2738 if (chk_guard && (data_len == 0)) {
2740 sgde = sg_next(sgde);
2744 data_src = (uint8_t *)sg_virt(sgde);
2745 data_len = sgde->length;
2746 if ((data_len & (blksize - 1)) == 0)
2751 /* Goto the next Protection data segment */
2752 sgpe = sg_next(sgpe);
2754 src = (struct scsi_dif_tuple *)sg_virt(sgpe);
2763 if (err_type == BGS_GUARD_ERR_MASK) {
2764 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
2766 cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
2767 SAM_STAT_CHECK_CONDITION;
2768 phba->bg_guard_err_cnt++;
2769 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
2770 "9069 BLKGRD: LBA %lx grd_tag error %x != %x\n",
2771 (unsigned long)scsi_get_lba(cmd),
2774 } else if (err_type == BGS_REFTAG_ERR_MASK) {
2775 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
2777 cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
2778 SAM_STAT_CHECK_CONDITION;
2780 phba->bg_reftag_err_cnt++;
2781 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
2782 "9066 BLKGRD: LBA %lx ref_tag error %x != %x\n",
2783 (unsigned long)scsi_get_lba(cmd),
2784 ref_tag, start_ref_tag);
2786 } else if (err_type == BGS_APPTAG_ERR_MASK) {
2787 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
2789 cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
2790 SAM_STAT_CHECK_CONDITION;
2792 phba->bg_apptag_err_cnt++;
2793 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
2794 "9041 BLKGRD: LBA %lx app_tag error %x != %x\n",
2795 (unsigned long)scsi_get_lba(cmd),
2796 app_tag, start_app_tag);
2802 * This function checks for BlockGuard errors detected by
2803 * the HBA. In case of errors, the ASC/ASCQ fields in the
2804 * sense buffer will be set accordingly, paired with
2805 * ILLEGAL_REQUEST to signal to the kernel that the HBA
2806 * detected corruption.
2809 * 0 - No error found
2810 * 1 - BlockGuard error found
2811 * -1 - Internal error (bad profile, ...etc)
2814 lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd,
2815 struct lpfc_iocbq *pIocbOut)
2817 struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
2818 struct sli3_bg_fields *bgf = &pIocbOut->iocb.unsli3.sli3_bg;
2820 uint32_t bghm = bgf->bghm;
2821 uint32_t bgstat = bgf->bgstat;
2822 uint64_t failing_sector = 0;
2824 spin_lock(&_dump_buf_lock);
2825 if (!_dump_buf_done) {
2826 lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9070 BLKGRD: Saving"
2827 " Data for %u blocks to debugfs\n",
2828 (cmd->cmnd[7] << 8 | cmd->cmnd[8]));
2829 lpfc_debug_save_data(phba, cmd);
2831 /* If we have a prot sgl, save the DIF buffer */
2832 if (lpfc_prot_group_type(phba, cmd) ==
2833 LPFC_PG_TYPE_DIF_BUF) {
2834 lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9071 BLKGRD: "
2835 "Saving DIF for %u blocks to debugfs\n",
2836 (cmd->cmnd[7] << 8 | cmd->cmnd[8]));
2837 lpfc_debug_save_dif(phba, cmd);
2842 spin_unlock(&_dump_buf_lock);
2844 if (lpfc_bgs_get_invalid_prof(bgstat)) {
2845 cmd->result = DID_ERROR << 16;
2846 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
2847 "9072 BLKGRD: Invalid BG Profile in cmd"
2848 " 0x%x lba 0x%llx blk cnt 0x%x "
2849 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
2850 (unsigned long long)scsi_get_lba(cmd),
2851 blk_rq_sectors(cmd->request), bgstat, bghm);
2856 if (lpfc_bgs_get_uninit_dif_block(bgstat)) {
2857 cmd->result = DID_ERROR << 16;
2858 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
2859 "9073 BLKGRD: Invalid BG PDIF Block in cmd"
2860 " 0x%x lba 0x%llx blk cnt 0x%x "
2861 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
2862 (unsigned long long)scsi_get_lba(cmd),
2863 blk_rq_sectors(cmd->request), bgstat, bghm);
2868 if (lpfc_bgs_get_guard_err(bgstat)) {
2871 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
2873 cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
2874 SAM_STAT_CHECK_CONDITION;
2875 phba->bg_guard_err_cnt++;
2876 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
2877 "9055 BLKGRD: Guard Tag error in cmd"
2878 " 0x%x lba 0x%llx blk cnt 0x%x "
2879 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
2880 (unsigned long long)scsi_get_lba(cmd),
2881 blk_rq_sectors(cmd->request), bgstat, bghm);
2884 if (lpfc_bgs_get_reftag_err(bgstat)) {
2887 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
2889 cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
2890 SAM_STAT_CHECK_CONDITION;
2892 phba->bg_reftag_err_cnt++;
2893 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
2894 "9056 BLKGRD: Ref Tag error in cmd"
2895 " 0x%x lba 0x%llx blk cnt 0x%x "
2896 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
2897 (unsigned long long)scsi_get_lba(cmd),
2898 blk_rq_sectors(cmd->request), bgstat, bghm);
2901 if (lpfc_bgs_get_apptag_err(bgstat)) {
2904 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
2906 cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
2907 SAM_STAT_CHECK_CONDITION;
2909 phba->bg_apptag_err_cnt++;
2910 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
2911 "9061 BLKGRD: App Tag error in cmd"
2912 " 0x%x lba 0x%llx blk cnt 0x%x "
2913 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
2914 (unsigned long long)scsi_get_lba(cmd),
2915 blk_rq_sectors(cmd->request), bgstat, bghm);
2918 if (lpfc_bgs_get_hi_water_mark_present(bgstat)) {
2920 * setup sense data descriptor 0 per SPC-4 as an information
2921 * field, and put the failing LBA in it.
2922 * This code assumes there was also a guard/app/ref tag error
2925 cmd->sense_buffer[7] = 0xc; /* Additional sense length */
2926 cmd->sense_buffer[8] = 0; /* Information descriptor type */
2927 cmd->sense_buffer[9] = 0xa; /* Additional descriptor length */
2928 cmd->sense_buffer[10] = 0x80; /* Validity bit */
2930 /* bghm is a "on the wire" FC frame based count */
2931 switch (scsi_get_prot_op(cmd)) {
2932 case SCSI_PROT_READ_INSERT:
2933 case SCSI_PROT_WRITE_STRIP:
2934 bghm /= cmd->device->sector_size;
2936 case SCSI_PROT_READ_STRIP:
2937 case SCSI_PROT_WRITE_INSERT:
2938 case SCSI_PROT_READ_PASS:
2939 case SCSI_PROT_WRITE_PASS:
2940 bghm /= (cmd->device->sector_size +
2941 sizeof(struct scsi_dif_tuple));
2945 failing_sector = scsi_get_lba(cmd);
2946 failing_sector += bghm;
2948 /* Descriptor Information */
2949 put_unaligned_be64(failing_sector, &cmd->sense_buffer[12]);
2953 /* No error was reported - problem in FW? */
2954 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
2955 "9057 BLKGRD: Unknown error in cmd"
2956 " 0x%x lba 0x%llx blk cnt 0x%x "
2957 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
2958 (unsigned long long)scsi_get_lba(cmd),
2959 blk_rq_sectors(cmd->request), bgstat, bghm);
2961 /* Calcuate what type of error it was */
2962 lpfc_calc_bg_err(phba, lpfc_cmd);
2969 * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
2970 * @phba: The Hba for which this call is being executed.
2971 * @lpfc_cmd: The scsi buffer which is going to be mapped.
2973 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
2974 * field of @lpfc_cmd for device with SLI-4 interface spec.
2981 lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
2983 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
2984 struct scatterlist *sgel = NULL;
2985 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
2986 struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
2987 struct sli4_sge *first_data_sgl;
2988 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
2989 dma_addr_t physaddr;
2990 uint32_t num_bde = 0;
2992 uint32_t dma_offset = 0;
2994 struct ulp_bde64 *bde;
2997 * There are three possibilities here - use scatter-gather segment, use
2998 * the single mapping, or neither. Start the lpfc command prep by
2999 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
3002 if (scsi_sg_count(scsi_cmnd)) {
3004 * The driver stores the segment count returned from pci_map_sg
3005 * because this a count of dma-mappings used to map the use_sg
3006 * pages. They are not guaranteed to be the same for those
3007 * architectures that implement an IOMMU.
3010 nseg = scsi_dma_map(scsi_cmnd);
3011 if (unlikely(nseg <= 0))
3014 /* clear the last flag in the fcp_rsp map entry */
3015 sgl->word2 = le32_to_cpu(sgl->word2);
3016 bf_set(lpfc_sli4_sge_last, sgl, 0);
3017 sgl->word2 = cpu_to_le32(sgl->word2);
3019 first_data_sgl = sgl;
3020 lpfc_cmd->seg_cnt = nseg;
3021 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
3022 lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9074 BLKGRD:"
3023 " %s: Too many sg segments from "
3024 "dma_map_sg. Config %d, seg_cnt %d\n",
3025 __func__, phba->cfg_sg_seg_cnt,
3027 lpfc_cmd->seg_cnt = 0;
3028 scsi_dma_unmap(scsi_cmnd);
3033 * The driver established a maximum scatter-gather segment count
3034 * during probe that limits the number of sg elements in any
3035 * single scsi command. Just run through the seg_cnt and format
3037 * When using SLI-3 the driver will try to fit all the BDEs into
3038 * the IOCB. If it can't then the BDEs get added to a BPL as it
3039 * does for SLI-2 mode.
3041 scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) {
3042 physaddr = sg_dma_address(sgel);
3043 dma_len = sg_dma_len(sgel);
3044 sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr));
3045 sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr));
3046 sgl->word2 = le32_to_cpu(sgl->word2);
3047 if ((num_bde + 1) == nseg)
3048 bf_set(lpfc_sli4_sge_last, sgl, 1);
3050 bf_set(lpfc_sli4_sge_last, sgl, 0);
3051 bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
3052 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA);
3053 sgl->word2 = cpu_to_le32(sgl->word2);
3054 sgl->sge_len = cpu_to_le32(dma_len);
3055 dma_offset += dma_len;
3059 * Setup the first Payload BDE. For FCoE we just key off
3060 * Performance Hints, for FC we use lpfc_enable_pbde.
3061 * We populate words 13-15 of IOCB/WQE.
3063 if ((phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) ||
3064 phba->cfg_enable_pbde) {
3065 bde = (struct ulp_bde64 *)
3066 &(iocb_cmd->unsli3.sli3Words[5]);
3067 bde->addrLow = first_data_sgl->addr_lo;
3068 bde->addrHigh = first_data_sgl->addr_hi;
3069 bde->tus.f.bdeSize =
3070 le32_to_cpu(first_data_sgl->sge_len);
3071 bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
3072 bde->tus.w = cpu_to_le32(bde->tus.w);
3076 /* clear the last flag in the fcp_rsp map entry */
3077 sgl->word2 = le32_to_cpu(sgl->word2);
3078 bf_set(lpfc_sli4_sge_last, sgl, 1);
3079 sgl->word2 = cpu_to_le32(sgl->word2);
3081 if ((phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) ||
3082 phba->cfg_enable_pbde) {
3083 bde = (struct ulp_bde64 *)
3084 &(iocb_cmd->unsli3.sli3Words[5]);
3085 memset(bde, 0, (sizeof(uint32_t) * 3));
3090 * Finish initializing those IOCB fields that are dependent on the
3091 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
3092 * explicitly reinitialized.
3093 * all iocb memory resources are reused.
3095 fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd));
3098 * Due to difference in data length between DIF/non-DIF paths,
3099 * we need to set word 4 of IOCB here
3101 iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd);
3104 * If the OAS driver feature is enabled and the lun is enabled for
3105 * OAS, set the oas iocb related flags.
3107 if ((phba->cfg_fof) && ((struct lpfc_device_data *)
3108 scsi_cmnd->device->hostdata)->oas_enabled) {
3109 lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF);
3110 lpfc_cmd->cur_iocbq.priority = ((struct lpfc_device_data *)
3111 scsi_cmnd->device->hostdata)->priority;
3117 * lpfc_bg_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
3118 * @phba: The Hba for which this call is being executed.
3119 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3121 * This is the protection/DIF aware version of
3122 * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the
3123 * two functions eventually, but for now, it's here
3126 lpfc_bg_scsi_prep_dma_buf_s4(struct lpfc_hba *phba,
3127 struct lpfc_scsi_buf *lpfc_cmd)
3129 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
3130 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
3131 struct sli4_sge *sgl = (struct sli4_sge *)(lpfc_cmd->dma_sgl);
3132 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
3133 uint32_t num_sge = 0;
3134 int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction;
3135 int prot_group_type = 0;
3137 struct lpfc_vport *vport = phba->pport;
3140 * Start the lpfc command prep by bumping the sgl beyond fcp_cmnd
3141 * fcp_rsp regions to the first data sge entry
3143 if (scsi_sg_count(scsi_cmnd)) {
3145 * The driver stores the segment count returned from pci_map_sg
3146 * because this a count of dma-mappings used to map the use_sg
3147 * pages. They are not guaranteed to be the same for those
3148 * architectures that implement an IOMMU.
3150 datasegcnt = dma_map_sg(&phba->pcidev->dev,
3151 scsi_sglist(scsi_cmnd),
3152 scsi_sg_count(scsi_cmnd), datadir);
3153 if (unlikely(!datasegcnt))
3157 /* clear the last flag in the fcp_rsp map entry */
3158 sgl->word2 = le32_to_cpu(sgl->word2);
3159 bf_set(lpfc_sli4_sge_last, sgl, 0);
3160 sgl->word2 = cpu_to_le32(sgl->word2);
3163 lpfc_cmd->seg_cnt = datasegcnt;
3165 /* First check if data segment count from SCSI Layer is good */
3166 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt)
3169 prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd);
3171 switch (prot_group_type) {
3172 case LPFC_PG_TYPE_NO_DIF:
3173 /* Here we need to add a DISEED to the count */
3174 if ((lpfc_cmd->seg_cnt + 1) > phba->cfg_total_seg_cnt)
3177 num_sge = lpfc_bg_setup_sgl(phba, scsi_cmnd, sgl,
3180 /* we should have 2 or more entries in buffer list */
3185 case LPFC_PG_TYPE_DIF_BUF:
3187 * This type indicates that protection buffers are
3188 * passed to the driver, so that needs to be prepared
3191 protsegcnt = dma_map_sg(&phba->pcidev->dev,
3192 scsi_prot_sglist(scsi_cmnd),
3193 scsi_prot_sg_count(scsi_cmnd), datadir);
3194 if (unlikely(!protsegcnt)) {
3195 scsi_dma_unmap(scsi_cmnd);
3199 lpfc_cmd->prot_seg_cnt = protsegcnt;
3201 * There is a minimun of 3 SGEs used for every
3202 * protection data segment.
3204 if ((lpfc_cmd->prot_seg_cnt * 3) >
3205 (phba->cfg_total_seg_cnt - 2))
3208 num_sge = lpfc_bg_setup_sgl_prot(phba, scsi_cmnd, sgl,
3209 datasegcnt, protsegcnt);
3211 /* we should have 3 or more entries in buffer list */
3212 if ((num_sge < 3) ||
3213 (num_sge > phba->cfg_total_seg_cnt))
3217 case LPFC_PG_TYPE_INVALID:
3219 scsi_dma_unmap(scsi_cmnd);
3220 lpfc_cmd->seg_cnt = 0;
3222 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
3223 "9083 Unexpected protection group %i\n",
3229 switch (scsi_get_prot_op(scsi_cmnd)) {
3230 case SCSI_PROT_WRITE_STRIP:
3231 case SCSI_PROT_READ_STRIP:
3232 lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_STRIP;
3234 case SCSI_PROT_WRITE_INSERT:
3235 case SCSI_PROT_READ_INSERT:
3236 lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_INSERT;
3238 case SCSI_PROT_WRITE_PASS:
3239 case SCSI_PROT_READ_PASS:
3240 lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_PASS;
3244 fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd);
3245 fcp_cmnd->fcpDl = be32_to_cpu(fcpdl);
3248 * Due to difference in data length between DIF/non-DIF paths,
3249 * we need to set word 4 of IOCB here
3251 iocb_cmd->un.fcpi.fcpi_parm = fcpdl;
3254 * For First burst, we may need to adjust the initial transfer
3257 if (iocb_cmd->un.fcpi.fcpi_XRdy &&
3258 (fcpdl < vport->cfg_first_burst_size))
3259 iocb_cmd->un.fcpi.fcpi_XRdy = fcpdl;
3262 * If the OAS driver feature is enabled and the lun is enabled for
3263 * OAS, set the oas iocb related flags.
3265 if ((phba->cfg_fof) && ((struct lpfc_device_data *)
3266 scsi_cmnd->device->hostdata)->oas_enabled)
3267 lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF);
3271 if (lpfc_cmd->seg_cnt)
3272 scsi_dma_unmap(scsi_cmnd);
3273 if (lpfc_cmd->prot_seg_cnt)
3274 dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd),
3275 scsi_prot_sg_count(scsi_cmnd),
3276 scsi_cmnd->sc_data_direction);
3278 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
3279 "9084 Cannot setup S/G List for HBA"
3280 "IO segs %d/%d SGL %d SCSI %d: %d %d\n",
3281 lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt,
3282 phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt,
3283 prot_group_type, num_sge);
3285 lpfc_cmd->seg_cnt = 0;
3286 lpfc_cmd->prot_seg_cnt = 0;
3291 * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
3292 * @phba: The Hba for which this call is being executed.
3293 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3295 * This routine wraps the actual DMA mapping function pointer from the
3303 lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
3305 return phba->lpfc_scsi_prep_dma_buf(phba, lpfc_cmd);
3309 * lpfc_bg_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
3311 * @phba: The Hba for which this call is being executed.
3312 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3314 * This routine wraps the actual DMA mapping function pointer from the
3322 lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
3324 return phba->lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd);
3328 * lpfc_send_scsi_error_event - Posts an event when there is SCSI error
3329 * @phba: Pointer to hba context object.
3330 * @vport: Pointer to vport object.
3331 * @lpfc_cmd: Pointer to lpfc scsi command which reported the error.
3332 * @rsp_iocb: Pointer to response iocb object which reported error.
3334 * This function posts an event when there is a SCSI command reporting
3335 * error from the scsi device.
3338 lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport,
3339 struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_iocbq *rsp_iocb) {
3340 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
3341 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
3342 uint32_t resp_info = fcprsp->rspStatus2;
3343 uint32_t scsi_status = fcprsp->rspStatus3;
3344 uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm;
3345 struct lpfc_fast_path_event *fast_path_evt = NULL;
3346 struct lpfc_nodelist *pnode = lpfc_cmd->rdata->pnode;
3347 unsigned long flags;
3349 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
3352 /* If there is queuefull or busy condition send a scsi event */
3353 if ((cmnd->result == SAM_STAT_TASK_SET_FULL) ||
3354 (cmnd->result == SAM_STAT_BUSY)) {
3355 fast_path_evt = lpfc_alloc_fast_evt(phba);
3358 fast_path_evt->un.scsi_evt.event_type =
3360 fast_path_evt->un.scsi_evt.subcategory =
3361 (cmnd->result == SAM_STAT_TASK_SET_FULL) ?
3362 LPFC_EVENT_QFULL : LPFC_EVENT_DEVBSY;
3363 fast_path_evt->un.scsi_evt.lun = cmnd->device->lun;
3364 memcpy(&fast_path_evt->un.scsi_evt.wwpn,
3365 &pnode->nlp_portname, sizeof(struct lpfc_name));
3366 memcpy(&fast_path_evt->un.scsi_evt.wwnn,
3367 &pnode->nlp_nodename, sizeof(struct lpfc_name));
3368 } else if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen &&
3369 ((cmnd->cmnd[0] == READ_10) || (cmnd->cmnd[0] == WRITE_10))) {
3370 fast_path_evt = lpfc_alloc_fast_evt(phba);
3373 fast_path_evt->un.check_cond_evt.scsi_event.event_type =
3375 fast_path_evt->un.check_cond_evt.scsi_event.subcategory =
3376 LPFC_EVENT_CHECK_COND;
3377 fast_path_evt->un.check_cond_evt.scsi_event.lun =
3379 memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwpn,
3380 &pnode->nlp_portname, sizeof(struct lpfc_name));
3381 memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwnn,
3382 &pnode->nlp_nodename, sizeof(struct lpfc_name));
3383 fast_path_evt->un.check_cond_evt.sense_key =
3384 cmnd->sense_buffer[2] & 0xf;
3385 fast_path_evt->un.check_cond_evt.asc = cmnd->sense_buffer[12];
3386 fast_path_evt->un.check_cond_evt.ascq = cmnd->sense_buffer[13];
3387 } else if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) &&
3389 ((be32_to_cpu(fcprsp->rspResId) != fcpi_parm) ||
3390 ((scsi_status == SAM_STAT_GOOD) &&
3391 !(resp_info & (RESID_UNDER | RESID_OVER))))) {
3393 * If status is good or resid does not match with fcp_param and
3394 * there is valid fcpi_parm, then there is a read_check error
3396 fast_path_evt = lpfc_alloc_fast_evt(phba);
3399 fast_path_evt->un.read_check_error.header.event_type =
3400 FC_REG_FABRIC_EVENT;
3401 fast_path_evt->un.read_check_error.header.subcategory =
3402 LPFC_EVENT_FCPRDCHKERR;
3403 memcpy(&fast_path_evt->un.read_check_error.header.wwpn,
3404 &pnode->nlp_portname, sizeof(struct lpfc_name));
3405 memcpy(&fast_path_evt->un.read_check_error.header.wwnn,
3406 &pnode->nlp_nodename, sizeof(struct lpfc_name));
3407 fast_path_evt->un.read_check_error.lun = cmnd->device->lun;
3408 fast_path_evt->un.read_check_error.opcode = cmnd->cmnd[0];
3409 fast_path_evt->un.read_check_error.fcpiparam =
3414 fast_path_evt->vport = vport;
3415 spin_lock_irqsave(&phba->hbalock, flags);
3416 list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list);
3417 spin_unlock_irqrestore(&phba->hbalock, flags);
3418 lpfc_worker_wake_up(phba);
3423 * lpfc_scsi_unprep_dma_buf - Un-map DMA mapping of SG-list for dev
3424 * @phba: The HBA for which this call is being executed.
3425 * @psb: The scsi buffer which is going to be un-mapped.
3427 * This routine does DMA un-mapping of scatter gather list of scsi command
3428 * field of @lpfc_cmd for device with SLI-3 interface spec.
3431 lpfc_scsi_unprep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
3434 * There are only two special cases to consider. (1) the scsi command
3435 * requested scatter-gather usage or (2) the scsi command allocated
3436 * a request buffer, but did not request use_sg. There is a third
3437 * case, but it does not require resource deallocation.
3439 if (psb->seg_cnt > 0)
3440 scsi_dma_unmap(psb->pCmd);
3441 if (psb->prot_seg_cnt > 0)
3442 dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(psb->pCmd),
3443 scsi_prot_sg_count(psb->pCmd),
3444 psb->pCmd->sc_data_direction);
3448 * lpfc_handler_fcp_err - FCP response handler
3449 * @vport: The virtual port for which this call is being executed.
3450 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
3451 * @rsp_iocb: The response IOCB which contains FCP error.
3453 * This routine is called to process response IOCB with status field
3454 * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command
3455 * based upon SCSI and FCP error.
3458 lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
3459 struct lpfc_iocbq *rsp_iocb)
3461 struct lpfc_hba *phba = vport->phba;
3462 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
3463 struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd;
3464 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
3465 uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm;
3466 uint32_t resp_info = fcprsp->rspStatus2;
3467 uint32_t scsi_status = fcprsp->rspStatus3;
3469 uint32_t host_status = DID_OK;
3470 uint32_t rsplen = 0;
3472 uint32_t logit = LOG_FCP | LOG_FCP_ERROR;
3476 * If this is a task management command, there is no
3477 * scsi packet associated with this lpfc_cmd. The driver
3480 if (fcpcmd->fcpCntl2) {
3485 if (resp_info & RSP_LEN_VALID) {
3486 rsplen = be32_to_cpu(fcprsp->rspRspLen);
3487 if (rsplen != 0 && rsplen != 4 && rsplen != 8) {
3488 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3489 "2719 Invalid response length: "
3490 "tgt x%x lun x%llx cmnd x%x rsplen x%x\n",
3492 cmnd->device->lun, cmnd->cmnd[0],
3494 host_status = DID_ERROR;
3497 if (fcprsp->rspInfo3 != RSP_NO_FAILURE) {
3498 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3499 "2757 Protocol failure detected during "
3500 "processing of FCP I/O op: "
3501 "tgt x%x lun x%llx cmnd x%x rspInfo3 x%x\n",
3503 cmnd->device->lun, cmnd->cmnd[0],
3505 host_status = DID_ERROR;
3510 if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) {
3511 uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen);
3512 if (snslen > SCSI_SENSE_BUFFERSIZE)
3513 snslen = SCSI_SENSE_BUFFERSIZE;
3515 if (resp_info & RSP_LEN_VALID)
3516 rsplen = be32_to_cpu(fcprsp->rspRspLen);
3517 memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen);
3519 lp = (uint32_t *)cmnd->sense_buffer;
3521 /* special handling for under run conditions */
3522 if (!scsi_status && (resp_info & RESID_UNDER)) {
3523 /* don't log under runs if fcp set... */
3524 if (vport->cfg_log_verbose & LOG_FCP)
3525 logit = LOG_FCP_ERROR;
3526 /* unless operator says so */
3527 if (vport->cfg_log_verbose & LOG_FCP_UNDER)
3528 logit = LOG_FCP_UNDER;
3531 lpfc_printf_vlog(vport, KERN_WARNING, logit,
3532 "9024 FCP command x%x failed: x%x SNS x%x x%x "
3533 "Data: x%x x%x x%x x%x x%x\n",
3534 cmnd->cmnd[0], scsi_status,
3535 be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info,
3536 be32_to_cpu(fcprsp->rspResId),
3537 be32_to_cpu(fcprsp->rspSnsLen),
3538 be32_to_cpu(fcprsp->rspRspLen),
3541 scsi_set_resid(cmnd, 0);
3542 fcpDl = be32_to_cpu(fcpcmd->fcpDl);
3543 if (resp_info & RESID_UNDER) {
3544 scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId));
3546 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_UNDER,
3547 "9025 FCP Underrun, expected %d, "
3548 "residual %d Data: x%x x%x x%x\n",
3550 scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0],
3554 * If there is an under run, check if under run reported by
3555 * storage array is same as the under run reported by HBA.
3556 * If this is not same, there is a dropped frame.
3558 if (fcpi_parm && (scsi_get_resid(cmnd) != fcpi_parm)) {
3559 lpfc_printf_vlog(vport, KERN_WARNING,
3560 LOG_FCP | LOG_FCP_ERROR,
3561 "9026 FCP Read Check Error "
3562 "and Underrun Data: x%x x%x x%x x%x\n",
3564 scsi_get_resid(cmnd), fcpi_parm,
3566 scsi_set_resid(cmnd, scsi_bufflen(cmnd));
3567 host_status = DID_ERROR;
3570 * The cmnd->underflow is the minimum number of bytes that must
3571 * be transferred for this command. Provided a sense condition
3572 * is not present, make sure the actual amount transferred is at
3573 * least the underflow value or fail.
3575 if (!(resp_info & SNS_LEN_VALID) &&
3576 (scsi_status == SAM_STAT_GOOD) &&
3577 (scsi_bufflen(cmnd) - scsi_get_resid(cmnd)
3578 < cmnd->underflow)) {
3579 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
3580 "9027 FCP command x%x residual "
3581 "underrun converted to error "
3582 "Data: x%x x%x x%x\n",
3583 cmnd->cmnd[0], scsi_bufflen(cmnd),
3584 scsi_get_resid(cmnd), cmnd->underflow);
3585 host_status = DID_ERROR;
3587 } else if (resp_info & RESID_OVER) {
3588 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
3589 "9028 FCP command x%x residual overrun error. "
3590 "Data: x%x x%x\n", cmnd->cmnd[0],
3591 scsi_bufflen(cmnd), scsi_get_resid(cmnd));
3592 host_status = DID_ERROR;
3595 * Check SLI validation that all the transfer was actually done
3596 * (fcpi_parm should be zero). Apply check only to reads.
3598 } else if (fcpi_parm) {
3599 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR,
3600 "9029 FCP %s Check Error xri x%x Data: "
3601 "x%x x%x x%x x%x x%x\n",
3602 ((cmnd->sc_data_direction == DMA_FROM_DEVICE) ?
3604 ((phba->sli_rev == LPFC_SLI_REV4) ?
3605 lpfc_cmd->cur_iocbq.sli4_xritag :
3606 rsp_iocb->iocb.ulpContext),
3607 fcpDl, be32_to_cpu(fcprsp->rspResId),
3608 fcpi_parm, cmnd->cmnd[0], scsi_status);
3610 /* There is some issue with the LPe12000 that causes it
3611 * to miscalculate the fcpi_parm and falsely trip this
3612 * recovery logic. Detect this case and don't error when true.
3614 if (fcpi_parm > fcpDl)
3617 switch (scsi_status) {
3619 case SAM_STAT_CHECK_CONDITION:
3620 /* Fabric dropped a data frame. Fail any successful
3621 * command in which we detected dropped frames.
3622 * A status of good or some check conditions could
3623 * be considered a successful command.
3625 host_status = DID_ERROR;
3628 scsi_set_resid(cmnd, scsi_bufflen(cmnd));
3632 cmnd->result = host_status << 16 | scsi_status;
3633 lpfc_send_scsi_error_event(vport->phba, vport, lpfc_cmd, rsp_iocb);
3637 * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
3638 * @phba: Pointer to HBA context object.
3640 * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
3641 * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
3643 * If scsi-mq is enabled, get the default block layer mapping of software queues
3644 * to hardware queues. This information is saved in request tag.
3646 * Return: index into SLI4 fast-path FCP queue index.
3648 int lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba,
3649 struct lpfc_scsi_buf *lpfc_cmd)
3651 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
3652 struct lpfc_vector_map_info *cpup;
3658 tag = blk_mq_unique_tag(cmnd->request);
3659 hwq = blk_mq_unique_tag_to_hwq(tag);
3664 if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_CPU
3665 && phba->cfg_fcp_io_channel > 1) {
3666 cpu = lpfc_cmd->cpu;
3667 if (cpu < phba->sli4_hba.num_present_cpu) {
3668 cpup = phba->sli4_hba.cpu_map;
3670 return cpup->channel_id;
3673 chann = atomic_add_return(1, &phba->fcp_qidx);
3674 chann = chann % phba->cfg_fcp_io_channel;
3680 * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine
3681 * @phba: The Hba for which this call is being executed.
3682 * @pIocbIn: The command IOCBQ for the scsi cmnd.
3683 * @pIocbOut: The response IOCBQ for the scsi cmnd.
3685 * This routine assigns scsi command result by looking into response IOCB
3686 * status field appropriately. This routine handles QUEUE FULL condition as
3687 * well by ramping down device queue depth.
3690 lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
3691 struct lpfc_iocbq *pIocbOut)
3693 struct lpfc_scsi_buf *lpfc_cmd =
3694 (struct lpfc_scsi_buf *) pIocbIn->context1;
3695 struct lpfc_vport *vport = pIocbIn->vport;
3696 struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
3697 struct lpfc_nodelist *pnode = rdata->pnode;
3698 struct scsi_cmnd *cmd;
3699 unsigned long flags;
3700 struct lpfc_fast_path_event *fast_path_evt;
3701 struct Scsi_Host *shost;
3702 uint32_t logit = LOG_FCP;
3704 atomic_inc(&phba->fc4ScsiIoCmpls);
3706 /* Sanity check on return of outstanding command */
3707 cmd = lpfc_cmd->pCmd;
3710 shost = cmd->device->host;
3712 lpfc_cmd->result = (pIocbOut->iocb.un.ulpWord[4] & IOERR_PARAM_MASK);
3713 lpfc_cmd->status = pIocbOut->iocb.ulpStatus;
3714 /* pick up SLI4 exhange busy status from HBA */
3715 lpfc_cmd->exch_busy = pIocbOut->iocb_flag & LPFC_EXCHANGE_BUSY;
3717 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3718 if (lpfc_cmd->prot_data_type) {
3719 struct scsi_dif_tuple *src = NULL;
3721 src = (struct scsi_dif_tuple *)lpfc_cmd->prot_data_segment;
3723 * Used to restore any changes to protection
3724 * data for error injection.
3726 switch (lpfc_cmd->prot_data_type) {
3727 case LPFC_INJERR_REFTAG:
3729 lpfc_cmd->prot_data;
3731 case LPFC_INJERR_APPTAG:
3733 (uint16_t)lpfc_cmd->prot_data;
3735 case LPFC_INJERR_GUARD:
3737 (uint16_t)lpfc_cmd->prot_data;
3743 lpfc_cmd->prot_data = 0;
3744 lpfc_cmd->prot_data_type = 0;
3745 lpfc_cmd->prot_data_segment = NULL;
3749 if (lpfc_cmd->status) {
3750 if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT &&
3751 (lpfc_cmd->result & IOERR_DRVR_MASK))
3752 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
3753 else if (lpfc_cmd->status >= IOSTAT_CNT)
3754 lpfc_cmd->status = IOSTAT_DEFAULT;
3755 if (lpfc_cmd->status == IOSTAT_FCP_RSP_ERROR &&
3756 !lpfc_cmd->fcp_rsp->rspStatus3 &&
3757 (lpfc_cmd->fcp_rsp->rspStatus2 & RESID_UNDER) &&
3758 !(vport->cfg_log_verbose & LOG_FCP_UNDER))
3761 logit = LOG_FCP | LOG_FCP_UNDER;
3762 lpfc_printf_vlog(vport, KERN_WARNING, logit,
3763 "9030 FCP cmd x%x failed <%d/%lld> "
3764 "status: x%x result: x%x "
3765 "sid: x%x did: x%x oxid: x%x "
3768 cmd->device ? cmd->device->id : 0xffff,
3769 cmd->device ? cmd->device->lun : 0xffff,
3770 lpfc_cmd->status, lpfc_cmd->result,
3772 (pnode) ? pnode->nlp_DID : 0,
3773 phba->sli_rev == LPFC_SLI_REV4 ?
3774 lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff,
3775 pIocbOut->iocb.ulpContext,
3776 lpfc_cmd->cur_iocbq.iocb.ulpIoTag);
3778 switch (lpfc_cmd->status) {
3779 case IOSTAT_FCP_RSP_ERROR:
3780 /* Call FCP RSP handler to determine result */
3781 lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut);
3783 case IOSTAT_NPORT_BSY:
3784 case IOSTAT_FABRIC_BSY:
3785 cmd->result = DID_TRANSPORT_DISRUPTED << 16;
3786 fast_path_evt = lpfc_alloc_fast_evt(phba);
3789 fast_path_evt->un.fabric_evt.event_type =
3790 FC_REG_FABRIC_EVENT;
3791 fast_path_evt->un.fabric_evt.subcategory =
3792 (lpfc_cmd->status == IOSTAT_NPORT_BSY) ?
3793 LPFC_EVENT_PORT_BUSY : LPFC_EVENT_FABRIC_BUSY;
3794 if (pnode && NLP_CHK_NODE_ACT(pnode)) {
3795 memcpy(&fast_path_evt->un.fabric_evt.wwpn,
3796 &pnode->nlp_portname,
3797 sizeof(struct lpfc_name));
3798 memcpy(&fast_path_evt->un.fabric_evt.wwnn,
3799 &pnode->nlp_nodename,
3800 sizeof(struct lpfc_name));
3802 fast_path_evt->vport = vport;
3803 fast_path_evt->work_evt.evt =
3804 LPFC_EVT_FASTPATH_MGMT_EVT;
3805 spin_lock_irqsave(&phba->hbalock, flags);
3806 list_add_tail(&fast_path_evt->work_evt.evt_listp,
3808 spin_unlock_irqrestore(&phba->hbalock, flags);
3809 lpfc_worker_wake_up(phba);
3811 case IOSTAT_LOCAL_REJECT:
3812 case IOSTAT_REMOTE_STOP:
3813 if (lpfc_cmd->result == IOERR_ELXSEC_KEY_UNWRAP_ERROR ||
3815 IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR ||
3816 lpfc_cmd->result == IOERR_ELXSEC_CRYPTO_ERROR ||
3818 IOERR_ELXSEC_CRYPTO_COMPARE_ERROR) {
3819 cmd->result = DID_NO_CONNECT << 16;
3822 if (lpfc_cmd->result == IOERR_INVALID_RPI ||
3823 lpfc_cmd->result == IOERR_NO_RESOURCES ||
3824 lpfc_cmd->result == IOERR_ABORT_REQUESTED ||
3825 lpfc_cmd->result == IOERR_SLER_CMD_RCV_FAILURE) {
3826 cmd->result = DID_REQUEUE << 16;
3829 if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED ||
3830 lpfc_cmd->result == IOERR_TX_DMA_FAILED) &&
3831 pIocbOut->iocb.unsli3.sli3_bg.bgstat) {
3832 if (scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
3834 * This is a response for a BG enabled
3835 * cmd. Parse BG error
3837 lpfc_parse_bg_err(phba, lpfc_cmd,
3841 lpfc_printf_vlog(vport, KERN_WARNING,
3843 "9031 non-zero BGSTAT "
3844 "on unprotected cmd\n");
3847 if ((lpfc_cmd->status == IOSTAT_REMOTE_STOP)
3848 && (phba->sli_rev == LPFC_SLI_REV4)
3849 && (pnode && NLP_CHK_NODE_ACT(pnode))) {
3850 /* This IO was aborted by the target, we don't
3851 * know the rxid and because we did not send the
3852 * ABTS we cannot generate and RRQ.
3854 lpfc_set_rrq_active(phba, pnode,
3855 lpfc_cmd->cur_iocbq.sli4_lxritag,
3858 /* else: fall through */
3860 cmd->result = DID_ERROR << 16;
3864 if (!pnode || !NLP_CHK_NODE_ACT(pnode)
3865 || (pnode->nlp_state != NLP_STE_MAPPED_NODE))
3866 cmd->result = DID_TRANSPORT_DISRUPTED << 16 |
3869 cmd->result = DID_OK << 16;
3871 if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) {
3872 uint32_t *lp = (uint32_t *)cmd->sense_buffer;
3874 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
3875 "0710 Iodone <%d/%llu> cmd %p, error "
3876 "x%x SNS x%x x%x Data: x%x x%x\n",
3877 cmd->device->id, cmd->device->lun, cmd,
3878 cmd->result, *lp, *(lp + 3), cmd->retries,
3879 scsi_get_resid(cmd));
3882 lpfc_update_stats(phba, lpfc_cmd);
3883 if (vport->cfg_max_scsicmpl_time &&
3884 time_after(jiffies, lpfc_cmd->start_time +
3885 msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) {
3886 spin_lock_irqsave(shost->host_lock, flags);
3887 if (pnode && NLP_CHK_NODE_ACT(pnode)) {
3888 if (pnode->cmd_qdepth >
3889 atomic_read(&pnode->cmd_pending) &&
3890 (atomic_read(&pnode->cmd_pending) >
3891 LPFC_MIN_TGT_QDEPTH) &&
3892 ((cmd->cmnd[0] == READ_10) ||
3893 (cmd->cmnd[0] == WRITE_10)))
3895 atomic_read(&pnode->cmd_pending);
3897 pnode->last_change_time = jiffies;
3899 spin_unlock_irqrestore(shost->host_lock, flags);
3901 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
3903 /* If pCmd was set to NULL from abort path, do not call scsi_done */
3904 if (xchg(&lpfc_cmd->pCmd, NULL) == NULL) {
3905 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
3906 "5688 FCP cmd already NULL, sid: 0x%06x, "
3907 "did: 0x%06x, oxid: 0x%04x\n",
3909 (pnode) ? pnode->nlp_DID : 0,
3910 phba->sli_rev == LPFC_SLI_REV4 ?
3911 lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff);
3915 /* The sdev is not guaranteed to be valid post scsi_done upcall. */
3916 cmd->scsi_done(cmd);
3919 * If there is a thread waiting for command completion
3920 * wake up the thread.
3922 spin_lock_irqsave(shost->host_lock, flags);
3923 if (lpfc_cmd->waitq)
3924 wake_up(lpfc_cmd->waitq);
3925 spin_unlock_irqrestore(shost->host_lock, flags);
3927 lpfc_release_scsi_buf(phba, lpfc_cmd);
3931 * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB
3932 * @data: A pointer to the immediate command data portion of the IOCB.
3933 * @fcp_cmnd: The FCP Command that is provided by the SCSI layer.
3935 * The routine copies the entire FCP command from @fcp_cmnd to @data while
3936 * byte swapping the data to big endian format for transmission on the wire.
3939 lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd)
3942 for (i = 0, j = 0; i < sizeof(struct fcp_cmnd);
3943 i += sizeof(uint32_t), j++) {
3944 ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]);
3949 * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit
3950 * @vport: The virtual port for which this call is being executed.
3951 * @lpfc_cmd: The scsi command which needs to send.
3952 * @pnode: Pointer to lpfc_nodelist.
3954 * This routine initializes fcp_cmnd and iocb data structure from scsi command
3955 * to transfer for device with SLI3 interface spec.
3958 lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
3959 struct lpfc_nodelist *pnode)
3961 struct lpfc_hba *phba = vport->phba;
3962 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
3963 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
3964 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
3965 struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq);
3966 int datadir = scsi_cmnd->sc_data_direction;
3971 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
3974 lpfc_cmd->fcp_rsp->rspSnsLen = 0;
3975 /* clear task management bits */
3976 lpfc_cmd->fcp_cmnd->fcpCntl2 = 0;
3978 int_to_scsilun(lpfc_cmd->pCmd->device->lun,
3979 &lpfc_cmd->fcp_cmnd->fcp_lun);
3981 ptr = &fcp_cmnd->fcpCdb[0];
3982 memcpy(ptr, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3983 if (scsi_cmnd->cmd_len < LPFC_FCP_CDB_LEN) {
3984 ptr += scsi_cmnd->cmd_len;
3985 memset(ptr, 0, (LPFC_FCP_CDB_LEN - scsi_cmnd->cmd_len));
3988 fcp_cmnd->fcpCntl1 = SIMPLE_Q;
3990 sli4 = (phba->sli_rev == LPFC_SLI_REV4);
3991 piocbq->iocb.un.fcpi.fcpi_XRdy = 0;
3994 * There are three possibilities here - use scatter-gather segment, use
3995 * the single mapping, or neither. Start the lpfc command prep by
3996 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
3999 if (scsi_sg_count(scsi_cmnd)) {
4000 if (datadir == DMA_TO_DEVICE) {
4001 iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR;
4002 iocb_cmd->ulpPU = PARM_READ_CHECK;
4003 if (vport->cfg_first_burst_size &&
4004 (pnode->nlp_flag & NLP_FIRSTBURST)) {
4005 fcpdl = scsi_bufflen(scsi_cmnd);
4006 if (fcpdl < vport->cfg_first_burst_size)
4007 piocbq->iocb.un.fcpi.fcpi_XRdy = fcpdl;
4009 piocbq->iocb.un.fcpi.fcpi_XRdy =
4010 vport->cfg_first_burst_size;
4012 fcp_cmnd->fcpCntl3 = WRITE_DATA;
4013 atomic_inc(&phba->fc4ScsiOutputRequests);
4015 iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR;
4016 iocb_cmd->ulpPU = PARM_READ_CHECK;
4017 fcp_cmnd->fcpCntl3 = READ_DATA;
4018 atomic_inc(&phba->fc4ScsiInputRequests);
4021 iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR;
4022 iocb_cmd->un.fcpi.fcpi_parm = 0;
4023 iocb_cmd->ulpPU = 0;
4024 fcp_cmnd->fcpCntl3 = 0;
4025 atomic_inc(&phba->fc4ScsiControlRequests);
4027 if (phba->sli_rev == 3 &&
4028 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED))
4029 lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd);
4031 * Finish initializing those IOCB fields that are independent
4032 * of the scsi_cmnd request_buffer
4034 piocbq->iocb.ulpContext = pnode->nlp_rpi;
4036 piocbq->iocb.ulpContext =
4037 phba->sli4_hba.rpi_ids[pnode->nlp_rpi];
4038 if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE)
4039 piocbq->iocb.ulpFCP2Rcvy = 1;
4041 piocbq->iocb.ulpFCP2Rcvy = 0;
4043 piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f);
4044 piocbq->context1 = lpfc_cmd;
4045 piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
4046 piocbq->iocb.ulpTimeout = lpfc_cmd->timeout;
4047 piocbq->vport = vport;
4051 * lpfc_scsi_prep_task_mgmt_cmd - Convert SLI3 scsi TM cmd to FCP info unit
4052 * @vport: The virtual port for which this call is being executed.
4053 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
4054 * @lun: Logical unit number.
4055 * @task_mgmt_cmd: SCSI task management command.
4057 * This routine creates FCP information unit corresponding to @task_mgmt_cmd
4058 * for device with SLI-3 interface spec.
4065 lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport,
4066 struct lpfc_scsi_buf *lpfc_cmd,
4068 uint8_t task_mgmt_cmd)
4070 struct lpfc_iocbq *piocbq;
4072 struct fcp_cmnd *fcp_cmnd;
4073 struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
4074 struct lpfc_nodelist *ndlp = rdata->pnode;
4076 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) ||
4077 ndlp->nlp_state != NLP_STE_MAPPED_NODE)
4080 piocbq = &(lpfc_cmd->cur_iocbq);
4081 piocbq->vport = vport;
4083 piocb = &piocbq->iocb;
4085 fcp_cmnd = lpfc_cmd->fcp_cmnd;
4086 /* Clear out any old data in the FCP command area */
4087 memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd));
4088 int_to_scsilun(lun, &fcp_cmnd->fcp_lun);
4089 fcp_cmnd->fcpCntl2 = task_mgmt_cmd;
4090 if (vport->phba->sli_rev == 3 &&
4091 !(vport->phba->sli3_options & LPFC_SLI3_BG_ENABLED))
4092 lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd);
4093 piocb->ulpCommand = CMD_FCP_ICMND64_CR;
4094 piocb->ulpContext = ndlp->nlp_rpi;
4095 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
4097 vport->phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
4099 piocb->ulpFCP2Rcvy = (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) ? 1 : 0;
4100 piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f);
4102 piocb->un.fcpi.fcpi_parm = 0;
4104 /* ulpTimeout is only one byte */
4105 if (lpfc_cmd->timeout > 0xff) {
4107 * Do not timeout the command at the firmware level.
4108 * The driver will provide the timeout mechanism.
4110 piocb->ulpTimeout = 0;
4112 piocb->ulpTimeout = lpfc_cmd->timeout;
4114 if (vport->phba->sli_rev == LPFC_SLI_REV4)
4115 lpfc_sli4_set_rsp_sgl_last(vport->phba, lpfc_cmd);
4121 * lpfc_scsi_api_table_setup - Set up scsi api function jump table
4122 * @phba: The hba struct for which this call is being executed.
4123 * @dev_grp: The HBA PCI-Device group number.
4125 * This routine sets up the SCSI interface API function jump table in @phba
4127 * Returns: 0 - success, -ENODEV - failure.
4130 lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
4133 phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf;
4134 phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd;
4137 case LPFC_PCI_DEV_LP:
4138 phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3;
4139 phba->lpfc_bg_scsi_prep_dma_buf = lpfc_bg_scsi_prep_dma_buf_s3;
4140 phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3;
4141 phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s3;
4143 case LPFC_PCI_DEV_OC:
4144 phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s4;
4145 phba->lpfc_bg_scsi_prep_dma_buf = lpfc_bg_scsi_prep_dma_buf_s4;
4146 phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s4;
4147 phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s4;
4150 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4151 "1418 Invalid HBA PCI-device group: 0x%x\n",
4156 phba->lpfc_rampdown_queue_depth = lpfc_rampdown_queue_depth;
4157 phba->lpfc_scsi_cmd_iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
4162 * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command
4163 * @phba: The Hba for which this call is being executed.
4164 * @cmdiocbq: Pointer to lpfc_iocbq data structure.
4165 * @rspiocbq: Pointer to lpfc_iocbq data structure.
4167 * This routine is IOCB completion routine for device reset and target reset
4168 * routine. This routine release scsi buffer associated with lpfc_cmd.
4171 lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba,
4172 struct lpfc_iocbq *cmdiocbq,
4173 struct lpfc_iocbq *rspiocbq)
4175 struct lpfc_scsi_buf *lpfc_cmd =
4176 (struct lpfc_scsi_buf *) cmdiocbq->context1;
4178 lpfc_release_scsi_buf(phba, lpfc_cmd);
4183 * lpfc_check_pci_resettable - Walks list of devices on pci_dev's bus to check
4184 * if issuing a pci_bus_reset is possibly unsafe
4185 * @phba: lpfc_hba pointer.
4188 * Walks the bus_list to ensure only PCI devices with Emulex
4189 * vendor id, device ids that support hot reset, and only one occurrence
4193 * -EBADSLT, detected invalid device
4197 lpfc_check_pci_resettable(const struct lpfc_hba *phba)
4199 const struct pci_dev *pdev = phba->pcidev;
4200 struct pci_dev *ptr = NULL;
4203 /* Walk the list of devices on the pci_dev's bus */
4204 list_for_each_entry(ptr, &pdev->bus->devices, bus_list) {
4205 /* Check for Emulex Vendor ID */
4206 if (ptr->vendor != PCI_VENDOR_ID_EMULEX) {
4207 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4208 "8346 Non-Emulex vendor found: "
4209 "0x%04x\n", ptr->vendor);
4213 /* Check for valid Emulex Device ID */
4214 switch (ptr->device) {
4215 case PCI_DEVICE_ID_LANCER_FC:
4216 case PCI_DEVICE_ID_LANCER_G6_FC:
4217 case PCI_DEVICE_ID_LANCER_G7_FC:
4220 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4221 "8347 Invalid device found: "
4222 "0x%04x\n", ptr->device);
4226 /* Check for only one function 0 ID to ensure only one HBA on
4229 if (ptr->devfn == 0) {
4230 if (++counter > 1) {
4231 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4232 "8348 More than one device on "
4233 "secondary bus found\n");
4243 * lpfc_info - Info entry point of scsi_host_template data structure
4244 * @host: The scsi host for which this call is being executed.
4246 * This routine provides module information about hba.
4249 * Pointer to char - Success.
4252 lpfc_info(struct Scsi_Host *host)
4254 struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata;
4255 struct lpfc_hba *phba = vport->phba;
4257 static char lpfcinfobuf[384];
4258 char tmp[384] = {0};
4260 memset(lpfcinfobuf, 0, sizeof(lpfcinfobuf));
4261 if (phba && phba->pcidev){
4262 /* Model Description */
4263 scnprintf(tmp, sizeof(tmp), phba->ModelDesc);
4264 if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >=
4265 sizeof(lpfcinfobuf))
4269 scnprintf(tmp, sizeof(tmp),
4270 " on PCI bus %02x device %02x irq %d",
4271 phba->pcidev->bus->number, phba->pcidev->devfn,
4273 if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >=
4274 sizeof(lpfcinfobuf))
4278 if (phba->Port[0]) {
4279 scnprintf(tmp, sizeof(tmp), " port %s", phba->Port);
4280 if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >=
4281 sizeof(lpfcinfobuf))
4286 link_speed = lpfc_sli_port_speed_get(phba);
4287 if (link_speed != 0) {
4288 scnprintf(tmp, sizeof(tmp),
4289 " Logical Link Speed: %d Mbps", link_speed);
4290 if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >=
4291 sizeof(lpfcinfobuf))
4295 /* PCI resettable */
4296 if (!lpfc_check_pci_resettable(phba)) {
4297 scnprintf(tmp, sizeof(tmp), " PCI resettable");
4298 strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf));
4307 * lpfc_poll_rearm_time - Routine to modify fcp_poll timer of hba
4308 * @phba: The Hba for which this call is being executed.
4310 * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo.
4311 * The default value of cfg_poll_tmo is 10 milliseconds.
4313 static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba)
4315 unsigned long poll_tmo_expires =
4316 (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo));
4318 if (!list_empty(&phba->sli.sli3_ring[LPFC_FCP_RING].txcmplq))
4319 mod_timer(&phba->fcp_poll_timer,
4324 * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA
4325 * @phba: The Hba for which this call is being executed.
4327 * This routine starts the fcp_poll_timer of @phba.
4329 void lpfc_poll_start_timer(struct lpfc_hba * phba)
4331 lpfc_poll_rearm_timer(phba);
4335 * lpfc_poll_timeout - Restart polling timer
4336 * @ptr: Map to lpfc_hba data structure pointer.
4338 * This routine restarts fcp_poll timer, when FCP ring polling is enable
4339 * and FCP Ring interrupt is disable.
4342 void lpfc_poll_timeout(struct timer_list *t)
4344 struct lpfc_hba *phba = from_timer(phba, t, fcp_poll_timer);
4346 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
4347 lpfc_sli_handle_fast_ring_event(phba,
4348 &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ);
4350 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
4351 lpfc_poll_rearm_timer(phba);
4356 * lpfc_queuecommand - scsi_host_template queuecommand entry point
4357 * @cmnd: Pointer to scsi_cmnd data structure.
4358 * @done: Pointer to done routine.
4360 * Driver registers this routine to scsi midlayer to submit a @cmd to process.
4361 * This routine prepares an IOCB from scsi command and provides to firmware.
4362 * The @done callback is invoked after driver finished processing the command.
4366 * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily.
4369 lpfc_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *cmnd)
4371 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4372 struct lpfc_hba *phba = vport->phba;
4373 struct lpfc_rport_data *rdata;
4374 struct lpfc_nodelist *ndlp;
4375 struct lpfc_scsi_buf *lpfc_cmd;
4376 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
4379 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
4381 /* sanity check on references */
4382 if (unlikely(!rdata) || unlikely(!rport))
4383 goto out_fail_command;
4385 err = fc_remote_port_chkready(rport);
4388 goto out_fail_command;
4390 ndlp = rdata->pnode;
4392 if ((scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) &&
4393 (!(phba->sli3_options & LPFC_SLI3_BG_ENABLED))) {
4395 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
4396 "9058 BLKGRD: ERROR: rcvd protected cmd:%02x"
4397 " op:%02x str=%s without registering for"
4398 " BlockGuard - Rejecting command\n",
4399 cmnd->cmnd[0], scsi_get_prot_op(cmnd),
4400 dif_op_str[scsi_get_prot_op(cmnd)]);
4401 goto out_fail_command;
4405 * Catch race where our node has transitioned, but the
4406 * transport is still transitioning.
4408 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
4410 if (lpfc_ndlp_check_qdepth(phba, ndlp)) {
4411 if (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth) {
4412 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_ERROR,
4413 "3377 Target Queue Full, scsi Id:%d "
4414 "Qdepth:%d Pending command:%d"
4415 " WWNN:%02x:%02x:%02x:%02x:"
4416 "%02x:%02x:%02x:%02x, "
4417 " WWPN:%02x:%02x:%02x:%02x:"
4418 "%02x:%02x:%02x:%02x",
4419 ndlp->nlp_sid, ndlp->cmd_qdepth,
4420 atomic_read(&ndlp->cmd_pending),
4421 ndlp->nlp_nodename.u.wwn[0],
4422 ndlp->nlp_nodename.u.wwn[1],
4423 ndlp->nlp_nodename.u.wwn[2],
4424 ndlp->nlp_nodename.u.wwn[3],
4425 ndlp->nlp_nodename.u.wwn[4],
4426 ndlp->nlp_nodename.u.wwn[5],
4427 ndlp->nlp_nodename.u.wwn[6],
4428 ndlp->nlp_nodename.u.wwn[7],
4429 ndlp->nlp_portname.u.wwn[0],
4430 ndlp->nlp_portname.u.wwn[1],
4431 ndlp->nlp_portname.u.wwn[2],
4432 ndlp->nlp_portname.u.wwn[3],
4433 ndlp->nlp_portname.u.wwn[4],
4434 ndlp->nlp_portname.u.wwn[5],
4435 ndlp->nlp_portname.u.wwn[6],
4436 ndlp->nlp_portname.u.wwn[7]);
4441 lpfc_cmd = lpfc_get_scsi_buf(phba, ndlp);
4442 if (lpfc_cmd == NULL) {
4443 lpfc_rampdown_queue_depth(phba);
4445 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_ERROR,
4446 "0707 driver's buffer pool is empty, "
4452 * Store the midlayer's command structure for the completion phase
4453 * and complete the command initialization.
4455 lpfc_cmd->pCmd = cmnd;
4456 lpfc_cmd->rdata = rdata;
4457 lpfc_cmd->ndlp = ndlp;
4458 cmnd->host_scribble = (unsigned char *)lpfc_cmd;
4460 if (scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) {
4461 if (vport->phba->cfg_enable_bg) {
4462 lpfc_printf_vlog(vport,
4463 KERN_INFO, LOG_SCSI_CMD,
4464 "9033 BLKGRD: rcvd %s cmd:x%x "
4465 "sector x%llx cnt %u pt %x\n",
4466 dif_op_str[scsi_get_prot_op(cmnd)],
4468 (unsigned long long)scsi_get_lba(cmnd),
4469 blk_rq_sectors(cmnd->request),
4470 (cmnd->cmnd[1]>>5));
4472 err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd);
4474 if (vport->phba->cfg_enable_bg) {
4475 lpfc_printf_vlog(vport,
4476 KERN_INFO, LOG_SCSI_CMD,
4477 "9038 BLKGRD: rcvd PROT_NORMAL cmd: "
4478 "x%x sector x%llx cnt %u pt %x\n",
4480 (unsigned long long)scsi_get_lba(cmnd),
4481 blk_rq_sectors(cmnd->request),
4482 (cmnd->cmnd[1]>>5));
4484 err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd);
4488 goto out_host_busy_free_buf;
4490 lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp);
4492 err = lpfc_sli_issue_iocb(phba, LPFC_FCP_RING,
4493 &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB);
4495 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4496 "3376 FCP could not issue IOCB err %x"
4497 "FCP cmd x%x <%d/%llu> "
4498 "sid: x%x did: x%x oxid: x%x "
4499 "Data: x%x x%x x%x x%x\n",
4501 cmnd->device ? cmnd->device->id : 0xffff,
4502 cmnd->device ? cmnd->device->lun : (u64) -1,
4503 vport->fc_myDID, ndlp->nlp_DID,
4504 phba->sli_rev == LPFC_SLI_REV4 ?
4505 lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff,
4506 lpfc_cmd->cur_iocbq.iocb.ulpContext,
4507 lpfc_cmd->cur_iocbq.iocb.ulpIoTag,
4508 lpfc_cmd->cur_iocbq.iocb.ulpTimeout,
4510 (cmnd->request->timeout / 1000));
4512 switch (lpfc_cmd->fcp_cmnd->fcpCntl3) {
4514 atomic_dec(&phba->fc4ScsiOutputRequests);
4517 atomic_dec(&phba->fc4ScsiInputRequests);
4520 atomic_dec(&phba->fc4ScsiControlRequests);
4522 goto out_host_busy_free_buf;
4524 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
4525 lpfc_sli_handle_fast_ring_event(phba,
4526 &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ);
4528 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
4529 lpfc_poll_rearm_timer(phba);
4534 out_host_busy_free_buf:
4535 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
4536 lpfc_release_scsi_buf(phba, lpfc_cmd);
4538 return SCSI_MLQUEUE_HOST_BUSY;
4541 return SCSI_MLQUEUE_TARGET_BUSY;
4544 cmnd->scsi_done(cmnd);
4550 * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point
4551 * @cmnd: Pointer to scsi_cmnd data structure.
4553 * This routine aborts @cmnd pending in base driver.
4560 lpfc_abort_handler(struct scsi_cmnd *cmnd)
4562 struct Scsi_Host *shost = cmnd->device->host;
4563 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4564 struct lpfc_hba *phba = vport->phba;
4565 struct lpfc_iocbq *iocb;
4566 struct lpfc_iocbq *abtsiocb;
4567 struct lpfc_scsi_buf *lpfc_cmd;
4569 int ret = SUCCESS, status = 0;
4570 struct lpfc_sli_ring *pring_s4 = NULL;
4572 unsigned long flags;
4573 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq);
4575 status = fc_block_scsi_eh(cmnd);
4576 if (status != 0 && status != SUCCESS)
4579 spin_lock_irqsave(&phba->hbalock, flags);
4580 /* driver queued commands are in process of being flushed */
4581 if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) {
4582 spin_unlock_irqrestore(&phba->hbalock, flags);
4583 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4584 "3168 SCSI Layer abort requested I/O has been "
4585 "flushed by LLD.\n");
4589 lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble;
4590 if (!lpfc_cmd || !lpfc_cmd->pCmd) {
4591 spin_unlock_irqrestore(&phba->hbalock, flags);
4592 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4593 "2873 SCSI Layer I/O Abort Request IO CMPL Status "
4594 "x%x ID %d LUN %llu\n",
4595 SUCCESS, cmnd->device->id, cmnd->device->lun);
4599 iocb = &lpfc_cmd->cur_iocbq;
4600 if (phba->sli_rev == LPFC_SLI_REV4) {
4601 if (!(phba->cfg_fof) ||
4602 (!(iocb->iocb_flag & LPFC_IO_FOF))) {
4604 phba->sli4_hba.fcp_wq[iocb->hba_wqidx]->pring;
4606 iocb->hba_wqidx = 0;
4607 pring_s4 = phba->sli4_hba.oas_wq->pring;
4613 spin_lock(&pring_s4->ring_lock);
4615 /* the command is in process of being cancelled */
4616 if (!(iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ)) {
4617 if (phba->sli_rev == LPFC_SLI_REV4)
4618 spin_unlock(&pring_s4->ring_lock);
4619 spin_unlock_irqrestore(&phba->hbalock, flags);
4620 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4621 "3169 SCSI Layer abort requested I/O has been "
4622 "cancelled by LLD.\n");
4626 * If pCmd field of the corresponding lpfc_scsi_buf structure
4627 * points to a different SCSI command, then the driver has
4628 * already completed this command, but the midlayer did not
4629 * see the completion before the eh fired. Just return SUCCESS.
4631 if (lpfc_cmd->pCmd != cmnd) {
4632 if (phba->sli_rev == LPFC_SLI_REV4)
4633 spin_unlock(&pring_s4->ring_lock);
4634 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4635 "3170 SCSI Layer abort requested I/O has been "
4636 "completed by LLD.\n");
4640 BUG_ON(iocb->context1 != lpfc_cmd);
4642 /* abort issued in recovery is still in progress */
4643 if (iocb->iocb_flag & LPFC_DRIVER_ABORTED) {
4644 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4645 "3389 SCSI Layer I/O Abort Request is pending\n");
4646 if (phba->sli_rev == LPFC_SLI_REV4)
4647 spin_unlock(&pring_s4->ring_lock);
4648 spin_unlock_irqrestore(&phba->hbalock, flags);
4652 abtsiocb = __lpfc_sli_get_iocbq(phba);
4653 if (abtsiocb == NULL) {
4655 if (phba->sli_rev == LPFC_SLI_REV4)
4656 spin_unlock(&pring_s4->ring_lock);
4660 /* Indicate the IO is being aborted by the driver. */
4661 iocb->iocb_flag |= LPFC_DRIVER_ABORTED;
4664 * The scsi command can not be in txq and it is in flight because the
4665 * pCmd is still pointig at the SCSI command we have to abort. There
4666 * is no need to search the txcmplq. Just send an abort to the FW.
4670 icmd = &abtsiocb->iocb;
4671 icmd->un.acxri.abortType = ABORT_TYPE_ABTS;
4672 icmd->un.acxri.abortContextTag = cmd->ulpContext;
4673 if (phba->sli_rev == LPFC_SLI_REV4)
4674 icmd->un.acxri.abortIoTag = iocb->sli4_xritag;
4676 icmd->un.acxri.abortIoTag = cmd->ulpIoTag;
4679 icmd->ulpClass = cmd->ulpClass;
4681 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
4682 abtsiocb->hba_wqidx = iocb->hba_wqidx;
4683 abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
4684 if (iocb->iocb_flag & LPFC_IO_FOF)
4685 abtsiocb->iocb_flag |= LPFC_IO_FOF;
4687 if (lpfc_is_link_up(phba))
4688 icmd->ulpCommand = CMD_ABORT_XRI_CN;
4690 icmd->ulpCommand = CMD_CLOSE_XRI_CN;
4692 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
4693 abtsiocb->vport = vport;
4694 lpfc_cmd->waitq = &waitq;
4695 if (phba->sli_rev == LPFC_SLI_REV4) {
4696 /* Note: both hbalock and ring_lock must be set here */
4697 ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno,
4699 spin_unlock(&pring_s4->ring_lock);
4701 ret_val = __lpfc_sli_issue_iocb(phba, LPFC_FCP_RING,
4704 /* no longer need the lock after this point */
4705 spin_unlock_irqrestore(&phba->hbalock, flags);
4708 if (ret_val == IOCB_ERROR) {
4709 if (phba->sli_rev == LPFC_SLI_REV4)
4710 spin_lock_irqsave(&pring_s4->ring_lock, flags);
4712 spin_lock_irqsave(&phba->hbalock, flags);
4713 /* Indicate the IO is not being aborted by the driver. */
4714 iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
4715 lpfc_cmd->waitq = NULL;
4716 if (phba->sli_rev == LPFC_SLI_REV4)
4717 spin_unlock_irqrestore(&pring_s4->ring_lock, flags);
4719 spin_unlock_irqrestore(&phba->hbalock, flags);
4720 lpfc_sli_release_iocbq(phba, abtsiocb);
4725 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
4726 lpfc_sli_handle_fast_ring_event(phba,
4727 &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ);
4730 /* Wait for abort to complete */
4731 wait_event_timeout(waitq,
4732 (lpfc_cmd->pCmd != cmnd),
4733 msecs_to_jiffies(2*vport->cfg_devloss_tmo*1000));
4735 spin_lock_irqsave(shost->host_lock, flags);
4736 lpfc_cmd->waitq = NULL;
4737 spin_unlock_irqrestore(shost->host_lock, flags);
4739 if (lpfc_cmd->pCmd == cmnd) {
4741 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
4742 "0748 abort handler timed out waiting "
4743 "for aborting I/O (xri:x%x) to complete: "
4744 "ret %#x, ID %d, LUN %llu\n",
4745 iocb->sli4_xritag, ret,
4746 cmnd->device->id, cmnd->device->lun);
4751 spin_unlock_irqrestore(&phba->hbalock, flags);
4753 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4754 "0749 SCSI Layer I/O Abort Request Status x%x ID %d "
4755 "LUN %llu\n", ret, cmnd->device->id,
4761 lpfc_taskmgmt_name(uint8_t task_mgmt_cmd)
4763 switch (task_mgmt_cmd) {
4764 case FCP_ABORT_TASK_SET:
4765 return "ABORT_TASK_SET";
4766 case FCP_CLEAR_TASK_SET:
4767 return "FCP_CLEAR_TASK_SET";
4769 return "FCP_BUS_RESET";
4771 return "FCP_LUN_RESET";
4772 case FCP_TARGET_RESET:
4773 return "FCP_TARGET_RESET";
4775 return "FCP_CLEAR_ACA";
4776 case FCP_TERMINATE_TASK:
4777 return "FCP_TERMINATE_TASK";
4785 * lpfc_check_fcp_rsp - check the returned fcp_rsp to see if task failed
4786 * @vport: The virtual port for which this call is being executed.
4787 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
4789 * This routine checks the FCP RSP INFO to see if the tsk mgmt command succeded
4796 lpfc_check_fcp_rsp(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd)
4798 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
4801 uint8_t rsp_info_code;
4806 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4807 "0703 fcp_rsp is missing\n");
4809 rsp_info = fcprsp->rspStatus2;
4810 rsp_len = be32_to_cpu(fcprsp->rspRspLen);
4811 rsp_info_code = fcprsp->rspInfo3;
4814 lpfc_printf_vlog(vport, KERN_INFO,
4816 "0706 fcp_rsp valid 0x%x,"
4817 " rsp len=%d code 0x%x\n",
4819 rsp_len, rsp_info_code);
4821 if ((fcprsp->rspStatus2&RSP_LEN_VALID) && (rsp_len == 8)) {
4822 switch (rsp_info_code) {
4823 case RSP_NO_FAILURE:
4824 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4825 "0715 Task Mgmt No Failure\n");
4828 case RSP_TM_NOT_SUPPORTED: /* TM rejected */
4829 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4830 "0716 Task Mgmt Target "
4833 case RSP_TM_NOT_COMPLETED: /* TM failed */
4834 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4835 "0717 Task Mgmt Target "
4838 case RSP_TM_INVALID_LU: /* TM to invalid LU! */
4839 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4840 "0718 Task Mgmt to invalid "
4851 * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler
4852 * @vport: The virtual port for which this call is being executed.
4853 * @rdata: Pointer to remote port local data
4854 * @tgt_id: Target ID of remote device.
4855 * @lun_id: Lun number for the TMF
4856 * @task_mgmt_cmd: type of TMF to send
4858 * This routine builds and sends a TMF (SCSI Task Mgmt Function) to
4866 lpfc_send_taskmgmt(struct lpfc_vport *vport, struct scsi_cmnd *cmnd,
4867 unsigned int tgt_id, uint64_t lun_id,
4868 uint8_t task_mgmt_cmd)
4870 struct lpfc_hba *phba = vport->phba;
4871 struct lpfc_scsi_buf *lpfc_cmd;
4872 struct lpfc_iocbq *iocbq;
4873 struct lpfc_iocbq *iocbqrsp;
4874 struct lpfc_rport_data *rdata;
4875 struct lpfc_nodelist *pnode;
4879 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
4880 if (!rdata || !rdata->pnode || !NLP_CHK_NODE_ACT(rdata->pnode))
4882 pnode = rdata->pnode;
4884 lpfc_cmd = lpfc_get_scsi_buf(phba, pnode);
4885 if (lpfc_cmd == NULL)
4887 lpfc_cmd->timeout = phba->cfg_task_mgmt_tmo;
4888 lpfc_cmd->rdata = rdata;
4889 lpfc_cmd->pCmd = cmnd;
4890 lpfc_cmd->ndlp = pnode;
4892 status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun_id,
4895 lpfc_release_scsi_buf(phba, lpfc_cmd);
4899 iocbq = &lpfc_cmd->cur_iocbq;
4900 iocbqrsp = lpfc_sli_get_iocbq(phba);
4901 if (iocbqrsp == NULL) {
4902 lpfc_release_scsi_buf(phba, lpfc_cmd);
4905 iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
4907 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4908 "0702 Issue %s to TGT %d LUN %llu "
4909 "rpi x%x nlp_flag x%x Data: x%x x%x\n",
4910 lpfc_taskmgmt_name(task_mgmt_cmd), tgt_id, lun_id,
4911 pnode->nlp_rpi, pnode->nlp_flag, iocbq->sli4_xritag,
4914 status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING,
4915 iocbq, iocbqrsp, lpfc_cmd->timeout);
4916 if ((status != IOCB_SUCCESS) ||
4917 (iocbqrsp->iocb.ulpStatus != IOSTAT_SUCCESS)) {
4918 if (status != IOCB_SUCCESS ||
4919 iocbqrsp->iocb.ulpStatus != IOSTAT_FCP_RSP_ERROR)
4920 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
4921 "0727 TMF %s to TGT %d LUN %llu "
4922 "failed (%d, %d) iocb_flag x%x\n",
4923 lpfc_taskmgmt_name(task_mgmt_cmd),
4925 iocbqrsp->iocb.ulpStatus,
4926 iocbqrsp->iocb.un.ulpWord[4],
4928 /* if ulpStatus != IOCB_SUCCESS, then status == IOCB_SUCCESS */
4929 if (status == IOCB_SUCCESS) {
4930 if (iocbqrsp->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
4931 /* Something in the FCP_RSP was invalid.
4932 * Check conditions */
4933 ret = lpfc_check_fcp_rsp(vport, lpfc_cmd);
4936 } else if (status == IOCB_TIMEDOUT) {
4937 ret = TIMEOUT_ERROR;
4944 lpfc_sli_release_iocbq(phba, iocbqrsp);
4946 if (ret != TIMEOUT_ERROR)
4947 lpfc_release_scsi_buf(phba, lpfc_cmd);
4953 * lpfc_chk_tgt_mapped -
4954 * @vport: The virtual port to check on
4955 * @cmnd: Pointer to scsi_cmnd data structure.
4957 * This routine delays until the scsi target (aka rport) for the
4958 * command exists (is present and logged in) or we declare it non-existent.
4965 lpfc_chk_tgt_mapped(struct lpfc_vport *vport, struct scsi_cmnd *cmnd)
4967 struct lpfc_rport_data *rdata;
4968 struct lpfc_nodelist *pnode;
4969 unsigned long later;
4971 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
4973 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4974 "0797 Tgt Map rport failure: rdata x%p\n", rdata);
4977 pnode = rdata->pnode;
4979 * If target is not in a MAPPED state, delay until
4980 * target is rediscovered or devloss timeout expires.
4982 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
4983 while (time_after(later, jiffies)) {
4984 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
4986 if (pnode->nlp_state == NLP_STE_MAPPED_NODE)
4988 schedule_timeout_uninterruptible(msecs_to_jiffies(500));
4989 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
4992 pnode = rdata->pnode;
4994 if (!pnode || !NLP_CHK_NODE_ACT(pnode) ||
4995 (pnode->nlp_state != NLP_STE_MAPPED_NODE))
5001 * lpfc_reset_flush_io_context -
5002 * @vport: The virtual port (scsi_host) for the flush context
5003 * @tgt_id: If aborting by Target contect - specifies the target id
5004 * @lun_id: If aborting by Lun context - specifies the lun id
5005 * @context: specifies the context level to flush at.
5007 * After a reset condition via TMF, we need to flush orphaned i/o
5008 * contexts from the adapter. This routine aborts any contexts
5009 * outstanding, then waits for their completions. The wait is
5010 * bounded by devloss_tmo though.
5017 lpfc_reset_flush_io_context(struct lpfc_vport *vport, uint16_t tgt_id,
5018 uint64_t lun_id, lpfc_ctx_cmd context)
5020 struct lpfc_hba *phba = vport->phba;
5021 unsigned long later;
5024 cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context);
5026 lpfc_sli_abort_taskmgmt(vport,
5027 &phba->sli.sli3_ring[LPFC_FCP_RING],
5028 tgt_id, lun_id, context);
5029 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
5030 while (time_after(later, jiffies) && cnt) {
5031 schedule_timeout_uninterruptible(msecs_to_jiffies(20));
5032 cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context);
5035 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5036 "0724 I/O flush failure for context %s : cnt x%x\n",
5037 ((context == LPFC_CTX_LUN) ? "LUN" :
5038 ((context == LPFC_CTX_TGT) ? "TGT" :
5039 ((context == LPFC_CTX_HOST) ? "HOST" : "Unknown"))),
5047 * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point
5048 * @cmnd: Pointer to scsi_cmnd data structure.
5050 * This routine does a device reset by sending a LUN_RESET task management
5058 lpfc_device_reset_handler(struct scsi_cmnd *cmnd)
5060 struct Scsi_Host *shost = cmnd->device->host;
5061 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5062 struct lpfc_rport_data *rdata;
5063 struct lpfc_nodelist *pnode;
5064 unsigned tgt_id = cmnd->device->id;
5065 uint64_t lun_id = cmnd->device->lun;
5066 struct lpfc_scsi_event_header scsi_event;
5069 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
5070 if (!rdata || !rdata->pnode) {
5071 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5072 "0798 Device Reset rport failure: rdata x%p\n",
5076 pnode = rdata->pnode;
5077 status = fc_block_scsi_eh(cmnd);
5078 if (status != 0 && status != SUCCESS)
5081 status = lpfc_chk_tgt_mapped(vport, cmnd);
5082 if (status == FAILED) {
5083 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5084 "0721 Device Reset rport failure: rdata x%p\n", rdata);
5088 scsi_event.event_type = FC_REG_SCSI_EVENT;
5089 scsi_event.subcategory = LPFC_EVENT_LUNRESET;
5090 scsi_event.lun = lun_id;
5091 memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name));
5092 memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name));
5094 fc_host_post_vendor_event(shost, fc_get_event_number(),
5095 sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
5097 status = lpfc_send_taskmgmt(vport, cmnd, tgt_id, lun_id,
5100 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5101 "0713 SCSI layer issued Device Reset (%d, %llu) "
5102 "return x%x\n", tgt_id, lun_id, status);
5105 * We have to clean up i/o as : they may be orphaned by the TMF;
5106 * or if the TMF failed, they may be in an indeterminate state.
5108 * We will report success if all the i/o aborts successfully.
5110 if (status == SUCCESS)
5111 status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
5118 * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point
5119 * @cmnd: Pointer to scsi_cmnd data structure.
5121 * This routine does a target reset by sending a TARGET_RESET task management
5129 lpfc_target_reset_handler(struct scsi_cmnd *cmnd)
5131 struct Scsi_Host *shost = cmnd->device->host;
5132 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5133 struct lpfc_rport_data *rdata;
5134 struct lpfc_nodelist *pnode;
5135 unsigned tgt_id = cmnd->device->id;
5136 uint64_t lun_id = cmnd->device->lun;
5137 struct lpfc_scsi_event_header scsi_event;
5140 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
5142 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5143 "0799 Target Reset rport failure: rdata x%p\n", rdata);
5146 pnode = rdata->pnode;
5147 status = fc_block_scsi_eh(cmnd);
5148 if (status != 0 && status != SUCCESS)
5151 status = lpfc_chk_tgt_mapped(vport, cmnd);
5152 if (status == FAILED) {
5153 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5154 "0722 Target Reset rport failure: rdata x%p\n", rdata);
5156 spin_lock_irq(shost->host_lock);
5157 pnode->nlp_flag &= ~NLP_NPR_ADISC;
5158 pnode->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
5159 spin_unlock_irq(shost->host_lock);
5161 lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
5163 return FAST_IO_FAIL;
5166 scsi_event.event_type = FC_REG_SCSI_EVENT;
5167 scsi_event.subcategory = LPFC_EVENT_TGTRESET;
5169 memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name));
5170 memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name));
5172 fc_host_post_vendor_event(shost, fc_get_event_number(),
5173 sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
5175 status = lpfc_send_taskmgmt(vport, cmnd, tgt_id, lun_id,
5178 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5179 "0723 SCSI layer issued Target Reset (%d, %llu) "
5180 "return x%x\n", tgt_id, lun_id, status);
5183 * We have to clean up i/o as : they may be orphaned by the TMF;
5184 * or if the TMF failed, they may be in an indeterminate state.
5186 * We will report success if all the i/o aborts successfully.
5188 if (status == SUCCESS)
5189 status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
5195 * lpfc_bus_reset_handler - scsi_host_template eh_bus_reset_handler entry point
5196 * @cmnd: Pointer to scsi_cmnd data structure.
5198 * This routine does target reset to all targets on @cmnd->device->host.
5199 * This emulates Parallel SCSI Bus Reset Semantics.
5206 lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
5208 struct Scsi_Host *shost = cmnd->device->host;
5209 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5210 struct lpfc_nodelist *ndlp = NULL;
5211 struct lpfc_scsi_event_header scsi_event;
5213 int ret = SUCCESS, status, i;
5215 scsi_event.event_type = FC_REG_SCSI_EVENT;
5216 scsi_event.subcategory = LPFC_EVENT_BUSRESET;
5218 memcpy(scsi_event.wwpn, &vport->fc_portname, sizeof(struct lpfc_name));
5219 memcpy(scsi_event.wwnn, &vport->fc_nodename, sizeof(struct lpfc_name));
5221 fc_host_post_vendor_event(shost, fc_get_event_number(),
5222 sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
5224 status = fc_block_scsi_eh(cmnd);
5225 if (status != 0 && status != SUCCESS)
5229 * Since the driver manages a single bus device, reset all
5230 * targets known to the driver. Should any target reset
5231 * fail, this routine returns failure to the midlayer.
5233 for (i = 0; i < LPFC_MAX_TARGET; i++) {
5234 /* Search for mapped node by target ID */
5236 spin_lock_irq(shost->host_lock);
5237 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5238 if (!NLP_CHK_NODE_ACT(ndlp))
5240 if (vport->phba->cfg_fcp2_no_tgt_reset &&
5241 (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE))
5243 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
5244 ndlp->nlp_sid == i &&
5246 ndlp->nlp_type & NLP_FCP_TARGET) {
5251 spin_unlock_irq(shost->host_lock);
5255 status = lpfc_send_taskmgmt(vport, cmnd,
5256 i, 0, FCP_TARGET_RESET);
5258 if (status != SUCCESS) {
5259 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5260 "0700 Bus Reset on target %d failed\n",
5266 * We have to clean up i/o as : they may be orphaned by the TMFs
5267 * above; or if any of the TMFs failed, they may be in an
5268 * indeterminate state.
5269 * We will report success if all the i/o aborts successfully.
5272 status = lpfc_reset_flush_io_context(vport, 0, 0, LPFC_CTX_HOST);
5273 if (status != SUCCESS)
5276 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5277 "0714 SCSI layer issued Bus Reset Data: x%x\n", ret);
5282 * lpfc_host_reset_handler - scsi_host_template eh_host_reset_handler entry pt
5283 * @cmnd: Pointer to scsi_cmnd data structure.
5285 * This routine does host reset to the adaptor port. It brings the HBA
5286 * offline, performs a board restart, and then brings the board back online.
5287 * The lpfc_offline calls lpfc_sli_hba_down which will abort and local
5288 * reject all outstanding SCSI commands to the host and error returned
5289 * back to SCSI mid-level. As this will be SCSI mid-level's last resort
5290 * of error handling, it will only return error if resetting of the adapter
5291 * is not successful; in all other cases, will return success.
5298 lpfc_host_reset_handler(struct scsi_cmnd *cmnd)
5300 struct Scsi_Host *shost = cmnd->device->host;
5301 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5302 struct lpfc_hba *phba = vport->phba;
5303 int rc, ret = SUCCESS;
5305 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5306 "3172 SCSI layer issued Host Reset Data:\n");
5308 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
5310 rc = lpfc_sli_brdrestart(phba);
5313 rc = lpfc_online(phba);
5316 lpfc_unblock_mgmt_io(phba);
5318 if (ret == FAILED) {
5319 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5320 "3323 Failed host reset, bring it offline\n");
5321 lpfc_sli4_offline_eratt(phba);
5327 * lpfc_slave_alloc - scsi_host_template slave_alloc entry point
5328 * @sdev: Pointer to scsi_device.
5330 * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's
5331 * globally available list of scsi buffers. This routine also makes sure scsi
5332 * buffer is not allocated more than HBA limit conveyed to midlayer. This list
5333 * of scsi buffer exists for the lifetime of the driver.
5340 lpfc_slave_alloc(struct scsi_device *sdev)
5342 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
5343 struct lpfc_hba *phba = vport->phba;
5344 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
5346 uint32_t num_to_alloc = 0;
5347 int num_allocated = 0;
5349 struct lpfc_device_data *device_data;
5350 unsigned long flags;
5351 struct lpfc_name target_wwpn;
5353 if (!rport || fc_remote_port_chkready(rport))
5356 if (phba->cfg_fof) {
5359 * Check to see if the device data structure for the lun
5360 * exists. If not, create one.
5363 u64_to_wwn(rport->port_name, target_wwpn.u.wwn);
5364 spin_lock_irqsave(&phba->devicelock, flags);
5365 device_data = __lpfc_get_device_data(phba,
5367 &vport->fc_portname,
5371 spin_unlock_irqrestore(&phba->devicelock, flags);
5372 device_data = lpfc_create_device_data(phba,
5373 &vport->fc_portname,
5376 phba->cfg_XLanePriority,
5380 spin_lock_irqsave(&phba->devicelock, flags);
5381 list_add_tail(&device_data->listentry, &phba->luns);
5383 device_data->rport_data = rport->dd_data;
5384 device_data->available = true;
5385 spin_unlock_irqrestore(&phba->devicelock, flags);
5386 sdev->hostdata = device_data;
5388 sdev->hostdata = rport->dd_data;
5390 sdev_cnt = atomic_inc_return(&phba->sdev_cnt);
5392 /* For SLI4, all IO buffers are pre-allocated */
5393 if (phba->sli_rev == LPFC_SLI_REV4)
5396 /* This code path is now ONLY for SLI3 adapters */
5399 * Populate the cmds_per_lun count scsi_bufs into this host's globally
5400 * available list of scsi buffers. Don't allocate more than the
5401 * HBA limit conveyed to the midlayer via the host structure. The
5402 * formula accounts for the lun_queue_depth + error handlers + 1
5403 * extra. This list of scsi bufs exists for the lifetime of the driver.
5405 total = phba->total_scsi_bufs;
5406 num_to_alloc = vport->cfg_lun_queue_depth + 2;
5408 /* If allocated buffers are enough do nothing */
5409 if ((sdev_cnt * (vport->cfg_lun_queue_depth + 2)) < total)
5412 /* Allow some exchanges to be available always to complete discovery */
5413 if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
5414 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
5415 "0704 At limitation of %d preallocated "
5416 "command buffers\n", total);
5418 /* Allow some exchanges to be available always to complete discovery */
5419 } else if (total + num_to_alloc >
5420 phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
5421 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
5422 "0705 Allocation request of %d "
5423 "command buffers will exceed max of %d. "
5424 "Reducing allocation request to %d.\n",
5425 num_to_alloc, phba->cfg_hba_queue_depth,
5426 (phba->cfg_hba_queue_depth - total));
5427 num_to_alloc = phba->cfg_hba_queue_depth - total;
5429 num_allocated = lpfc_new_scsi_buf_s3(vport, num_to_alloc);
5430 if (num_to_alloc != num_allocated) {
5431 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5432 "0708 Allocation request of %d "
5433 "command buffers did not succeed. "
5434 "Allocated %d buffers.\n",
5435 num_to_alloc, num_allocated);
5437 if (num_allocated > 0)
5438 phba->total_scsi_bufs += num_allocated;
5443 * lpfc_slave_configure - scsi_host_template slave_configure entry point
5444 * @sdev: Pointer to scsi_device.
5446 * This routine configures following items
5447 * - Tag command queuing support for @sdev if supported.
5448 * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set.
5454 lpfc_slave_configure(struct scsi_device *sdev)
5456 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
5457 struct lpfc_hba *phba = vport->phba;
5459 scsi_change_queue_depth(sdev, vport->cfg_lun_queue_depth);
5461 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
5462 lpfc_sli_handle_fast_ring_event(phba,
5463 &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ);
5464 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
5465 lpfc_poll_rearm_timer(phba);
5472 * lpfc_slave_destroy - slave_destroy entry point of SHT data structure
5473 * @sdev: Pointer to scsi_device.
5475 * This routine sets @sdev hostatdata filed to null.
5478 lpfc_slave_destroy(struct scsi_device *sdev)
5480 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
5481 struct lpfc_hba *phba = vport->phba;
5482 unsigned long flags;
5483 struct lpfc_device_data *device_data = sdev->hostdata;
5485 atomic_dec(&phba->sdev_cnt);
5486 if ((phba->cfg_fof) && (device_data)) {
5487 spin_lock_irqsave(&phba->devicelock, flags);
5488 device_data->available = false;
5489 if (!device_data->oas_enabled)
5490 lpfc_delete_device_data(phba, device_data);
5491 spin_unlock_irqrestore(&phba->devicelock, flags);
5493 sdev->hostdata = NULL;
5498 * lpfc_create_device_data - creates and initializes device data structure for OAS
5499 * @pha: Pointer to host bus adapter structure.
5500 * @vport_wwpn: Pointer to vport's wwpn information
5501 * @target_wwpn: Pointer to target's wwpn information
5502 * @lun: Lun on target
5503 * @atomic_create: Flag to indicate if memory should be allocated using the
5504 * GFP_ATOMIC flag or not.
5506 * This routine creates a device data structure which will contain identifying
5507 * information for the device (host wwpn, target wwpn, lun), state of OAS,
5508 * whether or not the corresponding lun is available by the system,
5509 * and pointer to the rport data.
5513 * Pointer to lpfc_device_data - Success
5515 struct lpfc_device_data*
5516 lpfc_create_device_data(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn,
5517 struct lpfc_name *target_wwpn, uint64_t lun,
5518 uint32_t pri, bool atomic_create)
5521 struct lpfc_device_data *lun_info;
5524 if (unlikely(!phba) || !vport_wwpn || !target_wwpn ||
5528 /* Attempt to create the device data to contain lun info */
5531 memory_flags = GFP_ATOMIC;
5533 memory_flags = GFP_KERNEL;
5534 lun_info = mempool_alloc(phba->device_data_mem_pool, memory_flags);
5537 INIT_LIST_HEAD(&lun_info->listentry);
5538 lun_info->rport_data = NULL;
5539 memcpy(&lun_info->device_id.vport_wwpn, vport_wwpn,
5540 sizeof(struct lpfc_name));
5541 memcpy(&lun_info->device_id.target_wwpn, target_wwpn,
5542 sizeof(struct lpfc_name));
5543 lun_info->device_id.lun = lun;
5544 lun_info->oas_enabled = false;
5545 lun_info->priority = pri;
5546 lun_info->available = false;
5551 * lpfc_delete_device_data - frees a device data structure for OAS
5552 * @pha: Pointer to host bus adapter structure.
5553 * @lun_info: Pointer to device data structure to free.
5555 * This routine frees the previously allocated device data structure passed.
5559 lpfc_delete_device_data(struct lpfc_hba *phba,
5560 struct lpfc_device_data *lun_info)
5563 if (unlikely(!phba) || !lun_info ||
5567 if (!list_empty(&lun_info->listentry))
5568 list_del(&lun_info->listentry);
5569 mempool_free(lun_info, phba->device_data_mem_pool);
5574 * __lpfc_get_device_data - returns the device data for the specified lun
5575 * @pha: Pointer to host bus adapter structure.
5576 * @list: Point to list to search.
5577 * @vport_wwpn: Pointer to vport's wwpn information
5578 * @target_wwpn: Pointer to target's wwpn information
5579 * @lun: Lun on target
5581 * This routine searches the list passed for the specified lun's device data.
5582 * This function does not hold locks, it is the responsibility of the caller
5583 * to ensure the proper lock is held before calling the function.
5587 * Pointer to lpfc_device_data - Success
5589 struct lpfc_device_data*
5590 __lpfc_get_device_data(struct lpfc_hba *phba, struct list_head *list,
5591 struct lpfc_name *vport_wwpn,
5592 struct lpfc_name *target_wwpn, uint64_t lun)
5595 struct lpfc_device_data *lun_info;
5597 if (unlikely(!phba) || !list || !vport_wwpn || !target_wwpn ||
5601 /* Check to see if the lun is already enabled for OAS. */
5603 list_for_each_entry(lun_info, list, listentry) {
5604 if ((memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn,
5605 sizeof(struct lpfc_name)) == 0) &&
5606 (memcmp(&lun_info->device_id.target_wwpn, target_wwpn,
5607 sizeof(struct lpfc_name)) == 0) &&
5608 (lun_info->device_id.lun == lun))
5616 * lpfc_find_next_oas_lun - searches for the next oas lun
5617 * @pha: Pointer to host bus adapter structure.
5618 * @vport_wwpn: Pointer to vport's wwpn information
5619 * @target_wwpn: Pointer to target's wwpn information
5620 * @starting_lun: Pointer to the lun to start searching for
5621 * @found_vport_wwpn: Pointer to the found lun's vport wwpn information
5622 * @found_target_wwpn: Pointer to the found lun's target wwpn information
5623 * @found_lun: Pointer to the found lun.
5624 * @found_lun_status: Pointer to status of the found lun.
5626 * This routine searches the luns list for the specified lun
5627 * or the first lun for the vport/target. If the vport wwpn contains
5628 * a zero value then a specific vport is not specified. In this case
5629 * any vport which contains the lun will be considered a match. If the
5630 * target wwpn contains a zero value then a specific target is not specified.
5631 * In this case any target which contains the lun will be considered a
5632 * match. If the lun is found, the lun, vport wwpn, target wwpn and lun status
5633 * are returned. The function will also return the next lun if available.
5634 * If the next lun is not found, starting_lun parameter will be set to
5642 lpfc_find_next_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn,
5643 struct lpfc_name *target_wwpn, uint64_t *starting_lun,
5644 struct lpfc_name *found_vport_wwpn,
5645 struct lpfc_name *found_target_wwpn,
5646 uint64_t *found_lun,
5647 uint32_t *found_lun_status,
5648 uint32_t *found_lun_pri)
5651 unsigned long flags;
5652 struct lpfc_device_data *lun_info;
5653 struct lpfc_device_id *device_id;
5657 if (unlikely(!phba) || !vport_wwpn || !target_wwpn ||
5658 !starting_lun || !found_vport_wwpn ||
5659 !found_target_wwpn || !found_lun || !found_lun_status ||
5660 (*starting_lun == NO_MORE_OAS_LUN) ||
5664 lun = *starting_lun;
5665 *found_lun = NO_MORE_OAS_LUN;
5666 *starting_lun = NO_MORE_OAS_LUN;
5668 /* Search for lun or the lun closet in value */
5670 spin_lock_irqsave(&phba->devicelock, flags);
5671 list_for_each_entry(lun_info, &phba->luns, listentry) {
5672 if (((wwn_to_u64(vport_wwpn->u.wwn) == 0) ||
5673 (memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn,
5674 sizeof(struct lpfc_name)) == 0)) &&
5675 ((wwn_to_u64(target_wwpn->u.wwn) == 0) ||
5676 (memcmp(&lun_info->device_id.target_wwpn, target_wwpn,
5677 sizeof(struct lpfc_name)) == 0)) &&
5678 (lun_info->oas_enabled)) {
5679 device_id = &lun_info->device_id;
5681 ((lun == FIND_FIRST_OAS_LUN) ||
5682 (device_id->lun == lun))) {
5683 *found_lun = device_id->lun;
5684 memcpy(found_vport_wwpn,
5685 &device_id->vport_wwpn,
5686 sizeof(struct lpfc_name));
5687 memcpy(found_target_wwpn,
5688 &device_id->target_wwpn,
5689 sizeof(struct lpfc_name));
5690 if (lun_info->available)
5692 OAS_LUN_STATUS_EXISTS;
5694 *found_lun_status = 0;
5695 *found_lun_pri = lun_info->priority;
5696 if (phba->cfg_oas_flags & OAS_FIND_ANY_VPORT)
5697 memset(vport_wwpn, 0x0,
5698 sizeof(struct lpfc_name));
5699 if (phba->cfg_oas_flags & OAS_FIND_ANY_TARGET)
5700 memset(target_wwpn, 0x0,
5701 sizeof(struct lpfc_name));
5704 *starting_lun = device_id->lun;
5705 memcpy(vport_wwpn, &device_id->vport_wwpn,
5706 sizeof(struct lpfc_name));
5707 memcpy(target_wwpn, &device_id->target_wwpn,
5708 sizeof(struct lpfc_name));
5713 spin_unlock_irqrestore(&phba->devicelock, flags);
5718 * lpfc_enable_oas_lun - enables a lun for OAS operations
5719 * @pha: Pointer to host bus adapter structure.
5720 * @vport_wwpn: Pointer to vport's wwpn information
5721 * @target_wwpn: Pointer to target's wwpn information
5724 * This routine enables a lun for oas operations. The routines does so by
5725 * doing the following :
5727 * 1) Checks to see if the device data for the lun has been created.
5728 * 2) If found, sets the OAS enabled flag if not set and returns.
5729 * 3) Otherwise, creates a device data structure.
5730 * 4) If successfully created, indicates the device data is for an OAS lun,
5731 * indicates the lun is not available and add to the list of luns.
5738 lpfc_enable_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn,
5739 struct lpfc_name *target_wwpn, uint64_t lun, uint8_t pri)
5742 struct lpfc_device_data *lun_info;
5743 unsigned long flags;
5745 if (unlikely(!phba) || !vport_wwpn || !target_wwpn ||
5749 spin_lock_irqsave(&phba->devicelock, flags);
5751 /* Check to see if the device data for the lun has been created */
5752 lun_info = __lpfc_get_device_data(phba, &phba->luns, vport_wwpn,
5755 if (!lun_info->oas_enabled)
5756 lun_info->oas_enabled = true;
5757 lun_info->priority = pri;
5758 spin_unlock_irqrestore(&phba->devicelock, flags);
5762 /* Create an lun info structure and add to list of luns */
5763 lun_info = lpfc_create_device_data(phba, vport_wwpn, target_wwpn, lun,
5766 lun_info->oas_enabled = true;
5767 lun_info->priority = pri;
5768 lun_info->available = false;
5769 list_add_tail(&lun_info->listentry, &phba->luns);
5770 spin_unlock_irqrestore(&phba->devicelock, flags);
5773 spin_unlock_irqrestore(&phba->devicelock, flags);
5778 * lpfc_disable_oas_lun - disables a lun for OAS operations
5779 * @pha: Pointer to host bus adapter structure.
5780 * @vport_wwpn: Pointer to vport's wwpn information
5781 * @target_wwpn: Pointer to target's wwpn information
5784 * This routine disables a lun for oas operations. The routines does so by
5785 * doing the following :
5787 * 1) Checks to see if the device data for the lun is created.
5788 * 2) If present, clears the flag indicating this lun is for OAS.
5789 * 3) If the lun is not available by the system, the device data is
5797 lpfc_disable_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn,
5798 struct lpfc_name *target_wwpn, uint64_t lun, uint8_t pri)
5801 struct lpfc_device_data *lun_info;
5802 unsigned long flags;
5804 if (unlikely(!phba) || !vport_wwpn || !target_wwpn ||
5808 spin_lock_irqsave(&phba->devicelock, flags);
5810 /* Check to see if the lun is available. */
5811 lun_info = __lpfc_get_device_data(phba,
5812 &phba->luns, vport_wwpn,
5815 lun_info->oas_enabled = false;
5816 lun_info->priority = pri;
5817 if (!lun_info->available)
5818 lpfc_delete_device_data(phba, lun_info);
5819 spin_unlock_irqrestore(&phba->devicelock, flags);
5823 spin_unlock_irqrestore(&phba->devicelock, flags);
5828 lpfc_no_command(struct Scsi_Host *shost, struct scsi_cmnd *cmnd)
5830 return SCSI_MLQUEUE_HOST_BUSY;
5834 lpfc_no_handler(struct scsi_cmnd *cmnd)
5840 lpfc_no_slave(struct scsi_device *sdev)
5845 struct scsi_host_template lpfc_template_nvme = {
5846 .module = THIS_MODULE,
5847 .name = LPFC_DRIVER_NAME,
5848 .proc_name = LPFC_DRIVER_NAME,
5850 .queuecommand = lpfc_no_command,
5851 .eh_abort_handler = lpfc_no_handler,
5852 .eh_device_reset_handler = lpfc_no_handler,
5853 .eh_target_reset_handler = lpfc_no_handler,
5854 .eh_bus_reset_handler = lpfc_no_handler,
5855 .eh_host_reset_handler = lpfc_no_handler,
5856 .slave_alloc = lpfc_no_slave,
5857 .slave_configure = lpfc_no_slave,
5858 .scan_finished = lpfc_scan_finished,
5862 .shost_attrs = lpfc_hba_attrs,
5863 .max_sectors = 0xFFFF,
5864 .vendor_id = LPFC_NL_VENDOR_ID,
5865 .track_queue_depth = 0,
5868 struct scsi_host_template lpfc_template_no_hr = {
5869 .module = THIS_MODULE,
5870 .name = LPFC_DRIVER_NAME,
5871 .proc_name = LPFC_DRIVER_NAME,
5873 .queuecommand = lpfc_queuecommand,
5874 .eh_timed_out = fc_eh_timed_out,
5875 .eh_abort_handler = lpfc_abort_handler,
5876 .eh_device_reset_handler = lpfc_device_reset_handler,
5877 .eh_target_reset_handler = lpfc_target_reset_handler,
5878 .eh_bus_reset_handler = lpfc_bus_reset_handler,
5879 .slave_alloc = lpfc_slave_alloc,
5880 .slave_configure = lpfc_slave_configure,
5881 .slave_destroy = lpfc_slave_destroy,
5882 .scan_finished = lpfc_scan_finished,
5884 .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
5885 .cmd_per_lun = LPFC_CMD_PER_LUN,
5886 .shost_attrs = lpfc_hba_attrs,
5887 .max_sectors = 0xFFFF,
5888 .vendor_id = LPFC_NL_VENDOR_ID,
5889 .change_queue_depth = scsi_change_queue_depth,
5890 .track_queue_depth = 1,
5893 struct scsi_host_template lpfc_template = {
5894 .module = THIS_MODULE,
5895 .name = LPFC_DRIVER_NAME,
5896 .proc_name = LPFC_DRIVER_NAME,
5898 .queuecommand = lpfc_queuecommand,
5899 .eh_timed_out = fc_eh_timed_out,
5900 .eh_abort_handler = lpfc_abort_handler,
5901 .eh_device_reset_handler = lpfc_device_reset_handler,
5902 .eh_target_reset_handler = lpfc_target_reset_handler,
5903 .eh_bus_reset_handler = lpfc_bus_reset_handler,
5904 .eh_host_reset_handler = lpfc_host_reset_handler,
5905 .slave_alloc = lpfc_slave_alloc,
5906 .slave_configure = lpfc_slave_configure,
5907 .slave_destroy = lpfc_slave_destroy,
5908 .scan_finished = lpfc_scan_finished,
5910 .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
5911 .cmd_per_lun = LPFC_CMD_PER_LUN,
5912 .shost_attrs = lpfc_hba_attrs,
5913 .max_sectors = 0xFFFF,
5914 .vendor_id = LPFC_NL_VENDOR_ID,
5915 .change_queue_depth = scsi_change_queue_depth,
5916 .track_queue_depth = 1,
5919 struct scsi_host_template lpfc_vport_template = {
5920 .module = THIS_MODULE,
5921 .name = LPFC_DRIVER_NAME,
5922 .proc_name = LPFC_DRIVER_NAME,
5924 .queuecommand = lpfc_queuecommand,
5925 .eh_timed_out = fc_eh_timed_out,
5926 .eh_abort_handler = lpfc_abort_handler,
5927 .eh_device_reset_handler = lpfc_device_reset_handler,
5928 .eh_target_reset_handler = lpfc_target_reset_handler,
5929 .slave_alloc = lpfc_slave_alloc,
5930 .slave_configure = lpfc_slave_configure,
5931 .slave_destroy = lpfc_slave_destroy,
5932 .scan_finished = lpfc_scan_finished,
5934 .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
5935 .cmd_per_lun = LPFC_CMD_PER_LUN,
5936 .shost_attrs = lpfc_vport_attrs,
5937 .max_sectors = 0xFFFF,
5938 .change_queue_depth = scsi_change_queue_depth,
5939 .track_queue_depth = 1,