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