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)
55 spin_lock_irqsave(&phba->hbalock, flags);
56 atomic_inc(&phba->num_rsrc_err);
57 phba->last_rsrc_error_time = jiffies;
59 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
60 spin_unlock_irqrestore(&phba->hbalock, flags);
64 phba->last_ramp_down_time = jiffies;
66 spin_unlock_irqrestore(&phba->hbalock, flags);
68 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
69 evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE;
71 phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE;
72 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
75 lpfc_worker_wake_up(phba);
80 * This function is called with no lock held when there is a successful
81 * SCSI command completion.
84 lpfc_rampup_queue_depth(struct lpfc_vport *vport,
85 struct scsi_device *sdev)
88 struct lpfc_hba *phba = vport->phba;
90 atomic_inc(&phba->num_cmd_success);
92 if (vport->cfg_lun_queue_depth <= sdev->queue_depth)
94 spin_lock_irqsave(&phba->hbalock, flags);
95 if (((phba->last_ramp_up_time + QUEUE_RAMP_UP_INTERVAL) > jiffies) ||
96 ((phba->last_rsrc_error_time + QUEUE_RAMP_UP_INTERVAL ) > jiffies)) {
97 spin_unlock_irqrestore(&phba->hbalock, flags);
100 phba->last_ramp_up_time = jiffies;
101 spin_unlock_irqrestore(&phba->hbalock, flags);
103 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
104 evt_posted = phba->pport->work_port_events & WORKER_RAMP_UP_QUEUE;
106 phba->pport->work_port_events |= WORKER_RAMP_UP_QUEUE;
107 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
110 lpfc_worker_wake_up(phba);
115 lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
117 struct lpfc_vport **vports;
118 struct Scsi_Host *shost;
119 struct scsi_device *sdev;
120 unsigned long new_queue_depth;
121 unsigned long num_rsrc_err, num_cmd_success;
124 num_rsrc_err = atomic_read(&phba->num_rsrc_err);
125 num_cmd_success = atomic_read(&phba->num_cmd_success);
127 vports = lpfc_create_vport_work_array(phba);
129 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
130 shost = lpfc_shost_from_vport(vports[i]);
131 shost_for_each_device(sdev, shost) {
133 sdev->queue_depth * num_rsrc_err /
134 (num_rsrc_err + num_cmd_success);
135 if (!new_queue_depth)
136 new_queue_depth = sdev->queue_depth - 1;
138 new_queue_depth = sdev->queue_depth -
140 if (sdev->ordered_tags)
141 scsi_adjust_queue_depth(sdev,
145 scsi_adjust_queue_depth(sdev,
150 lpfc_destroy_vport_work_array(phba, vports);
151 atomic_set(&phba->num_rsrc_err, 0);
152 atomic_set(&phba->num_cmd_success, 0);
156 lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
158 struct lpfc_vport **vports;
159 struct Scsi_Host *shost;
160 struct scsi_device *sdev;
163 vports = lpfc_create_vport_work_array(phba);
165 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
166 shost = lpfc_shost_from_vport(vports[i]);
167 shost_for_each_device(sdev, shost) {
168 if (vports[i]->cfg_lun_queue_depth <=
171 if (sdev->ordered_tags)
172 scsi_adjust_queue_depth(sdev,
174 sdev->queue_depth+1);
176 scsi_adjust_queue_depth(sdev,
178 sdev->queue_depth+1);
181 lpfc_destroy_vport_work_array(phba, vports);
182 atomic_set(&phba->num_rsrc_err, 0);
183 atomic_set(&phba->num_cmd_success, 0);
187 * This routine allocates a scsi buffer, which contains all the necessary
188 * information needed to initiate a SCSI I/O. The non-DMAable buffer region
189 * contains information to build the IOCB. The DMAable region contains
190 * memory for the FCP CMND, FCP RSP, and the inital BPL. In addition to
191 * allocating memeory, the FCP CMND and FCP RSP BDEs are setup in the BPL
192 * and the BPL BDE is setup in the IOCB.
194 static struct lpfc_scsi_buf *
195 lpfc_new_scsi_buf(struct lpfc_vport *vport)
197 struct lpfc_hba *phba = vport->phba;
198 struct lpfc_scsi_buf *psb;
199 struct ulp_bde64 *bpl;
201 dma_addr_t pdma_phys;
204 psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL);
209 * Get memory from the pci pool to map the virt space to pci bus space
210 * for an I/O. The DMA buffer includes space for the struct fcp_cmnd,
211 * struct fcp_rsp and the number of bde's necessary to support the
214 psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool, GFP_KERNEL,
221 /* Initialize virtual ptrs to dma_buf region. */
222 memset(psb->data, 0, phba->cfg_sg_dma_buf_size);
224 /* Allocate iotag for psb->cur_iocbq. */
225 iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq);
227 pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
228 psb->data, psb->dma_handle);
232 psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP;
234 psb->fcp_cmnd = psb->data;
235 psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd);
236 psb->fcp_bpl = psb->data + sizeof(struct fcp_cmnd) +
237 sizeof(struct fcp_rsp);
239 /* Initialize local short-hand pointers. */
241 pdma_phys = psb->dma_handle;
244 * The first two bdes are the FCP_CMD and FCP_RSP. The balance are sg
245 * list bdes. Initialize the first two and leave the rest for
248 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys));
249 bpl->addrLow = le32_to_cpu(putPaddrLow(pdma_phys));
250 bpl->tus.f.bdeSize = sizeof (struct fcp_cmnd);
251 bpl->tus.f.bdeFlags = BUFF_USE_CMND;
252 bpl->tus.w = le32_to_cpu(bpl->tus.w);
255 /* Setup the physical region for the FCP RSP */
256 pdma_phys += sizeof (struct fcp_cmnd);
257 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys));
258 bpl->addrLow = le32_to_cpu(putPaddrLow(pdma_phys));
259 bpl->tus.f.bdeSize = sizeof (struct fcp_rsp);
260 bpl->tus.f.bdeFlags = (BUFF_USE_CMND | BUFF_USE_RCV);
261 bpl->tus.w = le32_to_cpu(bpl->tus.w);
264 * Since the IOCB for the FCP I/O is built into this lpfc_scsi_buf,
265 * initialize it with all known data now.
267 pdma_phys += (sizeof (struct fcp_rsp));
268 iocb = &psb->cur_iocbq.iocb;
269 iocb->un.fcpi64.bdl.ulpIoTag32 = 0;
270 iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys);
271 iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys);
272 iocb->un.fcpi64.bdl.bdeSize = (2 * sizeof (struct ulp_bde64));
273 iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDL;
274 iocb->ulpBdeCount = 1;
275 iocb->ulpClass = CLASS3;
280 static struct lpfc_scsi_buf*
281 lpfc_get_scsi_buf(struct lpfc_hba * phba)
283 struct lpfc_scsi_buf * lpfc_cmd = NULL;
284 struct list_head *scsi_buf_list = &phba->lpfc_scsi_buf_list;
285 unsigned long iflag = 0;
287 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
288 list_remove_head(scsi_buf_list, lpfc_cmd, struct lpfc_scsi_buf, list);
290 lpfc_cmd->seg_cnt = 0;
291 lpfc_cmd->nonsg_phys = 0;
293 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
298 lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
300 unsigned long iflag = 0;
302 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
304 list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list);
305 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
309 lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
311 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
312 struct scatterlist *sgel = NULL;
313 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
314 struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl;
315 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
317 uint32_t i, num_bde = 0;
318 int nseg, datadir = scsi_cmnd->sc_data_direction;
321 * There are three possibilities here - use scatter-gather segment, use
322 * the single mapping, or neither. Start the lpfc command prep by
323 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
327 if (scsi_sg_count(scsi_cmnd)) {
329 * The driver stores the segment count returned from pci_map_sg
330 * because this a count of dma-mappings used to map the use_sg
331 * pages. They are not guaranteed to be the same for those
332 * architectures that implement an IOMMU.
335 nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd),
336 scsi_sg_count(scsi_cmnd), datadir);
340 lpfc_cmd->seg_cnt = nseg;
341 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
342 printk(KERN_ERR "%s: Too many sg segments from "
343 "dma_map_sg. Config %d, seg_cnt %d",
344 __FUNCTION__, phba->cfg_sg_seg_cnt,
346 scsi_dma_unmap(scsi_cmnd);
351 * The driver established a maximum scatter-gather segment count
352 * during probe that limits the number of sg elements in any
353 * single scsi command. Just run through the seg_cnt and format
356 scsi_for_each_sg(scsi_cmnd, sgel, nseg, i) {
357 physaddr = sg_dma_address(sgel);
358 bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr));
359 bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
360 bpl->tus.f.bdeSize = sg_dma_len(sgel);
361 if (datadir == DMA_TO_DEVICE)
362 bpl->tus.f.bdeFlags = 0;
364 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
365 bpl->tus.w = le32_to_cpu(bpl->tus.w);
372 * Finish initializing those IOCB fields that are dependent on the
373 * scsi_cmnd request_buffer. Note that the bdeSize is explicitly
374 * reinitialized since all iocb memory resources are used many times
375 * for transmit, receive, and continuation bpl's.
377 iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof (struct ulp_bde64));
378 iocb_cmd->un.fcpi64.bdl.bdeSize +=
379 (num_bde * sizeof (struct ulp_bde64));
380 iocb_cmd->ulpBdeCount = 1;
382 fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd));
387 lpfc_scsi_unprep_dma_buf(struct lpfc_hba * phba, struct lpfc_scsi_buf * psb)
390 * There are only two special cases to consider. (1) the scsi command
391 * requested scatter-gather usage or (2) the scsi command allocated
392 * a request buffer, but did not request use_sg. There is a third
393 * case, but it does not require resource deallocation.
395 if (psb->seg_cnt > 0)
396 scsi_dma_unmap(psb->pCmd);
400 lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
401 struct lpfc_iocbq *rsp_iocb)
403 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
404 struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd;
405 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
406 uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm;
407 uint32_t resp_info = fcprsp->rspStatus2;
408 uint32_t scsi_status = fcprsp->rspStatus3;
410 uint32_t host_status = DID_OK;
412 uint32_t logit = LOG_FCP | LOG_FCP_ERROR;
415 * If this is a task management command, there is no
416 * scsi packet associated with this lpfc_cmd. The driver
419 if (fcpcmd->fcpCntl2) {
424 if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) {
425 uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen);
426 if (snslen > SCSI_SENSE_BUFFERSIZE)
427 snslen = SCSI_SENSE_BUFFERSIZE;
429 if (resp_info & RSP_LEN_VALID)
430 rsplen = be32_to_cpu(fcprsp->rspRspLen);
431 memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen);
433 lp = (uint32_t *)cmnd->sense_buffer;
435 if (!scsi_status && (resp_info & RESID_UNDER))
438 lpfc_printf_vlog(vport, KERN_WARNING, logit,
439 "0730 FCP command x%x failed: x%x SNS x%x x%x "
440 "Data: x%x x%x x%x x%x x%x\n",
441 cmnd->cmnd[0], scsi_status,
442 be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info,
443 be32_to_cpu(fcprsp->rspResId),
444 be32_to_cpu(fcprsp->rspSnsLen),
445 be32_to_cpu(fcprsp->rspRspLen),
448 if (resp_info & RSP_LEN_VALID) {
449 rsplen = be32_to_cpu(fcprsp->rspRspLen);
450 if ((rsplen != 0 && rsplen != 4 && rsplen != 8) ||
451 (fcprsp->rspInfo3 != RSP_NO_FAILURE)) {
452 host_status = DID_ERROR;
457 scsi_set_resid(cmnd, 0);
458 if (resp_info & RESID_UNDER) {
459 scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId));
461 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
462 "0716 FCP Read Underrun, expected %d, "
463 "residual %d Data: x%x x%x x%x\n",
464 be32_to_cpu(fcpcmd->fcpDl),
465 scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0],
469 * If there is an under run check if under run reported by
470 * storage array is same as the under run reported by HBA.
471 * If this is not same, there is a dropped frame.
473 if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) &&
475 (scsi_get_resid(cmnd) != fcpi_parm)) {
476 lpfc_printf_vlog(vport, KERN_WARNING,
477 LOG_FCP | LOG_FCP_ERROR,
478 "0735 FCP Read Check Error "
479 "and Underrun Data: x%x x%x x%x x%x\n",
480 be32_to_cpu(fcpcmd->fcpDl),
481 scsi_get_resid(cmnd), fcpi_parm,
483 scsi_set_resid(cmnd, scsi_bufflen(cmnd));
484 host_status = DID_ERROR;
487 * The cmnd->underflow is the minimum number of bytes that must
488 * be transfered for this command. Provided a sense condition
489 * is not present, make sure the actual amount transferred is at
490 * least the underflow value or fail.
492 if (!(resp_info & SNS_LEN_VALID) &&
493 (scsi_status == SAM_STAT_GOOD) &&
494 (scsi_bufflen(cmnd) - scsi_get_resid(cmnd)
495 < cmnd->underflow)) {
496 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
497 "0717 FCP command x%x residual "
498 "underrun converted to error "
499 "Data: x%x x%x x%x\n",
500 cmnd->cmnd[0], scsi_bufflen(cmnd),
501 scsi_get_resid(cmnd), cmnd->underflow);
502 host_status = DID_ERROR;
504 } else if (resp_info & RESID_OVER) {
505 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
506 "0720 FCP command x%x residual overrun error. "
507 "Data: x%x x%x \n", cmnd->cmnd[0],
508 scsi_bufflen(cmnd), scsi_get_resid(cmnd));
509 host_status = DID_ERROR;
512 * Check SLI validation that all the transfer was actually done
513 * (fcpi_parm should be zero). Apply check only to reads.
515 } else if ((scsi_status == SAM_STAT_GOOD) && fcpi_parm &&
516 (cmnd->sc_data_direction == DMA_FROM_DEVICE)) {
517 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR,
518 "0734 FCP Read Check Error Data: "
520 be32_to_cpu(fcpcmd->fcpDl),
521 be32_to_cpu(fcprsp->rspResId),
522 fcpi_parm, cmnd->cmnd[0]);
523 host_status = DID_ERROR;
524 scsi_set_resid(cmnd, scsi_bufflen(cmnd));
528 cmnd->result = ScsiResult(host_status, scsi_status);
532 lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
533 struct lpfc_iocbq *pIocbOut)
535 struct lpfc_scsi_buf *lpfc_cmd =
536 (struct lpfc_scsi_buf *) pIocbIn->context1;
537 struct lpfc_vport *vport = pIocbIn->vport;
538 struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
539 struct lpfc_nodelist *pnode = rdata->pnode;
540 struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
542 struct scsi_device *sdev, *tmp_sdev;
546 lpfc_cmd->result = pIocbOut->iocb.un.ulpWord[4];
547 lpfc_cmd->status = pIocbOut->iocb.ulpStatus;
549 if (lpfc_cmd->status) {
550 if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT &&
551 (lpfc_cmd->result & IOERR_DRVR_MASK))
552 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
553 else if (lpfc_cmd->status >= IOSTAT_CNT)
554 lpfc_cmd->status = IOSTAT_DEFAULT;
556 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
557 "0729 FCP cmd x%x failed <%d/%d> "
558 "status: x%x result: x%x Data: x%x x%x\n",
560 cmd->device ? cmd->device->id : 0xffff,
561 cmd->device ? cmd->device->lun : 0xffff,
562 lpfc_cmd->status, lpfc_cmd->result,
563 pIocbOut->iocb.ulpContext,
564 lpfc_cmd->cur_iocbq.iocb.ulpIoTag);
566 switch (lpfc_cmd->status) {
567 case IOSTAT_FCP_RSP_ERROR:
568 /* Call FCP RSP handler to determine result */
569 lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut);
571 case IOSTAT_NPORT_BSY:
572 case IOSTAT_FABRIC_BSY:
573 cmd->result = ScsiResult(DID_BUS_BUSY, 0);
575 case IOSTAT_LOCAL_REJECT:
576 if (lpfc_cmd->result == RJT_UNAVAIL_PERM ||
577 lpfc_cmd->result == IOERR_NO_RESOURCES ||
578 lpfc_cmd->result == RJT_LOGIN_REQUIRED) {
579 cmd->result = ScsiResult(DID_REQUEUE, 0);
581 } /* else: fall through */
583 cmd->result = ScsiResult(DID_ERROR, 0);
587 if (!pnode || !NLP_CHK_NODE_ACT(pnode)
588 || (pnode->nlp_state != NLP_STE_MAPPED_NODE))
589 cmd->result = ScsiResult(DID_BUS_BUSY, SAM_STAT_BUSY);
591 cmd->result = ScsiResult(DID_OK, 0);
594 if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) {
595 uint32_t *lp = (uint32_t *)cmd->sense_buffer;
597 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
598 "0710 Iodone <%d/%d> cmd %p, error "
599 "x%x SNS x%x x%x Data: x%x x%x\n",
600 cmd->device->id, cmd->device->lun, cmd,
601 cmd->result, *lp, *(lp + 3), cmd->retries,
602 scsi_get_resid(cmd));
605 result = cmd->result;
607 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
610 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
612 * If there is a thread waiting for command completion
613 * wake up the thread.
615 spin_lock_irqsave(sdev->host->host_lock, flags);
616 lpfc_cmd->pCmd = NULL;
618 wake_up(lpfc_cmd->waitq);
619 spin_unlock_irqrestore(sdev->host->host_lock, flags);
620 lpfc_release_scsi_buf(phba, lpfc_cmd);
626 lpfc_rampup_queue_depth(vport, sdev);
628 if (!result && pnode && NLP_CHK_NODE_ACT(pnode) &&
629 ((jiffies - pnode->last_ramp_up_time) >
630 LPFC_Q_RAMP_UP_INTERVAL * HZ) &&
631 ((jiffies - pnode->last_q_full_time) >
632 LPFC_Q_RAMP_UP_INTERVAL * HZ) &&
633 (vport->cfg_lun_queue_depth > sdev->queue_depth)) {
634 shost_for_each_device(tmp_sdev, sdev->host) {
635 if (vport->cfg_lun_queue_depth > tmp_sdev->queue_depth){
636 if (tmp_sdev->id != sdev->id)
638 if (tmp_sdev->ordered_tags)
639 scsi_adjust_queue_depth(tmp_sdev,
641 tmp_sdev->queue_depth+1);
643 scsi_adjust_queue_depth(tmp_sdev,
645 tmp_sdev->queue_depth+1);
647 pnode->last_ramp_up_time = jiffies;
653 * Check for queue full. If the lun is reporting queue full, then
654 * back off the lun queue depth to prevent target overloads.
656 if (result == SAM_STAT_TASK_SET_FULL && pnode &&
657 NLP_CHK_NODE_ACT(pnode)) {
658 pnode->last_q_full_time = jiffies;
660 shost_for_each_device(tmp_sdev, sdev->host) {
661 if (tmp_sdev->id != sdev->id)
663 depth = scsi_track_queue_full(tmp_sdev,
664 tmp_sdev->queue_depth - 1);
667 * The queue depth cannot be lowered any more.
668 * Modify the returned error code to store
669 * the final depth value set by
670 * scsi_track_queue_full.
673 depth = sdev->host->cmd_per_lun;
676 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
677 "0711 detected queue full - lun queue "
678 "depth adjusted to %d.\n", depth);
683 * If there is a thread waiting for command completion
684 * wake up the thread.
686 spin_lock_irqsave(sdev->host->host_lock, flags);
687 lpfc_cmd->pCmd = NULL;
689 wake_up(lpfc_cmd->waitq);
690 spin_unlock_irqrestore(sdev->host->host_lock, flags);
692 lpfc_release_scsi_buf(phba, lpfc_cmd);
696 lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
697 struct lpfc_nodelist *pnode)
699 struct lpfc_hba *phba = vport->phba;
700 struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
701 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
702 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
703 struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq);
704 int datadir = scsi_cmnd->sc_data_direction;
707 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
710 lpfc_cmd->fcp_rsp->rspSnsLen = 0;
711 /* clear task management bits */
712 lpfc_cmd->fcp_cmnd->fcpCntl2 = 0;
714 int_to_scsilun(lpfc_cmd->pCmd->device->lun,
715 &lpfc_cmd->fcp_cmnd->fcp_lun);
717 memcpy(&fcp_cmnd->fcpCdb[0], scsi_cmnd->cmnd, 16);
719 if (scsi_populate_tag_msg(scsi_cmnd, tag)) {
721 case HEAD_OF_QUEUE_TAG:
722 fcp_cmnd->fcpCntl1 = HEAD_OF_Q;
724 case ORDERED_QUEUE_TAG:
725 fcp_cmnd->fcpCntl1 = ORDERED_Q;
728 fcp_cmnd->fcpCntl1 = SIMPLE_Q;
732 fcp_cmnd->fcpCntl1 = 0;
735 * There are three possibilities here - use scatter-gather segment, use
736 * the single mapping, or neither. Start the lpfc command prep by
737 * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
740 if (scsi_sg_count(scsi_cmnd)) {
741 if (datadir == DMA_TO_DEVICE) {
742 iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR;
743 iocb_cmd->un.fcpi.fcpi_parm = 0;
745 fcp_cmnd->fcpCntl3 = WRITE_DATA;
746 phba->fc4OutputRequests++;
748 iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR;
749 iocb_cmd->ulpPU = PARM_READ_CHECK;
750 iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd);
751 fcp_cmnd->fcpCntl3 = READ_DATA;
752 phba->fc4InputRequests++;
755 iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR;
756 iocb_cmd->un.fcpi.fcpi_parm = 0;
758 fcp_cmnd->fcpCntl3 = 0;
759 phba->fc4ControlRequests++;
763 * Finish initializing those IOCB fields that are independent
764 * of the scsi_cmnd request_buffer
766 piocbq->iocb.ulpContext = pnode->nlp_rpi;
767 if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE)
768 piocbq->iocb.ulpFCP2Rcvy = 1;
770 piocbq->iocb.ulpFCP2Rcvy = 0;
772 piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f);
773 piocbq->context1 = lpfc_cmd;
774 piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
775 piocbq->iocb.ulpTimeout = lpfc_cmd->timeout;
776 piocbq->vport = vport;
780 lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport,
781 struct lpfc_scsi_buf *lpfc_cmd,
783 uint8_t task_mgmt_cmd)
785 struct lpfc_iocbq *piocbq;
787 struct fcp_cmnd *fcp_cmnd;
788 struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
789 struct lpfc_nodelist *ndlp = rdata->pnode;
791 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) ||
792 ndlp->nlp_state != NLP_STE_MAPPED_NODE)
795 piocbq = &(lpfc_cmd->cur_iocbq);
796 piocbq->vport = vport;
798 piocb = &piocbq->iocb;
800 fcp_cmnd = lpfc_cmd->fcp_cmnd;
801 int_to_scsilun(lun, &lpfc_cmd->fcp_cmnd->fcp_lun);
802 fcp_cmnd->fcpCntl2 = task_mgmt_cmd;
804 piocb->ulpCommand = CMD_FCP_ICMND64_CR;
806 piocb->ulpContext = ndlp->nlp_rpi;
807 if (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
808 piocb->ulpFCP2Rcvy = 1;
810 piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f);
812 /* ulpTimeout is only one byte */
813 if (lpfc_cmd->timeout > 0xff) {
815 * Do not timeout the command at the firmware level.
816 * The driver will provide the timeout mechanism.
818 piocb->ulpTimeout = 0;
820 piocb->ulpTimeout = lpfc_cmd->timeout;
827 lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba,
828 struct lpfc_iocbq *cmdiocbq,
829 struct lpfc_iocbq *rspiocbq)
831 struct lpfc_scsi_buf *lpfc_cmd =
832 (struct lpfc_scsi_buf *) cmdiocbq->context1;
834 lpfc_release_scsi_buf(phba, lpfc_cmd);
839 lpfc_scsi_tgt_reset(struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_vport *vport,
840 unsigned tgt_id, unsigned int lun,
841 struct lpfc_rport_data *rdata)
843 struct lpfc_hba *phba = vport->phba;
844 struct lpfc_iocbq *iocbq;
845 struct lpfc_iocbq *iocbqrsp;
849 if (!rdata->pnode || !NLP_CHK_NODE_ACT(rdata->pnode))
852 lpfc_cmd->rdata = rdata;
853 status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun,
858 iocbq = &lpfc_cmd->cur_iocbq;
859 iocbqrsp = lpfc_sli_get_iocbq(phba);
864 /* Issue Target Reset to TGT <num> */
865 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
866 "0702 Issue Target Reset to TGT %d Data: x%x x%x\n",
867 tgt_id, rdata->pnode->nlp_rpi, rdata->pnode->nlp_flag);
868 status = lpfc_sli_issue_iocb_wait(phba,
869 &phba->sli.ring[phba->sli.fcp_ring],
870 iocbq, iocbqrsp, lpfc_cmd->timeout);
871 if (status != IOCB_SUCCESS) {
872 if (status == IOCB_TIMEDOUT) {
873 iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
877 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
880 lpfc_cmd->result = iocbqrsp->iocb.un.ulpWord[4];
881 lpfc_cmd->status = iocbqrsp->iocb.ulpStatus;
882 if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT &&
883 (lpfc_cmd->result & IOERR_DRVR_MASK))
884 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
887 lpfc_sli_release_iocbq(phba, iocbqrsp);
892 lpfc_info(struct Scsi_Host *host)
894 struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata;
895 struct lpfc_hba *phba = vport->phba;
897 static char lpfcinfobuf[384];
899 memset(lpfcinfobuf,0,384);
900 if (phba && phba->pcidev){
901 strncpy(lpfcinfobuf, phba->ModelDesc, 256);
902 len = strlen(lpfcinfobuf);
903 snprintf(lpfcinfobuf + len,
905 " on PCI bus %02x device %02x irq %d",
906 phba->pcidev->bus->number,
909 len = strlen(lpfcinfobuf);
911 snprintf(lpfcinfobuf + len,
920 static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba)
922 unsigned long poll_tmo_expires =
923 (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo));
925 if (phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt)
926 mod_timer(&phba->fcp_poll_timer,
930 void lpfc_poll_start_timer(struct lpfc_hba * phba)
932 lpfc_poll_rearm_timer(phba);
935 void lpfc_poll_timeout(unsigned long ptr)
937 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
939 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
940 lpfc_sli_poll_fcp_ring (phba);
941 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
942 lpfc_poll_rearm_timer(phba);
947 lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
949 struct Scsi_Host *shost = cmnd->device->host;
950 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
951 struct lpfc_hba *phba = vport->phba;
952 struct lpfc_sli *psli = &phba->sli;
953 struct lpfc_rport_data *rdata = cmnd->device->hostdata;
954 struct lpfc_nodelist *ndlp = rdata->pnode;
955 struct lpfc_scsi_buf *lpfc_cmd;
956 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
959 err = fc_remote_port_chkready(rport);
962 goto out_fail_command;
966 * Catch race where our node has transitioned, but the
967 * transport is still transitioning.
969 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
970 cmnd->result = ScsiResult(DID_BUS_BUSY, 0);
971 goto out_fail_command;
973 lpfc_cmd = lpfc_get_scsi_buf(phba);
974 if (lpfc_cmd == NULL) {
975 lpfc_adjust_queue_depth(phba);
977 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
978 "0707 driver's buffer pool is empty, "
984 * Store the midlayer's command structure for the completion phase
985 * and complete the command initialization.
987 lpfc_cmd->pCmd = cmnd;
988 lpfc_cmd->rdata = rdata;
989 lpfc_cmd->timeout = 0;
990 cmnd->host_scribble = (unsigned char *)lpfc_cmd;
991 cmnd->scsi_done = done;
993 err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd);
995 goto out_host_busy_free_buf;
997 lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp);
999 err = lpfc_sli_issue_iocb(phba, &phba->sli.ring[psli->fcp_ring],
1000 &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB);
1002 goto out_host_busy_free_buf;
1004 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
1005 lpfc_sli_poll_fcp_ring(phba);
1006 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
1007 lpfc_poll_rearm_timer(phba);
1012 out_host_busy_free_buf:
1013 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
1014 lpfc_release_scsi_buf(phba, lpfc_cmd);
1016 return SCSI_MLQUEUE_HOST_BUSY;
1024 lpfc_block_error_handler(struct scsi_cmnd *cmnd)
1026 struct Scsi_Host *shost = cmnd->device->host;
1027 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
1029 spin_lock_irq(shost->host_lock);
1030 while (rport->port_state == FC_PORTSTATE_BLOCKED) {
1031 spin_unlock_irq(shost->host_lock);
1033 spin_lock_irq(shost->host_lock);
1035 spin_unlock_irq(shost->host_lock);
1040 lpfc_abort_handler(struct scsi_cmnd *cmnd)
1042 struct Scsi_Host *shost = cmnd->device->host;
1043 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1044 struct lpfc_hba *phba = vport->phba;
1045 struct lpfc_sli_ring *pring = &phba->sli.ring[phba->sli.fcp_ring];
1046 struct lpfc_iocbq *iocb;
1047 struct lpfc_iocbq *abtsiocb;
1048 struct lpfc_scsi_buf *lpfc_cmd;
1051 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq);
1053 lpfc_block_error_handler(cmnd);
1054 lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble;
1058 * If pCmd field of the corresponding lpfc_scsi_buf structure
1059 * points to a different SCSI command, then the driver has
1060 * already completed this command, but the midlayer did not
1061 * see the completion before the eh fired. Just return
1064 iocb = &lpfc_cmd->cur_iocbq;
1065 if (lpfc_cmd->pCmd != cmnd)
1068 BUG_ON(iocb->context1 != lpfc_cmd);
1070 abtsiocb = lpfc_sli_get_iocbq(phba);
1071 if (abtsiocb == NULL) {
1077 * The scsi command can not be in txq and it is in flight because the
1078 * pCmd is still pointig at the SCSI command we have to abort. There
1079 * is no need to search the txcmplq. Just send an abort to the FW.
1083 icmd = &abtsiocb->iocb;
1084 icmd->un.acxri.abortType = ABORT_TYPE_ABTS;
1085 icmd->un.acxri.abortContextTag = cmd->ulpContext;
1086 icmd->un.acxri.abortIoTag = cmd->ulpIoTag;
1089 icmd->ulpClass = cmd->ulpClass;
1090 if (lpfc_is_link_up(phba))
1091 icmd->ulpCommand = CMD_ABORT_XRI_CN;
1093 icmd->ulpCommand = CMD_CLOSE_XRI_CN;
1095 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
1096 abtsiocb->vport = vport;
1097 if (lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0) == IOCB_ERROR) {
1098 lpfc_sli_release_iocbq(phba, abtsiocb);
1103 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
1104 lpfc_sli_poll_fcp_ring (phba);
1106 lpfc_cmd->waitq = &waitq;
1107 /* Wait for abort to complete */
1108 wait_event_timeout(waitq,
1109 (lpfc_cmd->pCmd != cmnd),
1110 (2*vport->cfg_devloss_tmo*HZ));
1112 spin_lock_irq(shost->host_lock);
1113 lpfc_cmd->waitq = NULL;
1114 spin_unlock_irq(shost->host_lock);
1116 if (lpfc_cmd->pCmd == cmnd) {
1118 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1119 "0748 abort handler timed out waiting "
1120 "for abort to complete: ret %#x, ID %d, "
1121 "LUN %d, snum %#lx\n",
1122 ret, cmnd->device->id, cmnd->device->lun,
1123 cmnd->serial_number);
1127 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
1128 "0749 SCSI Layer I/O Abort Request Status x%x ID %d "
1129 "LUN %d snum %#lx\n", ret, cmnd->device->id,
1130 cmnd->device->lun, cmnd->serial_number);
1135 lpfc_device_reset_handler(struct scsi_cmnd *cmnd)
1137 struct Scsi_Host *shost = cmnd->device->host;
1138 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1139 struct lpfc_hba *phba = vport->phba;
1140 struct lpfc_scsi_buf *lpfc_cmd;
1141 struct lpfc_iocbq *iocbq, *iocbqrsp;
1142 struct lpfc_rport_data *rdata = cmnd->device->hostdata;
1143 struct lpfc_nodelist *pnode = rdata->pnode;
1144 unsigned long later;
1149 lpfc_block_error_handler(cmnd);
1151 * If target is not in a MAPPED state, delay the reset until
1152 * target is rediscovered or devloss timeout expires.
1154 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
1155 while (time_after(later, jiffies)) {
1156 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
1158 if (pnode->nlp_state == NLP_STE_MAPPED_NODE)
1160 schedule_timeout_uninterruptible(msecs_to_jiffies(500));
1161 rdata = cmnd->device->hostdata;
1164 pnode = rdata->pnode;
1166 if (!rdata || pnode->nlp_state != NLP_STE_MAPPED_NODE) {
1167 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1168 "0721 LUN Reset rport "
1169 "failure: msec x%x rdata x%p\n",
1170 jiffies_to_msecs(jiffies - later), rdata);
1173 lpfc_cmd = lpfc_get_scsi_buf(phba);
1174 if (lpfc_cmd == NULL)
1176 lpfc_cmd->timeout = 60;
1177 lpfc_cmd->rdata = rdata;
1179 status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd,
1183 lpfc_release_scsi_buf(phba, lpfc_cmd);
1186 iocbq = &lpfc_cmd->cur_iocbq;
1188 /* get a buffer for this IOCB command response */
1189 iocbqrsp = lpfc_sli_get_iocbq(phba);
1190 if (iocbqrsp == NULL) {
1191 lpfc_release_scsi_buf(phba, lpfc_cmd);
1194 lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
1195 "0703 Issue target reset to TGT %d LUN %d "
1196 "rpi x%x nlp_flag x%x\n", cmnd->device->id,
1197 cmnd->device->lun, pnode->nlp_rpi, pnode->nlp_flag);
1198 status = lpfc_sli_issue_iocb_wait(phba,
1199 &phba->sli.ring[phba->sli.fcp_ring],
1200 iocbq, iocbqrsp, lpfc_cmd->timeout);
1201 if (status == IOCB_TIMEDOUT) {
1202 iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
1203 ret = TIMEOUT_ERROR;
1205 if (status != IOCB_SUCCESS)
1207 lpfc_release_scsi_buf(phba, lpfc_cmd);
1209 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1210 "0713 SCSI layer issued device reset (%d, %d) "
1211 "return x%x status x%x result x%x\n",
1212 cmnd->device->id, cmnd->device->lun, ret,
1213 iocbqrsp->iocb.ulpStatus,
1214 iocbqrsp->iocb.un.ulpWord[4]);
1215 lpfc_sli_release_iocbq(phba, iocbqrsp);
1216 cnt = lpfc_sli_sum_iocb(vport, cmnd->device->id, cmnd->device->lun,
1219 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
1220 cmnd->device->id, cmnd->device->lun,
1222 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
1223 while (time_after(later, jiffies) && cnt) {
1224 schedule_timeout_uninterruptible(msecs_to_jiffies(20));
1225 cnt = lpfc_sli_sum_iocb(vport, cmnd->device->id,
1226 cmnd->device->lun, LPFC_CTX_TGT);
1229 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1230 "0719 device reset I/O flush failure: "
1238 lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
1240 struct Scsi_Host *shost = cmnd->device->host;
1241 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1242 struct lpfc_hba *phba = vport->phba;
1243 struct lpfc_nodelist *ndlp = NULL;
1245 int ret = SUCCESS, status, i;
1247 struct lpfc_scsi_buf * lpfc_cmd;
1248 unsigned long later;
1250 lpfc_block_error_handler(cmnd);
1252 * Since the driver manages a single bus device, reset all
1253 * targets known to the driver. Should any target reset
1254 * fail, this routine returns failure to the midlayer.
1256 for (i = 0; i < LPFC_MAX_TARGET; i++) {
1257 /* Search for mapped node by target ID */
1259 spin_lock_irq(shost->host_lock);
1260 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
1261 if (!NLP_CHK_NODE_ACT(ndlp))
1263 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
1264 ndlp->nlp_sid == i &&
1270 spin_unlock_irq(shost->host_lock);
1273 lpfc_cmd = lpfc_get_scsi_buf(phba);
1275 lpfc_cmd->timeout = 60;
1276 status = lpfc_scsi_tgt_reset(lpfc_cmd, vport, i,
1278 ndlp->rport->dd_data);
1279 if (status != TIMEOUT_ERROR)
1280 lpfc_release_scsi_buf(phba, lpfc_cmd);
1282 if (!lpfc_cmd || status != SUCCESS) {
1283 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1284 "0700 Bus Reset on target %d failed\n",
1290 * All outstanding txcmplq I/Os should have been aborted by
1291 * the targets. Unfortunately, some targets do not abide by
1292 * this forcing the driver to double check.
1294 cnt = lpfc_sli_sum_iocb(vport, 0, 0, LPFC_CTX_HOST);
1296 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
1297 0, 0, LPFC_CTX_HOST);
1298 later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
1299 while (time_after(later, jiffies) && cnt) {
1300 schedule_timeout_uninterruptible(msecs_to_jiffies(20));
1301 cnt = lpfc_sli_sum_iocb(vport, 0, 0, LPFC_CTX_HOST);
1304 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1305 "0715 Bus Reset I/O flush failure: "
1306 "cnt x%x left x%x\n", cnt, i);
1309 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1310 "0714 SCSI layer issued Bus Reset Data: x%x\n", ret);
1315 lpfc_slave_alloc(struct scsi_device *sdev)
1317 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
1318 struct lpfc_hba *phba = vport->phba;
1319 struct lpfc_scsi_buf *scsi_buf = NULL;
1320 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1321 uint32_t total = 0, i;
1322 uint32_t num_to_alloc = 0;
1323 unsigned long flags;
1325 if (!rport || fc_remote_port_chkready(rport))
1328 sdev->hostdata = rport->dd_data;
1331 * Populate the cmds_per_lun count scsi_bufs into this host's globally
1332 * available list of scsi buffers. Don't allocate more than the
1333 * HBA limit conveyed to the midlayer via the host structure. The
1334 * formula accounts for the lun_queue_depth + error handlers + 1
1335 * extra. This list of scsi bufs exists for the lifetime of the driver.
1337 total = phba->total_scsi_bufs;
1338 num_to_alloc = vport->cfg_lun_queue_depth + 2;
1340 /* Allow some exchanges to be available always to complete discovery */
1341 if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
1342 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
1343 "0704 At limitation of %d preallocated "
1344 "command buffers\n", total);
1346 /* Allow some exchanges to be available always to complete discovery */
1347 } else if (total + num_to_alloc >
1348 phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
1349 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
1350 "0705 Allocation request of %d "
1351 "command buffers will exceed max of %d. "
1352 "Reducing allocation request to %d.\n",
1353 num_to_alloc, phba->cfg_hba_queue_depth,
1354 (phba->cfg_hba_queue_depth - total));
1355 num_to_alloc = phba->cfg_hba_queue_depth - total;
1358 for (i = 0; i < num_to_alloc; i++) {
1359 scsi_buf = lpfc_new_scsi_buf(vport);
1361 lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
1362 "0706 Failed to allocate "
1363 "command buffer\n");
1367 spin_lock_irqsave(&phba->scsi_buf_list_lock, flags);
1368 phba->total_scsi_bufs++;
1369 list_add_tail(&scsi_buf->list, &phba->lpfc_scsi_buf_list);
1370 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, flags);
1376 lpfc_slave_configure(struct scsi_device *sdev)
1378 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
1379 struct lpfc_hba *phba = vport->phba;
1380 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1382 if (sdev->tagged_supported)
1383 scsi_activate_tcq(sdev, vport->cfg_lun_queue_depth);
1385 scsi_deactivate_tcq(sdev, vport->cfg_lun_queue_depth);
1388 * Initialize the fc transport attributes for the target
1389 * containing this scsi device. Also note that the driver's
1390 * target pointer is stored in the starget_data for the
1391 * driver's sysfs entry point functions.
1393 rport->dev_loss_tmo = vport->cfg_devloss_tmo;
1395 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
1396 lpfc_sli_poll_fcp_ring(phba);
1397 if (phba->cfg_poll & DISABLE_FCP_RING_INT)
1398 lpfc_poll_rearm_timer(phba);
1405 lpfc_slave_destroy(struct scsi_device *sdev)
1407 sdev->hostdata = NULL;
1412 struct scsi_host_template lpfc_template = {
1413 .module = THIS_MODULE,
1414 .name = LPFC_DRIVER_NAME,
1416 .queuecommand = lpfc_queuecommand,
1417 .eh_abort_handler = lpfc_abort_handler,
1418 .eh_device_reset_handler= lpfc_device_reset_handler,
1419 .eh_bus_reset_handler = lpfc_bus_reset_handler,
1420 .slave_alloc = lpfc_slave_alloc,
1421 .slave_configure = lpfc_slave_configure,
1422 .slave_destroy = lpfc_slave_destroy,
1423 .scan_finished = lpfc_scan_finished,
1425 .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
1426 .cmd_per_lun = LPFC_CMD_PER_LUN,
1427 .use_clustering = ENABLE_CLUSTERING,
1428 .shost_attrs = lpfc_hba_attrs,
1429 .max_sectors = 0xFFFF,
1432 struct scsi_host_template lpfc_vport_template = {
1433 .module = THIS_MODULE,
1434 .name = LPFC_DRIVER_NAME,
1436 .queuecommand = lpfc_queuecommand,
1437 .eh_abort_handler = lpfc_abort_handler,
1438 .eh_device_reset_handler= lpfc_device_reset_handler,
1439 .eh_bus_reset_handler = lpfc_bus_reset_handler,
1440 .slave_alloc = lpfc_slave_alloc,
1441 .slave_configure = lpfc_slave_configure,
1442 .slave_destroy = lpfc_slave_destroy,
1443 .scan_finished = lpfc_scan_finished,
1445 .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
1446 .cmd_per_lun = LPFC_CMD_PER_LUN,
1447 .use_clustering = ENABLE_CLUSTERING,
1448 .shost_attrs = lpfc_vport_attrs,
1449 .max_sectors = 0xFFFF,