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