1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2020 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 static char *dif_op_str[] = {
66 struct scsi_dif_tuple {
67 __be16 guard_tag; /* Checksum */
68 __be16 app_tag; /* Opaque storage */
69 __be32 ref_tag; /* Target LBA or indirect LBA */
72 static struct lpfc_rport_data *
73 lpfc_rport_data_from_scsi_device(struct scsi_device *sdev)
75 struct lpfc_vport *vport = (struct lpfc_vport *)sdev->host->hostdata;
77 if (vport->phba->cfg_fof)
78 return ((struct lpfc_device_data *)sdev->hostdata)->rport_data;
80 return (struct lpfc_rport_data *)sdev->hostdata;
84 lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_io_buf *psb);
86 lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_io_buf *psb);
88 lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc);
90 static inline unsigned
91 lpfc_cmd_blksize(struct scsi_cmnd *sc)
93 return sc->device->sector_size;
96 #define LPFC_CHECK_PROTECT_GUARD 1
97 #define LPFC_CHECK_PROTECT_REF 2
98 static inline unsigned
99 lpfc_cmd_protect(struct scsi_cmnd *sc, int flag)
104 static inline unsigned
105 lpfc_cmd_guard_csum(struct scsi_cmnd *sc)
107 if (lpfc_prot_group_type(NULL, sc) == LPFC_PG_TYPE_NO_DIF)
109 if (scsi_host_get_guard(sc->device->host) == SHOST_DIX_GUARD_IP)
115 * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge.
116 * @phba: Pointer to HBA object.
117 * @lpfc_cmd: lpfc scsi command object pointer.
119 * This function is called from the lpfc_prep_task_mgmt_cmd function to
120 * set the last bit in the response sge entry.
123 lpfc_sli4_set_rsp_sgl_last(struct lpfc_hba *phba,
124 struct lpfc_io_buf *lpfc_cmd)
126 struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
129 sgl->word2 = le32_to_cpu(sgl->word2);
130 bf_set(lpfc_sli4_sge_last, sgl, 1);
131 sgl->word2 = cpu_to_le32(sgl->word2);
136 * lpfc_update_stats - Update statistical data for the command completion
137 * @vport: The virtual port on which this call is executing.
138 * @lpfc_cmd: lpfc scsi command object pointer.
140 * This function is called when there is a command completion and this
141 * function updates the statistical data for the command completion.
144 lpfc_update_stats(struct lpfc_vport *vport, struct lpfc_io_buf *lpfc_cmd)
146 struct lpfc_hba *phba = vport->phba;
147 struct lpfc_rport_data *rdata;
148 struct lpfc_nodelist *pnode;
149 struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
151 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
152 unsigned long latency;
155 if (!vport->stat_data_enabled ||
156 vport->stat_data_blocked ||
160 latency = jiffies_to_msecs((long)jiffies - (long)lpfc_cmd->start_time);
161 rdata = lpfc_cmd->rdata;
162 pnode = rdata->pnode;
164 spin_lock_irqsave(shost->host_lock, flags);
167 (phba->bucket_type == LPFC_NO_BUCKET)) {
168 spin_unlock_irqrestore(shost->host_lock, flags);
172 if (phba->bucket_type == LPFC_LINEAR_BUCKET) {
173 i = (latency + phba->bucket_step - 1 - phba->bucket_base)/
175 /* check array subscript bounds */
178 else if (i >= LPFC_MAX_BUCKET_COUNT)
179 i = LPFC_MAX_BUCKET_COUNT - 1;
181 for (i = 0; i < LPFC_MAX_BUCKET_COUNT-1; i++)
182 if (latency <= (phba->bucket_base +
183 ((1<<i)*phba->bucket_step)))
187 pnode->lat_data[i].cmd_count++;
188 spin_unlock_irqrestore(shost->host_lock, flags);
192 * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread
193 * @phba: The Hba for which this call is being executed.
195 * This routine is called when there is resource error in driver or firmware.
196 * This routine posts WORKER_RAMP_DOWN_QUEUE event for @phba. This routine
197 * posts at most 1 event each second. This routine wakes up worker thread of
198 * @phba to process WORKER_RAM_DOWN_EVENT event.
200 * This routine should be called with no lock held.
203 lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
207 unsigned long expires;
209 spin_lock_irqsave(&phba->hbalock, flags);
210 atomic_inc(&phba->num_rsrc_err);
211 phba->last_rsrc_error_time = jiffies;
213 expires = phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL;
214 if (time_after(expires, jiffies)) {
215 spin_unlock_irqrestore(&phba->hbalock, flags);
219 phba->last_ramp_down_time = jiffies;
221 spin_unlock_irqrestore(&phba->hbalock, flags);
223 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
224 evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE;
226 phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE;
227 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
230 lpfc_worker_wake_up(phba);
235 * lpfc_ramp_down_queue_handler - WORKER_RAMP_DOWN_QUEUE event handler
236 * @phba: The Hba for which this call is being executed.
238 * This routine is called to process WORKER_RAMP_DOWN_QUEUE event for worker
239 * thread.This routine reduces queue depth for all scsi device on each vport
240 * associated with @phba.
243 lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
245 struct lpfc_vport **vports;
246 struct Scsi_Host *shost;
247 struct scsi_device *sdev;
248 unsigned long new_queue_depth;
249 unsigned long num_rsrc_err;
252 num_rsrc_err = atomic_read(&phba->num_rsrc_err);
255 * The error and success command counters are global per
256 * driver instance. If another handler has already
257 * operated on this error event, just exit.
259 if (num_rsrc_err == 0)
262 vports = lpfc_create_vport_work_array(phba);
264 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
265 shost = lpfc_shost_from_vport(vports[i]);
266 shost_for_each_device(sdev, shost) {
267 if (num_rsrc_err >= sdev->queue_depth)
270 new_queue_depth = sdev->queue_depth -
272 scsi_change_queue_depth(sdev, new_queue_depth);
275 lpfc_destroy_vport_work_array(phba, vports);
276 atomic_set(&phba->num_rsrc_err, 0);
280 * lpfc_scsi_dev_block - set all scsi hosts to block state
281 * @phba: Pointer to HBA context object.
283 * This function walks vport list and set each SCSI host to block state
284 * by invoking fc_remote_port_delete() routine. This function is invoked
285 * with EEH when device's PCI slot has been permanently disabled.
288 lpfc_scsi_dev_block(struct lpfc_hba *phba)
290 struct lpfc_vport **vports;
291 struct Scsi_Host *shost;
292 struct scsi_device *sdev;
293 struct fc_rport *rport;
296 vports = lpfc_create_vport_work_array(phba);
298 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
299 shost = lpfc_shost_from_vport(vports[i]);
300 shost_for_each_device(sdev, shost) {
301 rport = starget_to_rport(scsi_target(sdev));
302 fc_remote_port_delete(rport);
305 lpfc_destroy_vport_work_array(phba, vports);
309 * lpfc_new_scsi_buf_s3 - Scsi buffer allocator for HBA with SLI3 IF spec
310 * @vport: The virtual port for which this call being executed.
311 * @num_to_allocate: The requested number of buffers to allocate.
313 * This routine allocates a scsi buffer for device with SLI-3 interface spec,
314 * the scsi buffer contains all the necessary information needed to initiate
315 * a SCSI I/O. The non-DMAable buffer region contains information to build
316 * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP,
317 * and the initial BPL. In addition to allocating memory, the FCP CMND and
318 * FCP RSP BDEs are setup in the BPL and the BPL BDE is setup in the IOCB.
321 * int - number of scsi buffers that were allocated.
322 * 0 = failure, less than num_to_alloc is a partial failure.
325 lpfc_new_scsi_buf_s3(struct lpfc_vport *vport, int num_to_alloc)
327 struct lpfc_hba *phba = vport->phba;
328 struct lpfc_io_buf *psb;
329 struct ulp_bde64 *bpl;
331 dma_addr_t pdma_phys_fcp_cmd;
332 dma_addr_t pdma_phys_fcp_rsp;
333 dma_addr_t pdma_phys_sgl;
337 bpl_size = phba->cfg_sg_dma_buf_size -
338 (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp));
340 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
341 "9067 ALLOC %d scsi_bufs: %d (%d + %d + %d)\n",
342 num_to_alloc, phba->cfg_sg_dma_buf_size,
343 (int)sizeof(struct fcp_cmnd),
344 (int)sizeof(struct fcp_rsp), bpl_size);
346 for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
347 psb = kzalloc(sizeof(struct lpfc_io_buf), GFP_KERNEL);
352 * Get memory from the pci pool to map the virt space to pci
353 * bus space for an I/O. The DMA buffer includes space for the
354 * struct fcp_cmnd, struct fcp_rsp and the number of bde's
355 * necessary to support the sg_tablesize.
357 psb->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool,
358 GFP_KERNEL, &psb->dma_handle);
365 /* Allocate iotag for psb->cur_iocbq. */
366 iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq);
368 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
369 psb->data, psb->dma_handle);
373 psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP;
375 psb->fcp_cmnd = psb->data;
376 psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd);
377 psb->dma_sgl = psb->data + sizeof(struct fcp_cmnd) +
378 sizeof(struct fcp_rsp);
380 /* Initialize local short-hand pointers. */
381 bpl = (struct ulp_bde64 *)psb->dma_sgl;
382 pdma_phys_fcp_cmd = psb->dma_handle;
383 pdma_phys_fcp_rsp = psb->dma_handle + sizeof(struct fcp_cmnd);
384 pdma_phys_sgl = psb->dma_handle + sizeof(struct fcp_cmnd) +
385 sizeof(struct fcp_rsp);
388 * The first two bdes are the FCP_CMD and FCP_RSP. The balance
389 * are sg list bdes. Initialize the first two and leave the
390 * rest for queuecommand.
392 bpl[0].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd));
393 bpl[0].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd));
394 bpl[0].tus.f.bdeSize = sizeof(struct fcp_cmnd);
395 bpl[0].tus.f.bdeFlags = BUFF_TYPE_BDE_64;
396 bpl[0].tus.w = le32_to_cpu(bpl[0].tus.w);
398 /* Setup the physical region for the FCP RSP */
399 bpl[1].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp));
400 bpl[1].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp));
401 bpl[1].tus.f.bdeSize = sizeof(struct fcp_rsp);
402 bpl[1].tus.f.bdeFlags = BUFF_TYPE_BDE_64;
403 bpl[1].tus.w = le32_to_cpu(bpl[1].tus.w);
406 * Since the IOCB for the FCP I/O is built into this
407 * lpfc_scsi_buf, initialize it with all known data now.
409 iocb = &psb->cur_iocbq.iocb;
410 iocb->un.fcpi64.bdl.ulpIoTag32 = 0;
411 if ((phba->sli_rev == 3) &&
412 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) {
413 /* fill in immediate fcp command BDE */
414 iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_IMMED;
415 iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd);
416 iocb->un.fcpi64.bdl.addrLow = offsetof(IOCB_t,
418 iocb->un.fcpi64.bdl.addrHigh = 0;
419 iocb->ulpBdeCount = 0;
421 /* fill in response BDE */
422 iocb->unsli3.fcp_ext.rbde.tus.f.bdeFlags =
424 iocb->unsli3.fcp_ext.rbde.tus.f.bdeSize =
425 sizeof(struct fcp_rsp);
426 iocb->unsli3.fcp_ext.rbde.addrLow =
427 putPaddrLow(pdma_phys_fcp_rsp);
428 iocb->unsli3.fcp_ext.rbde.addrHigh =
429 putPaddrHigh(pdma_phys_fcp_rsp);
431 iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
432 iocb->un.fcpi64.bdl.bdeSize =
433 (2 * sizeof(struct ulp_bde64));
434 iocb->un.fcpi64.bdl.addrLow =
435 putPaddrLow(pdma_phys_sgl);
436 iocb->un.fcpi64.bdl.addrHigh =
437 putPaddrHigh(pdma_phys_sgl);
438 iocb->ulpBdeCount = 1;
441 iocb->ulpClass = CLASS3;
442 psb->status = IOSTAT_SUCCESS;
443 /* Put it back into the SCSI buffer list */
444 psb->cur_iocbq.context1 = psb;
445 spin_lock_init(&psb->buf_lock);
446 lpfc_release_scsi_buf_s3(phba, psb);
454 * lpfc_sli4_vport_delete_fcp_xri_aborted -Remove all ndlp references for vport
455 * @vport: pointer to lpfc vport data structure.
457 * This routine is invoked by the vport cleanup for deletions and the cleanup
458 * for an ndlp on removal.
461 lpfc_sli4_vport_delete_fcp_xri_aborted(struct lpfc_vport *vport)
463 struct lpfc_hba *phba = vport->phba;
464 struct lpfc_io_buf *psb, *next_psb;
465 struct lpfc_sli4_hdw_queue *qp;
466 unsigned long iflag = 0;
469 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
472 spin_lock_irqsave(&phba->hbalock, iflag);
473 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
474 qp = &phba->sli4_hba.hdwq[idx];
476 spin_lock(&qp->abts_io_buf_list_lock);
477 list_for_each_entry_safe(psb, next_psb,
478 &qp->lpfc_abts_io_buf_list, list) {
479 if (psb->cur_iocbq.iocb_flag & LPFC_IO_NVME)
482 if (psb->rdata && psb->rdata->pnode &&
483 psb->rdata->pnode->vport == vport)
486 spin_unlock(&qp->abts_io_buf_list_lock);
488 spin_unlock_irqrestore(&phba->hbalock, iflag);
492 * lpfc_sli4_io_xri_aborted - Fast-path process of fcp xri abort
493 * @phba: pointer to lpfc hba data structure.
494 * @axri: pointer to the fcp xri abort wcqe structure.
496 * This routine is invoked by the worker thread to process a SLI4 fast-path
497 * FCP or NVME aborted xri.
500 lpfc_sli4_io_xri_aborted(struct lpfc_hba *phba,
501 struct sli4_wcqe_xri_aborted *axri, int idx)
503 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
504 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
505 struct lpfc_io_buf *psb, *next_psb;
506 struct lpfc_sli4_hdw_queue *qp;
507 unsigned long iflag = 0;
508 struct lpfc_iocbq *iocbq;
510 struct lpfc_nodelist *ndlp;
512 struct lpfc_sli_ring *pring = phba->sli4_hba.els_wq->pring;
514 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
517 qp = &phba->sli4_hba.hdwq[idx];
518 spin_lock_irqsave(&phba->hbalock, iflag);
519 spin_lock(&qp->abts_io_buf_list_lock);
520 list_for_each_entry_safe(psb, next_psb,
521 &qp->lpfc_abts_io_buf_list, list) {
522 if (psb->cur_iocbq.sli4_xritag == xri) {
523 list_del_init(&psb->list);
524 psb->flags &= ~LPFC_SBUF_XBUSY;
525 psb->status = IOSTAT_SUCCESS;
526 if (psb->cur_iocbq.iocb_flag & LPFC_IO_NVME) {
527 qp->abts_nvme_io_bufs--;
528 spin_unlock(&qp->abts_io_buf_list_lock);
529 spin_unlock_irqrestore(&phba->hbalock, iflag);
530 lpfc_sli4_nvme_xri_aborted(phba, axri, psb);
533 qp->abts_scsi_io_bufs--;
534 spin_unlock(&qp->abts_io_buf_list_lock);
536 if (psb->rdata && psb->rdata->pnode)
537 ndlp = psb->rdata->pnode;
541 rrq_empty = list_empty(&phba->active_rrq_list);
542 spin_unlock_irqrestore(&phba->hbalock, iflag);
544 lpfc_set_rrq_active(phba, ndlp,
545 psb->cur_iocbq.sli4_lxritag, rxid, 1);
546 lpfc_sli4_abts_err_handler(phba, ndlp, axri);
548 lpfc_release_scsi_buf_s4(phba, psb);
550 lpfc_worker_wake_up(phba);
554 spin_unlock(&qp->abts_io_buf_list_lock);
555 for (i = 1; i <= phba->sli.last_iotag; i++) {
556 iocbq = phba->sli.iocbq_lookup[i];
558 if (!(iocbq->iocb_flag & LPFC_IO_FCP) ||
559 (iocbq->iocb_flag & LPFC_IO_LIBDFC))
561 if (iocbq->sli4_xritag != xri)
563 psb = container_of(iocbq, struct lpfc_io_buf, cur_iocbq);
564 psb->flags &= ~LPFC_SBUF_XBUSY;
565 spin_unlock_irqrestore(&phba->hbalock, iflag);
566 if (!list_empty(&pring->txq))
567 lpfc_worker_wake_up(phba);
571 spin_unlock_irqrestore(&phba->hbalock, iflag);
575 * lpfc_get_scsi_buf_s3 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
576 * @phba: The HBA for which this call is being executed.
578 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
579 * and returns to caller.
583 * Pointer to lpfc_scsi_buf - Success
585 static struct lpfc_io_buf *
586 lpfc_get_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
587 struct scsi_cmnd *cmnd)
589 struct lpfc_io_buf *lpfc_cmd = NULL;
590 struct list_head *scsi_buf_list_get = &phba->lpfc_scsi_buf_list_get;
591 unsigned long iflag = 0;
593 spin_lock_irqsave(&phba->scsi_buf_list_get_lock, iflag);
594 list_remove_head(scsi_buf_list_get, lpfc_cmd, struct lpfc_io_buf,
597 spin_lock(&phba->scsi_buf_list_put_lock);
598 list_splice(&phba->lpfc_scsi_buf_list_put,
599 &phba->lpfc_scsi_buf_list_get);
600 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
601 list_remove_head(scsi_buf_list_get, lpfc_cmd,
602 struct lpfc_io_buf, list);
603 spin_unlock(&phba->scsi_buf_list_put_lock);
605 spin_unlock_irqrestore(&phba->scsi_buf_list_get_lock, iflag);
607 if (lpfc_ndlp_check_qdepth(phba, ndlp) && lpfc_cmd) {
608 atomic_inc(&ndlp->cmd_pending);
609 lpfc_cmd->flags |= LPFC_SBUF_BUMP_QDEPTH;
614 * lpfc_get_scsi_buf_s4 - Get a scsi buffer from io_buf_list of the HBA
615 * @phba: The HBA for which this call is being executed.
617 * This routine removes a scsi buffer from head of @hdwq io_buf_list
618 * and returns to caller.
622 * Pointer to lpfc_scsi_buf - Success
624 static struct lpfc_io_buf *
625 lpfc_get_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
626 struct scsi_cmnd *cmnd)
628 struct lpfc_io_buf *lpfc_cmd;
629 struct lpfc_sli4_hdw_queue *qp;
630 struct sli4_sge *sgl;
632 dma_addr_t pdma_phys_fcp_rsp;
633 dma_addr_t pdma_phys_fcp_cmd;
636 struct fcp_cmd_rsp_buf *tmp = NULL;
638 cpu = raw_smp_processor_id();
639 if (cmnd && phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_HDWQ) {
640 tag = blk_mq_unique_tag(cmnd->request);
641 idx = blk_mq_unique_tag_to_hwq(tag);
643 idx = phba->sli4_hba.cpu_map[cpu].hdwq;
646 lpfc_cmd = lpfc_get_io_buf(phba, ndlp, idx,
647 !phba->cfg_xri_rebalancing);
649 qp = &phba->sli4_hba.hdwq[idx];
654 /* Setup key fields in buffer that may have been changed
655 * if other protocols used this buffer.
657 lpfc_cmd->cur_iocbq.iocb_flag = LPFC_IO_FCP;
658 lpfc_cmd->prot_seg_cnt = 0;
659 lpfc_cmd->seg_cnt = 0;
660 lpfc_cmd->timeout = 0;
662 lpfc_cmd->start_time = jiffies;
663 lpfc_cmd->waitq = NULL;
665 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
666 lpfc_cmd->prot_data_type = 0;
668 tmp = lpfc_get_cmd_rsp_buf_per_hdwq(phba, lpfc_cmd);
670 lpfc_release_io_buf(phba, lpfc_cmd, lpfc_cmd->hdwq);
674 lpfc_cmd->fcp_cmnd = tmp->fcp_cmnd;
675 lpfc_cmd->fcp_rsp = tmp->fcp_rsp;
678 * The first two SGEs are the FCP_CMD and FCP_RSP.
679 * The balance are sg list bdes. Initialize the
680 * first two and leave the rest for queuecommand.
682 sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
683 pdma_phys_fcp_cmd = tmp->fcp_cmd_rsp_dma_handle;
684 sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd));
685 sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd));
686 sgl->word2 = le32_to_cpu(sgl->word2);
687 bf_set(lpfc_sli4_sge_last, sgl, 0);
688 sgl->word2 = cpu_to_le32(sgl->word2);
689 sgl->sge_len = cpu_to_le32(sizeof(struct fcp_cmnd));
692 /* Setup the physical region for the FCP RSP */
693 pdma_phys_fcp_rsp = pdma_phys_fcp_cmd + sizeof(struct fcp_cmnd);
694 sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp));
695 sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp));
696 sgl->word2 = le32_to_cpu(sgl->word2);
697 bf_set(lpfc_sli4_sge_last, sgl, 1);
698 sgl->word2 = cpu_to_le32(sgl->word2);
699 sgl->sge_len = cpu_to_le32(sizeof(struct fcp_rsp));
702 * Since the IOCB for the FCP I/O is built into this
703 * lpfc_io_buf, initialize it with all known data now.
705 iocb = &lpfc_cmd->cur_iocbq.iocb;
706 iocb->un.fcpi64.bdl.ulpIoTag32 = 0;
707 iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_64;
708 /* setting the BLP size to 2 * sizeof BDE may not be correct.
709 * We are setting the bpl to point to out sgl. An sgl's
710 * entries are 16 bytes, a bpl entries are 12 bytes.
712 iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd);
713 iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys_fcp_cmd);
714 iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys_fcp_cmd);
715 iocb->ulpBdeCount = 1;
717 iocb->ulpClass = CLASS3;
719 if (lpfc_ndlp_check_qdepth(phba, ndlp)) {
720 atomic_inc(&ndlp->cmd_pending);
721 lpfc_cmd->flags |= LPFC_SBUF_BUMP_QDEPTH;
726 * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
727 * @phba: The HBA for which this call is being executed.
729 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
730 * and returns to caller.
734 * Pointer to lpfc_scsi_buf - Success
736 static struct lpfc_io_buf*
737 lpfc_get_scsi_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
738 struct scsi_cmnd *cmnd)
740 return phba->lpfc_get_scsi_buf(phba, ndlp, cmnd);
744 * lpfc_release_scsi_buf - Return a scsi buffer back to hba scsi buf list
745 * @phba: The Hba for which this call is being executed.
746 * @psb: The scsi buffer which is being released.
748 * This routine releases @psb scsi buffer by adding it to tail of @phba
749 * lpfc_scsi_buf_list list.
752 lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_io_buf *psb)
754 unsigned long iflag = 0;
757 psb->prot_seg_cnt = 0;
759 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
761 psb->cur_iocbq.iocb_flag = LPFC_IO_FCP;
762 list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list_put);
763 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
767 * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list.
768 * @phba: The Hba for which this call is being executed.
769 * @psb: The scsi buffer which is being released.
771 * This routine releases @psb scsi buffer by adding it to tail of @hdwq
772 * io_buf_list list. For SLI4 XRI's are tied to the scsi buffer
773 * and cannot be reused for at least RA_TOV amount of time if it was
777 lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_io_buf *psb)
779 struct lpfc_sli4_hdw_queue *qp;
780 unsigned long iflag = 0;
783 psb->prot_seg_cnt = 0;
786 if (psb->flags & LPFC_SBUF_XBUSY) {
787 spin_lock_irqsave(&qp->abts_io_buf_list_lock, iflag);
789 list_add_tail(&psb->list, &qp->lpfc_abts_io_buf_list);
790 qp->abts_scsi_io_bufs++;
791 spin_unlock_irqrestore(&qp->abts_io_buf_list_lock, iflag);
793 lpfc_release_io_buf(phba, (struct lpfc_io_buf *)psb, qp);
798 * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list.
799 * @phba: The Hba for which this call is being executed.
800 * @psb: The scsi buffer which is being released.
802 * This routine releases @psb scsi buffer by adding it to tail of @phba
803 * lpfc_scsi_buf_list list.
806 lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_io_buf *psb)
808 if ((psb->flags & LPFC_SBUF_BUMP_QDEPTH) && psb->ndlp)
809 atomic_dec(&psb->ndlp->cmd_pending);
811 psb->flags &= ~LPFC_SBUF_BUMP_QDEPTH;
812 phba->lpfc_release_scsi_buf(phba, psb);
816 * lpfc_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
817 * @phba: The Hba for which this call is being executed.
818 * @lpfc_cmd: The scsi buffer which is going to be mapped.
820 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
821 * field of @lpfc_cmd for device with SLI-3 interface spec. This routine scans
822 * through sg elements and format the bde. This routine also initializes all
823 * IOCB fields which are dependent on scsi command request buffer.
830 lpfc_scsi_prep_dma_buf_s3(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
832 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
833 struct scatterlist *sgel = NULL;
834 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
835 struct ulp_bde64 *bpl = (struct ulp_bde64 *)lpfc_cmd->dma_sgl;
836 struct lpfc_iocbq *iocbq = &lpfc_cmd->cur_iocbq;
837 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
838 struct ulp_bde64 *data_bde = iocb_cmd->unsli3.fcp_ext.dbde;
840 uint32_t num_bde = 0;
841 int nseg, datadir = scsi_cmnd->sc_data_direction;
844 * There are three possibilities here - use scatter-gather segment, use
845 * the single mapping, or neither. Start the lpfc command prep by
846 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
850 if (scsi_sg_count(scsi_cmnd)) {
852 * The driver stores the segment count returned from pci_map_sg
853 * because this a count of dma-mappings used to map the use_sg
854 * pages. They are not guaranteed to be the same for those
855 * architectures that implement an IOMMU.
858 nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd),
859 scsi_sg_count(scsi_cmnd), datadir);
863 lpfc_cmd->seg_cnt = nseg;
864 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
865 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
866 "9064 BLKGRD: %s: Too many sg segments"
867 " from dma_map_sg. Config %d, seg_cnt"
868 " %d\n", __func__, phba->cfg_sg_seg_cnt,
870 WARN_ON_ONCE(lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt);
871 lpfc_cmd->seg_cnt = 0;
872 scsi_dma_unmap(scsi_cmnd);
877 * The driver established a maximum scatter-gather segment count
878 * during probe that limits the number of sg elements in any
879 * single scsi command. Just run through the seg_cnt and format
881 * When using SLI-3 the driver will try to fit all the BDEs into
882 * the IOCB. If it can't then the BDEs get added to a BPL as it
883 * does for SLI-2 mode.
885 scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) {
886 physaddr = sg_dma_address(sgel);
887 if (phba->sli_rev == 3 &&
888 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
889 !(iocbq->iocb_flag & DSS_SECURITY_OP) &&
890 nseg <= LPFC_EXT_DATA_BDE_COUNT) {
891 data_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
892 data_bde->tus.f.bdeSize = sg_dma_len(sgel);
893 data_bde->addrLow = putPaddrLow(physaddr);
894 data_bde->addrHigh = putPaddrHigh(physaddr);
897 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
898 bpl->tus.f.bdeSize = sg_dma_len(sgel);
899 bpl->tus.w = le32_to_cpu(bpl->tus.w);
901 le32_to_cpu(putPaddrLow(physaddr));
903 le32_to_cpu(putPaddrHigh(physaddr));
910 * Finish initializing those IOCB fields that are dependent on the
911 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
912 * explicitly reinitialized and for SLI-3 the extended bde count is
913 * explicitly reinitialized since all iocb memory resources are reused.
915 if (phba->sli_rev == 3 &&
916 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
917 !(iocbq->iocb_flag & DSS_SECURITY_OP)) {
918 if (num_bde > LPFC_EXT_DATA_BDE_COUNT) {
920 * The extended IOCB format can only fit 3 BDE or a BPL.
921 * This I/O has more than 3 BDE so the 1st data bde will
922 * be a BPL that is filled in here.
924 physaddr = lpfc_cmd->dma_handle;
925 data_bde->tus.f.bdeFlags = BUFF_TYPE_BLP_64;
926 data_bde->tus.f.bdeSize = (num_bde *
927 sizeof(struct ulp_bde64));
928 physaddr += (sizeof(struct fcp_cmnd) +
929 sizeof(struct fcp_rsp) +
930 (2 * sizeof(struct ulp_bde64)));
931 data_bde->addrHigh = putPaddrHigh(physaddr);
932 data_bde->addrLow = putPaddrLow(physaddr);
933 /* ebde count includes the response bde and data bpl */
934 iocb_cmd->unsli3.fcp_ext.ebde_count = 2;
936 /* ebde count includes the response bde and data bdes */
937 iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1);
940 iocb_cmd->un.fcpi64.bdl.bdeSize =
941 ((num_bde + 2) * sizeof(struct ulp_bde64));
942 iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1);
944 fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd));
947 * Due to difference in data length between DIF/non-DIF paths,
948 * we need to set word 4 of IOCB here
950 iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd);
954 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
956 /* Return BG_ERR_INIT if error injection is detected by Initiator */
957 #define BG_ERR_INIT 0x1
958 /* Return BG_ERR_TGT if error injection is detected by Target */
959 #define BG_ERR_TGT 0x2
960 /* Return BG_ERR_SWAP if swapping CSUM<-->CRC is required for error injection */
961 #define BG_ERR_SWAP 0x10
963 * Return BG_ERR_CHECK if disabling Guard/Ref/App checking is required for
966 #define BG_ERR_CHECK 0x20
969 * lpfc_bg_err_inject - Determine if we should inject an error
970 * @phba: The Hba for which this call is being executed.
971 * @sc: The SCSI command to examine
972 * @reftag: (out) BlockGuard reference tag for transmitted data
973 * @apptag: (out) BlockGuard application tag for transmitted data
974 * @new_guard (in) Value to replace CRC with if needed
976 * Returns BG_ERR_* bit mask or 0 if request ignored
979 lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc,
980 uint32_t *reftag, uint16_t *apptag, uint32_t new_guard)
982 struct scatterlist *sgpe; /* s/g prot entry */
983 struct lpfc_io_buf *lpfc_cmd = NULL;
984 struct scsi_dif_tuple *src = NULL;
985 struct lpfc_nodelist *ndlp;
986 struct lpfc_rport_data *rdata;
987 uint32_t op = scsi_get_prot_op(sc);
994 if (op == SCSI_PROT_NORMAL)
997 sgpe = scsi_prot_sglist(sc);
998 lba = scsi_get_lba(sc);
1000 /* First check if we need to match the LBA */
1001 if (phba->lpfc_injerr_lba != LPFC_INJERR_LBA_OFF) {
1002 blksize = lpfc_cmd_blksize(sc);
1003 numblks = (scsi_bufflen(sc) + blksize - 1) / blksize;
1005 /* Make sure we have the right LBA if one is specified */
1006 if ((phba->lpfc_injerr_lba < lba) ||
1007 (phba->lpfc_injerr_lba >= (lba + numblks)))
1010 blockoff = phba->lpfc_injerr_lba - lba;
1011 numblks = sg_dma_len(sgpe) /
1012 sizeof(struct scsi_dif_tuple);
1013 if (numblks < blockoff)
1018 /* Next check if we need to match the remote NPortID or WWPN */
1019 rdata = lpfc_rport_data_from_scsi_device(sc->device);
1020 if (rdata && rdata->pnode) {
1021 ndlp = rdata->pnode;
1023 /* Make sure we have the right NPortID if one is specified */
1024 if (phba->lpfc_injerr_nportid &&
1025 (phba->lpfc_injerr_nportid != ndlp->nlp_DID))
1029 * Make sure we have the right WWPN if one is specified.
1030 * wwn[0] should be a non-zero NAA in a good WWPN.
1032 if (phba->lpfc_injerr_wwpn.u.wwn[0] &&
1033 (memcmp(&ndlp->nlp_portname, &phba->lpfc_injerr_wwpn,
1034 sizeof(struct lpfc_name)) != 0))
1038 /* Setup a ptr to the protection data if the SCSI host provides it */
1040 src = (struct scsi_dif_tuple *)sg_virt(sgpe);
1042 lpfc_cmd = (struct lpfc_io_buf *)sc->host_scribble;
1045 /* Should we change the Reference Tag */
1047 if (phba->lpfc_injerr_wref_cnt) {
1049 case SCSI_PROT_WRITE_PASS:
1052 * For WRITE_PASS, force the error
1053 * to be sent on the wire. It should
1054 * be detected by the Target.
1055 * If blockoff != 0 error will be
1056 * inserted in middle of the IO.
1059 lpfc_printf_log(phba, KERN_ERR,
1061 "9076 BLKGRD: Injecting reftag error: "
1062 "write lba x%lx + x%x oldrefTag x%x\n",
1063 (unsigned long)lba, blockoff,
1064 be32_to_cpu(src->ref_tag));
1067 * Save the old ref_tag so we can
1068 * restore it on completion.
1071 lpfc_cmd->prot_data_type =
1073 lpfc_cmd->prot_data_segment =
1075 lpfc_cmd->prot_data =
1078 src->ref_tag = cpu_to_be32(0xDEADBEEF);
1079 phba->lpfc_injerr_wref_cnt--;
1080 if (phba->lpfc_injerr_wref_cnt == 0) {
1081 phba->lpfc_injerr_nportid = 0;
1082 phba->lpfc_injerr_lba =
1083 LPFC_INJERR_LBA_OFF;
1084 memset(&phba->lpfc_injerr_wwpn,
1085 0, sizeof(struct lpfc_name));
1087 rc = BG_ERR_TGT | BG_ERR_CHECK;
1092 case SCSI_PROT_WRITE_INSERT:
1094 * For WRITE_INSERT, force the error
1095 * to be sent on the wire. It should be
1096 * detected by the Target.
1098 /* DEADBEEF will be the reftag on the wire */
1099 *reftag = 0xDEADBEEF;
1100 phba->lpfc_injerr_wref_cnt--;
1101 if (phba->lpfc_injerr_wref_cnt == 0) {
1102 phba->lpfc_injerr_nportid = 0;
1103 phba->lpfc_injerr_lba =
1104 LPFC_INJERR_LBA_OFF;
1105 memset(&phba->lpfc_injerr_wwpn,
1106 0, sizeof(struct lpfc_name));
1108 rc = BG_ERR_TGT | BG_ERR_CHECK;
1110 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1111 "9078 BLKGRD: Injecting reftag error: "
1112 "write lba x%lx\n", (unsigned long)lba);
1114 case SCSI_PROT_WRITE_STRIP:
1116 * For WRITE_STRIP and WRITE_PASS,
1117 * force the error on data
1118 * being copied from SLI-Host to SLI-Port.
1120 *reftag = 0xDEADBEEF;
1121 phba->lpfc_injerr_wref_cnt--;
1122 if (phba->lpfc_injerr_wref_cnt == 0) {
1123 phba->lpfc_injerr_nportid = 0;
1124 phba->lpfc_injerr_lba =
1125 LPFC_INJERR_LBA_OFF;
1126 memset(&phba->lpfc_injerr_wwpn,
1127 0, sizeof(struct lpfc_name));
1131 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1132 "9077 BLKGRD: Injecting reftag error: "
1133 "write lba x%lx\n", (unsigned long)lba);
1137 if (phba->lpfc_injerr_rref_cnt) {
1139 case SCSI_PROT_READ_INSERT:
1140 case SCSI_PROT_READ_STRIP:
1141 case SCSI_PROT_READ_PASS:
1143 * For READ_STRIP and READ_PASS, force the
1144 * error on data being read off the wire. It
1145 * should force an IO error to the driver.
1147 *reftag = 0xDEADBEEF;
1148 phba->lpfc_injerr_rref_cnt--;
1149 if (phba->lpfc_injerr_rref_cnt == 0) {
1150 phba->lpfc_injerr_nportid = 0;
1151 phba->lpfc_injerr_lba =
1152 LPFC_INJERR_LBA_OFF;
1153 memset(&phba->lpfc_injerr_wwpn,
1154 0, sizeof(struct lpfc_name));
1158 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1159 "9079 BLKGRD: Injecting reftag error: "
1160 "read lba x%lx\n", (unsigned long)lba);
1166 /* Should we change the Application Tag */
1168 if (phba->lpfc_injerr_wapp_cnt) {
1170 case SCSI_PROT_WRITE_PASS:
1173 * For WRITE_PASS, force the error
1174 * to be sent on the wire. It should
1175 * be detected by the Target.
1176 * If blockoff != 0 error will be
1177 * inserted in middle of the IO.
1180 lpfc_printf_log(phba, KERN_ERR,
1182 "9080 BLKGRD: Injecting apptag error: "
1183 "write lba x%lx + x%x oldappTag x%x\n",
1184 (unsigned long)lba, blockoff,
1185 be16_to_cpu(src->app_tag));
1188 * Save the old app_tag so we can
1189 * restore it on completion.
1192 lpfc_cmd->prot_data_type =
1194 lpfc_cmd->prot_data_segment =
1196 lpfc_cmd->prot_data =
1199 src->app_tag = cpu_to_be16(0xDEAD);
1200 phba->lpfc_injerr_wapp_cnt--;
1201 if (phba->lpfc_injerr_wapp_cnt == 0) {
1202 phba->lpfc_injerr_nportid = 0;
1203 phba->lpfc_injerr_lba =
1204 LPFC_INJERR_LBA_OFF;
1205 memset(&phba->lpfc_injerr_wwpn,
1206 0, sizeof(struct lpfc_name));
1208 rc = BG_ERR_TGT | BG_ERR_CHECK;
1212 case SCSI_PROT_WRITE_INSERT:
1214 * For WRITE_INSERT, force the
1215 * error to be sent on the wire. It should be
1216 * detected by the Target.
1218 /* DEAD will be the apptag on the wire */
1220 phba->lpfc_injerr_wapp_cnt--;
1221 if (phba->lpfc_injerr_wapp_cnt == 0) {
1222 phba->lpfc_injerr_nportid = 0;
1223 phba->lpfc_injerr_lba =
1224 LPFC_INJERR_LBA_OFF;
1225 memset(&phba->lpfc_injerr_wwpn,
1226 0, sizeof(struct lpfc_name));
1228 rc = BG_ERR_TGT | BG_ERR_CHECK;
1230 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1231 "0813 BLKGRD: Injecting apptag error: "
1232 "write lba x%lx\n", (unsigned long)lba);
1234 case SCSI_PROT_WRITE_STRIP:
1236 * For WRITE_STRIP and WRITE_PASS,
1237 * force the error on data
1238 * being copied from SLI-Host to SLI-Port.
1241 phba->lpfc_injerr_wapp_cnt--;
1242 if (phba->lpfc_injerr_wapp_cnt == 0) {
1243 phba->lpfc_injerr_nportid = 0;
1244 phba->lpfc_injerr_lba =
1245 LPFC_INJERR_LBA_OFF;
1246 memset(&phba->lpfc_injerr_wwpn,
1247 0, sizeof(struct lpfc_name));
1251 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1252 "0812 BLKGRD: Injecting apptag error: "
1253 "write lba x%lx\n", (unsigned long)lba);
1257 if (phba->lpfc_injerr_rapp_cnt) {
1259 case SCSI_PROT_READ_INSERT:
1260 case SCSI_PROT_READ_STRIP:
1261 case SCSI_PROT_READ_PASS:
1263 * For READ_STRIP and READ_PASS, force the
1264 * error on data being read off the wire. It
1265 * should force an IO error to the driver.
1268 phba->lpfc_injerr_rapp_cnt--;
1269 if (phba->lpfc_injerr_rapp_cnt == 0) {
1270 phba->lpfc_injerr_nportid = 0;
1271 phba->lpfc_injerr_lba =
1272 LPFC_INJERR_LBA_OFF;
1273 memset(&phba->lpfc_injerr_wwpn,
1274 0, sizeof(struct lpfc_name));
1278 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1279 "0814 BLKGRD: Injecting apptag error: "
1280 "read lba x%lx\n", (unsigned long)lba);
1287 /* Should we change the Guard Tag */
1289 if (phba->lpfc_injerr_wgrd_cnt) {
1291 case SCSI_PROT_WRITE_PASS:
1295 case SCSI_PROT_WRITE_INSERT:
1297 * For WRITE_INSERT, force the
1298 * error to be sent on the wire. It should be
1299 * detected by the Target.
1301 phba->lpfc_injerr_wgrd_cnt--;
1302 if (phba->lpfc_injerr_wgrd_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));
1310 rc |= BG_ERR_TGT | BG_ERR_SWAP;
1311 /* Signals the caller to swap CRC->CSUM */
1313 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1314 "0817 BLKGRD: Injecting guard error: "
1315 "write lba x%lx\n", (unsigned long)lba);
1317 case SCSI_PROT_WRITE_STRIP:
1319 * For WRITE_STRIP and WRITE_PASS,
1320 * force the error on data
1321 * being copied from SLI-Host to SLI-Port.
1323 phba->lpfc_injerr_wgrd_cnt--;
1324 if (phba->lpfc_injerr_wgrd_cnt == 0) {
1325 phba->lpfc_injerr_nportid = 0;
1326 phba->lpfc_injerr_lba =
1327 LPFC_INJERR_LBA_OFF;
1328 memset(&phba->lpfc_injerr_wwpn,
1329 0, sizeof(struct lpfc_name));
1332 rc = BG_ERR_INIT | BG_ERR_SWAP;
1333 /* Signals the caller to swap CRC->CSUM */
1335 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1336 "0816 BLKGRD: Injecting guard error: "
1337 "write lba x%lx\n", (unsigned long)lba);
1341 if (phba->lpfc_injerr_rgrd_cnt) {
1343 case SCSI_PROT_READ_INSERT:
1344 case SCSI_PROT_READ_STRIP:
1345 case SCSI_PROT_READ_PASS:
1347 * For READ_STRIP and READ_PASS, force the
1348 * error on data being read off the wire. It
1349 * should force an IO error to the driver.
1351 phba->lpfc_injerr_rgrd_cnt--;
1352 if (phba->lpfc_injerr_rgrd_cnt == 0) {
1353 phba->lpfc_injerr_nportid = 0;
1354 phba->lpfc_injerr_lba =
1355 LPFC_INJERR_LBA_OFF;
1356 memset(&phba->lpfc_injerr_wwpn,
1357 0, sizeof(struct lpfc_name));
1360 rc = BG_ERR_INIT | BG_ERR_SWAP;
1361 /* Signals the caller to swap CRC->CSUM */
1363 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1364 "0818 BLKGRD: Injecting guard error: "
1365 "read lba x%lx\n", (unsigned long)lba);
1375 * lpfc_sc_to_bg_opcodes - Determine the BlockGuard opcodes to be used with
1376 * the specified SCSI command.
1377 * @phba: The Hba for which this call is being executed.
1378 * @sc: The SCSI command to examine
1379 * @txopt: (out) BlockGuard operation for transmitted data
1380 * @rxopt: (out) BlockGuard operation for received data
1382 * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
1386 lpfc_sc_to_bg_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1387 uint8_t *txop, uint8_t *rxop)
1391 if (lpfc_cmd_guard_csum(sc)) {
1392 switch (scsi_get_prot_op(sc)) {
1393 case SCSI_PROT_READ_INSERT:
1394 case SCSI_PROT_WRITE_STRIP:
1395 *rxop = BG_OP_IN_NODIF_OUT_CSUM;
1396 *txop = BG_OP_IN_CSUM_OUT_NODIF;
1399 case SCSI_PROT_READ_STRIP:
1400 case SCSI_PROT_WRITE_INSERT:
1401 *rxop = BG_OP_IN_CRC_OUT_NODIF;
1402 *txop = BG_OP_IN_NODIF_OUT_CRC;
1405 case SCSI_PROT_READ_PASS:
1406 case SCSI_PROT_WRITE_PASS:
1407 *rxop = BG_OP_IN_CRC_OUT_CSUM;
1408 *txop = BG_OP_IN_CSUM_OUT_CRC;
1411 case SCSI_PROT_NORMAL:
1413 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1414 "9063 BLKGRD: Bad op/guard:%d/IP combination\n",
1415 scsi_get_prot_op(sc));
1421 switch (scsi_get_prot_op(sc)) {
1422 case SCSI_PROT_READ_STRIP:
1423 case SCSI_PROT_WRITE_INSERT:
1424 *rxop = BG_OP_IN_CRC_OUT_NODIF;
1425 *txop = BG_OP_IN_NODIF_OUT_CRC;
1428 case SCSI_PROT_READ_PASS:
1429 case SCSI_PROT_WRITE_PASS:
1430 *rxop = BG_OP_IN_CRC_OUT_CRC;
1431 *txop = BG_OP_IN_CRC_OUT_CRC;
1434 case SCSI_PROT_READ_INSERT:
1435 case SCSI_PROT_WRITE_STRIP:
1436 *rxop = BG_OP_IN_NODIF_OUT_CRC;
1437 *txop = BG_OP_IN_CRC_OUT_NODIF;
1440 case SCSI_PROT_NORMAL:
1442 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1443 "9075 BLKGRD: Bad op/guard:%d/CRC combination\n",
1444 scsi_get_prot_op(sc));
1453 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1455 * lpfc_bg_err_opcodes - reDetermine the BlockGuard opcodes to be used with
1456 * the specified SCSI command in order to force a guard tag error.
1457 * @phba: The Hba for which this call is being executed.
1458 * @sc: The SCSI command to examine
1459 * @txopt: (out) BlockGuard operation for transmitted data
1460 * @rxopt: (out) BlockGuard operation for received data
1462 * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
1466 lpfc_bg_err_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1467 uint8_t *txop, uint8_t *rxop)
1471 if (lpfc_cmd_guard_csum(sc)) {
1472 switch (scsi_get_prot_op(sc)) {
1473 case SCSI_PROT_READ_INSERT:
1474 case SCSI_PROT_WRITE_STRIP:
1475 *rxop = BG_OP_IN_NODIF_OUT_CRC;
1476 *txop = BG_OP_IN_CRC_OUT_NODIF;
1479 case SCSI_PROT_READ_STRIP:
1480 case SCSI_PROT_WRITE_INSERT:
1481 *rxop = BG_OP_IN_CSUM_OUT_NODIF;
1482 *txop = BG_OP_IN_NODIF_OUT_CSUM;
1485 case SCSI_PROT_READ_PASS:
1486 case SCSI_PROT_WRITE_PASS:
1487 *rxop = BG_OP_IN_CSUM_OUT_CRC;
1488 *txop = BG_OP_IN_CRC_OUT_CSUM;
1491 case SCSI_PROT_NORMAL:
1497 switch (scsi_get_prot_op(sc)) {
1498 case SCSI_PROT_READ_STRIP:
1499 case SCSI_PROT_WRITE_INSERT:
1500 *rxop = BG_OP_IN_CSUM_OUT_NODIF;
1501 *txop = BG_OP_IN_NODIF_OUT_CSUM;
1504 case SCSI_PROT_READ_PASS:
1505 case SCSI_PROT_WRITE_PASS:
1506 *rxop = BG_OP_IN_CSUM_OUT_CSUM;
1507 *txop = BG_OP_IN_CSUM_OUT_CSUM;
1510 case SCSI_PROT_READ_INSERT:
1511 case SCSI_PROT_WRITE_STRIP:
1512 *rxop = BG_OP_IN_NODIF_OUT_CSUM;
1513 *txop = BG_OP_IN_CSUM_OUT_NODIF;
1516 case SCSI_PROT_NORMAL:
1527 * lpfc_bg_setup_bpl - Setup BlockGuard BPL with no protection data
1528 * @phba: The Hba for which this call is being executed.
1529 * @sc: pointer to scsi command we're working on
1530 * @bpl: pointer to buffer list for protection groups
1531 * @datacnt: number of segments of data that have been dma mapped
1533 * This function sets up BPL buffer list for protection groups of
1534 * type LPFC_PG_TYPE_NO_DIF
1536 * This is usually used when the HBA is instructed to generate
1537 * DIFs and insert them into data stream (or strip DIF from
1538 * incoming data stream)
1540 * The buffer list consists of just one protection group described
1542 * +-------------------------+
1543 * start of prot group --> | PDE_5 |
1544 * +-------------------------+
1546 * +-------------------------+
1548 * +-------------------------+
1549 * |more Data BDE's ... (opt)|
1550 * +-------------------------+
1553 * Note: Data s/g buffers have been dma mapped
1555 * Returns the number of BDEs added to the BPL.
1558 lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1559 struct ulp_bde64 *bpl, int datasegcnt)
1561 struct scatterlist *sgde = NULL; /* s/g data entry */
1562 struct lpfc_pde5 *pde5 = NULL;
1563 struct lpfc_pde6 *pde6 = NULL;
1564 dma_addr_t physaddr;
1565 int i = 0, num_bde = 0, status;
1566 int datadir = sc->sc_data_direction;
1567 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1570 uint32_t checking = 1;
1574 status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
1578 /* extract some info from the scsi command for pde*/
1579 reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
1581 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1582 rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
1584 if (rc & BG_ERR_SWAP)
1585 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
1586 if (rc & BG_ERR_CHECK)
1591 /* setup PDE5 with what we have */
1592 pde5 = (struct lpfc_pde5 *) bpl;
1593 memset(pde5, 0, sizeof(struct lpfc_pde5));
1594 bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR);
1596 /* Endianness conversion if necessary for PDE5 */
1597 pde5->word0 = cpu_to_le32(pde5->word0);
1598 pde5->reftag = cpu_to_le32(reftag);
1600 /* advance bpl and increment bde count */
1603 pde6 = (struct lpfc_pde6 *) bpl;
1605 /* setup PDE6 with the rest of the info */
1606 memset(pde6, 0, sizeof(struct lpfc_pde6));
1607 bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR);
1608 bf_set(pde6_optx, pde6, txop);
1609 bf_set(pde6_oprx, pde6, rxop);
1612 * We only need to check the data on READs, for WRITEs
1613 * protection data is automatically generated, not checked.
1615 if (datadir == DMA_FROM_DEVICE) {
1616 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD))
1617 bf_set(pde6_ce, pde6, checking);
1619 bf_set(pde6_ce, pde6, 0);
1621 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF))
1622 bf_set(pde6_re, pde6, checking);
1624 bf_set(pde6_re, pde6, 0);
1626 bf_set(pde6_ai, pde6, 1);
1627 bf_set(pde6_ae, pde6, 0);
1628 bf_set(pde6_apptagval, pde6, 0);
1630 /* Endianness conversion if necessary for PDE6 */
1631 pde6->word0 = cpu_to_le32(pde6->word0);
1632 pde6->word1 = cpu_to_le32(pde6->word1);
1633 pde6->word2 = cpu_to_le32(pde6->word2);
1635 /* advance bpl and increment bde count */
1639 /* assumption: caller has already run dma_map_sg on command data */
1640 scsi_for_each_sg(sc, sgde, datasegcnt, i) {
1641 physaddr = sg_dma_address(sgde);
1642 bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr));
1643 bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
1644 bpl->tus.f.bdeSize = sg_dma_len(sgde);
1645 if (datadir == DMA_TO_DEVICE)
1646 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1648 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
1649 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1659 * lpfc_bg_setup_bpl_prot - Setup BlockGuard BPL with protection data
1660 * @phba: The Hba for which this call is being executed.
1661 * @sc: pointer to scsi command we're working on
1662 * @bpl: pointer to buffer list for protection groups
1663 * @datacnt: number of segments of data that have been dma mapped
1664 * @protcnt: number of segment of protection data that have been dma mapped
1666 * This function sets up BPL buffer list for protection groups of
1667 * type LPFC_PG_TYPE_DIF
1669 * This is usually used when DIFs are in their own buffers,
1670 * separate from the data. The HBA can then by instructed
1671 * to place the DIFs in the outgoing stream. For read operations,
1672 * The HBA could extract the DIFs and place it in DIF buffers.
1674 * The buffer list for this type consists of one or more of the
1675 * protection groups described below:
1676 * +-------------------------+
1677 * start of first prot group --> | PDE_5 |
1678 * +-------------------------+
1680 * +-------------------------+
1681 * | PDE_7 (Prot BDE) |
1682 * +-------------------------+
1684 * +-------------------------+
1685 * |more Data BDE's ... (opt)|
1686 * +-------------------------+
1687 * start of new prot group --> | PDE_5 |
1688 * +-------------------------+
1690 * +-------------------------+
1692 * Note: It is assumed that both data and protection s/g buffers have been
1695 * Returns the number of BDEs added to the BPL.
1698 lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1699 struct ulp_bde64 *bpl, int datacnt, int protcnt)
1701 struct scatterlist *sgde = NULL; /* s/g data entry */
1702 struct scatterlist *sgpe = NULL; /* s/g prot entry */
1703 struct lpfc_pde5 *pde5 = NULL;
1704 struct lpfc_pde6 *pde6 = NULL;
1705 struct lpfc_pde7 *pde7 = NULL;
1706 dma_addr_t dataphysaddr, protphysaddr;
1707 unsigned short curr_data = 0, curr_prot = 0;
1708 unsigned int split_offset;
1709 unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder;
1710 unsigned int protgrp_blks, protgrp_bytes;
1711 unsigned int remainder, subtotal;
1713 int datadir = sc->sc_data_direction;
1714 unsigned char pgdone = 0, alldone = 0;
1716 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1719 uint32_t checking = 1;
1724 sgpe = scsi_prot_sglist(sc);
1725 sgde = scsi_sglist(sc);
1727 if (!sgpe || !sgde) {
1728 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1729 "9020 Invalid s/g entry: data=x%px prot=x%px\n",
1734 status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
1738 /* extract some info from the scsi command */
1739 blksize = lpfc_cmd_blksize(sc);
1740 reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
1742 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1743 rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
1745 if (rc & BG_ERR_SWAP)
1746 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
1747 if (rc & BG_ERR_CHECK)
1754 /* Check to see if we ran out of space */
1755 if (num_bde >= (phba->cfg_total_seg_cnt - 2))
1758 /* setup PDE5 with what we have */
1759 pde5 = (struct lpfc_pde5 *) bpl;
1760 memset(pde5, 0, sizeof(struct lpfc_pde5));
1761 bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR);
1763 /* Endianness conversion if necessary for PDE5 */
1764 pde5->word0 = cpu_to_le32(pde5->word0);
1765 pde5->reftag = cpu_to_le32(reftag);
1767 /* advance bpl and increment bde count */
1770 pde6 = (struct lpfc_pde6 *) bpl;
1772 /* setup PDE6 with the rest of the info */
1773 memset(pde6, 0, sizeof(struct lpfc_pde6));
1774 bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR);
1775 bf_set(pde6_optx, pde6, txop);
1776 bf_set(pde6_oprx, pde6, rxop);
1778 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD))
1779 bf_set(pde6_ce, pde6, checking);
1781 bf_set(pde6_ce, pde6, 0);
1783 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF))
1784 bf_set(pde6_re, pde6, checking);
1786 bf_set(pde6_re, pde6, 0);
1788 bf_set(pde6_ai, pde6, 1);
1789 bf_set(pde6_ae, pde6, 0);
1790 bf_set(pde6_apptagval, pde6, 0);
1792 /* Endianness conversion if necessary for PDE6 */
1793 pde6->word0 = cpu_to_le32(pde6->word0);
1794 pde6->word1 = cpu_to_le32(pde6->word1);
1795 pde6->word2 = cpu_to_le32(pde6->word2);
1797 /* advance bpl and increment bde count */
1801 /* setup the first BDE that points to protection buffer */
1802 protphysaddr = sg_dma_address(sgpe) + protgroup_offset;
1803 protgroup_len = sg_dma_len(sgpe) - protgroup_offset;
1805 /* must be integer multiple of the DIF block length */
1806 BUG_ON(protgroup_len % 8);
1808 pde7 = (struct lpfc_pde7 *) bpl;
1809 memset(pde7, 0, sizeof(struct lpfc_pde7));
1810 bf_set(pde7_type, pde7, LPFC_PDE7_DESCRIPTOR);
1812 pde7->addrHigh = le32_to_cpu(putPaddrHigh(protphysaddr));
1813 pde7->addrLow = le32_to_cpu(putPaddrLow(protphysaddr));
1815 protgrp_blks = protgroup_len / 8;
1816 protgrp_bytes = protgrp_blks * blksize;
1818 /* check if this pde is crossing the 4K boundary; if so split */
1819 if ((pde7->addrLow & 0xfff) + protgroup_len > 0x1000) {
1820 protgroup_remainder = 0x1000 - (pde7->addrLow & 0xfff);
1821 protgroup_offset += protgroup_remainder;
1822 protgrp_blks = protgroup_remainder / 8;
1823 protgrp_bytes = protgrp_blks * blksize;
1825 protgroup_offset = 0;
1831 /* setup BDE's for data blocks associated with DIF data */
1833 subtotal = 0; /* total bytes processed for current prot grp */
1835 /* Check to see if we ran out of space */
1836 if (num_bde >= phba->cfg_total_seg_cnt)
1840 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1841 "9065 BLKGRD:%s Invalid data segment\n",
1846 dataphysaddr = sg_dma_address(sgde) + split_offset;
1847 bpl->addrLow = le32_to_cpu(putPaddrLow(dataphysaddr));
1848 bpl->addrHigh = le32_to_cpu(putPaddrHigh(dataphysaddr));
1850 remainder = sg_dma_len(sgde) - split_offset;
1852 if ((subtotal + remainder) <= protgrp_bytes) {
1853 /* we can use this whole buffer */
1854 bpl->tus.f.bdeSize = remainder;
1857 if ((subtotal + remainder) == protgrp_bytes)
1860 /* must split this buffer with next prot grp */
1861 bpl->tus.f.bdeSize = protgrp_bytes - subtotal;
1862 split_offset += bpl->tus.f.bdeSize;
1865 subtotal += bpl->tus.f.bdeSize;
1867 if (datadir == DMA_TO_DEVICE)
1868 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1870 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
1871 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1879 /* Move to the next s/g segment if possible */
1880 sgde = sg_next(sgde);
1884 if (protgroup_offset) {
1885 /* update the reference tag */
1886 reftag += protgrp_blks;
1892 if (curr_prot == protcnt) {
1894 } else if (curr_prot < protcnt) {
1895 /* advance to next prot buffer */
1896 sgpe = sg_next(sgpe);
1899 /* update the reference tag */
1900 reftag += protgrp_blks;
1902 /* if we're here, we have a bug */
1903 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1904 "9054 BLKGRD: bug in %s\n", __func__);
1914 * lpfc_bg_setup_sgl - Setup BlockGuard SGL with no protection data
1915 * @phba: The Hba for which this call is being executed.
1916 * @sc: pointer to scsi command we're working on
1917 * @sgl: pointer to buffer list for protection groups
1918 * @datacnt: number of segments of data that have been dma mapped
1920 * This function sets up SGL buffer list for protection groups of
1921 * type LPFC_PG_TYPE_NO_DIF
1923 * This is usually used when the HBA is instructed to generate
1924 * DIFs and insert them into data stream (or strip DIF from
1925 * incoming data stream)
1927 * The buffer list consists of just one protection group described
1929 * +-------------------------+
1930 * start of prot group --> | DI_SEED |
1931 * +-------------------------+
1933 * +-------------------------+
1934 * |more Data SGE's ... (opt)|
1935 * +-------------------------+
1938 * Note: Data s/g buffers have been dma mapped
1940 * Returns the number of SGEs added to the SGL.
1943 lpfc_bg_setup_sgl(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1944 struct sli4_sge *sgl, int datasegcnt,
1945 struct lpfc_io_buf *lpfc_cmd)
1947 struct scatterlist *sgde = NULL; /* s/g data entry */
1948 struct sli4_sge_diseed *diseed = NULL;
1949 dma_addr_t physaddr;
1951 uint32_t reftag, num_sge = 0;
1953 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1956 uint32_t checking = 1;
1958 uint32_t dma_offset = 0;
1959 struct sli4_hybrid_sgl *sgl_xtra = NULL;
1961 bool lsp_just_set = false;
1963 status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
1967 /* extract some info from the scsi command for pde*/
1968 reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
1970 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1971 rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
1973 if (rc & BG_ERR_SWAP)
1974 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
1975 if (rc & BG_ERR_CHECK)
1980 /* setup DISEED with what we have */
1981 diseed = (struct sli4_sge_diseed *) sgl;
1982 memset(diseed, 0, sizeof(struct sli4_sge_diseed));
1983 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED);
1985 /* Endianness conversion if necessary */
1986 diseed->ref_tag = cpu_to_le32(reftag);
1987 diseed->ref_tag_tran = diseed->ref_tag;
1990 * We only need to check the data on READs, for WRITEs
1991 * protection data is automatically generated, not checked.
1993 if (sc->sc_data_direction == DMA_FROM_DEVICE) {
1994 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD))
1995 bf_set(lpfc_sli4_sge_dif_ce, diseed, checking);
1997 bf_set(lpfc_sli4_sge_dif_ce, diseed, 0);
1999 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF))
2000 bf_set(lpfc_sli4_sge_dif_re, diseed, checking);
2002 bf_set(lpfc_sli4_sge_dif_re, diseed, 0);
2005 /* setup DISEED with the rest of the info */
2006 bf_set(lpfc_sli4_sge_dif_optx, diseed, txop);
2007 bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop);
2009 bf_set(lpfc_sli4_sge_dif_ai, diseed, 1);
2010 bf_set(lpfc_sli4_sge_dif_me, diseed, 0);
2012 /* Endianness conversion if necessary for DISEED */
2013 diseed->word2 = cpu_to_le32(diseed->word2);
2014 diseed->word3 = cpu_to_le32(diseed->word3);
2016 /* advance bpl and increment sge count */
2020 /* assumption: caller has already run dma_map_sg on command data */
2021 sgde = scsi_sglist(sc);
2023 for (i = 0; i < datasegcnt; i++) {
2027 /* do we need to expand the segment */
2028 if (!lsp_just_set && !((j + 1) % phba->border_sge_num) &&
2029 ((datasegcnt - 1) != i)) {
2031 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_LSP);
2033 sgl_xtra = lpfc_get_sgl_per_hdwq(phba, lpfc_cmd);
2035 if (unlikely(!sgl_xtra)) {
2036 lpfc_cmd->seg_cnt = 0;
2039 sgl->addr_lo = cpu_to_le32(putPaddrLow(
2040 sgl_xtra->dma_phys_sgl));
2041 sgl->addr_hi = cpu_to_le32(putPaddrHigh(
2042 sgl_xtra->dma_phys_sgl));
2045 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA);
2048 if (!(bf_get(lpfc_sli4_sge_type, sgl) & LPFC_SGE_TYPE_LSP)) {
2049 if ((datasegcnt - 1) == i)
2050 bf_set(lpfc_sli4_sge_last, sgl, 1);
2051 physaddr = sg_dma_address(sgde);
2052 dma_len = sg_dma_len(sgde);
2053 sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr));
2054 sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr));
2056 bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
2057 sgl->word2 = cpu_to_le32(sgl->word2);
2058 sgl->sge_len = cpu_to_le32(dma_len);
2060 dma_offset += dma_len;
2061 sgde = sg_next(sgde);
2065 lsp_just_set = false;
2068 sgl->word2 = cpu_to_le32(sgl->word2);
2069 sgl->sge_len = cpu_to_le32(phba->cfg_sg_dma_buf_size);
2071 sgl = (struct sli4_sge *)sgl_xtra->dma_sgl;
2074 lsp_just_set = true;
2086 * lpfc_bg_setup_sgl_prot - Setup BlockGuard SGL with protection data
2087 * @phba: The Hba for which this call is being executed.
2088 * @sc: pointer to scsi command we're working on
2089 * @sgl: pointer to buffer list for protection groups
2090 * @datacnt: number of segments of data that have been dma mapped
2091 * @protcnt: number of segment of protection data that have been dma mapped
2093 * This function sets up SGL buffer list for protection groups of
2094 * type LPFC_PG_TYPE_DIF
2096 * This is usually used when DIFs are in their own buffers,
2097 * separate from the data. The HBA can then by instructed
2098 * to place the DIFs in the outgoing stream. For read operations,
2099 * The HBA could extract the DIFs and place it in DIF buffers.
2101 * The buffer list for this type consists of one or more of the
2102 * protection groups described below:
2103 * +-------------------------+
2104 * start of first prot group --> | DISEED |
2105 * +-------------------------+
2106 * | DIF (Prot SGE) |
2107 * +-------------------------+
2109 * +-------------------------+
2110 * |more Data SGE's ... (opt)|
2111 * +-------------------------+
2112 * start of new prot group --> | DISEED |
2113 * +-------------------------+
2115 * +-------------------------+
2117 * Note: It is assumed that both data and protection s/g buffers have been
2120 * Returns the number of SGEs added to the SGL.
2123 lpfc_bg_setup_sgl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc,
2124 struct sli4_sge *sgl, int datacnt, int protcnt,
2125 struct lpfc_io_buf *lpfc_cmd)
2127 struct scatterlist *sgde = NULL; /* s/g data entry */
2128 struct scatterlist *sgpe = NULL; /* s/g prot entry */
2129 struct sli4_sge_diseed *diseed = NULL;
2130 dma_addr_t dataphysaddr, protphysaddr;
2131 unsigned short curr_data = 0, curr_prot = 0;
2132 unsigned int split_offset;
2133 unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder;
2134 unsigned int protgrp_blks, protgrp_bytes;
2135 unsigned int remainder, subtotal;
2137 unsigned char pgdone = 0, alldone = 0;
2142 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2145 uint32_t checking = 1;
2146 uint32_t dma_offset = 0, num_sge = 0;
2148 struct sli4_hybrid_sgl *sgl_xtra = NULL;
2150 sgpe = scsi_prot_sglist(sc);
2151 sgde = scsi_sglist(sc);
2153 if (!sgpe || !sgde) {
2154 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2155 "9082 Invalid s/g entry: data=x%px prot=x%px\n",
2160 status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
2164 /* extract some info from the scsi command */
2165 blksize = lpfc_cmd_blksize(sc);
2166 reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
2168 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2169 rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
2171 if (rc & BG_ERR_SWAP)
2172 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
2173 if (rc & BG_ERR_CHECK)
2180 /* Check to see if we ran out of space */
2181 if ((num_sge >= (phba->cfg_total_seg_cnt - 2)) &&
2185 /* DISEED and DIF have to be together */
2186 if (!((j + 1) % phba->border_sge_num) ||
2187 !((j + 2) % phba->border_sge_num) ||
2188 !((j + 3) % phba->border_sge_num)) {
2192 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_LSP);
2194 sgl_xtra = lpfc_get_sgl_per_hdwq(phba, lpfc_cmd);
2196 if (unlikely(!sgl_xtra)) {
2199 sgl->addr_lo = cpu_to_le32(putPaddrLow(
2200 sgl_xtra->dma_phys_sgl));
2201 sgl->addr_hi = cpu_to_le32(putPaddrHigh(
2202 sgl_xtra->dma_phys_sgl));
2205 sgl->word2 = cpu_to_le32(sgl->word2);
2206 sgl->sge_len = cpu_to_le32(phba->cfg_sg_dma_buf_size);
2208 sgl = (struct sli4_sge *)sgl_xtra->dma_sgl;
2212 /* setup DISEED with what we have */
2213 diseed = (struct sli4_sge_diseed *) sgl;
2214 memset(diseed, 0, sizeof(struct sli4_sge_diseed));
2215 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED);
2217 /* Endianness conversion if necessary */
2218 diseed->ref_tag = cpu_to_le32(reftag);
2219 diseed->ref_tag_tran = diseed->ref_tag;
2221 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) {
2222 bf_set(lpfc_sli4_sge_dif_ce, diseed, checking);
2225 bf_set(lpfc_sli4_sge_dif_ce, diseed, 0);
2227 * When in this mode, the hardware will replace
2228 * the guard tag from the host with a
2229 * newly generated good CRC for the wire.
2230 * Switch to raw mode here to avoid this
2231 * behavior. What the host sends gets put on the wire.
2233 if (txop == BG_OP_IN_CRC_OUT_CRC) {
2234 txop = BG_OP_RAW_MODE;
2235 rxop = BG_OP_RAW_MODE;
2240 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF))
2241 bf_set(lpfc_sli4_sge_dif_re, diseed, checking);
2243 bf_set(lpfc_sli4_sge_dif_re, diseed, 0);
2245 /* setup DISEED with the rest of the info */
2246 bf_set(lpfc_sli4_sge_dif_optx, diseed, txop);
2247 bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop);
2249 bf_set(lpfc_sli4_sge_dif_ai, diseed, 1);
2250 bf_set(lpfc_sli4_sge_dif_me, diseed, 0);
2252 /* Endianness conversion if necessary for DISEED */
2253 diseed->word2 = cpu_to_le32(diseed->word2);
2254 diseed->word3 = cpu_to_le32(diseed->word3);
2256 /* advance sgl and increment bde count */
2262 /* setup the first BDE that points to protection buffer */
2263 protphysaddr = sg_dma_address(sgpe) + protgroup_offset;
2264 protgroup_len = sg_dma_len(sgpe) - protgroup_offset;
2266 /* must be integer multiple of the DIF block length */
2267 BUG_ON(protgroup_len % 8);
2269 /* Now setup DIF SGE */
2271 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DIF);
2272 sgl->addr_hi = le32_to_cpu(putPaddrHigh(protphysaddr));
2273 sgl->addr_lo = le32_to_cpu(putPaddrLow(protphysaddr));
2274 sgl->word2 = cpu_to_le32(sgl->word2);
2277 protgrp_blks = protgroup_len / 8;
2278 protgrp_bytes = protgrp_blks * blksize;
2280 /* check if DIF SGE is crossing the 4K boundary; if so split */
2281 if ((sgl->addr_lo & 0xfff) + protgroup_len > 0x1000) {
2282 protgroup_remainder = 0x1000 - (sgl->addr_lo & 0xfff);
2283 protgroup_offset += protgroup_remainder;
2284 protgrp_blks = protgroup_remainder / 8;
2285 protgrp_bytes = protgrp_blks * blksize;
2287 protgroup_offset = 0;
2293 /* setup SGE's for data blocks associated with DIF data */
2295 subtotal = 0; /* total bytes processed for current prot grp */
2301 /* Check to see if we ran out of space */
2302 if ((num_sge >= phba->cfg_total_seg_cnt) &&
2307 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2308 "9086 BLKGRD:%s Invalid data segment\n",
2313 if (!((j + 1) % phba->border_sge_num)) {
2317 bf_set(lpfc_sli4_sge_type, sgl,
2320 sgl_xtra = lpfc_get_sgl_per_hdwq(phba,
2323 if (unlikely(!sgl_xtra)) {
2326 sgl->addr_lo = cpu_to_le32(
2327 putPaddrLow(sgl_xtra->dma_phys_sgl));
2328 sgl->addr_hi = cpu_to_le32(
2329 putPaddrHigh(sgl_xtra->dma_phys_sgl));
2332 sgl->word2 = cpu_to_le32(sgl->word2);
2333 sgl->sge_len = cpu_to_le32(
2334 phba->cfg_sg_dma_buf_size);
2336 sgl = (struct sli4_sge *)sgl_xtra->dma_sgl;
2338 dataphysaddr = sg_dma_address(sgde) +
2341 remainder = sg_dma_len(sgde) - split_offset;
2343 if ((subtotal + remainder) <= protgrp_bytes) {
2344 /* we can use this whole buffer */
2345 dma_len = remainder;
2348 if ((subtotal + remainder) ==
2352 /* must split this buffer with next
2355 dma_len = protgrp_bytes - subtotal;
2356 split_offset += dma_len;
2359 subtotal += dma_len;
2362 sgl->addr_lo = cpu_to_le32(putPaddrLow(
2364 sgl->addr_hi = cpu_to_le32(putPaddrHigh(
2366 bf_set(lpfc_sli4_sge_last, sgl, 0);
2367 bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
2368 bf_set(lpfc_sli4_sge_type, sgl,
2369 LPFC_SGE_TYPE_DATA);
2371 sgl->sge_len = cpu_to_le32(dma_len);
2372 dma_offset += dma_len;
2383 /* Move to the next s/g segment if possible */
2384 sgde = sg_next(sgde);
2392 if (protgroup_offset) {
2393 /* update the reference tag */
2394 reftag += protgrp_blks;
2399 if (curr_prot == protcnt) {
2400 /* mark the last SGL */
2402 bf_set(lpfc_sli4_sge_last, sgl, 1);
2404 } else if (curr_prot < protcnt) {
2405 /* advance to next prot buffer */
2406 sgpe = sg_next(sgpe);
2408 /* update the reference tag */
2409 reftag += protgrp_blks;
2411 /* if we're here, we have a bug */
2412 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2413 "9085 BLKGRD: bug in %s\n", __func__);
2424 * lpfc_prot_group_type - Get prtotection group type of SCSI command
2425 * @phba: The Hba for which this call is being executed.
2426 * @sc: pointer to scsi command we're working on
2428 * Given a SCSI command that supports DIF, determine composition of protection
2429 * groups involved in setting up buffer lists
2431 * Returns: Protection group type (with or without DIF)
2435 lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc)
2437 int ret = LPFC_PG_TYPE_INVALID;
2438 unsigned char op = scsi_get_prot_op(sc);
2441 case SCSI_PROT_READ_STRIP:
2442 case SCSI_PROT_WRITE_INSERT:
2443 ret = LPFC_PG_TYPE_NO_DIF;
2445 case SCSI_PROT_READ_INSERT:
2446 case SCSI_PROT_WRITE_STRIP:
2447 case SCSI_PROT_READ_PASS:
2448 case SCSI_PROT_WRITE_PASS:
2449 ret = LPFC_PG_TYPE_DIF_BUF;
2453 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2454 "9021 Unsupported protection op:%d\n",
2462 * lpfc_bg_scsi_adjust_dl - Adjust SCSI data length for BlockGuard
2463 * @phba: The Hba for which this call is being executed.
2464 * @lpfc_cmd: The scsi buffer which is going to be adjusted.
2466 * Adjust the data length to account for how much data
2467 * is actually on the wire.
2469 * returns the adjusted data length
2472 lpfc_bg_scsi_adjust_dl(struct lpfc_hba *phba,
2473 struct lpfc_io_buf *lpfc_cmd)
2475 struct scsi_cmnd *sc = lpfc_cmd->pCmd;
2478 fcpdl = scsi_bufflen(sc);
2480 /* Check if there is protection data on the wire */
2481 if (sc->sc_data_direction == DMA_FROM_DEVICE) {
2482 /* Read check for protection data */
2483 if (scsi_get_prot_op(sc) == SCSI_PROT_READ_INSERT)
2487 /* Write check for protection data */
2488 if (scsi_get_prot_op(sc) == SCSI_PROT_WRITE_STRIP)
2493 * If we are in DIF Type 1 mode every data block has a 8 byte
2494 * DIF (trailer) attached to it. Must ajust FCP data length
2495 * to account for the protection data.
2497 fcpdl += (fcpdl / lpfc_cmd_blksize(sc)) * 8;
2503 * lpfc_bg_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
2504 * @phba: The Hba for which this call is being executed.
2505 * @lpfc_cmd: The scsi buffer which is going to be prep'ed.
2507 * This is the protection/DIF aware version of
2508 * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the
2509 * two functions eventually, but for now, it's here.
2510 * RETURNS 0 - SUCCESS,
2511 * 1 - Failed DMA map, retry.
2512 * 2 - Invalid scsi cmd or prot-type. Do not rety.
2515 lpfc_bg_scsi_prep_dma_buf_s3(struct lpfc_hba *phba,
2516 struct lpfc_io_buf *lpfc_cmd)
2518 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
2519 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
2520 struct ulp_bde64 *bpl = (struct ulp_bde64 *)lpfc_cmd->dma_sgl;
2521 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
2522 uint32_t num_bde = 0;
2523 int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction;
2524 int prot_group_type = 0;
2527 struct lpfc_vport *vport = phba->pport;
2530 * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd
2531 * fcp_rsp regions to the first data bde entry
2534 if (scsi_sg_count(scsi_cmnd)) {
2536 * The driver stores the segment count returned from pci_map_sg
2537 * because this a count of dma-mappings used to map the use_sg
2538 * pages. They are not guaranteed to be the same for those
2539 * architectures that implement an IOMMU.
2541 datasegcnt = dma_map_sg(&phba->pcidev->dev,
2542 scsi_sglist(scsi_cmnd),
2543 scsi_sg_count(scsi_cmnd), datadir);
2544 if (unlikely(!datasegcnt))
2547 lpfc_cmd->seg_cnt = datasegcnt;
2549 /* First check if data segment count from SCSI Layer is good */
2550 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
2551 WARN_ON_ONCE(lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt);
2556 prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd);
2558 switch (prot_group_type) {
2559 case LPFC_PG_TYPE_NO_DIF:
2561 /* Here we need to add a PDE5 and PDE6 to the count */
2562 if ((lpfc_cmd->seg_cnt + 2) > phba->cfg_total_seg_cnt) {
2567 num_bde = lpfc_bg_setup_bpl(phba, scsi_cmnd, bpl,
2569 /* we should have 2 or more entries in buffer list */
2576 case LPFC_PG_TYPE_DIF_BUF:
2578 * This type indicates that protection buffers are
2579 * passed to the driver, so that needs to be prepared
2582 protsegcnt = dma_map_sg(&phba->pcidev->dev,
2583 scsi_prot_sglist(scsi_cmnd),
2584 scsi_prot_sg_count(scsi_cmnd), datadir);
2585 if (unlikely(!protsegcnt)) {
2586 scsi_dma_unmap(scsi_cmnd);
2590 lpfc_cmd->prot_seg_cnt = protsegcnt;
2593 * There is a minimun of 4 BPLs used for every
2594 * protection data segment.
2596 if ((lpfc_cmd->prot_seg_cnt * 4) >
2597 (phba->cfg_total_seg_cnt - 2)) {
2602 num_bde = lpfc_bg_setup_bpl_prot(phba, scsi_cmnd, bpl,
2603 datasegcnt, protsegcnt);
2604 /* we should have 3 or more entries in buffer list */
2605 if ((num_bde < 3) ||
2606 (num_bde > phba->cfg_total_seg_cnt)) {
2612 case LPFC_PG_TYPE_INVALID:
2614 scsi_dma_unmap(scsi_cmnd);
2615 lpfc_cmd->seg_cnt = 0;
2617 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2618 "9022 Unexpected protection group %i\n",
2625 * Finish initializing those IOCB fields that are dependent on the
2626 * scsi_cmnd request_buffer. Note that the bdeSize is explicitly
2627 * reinitialized since all iocb memory resources are used many times
2628 * for transmit, receive, and continuation bpl's.
2630 iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
2631 iocb_cmd->un.fcpi64.bdl.bdeSize += (num_bde * sizeof(struct ulp_bde64));
2632 iocb_cmd->ulpBdeCount = 1;
2633 iocb_cmd->ulpLe = 1;
2635 fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd);
2636 fcp_cmnd->fcpDl = be32_to_cpu(fcpdl);
2639 * Due to difference in data length between DIF/non-DIF paths,
2640 * we need to set word 4 of IOCB here
2642 iocb_cmd->un.fcpi.fcpi_parm = fcpdl;
2645 * For First burst, we may need to adjust the initial transfer
2648 if (iocb_cmd->un.fcpi.fcpi_XRdy &&
2649 (fcpdl < vport->cfg_first_burst_size))
2650 iocb_cmd->un.fcpi.fcpi_XRdy = fcpdl;
2654 if (lpfc_cmd->seg_cnt)
2655 scsi_dma_unmap(scsi_cmnd);
2656 if (lpfc_cmd->prot_seg_cnt)
2657 dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd),
2658 scsi_prot_sg_count(scsi_cmnd),
2659 scsi_cmnd->sc_data_direction);
2661 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2662 "9023 Cannot setup S/G List for HBA"
2663 "IO segs %d/%d BPL %d SCSI %d: %d %d\n",
2664 lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt,
2665 phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt,
2666 prot_group_type, num_bde);
2668 lpfc_cmd->seg_cnt = 0;
2669 lpfc_cmd->prot_seg_cnt = 0;
2674 * This function calcuates the T10 DIF guard tag
2675 * on the specified data using a CRC algorithmn
2679 lpfc_bg_crc(uint8_t *data, int count)
2684 crc = crc_t10dif(data, count);
2685 x = cpu_to_be16(crc);
2690 * This function calcuates the T10 DIF guard tag
2691 * on the specified data using a CSUM algorithmn
2692 * using ip_compute_csum.
2695 lpfc_bg_csum(uint8_t *data, int count)
2699 ret = ip_compute_csum(data, count);
2704 * This function examines the protection data to try to determine
2705 * what type of T10-DIF error occurred.
2708 lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
2710 struct scatterlist *sgpe; /* s/g prot entry */
2711 struct scatterlist *sgde; /* s/g data entry */
2712 struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
2713 struct scsi_dif_tuple *src = NULL;
2714 uint8_t *data_src = NULL;
2716 uint16_t start_app_tag, app_tag;
2717 uint32_t start_ref_tag, ref_tag;
2718 int prot, protsegcnt;
2719 int err_type, len, data_len;
2720 int chk_ref, chk_app, chk_guard;
2724 err_type = BGS_GUARD_ERR_MASK;
2728 /* First check to see if there is protection data to examine */
2729 prot = scsi_get_prot_op(cmd);
2730 if ((prot == SCSI_PROT_READ_STRIP) ||
2731 (prot == SCSI_PROT_WRITE_INSERT) ||
2732 (prot == SCSI_PROT_NORMAL))
2735 /* Currently the driver just supports ref_tag and guard_tag checking */
2740 /* Setup a ptr to the protection data provided by the SCSI host */
2741 sgpe = scsi_prot_sglist(cmd);
2742 protsegcnt = lpfc_cmd->prot_seg_cnt;
2744 if (sgpe && protsegcnt) {
2747 * We will only try to verify guard tag if the segment
2748 * data length is a multiple of the blksize.
2750 sgde = scsi_sglist(cmd);
2751 blksize = lpfc_cmd_blksize(cmd);
2752 data_src = (uint8_t *)sg_virt(sgde);
2753 data_len = sgde->length;
2754 if ((data_len & (blksize - 1)) == 0)
2757 src = (struct scsi_dif_tuple *)sg_virt(sgpe);
2758 start_ref_tag = (uint32_t)scsi_get_lba(cmd); /* Truncate LBA */
2759 start_app_tag = src->app_tag;
2761 while (src && protsegcnt) {
2765 * First check to see if a protection data
2768 if ((src->ref_tag == T10_PI_REF_ESCAPE) ||
2769 (src->app_tag == T10_PI_APP_ESCAPE)) {
2774 /* First Guard Tag checking */
2776 guard_tag = src->guard_tag;
2777 if (lpfc_cmd_guard_csum(cmd))
2778 sum = lpfc_bg_csum(data_src,
2781 sum = lpfc_bg_crc(data_src,
2783 if ((guard_tag != sum)) {
2784 err_type = BGS_GUARD_ERR_MASK;
2789 /* Reference Tag checking */
2790 ref_tag = be32_to_cpu(src->ref_tag);
2791 if (chk_ref && (ref_tag != start_ref_tag)) {
2792 err_type = BGS_REFTAG_ERR_MASK;
2797 /* App Tag checking */
2798 app_tag = src->app_tag;
2799 if (chk_app && (app_tag != start_app_tag)) {
2800 err_type = BGS_APPTAG_ERR_MASK;
2804 len -= sizeof(struct scsi_dif_tuple);
2809 data_src += blksize;
2810 data_len -= blksize;
2813 * Are we at the end of the Data segment?
2814 * The data segment is only used for Guard
2817 if (chk_guard && (data_len == 0)) {
2819 sgde = sg_next(sgde);
2823 data_src = (uint8_t *)sg_virt(sgde);
2824 data_len = sgde->length;
2825 if ((data_len & (blksize - 1)) == 0)
2830 /* Goto the next Protection data segment */
2831 sgpe = sg_next(sgpe);
2833 src = (struct scsi_dif_tuple *)sg_virt(sgpe);
2842 if (err_type == BGS_GUARD_ERR_MASK) {
2843 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
2845 cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
2846 SAM_STAT_CHECK_CONDITION;
2847 phba->bg_guard_err_cnt++;
2848 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
2849 "9069 BLKGRD: LBA %lx grd_tag error %x != %x\n",
2850 (unsigned long)scsi_get_lba(cmd),
2853 } else if (err_type == BGS_REFTAG_ERR_MASK) {
2854 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
2856 cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
2857 SAM_STAT_CHECK_CONDITION;
2859 phba->bg_reftag_err_cnt++;
2860 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
2861 "9066 BLKGRD: LBA %lx ref_tag error %x != %x\n",
2862 (unsigned long)scsi_get_lba(cmd),
2863 ref_tag, start_ref_tag);
2865 } else if (err_type == BGS_APPTAG_ERR_MASK) {
2866 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
2868 cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
2869 SAM_STAT_CHECK_CONDITION;
2871 phba->bg_apptag_err_cnt++;
2872 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
2873 "9041 BLKGRD: LBA %lx app_tag error %x != %x\n",
2874 (unsigned long)scsi_get_lba(cmd),
2875 app_tag, start_app_tag);
2881 * This function checks for BlockGuard errors detected by
2882 * the HBA. In case of errors, the ASC/ASCQ fields in the
2883 * sense buffer will be set accordingly, paired with
2884 * ILLEGAL_REQUEST to signal to the kernel that the HBA
2885 * detected corruption.
2888 * 0 - No error found
2889 * 1 - BlockGuard error found
2890 * -1 - Internal error (bad profile, ...etc)
2893 lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
2894 struct lpfc_iocbq *pIocbOut)
2896 struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
2897 struct sli3_bg_fields *bgf = &pIocbOut->iocb.unsli3.sli3_bg;
2899 uint32_t bghm = bgf->bghm;
2900 uint32_t bgstat = bgf->bgstat;
2901 uint64_t failing_sector = 0;
2903 if (lpfc_bgs_get_invalid_prof(bgstat)) {
2904 cmd->result = DID_ERROR << 16;
2905 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
2906 "9072 BLKGRD: Invalid BG Profile in cmd"
2907 " 0x%x lba 0x%llx blk cnt 0x%x "
2908 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
2909 (unsigned long long)scsi_get_lba(cmd),
2910 blk_rq_sectors(cmd->request), bgstat, bghm);
2915 if (lpfc_bgs_get_uninit_dif_block(bgstat)) {
2916 cmd->result = DID_ERROR << 16;
2917 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
2918 "9073 BLKGRD: Invalid BG PDIF Block in cmd"
2919 " 0x%x lba 0x%llx blk cnt 0x%x "
2920 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
2921 (unsigned long long)scsi_get_lba(cmd),
2922 blk_rq_sectors(cmd->request), bgstat, bghm);
2927 if (lpfc_bgs_get_guard_err(bgstat)) {
2930 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
2932 cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
2933 SAM_STAT_CHECK_CONDITION;
2934 phba->bg_guard_err_cnt++;
2935 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
2936 "9055 BLKGRD: Guard Tag error in cmd"
2937 " 0x%x lba 0x%llx blk cnt 0x%x "
2938 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
2939 (unsigned long long)scsi_get_lba(cmd),
2940 blk_rq_sectors(cmd->request), bgstat, bghm);
2943 if (lpfc_bgs_get_reftag_err(bgstat)) {
2946 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
2948 cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
2949 SAM_STAT_CHECK_CONDITION;
2951 phba->bg_reftag_err_cnt++;
2952 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
2953 "9056 BLKGRD: Ref Tag error in cmd"
2954 " 0x%x lba 0x%llx blk cnt 0x%x "
2955 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
2956 (unsigned long long)scsi_get_lba(cmd),
2957 blk_rq_sectors(cmd->request), bgstat, bghm);
2960 if (lpfc_bgs_get_apptag_err(bgstat)) {
2963 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
2965 cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
2966 SAM_STAT_CHECK_CONDITION;
2968 phba->bg_apptag_err_cnt++;
2969 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
2970 "9061 BLKGRD: App Tag error in cmd"
2971 " 0x%x lba 0x%llx blk cnt 0x%x "
2972 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
2973 (unsigned long long)scsi_get_lba(cmd),
2974 blk_rq_sectors(cmd->request), bgstat, bghm);
2977 if (lpfc_bgs_get_hi_water_mark_present(bgstat)) {
2979 * setup sense data descriptor 0 per SPC-4 as an information
2980 * field, and put the failing LBA in it.
2981 * This code assumes there was also a guard/app/ref tag error
2984 cmd->sense_buffer[7] = 0xc; /* Additional sense length */
2985 cmd->sense_buffer[8] = 0; /* Information descriptor type */
2986 cmd->sense_buffer[9] = 0xa; /* Additional descriptor length */
2987 cmd->sense_buffer[10] = 0x80; /* Validity bit */
2989 /* bghm is a "on the wire" FC frame based count */
2990 switch (scsi_get_prot_op(cmd)) {
2991 case SCSI_PROT_READ_INSERT:
2992 case SCSI_PROT_WRITE_STRIP:
2993 bghm /= cmd->device->sector_size;
2995 case SCSI_PROT_READ_STRIP:
2996 case SCSI_PROT_WRITE_INSERT:
2997 case SCSI_PROT_READ_PASS:
2998 case SCSI_PROT_WRITE_PASS:
2999 bghm /= (cmd->device->sector_size +
3000 sizeof(struct scsi_dif_tuple));
3004 failing_sector = scsi_get_lba(cmd);
3005 failing_sector += bghm;
3007 /* Descriptor Information */
3008 put_unaligned_be64(failing_sector, &cmd->sense_buffer[12]);
3012 /* No error was reported - problem in FW? */
3013 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
3014 "9057 BLKGRD: Unknown error in cmd"
3015 " 0x%x lba 0x%llx blk cnt 0x%x "
3016 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
3017 (unsigned long long)scsi_get_lba(cmd),
3018 blk_rq_sectors(cmd->request), bgstat, bghm);
3020 /* Calcuate what type of error it was */
3021 lpfc_calc_bg_err(phba, lpfc_cmd);
3028 * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
3029 * @phba: The Hba for which this call is being executed.
3030 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3032 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
3033 * field of @lpfc_cmd for device with SLI-4 interface spec.
3036 * 2 - Error - Do not retry
3041 lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
3043 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
3044 struct scatterlist *sgel = NULL;
3045 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
3046 struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
3047 struct sli4_sge *first_data_sgl;
3048 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
3049 dma_addr_t physaddr;
3050 uint32_t num_bde = 0;
3052 uint32_t dma_offset = 0;
3054 struct ulp_bde64 *bde;
3055 bool lsp_just_set = false;
3056 struct sli4_hybrid_sgl *sgl_xtra = NULL;
3059 * There are three possibilities here - use scatter-gather segment, use
3060 * the single mapping, or neither. Start the lpfc command prep by
3061 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
3064 if (scsi_sg_count(scsi_cmnd)) {
3066 * The driver stores the segment count returned from pci_map_sg
3067 * because this a count of dma-mappings used to map the use_sg
3068 * pages. They are not guaranteed to be the same for those
3069 * architectures that implement an IOMMU.
3072 nseg = scsi_dma_map(scsi_cmnd);
3073 if (unlikely(nseg <= 0))
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, 0);
3079 sgl->word2 = cpu_to_le32(sgl->word2);
3081 first_data_sgl = sgl;
3082 lpfc_cmd->seg_cnt = nseg;
3083 if (!phba->cfg_xpsgl &&
3084 lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
3085 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3087 " %s: Too many sg segments from "
3088 "dma_map_sg. Config %d, seg_cnt %d\n",
3089 __func__, phba->cfg_sg_seg_cnt,
3091 WARN_ON_ONCE(lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt);
3092 lpfc_cmd->seg_cnt = 0;
3093 scsi_dma_unmap(scsi_cmnd);
3098 * The driver established a maximum scatter-gather segment count
3099 * during probe that limits the number of sg elements in any
3100 * single scsi command. Just run through the seg_cnt and format
3102 * When using SLI-3 the driver will try to fit all the BDEs into
3103 * the IOCB. If it can't then the BDEs get added to a BPL as it
3104 * does for SLI-2 mode.
3107 /* for tracking segment boundaries */
3108 sgel = scsi_sglist(scsi_cmnd);
3110 for (i = 0; i < nseg; i++) {
3112 if ((num_bde + 1) == nseg) {
3113 bf_set(lpfc_sli4_sge_last, sgl, 1);
3114 bf_set(lpfc_sli4_sge_type, sgl,
3115 LPFC_SGE_TYPE_DATA);
3117 bf_set(lpfc_sli4_sge_last, sgl, 0);
3119 /* do we need to expand the segment */
3120 if (!lsp_just_set &&
3121 !((j + 1) % phba->border_sge_num) &&
3122 ((nseg - 1) != i)) {
3124 bf_set(lpfc_sli4_sge_type, sgl,
3127 sgl_xtra = lpfc_get_sgl_per_hdwq(
3130 if (unlikely(!sgl_xtra)) {
3131 lpfc_cmd->seg_cnt = 0;
3132 scsi_dma_unmap(scsi_cmnd);
3135 sgl->addr_lo = cpu_to_le32(putPaddrLow(
3136 sgl_xtra->dma_phys_sgl));
3137 sgl->addr_hi = cpu_to_le32(putPaddrHigh(
3138 sgl_xtra->dma_phys_sgl));
3141 bf_set(lpfc_sli4_sge_type, sgl,
3142 LPFC_SGE_TYPE_DATA);
3146 if (!(bf_get(lpfc_sli4_sge_type, sgl) &
3147 LPFC_SGE_TYPE_LSP)) {
3148 if ((nseg - 1) == i)
3149 bf_set(lpfc_sli4_sge_last, sgl, 1);
3151 physaddr = sg_dma_address(sgel);
3152 dma_len = sg_dma_len(sgel);
3153 sgl->addr_lo = cpu_to_le32(putPaddrLow(
3155 sgl->addr_hi = cpu_to_le32(putPaddrHigh(
3158 bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
3159 sgl->word2 = cpu_to_le32(sgl->word2);
3160 sgl->sge_len = cpu_to_le32(dma_len);
3162 dma_offset += dma_len;
3163 sgel = sg_next(sgel);
3166 lsp_just_set = false;
3169 sgl->word2 = cpu_to_le32(sgl->word2);
3170 sgl->sge_len = cpu_to_le32(
3171 phba->cfg_sg_dma_buf_size);
3173 sgl = (struct sli4_sge *)sgl_xtra->dma_sgl;
3176 lsp_just_set = true;
3182 * Setup the first Payload BDE. For FCoE we just key off
3183 * Performance Hints, for FC we use lpfc_enable_pbde.
3184 * We populate words 13-15 of IOCB/WQE.
3186 if ((phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) ||
3187 phba->cfg_enable_pbde) {
3188 bde = (struct ulp_bde64 *)
3189 &(iocb_cmd->unsli3.sli3Words[5]);
3190 bde->addrLow = first_data_sgl->addr_lo;
3191 bde->addrHigh = first_data_sgl->addr_hi;
3192 bde->tus.f.bdeSize =
3193 le32_to_cpu(first_data_sgl->sge_len);
3194 bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
3195 bde->tus.w = cpu_to_le32(bde->tus.w);
3199 /* clear the last flag in the fcp_rsp map entry */
3200 sgl->word2 = le32_to_cpu(sgl->word2);
3201 bf_set(lpfc_sli4_sge_last, sgl, 1);
3202 sgl->word2 = cpu_to_le32(sgl->word2);
3204 if ((phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) ||
3205 phba->cfg_enable_pbde) {
3206 bde = (struct ulp_bde64 *)
3207 &(iocb_cmd->unsli3.sli3Words[5]);
3208 memset(bde, 0, (sizeof(uint32_t) * 3));
3213 * Finish initializing those IOCB fields that are dependent on the
3214 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
3215 * explicitly reinitialized.
3216 * all iocb memory resources are reused.
3218 fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd));
3221 * Due to difference in data length between DIF/non-DIF paths,
3222 * we need to set word 4 of IOCB here
3224 iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd);
3227 * If the OAS driver feature is enabled and the lun is enabled for
3228 * OAS, set the oas iocb related flags.
3230 if ((phba->cfg_fof) && ((struct lpfc_device_data *)
3231 scsi_cmnd->device->hostdata)->oas_enabled) {
3232 lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF);
3233 lpfc_cmd->cur_iocbq.priority = ((struct lpfc_device_data *)
3234 scsi_cmnd->device->hostdata)->priority;
3241 * lpfc_bg_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
3242 * @phba: The Hba for which this call is being executed.
3243 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3245 * This is the protection/DIF aware version of
3246 * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the
3247 * two functions eventually, but for now, it's here
3249 * 2 - Error - Do not retry
3254 lpfc_bg_scsi_prep_dma_buf_s4(struct lpfc_hba *phba,
3255 struct lpfc_io_buf *lpfc_cmd)
3257 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
3258 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
3259 struct sli4_sge *sgl = (struct sli4_sge *)(lpfc_cmd->dma_sgl);
3260 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
3261 uint32_t num_sge = 0;
3262 int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction;
3263 int prot_group_type = 0;
3266 struct lpfc_vport *vport = phba->pport;
3269 * Start the lpfc command prep by bumping the sgl beyond fcp_cmnd
3270 * fcp_rsp regions to the first data sge entry
3272 if (scsi_sg_count(scsi_cmnd)) {
3274 * The driver stores the segment count returned from pci_map_sg
3275 * because this a count of dma-mappings used to map the use_sg
3276 * pages. They are not guaranteed to be the same for those
3277 * architectures that implement an IOMMU.
3279 datasegcnt = dma_map_sg(&phba->pcidev->dev,
3280 scsi_sglist(scsi_cmnd),
3281 scsi_sg_count(scsi_cmnd), datadir);
3282 if (unlikely(!datasegcnt))
3286 /* clear the last flag in the fcp_rsp map entry */
3287 sgl->word2 = le32_to_cpu(sgl->word2);
3288 bf_set(lpfc_sli4_sge_last, sgl, 0);
3289 sgl->word2 = cpu_to_le32(sgl->word2);
3292 lpfc_cmd->seg_cnt = datasegcnt;
3294 /* First check if data segment count from SCSI Layer is good */
3295 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt &&
3297 WARN_ON_ONCE(lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt);
3302 prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd);
3304 switch (prot_group_type) {
3305 case LPFC_PG_TYPE_NO_DIF:
3306 /* Here we need to add a DISEED to the count */
3307 if (((lpfc_cmd->seg_cnt + 1) >
3308 phba->cfg_total_seg_cnt) &&
3314 num_sge = lpfc_bg_setup_sgl(phba, scsi_cmnd, sgl,
3315 datasegcnt, lpfc_cmd);
3317 /* we should have 2 or more entries in buffer list */
3324 case LPFC_PG_TYPE_DIF_BUF:
3326 * This type indicates that protection buffers are
3327 * passed to the driver, so that needs to be prepared
3330 protsegcnt = dma_map_sg(&phba->pcidev->dev,
3331 scsi_prot_sglist(scsi_cmnd),
3332 scsi_prot_sg_count(scsi_cmnd), datadir);
3333 if (unlikely(!protsegcnt)) {
3334 scsi_dma_unmap(scsi_cmnd);
3338 lpfc_cmd->prot_seg_cnt = protsegcnt;
3340 * There is a minimun of 3 SGEs used for every
3341 * protection data segment.
3343 if (((lpfc_cmd->prot_seg_cnt * 3) >
3344 (phba->cfg_total_seg_cnt - 2)) &&
3350 num_sge = lpfc_bg_setup_sgl_prot(phba, scsi_cmnd, sgl,
3351 datasegcnt, protsegcnt, lpfc_cmd);
3353 /* we should have 3 or more entries in buffer list */
3355 (num_sge > phba->cfg_total_seg_cnt &&
3356 !phba->cfg_xpsgl)) {
3362 case LPFC_PG_TYPE_INVALID:
3364 scsi_dma_unmap(scsi_cmnd);
3365 lpfc_cmd->seg_cnt = 0;
3367 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3368 "9083 Unexpected protection group %i\n",
3374 switch (scsi_get_prot_op(scsi_cmnd)) {
3375 case SCSI_PROT_WRITE_STRIP:
3376 case SCSI_PROT_READ_STRIP:
3377 lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_STRIP;
3379 case SCSI_PROT_WRITE_INSERT:
3380 case SCSI_PROT_READ_INSERT:
3381 lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_INSERT;
3383 case SCSI_PROT_WRITE_PASS:
3384 case SCSI_PROT_READ_PASS:
3385 lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_PASS;
3389 fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd);
3390 fcp_cmnd->fcpDl = be32_to_cpu(fcpdl);
3393 * Due to difference in data length between DIF/non-DIF paths,
3394 * we need to set word 4 of IOCB here
3396 iocb_cmd->un.fcpi.fcpi_parm = fcpdl;
3399 * For First burst, we may need to adjust the initial transfer
3402 if (iocb_cmd->un.fcpi.fcpi_XRdy &&
3403 (fcpdl < vport->cfg_first_burst_size))
3404 iocb_cmd->un.fcpi.fcpi_XRdy = fcpdl;
3407 * If the OAS driver feature is enabled and the lun is enabled for
3408 * OAS, set the oas iocb related flags.
3410 if ((phba->cfg_fof) && ((struct lpfc_device_data *)
3411 scsi_cmnd->device->hostdata)->oas_enabled)
3412 lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF);
3416 if (lpfc_cmd->seg_cnt)
3417 scsi_dma_unmap(scsi_cmnd);
3418 if (lpfc_cmd->prot_seg_cnt)
3419 dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd),
3420 scsi_prot_sg_count(scsi_cmnd),
3421 scsi_cmnd->sc_data_direction);
3423 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3424 "9084 Cannot setup S/G List for HBA"
3425 "IO segs %d/%d SGL %d SCSI %d: %d %d\n",
3426 lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt,
3427 phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt,
3428 prot_group_type, num_sge);
3430 lpfc_cmd->seg_cnt = 0;
3431 lpfc_cmd->prot_seg_cnt = 0;
3436 * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
3437 * @phba: The Hba for which this call is being executed.
3438 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3440 * This routine wraps the actual DMA mapping function pointer from the
3448 lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
3450 return phba->lpfc_scsi_prep_dma_buf(phba, lpfc_cmd);
3454 * lpfc_bg_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
3456 * @phba: The Hba for which this call is being executed.
3457 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3459 * This routine wraps the actual DMA mapping function pointer from the
3467 lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
3469 return phba->lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd);
3473 * lpfc_send_scsi_error_event - Posts an event when there is SCSI error
3474 * @phba: Pointer to hba context object.
3475 * @vport: Pointer to vport object.
3476 * @lpfc_cmd: Pointer to lpfc scsi command which reported the error.
3477 * @rsp_iocb: Pointer to response iocb object which reported error.
3479 * This function posts an event when there is a SCSI command reporting
3480 * error from the scsi device.
3483 lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport,
3484 struct lpfc_io_buf *lpfc_cmd, struct lpfc_iocbq *rsp_iocb) {
3485 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
3486 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
3487 uint32_t resp_info = fcprsp->rspStatus2;
3488 uint32_t scsi_status = fcprsp->rspStatus3;
3489 uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm;
3490 struct lpfc_fast_path_event *fast_path_evt = NULL;
3491 struct lpfc_nodelist *pnode = lpfc_cmd->rdata->pnode;
3492 unsigned long flags;
3494 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
3497 /* If there is queuefull or busy condition send a scsi event */
3498 if ((cmnd->result == SAM_STAT_TASK_SET_FULL) ||
3499 (cmnd->result == SAM_STAT_BUSY)) {
3500 fast_path_evt = lpfc_alloc_fast_evt(phba);
3503 fast_path_evt->un.scsi_evt.event_type =
3505 fast_path_evt->un.scsi_evt.subcategory =
3506 (cmnd->result == SAM_STAT_TASK_SET_FULL) ?
3507 LPFC_EVENT_QFULL : LPFC_EVENT_DEVBSY;
3508 fast_path_evt->un.scsi_evt.lun = cmnd->device->lun;
3509 memcpy(&fast_path_evt->un.scsi_evt.wwpn,
3510 &pnode->nlp_portname, sizeof(struct lpfc_name));
3511 memcpy(&fast_path_evt->un.scsi_evt.wwnn,
3512 &pnode->nlp_nodename, sizeof(struct lpfc_name));
3513 } else if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen &&
3514 ((cmnd->cmnd[0] == READ_10) || (cmnd->cmnd[0] == WRITE_10))) {
3515 fast_path_evt = lpfc_alloc_fast_evt(phba);
3518 fast_path_evt->un.check_cond_evt.scsi_event.event_type =
3520 fast_path_evt->un.check_cond_evt.scsi_event.subcategory =
3521 LPFC_EVENT_CHECK_COND;
3522 fast_path_evt->un.check_cond_evt.scsi_event.lun =
3524 memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwpn,
3525 &pnode->nlp_portname, sizeof(struct lpfc_name));
3526 memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwnn,
3527 &pnode->nlp_nodename, sizeof(struct lpfc_name));
3528 fast_path_evt->un.check_cond_evt.sense_key =
3529 cmnd->sense_buffer[2] & 0xf;
3530 fast_path_evt->un.check_cond_evt.asc = cmnd->sense_buffer[12];
3531 fast_path_evt->un.check_cond_evt.ascq = cmnd->sense_buffer[13];
3532 } else if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) &&
3534 ((be32_to_cpu(fcprsp->rspResId) != fcpi_parm) ||
3535 ((scsi_status == SAM_STAT_GOOD) &&
3536 !(resp_info & (RESID_UNDER | RESID_OVER))))) {
3538 * If status is good or resid does not match with fcp_param and
3539 * there is valid fcpi_parm, then there is a read_check error
3541 fast_path_evt = lpfc_alloc_fast_evt(phba);
3544 fast_path_evt->un.read_check_error.header.event_type =
3545 FC_REG_FABRIC_EVENT;
3546 fast_path_evt->un.read_check_error.header.subcategory =
3547 LPFC_EVENT_FCPRDCHKERR;
3548 memcpy(&fast_path_evt->un.read_check_error.header.wwpn,
3549 &pnode->nlp_portname, sizeof(struct lpfc_name));
3550 memcpy(&fast_path_evt->un.read_check_error.header.wwnn,
3551 &pnode->nlp_nodename, sizeof(struct lpfc_name));
3552 fast_path_evt->un.read_check_error.lun = cmnd->device->lun;
3553 fast_path_evt->un.read_check_error.opcode = cmnd->cmnd[0];
3554 fast_path_evt->un.read_check_error.fcpiparam =
3559 fast_path_evt->vport = vport;
3560 spin_lock_irqsave(&phba->hbalock, flags);
3561 list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list);
3562 spin_unlock_irqrestore(&phba->hbalock, flags);
3563 lpfc_worker_wake_up(phba);
3568 * lpfc_scsi_unprep_dma_buf - Un-map DMA mapping of SG-list for dev
3569 * @phba: The HBA for which this call is being executed.
3570 * @psb: The scsi buffer which is going to be un-mapped.
3572 * This routine does DMA un-mapping of scatter gather list of scsi command
3573 * field of @lpfc_cmd for device with SLI-3 interface spec.
3576 lpfc_scsi_unprep_dma_buf(struct lpfc_hba *phba, struct lpfc_io_buf *psb)
3579 * There are only two special cases to consider. (1) the scsi command
3580 * requested scatter-gather usage or (2) the scsi command allocated
3581 * a request buffer, but did not request use_sg. There is a third
3582 * case, but it does not require resource deallocation.
3584 if (psb->seg_cnt > 0)
3585 scsi_dma_unmap(psb->pCmd);
3586 if (psb->prot_seg_cnt > 0)
3587 dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(psb->pCmd),
3588 scsi_prot_sg_count(psb->pCmd),
3589 psb->pCmd->sc_data_direction);
3593 * lpfc_handler_fcp_err - FCP response handler
3594 * @vport: The virtual port for which this call is being executed.
3595 * @lpfc_cmd: Pointer to lpfc_io_buf data structure.
3596 * @rsp_iocb: The response IOCB which contains FCP error.
3598 * This routine is called to process response IOCB with status field
3599 * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command
3600 * based upon SCSI and FCP error.
3603 lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_io_buf *lpfc_cmd,
3604 struct lpfc_iocbq *rsp_iocb)
3606 struct lpfc_hba *phba = vport->phba;
3607 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
3608 struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd;
3609 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
3610 uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm;
3611 uint32_t resp_info = fcprsp->rspStatus2;
3612 uint32_t scsi_status = fcprsp->rspStatus3;
3614 uint32_t host_status = DID_OK;
3615 uint32_t rsplen = 0;
3617 uint32_t logit = LOG_FCP | LOG_FCP_ERROR;
3621 * If this is a task management command, there is no
3622 * scsi packet associated with this lpfc_cmd. The driver
3625 if (fcpcmd->fcpCntl2) {
3630 if (resp_info & RSP_LEN_VALID) {
3631 rsplen = be32_to_cpu(fcprsp->rspRspLen);
3632 if (rsplen != 0 && rsplen != 4 && rsplen != 8) {
3633 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3634 "2719 Invalid response length: "
3635 "tgt x%x lun x%llx cmnd x%x rsplen "
3636 "x%x\n", cmnd->device->id,
3637 cmnd->device->lun, cmnd->cmnd[0],
3639 host_status = DID_ERROR;
3642 if (fcprsp->rspInfo3 != RSP_NO_FAILURE) {
3643 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3644 "2757 Protocol failure detected during "
3645 "processing of FCP I/O op: "
3646 "tgt x%x lun x%llx cmnd x%x rspInfo3 x%x\n",
3648 cmnd->device->lun, cmnd->cmnd[0],
3650 host_status = DID_ERROR;
3655 if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) {
3656 uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen);
3657 if (snslen > SCSI_SENSE_BUFFERSIZE)
3658 snslen = SCSI_SENSE_BUFFERSIZE;
3660 if (resp_info & RSP_LEN_VALID)
3661 rsplen = be32_to_cpu(fcprsp->rspRspLen);
3662 memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen);
3664 lp = (uint32_t *)cmnd->sense_buffer;
3666 /* special handling for under run conditions */
3667 if (!scsi_status && (resp_info & RESID_UNDER)) {
3668 /* don't log under runs if fcp set... */
3669 if (vport->cfg_log_verbose & LOG_FCP)
3670 logit = LOG_FCP_ERROR;
3671 /* unless operator says so */
3672 if (vport->cfg_log_verbose & LOG_FCP_UNDER)
3673 logit = LOG_FCP_UNDER;
3676 lpfc_printf_vlog(vport, KERN_WARNING, logit,
3677 "9024 FCP command x%x failed: x%x SNS x%x x%x "
3678 "Data: x%x x%x x%x x%x x%x\n",
3679 cmnd->cmnd[0], scsi_status,
3680 be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info,
3681 be32_to_cpu(fcprsp->rspResId),
3682 be32_to_cpu(fcprsp->rspSnsLen),
3683 be32_to_cpu(fcprsp->rspRspLen),
3686 scsi_set_resid(cmnd, 0);
3687 fcpDl = be32_to_cpu(fcpcmd->fcpDl);
3688 if (resp_info & RESID_UNDER) {
3689 scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId));
3691 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_UNDER,
3692 "9025 FCP Underrun, expected %d, "
3693 "residual %d Data: x%x x%x x%x\n",
3695 scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0],
3699 * If there is an under run, check if under run reported by
3700 * storage array is same as the under run reported by HBA.
3701 * If this is not same, there is a dropped frame.
3703 if (fcpi_parm && (scsi_get_resid(cmnd) != fcpi_parm)) {
3704 lpfc_printf_vlog(vport, KERN_WARNING,
3705 LOG_FCP | LOG_FCP_ERROR,
3706 "9026 FCP Read Check Error "
3707 "and Underrun Data: x%x x%x x%x x%x\n",
3709 scsi_get_resid(cmnd), fcpi_parm,
3711 scsi_set_resid(cmnd, scsi_bufflen(cmnd));
3712 host_status = DID_ERROR;
3715 * The cmnd->underflow is the minimum number of bytes that must
3716 * be transferred for this command. Provided a sense condition
3717 * is not present, make sure the actual amount transferred is at
3718 * least the underflow value or fail.
3720 if (!(resp_info & SNS_LEN_VALID) &&
3721 (scsi_status == SAM_STAT_GOOD) &&
3722 (scsi_bufflen(cmnd) - scsi_get_resid(cmnd)
3723 < cmnd->underflow)) {
3724 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
3725 "9027 FCP command x%x residual "
3726 "underrun converted to error "
3727 "Data: x%x x%x x%x\n",
3728 cmnd->cmnd[0], scsi_bufflen(cmnd),
3729 scsi_get_resid(cmnd), cmnd->underflow);
3730 host_status = DID_ERROR;
3732 } else if (resp_info & RESID_OVER) {
3733 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
3734 "9028 FCP command x%x residual overrun error. "
3735 "Data: x%x x%x\n", cmnd->cmnd[0],
3736 scsi_bufflen(cmnd), scsi_get_resid(cmnd));
3737 host_status = DID_ERROR;
3740 * Check SLI validation that all the transfer was actually done
3741 * (fcpi_parm should be zero). Apply check only to reads.
3743 } else if (fcpi_parm) {
3744 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR,
3745 "9029 FCP %s Check Error xri x%x Data: "
3746 "x%x x%x x%x x%x x%x\n",
3747 ((cmnd->sc_data_direction == DMA_FROM_DEVICE) ?
3749 ((phba->sli_rev == LPFC_SLI_REV4) ?
3750 lpfc_cmd->cur_iocbq.sli4_xritag :
3751 rsp_iocb->iocb.ulpContext),
3752 fcpDl, be32_to_cpu(fcprsp->rspResId),
3753 fcpi_parm, cmnd->cmnd[0], scsi_status);
3755 /* There is some issue with the LPe12000 that causes it
3756 * to miscalculate the fcpi_parm and falsely trip this
3757 * recovery logic. Detect this case and don't error when true.
3759 if (fcpi_parm > fcpDl)
3762 switch (scsi_status) {
3764 case SAM_STAT_CHECK_CONDITION:
3765 /* Fabric dropped a data frame. Fail any successful
3766 * command in which we detected dropped frames.
3767 * A status of good or some check conditions could
3768 * be considered a successful command.
3770 host_status = DID_ERROR;
3773 scsi_set_resid(cmnd, scsi_bufflen(cmnd));
3777 cmnd->result = host_status << 16 | scsi_status;
3778 lpfc_send_scsi_error_event(vport->phba, vport, lpfc_cmd, rsp_iocb);
3782 * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine
3783 * @phba: The Hba for which this call is being executed.
3784 * @pIocbIn: The command IOCBQ for the scsi cmnd.
3785 * @pIocbOut: The response IOCBQ for the scsi cmnd.
3787 * This routine assigns scsi command result by looking into response IOCB
3788 * status field appropriately. This routine handles QUEUE FULL condition as
3789 * well by ramping down device queue depth.
3792 lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
3793 struct lpfc_iocbq *pIocbOut)
3795 struct lpfc_io_buf *lpfc_cmd =
3796 (struct lpfc_io_buf *) pIocbIn->context1;
3797 struct lpfc_vport *vport = pIocbIn->vport;
3798 struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
3799 struct lpfc_nodelist *pnode = rdata->pnode;
3800 struct scsi_cmnd *cmd;
3801 unsigned long flags;
3802 struct lpfc_fast_path_event *fast_path_evt;
3803 struct Scsi_Host *shost;
3805 uint32_t logit = LOG_FCP;
3807 /* Guard against abort handler being called at same time */
3808 spin_lock(&lpfc_cmd->buf_lock);
3810 /* Sanity check on return of outstanding command */
3811 cmd = lpfc_cmd->pCmd;
3812 if (!cmd || !phba) {
3813 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3814 "2621 IO completion: Not an active IO\n");
3815 spin_unlock(&lpfc_cmd->buf_lock);
3819 idx = lpfc_cmd->cur_iocbq.hba_wqidx;
3820 if (phba->sli4_hba.hdwq)
3821 phba->sli4_hba.hdwq[idx].scsi_cstat.io_cmpls++;
3823 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3824 if (unlikely(phba->hdwqstat_on & LPFC_CHECK_SCSI_IO))
3825 this_cpu_inc(phba->sli4_hba.c_stat->cmpl_io);
3827 shost = cmd->device->host;
3829 lpfc_cmd->result = (pIocbOut->iocb.un.ulpWord[4] & IOERR_PARAM_MASK);
3830 lpfc_cmd->status = pIocbOut->iocb.ulpStatus;
3831 /* pick up SLI4 exhange busy status from HBA */
3832 if (pIocbOut->iocb_flag & LPFC_EXCHANGE_BUSY)
3833 lpfc_cmd->flags |= LPFC_SBUF_XBUSY;
3835 lpfc_cmd->flags &= ~LPFC_SBUF_XBUSY;
3837 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3838 if (lpfc_cmd->prot_data_type) {
3839 struct scsi_dif_tuple *src = NULL;
3841 src = (struct scsi_dif_tuple *)lpfc_cmd->prot_data_segment;
3843 * Used to restore any changes to protection
3844 * data for error injection.
3846 switch (lpfc_cmd->prot_data_type) {
3847 case LPFC_INJERR_REFTAG:
3849 lpfc_cmd->prot_data;
3851 case LPFC_INJERR_APPTAG:
3853 (uint16_t)lpfc_cmd->prot_data;
3855 case LPFC_INJERR_GUARD:
3857 (uint16_t)lpfc_cmd->prot_data;
3863 lpfc_cmd->prot_data = 0;
3864 lpfc_cmd->prot_data_type = 0;
3865 lpfc_cmd->prot_data_segment = NULL;
3869 if (unlikely(lpfc_cmd->status)) {
3870 if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT &&
3871 (lpfc_cmd->result & IOERR_DRVR_MASK))
3872 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
3873 else if (lpfc_cmd->status >= IOSTAT_CNT)
3874 lpfc_cmd->status = IOSTAT_DEFAULT;
3875 if (lpfc_cmd->status == IOSTAT_FCP_RSP_ERROR &&
3876 !lpfc_cmd->fcp_rsp->rspStatus3 &&
3877 (lpfc_cmd->fcp_rsp->rspStatus2 & RESID_UNDER) &&
3878 !(vport->cfg_log_verbose & LOG_FCP_UNDER))
3881 logit = LOG_FCP | LOG_FCP_UNDER;
3882 lpfc_printf_vlog(vport, KERN_WARNING, logit,
3883 "9030 FCP cmd x%x failed <%d/%lld> "
3884 "status: x%x result: x%x "
3885 "sid: x%x did: x%x oxid: x%x "
3888 cmd->device ? cmd->device->id : 0xffff,
3889 cmd->device ? cmd->device->lun : 0xffff,
3890 lpfc_cmd->status, lpfc_cmd->result,
3892 (pnode) ? pnode->nlp_DID : 0,
3893 phba->sli_rev == LPFC_SLI_REV4 ?
3894 lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff,
3895 pIocbOut->iocb.ulpContext,
3896 lpfc_cmd->cur_iocbq.iocb.ulpIoTag);
3898 switch (lpfc_cmd->status) {
3899 case IOSTAT_FCP_RSP_ERROR:
3900 /* Call FCP RSP handler to determine result */
3901 lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut);
3903 case IOSTAT_NPORT_BSY:
3904 case IOSTAT_FABRIC_BSY:
3905 cmd->result = DID_TRANSPORT_DISRUPTED << 16;
3906 fast_path_evt = lpfc_alloc_fast_evt(phba);
3909 fast_path_evt->un.fabric_evt.event_type =
3910 FC_REG_FABRIC_EVENT;
3911 fast_path_evt->un.fabric_evt.subcategory =
3912 (lpfc_cmd->status == IOSTAT_NPORT_BSY) ?
3913 LPFC_EVENT_PORT_BUSY : LPFC_EVENT_FABRIC_BUSY;
3914 if (pnode && NLP_CHK_NODE_ACT(pnode)) {
3915 memcpy(&fast_path_evt->un.fabric_evt.wwpn,
3916 &pnode->nlp_portname,
3917 sizeof(struct lpfc_name));
3918 memcpy(&fast_path_evt->un.fabric_evt.wwnn,
3919 &pnode->nlp_nodename,
3920 sizeof(struct lpfc_name));
3922 fast_path_evt->vport = vport;
3923 fast_path_evt->work_evt.evt =
3924 LPFC_EVT_FASTPATH_MGMT_EVT;
3925 spin_lock_irqsave(&phba->hbalock, flags);
3926 list_add_tail(&fast_path_evt->work_evt.evt_listp,
3928 spin_unlock_irqrestore(&phba->hbalock, flags);
3929 lpfc_worker_wake_up(phba);
3931 case IOSTAT_LOCAL_REJECT:
3932 case IOSTAT_REMOTE_STOP:
3933 if (lpfc_cmd->result == IOERR_ELXSEC_KEY_UNWRAP_ERROR ||
3935 IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR ||
3936 lpfc_cmd->result == IOERR_ELXSEC_CRYPTO_ERROR ||
3938 IOERR_ELXSEC_CRYPTO_COMPARE_ERROR) {
3939 cmd->result = DID_NO_CONNECT << 16;
3942 if (lpfc_cmd->result == IOERR_INVALID_RPI ||
3943 lpfc_cmd->result == IOERR_NO_RESOURCES ||
3944 lpfc_cmd->result == IOERR_ABORT_REQUESTED ||
3945 lpfc_cmd->result == IOERR_SLER_CMD_RCV_FAILURE) {
3946 cmd->result = DID_REQUEUE << 16;
3949 if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED ||
3950 lpfc_cmd->result == IOERR_TX_DMA_FAILED) &&
3951 pIocbOut->iocb.unsli3.sli3_bg.bgstat) {
3952 if (scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
3954 * This is a response for a BG enabled
3955 * cmd. Parse BG error
3957 lpfc_parse_bg_err(phba, lpfc_cmd,
3961 lpfc_printf_vlog(vport, KERN_WARNING,
3963 "9031 non-zero BGSTAT "
3964 "on unprotected cmd\n");
3967 if ((lpfc_cmd->status == IOSTAT_REMOTE_STOP)
3968 && (phba->sli_rev == LPFC_SLI_REV4)
3969 && (pnode && NLP_CHK_NODE_ACT(pnode))) {
3970 /* This IO was aborted by the target, we don't
3971 * know the rxid and because we did not send the
3972 * ABTS we cannot generate and RRQ.
3974 lpfc_set_rrq_active(phba, pnode,
3975 lpfc_cmd->cur_iocbq.sli4_lxritag,
3980 cmd->result = DID_ERROR << 16;
3984 if (!pnode || !NLP_CHK_NODE_ACT(pnode)
3985 || (pnode->nlp_state != NLP_STE_MAPPED_NODE))
3986 cmd->result = DID_TRANSPORT_DISRUPTED << 16 |
3989 cmd->result = DID_OK << 16;
3991 if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) {
3992 uint32_t *lp = (uint32_t *)cmd->sense_buffer;
3994 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
3995 "0710 Iodone <%d/%llu> cmd x%px, error "
3996 "x%x SNS x%x x%x Data: x%x x%x\n",
3997 cmd->device->id, cmd->device->lun, cmd,
3998 cmd->result, *lp, *(lp + 3), cmd->retries,
3999 scsi_get_resid(cmd));
4002 lpfc_update_stats(vport, lpfc_cmd);
4003 if (vport->cfg_max_scsicmpl_time &&
4004 time_after(jiffies, lpfc_cmd->start_time +
4005 msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) {
4006 spin_lock_irqsave(shost->host_lock, flags);
4007 if (pnode && NLP_CHK_NODE_ACT(pnode)) {
4008 if (pnode->cmd_qdepth >
4009 atomic_read(&pnode->cmd_pending) &&
4010 (atomic_read(&pnode->cmd_pending) >
4011 LPFC_MIN_TGT_QDEPTH) &&
4012 ((cmd->cmnd[0] == READ_10) ||
4013 (cmd->cmnd[0] == WRITE_10)))
4015 atomic_read(&pnode->cmd_pending);
4017 pnode->last_change_time = jiffies;
4019 spin_unlock_irqrestore(shost->host_lock, flags);
4021 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
4023 lpfc_cmd->pCmd = NULL;
4024 spin_unlock(&lpfc_cmd->buf_lock);
4026 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4027 if (lpfc_cmd->ts_cmd_start) {
4028 lpfc_cmd->ts_isr_cmpl = pIocbIn->isr_timestamp;
4029 lpfc_cmd->ts_data_io = ktime_get_ns();
4030 phba->ktime_last_cmd = lpfc_cmd->ts_data_io;
4031 lpfc_io_ktime(phba, lpfc_cmd);
4034 /* The sdev is not guaranteed to be valid post scsi_done upcall. */
4035 cmd->scsi_done(cmd);
4038 * If there is an abort thread waiting for command completion
4039 * wake up the thread.
4041 spin_lock(&lpfc_cmd->buf_lock);
4042 lpfc_cmd->cur_iocbq.iocb_flag &= ~LPFC_DRIVER_ABORTED;
4043 if (lpfc_cmd->waitq)
4044 wake_up(lpfc_cmd->waitq);
4045 spin_unlock(&lpfc_cmd->buf_lock);
4047 lpfc_release_scsi_buf(phba, lpfc_cmd);
4051 * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB
4052 * @data: A pointer to the immediate command data portion of the IOCB.
4053 * @fcp_cmnd: The FCP Command that is provided by the SCSI layer.
4055 * The routine copies the entire FCP command from @fcp_cmnd to @data while
4056 * byte swapping the data to big endian format for transmission on the wire.
4059 lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd)
4062 for (i = 0, j = 0; i < sizeof(struct fcp_cmnd);
4063 i += sizeof(uint32_t), j++) {
4064 ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]);
4069 * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit
4070 * @vport: The virtual port for which this call is being executed.
4071 * @lpfc_cmd: The scsi command which needs to send.
4072 * @pnode: Pointer to lpfc_nodelist.
4074 * This routine initializes fcp_cmnd and iocb data structure from scsi command
4075 * to transfer for device with SLI3 interface spec.
4078 lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_io_buf *lpfc_cmd,
4079 struct lpfc_nodelist *pnode)
4081 struct lpfc_hba *phba = vport->phba;
4082 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
4083 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
4084 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
4085 struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq);
4086 struct lpfc_sli4_hdw_queue *hdwq = NULL;
4087 int datadir = scsi_cmnd->sc_data_direction;
4093 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
4096 lpfc_cmd->fcp_rsp->rspSnsLen = 0;
4097 /* clear task management bits */
4098 lpfc_cmd->fcp_cmnd->fcpCntl2 = 0;
4100 int_to_scsilun(lpfc_cmd->pCmd->device->lun,
4101 &lpfc_cmd->fcp_cmnd->fcp_lun);
4103 ptr = &fcp_cmnd->fcpCdb[0];
4104 memcpy(ptr, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
4105 if (scsi_cmnd->cmd_len < LPFC_FCP_CDB_LEN) {
4106 ptr += scsi_cmnd->cmd_len;
4107 memset(ptr, 0, (LPFC_FCP_CDB_LEN - scsi_cmnd->cmd_len));
4110 fcp_cmnd->fcpCntl1 = SIMPLE_Q;
4112 sli4 = (phba->sli_rev == LPFC_SLI_REV4);
4113 piocbq->iocb.un.fcpi.fcpi_XRdy = 0;
4114 idx = lpfc_cmd->hdwq_no;
4115 if (phba->sli4_hba.hdwq)
4116 hdwq = &phba->sli4_hba.hdwq[idx];
4119 * There are three possibilities here - use scatter-gather segment, use
4120 * the single mapping, or neither. Start the lpfc command prep by
4121 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
4124 if (scsi_sg_count(scsi_cmnd)) {
4125 if (datadir == DMA_TO_DEVICE) {
4126 iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR;
4127 iocb_cmd->ulpPU = PARM_READ_CHECK;
4128 if (vport->cfg_first_burst_size &&
4129 (pnode->nlp_flag & NLP_FIRSTBURST)) {
4130 fcpdl = scsi_bufflen(scsi_cmnd);
4131 if (fcpdl < vport->cfg_first_burst_size)
4132 piocbq->iocb.un.fcpi.fcpi_XRdy = fcpdl;
4134 piocbq->iocb.un.fcpi.fcpi_XRdy =
4135 vport->cfg_first_burst_size;
4137 fcp_cmnd->fcpCntl3 = WRITE_DATA;
4139 hdwq->scsi_cstat.output_requests++;
4141 iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR;
4142 iocb_cmd->ulpPU = PARM_READ_CHECK;
4143 fcp_cmnd->fcpCntl3 = READ_DATA;
4145 hdwq->scsi_cstat.input_requests++;
4148 iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR;
4149 iocb_cmd->un.fcpi.fcpi_parm = 0;
4150 iocb_cmd->ulpPU = 0;
4151 fcp_cmnd->fcpCntl3 = 0;
4153 hdwq->scsi_cstat.control_requests++;
4155 if (phba->sli_rev == 3 &&
4156 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED))
4157 lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd);
4159 * Finish initializing those IOCB fields that are independent
4160 * of the scsi_cmnd request_buffer
4162 piocbq->iocb.ulpContext = pnode->nlp_rpi;
4164 piocbq->iocb.ulpContext =
4165 phba->sli4_hba.rpi_ids[pnode->nlp_rpi];
4166 if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE)
4167 piocbq->iocb.ulpFCP2Rcvy = 1;
4169 piocbq->iocb.ulpFCP2Rcvy = 0;
4171 piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f);
4172 piocbq->context1 = lpfc_cmd;
4173 piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
4174 piocbq->iocb.ulpTimeout = lpfc_cmd->timeout;
4175 piocbq->vport = vport;
4179 * lpfc_scsi_prep_task_mgmt_cmd - Convert SLI3 scsi TM cmd to FCP info unit
4180 * @vport: The virtual port for which this call is being executed.
4181 * @lpfc_cmd: Pointer to lpfc_io_buf data structure.
4182 * @lun: Logical unit number.
4183 * @task_mgmt_cmd: SCSI task management command.
4185 * This routine creates FCP information unit corresponding to @task_mgmt_cmd
4186 * for device with SLI-3 interface spec.
4193 lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport,
4194 struct lpfc_io_buf *lpfc_cmd,
4196 uint8_t task_mgmt_cmd)
4198 struct lpfc_iocbq *piocbq;
4200 struct fcp_cmnd *fcp_cmnd;
4201 struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
4202 struct lpfc_nodelist *ndlp = rdata->pnode;
4204 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) ||
4205 ndlp->nlp_state != NLP_STE_MAPPED_NODE)
4208 piocbq = &(lpfc_cmd->cur_iocbq);
4209 piocbq->vport = vport;
4211 piocb = &piocbq->iocb;
4213 fcp_cmnd = lpfc_cmd->fcp_cmnd;
4214 /* Clear out any old data in the FCP command area */
4215 memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd));
4216 int_to_scsilun(lun, &fcp_cmnd->fcp_lun);
4217 fcp_cmnd->fcpCntl2 = task_mgmt_cmd;
4218 if (vport->phba->sli_rev == 3 &&
4219 !(vport->phba->sli3_options & LPFC_SLI3_BG_ENABLED))
4220 lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd);
4221 piocb->ulpCommand = CMD_FCP_ICMND64_CR;
4222 piocb->ulpContext = ndlp->nlp_rpi;
4223 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
4225 vport->phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
4227 piocb->ulpFCP2Rcvy = (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) ? 1 : 0;
4228 piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f);
4230 piocb->un.fcpi.fcpi_parm = 0;
4232 /* ulpTimeout is only one byte */
4233 if (lpfc_cmd->timeout > 0xff) {
4235 * Do not timeout the command at the firmware level.
4236 * The driver will provide the timeout mechanism.
4238 piocb->ulpTimeout = 0;
4240 piocb->ulpTimeout = lpfc_cmd->timeout;
4242 if (vport->phba->sli_rev == LPFC_SLI_REV4)
4243 lpfc_sli4_set_rsp_sgl_last(vport->phba, lpfc_cmd);
4249 * lpfc_scsi_api_table_setup - Set up scsi api function jump table
4250 * @phba: The hba struct for which this call is being executed.
4251 * @dev_grp: The HBA PCI-Device group number.
4253 * This routine sets up the SCSI interface API function jump table in @phba
4255 * Returns: 0 - success, -ENODEV - failure.
4258 lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
4261 phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf;
4262 phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd;
4265 case LPFC_PCI_DEV_LP:
4266 phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3;
4267 phba->lpfc_bg_scsi_prep_dma_buf = lpfc_bg_scsi_prep_dma_buf_s3;
4268 phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3;
4269 phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s3;
4271 case LPFC_PCI_DEV_OC:
4272 phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s4;
4273 phba->lpfc_bg_scsi_prep_dma_buf = lpfc_bg_scsi_prep_dma_buf_s4;
4274 phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s4;
4275 phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s4;
4278 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4279 "1418 Invalid HBA PCI-device group: 0x%x\n",
4284 phba->lpfc_rampdown_queue_depth = lpfc_rampdown_queue_depth;
4285 phba->lpfc_scsi_cmd_iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
4290 * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command
4291 * @phba: The Hba for which this call is being executed.
4292 * @cmdiocbq: Pointer to lpfc_iocbq data structure.
4293 * @rspiocbq: Pointer to lpfc_iocbq data structure.
4295 * This routine is IOCB completion routine for device reset and target reset
4296 * routine. This routine release scsi buffer associated with lpfc_cmd.
4299 lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba,
4300 struct lpfc_iocbq *cmdiocbq,
4301 struct lpfc_iocbq *rspiocbq)
4303 struct lpfc_io_buf *lpfc_cmd =
4304 (struct lpfc_io_buf *) cmdiocbq->context1;
4306 lpfc_release_scsi_buf(phba, lpfc_cmd);
4311 * lpfc_check_pci_resettable - Walks list of devices on pci_dev's bus to check
4312 * if issuing a pci_bus_reset is possibly unsafe
4313 * @phba: lpfc_hba pointer.
4316 * Walks the bus_list to ensure only PCI devices with Emulex
4317 * vendor id, device ids that support hot reset, and only one occurrence
4321 * -EBADSLT, detected invalid device
4325 lpfc_check_pci_resettable(struct lpfc_hba *phba)
4327 const struct pci_dev *pdev = phba->pcidev;
4328 struct pci_dev *ptr = NULL;
4331 /* Walk the list of devices on the pci_dev's bus */
4332 list_for_each_entry(ptr, &pdev->bus->devices, bus_list) {
4333 /* Check for Emulex Vendor ID */
4334 if (ptr->vendor != PCI_VENDOR_ID_EMULEX) {
4335 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4336 "8346 Non-Emulex vendor found: "
4337 "0x%04x\n", ptr->vendor);
4341 /* Check for valid Emulex Device ID */
4342 switch (ptr->device) {
4343 case PCI_DEVICE_ID_LANCER_FC:
4344 case PCI_DEVICE_ID_LANCER_G6_FC:
4345 case PCI_DEVICE_ID_LANCER_G7_FC:
4348 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4349 "8347 Invalid device found: "
4350 "0x%04x\n", ptr->device);
4354 /* Check for only one function 0 ID to ensure only one HBA on
4357 if (ptr->devfn == 0) {
4358 if (++counter > 1) {
4359 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4360 "8348 More than one device on "
4361 "secondary bus found\n");
4371 * lpfc_info - Info entry point of scsi_host_template data structure
4372 * @host: The scsi host for which this call is being executed.
4374 * This routine provides module information about hba.
4377 * Pointer to char - Success.
4380 lpfc_info(struct Scsi_Host *host)
4382 struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata;
4383 struct lpfc_hba *phba = vport->phba;
4385 static char lpfcinfobuf[384];
4386 char tmp[384] = {0};
4388 memset(lpfcinfobuf, 0, sizeof(lpfcinfobuf));
4389 if (phba && phba->pcidev){
4390 /* Model Description */
4391 scnprintf(tmp, sizeof(tmp), phba->ModelDesc);
4392 if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >=
4393 sizeof(lpfcinfobuf))
4397 scnprintf(tmp, sizeof(tmp),
4398 " on PCI bus %02x device %02x irq %d",
4399 phba->pcidev->bus->number, phba->pcidev->devfn,
4401 if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >=
4402 sizeof(lpfcinfobuf))
4406 if (phba->Port[0]) {
4407 scnprintf(tmp, sizeof(tmp), " port %s", phba->Port);
4408 if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >=
4409 sizeof(lpfcinfobuf))
4414 link_speed = lpfc_sli_port_speed_get(phba);
4415 if (link_speed != 0) {
4416 scnprintf(tmp, sizeof(tmp),
4417 " Logical Link Speed: %d Mbps", link_speed);
4418 if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >=
4419 sizeof(lpfcinfobuf))
4423 /* PCI resettable */
4424 if (!lpfc_check_pci_resettable(phba)) {
4425 scnprintf(tmp, sizeof(tmp), " PCI resettable");
4426 strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf));
4435 * lpfc_poll_rearm_time - Routine to modify fcp_poll timer of hba
4436 * @phba: The Hba for which this call is being executed.
4438 * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo.
4439 * The default value of cfg_poll_tmo is 10 milliseconds.
4441 static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba)
4443 unsigned long poll_tmo_expires =
4444 (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo));
4446 if (!list_empty(&phba->sli.sli3_ring[LPFC_FCP_RING].txcmplq))
4447 mod_timer(&phba->fcp_poll_timer,
4452 * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA
4453 * @phba: The Hba for which this call is being executed.
4455 * This routine starts the fcp_poll_timer of @phba.
4457 void lpfc_poll_start_timer(struct lpfc_hba * phba)
4459 lpfc_poll_rearm_timer(phba);
4463 * lpfc_poll_timeout - Restart polling timer
4464 * @ptr: Map to lpfc_hba data structure pointer.
4466 * This routine restarts fcp_poll timer, when FCP ring polling is enable
4467 * and FCP Ring interrupt is disable.
4470 void lpfc_poll_timeout(struct timer_list *t)
4472 struct lpfc_hba *phba = from_timer(phba, t, fcp_poll_timer);
4474 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
4475 lpfc_sli_handle_fast_ring_event(phba,
4476 &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ);
4478 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
4479 lpfc_poll_rearm_timer(phba);
4484 * lpfc_queuecommand - scsi_host_template queuecommand entry point
4485 * @cmnd: Pointer to scsi_cmnd data structure.
4486 * @done: Pointer to done routine.
4488 * Driver registers this routine to scsi midlayer to submit a @cmd to process.
4489 * This routine prepares an IOCB from scsi command and provides to firmware.
4490 * The @done callback is invoked after driver finished processing the command.
4494 * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily.
4497 lpfc_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *cmnd)
4499 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4500 struct lpfc_hba *phba = vport->phba;
4501 struct lpfc_rport_data *rdata;
4502 struct lpfc_nodelist *ndlp;
4503 struct lpfc_io_buf *lpfc_cmd;
4504 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
4506 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4507 uint64_t start = 0L;
4510 start = ktime_get_ns();
4513 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
4515 /* sanity check on references */
4516 if (unlikely(!rdata) || unlikely(!rport))
4517 goto out_fail_command;
4519 err = fc_remote_port_chkready(rport);
4522 goto out_fail_command;
4524 ndlp = rdata->pnode;
4526 if ((scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) &&
4527 (!(phba->sli3_options & LPFC_SLI3_BG_ENABLED))) {
4529 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4530 "9058 BLKGRD: ERROR: rcvd protected cmd:%02x"
4531 " op:%02x str=%s without registering for"
4532 " BlockGuard - Rejecting command\n",
4533 cmnd->cmnd[0], scsi_get_prot_op(cmnd),
4534 dif_op_str[scsi_get_prot_op(cmnd)]);
4535 goto out_fail_command;
4539 * Catch race where our node has transitioned, but the
4540 * transport is still transitioning.
4542 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
4544 if (lpfc_ndlp_check_qdepth(phba, ndlp)) {
4545 if (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth) {
4546 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_ERROR,
4547 "3377 Target Queue Full, scsi Id:%d "
4548 "Qdepth:%d Pending command:%d"
4549 " WWNN:%02x:%02x:%02x:%02x:"
4550 "%02x:%02x:%02x:%02x, "
4551 " WWPN:%02x:%02x:%02x:%02x:"
4552 "%02x:%02x:%02x:%02x",
4553 ndlp->nlp_sid, ndlp->cmd_qdepth,
4554 atomic_read(&ndlp->cmd_pending),
4555 ndlp->nlp_nodename.u.wwn[0],
4556 ndlp->nlp_nodename.u.wwn[1],
4557 ndlp->nlp_nodename.u.wwn[2],
4558 ndlp->nlp_nodename.u.wwn[3],
4559 ndlp->nlp_nodename.u.wwn[4],
4560 ndlp->nlp_nodename.u.wwn[5],
4561 ndlp->nlp_nodename.u.wwn[6],
4562 ndlp->nlp_nodename.u.wwn[7],
4563 ndlp->nlp_portname.u.wwn[0],
4564 ndlp->nlp_portname.u.wwn[1],
4565 ndlp->nlp_portname.u.wwn[2],
4566 ndlp->nlp_portname.u.wwn[3],
4567 ndlp->nlp_portname.u.wwn[4],
4568 ndlp->nlp_portname.u.wwn[5],
4569 ndlp->nlp_portname.u.wwn[6],
4570 ndlp->nlp_portname.u.wwn[7]);
4575 lpfc_cmd = lpfc_get_scsi_buf(phba, ndlp, cmnd);
4576 if (lpfc_cmd == NULL) {
4577 lpfc_rampdown_queue_depth(phba);
4579 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_ERROR,
4580 "0707 driver's buffer pool is empty, "
4586 * Store the midlayer's command structure for the completion phase
4587 * and complete the command initialization.
4589 lpfc_cmd->pCmd = cmnd;
4590 lpfc_cmd->rdata = rdata;
4591 lpfc_cmd->ndlp = ndlp;
4592 cmnd->host_scribble = (unsigned char *)lpfc_cmd;
4594 if (scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) {
4595 if (vport->phba->cfg_enable_bg) {
4596 lpfc_printf_vlog(vport,
4597 KERN_INFO, LOG_SCSI_CMD,
4598 "9033 BLKGRD: rcvd %s cmd:x%x "
4599 "sector x%llx cnt %u pt %x\n",
4600 dif_op_str[scsi_get_prot_op(cmnd)],
4602 (unsigned long long)scsi_get_lba(cmnd),
4603 blk_rq_sectors(cmnd->request),
4604 (cmnd->cmnd[1]>>5));
4606 err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd);
4608 if (vport->phba->cfg_enable_bg) {
4609 lpfc_printf_vlog(vport,
4610 KERN_INFO, LOG_SCSI_CMD,
4611 "9038 BLKGRD: rcvd PROT_NORMAL cmd: "
4612 "x%x sector x%llx cnt %u pt %x\n",
4614 (unsigned long long)scsi_get_lba(cmnd),
4615 blk_rq_sectors(cmnd->request),
4616 (cmnd->cmnd[1]>>5));
4618 err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd);
4621 if (unlikely(err)) {
4623 cmnd->result = DID_ERROR << 16;
4624 goto out_fail_command_release_buf;
4626 goto out_host_busy_free_buf;
4629 lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp);
4631 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4632 if (unlikely(phba->hdwqstat_on & LPFC_CHECK_SCSI_IO))
4633 this_cpu_inc(phba->sli4_hba.c_stat->xmt_io);
4635 err = lpfc_sli_issue_iocb(phba, LPFC_FCP_RING,
4636 &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB);
4637 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4639 lpfc_cmd->ts_cmd_start = start;
4640 lpfc_cmd->ts_last_cmd = phba->ktime_last_cmd;
4641 lpfc_cmd->ts_cmd_wqput = ktime_get_ns();
4643 lpfc_cmd->ts_cmd_start = 0;
4647 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4648 "3376 FCP could not issue IOCB err %x"
4649 "FCP cmd x%x <%d/%llu> "
4650 "sid: x%x did: x%x oxid: x%x "
4651 "Data: x%x x%x x%x x%x\n",
4653 cmnd->device ? cmnd->device->id : 0xffff,
4654 cmnd->device ? cmnd->device->lun : (u64) -1,
4655 vport->fc_myDID, ndlp->nlp_DID,
4656 phba->sli_rev == LPFC_SLI_REV4 ?
4657 lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff,
4658 lpfc_cmd->cur_iocbq.iocb.ulpContext,
4659 lpfc_cmd->cur_iocbq.iocb.ulpIoTag,
4660 lpfc_cmd->cur_iocbq.iocb.ulpTimeout,
4662 (cmnd->request->timeout / 1000));
4664 goto out_host_busy_free_buf;
4666 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
4667 lpfc_sli_handle_fast_ring_event(phba,
4668 &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ);
4670 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
4671 lpfc_poll_rearm_timer(phba);
4674 if (phba->cfg_xri_rebalancing)
4675 lpfc_keep_pvt_pool_above_lowwm(phba, lpfc_cmd->hdwq_no);
4679 out_host_busy_free_buf:
4680 idx = lpfc_cmd->hdwq_no;
4681 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
4682 if (phba->sli4_hba.hdwq) {
4683 switch (lpfc_cmd->fcp_cmnd->fcpCntl3) {
4685 phba->sli4_hba.hdwq[idx].scsi_cstat.output_requests--;
4688 phba->sli4_hba.hdwq[idx].scsi_cstat.input_requests--;
4691 phba->sli4_hba.hdwq[idx].scsi_cstat.control_requests--;
4694 lpfc_release_scsi_buf(phba, lpfc_cmd);
4696 return SCSI_MLQUEUE_HOST_BUSY;
4699 return SCSI_MLQUEUE_TARGET_BUSY;
4701 out_fail_command_release_buf:
4702 lpfc_release_scsi_buf(phba, lpfc_cmd);
4705 cmnd->scsi_done(cmnd);
4711 * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point
4712 * @cmnd: Pointer to scsi_cmnd data structure.
4714 * This routine aborts @cmnd pending in base driver.
4721 lpfc_abort_handler(struct scsi_cmnd *cmnd)
4723 struct Scsi_Host *shost = cmnd->device->host;
4724 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4725 struct lpfc_hba *phba = vport->phba;
4726 struct lpfc_iocbq *iocb;
4727 struct lpfc_iocbq *abtsiocb;
4728 struct lpfc_io_buf *lpfc_cmd;
4730 int ret = SUCCESS, status = 0;
4731 struct lpfc_sli_ring *pring_s4 = NULL;
4733 unsigned long flags;
4734 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq);
4736 status = fc_block_scsi_eh(cmnd);
4737 if (status != 0 && status != SUCCESS)
4740 lpfc_cmd = (struct lpfc_io_buf *)cmnd->host_scribble;
4744 spin_lock_irqsave(&phba->hbalock, flags);
4745 /* driver queued commands are in process of being flushed */
4746 if (phba->hba_flag & HBA_IOQ_FLUSH) {
4747 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4748 "3168 SCSI Layer abort requested I/O has been "
4749 "flushed by LLD.\n");
4754 /* Guard against IO completion being called at same time */
4755 spin_lock(&lpfc_cmd->buf_lock);
4757 if (!lpfc_cmd->pCmd) {
4758 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4759 "2873 SCSI Layer I/O Abort Request IO CMPL Status "
4760 "x%x ID %d LUN %llu\n",
4761 SUCCESS, cmnd->device->id, cmnd->device->lun);
4762 goto out_unlock_buf;
4765 iocb = &lpfc_cmd->cur_iocbq;
4766 if (phba->sli_rev == LPFC_SLI_REV4) {
4767 pring_s4 = phba->sli4_hba.hdwq[iocb->hba_wqidx].io_wq->pring;
4770 goto out_unlock_buf;
4772 spin_lock(&pring_s4->ring_lock);
4774 /* the command is in process of being cancelled */
4775 if (!(iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ)) {
4776 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4777 "3169 SCSI Layer abort requested I/O has been "
4778 "cancelled by LLD.\n");
4780 goto out_unlock_ring;
4783 * If pCmd field of the corresponding lpfc_io_buf structure
4784 * points to a different SCSI command, then the driver has
4785 * already completed this command, but the midlayer did not
4786 * see the completion before the eh fired. Just return SUCCESS.
4788 if (lpfc_cmd->pCmd != cmnd) {
4789 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4790 "3170 SCSI Layer abort requested I/O has been "
4791 "completed by LLD.\n");
4792 goto out_unlock_ring;
4795 BUG_ON(iocb->context1 != lpfc_cmd);
4797 /* abort issued in recovery is still in progress */
4798 if (iocb->iocb_flag & LPFC_DRIVER_ABORTED) {
4799 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4800 "3389 SCSI Layer I/O Abort Request is pending\n");
4801 if (phba->sli_rev == LPFC_SLI_REV4)
4802 spin_unlock(&pring_s4->ring_lock);
4803 spin_unlock(&lpfc_cmd->buf_lock);
4804 spin_unlock_irqrestore(&phba->hbalock, flags);
4808 abtsiocb = __lpfc_sli_get_iocbq(phba);
4809 if (abtsiocb == NULL) {
4811 goto out_unlock_ring;
4814 /* Indicate the IO is being aborted by the driver. */
4815 iocb->iocb_flag |= LPFC_DRIVER_ABORTED;
4818 * The scsi command can not be in txq and it is in flight because the
4819 * pCmd is still pointig at the SCSI command we have to abort. There
4820 * is no need to search the txcmplq. Just send an abort to the FW.
4824 icmd = &abtsiocb->iocb;
4825 icmd->un.acxri.abortType = ABORT_TYPE_ABTS;
4826 icmd->un.acxri.abortContextTag = cmd->ulpContext;
4827 if (phba->sli_rev == LPFC_SLI_REV4)
4828 icmd->un.acxri.abortIoTag = iocb->sli4_xritag;
4830 icmd->un.acxri.abortIoTag = cmd->ulpIoTag;
4833 icmd->ulpClass = cmd->ulpClass;
4835 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
4836 abtsiocb->hba_wqidx = iocb->hba_wqidx;
4837 abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
4838 if (iocb->iocb_flag & LPFC_IO_FOF)
4839 abtsiocb->iocb_flag |= LPFC_IO_FOF;
4841 if (lpfc_is_link_up(phba))
4842 icmd->ulpCommand = CMD_ABORT_XRI_CN;
4844 icmd->ulpCommand = CMD_CLOSE_XRI_CN;
4846 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
4847 abtsiocb->vport = vport;
4848 lpfc_cmd->waitq = &waitq;
4849 if (phba->sli_rev == LPFC_SLI_REV4) {
4850 /* Note: both hbalock and ring_lock must be set here */
4851 ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno,
4853 spin_unlock(&pring_s4->ring_lock);
4855 ret_val = __lpfc_sli_issue_iocb(phba, LPFC_FCP_RING,
4859 if (ret_val == IOCB_ERROR) {
4860 /* Indicate the IO is not being aborted by the driver. */
4861 iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
4862 lpfc_cmd->waitq = NULL;
4863 spin_unlock(&lpfc_cmd->buf_lock);
4864 spin_unlock_irqrestore(&phba->hbalock, flags);
4865 lpfc_sli_release_iocbq(phba, abtsiocb);
4870 /* no longer need the lock after this point */
4871 spin_unlock(&lpfc_cmd->buf_lock);
4872 spin_unlock_irqrestore(&phba->hbalock, flags);
4874 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
4875 lpfc_sli_handle_fast_ring_event(phba,
4876 &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ);
4879 /* Wait for abort to complete */
4880 wait_event_timeout(waitq,
4881 (lpfc_cmd->pCmd != cmnd),
4882 msecs_to_jiffies(2*vport->cfg_devloss_tmo*1000));
4884 spin_lock(&lpfc_cmd->buf_lock);
4886 if (lpfc_cmd->pCmd == cmnd) {
4888 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4889 "0748 abort handler timed out waiting "
4890 "for aborting I/O (xri:x%x) to complete: "
4891 "ret %#x, ID %d, LUN %llu\n",
4892 iocb->sli4_xritag, ret,
4893 cmnd->device->id, cmnd->device->lun);
4896 lpfc_cmd->waitq = NULL;
4898 spin_unlock(&lpfc_cmd->buf_lock);
4902 if (phba->sli_rev == LPFC_SLI_REV4)
4903 spin_unlock(&pring_s4->ring_lock);
4905 spin_unlock(&lpfc_cmd->buf_lock);
4907 spin_unlock_irqrestore(&phba->hbalock, flags);
4909 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4910 "0749 SCSI Layer I/O Abort Request Status x%x ID %d "
4911 "LUN %llu\n", ret, cmnd->device->id,
4917 lpfc_taskmgmt_name(uint8_t task_mgmt_cmd)
4919 switch (task_mgmt_cmd) {
4920 case FCP_ABORT_TASK_SET:
4921 return "ABORT_TASK_SET";
4922 case FCP_CLEAR_TASK_SET:
4923 return "FCP_CLEAR_TASK_SET";
4925 return "FCP_BUS_RESET";
4927 return "FCP_LUN_RESET";
4928 case FCP_TARGET_RESET:
4929 return "FCP_TARGET_RESET";
4931 return "FCP_CLEAR_ACA";
4932 case FCP_TERMINATE_TASK:
4933 return "FCP_TERMINATE_TASK";
4941 * lpfc_check_fcp_rsp - check the returned fcp_rsp to see if task failed
4942 * @vport: The virtual port for which this call is being executed.
4943 * @lpfc_cmd: Pointer to lpfc_io_buf data structure.
4945 * This routine checks the FCP RSP INFO to see if the tsk mgmt command succeded
4952 lpfc_check_fcp_rsp(struct lpfc_vport *vport, struct lpfc_io_buf *lpfc_cmd)
4954 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
4957 uint8_t rsp_info_code;
4962 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4963 "0703 fcp_rsp is missing\n");
4965 rsp_info = fcprsp->rspStatus2;
4966 rsp_len = be32_to_cpu(fcprsp->rspRspLen);
4967 rsp_info_code = fcprsp->rspInfo3;
4970 lpfc_printf_vlog(vport, KERN_INFO,
4972 "0706 fcp_rsp valid 0x%x,"
4973 " rsp len=%d code 0x%x\n",
4975 rsp_len, rsp_info_code);
4977 /* If FCP_RSP_LEN_VALID bit is one, then the FCP_RSP_LEN
4978 * field specifies the number of valid bytes of FCP_RSP_INFO.
4979 * The FCP_RSP_LEN field shall be set to 0x04 or 0x08
4981 if ((fcprsp->rspStatus2 & RSP_LEN_VALID) &&
4982 ((rsp_len == 8) || (rsp_len == 4))) {
4983 switch (rsp_info_code) {
4984 case RSP_NO_FAILURE:
4985 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4986 "0715 Task Mgmt No Failure\n");
4989 case RSP_TM_NOT_SUPPORTED: /* TM rejected */
4990 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4991 "0716 Task Mgmt Target "
4994 case RSP_TM_NOT_COMPLETED: /* TM failed */
4995 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4996 "0717 Task Mgmt Target "
4999 case RSP_TM_INVALID_LU: /* TM to invalid LU! */
5000 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
5001 "0718 Task Mgmt to invalid "
5012 * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler
5013 * @vport: The virtual port for which this call is being executed.
5014 * @rdata: Pointer to remote port local data
5015 * @tgt_id: Target ID of remote device.
5016 * @lun_id: Lun number for the TMF
5017 * @task_mgmt_cmd: type of TMF to send
5019 * This routine builds and sends a TMF (SCSI Task Mgmt Function) to
5027 lpfc_send_taskmgmt(struct lpfc_vport *vport, struct scsi_cmnd *cmnd,
5028 unsigned int tgt_id, uint64_t lun_id,
5029 uint8_t task_mgmt_cmd)
5031 struct lpfc_hba *phba = vport->phba;
5032 struct lpfc_io_buf *lpfc_cmd;
5033 struct lpfc_iocbq *iocbq;
5034 struct lpfc_iocbq *iocbqrsp;
5035 struct lpfc_rport_data *rdata;
5036 struct lpfc_nodelist *pnode;
5040 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
5041 if (!rdata || !rdata->pnode || !NLP_CHK_NODE_ACT(rdata->pnode))
5043 pnode = rdata->pnode;
5045 lpfc_cmd = lpfc_get_scsi_buf(phba, pnode, NULL);
5046 if (lpfc_cmd == NULL)
5048 lpfc_cmd->timeout = phba->cfg_task_mgmt_tmo;
5049 lpfc_cmd->rdata = rdata;
5050 lpfc_cmd->pCmd = cmnd;
5051 lpfc_cmd->ndlp = pnode;
5053 status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun_id,
5056 lpfc_release_scsi_buf(phba, lpfc_cmd);
5060 iocbq = &lpfc_cmd->cur_iocbq;
5061 iocbqrsp = lpfc_sli_get_iocbq(phba);
5062 if (iocbqrsp == NULL) {
5063 lpfc_release_scsi_buf(phba, lpfc_cmd);
5066 iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
5068 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
5069 "0702 Issue %s to TGT %d LUN %llu "
5070 "rpi x%x nlp_flag x%x Data: x%x x%x\n",
5071 lpfc_taskmgmt_name(task_mgmt_cmd), tgt_id, lun_id,
5072 pnode->nlp_rpi, pnode->nlp_flag, iocbq->sli4_xritag,
5075 status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING,
5076 iocbq, iocbqrsp, lpfc_cmd->timeout);
5077 if ((status != IOCB_SUCCESS) ||
5078 (iocbqrsp->iocb.ulpStatus != IOSTAT_SUCCESS)) {
5079 if (status != IOCB_SUCCESS ||
5080 iocbqrsp->iocb.ulpStatus != IOSTAT_FCP_RSP_ERROR)
5081 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5082 "0727 TMF %s to TGT %d LUN %llu "
5083 "failed (%d, %d) iocb_flag x%x\n",
5084 lpfc_taskmgmt_name(task_mgmt_cmd),
5086 iocbqrsp->iocb.ulpStatus,
5087 iocbqrsp->iocb.un.ulpWord[4],
5089 /* if ulpStatus != IOCB_SUCCESS, then status == IOCB_SUCCESS */
5090 if (status == IOCB_SUCCESS) {
5091 if (iocbqrsp->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
5092 /* Something in the FCP_RSP was invalid.
5093 * Check conditions */
5094 ret = lpfc_check_fcp_rsp(vport, lpfc_cmd);
5097 } else if (status == IOCB_TIMEDOUT) {
5098 ret = TIMEOUT_ERROR;
5105 lpfc_sli_release_iocbq(phba, iocbqrsp);
5107 if (ret != TIMEOUT_ERROR)
5108 lpfc_release_scsi_buf(phba, lpfc_cmd);
5114 * lpfc_chk_tgt_mapped -
5115 * @vport: The virtual port to check on
5116 * @cmnd: Pointer to scsi_cmnd data structure.
5118 * This routine delays until the scsi target (aka rport) for the
5119 * command exists (is present and logged in) or we declare it non-existent.
5126 lpfc_chk_tgt_mapped(struct lpfc_vport *vport, struct scsi_cmnd *cmnd)
5128 struct lpfc_rport_data *rdata;
5129 struct lpfc_nodelist *pnode;
5130 unsigned long later;
5132 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
5134 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
5135 "0797 Tgt Map rport failure: rdata x%px\n", rdata);
5138 pnode = rdata->pnode;
5140 * If target is not in a MAPPED state, delay until
5141 * target is rediscovered or devloss timeout expires.
5143 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
5144 while (time_after(later, jiffies)) {
5145 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
5147 if (pnode->nlp_state == NLP_STE_MAPPED_NODE)
5149 schedule_timeout_uninterruptible(msecs_to_jiffies(500));
5150 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
5153 pnode = rdata->pnode;
5155 if (!pnode || !NLP_CHK_NODE_ACT(pnode) ||
5156 (pnode->nlp_state != NLP_STE_MAPPED_NODE))
5162 * lpfc_reset_flush_io_context -
5163 * @vport: The virtual port (scsi_host) for the flush context
5164 * @tgt_id: If aborting by Target contect - specifies the target id
5165 * @lun_id: If aborting by Lun context - specifies the lun id
5166 * @context: specifies the context level to flush at.
5168 * After a reset condition via TMF, we need to flush orphaned i/o
5169 * contexts from the adapter. This routine aborts any contexts
5170 * outstanding, then waits for their completions. The wait is
5171 * bounded by devloss_tmo though.
5178 lpfc_reset_flush_io_context(struct lpfc_vport *vport, uint16_t tgt_id,
5179 uint64_t lun_id, lpfc_ctx_cmd context)
5181 struct lpfc_hba *phba = vport->phba;
5182 unsigned long later;
5185 cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context);
5187 lpfc_sli_abort_taskmgmt(vport,
5188 &phba->sli.sli3_ring[LPFC_FCP_RING],
5189 tgt_id, lun_id, context);
5190 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
5191 while (time_after(later, jiffies) && cnt) {
5192 schedule_timeout_uninterruptible(msecs_to_jiffies(20));
5193 cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context);
5196 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5197 "0724 I/O flush failure for context %s : cnt x%x\n",
5198 ((context == LPFC_CTX_LUN) ? "LUN" :
5199 ((context == LPFC_CTX_TGT) ? "TGT" :
5200 ((context == LPFC_CTX_HOST) ? "HOST" : "Unknown"))),
5208 * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point
5209 * @cmnd: Pointer to scsi_cmnd data structure.
5211 * This routine does a device reset by sending a LUN_RESET task management
5219 lpfc_device_reset_handler(struct scsi_cmnd *cmnd)
5221 struct Scsi_Host *shost = cmnd->device->host;
5222 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5223 struct lpfc_rport_data *rdata;
5224 struct lpfc_nodelist *pnode;
5225 unsigned tgt_id = cmnd->device->id;
5226 uint64_t lun_id = cmnd->device->lun;
5227 struct lpfc_scsi_event_header scsi_event;
5230 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
5231 if (!rdata || !rdata->pnode) {
5232 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5233 "0798 Device Reset rdata failure: rdata x%px\n",
5237 pnode = rdata->pnode;
5238 status = fc_block_scsi_eh(cmnd);
5239 if (status != 0 && status != SUCCESS)
5242 status = lpfc_chk_tgt_mapped(vport, cmnd);
5243 if (status == FAILED) {
5244 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5245 "0721 Device Reset rport failure: rdata x%px\n", rdata);
5249 scsi_event.event_type = FC_REG_SCSI_EVENT;
5250 scsi_event.subcategory = LPFC_EVENT_LUNRESET;
5251 scsi_event.lun = lun_id;
5252 memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name));
5253 memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name));
5255 fc_host_post_vendor_event(shost, fc_get_event_number(),
5256 sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
5258 status = lpfc_send_taskmgmt(vport, cmnd, tgt_id, lun_id,
5261 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5262 "0713 SCSI layer issued Device Reset (%d, %llu) "
5263 "return x%x\n", tgt_id, lun_id, status);
5266 * We have to clean up i/o as : they may be orphaned by the TMF;
5267 * or if the TMF failed, they may be in an indeterminate state.
5269 * We will report success if all the i/o aborts successfully.
5271 if (status == SUCCESS)
5272 status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
5279 * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point
5280 * @cmnd: Pointer to scsi_cmnd data structure.
5282 * This routine does a target reset by sending a TARGET_RESET task management
5290 lpfc_target_reset_handler(struct scsi_cmnd *cmnd)
5292 struct Scsi_Host *shost = cmnd->device->host;
5293 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5294 struct lpfc_rport_data *rdata;
5295 struct lpfc_nodelist *pnode;
5296 unsigned tgt_id = cmnd->device->id;
5297 uint64_t lun_id = cmnd->device->lun;
5298 struct lpfc_scsi_event_header scsi_event;
5301 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
5302 if (!rdata || !rdata->pnode) {
5303 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5304 "0799 Target Reset rdata failure: rdata x%px\n",
5308 pnode = rdata->pnode;
5309 status = fc_block_scsi_eh(cmnd);
5310 if (status != 0 && status != SUCCESS)
5313 status = lpfc_chk_tgt_mapped(vport, cmnd);
5314 if (status == FAILED) {
5315 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5316 "0722 Target Reset rport failure: rdata x%px\n", rdata);
5318 spin_lock_irq(shost->host_lock);
5319 pnode->nlp_flag &= ~NLP_NPR_ADISC;
5320 pnode->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
5321 spin_unlock_irq(shost->host_lock);
5323 lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
5325 return FAST_IO_FAIL;
5328 scsi_event.event_type = FC_REG_SCSI_EVENT;
5329 scsi_event.subcategory = LPFC_EVENT_TGTRESET;
5331 memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name));
5332 memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name));
5334 fc_host_post_vendor_event(shost, fc_get_event_number(),
5335 sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
5337 status = lpfc_send_taskmgmt(vport, cmnd, tgt_id, lun_id,
5340 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5341 "0723 SCSI layer issued Target Reset (%d, %llu) "
5342 "return x%x\n", tgt_id, lun_id, status);
5345 * We have to clean up i/o as : they may be orphaned by the TMF;
5346 * or if the TMF failed, they may be in an indeterminate state.
5348 * We will report success if all the i/o aborts successfully.
5350 if (status == SUCCESS)
5351 status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
5357 * lpfc_bus_reset_handler - scsi_host_template eh_bus_reset_handler entry point
5358 * @cmnd: Pointer to scsi_cmnd data structure.
5360 * This routine does target reset to all targets on @cmnd->device->host.
5361 * This emulates Parallel SCSI Bus Reset Semantics.
5368 lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
5370 struct Scsi_Host *shost = cmnd->device->host;
5371 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5372 struct lpfc_nodelist *ndlp = NULL;
5373 struct lpfc_scsi_event_header scsi_event;
5375 int ret = SUCCESS, status, i;
5377 scsi_event.event_type = FC_REG_SCSI_EVENT;
5378 scsi_event.subcategory = LPFC_EVENT_BUSRESET;
5380 memcpy(scsi_event.wwpn, &vport->fc_portname, sizeof(struct lpfc_name));
5381 memcpy(scsi_event.wwnn, &vport->fc_nodename, sizeof(struct lpfc_name));
5383 fc_host_post_vendor_event(shost, fc_get_event_number(),
5384 sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
5386 status = fc_block_scsi_eh(cmnd);
5387 if (status != 0 && status != SUCCESS)
5391 * Since the driver manages a single bus device, reset all
5392 * targets known to the driver. Should any target reset
5393 * fail, this routine returns failure to the midlayer.
5395 for (i = 0; i < LPFC_MAX_TARGET; i++) {
5396 /* Search for mapped node by target ID */
5398 spin_lock_irq(shost->host_lock);
5399 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5400 if (!NLP_CHK_NODE_ACT(ndlp))
5402 if (vport->phba->cfg_fcp2_no_tgt_reset &&
5403 (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE))
5405 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
5406 ndlp->nlp_sid == i &&
5408 ndlp->nlp_type & NLP_FCP_TARGET) {
5413 spin_unlock_irq(shost->host_lock);
5417 status = lpfc_send_taskmgmt(vport, cmnd,
5418 i, 0, FCP_TARGET_RESET);
5420 if (status != SUCCESS) {
5421 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5422 "0700 Bus Reset on target %d failed\n",
5428 * We have to clean up i/o as : they may be orphaned by the TMFs
5429 * above; or if any of the TMFs failed, they may be in an
5430 * indeterminate state.
5431 * We will report success if all the i/o aborts successfully.
5434 status = lpfc_reset_flush_io_context(vport, 0, 0, LPFC_CTX_HOST);
5435 if (status != SUCCESS)
5438 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5439 "0714 SCSI layer issued Bus Reset Data: x%x\n", ret);
5444 * lpfc_host_reset_handler - scsi_host_template eh_host_reset_handler entry pt
5445 * @cmnd: Pointer to scsi_cmnd data structure.
5447 * This routine does host reset to the adaptor port. It brings the HBA
5448 * offline, performs a board restart, and then brings the board back online.
5449 * The lpfc_offline calls lpfc_sli_hba_down which will abort and local
5450 * reject all outstanding SCSI commands to the host and error returned
5451 * back to SCSI mid-level. As this will be SCSI mid-level's last resort
5452 * of error handling, it will only return error if resetting of the adapter
5453 * is not successful; in all other cases, will return success.
5460 lpfc_host_reset_handler(struct scsi_cmnd *cmnd)
5462 struct Scsi_Host *shost = cmnd->device->host;
5463 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5464 struct lpfc_hba *phba = vport->phba;
5465 int rc, ret = SUCCESS;
5467 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5468 "3172 SCSI layer issued Host Reset Data:\n");
5470 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
5472 rc = lpfc_sli_brdrestart(phba);
5476 rc = lpfc_online(phba);
5480 lpfc_unblock_mgmt_io(phba);
5484 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5485 "3323 Failed host reset\n");
5486 lpfc_unblock_mgmt_io(phba);
5491 * lpfc_slave_alloc - scsi_host_template slave_alloc entry point
5492 * @sdev: Pointer to scsi_device.
5494 * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's
5495 * globally available list of scsi buffers. This routine also makes sure scsi
5496 * buffer is not allocated more than HBA limit conveyed to midlayer. This list
5497 * of scsi buffer exists for the lifetime of the driver.
5504 lpfc_slave_alloc(struct scsi_device *sdev)
5506 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
5507 struct lpfc_hba *phba = vport->phba;
5508 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
5510 uint32_t num_to_alloc = 0;
5511 int num_allocated = 0;
5513 struct lpfc_device_data *device_data;
5514 unsigned long flags;
5515 struct lpfc_name target_wwpn;
5517 if (!rport || fc_remote_port_chkready(rport))
5520 if (phba->cfg_fof) {
5523 * Check to see if the device data structure for the lun
5524 * exists. If not, create one.
5527 u64_to_wwn(rport->port_name, target_wwpn.u.wwn);
5528 spin_lock_irqsave(&phba->devicelock, flags);
5529 device_data = __lpfc_get_device_data(phba,
5531 &vport->fc_portname,
5535 spin_unlock_irqrestore(&phba->devicelock, flags);
5536 device_data = lpfc_create_device_data(phba,
5537 &vport->fc_portname,
5540 phba->cfg_XLanePriority,
5544 spin_lock_irqsave(&phba->devicelock, flags);
5545 list_add_tail(&device_data->listentry, &phba->luns);
5547 device_data->rport_data = rport->dd_data;
5548 device_data->available = true;
5549 spin_unlock_irqrestore(&phba->devicelock, flags);
5550 sdev->hostdata = device_data;
5552 sdev->hostdata = rport->dd_data;
5554 sdev_cnt = atomic_inc_return(&phba->sdev_cnt);
5556 /* For SLI4, all IO buffers are pre-allocated */
5557 if (phba->sli_rev == LPFC_SLI_REV4)
5560 /* This code path is now ONLY for SLI3 adapters */
5563 * Populate the cmds_per_lun count scsi_bufs into this host's globally
5564 * available list of scsi buffers. Don't allocate more than the
5565 * HBA limit conveyed to the midlayer via the host structure. The
5566 * formula accounts for the lun_queue_depth + error handlers + 1
5567 * extra. This list of scsi bufs exists for the lifetime of the driver.
5569 total = phba->total_scsi_bufs;
5570 num_to_alloc = vport->cfg_lun_queue_depth + 2;
5572 /* If allocated buffers are enough do nothing */
5573 if ((sdev_cnt * (vport->cfg_lun_queue_depth + 2)) < total)
5576 /* Allow some exchanges to be available always to complete discovery */
5577 if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
5578 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
5579 "0704 At limitation of %d preallocated "
5580 "command buffers\n", total);
5582 /* Allow some exchanges to be available always to complete discovery */
5583 } else if (total + num_to_alloc >
5584 phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
5585 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
5586 "0705 Allocation request of %d "
5587 "command buffers will exceed max of %d. "
5588 "Reducing allocation request to %d.\n",
5589 num_to_alloc, phba->cfg_hba_queue_depth,
5590 (phba->cfg_hba_queue_depth - total));
5591 num_to_alloc = phba->cfg_hba_queue_depth - total;
5593 num_allocated = lpfc_new_scsi_buf_s3(vport, num_to_alloc);
5594 if (num_to_alloc != num_allocated) {
5595 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5596 "0708 Allocation request of %d "
5597 "command buffers did not succeed. "
5598 "Allocated %d buffers.\n",
5599 num_to_alloc, num_allocated);
5601 if (num_allocated > 0)
5602 phba->total_scsi_bufs += num_allocated;
5607 * lpfc_slave_configure - scsi_host_template slave_configure entry point
5608 * @sdev: Pointer to scsi_device.
5610 * This routine configures following items
5611 * - Tag command queuing support for @sdev if supported.
5612 * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set.
5618 lpfc_slave_configure(struct scsi_device *sdev)
5620 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
5621 struct lpfc_hba *phba = vport->phba;
5623 scsi_change_queue_depth(sdev, vport->cfg_lun_queue_depth);
5625 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
5626 lpfc_sli_handle_fast_ring_event(phba,
5627 &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ);
5628 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
5629 lpfc_poll_rearm_timer(phba);
5636 * lpfc_slave_destroy - slave_destroy entry point of SHT data structure
5637 * @sdev: Pointer to scsi_device.
5639 * This routine sets @sdev hostatdata filed to null.
5642 lpfc_slave_destroy(struct scsi_device *sdev)
5644 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
5645 struct lpfc_hba *phba = vport->phba;
5646 unsigned long flags;
5647 struct lpfc_device_data *device_data = sdev->hostdata;
5649 atomic_dec(&phba->sdev_cnt);
5650 if ((phba->cfg_fof) && (device_data)) {
5651 spin_lock_irqsave(&phba->devicelock, flags);
5652 device_data->available = false;
5653 if (!device_data->oas_enabled)
5654 lpfc_delete_device_data(phba, device_data);
5655 spin_unlock_irqrestore(&phba->devicelock, flags);
5657 sdev->hostdata = NULL;
5662 * lpfc_create_device_data - creates and initializes device data structure for OAS
5663 * @pha: Pointer to host bus adapter structure.
5664 * @vport_wwpn: Pointer to vport's wwpn information
5665 * @target_wwpn: Pointer to target's wwpn information
5666 * @lun: Lun on target
5667 * @atomic_create: Flag to indicate if memory should be allocated using the
5668 * GFP_ATOMIC flag or not.
5670 * This routine creates a device data structure which will contain identifying
5671 * information for the device (host wwpn, target wwpn, lun), state of OAS,
5672 * whether or not the corresponding lun is available by the system,
5673 * and pointer to the rport data.
5677 * Pointer to lpfc_device_data - Success
5679 struct lpfc_device_data*
5680 lpfc_create_device_data(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn,
5681 struct lpfc_name *target_wwpn, uint64_t lun,
5682 uint32_t pri, bool atomic_create)
5685 struct lpfc_device_data *lun_info;
5688 if (unlikely(!phba) || !vport_wwpn || !target_wwpn ||
5692 /* Attempt to create the device data to contain lun info */
5695 memory_flags = GFP_ATOMIC;
5697 memory_flags = GFP_KERNEL;
5698 lun_info = mempool_alloc(phba->device_data_mem_pool, memory_flags);
5701 INIT_LIST_HEAD(&lun_info->listentry);
5702 lun_info->rport_data = NULL;
5703 memcpy(&lun_info->device_id.vport_wwpn, vport_wwpn,
5704 sizeof(struct lpfc_name));
5705 memcpy(&lun_info->device_id.target_wwpn, target_wwpn,
5706 sizeof(struct lpfc_name));
5707 lun_info->device_id.lun = lun;
5708 lun_info->oas_enabled = false;
5709 lun_info->priority = pri;
5710 lun_info->available = false;
5715 * lpfc_delete_device_data - frees a device data structure for OAS
5716 * @pha: Pointer to host bus adapter structure.
5717 * @lun_info: Pointer to device data structure to free.
5719 * This routine frees the previously allocated device data structure passed.
5723 lpfc_delete_device_data(struct lpfc_hba *phba,
5724 struct lpfc_device_data *lun_info)
5727 if (unlikely(!phba) || !lun_info ||
5731 if (!list_empty(&lun_info->listentry))
5732 list_del(&lun_info->listentry);
5733 mempool_free(lun_info, phba->device_data_mem_pool);
5738 * __lpfc_get_device_data - returns the device data for the specified lun
5739 * @pha: Pointer to host bus adapter structure.
5740 * @list: Point to list to search.
5741 * @vport_wwpn: Pointer to vport's wwpn information
5742 * @target_wwpn: Pointer to target's wwpn information
5743 * @lun: Lun on target
5745 * This routine searches the list passed for the specified lun's device data.
5746 * This function does not hold locks, it is the responsibility of the caller
5747 * to ensure the proper lock is held before calling the function.
5751 * Pointer to lpfc_device_data - Success
5753 struct lpfc_device_data*
5754 __lpfc_get_device_data(struct lpfc_hba *phba, struct list_head *list,
5755 struct lpfc_name *vport_wwpn,
5756 struct lpfc_name *target_wwpn, uint64_t lun)
5759 struct lpfc_device_data *lun_info;
5761 if (unlikely(!phba) || !list || !vport_wwpn || !target_wwpn ||
5765 /* Check to see if the lun is already enabled for OAS. */
5767 list_for_each_entry(lun_info, list, listentry) {
5768 if ((memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn,
5769 sizeof(struct lpfc_name)) == 0) &&
5770 (memcmp(&lun_info->device_id.target_wwpn, target_wwpn,
5771 sizeof(struct lpfc_name)) == 0) &&
5772 (lun_info->device_id.lun == lun))
5780 * lpfc_find_next_oas_lun - searches for the next oas lun
5781 * @pha: Pointer to host bus adapter structure.
5782 * @vport_wwpn: Pointer to vport's wwpn information
5783 * @target_wwpn: Pointer to target's wwpn information
5784 * @starting_lun: Pointer to the lun to start searching for
5785 * @found_vport_wwpn: Pointer to the found lun's vport wwpn information
5786 * @found_target_wwpn: Pointer to the found lun's target wwpn information
5787 * @found_lun: Pointer to the found lun.
5788 * @found_lun_status: Pointer to status of the found lun.
5790 * This routine searches the luns list for the specified lun
5791 * or the first lun for the vport/target. If the vport wwpn contains
5792 * a zero value then a specific vport is not specified. In this case
5793 * any vport which contains the lun will be considered a match. If the
5794 * target wwpn contains a zero value then a specific target is not specified.
5795 * In this case any target which contains the lun will be considered a
5796 * match. If the lun is found, the lun, vport wwpn, target wwpn and lun status
5797 * are returned. The function will also return the next lun if available.
5798 * If the next lun is not found, starting_lun parameter will be set to
5806 lpfc_find_next_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn,
5807 struct lpfc_name *target_wwpn, uint64_t *starting_lun,
5808 struct lpfc_name *found_vport_wwpn,
5809 struct lpfc_name *found_target_wwpn,
5810 uint64_t *found_lun,
5811 uint32_t *found_lun_status,
5812 uint32_t *found_lun_pri)
5815 unsigned long flags;
5816 struct lpfc_device_data *lun_info;
5817 struct lpfc_device_id *device_id;
5821 if (unlikely(!phba) || !vport_wwpn || !target_wwpn ||
5822 !starting_lun || !found_vport_wwpn ||
5823 !found_target_wwpn || !found_lun || !found_lun_status ||
5824 (*starting_lun == NO_MORE_OAS_LUN) ||
5828 lun = *starting_lun;
5829 *found_lun = NO_MORE_OAS_LUN;
5830 *starting_lun = NO_MORE_OAS_LUN;
5832 /* Search for lun or the lun closet in value */
5834 spin_lock_irqsave(&phba->devicelock, flags);
5835 list_for_each_entry(lun_info, &phba->luns, listentry) {
5836 if (((wwn_to_u64(vport_wwpn->u.wwn) == 0) ||
5837 (memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn,
5838 sizeof(struct lpfc_name)) == 0)) &&
5839 ((wwn_to_u64(target_wwpn->u.wwn) == 0) ||
5840 (memcmp(&lun_info->device_id.target_wwpn, target_wwpn,
5841 sizeof(struct lpfc_name)) == 0)) &&
5842 (lun_info->oas_enabled)) {
5843 device_id = &lun_info->device_id;
5845 ((lun == FIND_FIRST_OAS_LUN) ||
5846 (device_id->lun == lun))) {
5847 *found_lun = device_id->lun;
5848 memcpy(found_vport_wwpn,
5849 &device_id->vport_wwpn,
5850 sizeof(struct lpfc_name));
5851 memcpy(found_target_wwpn,
5852 &device_id->target_wwpn,
5853 sizeof(struct lpfc_name));
5854 if (lun_info->available)
5856 OAS_LUN_STATUS_EXISTS;
5858 *found_lun_status = 0;
5859 *found_lun_pri = lun_info->priority;
5860 if (phba->cfg_oas_flags & OAS_FIND_ANY_VPORT)
5861 memset(vport_wwpn, 0x0,
5862 sizeof(struct lpfc_name));
5863 if (phba->cfg_oas_flags & OAS_FIND_ANY_TARGET)
5864 memset(target_wwpn, 0x0,
5865 sizeof(struct lpfc_name));
5868 *starting_lun = device_id->lun;
5869 memcpy(vport_wwpn, &device_id->vport_wwpn,
5870 sizeof(struct lpfc_name));
5871 memcpy(target_wwpn, &device_id->target_wwpn,
5872 sizeof(struct lpfc_name));
5877 spin_unlock_irqrestore(&phba->devicelock, flags);
5882 * lpfc_enable_oas_lun - enables a lun for OAS operations
5883 * @pha: Pointer to host bus adapter structure.
5884 * @vport_wwpn: Pointer to vport's wwpn information
5885 * @target_wwpn: Pointer to target's wwpn information
5888 * This routine enables a lun for oas operations. The routines does so by
5889 * doing the following :
5891 * 1) Checks to see if the device data for the lun has been created.
5892 * 2) If found, sets the OAS enabled flag if not set and returns.
5893 * 3) Otherwise, creates a device data structure.
5894 * 4) If successfully created, indicates the device data is for an OAS lun,
5895 * indicates the lun is not available and add to the list of luns.
5902 lpfc_enable_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn,
5903 struct lpfc_name *target_wwpn, uint64_t lun, uint8_t pri)
5906 struct lpfc_device_data *lun_info;
5907 unsigned long flags;
5909 if (unlikely(!phba) || !vport_wwpn || !target_wwpn ||
5913 spin_lock_irqsave(&phba->devicelock, flags);
5915 /* Check to see if the device data for the lun has been created */
5916 lun_info = __lpfc_get_device_data(phba, &phba->luns, vport_wwpn,
5919 if (!lun_info->oas_enabled)
5920 lun_info->oas_enabled = true;
5921 lun_info->priority = pri;
5922 spin_unlock_irqrestore(&phba->devicelock, flags);
5926 /* Create an lun info structure and add to list of luns */
5927 lun_info = lpfc_create_device_data(phba, vport_wwpn, target_wwpn, lun,
5930 lun_info->oas_enabled = true;
5931 lun_info->priority = pri;
5932 lun_info->available = false;
5933 list_add_tail(&lun_info->listentry, &phba->luns);
5934 spin_unlock_irqrestore(&phba->devicelock, flags);
5937 spin_unlock_irqrestore(&phba->devicelock, flags);
5942 * lpfc_disable_oas_lun - disables a lun for OAS operations
5943 * @pha: Pointer to host bus adapter structure.
5944 * @vport_wwpn: Pointer to vport's wwpn information
5945 * @target_wwpn: Pointer to target's wwpn information
5948 * This routine disables a lun for oas operations. The routines does so by
5949 * doing the following :
5951 * 1) Checks to see if the device data for the lun is created.
5952 * 2) If present, clears the flag indicating this lun is for OAS.
5953 * 3) If the lun is not available by the system, the device data is
5961 lpfc_disable_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn,
5962 struct lpfc_name *target_wwpn, uint64_t lun, uint8_t pri)
5965 struct lpfc_device_data *lun_info;
5966 unsigned long flags;
5968 if (unlikely(!phba) || !vport_wwpn || !target_wwpn ||
5972 spin_lock_irqsave(&phba->devicelock, flags);
5974 /* Check to see if the lun is available. */
5975 lun_info = __lpfc_get_device_data(phba,
5976 &phba->luns, vport_wwpn,
5979 lun_info->oas_enabled = false;
5980 lun_info->priority = pri;
5981 if (!lun_info->available)
5982 lpfc_delete_device_data(phba, lun_info);
5983 spin_unlock_irqrestore(&phba->devicelock, flags);
5987 spin_unlock_irqrestore(&phba->devicelock, flags);
5992 lpfc_no_command(struct Scsi_Host *shost, struct scsi_cmnd *cmnd)
5994 return SCSI_MLQUEUE_HOST_BUSY;
5998 lpfc_no_handler(struct scsi_cmnd *cmnd)
6004 lpfc_no_slave(struct scsi_device *sdev)
6009 struct scsi_host_template lpfc_template_nvme = {
6010 .module = THIS_MODULE,
6011 .name = LPFC_DRIVER_NAME,
6012 .proc_name = LPFC_DRIVER_NAME,
6014 .queuecommand = lpfc_no_command,
6015 .eh_abort_handler = lpfc_no_handler,
6016 .eh_device_reset_handler = lpfc_no_handler,
6017 .eh_target_reset_handler = lpfc_no_handler,
6018 .eh_bus_reset_handler = lpfc_no_handler,
6019 .eh_host_reset_handler = lpfc_no_handler,
6020 .slave_alloc = lpfc_no_slave,
6021 .slave_configure = lpfc_no_slave,
6022 .scan_finished = lpfc_scan_finished,
6026 .shost_attrs = lpfc_hba_attrs,
6027 .max_sectors = 0xFFFF,
6028 .vendor_id = LPFC_NL_VENDOR_ID,
6029 .track_queue_depth = 0,
6032 struct scsi_host_template lpfc_template = {
6033 .module = THIS_MODULE,
6034 .name = LPFC_DRIVER_NAME,
6035 .proc_name = LPFC_DRIVER_NAME,
6037 .queuecommand = lpfc_queuecommand,
6038 .eh_timed_out = fc_eh_timed_out,
6039 .eh_abort_handler = lpfc_abort_handler,
6040 .eh_device_reset_handler = lpfc_device_reset_handler,
6041 .eh_target_reset_handler = lpfc_target_reset_handler,
6042 .eh_bus_reset_handler = lpfc_bus_reset_handler,
6043 .eh_host_reset_handler = lpfc_host_reset_handler,
6044 .slave_alloc = lpfc_slave_alloc,
6045 .slave_configure = lpfc_slave_configure,
6046 .slave_destroy = lpfc_slave_destroy,
6047 .scan_finished = lpfc_scan_finished,
6049 .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
6050 .cmd_per_lun = LPFC_CMD_PER_LUN,
6051 .shost_attrs = lpfc_hba_attrs,
6052 .max_sectors = 0xFFFF,
6053 .vendor_id = LPFC_NL_VENDOR_ID,
6054 .change_queue_depth = scsi_change_queue_depth,
6055 .track_queue_depth = 1,