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