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