1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2015 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
21 #include <linux/pci.h>
22 #include <linux/slab.h>
23 #include <linux/interrupt.h>
24 #include <linux/export.h>
25 #include <linux/delay.h>
26 #include <asm/unaligned.h>
27 #include <linux/crc-t10dif.h>
28 #include <net/checksum.h>
30 #include <scsi/scsi.h>
31 #include <scsi/scsi_device.h>
32 #include <scsi/scsi_eh.h>
33 #include <scsi/scsi_host.h>
34 #include <scsi/scsi_tcq.h>
35 #include <scsi/scsi_transport_fc.h>
37 #include "lpfc_version.h"
41 #include "lpfc_sli4.h"
43 #include "lpfc_disc.h"
45 #include "lpfc_scsi.h"
46 #include "lpfc_logmsg.h"
47 #include "lpfc_crtn.h"
48 #include "lpfc_vport.h"
50 #define LPFC_RESET_WAIT 2
51 #define LPFC_ABORT_WAIT 2
53 int _dump_buf_done = 1;
55 static char *dif_op_str[] = {
65 struct scsi_dif_tuple {
66 __be16 guard_tag; /* Checksum */
67 __be16 app_tag; /* Opaque storage */
68 __be32 ref_tag; /* Target LBA or indirect LBA */
71 static struct lpfc_rport_data *
72 lpfc_rport_data_from_scsi_device(struct scsi_device *sdev)
74 struct lpfc_vport *vport = (struct lpfc_vport *)sdev->host->hostdata;
76 if (vport->phba->cfg_fof)
77 return ((struct lpfc_device_data *)sdev->hostdata)->rport_data;
79 return (struct lpfc_rport_data *)sdev->hostdata;
83 lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb);
85 lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb);
87 lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc);
90 lpfc_debug_save_data(struct lpfc_hba *phba, struct scsi_cmnd *cmnd)
93 struct scatterlist *sgde = scsi_sglist(cmnd);
95 if (!_dump_buf_data) {
96 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
97 "9050 BLKGRD: ERROR %s _dump_buf_data is NULL\n",
104 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
105 "9051 BLKGRD: ERROR: data scatterlist is null\n");
109 dst = (void *) _dump_buf_data;
112 memcpy(dst, src, sgde->length);
114 sgde = sg_next(sgde);
119 lpfc_debug_save_dif(struct lpfc_hba *phba, struct scsi_cmnd *cmnd)
122 struct scatterlist *sgde = scsi_prot_sglist(cmnd);
124 if (!_dump_buf_dif) {
125 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
126 "9052 BLKGRD: ERROR %s _dump_buf_data is NULL\n",
132 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
133 "9053 BLKGRD: ERROR: prot scatterlist is null\n");
140 memcpy(dst, src, sgde->length);
142 sgde = sg_next(sgde);
146 static inline unsigned
147 lpfc_cmd_blksize(struct scsi_cmnd *sc)
149 return sc->device->sector_size;
152 #define LPFC_CHECK_PROTECT_GUARD 1
153 #define LPFC_CHECK_PROTECT_REF 2
154 static inline unsigned
155 lpfc_cmd_protect(struct scsi_cmnd *sc, int flag)
160 static inline unsigned
161 lpfc_cmd_guard_csum(struct scsi_cmnd *sc)
163 if (lpfc_prot_group_type(NULL, sc) == LPFC_PG_TYPE_NO_DIF)
165 if (scsi_host_get_guard(sc->device->host) == SHOST_DIX_GUARD_IP)
171 * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge.
172 * @phba: Pointer to HBA object.
173 * @lpfc_cmd: lpfc scsi command object pointer.
175 * This function is called from the lpfc_prep_task_mgmt_cmd function to
176 * set the last bit in the response sge entry.
179 lpfc_sli4_set_rsp_sgl_last(struct lpfc_hba *phba,
180 struct lpfc_scsi_buf *lpfc_cmd)
182 struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl;
185 sgl->word2 = le32_to_cpu(sgl->word2);
186 bf_set(lpfc_sli4_sge_last, sgl, 1);
187 sgl->word2 = cpu_to_le32(sgl->word2);
192 * lpfc_update_stats - Update statistical data for the command completion
193 * @phba: Pointer to HBA object.
194 * @lpfc_cmd: lpfc scsi command object pointer.
196 * This function is called when there is a command completion and this
197 * function updates the statistical data for the command completion.
200 lpfc_update_stats(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
202 struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
203 struct lpfc_nodelist *pnode = rdata->pnode;
204 struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
206 struct Scsi_Host *shost = cmd->device->host;
207 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
208 unsigned long latency;
214 latency = jiffies_to_msecs((long)jiffies - (long)lpfc_cmd->start_time);
216 spin_lock_irqsave(shost->host_lock, flags);
217 if (!vport->stat_data_enabled ||
218 vport->stat_data_blocked ||
221 (phba->bucket_type == LPFC_NO_BUCKET)) {
222 spin_unlock_irqrestore(shost->host_lock, flags);
226 if (phba->bucket_type == LPFC_LINEAR_BUCKET) {
227 i = (latency + phba->bucket_step - 1 - phba->bucket_base)/
229 /* check array subscript bounds */
232 else if (i >= LPFC_MAX_BUCKET_COUNT)
233 i = LPFC_MAX_BUCKET_COUNT - 1;
235 for (i = 0; i < LPFC_MAX_BUCKET_COUNT-1; i++)
236 if (latency <= (phba->bucket_base +
237 ((1<<i)*phba->bucket_step)))
241 pnode->lat_data[i].cmd_count++;
242 spin_unlock_irqrestore(shost->host_lock, flags);
246 * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread
247 * @phba: The Hba for which this call is being executed.
249 * This routine is called when there is resource error in driver or firmware.
250 * This routine posts WORKER_RAMP_DOWN_QUEUE event for @phba. This routine
251 * posts at most 1 event each second. This routine wakes up worker thread of
252 * @phba to process WORKER_RAM_DOWN_EVENT event.
254 * This routine should be called with no lock held.
257 lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
261 unsigned long expires;
263 spin_lock_irqsave(&phba->hbalock, flags);
264 atomic_inc(&phba->num_rsrc_err);
265 phba->last_rsrc_error_time = jiffies;
267 expires = phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL;
268 if (time_after(expires, jiffies)) {
269 spin_unlock_irqrestore(&phba->hbalock, flags);
273 phba->last_ramp_down_time = jiffies;
275 spin_unlock_irqrestore(&phba->hbalock, flags);
277 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
278 evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE;
280 phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE;
281 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
284 lpfc_worker_wake_up(phba);
289 * lpfc_ramp_down_queue_handler - WORKER_RAMP_DOWN_QUEUE event handler
290 * @phba: The Hba for which this call is being executed.
292 * This routine is called to process WORKER_RAMP_DOWN_QUEUE event for worker
293 * thread.This routine reduces queue depth for all scsi device on each vport
294 * associated with @phba.
297 lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
299 struct lpfc_vport **vports;
300 struct Scsi_Host *shost;
301 struct scsi_device *sdev;
302 unsigned long new_queue_depth;
303 unsigned long num_rsrc_err, num_cmd_success;
306 num_rsrc_err = atomic_read(&phba->num_rsrc_err);
307 num_cmd_success = atomic_read(&phba->num_cmd_success);
310 * The error and success command counters are global per
311 * driver instance. If another handler has already
312 * operated on this error event, just exit.
314 if (num_rsrc_err == 0)
317 vports = lpfc_create_vport_work_array(phba);
319 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
320 shost = lpfc_shost_from_vport(vports[i]);
321 shost_for_each_device(sdev, shost) {
323 sdev->queue_depth * num_rsrc_err /
324 (num_rsrc_err + num_cmd_success);
325 if (!new_queue_depth)
326 new_queue_depth = sdev->queue_depth - 1;
328 new_queue_depth = sdev->queue_depth -
330 scsi_change_queue_depth(sdev, new_queue_depth);
333 lpfc_destroy_vport_work_array(phba, vports);
334 atomic_set(&phba->num_rsrc_err, 0);
335 atomic_set(&phba->num_cmd_success, 0);
339 * lpfc_scsi_dev_block - set all scsi hosts to block state
340 * @phba: Pointer to HBA context object.
342 * This function walks vport list and set each SCSI host to block state
343 * by invoking fc_remote_port_delete() routine. This function is invoked
344 * with EEH when device's PCI slot has been permanently disabled.
347 lpfc_scsi_dev_block(struct lpfc_hba *phba)
349 struct lpfc_vport **vports;
350 struct Scsi_Host *shost;
351 struct scsi_device *sdev;
352 struct fc_rport *rport;
355 vports = lpfc_create_vport_work_array(phba);
357 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
358 shost = lpfc_shost_from_vport(vports[i]);
359 shost_for_each_device(sdev, shost) {
360 rport = starget_to_rport(scsi_target(sdev));
361 fc_remote_port_delete(rport);
364 lpfc_destroy_vport_work_array(phba, vports);
368 * lpfc_new_scsi_buf_s3 - Scsi buffer allocator for HBA with SLI3 IF spec
369 * @vport: The virtual port for which this call being executed.
370 * @num_to_allocate: The requested number of buffers to allocate.
372 * This routine allocates a scsi buffer for device with SLI-3 interface spec,
373 * the scsi buffer contains all the necessary information needed to initiate
374 * a SCSI I/O. The non-DMAable buffer region contains information to build
375 * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP,
376 * and the initial BPL. In addition to allocating memory, the FCP CMND and
377 * FCP RSP BDEs are setup in the BPL and the BPL BDE is setup in the IOCB.
380 * int - number of scsi buffers that were allocated.
381 * 0 = failure, less than num_to_alloc is a partial failure.
384 lpfc_new_scsi_buf_s3(struct lpfc_vport *vport, int num_to_alloc)
386 struct lpfc_hba *phba = vport->phba;
387 struct lpfc_scsi_buf *psb;
388 struct ulp_bde64 *bpl;
390 dma_addr_t pdma_phys_fcp_cmd;
391 dma_addr_t pdma_phys_fcp_rsp;
392 dma_addr_t pdma_phys_bpl;
396 bpl_size = phba->cfg_sg_dma_buf_size -
397 (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp));
399 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
400 "9067 ALLOC %d scsi_bufs: %d (%d + %d + %d)\n",
401 num_to_alloc, phba->cfg_sg_dma_buf_size,
402 (int)sizeof(struct fcp_cmnd),
403 (int)sizeof(struct fcp_rsp), bpl_size);
405 for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
406 psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL);
411 * Get memory from the pci pool to map the virt space to pci
412 * bus space for an I/O. The DMA buffer includes space for the
413 * struct fcp_cmnd, struct fcp_rsp and the number of bde's
414 * necessary to support the sg_tablesize.
416 psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool,
417 GFP_KERNEL, &psb->dma_handle);
423 /* Initialize virtual ptrs to dma_buf region. */
424 memset(psb->data, 0, phba->cfg_sg_dma_buf_size);
426 /* Allocate iotag for psb->cur_iocbq. */
427 iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq);
429 pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
430 psb->data, psb->dma_handle);
434 psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP;
436 psb->fcp_cmnd = psb->data;
437 psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd);
438 psb->fcp_bpl = psb->data + sizeof(struct fcp_cmnd) +
439 sizeof(struct fcp_rsp);
441 /* Initialize local short-hand pointers. */
443 pdma_phys_fcp_cmd = psb->dma_handle;
444 pdma_phys_fcp_rsp = psb->dma_handle + sizeof(struct fcp_cmnd);
445 pdma_phys_bpl = psb->dma_handle + sizeof(struct fcp_cmnd) +
446 sizeof(struct fcp_rsp);
449 * The first two bdes are the FCP_CMD and FCP_RSP. The balance
450 * are sg list bdes. Initialize the first two and leave the
451 * rest for queuecommand.
453 bpl[0].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd));
454 bpl[0].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd));
455 bpl[0].tus.f.bdeSize = sizeof(struct fcp_cmnd);
456 bpl[0].tus.f.bdeFlags = BUFF_TYPE_BDE_64;
457 bpl[0].tus.w = le32_to_cpu(bpl[0].tus.w);
459 /* Setup the physical region for the FCP RSP */
460 bpl[1].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp));
461 bpl[1].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp));
462 bpl[1].tus.f.bdeSize = sizeof(struct fcp_rsp);
463 bpl[1].tus.f.bdeFlags = BUFF_TYPE_BDE_64;
464 bpl[1].tus.w = le32_to_cpu(bpl[1].tus.w);
467 * Since the IOCB for the FCP I/O is built into this
468 * lpfc_scsi_buf, initialize it with all known data now.
470 iocb = &psb->cur_iocbq.iocb;
471 iocb->un.fcpi64.bdl.ulpIoTag32 = 0;
472 if ((phba->sli_rev == 3) &&
473 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) {
474 /* fill in immediate fcp command BDE */
475 iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_IMMED;
476 iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd);
477 iocb->un.fcpi64.bdl.addrLow = offsetof(IOCB_t,
479 iocb->un.fcpi64.bdl.addrHigh = 0;
480 iocb->ulpBdeCount = 0;
482 /* fill in response BDE */
483 iocb->unsli3.fcp_ext.rbde.tus.f.bdeFlags =
485 iocb->unsli3.fcp_ext.rbde.tus.f.bdeSize =
486 sizeof(struct fcp_rsp);
487 iocb->unsli3.fcp_ext.rbde.addrLow =
488 putPaddrLow(pdma_phys_fcp_rsp);
489 iocb->unsli3.fcp_ext.rbde.addrHigh =
490 putPaddrHigh(pdma_phys_fcp_rsp);
492 iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
493 iocb->un.fcpi64.bdl.bdeSize =
494 (2 * sizeof(struct ulp_bde64));
495 iocb->un.fcpi64.bdl.addrLow =
496 putPaddrLow(pdma_phys_bpl);
497 iocb->un.fcpi64.bdl.addrHigh =
498 putPaddrHigh(pdma_phys_bpl);
499 iocb->ulpBdeCount = 1;
502 iocb->ulpClass = CLASS3;
503 psb->status = IOSTAT_SUCCESS;
504 /* Put it back into the SCSI buffer list */
505 psb->cur_iocbq.context1 = psb;
506 lpfc_release_scsi_buf_s3(phba, psb);
514 * lpfc_sli4_vport_delete_fcp_xri_aborted -Remove all ndlp references for vport
515 * @vport: pointer to lpfc vport data structure.
517 * This routine is invoked by the vport cleanup for deletions and the cleanup
518 * for an ndlp on removal.
521 lpfc_sli4_vport_delete_fcp_xri_aborted(struct lpfc_vport *vport)
523 struct lpfc_hba *phba = vport->phba;
524 struct lpfc_scsi_buf *psb, *next_psb;
525 unsigned long iflag = 0;
527 spin_lock_irqsave(&phba->hbalock, iflag);
528 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
529 list_for_each_entry_safe(psb, next_psb,
530 &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) {
531 if (psb->rdata && psb->rdata->pnode
532 && psb->rdata->pnode->vport == vport)
535 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
536 spin_unlock_irqrestore(&phba->hbalock, iflag);
540 * lpfc_sli4_fcp_xri_aborted - Fast-path process of fcp xri abort
541 * @phba: pointer to lpfc hba data structure.
542 * @axri: pointer to the fcp xri abort wcqe structure.
544 * This routine is invoked by the worker thread to process a SLI4 fast-path
548 lpfc_sli4_fcp_xri_aborted(struct lpfc_hba *phba,
549 struct sli4_wcqe_xri_aborted *axri)
551 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
552 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
553 struct lpfc_scsi_buf *psb, *next_psb;
554 unsigned long iflag = 0;
555 struct lpfc_iocbq *iocbq;
557 struct lpfc_nodelist *ndlp;
559 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
561 spin_lock_irqsave(&phba->hbalock, iflag);
562 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
563 list_for_each_entry_safe(psb, next_psb,
564 &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) {
565 if (psb->cur_iocbq.sli4_xritag == xri) {
566 list_del(&psb->list);
568 psb->status = IOSTAT_SUCCESS;
570 &phba->sli4_hba.abts_scsi_buf_list_lock);
571 if (psb->rdata && psb->rdata->pnode)
572 ndlp = psb->rdata->pnode;
576 rrq_empty = list_empty(&phba->active_rrq_list);
577 spin_unlock_irqrestore(&phba->hbalock, iflag);
579 lpfc_set_rrq_active(phba, ndlp,
580 psb->cur_iocbq.sli4_lxritag, rxid, 1);
581 lpfc_sli4_abts_err_handler(phba, ndlp, axri);
583 lpfc_release_scsi_buf_s4(phba, psb);
585 lpfc_worker_wake_up(phba);
589 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
590 for (i = 1; i <= phba->sli.last_iotag; i++) {
591 iocbq = phba->sli.iocbq_lookup[i];
593 if (!(iocbq->iocb_flag & LPFC_IO_FCP) ||
594 (iocbq->iocb_flag & LPFC_IO_LIBDFC))
596 if (iocbq->sli4_xritag != xri)
598 psb = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
600 spin_unlock_irqrestore(&phba->hbalock, iflag);
601 if (!list_empty(&pring->txq))
602 lpfc_worker_wake_up(phba);
606 spin_unlock_irqrestore(&phba->hbalock, iflag);
610 * lpfc_sli4_post_scsi_sgl_list - Psot blocks of scsi buffer sgls from a list
611 * @phba: pointer to lpfc hba data structure.
612 * @post_sblist: pointer to the scsi buffer list.
614 * This routine walks a list of scsi buffers that was passed in. It attempts
615 * to construct blocks of scsi buffer sgls which contains contiguous xris and
616 * uses the non-embedded SGL block post mailbox commands to post to the port.
617 * For single SCSI buffer sgl with non-contiguous xri, if any, it shall use
618 * embedded SGL post mailbox command for posting. The @post_sblist passed in
619 * must be local list, thus no lock is needed when manipulate the list.
621 * Returns: 0 = failure, non-zero number of successfully posted buffers.
624 lpfc_sli4_post_scsi_sgl_list(struct lpfc_hba *phba,
625 struct list_head *post_sblist, int sb_count)
627 struct lpfc_scsi_buf *psb, *psb_next;
628 int status, sgl_size;
629 int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0;
630 dma_addr_t pdma_phys_bpl1;
631 int last_xritag = NO_XRI;
632 LIST_HEAD(prep_sblist);
633 LIST_HEAD(blck_sblist);
634 LIST_HEAD(scsi_sblist);
640 sgl_size = phba->cfg_sg_dma_buf_size -
641 (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp));
643 list_for_each_entry_safe(psb, psb_next, post_sblist, list) {
644 list_del_init(&psb->list);
646 if ((last_xritag != NO_XRI) &&
647 (psb->cur_iocbq.sli4_xritag != last_xritag + 1)) {
648 /* a hole in xri block, form a sgl posting block */
649 list_splice_init(&prep_sblist, &blck_sblist);
650 post_cnt = block_cnt - 1;
651 /* prepare list for next posting block */
652 list_add_tail(&psb->list, &prep_sblist);
655 /* prepare list for next posting block */
656 list_add_tail(&psb->list, &prep_sblist);
657 /* enough sgls for non-embed sgl mbox command */
658 if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
659 list_splice_init(&prep_sblist, &blck_sblist);
660 post_cnt = block_cnt;
665 last_xritag = psb->cur_iocbq.sli4_xritag;
667 /* end of repost sgl list condition for SCSI buffers */
668 if (num_posting == sb_count) {
670 /* last sgl posting block */
671 list_splice_init(&prep_sblist, &blck_sblist);
672 post_cnt = block_cnt;
673 } else if (block_cnt == 1) {
674 /* last single sgl with non-contiguous xri */
675 if (sgl_size > SGL_PAGE_SIZE)
676 pdma_phys_bpl1 = psb->dma_phys_bpl +
680 status = lpfc_sli4_post_sgl(phba,
683 psb->cur_iocbq.sli4_xritag);
685 /* failure, put on abort scsi list */
688 /* success, put on SCSI buffer list */
690 psb->status = IOSTAT_SUCCESS;
693 /* success, put on SCSI buffer sgl list */
694 list_add_tail(&psb->list, &scsi_sblist);
698 /* continue until a nembed page worth of sgls */
702 /* post block of SCSI buffer list sgls */
703 status = lpfc_sli4_post_scsi_sgl_block(phba, &blck_sblist,
706 /* don't reset xirtag due to hole in xri block */
708 last_xritag = NO_XRI;
710 /* reset SCSI buffer post count for next round of posting */
713 /* put posted SCSI buffer-sgl posted on SCSI buffer sgl list */
714 while (!list_empty(&blck_sblist)) {
715 list_remove_head(&blck_sblist, psb,
716 struct lpfc_scsi_buf, list);
718 /* failure, put on abort scsi list */
721 /* success, put on SCSI buffer list */
723 psb->status = IOSTAT_SUCCESS;
726 list_add_tail(&psb->list, &scsi_sblist);
729 /* Push SCSI buffers with sgl posted to the availble list */
730 while (!list_empty(&scsi_sblist)) {
731 list_remove_head(&scsi_sblist, psb,
732 struct lpfc_scsi_buf, list);
733 lpfc_release_scsi_buf_s4(phba, psb);
739 * lpfc_sli4_repost_scsi_sgl_list - Repsot all the allocated scsi buffer sgls
740 * @phba: pointer to lpfc hba data structure.
742 * This routine walks the list of scsi buffers that have been allocated and
743 * repost them to the port by using SGL block post. This is needed after a
744 * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine
745 * is responsible for moving all scsi buffers on the lpfc_abts_scsi_sgl_list
746 * to the lpfc_scsi_buf_list. If the repost fails, reject all scsi buffers.
748 * Returns: 0 = success, non-zero failure.
751 lpfc_sli4_repost_scsi_sgl_list(struct lpfc_hba *phba)
753 LIST_HEAD(post_sblist);
754 int num_posted, rc = 0;
756 /* get all SCSI buffers need to repost to a local list */
757 spin_lock_irq(&phba->scsi_buf_list_get_lock);
758 spin_lock(&phba->scsi_buf_list_put_lock);
759 list_splice_init(&phba->lpfc_scsi_buf_list_get, &post_sblist);
760 list_splice(&phba->lpfc_scsi_buf_list_put, &post_sblist);
761 spin_unlock(&phba->scsi_buf_list_put_lock);
762 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
764 /* post the list of scsi buffer sgls to port if available */
765 if (!list_empty(&post_sblist)) {
766 num_posted = lpfc_sli4_post_scsi_sgl_list(phba, &post_sblist,
767 phba->sli4_hba.scsi_xri_cnt);
768 /* failed to post any scsi buffer, return error */
776 * lpfc_new_scsi_buf_s4 - Scsi buffer allocator for HBA with SLI4 IF spec
777 * @vport: The virtual port for which this call being executed.
778 * @num_to_allocate: The requested number of buffers to allocate.
780 * This routine allocates scsi buffers for device with SLI-4 interface spec,
781 * the scsi buffer contains all the necessary information needed to initiate
782 * a SCSI I/O. After allocating up to @num_to_allocate SCSI buffers and put
783 * them on a list, it post them to the port by using SGL block post.
786 * int - number of scsi buffers that were allocated and posted.
787 * 0 = failure, less than num_to_alloc is a partial failure.
790 lpfc_new_scsi_buf_s4(struct lpfc_vport *vport, int num_to_alloc)
792 struct lpfc_hba *phba = vport->phba;
793 struct lpfc_scsi_buf *psb;
794 struct sli4_sge *sgl;
796 dma_addr_t pdma_phys_fcp_cmd;
797 dma_addr_t pdma_phys_fcp_rsp;
798 dma_addr_t pdma_phys_bpl;
799 uint16_t iotag, lxri = 0;
800 int bcnt, num_posted, sgl_size;
801 LIST_HEAD(prep_sblist);
802 LIST_HEAD(post_sblist);
803 LIST_HEAD(scsi_sblist);
805 sgl_size = phba->cfg_sg_dma_buf_size -
806 (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp));
808 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
809 "9068 ALLOC %d scsi_bufs: %d (%d + %d + %d)\n",
810 num_to_alloc, phba->cfg_sg_dma_buf_size, sgl_size,
811 (int)sizeof(struct fcp_cmnd),
812 (int)sizeof(struct fcp_rsp));
814 for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
815 psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL);
819 * Get memory from the pci pool to map the virt space to
820 * pci bus space for an I/O. The DMA buffer includes space
821 * for the struct fcp_cmnd, struct fcp_rsp and the number
822 * of bde's necessary to support the sg_tablesize.
824 psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool,
825 GFP_KERNEL, &psb->dma_handle);
830 memset(psb->data, 0, phba->cfg_sg_dma_buf_size);
833 * 4K Page alignment is CRITICAL to BlockGuard, double check
836 if (phba->cfg_enable_bg && (((unsigned long)(psb->data) &
837 (unsigned long)(SLI4_PAGE_SIZE - 1)) != 0)) {
838 pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
839 psb->data, psb->dma_handle);
845 lxri = lpfc_sli4_next_xritag(phba);
846 if (lxri == NO_XRI) {
847 pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
848 psb->data, psb->dma_handle);
853 /* Allocate iotag for psb->cur_iocbq. */
854 iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq);
856 pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
857 psb->data, psb->dma_handle);
859 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
860 "3368 Failed to allocated IOTAG for"
861 " XRI:0x%x\n", lxri);
862 lpfc_sli4_free_xri(phba, lxri);
865 psb->cur_iocbq.sli4_lxritag = lxri;
866 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
867 psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP;
868 psb->fcp_bpl = psb->data;
869 psb->fcp_cmnd = (psb->data + sgl_size);
870 psb->fcp_rsp = (struct fcp_rsp *)((uint8_t *)psb->fcp_cmnd +
871 sizeof(struct fcp_cmnd));
873 /* Initialize local short-hand pointers. */
874 sgl = (struct sli4_sge *)psb->fcp_bpl;
875 pdma_phys_bpl = psb->dma_handle;
876 pdma_phys_fcp_cmd = (psb->dma_handle + sgl_size);
877 pdma_phys_fcp_rsp = pdma_phys_fcp_cmd + sizeof(struct fcp_cmnd);
880 * The first two bdes are the FCP_CMD and FCP_RSP.
881 * The balance are sg list bdes. Initialize the
882 * first two and leave the rest for queuecommand.
884 sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd));
885 sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd));
886 sgl->word2 = le32_to_cpu(sgl->word2);
887 bf_set(lpfc_sli4_sge_last, sgl, 0);
888 sgl->word2 = cpu_to_le32(sgl->word2);
889 sgl->sge_len = cpu_to_le32(sizeof(struct fcp_cmnd));
892 /* Setup the physical region for the FCP RSP */
893 sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp));
894 sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp));
895 sgl->word2 = le32_to_cpu(sgl->word2);
896 bf_set(lpfc_sli4_sge_last, sgl, 1);
897 sgl->word2 = cpu_to_le32(sgl->word2);
898 sgl->sge_len = cpu_to_le32(sizeof(struct fcp_rsp));
901 * Since the IOCB for the FCP I/O is built into this
902 * lpfc_scsi_buf, initialize it with all known data now.
904 iocb = &psb->cur_iocbq.iocb;
905 iocb->un.fcpi64.bdl.ulpIoTag32 = 0;
906 iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_64;
907 /* setting the BLP size to 2 * sizeof BDE may not be correct.
908 * We are setting the bpl to point to out sgl. An sgl's
909 * entries are 16 bytes, a bpl entries are 12 bytes.
911 iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd);
912 iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys_fcp_cmd);
913 iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys_fcp_cmd);
914 iocb->ulpBdeCount = 1;
916 iocb->ulpClass = CLASS3;
917 psb->cur_iocbq.context1 = psb;
918 psb->dma_phys_bpl = pdma_phys_bpl;
920 /* add the scsi buffer to a post list */
921 list_add_tail(&psb->list, &post_sblist);
922 spin_lock_irq(&phba->scsi_buf_list_get_lock);
923 phba->sli4_hba.scsi_xri_cnt++;
924 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
926 lpfc_printf_log(phba, KERN_INFO, LOG_BG,
927 "3021 Allocate %d out of %d requested new SCSI "
928 "buffers\n", bcnt, num_to_alloc);
930 /* post the list of scsi buffer sgls to port if available */
931 if (!list_empty(&post_sblist))
932 num_posted = lpfc_sli4_post_scsi_sgl_list(phba,
941 * lpfc_new_scsi_buf - Wrapper funciton for scsi buffer allocator
942 * @vport: The virtual port for which this call being executed.
943 * @num_to_allocate: The requested number of buffers to allocate.
945 * This routine wraps the actual SCSI buffer allocator function pointer from
946 * the lpfc_hba struct.
949 * int - number of scsi buffers that were allocated.
950 * 0 = failure, less than num_to_alloc is a partial failure.
953 lpfc_new_scsi_buf(struct lpfc_vport *vport, int num_to_alloc)
955 return vport->phba->lpfc_new_scsi_buf(vport, num_to_alloc);
959 * lpfc_get_scsi_buf_s3 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
960 * @phba: The HBA for which this call is being executed.
962 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
963 * and returns to caller.
967 * Pointer to lpfc_scsi_buf - Success
969 static struct lpfc_scsi_buf*
970 lpfc_get_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
972 struct lpfc_scsi_buf * lpfc_cmd = NULL;
973 struct list_head *scsi_buf_list_get = &phba->lpfc_scsi_buf_list_get;
974 unsigned long iflag = 0;
976 spin_lock_irqsave(&phba->scsi_buf_list_get_lock, iflag);
977 list_remove_head(scsi_buf_list_get, lpfc_cmd, struct lpfc_scsi_buf,
980 spin_lock(&phba->scsi_buf_list_put_lock);
981 list_splice(&phba->lpfc_scsi_buf_list_put,
982 &phba->lpfc_scsi_buf_list_get);
983 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
984 list_remove_head(scsi_buf_list_get, lpfc_cmd,
985 struct lpfc_scsi_buf, list);
986 spin_unlock(&phba->scsi_buf_list_put_lock);
988 spin_unlock_irqrestore(&phba->scsi_buf_list_get_lock, iflag);
992 * lpfc_get_scsi_buf_s4 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
993 * @phba: The HBA for which this call is being executed.
995 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
996 * and returns to caller.
1000 * Pointer to lpfc_scsi_buf - Success
1002 static struct lpfc_scsi_buf*
1003 lpfc_get_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1005 struct lpfc_scsi_buf *lpfc_cmd, *lpfc_cmd_next;
1006 unsigned long iflag = 0;
1009 spin_lock_irqsave(&phba->scsi_buf_list_get_lock, iflag);
1010 list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next,
1011 &phba->lpfc_scsi_buf_list_get, list) {
1012 if (lpfc_test_rrq_active(phba, ndlp,
1013 lpfc_cmd->cur_iocbq.sli4_lxritag))
1015 list_del(&lpfc_cmd->list);
1020 spin_lock(&phba->scsi_buf_list_put_lock);
1021 list_splice(&phba->lpfc_scsi_buf_list_put,
1022 &phba->lpfc_scsi_buf_list_get);
1023 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
1024 spin_unlock(&phba->scsi_buf_list_put_lock);
1025 list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next,
1026 &phba->lpfc_scsi_buf_list_get, list) {
1027 if (lpfc_test_rrq_active(
1028 phba, ndlp, lpfc_cmd->cur_iocbq.sli4_lxritag))
1030 list_del(&lpfc_cmd->list);
1035 spin_unlock_irqrestore(&phba->scsi_buf_list_get_lock, iflag);
1041 * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
1042 * @phba: The HBA for which this call is being executed.
1044 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
1045 * and returns to caller.
1049 * Pointer to lpfc_scsi_buf - Success
1051 static struct lpfc_scsi_buf*
1052 lpfc_get_scsi_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1054 return phba->lpfc_get_scsi_buf(phba, ndlp);
1058 * lpfc_release_scsi_buf - Return a scsi buffer back to hba scsi buf list
1059 * @phba: The Hba for which this call is being executed.
1060 * @psb: The scsi buffer which is being released.
1062 * This routine releases @psb scsi buffer by adding it to tail of @phba
1063 * lpfc_scsi_buf_list list.
1066 lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
1068 unsigned long iflag = 0;
1071 psb->nonsg_phys = 0;
1072 psb->prot_seg_cnt = 0;
1074 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
1076 psb->cur_iocbq.iocb_flag = LPFC_IO_FCP;
1077 list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list_put);
1078 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
1082 * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list.
1083 * @phba: The Hba for which this call is being executed.
1084 * @psb: The scsi buffer which is being released.
1086 * This routine releases @psb scsi buffer by adding it to tail of @phba
1087 * lpfc_scsi_buf_list list. For SLI4 XRI's are tied to the scsi buffer
1088 * and cannot be reused for at least RA_TOV amount of time if it was
1092 lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
1094 unsigned long iflag = 0;
1097 psb->nonsg_phys = 0;
1098 psb->prot_seg_cnt = 0;
1100 if (psb->exch_busy) {
1101 spin_lock_irqsave(&phba->sli4_hba.abts_scsi_buf_list_lock,
1104 list_add_tail(&psb->list,
1105 &phba->sli4_hba.lpfc_abts_scsi_buf_list);
1106 spin_unlock_irqrestore(&phba->sli4_hba.abts_scsi_buf_list_lock,
1110 psb->cur_iocbq.iocb_flag = LPFC_IO_FCP;
1111 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
1112 list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list_put);
1113 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
1118 * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list.
1119 * @phba: The Hba for which this call is being executed.
1120 * @psb: The scsi buffer which is being released.
1122 * This routine releases @psb scsi buffer by adding it to tail of @phba
1123 * lpfc_scsi_buf_list list.
1126 lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
1129 phba->lpfc_release_scsi_buf(phba, psb);
1133 * lpfc_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
1134 * @phba: The Hba for which this call is being executed.
1135 * @lpfc_cmd: The scsi buffer which is going to be mapped.
1137 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
1138 * field of @lpfc_cmd for device with SLI-3 interface spec. This routine scans
1139 * through sg elements and format the bdea. This routine also initializes all
1140 * IOCB fields which are dependent on scsi command request buffer.
1147 lpfc_scsi_prep_dma_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
1149 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
1150 struct scatterlist *sgel = NULL;
1151 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
1152 struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl;
1153 struct lpfc_iocbq *iocbq = &lpfc_cmd->cur_iocbq;
1154 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
1155 struct ulp_bde64 *data_bde = iocb_cmd->unsli3.fcp_ext.dbde;
1156 dma_addr_t physaddr;
1157 uint32_t num_bde = 0;
1158 int nseg, datadir = scsi_cmnd->sc_data_direction;
1161 * There are three possibilities here - use scatter-gather segment, use
1162 * the single mapping, or neither. Start the lpfc command prep by
1163 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
1167 if (scsi_sg_count(scsi_cmnd)) {
1169 * The driver stores the segment count returned from pci_map_sg
1170 * because this a count of dma-mappings used to map the use_sg
1171 * pages. They are not guaranteed to be the same for those
1172 * architectures that implement an IOMMU.
1175 nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd),
1176 scsi_sg_count(scsi_cmnd), datadir);
1177 if (unlikely(!nseg))
1180 lpfc_cmd->seg_cnt = nseg;
1181 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
1182 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1183 "9064 BLKGRD: %s: Too many sg segments from "
1184 "dma_map_sg. Config %d, seg_cnt %d\n",
1185 __func__, phba->cfg_sg_seg_cnt,
1187 lpfc_cmd->seg_cnt = 0;
1188 scsi_dma_unmap(scsi_cmnd);
1193 * The driver established a maximum scatter-gather segment count
1194 * during probe that limits the number of sg elements in any
1195 * single scsi command. Just run through the seg_cnt and format
1197 * When using SLI-3 the driver will try to fit all the BDEs into
1198 * the IOCB. If it can't then the BDEs get added to a BPL as it
1199 * does for SLI-2 mode.
1201 scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) {
1202 physaddr = sg_dma_address(sgel);
1203 if (phba->sli_rev == 3 &&
1204 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
1205 !(iocbq->iocb_flag & DSS_SECURITY_OP) &&
1206 nseg <= LPFC_EXT_DATA_BDE_COUNT) {
1207 data_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1208 data_bde->tus.f.bdeSize = sg_dma_len(sgel);
1209 data_bde->addrLow = putPaddrLow(physaddr);
1210 data_bde->addrHigh = putPaddrHigh(physaddr);
1213 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1214 bpl->tus.f.bdeSize = sg_dma_len(sgel);
1215 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1217 le32_to_cpu(putPaddrLow(physaddr));
1219 le32_to_cpu(putPaddrHigh(physaddr));
1226 * Finish initializing those IOCB fields that are dependent on the
1227 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
1228 * explicitly reinitialized and for SLI-3 the extended bde count is
1229 * explicitly reinitialized since all iocb memory resources are reused.
1231 if (phba->sli_rev == 3 &&
1232 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
1233 !(iocbq->iocb_flag & DSS_SECURITY_OP)) {
1234 if (num_bde > LPFC_EXT_DATA_BDE_COUNT) {
1236 * The extended IOCB format can only fit 3 BDE or a BPL.
1237 * This I/O has more than 3 BDE so the 1st data bde will
1238 * be a BPL that is filled in here.
1240 physaddr = lpfc_cmd->dma_handle;
1241 data_bde->tus.f.bdeFlags = BUFF_TYPE_BLP_64;
1242 data_bde->tus.f.bdeSize = (num_bde *
1243 sizeof(struct ulp_bde64));
1244 physaddr += (sizeof(struct fcp_cmnd) +
1245 sizeof(struct fcp_rsp) +
1246 (2 * sizeof(struct ulp_bde64)));
1247 data_bde->addrHigh = putPaddrHigh(physaddr);
1248 data_bde->addrLow = putPaddrLow(physaddr);
1249 /* ebde count includes the response bde and data bpl */
1250 iocb_cmd->unsli3.fcp_ext.ebde_count = 2;
1252 /* ebde count includes the response bde and data bdes */
1253 iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1);
1256 iocb_cmd->un.fcpi64.bdl.bdeSize =
1257 ((num_bde + 2) * sizeof(struct ulp_bde64));
1258 iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1);
1260 fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd));
1263 * Due to difference in data length between DIF/non-DIF paths,
1264 * we need to set word 4 of IOCB here
1266 iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd);
1270 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1272 /* Return if if error injection is detected by Initiator */
1273 #define BG_ERR_INIT 0x1
1274 /* Return if if error injection is detected by Target */
1275 #define BG_ERR_TGT 0x2
1276 /* Return if if swapping CSUM<-->CRC is required for error injection */
1277 #define BG_ERR_SWAP 0x10
1278 /* Return if disabling Guard/Ref/App checking is required for error injection */
1279 #define BG_ERR_CHECK 0x20
1282 * lpfc_bg_err_inject - Determine if we should inject an error
1283 * @phba: The Hba for which this call is being executed.
1284 * @sc: The SCSI command to examine
1285 * @reftag: (out) BlockGuard reference tag for transmitted data
1286 * @apptag: (out) BlockGuard application tag for transmitted data
1287 * @new_guard (in) Value to replace CRC with if needed
1289 * Returns BG_ERR_* bit mask or 0 if request ignored
1292 lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1293 uint32_t *reftag, uint16_t *apptag, uint32_t new_guard)
1295 struct scatterlist *sgpe; /* s/g prot entry */
1296 struct lpfc_scsi_buf *lpfc_cmd = NULL;
1297 struct scsi_dif_tuple *src = NULL;
1298 struct lpfc_nodelist *ndlp;
1299 struct lpfc_rport_data *rdata;
1300 uint32_t op = scsi_get_prot_op(sc);
1307 if (op == SCSI_PROT_NORMAL)
1310 sgpe = scsi_prot_sglist(sc);
1311 lba = scsi_get_lba(sc);
1313 /* First check if we need to match the LBA */
1314 if (phba->lpfc_injerr_lba != LPFC_INJERR_LBA_OFF) {
1315 blksize = lpfc_cmd_blksize(sc);
1316 numblks = (scsi_bufflen(sc) + blksize - 1) / blksize;
1318 /* Make sure we have the right LBA if one is specified */
1319 if ((phba->lpfc_injerr_lba < lba) ||
1320 (phba->lpfc_injerr_lba >= (lba + numblks)))
1323 blockoff = phba->lpfc_injerr_lba - lba;
1324 numblks = sg_dma_len(sgpe) /
1325 sizeof(struct scsi_dif_tuple);
1326 if (numblks < blockoff)
1331 /* Next check if we need to match the remote NPortID or WWPN */
1332 rdata = lpfc_rport_data_from_scsi_device(sc->device);
1333 if (rdata && rdata->pnode) {
1334 ndlp = rdata->pnode;
1336 /* Make sure we have the right NPortID if one is specified */
1337 if (phba->lpfc_injerr_nportid &&
1338 (phba->lpfc_injerr_nportid != ndlp->nlp_DID))
1342 * Make sure we have the right WWPN if one is specified.
1343 * wwn[0] should be a non-zero NAA in a good WWPN.
1345 if (phba->lpfc_injerr_wwpn.u.wwn[0] &&
1346 (memcmp(&ndlp->nlp_portname, &phba->lpfc_injerr_wwpn,
1347 sizeof(struct lpfc_name)) != 0))
1351 /* Setup a ptr to the protection data if the SCSI host provides it */
1353 src = (struct scsi_dif_tuple *)sg_virt(sgpe);
1355 lpfc_cmd = (struct lpfc_scsi_buf *)sc->host_scribble;
1358 /* Should we change the Reference Tag */
1360 if (phba->lpfc_injerr_wref_cnt) {
1362 case SCSI_PROT_WRITE_PASS:
1365 * For WRITE_PASS, force the error
1366 * to be sent on the wire. It should
1367 * be detected by the Target.
1368 * If blockoff != 0 error will be
1369 * inserted in middle of the IO.
1372 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1373 "9076 BLKGRD: Injecting reftag error: "
1374 "write lba x%lx + x%x oldrefTag x%x\n",
1375 (unsigned long)lba, blockoff,
1376 be32_to_cpu(src->ref_tag));
1379 * Save the old ref_tag so we can
1380 * restore it on completion.
1383 lpfc_cmd->prot_data_type =
1385 lpfc_cmd->prot_data_segment =
1387 lpfc_cmd->prot_data =
1390 src->ref_tag = cpu_to_be32(0xDEADBEEF);
1391 phba->lpfc_injerr_wref_cnt--;
1392 if (phba->lpfc_injerr_wref_cnt == 0) {
1393 phba->lpfc_injerr_nportid = 0;
1394 phba->lpfc_injerr_lba =
1395 LPFC_INJERR_LBA_OFF;
1396 memset(&phba->lpfc_injerr_wwpn,
1397 0, sizeof(struct lpfc_name));
1399 rc = BG_ERR_TGT | BG_ERR_CHECK;
1404 case SCSI_PROT_WRITE_INSERT:
1406 * For WRITE_INSERT, force the error
1407 * to be sent on the wire. It should be
1408 * detected by the Target.
1410 /* DEADBEEF will be the reftag on the wire */
1411 *reftag = 0xDEADBEEF;
1412 phba->lpfc_injerr_wref_cnt--;
1413 if (phba->lpfc_injerr_wref_cnt == 0) {
1414 phba->lpfc_injerr_nportid = 0;
1415 phba->lpfc_injerr_lba =
1416 LPFC_INJERR_LBA_OFF;
1417 memset(&phba->lpfc_injerr_wwpn,
1418 0, sizeof(struct lpfc_name));
1420 rc = BG_ERR_TGT | BG_ERR_CHECK;
1422 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1423 "9078 BLKGRD: Injecting reftag error: "
1424 "write lba x%lx\n", (unsigned long)lba);
1426 case SCSI_PROT_WRITE_STRIP:
1428 * For WRITE_STRIP and WRITE_PASS,
1429 * force the error on data
1430 * being copied from SLI-Host to SLI-Port.
1432 *reftag = 0xDEADBEEF;
1433 phba->lpfc_injerr_wref_cnt--;
1434 if (phba->lpfc_injerr_wref_cnt == 0) {
1435 phba->lpfc_injerr_nportid = 0;
1436 phba->lpfc_injerr_lba =
1437 LPFC_INJERR_LBA_OFF;
1438 memset(&phba->lpfc_injerr_wwpn,
1439 0, sizeof(struct lpfc_name));
1443 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1444 "9077 BLKGRD: Injecting reftag error: "
1445 "write lba x%lx\n", (unsigned long)lba);
1449 if (phba->lpfc_injerr_rref_cnt) {
1451 case SCSI_PROT_READ_INSERT:
1452 case SCSI_PROT_READ_STRIP:
1453 case SCSI_PROT_READ_PASS:
1455 * For READ_STRIP and READ_PASS, force the
1456 * error on data being read off the wire. It
1457 * should force an IO error to the driver.
1459 *reftag = 0xDEADBEEF;
1460 phba->lpfc_injerr_rref_cnt--;
1461 if (phba->lpfc_injerr_rref_cnt == 0) {
1462 phba->lpfc_injerr_nportid = 0;
1463 phba->lpfc_injerr_lba =
1464 LPFC_INJERR_LBA_OFF;
1465 memset(&phba->lpfc_injerr_wwpn,
1466 0, sizeof(struct lpfc_name));
1470 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1471 "9079 BLKGRD: Injecting reftag error: "
1472 "read lba x%lx\n", (unsigned long)lba);
1478 /* Should we change the Application Tag */
1480 if (phba->lpfc_injerr_wapp_cnt) {
1482 case SCSI_PROT_WRITE_PASS:
1485 * For WRITE_PASS, force the error
1486 * to be sent on the wire. It should
1487 * be detected by the Target.
1488 * If blockoff != 0 error will be
1489 * inserted in middle of the IO.
1492 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1493 "9080 BLKGRD: Injecting apptag error: "
1494 "write lba x%lx + x%x oldappTag x%x\n",
1495 (unsigned long)lba, blockoff,
1496 be16_to_cpu(src->app_tag));
1499 * Save the old app_tag so we can
1500 * restore it on completion.
1503 lpfc_cmd->prot_data_type =
1505 lpfc_cmd->prot_data_segment =
1507 lpfc_cmd->prot_data =
1510 src->app_tag = cpu_to_be16(0xDEAD);
1511 phba->lpfc_injerr_wapp_cnt--;
1512 if (phba->lpfc_injerr_wapp_cnt == 0) {
1513 phba->lpfc_injerr_nportid = 0;
1514 phba->lpfc_injerr_lba =
1515 LPFC_INJERR_LBA_OFF;
1516 memset(&phba->lpfc_injerr_wwpn,
1517 0, sizeof(struct lpfc_name));
1519 rc = BG_ERR_TGT | BG_ERR_CHECK;
1523 case SCSI_PROT_WRITE_INSERT:
1525 * For WRITE_INSERT, force the
1526 * error to be sent on the wire. It should be
1527 * detected by the Target.
1529 /* DEAD will be the apptag on the wire */
1531 phba->lpfc_injerr_wapp_cnt--;
1532 if (phba->lpfc_injerr_wapp_cnt == 0) {
1533 phba->lpfc_injerr_nportid = 0;
1534 phba->lpfc_injerr_lba =
1535 LPFC_INJERR_LBA_OFF;
1536 memset(&phba->lpfc_injerr_wwpn,
1537 0, sizeof(struct lpfc_name));
1539 rc = BG_ERR_TGT | BG_ERR_CHECK;
1541 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1542 "0813 BLKGRD: Injecting apptag error: "
1543 "write lba x%lx\n", (unsigned long)lba);
1545 case SCSI_PROT_WRITE_STRIP:
1547 * For WRITE_STRIP and WRITE_PASS,
1548 * force the error on data
1549 * being copied from SLI-Host to SLI-Port.
1552 phba->lpfc_injerr_wapp_cnt--;
1553 if (phba->lpfc_injerr_wapp_cnt == 0) {
1554 phba->lpfc_injerr_nportid = 0;
1555 phba->lpfc_injerr_lba =
1556 LPFC_INJERR_LBA_OFF;
1557 memset(&phba->lpfc_injerr_wwpn,
1558 0, sizeof(struct lpfc_name));
1562 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1563 "0812 BLKGRD: Injecting apptag error: "
1564 "write lba x%lx\n", (unsigned long)lba);
1568 if (phba->lpfc_injerr_rapp_cnt) {
1570 case SCSI_PROT_READ_INSERT:
1571 case SCSI_PROT_READ_STRIP:
1572 case SCSI_PROT_READ_PASS:
1574 * For READ_STRIP and READ_PASS, force the
1575 * error on data being read off the wire. It
1576 * should force an IO error to the driver.
1579 phba->lpfc_injerr_rapp_cnt--;
1580 if (phba->lpfc_injerr_rapp_cnt == 0) {
1581 phba->lpfc_injerr_nportid = 0;
1582 phba->lpfc_injerr_lba =
1583 LPFC_INJERR_LBA_OFF;
1584 memset(&phba->lpfc_injerr_wwpn,
1585 0, sizeof(struct lpfc_name));
1589 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1590 "0814 BLKGRD: Injecting apptag error: "
1591 "read lba x%lx\n", (unsigned long)lba);
1598 /* Should we change the Guard Tag */
1600 if (phba->lpfc_injerr_wgrd_cnt) {
1602 case SCSI_PROT_WRITE_PASS:
1606 case SCSI_PROT_WRITE_INSERT:
1608 * For WRITE_INSERT, force the
1609 * error to be sent on the wire. It should be
1610 * detected by the Target.
1612 phba->lpfc_injerr_wgrd_cnt--;
1613 if (phba->lpfc_injerr_wgrd_cnt == 0) {
1614 phba->lpfc_injerr_nportid = 0;
1615 phba->lpfc_injerr_lba =
1616 LPFC_INJERR_LBA_OFF;
1617 memset(&phba->lpfc_injerr_wwpn,
1618 0, sizeof(struct lpfc_name));
1621 rc |= BG_ERR_TGT | BG_ERR_SWAP;
1622 /* Signals the caller to swap CRC->CSUM */
1624 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1625 "0817 BLKGRD: Injecting guard error: "
1626 "write lba x%lx\n", (unsigned long)lba);
1628 case SCSI_PROT_WRITE_STRIP:
1630 * For WRITE_STRIP and WRITE_PASS,
1631 * force the error on data
1632 * being copied from SLI-Host to SLI-Port.
1634 phba->lpfc_injerr_wgrd_cnt--;
1635 if (phba->lpfc_injerr_wgrd_cnt == 0) {
1636 phba->lpfc_injerr_nportid = 0;
1637 phba->lpfc_injerr_lba =
1638 LPFC_INJERR_LBA_OFF;
1639 memset(&phba->lpfc_injerr_wwpn,
1640 0, sizeof(struct lpfc_name));
1643 rc = BG_ERR_INIT | BG_ERR_SWAP;
1644 /* Signals the caller to swap CRC->CSUM */
1646 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1647 "0816 BLKGRD: Injecting guard error: "
1648 "write lba x%lx\n", (unsigned long)lba);
1652 if (phba->lpfc_injerr_rgrd_cnt) {
1654 case SCSI_PROT_READ_INSERT:
1655 case SCSI_PROT_READ_STRIP:
1656 case SCSI_PROT_READ_PASS:
1658 * For READ_STRIP and READ_PASS, force the
1659 * error on data being read off the wire. It
1660 * should force an IO error to the driver.
1662 phba->lpfc_injerr_rgrd_cnt--;
1663 if (phba->lpfc_injerr_rgrd_cnt == 0) {
1664 phba->lpfc_injerr_nportid = 0;
1665 phba->lpfc_injerr_lba =
1666 LPFC_INJERR_LBA_OFF;
1667 memset(&phba->lpfc_injerr_wwpn,
1668 0, sizeof(struct lpfc_name));
1671 rc = BG_ERR_INIT | BG_ERR_SWAP;
1672 /* Signals the caller to swap CRC->CSUM */
1674 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1675 "0818 BLKGRD: Injecting guard error: "
1676 "read lba x%lx\n", (unsigned long)lba);
1686 * lpfc_sc_to_bg_opcodes - Determine the BlockGuard opcodes to be used with
1687 * the specified SCSI command.
1688 * @phba: The Hba for which this call is being executed.
1689 * @sc: The SCSI command to examine
1690 * @txopt: (out) BlockGuard operation for transmitted data
1691 * @rxopt: (out) BlockGuard operation for received data
1693 * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
1697 lpfc_sc_to_bg_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1698 uint8_t *txop, uint8_t *rxop)
1702 if (lpfc_cmd_guard_csum(sc)) {
1703 switch (scsi_get_prot_op(sc)) {
1704 case SCSI_PROT_READ_INSERT:
1705 case SCSI_PROT_WRITE_STRIP:
1706 *rxop = BG_OP_IN_NODIF_OUT_CSUM;
1707 *txop = BG_OP_IN_CSUM_OUT_NODIF;
1710 case SCSI_PROT_READ_STRIP:
1711 case SCSI_PROT_WRITE_INSERT:
1712 *rxop = BG_OP_IN_CRC_OUT_NODIF;
1713 *txop = BG_OP_IN_NODIF_OUT_CRC;
1716 case SCSI_PROT_READ_PASS:
1717 case SCSI_PROT_WRITE_PASS:
1718 *rxop = BG_OP_IN_CRC_OUT_CSUM;
1719 *txop = BG_OP_IN_CSUM_OUT_CRC;
1722 case SCSI_PROT_NORMAL:
1724 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1725 "9063 BLKGRD: Bad op/guard:%d/IP combination\n",
1726 scsi_get_prot_op(sc));
1732 switch (scsi_get_prot_op(sc)) {
1733 case SCSI_PROT_READ_STRIP:
1734 case SCSI_PROT_WRITE_INSERT:
1735 *rxop = BG_OP_IN_CRC_OUT_NODIF;
1736 *txop = BG_OP_IN_NODIF_OUT_CRC;
1739 case SCSI_PROT_READ_PASS:
1740 case SCSI_PROT_WRITE_PASS:
1741 *rxop = BG_OP_IN_CRC_OUT_CRC;
1742 *txop = BG_OP_IN_CRC_OUT_CRC;
1745 case SCSI_PROT_READ_INSERT:
1746 case SCSI_PROT_WRITE_STRIP:
1747 *rxop = BG_OP_IN_NODIF_OUT_CRC;
1748 *txop = BG_OP_IN_CRC_OUT_NODIF;
1751 case SCSI_PROT_NORMAL:
1753 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1754 "9075 BLKGRD: Bad op/guard:%d/CRC combination\n",
1755 scsi_get_prot_op(sc));
1764 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1766 * lpfc_bg_err_opcodes - reDetermine the BlockGuard opcodes to be used with
1767 * the specified SCSI command in order to force a guard tag error.
1768 * @phba: The Hba for which this call is being executed.
1769 * @sc: The SCSI command to examine
1770 * @txopt: (out) BlockGuard operation for transmitted data
1771 * @rxopt: (out) BlockGuard operation for received data
1773 * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
1777 lpfc_bg_err_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1778 uint8_t *txop, uint8_t *rxop)
1782 if (lpfc_cmd_guard_csum(sc)) {
1783 switch (scsi_get_prot_op(sc)) {
1784 case SCSI_PROT_READ_INSERT:
1785 case SCSI_PROT_WRITE_STRIP:
1786 *rxop = BG_OP_IN_NODIF_OUT_CRC;
1787 *txop = BG_OP_IN_CRC_OUT_NODIF;
1790 case SCSI_PROT_READ_STRIP:
1791 case SCSI_PROT_WRITE_INSERT:
1792 *rxop = BG_OP_IN_CSUM_OUT_NODIF;
1793 *txop = BG_OP_IN_NODIF_OUT_CSUM;
1796 case SCSI_PROT_READ_PASS:
1797 case SCSI_PROT_WRITE_PASS:
1798 *rxop = BG_OP_IN_CSUM_OUT_CRC;
1799 *txop = BG_OP_IN_CRC_OUT_CSUM;
1802 case SCSI_PROT_NORMAL:
1808 switch (scsi_get_prot_op(sc)) {
1809 case SCSI_PROT_READ_STRIP:
1810 case SCSI_PROT_WRITE_INSERT:
1811 *rxop = BG_OP_IN_CSUM_OUT_NODIF;
1812 *txop = BG_OP_IN_NODIF_OUT_CSUM;
1815 case SCSI_PROT_READ_PASS:
1816 case SCSI_PROT_WRITE_PASS:
1817 *rxop = BG_OP_IN_CSUM_OUT_CSUM;
1818 *txop = BG_OP_IN_CSUM_OUT_CSUM;
1821 case SCSI_PROT_READ_INSERT:
1822 case SCSI_PROT_WRITE_STRIP:
1823 *rxop = BG_OP_IN_NODIF_OUT_CSUM;
1824 *txop = BG_OP_IN_CSUM_OUT_NODIF;
1827 case SCSI_PROT_NORMAL:
1838 * lpfc_bg_setup_bpl - Setup BlockGuard BPL with no protection data
1839 * @phba: The Hba for which this call is being executed.
1840 * @sc: pointer to scsi command we're working on
1841 * @bpl: pointer to buffer list for protection groups
1842 * @datacnt: number of segments of data that have been dma mapped
1844 * This function sets up BPL buffer list for protection groups of
1845 * type LPFC_PG_TYPE_NO_DIF
1847 * This is usually used when the HBA is instructed to generate
1848 * DIFs and insert them into data stream (or strip DIF from
1849 * incoming data stream)
1851 * The buffer list consists of just one protection group described
1853 * +-------------------------+
1854 * start of prot group --> | PDE_5 |
1855 * +-------------------------+
1857 * +-------------------------+
1859 * +-------------------------+
1860 * |more Data BDE's ... (opt)|
1861 * +-------------------------+
1864 * Note: Data s/g buffers have been dma mapped
1866 * Returns the number of BDEs added to the BPL.
1869 lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1870 struct ulp_bde64 *bpl, int datasegcnt)
1872 struct scatterlist *sgde = NULL; /* s/g data entry */
1873 struct lpfc_pde5 *pde5 = NULL;
1874 struct lpfc_pde6 *pde6 = NULL;
1875 dma_addr_t physaddr;
1876 int i = 0, num_bde = 0, status;
1877 int datadir = sc->sc_data_direction;
1878 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1881 uint32_t checking = 1;
1885 status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
1889 /* extract some info from the scsi command for pde*/
1890 reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
1892 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1893 rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
1895 if (rc & BG_ERR_SWAP)
1896 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
1897 if (rc & BG_ERR_CHECK)
1902 /* setup PDE5 with what we have */
1903 pde5 = (struct lpfc_pde5 *) bpl;
1904 memset(pde5, 0, sizeof(struct lpfc_pde5));
1905 bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR);
1907 /* Endianness conversion if necessary for PDE5 */
1908 pde5->word0 = cpu_to_le32(pde5->word0);
1909 pde5->reftag = cpu_to_le32(reftag);
1911 /* advance bpl and increment bde count */
1914 pde6 = (struct lpfc_pde6 *) bpl;
1916 /* setup PDE6 with the rest of the info */
1917 memset(pde6, 0, sizeof(struct lpfc_pde6));
1918 bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR);
1919 bf_set(pde6_optx, pde6, txop);
1920 bf_set(pde6_oprx, pde6, rxop);
1923 * We only need to check the data on READs, for WRITEs
1924 * protection data is automatically generated, not checked.
1926 if (datadir == DMA_FROM_DEVICE) {
1927 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD))
1928 bf_set(pde6_ce, pde6, checking);
1930 bf_set(pde6_ce, pde6, 0);
1932 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF))
1933 bf_set(pde6_re, pde6, checking);
1935 bf_set(pde6_re, pde6, 0);
1937 bf_set(pde6_ai, pde6, 1);
1938 bf_set(pde6_ae, pde6, 0);
1939 bf_set(pde6_apptagval, pde6, 0);
1941 /* Endianness conversion if necessary for PDE6 */
1942 pde6->word0 = cpu_to_le32(pde6->word0);
1943 pde6->word1 = cpu_to_le32(pde6->word1);
1944 pde6->word2 = cpu_to_le32(pde6->word2);
1946 /* advance bpl and increment bde count */
1950 /* assumption: caller has already run dma_map_sg on command data */
1951 scsi_for_each_sg(sc, sgde, datasegcnt, i) {
1952 physaddr = sg_dma_address(sgde);
1953 bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr));
1954 bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
1955 bpl->tus.f.bdeSize = sg_dma_len(sgde);
1956 if (datadir == DMA_TO_DEVICE)
1957 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1959 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
1960 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1970 * lpfc_bg_setup_bpl_prot - Setup BlockGuard BPL with protection data
1971 * @phba: The Hba for which this call is being executed.
1972 * @sc: pointer to scsi command we're working on
1973 * @bpl: pointer to buffer list for protection groups
1974 * @datacnt: number of segments of data that have been dma mapped
1975 * @protcnt: number of segment of protection data that have been dma mapped
1977 * This function sets up BPL buffer list for protection groups of
1978 * type LPFC_PG_TYPE_DIF
1980 * This is usually used when DIFs are in their own buffers,
1981 * separate from the data. The HBA can then by instructed
1982 * to place the DIFs in the outgoing stream. For read operations,
1983 * The HBA could extract the DIFs and place it in DIF buffers.
1985 * The buffer list for this type consists of one or more of the
1986 * protection groups described below:
1987 * +-------------------------+
1988 * start of first prot group --> | PDE_5 |
1989 * +-------------------------+
1991 * +-------------------------+
1992 * | PDE_7 (Prot BDE) |
1993 * +-------------------------+
1995 * +-------------------------+
1996 * |more Data BDE's ... (opt)|
1997 * +-------------------------+
1998 * start of new prot group --> | PDE_5 |
1999 * +-------------------------+
2001 * +-------------------------+
2003 * Note: It is assumed that both data and protection s/g buffers have been
2006 * Returns the number of BDEs added to the BPL.
2009 lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc,
2010 struct ulp_bde64 *bpl, int datacnt, int protcnt)
2012 struct scatterlist *sgde = NULL; /* s/g data entry */
2013 struct scatterlist *sgpe = NULL; /* s/g prot entry */
2014 struct lpfc_pde5 *pde5 = NULL;
2015 struct lpfc_pde6 *pde6 = NULL;
2016 struct lpfc_pde7 *pde7 = NULL;
2017 dma_addr_t dataphysaddr, protphysaddr;
2018 unsigned short curr_data = 0, curr_prot = 0;
2019 unsigned int split_offset;
2020 unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder;
2021 unsigned int protgrp_blks, protgrp_bytes;
2022 unsigned int remainder, subtotal;
2024 int datadir = sc->sc_data_direction;
2025 unsigned char pgdone = 0, alldone = 0;
2027 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2030 uint32_t checking = 1;
2035 sgpe = scsi_prot_sglist(sc);
2036 sgde = scsi_sglist(sc);
2038 if (!sgpe || !sgde) {
2039 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
2040 "9020 Invalid s/g entry: data=0x%p prot=0x%p\n",
2045 status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
2049 /* extract some info from the scsi command */
2050 blksize = lpfc_cmd_blksize(sc);
2051 reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
2053 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2054 rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
2056 if (rc & BG_ERR_SWAP)
2057 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
2058 if (rc & BG_ERR_CHECK)
2065 /* Check to see if we ran out of space */
2066 if (num_bde >= (phba->cfg_total_seg_cnt - 2))
2069 /* setup PDE5 with what we have */
2070 pde5 = (struct lpfc_pde5 *) bpl;
2071 memset(pde5, 0, sizeof(struct lpfc_pde5));
2072 bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR);
2074 /* Endianness conversion if necessary for PDE5 */
2075 pde5->word0 = cpu_to_le32(pde5->word0);
2076 pde5->reftag = cpu_to_le32(reftag);
2078 /* advance bpl and increment bde count */
2081 pde6 = (struct lpfc_pde6 *) bpl;
2083 /* setup PDE6 with the rest of the info */
2084 memset(pde6, 0, sizeof(struct lpfc_pde6));
2085 bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR);
2086 bf_set(pde6_optx, pde6, txop);
2087 bf_set(pde6_oprx, pde6, rxop);
2089 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD))
2090 bf_set(pde6_ce, pde6, checking);
2092 bf_set(pde6_ce, pde6, 0);
2094 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF))
2095 bf_set(pde6_re, pde6, checking);
2097 bf_set(pde6_re, pde6, 0);
2099 bf_set(pde6_ai, pde6, 1);
2100 bf_set(pde6_ae, pde6, 0);
2101 bf_set(pde6_apptagval, pde6, 0);
2103 /* Endianness conversion if necessary for PDE6 */
2104 pde6->word0 = cpu_to_le32(pde6->word0);
2105 pde6->word1 = cpu_to_le32(pde6->word1);
2106 pde6->word2 = cpu_to_le32(pde6->word2);
2108 /* advance bpl and increment bde count */
2112 /* setup the first BDE that points to protection buffer */
2113 protphysaddr = sg_dma_address(sgpe) + protgroup_offset;
2114 protgroup_len = sg_dma_len(sgpe) - protgroup_offset;
2116 /* must be integer multiple of the DIF block length */
2117 BUG_ON(protgroup_len % 8);
2119 pde7 = (struct lpfc_pde7 *) bpl;
2120 memset(pde7, 0, sizeof(struct lpfc_pde7));
2121 bf_set(pde7_type, pde7, LPFC_PDE7_DESCRIPTOR);
2123 pde7->addrHigh = le32_to_cpu(putPaddrHigh(protphysaddr));
2124 pde7->addrLow = le32_to_cpu(putPaddrLow(protphysaddr));
2126 protgrp_blks = protgroup_len / 8;
2127 protgrp_bytes = protgrp_blks * blksize;
2129 /* check if this pde is crossing the 4K boundary; if so split */
2130 if ((pde7->addrLow & 0xfff) + protgroup_len > 0x1000) {
2131 protgroup_remainder = 0x1000 - (pde7->addrLow & 0xfff);
2132 protgroup_offset += protgroup_remainder;
2133 protgrp_blks = protgroup_remainder / 8;
2134 protgrp_bytes = protgrp_blks * blksize;
2136 protgroup_offset = 0;
2142 /* setup BDE's for data blocks associated with DIF data */
2144 subtotal = 0; /* total bytes processed for current prot grp */
2146 /* Check to see if we ran out of space */
2147 if (num_bde >= phba->cfg_total_seg_cnt)
2151 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
2152 "9065 BLKGRD:%s Invalid data segment\n",
2157 dataphysaddr = sg_dma_address(sgde) + split_offset;
2158 bpl->addrLow = le32_to_cpu(putPaddrLow(dataphysaddr));
2159 bpl->addrHigh = le32_to_cpu(putPaddrHigh(dataphysaddr));
2161 remainder = sg_dma_len(sgde) - split_offset;
2163 if ((subtotal + remainder) <= protgrp_bytes) {
2164 /* we can use this whole buffer */
2165 bpl->tus.f.bdeSize = remainder;
2168 if ((subtotal + remainder) == protgrp_bytes)
2171 /* must split this buffer with next prot grp */
2172 bpl->tus.f.bdeSize = protgrp_bytes - subtotal;
2173 split_offset += bpl->tus.f.bdeSize;
2176 subtotal += bpl->tus.f.bdeSize;
2178 if (datadir == DMA_TO_DEVICE)
2179 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
2181 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
2182 bpl->tus.w = le32_to_cpu(bpl->tus.w);
2190 /* Move to the next s/g segment if possible */
2191 sgde = sg_next(sgde);
2195 if (protgroup_offset) {
2196 /* update the reference tag */
2197 reftag += protgrp_blks;
2203 if (curr_prot == protcnt) {
2205 } else if (curr_prot < protcnt) {
2206 /* advance to next prot buffer */
2207 sgpe = sg_next(sgpe);
2210 /* update the reference tag */
2211 reftag += protgrp_blks;
2213 /* if we're here, we have a bug */
2214 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
2215 "9054 BLKGRD: bug in %s\n", __func__);
2225 * lpfc_bg_setup_sgl - Setup BlockGuard SGL with no protection data
2226 * @phba: The Hba for which this call is being executed.
2227 * @sc: pointer to scsi command we're working on
2228 * @sgl: pointer to buffer list for protection groups
2229 * @datacnt: number of segments of data that have been dma mapped
2231 * This function sets up SGL buffer list for protection groups of
2232 * type LPFC_PG_TYPE_NO_DIF
2234 * This is usually used when the HBA is instructed to generate
2235 * DIFs and insert them into data stream (or strip DIF from
2236 * incoming data stream)
2238 * The buffer list consists of just one protection group described
2240 * +-------------------------+
2241 * start of prot group --> | DI_SEED |
2242 * +-------------------------+
2244 * +-------------------------+
2245 * |more Data SGE's ... (opt)|
2246 * +-------------------------+
2249 * Note: Data s/g buffers have been dma mapped
2251 * Returns the number of SGEs added to the SGL.
2254 lpfc_bg_setup_sgl(struct lpfc_hba *phba, struct scsi_cmnd *sc,
2255 struct sli4_sge *sgl, int datasegcnt)
2257 struct scatterlist *sgde = NULL; /* s/g data entry */
2258 struct sli4_sge_diseed *diseed = NULL;
2259 dma_addr_t physaddr;
2260 int i = 0, num_sge = 0, status;
2263 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2266 uint32_t checking = 1;
2268 uint32_t dma_offset = 0;
2270 status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
2274 /* extract some info from the scsi command for pde*/
2275 reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
2277 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2278 rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
2280 if (rc & BG_ERR_SWAP)
2281 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
2282 if (rc & BG_ERR_CHECK)
2287 /* setup DISEED with what we have */
2288 diseed = (struct sli4_sge_diseed *) sgl;
2289 memset(diseed, 0, sizeof(struct sli4_sge_diseed));
2290 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED);
2292 /* Endianness conversion if necessary */
2293 diseed->ref_tag = cpu_to_le32(reftag);
2294 diseed->ref_tag_tran = diseed->ref_tag;
2297 * We only need to check the data on READs, for WRITEs
2298 * protection data is automatically generated, not checked.
2300 if (sc->sc_data_direction == DMA_FROM_DEVICE) {
2301 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD))
2302 bf_set(lpfc_sli4_sge_dif_ce, diseed, checking);
2304 bf_set(lpfc_sli4_sge_dif_ce, diseed, 0);
2306 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF))
2307 bf_set(lpfc_sli4_sge_dif_re, diseed, checking);
2309 bf_set(lpfc_sli4_sge_dif_re, diseed, 0);
2312 /* setup DISEED with the rest of the info */
2313 bf_set(lpfc_sli4_sge_dif_optx, diseed, txop);
2314 bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop);
2316 bf_set(lpfc_sli4_sge_dif_ai, diseed, 1);
2317 bf_set(lpfc_sli4_sge_dif_me, diseed, 0);
2319 /* Endianness conversion if necessary for DISEED */
2320 diseed->word2 = cpu_to_le32(diseed->word2);
2321 diseed->word3 = cpu_to_le32(diseed->word3);
2323 /* advance bpl and increment sge count */
2327 /* assumption: caller has already run dma_map_sg on command data */
2328 scsi_for_each_sg(sc, sgde, datasegcnt, i) {
2329 physaddr = sg_dma_address(sgde);
2330 dma_len = sg_dma_len(sgde);
2331 sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr));
2332 sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr));
2333 if ((i + 1) == datasegcnt)
2334 bf_set(lpfc_sli4_sge_last, sgl, 1);
2336 bf_set(lpfc_sli4_sge_last, sgl, 0);
2337 bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
2338 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA);
2340 sgl->sge_len = cpu_to_le32(dma_len);
2341 dma_offset += dma_len;
2352 * lpfc_bg_setup_sgl_prot - Setup BlockGuard SGL with protection data
2353 * @phba: The Hba for which this call is being executed.
2354 * @sc: pointer to scsi command we're working on
2355 * @sgl: pointer to buffer list for protection groups
2356 * @datacnt: number of segments of data that have been dma mapped
2357 * @protcnt: number of segment of protection data that have been dma mapped
2359 * This function sets up SGL buffer list for protection groups of
2360 * type LPFC_PG_TYPE_DIF
2362 * This is usually used when DIFs are in their own buffers,
2363 * separate from the data. The HBA can then by instructed
2364 * to place the DIFs in the outgoing stream. For read operations,
2365 * The HBA could extract the DIFs and place it in DIF buffers.
2367 * The buffer list for this type consists of one or more of the
2368 * protection groups described below:
2369 * +-------------------------+
2370 * start of first prot group --> | DISEED |
2371 * +-------------------------+
2372 * | DIF (Prot SGE) |
2373 * +-------------------------+
2375 * +-------------------------+
2376 * |more Data SGE's ... (opt)|
2377 * +-------------------------+
2378 * start of new prot group --> | DISEED |
2379 * +-------------------------+
2381 * +-------------------------+
2383 * Note: It is assumed that both data and protection s/g buffers have been
2386 * Returns the number of SGEs added to the SGL.
2389 lpfc_bg_setup_sgl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc,
2390 struct sli4_sge *sgl, int datacnt, int protcnt)
2392 struct scatterlist *sgde = NULL; /* s/g data entry */
2393 struct scatterlist *sgpe = NULL; /* s/g prot entry */
2394 struct sli4_sge_diseed *diseed = NULL;
2395 dma_addr_t dataphysaddr, protphysaddr;
2396 unsigned short curr_data = 0, curr_prot = 0;
2397 unsigned int split_offset;
2398 unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder;
2399 unsigned int protgrp_blks, protgrp_bytes;
2400 unsigned int remainder, subtotal;
2402 unsigned char pgdone = 0, alldone = 0;
2407 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2410 uint32_t checking = 1;
2411 uint32_t dma_offset = 0;
2414 sgpe = scsi_prot_sglist(sc);
2415 sgde = scsi_sglist(sc);
2417 if (!sgpe || !sgde) {
2418 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
2419 "9082 Invalid s/g entry: data=0x%p prot=0x%p\n",
2424 status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
2428 /* extract some info from the scsi command */
2429 blksize = lpfc_cmd_blksize(sc);
2430 reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
2432 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2433 rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
2435 if (rc & BG_ERR_SWAP)
2436 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
2437 if (rc & BG_ERR_CHECK)
2444 /* Check to see if we ran out of space */
2445 if (num_sge >= (phba->cfg_total_seg_cnt - 2))
2448 /* setup DISEED with what we have */
2449 diseed = (struct sli4_sge_diseed *) sgl;
2450 memset(diseed, 0, sizeof(struct sli4_sge_diseed));
2451 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED);
2453 /* Endianness conversion if necessary */
2454 diseed->ref_tag = cpu_to_le32(reftag);
2455 diseed->ref_tag_tran = diseed->ref_tag;
2457 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) {
2458 bf_set(lpfc_sli4_sge_dif_ce, diseed, checking);
2461 bf_set(lpfc_sli4_sge_dif_ce, diseed, 0);
2463 * When in this mode, the hardware will replace
2464 * the guard tag from the host with a
2465 * newly generated good CRC for the wire.
2466 * Switch to raw mode here to avoid this
2467 * behavior. What the host sends gets put on the wire.
2469 if (txop == BG_OP_IN_CRC_OUT_CRC) {
2470 txop = BG_OP_RAW_MODE;
2471 rxop = BG_OP_RAW_MODE;
2476 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF))
2477 bf_set(lpfc_sli4_sge_dif_re, diseed, checking);
2479 bf_set(lpfc_sli4_sge_dif_re, diseed, 0);
2481 /* setup DISEED with the rest of the info */
2482 bf_set(lpfc_sli4_sge_dif_optx, diseed, txop);
2483 bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop);
2485 bf_set(lpfc_sli4_sge_dif_ai, diseed, 1);
2486 bf_set(lpfc_sli4_sge_dif_me, diseed, 0);
2488 /* Endianness conversion if necessary for DISEED */
2489 diseed->word2 = cpu_to_le32(diseed->word2);
2490 diseed->word3 = cpu_to_le32(diseed->word3);
2492 /* advance sgl and increment bde count */
2496 /* setup the first BDE that points to protection buffer */
2497 protphysaddr = sg_dma_address(sgpe) + protgroup_offset;
2498 protgroup_len = sg_dma_len(sgpe) - protgroup_offset;
2500 /* must be integer multiple of the DIF block length */
2501 BUG_ON(protgroup_len % 8);
2503 /* Now setup DIF SGE */
2505 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DIF);
2506 sgl->addr_hi = le32_to_cpu(putPaddrHigh(protphysaddr));
2507 sgl->addr_lo = le32_to_cpu(putPaddrLow(protphysaddr));
2508 sgl->word2 = cpu_to_le32(sgl->word2);
2510 protgrp_blks = protgroup_len / 8;
2511 protgrp_bytes = protgrp_blks * blksize;
2513 /* check if DIF SGE is crossing the 4K boundary; if so split */
2514 if ((sgl->addr_lo & 0xfff) + protgroup_len > 0x1000) {
2515 protgroup_remainder = 0x1000 - (sgl->addr_lo & 0xfff);
2516 protgroup_offset += protgroup_remainder;
2517 protgrp_blks = protgroup_remainder / 8;
2518 protgrp_bytes = protgrp_blks * blksize;
2520 protgroup_offset = 0;
2526 /* setup SGE's for data blocks associated with DIF data */
2528 subtotal = 0; /* total bytes processed for current prot grp */
2530 /* Check to see if we ran out of space */
2531 if (num_sge >= phba->cfg_total_seg_cnt)
2535 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
2536 "9086 BLKGRD:%s Invalid data segment\n",
2541 dataphysaddr = sg_dma_address(sgde) + split_offset;
2543 remainder = sg_dma_len(sgde) - split_offset;
2545 if ((subtotal + remainder) <= protgrp_bytes) {
2546 /* we can use this whole buffer */
2547 dma_len = remainder;
2550 if ((subtotal + remainder) == protgrp_bytes)
2553 /* must split this buffer with next prot grp */
2554 dma_len = protgrp_bytes - subtotal;
2555 split_offset += dma_len;
2558 subtotal += dma_len;
2560 sgl->addr_lo = cpu_to_le32(putPaddrLow(dataphysaddr));
2561 sgl->addr_hi = cpu_to_le32(putPaddrHigh(dataphysaddr));
2562 bf_set(lpfc_sli4_sge_last, sgl, 0);
2563 bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
2564 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA);
2566 sgl->sge_len = cpu_to_le32(dma_len);
2567 dma_offset += dma_len;
2575 /* Move to the next s/g segment if possible */
2576 sgde = sg_next(sgde);
2579 if (protgroup_offset) {
2580 /* update the reference tag */
2581 reftag += protgrp_blks;
2587 if (curr_prot == protcnt) {
2588 bf_set(lpfc_sli4_sge_last, sgl, 1);
2590 } else if (curr_prot < protcnt) {
2591 /* advance to next prot buffer */
2592 sgpe = sg_next(sgpe);
2595 /* update the reference tag */
2596 reftag += protgrp_blks;
2598 /* if we're here, we have a bug */
2599 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
2600 "9085 BLKGRD: bug in %s\n", __func__);
2611 * lpfc_prot_group_type - Get prtotection group type of SCSI command
2612 * @phba: The Hba for which this call is being executed.
2613 * @sc: pointer to scsi command we're working on
2615 * Given a SCSI command that supports DIF, determine composition of protection
2616 * groups involved in setting up buffer lists
2618 * Returns: Protection group type (with or without DIF)
2622 lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc)
2624 int ret = LPFC_PG_TYPE_INVALID;
2625 unsigned char op = scsi_get_prot_op(sc);
2628 case SCSI_PROT_READ_STRIP:
2629 case SCSI_PROT_WRITE_INSERT:
2630 ret = LPFC_PG_TYPE_NO_DIF;
2632 case SCSI_PROT_READ_INSERT:
2633 case SCSI_PROT_WRITE_STRIP:
2634 case SCSI_PROT_READ_PASS:
2635 case SCSI_PROT_WRITE_PASS:
2636 ret = LPFC_PG_TYPE_DIF_BUF;
2640 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
2641 "9021 Unsupported protection op:%d\n",
2649 * lpfc_bg_scsi_adjust_dl - Adjust SCSI data length for BlockGuard
2650 * @phba: The Hba for which this call is being executed.
2651 * @lpfc_cmd: The scsi buffer which is going to be adjusted.
2653 * Adjust the data length to account for how much data
2654 * is actually on the wire.
2656 * returns the adjusted data length
2659 lpfc_bg_scsi_adjust_dl(struct lpfc_hba *phba,
2660 struct lpfc_scsi_buf *lpfc_cmd)
2662 struct scsi_cmnd *sc = lpfc_cmd->pCmd;
2665 fcpdl = scsi_bufflen(sc);
2667 /* Check if there is protection data on the wire */
2668 if (sc->sc_data_direction == DMA_FROM_DEVICE) {
2669 /* Read check for protection data */
2670 if (scsi_get_prot_op(sc) == SCSI_PROT_READ_INSERT)
2674 /* Write check for protection data */
2675 if (scsi_get_prot_op(sc) == SCSI_PROT_WRITE_STRIP)
2680 * If we are in DIF Type 1 mode every data block has a 8 byte
2681 * DIF (trailer) attached to it. Must ajust FCP data length
2682 * to account for the protection data.
2684 fcpdl += (fcpdl / lpfc_cmd_blksize(sc)) * 8;
2690 * lpfc_bg_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
2691 * @phba: The Hba for which this call is being executed.
2692 * @lpfc_cmd: The scsi buffer which is going to be prep'ed.
2694 * This is the protection/DIF aware version of
2695 * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the
2696 * two functions eventually, but for now, it's here
2699 lpfc_bg_scsi_prep_dma_buf_s3(struct lpfc_hba *phba,
2700 struct lpfc_scsi_buf *lpfc_cmd)
2702 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
2703 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
2704 struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl;
2705 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
2706 uint32_t num_bde = 0;
2707 int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction;
2708 int prot_group_type = 0;
2710 struct lpfc_vport *vport = phba->pport;
2713 * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd
2714 * fcp_rsp regions to the first data bde entry
2717 if (scsi_sg_count(scsi_cmnd)) {
2719 * The driver stores the segment count returned from pci_map_sg
2720 * because this a count of dma-mappings used to map the use_sg
2721 * pages. They are not guaranteed to be the same for those
2722 * architectures that implement an IOMMU.
2724 datasegcnt = dma_map_sg(&phba->pcidev->dev,
2725 scsi_sglist(scsi_cmnd),
2726 scsi_sg_count(scsi_cmnd), datadir);
2727 if (unlikely(!datasegcnt))
2730 lpfc_cmd->seg_cnt = datasegcnt;
2732 /* First check if data segment count from SCSI Layer is good */
2733 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt)
2736 prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd);
2738 switch (prot_group_type) {
2739 case LPFC_PG_TYPE_NO_DIF:
2741 /* Here we need to add a PDE5 and PDE6 to the count */
2742 if ((lpfc_cmd->seg_cnt + 2) > phba->cfg_total_seg_cnt)
2745 num_bde = lpfc_bg_setup_bpl(phba, scsi_cmnd, bpl,
2747 /* we should have 2 or more entries in buffer list */
2752 case LPFC_PG_TYPE_DIF_BUF:
2754 * This type indicates that protection buffers are
2755 * passed to the driver, so that needs to be prepared
2758 protsegcnt = dma_map_sg(&phba->pcidev->dev,
2759 scsi_prot_sglist(scsi_cmnd),
2760 scsi_prot_sg_count(scsi_cmnd), datadir);
2761 if (unlikely(!protsegcnt)) {
2762 scsi_dma_unmap(scsi_cmnd);
2766 lpfc_cmd->prot_seg_cnt = protsegcnt;
2769 * There is a minimun of 4 BPLs used for every
2770 * protection data segment.
2772 if ((lpfc_cmd->prot_seg_cnt * 4) >
2773 (phba->cfg_total_seg_cnt - 2))
2776 num_bde = lpfc_bg_setup_bpl_prot(phba, scsi_cmnd, bpl,
2777 datasegcnt, protsegcnt);
2778 /* we should have 3 or more entries in buffer list */
2779 if ((num_bde < 3) ||
2780 (num_bde > phba->cfg_total_seg_cnt))
2784 case LPFC_PG_TYPE_INVALID:
2786 scsi_dma_unmap(scsi_cmnd);
2787 lpfc_cmd->seg_cnt = 0;
2789 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
2790 "9022 Unexpected protection group %i\n",
2797 * Finish initializing those IOCB fields that are dependent on the
2798 * scsi_cmnd request_buffer. Note that the bdeSize is explicitly
2799 * reinitialized since all iocb memory resources are used many times
2800 * for transmit, receive, and continuation bpl's.
2802 iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
2803 iocb_cmd->un.fcpi64.bdl.bdeSize += (num_bde * sizeof(struct ulp_bde64));
2804 iocb_cmd->ulpBdeCount = 1;
2805 iocb_cmd->ulpLe = 1;
2807 fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd);
2808 fcp_cmnd->fcpDl = be32_to_cpu(fcpdl);
2811 * Due to difference in data length between DIF/non-DIF paths,
2812 * we need to set word 4 of IOCB here
2814 iocb_cmd->un.fcpi.fcpi_parm = fcpdl;
2817 * For First burst, we may need to adjust the initial transfer
2820 if (iocb_cmd->un.fcpi.fcpi_XRdy &&
2821 (fcpdl < vport->cfg_first_burst_size))
2822 iocb_cmd->un.fcpi.fcpi_XRdy = fcpdl;
2826 if (lpfc_cmd->seg_cnt)
2827 scsi_dma_unmap(scsi_cmnd);
2828 if (lpfc_cmd->prot_seg_cnt)
2829 dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd),
2830 scsi_prot_sg_count(scsi_cmnd),
2831 scsi_cmnd->sc_data_direction);
2833 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
2834 "9023 Cannot setup S/G List for HBA"
2835 "IO segs %d/%d BPL %d SCSI %d: %d %d\n",
2836 lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt,
2837 phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt,
2838 prot_group_type, num_bde);
2840 lpfc_cmd->seg_cnt = 0;
2841 lpfc_cmd->prot_seg_cnt = 0;
2846 * This function calcuates the T10 DIF guard tag
2847 * on the specified data using a CRC algorithmn
2851 lpfc_bg_crc(uint8_t *data, int count)
2856 crc = crc_t10dif(data, count);
2857 x = cpu_to_be16(crc);
2862 * This function calcuates the T10 DIF guard tag
2863 * on the specified data using a CSUM algorithmn
2864 * using ip_compute_csum.
2867 lpfc_bg_csum(uint8_t *data, int count)
2871 ret = ip_compute_csum(data, count);
2876 * This function examines the protection data to try to determine
2877 * what type of T10-DIF error occurred.
2880 lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
2882 struct scatterlist *sgpe; /* s/g prot entry */
2883 struct scatterlist *sgde; /* s/g data entry */
2884 struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
2885 struct scsi_dif_tuple *src = NULL;
2886 uint8_t *data_src = NULL;
2888 uint16_t start_app_tag, app_tag;
2889 uint32_t start_ref_tag, ref_tag;
2890 int prot, protsegcnt;
2891 int err_type, len, data_len;
2892 int chk_ref, chk_app, chk_guard;
2896 err_type = BGS_GUARD_ERR_MASK;
2900 /* First check to see if there is protection data to examine */
2901 prot = scsi_get_prot_op(cmd);
2902 if ((prot == SCSI_PROT_READ_STRIP) ||
2903 (prot == SCSI_PROT_WRITE_INSERT) ||
2904 (prot == SCSI_PROT_NORMAL))
2907 /* Currently the driver just supports ref_tag and guard_tag checking */
2912 /* Setup a ptr to the protection data provided by the SCSI host */
2913 sgpe = scsi_prot_sglist(cmd);
2914 protsegcnt = lpfc_cmd->prot_seg_cnt;
2916 if (sgpe && protsegcnt) {
2919 * We will only try to verify guard tag if the segment
2920 * data length is a multiple of the blksize.
2922 sgde = scsi_sglist(cmd);
2923 blksize = lpfc_cmd_blksize(cmd);
2924 data_src = (uint8_t *)sg_virt(sgde);
2925 data_len = sgde->length;
2926 if ((data_len & (blksize - 1)) == 0)
2929 src = (struct scsi_dif_tuple *)sg_virt(sgpe);
2930 start_ref_tag = (uint32_t)scsi_get_lba(cmd); /* Truncate LBA */
2931 start_app_tag = src->app_tag;
2933 while (src && protsegcnt) {
2937 * First check to see if a protection data
2940 if ((src->ref_tag == 0xffffffff) ||
2941 (src->app_tag == 0xffff)) {
2946 /* First Guard Tag checking */
2948 guard_tag = src->guard_tag;
2949 if (lpfc_cmd_guard_csum(cmd))
2950 sum = lpfc_bg_csum(data_src,
2953 sum = lpfc_bg_crc(data_src,
2955 if ((guard_tag != sum)) {
2956 err_type = BGS_GUARD_ERR_MASK;
2961 /* Reference Tag checking */
2962 ref_tag = be32_to_cpu(src->ref_tag);
2963 if (chk_ref && (ref_tag != start_ref_tag)) {
2964 err_type = BGS_REFTAG_ERR_MASK;
2969 /* App Tag checking */
2970 app_tag = src->app_tag;
2971 if (chk_app && (app_tag != start_app_tag)) {
2972 err_type = BGS_APPTAG_ERR_MASK;
2976 len -= sizeof(struct scsi_dif_tuple);
2981 data_src += blksize;
2982 data_len -= blksize;
2985 * Are we at the end of the Data segment?
2986 * The data segment is only used for Guard
2989 if (chk_guard && (data_len == 0)) {
2991 sgde = sg_next(sgde);
2995 data_src = (uint8_t *)sg_virt(sgde);
2996 data_len = sgde->length;
2997 if ((data_len & (blksize - 1)) == 0)
3002 /* Goto the next Protection data segment */
3003 sgpe = sg_next(sgpe);
3005 src = (struct scsi_dif_tuple *)sg_virt(sgpe);
3014 if (err_type == BGS_GUARD_ERR_MASK) {
3015 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
3017 cmd->result = DRIVER_SENSE << 24
3018 | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
3019 phba->bg_guard_err_cnt++;
3020 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
3021 "9069 BLKGRD: LBA %lx grd_tag error %x != %x\n",
3022 (unsigned long)scsi_get_lba(cmd),
3025 } else if (err_type == BGS_REFTAG_ERR_MASK) {
3026 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
3028 cmd->result = DRIVER_SENSE << 24
3029 | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
3031 phba->bg_reftag_err_cnt++;
3032 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
3033 "9066 BLKGRD: LBA %lx ref_tag error %x != %x\n",
3034 (unsigned long)scsi_get_lba(cmd),
3035 ref_tag, start_ref_tag);
3037 } else if (err_type == BGS_APPTAG_ERR_MASK) {
3038 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
3040 cmd->result = DRIVER_SENSE << 24
3041 | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
3043 phba->bg_apptag_err_cnt++;
3044 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
3045 "9041 BLKGRD: LBA %lx app_tag error %x != %x\n",
3046 (unsigned long)scsi_get_lba(cmd),
3047 app_tag, start_app_tag);
3053 * This function checks for BlockGuard errors detected by
3054 * the HBA. In case of errors, the ASC/ASCQ fields in the
3055 * sense buffer will be set accordingly, paired with
3056 * ILLEGAL_REQUEST to signal to the kernel that the HBA
3057 * detected corruption.
3060 * 0 - No error found
3061 * 1 - BlockGuard error found
3062 * -1 - Internal error (bad profile, ...etc)
3065 lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd,
3066 struct lpfc_iocbq *pIocbOut)
3068 struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
3069 struct sli3_bg_fields *bgf = &pIocbOut->iocb.unsli3.sli3_bg;
3071 uint32_t bghm = bgf->bghm;
3072 uint32_t bgstat = bgf->bgstat;
3073 uint64_t failing_sector = 0;
3075 spin_lock(&_dump_buf_lock);
3076 if (!_dump_buf_done) {
3077 lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9070 BLKGRD: Saving"
3078 " Data for %u blocks to debugfs\n",
3079 (cmd->cmnd[7] << 8 | cmd->cmnd[8]));
3080 lpfc_debug_save_data(phba, cmd);
3082 /* If we have a prot sgl, save the DIF buffer */
3083 if (lpfc_prot_group_type(phba, cmd) ==
3084 LPFC_PG_TYPE_DIF_BUF) {
3085 lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9071 BLKGRD: "
3086 "Saving DIF for %u blocks to debugfs\n",
3087 (cmd->cmnd[7] << 8 | cmd->cmnd[8]));
3088 lpfc_debug_save_dif(phba, cmd);
3093 spin_unlock(&_dump_buf_lock);
3095 if (lpfc_bgs_get_invalid_prof(bgstat)) {
3096 cmd->result = ScsiResult(DID_ERROR, 0);
3097 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
3098 "9072 BLKGRD: Invalid BG Profile in cmd"
3099 " 0x%x lba 0x%llx blk cnt 0x%x "
3100 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
3101 (unsigned long long)scsi_get_lba(cmd),
3102 blk_rq_sectors(cmd->request), bgstat, bghm);
3107 if (lpfc_bgs_get_uninit_dif_block(bgstat)) {
3108 cmd->result = ScsiResult(DID_ERROR, 0);
3109 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
3110 "9073 BLKGRD: Invalid BG PDIF Block in cmd"
3111 " 0x%x lba 0x%llx blk cnt 0x%x "
3112 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
3113 (unsigned long long)scsi_get_lba(cmd),
3114 blk_rq_sectors(cmd->request), bgstat, bghm);
3119 if (lpfc_bgs_get_guard_err(bgstat)) {
3122 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
3124 cmd->result = DRIVER_SENSE << 24
3125 | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
3126 phba->bg_guard_err_cnt++;
3127 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
3128 "9055 BLKGRD: Guard Tag error in cmd"
3129 " 0x%x lba 0x%llx blk cnt 0x%x "
3130 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
3131 (unsigned long long)scsi_get_lba(cmd),
3132 blk_rq_sectors(cmd->request), bgstat, bghm);
3135 if (lpfc_bgs_get_reftag_err(bgstat)) {
3138 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
3140 cmd->result = DRIVER_SENSE << 24
3141 | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
3143 phba->bg_reftag_err_cnt++;
3144 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
3145 "9056 BLKGRD: Ref Tag error in cmd"
3146 " 0x%x lba 0x%llx blk cnt 0x%x "
3147 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
3148 (unsigned long long)scsi_get_lba(cmd),
3149 blk_rq_sectors(cmd->request), bgstat, bghm);
3152 if (lpfc_bgs_get_apptag_err(bgstat)) {
3155 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
3157 cmd->result = DRIVER_SENSE << 24
3158 | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
3160 phba->bg_apptag_err_cnt++;
3161 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
3162 "9061 BLKGRD: App Tag error in cmd"
3163 " 0x%x lba 0x%llx blk cnt 0x%x "
3164 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
3165 (unsigned long long)scsi_get_lba(cmd),
3166 blk_rq_sectors(cmd->request), bgstat, bghm);
3169 if (lpfc_bgs_get_hi_water_mark_present(bgstat)) {
3171 * setup sense data descriptor 0 per SPC-4 as an information
3172 * field, and put the failing LBA in it.
3173 * This code assumes there was also a guard/app/ref tag error
3176 cmd->sense_buffer[7] = 0xc; /* Additional sense length */
3177 cmd->sense_buffer[8] = 0; /* Information descriptor type */
3178 cmd->sense_buffer[9] = 0xa; /* Additional descriptor length */
3179 cmd->sense_buffer[10] = 0x80; /* Validity bit */
3181 /* bghm is a "on the wire" FC frame based count */
3182 switch (scsi_get_prot_op(cmd)) {
3183 case SCSI_PROT_READ_INSERT:
3184 case SCSI_PROT_WRITE_STRIP:
3185 bghm /= cmd->device->sector_size;
3187 case SCSI_PROT_READ_STRIP:
3188 case SCSI_PROT_WRITE_INSERT:
3189 case SCSI_PROT_READ_PASS:
3190 case SCSI_PROT_WRITE_PASS:
3191 bghm /= (cmd->device->sector_size +
3192 sizeof(struct scsi_dif_tuple));
3196 failing_sector = scsi_get_lba(cmd);
3197 failing_sector += bghm;
3199 /* Descriptor Information */
3200 put_unaligned_be64(failing_sector, &cmd->sense_buffer[12]);
3204 /* No error was reported - problem in FW? */
3205 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
3206 "9057 BLKGRD: Unknown error in cmd"
3207 " 0x%x lba 0x%llx blk cnt 0x%x "
3208 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
3209 (unsigned long long)scsi_get_lba(cmd),
3210 blk_rq_sectors(cmd->request), bgstat, bghm);
3212 /* Calcuate what type of error it was */
3213 lpfc_calc_bg_err(phba, lpfc_cmd);
3220 * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
3221 * @phba: The Hba for which this call is being executed.
3222 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3224 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
3225 * field of @lpfc_cmd for device with SLI-4 interface spec.
3232 lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
3234 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
3235 struct scatterlist *sgel = NULL;
3236 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
3237 struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl;
3238 struct sli4_sge *first_data_sgl;
3239 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
3240 dma_addr_t physaddr;
3241 uint32_t num_bde = 0;
3243 uint32_t dma_offset = 0;
3245 struct ulp_bde64 *bde;
3248 * There are three possibilities here - use scatter-gather segment, use
3249 * the single mapping, or neither. Start the lpfc command prep by
3250 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
3253 if (scsi_sg_count(scsi_cmnd)) {
3255 * The driver stores the segment count returned from pci_map_sg
3256 * because this a count of dma-mappings used to map the use_sg
3257 * pages. They are not guaranteed to be the same for those
3258 * architectures that implement an IOMMU.
3261 nseg = scsi_dma_map(scsi_cmnd);
3262 if (unlikely(nseg <= 0))
3265 /* clear the last flag in the fcp_rsp map entry */
3266 sgl->word2 = le32_to_cpu(sgl->word2);
3267 bf_set(lpfc_sli4_sge_last, sgl, 0);
3268 sgl->word2 = cpu_to_le32(sgl->word2);
3270 first_data_sgl = sgl;
3271 lpfc_cmd->seg_cnt = nseg;
3272 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
3273 lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9074 BLKGRD:"
3274 " %s: Too many sg segments from "
3275 "dma_map_sg. Config %d, seg_cnt %d\n",
3276 __func__, phba->cfg_sg_seg_cnt,
3278 lpfc_cmd->seg_cnt = 0;
3279 scsi_dma_unmap(scsi_cmnd);
3284 * The driver established a maximum scatter-gather segment count
3285 * during probe that limits the number of sg elements in any
3286 * single scsi command. Just run through the seg_cnt and format
3288 * When using SLI-3 the driver will try to fit all the BDEs into
3289 * the IOCB. If it can't then the BDEs get added to a BPL as it
3290 * does for SLI-2 mode.
3292 scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) {
3293 physaddr = sg_dma_address(sgel);
3294 dma_len = sg_dma_len(sgel);
3295 sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr));
3296 sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr));
3297 sgl->word2 = le32_to_cpu(sgl->word2);
3298 if ((num_bde + 1) == nseg)
3299 bf_set(lpfc_sli4_sge_last, sgl, 1);
3301 bf_set(lpfc_sli4_sge_last, sgl, 0);
3302 bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
3303 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA);
3304 sgl->word2 = cpu_to_le32(sgl->word2);
3305 sgl->sge_len = cpu_to_le32(dma_len);
3306 dma_offset += dma_len;
3309 /* setup the performance hint (first data BDE) if enabled */
3310 if (phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) {
3311 bde = (struct ulp_bde64 *)
3312 &(iocb_cmd->unsli3.sli3Words[5]);
3313 bde->addrLow = first_data_sgl->addr_lo;
3314 bde->addrHigh = first_data_sgl->addr_hi;
3315 bde->tus.f.bdeSize =
3316 le32_to_cpu(first_data_sgl->sge_len);
3317 bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
3318 bde->tus.w = cpu_to_le32(bde->tus.w);
3322 /* clear the last flag in the fcp_rsp map entry */
3323 sgl->word2 = le32_to_cpu(sgl->word2);
3324 bf_set(lpfc_sli4_sge_last, sgl, 1);
3325 sgl->word2 = cpu_to_le32(sgl->word2);
3329 * Finish initializing those IOCB fields that are dependent on the
3330 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
3331 * explicitly reinitialized.
3332 * all iocb memory resources are reused.
3334 fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd));
3337 * Due to difference in data length between DIF/non-DIF paths,
3338 * we need to set word 4 of IOCB here
3340 iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd);
3343 * If the OAS driver feature is enabled and the lun is enabled for
3344 * OAS, set the oas iocb related flags.
3346 if ((phba->cfg_fof) && ((struct lpfc_device_data *)
3347 scsi_cmnd->device->hostdata)->oas_enabled)
3348 lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF);
3353 * lpfc_bg_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
3354 * @phba: The Hba for which this call is being executed.
3355 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3357 * This is the protection/DIF aware version of
3358 * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the
3359 * two functions eventually, but for now, it's here
3362 lpfc_bg_scsi_prep_dma_buf_s4(struct lpfc_hba *phba,
3363 struct lpfc_scsi_buf *lpfc_cmd)
3365 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
3366 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
3367 struct sli4_sge *sgl = (struct sli4_sge *)(lpfc_cmd->fcp_bpl);
3368 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
3369 uint32_t num_sge = 0;
3370 int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction;
3371 int prot_group_type = 0;
3373 struct lpfc_vport *vport = phba->pport;
3376 * Start the lpfc command prep by bumping the sgl beyond fcp_cmnd
3377 * fcp_rsp regions to the first data sge entry
3379 if (scsi_sg_count(scsi_cmnd)) {
3381 * The driver stores the segment count returned from pci_map_sg
3382 * because this a count of dma-mappings used to map the use_sg
3383 * pages. They are not guaranteed to be the same for those
3384 * architectures that implement an IOMMU.
3386 datasegcnt = dma_map_sg(&phba->pcidev->dev,
3387 scsi_sglist(scsi_cmnd),
3388 scsi_sg_count(scsi_cmnd), datadir);
3389 if (unlikely(!datasegcnt))
3393 /* clear the last flag in the fcp_rsp map entry */
3394 sgl->word2 = le32_to_cpu(sgl->word2);
3395 bf_set(lpfc_sli4_sge_last, sgl, 0);
3396 sgl->word2 = cpu_to_le32(sgl->word2);
3399 lpfc_cmd->seg_cnt = datasegcnt;
3401 /* First check if data segment count from SCSI Layer is good */
3402 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt)
3405 prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd);
3407 switch (prot_group_type) {
3408 case LPFC_PG_TYPE_NO_DIF:
3409 /* Here we need to add a DISEED to the count */
3410 if ((lpfc_cmd->seg_cnt + 1) > phba->cfg_total_seg_cnt)
3413 num_sge = lpfc_bg_setup_sgl(phba, scsi_cmnd, sgl,
3416 /* we should have 2 or more entries in buffer list */
3421 case LPFC_PG_TYPE_DIF_BUF:
3423 * This type indicates that protection buffers are
3424 * passed to the driver, so that needs to be prepared
3427 protsegcnt = dma_map_sg(&phba->pcidev->dev,
3428 scsi_prot_sglist(scsi_cmnd),
3429 scsi_prot_sg_count(scsi_cmnd), datadir);
3430 if (unlikely(!protsegcnt)) {
3431 scsi_dma_unmap(scsi_cmnd);
3435 lpfc_cmd->prot_seg_cnt = protsegcnt;
3437 * There is a minimun of 3 SGEs used for every
3438 * protection data segment.
3440 if ((lpfc_cmd->prot_seg_cnt * 3) >
3441 (phba->cfg_total_seg_cnt - 2))
3444 num_sge = lpfc_bg_setup_sgl_prot(phba, scsi_cmnd, sgl,
3445 datasegcnt, protsegcnt);
3447 /* we should have 3 or more entries in buffer list */
3448 if ((num_sge < 3) ||
3449 (num_sge > phba->cfg_total_seg_cnt))
3453 case LPFC_PG_TYPE_INVALID:
3455 scsi_dma_unmap(scsi_cmnd);
3456 lpfc_cmd->seg_cnt = 0;
3458 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
3459 "9083 Unexpected protection group %i\n",
3465 switch (scsi_get_prot_op(scsi_cmnd)) {
3466 case SCSI_PROT_WRITE_STRIP:
3467 case SCSI_PROT_READ_STRIP:
3468 lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_STRIP;
3470 case SCSI_PROT_WRITE_INSERT:
3471 case SCSI_PROT_READ_INSERT:
3472 lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_INSERT;
3474 case SCSI_PROT_WRITE_PASS:
3475 case SCSI_PROT_READ_PASS:
3476 lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_PASS;
3480 fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd);
3481 fcp_cmnd->fcpDl = be32_to_cpu(fcpdl);
3484 * Due to difference in data length between DIF/non-DIF paths,
3485 * we need to set word 4 of IOCB here
3487 iocb_cmd->un.fcpi.fcpi_parm = fcpdl;
3490 * For First burst, we may need to adjust the initial transfer
3493 if (iocb_cmd->un.fcpi.fcpi_XRdy &&
3494 (fcpdl < vport->cfg_first_burst_size))
3495 iocb_cmd->un.fcpi.fcpi_XRdy = fcpdl;
3498 * If the OAS driver feature is enabled and the lun is enabled for
3499 * OAS, set the oas iocb related flags.
3501 if ((phba->cfg_fof) && ((struct lpfc_device_data *)
3502 scsi_cmnd->device->hostdata)->oas_enabled)
3503 lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF);
3507 if (lpfc_cmd->seg_cnt)
3508 scsi_dma_unmap(scsi_cmnd);
3509 if (lpfc_cmd->prot_seg_cnt)
3510 dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd),
3511 scsi_prot_sg_count(scsi_cmnd),
3512 scsi_cmnd->sc_data_direction);
3514 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
3515 "9084 Cannot setup S/G List for HBA"
3516 "IO segs %d/%d SGL %d SCSI %d: %d %d\n",
3517 lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt,
3518 phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt,
3519 prot_group_type, num_sge);
3521 lpfc_cmd->seg_cnt = 0;
3522 lpfc_cmd->prot_seg_cnt = 0;
3527 * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
3528 * @phba: The Hba for which this call is being executed.
3529 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3531 * This routine wraps the actual DMA mapping function pointer from the
3539 lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
3541 return phba->lpfc_scsi_prep_dma_buf(phba, lpfc_cmd);
3545 * lpfc_bg_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
3547 * @phba: The Hba for which this call is being executed.
3548 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3550 * This routine wraps the actual DMA mapping function pointer from the
3558 lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
3560 return phba->lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd);
3564 * lpfc_send_scsi_error_event - Posts an event when there is SCSI error
3565 * @phba: Pointer to hba context object.
3566 * @vport: Pointer to vport object.
3567 * @lpfc_cmd: Pointer to lpfc scsi command which reported the error.
3568 * @rsp_iocb: Pointer to response iocb object which reported error.
3570 * This function posts an event when there is a SCSI command reporting
3571 * error from the scsi device.
3574 lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport,
3575 struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_iocbq *rsp_iocb) {
3576 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
3577 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
3578 uint32_t resp_info = fcprsp->rspStatus2;
3579 uint32_t scsi_status = fcprsp->rspStatus3;
3580 uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm;
3581 struct lpfc_fast_path_event *fast_path_evt = NULL;
3582 struct lpfc_nodelist *pnode = lpfc_cmd->rdata->pnode;
3583 unsigned long flags;
3585 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
3588 /* If there is queuefull or busy condition send a scsi event */
3589 if ((cmnd->result == SAM_STAT_TASK_SET_FULL) ||
3590 (cmnd->result == SAM_STAT_BUSY)) {
3591 fast_path_evt = lpfc_alloc_fast_evt(phba);
3594 fast_path_evt->un.scsi_evt.event_type =
3596 fast_path_evt->un.scsi_evt.subcategory =
3597 (cmnd->result == SAM_STAT_TASK_SET_FULL) ?
3598 LPFC_EVENT_QFULL : LPFC_EVENT_DEVBSY;
3599 fast_path_evt->un.scsi_evt.lun = cmnd->device->lun;
3600 memcpy(&fast_path_evt->un.scsi_evt.wwpn,
3601 &pnode->nlp_portname, sizeof(struct lpfc_name));
3602 memcpy(&fast_path_evt->un.scsi_evt.wwnn,
3603 &pnode->nlp_nodename, sizeof(struct lpfc_name));
3604 } else if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen &&
3605 ((cmnd->cmnd[0] == READ_10) || (cmnd->cmnd[0] == WRITE_10))) {
3606 fast_path_evt = lpfc_alloc_fast_evt(phba);
3609 fast_path_evt->un.check_cond_evt.scsi_event.event_type =
3611 fast_path_evt->un.check_cond_evt.scsi_event.subcategory =
3612 LPFC_EVENT_CHECK_COND;
3613 fast_path_evt->un.check_cond_evt.scsi_event.lun =
3615 memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwpn,
3616 &pnode->nlp_portname, sizeof(struct lpfc_name));
3617 memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwnn,
3618 &pnode->nlp_nodename, sizeof(struct lpfc_name));
3619 fast_path_evt->un.check_cond_evt.sense_key =
3620 cmnd->sense_buffer[2] & 0xf;
3621 fast_path_evt->un.check_cond_evt.asc = cmnd->sense_buffer[12];
3622 fast_path_evt->un.check_cond_evt.ascq = cmnd->sense_buffer[13];
3623 } else if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) &&
3625 ((be32_to_cpu(fcprsp->rspResId) != fcpi_parm) ||
3626 ((scsi_status == SAM_STAT_GOOD) &&
3627 !(resp_info & (RESID_UNDER | RESID_OVER))))) {
3629 * If status is good or resid does not match with fcp_param and
3630 * there is valid fcpi_parm, then there is a read_check error
3632 fast_path_evt = lpfc_alloc_fast_evt(phba);
3635 fast_path_evt->un.read_check_error.header.event_type =
3636 FC_REG_FABRIC_EVENT;
3637 fast_path_evt->un.read_check_error.header.subcategory =
3638 LPFC_EVENT_FCPRDCHKERR;
3639 memcpy(&fast_path_evt->un.read_check_error.header.wwpn,
3640 &pnode->nlp_portname, sizeof(struct lpfc_name));
3641 memcpy(&fast_path_evt->un.read_check_error.header.wwnn,
3642 &pnode->nlp_nodename, sizeof(struct lpfc_name));
3643 fast_path_evt->un.read_check_error.lun = cmnd->device->lun;
3644 fast_path_evt->un.read_check_error.opcode = cmnd->cmnd[0];
3645 fast_path_evt->un.read_check_error.fcpiparam =
3650 fast_path_evt->vport = vport;
3651 spin_lock_irqsave(&phba->hbalock, flags);
3652 list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list);
3653 spin_unlock_irqrestore(&phba->hbalock, flags);
3654 lpfc_worker_wake_up(phba);
3659 * lpfc_scsi_unprep_dma_buf - Un-map DMA mapping of SG-list for dev
3660 * @phba: The HBA for which this call is being executed.
3661 * @psb: The scsi buffer which is going to be un-mapped.
3663 * This routine does DMA un-mapping of scatter gather list of scsi command
3664 * field of @lpfc_cmd for device with SLI-3 interface spec.
3667 lpfc_scsi_unprep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
3670 * There are only two special cases to consider. (1) the scsi command
3671 * requested scatter-gather usage or (2) the scsi command allocated
3672 * a request buffer, but did not request use_sg. There is a third
3673 * case, but it does not require resource deallocation.
3675 if (psb->seg_cnt > 0)
3676 scsi_dma_unmap(psb->pCmd);
3677 if (psb->prot_seg_cnt > 0)
3678 dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(psb->pCmd),
3679 scsi_prot_sg_count(psb->pCmd),
3680 psb->pCmd->sc_data_direction);
3684 * lpfc_handler_fcp_err - FCP response handler
3685 * @vport: The virtual port for which this call is being executed.
3686 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
3687 * @rsp_iocb: The response IOCB which contains FCP error.
3689 * This routine is called to process response IOCB with status field
3690 * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command
3691 * based upon SCSI and FCP error.
3694 lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
3695 struct lpfc_iocbq *rsp_iocb)
3697 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
3698 struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd;
3699 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
3700 uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm;
3701 uint32_t resp_info = fcprsp->rspStatus2;
3702 uint32_t scsi_status = fcprsp->rspStatus3;
3704 uint32_t host_status = DID_OK;
3705 uint32_t rsplen = 0;
3706 uint32_t logit = LOG_FCP | LOG_FCP_ERROR;
3710 * If this is a task management command, there is no
3711 * scsi packet associated with this lpfc_cmd. The driver
3714 if (fcpcmd->fcpCntl2) {
3719 if (resp_info & RSP_LEN_VALID) {
3720 rsplen = be32_to_cpu(fcprsp->rspRspLen);
3721 if (rsplen != 0 && rsplen != 4 && rsplen != 8) {
3722 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3723 "2719 Invalid response length: "
3724 "tgt x%x lun x%llx cmnd x%x rsplen x%x\n",
3726 cmnd->device->lun, cmnd->cmnd[0],
3728 host_status = DID_ERROR;
3731 if (fcprsp->rspInfo3 != RSP_NO_FAILURE) {
3732 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3733 "2757 Protocol failure detected during "
3734 "processing of FCP I/O op: "
3735 "tgt x%x lun x%llx cmnd x%x rspInfo3 x%x\n",
3737 cmnd->device->lun, cmnd->cmnd[0],
3739 host_status = DID_ERROR;
3744 if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) {
3745 uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen);
3746 if (snslen > SCSI_SENSE_BUFFERSIZE)
3747 snslen = SCSI_SENSE_BUFFERSIZE;
3749 if (resp_info & RSP_LEN_VALID)
3750 rsplen = be32_to_cpu(fcprsp->rspRspLen);
3751 memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen);
3753 lp = (uint32_t *)cmnd->sense_buffer;
3755 /* special handling for under run conditions */
3756 if (!scsi_status && (resp_info & RESID_UNDER)) {
3757 /* don't log under runs if fcp set... */
3758 if (vport->cfg_log_verbose & LOG_FCP)
3759 logit = LOG_FCP_ERROR;
3760 /* unless operator says so */
3761 if (vport->cfg_log_verbose & LOG_FCP_UNDER)
3762 logit = LOG_FCP_UNDER;
3765 lpfc_printf_vlog(vport, KERN_WARNING, logit,
3766 "9024 FCP command x%x failed: x%x SNS x%x x%x "
3767 "Data: x%x x%x x%x x%x x%x\n",
3768 cmnd->cmnd[0], scsi_status,
3769 be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info,
3770 be32_to_cpu(fcprsp->rspResId),
3771 be32_to_cpu(fcprsp->rspSnsLen),
3772 be32_to_cpu(fcprsp->rspRspLen),
3775 scsi_set_resid(cmnd, 0);
3776 if (resp_info & RESID_UNDER) {
3777 scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId));
3779 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_UNDER,
3780 "9025 FCP Read Underrun, expected %d, "
3781 "residual %d Data: x%x x%x x%x\n",
3782 be32_to_cpu(fcpcmd->fcpDl),
3783 scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0],
3787 * If there is an under run check if under run reported by
3788 * storage array is same as the under run reported by HBA.
3789 * If this is not same, there is a dropped frame.
3791 if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) &&
3793 (scsi_get_resid(cmnd) != fcpi_parm)) {
3794 lpfc_printf_vlog(vport, KERN_WARNING,
3795 LOG_FCP | LOG_FCP_ERROR,
3796 "9026 FCP Read Check Error "
3797 "and Underrun Data: x%x x%x x%x x%x\n",
3798 be32_to_cpu(fcpcmd->fcpDl),
3799 scsi_get_resid(cmnd), fcpi_parm,
3801 scsi_set_resid(cmnd, scsi_bufflen(cmnd));
3802 host_status = DID_ERROR;
3805 * The cmnd->underflow is the minimum number of bytes that must
3806 * be transferred for this command. Provided a sense condition
3807 * is not present, make sure the actual amount transferred is at
3808 * least the underflow value or fail.
3810 if (!(resp_info & SNS_LEN_VALID) &&
3811 (scsi_status == SAM_STAT_GOOD) &&
3812 (scsi_bufflen(cmnd) - scsi_get_resid(cmnd)
3813 < cmnd->underflow)) {
3814 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
3815 "9027 FCP command x%x residual "
3816 "underrun converted to error "
3817 "Data: x%x x%x x%x\n",
3818 cmnd->cmnd[0], scsi_bufflen(cmnd),
3819 scsi_get_resid(cmnd), cmnd->underflow);
3820 host_status = DID_ERROR;
3822 } else if (resp_info & RESID_OVER) {
3823 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
3824 "9028 FCP command x%x residual overrun error. "
3825 "Data: x%x x%x\n", cmnd->cmnd[0],
3826 scsi_bufflen(cmnd), scsi_get_resid(cmnd));
3827 host_status = DID_ERROR;
3830 * Check SLI validation that all the transfer was actually done
3831 * (fcpi_parm should be zero). Apply check only to reads.
3833 } else if (fcpi_parm && (cmnd->sc_data_direction == DMA_FROM_DEVICE)) {
3834 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR,
3835 "9029 FCP Read Check Error Data: "
3836 "x%x x%x x%x x%x x%x\n",
3837 be32_to_cpu(fcpcmd->fcpDl),
3838 be32_to_cpu(fcprsp->rspResId),
3839 fcpi_parm, cmnd->cmnd[0], scsi_status);
3840 switch (scsi_status) {
3842 case SAM_STAT_CHECK_CONDITION:
3843 /* Fabric dropped a data frame. Fail any successful
3844 * command in which we detected dropped frames.
3845 * A status of good or some check conditions could
3846 * be considered a successful command.
3848 host_status = DID_ERROR;
3851 scsi_set_resid(cmnd, scsi_bufflen(cmnd));
3855 cmnd->result = ScsiResult(host_status, scsi_status);
3856 lpfc_send_scsi_error_event(vport->phba, vport, lpfc_cmd, rsp_iocb);
3860 * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
3861 * @phba: Pointer to HBA context object.
3863 * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
3864 * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
3866 * If scsi-mq is enabled, get the default block layer mapping of software queues
3867 * to hardware queues. This information is saved in request tag.
3869 * Return: index into SLI4 fast-path FCP queue index.
3871 int lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba,
3872 struct lpfc_scsi_buf *lpfc_cmd)
3874 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
3875 struct lpfc_vector_map_info *cpup;
3880 if (cmnd && shost_use_blk_mq(cmnd->device->host)) {
3881 tag = blk_mq_unique_tag(cmnd->request);
3882 hwq = blk_mq_unique_tag_to_hwq(tag);
3887 if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_CPU
3888 && phba->cfg_fcp_io_channel > 1) {
3889 cpu = smp_processor_id();
3890 if (cpu < phba->sli4_hba.num_present_cpu) {
3891 cpup = phba->sli4_hba.cpu_map;
3893 return cpup->channel_id;
3896 chann = atomic_add_return(1, &phba->fcp_qidx);
3897 chann = (chann % phba->cfg_fcp_io_channel);
3903 * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine
3904 * @phba: The Hba for which this call is being executed.
3905 * @pIocbIn: The command IOCBQ for the scsi cmnd.
3906 * @pIocbOut: The response IOCBQ for the scsi cmnd.
3908 * This routine assigns scsi command result by looking into response IOCB
3909 * status field appropriately. This routine handles QUEUE FULL condition as
3910 * well by ramping down device queue depth.
3913 lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
3914 struct lpfc_iocbq *pIocbOut)
3916 struct lpfc_scsi_buf *lpfc_cmd =
3917 (struct lpfc_scsi_buf *) pIocbIn->context1;
3918 struct lpfc_vport *vport = pIocbIn->vport;
3919 struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
3920 struct lpfc_nodelist *pnode = rdata->pnode;
3921 struct scsi_cmnd *cmd;
3923 unsigned long flags;
3924 struct lpfc_fast_path_event *fast_path_evt;
3925 struct Scsi_Host *shost;
3926 uint32_t logit = LOG_FCP;
3928 /* Sanity check on return of outstanding command */
3929 cmd = lpfc_cmd->pCmd;
3932 shost = cmd->device->host;
3934 lpfc_cmd->result = (pIocbOut->iocb.un.ulpWord[4] & IOERR_PARAM_MASK);
3935 lpfc_cmd->status = pIocbOut->iocb.ulpStatus;
3936 /* pick up SLI4 exhange busy status from HBA */
3937 lpfc_cmd->exch_busy = pIocbOut->iocb_flag & LPFC_EXCHANGE_BUSY;
3939 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3940 if (lpfc_cmd->prot_data_type) {
3941 struct scsi_dif_tuple *src = NULL;
3943 src = (struct scsi_dif_tuple *)lpfc_cmd->prot_data_segment;
3945 * Used to restore any changes to protection
3946 * data for error injection.
3948 switch (lpfc_cmd->prot_data_type) {
3949 case LPFC_INJERR_REFTAG:
3951 lpfc_cmd->prot_data;
3953 case LPFC_INJERR_APPTAG:
3955 (uint16_t)lpfc_cmd->prot_data;
3957 case LPFC_INJERR_GUARD:
3959 (uint16_t)lpfc_cmd->prot_data;
3965 lpfc_cmd->prot_data = 0;
3966 lpfc_cmd->prot_data_type = 0;
3967 lpfc_cmd->prot_data_segment = NULL;
3970 if (pnode && NLP_CHK_NODE_ACT(pnode))
3971 atomic_dec(&pnode->cmd_pending);
3973 if (lpfc_cmd->status) {
3974 if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT &&
3975 (lpfc_cmd->result & IOERR_DRVR_MASK))
3976 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
3977 else if (lpfc_cmd->status >= IOSTAT_CNT)
3978 lpfc_cmd->status = IOSTAT_DEFAULT;
3979 if (lpfc_cmd->status == IOSTAT_FCP_RSP_ERROR &&
3980 !lpfc_cmd->fcp_rsp->rspStatus3 &&
3981 (lpfc_cmd->fcp_rsp->rspStatus2 & RESID_UNDER) &&
3982 !(vport->cfg_log_verbose & LOG_FCP_UNDER))
3985 logit = LOG_FCP | LOG_FCP_UNDER;
3986 lpfc_printf_vlog(vport, KERN_WARNING, logit,
3987 "9030 FCP cmd x%x failed <%d/%lld> "
3988 "status: x%x result: x%x "
3989 "sid: x%x did: x%x oxid: x%x "
3992 cmd->device ? cmd->device->id : 0xffff,
3993 cmd->device ? cmd->device->lun : 0xffff,
3994 lpfc_cmd->status, lpfc_cmd->result,
3996 (pnode) ? pnode->nlp_DID : 0,
3997 phba->sli_rev == LPFC_SLI_REV4 ?
3998 lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff,
3999 pIocbOut->iocb.ulpContext,
4000 lpfc_cmd->cur_iocbq.iocb.ulpIoTag);
4002 switch (lpfc_cmd->status) {
4003 case IOSTAT_FCP_RSP_ERROR:
4004 /* Call FCP RSP handler to determine result */
4005 lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut);
4007 case IOSTAT_NPORT_BSY:
4008 case IOSTAT_FABRIC_BSY:
4009 cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 0);
4010 fast_path_evt = lpfc_alloc_fast_evt(phba);
4013 fast_path_evt->un.fabric_evt.event_type =
4014 FC_REG_FABRIC_EVENT;
4015 fast_path_evt->un.fabric_evt.subcategory =
4016 (lpfc_cmd->status == IOSTAT_NPORT_BSY) ?
4017 LPFC_EVENT_PORT_BUSY : LPFC_EVENT_FABRIC_BUSY;
4018 if (pnode && NLP_CHK_NODE_ACT(pnode)) {
4019 memcpy(&fast_path_evt->un.fabric_evt.wwpn,
4020 &pnode->nlp_portname,
4021 sizeof(struct lpfc_name));
4022 memcpy(&fast_path_evt->un.fabric_evt.wwnn,
4023 &pnode->nlp_nodename,
4024 sizeof(struct lpfc_name));
4026 fast_path_evt->vport = vport;
4027 fast_path_evt->work_evt.evt =
4028 LPFC_EVT_FASTPATH_MGMT_EVT;
4029 spin_lock_irqsave(&phba->hbalock, flags);
4030 list_add_tail(&fast_path_evt->work_evt.evt_listp,
4032 spin_unlock_irqrestore(&phba->hbalock, flags);
4033 lpfc_worker_wake_up(phba);
4035 case IOSTAT_LOCAL_REJECT:
4036 case IOSTAT_REMOTE_STOP:
4037 if (lpfc_cmd->result == IOERR_ELXSEC_KEY_UNWRAP_ERROR ||
4039 IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR ||
4040 lpfc_cmd->result == IOERR_ELXSEC_CRYPTO_ERROR ||
4042 IOERR_ELXSEC_CRYPTO_COMPARE_ERROR) {
4043 cmd->result = ScsiResult(DID_NO_CONNECT, 0);
4046 if (lpfc_cmd->result == IOERR_INVALID_RPI ||
4047 lpfc_cmd->result == IOERR_NO_RESOURCES ||
4048 lpfc_cmd->result == IOERR_ABORT_REQUESTED ||
4049 lpfc_cmd->result == IOERR_SLER_CMD_RCV_FAILURE) {
4050 cmd->result = ScsiResult(DID_REQUEUE, 0);
4053 if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED ||
4054 lpfc_cmd->result == IOERR_TX_DMA_FAILED) &&
4055 pIocbOut->iocb.unsli3.sli3_bg.bgstat) {
4056 if (scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
4058 * This is a response for a BG enabled
4059 * cmd. Parse BG error
4061 lpfc_parse_bg_err(phba, lpfc_cmd,
4065 lpfc_printf_vlog(vport, KERN_WARNING,
4067 "9031 non-zero BGSTAT "
4068 "on unprotected cmd\n");
4071 if ((lpfc_cmd->status == IOSTAT_REMOTE_STOP)
4072 && (phba->sli_rev == LPFC_SLI_REV4)
4073 && (pnode && NLP_CHK_NODE_ACT(pnode))) {
4074 /* This IO was aborted by the target, we don't
4075 * know the rxid and because we did not send the
4076 * ABTS we cannot generate and RRQ.
4078 lpfc_set_rrq_active(phba, pnode,
4079 lpfc_cmd->cur_iocbq.sli4_lxritag,
4082 /* else: fall through */
4084 cmd->result = ScsiResult(DID_ERROR, 0);
4088 if (!pnode || !NLP_CHK_NODE_ACT(pnode)
4089 || (pnode->nlp_state != NLP_STE_MAPPED_NODE))
4090 cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED,
4093 cmd->result = ScsiResult(DID_OK, 0);
4095 if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) {
4096 uint32_t *lp = (uint32_t *)cmd->sense_buffer;
4098 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4099 "0710 Iodone <%d/%llu> cmd %p, error "
4100 "x%x SNS x%x x%x Data: x%x x%x\n",
4101 cmd->device->id, cmd->device->lun, cmd,
4102 cmd->result, *lp, *(lp + 3), cmd->retries,
4103 scsi_get_resid(cmd));
4106 lpfc_update_stats(phba, lpfc_cmd);
4107 if (vport->cfg_max_scsicmpl_time &&
4108 time_after(jiffies, lpfc_cmd->start_time +
4109 msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) {
4110 spin_lock_irqsave(shost->host_lock, flags);
4111 if (pnode && NLP_CHK_NODE_ACT(pnode)) {
4112 if (pnode->cmd_qdepth >
4113 atomic_read(&pnode->cmd_pending) &&
4114 (atomic_read(&pnode->cmd_pending) >
4115 LPFC_MIN_TGT_QDEPTH) &&
4116 ((cmd->cmnd[0] == READ_10) ||
4117 (cmd->cmnd[0] == WRITE_10)))
4119 atomic_read(&pnode->cmd_pending);
4121 pnode->last_change_time = jiffies;
4123 spin_unlock_irqrestore(shost->host_lock, flags);
4124 } else if (pnode && NLP_CHK_NODE_ACT(pnode)) {
4125 if ((pnode->cmd_qdepth < vport->cfg_tgt_queue_depth) &&
4126 time_after(jiffies, pnode->last_change_time +
4127 msecs_to_jiffies(LPFC_TGTQ_INTERVAL))) {
4128 spin_lock_irqsave(shost->host_lock, flags);
4129 depth = pnode->cmd_qdepth * LPFC_TGTQ_RAMPUP_PCENT
4131 depth = depth ? depth : 1;
4132 pnode->cmd_qdepth += depth;
4133 if (pnode->cmd_qdepth > vport->cfg_tgt_queue_depth)
4134 pnode->cmd_qdepth = vport->cfg_tgt_queue_depth;
4135 pnode->last_change_time = jiffies;
4136 spin_unlock_irqrestore(shost->host_lock, flags);
4140 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
4142 /* The sdev is not guaranteed to be valid post scsi_done upcall. */
4143 cmd->scsi_done(cmd);
4145 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
4146 spin_lock_irqsave(&phba->hbalock, flags);
4147 lpfc_cmd->pCmd = NULL;
4148 spin_unlock_irqrestore(&phba->hbalock, flags);
4151 * If there is a thread waiting for command completion
4152 * wake up the thread.
4154 spin_lock_irqsave(shost->host_lock, flags);
4155 if (lpfc_cmd->waitq)
4156 wake_up(lpfc_cmd->waitq);
4157 spin_unlock_irqrestore(shost->host_lock, flags);
4158 lpfc_release_scsi_buf(phba, lpfc_cmd);
4162 spin_lock_irqsave(&phba->hbalock, flags);
4163 lpfc_cmd->pCmd = NULL;
4164 spin_unlock_irqrestore(&phba->hbalock, flags);
4167 * If there is a thread waiting for command completion
4168 * wake up the thread.
4170 spin_lock_irqsave(shost->host_lock, flags);
4171 if (lpfc_cmd->waitq)
4172 wake_up(lpfc_cmd->waitq);
4173 spin_unlock_irqrestore(shost->host_lock, flags);
4175 lpfc_release_scsi_buf(phba, lpfc_cmd);
4179 * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB
4180 * @data: A pointer to the immediate command data portion of the IOCB.
4181 * @fcp_cmnd: The FCP Command that is provided by the SCSI layer.
4183 * The routine copies the entire FCP command from @fcp_cmnd to @data while
4184 * byte swapping the data to big endian format for transmission on the wire.
4187 lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd)
4190 for (i = 0, j = 0; i < sizeof(struct fcp_cmnd);
4191 i += sizeof(uint32_t), j++) {
4192 ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]);
4197 * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit
4198 * @vport: The virtual port for which this call is being executed.
4199 * @lpfc_cmd: The scsi command which needs to send.
4200 * @pnode: Pointer to lpfc_nodelist.
4202 * This routine initializes fcp_cmnd and iocb data structure from scsi command
4203 * to transfer for device with SLI3 interface spec.
4206 lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
4207 struct lpfc_nodelist *pnode)
4209 struct lpfc_hba *phba = vport->phba;
4210 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
4211 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
4212 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
4213 struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq);
4214 int datadir = scsi_cmnd->sc_data_direction;
4219 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
4222 lpfc_cmd->fcp_rsp->rspSnsLen = 0;
4223 /* clear task management bits */
4224 lpfc_cmd->fcp_cmnd->fcpCntl2 = 0;
4226 int_to_scsilun(lpfc_cmd->pCmd->device->lun,
4227 &lpfc_cmd->fcp_cmnd->fcp_lun);
4229 ptr = &fcp_cmnd->fcpCdb[0];
4230 memcpy(ptr, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
4231 if (scsi_cmnd->cmd_len < LPFC_FCP_CDB_LEN) {
4232 ptr += scsi_cmnd->cmd_len;
4233 memset(ptr, 0, (LPFC_FCP_CDB_LEN - scsi_cmnd->cmd_len));
4236 fcp_cmnd->fcpCntl1 = SIMPLE_Q;
4238 sli4 = (phba->sli_rev == LPFC_SLI_REV4);
4239 piocbq->iocb.un.fcpi.fcpi_XRdy = 0;
4242 * There are three possibilities here - use scatter-gather segment, use
4243 * the single mapping, or neither. Start the lpfc command prep by
4244 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
4247 if (scsi_sg_count(scsi_cmnd)) {
4248 if (datadir == DMA_TO_DEVICE) {
4249 iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR;
4250 iocb_cmd->ulpPU = PARM_READ_CHECK;
4251 if (vport->cfg_first_burst_size &&
4252 (pnode->nlp_flag & NLP_FIRSTBURST)) {
4253 fcpdl = scsi_bufflen(scsi_cmnd);
4254 if (fcpdl < vport->cfg_first_burst_size)
4255 piocbq->iocb.un.fcpi.fcpi_XRdy = fcpdl;
4257 piocbq->iocb.un.fcpi.fcpi_XRdy =
4258 vport->cfg_first_burst_size;
4260 fcp_cmnd->fcpCntl3 = WRITE_DATA;
4261 phba->fc4OutputRequests++;
4263 iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR;
4264 iocb_cmd->ulpPU = PARM_READ_CHECK;
4265 fcp_cmnd->fcpCntl3 = READ_DATA;
4266 phba->fc4InputRequests++;
4269 iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR;
4270 iocb_cmd->un.fcpi.fcpi_parm = 0;
4271 iocb_cmd->ulpPU = 0;
4272 fcp_cmnd->fcpCntl3 = 0;
4273 phba->fc4ControlRequests++;
4275 if (phba->sli_rev == 3 &&
4276 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED))
4277 lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd);
4279 * Finish initializing those IOCB fields that are independent
4280 * of the scsi_cmnd request_buffer
4282 piocbq->iocb.ulpContext = pnode->nlp_rpi;
4284 piocbq->iocb.ulpContext =
4285 phba->sli4_hba.rpi_ids[pnode->nlp_rpi];
4286 if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE)
4287 piocbq->iocb.ulpFCP2Rcvy = 1;
4289 piocbq->iocb.ulpFCP2Rcvy = 0;
4291 piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f);
4292 piocbq->context1 = lpfc_cmd;
4293 piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
4294 piocbq->iocb.ulpTimeout = lpfc_cmd->timeout;
4295 piocbq->vport = vport;
4299 * lpfc_scsi_prep_task_mgmt_cmd - Convert SLI3 scsi TM cmd to FCP info unit
4300 * @vport: The virtual port for which this call is being executed.
4301 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
4302 * @lun: Logical unit number.
4303 * @task_mgmt_cmd: SCSI task management command.
4305 * This routine creates FCP information unit corresponding to @task_mgmt_cmd
4306 * for device with SLI-3 interface spec.
4313 lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport,
4314 struct lpfc_scsi_buf *lpfc_cmd,
4316 uint8_t task_mgmt_cmd)
4318 struct lpfc_iocbq *piocbq;
4320 struct fcp_cmnd *fcp_cmnd;
4321 struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
4322 struct lpfc_nodelist *ndlp = rdata->pnode;
4324 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) ||
4325 ndlp->nlp_state != NLP_STE_MAPPED_NODE)
4328 piocbq = &(lpfc_cmd->cur_iocbq);
4329 piocbq->vport = vport;
4331 piocb = &piocbq->iocb;
4333 fcp_cmnd = lpfc_cmd->fcp_cmnd;
4334 /* Clear out any old data in the FCP command area */
4335 memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd));
4336 int_to_scsilun(lun, &fcp_cmnd->fcp_lun);
4337 fcp_cmnd->fcpCntl2 = task_mgmt_cmd;
4338 if (vport->phba->sli_rev == 3 &&
4339 !(vport->phba->sli3_options & LPFC_SLI3_BG_ENABLED))
4340 lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd);
4341 piocb->ulpCommand = CMD_FCP_ICMND64_CR;
4342 piocb->ulpContext = ndlp->nlp_rpi;
4343 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
4345 vport->phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
4347 piocb->ulpFCP2Rcvy = (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) ? 1 : 0;
4348 piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f);
4350 piocb->un.fcpi.fcpi_parm = 0;
4352 /* ulpTimeout is only one byte */
4353 if (lpfc_cmd->timeout > 0xff) {
4355 * Do not timeout the command at the firmware level.
4356 * The driver will provide the timeout mechanism.
4358 piocb->ulpTimeout = 0;
4360 piocb->ulpTimeout = lpfc_cmd->timeout;
4362 if (vport->phba->sli_rev == LPFC_SLI_REV4)
4363 lpfc_sli4_set_rsp_sgl_last(vport->phba, lpfc_cmd);
4369 * lpfc_scsi_api_table_setup - Set up scsi api function jump table
4370 * @phba: The hba struct for which this call is being executed.
4371 * @dev_grp: The HBA PCI-Device group number.
4373 * This routine sets up the SCSI interface API function jump table in @phba
4375 * Returns: 0 - success, -ENODEV - failure.
4378 lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
4381 phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf;
4382 phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd;
4385 case LPFC_PCI_DEV_LP:
4386 phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s3;
4387 phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3;
4388 phba->lpfc_bg_scsi_prep_dma_buf = lpfc_bg_scsi_prep_dma_buf_s3;
4389 phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3;
4390 phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s3;
4392 case LPFC_PCI_DEV_OC:
4393 phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s4;
4394 phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s4;
4395 phba->lpfc_bg_scsi_prep_dma_buf = lpfc_bg_scsi_prep_dma_buf_s4;
4396 phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s4;
4397 phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s4;
4400 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4401 "1418 Invalid HBA PCI-device group: 0x%x\n",
4406 phba->lpfc_rampdown_queue_depth = lpfc_rampdown_queue_depth;
4407 phba->lpfc_scsi_cmd_iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
4412 * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command
4413 * @phba: The Hba for which this call is being executed.
4414 * @cmdiocbq: Pointer to lpfc_iocbq data structure.
4415 * @rspiocbq: Pointer to lpfc_iocbq data structure.
4417 * This routine is IOCB completion routine for device reset and target reset
4418 * routine. This routine release scsi buffer associated with lpfc_cmd.
4421 lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba,
4422 struct lpfc_iocbq *cmdiocbq,
4423 struct lpfc_iocbq *rspiocbq)
4425 struct lpfc_scsi_buf *lpfc_cmd =
4426 (struct lpfc_scsi_buf *) cmdiocbq->context1;
4428 lpfc_release_scsi_buf(phba, lpfc_cmd);
4433 * lpfc_info - Info entry point of scsi_host_template data structure
4434 * @host: The scsi host for which this call is being executed.
4436 * This routine provides module information about hba.
4439 * Pointer to char - Success.
4442 lpfc_info(struct Scsi_Host *host)
4444 struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata;
4445 struct lpfc_hba *phba = vport->phba;
4446 int len, link_speed = 0;
4447 static char lpfcinfobuf[384];
4449 memset(lpfcinfobuf,0,384);
4450 if (phba && phba->pcidev){
4451 strncpy(lpfcinfobuf, phba->ModelDesc, 256);
4452 len = strlen(lpfcinfobuf);
4453 snprintf(lpfcinfobuf + len,
4455 " on PCI bus %02x device %02x irq %d",
4456 phba->pcidev->bus->number,
4457 phba->pcidev->devfn,
4459 len = strlen(lpfcinfobuf);
4460 if (phba->Port[0]) {
4461 snprintf(lpfcinfobuf + len,
4466 len = strlen(lpfcinfobuf);
4467 if (phba->sli_rev <= LPFC_SLI_REV3) {
4468 link_speed = lpfc_sli_port_speed_get(phba);
4470 if (phba->sli4_hba.link_state.logical_speed)
4472 phba->sli4_hba.link_state.logical_speed;
4474 link_speed = phba->sli4_hba.link_state.speed;
4476 if (link_speed != 0)
4477 snprintf(lpfcinfobuf + len, 384-len,
4478 " Logical Link Speed: %d Mbps", link_speed);
4484 * lpfc_poll_rearm_time - Routine to modify fcp_poll timer of hba
4485 * @phba: The Hba for which this call is being executed.
4487 * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo.
4488 * The default value of cfg_poll_tmo is 10 milliseconds.
4490 static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba)
4492 unsigned long poll_tmo_expires =
4493 (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo));
4495 if (!list_empty(&phba->sli.ring[LPFC_FCP_RING].txcmplq))
4496 mod_timer(&phba->fcp_poll_timer,
4501 * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA
4502 * @phba: The Hba for which this call is being executed.
4504 * This routine starts the fcp_poll_timer of @phba.
4506 void lpfc_poll_start_timer(struct lpfc_hba * phba)
4508 lpfc_poll_rearm_timer(phba);
4512 * lpfc_poll_timeout - Restart polling timer
4513 * @ptr: Map to lpfc_hba data structure pointer.
4515 * This routine restarts fcp_poll timer, when FCP ring polling is enable
4516 * and FCP Ring interrupt is disable.
4519 void lpfc_poll_timeout(unsigned long ptr)
4521 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
4523 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
4524 lpfc_sli_handle_fast_ring_event(phba,
4525 &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
4527 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
4528 lpfc_poll_rearm_timer(phba);
4533 * lpfc_queuecommand - scsi_host_template queuecommand entry point
4534 * @cmnd: Pointer to scsi_cmnd data structure.
4535 * @done: Pointer to done routine.
4537 * Driver registers this routine to scsi midlayer to submit a @cmd to process.
4538 * This routine prepares an IOCB from scsi command and provides to firmware.
4539 * The @done callback is invoked after driver finished processing the command.
4543 * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily.
4546 lpfc_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *cmnd)
4548 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4549 struct lpfc_hba *phba = vport->phba;
4550 struct lpfc_rport_data *rdata;
4551 struct lpfc_nodelist *ndlp;
4552 struct lpfc_scsi_buf *lpfc_cmd;
4553 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
4556 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
4557 err = fc_remote_port_chkready(rport);
4560 goto out_fail_command;
4562 ndlp = rdata->pnode;
4564 if ((scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) &&
4565 (!(phba->sli3_options & LPFC_SLI3_BG_ENABLED))) {
4567 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
4568 "9058 BLKGRD: ERROR: rcvd protected cmd:%02x"
4569 " op:%02x str=%s without registering for"
4570 " BlockGuard - Rejecting command\n",
4571 cmnd->cmnd[0], scsi_get_prot_op(cmnd),
4572 dif_op_str[scsi_get_prot_op(cmnd)]);
4573 goto out_fail_command;
4577 * Catch race where our node has transitioned, but the
4578 * transport is still transitioning.
4580 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
4582 if (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth)
4585 lpfc_cmd = lpfc_get_scsi_buf(phba, ndlp);
4586 if (lpfc_cmd == NULL) {
4587 lpfc_rampdown_queue_depth(phba);
4589 lpfc_printf_vlog(vport, KERN_INFO, LOG_MISC,
4590 "0707 driver's buffer pool is empty, "
4596 * Store the midlayer's command structure for the completion phase
4597 * and complete the command initialization.
4599 lpfc_cmd->pCmd = cmnd;
4600 lpfc_cmd->rdata = rdata;
4601 lpfc_cmd->timeout = 0;
4602 lpfc_cmd->start_time = jiffies;
4603 cmnd->host_scribble = (unsigned char *)lpfc_cmd;
4605 if (scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) {
4606 if (vport->phba->cfg_enable_bg) {
4607 lpfc_printf_vlog(vport,
4608 KERN_INFO, LOG_SCSI_CMD,
4609 "9033 BLKGRD: rcvd %s cmd:x%x "
4610 "sector x%llx cnt %u pt %x\n",
4611 dif_op_str[scsi_get_prot_op(cmnd)],
4613 (unsigned long long)scsi_get_lba(cmnd),
4614 blk_rq_sectors(cmnd->request),
4615 (cmnd->cmnd[1]>>5));
4617 err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd);
4619 if (vport->phba->cfg_enable_bg) {
4620 lpfc_printf_vlog(vport,
4621 KERN_INFO, LOG_SCSI_CMD,
4622 "9038 BLKGRD: rcvd PROT_NORMAL cmd: "
4623 "x%x sector x%llx cnt %u pt %x\n",
4625 (unsigned long long)scsi_get_lba(cmnd),
4626 blk_rq_sectors(cmnd->request),
4627 (cmnd->cmnd[1]>>5));
4629 err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd);
4633 goto out_host_busy_free_buf;
4635 lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp);
4637 atomic_inc(&ndlp->cmd_pending);
4638 err = lpfc_sli_issue_iocb(phba, LPFC_FCP_RING,
4639 &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB);
4641 atomic_dec(&ndlp->cmd_pending);
4642 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4643 "3376 FCP could not issue IOCB err %x"
4644 "FCP cmd x%x <%d/%llu> "
4645 "sid: x%x did: x%x oxid: x%x "
4646 "Data: x%x x%x x%x x%x\n",
4648 cmnd->device ? cmnd->device->id : 0xffff,
4649 cmnd->device ? cmnd->device->lun : (u64) -1,
4650 vport->fc_myDID, ndlp->nlp_DID,
4651 phba->sli_rev == LPFC_SLI_REV4 ?
4652 lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff,
4653 lpfc_cmd->cur_iocbq.iocb.ulpContext,
4654 lpfc_cmd->cur_iocbq.iocb.ulpIoTag,
4655 lpfc_cmd->cur_iocbq.iocb.ulpTimeout,
4657 (cmnd->request->timeout / 1000));
4660 goto out_host_busy_free_buf;
4662 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
4663 lpfc_sli_handle_fast_ring_event(phba,
4664 &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
4666 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
4667 lpfc_poll_rearm_timer(phba);
4672 out_host_busy_free_buf:
4673 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
4674 lpfc_release_scsi_buf(phba, lpfc_cmd);
4676 return SCSI_MLQUEUE_HOST_BUSY;
4679 return SCSI_MLQUEUE_TARGET_BUSY;
4682 cmnd->scsi_done(cmnd);
4688 * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point
4689 * @cmnd: Pointer to scsi_cmnd data structure.
4691 * This routine aborts @cmnd pending in base driver.
4698 lpfc_abort_handler(struct scsi_cmnd *cmnd)
4700 struct Scsi_Host *shost = cmnd->device->host;
4701 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4702 struct lpfc_hba *phba = vport->phba;
4703 struct lpfc_iocbq *iocb;
4704 struct lpfc_iocbq *abtsiocb;
4705 struct lpfc_scsi_buf *lpfc_cmd;
4707 int ret = SUCCESS, status = 0;
4708 struct lpfc_sli_ring *pring_s4;
4709 int ring_number, ret_val;
4710 unsigned long flags, iflags;
4711 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq);
4713 status = fc_block_scsi_eh(cmnd);
4714 if (status != 0 && status != SUCCESS)
4717 spin_lock_irqsave(&phba->hbalock, flags);
4718 /* driver queued commands are in process of being flushed */
4719 if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) {
4720 spin_unlock_irqrestore(&phba->hbalock, flags);
4721 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4722 "3168 SCSI Layer abort requested I/O has been "
4723 "flushed by LLD.\n");
4727 lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble;
4728 if (!lpfc_cmd || !lpfc_cmd->pCmd) {
4729 spin_unlock_irqrestore(&phba->hbalock, flags);
4730 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4731 "2873 SCSI Layer I/O Abort Request IO CMPL Status "
4732 "x%x ID %d LUN %llu\n",
4733 SUCCESS, cmnd->device->id, cmnd->device->lun);
4737 iocb = &lpfc_cmd->cur_iocbq;
4738 /* the command is in process of being cancelled */
4739 if (!(iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ)) {
4740 spin_unlock_irqrestore(&phba->hbalock, flags);
4741 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4742 "3169 SCSI Layer abort requested I/O has been "
4743 "cancelled by LLD.\n");
4747 * If pCmd field of the corresponding lpfc_scsi_buf structure
4748 * points to a different SCSI command, then the driver has
4749 * already completed this command, but the midlayer did not
4750 * see the completion before the eh fired. Just return SUCCESS.
4752 if (lpfc_cmd->pCmd != cmnd) {
4753 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4754 "3170 SCSI Layer abort requested I/O has been "
4755 "completed by LLD.\n");
4759 BUG_ON(iocb->context1 != lpfc_cmd);
4761 /* abort issued in recovery is still in progress */
4762 if (iocb->iocb_flag & LPFC_DRIVER_ABORTED) {
4763 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4764 "3389 SCSI Layer I/O Abort Request is pending\n");
4765 spin_unlock_irqrestore(&phba->hbalock, flags);
4769 abtsiocb = __lpfc_sli_get_iocbq(phba);
4770 if (abtsiocb == NULL) {
4775 /* Indicate the IO is being aborted by the driver. */
4776 iocb->iocb_flag |= LPFC_DRIVER_ABORTED;
4779 * The scsi command can not be in txq and it is in flight because the
4780 * pCmd is still pointig at the SCSI command we have to abort. There
4781 * is no need to search the txcmplq. Just send an abort to the FW.
4785 icmd = &abtsiocb->iocb;
4786 icmd->un.acxri.abortType = ABORT_TYPE_ABTS;
4787 icmd->un.acxri.abortContextTag = cmd->ulpContext;
4788 if (phba->sli_rev == LPFC_SLI_REV4)
4789 icmd->un.acxri.abortIoTag = iocb->sli4_xritag;
4791 icmd->un.acxri.abortIoTag = cmd->ulpIoTag;
4794 icmd->ulpClass = cmd->ulpClass;
4796 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
4797 abtsiocb->fcp_wqidx = iocb->fcp_wqidx;
4798 abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
4799 if (iocb->iocb_flag & LPFC_IO_FOF)
4800 abtsiocb->iocb_flag |= LPFC_IO_FOF;
4802 if (lpfc_is_link_up(phba))
4803 icmd->ulpCommand = CMD_ABORT_XRI_CN;
4805 icmd->ulpCommand = CMD_CLOSE_XRI_CN;
4807 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
4808 abtsiocb->vport = vport;
4809 if (phba->sli_rev == LPFC_SLI_REV4) {
4810 ring_number = MAX_SLI3_CONFIGURED_RINGS + iocb->fcp_wqidx;
4811 pring_s4 = &phba->sli.ring[ring_number];
4812 /* Note: both hbalock and ring_lock must be set here */
4813 spin_lock_irqsave(&pring_s4->ring_lock, iflags);
4814 ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno,
4816 spin_unlock_irqrestore(&pring_s4->ring_lock, iflags);
4818 ret_val = __lpfc_sli_issue_iocb(phba, LPFC_FCP_RING,
4821 /* no longer need the lock after this point */
4822 spin_unlock_irqrestore(&phba->hbalock, flags);
4825 if (ret_val == IOCB_ERROR) {
4826 lpfc_sli_release_iocbq(phba, abtsiocb);
4831 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
4832 lpfc_sli_handle_fast_ring_event(phba,
4833 &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
4836 lpfc_cmd->waitq = &waitq;
4837 /* Wait for abort to complete */
4838 wait_event_timeout(waitq,
4839 (lpfc_cmd->pCmd != cmnd),
4840 msecs_to_jiffies(2*vport->cfg_devloss_tmo*1000));
4842 spin_lock_irqsave(shost->host_lock, flags);
4843 lpfc_cmd->waitq = NULL;
4844 spin_unlock_irqrestore(shost->host_lock, flags);
4846 if (lpfc_cmd->pCmd == cmnd) {
4848 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
4849 "0748 abort handler timed out waiting "
4850 "for abortng I/O (xri:x%x) to complete: "
4851 "ret %#x, ID %d, LUN %llu\n",
4852 iocb->sli4_xritag, ret,
4853 cmnd->device->id, cmnd->device->lun);
4858 spin_unlock_irqrestore(&phba->hbalock, flags);
4860 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4861 "0749 SCSI Layer I/O Abort Request Status x%x ID %d "
4862 "LUN %llu\n", ret, cmnd->device->id,
4868 lpfc_taskmgmt_name(uint8_t task_mgmt_cmd)
4870 switch (task_mgmt_cmd) {
4871 case FCP_ABORT_TASK_SET:
4872 return "ABORT_TASK_SET";
4873 case FCP_CLEAR_TASK_SET:
4874 return "FCP_CLEAR_TASK_SET";
4876 return "FCP_BUS_RESET";
4878 return "FCP_LUN_RESET";
4879 case FCP_TARGET_RESET:
4880 return "FCP_TARGET_RESET";
4882 return "FCP_CLEAR_ACA";
4883 case FCP_TERMINATE_TASK:
4884 return "FCP_TERMINATE_TASK";
4892 * lpfc_check_fcp_rsp - check the returned fcp_rsp to see if task failed
4893 * @vport: The virtual port for which this call is being executed.
4894 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
4896 * This routine checks the FCP RSP INFO to see if the tsk mgmt command succeded
4903 lpfc_check_fcp_rsp(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd)
4905 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
4908 uint8_t rsp_info_code;
4913 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4914 "0703 fcp_rsp is missing\n");
4916 rsp_info = fcprsp->rspStatus2;
4917 rsp_len = be32_to_cpu(fcprsp->rspRspLen);
4918 rsp_info_code = fcprsp->rspInfo3;
4921 lpfc_printf_vlog(vport, KERN_INFO,
4923 "0706 fcp_rsp valid 0x%x,"
4924 " rsp len=%d code 0x%x\n",
4926 rsp_len, rsp_info_code);
4928 if ((fcprsp->rspStatus2&RSP_LEN_VALID) && (rsp_len == 8)) {
4929 switch (rsp_info_code) {
4930 case RSP_NO_FAILURE:
4931 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4932 "0715 Task Mgmt No Failure\n");
4935 case RSP_TM_NOT_SUPPORTED: /* TM rejected */
4936 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4937 "0716 Task Mgmt Target "
4940 case RSP_TM_NOT_COMPLETED: /* TM failed */
4941 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4942 "0717 Task Mgmt Target "
4945 case RSP_TM_INVALID_LU: /* TM to invalid LU! */
4946 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4947 "0718 Task Mgmt to invalid "
4958 * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler
4959 * @vport: The virtual port for which this call is being executed.
4960 * @rdata: Pointer to remote port local data
4961 * @tgt_id: Target ID of remote device.
4962 * @lun_id: Lun number for the TMF
4963 * @task_mgmt_cmd: type of TMF to send
4965 * This routine builds and sends a TMF (SCSI Task Mgmt Function) to
4973 lpfc_send_taskmgmt(struct lpfc_vport *vport, struct lpfc_rport_data *rdata,
4974 unsigned tgt_id, uint64_t lun_id,
4975 uint8_t task_mgmt_cmd)
4977 struct lpfc_hba *phba = vport->phba;
4978 struct lpfc_scsi_buf *lpfc_cmd;
4979 struct lpfc_iocbq *iocbq;
4980 struct lpfc_iocbq *iocbqrsp;
4981 struct lpfc_nodelist *pnode = rdata->pnode;
4985 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
4988 lpfc_cmd = lpfc_get_scsi_buf(phba, rdata->pnode);
4989 if (lpfc_cmd == NULL)
4991 lpfc_cmd->timeout = phba->cfg_task_mgmt_tmo;
4992 lpfc_cmd->rdata = rdata;
4994 status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun_id,
4997 lpfc_release_scsi_buf(phba, lpfc_cmd);
5001 iocbq = &lpfc_cmd->cur_iocbq;
5002 iocbqrsp = lpfc_sli_get_iocbq(phba);
5003 if (iocbqrsp == NULL) {
5004 lpfc_release_scsi_buf(phba, lpfc_cmd);
5007 iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
5009 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
5010 "0702 Issue %s to TGT %d LUN %llu "
5011 "rpi x%x nlp_flag x%x Data: x%x x%x\n",
5012 lpfc_taskmgmt_name(task_mgmt_cmd), tgt_id, lun_id,
5013 pnode->nlp_rpi, pnode->nlp_flag, iocbq->sli4_xritag,
5016 status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING,
5017 iocbq, iocbqrsp, lpfc_cmd->timeout);
5018 if ((status != IOCB_SUCCESS) ||
5019 (iocbqrsp->iocb.ulpStatus != IOSTAT_SUCCESS)) {
5020 if (status != IOCB_SUCCESS ||
5021 iocbqrsp->iocb.ulpStatus != IOSTAT_FCP_RSP_ERROR)
5022 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5023 "0727 TMF %s to TGT %d LUN %llu "
5024 "failed (%d, %d) iocb_flag x%x\n",
5025 lpfc_taskmgmt_name(task_mgmt_cmd),
5027 iocbqrsp->iocb.ulpStatus,
5028 iocbqrsp->iocb.un.ulpWord[4],
5030 /* if ulpStatus != IOCB_SUCCESS, then status == IOCB_SUCCESS */
5031 if (status == IOCB_SUCCESS) {
5032 if (iocbqrsp->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
5033 /* Something in the FCP_RSP was invalid.
5034 * Check conditions */
5035 ret = lpfc_check_fcp_rsp(vport, lpfc_cmd);
5038 } else if (status == IOCB_TIMEDOUT) {
5039 ret = TIMEOUT_ERROR;
5046 lpfc_sli_release_iocbq(phba, iocbqrsp);
5048 if (ret != TIMEOUT_ERROR)
5049 lpfc_release_scsi_buf(phba, lpfc_cmd);
5055 * lpfc_chk_tgt_mapped -
5056 * @vport: The virtual port to check on
5057 * @cmnd: Pointer to scsi_cmnd data structure.
5059 * This routine delays until the scsi target (aka rport) for the
5060 * command exists (is present and logged in) or we declare it non-existent.
5067 lpfc_chk_tgt_mapped(struct lpfc_vport *vport, struct scsi_cmnd *cmnd)
5069 struct lpfc_rport_data *rdata;
5070 struct lpfc_nodelist *pnode;
5071 unsigned long later;
5073 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
5075 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
5076 "0797 Tgt Map rport failure: rdata x%p\n", rdata);
5079 pnode = rdata->pnode;
5081 * If target is not in a MAPPED state, delay until
5082 * target is rediscovered or devloss timeout expires.
5084 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
5085 while (time_after(later, jiffies)) {
5086 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
5088 if (pnode->nlp_state == NLP_STE_MAPPED_NODE)
5090 schedule_timeout_uninterruptible(msecs_to_jiffies(500));
5091 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
5094 pnode = rdata->pnode;
5096 if (!pnode || !NLP_CHK_NODE_ACT(pnode) ||
5097 (pnode->nlp_state != NLP_STE_MAPPED_NODE))
5103 * lpfc_reset_flush_io_context -
5104 * @vport: The virtual port (scsi_host) for the flush context
5105 * @tgt_id: If aborting by Target contect - specifies the target id
5106 * @lun_id: If aborting by Lun context - specifies the lun id
5107 * @context: specifies the context level to flush at.
5109 * After a reset condition via TMF, we need to flush orphaned i/o
5110 * contexts from the adapter. This routine aborts any contexts
5111 * outstanding, then waits for their completions. The wait is
5112 * bounded by devloss_tmo though.
5119 lpfc_reset_flush_io_context(struct lpfc_vport *vport, uint16_t tgt_id,
5120 uint64_t lun_id, lpfc_ctx_cmd context)
5122 struct lpfc_hba *phba = vport->phba;
5123 unsigned long later;
5126 cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context);
5128 lpfc_sli_abort_taskmgmt(vport,
5129 &phba->sli.ring[phba->sli.fcp_ring],
5130 tgt_id, lun_id, context);
5131 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
5132 while (time_after(later, jiffies) && cnt) {
5133 schedule_timeout_uninterruptible(msecs_to_jiffies(20));
5134 cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context);
5137 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5138 "0724 I/O flush failure for context %s : cnt x%x\n",
5139 ((context == LPFC_CTX_LUN) ? "LUN" :
5140 ((context == LPFC_CTX_TGT) ? "TGT" :
5141 ((context == LPFC_CTX_HOST) ? "HOST" : "Unknown"))),
5149 * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point
5150 * @cmnd: Pointer to scsi_cmnd data structure.
5152 * This routine does a device reset by sending a LUN_RESET task management
5160 lpfc_device_reset_handler(struct scsi_cmnd *cmnd)
5162 struct Scsi_Host *shost = cmnd->device->host;
5163 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5164 struct lpfc_rport_data *rdata;
5165 struct lpfc_nodelist *pnode;
5166 unsigned tgt_id = cmnd->device->id;
5167 uint64_t lun_id = cmnd->device->lun;
5168 struct lpfc_scsi_event_header scsi_event;
5171 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
5172 if (!rdata || !rdata->pnode) {
5173 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5174 "0798 Device Reset rport failure: rdata x%p\n",
5178 pnode = rdata->pnode;
5179 status = fc_block_scsi_eh(cmnd);
5180 if (status != 0 && status != SUCCESS)
5183 status = lpfc_chk_tgt_mapped(vport, cmnd);
5184 if (status == FAILED) {
5185 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5186 "0721 Device Reset rport failure: rdata x%p\n", rdata);
5190 scsi_event.event_type = FC_REG_SCSI_EVENT;
5191 scsi_event.subcategory = LPFC_EVENT_LUNRESET;
5192 scsi_event.lun = lun_id;
5193 memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name));
5194 memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name));
5196 fc_host_post_vendor_event(shost, fc_get_event_number(),
5197 sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
5199 status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id,
5202 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5203 "0713 SCSI layer issued Device Reset (%d, %llu) "
5204 "return x%x\n", tgt_id, lun_id, status);
5207 * We have to clean up i/o as : they may be orphaned by the TMF;
5208 * or if the TMF failed, they may be in an indeterminate state.
5210 * We will report success if all the i/o aborts successfully.
5212 if (status == SUCCESS)
5213 status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
5220 * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point
5221 * @cmnd: Pointer to scsi_cmnd data structure.
5223 * This routine does a target reset by sending a TARGET_RESET task management
5231 lpfc_target_reset_handler(struct scsi_cmnd *cmnd)
5233 struct Scsi_Host *shost = cmnd->device->host;
5234 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5235 struct lpfc_rport_data *rdata;
5236 struct lpfc_nodelist *pnode;
5237 unsigned tgt_id = cmnd->device->id;
5238 uint64_t lun_id = cmnd->device->lun;
5239 struct lpfc_scsi_event_header scsi_event;
5242 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
5244 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5245 "0799 Target Reset rport failure: rdata x%p\n", rdata);
5248 pnode = rdata->pnode;
5249 status = fc_block_scsi_eh(cmnd);
5250 if (status != 0 && status != SUCCESS)
5253 status = lpfc_chk_tgt_mapped(vport, cmnd);
5254 if (status == FAILED) {
5255 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5256 "0722 Target Reset rport failure: rdata x%p\n", rdata);
5258 spin_lock_irq(shost->host_lock);
5259 pnode->nlp_flag &= ~NLP_NPR_ADISC;
5260 pnode->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
5261 spin_unlock_irq(shost->host_lock);
5263 lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
5265 return FAST_IO_FAIL;
5268 scsi_event.event_type = FC_REG_SCSI_EVENT;
5269 scsi_event.subcategory = LPFC_EVENT_TGTRESET;
5271 memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name));
5272 memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name));
5274 fc_host_post_vendor_event(shost, fc_get_event_number(),
5275 sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
5277 status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id,
5280 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5281 "0723 SCSI layer issued Target Reset (%d, %llu) "
5282 "return x%x\n", tgt_id, lun_id, status);
5285 * We have to clean up i/o as : they may be orphaned by the TMF;
5286 * or if the TMF failed, they may be in an indeterminate state.
5288 * We will report success if all the i/o aborts successfully.
5290 if (status == SUCCESS)
5291 status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
5297 * lpfc_bus_reset_handler - scsi_host_template eh_bus_reset_handler entry point
5298 * @cmnd: Pointer to scsi_cmnd data structure.
5300 * This routine does target reset to all targets on @cmnd->device->host.
5301 * This emulates Parallel SCSI Bus Reset Semantics.
5308 lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
5310 struct Scsi_Host *shost = cmnd->device->host;
5311 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5312 struct lpfc_nodelist *ndlp = NULL;
5313 struct lpfc_scsi_event_header scsi_event;
5315 int ret = SUCCESS, status, i;
5317 scsi_event.event_type = FC_REG_SCSI_EVENT;
5318 scsi_event.subcategory = LPFC_EVENT_BUSRESET;
5320 memcpy(scsi_event.wwpn, &vport->fc_portname, sizeof(struct lpfc_name));
5321 memcpy(scsi_event.wwnn, &vport->fc_nodename, sizeof(struct lpfc_name));
5323 fc_host_post_vendor_event(shost, fc_get_event_number(),
5324 sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
5326 status = fc_block_scsi_eh(cmnd);
5327 if (status != 0 && status != SUCCESS)
5331 * Since the driver manages a single bus device, reset all
5332 * targets known to the driver. Should any target reset
5333 * fail, this routine returns failure to the midlayer.
5335 for (i = 0; i < LPFC_MAX_TARGET; i++) {
5336 /* Search for mapped node by target ID */
5338 spin_lock_irq(shost->host_lock);
5339 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5340 if (!NLP_CHK_NODE_ACT(ndlp))
5342 if (vport->phba->cfg_fcp2_no_tgt_reset &&
5343 (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE))
5345 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
5346 ndlp->nlp_sid == i &&
5352 spin_unlock_irq(shost->host_lock);
5356 status = lpfc_send_taskmgmt(vport, ndlp->rport->dd_data,
5357 i, 0, FCP_TARGET_RESET);
5359 if (status != SUCCESS) {
5360 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5361 "0700 Bus Reset on target %d failed\n",
5367 * We have to clean up i/o as : they may be orphaned by the TMFs
5368 * above; or if any of the TMFs failed, they may be in an
5369 * indeterminate state.
5370 * We will report success if all the i/o aborts successfully.
5373 status = lpfc_reset_flush_io_context(vport, 0, 0, LPFC_CTX_HOST);
5374 if (status != SUCCESS)
5377 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5378 "0714 SCSI layer issued Bus Reset Data: x%x\n", ret);
5383 * lpfc_host_reset_handler - scsi_host_template eh_host_reset_handler entry pt
5384 * @cmnd: Pointer to scsi_cmnd data structure.
5386 * This routine does host reset to the adaptor port. It brings the HBA
5387 * offline, performs a board restart, and then brings the board back online.
5388 * The lpfc_offline calls lpfc_sli_hba_down which will abort and local
5389 * reject all outstanding SCSI commands to the host and error returned
5390 * back to SCSI mid-level. As this will be SCSI mid-level's last resort
5391 * of error handling, it will only return error if resetting of the adapter
5392 * is not successful; in all other cases, will return success.
5399 lpfc_host_reset_handler(struct scsi_cmnd *cmnd)
5401 struct Scsi_Host *shost = cmnd->device->host;
5402 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5403 struct lpfc_hba *phba = vport->phba;
5404 int rc, ret = SUCCESS;
5406 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5407 "3172 SCSI layer issued Host Reset Data:\n");
5409 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
5411 rc = lpfc_sli_brdrestart(phba);
5414 rc = lpfc_online(phba);
5417 lpfc_unblock_mgmt_io(phba);
5419 if (ret == FAILED) {
5420 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5421 "3323 Failed host reset, bring it offline\n");
5422 lpfc_sli4_offline_eratt(phba);
5428 * lpfc_slave_alloc - scsi_host_template slave_alloc entry point
5429 * @sdev: Pointer to scsi_device.
5431 * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's
5432 * globally available list of scsi buffers. This routine also makes sure scsi
5433 * buffer is not allocated more than HBA limit conveyed to midlayer. This list
5434 * of scsi buffer exists for the lifetime of the driver.
5441 lpfc_slave_alloc(struct scsi_device *sdev)
5443 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
5444 struct lpfc_hba *phba = vport->phba;
5445 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
5447 uint32_t num_to_alloc = 0;
5448 int num_allocated = 0;
5450 struct lpfc_device_data *device_data;
5451 unsigned long flags;
5452 struct lpfc_name target_wwpn;
5454 if (!rport || fc_remote_port_chkready(rport))
5457 if (phba->cfg_fof) {
5460 * Check to see if the device data structure for the lun
5461 * exists. If not, create one.
5464 u64_to_wwn(rport->port_name, target_wwpn.u.wwn);
5465 spin_lock_irqsave(&phba->devicelock, flags);
5466 device_data = __lpfc_get_device_data(phba,
5468 &vport->fc_portname,
5472 spin_unlock_irqrestore(&phba->devicelock, flags);
5473 device_data = lpfc_create_device_data(phba,
5474 &vport->fc_portname,
5479 spin_lock_irqsave(&phba->devicelock, flags);
5480 list_add_tail(&device_data->listentry, &phba->luns);
5482 device_data->rport_data = rport->dd_data;
5483 device_data->available = true;
5484 spin_unlock_irqrestore(&phba->devicelock, flags);
5485 sdev->hostdata = device_data;
5487 sdev->hostdata = rport->dd_data;
5489 sdev_cnt = atomic_inc_return(&phba->sdev_cnt);
5492 * Populate the cmds_per_lun count scsi_bufs into this host's globally
5493 * available list of scsi buffers. Don't allocate more than the
5494 * HBA limit conveyed to the midlayer via the host structure. The
5495 * formula accounts for the lun_queue_depth + error handlers + 1
5496 * extra. This list of scsi bufs exists for the lifetime of the driver.
5498 total = phba->total_scsi_bufs;
5499 num_to_alloc = vport->cfg_lun_queue_depth + 2;
5501 /* If allocated buffers are enough do nothing */
5502 if ((sdev_cnt * (vport->cfg_lun_queue_depth + 2)) < total)
5505 /* Allow some exchanges to be available always to complete discovery */
5506 if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
5507 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
5508 "0704 At limitation of %d preallocated "
5509 "command buffers\n", total);
5511 /* Allow some exchanges to be available always to complete discovery */
5512 } else if (total + num_to_alloc >
5513 phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
5514 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
5515 "0705 Allocation request of %d "
5516 "command buffers will exceed max of %d. "
5517 "Reducing allocation request to %d.\n",
5518 num_to_alloc, phba->cfg_hba_queue_depth,
5519 (phba->cfg_hba_queue_depth - total));
5520 num_to_alloc = phba->cfg_hba_queue_depth - total;
5522 num_allocated = lpfc_new_scsi_buf(vport, num_to_alloc);
5523 if (num_to_alloc != num_allocated) {
5524 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5525 "0708 Allocation request of %d "
5526 "command buffers did not succeed. "
5527 "Allocated %d buffers.\n",
5528 num_to_alloc, num_allocated);
5530 if (num_allocated > 0)
5531 phba->total_scsi_bufs += num_allocated;
5536 * lpfc_slave_configure - scsi_host_template slave_configure entry point
5537 * @sdev: Pointer to scsi_device.
5539 * This routine configures following items
5540 * - Tag command queuing support for @sdev if supported.
5541 * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set.
5547 lpfc_slave_configure(struct scsi_device *sdev)
5549 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
5550 struct lpfc_hba *phba = vport->phba;
5552 scsi_change_queue_depth(sdev, vport->cfg_lun_queue_depth);
5554 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
5555 lpfc_sli_handle_fast_ring_event(phba,
5556 &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
5557 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
5558 lpfc_poll_rearm_timer(phba);
5565 * lpfc_slave_destroy - slave_destroy entry point of SHT data structure
5566 * @sdev: Pointer to scsi_device.
5568 * This routine sets @sdev hostatdata filed to null.
5571 lpfc_slave_destroy(struct scsi_device *sdev)
5573 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
5574 struct lpfc_hba *phba = vport->phba;
5575 unsigned long flags;
5576 struct lpfc_device_data *device_data = sdev->hostdata;
5578 atomic_dec(&phba->sdev_cnt);
5579 if ((phba->cfg_fof) && (device_data)) {
5580 spin_lock_irqsave(&phba->devicelock, flags);
5581 device_data->available = false;
5582 if (!device_data->oas_enabled)
5583 lpfc_delete_device_data(phba, device_data);
5584 spin_unlock_irqrestore(&phba->devicelock, flags);
5586 sdev->hostdata = NULL;
5591 * lpfc_create_device_data - creates and initializes device data structure for OAS
5592 * @pha: Pointer to host bus adapter structure.
5593 * @vport_wwpn: Pointer to vport's wwpn information
5594 * @target_wwpn: Pointer to target's wwpn information
5595 * @lun: Lun on target
5596 * @atomic_create: Flag to indicate if memory should be allocated using the
5597 * GFP_ATOMIC flag or not.
5599 * This routine creates a device data structure which will contain identifying
5600 * information for the device (host wwpn, target wwpn, lun), state of OAS,
5601 * whether or not the corresponding lun is available by the system,
5602 * and pointer to the rport data.
5606 * Pointer to lpfc_device_data - Success
5608 struct lpfc_device_data*
5609 lpfc_create_device_data(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn,
5610 struct lpfc_name *target_wwpn, uint64_t lun,
5614 struct lpfc_device_data *lun_info;
5617 if (unlikely(!phba) || !vport_wwpn || !target_wwpn ||
5621 /* Attempt to create the device data to contain lun info */
5624 memory_flags = GFP_ATOMIC;
5626 memory_flags = GFP_KERNEL;
5627 lun_info = mempool_alloc(phba->device_data_mem_pool, memory_flags);
5630 INIT_LIST_HEAD(&lun_info->listentry);
5631 lun_info->rport_data = NULL;
5632 memcpy(&lun_info->device_id.vport_wwpn, vport_wwpn,
5633 sizeof(struct lpfc_name));
5634 memcpy(&lun_info->device_id.target_wwpn, target_wwpn,
5635 sizeof(struct lpfc_name));
5636 lun_info->device_id.lun = lun;
5637 lun_info->oas_enabled = false;
5638 lun_info->available = false;
5643 * lpfc_delete_device_data - frees a device data structure for OAS
5644 * @pha: Pointer to host bus adapter structure.
5645 * @lun_info: Pointer to device data structure to free.
5647 * This routine frees the previously allocated device data structure passed.
5651 lpfc_delete_device_data(struct lpfc_hba *phba,
5652 struct lpfc_device_data *lun_info)
5655 if (unlikely(!phba) || !lun_info ||
5659 if (!list_empty(&lun_info->listentry))
5660 list_del(&lun_info->listentry);
5661 mempool_free(lun_info, phba->device_data_mem_pool);
5666 * __lpfc_get_device_data - returns the device data for the specified lun
5667 * @pha: Pointer to host bus adapter structure.
5668 * @list: Point to list to search.
5669 * @vport_wwpn: Pointer to vport's wwpn information
5670 * @target_wwpn: Pointer to target's wwpn information
5671 * @lun: Lun on target
5673 * This routine searches the list passed for the specified lun's device data.
5674 * This function does not hold locks, it is the responsibility of the caller
5675 * to ensure the proper lock is held before calling the function.
5679 * Pointer to lpfc_device_data - Success
5681 struct lpfc_device_data*
5682 __lpfc_get_device_data(struct lpfc_hba *phba, struct list_head *list,
5683 struct lpfc_name *vport_wwpn,
5684 struct lpfc_name *target_wwpn, uint64_t lun)
5687 struct lpfc_device_data *lun_info;
5689 if (unlikely(!phba) || !list || !vport_wwpn || !target_wwpn ||
5693 /* Check to see if the lun is already enabled for OAS. */
5695 list_for_each_entry(lun_info, list, listentry) {
5696 if ((memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn,
5697 sizeof(struct lpfc_name)) == 0) &&
5698 (memcmp(&lun_info->device_id.target_wwpn, target_wwpn,
5699 sizeof(struct lpfc_name)) == 0) &&
5700 (lun_info->device_id.lun == lun))
5708 * lpfc_find_next_oas_lun - searches for the next oas lun
5709 * @pha: Pointer to host bus adapter structure.
5710 * @vport_wwpn: Pointer to vport's wwpn information
5711 * @target_wwpn: Pointer to target's wwpn information
5712 * @starting_lun: Pointer to the lun to start searching for
5713 * @found_vport_wwpn: Pointer to the found lun's vport wwpn information
5714 * @found_target_wwpn: Pointer to the found lun's target wwpn information
5715 * @found_lun: Pointer to the found lun.
5716 * @found_lun_status: Pointer to status of the found lun.
5718 * This routine searches the luns list for the specified lun
5719 * or the first lun for the vport/target. If the vport wwpn contains
5720 * a zero value then a specific vport is not specified. In this case
5721 * any vport which contains the lun will be considered a match. If the
5722 * target wwpn contains a zero value then a specific target is not specified.
5723 * In this case any target which contains the lun will be considered a
5724 * match. If the lun is found, the lun, vport wwpn, target wwpn and lun status
5725 * are returned. The function will also return the next lun if available.
5726 * If the next lun is not found, starting_lun parameter will be set to
5734 lpfc_find_next_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn,
5735 struct lpfc_name *target_wwpn, uint64_t *starting_lun,
5736 struct lpfc_name *found_vport_wwpn,
5737 struct lpfc_name *found_target_wwpn,
5738 uint64_t *found_lun,
5739 uint32_t *found_lun_status)
5742 unsigned long flags;
5743 struct lpfc_device_data *lun_info;
5744 struct lpfc_device_id *device_id;
5748 if (unlikely(!phba) || !vport_wwpn || !target_wwpn ||
5749 !starting_lun || !found_vport_wwpn ||
5750 !found_target_wwpn || !found_lun || !found_lun_status ||
5751 (*starting_lun == NO_MORE_OAS_LUN) ||
5755 lun = *starting_lun;
5756 *found_lun = NO_MORE_OAS_LUN;
5757 *starting_lun = NO_MORE_OAS_LUN;
5759 /* Search for lun or the lun closet in value */
5761 spin_lock_irqsave(&phba->devicelock, flags);
5762 list_for_each_entry(lun_info, &phba->luns, listentry) {
5763 if (((wwn_to_u64(vport_wwpn->u.wwn) == 0) ||
5764 (memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn,
5765 sizeof(struct lpfc_name)) == 0)) &&
5766 ((wwn_to_u64(target_wwpn->u.wwn) == 0) ||
5767 (memcmp(&lun_info->device_id.target_wwpn, target_wwpn,
5768 sizeof(struct lpfc_name)) == 0)) &&
5769 (lun_info->oas_enabled)) {
5770 device_id = &lun_info->device_id;
5772 ((lun == FIND_FIRST_OAS_LUN) ||
5773 (device_id->lun == lun))) {
5774 *found_lun = device_id->lun;
5775 memcpy(found_vport_wwpn,
5776 &device_id->vport_wwpn,
5777 sizeof(struct lpfc_name));
5778 memcpy(found_target_wwpn,
5779 &device_id->target_wwpn,
5780 sizeof(struct lpfc_name));
5781 if (lun_info->available)
5783 OAS_LUN_STATUS_EXISTS;
5785 *found_lun_status = 0;
5786 if (phba->cfg_oas_flags & OAS_FIND_ANY_VPORT)
5787 memset(vport_wwpn, 0x0,
5788 sizeof(struct lpfc_name));
5789 if (phba->cfg_oas_flags & OAS_FIND_ANY_TARGET)
5790 memset(target_wwpn, 0x0,
5791 sizeof(struct lpfc_name));
5794 *starting_lun = device_id->lun;
5795 memcpy(vport_wwpn, &device_id->vport_wwpn,
5796 sizeof(struct lpfc_name));
5797 memcpy(target_wwpn, &device_id->target_wwpn,
5798 sizeof(struct lpfc_name));
5803 spin_unlock_irqrestore(&phba->devicelock, flags);
5808 * lpfc_enable_oas_lun - enables a lun for OAS operations
5809 * @pha: Pointer to host bus adapter structure.
5810 * @vport_wwpn: Pointer to vport's wwpn information
5811 * @target_wwpn: Pointer to target's wwpn information
5814 * This routine enables a lun for oas operations. The routines does so by
5815 * doing the following :
5817 * 1) Checks to see if the device data for the lun has been created.
5818 * 2) If found, sets the OAS enabled flag if not set and returns.
5819 * 3) Otherwise, creates a device data structure.
5820 * 4) If successfully created, indicates the device data is for an OAS lun,
5821 * indicates the lun is not available and add to the list of luns.
5828 lpfc_enable_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn,
5829 struct lpfc_name *target_wwpn, uint64_t lun)
5832 struct lpfc_device_data *lun_info;
5833 unsigned long flags;
5835 if (unlikely(!phba) || !vport_wwpn || !target_wwpn ||
5839 spin_lock_irqsave(&phba->devicelock, flags);
5841 /* Check to see if the device data for the lun has been created */
5842 lun_info = __lpfc_get_device_data(phba, &phba->luns, vport_wwpn,
5845 if (!lun_info->oas_enabled)
5846 lun_info->oas_enabled = true;
5847 spin_unlock_irqrestore(&phba->devicelock, flags);
5851 /* Create an lun info structure and add to list of luns */
5852 lun_info = lpfc_create_device_data(phba, vport_wwpn, target_wwpn, lun,
5855 lun_info->oas_enabled = true;
5856 lun_info->available = false;
5857 list_add_tail(&lun_info->listentry, &phba->luns);
5858 spin_unlock_irqrestore(&phba->devicelock, flags);
5861 spin_unlock_irqrestore(&phba->devicelock, flags);
5866 * lpfc_disable_oas_lun - disables a lun for OAS operations
5867 * @pha: Pointer to host bus adapter structure.
5868 * @vport_wwpn: Pointer to vport's wwpn information
5869 * @target_wwpn: Pointer to target's wwpn information
5872 * This routine disables a lun for oas operations. The routines does so by
5873 * doing the following :
5875 * 1) Checks to see if the device data for the lun is created.
5876 * 2) If present, clears the flag indicating this lun is for OAS.
5877 * 3) If the lun is not available by the system, the device data is
5885 lpfc_disable_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn,
5886 struct lpfc_name *target_wwpn, uint64_t lun)
5889 struct lpfc_device_data *lun_info;
5890 unsigned long flags;
5892 if (unlikely(!phba) || !vport_wwpn || !target_wwpn ||
5896 spin_lock_irqsave(&phba->devicelock, flags);
5898 /* Check to see if the lun is available. */
5899 lun_info = __lpfc_get_device_data(phba,
5900 &phba->luns, vport_wwpn,
5903 lun_info->oas_enabled = false;
5904 if (!lun_info->available)
5905 lpfc_delete_device_data(phba, lun_info);
5906 spin_unlock_irqrestore(&phba->devicelock, flags);
5910 spin_unlock_irqrestore(&phba->devicelock, flags);
5914 struct scsi_host_template lpfc_template_s3 = {
5915 .module = THIS_MODULE,
5916 .name = LPFC_DRIVER_NAME,
5918 .queuecommand = lpfc_queuecommand,
5919 .eh_abort_handler = lpfc_abort_handler,
5920 .eh_device_reset_handler = lpfc_device_reset_handler,
5921 .eh_target_reset_handler = lpfc_target_reset_handler,
5922 .eh_bus_reset_handler = lpfc_bus_reset_handler,
5923 .slave_alloc = lpfc_slave_alloc,
5924 .slave_configure = lpfc_slave_configure,
5925 .slave_destroy = lpfc_slave_destroy,
5926 .scan_finished = lpfc_scan_finished,
5928 .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
5929 .cmd_per_lun = LPFC_CMD_PER_LUN,
5930 .use_clustering = ENABLE_CLUSTERING,
5931 .shost_attrs = lpfc_hba_attrs,
5932 .max_sectors = 0xFFFF,
5933 .vendor_id = LPFC_NL_VENDOR_ID,
5934 .change_queue_depth = scsi_change_queue_depth,
5935 .track_queue_depth = 1,
5938 struct scsi_host_template lpfc_template = {
5939 .module = THIS_MODULE,
5940 .name = LPFC_DRIVER_NAME,
5942 .queuecommand = lpfc_queuecommand,
5943 .eh_abort_handler = lpfc_abort_handler,
5944 .eh_device_reset_handler = lpfc_device_reset_handler,
5945 .eh_target_reset_handler = lpfc_target_reset_handler,
5946 .eh_bus_reset_handler = lpfc_bus_reset_handler,
5947 .eh_host_reset_handler = lpfc_host_reset_handler,
5948 .slave_alloc = lpfc_slave_alloc,
5949 .slave_configure = lpfc_slave_configure,
5950 .slave_destroy = lpfc_slave_destroy,
5951 .scan_finished = lpfc_scan_finished,
5953 .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
5954 .cmd_per_lun = LPFC_CMD_PER_LUN,
5955 .use_clustering = ENABLE_CLUSTERING,
5956 .shost_attrs = lpfc_hba_attrs,
5957 .max_sectors = 0xFFFF,
5958 .vendor_id = LPFC_NL_VENDOR_ID,
5959 .change_queue_depth = scsi_change_queue_depth,
5960 .track_queue_depth = 1,
5963 struct scsi_host_template lpfc_vport_template = {
5964 .module = THIS_MODULE,
5965 .name = LPFC_DRIVER_NAME,
5967 .queuecommand = lpfc_queuecommand,
5968 .eh_abort_handler = lpfc_abort_handler,
5969 .eh_device_reset_handler = lpfc_device_reset_handler,
5970 .eh_target_reset_handler = lpfc_target_reset_handler,
5971 .eh_bus_reset_handler = lpfc_bus_reset_handler,
5972 .slave_alloc = lpfc_slave_alloc,
5973 .slave_configure = lpfc_slave_configure,
5974 .slave_destroy = lpfc_slave_destroy,
5975 .scan_finished = lpfc_scan_finished,
5977 .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
5978 .cmd_per_lun = LPFC_CMD_PER_LUN,
5979 .use_clustering = ENABLE_CLUSTERING,
5980 .shost_attrs = lpfc_vport_attrs,
5981 .max_sectors = 0xFFFF,
5982 .change_queue_depth = scsi_change_queue_depth,
5983 .track_queue_depth = 1,