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