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