| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1 | /******************************************************************* |
| 2 | * This file is part of the Emulex Linux Device Driver for * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3 | * Fibre Channel Host Bus Adapters. * |
James Smart | 9413aff | 2007-04-25 09:53:35 -0400 | [diff] [blame] | 4 | * Copyright (C) 2004-2007 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 5 | * EMULEX and SLI are trademarks of Emulex. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6 | * www.emulex.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8 | * * |
| 9 | * This program is free software; you can redistribute it and/or * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 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. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 20 | *******************************************************************/ |
| 21 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | #include <linux/pci.h> |
| 23 | #include <linux/interrupt.h> |
James Smart | a90f568 | 2006-08-17 11:58:04 -0400 | [diff] [blame] | 24 | #include <linux/delay.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 25 | |
| 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> |
| 31 | |
| 32 | #include "lpfc_version.h" |
| 33 | #include "lpfc_hw.h" |
| 34 | #include "lpfc_sli.h" |
| 35 | #include "lpfc_disc.h" |
| 36 | #include "lpfc_scsi.h" |
| 37 | #include "lpfc.h" |
| 38 | #include "lpfc_logmsg.h" |
| 39 | #include "lpfc_crtn.h" |
| 40 | |
| 41 | #define LPFC_RESET_WAIT 2 |
| 42 | #define LPFC_ABORT_WAIT 2 |
| 43 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 44 | /* |
| 45 | * This routine allocates a scsi buffer, which contains all the necessary |
| 46 | * information needed to initiate a SCSI I/O. The non-DMAable buffer region |
| 47 | * contains information to build the IOCB. The DMAable region contains |
| 48 | * memory for the FCP CMND, FCP RSP, and the inital BPL. In addition to |
| 49 | * allocating memeory, the FCP CMND and FCP RSP BDEs are setup in the BPL |
| 50 | * and the BPL BDE is setup in the IOCB. |
| 51 | */ |
| 52 | static struct lpfc_scsi_buf * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 53 | lpfc_new_scsi_buf(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 54 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 55 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 56 | struct lpfc_scsi_buf *psb; |
| 57 | struct ulp_bde64 *bpl; |
| 58 | IOCB_t *iocb; |
| 59 | dma_addr_t pdma_phys; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 60 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 61 | |
| 62 | psb = kmalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL); |
| 63 | if (!psb) |
| 64 | return NULL; |
| 65 | memset(psb, 0, sizeof (struct lpfc_scsi_buf)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 66 | |
| 67 | /* |
| 68 | * Get memory from the pci pool to map the virt space to pci bus space |
| 69 | * for an I/O. The DMA buffer includes space for the struct fcp_cmnd, |
| 70 | * struct fcp_rsp and the number of bde's necessary to support the |
| 71 | * sg_tablesize. |
| 72 | */ |
| 73 | psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool, GFP_KERNEL, |
| 74 | &psb->dma_handle); |
| 75 | if (!psb->data) { |
| 76 | kfree(psb); |
| 77 | return NULL; |
| 78 | } |
| 79 | |
| 80 | /* Initialize virtual ptrs to dma_buf region. */ |
| 81 | memset(psb->data, 0, phba->cfg_sg_dma_buf_size); |
| 82 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 83 | /* Allocate iotag for psb->cur_iocbq. */ |
| 84 | iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq); |
| 85 | if (iotag == 0) { |
| 86 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, |
| 87 | psb->data, psb->dma_handle); |
| 88 | kfree (psb); |
| 89 | return NULL; |
| 90 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 91 | psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 92 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 93 | psb->fcp_cmnd = psb->data; |
| 94 | psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd); |
| 95 | psb->fcp_bpl = psb->data + sizeof(struct fcp_cmnd) + |
| 96 | sizeof(struct fcp_rsp); |
| 97 | |
| 98 | /* Initialize local short-hand pointers. */ |
| 99 | bpl = psb->fcp_bpl; |
| 100 | pdma_phys = psb->dma_handle; |
| 101 | |
| 102 | /* |
| 103 | * The first two bdes are the FCP_CMD and FCP_RSP. The balance are sg |
| 104 | * list bdes. Initialize the first two and leave the rest for |
| 105 | * queuecommand. |
| 106 | */ |
| 107 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys)); |
| 108 | bpl->addrLow = le32_to_cpu(putPaddrLow(pdma_phys)); |
| 109 | bpl->tus.f.bdeSize = sizeof (struct fcp_cmnd); |
| 110 | bpl->tus.f.bdeFlags = BUFF_USE_CMND; |
| 111 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 112 | bpl++; |
| 113 | |
| 114 | /* Setup the physical region for the FCP RSP */ |
| 115 | pdma_phys += sizeof (struct fcp_cmnd); |
| 116 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys)); |
| 117 | bpl->addrLow = le32_to_cpu(putPaddrLow(pdma_phys)); |
| 118 | bpl->tus.f.bdeSize = sizeof (struct fcp_rsp); |
| 119 | bpl->tus.f.bdeFlags = (BUFF_USE_CMND | BUFF_USE_RCV); |
| 120 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 121 | |
| 122 | /* |
| 123 | * Since the IOCB for the FCP I/O is built into this lpfc_scsi_buf, |
| 124 | * initialize it with all known data now. |
| 125 | */ |
| 126 | pdma_phys += (sizeof (struct fcp_rsp)); |
| 127 | iocb = &psb->cur_iocbq.iocb; |
| 128 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; |
| 129 | iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys); |
| 130 | iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys); |
| 131 | iocb->un.fcpi64.bdl.bdeSize = (2 * sizeof (struct ulp_bde64)); |
| 132 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDL; |
| 133 | iocb->ulpBdeCount = 1; |
| 134 | iocb->ulpClass = CLASS3; |
| 135 | |
| 136 | return psb; |
| 137 | } |
| 138 | |
Adrian Bunk | 455c53e | 2006-01-06 20:21:28 +0100 | [diff] [blame] | 139 | static struct lpfc_scsi_buf* |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 140 | lpfc_get_scsi_buf(struct lpfc_hba * phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 141 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 142 | struct lpfc_scsi_buf * lpfc_cmd = NULL; |
| 143 | struct list_head *scsi_buf_list = &phba->lpfc_scsi_buf_list; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 144 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 145 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 146 | spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 147 | list_remove_head(scsi_buf_list, lpfc_cmd, struct lpfc_scsi_buf, list); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 148 | if (lpfc_cmd) { |
| 149 | lpfc_cmd->seg_cnt = 0; |
| 150 | lpfc_cmd->nonsg_phys = 0; |
| 151 | } |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 152 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 153 | return lpfc_cmd; |
| 154 | } |
| 155 | |
| 156 | static void |
| 157 | lpfc_release_scsi_buf(struct lpfc_hba * phba, struct lpfc_scsi_buf * psb) |
| 158 | { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 159 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 160 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 161 | spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 162 | psb->pCmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 163 | list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 164 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | static int |
| 168 | lpfc_scsi_prep_dma_buf(struct lpfc_hba * phba, struct lpfc_scsi_buf * lpfc_cmd) |
| 169 | { |
| 170 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 171 | struct scatterlist *sgel = NULL; |
| 172 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 173 | struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl; |
| 174 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 175 | dma_addr_t physaddr; |
| 176 | uint32_t i, num_bde = 0; |
| 177 | int datadir = scsi_cmnd->sc_data_direction; |
| 178 | int dma_error; |
| 179 | |
| 180 | /* |
| 181 | * There are three possibilities here - use scatter-gather segment, use |
| 182 | * the single mapping, or neither. Start the lpfc command prep by |
| 183 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 184 | * data bde entry. |
| 185 | */ |
| 186 | bpl += 2; |
| 187 | if (scsi_cmnd->use_sg) { |
| 188 | /* |
| 189 | * The driver stores the segment count returned from pci_map_sg |
| 190 | * because this a count of dma-mappings used to map the use_sg |
| 191 | * pages. They are not guaranteed to be the same for those |
| 192 | * architectures that implement an IOMMU. |
| 193 | */ |
| 194 | sgel = (struct scatterlist *)scsi_cmnd->request_buffer; |
| 195 | lpfc_cmd->seg_cnt = dma_map_sg(&phba->pcidev->dev, sgel, |
| 196 | scsi_cmnd->use_sg, datadir); |
| 197 | if (lpfc_cmd->seg_cnt == 0) |
| 198 | return 1; |
| 199 | |
| 200 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
| 201 | printk(KERN_ERR "%s: Too many sg segments from " |
| 202 | "dma_map_sg. Config %d, seg_cnt %d", |
| 203 | __FUNCTION__, phba->cfg_sg_seg_cnt, |
| 204 | lpfc_cmd->seg_cnt); |
| 205 | dma_unmap_sg(&phba->pcidev->dev, sgel, |
| 206 | lpfc_cmd->seg_cnt, datadir); |
| 207 | return 1; |
| 208 | } |
| 209 | |
| 210 | /* |
| 211 | * The driver established a maximum scatter-gather segment count |
| 212 | * during probe that limits the number of sg elements in any |
| 213 | * single scsi command. Just run through the seg_cnt and format |
| 214 | * the bde's. |
| 215 | */ |
| 216 | for (i = 0; i < lpfc_cmd->seg_cnt; i++) { |
| 217 | physaddr = sg_dma_address(sgel); |
| 218 | bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
| 219 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 220 | bpl->tus.f.bdeSize = sg_dma_len(sgel); |
| 221 | if (datadir == DMA_TO_DEVICE) |
| 222 | bpl->tus.f.bdeFlags = 0; |
| 223 | else |
| 224 | bpl->tus.f.bdeFlags = BUFF_USE_RCV; |
| 225 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 226 | bpl++; |
| 227 | sgel++; |
| 228 | num_bde++; |
| 229 | } |
| 230 | } else if (scsi_cmnd->request_buffer && scsi_cmnd->request_bufflen) { |
| 231 | physaddr = dma_map_single(&phba->pcidev->dev, |
| 232 | scsi_cmnd->request_buffer, |
| 233 | scsi_cmnd->request_bufflen, |
| 234 | datadir); |
| 235 | dma_error = dma_mapping_error(physaddr); |
| 236 | if (dma_error) { |
| 237 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 238 | "%d:0718 Unable to dma_map_single " |
| 239 | "request_buffer: x%x\n", |
| 240 | phba->brd_no, dma_error); |
| 241 | return 1; |
| 242 | } |
| 243 | |
| 244 | lpfc_cmd->nonsg_phys = physaddr; |
| 245 | bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
| 246 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 247 | bpl->tus.f.bdeSize = scsi_cmnd->request_bufflen; |
| 248 | if (datadir == DMA_TO_DEVICE) |
| 249 | bpl->tus.f.bdeFlags = 0; |
James.Smart@Emulex.Com | 483f05f | 2005-08-10 15:02:45 -0400 | [diff] [blame] | 250 | else |
| 251 | bpl->tus.f.bdeFlags = BUFF_USE_RCV; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 252 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 253 | num_bde = 1; |
| 254 | bpl++; |
| 255 | } |
| 256 | |
| 257 | /* |
| 258 | * Finish initializing those IOCB fields that are dependent on the |
James.Smart@Emulex.Com | 483f05f | 2005-08-10 15:02:45 -0400 | [diff] [blame] | 259 | * scsi_cmnd request_buffer. Note that the bdeSize is explicitly |
| 260 | * reinitialized since all iocb memory resources are used many times |
| 261 | * for transmit, receive, and continuation bpl's. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 262 | */ |
James.Smart@Emulex.Com | 483f05f | 2005-08-10 15:02:45 -0400 | [diff] [blame] | 263 | iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof (struct ulp_bde64)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 264 | iocb_cmd->un.fcpi64.bdl.bdeSize += |
| 265 | (num_bde * sizeof (struct ulp_bde64)); |
| 266 | iocb_cmd->ulpBdeCount = 1; |
| 267 | iocb_cmd->ulpLe = 1; |
| 268 | fcp_cmnd->fcpDl = be32_to_cpu(scsi_cmnd->request_bufflen); |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | static void |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 273 | lpfc_scsi_unprep_dma_buf(struct lpfc_hba * phba, struct lpfc_scsi_buf * psb) |
| 274 | { |
| 275 | /* |
| 276 | * There are only two special cases to consider. (1) the scsi command |
| 277 | * requested scatter-gather usage or (2) the scsi command allocated |
| 278 | * a request buffer, but did not request use_sg. There is a third |
| 279 | * case, but it does not require resource deallocation. |
| 280 | */ |
| 281 | if ((psb->seg_cnt > 0) && (psb->pCmd->use_sg)) { |
| 282 | dma_unmap_sg(&phba->pcidev->dev, psb->pCmd->request_buffer, |
| 283 | psb->seg_cnt, psb->pCmd->sc_data_direction); |
| 284 | } else { |
| 285 | if ((psb->nonsg_phys) && (psb->pCmd->request_bufflen)) { |
| 286 | dma_unmap_single(&phba->pcidev->dev, psb->nonsg_phys, |
| 287 | psb->pCmd->request_bufflen, |
| 288 | psb->pCmd->sc_data_direction); |
| 289 | } |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 294 | lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd, |
| 295 | struct lpfc_iocbq *rsp_iocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 296 | { |
| 297 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 298 | struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd; |
| 299 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 300 | struct lpfc_hba *phba = vport->phba; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 301 | uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 302 | uint32_t resp_info = fcprsp->rspStatus2; |
| 303 | uint32_t scsi_status = fcprsp->rspStatus3; |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 304 | uint32_t *lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 305 | uint32_t host_status = DID_OK; |
| 306 | uint32_t rsplen = 0; |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 307 | uint32_t logit = LOG_FCP | LOG_FCP_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 308 | |
| 309 | /* |
| 310 | * If this is a task management command, there is no |
| 311 | * scsi packet associated with this lpfc_cmd. The driver |
| 312 | * consumes it. |
| 313 | */ |
| 314 | if (fcpcmd->fcpCntl2) { |
| 315 | scsi_status = 0; |
| 316 | goto out; |
| 317 | } |
| 318 | |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 319 | if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) { |
| 320 | uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen); |
| 321 | if (snslen > SCSI_SENSE_BUFFERSIZE) |
| 322 | snslen = SCSI_SENSE_BUFFERSIZE; |
| 323 | |
| 324 | if (resp_info & RSP_LEN_VALID) |
| 325 | rsplen = be32_to_cpu(fcprsp->rspRspLen); |
| 326 | memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen); |
| 327 | } |
| 328 | lp = (uint32_t *)cmnd->sense_buffer; |
| 329 | |
| 330 | if (!scsi_status && (resp_info & RESID_UNDER)) |
| 331 | logit = LOG_FCP; |
| 332 | |
| 333 | lpfc_printf_log(phba, KERN_WARNING, logit, |
| 334 | "%d:0730 FCP command x%x failed: x%x SNS x%x x%x " |
| 335 | "Data: x%x x%x x%x x%x x%x\n", |
| 336 | phba->brd_no, cmnd->cmnd[0], scsi_status, |
| 337 | be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 338 | be32_to_cpu(fcprsp->rspResId), |
| 339 | be32_to_cpu(fcprsp->rspSnsLen), |
| 340 | be32_to_cpu(fcprsp->rspRspLen), |
| 341 | fcprsp->rspInfo3); |
| 342 | |
| 343 | if (resp_info & RSP_LEN_VALID) { |
| 344 | rsplen = be32_to_cpu(fcprsp->rspRspLen); |
| 345 | if ((rsplen != 0 && rsplen != 4 && rsplen != 8) || |
| 346 | (fcprsp->rspInfo3 != RSP_NO_FAILURE)) { |
| 347 | host_status = DID_ERROR; |
| 348 | goto out; |
| 349 | } |
| 350 | } |
| 351 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 352 | cmnd->resid = 0; |
| 353 | if (resp_info & RESID_UNDER) { |
| 354 | cmnd->resid = be32_to_cpu(fcprsp->rspResId); |
| 355 | |
| 356 | lpfc_printf_log(phba, KERN_INFO, LOG_FCP, |
| 357 | "%d:0716 FCP Read Underrun, expected %d, " |
| 358 | "residual %d Data: x%x x%x x%x\n", phba->brd_no, |
| 359 | be32_to_cpu(fcpcmd->fcpDl), cmnd->resid, |
| 360 | fcpi_parm, cmnd->cmnd[0], cmnd->underflow); |
| 361 | |
| 362 | /* |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 363 | * If there is an under run check if under run reported by |
| 364 | * storage array is same as the under run reported by HBA. |
| 365 | * If this is not same, there is a dropped frame. |
| 366 | */ |
| 367 | if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) && |
| 368 | fcpi_parm && |
| 369 | (cmnd->resid != fcpi_parm)) { |
| 370 | lpfc_printf_log(phba, KERN_WARNING, |
| 371 | LOG_FCP | LOG_FCP_ERROR, |
| 372 | "%d:0735 FCP Read Check Error and Underrun " |
| 373 | "Data: x%x x%x x%x x%x\n", phba->brd_no, |
| 374 | be32_to_cpu(fcpcmd->fcpDl), |
| 375 | cmnd->resid, |
| 376 | fcpi_parm, cmnd->cmnd[0]); |
| 377 | cmnd->resid = cmnd->request_bufflen; |
| 378 | host_status = DID_ERROR; |
| 379 | } |
| 380 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 381 | * The cmnd->underflow is the minimum number of bytes that must |
| 382 | * be transfered for this command. Provided a sense condition |
| 383 | * is not present, make sure the actual amount transferred is at |
| 384 | * least the underflow value or fail. |
| 385 | */ |
| 386 | if (!(resp_info & SNS_LEN_VALID) && |
| 387 | (scsi_status == SAM_STAT_GOOD) && |
| 388 | (cmnd->request_bufflen - cmnd->resid) < cmnd->underflow) { |
| 389 | lpfc_printf_log(phba, KERN_INFO, LOG_FCP, |
| 390 | "%d:0717 FCP command x%x residual " |
| 391 | "underrun converted to error " |
| 392 | "Data: x%x x%x x%x\n", phba->brd_no, |
| 393 | cmnd->cmnd[0], cmnd->request_bufflen, |
| 394 | cmnd->resid, cmnd->underflow); |
| 395 | |
| 396 | host_status = DID_ERROR; |
| 397 | } |
| 398 | } else if (resp_info & RESID_OVER) { |
| 399 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP, |
| 400 | "%d:0720 FCP command x%x residual " |
| 401 | "overrun error. Data: x%x x%x \n", |
| 402 | phba->brd_no, cmnd->cmnd[0], |
| 403 | cmnd->request_bufflen, cmnd->resid); |
| 404 | host_status = DID_ERROR; |
| 405 | |
| 406 | /* |
| 407 | * Check SLI validation that all the transfer was actually done |
| 408 | * (fcpi_parm should be zero). Apply check only to reads. |
| 409 | */ |
| 410 | } else if ((scsi_status == SAM_STAT_GOOD) && fcpi_parm && |
| 411 | (cmnd->sc_data_direction == DMA_FROM_DEVICE)) { |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 412 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 413 | "%d:0734 FCP Read Check Error Data: " |
| 414 | "x%x x%x x%x x%x\n", phba->brd_no, |
| 415 | be32_to_cpu(fcpcmd->fcpDl), |
| 416 | be32_to_cpu(fcprsp->rspResId), |
| 417 | fcpi_parm, cmnd->cmnd[0]); |
| 418 | host_status = DID_ERROR; |
| 419 | cmnd->resid = cmnd->request_bufflen; |
| 420 | } |
| 421 | |
| 422 | out: |
| 423 | cmnd->result = ScsiResult(host_status, scsi_status); |
| 424 | } |
| 425 | |
| 426 | static void |
| 427 | lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn, |
| 428 | struct lpfc_iocbq *pIocbOut) |
| 429 | { |
| 430 | struct lpfc_scsi_buf *lpfc_cmd = |
| 431 | (struct lpfc_scsi_buf *) pIocbIn->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 432 | struct lpfc_vport *vport = pIocbIn->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 433 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| 434 | struct lpfc_nodelist *pnode = rdata->pnode; |
| 435 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
James.Smart@Emulex.Com | 445cf4f | 2005-11-28 11:42:38 -0500 | [diff] [blame] | 436 | int result; |
| 437 | struct scsi_device *sdev, *tmp_sdev; |
| 438 | int depth = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 439 | |
| 440 | lpfc_cmd->result = pIocbOut->iocb.un.ulpWord[4]; |
| 441 | lpfc_cmd->status = pIocbOut->iocb.ulpStatus; |
| 442 | |
| 443 | if (lpfc_cmd->status) { |
| 444 | if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT && |
| 445 | (lpfc_cmd->result & IOERR_DRVR_MASK)) |
| 446 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; |
| 447 | else if (lpfc_cmd->status >= IOSTAT_CNT) |
| 448 | lpfc_cmd->status = IOSTAT_DEFAULT; |
| 449 | |
| 450 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP, |
| 451 | "%d:0729 FCP cmd x%x failed <%d/%d> status: " |
| 452 | "x%x result: x%x Data: x%x x%x\n", |
| 453 | phba->brd_no, cmd->cmnd[0], cmd->device->id, |
| 454 | cmd->device->lun, lpfc_cmd->status, |
| 455 | lpfc_cmd->result, pIocbOut->iocb.ulpContext, |
| 456 | lpfc_cmd->cur_iocbq.iocb.ulpIoTag); |
| 457 | |
| 458 | switch (lpfc_cmd->status) { |
| 459 | case IOSTAT_FCP_RSP_ERROR: |
| 460 | /* Call FCP RSP handler to determine result */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 461 | lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 462 | break; |
| 463 | case IOSTAT_NPORT_BSY: |
| 464 | case IOSTAT_FABRIC_BSY: |
| 465 | cmd->result = ScsiResult(DID_BUS_BUSY, 0); |
| 466 | break; |
| 467 | default: |
| 468 | cmd->result = ScsiResult(DID_ERROR, 0); |
| 469 | break; |
| 470 | } |
| 471 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 472 | if ((pnode == NULL ) |
| 473 | || (pnode->nlp_state != NLP_STE_MAPPED_NODE)) |
| 474 | cmd->result = ScsiResult(DID_BUS_BUSY, SAM_STAT_BUSY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 475 | } else { |
| 476 | cmd->result = ScsiResult(DID_OK, 0); |
| 477 | } |
| 478 | |
| 479 | if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) { |
| 480 | uint32_t *lp = (uint32_t *)cmd->sense_buffer; |
| 481 | |
| 482 | lpfc_printf_log(phba, KERN_INFO, LOG_FCP, |
| 483 | "%d:0710 Iodone <%d/%d> cmd %p, error x%x " |
| 484 | "SNS x%x x%x Data: x%x x%x\n", |
| 485 | phba->brd_no, cmd->device->id, |
| 486 | cmd->device->lun, cmd, cmd->result, |
| 487 | *lp, *(lp + 3), cmd->retries, cmd->resid); |
| 488 | } |
| 489 | |
James.Smart@Emulex.Com | 445cf4f | 2005-11-28 11:42:38 -0500 | [diff] [blame] | 490 | result = cmd->result; |
| 491 | sdev = cmd->device; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 492 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 493 | cmd->scsi_done(cmd); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 494 | |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 495 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
| 496 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 497 | return; |
| 498 | } |
| 499 | |
Jamie Wellnitz | 0c6ac8e | 2006-02-28 19:25:36 -0500 | [diff] [blame] | 500 | if (!result && pnode != NULL && |
James.Smart@Emulex.Com | 445cf4f | 2005-11-28 11:42:38 -0500 | [diff] [blame] | 501 | ((jiffies - pnode->last_ramp_up_time) > |
| 502 | LPFC_Q_RAMP_UP_INTERVAL * HZ) && |
| 503 | ((jiffies - pnode->last_q_full_time) > |
| 504 | LPFC_Q_RAMP_UP_INTERVAL * HZ) && |
| 505 | (phba->cfg_lun_queue_depth > sdev->queue_depth)) { |
| 506 | shost_for_each_device(tmp_sdev, sdev->host) { |
| 507 | if (phba->cfg_lun_queue_depth > tmp_sdev->queue_depth) { |
| 508 | if (tmp_sdev->id != sdev->id) |
| 509 | continue; |
| 510 | if (tmp_sdev->ordered_tags) |
| 511 | scsi_adjust_queue_depth(tmp_sdev, |
| 512 | MSG_ORDERED_TAG, |
| 513 | tmp_sdev->queue_depth+1); |
| 514 | else |
| 515 | scsi_adjust_queue_depth(tmp_sdev, |
| 516 | MSG_SIMPLE_TAG, |
| 517 | tmp_sdev->queue_depth+1); |
| 518 | |
| 519 | pnode->last_ramp_up_time = jiffies; |
| 520 | } |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | /* |
| 525 | * Check for queue full. If the lun is reporting queue full, then |
| 526 | * back off the lun queue depth to prevent target overloads. |
| 527 | */ |
Jamie Wellnitz | 0c6ac8e | 2006-02-28 19:25:36 -0500 | [diff] [blame] | 528 | if (result == SAM_STAT_TASK_SET_FULL && pnode != NULL) { |
James.Smart@Emulex.Com | 445cf4f | 2005-11-28 11:42:38 -0500 | [diff] [blame] | 529 | pnode->last_q_full_time = jiffies; |
| 530 | |
| 531 | shost_for_each_device(tmp_sdev, sdev->host) { |
| 532 | if (tmp_sdev->id != sdev->id) |
| 533 | continue; |
| 534 | depth = scsi_track_queue_full(tmp_sdev, |
| 535 | tmp_sdev->queue_depth - 1); |
| 536 | } |
| 537 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 538 | * The queue depth cannot be lowered any more. |
James.Smart@Emulex.Com | 445cf4f | 2005-11-28 11:42:38 -0500 | [diff] [blame] | 539 | * Modify the returned error code to store |
| 540 | * the final depth value set by |
| 541 | * scsi_track_queue_full. |
| 542 | */ |
| 543 | if (depth == -1) |
| 544 | depth = sdev->host->cmd_per_lun; |
| 545 | |
| 546 | if (depth) { |
| 547 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP, |
| 548 | "%d:0711 detected queue full - lun queue depth " |
| 549 | " adjusted to %d.\n", phba->brd_no, depth); |
| 550 | } |
| 551 | } |
| 552 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 553 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 557 | lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd, |
| 558 | struct lpfc_nodelist *pnode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 559 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 560 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 561 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 562 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 563 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 564 | struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq); |
| 565 | int datadir = scsi_cmnd->sc_data_direction; |
| 566 | |
| 567 | lpfc_cmd->fcp_rsp->rspSnsLen = 0; |
James.Smart@Emulex.Com | 69859dc | 2005-08-10 15:02:37 -0400 | [diff] [blame] | 568 | /* clear task management bits */ |
| 569 | lpfc_cmd->fcp_cmnd->fcpCntl2 = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 570 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 571 | int_to_scsilun(lpfc_cmd->pCmd->device->lun, |
| 572 | &lpfc_cmd->fcp_cmnd->fcp_lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 573 | |
| 574 | memcpy(&fcp_cmnd->fcpCdb[0], scsi_cmnd->cmnd, 16); |
| 575 | |
| 576 | if (scsi_cmnd->device->tagged_supported) { |
| 577 | switch (scsi_cmnd->tag) { |
| 578 | case HEAD_OF_QUEUE_TAG: |
| 579 | fcp_cmnd->fcpCntl1 = HEAD_OF_Q; |
| 580 | break; |
| 581 | case ORDERED_QUEUE_TAG: |
| 582 | fcp_cmnd->fcpCntl1 = ORDERED_Q; |
| 583 | break; |
| 584 | default: |
| 585 | fcp_cmnd->fcpCntl1 = SIMPLE_Q; |
| 586 | break; |
| 587 | } |
| 588 | } else |
| 589 | fcp_cmnd->fcpCntl1 = 0; |
| 590 | |
| 591 | /* |
| 592 | * There are three possibilities here - use scatter-gather segment, use |
| 593 | * the single mapping, or neither. Start the lpfc command prep by |
| 594 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 595 | * data bde entry. |
| 596 | */ |
| 597 | if (scsi_cmnd->use_sg) { |
| 598 | if (datadir == DMA_TO_DEVICE) { |
| 599 | iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR; |
| 600 | iocb_cmd->un.fcpi.fcpi_parm = 0; |
| 601 | iocb_cmd->ulpPU = 0; |
| 602 | fcp_cmnd->fcpCntl3 = WRITE_DATA; |
| 603 | phba->fc4OutputRequests++; |
| 604 | } else { |
| 605 | iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR; |
| 606 | iocb_cmd->ulpPU = PARM_READ_CHECK; |
| 607 | iocb_cmd->un.fcpi.fcpi_parm = |
| 608 | scsi_cmnd->request_bufflen; |
| 609 | fcp_cmnd->fcpCntl3 = READ_DATA; |
| 610 | phba->fc4InputRequests++; |
| 611 | } |
| 612 | } else if (scsi_cmnd->request_buffer && scsi_cmnd->request_bufflen) { |
| 613 | if (datadir == DMA_TO_DEVICE) { |
| 614 | iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR; |
| 615 | iocb_cmd->un.fcpi.fcpi_parm = 0; |
| 616 | iocb_cmd->ulpPU = 0; |
| 617 | fcp_cmnd->fcpCntl3 = WRITE_DATA; |
| 618 | phba->fc4OutputRequests++; |
| 619 | } else { |
| 620 | iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR; |
| 621 | iocb_cmd->ulpPU = PARM_READ_CHECK; |
| 622 | iocb_cmd->un.fcpi.fcpi_parm = |
| 623 | scsi_cmnd->request_bufflen; |
| 624 | fcp_cmnd->fcpCntl3 = READ_DATA; |
| 625 | phba->fc4InputRequests++; |
| 626 | } |
| 627 | } else { |
| 628 | iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR; |
| 629 | iocb_cmd->un.fcpi.fcpi_parm = 0; |
| 630 | iocb_cmd->ulpPU = 0; |
| 631 | fcp_cmnd->fcpCntl3 = 0; |
| 632 | phba->fc4ControlRequests++; |
| 633 | } |
| 634 | |
| 635 | /* |
| 636 | * Finish initializing those IOCB fields that are independent |
| 637 | * of the scsi_cmnd request_buffer |
| 638 | */ |
| 639 | piocbq->iocb.ulpContext = pnode->nlp_rpi; |
| 640 | if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE) |
| 641 | piocbq->iocb.ulpFCP2Rcvy = 1; |
| 642 | |
| 643 | piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f); |
| 644 | piocbq->context1 = lpfc_cmd; |
| 645 | piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; |
| 646 | piocbq->iocb.ulpTimeout = lpfc_cmd->timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 647 | piocbq->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 651 | lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 652 | struct lpfc_scsi_buf *lpfc_cmd, |
James Smart | 420b630d | 2006-07-06 15:50:16 -0400 | [diff] [blame] | 653 | unsigned int lun, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 654 | uint8_t task_mgmt_cmd) |
| 655 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 656 | struct lpfc_iocbq *piocbq; |
| 657 | IOCB_t *piocb; |
| 658 | struct fcp_cmnd *fcp_cmnd; |
James Smart | 0b18ac4 | 2006-05-01 21:50:40 -0400 | [diff] [blame] | 659 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 660 | struct lpfc_nodelist *ndlp = rdata->pnode; |
| 661 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 662 | if ((ndlp == NULL) || (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 663 | return 0; |
| 664 | } |
| 665 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 666 | piocbq = &(lpfc_cmd->cur_iocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 667 | piocbq->vport = vport; |
| 668 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 669 | piocb = &piocbq->iocb; |
| 670 | |
| 671 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | 420b630d | 2006-07-06 15:50:16 -0400 | [diff] [blame] | 672 | int_to_scsilun(lun, &lpfc_cmd->fcp_cmnd->fcp_lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 673 | fcp_cmnd->fcpCntl2 = task_mgmt_cmd; |
| 674 | |
| 675 | piocb->ulpCommand = CMD_FCP_ICMND64_CR; |
| 676 | |
| 677 | piocb->ulpContext = ndlp->nlp_rpi; |
| 678 | if (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) { |
| 679 | piocb->ulpFCP2Rcvy = 1; |
| 680 | } |
| 681 | piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f); |
| 682 | |
| 683 | /* ulpTimeout is only one byte */ |
| 684 | if (lpfc_cmd->timeout > 0xff) { |
| 685 | /* |
| 686 | * Do not timeout the command at the firmware level. |
| 687 | * The driver will provide the timeout mechanism. |
| 688 | */ |
| 689 | piocb->ulpTimeout = 0; |
| 690 | } else { |
| 691 | piocb->ulpTimeout = lpfc_cmd->timeout; |
| 692 | } |
| 693 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 694 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 695 | } |
| 696 | |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 697 | static void |
| 698 | lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba, |
| 699 | struct lpfc_iocbq *cmdiocbq, |
| 700 | struct lpfc_iocbq *rspiocbq) |
| 701 | { |
| 702 | struct lpfc_scsi_buf *lpfc_cmd = |
| 703 | (struct lpfc_scsi_buf *) cmdiocbq->context1; |
| 704 | if (lpfc_cmd) |
| 705 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 706 | return; |
| 707 | } |
| 708 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 709 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 710 | lpfc_scsi_tgt_reset(struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_vport *vport, |
James Smart | 420b630d | 2006-07-06 15:50:16 -0400 | [diff] [blame] | 711 | unsigned tgt_id, unsigned int lun, |
| 712 | struct lpfc_rport_data *rdata) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 713 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 714 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 715 | struct lpfc_iocbq *iocbq; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 716 | struct lpfc_iocbq *iocbqrsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 717 | int ret; |
| 718 | |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 719 | if (!rdata->pnode) |
| 720 | return FAILED; |
| 721 | |
James Smart | 0b18ac4 | 2006-05-01 21:50:40 -0400 | [diff] [blame] | 722 | lpfc_cmd->rdata = rdata; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 723 | ret = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun, |
James Smart | 420b630d | 2006-07-06 15:50:16 -0400 | [diff] [blame] | 724 | FCP_TARGET_RESET); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 725 | if (!ret) |
| 726 | return FAILED; |
| 727 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 728 | iocbq = &lpfc_cmd->cur_iocbq; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 729 | iocbqrsp = lpfc_sli_get_iocbq(phba); |
| 730 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 731 | if (!iocbqrsp) |
| 732 | return FAILED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 733 | |
James Smart | 0b18ac4 | 2006-05-01 21:50:40 -0400 | [diff] [blame] | 734 | /* Issue Target Reset to TGT <num> */ |
| 735 | lpfc_printf_log(phba, KERN_INFO, LOG_FCP, |
| 736 | "%d:0702 Issue Target Reset to TGT %d " |
| 737 | "Data: x%x x%x\n", |
| 738 | phba->brd_no, tgt_id, rdata->pnode->nlp_rpi, |
| 739 | rdata->pnode->nlp_flag); |
| 740 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 741 | ret = lpfc_sli_issue_iocb_wait(phba, |
| 742 | &phba->sli.ring[phba->sli.fcp_ring], |
| 743 | iocbq, iocbqrsp, lpfc_cmd->timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 744 | if (ret != IOCB_SUCCESS) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 745 | if (ret == IOCB_TIMEDOUT) |
| 746 | iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 747 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 748 | } else { |
| 749 | ret = SUCCESS; |
| 750 | lpfc_cmd->result = iocbqrsp->iocb.un.ulpWord[4]; |
| 751 | lpfc_cmd->status = iocbqrsp->iocb.ulpStatus; |
| 752 | if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT && |
| 753 | (lpfc_cmd->result & IOERR_DRVR_MASK)) |
| 754 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; |
| 755 | } |
| 756 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 757 | lpfc_sli_release_iocbq(phba, iocbqrsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 758 | return ret; |
| 759 | } |
| 760 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 761 | const char * |
| 762 | lpfc_info(struct Scsi_Host *host) |
| 763 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 764 | struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata; |
| 765 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 766 | int len; |
| 767 | static char lpfcinfobuf[384]; |
| 768 | |
| 769 | memset(lpfcinfobuf,0,384); |
| 770 | if (phba && phba->pcidev){ |
| 771 | strncpy(lpfcinfobuf, phba->ModelDesc, 256); |
| 772 | len = strlen(lpfcinfobuf); |
| 773 | snprintf(lpfcinfobuf + len, |
| 774 | 384-len, |
| 775 | " on PCI bus %02x device %02x irq %d", |
| 776 | phba->pcidev->bus->number, |
| 777 | phba->pcidev->devfn, |
| 778 | phba->pcidev->irq); |
| 779 | len = strlen(lpfcinfobuf); |
| 780 | if (phba->Port[0]) { |
| 781 | snprintf(lpfcinfobuf + len, |
| 782 | 384-len, |
| 783 | " port %s", |
| 784 | phba->Port); |
| 785 | } |
| 786 | } |
| 787 | return lpfcinfobuf; |
| 788 | } |
| 789 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 790 | static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba) |
| 791 | { |
| 792 | unsigned long poll_tmo_expires = |
| 793 | (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo)); |
| 794 | |
| 795 | if (phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt) |
| 796 | mod_timer(&phba->fcp_poll_timer, |
| 797 | poll_tmo_expires); |
| 798 | } |
| 799 | |
| 800 | void lpfc_poll_start_timer(struct lpfc_hba * phba) |
| 801 | { |
| 802 | lpfc_poll_rearm_timer(phba); |
| 803 | } |
| 804 | |
| 805 | void lpfc_poll_timeout(unsigned long ptr) |
| 806 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 807 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 808 | |
| 809 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
| 810 | lpfc_sli_poll_fcp_ring (phba); |
| 811 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 812 | lpfc_poll_rearm_timer(phba); |
| 813 | } |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 814 | } |
| 815 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 816 | static int |
| 817 | lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *)) |
| 818 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 819 | struct Scsi_Host *shost = cmnd->device->host; |
| 820 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 821 | struct lpfc_hba *phba = vport->phba; |
| 822 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 823 | struct lpfc_rport_data *rdata = cmnd->device->hostdata; |
| 824 | struct lpfc_nodelist *ndlp = rdata->pnode; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 825 | struct lpfc_scsi_buf *lpfc_cmd; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 826 | struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device)); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 827 | int err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 828 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 829 | err = fc_remote_port_chkready(rport); |
| 830 | if (err) { |
| 831 | cmnd->result = err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 832 | goto out_fail_command; |
| 833 | } |
| 834 | |
| 835 | /* |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 836 | * Catch race where our node has transitioned, but the |
| 837 | * transport is still transitioning. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 838 | */ |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 839 | if (!ndlp) { |
| 840 | cmnd->result = ScsiResult(DID_BUS_BUSY, 0); |
| 841 | goto out_fail_command; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 842 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame^] | 843 | lpfc_cmd = lpfc_get_scsi_buf(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 844 | if (lpfc_cmd == NULL) { |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 845 | lpfc_printf_log(phba, KERN_INFO, LOG_FCP, |
| 846 | "%d:0707 driver's buffer pool is empty, " |
| 847 | "IO busied\n", phba->brd_no); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 848 | goto out_host_busy; |
| 849 | } |
| 850 | |
| 851 | /* |
| 852 | * Store the midlayer's command structure for the completion phase |
| 853 | * and complete the command initialization. |
| 854 | */ |
| 855 | lpfc_cmd->pCmd = cmnd; |
| 856 | lpfc_cmd->rdata = rdata; |
| 857 | lpfc_cmd->timeout = 0; |
| 858 | cmnd->host_scribble = (unsigned char *)lpfc_cmd; |
| 859 | cmnd->scsi_done = done; |
| 860 | |
| 861 | err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 862 | if (err) |
| 863 | goto out_host_busy_free_buf; |
| 864 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 865 | lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 866 | |
| 867 | err = lpfc_sli_issue_iocb(phba, &phba->sli.ring[psli->fcp_ring], |
| 868 | &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB); |
| 869 | if (err) |
| 870 | goto out_host_busy_free_buf; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 871 | |
| 872 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
| 873 | lpfc_sli_poll_fcp_ring(phba); |
| 874 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 875 | lpfc_poll_rearm_timer(phba); |
| 876 | } |
| 877 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 878 | return 0; |
| 879 | |
| 880 | out_host_busy_free_buf: |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 881 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 882 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 883 | out_host_busy: |
| 884 | return SCSI_MLQUEUE_HOST_BUSY; |
| 885 | |
| 886 | out_fail_command: |
| 887 | done(cmnd); |
| 888 | return 0; |
| 889 | } |
| 890 | |
James Smart | a90f568 | 2006-08-17 11:58:04 -0400 | [diff] [blame] | 891 | static void |
| 892 | lpfc_block_error_handler(struct scsi_cmnd *cmnd) |
| 893 | { |
| 894 | struct Scsi_Host *shost = cmnd->device->host; |
| 895 | struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device)); |
| 896 | |
| 897 | spin_lock_irq(shost->host_lock); |
| 898 | while (rport->port_state == FC_PORTSTATE_BLOCKED) { |
| 899 | spin_unlock_irq(shost->host_lock); |
| 900 | msleep(1000); |
| 901 | spin_lock_irq(shost->host_lock); |
| 902 | } |
| 903 | spin_unlock_irq(shost->host_lock); |
| 904 | return; |
| 905 | } |
James.Smart@Emulex.Com | 63c59c3 | 2005-11-28 11:41:53 -0500 | [diff] [blame] | 906 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 907 | static int |
James.Smart@Emulex.Com | 63c59c3 | 2005-11-28 11:41:53 -0500 | [diff] [blame] | 908 | lpfc_abort_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 909 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 910 | struct Scsi_Host *shost = cmnd->device->host; |
| 911 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 912 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 913 | struct lpfc_sli_ring *pring = &phba->sli.ring[phba->sli.fcp_ring]; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 914 | struct lpfc_iocbq *iocb; |
| 915 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 916 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 917 | IOCB_t *cmd, *icmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 918 | unsigned int loop_count = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 919 | int ret = SUCCESS; |
| 920 | |
James Smart | a90f568 | 2006-08-17 11:58:04 -0400 | [diff] [blame] | 921 | lpfc_block_error_handler(cmnd); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 922 | lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble; |
| 923 | BUG_ON(!lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 924 | |
| 925 | /* |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 926 | * If pCmd field of the corresponding lpfc_scsi_buf structure |
| 927 | * points to a different SCSI command, then the driver has |
| 928 | * already completed this command, but the midlayer did not |
| 929 | * see the completion before the eh fired. Just return |
| 930 | * SUCCESS. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 931 | */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 932 | iocb = &lpfc_cmd->cur_iocbq; |
| 933 | if (lpfc_cmd->pCmd != cmnd) |
| 934 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 935 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 936 | BUG_ON(iocb->context1 != lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 937 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 938 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| 939 | if (abtsiocb == NULL) { |
| 940 | ret = FAILED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 941 | goto out; |
| 942 | } |
| 943 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 944 | /* |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 945 | * The scsi command can not be in txq and it is in flight because the |
| 946 | * pCmd is still pointig at the SCSI command we have to abort. There |
| 947 | * is no need to search the txcmplq. Just send an abort to the FW. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 948 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 949 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 950 | cmd = &iocb->iocb; |
| 951 | icmd = &abtsiocb->iocb; |
| 952 | icmd->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 953 | icmd->un.acxri.abortContextTag = cmd->ulpContext; |
| 954 | icmd->un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 955 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 956 | icmd->ulpLe = 1; |
| 957 | icmd->ulpClass = cmd->ulpClass; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 958 | if (lpfc_is_link_up(phba)) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 959 | icmd->ulpCommand = CMD_ABORT_XRI_CN; |
| 960 | else |
| 961 | icmd->ulpCommand = CMD_CLOSE_XRI_CN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 962 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 963 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 964 | abtsiocb->vport = vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 965 | if (lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0) == IOCB_ERROR) { |
| 966 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| 967 | ret = FAILED; |
| 968 | goto out; |
| 969 | } |
| 970 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 971 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 972 | lpfc_sli_poll_fcp_ring (phba); |
| 973 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 974 | /* Wait for abort to complete */ |
| 975 | while (lpfc_cmd->pCmd == cmnd) |
| 976 | { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 977 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 978 | lpfc_sli_poll_fcp_ring (phba); |
| 979 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 980 | schedule_timeout_uninterruptible(LPFC_ABORT_WAIT * HZ); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 981 | if (++loop_count |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 982 | > (2 * phba->cfg_devloss_tmo)/LPFC_ABORT_WAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 983 | break; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 984 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 985 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 986 | if (lpfc_cmd->pCmd == cmnd) { |
| 987 | ret = FAILED; |
| 988 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 989 | "%d:0748 abort handler timed out waiting for " |
| 990 | "abort to complete: ret %#x, ID %d, LUN %d, " |
| 991 | "snum %#lx\n", |
| 992 | phba->brd_no, ret, cmnd->device->id, |
| 993 | cmnd->device->lun, cmnd->serial_number); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | out: |
| 997 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP, |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 998 | "%d:0749 SCSI Layer I/O Abort Request " |
| 999 | "Status x%x ID %d LUN %d snum %#lx\n", |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1000 | phba->brd_no, ret, cmnd->device->id, |
| 1001 | cmnd->device->lun, cmnd->serial_number); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1002 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1003 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | static int |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1007 | lpfc_device_reset_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1008 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1009 | struct Scsi_Host *shost = cmnd->device->host; |
| 1010 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 1011 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1012 | struct lpfc_scsi_buf *lpfc_cmd; |
| 1013 | struct lpfc_iocbq *iocbq, *iocbqrsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1014 | struct lpfc_rport_data *rdata = cmnd->device->hostdata; |
| 1015 | struct lpfc_nodelist *pnode = rdata->pnode; |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 1016 | uint32_t cmd_result = 0, cmd_status = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1017 | int ret = FAILED; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1018 | int iocb_status = IOCB_SUCCESS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1019 | int cnt, loopcnt; |
| 1020 | |
James Smart | a90f568 | 2006-08-17 11:58:04 -0400 | [diff] [blame] | 1021 | lpfc_block_error_handler(cmnd); |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1022 | loopcnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1023 | /* |
| 1024 | * If target is not in a MAPPED state, delay the reset until |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 1025 | * target is rediscovered or devloss timeout expires. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1026 | */ |
| 1027 | while ( 1 ) { |
| 1028 | if (!pnode) |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1029 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1030 | |
| 1031 | if (pnode->nlp_state != NLP_STE_MAPPED_NODE) { |
Nishanth Aravamudan | a9a3047 | 2005-11-07 01:01:20 -0800 | [diff] [blame] | 1032 | schedule_timeout_uninterruptible(msecs_to_jiffies(500)); |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1033 | loopcnt++; |
| 1034 | rdata = cmnd->device->hostdata; |
| 1035 | if (!rdata || |
| 1036 | (loopcnt > ((phba->cfg_devloss_tmo * 2) + 1))) { |
| 1037 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 1038 | "%d:0721 LUN Reset rport failure:" |
| 1039 | " cnt x%x rdata x%p\n", |
| 1040 | phba->brd_no, loopcnt, rdata); |
| 1041 | goto out; |
| 1042 | } |
| 1043 | pnode = rdata->pnode; |
| 1044 | if (!pnode) |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1045 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1046 | } |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1047 | if (pnode->nlp_state == NLP_STE_MAPPED_NODE) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1048 | break; |
| 1049 | } |
| 1050 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1051 | lpfc_cmd = lpfc_get_scsi_buf(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1052 | if (lpfc_cmd == NULL) |
| 1053 | goto out; |
| 1054 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1055 | lpfc_cmd->timeout = 60; |
James Smart | 0b18ac4 | 2006-05-01 21:50:40 -0400 | [diff] [blame] | 1056 | lpfc_cmd->rdata = rdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1057 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1058 | ret = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, cmnd->device->lun, |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1059 | FCP_TARGET_RESET); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1060 | if (!ret) |
| 1061 | goto out_free_scsi_buf; |
| 1062 | |
| 1063 | iocbq = &lpfc_cmd->cur_iocbq; |
| 1064 | |
| 1065 | /* get a buffer for this IOCB command response */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1066 | iocbqrsp = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1067 | if (iocbqrsp == NULL) |
| 1068 | goto out_free_scsi_buf; |
| 1069 | |
James Smart | 0b18ac4 | 2006-05-01 21:50:40 -0400 | [diff] [blame] | 1070 | lpfc_printf_log(phba, KERN_INFO, LOG_FCP, |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1071 | "%d:0703 Issue target reset to TGT %d LUN %d rpi x%x " |
| 1072 | "nlp_flag x%x\n", phba->brd_no, cmnd->device->id, |
James Smart | 0b18ac4 | 2006-05-01 21:50:40 -0400 | [diff] [blame] | 1073 | cmnd->device->lun, pnode->nlp_rpi, pnode->nlp_flag); |
| 1074 | |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1075 | iocb_status = lpfc_sli_issue_iocb_wait(phba, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 1076 | &phba->sli.ring[phba->sli.fcp_ring], |
| 1077 | iocbq, iocbqrsp, lpfc_cmd->timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1078 | |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1079 | if (iocb_status == IOCB_TIMEDOUT) |
| 1080 | iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl; |
| 1081 | |
| 1082 | if (iocb_status == IOCB_SUCCESS) |
| 1083 | ret = SUCCESS; |
| 1084 | else |
| 1085 | ret = iocb_status; |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 1086 | |
| 1087 | cmd_result = iocbqrsp->iocb.un.ulpWord[4]; |
| 1088 | cmd_status = iocbqrsp->iocb.ulpStatus; |
| 1089 | |
| 1090 | lpfc_sli_release_iocbq(phba, iocbqrsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1091 | |
| 1092 | /* |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 1093 | * All outstanding txcmplq I/Os should have been aborted by the device. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1094 | * Unfortunately, some targets do not abide by this forcing the driver |
| 1095 | * to double check. |
| 1096 | */ |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 1097 | cnt = lpfc_sli_sum_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring], |
| 1098 | cmnd->device->id, cmnd->device->lun, |
| 1099 | LPFC_CTX_LUN); |
| 1100 | if (cnt) |
| 1101 | lpfc_sli_abort_iocb(phba, |
| 1102 | &phba->sli.ring[phba->sli.fcp_ring], |
| 1103 | cmnd->device->id, cmnd->device->lun, |
| 1104 | 0, LPFC_CTX_LUN); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1105 | loopcnt = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1106 | while (cnt) { |
Nishanth Aravamudan | a9a3047 | 2005-11-07 01:01:20 -0800 | [diff] [blame] | 1107 | schedule_timeout_uninterruptible(LPFC_RESET_WAIT*HZ); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1108 | |
| 1109 | if (++loopcnt |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 1110 | > (2 * phba->cfg_devloss_tmo)/LPFC_RESET_WAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1111 | break; |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 1112 | |
| 1113 | cnt = lpfc_sli_sum_iocb(phba, |
| 1114 | &phba->sli.ring[phba->sli.fcp_ring], |
| 1115 | cmnd->device->id, cmnd->device->lun, |
| 1116 | LPFC_CTX_LUN); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | if (cnt) { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1120 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1121 | "%d:0719 device reset I/O flush failure: cnt x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1122 | phba->brd_no, cnt); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1123 | ret = FAILED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1124 | } |
| 1125 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1126 | out_free_scsi_buf: |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1127 | if (iocb_status != IOCB_TIMEDOUT) { |
| 1128 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 1129 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1130 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1131 | "%d:0713 SCSI layer issued device reset (%d, %d) " |
| 1132 | "return x%x status x%x result x%x\n", |
| 1133 | phba->brd_no, cmnd->device->id, cmnd->device->lun, |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 1134 | ret, cmd_status, cmd_result); |
| 1135 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1136 | out: |
| 1137 | return ret; |
| 1138 | } |
| 1139 | |
Jeff Garzik | 94d0e7b | 2005-05-28 07:55:48 -0400 | [diff] [blame] | 1140 | static int |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1141 | lpfc_bus_reset_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1142 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1143 | struct Scsi_Host *shost = cmnd->device->host; |
| 1144 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 1145 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1146 | struct lpfc_nodelist *ndlp = NULL; |
| 1147 | int match; |
| 1148 | int ret = FAILED, i, err_count = 0; |
| 1149 | int cnt, loopcnt; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1150 | struct lpfc_scsi_buf * lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1151 | |
James Smart | a90f568 | 2006-08-17 11:58:04 -0400 | [diff] [blame] | 1152 | lpfc_block_error_handler(cmnd); |
James.Smart@Emulex.Com | 63c59c3 | 2005-11-28 11:41:53 -0500 | [diff] [blame] | 1153 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1154 | lpfc_cmd = lpfc_get_scsi_buf(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1155 | if (lpfc_cmd == NULL) |
| 1156 | goto out; |
| 1157 | |
| 1158 | /* The lpfc_cmd storage is reused. Set all loop invariants. */ |
| 1159 | lpfc_cmd->timeout = 60; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1160 | |
| 1161 | /* |
| 1162 | * Since the driver manages a single bus device, reset all |
| 1163 | * targets known to the driver. Should any target reset |
| 1164 | * fail, this routine returns failure to the midlayer. |
| 1165 | */ |
James Smart | e17da18 | 2006-07-06 15:49:25 -0400 | [diff] [blame] | 1166 | for (i = 0; i < LPFC_MAX_TARGET; i++) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1167 | /* Search for mapped node by target ID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1168 | match = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1169 | spin_lock_irq(shost->host_lock); |
| 1170 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1171 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE && |
| 1172 | i == ndlp->nlp_sid && |
| 1173 | ndlp->rport) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1174 | match = 1; |
| 1175 | break; |
| 1176 | } |
| 1177 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1178 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1179 | if (!match) |
| 1180 | continue; |
| 1181 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1182 | ret = lpfc_scsi_tgt_reset(lpfc_cmd, vport, i, |
| 1183 | cmnd->device->lun, |
James Smart | 420b630d | 2006-07-06 15:50:16 -0400 | [diff] [blame] | 1184 | ndlp->rport->dd_data); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1185 | if (ret != SUCCESS) { |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 1186 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1187 | "%d:0700 Bus Reset on target %d failed\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1188 | phba->brd_no, i); |
| 1189 | err_count++; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1190 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1191 | } |
| 1192 | } |
| 1193 | |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1194 | if (ret != IOCB_TIMEDOUT) |
| 1195 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 1196 | |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 1197 | if (err_count == 0) |
| 1198 | ret = SUCCESS; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1199 | else |
| 1200 | ret = FAILED; |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 1201 | |
| 1202 | /* |
| 1203 | * All outstanding txcmplq I/Os should have been aborted by |
| 1204 | * the targets. Unfortunately, some targets do not abide by |
| 1205 | * this forcing the driver to double check. |
| 1206 | */ |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 1207 | cnt = lpfc_sli_sum_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring], |
| 1208 | 0, 0, LPFC_CTX_HOST); |
| 1209 | if (cnt) |
| 1210 | lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring], |
| 1211 | 0, 0, 0, LPFC_CTX_HOST); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1212 | loopcnt = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1213 | while (cnt) { |
Nishanth Aravamudan | a9a3047 | 2005-11-07 01:01:20 -0800 | [diff] [blame] | 1214 | schedule_timeout_uninterruptible(LPFC_RESET_WAIT*HZ); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1215 | |
| 1216 | if (++loopcnt |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 1217 | > (2 * phba->cfg_devloss_tmo)/LPFC_RESET_WAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1218 | break; |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 1219 | |
| 1220 | cnt = lpfc_sli_sum_iocb(phba, |
| 1221 | &phba->sli.ring[phba->sli.fcp_ring], |
| 1222 | 0, 0, LPFC_CTX_HOST); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1223 | } |
| 1224 | |
| 1225 | if (cnt) { |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 1226 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1227 | "%d:0715 Bus Reset I/O flush failure: cnt x%x left x%x\n", |
| 1228 | phba->brd_no, cnt, i); |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 1229 | ret = FAILED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1230 | } |
| 1231 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1232 | lpfc_printf_log(phba, |
| 1233 | KERN_ERR, |
| 1234 | LOG_FCP, |
| 1235 | "%d:0714 SCSI layer issued Bus Reset Data: x%x\n", |
| 1236 | phba->brd_no, ret); |
| 1237 | out: |
| 1238 | return ret; |
| 1239 | } |
| 1240 | |
| 1241 | static int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1242 | lpfc_slave_alloc(struct scsi_device *sdev) |
| 1243 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1244 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 1245 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1246 | struct lpfc_scsi_buf *scsi_buf = NULL; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 1247 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1248 | uint32_t total = 0, i; |
| 1249 | uint32_t num_to_alloc = 0; |
| 1250 | unsigned long flags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1251 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 1252 | if (!rport || fc_remote_port_chkready(rport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1253 | return -ENXIO; |
| 1254 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 1255 | sdev->hostdata = rport->dd_data; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1256 | |
| 1257 | /* |
| 1258 | * Populate the cmds_per_lun count scsi_bufs into this host's globally |
| 1259 | * available list of scsi buffers. Don't allocate more than the |
James.Smart@Emulex.Com | a784efb | 2005-10-28 20:29:51 -0400 | [diff] [blame] | 1260 | * HBA limit conveyed to the midlayer via the host structure. The |
| 1261 | * formula accounts for the lun_queue_depth + error handlers + 1 |
| 1262 | * extra. This list of scsi bufs exists for the lifetime of the driver. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1263 | */ |
| 1264 | total = phba->total_scsi_bufs; |
James.Smart@Emulex.Com | a784efb | 2005-10-28 20:29:51 -0400 | [diff] [blame] | 1265 | num_to_alloc = phba->cfg_lun_queue_depth + 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1266 | if (total >= phba->cfg_hba_queue_depth) { |
James.Smart@Emulex.Com | a784efb | 2005-10-28 20:29:51 -0400 | [diff] [blame] | 1267 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP, |
| 1268 | "%d:0704 At limitation of %d preallocated " |
| 1269 | "command buffers\n", phba->brd_no, total); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1270 | return 0; |
| 1271 | } else if (total + num_to_alloc > phba->cfg_hba_queue_depth) { |
James.Smart@Emulex.Com | a784efb | 2005-10-28 20:29:51 -0400 | [diff] [blame] | 1272 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP, |
| 1273 | "%d:0705 Allocation request of %d command " |
| 1274 | "buffers will exceed max of %d. Reducing " |
| 1275 | "allocation request to %d.\n", phba->brd_no, |
| 1276 | num_to_alloc, phba->cfg_hba_queue_depth, |
| 1277 | (phba->cfg_hba_queue_depth - total)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1278 | num_to_alloc = phba->cfg_hba_queue_depth - total; |
| 1279 | } |
| 1280 | |
| 1281 | for (i = 0; i < num_to_alloc; i++) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1282 | scsi_buf = lpfc_new_scsi_buf(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1283 | if (!scsi_buf) { |
James.Smart@Emulex.Com | a784efb | 2005-10-28 20:29:51 -0400 | [diff] [blame] | 1284 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 1285 | "%d:0706 Failed to allocate command " |
| 1286 | "buffer\n", phba->brd_no); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1287 | break; |
| 1288 | } |
| 1289 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1290 | spin_lock_irqsave(&phba->scsi_buf_list_lock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1291 | phba->total_scsi_bufs++; |
| 1292 | list_add_tail(&scsi_buf->list, &phba->lpfc_scsi_buf_list); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1293 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1294 | } |
| 1295 | return 0; |
| 1296 | } |
| 1297 | |
| 1298 | static int |
| 1299 | lpfc_slave_configure(struct scsi_device *sdev) |
| 1300 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1301 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 1302 | struct lpfc_hba *phba = vport->phba; |
| 1303 | struct fc_rport *rport = starget_to_rport(sdev->sdev_target); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1304 | |
| 1305 | if (sdev->tagged_supported) |
| 1306 | scsi_activate_tcq(sdev, phba->cfg_lun_queue_depth); |
| 1307 | else |
| 1308 | scsi_deactivate_tcq(sdev, phba->cfg_lun_queue_depth); |
| 1309 | |
| 1310 | /* |
| 1311 | * Initialize the fc transport attributes for the target |
| 1312 | * containing this scsi device. Also note that the driver's |
| 1313 | * target pointer is stored in the starget_data for the |
| 1314 | * driver's sysfs entry point functions. |
| 1315 | */ |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 1316 | rport->dev_loss_tmo = phba->cfg_devloss_tmo; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1317 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1318 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
| 1319 | lpfc_sli_poll_fcp_ring(phba); |
| 1320 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 1321 | lpfc_poll_rearm_timer(phba); |
| 1322 | } |
| 1323 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1324 | return 0; |
| 1325 | } |
| 1326 | |
| 1327 | static void |
| 1328 | lpfc_slave_destroy(struct scsi_device *sdev) |
| 1329 | { |
| 1330 | sdev->hostdata = NULL; |
| 1331 | return; |
| 1332 | } |
| 1333 | |
| 1334 | struct scsi_host_template lpfc_template = { |
| 1335 | .module = THIS_MODULE, |
| 1336 | .name = LPFC_DRIVER_NAME, |
| 1337 | .info = lpfc_info, |
| 1338 | .queuecommand = lpfc_queuecommand, |
| 1339 | .eh_abort_handler = lpfc_abort_handler, |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1340 | .eh_device_reset_handler= lpfc_device_reset_handler, |
| 1341 | .eh_bus_reset_handler = lpfc_bus_reset_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1342 | .slave_alloc = lpfc_slave_alloc, |
| 1343 | .slave_configure = lpfc_slave_configure, |
| 1344 | .slave_destroy = lpfc_slave_destroy, |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1345 | .scan_finished = lpfc_scan_finished, |
| 1346 | .scan_start = lpfc_scan_start, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1347 | .this_id = -1, |
| 1348 | .sg_tablesize = LPFC_SG_SEG_CNT, |
| 1349 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
| 1350 | .use_clustering = ENABLE_CLUSTERING, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1351 | .shost_attrs = lpfc_hba_attrs, |
James.Smart@Emulex.Com | 564b296 | 2005-06-25 10:34:17 -0400 | [diff] [blame] | 1352 | .max_sectors = 0xFFFF, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1353 | }; |