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