1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2014 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_change_queue_depth - Alter scsi device queue depth
247 * @sdev: Pointer the scsi device on which to change the queue depth.
248 * @qdepth: New queue depth to set the sdev to.
249 * @reason: The reason for the queue depth change.
251 * This function is called by the midlayer and the LLD to alter the queue
252 * depth for a scsi device. This function sets the queue depth to the new
253 * value and sends an event out to log the queue depth change.
256 lpfc_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
258 scsi_adjust_queue_depth(sdev, qdepth);
259 return sdev->queue_depth;
263 * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread
264 * @phba: The Hba for which this call is being executed.
266 * This routine is called when there is resource error in driver or firmware.
267 * This routine posts WORKER_RAMP_DOWN_QUEUE event for @phba. This routine
268 * posts at most 1 event each second. This routine wakes up worker thread of
269 * @phba to process WORKER_RAM_DOWN_EVENT event.
271 * This routine should be called with no lock held.
274 lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
278 unsigned long expires;
280 spin_lock_irqsave(&phba->hbalock, flags);
281 atomic_inc(&phba->num_rsrc_err);
282 phba->last_rsrc_error_time = jiffies;
284 expires = phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL;
285 if (time_after(expires, jiffies)) {
286 spin_unlock_irqrestore(&phba->hbalock, flags);
290 phba->last_ramp_down_time = jiffies;
292 spin_unlock_irqrestore(&phba->hbalock, flags);
294 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
295 evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE;
297 phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE;
298 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
301 lpfc_worker_wake_up(phba);
306 * lpfc_ramp_down_queue_handler - WORKER_RAMP_DOWN_QUEUE event handler
307 * @phba: The Hba for which this call is being executed.
309 * This routine is called to process WORKER_RAMP_DOWN_QUEUE event for worker
310 * thread.This routine reduces queue depth for all scsi device on each vport
311 * associated with @phba.
314 lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
316 struct lpfc_vport **vports;
317 struct Scsi_Host *shost;
318 struct scsi_device *sdev;
319 unsigned long new_queue_depth;
320 unsigned long num_rsrc_err, num_cmd_success;
323 num_rsrc_err = atomic_read(&phba->num_rsrc_err);
324 num_cmd_success = atomic_read(&phba->num_cmd_success);
327 * The error and success command counters are global per
328 * driver instance. If another handler has already
329 * operated on this error event, just exit.
331 if (num_rsrc_err == 0)
334 vports = lpfc_create_vport_work_array(phba);
336 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
337 shost = lpfc_shost_from_vport(vports[i]);
338 shost_for_each_device(sdev, shost) {
340 sdev->queue_depth * num_rsrc_err /
341 (num_rsrc_err + num_cmd_success);
342 if (!new_queue_depth)
343 new_queue_depth = sdev->queue_depth - 1;
345 new_queue_depth = sdev->queue_depth -
347 lpfc_change_queue_depth(sdev, new_queue_depth,
348 SCSI_QDEPTH_DEFAULT);
351 lpfc_destroy_vport_work_array(phba, vports);
352 atomic_set(&phba->num_rsrc_err, 0);
353 atomic_set(&phba->num_cmd_success, 0);
357 * lpfc_scsi_dev_block - set all scsi hosts to block state
358 * @phba: Pointer to HBA context object.
360 * This function walks vport list and set each SCSI host to block state
361 * by invoking fc_remote_port_delete() routine. This function is invoked
362 * with EEH when device's PCI slot has been permanently disabled.
365 lpfc_scsi_dev_block(struct lpfc_hba *phba)
367 struct lpfc_vport **vports;
368 struct Scsi_Host *shost;
369 struct scsi_device *sdev;
370 struct fc_rport *rport;
373 vports = lpfc_create_vport_work_array(phba);
375 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
376 shost = lpfc_shost_from_vport(vports[i]);
377 shost_for_each_device(sdev, shost) {
378 rport = starget_to_rport(scsi_target(sdev));
379 fc_remote_port_delete(rport);
382 lpfc_destroy_vport_work_array(phba, vports);
386 * lpfc_new_scsi_buf_s3 - Scsi buffer allocator for HBA with SLI3 IF spec
387 * @vport: The virtual port for which this call being executed.
388 * @num_to_allocate: The requested number of buffers to allocate.
390 * This routine allocates a scsi buffer for device with SLI-3 interface spec,
391 * the scsi buffer contains all the necessary information needed to initiate
392 * a SCSI I/O. The non-DMAable buffer region contains information to build
393 * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP,
394 * and the initial BPL. In addition to allocating memory, the FCP CMND and
395 * FCP RSP BDEs are setup in the BPL and the BPL BDE is setup in the IOCB.
398 * int - number of scsi buffers that were allocated.
399 * 0 = failure, less than num_to_alloc is a partial failure.
402 lpfc_new_scsi_buf_s3(struct lpfc_vport *vport, int num_to_alloc)
404 struct lpfc_hba *phba = vport->phba;
405 struct lpfc_scsi_buf *psb;
406 struct ulp_bde64 *bpl;
408 dma_addr_t pdma_phys_fcp_cmd;
409 dma_addr_t pdma_phys_fcp_rsp;
410 dma_addr_t pdma_phys_bpl;
414 bpl_size = phba->cfg_sg_dma_buf_size -
415 (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp));
417 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
418 "9067 ALLOC %d scsi_bufs: %d (%d + %d + %d)\n",
419 num_to_alloc, phba->cfg_sg_dma_buf_size,
420 (int)sizeof(struct fcp_cmnd),
421 (int)sizeof(struct fcp_rsp), bpl_size);
423 for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
424 psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL);
429 * Get memory from the pci pool to map the virt space to pci
430 * bus space for an I/O. The DMA buffer includes space for the
431 * struct fcp_cmnd, struct fcp_rsp and the number of bde's
432 * necessary to support the sg_tablesize.
434 psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool,
435 GFP_KERNEL, &psb->dma_handle);
441 /* Initialize virtual ptrs to dma_buf region. */
442 memset(psb->data, 0, phba->cfg_sg_dma_buf_size);
444 /* Allocate iotag for psb->cur_iocbq. */
445 iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq);
447 pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
448 psb->data, psb->dma_handle);
452 psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP;
454 psb->fcp_cmnd = psb->data;
455 psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd);
456 psb->fcp_bpl = psb->data + sizeof(struct fcp_cmnd) +
457 sizeof(struct fcp_rsp);
459 /* Initialize local short-hand pointers. */
461 pdma_phys_fcp_cmd = psb->dma_handle;
462 pdma_phys_fcp_rsp = psb->dma_handle + sizeof(struct fcp_cmnd);
463 pdma_phys_bpl = psb->dma_handle + sizeof(struct fcp_cmnd) +
464 sizeof(struct fcp_rsp);
467 * The first two bdes are the FCP_CMD and FCP_RSP. The balance
468 * are sg list bdes. Initialize the first two and leave the
469 * rest for queuecommand.
471 bpl[0].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd));
472 bpl[0].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd));
473 bpl[0].tus.f.bdeSize = sizeof(struct fcp_cmnd);
474 bpl[0].tus.f.bdeFlags = BUFF_TYPE_BDE_64;
475 bpl[0].tus.w = le32_to_cpu(bpl[0].tus.w);
477 /* Setup the physical region for the FCP RSP */
478 bpl[1].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp));
479 bpl[1].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp));
480 bpl[1].tus.f.bdeSize = sizeof(struct fcp_rsp);
481 bpl[1].tus.f.bdeFlags = BUFF_TYPE_BDE_64;
482 bpl[1].tus.w = le32_to_cpu(bpl[1].tus.w);
485 * Since the IOCB for the FCP I/O is built into this
486 * lpfc_scsi_buf, initialize it with all known data now.
488 iocb = &psb->cur_iocbq.iocb;
489 iocb->un.fcpi64.bdl.ulpIoTag32 = 0;
490 if ((phba->sli_rev == 3) &&
491 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) {
492 /* fill in immediate fcp command BDE */
493 iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_IMMED;
494 iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd);
495 iocb->un.fcpi64.bdl.addrLow = offsetof(IOCB_t,
497 iocb->un.fcpi64.bdl.addrHigh = 0;
498 iocb->ulpBdeCount = 0;
500 /* fill in response BDE */
501 iocb->unsli3.fcp_ext.rbde.tus.f.bdeFlags =
503 iocb->unsli3.fcp_ext.rbde.tus.f.bdeSize =
504 sizeof(struct fcp_rsp);
505 iocb->unsli3.fcp_ext.rbde.addrLow =
506 putPaddrLow(pdma_phys_fcp_rsp);
507 iocb->unsli3.fcp_ext.rbde.addrHigh =
508 putPaddrHigh(pdma_phys_fcp_rsp);
510 iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
511 iocb->un.fcpi64.bdl.bdeSize =
512 (2 * sizeof(struct ulp_bde64));
513 iocb->un.fcpi64.bdl.addrLow =
514 putPaddrLow(pdma_phys_bpl);
515 iocb->un.fcpi64.bdl.addrHigh =
516 putPaddrHigh(pdma_phys_bpl);
517 iocb->ulpBdeCount = 1;
520 iocb->ulpClass = CLASS3;
521 psb->status = IOSTAT_SUCCESS;
522 /* Put it back into the SCSI buffer list */
523 psb->cur_iocbq.context1 = psb;
524 lpfc_release_scsi_buf_s3(phba, psb);
532 * lpfc_sli4_vport_delete_fcp_xri_aborted -Remove all ndlp references for vport
533 * @vport: pointer to lpfc vport data structure.
535 * This routine is invoked by the vport cleanup for deletions and the cleanup
536 * for an ndlp on removal.
539 lpfc_sli4_vport_delete_fcp_xri_aborted(struct lpfc_vport *vport)
541 struct lpfc_hba *phba = vport->phba;
542 struct lpfc_scsi_buf *psb, *next_psb;
543 unsigned long iflag = 0;
545 spin_lock_irqsave(&phba->hbalock, iflag);
546 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
547 list_for_each_entry_safe(psb, next_psb,
548 &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) {
549 if (psb->rdata && psb->rdata->pnode
550 && psb->rdata->pnode->vport == vport)
553 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
554 spin_unlock_irqrestore(&phba->hbalock, iflag);
558 * lpfc_sli4_fcp_xri_aborted - Fast-path process of fcp xri abort
559 * @phba: pointer to lpfc hba data structure.
560 * @axri: pointer to the fcp xri abort wcqe structure.
562 * This routine is invoked by the worker thread to process a SLI4 fast-path
566 lpfc_sli4_fcp_xri_aborted(struct lpfc_hba *phba,
567 struct sli4_wcqe_xri_aborted *axri)
569 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
570 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
571 struct lpfc_scsi_buf *psb, *next_psb;
572 unsigned long iflag = 0;
573 struct lpfc_iocbq *iocbq;
575 struct lpfc_nodelist *ndlp;
577 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
579 spin_lock_irqsave(&phba->hbalock, iflag);
580 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
581 list_for_each_entry_safe(psb, next_psb,
582 &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) {
583 if (psb->cur_iocbq.sli4_xritag == xri) {
584 list_del(&psb->list);
586 psb->status = IOSTAT_SUCCESS;
588 &phba->sli4_hba.abts_scsi_buf_list_lock);
589 if (psb->rdata && psb->rdata->pnode)
590 ndlp = psb->rdata->pnode;
594 rrq_empty = list_empty(&phba->active_rrq_list);
595 spin_unlock_irqrestore(&phba->hbalock, iflag);
597 lpfc_set_rrq_active(phba, ndlp,
598 psb->cur_iocbq.sli4_lxritag, rxid, 1);
599 lpfc_sli4_abts_err_handler(phba, ndlp, axri);
601 lpfc_release_scsi_buf_s4(phba, psb);
603 lpfc_worker_wake_up(phba);
607 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
608 for (i = 1; i <= phba->sli.last_iotag; i++) {
609 iocbq = phba->sli.iocbq_lookup[i];
611 if (!(iocbq->iocb_flag & LPFC_IO_FCP) ||
612 (iocbq->iocb_flag & LPFC_IO_LIBDFC))
614 if (iocbq->sli4_xritag != xri)
616 psb = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
618 spin_unlock_irqrestore(&phba->hbalock, iflag);
619 if (!list_empty(&pring->txq))
620 lpfc_worker_wake_up(phba);
624 spin_unlock_irqrestore(&phba->hbalock, iflag);
628 * lpfc_sli4_post_scsi_sgl_list - Psot blocks of scsi buffer sgls from a list
629 * @phba: pointer to lpfc hba data structure.
630 * @post_sblist: pointer to the scsi buffer list.
632 * This routine walks a list of scsi buffers that was passed in. It attempts
633 * to construct blocks of scsi buffer sgls which contains contiguous xris and
634 * uses the non-embedded SGL block post mailbox commands to post to the port.
635 * For single SCSI buffer sgl with non-contiguous xri, if any, it shall use
636 * embedded SGL post mailbox command for posting. The @post_sblist passed in
637 * must be local list, thus no lock is needed when manipulate the list.
639 * Returns: 0 = failure, non-zero number of successfully posted buffers.
642 lpfc_sli4_post_scsi_sgl_list(struct lpfc_hba *phba,
643 struct list_head *post_sblist, int sb_count)
645 struct lpfc_scsi_buf *psb, *psb_next;
646 int status, sgl_size;
647 int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0;
648 dma_addr_t pdma_phys_bpl1;
649 int last_xritag = NO_XRI;
650 LIST_HEAD(prep_sblist);
651 LIST_HEAD(blck_sblist);
652 LIST_HEAD(scsi_sblist);
658 sgl_size = phba->cfg_sg_dma_buf_size -
659 (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp));
661 list_for_each_entry_safe(psb, psb_next, post_sblist, list) {
662 list_del_init(&psb->list);
664 if ((last_xritag != NO_XRI) &&
665 (psb->cur_iocbq.sli4_xritag != last_xritag + 1)) {
666 /* a hole in xri block, form a sgl posting block */
667 list_splice_init(&prep_sblist, &blck_sblist);
668 post_cnt = block_cnt - 1;
669 /* prepare list for next posting block */
670 list_add_tail(&psb->list, &prep_sblist);
673 /* prepare list for next posting block */
674 list_add_tail(&psb->list, &prep_sblist);
675 /* enough sgls for non-embed sgl mbox command */
676 if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
677 list_splice_init(&prep_sblist, &blck_sblist);
678 post_cnt = block_cnt;
683 last_xritag = psb->cur_iocbq.sli4_xritag;
685 /* end of repost sgl list condition for SCSI buffers */
686 if (num_posting == sb_count) {
688 /* last sgl posting block */
689 list_splice_init(&prep_sblist, &blck_sblist);
690 post_cnt = block_cnt;
691 } else if (block_cnt == 1) {
692 /* last single sgl with non-contiguous xri */
693 if (sgl_size > SGL_PAGE_SIZE)
694 pdma_phys_bpl1 = psb->dma_phys_bpl +
698 status = lpfc_sli4_post_sgl(phba,
701 psb->cur_iocbq.sli4_xritag);
703 /* failure, put on abort scsi list */
706 /* success, put on SCSI buffer list */
708 psb->status = IOSTAT_SUCCESS;
711 /* success, put on SCSI buffer sgl list */
712 list_add_tail(&psb->list, &scsi_sblist);
716 /* continue until a nembed page worth of sgls */
720 /* post block of SCSI buffer list sgls */
721 status = lpfc_sli4_post_scsi_sgl_block(phba, &blck_sblist,
724 /* don't reset xirtag due to hole in xri block */
726 last_xritag = NO_XRI;
728 /* reset SCSI buffer post count for next round of posting */
731 /* put posted SCSI buffer-sgl posted on SCSI buffer sgl list */
732 while (!list_empty(&blck_sblist)) {
733 list_remove_head(&blck_sblist, psb,
734 struct lpfc_scsi_buf, list);
736 /* failure, put on abort scsi list */
739 /* success, put on SCSI buffer list */
741 psb->status = IOSTAT_SUCCESS;
744 list_add_tail(&psb->list, &scsi_sblist);
747 /* Push SCSI buffers with sgl posted to the availble list */
748 while (!list_empty(&scsi_sblist)) {
749 list_remove_head(&scsi_sblist, psb,
750 struct lpfc_scsi_buf, list);
751 lpfc_release_scsi_buf_s4(phba, psb);
757 * lpfc_sli4_repost_scsi_sgl_list - Repsot all the allocated scsi buffer sgls
758 * @phba: pointer to lpfc hba data structure.
760 * This routine walks the list of scsi buffers that have been allocated and
761 * repost them to the port by using SGL block post. This is needed after a
762 * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine
763 * is responsible for moving all scsi buffers on the lpfc_abts_scsi_sgl_list
764 * to the lpfc_scsi_buf_list. If the repost fails, reject all scsi buffers.
766 * Returns: 0 = success, non-zero failure.
769 lpfc_sli4_repost_scsi_sgl_list(struct lpfc_hba *phba)
771 LIST_HEAD(post_sblist);
772 int num_posted, rc = 0;
774 /* get all SCSI buffers need to repost to a local list */
775 spin_lock_irq(&phba->scsi_buf_list_get_lock);
776 spin_lock(&phba->scsi_buf_list_put_lock);
777 list_splice_init(&phba->lpfc_scsi_buf_list_get, &post_sblist);
778 list_splice(&phba->lpfc_scsi_buf_list_put, &post_sblist);
779 spin_unlock(&phba->scsi_buf_list_put_lock);
780 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
782 /* post the list of scsi buffer sgls to port if available */
783 if (!list_empty(&post_sblist)) {
784 num_posted = lpfc_sli4_post_scsi_sgl_list(phba, &post_sblist,
785 phba->sli4_hba.scsi_xri_cnt);
786 /* failed to post any scsi buffer, return error */
794 * lpfc_new_scsi_buf_s4 - Scsi buffer allocator for HBA with SLI4 IF spec
795 * @vport: The virtual port for which this call being executed.
796 * @num_to_allocate: The requested number of buffers to allocate.
798 * This routine allocates scsi buffers for device with SLI-4 interface spec,
799 * the scsi buffer contains all the necessary information needed to initiate
800 * a SCSI I/O. After allocating up to @num_to_allocate SCSI buffers and put
801 * them on a list, it post them to the port by using SGL block post.
804 * int - number of scsi buffers that were allocated and posted.
805 * 0 = failure, less than num_to_alloc is a partial failure.
808 lpfc_new_scsi_buf_s4(struct lpfc_vport *vport, int num_to_alloc)
810 struct lpfc_hba *phba = vport->phba;
811 struct lpfc_scsi_buf *psb;
812 struct sli4_sge *sgl;
814 dma_addr_t pdma_phys_fcp_cmd;
815 dma_addr_t pdma_phys_fcp_rsp;
816 dma_addr_t pdma_phys_bpl;
817 uint16_t iotag, lxri = 0;
818 int bcnt, num_posted, sgl_size;
819 LIST_HEAD(prep_sblist);
820 LIST_HEAD(post_sblist);
821 LIST_HEAD(scsi_sblist);
823 sgl_size = phba->cfg_sg_dma_buf_size -
824 (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp));
826 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
827 "9068 ALLOC %d scsi_bufs: %d (%d + %d + %d)\n",
828 num_to_alloc, phba->cfg_sg_dma_buf_size, sgl_size,
829 (int)sizeof(struct fcp_cmnd),
830 (int)sizeof(struct fcp_rsp));
832 for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
833 psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL);
837 * Get memory from the pci pool to map the virt space to
838 * pci bus space for an I/O. The DMA buffer includes space
839 * for the struct fcp_cmnd, struct fcp_rsp and the number
840 * of bde's necessary to support the sg_tablesize.
842 psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool,
843 GFP_KERNEL, &psb->dma_handle);
848 memset(psb->data, 0, phba->cfg_sg_dma_buf_size);
851 * 4K Page alignment is CRITICAL to BlockGuard, double check
854 if (phba->cfg_enable_bg && (((unsigned long)(psb->data) &
855 (unsigned long)(SLI4_PAGE_SIZE - 1)) != 0)) {
856 pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
857 psb->data, psb->dma_handle);
863 lxri = lpfc_sli4_next_xritag(phba);
864 if (lxri == NO_XRI) {
865 pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
866 psb->data, psb->dma_handle);
871 /* Allocate iotag for psb->cur_iocbq. */
872 iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq);
874 pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
875 psb->data, psb->dma_handle);
877 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
878 "3368 Failed to allocated IOTAG for"
879 " XRI:0x%x\n", lxri);
880 lpfc_sli4_free_xri(phba, lxri);
883 psb->cur_iocbq.sli4_lxritag = lxri;
884 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
885 psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP;
886 psb->fcp_bpl = psb->data;
887 psb->fcp_cmnd = (psb->data + sgl_size);
888 psb->fcp_rsp = (struct fcp_rsp *)((uint8_t *)psb->fcp_cmnd +
889 sizeof(struct fcp_cmnd));
891 /* Initialize local short-hand pointers. */
892 sgl = (struct sli4_sge *)psb->fcp_bpl;
893 pdma_phys_bpl = psb->dma_handle;
894 pdma_phys_fcp_cmd = (psb->dma_handle + sgl_size);
895 pdma_phys_fcp_rsp = pdma_phys_fcp_cmd + sizeof(struct fcp_cmnd);
898 * The first two bdes are the FCP_CMD and FCP_RSP.
899 * The balance are sg list bdes. Initialize the
900 * first two and leave the rest for queuecommand.
902 sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd));
903 sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd));
904 sgl->word2 = le32_to_cpu(sgl->word2);
905 bf_set(lpfc_sli4_sge_last, sgl, 0);
906 sgl->word2 = cpu_to_le32(sgl->word2);
907 sgl->sge_len = cpu_to_le32(sizeof(struct fcp_cmnd));
910 /* Setup the physical region for the FCP RSP */
911 sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp));
912 sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp));
913 sgl->word2 = le32_to_cpu(sgl->word2);
914 bf_set(lpfc_sli4_sge_last, sgl, 1);
915 sgl->word2 = cpu_to_le32(sgl->word2);
916 sgl->sge_len = cpu_to_le32(sizeof(struct fcp_rsp));
919 * Since the IOCB for the FCP I/O is built into this
920 * lpfc_scsi_buf, initialize it with all known data now.
922 iocb = &psb->cur_iocbq.iocb;
923 iocb->un.fcpi64.bdl.ulpIoTag32 = 0;
924 iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_64;
925 /* setting the BLP size to 2 * sizeof BDE may not be correct.
926 * We are setting the bpl to point to out sgl. An sgl's
927 * entries are 16 bytes, a bpl entries are 12 bytes.
929 iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd);
930 iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys_fcp_cmd);
931 iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys_fcp_cmd);
932 iocb->ulpBdeCount = 1;
934 iocb->ulpClass = CLASS3;
935 psb->cur_iocbq.context1 = psb;
936 psb->dma_phys_bpl = pdma_phys_bpl;
938 /* add the scsi buffer to a post list */
939 list_add_tail(&psb->list, &post_sblist);
940 spin_lock_irq(&phba->scsi_buf_list_get_lock);
941 phba->sli4_hba.scsi_xri_cnt++;
942 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
944 lpfc_printf_log(phba, KERN_INFO, LOG_BG,
945 "3021 Allocate %d out of %d requested new SCSI "
946 "buffers\n", bcnt, num_to_alloc);
948 /* post the list of scsi buffer sgls to port if available */
949 if (!list_empty(&post_sblist))
950 num_posted = lpfc_sli4_post_scsi_sgl_list(phba,
959 * lpfc_new_scsi_buf - Wrapper funciton for scsi buffer allocator
960 * @vport: The virtual port for which this call being executed.
961 * @num_to_allocate: The requested number of buffers to allocate.
963 * This routine wraps the actual SCSI buffer allocator function pointer from
964 * the lpfc_hba struct.
967 * int - number of scsi buffers that were allocated.
968 * 0 = failure, less than num_to_alloc is a partial failure.
971 lpfc_new_scsi_buf(struct lpfc_vport *vport, int num_to_alloc)
973 return vport->phba->lpfc_new_scsi_buf(vport, num_to_alloc);
977 * lpfc_get_scsi_buf_s3 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
978 * @phba: The HBA for which this call is being executed.
980 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
981 * and returns to caller.
985 * Pointer to lpfc_scsi_buf - Success
987 static struct lpfc_scsi_buf*
988 lpfc_get_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
990 struct lpfc_scsi_buf * lpfc_cmd = NULL;
991 struct list_head *scsi_buf_list_get = &phba->lpfc_scsi_buf_list_get;
992 unsigned long iflag = 0;
994 spin_lock_irqsave(&phba->scsi_buf_list_get_lock, iflag);
995 list_remove_head(scsi_buf_list_get, lpfc_cmd, struct lpfc_scsi_buf,
998 spin_lock(&phba->scsi_buf_list_put_lock);
999 list_splice(&phba->lpfc_scsi_buf_list_put,
1000 &phba->lpfc_scsi_buf_list_get);
1001 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
1002 list_remove_head(scsi_buf_list_get, lpfc_cmd,
1003 struct lpfc_scsi_buf, list);
1004 spin_unlock(&phba->scsi_buf_list_put_lock);
1006 spin_unlock_irqrestore(&phba->scsi_buf_list_get_lock, iflag);
1010 * lpfc_get_scsi_buf_s4 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
1011 * @phba: The HBA for which this call is being executed.
1013 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
1014 * and returns to caller.
1018 * Pointer to lpfc_scsi_buf - Success
1020 static struct lpfc_scsi_buf*
1021 lpfc_get_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1023 struct lpfc_scsi_buf *lpfc_cmd, *lpfc_cmd_next;
1024 unsigned long iflag = 0;
1027 spin_lock_irqsave(&phba->scsi_buf_list_get_lock, iflag);
1028 list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next,
1029 &phba->lpfc_scsi_buf_list_get, list) {
1030 if (lpfc_test_rrq_active(phba, ndlp,
1031 lpfc_cmd->cur_iocbq.sli4_lxritag))
1033 list_del(&lpfc_cmd->list);
1038 spin_lock(&phba->scsi_buf_list_put_lock);
1039 list_splice(&phba->lpfc_scsi_buf_list_put,
1040 &phba->lpfc_scsi_buf_list_get);
1041 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
1042 spin_unlock(&phba->scsi_buf_list_put_lock);
1043 list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next,
1044 &phba->lpfc_scsi_buf_list_get, list) {
1045 if (lpfc_test_rrq_active(
1046 phba, ndlp, lpfc_cmd->cur_iocbq.sli4_lxritag))
1048 list_del(&lpfc_cmd->list);
1053 spin_unlock_irqrestore(&phba->scsi_buf_list_get_lock, iflag);
1059 * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
1060 * @phba: The HBA for which this call is being executed.
1062 * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
1063 * and returns to caller.
1067 * Pointer to lpfc_scsi_buf - Success
1069 static struct lpfc_scsi_buf*
1070 lpfc_get_scsi_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1072 return phba->lpfc_get_scsi_buf(phba, ndlp);
1076 * lpfc_release_scsi_buf - Return a scsi buffer back to hba scsi buf list
1077 * @phba: The Hba for which this call is being executed.
1078 * @psb: The scsi buffer which is being released.
1080 * This routine releases @psb scsi buffer by adding it to tail of @phba
1081 * lpfc_scsi_buf_list list.
1084 lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
1086 unsigned long iflag = 0;
1089 psb->nonsg_phys = 0;
1090 psb->prot_seg_cnt = 0;
1092 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
1094 psb->cur_iocbq.iocb_flag = LPFC_IO_FCP;
1095 list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list_put);
1096 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
1100 * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list.
1101 * @phba: The Hba for which this call is being executed.
1102 * @psb: The scsi buffer which is being released.
1104 * This routine releases @psb scsi buffer by adding it to tail of @phba
1105 * lpfc_scsi_buf_list list. For SLI4 XRI's are tied to the scsi buffer
1106 * and cannot be reused for at least RA_TOV amount of time if it was
1110 lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
1112 unsigned long iflag = 0;
1115 psb->nonsg_phys = 0;
1116 psb->prot_seg_cnt = 0;
1118 if (psb->exch_busy) {
1119 spin_lock_irqsave(&phba->sli4_hba.abts_scsi_buf_list_lock,
1122 list_add_tail(&psb->list,
1123 &phba->sli4_hba.lpfc_abts_scsi_buf_list);
1124 spin_unlock_irqrestore(&phba->sli4_hba.abts_scsi_buf_list_lock,
1128 psb->cur_iocbq.iocb_flag = LPFC_IO_FCP;
1129 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
1130 list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list_put);
1131 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
1136 * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list.
1137 * @phba: The Hba for which this call is being executed.
1138 * @psb: The scsi buffer which is being released.
1140 * This routine releases @psb scsi buffer by adding it to tail of @phba
1141 * lpfc_scsi_buf_list list.
1144 lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
1147 phba->lpfc_release_scsi_buf(phba, psb);
1151 * lpfc_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
1152 * @phba: The Hba for which this call is being executed.
1153 * @lpfc_cmd: The scsi buffer which is going to be mapped.
1155 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
1156 * field of @lpfc_cmd for device with SLI-3 interface spec. This routine scans
1157 * through sg elements and format the bdea. This routine also initializes all
1158 * IOCB fields which are dependent on scsi command request buffer.
1165 lpfc_scsi_prep_dma_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
1167 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
1168 struct scatterlist *sgel = NULL;
1169 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
1170 struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl;
1171 struct lpfc_iocbq *iocbq = &lpfc_cmd->cur_iocbq;
1172 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
1173 struct ulp_bde64 *data_bde = iocb_cmd->unsli3.fcp_ext.dbde;
1174 dma_addr_t physaddr;
1175 uint32_t num_bde = 0;
1176 int nseg, datadir = scsi_cmnd->sc_data_direction;
1179 * There are three possibilities here - use scatter-gather segment, use
1180 * the single mapping, or neither. Start the lpfc command prep by
1181 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
1185 if (scsi_sg_count(scsi_cmnd)) {
1187 * The driver stores the segment count returned from pci_map_sg
1188 * because this a count of dma-mappings used to map the use_sg
1189 * pages. They are not guaranteed to be the same for those
1190 * architectures that implement an IOMMU.
1193 nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd),
1194 scsi_sg_count(scsi_cmnd), datadir);
1195 if (unlikely(!nseg))
1198 lpfc_cmd->seg_cnt = nseg;
1199 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
1200 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1201 "9064 BLKGRD: %s: Too many sg segments from "
1202 "dma_map_sg. Config %d, seg_cnt %d\n",
1203 __func__, phba->cfg_sg_seg_cnt,
1205 lpfc_cmd->seg_cnt = 0;
1206 scsi_dma_unmap(scsi_cmnd);
1211 * The driver established a maximum scatter-gather segment count
1212 * during probe that limits the number of sg elements in any
1213 * single scsi command. Just run through the seg_cnt and format
1215 * When using SLI-3 the driver will try to fit all the BDEs into
1216 * the IOCB. If it can't then the BDEs get added to a BPL as it
1217 * does for SLI-2 mode.
1219 scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) {
1220 physaddr = sg_dma_address(sgel);
1221 if (phba->sli_rev == 3 &&
1222 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
1223 !(iocbq->iocb_flag & DSS_SECURITY_OP) &&
1224 nseg <= LPFC_EXT_DATA_BDE_COUNT) {
1225 data_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1226 data_bde->tus.f.bdeSize = sg_dma_len(sgel);
1227 data_bde->addrLow = putPaddrLow(physaddr);
1228 data_bde->addrHigh = putPaddrHigh(physaddr);
1231 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1232 bpl->tus.f.bdeSize = sg_dma_len(sgel);
1233 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1235 le32_to_cpu(putPaddrLow(physaddr));
1237 le32_to_cpu(putPaddrHigh(physaddr));
1244 * Finish initializing those IOCB fields that are dependent on the
1245 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
1246 * explicitly reinitialized and for SLI-3 the extended bde count is
1247 * explicitly reinitialized since all iocb memory resources are reused.
1249 if (phba->sli_rev == 3 &&
1250 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
1251 !(iocbq->iocb_flag & DSS_SECURITY_OP)) {
1252 if (num_bde > LPFC_EXT_DATA_BDE_COUNT) {
1254 * The extended IOCB format can only fit 3 BDE or a BPL.
1255 * This I/O has more than 3 BDE so the 1st data bde will
1256 * be a BPL that is filled in here.
1258 physaddr = lpfc_cmd->dma_handle;
1259 data_bde->tus.f.bdeFlags = BUFF_TYPE_BLP_64;
1260 data_bde->tus.f.bdeSize = (num_bde *
1261 sizeof(struct ulp_bde64));
1262 physaddr += (sizeof(struct fcp_cmnd) +
1263 sizeof(struct fcp_rsp) +
1264 (2 * sizeof(struct ulp_bde64)));
1265 data_bde->addrHigh = putPaddrHigh(physaddr);
1266 data_bde->addrLow = putPaddrLow(physaddr);
1267 /* ebde count includes the response bde and data bpl */
1268 iocb_cmd->unsli3.fcp_ext.ebde_count = 2;
1270 /* ebde count includes the response bde and data bdes */
1271 iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1);
1274 iocb_cmd->un.fcpi64.bdl.bdeSize =
1275 ((num_bde + 2) * sizeof(struct ulp_bde64));
1276 iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1);
1278 fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd));
1281 * Due to difference in data length between DIF/non-DIF paths,
1282 * we need to set word 4 of IOCB here
1284 iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd);
1288 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1290 /* Return if if error injection is detected by Initiator */
1291 #define BG_ERR_INIT 0x1
1292 /* Return if if error injection is detected by Target */
1293 #define BG_ERR_TGT 0x2
1294 /* Return if if swapping CSUM<-->CRC is required for error injection */
1295 #define BG_ERR_SWAP 0x10
1296 /* Return if disabling Guard/Ref/App checking is required for error injection */
1297 #define BG_ERR_CHECK 0x20
1300 * lpfc_bg_err_inject - Determine if we should inject an error
1301 * @phba: The Hba for which this call is being executed.
1302 * @sc: The SCSI command to examine
1303 * @reftag: (out) BlockGuard reference tag for transmitted data
1304 * @apptag: (out) BlockGuard application tag for transmitted data
1305 * @new_guard (in) Value to replace CRC with if needed
1307 * Returns BG_ERR_* bit mask or 0 if request ignored
1310 lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1311 uint32_t *reftag, uint16_t *apptag, uint32_t new_guard)
1313 struct scatterlist *sgpe; /* s/g prot entry */
1314 struct scatterlist *sgde; /* s/g data entry */
1315 struct lpfc_scsi_buf *lpfc_cmd = NULL;
1316 struct scsi_dif_tuple *src = NULL;
1317 struct lpfc_nodelist *ndlp;
1318 struct lpfc_rport_data *rdata;
1319 uint32_t op = scsi_get_prot_op(sc);
1326 if (op == SCSI_PROT_NORMAL)
1329 sgpe = scsi_prot_sglist(sc);
1330 sgde = scsi_sglist(sc);
1331 lba = scsi_get_lba(sc);
1333 /* First check if we need to match the LBA */
1334 if (phba->lpfc_injerr_lba != LPFC_INJERR_LBA_OFF) {
1335 blksize = lpfc_cmd_blksize(sc);
1336 numblks = (scsi_bufflen(sc) + blksize - 1) / blksize;
1338 /* Make sure we have the right LBA if one is specified */
1339 if ((phba->lpfc_injerr_lba < lba) ||
1340 (phba->lpfc_injerr_lba >= (lba + numblks)))
1343 blockoff = phba->lpfc_injerr_lba - lba;
1344 numblks = sg_dma_len(sgpe) /
1345 sizeof(struct scsi_dif_tuple);
1346 if (numblks < blockoff)
1351 /* Next check if we need to match the remote NPortID or WWPN */
1352 rdata = lpfc_rport_data_from_scsi_device(sc->device);
1353 if (rdata && rdata->pnode) {
1354 ndlp = rdata->pnode;
1356 /* Make sure we have the right NPortID if one is specified */
1357 if (phba->lpfc_injerr_nportid &&
1358 (phba->lpfc_injerr_nportid != ndlp->nlp_DID))
1362 * Make sure we have the right WWPN if one is specified.
1363 * wwn[0] should be a non-zero NAA in a good WWPN.
1365 if (phba->lpfc_injerr_wwpn.u.wwn[0] &&
1366 (memcmp(&ndlp->nlp_portname, &phba->lpfc_injerr_wwpn,
1367 sizeof(struct lpfc_name)) != 0))
1371 /* Setup a ptr to the protection data if the SCSI host provides it */
1373 src = (struct scsi_dif_tuple *)sg_virt(sgpe);
1375 lpfc_cmd = (struct lpfc_scsi_buf *)sc->host_scribble;
1378 /* Should we change the Reference Tag */
1380 if (phba->lpfc_injerr_wref_cnt) {
1382 case SCSI_PROT_WRITE_PASS:
1385 * For WRITE_PASS, force the error
1386 * to be sent on the wire. It should
1387 * be detected by the Target.
1388 * If blockoff != 0 error will be
1389 * inserted in middle of the IO.
1392 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1393 "9076 BLKGRD: Injecting reftag error: "
1394 "write lba x%lx + x%x oldrefTag x%x\n",
1395 (unsigned long)lba, blockoff,
1396 be32_to_cpu(src->ref_tag));
1399 * Save the old ref_tag so we can
1400 * restore it on completion.
1403 lpfc_cmd->prot_data_type =
1405 lpfc_cmd->prot_data_segment =
1407 lpfc_cmd->prot_data =
1410 src->ref_tag = cpu_to_be32(0xDEADBEEF);
1411 phba->lpfc_injerr_wref_cnt--;
1412 if (phba->lpfc_injerr_wref_cnt == 0) {
1413 phba->lpfc_injerr_nportid = 0;
1414 phba->lpfc_injerr_lba =
1415 LPFC_INJERR_LBA_OFF;
1416 memset(&phba->lpfc_injerr_wwpn,
1417 0, sizeof(struct lpfc_name));
1419 rc = BG_ERR_TGT | BG_ERR_CHECK;
1424 case SCSI_PROT_WRITE_INSERT:
1426 * For WRITE_INSERT, force the error
1427 * to be sent on the wire. It should be
1428 * detected by the Target.
1430 /* DEADBEEF will be the reftag on the wire */
1431 *reftag = 0xDEADBEEF;
1432 phba->lpfc_injerr_wref_cnt--;
1433 if (phba->lpfc_injerr_wref_cnt == 0) {
1434 phba->lpfc_injerr_nportid = 0;
1435 phba->lpfc_injerr_lba =
1436 LPFC_INJERR_LBA_OFF;
1437 memset(&phba->lpfc_injerr_wwpn,
1438 0, sizeof(struct lpfc_name));
1440 rc = BG_ERR_TGT | BG_ERR_CHECK;
1442 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1443 "9078 BLKGRD: Injecting reftag error: "
1444 "write lba x%lx\n", (unsigned long)lba);
1446 case SCSI_PROT_WRITE_STRIP:
1448 * For WRITE_STRIP and WRITE_PASS,
1449 * force the error on data
1450 * being copied from SLI-Host to SLI-Port.
1452 *reftag = 0xDEADBEEF;
1453 phba->lpfc_injerr_wref_cnt--;
1454 if (phba->lpfc_injerr_wref_cnt == 0) {
1455 phba->lpfc_injerr_nportid = 0;
1456 phba->lpfc_injerr_lba =
1457 LPFC_INJERR_LBA_OFF;
1458 memset(&phba->lpfc_injerr_wwpn,
1459 0, sizeof(struct lpfc_name));
1463 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1464 "9077 BLKGRD: Injecting reftag error: "
1465 "write lba x%lx\n", (unsigned long)lba);
1469 if (phba->lpfc_injerr_rref_cnt) {
1471 case SCSI_PROT_READ_INSERT:
1472 case SCSI_PROT_READ_STRIP:
1473 case SCSI_PROT_READ_PASS:
1475 * For READ_STRIP and READ_PASS, force the
1476 * error on data being read off the wire. It
1477 * should force an IO error to the driver.
1479 *reftag = 0xDEADBEEF;
1480 phba->lpfc_injerr_rref_cnt--;
1481 if (phba->lpfc_injerr_rref_cnt == 0) {
1482 phba->lpfc_injerr_nportid = 0;
1483 phba->lpfc_injerr_lba =
1484 LPFC_INJERR_LBA_OFF;
1485 memset(&phba->lpfc_injerr_wwpn,
1486 0, sizeof(struct lpfc_name));
1490 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1491 "9079 BLKGRD: Injecting reftag error: "
1492 "read lba x%lx\n", (unsigned long)lba);
1498 /* Should we change the Application Tag */
1500 if (phba->lpfc_injerr_wapp_cnt) {
1502 case SCSI_PROT_WRITE_PASS:
1505 * For WRITE_PASS, force the error
1506 * to be sent on the wire. It should
1507 * be detected by the Target.
1508 * If blockoff != 0 error will be
1509 * inserted in middle of the IO.
1512 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1513 "9080 BLKGRD: Injecting apptag error: "
1514 "write lba x%lx + x%x oldappTag x%x\n",
1515 (unsigned long)lba, blockoff,
1516 be16_to_cpu(src->app_tag));
1519 * Save the old app_tag so we can
1520 * restore it on completion.
1523 lpfc_cmd->prot_data_type =
1525 lpfc_cmd->prot_data_segment =
1527 lpfc_cmd->prot_data =
1530 src->app_tag = cpu_to_be16(0xDEAD);
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;
1543 case SCSI_PROT_WRITE_INSERT:
1545 * For WRITE_INSERT, force the
1546 * error to be sent on the wire. It should be
1547 * detected by the Target.
1549 /* DEAD will be the apptag on the wire */
1551 phba->lpfc_injerr_wapp_cnt--;
1552 if (phba->lpfc_injerr_wapp_cnt == 0) {
1553 phba->lpfc_injerr_nportid = 0;
1554 phba->lpfc_injerr_lba =
1555 LPFC_INJERR_LBA_OFF;
1556 memset(&phba->lpfc_injerr_wwpn,
1557 0, sizeof(struct lpfc_name));
1559 rc = BG_ERR_TGT | BG_ERR_CHECK;
1561 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1562 "0813 BLKGRD: Injecting apptag error: "
1563 "write lba x%lx\n", (unsigned long)lba);
1565 case SCSI_PROT_WRITE_STRIP:
1567 * For WRITE_STRIP and WRITE_PASS,
1568 * force the error on data
1569 * being copied from SLI-Host to SLI-Port.
1572 phba->lpfc_injerr_wapp_cnt--;
1573 if (phba->lpfc_injerr_wapp_cnt == 0) {
1574 phba->lpfc_injerr_nportid = 0;
1575 phba->lpfc_injerr_lba =
1576 LPFC_INJERR_LBA_OFF;
1577 memset(&phba->lpfc_injerr_wwpn,
1578 0, sizeof(struct lpfc_name));
1582 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1583 "0812 BLKGRD: Injecting apptag error: "
1584 "write lba x%lx\n", (unsigned long)lba);
1588 if (phba->lpfc_injerr_rapp_cnt) {
1590 case SCSI_PROT_READ_INSERT:
1591 case SCSI_PROT_READ_STRIP:
1592 case SCSI_PROT_READ_PASS:
1594 * For READ_STRIP and READ_PASS, force the
1595 * error on data being read off the wire. It
1596 * should force an IO error to the driver.
1599 phba->lpfc_injerr_rapp_cnt--;
1600 if (phba->lpfc_injerr_rapp_cnt == 0) {
1601 phba->lpfc_injerr_nportid = 0;
1602 phba->lpfc_injerr_lba =
1603 LPFC_INJERR_LBA_OFF;
1604 memset(&phba->lpfc_injerr_wwpn,
1605 0, sizeof(struct lpfc_name));
1609 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1610 "0814 BLKGRD: Injecting apptag error: "
1611 "read lba x%lx\n", (unsigned long)lba);
1618 /* Should we change the Guard Tag */
1620 if (phba->lpfc_injerr_wgrd_cnt) {
1622 case SCSI_PROT_WRITE_PASS:
1626 case SCSI_PROT_WRITE_INSERT:
1628 * For WRITE_INSERT, force the
1629 * error to be sent on the wire. It should be
1630 * detected by the Target.
1632 phba->lpfc_injerr_wgrd_cnt--;
1633 if (phba->lpfc_injerr_wgrd_cnt == 0) {
1634 phba->lpfc_injerr_nportid = 0;
1635 phba->lpfc_injerr_lba =
1636 LPFC_INJERR_LBA_OFF;
1637 memset(&phba->lpfc_injerr_wwpn,
1638 0, sizeof(struct lpfc_name));
1641 rc |= BG_ERR_TGT | BG_ERR_SWAP;
1642 /* Signals the caller to swap CRC->CSUM */
1644 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1645 "0817 BLKGRD: Injecting guard error: "
1646 "write lba x%lx\n", (unsigned long)lba);
1648 case SCSI_PROT_WRITE_STRIP:
1650 * For WRITE_STRIP and WRITE_PASS,
1651 * force the error on data
1652 * being copied from SLI-Host to SLI-Port.
1654 phba->lpfc_injerr_wgrd_cnt--;
1655 if (phba->lpfc_injerr_wgrd_cnt == 0) {
1656 phba->lpfc_injerr_nportid = 0;
1657 phba->lpfc_injerr_lba =
1658 LPFC_INJERR_LBA_OFF;
1659 memset(&phba->lpfc_injerr_wwpn,
1660 0, sizeof(struct lpfc_name));
1663 rc = BG_ERR_INIT | BG_ERR_SWAP;
1664 /* Signals the caller to swap CRC->CSUM */
1666 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1667 "0816 BLKGRD: Injecting guard error: "
1668 "write lba x%lx\n", (unsigned long)lba);
1672 if (phba->lpfc_injerr_rgrd_cnt) {
1674 case SCSI_PROT_READ_INSERT:
1675 case SCSI_PROT_READ_STRIP:
1676 case SCSI_PROT_READ_PASS:
1678 * For READ_STRIP and READ_PASS, force the
1679 * error on data being read off the wire. It
1680 * should force an IO error to the driver.
1682 phba->lpfc_injerr_rgrd_cnt--;
1683 if (phba->lpfc_injerr_rgrd_cnt == 0) {
1684 phba->lpfc_injerr_nportid = 0;
1685 phba->lpfc_injerr_lba =
1686 LPFC_INJERR_LBA_OFF;
1687 memset(&phba->lpfc_injerr_wwpn,
1688 0, sizeof(struct lpfc_name));
1691 rc = BG_ERR_INIT | BG_ERR_SWAP;
1692 /* Signals the caller to swap CRC->CSUM */
1694 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1695 "0818 BLKGRD: Injecting guard error: "
1696 "read lba x%lx\n", (unsigned long)lba);
1706 * lpfc_sc_to_bg_opcodes - Determine the BlockGuard opcodes to be used with
1707 * the specified SCSI command.
1708 * @phba: The Hba for which this call is being executed.
1709 * @sc: The SCSI command to examine
1710 * @txopt: (out) BlockGuard operation for transmitted data
1711 * @rxopt: (out) BlockGuard operation for received data
1713 * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
1717 lpfc_sc_to_bg_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1718 uint8_t *txop, uint8_t *rxop)
1722 if (lpfc_cmd_guard_csum(sc)) {
1723 switch (scsi_get_prot_op(sc)) {
1724 case SCSI_PROT_READ_INSERT:
1725 case SCSI_PROT_WRITE_STRIP:
1726 *rxop = BG_OP_IN_NODIF_OUT_CSUM;
1727 *txop = BG_OP_IN_CSUM_OUT_NODIF;
1730 case SCSI_PROT_READ_STRIP:
1731 case SCSI_PROT_WRITE_INSERT:
1732 *rxop = BG_OP_IN_CRC_OUT_NODIF;
1733 *txop = BG_OP_IN_NODIF_OUT_CRC;
1736 case SCSI_PROT_READ_PASS:
1737 case SCSI_PROT_WRITE_PASS:
1738 *rxop = BG_OP_IN_CRC_OUT_CSUM;
1739 *txop = BG_OP_IN_CSUM_OUT_CRC;
1742 case SCSI_PROT_NORMAL:
1744 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1745 "9063 BLKGRD: Bad op/guard:%d/IP combination\n",
1746 scsi_get_prot_op(sc));
1752 switch (scsi_get_prot_op(sc)) {
1753 case SCSI_PROT_READ_STRIP:
1754 case SCSI_PROT_WRITE_INSERT:
1755 *rxop = BG_OP_IN_CRC_OUT_NODIF;
1756 *txop = BG_OP_IN_NODIF_OUT_CRC;
1759 case SCSI_PROT_READ_PASS:
1760 case SCSI_PROT_WRITE_PASS:
1761 *rxop = BG_OP_IN_CRC_OUT_CRC;
1762 *txop = BG_OP_IN_CRC_OUT_CRC;
1765 case SCSI_PROT_READ_INSERT:
1766 case SCSI_PROT_WRITE_STRIP:
1767 *rxop = BG_OP_IN_NODIF_OUT_CRC;
1768 *txop = BG_OP_IN_CRC_OUT_NODIF;
1771 case SCSI_PROT_NORMAL:
1773 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1774 "9075 BLKGRD: Bad op/guard:%d/CRC combination\n",
1775 scsi_get_prot_op(sc));
1784 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1786 * lpfc_bg_err_opcodes - reDetermine the BlockGuard opcodes to be used with
1787 * the specified SCSI command in order to force a guard tag error.
1788 * @phba: The Hba for which this call is being executed.
1789 * @sc: The SCSI command to examine
1790 * @txopt: (out) BlockGuard operation for transmitted data
1791 * @rxopt: (out) BlockGuard operation for received data
1793 * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
1797 lpfc_bg_err_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1798 uint8_t *txop, uint8_t *rxop)
1802 if (lpfc_cmd_guard_csum(sc)) {
1803 switch (scsi_get_prot_op(sc)) {
1804 case SCSI_PROT_READ_INSERT:
1805 case SCSI_PROT_WRITE_STRIP:
1806 *rxop = BG_OP_IN_NODIF_OUT_CRC;
1807 *txop = BG_OP_IN_CRC_OUT_NODIF;
1810 case SCSI_PROT_READ_STRIP:
1811 case SCSI_PROT_WRITE_INSERT:
1812 *rxop = BG_OP_IN_CSUM_OUT_NODIF;
1813 *txop = BG_OP_IN_NODIF_OUT_CSUM;
1816 case SCSI_PROT_READ_PASS:
1817 case SCSI_PROT_WRITE_PASS:
1818 *rxop = BG_OP_IN_CSUM_OUT_CRC;
1819 *txop = BG_OP_IN_CRC_OUT_CSUM;
1822 case SCSI_PROT_NORMAL:
1828 switch (scsi_get_prot_op(sc)) {
1829 case SCSI_PROT_READ_STRIP:
1830 case SCSI_PROT_WRITE_INSERT:
1831 *rxop = BG_OP_IN_CSUM_OUT_NODIF;
1832 *txop = BG_OP_IN_NODIF_OUT_CSUM;
1835 case SCSI_PROT_READ_PASS:
1836 case SCSI_PROT_WRITE_PASS:
1837 *rxop = BG_OP_IN_CSUM_OUT_CSUM;
1838 *txop = BG_OP_IN_CSUM_OUT_CSUM;
1841 case SCSI_PROT_READ_INSERT:
1842 case SCSI_PROT_WRITE_STRIP:
1843 *rxop = BG_OP_IN_NODIF_OUT_CSUM;
1844 *txop = BG_OP_IN_CSUM_OUT_NODIF;
1847 case SCSI_PROT_NORMAL:
1858 * lpfc_bg_setup_bpl - Setup BlockGuard BPL with no protection data
1859 * @phba: The Hba for which this call is being executed.
1860 * @sc: pointer to scsi command we're working on
1861 * @bpl: pointer to buffer list for protection groups
1862 * @datacnt: number of segments of data that have been dma mapped
1864 * This function sets up BPL buffer list for protection groups of
1865 * type LPFC_PG_TYPE_NO_DIF
1867 * This is usually used when the HBA is instructed to generate
1868 * DIFs and insert them into data stream (or strip DIF from
1869 * incoming data stream)
1871 * The buffer list consists of just one protection group described
1873 * +-------------------------+
1874 * start of prot group --> | PDE_5 |
1875 * +-------------------------+
1877 * +-------------------------+
1879 * +-------------------------+
1880 * |more Data BDE's ... (opt)|
1881 * +-------------------------+
1884 * Note: Data s/g buffers have been dma mapped
1886 * Returns the number of BDEs added to the BPL.
1889 lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1890 struct ulp_bde64 *bpl, int datasegcnt)
1892 struct scatterlist *sgde = NULL; /* s/g data entry */
1893 struct lpfc_pde5 *pde5 = NULL;
1894 struct lpfc_pde6 *pde6 = NULL;
1895 dma_addr_t physaddr;
1896 int i = 0, num_bde = 0, status;
1897 int datadir = sc->sc_data_direction;
1898 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1901 uint32_t checking = 1;
1906 status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
1910 /* extract some info from the scsi command for pde*/
1911 blksize = lpfc_cmd_blksize(sc);
1912 reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
1914 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1915 rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
1917 if (rc & BG_ERR_SWAP)
1918 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
1919 if (rc & BG_ERR_CHECK)
1924 /* setup PDE5 with what we have */
1925 pde5 = (struct lpfc_pde5 *) bpl;
1926 memset(pde5, 0, sizeof(struct lpfc_pde5));
1927 bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR);
1929 /* Endianness conversion if necessary for PDE5 */
1930 pde5->word0 = cpu_to_le32(pde5->word0);
1931 pde5->reftag = cpu_to_le32(reftag);
1933 /* advance bpl and increment bde count */
1936 pde6 = (struct lpfc_pde6 *) bpl;
1938 /* setup PDE6 with the rest of the info */
1939 memset(pde6, 0, sizeof(struct lpfc_pde6));
1940 bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR);
1941 bf_set(pde6_optx, pde6, txop);
1942 bf_set(pde6_oprx, pde6, rxop);
1945 * We only need to check the data on READs, for WRITEs
1946 * protection data is automatically generated, not checked.
1948 if (datadir == DMA_FROM_DEVICE) {
1949 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD))
1950 bf_set(pde6_ce, pde6, checking);
1952 bf_set(pde6_ce, pde6, 0);
1954 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF))
1955 bf_set(pde6_re, pde6, checking);
1957 bf_set(pde6_re, pde6, 0);
1959 bf_set(pde6_ai, pde6, 1);
1960 bf_set(pde6_ae, pde6, 0);
1961 bf_set(pde6_apptagval, pde6, 0);
1963 /* Endianness conversion if necessary for PDE6 */
1964 pde6->word0 = cpu_to_le32(pde6->word0);
1965 pde6->word1 = cpu_to_le32(pde6->word1);
1966 pde6->word2 = cpu_to_le32(pde6->word2);
1968 /* advance bpl and increment bde count */
1972 /* assumption: caller has already run dma_map_sg on command data */
1973 scsi_for_each_sg(sc, sgde, datasegcnt, i) {
1974 physaddr = sg_dma_address(sgde);
1975 bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr));
1976 bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
1977 bpl->tus.f.bdeSize = sg_dma_len(sgde);
1978 if (datadir == DMA_TO_DEVICE)
1979 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1981 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
1982 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1992 * lpfc_bg_setup_bpl_prot - Setup BlockGuard BPL with protection data
1993 * @phba: The Hba for which this call is being executed.
1994 * @sc: pointer to scsi command we're working on
1995 * @bpl: pointer to buffer list for protection groups
1996 * @datacnt: number of segments of data that have been dma mapped
1997 * @protcnt: number of segment of protection data that have been dma mapped
1999 * This function sets up BPL buffer list for protection groups of
2000 * type LPFC_PG_TYPE_DIF
2002 * This is usually used when DIFs are in their own buffers,
2003 * separate from the data. The HBA can then by instructed
2004 * to place the DIFs in the outgoing stream. For read operations,
2005 * The HBA could extract the DIFs and place it in DIF buffers.
2007 * The buffer list for this type consists of one or more of the
2008 * protection groups described below:
2009 * +-------------------------+
2010 * start of first prot group --> | PDE_5 |
2011 * +-------------------------+
2013 * +-------------------------+
2014 * | PDE_7 (Prot BDE) |
2015 * +-------------------------+
2017 * +-------------------------+
2018 * |more Data BDE's ... (opt)|
2019 * +-------------------------+
2020 * start of new prot group --> | PDE_5 |
2021 * +-------------------------+
2023 * +-------------------------+
2025 * Note: It is assumed that both data and protection s/g buffers have been
2028 * Returns the number of BDEs added to the BPL.
2031 lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc,
2032 struct ulp_bde64 *bpl, int datacnt, int protcnt)
2034 struct scatterlist *sgde = NULL; /* s/g data entry */
2035 struct scatterlist *sgpe = NULL; /* s/g prot entry */
2036 struct lpfc_pde5 *pde5 = NULL;
2037 struct lpfc_pde6 *pde6 = NULL;
2038 struct lpfc_pde7 *pde7 = NULL;
2039 dma_addr_t dataphysaddr, protphysaddr;
2040 unsigned short curr_data = 0, curr_prot = 0;
2041 unsigned int split_offset;
2042 unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder;
2043 unsigned int protgrp_blks, protgrp_bytes;
2044 unsigned int remainder, subtotal;
2046 int datadir = sc->sc_data_direction;
2047 unsigned char pgdone = 0, alldone = 0;
2049 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2052 uint32_t checking = 1;
2057 sgpe = scsi_prot_sglist(sc);
2058 sgde = scsi_sglist(sc);
2060 if (!sgpe || !sgde) {
2061 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
2062 "9020 Invalid s/g entry: data=0x%p prot=0x%p\n",
2067 status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
2071 /* extract some info from the scsi command */
2072 blksize = lpfc_cmd_blksize(sc);
2073 reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
2075 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2076 rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
2078 if (rc & BG_ERR_SWAP)
2079 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
2080 if (rc & BG_ERR_CHECK)
2087 /* Check to see if we ran out of space */
2088 if (num_bde >= (phba->cfg_total_seg_cnt - 2))
2091 /* setup PDE5 with what we have */
2092 pde5 = (struct lpfc_pde5 *) bpl;
2093 memset(pde5, 0, sizeof(struct lpfc_pde5));
2094 bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR);
2096 /* Endianness conversion if necessary for PDE5 */
2097 pde5->word0 = cpu_to_le32(pde5->word0);
2098 pde5->reftag = cpu_to_le32(reftag);
2100 /* advance bpl and increment bde count */
2103 pde6 = (struct lpfc_pde6 *) bpl;
2105 /* setup PDE6 with the rest of the info */
2106 memset(pde6, 0, sizeof(struct lpfc_pde6));
2107 bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR);
2108 bf_set(pde6_optx, pde6, txop);
2109 bf_set(pde6_oprx, pde6, rxop);
2111 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD))
2112 bf_set(pde6_ce, pde6, checking);
2114 bf_set(pde6_ce, pde6, 0);
2116 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF))
2117 bf_set(pde6_re, pde6, checking);
2119 bf_set(pde6_re, pde6, 0);
2121 bf_set(pde6_ai, pde6, 1);
2122 bf_set(pde6_ae, pde6, 0);
2123 bf_set(pde6_apptagval, pde6, 0);
2125 /* Endianness conversion if necessary for PDE6 */
2126 pde6->word0 = cpu_to_le32(pde6->word0);
2127 pde6->word1 = cpu_to_le32(pde6->word1);
2128 pde6->word2 = cpu_to_le32(pde6->word2);
2130 /* advance bpl and increment bde count */
2134 /* setup the first BDE that points to protection buffer */
2135 protphysaddr = sg_dma_address(sgpe) + protgroup_offset;
2136 protgroup_len = sg_dma_len(sgpe) - protgroup_offset;
2138 /* must be integer multiple of the DIF block length */
2139 BUG_ON(protgroup_len % 8);
2141 pde7 = (struct lpfc_pde7 *) bpl;
2142 memset(pde7, 0, sizeof(struct lpfc_pde7));
2143 bf_set(pde7_type, pde7, LPFC_PDE7_DESCRIPTOR);
2145 pde7->addrHigh = le32_to_cpu(putPaddrHigh(protphysaddr));
2146 pde7->addrLow = le32_to_cpu(putPaddrLow(protphysaddr));
2148 protgrp_blks = protgroup_len / 8;
2149 protgrp_bytes = protgrp_blks * blksize;
2151 /* check if this pde is crossing the 4K boundary; if so split */
2152 if ((pde7->addrLow & 0xfff) + protgroup_len > 0x1000) {
2153 protgroup_remainder = 0x1000 - (pde7->addrLow & 0xfff);
2154 protgroup_offset += protgroup_remainder;
2155 protgrp_blks = protgroup_remainder / 8;
2156 protgrp_bytes = protgrp_blks * blksize;
2158 protgroup_offset = 0;
2164 /* setup BDE's for data blocks associated with DIF data */
2166 subtotal = 0; /* total bytes processed for current prot grp */
2168 /* Check to see if we ran out of space */
2169 if (num_bde >= phba->cfg_total_seg_cnt)
2173 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
2174 "9065 BLKGRD:%s Invalid data segment\n",
2179 dataphysaddr = sg_dma_address(sgde) + split_offset;
2180 bpl->addrLow = le32_to_cpu(putPaddrLow(dataphysaddr));
2181 bpl->addrHigh = le32_to_cpu(putPaddrHigh(dataphysaddr));
2183 remainder = sg_dma_len(sgde) - split_offset;
2185 if ((subtotal + remainder) <= protgrp_bytes) {
2186 /* we can use this whole buffer */
2187 bpl->tus.f.bdeSize = remainder;
2190 if ((subtotal + remainder) == protgrp_bytes)
2193 /* must split this buffer with next prot grp */
2194 bpl->tus.f.bdeSize = protgrp_bytes - subtotal;
2195 split_offset += bpl->tus.f.bdeSize;
2198 subtotal += bpl->tus.f.bdeSize;
2200 if (datadir == DMA_TO_DEVICE)
2201 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
2203 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
2204 bpl->tus.w = le32_to_cpu(bpl->tus.w);
2212 /* Move to the next s/g segment if possible */
2213 sgde = sg_next(sgde);
2217 if (protgroup_offset) {
2218 /* update the reference tag */
2219 reftag += protgrp_blks;
2225 if (curr_prot == protcnt) {
2227 } else if (curr_prot < protcnt) {
2228 /* advance to next prot buffer */
2229 sgpe = sg_next(sgpe);
2232 /* update the reference tag */
2233 reftag += protgrp_blks;
2235 /* if we're here, we have a bug */
2236 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
2237 "9054 BLKGRD: bug in %s\n", __func__);
2247 * lpfc_bg_setup_sgl - Setup BlockGuard SGL with no protection data
2248 * @phba: The Hba for which this call is being executed.
2249 * @sc: pointer to scsi command we're working on
2250 * @sgl: pointer to buffer list for protection groups
2251 * @datacnt: number of segments of data that have been dma mapped
2253 * This function sets up SGL buffer list for protection groups of
2254 * type LPFC_PG_TYPE_NO_DIF
2256 * This is usually used when the HBA is instructed to generate
2257 * DIFs and insert them into data stream (or strip DIF from
2258 * incoming data stream)
2260 * The buffer list consists of just one protection group described
2262 * +-------------------------+
2263 * start of prot group --> | DI_SEED |
2264 * +-------------------------+
2266 * +-------------------------+
2267 * |more Data SGE's ... (opt)|
2268 * +-------------------------+
2271 * Note: Data s/g buffers have been dma mapped
2273 * Returns the number of SGEs added to the SGL.
2276 lpfc_bg_setup_sgl(struct lpfc_hba *phba, struct scsi_cmnd *sc,
2277 struct sli4_sge *sgl, int datasegcnt)
2279 struct scatterlist *sgde = NULL; /* s/g data entry */
2280 struct sli4_sge_diseed *diseed = NULL;
2281 dma_addr_t physaddr;
2282 int i = 0, num_sge = 0, status;
2286 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2289 uint32_t checking = 1;
2291 uint32_t dma_offset = 0;
2293 status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
2297 /* extract some info from the scsi command for pde*/
2298 blksize = lpfc_cmd_blksize(sc);
2299 reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
2301 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2302 rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
2304 if (rc & BG_ERR_SWAP)
2305 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
2306 if (rc & BG_ERR_CHECK)
2311 /* setup DISEED with what we have */
2312 diseed = (struct sli4_sge_diseed *) sgl;
2313 memset(diseed, 0, sizeof(struct sli4_sge_diseed));
2314 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED);
2316 /* Endianness conversion if necessary */
2317 diseed->ref_tag = cpu_to_le32(reftag);
2318 diseed->ref_tag_tran = diseed->ref_tag;
2321 * We only need to check the data on READs, for WRITEs
2322 * protection data is automatically generated, not checked.
2324 if (sc->sc_data_direction == DMA_FROM_DEVICE) {
2325 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD))
2326 bf_set(lpfc_sli4_sge_dif_ce, diseed, checking);
2328 bf_set(lpfc_sli4_sge_dif_ce, diseed, 0);
2330 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF))
2331 bf_set(lpfc_sli4_sge_dif_re, diseed, checking);
2333 bf_set(lpfc_sli4_sge_dif_re, diseed, 0);
2336 /* setup DISEED with the rest of the info */
2337 bf_set(lpfc_sli4_sge_dif_optx, diseed, txop);
2338 bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop);
2340 bf_set(lpfc_sli4_sge_dif_ai, diseed, 1);
2341 bf_set(lpfc_sli4_sge_dif_me, diseed, 0);
2343 /* Endianness conversion if necessary for DISEED */
2344 diseed->word2 = cpu_to_le32(diseed->word2);
2345 diseed->word3 = cpu_to_le32(diseed->word3);
2347 /* advance bpl and increment sge count */
2351 /* assumption: caller has already run dma_map_sg on command data */
2352 scsi_for_each_sg(sc, sgde, datasegcnt, i) {
2353 physaddr = sg_dma_address(sgde);
2354 dma_len = sg_dma_len(sgde);
2355 sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr));
2356 sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr));
2357 if ((i + 1) == datasegcnt)
2358 bf_set(lpfc_sli4_sge_last, sgl, 1);
2360 bf_set(lpfc_sli4_sge_last, sgl, 0);
2361 bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
2362 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA);
2364 sgl->sge_len = cpu_to_le32(dma_len);
2365 dma_offset += dma_len;
2376 * lpfc_bg_setup_sgl_prot - Setup BlockGuard SGL with protection data
2377 * @phba: The Hba for which this call is being executed.
2378 * @sc: pointer to scsi command we're working on
2379 * @sgl: pointer to buffer list for protection groups
2380 * @datacnt: number of segments of data that have been dma mapped
2381 * @protcnt: number of segment of protection data that have been dma mapped
2383 * This function sets up SGL buffer list for protection groups of
2384 * type LPFC_PG_TYPE_DIF
2386 * This is usually used when DIFs are in their own buffers,
2387 * separate from the data. The HBA can then by instructed
2388 * to place the DIFs in the outgoing stream. For read operations,
2389 * The HBA could extract the DIFs and place it in DIF buffers.
2391 * The buffer list for this type consists of one or more of the
2392 * protection groups described below:
2393 * +-------------------------+
2394 * start of first prot group --> | DISEED |
2395 * +-------------------------+
2396 * | DIF (Prot SGE) |
2397 * +-------------------------+
2399 * +-------------------------+
2400 * |more Data SGE's ... (opt)|
2401 * +-------------------------+
2402 * start of new prot group --> | DISEED |
2403 * +-------------------------+
2405 * +-------------------------+
2407 * Note: It is assumed that both data and protection s/g buffers have been
2410 * Returns the number of SGEs added to the SGL.
2413 lpfc_bg_setup_sgl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc,
2414 struct sli4_sge *sgl, int datacnt, int protcnt)
2416 struct scatterlist *sgde = NULL; /* s/g data entry */
2417 struct scatterlist *sgpe = NULL; /* s/g prot entry */
2418 struct sli4_sge_diseed *diseed = NULL;
2419 dma_addr_t dataphysaddr, protphysaddr;
2420 unsigned short curr_data = 0, curr_prot = 0;
2421 unsigned int split_offset;
2422 unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder;
2423 unsigned int protgrp_blks, protgrp_bytes;
2424 unsigned int remainder, subtotal;
2426 unsigned char pgdone = 0, alldone = 0;
2431 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2434 uint32_t checking = 1;
2435 uint32_t dma_offset = 0;
2438 sgpe = scsi_prot_sglist(sc);
2439 sgde = scsi_sglist(sc);
2441 if (!sgpe || !sgde) {
2442 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
2443 "9082 Invalid s/g entry: data=0x%p prot=0x%p\n",
2448 status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
2452 /* extract some info from the scsi command */
2453 blksize = lpfc_cmd_blksize(sc);
2454 reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
2456 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2457 rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
2459 if (rc & BG_ERR_SWAP)
2460 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
2461 if (rc & BG_ERR_CHECK)
2468 /* Check to see if we ran out of space */
2469 if (num_sge >= (phba->cfg_total_seg_cnt - 2))
2472 /* setup DISEED with what we have */
2473 diseed = (struct sli4_sge_diseed *) sgl;
2474 memset(diseed, 0, sizeof(struct sli4_sge_diseed));
2475 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED);
2477 /* Endianness conversion if necessary */
2478 diseed->ref_tag = cpu_to_le32(reftag);
2479 diseed->ref_tag_tran = diseed->ref_tag;
2481 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) {
2482 bf_set(lpfc_sli4_sge_dif_ce, diseed, checking);
2485 bf_set(lpfc_sli4_sge_dif_ce, diseed, 0);
2487 * When in this mode, the hardware will replace
2488 * the guard tag from the host with a
2489 * newly generated good CRC for the wire.
2490 * Switch to raw mode here to avoid this
2491 * behavior. What the host sends gets put on the wire.
2493 if (txop == BG_OP_IN_CRC_OUT_CRC) {
2494 txop = BG_OP_RAW_MODE;
2495 rxop = BG_OP_RAW_MODE;
2500 if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF))
2501 bf_set(lpfc_sli4_sge_dif_re, diseed, checking);
2503 bf_set(lpfc_sli4_sge_dif_re, diseed, 0);
2505 /* setup DISEED with the rest of the info */
2506 bf_set(lpfc_sli4_sge_dif_optx, diseed, txop);
2507 bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop);
2509 bf_set(lpfc_sli4_sge_dif_ai, diseed, 1);
2510 bf_set(lpfc_sli4_sge_dif_me, diseed, 0);
2512 /* Endianness conversion if necessary for DISEED */
2513 diseed->word2 = cpu_to_le32(diseed->word2);
2514 diseed->word3 = cpu_to_le32(diseed->word3);
2516 /* advance sgl and increment bde count */
2520 /* setup the first BDE that points to protection buffer */
2521 protphysaddr = sg_dma_address(sgpe) + protgroup_offset;
2522 protgroup_len = sg_dma_len(sgpe) - protgroup_offset;
2524 /* must be integer multiple of the DIF block length */
2525 BUG_ON(protgroup_len % 8);
2527 /* Now setup DIF SGE */
2529 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DIF);
2530 sgl->addr_hi = le32_to_cpu(putPaddrHigh(protphysaddr));
2531 sgl->addr_lo = le32_to_cpu(putPaddrLow(protphysaddr));
2532 sgl->word2 = cpu_to_le32(sgl->word2);
2534 protgrp_blks = protgroup_len / 8;
2535 protgrp_bytes = protgrp_blks * blksize;
2537 /* check if DIF SGE is crossing the 4K boundary; if so split */
2538 if ((sgl->addr_lo & 0xfff) + protgroup_len > 0x1000) {
2539 protgroup_remainder = 0x1000 - (sgl->addr_lo & 0xfff);
2540 protgroup_offset += protgroup_remainder;
2541 protgrp_blks = protgroup_remainder / 8;
2542 protgrp_bytes = protgrp_blks * blksize;
2544 protgroup_offset = 0;
2550 /* setup SGE's for data blocks associated with DIF data */
2552 subtotal = 0; /* total bytes processed for current prot grp */
2554 /* Check to see if we ran out of space */
2555 if (num_sge >= phba->cfg_total_seg_cnt)
2559 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
2560 "9086 BLKGRD:%s Invalid data segment\n",
2565 dataphysaddr = sg_dma_address(sgde) + split_offset;
2567 remainder = sg_dma_len(sgde) - split_offset;
2569 if ((subtotal + remainder) <= protgrp_bytes) {
2570 /* we can use this whole buffer */
2571 dma_len = remainder;
2574 if ((subtotal + remainder) == protgrp_bytes)
2577 /* must split this buffer with next prot grp */
2578 dma_len = protgrp_bytes - subtotal;
2579 split_offset += dma_len;
2582 subtotal += dma_len;
2584 sgl->addr_lo = cpu_to_le32(putPaddrLow(dataphysaddr));
2585 sgl->addr_hi = cpu_to_le32(putPaddrHigh(dataphysaddr));
2586 bf_set(lpfc_sli4_sge_last, sgl, 0);
2587 bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
2588 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA);
2590 sgl->sge_len = cpu_to_le32(dma_len);
2591 dma_offset += dma_len;
2599 /* Move to the next s/g segment if possible */
2600 sgde = sg_next(sgde);
2603 if (protgroup_offset) {
2604 /* update the reference tag */
2605 reftag += protgrp_blks;
2611 if (curr_prot == protcnt) {
2612 bf_set(lpfc_sli4_sge_last, sgl, 1);
2614 } else if (curr_prot < protcnt) {
2615 /* advance to next prot buffer */
2616 sgpe = sg_next(sgpe);
2619 /* update the reference tag */
2620 reftag += protgrp_blks;
2622 /* if we're here, we have a bug */
2623 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
2624 "9085 BLKGRD: bug in %s\n", __func__);
2635 * lpfc_prot_group_type - Get prtotection group type of SCSI command
2636 * @phba: The Hba for which this call is being executed.
2637 * @sc: pointer to scsi command we're working on
2639 * Given a SCSI command that supports DIF, determine composition of protection
2640 * groups involved in setting up buffer lists
2642 * Returns: Protection group type (with or without DIF)
2646 lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc)
2648 int ret = LPFC_PG_TYPE_INVALID;
2649 unsigned char op = scsi_get_prot_op(sc);
2652 case SCSI_PROT_READ_STRIP:
2653 case SCSI_PROT_WRITE_INSERT:
2654 ret = LPFC_PG_TYPE_NO_DIF;
2656 case SCSI_PROT_READ_INSERT:
2657 case SCSI_PROT_WRITE_STRIP:
2658 case SCSI_PROT_READ_PASS:
2659 case SCSI_PROT_WRITE_PASS:
2660 ret = LPFC_PG_TYPE_DIF_BUF;
2664 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
2665 "9021 Unsupported protection op:%d\n",
2673 * lpfc_bg_scsi_adjust_dl - Adjust SCSI data length for BlockGuard
2674 * @phba: The Hba for which this call is being executed.
2675 * @lpfc_cmd: The scsi buffer which is going to be adjusted.
2677 * Adjust the data length to account for how much data
2678 * is actually on the wire.
2680 * returns the adjusted data length
2683 lpfc_bg_scsi_adjust_dl(struct lpfc_hba *phba,
2684 struct lpfc_scsi_buf *lpfc_cmd)
2686 struct scsi_cmnd *sc = lpfc_cmd->pCmd;
2689 fcpdl = scsi_bufflen(sc);
2691 /* Check if there is protection data on the wire */
2692 if (sc->sc_data_direction == DMA_FROM_DEVICE) {
2693 /* Read check for protection data */
2694 if (scsi_get_prot_op(sc) == SCSI_PROT_READ_INSERT)
2698 /* Write check for protection data */
2699 if (scsi_get_prot_op(sc) == SCSI_PROT_WRITE_STRIP)
2704 * If we are in DIF Type 1 mode every data block has a 8 byte
2705 * DIF (trailer) attached to it. Must ajust FCP data length
2706 * to account for the protection data.
2708 fcpdl += (fcpdl / lpfc_cmd_blksize(sc)) * 8;
2714 * lpfc_bg_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
2715 * @phba: The Hba for which this call is being executed.
2716 * @lpfc_cmd: The scsi buffer which is going to be prep'ed.
2718 * This is the protection/DIF aware version of
2719 * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the
2720 * two functions eventually, but for now, it's here
2723 lpfc_bg_scsi_prep_dma_buf_s3(struct lpfc_hba *phba,
2724 struct lpfc_scsi_buf *lpfc_cmd)
2726 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
2727 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
2728 struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl;
2729 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
2730 uint32_t num_bde = 0;
2731 int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction;
2732 int prot_group_type = 0;
2736 * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd
2737 * fcp_rsp regions to the first data bde entry
2740 if (scsi_sg_count(scsi_cmnd)) {
2742 * The driver stores the segment count returned from pci_map_sg
2743 * because this a count of dma-mappings used to map the use_sg
2744 * pages. They are not guaranteed to be the same for those
2745 * architectures that implement an IOMMU.
2747 datasegcnt = dma_map_sg(&phba->pcidev->dev,
2748 scsi_sglist(scsi_cmnd),
2749 scsi_sg_count(scsi_cmnd), datadir);
2750 if (unlikely(!datasegcnt))
2753 lpfc_cmd->seg_cnt = datasegcnt;
2755 /* First check if data segment count from SCSI Layer is good */
2756 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt)
2759 prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd);
2761 switch (prot_group_type) {
2762 case LPFC_PG_TYPE_NO_DIF:
2764 /* Here we need to add a PDE5 and PDE6 to the count */
2765 if ((lpfc_cmd->seg_cnt + 2) > phba->cfg_total_seg_cnt)
2768 num_bde = lpfc_bg_setup_bpl(phba, scsi_cmnd, bpl,
2770 /* we should have 2 or more entries in buffer list */
2775 case LPFC_PG_TYPE_DIF_BUF:
2777 * This type indicates that protection buffers are
2778 * passed to the driver, so that needs to be prepared
2781 protsegcnt = dma_map_sg(&phba->pcidev->dev,
2782 scsi_prot_sglist(scsi_cmnd),
2783 scsi_prot_sg_count(scsi_cmnd), datadir);
2784 if (unlikely(!protsegcnt)) {
2785 scsi_dma_unmap(scsi_cmnd);
2789 lpfc_cmd->prot_seg_cnt = protsegcnt;
2792 * There is a minimun of 4 BPLs used for every
2793 * protection data segment.
2795 if ((lpfc_cmd->prot_seg_cnt * 4) >
2796 (phba->cfg_total_seg_cnt - 2))
2799 num_bde = lpfc_bg_setup_bpl_prot(phba, scsi_cmnd, bpl,
2800 datasegcnt, protsegcnt);
2801 /* we should have 3 or more entries in buffer list */
2802 if ((num_bde < 3) ||
2803 (num_bde > phba->cfg_total_seg_cnt))
2807 case LPFC_PG_TYPE_INVALID:
2809 scsi_dma_unmap(scsi_cmnd);
2810 lpfc_cmd->seg_cnt = 0;
2812 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
2813 "9022 Unexpected protection group %i\n",
2820 * Finish initializing those IOCB fields that are dependent on the
2821 * scsi_cmnd request_buffer. Note that the bdeSize is explicitly
2822 * reinitialized since all iocb memory resources are used many times
2823 * for transmit, receive, and continuation bpl's.
2825 iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
2826 iocb_cmd->un.fcpi64.bdl.bdeSize += (num_bde * sizeof(struct ulp_bde64));
2827 iocb_cmd->ulpBdeCount = 1;
2828 iocb_cmd->ulpLe = 1;
2830 fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd);
2831 fcp_cmnd->fcpDl = be32_to_cpu(fcpdl);
2834 * Due to difference in data length between DIF/non-DIF paths,
2835 * we need to set word 4 of IOCB here
2837 iocb_cmd->un.fcpi.fcpi_parm = fcpdl;
2841 if (lpfc_cmd->seg_cnt)
2842 scsi_dma_unmap(scsi_cmnd);
2843 if (lpfc_cmd->prot_seg_cnt)
2844 dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd),
2845 scsi_prot_sg_count(scsi_cmnd),
2846 scsi_cmnd->sc_data_direction);
2848 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
2849 "9023 Cannot setup S/G List for HBA"
2850 "IO segs %d/%d BPL %d SCSI %d: %d %d\n",
2851 lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt,
2852 phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt,
2853 prot_group_type, num_bde);
2855 lpfc_cmd->seg_cnt = 0;
2856 lpfc_cmd->prot_seg_cnt = 0;
2861 * This function calcuates the T10 DIF guard tag
2862 * on the specified data using a CRC algorithmn
2866 lpfc_bg_crc(uint8_t *data, int count)
2871 crc = crc_t10dif(data, count);
2872 x = cpu_to_be16(crc);
2877 * This function calcuates the T10 DIF guard tag
2878 * on the specified data using a CSUM algorithmn
2879 * using ip_compute_csum.
2882 lpfc_bg_csum(uint8_t *data, int count)
2886 ret = ip_compute_csum(data, count);
2891 * This function examines the protection data to try to determine
2892 * what type of T10-DIF error occurred.
2895 lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
2897 struct scatterlist *sgpe; /* s/g prot entry */
2898 struct scatterlist *sgde; /* s/g data entry */
2899 struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
2900 struct scsi_dif_tuple *src = NULL;
2901 uint8_t *data_src = NULL;
2902 uint16_t guard_tag, guard_type;
2903 uint16_t start_app_tag, app_tag;
2904 uint32_t start_ref_tag, ref_tag;
2905 int prot, protsegcnt;
2906 int err_type, len, data_len;
2907 int chk_ref, chk_app, chk_guard;
2911 err_type = BGS_GUARD_ERR_MASK;
2915 /* First check to see if there is protection data to examine */
2916 prot = scsi_get_prot_op(cmd);
2917 if ((prot == SCSI_PROT_READ_STRIP) ||
2918 (prot == SCSI_PROT_WRITE_INSERT) ||
2919 (prot == SCSI_PROT_NORMAL))
2922 /* Currently the driver just supports ref_tag and guard_tag checking */
2927 /* Setup a ptr to the protection data provided by the SCSI host */
2928 sgpe = scsi_prot_sglist(cmd);
2929 protsegcnt = lpfc_cmd->prot_seg_cnt;
2931 if (sgpe && protsegcnt) {
2934 * We will only try to verify guard tag if the segment
2935 * data length is a multiple of the blksize.
2937 sgde = scsi_sglist(cmd);
2938 blksize = lpfc_cmd_blksize(cmd);
2939 data_src = (uint8_t *)sg_virt(sgde);
2940 data_len = sgde->length;
2941 if ((data_len & (blksize - 1)) == 0)
2943 guard_type = scsi_host_get_guard(cmd->device->host);
2945 src = (struct scsi_dif_tuple *)sg_virt(sgpe);
2946 start_ref_tag = (uint32_t)scsi_get_lba(cmd); /* Truncate LBA */
2947 start_app_tag = src->app_tag;
2949 while (src && protsegcnt) {
2953 * First check to see if a protection data
2956 if ((src->ref_tag == 0xffffffff) ||
2957 (src->app_tag == 0xffff)) {
2962 /* First Guard Tag checking */
2964 guard_tag = src->guard_tag;
2965 if (lpfc_cmd_guard_csum(cmd))
2966 sum = lpfc_bg_csum(data_src,
2969 sum = lpfc_bg_crc(data_src,
2971 if ((guard_tag != sum)) {
2972 err_type = BGS_GUARD_ERR_MASK;
2977 /* Reference Tag checking */
2978 ref_tag = be32_to_cpu(src->ref_tag);
2979 if (chk_ref && (ref_tag != start_ref_tag)) {
2980 err_type = BGS_REFTAG_ERR_MASK;
2985 /* App Tag checking */
2986 app_tag = src->app_tag;
2987 if (chk_app && (app_tag != start_app_tag)) {
2988 err_type = BGS_APPTAG_ERR_MASK;
2992 len -= sizeof(struct scsi_dif_tuple);
2997 data_src += blksize;
2998 data_len -= blksize;
3001 * Are we at the end of the Data segment?
3002 * The data segment is only used for Guard
3005 if (chk_guard && (data_len == 0)) {
3007 sgde = sg_next(sgde);
3011 data_src = (uint8_t *)sg_virt(sgde);
3012 data_len = sgde->length;
3013 if ((data_len & (blksize - 1)) == 0)
3018 /* Goto the next Protection data segment */
3019 sgpe = sg_next(sgpe);
3021 src = (struct scsi_dif_tuple *)sg_virt(sgpe);
3030 if (err_type == BGS_GUARD_ERR_MASK) {
3031 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
3033 cmd->result = DRIVER_SENSE << 24
3034 | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
3035 phba->bg_guard_err_cnt++;
3036 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
3037 "9069 BLKGRD: LBA %lx grd_tag error %x != %x\n",
3038 (unsigned long)scsi_get_lba(cmd),
3041 } else if (err_type == BGS_REFTAG_ERR_MASK) {
3042 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
3044 cmd->result = DRIVER_SENSE << 24
3045 | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
3047 phba->bg_reftag_err_cnt++;
3048 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
3049 "9066 BLKGRD: LBA %lx ref_tag error %x != %x\n",
3050 (unsigned long)scsi_get_lba(cmd),
3051 ref_tag, start_ref_tag);
3053 } else if (err_type == BGS_APPTAG_ERR_MASK) {
3054 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
3056 cmd->result = DRIVER_SENSE << 24
3057 | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
3059 phba->bg_apptag_err_cnt++;
3060 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
3061 "9041 BLKGRD: LBA %lx app_tag error %x != %x\n",
3062 (unsigned long)scsi_get_lba(cmd),
3063 app_tag, start_app_tag);
3069 * This function checks for BlockGuard errors detected by
3070 * the HBA. In case of errors, the ASC/ASCQ fields in the
3071 * sense buffer will be set accordingly, paired with
3072 * ILLEGAL_REQUEST to signal to the kernel that the HBA
3073 * detected corruption.
3076 * 0 - No error found
3077 * 1 - BlockGuard error found
3078 * -1 - Internal error (bad profile, ...etc)
3081 lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd,
3082 struct lpfc_iocbq *pIocbOut)
3084 struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
3085 struct sli3_bg_fields *bgf = &pIocbOut->iocb.unsli3.sli3_bg;
3087 uint32_t bghm = bgf->bghm;
3088 uint32_t bgstat = bgf->bgstat;
3089 uint64_t failing_sector = 0;
3091 spin_lock(&_dump_buf_lock);
3092 if (!_dump_buf_done) {
3093 lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9070 BLKGRD: Saving"
3094 " Data for %u blocks to debugfs\n",
3095 (cmd->cmnd[7] << 8 | cmd->cmnd[8]));
3096 lpfc_debug_save_data(phba, cmd);
3098 /* If we have a prot sgl, save the DIF buffer */
3099 if (lpfc_prot_group_type(phba, cmd) ==
3100 LPFC_PG_TYPE_DIF_BUF) {
3101 lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9071 BLKGRD: "
3102 "Saving DIF for %u blocks to debugfs\n",
3103 (cmd->cmnd[7] << 8 | cmd->cmnd[8]));
3104 lpfc_debug_save_dif(phba, cmd);
3109 spin_unlock(&_dump_buf_lock);
3111 if (lpfc_bgs_get_invalid_prof(bgstat)) {
3112 cmd->result = ScsiResult(DID_ERROR, 0);
3113 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
3114 "9072 BLKGRD: Invalid BG Profile in cmd"
3115 " 0x%x lba 0x%llx blk cnt 0x%x "
3116 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
3117 (unsigned long long)scsi_get_lba(cmd),
3118 blk_rq_sectors(cmd->request), bgstat, bghm);
3123 if (lpfc_bgs_get_uninit_dif_block(bgstat)) {
3124 cmd->result = ScsiResult(DID_ERROR, 0);
3125 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
3126 "9073 BLKGRD: Invalid BG PDIF Block in cmd"
3127 " 0x%x lba 0x%llx blk cnt 0x%x "
3128 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
3129 (unsigned long long)scsi_get_lba(cmd),
3130 blk_rq_sectors(cmd->request), bgstat, bghm);
3135 if (lpfc_bgs_get_guard_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);
3142 phba->bg_guard_err_cnt++;
3143 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
3144 "9055 BLKGRD: Guard Tag error in cmd"
3145 " 0x%x lba 0x%llx blk cnt 0x%x "
3146 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
3147 (unsigned long long)scsi_get_lba(cmd),
3148 blk_rq_sectors(cmd->request), bgstat, bghm);
3151 if (lpfc_bgs_get_reftag_err(bgstat)) {
3154 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
3156 cmd->result = DRIVER_SENSE << 24
3157 | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
3159 phba->bg_reftag_err_cnt++;
3160 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
3161 "9056 BLKGRD: Ref Tag error in cmd"
3162 " 0x%x lba 0x%llx blk cnt 0x%x "
3163 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
3164 (unsigned long long)scsi_get_lba(cmd),
3165 blk_rq_sectors(cmd->request), bgstat, bghm);
3168 if (lpfc_bgs_get_apptag_err(bgstat)) {
3171 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
3173 cmd->result = DRIVER_SENSE << 24
3174 | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
3176 phba->bg_apptag_err_cnt++;
3177 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
3178 "9061 BLKGRD: App Tag error in cmd"
3179 " 0x%x lba 0x%llx blk cnt 0x%x "
3180 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
3181 (unsigned long long)scsi_get_lba(cmd),
3182 blk_rq_sectors(cmd->request), bgstat, bghm);
3185 if (lpfc_bgs_get_hi_water_mark_present(bgstat)) {
3187 * setup sense data descriptor 0 per SPC-4 as an information
3188 * field, and put the failing LBA in it.
3189 * This code assumes there was also a guard/app/ref tag error
3192 cmd->sense_buffer[7] = 0xc; /* Additional sense length */
3193 cmd->sense_buffer[8] = 0; /* Information descriptor type */
3194 cmd->sense_buffer[9] = 0xa; /* Additional descriptor length */
3195 cmd->sense_buffer[10] = 0x80; /* Validity bit */
3197 /* bghm is a "on the wire" FC frame based count */
3198 switch (scsi_get_prot_op(cmd)) {
3199 case SCSI_PROT_READ_INSERT:
3200 case SCSI_PROT_WRITE_STRIP:
3201 bghm /= cmd->device->sector_size;
3203 case SCSI_PROT_READ_STRIP:
3204 case SCSI_PROT_WRITE_INSERT:
3205 case SCSI_PROT_READ_PASS:
3206 case SCSI_PROT_WRITE_PASS:
3207 bghm /= (cmd->device->sector_size +
3208 sizeof(struct scsi_dif_tuple));
3212 failing_sector = scsi_get_lba(cmd);
3213 failing_sector += bghm;
3215 /* Descriptor Information */
3216 put_unaligned_be64(failing_sector, &cmd->sense_buffer[12]);
3220 /* No error was reported - problem in FW? */
3221 lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
3222 "9057 BLKGRD: Unknown error in cmd"
3223 " 0x%x lba 0x%llx blk cnt 0x%x "
3224 "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
3225 (unsigned long long)scsi_get_lba(cmd),
3226 blk_rq_sectors(cmd->request), bgstat, bghm);
3228 /* Calcuate what type of error it was */
3229 lpfc_calc_bg_err(phba, lpfc_cmd);
3236 * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
3237 * @phba: The Hba for which this call is being executed.
3238 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3240 * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
3241 * field of @lpfc_cmd for device with SLI-4 interface spec.
3248 lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
3250 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
3251 struct scatterlist *sgel = NULL;
3252 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
3253 struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl;
3254 struct sli4_sge *first_data_sgl;
3255 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
3256 dma_addr_t physaddr;
3257 uint32_t num_bde = 0;
3259 uint32_t dma_offset = 0;
3261 struct ulp_bde64 *bde;
3264 * There are three possibilities here - use scatter-gather segment, use
3265 * the single mapping, or neither. Start the lpfc command prep by
3266 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
3269 if (scsi_sg_count(scsi_cmnd)) {
3271 * The driver stores the segment count returned from pci_map_sg
3272 * because this a count of dma-mappings used to map the use_sg
3273 * pages. They are not guaranteed to be the same for those
3274 * architectures that implement an IOMMU.
3277 nseg = scsi_dma_map(scsi_cmnd);
3278 if (unlikely(!nseg))
3281 /* clear the last flag in the fcp_rsp map entry */
3282 sgl->word2 = le32_to_cpu(sgl->word2);
3283 bf_set(lpfc_sli4_sge_last, sgl, 0);
3284 sgl->word2 = cpu_to_le32(sgl->word2);
3286 first_data_sgl = sgl;
3287 lpfc_cmd->seg_cnt = nseg;
3288 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
3289 lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9074 BLKGRD:"
3290 " %s: Too many sg segments from "
3291 "dma_map_sg. Config %d, seg_cnt %d\n",
3292 __func__, phba->cfg_sg_seg_cnt,
3294 lpfc_cmd->seg_cnt = 0;
3295 scsi_dma_unmap(scsi_cmnd);
3300 * The driver established a maximum scatter-gather segment count
3301 * during probe that limits the number of sg elements in any
3302 * single scsi command. Just run through the seg_cnt and format
3304 * When using SLI-3 the driver will try to fit all the BDEs into
3305 * the IOCB. If it can't then the BDEs get added to a BPL as it
3306 * does for SLI-2 mode.
3308 scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) {
3309 physaddr = sg_dma_address(sgel);
3310 dma_len = sg_dma_len(sgel);
3311 sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr));
3312 sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr));
3313 sgl->word2 = le32_to_cpu(sgl->word2);
3314 if ((num_bde + 1) == nseg)
3315 bf_set(lpfc_sli4_sge_last, sgl, 1);
3317 bf_set(lpfc_sli4_sge_last, sgl, 0);
3318 bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
3319 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA);
3320 sgl->word2 = cpu_to_le32(sgl->word2);
3321 sgl->sge_len = cpu_to_le32(dma_len);
3322 dma_offset += dma_len;
3325 /* setup the performance hint (first data BDE) if enabled */
3326 if (phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) {
3327 bde = (struct ulp_bde64 *)
3328 &(iocb_cmd->unsli3.sli3Words[5]);
3329 bde->addrLow = first_data_sgl->addr_lo;
3330 bde->addrHigh = first_data_sgl->addr_hi;
3331 bde->tus.f.bdeSize =
3332 le32_to_cpu(first_data_sgl->sge_len);
3333 bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
3334 bde->tus.w = cpu_to_le32(bde->tus.w);
3338 /* clear the last flag in the fcp_rsp map entry */
3339 sgl->word2 = le32_to_cpu(sgl->word2);
3340 bf_set(lpfc_sli4_sge_last, sgl, 1);
3341 sgl->word2 = cpu_to_le32(sgl->word2);
3345 * Finish initializing those IOCB fields that are dependent on the
3346 * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
3347 * explicitly reinitialized.
3348 * all iocb memory resources are reused.
3350 fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd));
3353 * Due to difference in data length between DIF/non-DIF paths,
3354 * we need to set word 4 of IOCB here
3356 iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd);
3359 * If the OAS driver feature is enabled and the lun is enabled for
3360 * OAS, set the oas iocb related flags.
3362 if ((phba->cfg_fof) && ((struct lpfc_device_data *)
3363 scsi_cmnd->device->hostdata)->oas_enabled)
3364 lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF);
3369 * lpfc_bg_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
3370 * @phba: The Hba for which this call is being executed.
3371 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3373 * This is the protection/DIF aware version of
3374 * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the
3375 * two functions eventually, but for now, it's here
3378 lpfc_bg_scsi_prep_dma_buf_s4(struct lpfc_hba *phba,
3379 struct lpfc_scsi_buf *lpfc_cmd)
3381 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
3382 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
3383 struct sli4_sge *sgl = (struct sli4_sge *)(lpfc_cmd->fcp_bpl);
3384 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
3385 uint32_t num_sge = 0;
3386 int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction;
3387 int prot_group_type = 0;
3391 * Start the lpfc command prep by bumping the sgl beyond fcp_cmnd
3392 * fcp_rsp regions to the first data sge entry
3394 if (scsi_sg_count(scsi_cmnd)) {
3396 * The driver stores the segment count returned from pci_map_sg
3397 * because this a count of dma-mappings used to map the use_sg
3398 * pages. They are not guaranteed to be the same for those
3399 * architectures that implement an IOMMU.
3401 datasegcnt = dma_map_sg(&phba->pcidev->dev,
3402 scsi_sglist(scsi_cmnd),
3403 scsi_sg_count(scsi_cmnd), datadir);
3404 if (unlikely(!datasegcnt))
3408 /* clear the last flag in the fcp_rsp map entry */
3409 sgl->word2 = le32_to_cpu(sgl->word2);
3410 bf_set(lpfc_sli4_sge_last, sgl, 0);
3411 sgl->word2 = cpu_to_le32(sgl->word2);
3414 lpfc_cmd->seg_cnt = datasegcnt;
3416 /* First check if data segment count from SCSI Layer is good */
3417 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt)
3420 prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd);
3422 switch (prot_group_type) {
3423 case LPFC_PG_TYPE_NO_DIF:
3424 /* Here we need to add a DISEED to the count */
3425 if ((lpfc_cmd->seg_cnt + 1) > phba->cfg_total_seg_cnt)
3428 num_sge = lpfc_bg_setup_sgl(phba, scsi_cmnd, sgl,
3431 /* we should have 2 or more entries in buffer list */
3436 case LPFC_PG_TYPE_DIF_BUF:
3438 * This type indicates that protection buffers are
3439 * passed to the driver, so that needs to be prepared
3442 protsegcnt = dma_map_sg(&phba->pcidev->dev,
3443 scsi_prot_sglist(scsi_cmnd),
3444 scsi_prot_sg_count(scsi_cmnd), datadir);
3445 if (unlikely(!protsegcnt)) {
3446 scsi_dma_unmap(scsi_cmnd);
3450 lpfc_cmd->prot_seg_cnt = protsegcnt;
3452 * There is a minimun of 3 SGEs used for every
3453 * protection data segment.
3455 if ((lpfc_cmd->prot_seg_cnt * 3) >
3456 (phba->cfg_total_seg_cnt - 2))
3459 num_sge = lpfc_bg_setup_sgl_prot(phba, scsi_cmnd, sgl,
3460 datasegcnt, protsegcnt);
3462 /* we should have 3 or more entries in buffer list */
3463 if ((num_sge < 3) ||
3464 (num_sge > phba->cfg_total_seg_cnt))
3468 case LPFC_PG_TYPE_INVALID:
3470 scsi_dma_unmap(scsi_cmnd);
3471 lpfc_cmd->seg_cnt = 0;
3473 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
3474 "9083 Unexpected protection group %i\n",
3480 switch (scsi_get_prot_op(scsi_cmnd)) {
3481 case SCSI_PROT_WRITE_STRIP:
3482 case SCSI_PROT_READ_STRIP:
3483 lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_STRIP;
3485 case SCSI_PROT_WRITE_INSERT:
3486 case SCSI_PROT_READ_INSERT:
3487 lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_INSERT;
3489 case SCSI_PROT_WRITE_PASS:
3490 case SCSI_PROT_READ_PASS:
3491 lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_PASS;
3495 fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd);
3496 fcp_cmnd->fcpDl = be32_to_cpu(fcpdl);
3499 * Due to difference in data length between DIF/non-DIF paths,
3500 * we need to set word 4 of IOCB here
3502 iocb_cmd->un.fcpi.fcpi_parm = fcpdl;
3505 * If the OAS driver feature is enabled and the lun is enabled for
3506 * OAS, set the oas iocb related flags.
3508 if ((phba->cfg_fof) && ((struct lpfc_device_data *)
3509 scsi_cmnd->device->hostdata)->oas_enabled)
3510 lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF);
3514 if (lpfc_cmd->seg_cnt)
3515 scsi_dma_unmap(scsi_cmnd);
3516 if (lpfc_cmd->prot_seg_cnt)
3517 dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd),
3518 scsi_prot_sg_count(scsi_cmnd),
3519 scsi_cmnd->sc_data_direction);
3521 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
3522 "9084 Cannot setup S/G List for HBA"
3523 "IO segs %d/%d SGL %d SCSI %d: %d %d\n",
3524 lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt,
3525 phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt,
3526 prot_group_type, num_sge);
3528 lpfc_cmd->seg_cnt = 0;
3529 lpfc_cmd->prot_seg_cnt = 0;
3534 * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
3535 * @phba: The Hba for which this call is being executed.
3536 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3538 * This routine wraps the actual DMA mapping function pointer from the
3546 lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
3548 return phba->lpfc_scsi_prep_dma_buf(phba, lpfc_cmd);
3552 * lpfc_bg_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
3554 * @phba: The Hba for which this call is being executed.
3555 * @lpfc_cmd: The scsi buffer which is going to be mapped.
3557 * This routine wraps the actual DMA mapping function pointer from the
3565 lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
3567 return phba->lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd);
3571 * lpfc_send_scsi_error_event - Posts an event when there is SCSI error
3572 * @phba: Pointer to hba context object.
3573 * @vport: Pointer to vport object.
3574 * @lpfc_cmd: Pointer to lpfc scsi command which reported the error.
3575 * @rsp_iocb: Pointer to response iocb object which reported error.
3577 * This function posts an event when there is a SCSI command reporting
3578 * error from the scsi device.
3581 lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport,
3582 struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_iocbq *rsp_iocb) {
3583 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
3584 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
3585 uint32_t resp_info = fcprsp->rspStatus2;
3586 uint32_t scsi_status = fcprsp->rspStatus3;
3587 uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm;
3588 struct lpfc_fast_path_event *fast_path_evt = NULL;
3589 struct lpfc_nodelist *pnode = lpfc_cmd->rdata->pnode;
3590 unsigned long flags;
3592 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
3595 /* If there is queuefull or busy condition send a scsi event */
3596 if ((cmnd->result == SAM_STAT_TASK_SET_FULL) ||
3597 (cmnd->result == SAM_STAT_BUSY)) {
3598 fast_path_evt = lpfc_alloc_fast_evt(phba);
3601 fast_path_evt->un.scsi_evt.event_type =
3603 fast_path_evt->un.scsi_evt.subcategory =
3604 (cmnd->result == SAM_STAT_TASK_SET_FULL) ?
3605 LPFC_EVENT_QFULL : LPFC_EVENT_DEVBSY;
3606 fast_path_evt->un.scsi_evt.lun = cmnd->device->lun;
3607 memcpy(&fast_path_evt->un.scsi_evt.wwpn,
3608 &pnode->nlp_portname, sizeof(struct lpfc_name));
3609 memcpy(&fast_path_evt->un.scsi_evt.wwnn,
3610 &pnode->nlp_nodename, sizeof(struct lpfc_name));
3611 } else if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen &&
3612 ((cmnd->cmnd[0] == READ_10) || (cmnd->cmnd[0] == WRITE_10))) {
3613 fast_path_evt = lpfc_alloc_fast_evt(phba);
3616 fast_path_evt->un.check_cond_evt.scsi_event.event_type =
3618 fast_path_evt->un.check_cond_evt.scsi_event.subcategory =
3619 LPFC_EVENT_CHECK_COND;
3620 fast_path_evt->un.check_cond_evt.scsi_event.lun =
3622 memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwpn,
3623 &pnode->nlp_portname, sizeof(struct lpfc_name));
3624 memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwnn,
3625 &pnode->nlp_nodename, sizeof(struct lpfc_name));
3626 fast_path_evt->un.check_cond_evt.sense_key =
3627 cmnd->sense_buffer[2] & 0xf;
3628 fast_path_evt->un.check_cond_evt.asc = cmnd->sense_buffer[12];
3629 fast_path_evt->un.check_cond_evt.ascq = cmnd->sense_buffer[13];
3630 } else if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) &&
3632 ((be32_to_cpu(fcprsp->rspResId) != fcpi_parm) ||
3633 ((scsi_status == SAM_STAT_GOOD) &&
3634 !(resp_info & (RESID_UNDER | RESID_OVER))))) {
3636 * If status is good or resid does not match with fcp_param and
3637 * there is valid fcpi_parm, then there is a read_check error
3639 fast_path_evt = lpfc_alloc_fast_evt(phba);
3642 fast_path_evt->un.read_check_error.header.event_type =
3643 FC_REG_FABRIC_EVENT;
3644 fast_path_evt->un.read_check_error.header.subcategory =
3645 LPFC_EVENT_FCPRDCHKERR;
3646 memcpy(&fast_path_evt->un.read_check_error.header.wwpn,
3647 &pnode->nlp_portname, sizeof(struct lpfc_name));
3648 memcpy(&fast_path_evt->un.read_check_error.header.wwnn,
3649 &pnode->nlp_nodename, sizeof(struct lpfc_name));
3650 fast_path_evt->un.read_check_error.lun = cmnd->device->lun;
3651 fast_path_evt->un.read_check_error.opcode = cmnd->cmnd[0];
3652 fast_path_evt->un.read_check_error.fcpiparam =
3657 fast_path_evt->vport = vport;
3658 spin_lock_irqsave(&phba->hbalock, flags);
3659 list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list);
3660 spin_unlock_irqrestore(&phba->hbalock, flags);
3661 lpfc_worker_wake_up(phba);
3666 * lpfc_scsi_unprep_dma_buf - Un-map DMA mapping of SG-list for dev
3667 * @phba: The HBA for which this call is being executed.
3668 * @psb: The scsi buffer which is going to be un-mapped.
3670 * This routine does DMA un-mapping of scatter gather list of scsi command
3671 * field of @lpfc_cmd for device with SLI-3 interface spec.
3674 lpfc_scsi_unprep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
3677 * There are only two special cases to consider. (1) the scsi command
3678 * requested scatter-gather usage or (2) the scsi command allocated
3679 * a request buffer, but did not request use_sg. There is a third
3680 * case, but it does not require resource deallocation.
3682 if (psb->seg_cnt > 0)
3683 scsi_dma_unmap(psb->pCmd);
3684 if (psb->prot_seg_cnt > 0)
3685 dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(psb->pCmd),
3686 scsi_prot_sg_count(psb->pCmd),
3687 psb->pCmd->sc_data_direction);
3691 * lpfc_handler_fcp_err - FCP response handler
3692 * @vport: The virtual port for which this call is being executed.
3693 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
3694 * @rsp_iocb: The response IOCB which contains FCP error.
3696 * This routine is called to process response IOCB with status field
3697 * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command
3698 * based upon SCSI and FCP error.
3701 lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
3702 struct lpfc_iocbq *rsp_iocb)
3704 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
3705 struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd;
3706 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
3707 uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm;
3708 uint32_t resp_info = fcprsp->rspStatus2;
3709 uint32_t scsi_status = fcprsp->rspStatus3;
3711 uint32_t host_status = DID_OK;
3712 uint32_t rsplen = 0;
3713 uint32_t logit = LOG_FCP | LOG_FCP_ERROR;
3717 * If this is a task management command, there is no
3718 * scsi packet associated with this lpfc_cmd. The driver
3721 if (fcpcmd->fcpCntl2) {
3726 if (resp_info & RSP_LEN_VALID) {
3727 rsplen = be32_to_cpu(fcprsp->rspRspLen);
3728 if (rsplen != 0 && rsplen != 4 && rsplen != 8) {
3729 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3730 "2719 Invalid response length: "
3731 "tgt x%x lun x%llx cmnd x%x rsplen x%x\n",
3733 cmnd->device->lun, cmnd->cmnd[0],
3735 host_status = DID_ERROR;
3738 if (fcprsp->rspInfo3 != RSP_NO_FAILURE) {
3739 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
3740 "2757 Protocol failure detected during "
3741 "processing of FCP I/O op: "
3742 "tgt x%x lun x%llx cmnd x%x rspInfo3 x%x\n",
3744 cmnd->device->lun, cmnd->cmnd[0],
3746 host_status = DID_ERROR;
3751 if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) {
3752 uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen);
3753 if (snslen > SCSI_SENSE_BUFFERSIZE)
3754 snslen = SCSI_SENSE_BUFFERSIZE;
3756 if (resp_info & RSP_LEN_VALID)
3757 rsplen = be32_to_cpu(fcprsp->rspRspLen);
3758 memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen);
3760 lp = (uint32_t *)cmnd->sense_buffer;
3762 /* special handling for under run conditions */
3763 if (!scsi_status && (resp_info & RESID_UNDER)) {
3764 /* don't log under runs if fcp set... */
3765 if (vport->cfg_log_verbose & LOG_FCP)
3766 logit = LOG_FCP_ERROR;
3767 /* unless operator says so */
3768 if (vport->cfg_log_verbose & LOG_FCP_UNDER)
3769 logit = LOG_FCP_UNDER;
3772 lpfc_printf_vlog(vport, KERN_WARNING, logit,
3773 "9024 FCP command x%x failed: x%x SNS x%x x%x "
3774 "Data: x%x x%x x%x x%x x%x\n",
3775 cmnd->cmnd[0], scsi_status,
3776 be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info,
3777 be32_to_cpu(fcprsp->rspResId),
3778 be32_to_cpu(fcprsp->rspSnsLen),
3779 be32_to_cpu(fcprsp->rspRspLen),
3782 scsi_set_resid(cmnd, 0);
3783 if (resp_info & RESID_UNDER) {
3784 scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId));
3786 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_UNDER,
3787 "9025 FCP Read Underrun, expected %d, "
3788 "residual %d Data: x%x x%x x%x\n",
3789 be32_to_cpu(fcpcmd->fcpDl),
3790 scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0],
3794 * If there is an under run check if under run reported by
3795 * storage array is same as the under run reported by HBA.
3796 * If this is not same, there is a dropped frame.
3798 if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) &&
3800 (scsi_get_resid(cmnd) != fcpi_parm)) {
3801 lpfc_printf_vlog(vport, KERN_WARNING,
3802 LOG_FCP | LOG_FCP_ERROR,
3803 "9026 FCP Read Check Error "
3804 "and Underrun Data: x%x x%x x%x x%x\n",
3805 be32_to_cpu(fcpcmd->fcpDl),
3806 scsi_get_resid(cmnd), fcpi_parm,
3808 scsi_set_resid(cmnd, scsi_bufflen(cmnd));
3809 host_status = DID_ERROR;
3812 * The cmnd->underflow is the minimum number of bytes that must
3813 * be transferred for this command. Provided a sense condition
3814 * is not present, make sure the actual amount transferred is at
3815 * least the underflow value or fail.
3817 if (!(resp_info & SNS_LEN_VALID) &&
3818 (scsi_status == SAM_STAT_GOOD) &&
3819 (scsi_bufflen(cmnd) - scsi_get_resid(cmnd)
3820 < cmnd->underflow)) {
3821 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
3822 "9027 FCP command x%x residual "
3823 "underrun converted to error "
3824 "Data: x%x x%x x%x\n",
3825 cmnd->cmnd[0], scsi_bufflen(cmnd),
3826 scsi_get_resid(cmnd), cmnd->underflow);
3827 host_status = DID_ERROR;
3829 } else if (resp_info & RESID_OVER) {
3830 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
3831 "9028 FCP command x%x residual overrun error. "
3832 "Data: x%x x%x\n", cmnd->cmnd[0],
3833 scsi_bufflen(cmnd), scsi_get_resid(cmnd));
3834 host_status = DID_ERROR;
3837 * Check SLI validation that all the transfer was actually done
3838 * (fcpi_parm should be zero). Apply check only to reads.
3840 } else if (fcpi_parm && (cmnd->sc_data_direction == DMA_FROM_DEVICE)) {
3841 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR,
3842 "9029 FCP Read Check Error Data: "
3843 "x%x x%x x%x x%x x%x\n",
3844 be32_to_cpu(fcpcmd->fcpDl),
3845 be32_to_cpu(fcprsp->rspResId),
3846 fcpi_parm, cmnd->cmnd[0], scsi_status);
3847 switch (scsi_status) {
3849 case SAM_STAT_CHECK_CONDITION:
3850 /* Fabric dropped a data frame. Fail any successful
3851 * command in which we detected dropped frames.
3852 * A status of good or some check conditions could
3853 * be considered a successful command.
3855 host_status = DID_ERROR;
3858 scsi_set_resid(cmnd, scsi_bufflen(cmnd));
3862 cmnd->result = ScsiResult(host_status, scsi_status);
3863 lpfc_send_scsi_error_event(vport->phba, vport, lpfc_cmd, rsp_iocb);
3867 * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine
3868 * @phba: The Hba for which this call is being executed.
3869 * @pIocbIn: The command IOCBQ for the scsi cmnd.
3870 * @pIocbOut: The response IOCBQ for the scsi cmnd.
3872 * This routine assigns scsi command result by looking into response IOCB
3873 * status field appropriately. This routine handles QUEUE FULL condition as
3874 * well by ramping down device queue depth.
3877 lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
3878 struct lpfc_iocbq *pIocbOut)
3880 struct lpfc_scsi_buf *lpfc_cmd =
3881 (struct lpfc_scsi_buf *) pIocbIn->context1;
3882 struct lpfc_vport *vport = pIocbIn->vport;
3883 struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
3884 struct lpfc_nodelist *pnode = rdata->pnode;
3885 struct scsi_cmnd *cmd;
3888 unsigned long flags;
3889 struct lpfc_fast_path_event *fast_path_evt;
3890 struct Scsi_Host *shost;
3891 uint32_t queue_depth, scsi_id;
3892 uint32_t logit = LOG_FCP;
3894 /* Sanity check on return of outstanding command */
3895 if (!(lpfc_cmd->pCmd))
3897 cmd = lpfc_cmd->pCmd;
3898 shost = cmd->device->host;
3900 lpfc_cmd->result = (pIocbOut->iocb.un.ulpWord[4] & IOERR_PARAM_MASK);
3901 lpfc_cmd->status = pIocbOut->iocb.ulpStatus;
3902 /* pick up SLI4 exhange busy status from HBA */
3903 lpfc_cmd->exch_busy = pIocbOut->iocb_flag & LPFC_EXCHANGE_BUSY;
3905 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3906 if (lpfc_cmd->prot_data_type) {
3907 struct scsi_dif_tuple *src = NULL;
3909 src = (struct scsi_dif_tuple *)lpfc_cmd->prot_data_segment;
3911 * Used to restore any changes to protection
3912 * data for error injection.
3914 switch (lpfc_cmd->prot_data_type) {
3915 case LPFC_INJERR_REFTAG:
3917 lpfc_cmd->prot_data;
3919 case LPFC_INJERR_APPTAG:
3921 (uint16_t)lpfc_cmd->prot_data;
3923 case LPFC_INJERR_GUARD:
3925 (uint16_t)lpfc_cmd->prot_data;
3931 lpfc_cmd->prot_data = 0;
3932 lpfc_cmd->prot_data_type = 0;
3933 lpfc_cmd->prot_data_segment = NULL;
3936 if (pnode && NLP_CHK_NODE_ACT(pnode))
3937 atomic_dec(&pnode->cmd_pending);
3939 if (lpfc_cmd->status) {
3940 if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT &&
3941 (lpfc_cmd->result & IOERR_DRVR_MASK))
3942 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
3943 else if (lpfc_cmd->status >= IOSTAT_CNT)
3944 lpfc_cmd->status = IOSTAT_DEFAULT;
3945 if (lpfc_cmd->status == IOSTAT_FCP_RSP_ERROR &&
3946 !lpfc_cmd->fcp_rsp->rspStatus3 &&
3947 (lpfc_cmd->fcp_rsp->rspStatus2 & RESID_UNDER) &&
3948 !(vport->cfg_log_verbose & LOG_FCP_UNDER))
3951 logit = LOG_FCP | LOG_FCP_UNDER;
3952 lpfc_printf_vlog(vport, KERN_WARNING, logit,
3953 "9030 FCP cmd x%x failed <%d/%lld> "
3954 "status: x%x result: x%x "
3955 "sid: x%x did: x%x oxid: x%x "
3958 cmd->device ? cmd->device->id : 0xffff,
3959 cmd->device ? cmd->device->lun : 0xffff,
3960 lpfc_cmd->status, lpfc_cmd->result,
3962 (pnode) ? pnode->nlp_DID : 0,
3963 phba->sli_rev == LPFC_SLI_REV4 ?
3964 lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff,
3965 pIocbOut->iocb.ulpContext,
3966 lpfc_cmd->cur_iocbq.iocb.ulpIoTag);
3968 switch (lpfc_cmd->status) {
3969 case IOSTAT_FCP_RSP_ERROR:
3970 /* Call FCP RSP handler to determine result */
3971 lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut);
3973 case IOSTAT_NPORT_BSY:
3974 case IOSTAT_FABRIC_BSY:
3975 cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 0);
3976 fast_path_evt = lpfc_alloc_fast_evt(phba);
3979 fast_path_evt->un.fabric_evt.event_type =
3980 FC_REG_FABRIC_EVENT;
3981 fast_path_evt->un.fabric_evt.subcategory =
3982 (lpfc_cmd->status == IOSTAT_NPORT_BSY) ?
3983 LPFC_EVENT_PORT_BUSY : LPFC_EVENT_FABRIC_BUSY;
3984 if (pnode && NLP_CHK_NODE_ACT(pnode)) {
3985 memcpy(&fast_path_evt->un.fabric_evt.wwpn,
3986 &pnode->nlp_portname,
3987 sizeof(struct lpfc_name));
3988 memcpy(&fast_path_evt->un.fabric_evt.wwnn,
3989 &pnode->nlp_nodename,
3990 sizeof(struct lpfc_name));
3992 fast_path_evt->vport = vport;
3993 fast_path_evt->work_evt.evt =
3994 LPFC_EVT_FASTPATH_MGMT_EVT;
3995 spin_lock_irqsave(&phba->hbalock, flags);
3996 list_add_tail(&fast_path_evt->work_evt.evt_listp,
3998 spin_unlock_irqrestore(&phba->hbalock, flags);
3999 lpfc_worker_wake_up(phba);
4001 case IOSTAT_LOCAL_REJECT:
4002 case IOSTAT_REMOTE_STOP:
4003 if (lpfc_cmd->result == IOERR_ELXSEC_KEY_UNWRAP_ERROR ||
4005 IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR ||
4006 lpfc_cmd->result == IOERR_ELXSEC_CRYPTO_ERROR ||
4008 IOERR_ELXSEC_CRYPTO_COMPARE_ERROR) {
4009 cmd->result = ScsiResult(DID_NO_CONNECT, 0);
4012 if (lpfc_cmd->result == IOERR_INVALID_RPI ||
4013 lpfc_cmd->result == IOERR_NO_RESOURCES ||
4014 lpfc_cmd->result == IOERR_ABORT_REQUESTED ||
4015 lpfc_cmd->result == IOERR_SLER_CMD_RCV_FAILURE) {
4016 cmd->result = ScsiResult(DID_REQUEUE, 0);
4019 if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED ||
4020 lpfc_cmd->result == IOERR_TX_DMA_FAILED) &&
4021 pIocbOut->iocb.unsli3.sli3_bg.bgstat) {
4022 if (scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
4024 * This is a response for a BG enabled
4025 * cmd. Parse BG error
4027 lpfc_parse_bg_err(phba, lpfc_cmd,
4031 lpfc_printf_vlog(vport, KERN_WARNING,
4033 "9031 non-zero BGSTAT "
4034 "on unprotected cmd\n");
4037 if ((lpfc_cmd->status == IOSTAT_REMOTE_STOP)
4038 && (phba->sli_rev == LPFC_SLI_REV4)
4039 && (pnode && NLP_CHK_NODE_ACT(pnode))) {
4040 /* This IO was aborted by the target, we don't
4041 * know the rxid and because we did not send the
4042 * ABTS we cannot generate and RRQ.
4044 lpfc_set_rrq_active(phba, pnode,
4045 lpfc_cmd->cur_iocbq.sli4_lxritag,
4048 /* else: fall through */
4050 cmd->result = ScsiResult(DID_ERROR, 0);
4054 if (!pnode || !NLP_CHK_NODE_ACT(pnode)
4055 || (pnode->nlp_state != NLP_STE_MAPPED_NODE))
4056 cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED,
4059 cmd->result = ScsiResult(DID_OK, 0);
4061 if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) {
4062 uint32_t *lp = (uint32_t *)cmd->sense_buffer;
4064 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4065 "0710 Iodone <%d/%llu> cmd %p, error "
4066 "x%x SNS x%x x%x Data: x%x x%x\n",
4067 cmd->device->id, cmd->device->lun, cmd,
4068 cmd->result, *lp, *(lp + 3), cmd->retries,
4069 scsi_get_resid(cmd));
4072 lpfc_update_stats(phba, lpfc_cmd);
4073 result = cmd->result;
4074 if (vport->cfg_max_scsicmpl_time &&
4075 time_after(jiffies, lpfc_cmd->start_time +
4076 msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) {
4077 spin_lock_irqsave(shost->host_lock, flags);
4078 if (pnode && NLP_CHK_NODE_ACT(pnode)) {
4079 if (pnode->cmd_qdepth >
4080 atomic_read(&pnode->cmd_pending) &&
4081 (atomic_read(&pnode->cmd_pending) >
4082 LPFC_MIN_TGT_QDEPTH) &&
4083 ((cmd->cmnd[0] == READ_10) ||
4084 (cmd->cmnd[0] == WRITE_10)))
4086 atomic_read(&pnode->cmd_pending);
4088 pnode->last_change_time = jiffies;
4090 spin_unlock_irqrestore(shost->host_lock, flags);
4091 } else if (pnode && NLP_CHK_NODE_ACT(pnode)) {
4092 if ((pnode->cmd_qdepth < vport->cfg_tgt_queue_depth) &&
4093 time_after(jiffies, pnode->last_change_time +
4094 msecs_to_jiffies(LPFC_TGTQ_INTERVAL))) {
4095 spin_lock_irqsave(shost->host_lock, flags);
4096 depth = pnode->cmd_qdepth * LPFC_TGTQ_RAMPUP_PCENT
4098 depth = depth ? depth : 1;
4099 pnode->cmd_qdepth += depth;
4100 if (pnode->cmd_qdepth > vport->cfg_tgt_queue_depth)
4101 pnode->cmd_qdepth = vport->cfg_tgt_queue_depth;
4102 pnode->last_change_time = jiffies;
4103 spin_unlock_irqrestore(shost->host_lock, flags);
4107 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
4109 /* The sdev is not guaranteed to be valid post scsi_done upcall. */
4110 queue_depth = cmd->device->queue_depth;
4111 scsi_id = cmd->device->id;
4112 cmd->scsi_done(cmd);
4114 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
4115 spin_lock_irqsave(&phba->hbalock, flags);
4116 lpfc_cmd->pCmd = NULL;
4117 spin_unlock_irqrestore(&phba->hbalock, flags);
4120 * If there is a thread waiting for command completion
4121 * wake up the thread.
4123 spin_lock_irqsave(shost->host_lock, flags);
4124 if (lpfc_cmd->waitq)
4125 wake_up(lpfc_cmd->waitq);
4126 spin_unlock_irqrestore(shost->host_lock, flags);
4127 lpfc_release_scsi_buf(phba, lpfc_cmd);
4131 spin_lock_irqsave(&phba->hbalock, flags);
4132 lpfc_cmd->pCmd = NULL;
4133 spin_unlock_irqrestore(&phba->hbalock, flags);
4136 * If there is a thread waiting for command completion
4137 * wake up the thread.
4139 spin_lock_irqsave(shost->host_lock, flags);
4140 if (lpfc_cmd->waitq)
4141 wake_up(lpfc_cmd->waitq);
4142 spin_unlock_irqrestore(shost->host_lock, flags);
4144 lpfc_release_scsi_buf(phba, lpfc_cmd);
4148 * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB
4149 * @data: A pointer to the immediate command data portion of the IOCB.
4150 * @fcp_cmnd: The FCP Command that is provided by the SCSI layer.
4152 * The routine copies the entire FCP command from @fcp_cmnd to @data while
4153 * byte swapping the data to big endian format for transmission on the wire.
4156 lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd)
4159 for (i = 0, j = 0; i < sizeof(struct fcp_cmnd);
4160 i += sizeof(uint32_t), j++) {
4161 ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]);
4166 * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit
4167 * @vport: The virtual port for which this call is being executed.
4168 * @lpfc_cmd: The scsi command which needs to send.
4169 * @pnode: Pointer to lpfc_nodelist.
4171 * This routine initializes fcp_cmnd and iocb data structure from scsi command
4172 * to transfer for device with SLI3 interface spec.
4175 lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
4176 struct lpfc_nodelist *pnode)
4178 struct lpfc_hba *phba = vport->phba;
4179 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
4180 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
4181 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
4182 struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq);
4183 int datadir = scsi_cmnd->sc_data_direction;
4188 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
4191 lpfc_cmd->fcp_rsp->rspSnsLen = 0;
4192 /* clear task management bits */
4193 lpfc_cmd->fcp_cmnd->fcpCntl2 = 0;
4195 int_to_scsilun(lpfc_cmd->pCmd->device->lun,
4196 &lpfc_cmd->fcp_cmnd->fcp_lun);
4198 ptr = &fcp_cmnd->fcpCdb[0];
4199 memcpy(ptr, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
4200 if (scsi_cmnd->cmd_len < LPFC_FCP_CDB_LEN) {
4201 ptr += scsi_cmnd->cmd_len;
4202 memset(ptr, 0, (LPFC_FCP_CDB_LEN - scsi_cmnd->cmd_len));
4205 fcp_cmnd->fcpCntl1 = SIMPLE_Q;
4207 sli4 = (phba->sli_rev == LPFC_SLI_REV4);
4208 piocbq->iocb.un.fcpi.fcpi_XRdy = 0;
4211 * There are three possibilities here - use scatter-gather segment, use
4212 * the single mapping, or neither. Start the lpfc command prep by
4213 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
4216 if (scsi_sg_count(scsi_cmnd)) {
4217 if (datadir == DMA_TO_DEVICE) {
4218 iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR;
4219 iocb_cmd->ulpPU = PARM_READ_CHECK;
4220 if (vport->cfg_first_burst_size &&
4221 (pnode->nlp_flag & NLP_FIRSTBURST)) {
4222 fcpdl = scsi_bufflen(scsi_cmnd);
4223 if (fcpdl < vport->cfg_first_burst_size)
4224 piocbq->iocb.un.fcpi.fcpi_XRdy = fcpdl;
4226 piocbq->iocb.un.fcpi.fcpi_XRdy =
4227 vport->cfg_first_burst_size;
4229 fcp_cmnd->fcpCntl3 = WRITE_DATA;
4230 phba->fc4OutputRequests++;
4232 iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR;
4233 iocb_cmd->ulpPU = PARM_READ_CHECK;
4234 fcp_cmnd->fcpCntl3 = READ_DATA;
4235 phba->fc4InputRequests++;
4238 iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR;
4239 iocb_cmd->un.fcpi.fcpi_parm = 0;
4240 iocb_cmd->ulpPU = 0;
4241 fcp_cmnd->fcpCntl3 = 0;
4242 phba->fc4ControlRequests++;
4244 if (phba->sli_rev == 3 &&
4245 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED))
4246 lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd);
4248 * Finish initializing those IOCB fields that are independent
4249 * of the scsi_cmnd request_buffer
4251 piocbq->iocb.ulpContext = pnode->nlp_rpi;
4253 piocbq->iocb.ulpContext =
4254 phba->sli4_hba.rpi_ids[pnode->nlp_rpi];
4255 if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE)
4256 piocbq->iocb.ulpFCP2Rcvy = 1;
4258 piocbq->iocb.ulpFCP2Rcvy = 0;
4260 piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f);
4261 piocbq->context1 = lpfc_cmd;
4262 piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
4263 piocbq->iocb.ulpTimeout = lpfc_cmd->timeout;
4264 piocbq->vport = vport;
4268 * lpfc_scsi_prep_task_mgmt_cmd - Convert SLI3 scsi TM cmd to FCP info unit
4269 * @vport: The virtual port for which this call is being executed.
4270 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
4271 * @lun: Logical unit number.
4272 * @task_mgmt_cmd: SCSI task management command.
4274 * This routine creates FCP information unit corresponding to @task_mgmt_cmd
4275 * for device with SLI-3 interface spec.
4282 lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport,
4283 struct lpfc_scsi_buf *lpfc_cmd,
4285 uint8_t task_mgmt_cmd)
4287 struct lpfc_iocbq *piocbq;
4289 struct fcp_cmnd *fcp_cmnd;
4290 struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
4291 struct lpfc_nodelist *ndlp = rdata->pnode;
4293 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) ||
4294 ndlp->nlp_state != NLP_STE_MAPPED_NODE)
4297 piocbq = &(lpfc_cmd->cur_iocbq);
4298 piocbq->vport = vport;
4300 piocb = &piocbq->iocb;
4302 fcp_cmnd = lpfc_cmd->fcp_cmnd;
4303 /* Clear out any old data in the FCP command area */
4304 memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd));
4305 int_to_scsilun(lun, &fcp_cmnd->fcp_lun);
4306 fcp_cmnd->fcpCntl2 = task_mgmt_cmd;
4307 if (vport->phba->sli_rev == 3 &&
4308 !(vport->phba->sli3_options & LPFC_SLI3_BG_ENABLED))
4309 lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd);
4310 piocb->ulpCommand = CMD_FCP_ICMND64_CR;
4311 piocb->ulpContext = ndlp->nlp_rpi;
4312 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
4314 vport->phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
4316 piocb->ulpFCP2Rcvy = (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) ? 1 : 0;
4317 piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f);
4319 piocb->un.fcpi.fcpi_parm = 0;
4321 /* ulpTimeout is only one byte */
4322 if (lpfc_cmd->timeout > 0xff) {
4324 * Do not timeout the command at the firmware level.
4325 * The driver will provide the timeout mechanism.
4327 piocb->ulpTimeout = 0;
4329 piocb->ulpTimeout = lpfc_cmd->timeout;
4331 if (vport->phba->sli_rev == LPFC_SLI_REV4)
4332 lpfc_sli4_set_rsp_sgl_last(vport->phba, lpfc_cmd);
4338 * lpfc_scsi_api_table_setup - Set up scsi api function jump table
4339 * @phba: The hba struct for which this call is being executed.
4340 * @dev_grp: The HBA PCI-Device group number.
4342 * This routine sets up the SCSI interface API function jump table in @phba
4344 * Returns: 0 - success, -ENODEV - failure.
4347 lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
4350 phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf;
4351 phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd;
4354 case LPFC_PCI_DEV_LP:
4355 phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s3;
4356 phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3;
4357 phba->lpfc_bg_scsi_prep_dma_buf = lpfc_bg_scsi_prep_dma_buf_s3;
4358 phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3;
4359 phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s3;
4361 case LPFC_PCI_DEV_OC:
4362 phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s4;
4363 phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s4;
4364 phba->lpfc_bg_scsi_prep_dma_buf = lpfc_bg_scsi_prep_dma_buf_s4;
4365 phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s4;
4366 phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s4;
4369 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4370 "1418 Invalid HBA PCI-device group: 0x%x\n",
4375 phba->lpfc_rampdown_queue_depth = lpfc_rampdown_queue_depth;
4376 phba->lpfc_scsi_cmd_iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
4381 * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command
4382 * @phba: The Hba for which this call is being executed.
4383 * @cmdiocbq: Pointer to lpfc_iocbq data structure.
4384 * @rspiocbq: Pointer to lpfc_iocbq data structure.
4386 * This routine is IOCB completion routine for device reset and target reset
4387 * routine. This routine release scsi buffer associated with lpfc_cmd.
4390 lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba,
4391 struct lpfc_iocbq *cmdiocbq,
4392 struct lpfc_iocbq *rspiocbq)
4394 struct lpfc_scsi_buf *lpfc_cmd =
4395 (struct lpfc_scsi_buf *) cmdiocbq->context1;
4397 lpfc_release_scsi_buf(phba, lpfc_cmd);
4402 * lpfc_info - Info entry point of scsi_host_template data structure
4403 * @host: The scsi host for which this call is being executed.
4405 * This routine provides module information about hba.
4408 * Pointer to char - Success.
4411 lpfc_info(struct Scsi_Host *host)
4413 struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata;
4414 struct lpfc_hba *phba = vport->phba;
4415 int len, link_speed = 0;
4416 static char lpfcinfobuf[384];
4418 memset(lpfcinfobuf,0,384);
4419 if (phba && phba->pcidev){
4420 strncpy(lpfcinfobuf, phba->ModelDesc, 256);
4421 len = strlen(lpfcinfobuf);
4422 snprintf(lpfcinfobuf + len,
4424 " on PCI bus %02x device %02x irq %d",
4425 phba->pcidev->bus->number,
4426 phba->pcidev->devfn,
4428 len = strlen(lpfcinfobuf);
4429 if (phba->Port[0]) {
4430 snprintf(lpfcinfobuf + len,
4435 len = strlen(lpfcinfobuf);
4436 if (phba->sli_rev <= LPFC_SLI_REV3) {
4437 link_speed = lpfc_sli_port_speed_get(phba);
4439 if (phba->sli4_hba.link_state.logical_speed)
4441 phba->sli4_hba.link_state.logical_speed;
4443 link_speed = phba->sli4_hba.link_state.speed;
4445 if (link_speed != 0)
4446 snprintf(lpfcinfobuf + len, 384-len,
4447 " Logical Link Speed: %d Mbps", link_speed);
4453 * lpfc_poll_rearm_time - Routine to modify fcp_poll timer of hba
4454 * @phba: The Hba for which this call is being executed.
4456 * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo.
4457 * The default value of cfg_poll_tmo is 10 milliseconds.
4459 static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba)
4461 unsigned long poll_tmo_expires =
4462 (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo));
4464 if (!list_empty(&phba->sli.ring[LPFC_FCP_RING].txcmplq))
4465 mod_timer(&phba->fcp_poll_timer,
4470 * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA
4471 * @phba: The Hba for which this call is being executed.
4473 * This routine starts the fcp_poll_timer of @phba.
4475 void lpfc_poll_start_timer(struct lpfc_hba * phba)
4477 lpfc_poll_rearm_timer(phba);
4481 * lpfc_poll_timeout - Restart polling timer
4482 * @ptr: Map to lpfc_hba data structure pointer.
4484 * This routine restarts fcp_poll timer, when FCP ring polling is enable
4485 * and FCP Ring interrupt is disable.
4488 void lpfc_poll_timeout(unsigned long ptr)
4490 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
4492 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
4493 lpfc_sli_handle_fast_ring_event(phba,
4494 &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
4496 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
4497 lpfc_poll_rearm_timer(phba);
4502 * lpfc_queuecommand - scsi_host_template queuecommand entry point
4503 * @cmnd: Pointer to scsi_cmnd data structure.
4504 * @done: Pointer to done routine.
4506 * Driver registers this routine to scsi midlayer to submit a @cmd to process.
4507 * This routine prepares an IOCB from scsi command and provides to firmware.
4508 * The @done callback is invoked after driver finished processing the command.
4512 * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily.
4515 lpfc_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *cmnd)
4517 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4518 struct lpfc_hba *phba = vport->phba;
4519 struct lpfc_rport_data *rdata;
4520 struct lpfc_nodelist *ndlp;
4521 struct lpfc_scsi_buf *lpfc_cmd;
4522 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
4525 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
4526 err = fc_remote_port_chkready(rport);
4529 goto out_fail_command;
4531 ndlp = rdata->pnode;
4533 if ((scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) &&
4534 (!(phba->sli3_options & LPFC_SLI3_BG_ENABLED))) {
4536 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
4537 "9058 BLKGRD: ERROR: rcvd protected cmd:%02x"
4538 " op:%02x str=%s without registering for"
4539 " BlockGuard - Rejecting command\n",
4540 cmnd->cmnd[0], scsi_get_prot_op(cmnd),
4541 dif_op_str[scsi_get_prot_op(cmnd)]);
4542 goto out_fail_command;
4546 * Catch race where our node has transitioned, but the
4547 * transport is still transitioning.
4549 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
4551 if (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth)
4554 lpfc_cmd = lpfc_get_scsi_buf(phba, ndlp);
4555 if (lpfc_cmd == NULL) {
4556 lpfc_rampdown_queue_depth(phba);
4558 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4559 "0707 driver's buffer pool is empty, "
4565 * Store the midlayer's command structure for the completion phase
4566 * and complete the command initialization.
4568 lpfc_cmd->pCmd = cmnd;
4569 lpfc_cmd->rdata = rdata;
4570 lpfc_cmd->timeout = 0;
4571 lpfc_cmd->start_time = jiffies;
4572 cmnd->host_scribble = (unsigned char *)lpfc_cmd;
4574 if (scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) {
4575 if (vport->phba->cfg_enable_bg) {
4576 lpfc_printf_vlog(vport,
4577 KERN_INFO, LOG_SCSI_CMD,
4578 "9033 BLKGRD: rcvd %s cmd:x%x "
4579 "sector x%llx cnt %u pt %x\n",
4580 dif_op_str[scsi_get_prot_op(cmnd)],
4582 (unsigned long long)scsi_get_lba(cmnd),
4583 blk_rq_sectors(cmnd->request),
4584 (cmnd->cmnd[1]>>5));
4586 err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd);
4588 if (vport->phba->cfg_enable_bg) {
4589 lpfc_printf_vlog(vport,
4590 KERN_INFO, LOG_SCSI_CMD,
4591 "9038 BLKGRD: rcvd PROT_NORMAL cmd: "
4592 "x%x sector x%llx cnt %u pt %x\n",
4594 (unsigned long long)scsi_get_lba(cmnd),
4595 blk_rq_sectors(cmnd->request),
4596 (cmnd->cmnd[1]>>5));
4598 err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd);
4602 goto out_host_busy_free_buf;
4604 lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp);
4606 atomic_inc(&ndlp->cmd_pending);
4607 err = lpfc_sli_issue_iocb(phba, LPFC_FCP_RING,
4608 &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB);
4610 atomic_dec(&ndlp->cmd_pending);
4611 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4612 "3376 FCP could not issue IOCB err %x"
4613 "FCP cmd x%x <%d/%llu> "
4614 "sid: x%x did: x%x oxid: x%x "
4615 "Data: x%x x%x x%x x%x\n",
4617 cmnd->device ? cmnd->device->id : 0xffff,
4618 cmnd->device ? cmnd->device->lun : (u64) -1,
4619 vport->fc_myDID, ndlp->nlp_DID,
4620 phba->sli_rev == LPFC_SLI_REV4 ?
4621 lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff,
4622 lpfc_cmd->cur_iocbq.iocb.ulpContext,
4623 lpfc_cmd->cur_iocbq.iocb.ulpIoTag,
4624 lpfc_cmd->cur_iocbq.iocb.ulpTimeout,
4626 (cmnd->request->timeout / 1000));
4629 goto out_host_busy_free_buf;
4631 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
4632 lpfc_sli_handle_fast_ring_event(phba,
4633 &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
4635 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
4636 lpfc_poll_rearm_timer(phba);
4641 out_host_busy_free_buf:
4642 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
4643 lpfc_release_scsi_buf(phba, lpfc_cmd);
4645 return SCSI_MLQUEUE_HOST_BUSY;
4648 return SCSI_MLQUEUE_TARGET_BUSY;
4651 cmnd->scsi_done(cmnd);
4657 * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point
4658 * @cmnd: Pointer to scsi_cmnd data structure.
4660 * This routine aborts @cmnd pending in base driver.
4667 lpfc_abort_handler(struct scsi_cmnd *cmnd)
4669 struct Scsi_Host *shost = cmnd->device->host;
4670 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4671 struct lpfc_hba *phba = vport->phba;
4672 struct lpfc_iocbq *iocb;
4673 struct lpfc_iocbq *abtsiocb;
4674 struct lpfc_scsi_buf *lpfc_cmd;
4676 int ret = SUCCESS, status = 0;
4677 struct lpfc_sli_ring *pring_s4;
4678 int ring_number, ret_val;
4679 unsigned long flags, iflags;
4680 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq);
4682 status = fc_block_scsi_eh(cmnd);
4683 if (status != 0 && status != SUCCESS)
4686 spin_lock_irqsave(&phba->hbalock, flags);
4687 /* driver queued commands are in process of being flushed */
4688 if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) {
4689 spin_unlock_irqrestore(&phba->hbalock, flags);
4690 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4691 "3168 SCSI Layer abort requested I/O has been "
4692 "flushed by LLD.\n");
4696 lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble;
4697 if (!lpfc_cmd || !lpfc_cmd->pCmd) {
4698 spin_unlock_irqrestore(&phba->hbalock, flags);
4699 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4700 "2873 SCSI Layer I/O Abort Request IO CMPL Status "
4701 "x%x ID %d LUN %llu\n",
4702 SUCCESS, cmnd->device->id, cmnd->device->lun);
4706 iocb = &lpfc_cmd->cur_iocbq;
4707 /* the command is in process of being cancelled */
4708 if (!(iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ)) {
4709 spin_unlock_irqrestore(&phba->hbalock, flags);
4710 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4711 "3169 SCSI Layer abort requested I/O has been "
4712 "cancelled by LLD.\n");
4716 * If pCmd field of the corresponding lpfc_scsi_buf structure
4717 * points to a different SCSI command, then the driver has
4718 * already completed this command, but the midlayer did not
4719 * see the completion before the eh fired. Just return SUCCESS.
4721 if (lpfc_cmd->pCmd != cmnd) {
4722 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4723 "3170 SCSI Layer abort requested I/O has been "
4724 "completed by LLD.\n");
4728 BUG_ON(iocb->context1 != lpfc_cmd);
4730 /* abort issued in recovery is still in progress */
4731 if (iocb->iocb_flag & LPFC_DRIVER_ABORTED) {
4732 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4733 "3389 SCSI Layer I/O Abort Request is pending\n");
4734 spin_unlock_irqrestore(&phba->hbalock, flags);
4738 abtsiocb = __lpfc_sli_get_iocbq(phba);
4739 if (abtsiocb == NULL) {
4744 /* Indicate the IO is being aborted by the driver. */
4745 iocb->iocb_flag |= LPFC_DRIVER_ABORTED;
4748 * The scsi command can not be in txq and it is in flight because the
4749 * pCmd is still pointig at the SCSI command we have to abort. There
4750 * is no need to search the txcmplq. Just send an abort to the FW.
4754 icmd = &abtsiocb->iocb;
4755 icmd->un.acxri.abortType = ABORT_TYPE_ABTS;
4756 icmd->un.acxri.abortContextTag = cmd->ulpContext;
4757 if (phba->sli_rev == LPFC_SLI_REV4)
4758 icmd->un.acxri.abortIoTag = iocb->sli4_xritag;
4760 icmd->un.acxri.abortIoTag = cmd->ulpIoTag;
4763 icmd->ulpClass = cmd->ulpClass;
4765 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
4766 abtsiocb->fcp_wqidx = iocb->fcp_wqidx;
4767 abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
4768 if (iocb->iocb_flag & LPFC_IO_FOF)
4769 abtsiocb->iocb_flag |= LPFC_IO_FOF;
4771 if (lpfc_is_link_up(phba))
4772 icmd->ulpCommand = CMD_ABORT_XRI_CN;
4774 icmd->ulpCommand = CMD_CLOSE_XRI_CN;
4776 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
4777 abtsiocb->vport = vport;
4778 if (phba->sli_rev == LPFC_SLI_REV4) {
4779 ring_number = MAX_SLI3_CONFIGURED_RINGS + iocb->fcp_wqidx;
4780 pring_s4 = &phba->sli.ring[ring_number];
4781 /* Note: both hbalock and ring_lock must be set here */
4782 spin_lock_irqsave(&pring_s4->ring_lock, iflags);
4783 ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno,
4785 spin_unlock_irqrestore(&pring_s4->ring_lock, iflags);
4787 ret_val = __lpfc_sli_issue_iocb(phba, LPFC_FCP_RING,
4790 /* no longer need the lock after this point */
4791 spin_unlock_irqrestore(&phba->hbalock, flags);
4794 if (ret_val == IOCB_ERROR) {
4795 lpfc_sli_release_iocbq(phba, abtsiocb);
4800 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
4801 lpfc_sli_handle_fast_ring_event(phba,
4802 &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
4805 lpfc_cmd->waitq = &waitq;
4806 /* Wait for abort to complete */
4807 wait_event_timeout(waitq,
4808 (lpfc_cmd->pCmd != cmnd),
4809 msecs_to_jiffies(2*vport->cfg_devloss_tmo*1000));
4811 spin_lock_irqsave(shost->host_lock, flags);
4812 lpfc_cmd->waitq = NULL;
4813 spin_unlock_irqrestore(shost->host_lock, flags);
4815 if (lpfc_cmd->pCmd == cmnd) {
4817 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
4818 "0748 abort handler timed out waiting "
4819 "for abortng I/O (xri:x%x) to complete: "
4820 "ret %#x, ID %d, LUN %llu\n",
4821 iocb->sli4_xritag, ret,
4822 cmnd->device->id, cmnd->device->lun);
4827 spin_unlock_irqrestore(&phba->hbalock, flags);
4829 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
4830 "0749 SCSI Layer I/O Abort Request Status x%x ID %d "
4831 "LUN %llu\n", ret, cmnd->device->id,
4837 lpfc_taskmgmt_name(uint8_t task_mgmt_cmd)
4839 switch (task_mgmt_cmd) {
4840 case FCP_ABORT_TASK_SET:
4841 return "ABORT_TASK_SET";
4842 case FCP_CLEAR_TASK_SET:
4843 return "FCP_CLEAR_TASK_SET";
4845 return "FCP_BUS_RESET";
4847 return "FCP_LUN_RESET";
4848 case FCP_TARGET_RESET:
4849 return "FCP_TARGET_RESET";
4851 return "FCP_CLEAR_ACA";
4852 case FCP_TERMINATE_TASK:
4853 return "FCP_TERMINATE_TASK";
4861 * lpfc_check_fcp_rsp - check the returned fcp_rsp to see if task failed
4862 * @vport: The virtual port for which this call is being executed.
4863 * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
4865 * This routine checks the FCP RSP INFO to see if the tsk mgmt command succeded
4872 lpfc_check_fcp_rsp(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd)
4874 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
4877 uint8_t rsp_info_code;
4882 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4883 "0703 fcp_rsp is missing\n");
4885 rsp_info = fcprsp->rspStatus2;
4886 rsp_len = be32_to_cpu(fcprsp->rspRspLen);
4887 rsp_info_code = fcprsp->rspInfo3;
4890 lpfc_printf_vlog(vport, KERN_INFO,
4892 "0706 fcp_rsp valid 0x%x,"
4893 " rsp len=%d code 0x%x\n",
4895 rsp_len, rsp_info_code);
4897 if ((fcprsp->rspStatus2&RSP_LEN_VALID) && (rsp_len == 8)) {
4898 switch (rsp_info_code) {
4899 case RSP_NO_FAILURE:
4900 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4901 "0715 Task Mgmt No Failure\n");
4904 case RSP_TM_NOT_SUPPORTED: /* TM rejected */
4905 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4906 "0716 Task Mgmt Target "
4909 case RSP_TM_NOT_COMPLETED: /* TM failed */
4910 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4911 "0717 Task Mgmt Target "
4914 case RSP_TM_INVALID_LU: /* TM to invalid LU! */
4915 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4916 "0718 Task Mgmt to invalid "
4927 * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler
4928 * @vport: The virtual port for which this call is being executed.
4929 * @rdata: Pointer to remote port local data
4930 * @tgt_id: Target ID of remote device.
4931 * @lun_id: Lun number for the TMF
4932 * @task_mgmt_cmd: type of TMF to send
4934 * This routine builds and sends a TMF (SCSI Task Mgmt Function) to
4942 lpfc_send_taskmgmt(struct lpfc_vport *vport, struct lpfc_rport_data *rdata,
4943 unsigned tgt_id, uint64_t lun_id,
4944 uint8_t task_mgmt_cmd)
4946 struct lpfc_hba *phba = vport->phba;
4947 struct lpfc_scsi_buf *lpfc_cmd;
4948 struct lpfc_iocbq *iocbq;
4949 struct lpfc_iocbq *iocbqrsp;
4950 struct lpfc_nodelist *pnode = rdata->pnode;
4954 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
4957 lpfc_cmd = lpfc_get_scsi_buf(phba, rdata->pnode);
4958 if (lpfc_cmd == NULL)
4960 lpfc_cmd->timeout = phba->cfg_task_mgmt_tmo;
4961 lpfc_cmd->rdata = rdata;
4963 status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun_id,
4966 lpfc_release_scsi_buf(phba, lpfc_cmd);
4970 iocbq = &lpfc_cmd->cur_iocbq;
4971 iocbqrsp = lpfc_sli_get_iocbq(phba);
4972 if (iocbqrsp == NULL) {
4973 lpfc_release_scsi_buf(phba, lpfc_cmd);
4976 iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
4978 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
4979 "0702 Issue %s to TGT %d LUN %llu "
4980 "rpi x%x nlp_flag x%x Data: x%x x%x\n",
4981 lpfc_taskmgmt_name(task_mgmt_cmd), tgt_id, lun_id,
4982 pnode->nlp_rpi, pnode->nlp_flag, iocbq->sli4_xritag,
4985 status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING,
4986 iocbq, iocbqrsp, lpfc_cmd->timeout);
4987 if ((status != IOCB_SUCCESS) ||
4988 (iocbqrsp->iocb.ulpStatus != IOSTAT_SUCCESS)) {
4989 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
4990 "0727 TMF %s to TGT %d LUN %llu failed (%d, %d) "
4992 lpfc_taskmgmt_name(task_mgmt_cmd),
4993 tgt_id, lun_id, iocbqrsp->iocb.ulpStatus,
4994 iocbqrsp->iocb.un.ulpWord[4],
4996 /* if ulpStatus != IOCB_SUCCESS, then status == IOCB_SUCCESS */
4997 if (status == IOCB_SUCCESS) {
4998 if (iocbqrsp->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
4999 /* Something in the FCP_RSP was invalid.
5000 * Check conditions */
5001 ret = lpfc_check_fcp_rsp(vport, lpfc_cmd);
5004 } else if (status == IOCB_TIMEDOUT) {
5005 ret = TIMEOUT_ERROR;
5009 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
5013 lpfc_sli_release_iocbq(phba, iocbqrsp);
5015 if (ret != TIMEOUT_ERROR)
5016 lpfc_release_scsi_buf(phba, lpfc_cmd);
5022 * lpfc_chk_tgt_mapped -
5023 * @vport: The virtual port to check on
5024 * @cmnd: Pointer to scsi_cmnd data structure.
5026 * This routine delays until the scsi target (aka rport) for the
5027 * command exists (is present and logged in) or we declare it non-existent.
5034 lpfc_chk_tgt_mapped(struct lpfc_vport *vport, struct scsi_cmnd *cmnd)
5036 struct lpfc_rport_data *rdata;
5037 struct lpfc_nodelist *pnode;
5038 unsigned long later;
5040 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
5042 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
5043 "0797 Tgt Map rport failure: rdata x%p\n", rdata);
5046 pnode = rdata->pnode;
5048 * If target is not in a MAPPED state, delay until
5049 * target is rediscovered or devloss timeout expires.
5051 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
5052 while (time_after(later, jiffies)) {
5053 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
5055 if (pnode->nlp_state == NLP_STE_MAPPED_NODE)
5057 schedule_timeout_uninterruptible(msecs_to_jiffies(500));
5058 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
5061 pnode = rdata->pnode;
5063 if (!pnode || !NLP_CHK_NODE_ACT(pnode) ||
5064 (pnode->nlp_state != NLP_STE_MAPPED_NODE))
5070 * lpfc_reset_flush_io_context -
5071 * @vport: The virtual port (scsi_host) for the flush context
5072 * @tgt_id: If aborting by Target contect - specifies the target id
5073 * @lun_id: If aborting by Lun context - specifies the lun id
5074 * @context: specifies the context level to flush at.
5076 * After a reset condition via TMF, we need to flush orphaned i/o
5077 * contexts from the adapter. This routine aborts any contexts
5078 * outstanding, then waits for their completions. The wait is
5079 * bounded by devloss_tmo though.
5086 lpfc_reset_flush_io_context(struct lpfc_vport *vport, uint16_t tgt_id,
5087 uint64_t lun_id, lpfc_ctx_cmd context)
5089 struct lpfc_hba *phba = vport->phba;
5090 unsigned long later;
5093 cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context);
5095 lpfc_sli_abort_taskmgmt(vport,
5096 &phba->sli.ring[phba->sli.fcp_ring],
5097 tgt_id, lun_id, context);
5098 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
5099 while (time_after(later, jiffies) && cnt) {
5100 schedule_timeout_uninterruptible(msecs_to_jiffies(20));
5101 cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context);
5104 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5105 "0724 I/O flush failure for context %s : cnt x%x\n",
5106 ((context == LPFC_CTX_LUN) ? "LUN" :
5107 ((context == LPFC_CTX_TGT) ? "TGT" :
5108 ((context == LPFC_CTX_HOST) ? "HOST" : "Unknown"))),
5116 * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point
5117 * @cmnd: Pointer to scsi_cmnd data structure.
5119 * This routine does a device reset by sending a LUN_RESET task management
5127 lpfc_device_reset_handler(struct scsi_cmnd *cmnd)
5129 struct Scsi_Host *shost = cmnd->device->host;
5130 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5131 struct lpfc_rport_data *rdata;
5132 struct lpfc_nodelist *pnode;
5133 unsigned tgt_id = cmnd->device->id;
5134 uint64_t lun_id = cmnd->device->lun;
5135 struct lpfc_scsi_event_header scsi_event;
5138 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
5140 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5141 "0798 Device Reset rport failure: rdata x%p\n", rdata);
5144 pnode = rdata->pnode;
5145 status = fc_block_scsi_eh(cmnd);
5146 if (status != 0 && status != SUCCESS)
5149 status = lpfc_chk_tgt_mapped(vport, cmnd);
5150 if (status == FAILED) {
5151 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5152 "0721 Device Reset rport failure: rdata x%p\n", rdata);
5156 scsi_event.event_type = FC_REG_SCSI_EVENT;
5157 scsi_event.subcategory = LPFC_EVENT_LUNRESET;
5158 scsi_event.lun = lun_id;
5159 memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name));
5160 memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name));
5162 fc_host_post_vendor_event(shost, fc_get_event_number(),
5163 sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
5165 status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id,
5168 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5169 "0713 SCSI layer issued Device Reset (%d, %llu) "
5170 "return x%x\n", tgt_id, lun_id, status);
5173 * We have to clean up i/o as : they may be orphaned by the TMF;
5174 * or if the TMF failed, they may be in an indeterminate state.
5176 * We will report success if all the i/o aborts successfully.
5178 if (status == SUCCESS)
5179 status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
5186 * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point
5187 * @cmnd: Pointer to scsi_cmnd data structure.
5189 * This routine does a target reset by sending a TARGET_RESET task management
5197 lpfc_target_reset_handler(struct scsi_cmnd *cmnd)
5199 struct Scsi_Host *shost = cmnd->device->host;
5200 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5201 struct lpfc_rport_data *rdata;
5202 struct lpfc_nodelist *pnode;
5203 unsigned tgt_id = cmnd->device->id;
5204 uint64_t lun_id = cmnd->device->lun;
5205 struct lpfc_scsi_event_header scsi_event;
5208 rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
5210 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5211 "0799 Target Reset rport failure: rdata x%p\n", rdata);
5214 pnode = rdata->pnode;
5215 status = fc_block_scsi_eh(cmnd);
5216 if (status != 0 && status != SUCCESS)
5219 status = lpfc_chk_tgt_mapped(vport, cmnd);
5220 if (status == FAILED) {
5221 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5222 "0722 Target Reset rport failure: rdata x%p\n", rdata);
5223 spin_lock_irq(shost->host_lock);
5224 pnode->nlp_flag &= ~NLP_NPR_ADISC;
5225 pnode->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
5226 spin_unlock_irq(shost->host_lock);
5227 lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
5229 return FAST_IO_FAIL;
5232 scsi_event.event_type = FC_REG_SCSI_EVENT;
5233 scsi_event.subcategory = LPFC_EVENT_TGTRESET;
5235 memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name));
5236 memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name));
5238 fc_host_post_vendor_event(shost, fc_get_event_number(),
5239 sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
5241 status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id,
5244 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5245 "0723 SCSI layer issued Target Reset (%d, %llu) "
5246 "return x%x\n", tgt_id, lun_id, status);
5249 * We have to clean up i/o as : they may be orphaned by the TMF;
5250 * or if the TMF failed, they may be in an indeterminate state.
5252 * We will report success if all the i/o aborts successfully.
5254 if (status == SUCCESS)
5255 status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
5261 * lpfc_bus_reset_handler - scsi_host_template eh_bus_reset_handler entry point
5262 * @cmnd: Pointer to scsi_cmnd data structure.
5264 * This routine does target reset to all targets on @cmnd->device->host.
5265 * This emulates Parallel SCSI Bus Reset Semantics.
5272 lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
5274 struct Scsi_Host *shost = cmnd->device->host;
5275 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5276 struct lpfc_nodelist *ndlp = NULL;
5277 struct lpfc_scsi_event_header scsi_event;
5279 int ret = SUCCESS, status, i;
5281 scsi_event.event_type = FC_REG_SCSI_EVENT;
5282 scsi_event.subcategory = LPFC_EVENT_BUSRESET;
5284 memcpy(scsi_event.wwpn, &vport->fc_portname, sizeof(struct lpfc_name));
5285 memcpy(scsi_event.wwnn, &vport->fc_nodename, sizeof(struct lpfc_name));
5287 fc_host_post_vendor_event(shost, fc_get_event_number(),
5288 sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
5290 status = fc_block_scsi_eh(cmnd);
5291 if (status != 0 && status != SUCCESS)
5295 * Since the driver manages a single bus device, reset all
5296 * targets known to the driver. Should any target reset
5297 * fail, this routine returns failure to the midlayer.
5299 for (i = 0; i < LPFC_MAX_TARGET; i++) {
5300 /* Search for mapped node by target ID */
5302 spin_lock_irq(shost->host_lock);
5303 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5304 if (!NLP_CHK_NODE_ACT(ndlp))
5306 if (vport->phba->cfg_fcp2_no_tgt_reset &&
5307 (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE))
5309 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
5310 ndlp->nlp_sid == i &&
5316 spin_unlock_irq(shost->host_lock);
5320 status = lpfc_send_taskmgmt(vport, ndlp->rport->dd_data,
5321 i, 0, FCP_TARGET_RESET);
5323 if (status != SUCCESS) {
5324 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5325 "0700 Bus Reset on target %d failed\n",
5331 * We have to clean up i/o as : they may be orphaned by the TMFs
5332 * above; or if any of the TMFs failed, they may be in an
5333 * indeterminate state.
5334 * We will report success if all the i/o aborts successfully.
5337 status = lpfc_reset_flush_io_context(vport, 0, 0, LPFC_CTX_HOST);
5338 if (status != SUCCESS)
5341 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5342 "0714 SCSI layer issued Bus Reset Data: x%x\n", ret);
5347 * lpfc_host_reset_handler - scsi_host_template eh_host_reset_handler entry pt
5348 * @cmnd: Pointer to scsi_cmnd data structure.
5350 * This routine does host reset to the adaptor port. It brings the HBA
5351 * offline, performs a board restart, and then brings the board back online.
5352 * The lpfc_offline calls lpfc_sli_hba_down which will abort and local
5353 * reject all outstanding SCSI commands to the host and error returned
5354 * back to SCSI mid-level. As this will be SCSI mid-level's last resort
5355 * of error handling, it will only return error if resetting of the adapter
5356 * is not successful; in all other cases, will return success.
5363 lpfc_host_reset_handler(struct scsi_cmnd *cmnd)
5365 struct Scsi_Host *shost = cmnd->device->host;
5366 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5367 struct lpfc_hba *phba = vport->phba;
5368 int rc, ret = SUCCESS;
5370 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5371 "3172 SCSI layer issued Host Reset Data:\n");
5373 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
5375 rc = lpfc_sli_brdrestart(phba);
5378 rc = lpfc_online(phba);
5381 lpfc_unblock_mgmt_io(phba);
5383 if (ret == FAILED) {
5384 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5385 "3323 Failed host reset, bring it offline\n");
5386 lpfc_sli4_offline_eratt(phba);
5392 * lpfc_slave_alloc - scsi_host_template slave_alloc entry point
5393 * @sdev: Pointer to scsi_device.
5395 * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's
5396 * globally available list of scsi buffers. This routine also makes sure scsi
5397 * buffer is not allocated more than HBA limit conveyed to midlayer. This list
5398 * of scsi buffer exists for the lifetime of the driver.
5405 lpfc_slave_alloc(struct scsi_device *sdev)
5407 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
5408 struct lpfc_hba *phba = vport->phba;
5409 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
5411 uint32_t num_to_alloc = 0;
5412 int num_allocated = 0;
5414 struct lpfc_device_data *device_data;
5415 unsigned long flags;
5416 struct lpfc_name target_wwpn;
5418 if (!rport || fc_remote_port_chkready(rport))
5421 if (phba->cfg_fof) {
5424 * Check to see if the device data structure for the lun
5425 * exists. If not, create one.
5428 u64_to_wwn(rport->port_name, target_wwpn.u.wwn);
5429 spin_lock_irqsave(&phba->devicelock, flags);
5430 device_data = __lpfc_get_device_data(phba,
5432 &vport->fc_portname,
5436 spin_unlock_irqrestore(&phba->devicelock, flags);
5437 device_data = lpfc_create_device_data(phba,
5438 &vport->fc_portname,
5443 spin_lock_irqsave(&phba->devicelock, flags);
5444 list_add_tail(&device_data->listentry, &phba->luns);
5446 device_data->rport_data = rport->dd_data;
5447 device_data->available = true;
5448 spin_unlock_irqrestore(&phba->devicelock, flags);
5449 sdev->hostdata = device_data;
5451 sdev->hostdata = rport->dd_data;
5453 sdev_cnt = atomic_inc_return(&phba->sdev_cnt);
5456 * Populate the cmds_per_lun count scsi_bufs into this host's globally
5457 * available list of scsi buffers. Don't allocate more than the
5458 * HBA limit conveyed to the midlayer via the host structure. The
5459 * formula accounts for the lun_queue_depth + error handlers + 1
5460 * extra. This list of scsi bufs exists for the lifetime of the driver.
5462 total = phba->total_scsi_bufs;
5463 num_to_alloc = vport->cfg_lun_queue_depth + 2;
5465 /* If allocated buffers are enough do nothing */
5466 if ((sdev_cnt * (vport->cfg_lun_queue_depth + 2)) < total)
5469 /* Allow some exchanges to be available always to complete discovery */
5470 if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
5471 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
5472 "0704 At limitation of %d preallocated "
5473 "command buffers\n", total);
5475 /* Allow some exchanges to be available always to complete discovery */
5476 } else if (total + num_to_alloc >
5477 phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
5478 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
5479 "0705 Allocation request of %d "
5480 "command buffers will exceed max of %d. "
5481 "Reducing allocation request to %d.\n",
5482 num_to_alloc, phba->cfg_hba_queue_depth,
5483 (phba->cfg_hba_queue_depth - total));
5484 num_to_alloc = phba->cfg_hba_queue_depth - total;
5486 num_allocated = lpfc_new_scsi_buf(vport, num_to_alloc);
5487 if (num_to_alloc != num_allocated) {
5488 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
5489 "0708 Allocation request of %d "
5490 "command buffers did not succeed. "
5491 "Allocated %d buffers.\n",
5492 num_to_alloc, num_allocated);
5494 if (num_allocated > 0)
5495 phba->total_scsi_bufs += num_allocated;
5500 * lpfc_slave_configure - scsi_host_template slave_configure entry point
5501 * @sdev: Pointer to scsi_device.
5503 * This routine configures following items
5504 * - Tag command queuing support for @sdev if supported.
5505 * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set.
5511 lpfc_slave_configure(struct scsi_device *sdev)
5513 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
5514 struct lpfc_hba *phba = vport->phba;
5516 scsi_adjust_queue_depth(sdev, vport->cfg_lun_queue_depth);
5518 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
5519 lpfc_sli_handle_fast_ring_event(phba,
5520 &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
5521 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
5522 lpfc_poll_rearm_timer(phba);
5529 * lpfc_slave_destroy - slave_destroy entry point of SHT data structure
5530 * @sdev: Pointer to scsi_device.
5532 * This routine sets @sdev hostatdata filed to null.
5535 lpfc_slave_destroy(struct scsi_device *sdev)
5537 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
5538 struct lpfc_hba *phba = vport->phba;
5539 unsigned long flags;
5540 struct lpfc_device_data *device_data = sdev->hostdata;
5542 atomic_dec(&phba->sdev_cnt);
5543 if ((phba->cfg_fof) && (device_data)) {
5544 spin_lock_irqsave(&phba->devicelock, flags);
5545 device_data->available = false;
5546 if (!device_data->oas_enabled)
5547 lpfc_delete_device_data(phba, device_data);
5548 spin_unlock_irqrestore(&phba->devicelock, flags);
5550 sdev->hostdata = NULL;
5555 * lpfc_create_device_data - creates and initializes device data structure for OAS
5556 * @pha: Pointer to host bus adapter structure.
5557 * @vport_wwpn: Pointer to vport's wwpn information
5558 * @target_wwpn: Pointer to target's wwpn information
5559 * @lun: Lun on target
5560 * @atomic_create: Flag to indicate if memory should be allocated using the
5561 * GFP_ATOMIC flag or not.
5563 * This routine creates a device data structure which will contain identifying
5564 * information for the device (host wwpn, target wwpn, lun), state of OAS,
5565 * whether or not the corresponding lun is available by the system,
5566 * and pointer to the rport data.
5570 * Pointer to lpfc_device_data - Success
5572 struct lpfc_device_data*
5573 lpfc_create_device_data(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn,
5574 struct lpfc_name *target_wwpn, uint64_t lun,
5578 struct lpfc_device_data *lun_info;
5581 if (unlikely(!phba) || !vport_wwpn || !target_wwpn ||
5585 /* Attempt to create the device data to contain lun info */
5588 memory_flags = GFP_ATOMIC;
5590 memory_flags = GFP_KERNEL;
5591 lun_info = mempool_alloc(phba->device_data_mem_pool, memory_flags);
5594 INIT_LIST_HEAD(&lun_info->listentry);
5595 lun_info->rport_data = NULL;
5596 memcpy(&lun_info->device_id.vport_wwpn, vport_wwpn,
5597 sizeof(struct lpfc_name));
5598 memcpy(&lun_info->device_id.target_wwpn, target_wwpn,
5599 sizeof(struct lpfc_name));
5600 lun_info->device_id.lun = lun;
5601 lun_info->oas_enabled = false;
5602 lun_info->available = false;
5607 * lpfc_delete_device_data - frees a device data structure for OAS
5608 * @pha: Pointer to host bus adapter structure.
5609 * @lun_info: Pointer to device data structure to free.
5611 * This routine frees the previously allocated device data structure passed.
5615 lpfc_delete_device_data(struct lpfc_hba *phba,
5616 struct lpfc_device_data *lun_info)
5619 if (unlikely(!phba) || !lun_info ||
5623 if (!list_empty(&lun_info->listentry))
5624 list_del(&lun_info->listentry);
5625 mempool_free(lun_info, phba->device_data_mem_pool);
5630 * __lpfc_get_device_data - returns the device data for the specified lun
5631 * @pha: Pointer to host bus adapter structure.
5632 * @list: Point to list to search.
5633 * @vport_wwpn: Pointer to vport's wwpn information
5634 * @target_wwpn: Pointer to target's wwpn information
5635 * @lun: Lun on target
5637 * This routine searches the list passed for the specified lun's device data.
5638 * This function does not hold locks, it is the responsibility of the caller
5639 * to ensure the proper lock is held before calling the function.
5643 * Pointer to lpfc_device_data - Success
5645 struct lpfc_device_data*
5646 __lpfc_get_device_data(struct lpfc_hba *phba, struct list_head *list,
5647 struct lpfc_name *vport_wwpn,
5648 struct lpfc_name *target_wwpn, uint64_t lun)
5651 struct lpfc_device_data *lun_info;
5653 if (unlikely(!phba) || !list || !vport_wwpn || !target_wwpn ||
5657 /* Check to see if the lun is already enabled for OAS. */
5659 list_for_each_entry(lun_info, list, listentry) {
5660 if ((memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn,
5661 sizeof(struct lpfc_name)) == 0) &&
5662 (memcmp(&lun_info->device_id.target_wwpn, target_wwpn,
5663 sizeof(struct lpfc_name)) == 0) &&
5664 (lun_info->device_id.lun == lun))
5672 * lpfc_find_next_oas_lun - searches for the next oas lun
5673 * @pha: Pointer to host bus adapter structure.
5674 * @vport_wwpn: Pointer to vport's wwpn information
5675 * @target_wwpn: Pointer to target's wwpn information
5676 * @starting_lun: Pointer to the lun to start searching for
5677 * @found_vport_wwpn: Pointer to the found lun's vport wwpn information
5678 * @found_target_wwpn: Pointer to the found lun's target wwpn information
5679 * @found_lun: Pointer to the found lun.
5680 * @found_lun_status: Pointer to status of the found lun.
5682 * This routine searches the luns list for the specified lun
5683 * or the first lun for the vport/target. If the vport wwpn contains
5684 * a zero value then a specific vport is not specified. In this case
5685 * any vport which contains the lun will be considered a match. If the
5686 * target wwpn contains a zero value then a specific target is not specified.
5687 * In this case any target which contains the lun will be considered a
5688 * match. If the lun is found, the lun, vport wwpn, target wwpn and lun status
5689 * are returned. The function will also return the next lun if available.
5690 * If the next lun is not found, starting_lun parameter will be set to
5698 lpfc_find_next_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn,
5699 struct lpfc_name *target_wwpn, uint64_t *starting_lun,
5700 struct lpfc_name *found_vport_wwpn,
5701 struct lpfc_name *found_target_wwpn,
5702 uint64_t *found_lun,
5703 uint32_t *found_lun_status)
5706 unsigned long flags;
5707 struct lpfc_device_data *lun_info;
5708 struct lpfc_device_id *device_id;
5712 if (unlikely(!phba) || !vport_wwpn || !target_wwpn ||
5713 !starting_lun || !found_vport_wwpn ||
5714 !found_target_wwpn || !found_lun || !found_lun_status ||
5715 (*starting_lun == NO_MORE_OAS_LUN) ||
5719 lun = *starting_lun;
5720 *found_lun = NO_MORE_OAS_LUN;
5721 *starting_lun = NO_MORE_OAS_LUN;
5723 /* Search for lun or the lun closet in value */
5725 spin_lock_irqsave(&phba->devicelock, flags);
5726 list_for_each_entry(lun_info, &phba->luns, listentry) {
5727 if (((wwn_to_u64(vport_wwpn->u.wwn) == 0) ||
5728 (memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn,
5729 sizeof(struct lpfc_name)) == 0)) &&
5730 ((wwn_to_u64(target_wwpn->u.wwn) == 0) ||
5731 (memcmp(&lun_info->device_id.target_wwpn, target_wwpn,
5732 sizeof(struct lpfc_name)) == 0)) &&
5733 (lun_info->oas_enabled)) {
5734 device_id = &lun_info->device_id;
5736 ((lun == FIND_FIRST_OAS_LUN) ||
5737 (device_id->lun == lun))) {
5738 *found_lun = device_id->lun;
5739 memcpy(found_vport_wwpn,
5740 &device_id->vport_wwpn,
5741 sizeof(struct lpfc_name));
5742 memcpy(found_target_wwpn,
5743 &device_id->target_wwpn,
5744 sizeof(struct lpfc_name));
5745 if (lun_info->available)
5747 OAS_LUN_STATUS_EXISTS;
5749 *found_lun_status = 0;
5750 if (phba->cfg_oas_flags & OAS_FIND_ANY_VPORT)
5751 memset(vport_wwpn, 0x0,
5752 sizeof(struct lpfc_name));
5753 if (phba->cfg_oas_flags & OAS_FIND_ANY_TARGET)
5754 memset(target_wwpn, 0x0,
5755 sizeof(struct lpfc_name));
5758 *starting_lun = device_id->lun;
5759 memcpy(vport_wwpn, &device_id->vport_wwpn,
5760 sizeof(struct lpfc_name));
5761 memcpy(target_wwpn, &device_id->target_wwpn,
5762 sizeof(struct lpfc_name));
5767 spin_unlock_irqrestore(&phba->devicelock, flags);
5772 * lpfc_enable_oas_lun - enables a lun for OAS operations
5773 * @pha: Pointer to host bus adapter structure.
5774 * @vport_wwpn: Pointer to vport's wwpn information
5775 * @target_wwpn: Pointer to target's wwpn information
5778 * This routine enables a lun for oas operations. The routines does so by
5779 * doing the following :
5781 * 1) Checks to see if the device data for the lun has been created.
5782 * 2) If found, sets the OAS enabled flag if not set and returns.
5783 * 3) Otherwise, creates a device data structure.
5784 * 4) If successfully created, indicates the device data is for an OAS lun,
5785 * indicates the lun is not available and add to the list of luns.
5792 lpfc_enable_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn,
5793 struct lpfc_name *target_wwpn, uint64_t lun)
5796 struct lpfc_device_data *lun_info;
5797 unsigned long flags;
5799 if (unlikely(!phba) || !vport_wwpn || !target_wwpn ||
5803 spin_lock_irqsave(&phba->devicelock, flags);
5805 /* Check to see if the device data for the lun has been created */
5806 lun_info = __lpfc_get_device_data(phba, &phba->luns, vport_wwpn,
5809 if (!lun_info->oas_enabled)
5810 lun_info->oas_enabled = true;
5811 spin_unlock_irqrestore(&phba->devicelock, flags);
5815 /* Create an lun info structure and add to list of luns */
5816 lun_info = lpfc_create_device_data(phba, vport_wwpn, target_wwpn, lun,
5819 lun_info->oas_enabled = true;
5820 lun_info->available = false;
5821 list_add_tail(&lun_info->listentry, &phba->luns);
5822 spin_unlock_irqrestore(&phba->devicelock, flags);
5825 spin_unlock_irqrestore(&phba->devicelock, flags);
5830 * lpfc_disable_oas_lun - disables a lun for OAS operations
5831 * @pha: Pointer to host bus adapter structure.
5832 * @vport_wwpn: Pointer to vport's wwpn information
5833 * @target_wwpn: Pointer to target's wwpn information
5836 * This routine disables a lun for oas operations. The routines does so by
5837 * doing the following :
5839 * 1) Checks to see if the device data for the lun is created.
5840 * 2) If present, clears the flag indicating this lun is for OAS.
5841 * 3) If the lun is not available by the system, the device data is
5849 lpfc_disable_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn,
5850 struct lpfc_name *target_wwpn, uint64_t lun)
5853 struct lpfc_device_data *lun_info;
5854 unsigned long flags;
5856 if (unlikely(!phba) || !vport_wwpn || !target_wwpn ||
5860 spin_lock_irqsave(&phba->devicelock, flags);
5862 /* Check to see if the lun is available. */
5863 lun_info = __lpfc_get_device_data(phba,
5864 &phba->luns, vport_wwpn,
5867 lun_info->oas_enabled = false;
5868 if (!lun_info->available)
5869 lpfc_delete_device_data(phba, lun_info);
5870 spin_unlock_irqrestore(&phba->devicelock, flags);
5874 spin_unlock_irqrestore(&phba->devicelock, flags);
5878 struct scsi_host_template lpfc_template = {
5879 .module = THIS_MODULE,
5880 .name = LPFC_DRIVER_NAME,
5882 .queuecommand = lpfc_queuecommand,
5883 .eh_abort_handler = lpfc_abort_handler,
5884 .eh_device_reset_handler = lpfc_device_reset_handler,
5885 .eh_target_reset_handler = lpfc_target_reset_handler,
5886 .eh_bus_reset_handler = lpfc_bus_reset_handler,
5887 .eh_host_reset_handler = lpfc_host_reset_handler,
5888 .slave_alloc = lpfc_slave_alloc,
5889 .slave_configure = lpfc_slave_configure,
5890 .slave_destroy = lpfc_slave_destroy,
5891 .scan_finished = lpfc_scan_finished,
5893 .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
5894 .cmd_per_lun = LPFC_CMD_PER_LUN,
5895 .use_clustering = ENABLE_CLUSTERING,
5896 .shost_attrs = lpfc_hba_attrs,
5897 .max_sectors = 0xFFFF,
5898 .vendor_id = LPFC_NL_VENDOR_ID,
5899 .change_queue_depth = lpfc_change_queue_depth,
5900 .change_queue_type = scsi_change_queue_type,
5902 .track_queue_depth = 1,
5905 struct scsi_host_template lpfc_vport_template = {
5906 .module = THIS_MODULE,
5907 .name = LPFC_DRIVER_NAME,
5909 .queuecommand = lpfc_queuecommand,
5910 .eh_abort_handler = lpfc_abort_handler,
5911 .eh_device_reset_handler = lpfc_device_reset_handler,
5912 .eh_target_reset_handler = lpfc_target_reset_handler,
5913 .eh_bus_reset_handler = lpfc_bus_reset_handler,
5914 .slave_alloc = lpfc_slave_alloc,
5915 .slave_configure = lpfc_slave_configure,
5916 .slave_destroy = lpfc_slave_destroy,
5917 .scan_finished = lpfc_scan_finished,
5919 .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
5920 .cmd_per_lun = LPFC_CMD_PER_LUN,
5921 .use_clustering = ENABLE_CLUSTERING,
5922 .shost_attrs = lpfc_vport_attrs,
5923 .max_sectors = 0xFFFF,
5924 .change_queue_depth = lpfc_change_queue_depth,
5925 .change_queue_type = scsi_change_queue_type,
5927 .track_queue_depth = 1,