1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2008 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 *******************************************************************/
22 #include <linux/pci.h>
23 #include <linux/interrupt.h>
24 #include <linux/delay.h>
26 #include <scsi/scsi.h>
27 #include <scsi/scsi_device.h>
28 #include <scsi/scsi_host.h>
29 #include <scsi/scsi_tcq.h>
30 #include <scsi/scsi_transport_fc.h>
32 #include "lpfc_version.h"
35 #include "lpfc_disc.h"
36 #include "lpfc_scsi.h"
38 #include "lpfc_logmsg.h"
39 #include "lpfc_crtn.h"
40 #include "lpfc_vport.h"
42 #define LPFC_RESET_WAIT 2
43 #define LPFC_ABORT_WAIT 2
46 * This function is called with no lock held when there is a resource
47 * error in driver or in firmware.
50 lpfc_adjust_queue_depth(struct lpfc_hba *phba)
54 spin_lock_irqsave(&phba->hbalock, flags);
55 atomic_inc(&phba->num_rsrc_err);
56 phba->last_rsrc_error_time = jiffies;
58 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
59 spin_unlock_irqrestore(&phba->hbalock, flags);
63 phba->last_ramp_down_time = jiffies;
65 spin_unlock_irqrestore(&phba->hbalock, flags);
67 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
68 if ((phba->pport->work_port_events &
69 WORKER_RAMP_DOWN_QUEUE) == 0) {
70 phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE;
72 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
74 spin_lock_irqsave(&phba->hbalock, flags);
76 wake_up(phba->work_wait);
77 spin_unlock_irqrestore(&phba->hbalock, flags);
83 * This function is called with no lock held when there is a successful
84 * SCSI command completion.
87 lpfc_rampup_queue_depth(struct lpfc_vport *vport,
88 struct scsi_device *sdev)
91 struct lpfc_hba *phba = vport->phba;
92 atomic_inc(&phba->num_cmd_success);
94 if (vport->cfg_lun_queue_depth <= sdev->queue_depth)
96 spin_lock_irqsave(&phba->hbalock, flags);
97 if (((phba->last_ramp_up_time + QUEUE_RAMP_UP_INTERVAL) > jiffies) ||
98 ((phba->last_rsrc_error_time + QUEUE_RAMP_UP_INTERVAL ) > jiffies)) {
99 spin_unlock_irqrestore(&phba->hbalock, flags);
102 phba->last_ramp_up_time = jiffies;
103 spin_unlock_irqrestore(&phba->hbalock, flags);
105 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
106 if ((phba->pport->work_port_events &
107 WORKER_RAMP_UP_QUEUE) == 0) {
108 phba->pport->work_port_events |= WORKER_RAMP_UP_QUEUE;
110 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
112 spin_lock_irqsave(&phba->hbalock, flags);
114 wake_up(phba->work_wait);
115 spin_unlock_irqrestore(&phba->hbalock, flags);
119 lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
121 struct lpfc_vport **vports;
122 struct Scsi_Host *shost;
123 struct scsi_device *sdev;
124 unsigned long new_queue_depth;
125 unsigned long num_rsrc_err, num_cmd_success;
128 num_rsrc_err = atomic_read(&phba->num_rsrc_err);
129 num_cmd_success = atomic_read(&phba->num_cmd_success);
131 vports = lpfc_create_vport_work_array(phba);
133 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
134 shost = lpfc_shost_from_vport(vports[i]);
135 shost_for_each_device(sdev, shost) {
137 sdev->queue_depth * num_rsrc_err /
138 (num_rsrc_err + num_cmd_success);
139 if (!new_queue_depth)
140 new_queue_depth = sdev->queue_depth - 1;
142 new_queue_depth = sdev->queue_depth -
144 if (sdev->ordered_tags)
145 scsi_adjust_queue_depth(sdev,
149 scsi_adjust_queue_depth(sdev,
154 lpfc_destroy_vport_work_array(phba, vports);
155 atomic_set(&phba->num_rsrc_err, 0);
156 atomic_set(&phba->num_cmd_success, 0);
160 lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
162 struct lpfc_vport **vports;
163 struct Scsi_Host *shost;
164 struct scsi_device *sdev;
167 vports = lpfc_create_vport_work_array(phba);
169 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
170 shost = lpfc_shost_from_vport(vports[i]);
171 shost_for_each_device(sdev, shost) {
172 if (vports[i]->cfg_lun_queue_depth <=
175 if (sdev->ordered_tags)
176 scsi_adjust_queue_depth(sdev,
178 sdev->queue_depth+1);
180 scsi_adjust_queue_depth(sdev,
182 sdev->queue_depth+1);
185 lpfc_destroy_vport_work_array(phba, vports);
186 atomic_set(&phba->num_rsrc_err, 0);
187 atomic_set(&phba->num_cmd_success, 0);
191 * This routine allocates a scsi buffer, which contains all the necessary
192 * information needed to initiate a SCSI I/O. The non-DMAable buffer region
193 * contains information to build the IOCB. The DMAable region contains
194 * memory for the FCP CMND, FCP RSP, and the inital BPL. In addition to
195 * allocating memeory, the FCP CMND and FCP RSP BDEs are setup in the BPL
196 * and the BPL BDE is setup in the IOCB.
198 static struct lpfc_scsi_buf *
199 lpfc_new_scsi_buf(struct lpfc_vport *vport)
201 struct lpfc_hba *phba = vport->phba;
202 struct lpfc_scsi_buf *psb;
203 struct ulp_bde64 *bpl;
205 dma_addr_t pdma_phys;
208 psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL);
213 * Get memory from the pci pool to map the virt space to pci bus space
214 * for an I/O. The DMA buffer includes space for the struct fcp_cmnd,
215 * struct fcp_rsp and the number of bde's necessary to support the
218 psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool, GFP_KERNEL,
225 /* Initialize virtual ptrs to dma_buf region. */
226 memset(psb->data, 0, phba->cfg_sg_dma_buf_size);
228 /* Allocate iotag for psb->cur_iocbq. */
229 iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq);
231 pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
232 psb->data, psb->dma_handle);
236 psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP;
238 psb->fcp_cmnd = psb->data;
239 psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd);
240 psb->fcp_bpl = psb->data + sizeof(struct fcp_cmnd) +
241 sizeof(struct fcp_rsp);
243 /* Initialize local short-hand pointers. */
245 pdma_phys = psb->dma_handle;
248 * The first two bdes are the FCP_CMD and FCP_RSP. The balance are sg
249 * list bdes. Initialize the first two and leave the rest for
252 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys));
253 bpl->addrLow = le32_to_cpu(putPaddrLow(pdma_phys));
254 bpl->tus.f.bdeSize = sizeof (struct fcp_cmnd);
255 bpl->tus.f.bdeFlags = BUFF_USE_CMND;
256 bpl->tus.w = le32_to_cpu(bpl->tus.w);
259 /* Setup the physical region for the FCP RSP */
260 pdma_phys += sizeof (struct fcp_cmnd);
261 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys));
262 bpl->addrLow = le32_to_cpu(putPaddrLow(pdma_phys));
263 bpl->tus.f.bdeSize = sizeof (struct fcp_rsp);
264 bpl->tus.f.bdeFlags = (BUFF_USE_CMND | BUFF_USE_RCV);
265 bpl->tus.w = le32_to_cpu(bpl->tus.w);
268 * Since the IOCB for the FCP I/O is built into this lpfc_scsi_buf,
269 * initialize it with all known data now.
271 pdma_phys += (sizeof (struct fcp_rsp));
272 iocb = &psb->cur_iocbq.iocb;
273 iocb->un.fcpi64.bdl.ulpIoTag32 = 0;
274 iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys);
275 iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys);
276 iocb->un.fcpi64.bdl.bdeSize = (2 * sizeof (struct ulp_bde64));
277 iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDL;
278 iocb->ulpBdeCount = 1;
279 iocb->ulpClass = CLASS3;
284 static struct lpfc_scsi_buf*
285 lpfc_get_scsi_buf(struct lpfc_hba * phba)
287 struct lpfc_scsi_buf * lpfc_cmd = NULL;
288 struct list_head *scsi_buf_list = &phba->lpfc_scsi_buf_list;
289 unsigned long iflag = 0;
291 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
292 list_remove_head(scsi_buf_list, lpfc_cmd, struct lpfc_scsi_buf, list);
294 lpfc_cmd->seg_cnt = 0;
295 lpfc_cmd->nonsg_phys = 0;
297 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
302 lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
304 unsigned long iflag = 0;
306 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
308 list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list);
309 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
313 lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
315 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
316 struct scatterlist *sgel = NULL;
317 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
318 struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl;
319 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
321 uint32_t i, num_bde = 0;
322 int nseg, datadir = scsi_cmnd->sc_data_direction;
325 * There are three possibilities here - use scatter-gather segment, use
326 * the single mapping, or neither. Start the lpfc command prep by
327 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
331 if (scsi_sg_count(scsi_cmnd)) {
333 * The driver stores the segment count returned from pci_map_sg
334 * because this a count of dma-mappings used to map the use_sg
335 * pages. They are not guaranteed to be the same for those
336 * architectures that implement an IOMMU.
339 nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd),
340 scsi_sg_count(scsi_cmnd), datadir);
344 lpfc_cmd->seg_cnt = nseg;
345 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
346 printk(KERN_ERR "%s: Too many sg segments from "
347 "dma_map_sg. Config %d, seg_cnt %d",
348 __FUNCTION__, phba->cfg_sg_seg_cnt,
350 scsi_dma_unmap(scsi_cmnd);
355 * The driver established a maximum scatter-gather segment count
356 * during probe that limits the number of sg elements in any
357 * single scsi command. Just run through the seg_cnt and format
360 scsi_for_each_sg(scsi_cmnd, sgel, nseg, i) {
361 physaddr = sg_dma_address(sgel);
362 bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr));
363 bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
364 bpl->tus.f.bdeSize = sg_dma_len(sgel);
365 if (datadir == DMA_TO_DEVICE)
366 bpl->tus.f.bdeFlags = 0;
368 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
369 bpl->tus.w = le32_to_cpu(bpl->tus.w);
376 * Finish initializing those IOCB fields that are dependent on the
377 * scsi_cmnd request_buffer. Note that the bdeSize is explicitly
378 * reinitialized since all iocb memory resources are used many times
379 * for transmit, receive, and continuation bpl's.
381 iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof (struct ulp_bde64));
382 iocb_cmd->un.fcpi64.bdl.bdeSize +=
383 (num_bde * sizeof (struct ulp_bde64));
384 iocb_cmd->ulpBdeCount = 1;
386 fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd));
391 lpfc_scsi_unprep_dma_buf(struct lpfc_hba * phba, struct lpfc_scsi_buf * psb)
394 * There are only two special cases to consider. (1) the scsi command
395 * requested scatter-gather usage or (2) the scsi command allocated
396 * a request buffer, but did not request use_sg. There is a third
397 * case, but it does not require resource deallocation.
399 if (psb->seg_cnt > 0)
400 scsi_dma_unmap(psb->pCmd);
404 lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
405 struct lpfc_iocbq *rsp_iocb)
407 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
408 struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd;
409 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
410 uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm;
411 uint32_t resp_info = fcprsp->rspStatus2;
412 uint32_t scsi_status = fcprsp->rspStatus3;
414 uint32_t host_status = DID_OK;
416 uint32_t logit = LOG_FCP | LOG_FCP_ERROR;
419 * If this is a task management command, there is no
420 * scsi packet associated with this lpfc_cmd. The driver
423 if (fcpcmd->fcpCntl2) {
428 if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) {
429 uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen);
430 if (snslen > SCSI_SENSE_BUFFERSIZE)
431 snslen = SCSI_SENSE_BUFFERSIZE;
433 if (resp_info & RSP_LEN_VALID)
434 rsplen = be32_to_cpu(fcprsp->rspRspLen);
435 memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen);
437 lp = (uint32_t *)cmnd->sense_buffer;
439 if (!scsi_status && (resp_info & RESID_UNDER))
442 lpfc_printf_vlog(vport, KERN_WARNING, logit,
443 "0730 FCP command x%x failed: x%x SNS x%x x%x "
444 "Data: x%x x%x x%x x%x x%x\n",
445 cmnd->cmnd[0], scsi_status,
446 be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info,
447 be32_to_cpu(fcprsp->rspResId),
448 be32_to_cpu(fcprsp->rspSnsLen),
449 be32_to_cpu(fcprsp->rspRspLen),
452 if (resp_info & RSP_LEN_VALID) {
453 rsplen = be32_to_cpu(fcprsp->rspRspLen);
454 if ((rsplen != 0 && rsplen != 4 && rsplen != 8) ||
455 (fcprsp->rspInfo3 != RSP_NO_FAILURE)) {
456 host_status = DID_ERROR;
461 scsi_set_resid(cmnd, 0);
462 if (resp_info & RESID_UNDER) {
463 scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId));
465 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
466 "0716 FCP Read Underrun, expected %d, "
467 "residual %d Data: x%x x%x x%x\n",
468 be32_to_cpu(fcpcmd->fcpDl),
469 scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0],
473 * If there is an under run check if under run reported by
474 * storage array is same as the under run reported by HBA.
475 * If this is not same, there is a dropped frame.
477 if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) &&
479 (scsi_get_resid(cmnd) != fcpi_parm)) {
480 lpfc_printf_vlog(vport, KERN_WARNING,
481 LOG_FCP | LOG_FCP_ERROR,
482 "0735 FCP Read Check Error "
483 "and Underrun Data: x%x x%x x%x x%x\n",
484 be32_to_cpu(fcpcmd->fcpDl),
485 scsi_get_resid(cmnd), fcpi_parm,
487 scsi_set_resid(cmnd, scsi_bufflen(cmnd));
488 host_status = DID_ERROR;
491 * The cmnd->underflow is the minimum number of bytes that must
492 * be transfered for this command. Provided a sense condition
493 * is not present, make sure the actual amount transferred is at
494 * least the underflow value or fail.
496 if (!(resp_info & SNS_LEN_VALID) &&
497 (scsi_status == SAM_STAT_GOOD) &&
498 (scsi_bufflen(cmnd) - scsi_get_resid(cmnd)
499 < cmnd->underflow)) {
500 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
501 "0717 FCP command x%x residual "
502 "underrun converted to error "
503 "Data: x%x x%x x%x\n",
504 cmnd->cmnd[0], scsi_bufflen(cmnd),
505 scsi_get_resid(cmnd), cmnd->underflow);
506 host_status = DID_ERROR;
508 } else if (resp_info & RESID_OVER) {
509 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
510 "0720 FCP command x%x residual overrun error. "
511 "Data: x%x x%x \n", cmnd->cmnd[0],
512 scsi_bufflen(cmnd), scsi_get_resid(cmnd));
513 host_status = DID_ERROR;
516 * Check SLI validation that all the transfer was actually done
517 * (fcpi_parm should be zero). Apply check only to reads.
519 } else if ((scsi_status == SAM_STAT_GOOD) && fcpi_parm &&
520 (cmnd->sc_data_direction == DMA_FROM_DEVICE)) {
521 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR,
522 "0734 FCP Read Check Error Data: "
524 be32_to_cpu(fcpcmd->fcpDl),
525 be32_to_cpu(fcprsp->rspResId),
526 fcpi_parm, cmnd->cmnd[0]);
527 host_status = DID_ERROR;
528 scsi_set_resid(cmnd, scsi_bufflen(cmnd));
532 cmnd->result = ScsiResult(host_status, scsi_status);
536 lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
537 struct lpfc_iocbq *pIocbOut)
539 struct lpfc_scsi_buf *lpfc_cmd =
540 (struct lpfc_scsi_buf *) pIocbIn->context1;
541 struct lpfc_vport *vport = pIocbIn->vport;
542 struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
543 struct lpfc_nodelist *pnode = rdata->pnode;
544 struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
546 struct scsi_device *sdev, *tmp_sdev;
550 lpfc_cmd->result = pIocbOut->iocb.un.ulpWord[4];
551 lpfc_cmd->status = pIocbOut->iocb.ulpStatus;
553 if (lpfc_cmd->status) {
554 if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT &&
555 (lpfc_cmd->result & IOERR_DRVR_MASK))
556 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
557 else if (lpfc_cmd->status >= IOSTAT_CNT)
558 lpfc_cmd->status = IOSTAT_DEFAULT;
560 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
561 "0729 FCP cmd x%x failed <%d/%d> "
562 "status: x%x result: x%x Data: x%x x%x\n",
564 cmd->device ? cmd->device->id : 0xffff,
565 cmd->device ? cmd->device->lun : 0xffff,
566 lpfc_cmd->status, lpfc_cmd->result,
567 pIocbOut->iocb.ulpContext,
568 lpfc_cmd->cur_iocbq.iocb.ulpIoTag);
570 switch (lpfc_cmd->status) {
571 case IOSTAT_FCP_RSP_ERROR:
572 /* Call FCP RSP handler to determine result */
573 lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut);
575 case IOSTAT_NPORT_BSY:
576 case IOSTAT_FABRIC_BSY:
577 cmd->result = ScsiResult(DID_BUS_BUSY, 0);
579 case IOSTAT_LOCAL_REJECT:
580 if (lpfc_cmd->result == RJT_UNAVAIL_PERM ||
581 lpfc_cmd->result == IOERR_NO_RESOURCES ||
582 lpfc_cmd->result == RJT_LOGIN_REQUIRED) {
583 cmd->result = ScsiResult(DID_REQUEUE, 0);
585 } /* else: fall through */
587 cmd->result = ScsiResult(DID_ERROR, 0);
591 if (!pnode || !NLP_CHK_NODE_ACT(pnode)
592 || (pnode->nlp_state != NLP_STE_MAPPED_NODE))
593 cmd->result = ScsiResult(DID_BUS_BUSY, SAM_STAT_BUSY);
595 cmd->result = ScsiResult(DID_OK, 0);
598 if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) {
599 uint32_t *lp = (uint32_t *)cmd->sense_buffer;
601 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
602 "0710 Iodone <%d/%d> cmd %p, error "
603 "x%x SNS x%x x%x Data: x%x x%x\n",
604 cmd->device->id, cmd->device->lun, cmd,
605 cmd->result, *lp, *(lp + 3), cmd->retries,
606 scsi_get_resid(cmd));
609 result = cmd->result;
611 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
612 spin_lock_irqsave(sdev->host->host_lock, flags);
613 lpfc_cmd->pCmd = NULL; /* This must be done before scsi_done */
614 spin_unlock_irqrestore(sdev->host->host_lock, flags);
617 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
619 * If there is a thread waiting for command completion
620 * wake up the thread.
622 spin_lock_irqsave(sdev->host->host_lock, flags);
624 wake_up(lpfc_cmd->waitq);
625 spin_unlock_irqrestore(sdev->host->host_lock, flags);
626 lpfc_release_scsi_buf(phba, lpfc_cmd);
632 lpfc_rampup_queue_depth(vport, sdev);
634 if (!result && pnode && NLP_CHK_NODE_ACT(pnode) &&
635 ((jiffies - pnode->last_ramp_up_time) >
636 LPFC_Q_RAMP_UP_INTERVAL * HZ) &&
637 ((jiffies - pnode->last_q_full_time) >
638 LPFC_Q_RAMP_UP_INTERVAL * HZ) &&
639 (vport->cfg_lun_queue_depth > sdev->queue_depth)) {
640 shost_for_each_device(tmp_sdev, sdev->host) {
641 if (vport->cfg_lun_queue_depth > tmp_sdev->queue_depth){
642 if (tmp_sdev->id != sdev->id)
644 if (tmp_sdev->ordered_tags)
645 scsi_adjust_queue_depth(tmp_sdev,
647 tmp_sdev->queue_depth+1);
649 scsi_adjust_queue_depth(tmp_sdev,
651 tmp_sdev->queue_depth+1);
653 pnode->last_ramp_up_time = jiffies;
659 * Check for queue full. If the lun is reporting queue full, then
660 * back off the lun queue depth to prevent target overloads.
662 if (result == SAM_STAT_TASK_SET_FULL && pnode &&
663 NLP_CHK_NODE_ACT(pnode)) {
664 pnode->last_q_full_time = jiffies;
666 shost_for_each_device(tmp_sdev, sdev->host) {
667 if (tmp_sdev->id != sdev->id)
669 depth = scsi_track_queue_full(tmp_sdev,
670 tmp_sdev->queue_depth - 1);
673 * The queue depth cannot be lowered any more.
674 * Modify the returned error code to store
675 * the final depth value set by
676 * scsi_track_queue_full.
679 depth = sdev->host->cmd_per_lun;
682 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
683 "0711 detected queue full - lun queue "
684 "depth adjusted to %d.\n", depth);
689 * If there is a thread waiting for command completion
690 * wake up the thread.
692 spin_lock_irqsave(sdev->host->host_lock, flags);
694 wake_up(lpfc_cmd->waitq);
695 spin_unlock_irqrestore(sdev->host->host_lock, flags);
697 lpfc_release_scsi_buf(phba, lpfc_cmd);
701 lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
702 struct lpfc_nodelist *pnode)
704 struct lpfc_hba *phba = vport->phba;
705 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
706 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
707 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
708 struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq);
709 int datadir = scsi_cmnd->sc_data_direction;
712 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
715 lpfc_cmd->fcp_rsp->rspSnsLen = 0;
716 /* clear task management bits */
717 lpfc_cmd->fcp_cmnd->fcpCntl2 = 0;
719 int_to_scsilun(lpfc_cmd->pCmd->device->lun,
720 &lpfc_cmd->fcp_cmnd->fcp_lun);
722 memcpy(&fcp_cmnd->fcpCdb[0], scsi_cmnd->cmnd, 16);
724 if (scsi_populate_tag_msg(scsi_cmnd, tag)) {
726 case HEAD_OF_QUEUE_TAG:
727 fcp_cmnd->fcpCntl1 = HEAD_OF_Q;
729 case ORDERED_QUEUE_TAG:
730 fcp_cmnd->fcpCntl1 = ORDERED_Q;
733 fcp_cmnd->fcpCntl1 = SIMPLE_Q;
737 fcp_cmnd->fcpCntl1 = 0;
740 * There are three possibilities here - use scatter-gather segment, use
741 * the single mapping, or neither. Start the lpfc command prep by
742 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
745 if (scsi_sg_count(scsi_cmnd)) {
746 if (datadir == DMA_TO_DEVICE) {
747 iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR;
748 iocb_cmd->un.fcpi.fcpi_parm = 0;
750 fcp_cmnd->fcpCntl3 = WRITE_DATA;
751 phba->fc4OutputRequests++;
753 iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR;
754 iocb_cmd->ulpPU = PARM_READ_CHECK;
755 iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd);
756 fcp_cmnd->fcpCntl3 = READ_DATA;
757 phba->fc4InputRequests++;
760 iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR;
761 iocb_cmd->un.fcpi.fcpi_parm = 0;
763 fcp_cmnd->fcpCntl3 = 0;
764 phba->fc4ControlRequests++;
768 * Finish initializing those IOCB fields that are independent
769 * of the scsi_cmnd request_buffer
771 piocbq->iocb.ulpContext = pnode->nlp_rpi;
772 if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE)
773 piocbq->iocb.ulpFCP2Rcvy = 1;
775 piocbq->iocb.ulpFCP2Rcvy = 0;
777 piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f);
778 piocbq->context1 = lpfc_cmd;
779 piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
780 piocbq->iocb.ulpTimeout = lpfc_cmd->timeout;
781 piocbq->vport = vport;
785 lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport,
786 struct lpfc_scsi_buf *lpfc_cmd,
788 uint8_t task_mgmt_cmd)
790 struct lpfc_iocbq *piocbq;
792 struct fcp_cmnd *fcp_cmnd;
793 struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
794 struct lpfc_nodelist *ndlp = rdata->pnode;
796 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) ||
797 ndlp->nlp_state != NLP_STE_MAPPED_NODE)
800 piocbq = &(lpfc_cmd->cur_iocbq);
801 piocbq->vport = vport;
803 piocb = &piocbq->iocb;
805 fcp_cmnd = lpfc_cmd->fcp_cmnd;
806 int_to_scsilun(lun, &lpfc_cmd->fcp_cmnd->fcp_lun);
807 fcp_cmnd->fcpCntl2 = task_mgmt_cmd;
809 piocb->ulpCommand = CMD_FCP_ICMND64_CR;
811 piocb->ulpContext = ndlp->nlp_rpi;
812 if (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
813 piocb->ulpFCP2Rcvy = 1;
815 piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f);
817 /* ulpTimeout is only one byte */
818 if (lpfc_cmd->timeout > 0xff) {
820 * Do not timeout the command at the firmware level.
821 * The driver will provide the timeout mechanism.
823 piocb->ulpTimeout = 0;
825 piocb->ulpTimeout = lpfc_cmd->timeout;
832 lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba,
833 struct lpfc_iocbq *cmdiocbq,
834 struct lpfc_iocbq *rspiocbq)
836 struct lpfc_scsi_buf *lpfc_cmd =
837 (struct lpfc_scsi_buf *) cmdiocbq->context1;
839 lpfc_release_scsi_buf(phba, lpfc_cmd);
844 lpfc_scsi_tgt_reset(struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_vport *vport,
845 unsigned tgt_id, unsigned int lun,
846 struct lpfc_rport_data *rdata)
848 struct lpfc_hba *phba = vport->phba;
849 struct lpfc_iocbq *iocbq;
850 struct lpfc_iocbq *iocbqrsp;
853 if (!rdata->pnode || !NLP_CHK_NODE_ACT(rdata->pnode))
856 lpfc_cmd->rdata = rdata;
857 ret = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun,
862 iocbq = &lpfc_cmd->cur_iocbq;
863 iocbqrsp = lpfc_sli_get_iocbq(phba);
868 /* Issue Target Reset to TGT <num> */
869 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
870 "0702 Issue Target Reset to TGT %d Data: x%x x%x\n",
871 tgt_id, rdata->pnode->nlp_rpi, rdata->pnode->nlp_flag);
872 ret = lpfc_sli_issue_iocb_wait(phba,
873 &phba->sli.ring[phba->sli.fcp_ring],
874 iocbq, iocbqrsp, lpfc_cmd->timeout);
875 if (ret != IOCB_SUCCESS) {
876 if (ret == IOCB_TIMEDOUT)
877 iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
878 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
881 lpfc_cmd->result = iocbqrsp->iocb.un.ulpWord[4];
882 lpfc_cmd->status = iocbqrsp->iocb.ulpStatus;
883 if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT &&
884 (lpfc_cmd->result & IOERR_DRVR_MASK))
885 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
888 lpfc_sli_release_iocbq(phba, iocbqrsp);
893 lpfc_info(struct Scsi_Host *host)
895 struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata;
896 struct lpfc_hba *phba = vport->phba;
898 static char lpfcinfobuf[384];
900 memset(lpfcinfobuf,0,384);
901 if (phba && phba->pcidev){
902 strncpy(lpfcinfobuf, phba->ModelDesc, 256);
903 len = strlen(lpfcinfobuf);
904 snprintf(lpfcinfobuf + len,
906 " on PCI bus %02x device %02x irq %d",
907 phba->pcidev->bus->number,
910 len = strlen(lpfcinfobuf);
912 snprintf(lpfcinfobuf + len,
921 static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba)
923 unsigned long poll_tmo_expires =
924 (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo));
926 if (phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt)
927 mod_timer(&phba->fcp_poll_timer,
931 void lpfc_poll_start_timer(struct lpfc_hba * phba)
933 lpfc_poll_rearm_timer(phba);
936 void lpfc_poll_timeout(unsigned long ptr)
938 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
940 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
941 lpfc_sli_poll_fcp_ring (phba);
942 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
943 lpfc_poll_rearm_timer(phba);
948 lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
950 struct Scsi_Host *shost = cmnd->device->host;
951 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
952 struct lpfc_hba *phba = vport->phba;
953 struct lpfc_sli *psli = &phba->sli;
954 struct lpfc_rport_data *rdata = cmnd->device->hostdata;
955 struct lpfc_nodelist *ndlp = rdata->pnode;
956 struct lpfc_scsi_buf *lpfc_cmd;
957 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
960 err = fc_remote_port_chkready(rport);
963 goto out_fail_command;
967 * Catch race where our node has transitioned, but the
968 * transport is still transitioning.
970 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
971 cmnd->result = ScsiResult(DID_BUS_BUSY, 0);
972 goto out_fail_command;
974 lpfc_cmd = lpfc_get_scsi_buf(phba);
975 if (lpfc_cmd == NULL) {
976 lpfc_adjust_queue_depth(phba);
978 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
979 "0707 driver's buffer pool is empty, "
985 * Store the midlayer's command structure for the completion phase
986 * and complete the command initialization.
988 lpfc_cmd->pCmd = cmnd;
989 lpfc_cmd->rdata = rdata;
990 lpfc_cmd->timeout = 0;
991 cmnd->host_scribble = (unsigned char *)lpfc_cmd;
992 cmnd->scsi_done = done;
994 err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd);
996 goto out_host_busy_free_buf;
998 lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp);
1000 err = lpfc_sli_issue_iocb(phba, &phba->sli.ring[psli->fcp_ring],
1001 &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB);
1003 goto out_host_busy_free_buf;
1005 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
1006 lpfc_sli_poll_fcp_ring(phba);
1007 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
1008 lpfc_poll_rearm_timer(phba);
1013 out_host_busy_free_buf:
1014 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
1015 lpfc_release_scsi_buf(phba, lpfc_cmd);
1017 return SCSI_MLQUEUE_HOST_BUSY;
1025 lpfc_block_error_handler(struct scsi_cmnd *cmnd)
1027 struct Scsi_Host *shost = cmnd->device->host;
1028 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
1030 spin_lock_irq(shost->host_lock);
1031 while (rport->port_state == FC_PORTSTATE_BLOCKED) {
1032 spin_unlock_irq(shost->host_lock);
1034 spin_lock_irq(shost->host_lock);
1036 spin_unlock_irq(shost->host_lock);
1041 lpfc_abort_handler(struct scsi_cmnd *cmnd)
1043 struct Scsi_Host *shost = cmnd->device->host;
1044 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1045 struct lpfc_hba *phba = vport->phba;
1046 struct lpfc_sli_ring *pring = &phba->sli.ring[phba->sli.fcp_ring];
1047 struct lpfc_iocbq *iocb;
1048 struct lpfc_iocbq *abtsiocb;
1049 struct lpfc_scsi_buf *lpfc_cmd;
1052 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq);
1054 lpfc_block_error_handler(cmnd);
1055 lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble;
1059 * If pCmd field of the corresponding lpfc_scsi_buf structure
1060 * points to a different SCSI command, then the driver has
1061 * already completed this command, but the midlayer did not
1062 * see the completion before the eh fired. Just return
1065 iocb = &lpfc_cmd->cur_iocbq;
1066 if (lpfc_cmd->pCmd != cmnd)
1069 BUG_ON(iocb->context1 != lpfc_cmd);
1071 abtsiocb = lpfc_sli_get_iocbq(phba);
1072 if (abtsiocb == NULL) {
1078 * The scsi command can not be in txq and it is in flight because the
1079 * pCmd is still pointig at the SCSI command we have to abort. There
1080 * is no need to search the txcmplq. Just send an abort to the FW.
1084 icmd = &abtsiocb->iocb;
1085 icmd->un.acxri.abortType = ABORT_TYPE_ABTS;
1086 icmd->un.acxri.abortContextTag = cmd->ulpContext;
1087 icmd->un.acxri.abortIoTag = cmd->ulpIoTag;
1090 icmd->ulpClass = cmd->ulpClass;
1091 if (lpfc_is_link_up(phba))
1092 icmd->ulpCommand = CMD_ABORT_XRI_CN;
1094 icmd->ulpCommand = CMD_CLOSE_XRI_CN;
1096 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
1097 abtsiocb->vport = vport;
1098 if (lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0) == IOCB_ERROR) {
1099 lpfc_sli_release_iocbq(phba, abtsiocb);
1104 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
1105 lpfc_sli_poll_fcp_ring (phba);
1107 lpfc_cmd->waitq = &waitq;
1108 /* Wait for abort to complete */
1109 wait_event_timeout(waitq,
1110 (lpfc_cmd->pCmd != cmnd),
1111 (2*vport->cfg_devloss_tmo*HZ));
1113 spin_lock_irq(shost->host_lock);
1114 lpfc_cmd->waitq = NULL;
1115 spin_unlock_irq(shost->host_lock);
1117 if (lpfc_cmd->pCmd == cmnd) {
1119 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1120 "0748 abort handler timed out waiting "
1121 "for abort to complete: ret %#x, ID %d, "
1122 "LUN %d, snum %#lx\n",
1123 ret, cmnd->device->id, cmnd->device->lun,
1124 cmnd->serial_number);
1128 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
1129 "0749 SCSI Layer I/O Abort Request Status x%x ID %d "
1130 "LUN %d snum %#lx\n", ret, cmnd->device->id,
1131 cmnd->device->lun, cmnd->serial_number);
1136 lpfc_device_reset_handler(struct scsi_cmnd *cmnd)
1138 struct Scsi_Host *shost = cmnd->device->host;
1139 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1140 struct lpfc_hba *phba = vport->phba;
1141 struct lpfc_scsi_buf *lpfc_cmd;
1142 struct lpfc_iocbq *iocbq, *iocbqrsp;
1143 struct lpfc_rport_data *rdata = cmnd->device->hostdata;
1144 struct lpfc_nodelist *pnode = rdata->pnode;
1145 uint32_t cmd_result = 0, cmd_status = 0;
1147 int iocb_status = IOCB_SUCCESS;
1150 lpfc_block_error_handler(cmnd);
1153 * If target is not in a MAPPED state, delay the reset until
1154 * target is rediscovered or devloss timeout expires.
1157 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
1160 if (pnode->nlp_state != NLP_STE_MAPPED_NODE) {
1161 schedule_timeout_uninterruptible(msecs_to_jiffies(500));
1163 rdata = cmnd->device->hostdata;
1165 (loopcnt > ((vport->cfg_devloss_tmo * 2) + 1))){
1166 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1167 "0721 LUN Reset rport "
1168 "failure: cnt x%x rdata x%p\n",
1172 pnode = rdata->pnode;
1173 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
1176 if (pnode->nlp_state == NLP_STE_MAPPED_NODE)
1180 lpfc_cmd = lpfc_get_scsi_buf(phba);
1181 if (lpfc_cmd == NULL)
1184 lpfc_cmd->timeout = 60;
1185 lpfc_cmd->rdata = rdata;
1187 ret = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, cmnd->device->lun,
1190 goto out_free_scsi_buf;
1192 iocbq = &lpfc_cmd->cur_iocbq;
1194 /* get a buffer for this IOCB command response */
1195 iocbqrsp = lpfc_sli_get_iocbq(phba);
1196 if (iocbqrsp == NULL)
1197 goto out_free_scsi_buf;
1199 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
1200 "0703 Issue target reset to TGT %d LUN %d "
1201 "rpi x%x nlp_flag x%x\n", cmnd->device->id,
1202 cmnd->device->lun, pnode->nlp_rpi, pnode->nlp_flag);
1203 iocb_status = lpfc_sli_issue_iocb_wait(phba,
1204 &phba->sli.ring[phba->sli.fcp_ring],
1205 iocbq, iocbqrsp, lpfc_cmd->timeout);
1207 if (iocb_status == IOCB_TIMEDOUT)
1208 iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
1210 if (iocb_status == IOCB_SUCCESS)
1215 cmd_result = iocbqrsp->iocb.un.ulpWord[4];
1216 cmd_status = iocbqrsp->iocb.ulpStatus;
1218 lpfc_sli_release_iocbq(phba, iocbqrsp);
1221 * All outstanding txcmplq I/Os should have been aborted by the device.
1222 * Unfortunately, some targets do not abide by this forcing the driver
1225 cnt = lpfc_sli_sum_iocb(vport, cmnd->device->id, cmnd->device->lun,
1228 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
1229 cmnd->device->id, cmnd->device->lun,
1233 schedule_timeout_uninterruptible(LPFC_RESET_WAIT*HZ);
1236 > (2 * vport->cfg_devloss_tmo)/LPFC_RESET_WAIT)
1239 cnt = lpfc_sli_sum_iocb(vport, cmnd->device->id,
1240 cmnd->device->lun, LPFC_CTX_LUN);
1244 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1245 "0719 device reset I/O flush failure: "
1251 if (iocb_status != IOCB_TIMEDOUT) {
1252 lpfc_release_scsi_buf(phba, lpfc_cmd);
1254 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1255 "0713 SCSI layer issued device reset (%d, %d) "
1256 "return x%x status x%x result x%x\n",
1257 cmnd->device->id, cmnd->device->lun, ret,
1258 cmd_status, cmd_result);
1264 lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
1266 struct Scsi_Host *shost = cmnd->device->host;
1267 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1268 struct lpfc_hba *phba = vport->phba;
1269 struct lpfc_nodelist *ndlp = NULL;
1271 int ret = FAILED, i, err_count = 0;
1273 struct lpfc_scsi_buf * lpfc_cmd;
1275 lpfc_block_error_handler(cmnd);
1277 lpfc_cmd = lpfc_get_scsi_buf(phba);
1278 if (lpfc_cmd == NULL)
1281 /* The lpfc_cmd storage is reused. Set all loop invariants. */
1282 lpfc_cmd->timeout = 60;
1285 * Since the driver manages a single bus device, reset all
1286 * targets known to the driver. Should any target reset
1287 * fail, this routine returns failure to the midlayer.
1289 for (i = 0; i < LPFC_MAX_TARGET; i++) {
1290 /* Search for mapped node by target ID */
1292 spin_lock_irq(shost->host_lock);
1293 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
1294 if (!NLP_CHK_NODE_ACT(ndlp))
1296 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
1297 i == ndlp->nlp_sid &&
1303 spin_unlock_irq(shost->host_lock);
1307 ret = lpfc_scsi_tgt_reset(lpfc_cmd, vport, i,
1309 ndlp->rport->dd_data);
1310 if (ret != SUCCESS) {
1311 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1312 "0700 Bus Reset on target %d failed\n",
1319 if (ret != IOCB_TIMEDOUT)
1320 lpfc_release_scsi_buf(phba, lpfc_cmd);
1328 * All outstanding txcmplq I/Os should have been aborted by
1329 * the targets. Unfortunately, some targets do not abide by
1330 * this forcing the driver to double check.
1332 cnt = lpfc_sli_sum_iocb(vport, 0, 0, LPFC_CTX_HOST);
1334 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
1335 0, 0, LPFC_CTX_HOST);
1338 schedule_timeout_uninterruptible(LPFC_RESET_WAIT*HZ);
1341 > (2 * vport->cfg_devloss_tmo)/LPFC_RESET_WAIT)
1344 cnt = lpfc_sli_sum_iocb(vport, 0, 0, LPFC_CTX_HOST);
1348 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1349 "0715 Bus Reset I/O flush failure: "
1350 "cnt x%x left x%x\n", cnt, i);
1354 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1355 "0714 SCSI layer issued Bus Reset Data: x%x\n", ret);
1361 lpfc_slave_alloc(struct scsi_device *sdev)
1363 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
1364 struct lpfc_hba *phba = vport->phba;
1365 struct lpfc_scsi_buf *scsi_buf = NULL;
1366 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1367 uint32_t total = 0, i;
1368 uint32_t num_to_alloc = 0;
1369 unsigned long flags;
1371 if (!rport || fc_remote_port_chkready(rport))
1374 sdev->hostdata = rport->dd_data;
1377 * Populate the cmds_per_lun count scsi_bufs into this host's globally
1378 * available list of scsi buffers. Don't allocate more than the
1379 * HBA limit conveyed to the midlayer via the host structure. The
1380 * formula accounts for the lun_queue_depth + error handlers + 1
1381 * extra. This list of scsi bufs exists for the lifetime of the driver.
1383 total = phba->total_scsi_bufs;
1384 num_to_alloc = vport->cfg_lun_queue_depth + 2;
1386 /* Allow some exchanges to be available always to complete discovery */
1387 if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
1388 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
1389 "0704 At limitation of %d preallocated "
1390 "command buffers\n", total);
1392 /* Allow some exchanges to be available always to complete discovery */
1393 } else if (total + num_to_alloc >
1394 phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
1395 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
1396 "0705 Allocation request of %d "
1397 "command buffers will exceed max of %d. "
1398 "Reducing allocation request to %d.\n",
1399 num_to_alloc, phba->cfg_hba_queue_depth,
1400 (phba->cfg_hba_queue_depth - total));
1401 num_to_alloc = phba->cfg_hba_queue_depth - total;
1404 for (i = 0; i < num_to_alloc; i++) {
1405 scsi_buf = lpfc_new_scsi_buf(vport);
1407 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1408 "0706 Failed to allocate "
1409 "command buffer\n");
1413 spin_lock_irqsave(&phba->scsi_buf_list_lock, flags);
1414 phba->total_scsi_bufs++;
1415 list_add_tail(&scsi_buf->list, &phba->lpfc_scsi_buf_list);
1416 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, flags);
1422 lpfc_slave_configure(struct scsi_device *sdev)
1424 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
1425 struct lpfc_hba *phba = vport->phba;
1426 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1428 if (sdev->tagged_supported)
1429 scsi_activate_tcq(sdev, vport->cfg_lun_queue_depth);
1431 scsi_deactivate_tcq(sdev, vport->cfg_lun_queue_depth);
1434 * Initialize the fc transport attributes for the target
1435 * containing this scsi device. Also note that the driver's
1436 * target pointer is stored in the starget_data for the
1437 * driver's sysfs entry point functions.
1439 rport->dev_loss_tmo = vport->cfg_devloss_tmo;
1441 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
1442 lpfc_sli_poll_fcp_ring(phba);
1443 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
1444 lpfc_poll_rearm_timer(phba);
1451 lpfc_slave_destroy(struct scsi_device *sdev)
1453 sdev->hostdata = NULL;
1458 struct scsi_host_template lpfc_template = {
1459 .module = THIS_MODULE,
1460 .name = LPFC_DRIVER_NAME,
1462 .queuecommand = lpfc_queuecommand,
1463 .eh_abort_handler = lpfc_abort_handler,
1464 .eh_device_reset_handler= lpfc_device_reset_handler,
1465 .eh_bus_reset_handler = lpfc_bus_reset_handler,
1466 .slave_alloc = lpfc_slave_alloc,
1467 .slave_configure = lpfc_slave_configure,
1468 .slave_destroy = lpfc_slave_destroy,
1469 .scan_finished = lpfc_scan_finished,
1471 .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
1472 .cmd_per_lun = LPFC_CMD_PER_LUN,
1473 .use_clustering = ENABLE_CLUSTERING,
1474 .shost_attrs = lpfc_hba_attrs,
1475 .max_sectors = 0xFFFF,
1478 struct scsi_host_template lpfc_vport_template = {
1479 .module = THIS_MODULE,
1480 .name = LPFC_DRIVER_NAME,
1482 .queuecommand = lpfc_queuecommand,
1483 .eh_abort_handler = lpfc_abort_handler,
1484 .eh_device_reset_handler= lpfc_device_reset_handler,
1485 .eh_bus_reset_handler = lpfc_bus_reset_handler,
1486 .slave_alloc = lpfc_slave_alloc,
1487 .slave_configure = lpfc_slave_configure,
1488 .slave_destroy = lpfc_slave_destroy,
1489 .scan_finished = lpfc_scan_finished,
1491 .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
1492 .cmd_per_lun = LPFC_CMD_PER_LUN,
1493 .use_clustering = ENABLE_CLUSTERING,
1494 .shost_attrs = lpfc_vport_attrs,
1495 .max_sectors = 0xFFFF,