| 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 | *******************************************************************/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 21 | #include <linux/pci.h> |
| 22 | #include <linux/interrupt.h> |
James Smart | a90f568 | 2006-08-17 11:58:04 -0400 | [diff] [blame] | 23 | #include <linux/delay.h> |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 24 | #include <asm/unaligned.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 25 | |
| 26 | #include <scsi/scsi.h> |
| 27 | #include <scsi/scsi_device.h> |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 28 | #include <scsi/scsi_eh.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 29 | #include <scsi/scsi_host.h> |
| 30 | #include <scsi/scsi_tcq.h> |
| 31 | #include <scsi/scsi_transport_fc.h> |
| 32 | |
| 33 | #include "lpfc_version.h" |
| 34 | #include "lpfc_hw.h" |
| 35 | #include "lpfc_sli.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 36 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 37 | #include "lpfc_disc.h" |
| 38 | #include "lpfc_scsi.h" |
| 39 | #include "lpfc.h" |
| 40 | #include "lpfc_logmsg.h" |
| 41 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 42 | #include "lpfc_vport.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 43 | |
| 44 | #define LPFC_RESET_WAIT 2 |
| 45 | #define LPFC_ABORT_WAIT 2 |
| 46 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 47 | int _dump_buf_done; |
| 48 | |
| 49 | static char *dif_op_str[] = { |
| 50 | "SCSI_PROT_NORMAL", |
| 51 | "SCSI_PROT_READ_INSERT", |
| 52 | "SCSI_PROT_WRITE_STRIP", |
| 53 | "SCSI_PROT_READ_STRIP", |
| 54 | "SCSI_PROT_WRITE_INSERT", |
| 55 | "SCSI_PROT_READ_PASS", |
| 56 | "SCSI_PROT_WRITE_PASS", |
| 57 | "SCSI_PROT_READ_CONVERT", |
| 58 | "SCSI_PROT_WRITE_CONVERT" |
| 59 | }; |
| 60 | |
| 61 | static void |
| 62 | lpfc_debug_save_data(struct scsi_cmnd *cmnd) |
| 63 | { |
| 64 | void *src, *dst; |
| 65 | struct scatterlist *sgde = scsi_sglist(cmnd); |
| 66 | |
| 67 | if (!_dump_buf_data) { |
| 68 | printk(KERN_ERR "BLKGRD ERROR %s _dump_buf_data is NULL\n", |
| 69 | __func__); |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | |
| 74 | if (!sgde) { |
| 75 | printk(KERN_ERR "BLKGRD ERROR: data scatterlist is null\n"); |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | dst = (void *) _dump_buf_data; |
| 80 | while (sgde) { |
| 81 | src = sg_virt(sgde); |
| 82 | memcpy(dst, src, sgde->length); |
| 83 | dst += sgde->length; |
| 84 | sgde = sg_next(sgde); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | static void |
| 89 | lpfc_debug_save_dif(struct scsi_cmnd *cmnd) |
| 90 | { |
| 91 | void *src, *dst; |
| 92 | struct scatterlist *sgde = scsi_prot_sglist(cmnd); |
| 93 | |
| 94 | if (!_dump_buf_dif) { |
| 95 | printk(KERN_ERR "BLKGRD ERROR %s _dump_buf_data is NULL\n", |
| 96 | __func__); |
| 97 | return; |
| 98 | } |
| 99 | |
| 100 | if (!sgde) { |
| 101 | printk(KERN_ERR "BLKGRD ERROR: prot scatterlist is null\n"); |
| 102 | return; |
| 103 | } |
| 104 | |
| 105 | dst = _dump_buf_dif; |
| 106 | while (sgde) { |
| 107 | src = sg_virt(sgde); |
| 108 | memcpy(dst, src, sgde->length); |
| 109 | dst += sgde->length; |
| 110 | sgde = sg_next(sgde); |
| 111 | } |
| 112 | } |
| 113 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 114 | /** |
| 115 | * lpfc_update_stats: Update statistical data for the command completion. |
| 116 | * @phba: Pointer to HBA object. |
| 117 | * @lpfc_cmd: lpfc scsi command object pointer. |
| 118 | * |
| 119 | * This function is called when there is a command completion and this |
| 120 | * function updates the statistical data for the command completion. |
| 121 | **/ |
| 122 | static void |
| 123 | lpfc_update_stats(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 124 | { |
| 125 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| 126 | struct lpfc_nodelist *pnode = rdata->pnode; |
| 127 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 128 | unsigned long flags; |
| 129 | struct Scsi_Host *shost = cmd->device->host; |
| 130 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 131 | unsigned long latency; |
| 132 | int i; |
| 133 | |
| 134 | if (cmd->result) |
| 135 | return; |
| 136 | |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 137 | latency = jiffies_to_msecs((long)jiffies - (long)lpfc_cmd->start_time); |
| 138 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 139 | spin_lock_irqsave(shost->host_lock, flags); |
| 140 | if (!vport->stat_data_enabled || |
| 141 | vport->stat_data_blocked || |
| 142 | !pnode->lat_data || |
| 143 | (phba->bucket_type == LPFC_NO_BUCKET)) { |
| 144 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 145 | return; |
| 146 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 147 | |
| 148 | if (phba->bucket_type == LPFC_LINEAR_BUCKET) { |
| 149 | i = (latency + phba->bucket_step - 1 - phba->bucket_base)/ |
| 150 | phba->bucket_step; |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 151 | /* check array subscript bounds */ |
| 152 | if (i < 0) |
| 153 | i = 0; |
| 154 | else if (i >= LPFC_MAX_BUCKET_COUNT) |
| 155 | i = LPFC_MAX_BUCKET_COUNT - 1; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 156 | } else { |
| 157 | for (i = 0; i < LPFC_MAX_BUCKET_COUNT-1; i++) |
| 158 | if (latency <= (phba->bucket_base + |
| 159 | ((1<<i)*phba->bucket_step))) |
| 160 | break; |
| 161 | } |
| 162 | |
| 163 | pnode->lat_data[i].cmd_count++; |
| 164 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 165 | } |
| 166 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 167 | /** |
| 168 | * lpfc_send_sdev_queuedepth_change_event: Posts a queuedepth change |
| 169 | * event. |
| 170 | * @phba: Pointer to HBA context object. |
| 171 | * @vport: Pointer to vport object. |
| 172 | * @ndlp: Pointer to FC node associated with the target. |
| 173 | * @lun: Lun number of the scsi device. |
| 174 | * @old_val: Old value of the queue depth. |
| 175 | * @new_val: New value of the queue depth. |
| 176 | * |
| 177 | * This function sends an event to the mgmt application indicating |
| 178 | * there is a change in the scsi device queue depth. |
| 179 | **/ |
| 180 | static void |
| 181 | lpfc_send_sdev_queuedepth_change_event(struct lpfc_hba *phba, |
| 182 | struct lpfc_vport *vport, |
| 183 | struct lpfc_nodelist *ndlp, |
| 184 | uint32_t lun, |
| 185 | uint32_t old_val, |
| 186 | uint32_t new_val) |
| 187 | { |
| 188 | struct lpfc_fast_path_event *fast_path_evt; |
| 189 | unsigned long flags; |
| 190 | |
| 191 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 192 | if (!fast_path_evt) |
| 193 | return; |
| 194 | |
| 195 | fast_path_evt->un.queue_depth_evt.scsi_event.event_type = |
| 196 | FC_REG_SCSI_EVENT; |
| 197 | fast_path_evt->un.queue_depth_evt.scsi_event.subcategory = |
| 198 | LPFC_EVENT_VARQUEDEPTH; |
| 199 | |
| 200 | /* Report all luns with change in queue depth */ |
| 201 | fast_path_evt->un.queue_depth_evt.scsi_event.lun = lun; |
| 202 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
| 203 | memcpy(&fast_path_evt->un.queue_depth_evt.scsi_event.wwpn, |
| 204 | &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 205 | memcpy(&fast_path_evt->un.queue_depth_evt.scsi_event.wwnn, |
| 206 | &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 207 | } |
| 208 | |
| 209 | fast_path_evt->un.queue_depth_evt.oldval = old_val; |
| 210 | fast_path_evt->un.queue_depth_evt.newval = new_val; |
| 211 | fast_path_evt->vport = vport; |
| 212 | |
| 213 | fast_path_evt->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT; |
| 214 | spin_lock_irqsave(&phba->hbalock, flags); |
| 215 | list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list); |
| 216 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 217 | lpfc_worker_wake_up(phba); |
| 218 | |
| 219 | return; |
| 220 | } |
| 221 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 222 | /** |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 223 | * lpfc_rampdown_queue_depth: Post RAMP_DOWN_QUEUE event to worker thread. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 224 | * @phba: The Hba for which this call is being executed. |
| 225 | * |
| 226 | * This routine is called when there is resource error in driver or firmware. |
| 227 | * This routine posts WORKER_RAMP_DOWN_QUEUE event for @phba. This routine |
| 228 | * posts at most 1 event each second. This routine wakes up worker thread of |
| 229 | * @phba to process WORKER_RAM_DOWN_EVENT event. |
| 230 | * |
| 231 | * This routine should be called with no lock held. |
| 232 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 233 | void |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 234 | lpfc_rampdown_queue_depth(struct lpfc_hba *phba) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 235 | { |
| 236 | unsigned long flags; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 237 | uint32_t evt_posted; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 238 | |
| 239 | spin_lock_irqsave(&phba->hbalock, flags); |
| 240 | atomic_inc(&phba->num_rsrc_err); |
| 241 | phba->last_rsrc_error_time = jiffies; |
| 242 | |
| 243 | if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) { |
| 244 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 245 | return; |
| 246 | } |
| 247 | |
| 248 | phba->last_ramp_down_time = jiffies; |
| 249 | |
| 250 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 251 | |
| 252 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 253 | evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE; |
| 254 | if (!evt_posted) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 255 | phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 256 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
| 257 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 258 | if (!evt_posted) |
| 259 | lpfc_worker_wake_up(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 260 | return; |
| 261 | } |
| 262 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 263 | /** |
| 264 | * lpfc_rampup_queue_depth: Post RAMP_UP_QUEUE event for worker thread. |
| 265 | * @phba: The Hba for which this call is being executed. |
| 266 | * |
| 267 | * This routine post WORKER_RAMP_UP_QUEUE event for @phba vport. This routine |
| 268 | * post at most 1 event every 5 minute after last_ramp_up_time or |
| 269 | * last_rsrc_error_time. This routine wakes up worker thread of @phba |
| 270 | * to process WORKER_RAM_DOWN_EVENT event. |
| 271 | * |
| 272 | * This routine should be called with no lock held. |
| 273 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 274 | static inline void |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 275 | lpfc_rampup_queue_depth(struct lpfc_vport *vport, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 276 | struct scsi_device *sdev) |
| 277 | { |
| 278 | unsigned long flags; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 279 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 280 | uint32_t evt_posted; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 281 | atomic_inc(&phba->num_cmd_success); |
| 282 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 283 | if (vport->cfg_lun_queue_depth <= sdev->queue_depth) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 284 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 285 | spin_lock_irqsave(&phba->hbalock, flags); |
| 286 | if (((phba->last_ramp_up_time + QUEUE_RAMP_UP_INTERVAL) > jiffies) || |
| 287 | ((phba->last_rsrc_error_time + QUEUE_RAMP_UP_INTERVAL ) > jiffies)) { |
| 288 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 289 | return; |
| 290 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 291 | phba->last_ramp_up_time = jiffies; |
| 292 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 293 | |
| 294 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 295 | evt_posted = phba->pport->work_port_events & WORKER_RAMP_UP_QUEUE; |
| 296 | if (!evt_posted) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 297 | phba->pport->work_port_events |= WORKER_RAMP_UP_QUEUE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 298 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
| 299 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 300 | if (!evt_posted) |
| 301 | lpfc_worker_wake_up(phba); |
| 302 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 303 | } |
| 304 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 305 | /** |
| 306 | * lpfc_ramp_down_queue_handler: WORKER_RAMP_DOWN_QUEUE event handler. |
| 307 | * @phba: The Hba for which this call is being executed. |
| 308 | * |
| 309 | * This routine is called to process WORKER_RAMP_DOWN_QUEUE event for worker |
| 310 | * thread.This routine reduces queue depth for all scsi device on each vport |
| 311 | * associated with @phba. |
| 312 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 313 | void |
| 314 | lpfc_ramp_down_queue_handler(struct lpfc_hba *phba) |
| 315 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 316 | struct lpfc_vport **vports; |
| 317 | struct Scsi_Host *shost; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 318 | struct scsi_device *sdev; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 319 | unsigned long new_queue_depth, old_queue_depth; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 320 | unsigned long num_rsrc_err, num_cmd_success; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 321 | int i; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 322 | struct lpfc_rport_data *rdata; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 323 | |
| 324 | num_rsrc_err = atomic_read(&phba->num_rsrc_err); |
| 325 | num_cmd_success = atomic_read(&phba->num_cmd_success); |
| 326 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 327 | vports = lpfc_create_vport_work_array(phba); |
| 328 | if (vports != NULL) |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 329 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 330 | shost = lpfc_shost_from_vport(vports[i]); |
| 331 | shost_for_each_device(sdev, shost) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 332 | new_queue_depth = |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 333 | sdev->queue_depth * num_rsrc_err / |
| 334 | (num_rsrc_err + num_cmd_success); |
| 335 | if (!new_queue_depth) |
| 336 | new_queue_depth = sdev->queue_depth - 1; |
| 337 | else |
| 338 | new_queue_depth = sdev->queue_depth - |
| 339 | new_queue_depth; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 340 | old_queue_depth = sdev->queue_depth; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 341 | if (sdev->ordered_tags) |
| 342 | scsi_adjust_queue_depth(sdev, |
| 343 | MSG_ORDERED_TAG, |
| 344 | new_queue_depth); |
| 345 | else |
| 346 | scsi_adjust_queue_depth(sdev, |
| 347 | MSG_SIMPLE_TAG, |
| 348 | new_queue_depth); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 349 | rdata = sdev->hostdata; |
| 350 | if (rdata) |
| 351 | lpfc_send_sdev_queuedepth_change_event( |
| 352 | phba, vports[i], |
| 353 | rdata->pnode, |
| 354 | sdev->lun, old_queue_depth, |
| 355 | new_queue_depth); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 356 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 357 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 358 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 359 | atomic_set(&phba->num_rsrc_err, 0); |
| 360 | atomic_set(&phba->num_cmd_success, 0); |
| 361 | } |
| 362 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 363 | /** |
| 364 | * lpfc_ramp_up_queue_handler: WORKER_RAMP_UP_QUEUE event handler. |
| 365 | * @phba: The Hba for which this call is being executed. |
| 366 | * |
| 367 | * This routine is called to process WORKER_RAMP_UP_QUEUE event for worker |
| 368 | * thread.This routine increases queue depth for all scsi device on each vport |
| 369 | * associated with @phba by 1. This routine also sets @phba num_rsrc_err and |
| 370 | * num_cmd_success to zero. |
| 371 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 372 | void |
| 373 | lpfc_ramp_up_queue_handler(struct lpfc_hba *phba) |
| 374 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 375 | struct lpfc_vport **vports; |
| 376 | struct Scsi_Host *shost; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 377 | struct scsi_device *sdev; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 378 | int i; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 379 | struct lpfc_rport_data *rdata; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 380 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 381 | vports = lpfc_create_vport_work_array(phba); |
| 382 | if (vports != NULL) |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 383 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 384 | shost = lpfc_shost_from_vport(vports[i]); |
| 385 | shost_for_each_device(sdev, shost) { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 386 | if (vports[i]->cfg_lun_queue_depth <= |
| 387 | sdev->queue_depth) |
| 388 | continue; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 389 | if (sdev->ordered_tags) |
| 390 | scsi_adjust_queue_depth(sdev, |
| 391 | MSG_ORDERED_TAG, |
| 392 | sdev->queue_depth+1); |
| 393 | else |
| 394 | scsi_adjust_queue_depth(sdev, |
| 395 | MSG_SIMPLE_TAG, |
| 396 | sdev->queue_depth+1); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 397 | rdata = sdev->hostdata; |
| 398 | if (rdata) |
| 399 | lpfc_send_sdev_queuedepth_change_event( |
| 400 | phba, vports[i], |
| 401 | rdata->pnode, |
| 402 | sdev->lun, |
| 403 | sdev->queue_depth - 1, |
| 404 | sdev->queue_depth); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 405 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 406 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 407 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 408 | atomic_set(&phba->num_rsrc_err, 0); |
| 409 | atomic_set(&phba->num_cmd_success, 0); |
| 410 | } |
| 411 | |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 412 | /** |
| 413 | * lpfc_scsi_dev_block: set all scsi hosts to block state. |
| 414 | * @phba: Pointer to HBA context object. |
| 415 | * |
| 416 | * This function walks vport list and set each SCSI host to block state |
| 417 | * by invoking fc_remote_port_delete() routine. This function is invoked |
| 418 | * with EEH when device's PCI slot has been permanently disabled. |
| 419 | **/ |
| 420 | void |
| 421 | lpfc_scsi_dev_block(struct lpfc_hba *phba) |
| 422 | { |
| 423 | struct lpfc_vport **vports; |
| 424 | struct Scsi_Host *shost; |
| 425 | struct scsi_device *sdev; |
| 426 | struct fc_rport *rport; |
| 427 | int i; |
| 428 | |
| 429 | vports = lpfc_create_vport_work_array(phba); |
| 430 | if (vports != NULL) |
| 431 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 432 | shost = lpfc_shost_from_vport(vports[i]); |
| 433 | shost_for_each_device(sdev, shost) { |
| 434 | rport = starget_to_rport(scsi_target(sdev)); |
| 435 | fc_remote_port_delete(rport); |
| 436 | } |
| 437 | } |
| 438 | lpfc_destroy_vport_work_array(phba, vports); |
| 439 | } |
| 440 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 441 | /** |
| 442 | * lpfc_new_scsi_buf: Scsi buffer allocator. |
| 443 | * @vport: The virtual port for which this call being executed. |
| 444 | * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 445 | * This routine allocates a scsi buffer, which contains all the necessary |
| 446 | * information needed to initiate a SCSI I/O. The non-DMAable buffer region |
| 447 | * contains information to build the IOCB. The DMAable region contains |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 448 | * memory for the FCP CMND, FCP RSP, and the initial BPL. In addition to |
| 449 | * allocating memory, the FCP CMND and FCP RSP BDEs are setup in the BPL |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 450 | * and the BPL BDE is setup in the IOCB. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 451 | * |
| 452 | * Return codes: |
| 453 | * NULL - Error |
| 454 | * Pointer to lpfc_scsi_buf data structure - Success |
| 455 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 456 | static struct lpfc_scsi_buf * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 457 | lpfc_new_scsi_buf(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 458 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 459 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 460 | struct lpfc_scsi_buf *psb; |
| 461 | struct ulp_bde64 *bpl; |
| 462 | IOCB_t *iocb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 463 | dma_addr_t pdma_phys_fcp_cmd; |
| 464 | dma_addr_t pdma_phys_fcp_rsp; |
| 465 | dma_addr_t pdma_phys_bpl; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 466 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 467 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 468 | psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 469 | if (!psb) |
| 470 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 471 | |
| 472 | /* |
| 473 | * Get memory from the pci pool to map the virt space to pci bus space |
| 474 | * for an I/O. The DMA buffer includes space for the struct fcp_cmnd, |
| 475 | * struct fcp_rsp and the number of bde's necessary to support the |
| 476 | * sg_tablesize. |
| 477 | */ |
| 478 | psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool, GFP_KERNEL, |
| 479 | &psb->dma_handle); |
| 480 | if (!psb->data) { |
| 481 | kfree(psb); |
| 482 | return NULL; |
| 483 | } |
| 484 | |
| 485 | /* Initialize virtual ptrs to dma_buf region. */ |
| 486 | memset(psb->data, 0, phba->cfg_sg_dma_buf_size); |
| 487 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 488 | /* Allocate iotag for psb->cur_iocbq. */ |
| 489 | iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq); |
| 490 | if (iotag == 0) { |
| 491 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, |
| 492 | psb->data, psb->dma_handle); |
| 493 | kfree (psb); |
| 494 | return NULL; |
| 495 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 496 | psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 497 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 498 | psb->fcp_cmnd = psb->data; |
| 499 | psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd); |
| 500 | psb->fcp_bpl = psb->data + sizeof(struct fcp_cmnd) + |
| 501 | sizeof(struct fcp_rsp); |
| 502 | |
| 503 | /* Initialize local short-hand pointers. */ |
| 504 | bpl = psb->fcp_bpl; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 505 | pdma_phys_fcp_cmd = psb->dma_handle; |
| 506 | pdma_phys_fcp_rsp = psb->dma_handle + sizeof(struct fcp_cmnd); |
| 507 | pdma_phys_bpl = psb->dma_handle + sizeof(struct fcp_cmnd) + |
| 508 | sizeof(struct fcp_rsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 509 | |
| 510 | /* |
| 511 | * The first two bdes are the FCP_CMD and FCP_RSP. The balance are sg |
| 512 | * list bdes. Initialize the first two and leave the rest for |
| 513 | * queuecommand. |
| 514 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 515 | bpl[0].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd)); |
| 516 | bpl[0].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd)); |
| 517 | bpl[0].tus.f.bdeSize = sizeof(struct fcp_cmnd); |
| 518 | bpl[0].tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 519 | bpl[0].tus.w = le32_to_cpu(bpl[0].tus.w); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 520 | |
| 521 | /* Setup the physical region for the FCP RSP */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 522 | bpl[1].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp)); |
| 523 | bpl[1].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp)); |
| 524 | bpl[1].tus.f.bdeSize = sizeof(struct fcp_rsp); |
| 525 | bpl[1].tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 526 | bpl[1].tus.w = le32_to_cpu(bpl[1].tus.w); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 527 | |
| 528 | /* |
| 529 | * Since the IOCB for the FCP I/O is built into this lpfc_scsi_buf, |
| 530 | * initialize it with all known data now. |
| 531 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 532 | iocb = &psb->cur_iocbq.iocb; |
| 533 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 534 | if ((phba->sli_rev == 3) && |
| 535 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 536 | /* fill in immediate fcp command BDE */ |
| 537 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_IMMED; |
| 538 | iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); |
| 539 | iocb->un.fcpi64.bdl.addrLow = offsetof(IOCB_t, |
| 540 | unsli3.fcp_ext.icd); |
| 541 | iocb->un.fcpi64.bdl.addrHigh = 0; |
| 542 | iocb->ulpBdeCount = 0; |
| 543 | iocb->ulpLe = 0; |
| 544 | /* fill in responce BDE */ |
| 545 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 546 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeSize = |
| 547 | sizeof(struct fcp_rsp); |
| 548 | iocb->unsli3.fcp_ext.rbde.addrLow = |
| 549 | putPaddrLow(pdma_phys_fcp_rsp); |
| 550 | iocb->unsli3.fcp_ext.rbde.addrHigh = |
| 551 | putPaddrHigh(pdma_phys_fcp_rsp); |
| 552 | } else { |
| 553 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
| 554 | iocb->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| 555 | iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys_bpl); |
| 556 | iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys_bpl); |
| 557 | iocb->ulpBdeCount = 1; |
| 558 | iocb->ulpLe = 1; |
| 559 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 560 | iocb->ulpClass = CLASS3; |
| 561 | |
| 562 | return psb; |
| 563 | } |
| 564 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 565 | /** |
| 566 | * lpfc_get_scsi_buf: Get a scsi buffer from lpfc_scsi_buf_list list of Hba. |
| 567 | * @phba: The Hba for which this call is being executed. |
| 568 | * |
| 569 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list |
| 570 | * and returns to caller. |
| 571 | * |
| 572 | * Return codes: |
| 573 | * NULL - Error |
| 574 | * Pointer to lpfc_scsi_buf - Success |
| 575 | **/ |
Adrian Bunk | 455c53e | 2006-01-06 20:21:28 +0100 | [diff] [blame] | 576 | static struct lpfc_scsi_buf* |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 577 | lpfc_get_scsi_buf(struct lpfc_hba * phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 578 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 579 | struct lpfc_scsi_buf * lpfc_cmd = NULL; |
| 580 | 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] | 581 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 582 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 583 | spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 584 | 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] | 585 | if (lpfc_cmd) { |
| 586 | lpfc_cmd->seg_cnt = 0; |
| 587 | lpfc_cmd->nonsg_phys = 0; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 588 | lpfc_cmd->prot_seg_cnt = 0; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 589 | } |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 590 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 591 | return lpfc_cmd; |
| 592 | } |
| 593 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 594 | /** |
| 595 | * lpfc_release_scsi_buf: Return a scsi buffer back to hba lpfc_scsi_buf_list list. |
| 596 | * @phba: The Hba for which this call is being executed. |
| 597 | * @psb: The scsi buffer which is being released. |
| 598 | * |
| 599 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
| 600 | * lpfc_scsi_buf_list list. |
| 601 | **/ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 602 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 603 | 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] | 604 | { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 605 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 606 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 607 | spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 608 | psb->pCmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 609 | list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 610 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 611 | } |
| 612 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 613 | /** |
| 614 | * lpfc_scsi_prep_dma_buf: Routine to do DMA mapping for scsi buffer. |
| 615 | * @phba: The Hba for which this call is being executed. |
| 616 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 617 | * |
| 618 | * This routine does the pci dma mapping for scatter-gather list of scsi cmnd |
| 619 | * field of @lpfc_cmd. This routine scans through sg elements and format the |
| 620 | * bdea. This routine also initializes all IOCB fields which are dependent on |
| 621 | * scsi command request buffer. |
| 622 | * |
| 623 | * Return codes: |
| 624 | * 1 - Error |
| 625 | * 0 - Success |
| 626 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 627 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 628 | 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] | 629 | { |
| 630 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 631 | struct scatterlist *sgel = NULL; |
| 632 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 633 | struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl; |
| 634 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 635 | struct ulp_bde64 *data_bde = iocb_cmd->unsli3.fcp_ext.dbde; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 636 | dma_addr_t physaddr; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 637 | uint32_t num_bde = 0; |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 638 | int nseg, datadir = scsi_cmnd->sc_data_direction; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 639 | |
| 640 | /* |
| 641 | * There are three possibilities here - use scatter-gather segment, use |
| 642 | * the single mapping, or neither. Start the lpfc command prep by |
| 643 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 644 | * data bde entry. |
| 645 | */ |
| 646 | bpl += 2; |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 647 | if (scsi_sg_count(scsi_cmnd)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 648 | /* |
| 649 | * The driver stores the segment count returned from pci_map_sg |
| 650 | * because this a count of dma-mappings used to map the use_sg |
| 651 | * pages. They are not guaranteed to be the same for those |
| 652 | * architectures that implement an IOMMU. |
| 653 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 654 | |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 655 | nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd), |
| 656 | scsi_sg_count(scsi_cmnd), datadir); |
| 657 | if (unlikely(!nseg)) |
| 658 | return 1; |
| 659 | |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 660 | lpfc_cmd->seg_cnt = nseg; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 661 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
| 662 | printk(KERN_ERR "%s: Too many sg segments from " |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 663 | "dma_map_sg. Config %d, seg_cnt %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 664 | __func__, phba->cfg_sg_seg_cnt, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 665 | lpfc_cmd->seg_cnt); |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 666 | scsi_dma_unmap(scsi_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 667 | return 1; |
| 668 | } |
| 669 | |
| 670 | /* |
| 671 | * The driver established a maximum scatter-gather segment count |
| 672 | * during probe that limits the number of sg elements in any |
| 673 | * single scsi command. Just run through the seg_cnt and format |
| 674 | * the bde's. |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 675 | * When using SLI-3 the driver will try to fit all the BDEs into |
| 676 | * the IOCB. If it can't then the BDEs get added to a BPL as it |
| 677 | * does for SLI-2 mode. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 678 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 679 | scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 680 | physaddr = sg_dma_address(sgel); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 681 | if (phba->sli_rev == 3 && |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 682 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 683 | nseg <= LPFC_EXT_DATA_BDE_COUNT) { |
| 684 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 685 | data_bde->tus.f.bdeSize = sg_dma_len(sgel); |
| 686 | data_bde->addrLow = putPaddrLow(physaddr); |
| 687 | data_bde->addrHigh = putPaddrHigh(physaddr); |
| 688 | data_bde++; |
| 689 | } else { |
| 690 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 691 | bpl->tus.f.bdeSize = sg_dma_len(sgel); |
| 692 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 693 | bpl->addrLow = |
| 694 | le32_to_cpu(putPaddrLow(physaddr)); |
| 695 | bpl->addrHigh = |
| 696 | le32_to_cpu(putPaddrHigh(physaddr)); |
| 697 | bpl++; |
| 698 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 699 | } |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 700 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 701 | |
| 702 | /* |
| 703 | * Finish initializing those IOCB fields that are dependent on the |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 704 | * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is |
| 705 | * explicitly reinitialized and for SLI-3 the extended bde count is |
| 706 | * explicitly reinitialized since all iocb memory resources are reused. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 707 | */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 708 | if (phba->sli_rev == 3 && |
| 709 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 710 | if (num_bde > LPFC_EXT_DATA_BDE_COUNT) { |
| 711 | /* |
| 712 | * The extended IOCB format can only fit 3 BDE or a BPL. |
| 713 | * This I/O has more than 3 BDE so the 1st data bde will |
| 714 | * be a BPL that is filled in here. |
| 715 | */ |
| 716 | physaddr = lpfc_cmd->dma_handle; |
| 717 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BLP_64; |
| 718 | data_bde->tus.f.bdeSize = (num_bde * |
| 719 | sizeof(struct ulp_bde64)); |
| 720 | physaddr += (sizeof(struct fcp_cmnd) + |
| 721 | sizeof(struct fcp_rsp) + |
| 722 | (2 * sizeof(struct ulp_bde64))); |
| 723 | data_bde->addrHigh = putPaddrHigh(physaddr); |
| 724 | data_bde->addrLow = putPaddrLow(physaddr); |
| 725 | /* ebde count includes the responce bde and data bpl */ |
| 726 | iocb_cmd->unsli3.fcp_ext.ebde_count = 2; |
| 727 | } else { |
| 728 | /* ebde count includes the responce bde and data bdes */ |
| 729 | iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); |
| 730 | } |
| 731 | } else { |
| 732 | iocb_cmd->un.fcpi64.bdl.bdeSize = |
| 733 | ((num_bde + 2) * sizeof(struct ulp_bde64)); |
| 734 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 735 | fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 736 | |
| 737 | /* |
| 738 | * Due to difference in data length between DIF/non-DIF paths, |
| 739 | * we need to set word 4 of IOCB here |
| 740 | */ |
| 741 | iocb_cmd->un.fcpi.fcpi_parm = le32_to_cpu(scsi_bufflen(scsi_cmnd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 742 | return 0; |
| 743 | } |
| 744 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 745 | /* |
| 746 | * Given a scsi cmnd, determine the BlockGuard profile to be used |
| 747 | * with the cmd |
| 748 | */ |
| 749 | static int |
| 750 | lpfc_sc_to_sli_prof(struct scsi_cmnd *sc) |
| 751 | { |
| 752 | uint8_t guard_type = scsi_host_get_guard(sc->device->host); |
| 753 | uint8_t ret_prof = LPFC_PROF_INVALID; |
| 754 | |
| 755 | if (guard_type == SHOST_DIX_GUARD_IP) { |
| 756 | switch (scsi_get_prot_op(sc)) { |
| 757 | case SCSI_PROT_READ_INSERT: |
| 758 | case SCSI_PROT_WRITE_STRIP: |
| 759 | ret_prof = LPFC_PROF_AST2; |
| 760 | break; |
| 761 | |
| 762 | case SCSI_PROT_READ_STRIP: |
| 763 | case SCSI_PROT_WRITE_INSERT: |
| 764 | ret_prof = LPFC_PROF_A1; |
| 765 | break; |
| 766 | |
| 767 | case SCSI_PROT_READ_CONVERT: |
| 768 | case SCSI_PROT_WRITE_CONVERT: |
| 769 | ret_prof = LPFC_PROF_AST1; |
| 770 | break; |
| 771 | |
| 772 | case SCSI_PROT_READ_PASS: |
| 773 | case SCSI_PROT_WRITE_PASS: |
| 774 | case SCSI_PROT_NORMAL: |
| 775 | default: |
| 776 | printk(KERN_ERR "Bad op/guard:%d/%d combination\n", |
| 777 | scsi_get_prot_op(sc), guard_type); |
| 778 | break; |
| 779 | |
| 780 | } |
| 781 | } else if (guard_type == SHOST_DIX_GUARD_CRC) { |
| 782 | switch (scsi_get_prot_op(sc)) { |
| 783 | case SCSI_PROT_READ_STRIP: |
| 784 | case SCSI_PROT_WRITE_INSERT: |
| 785 | ret_prof = LPFC_PROF_A1; |
| 786 | break; |
| 787 | |
| 788 | case SCSI_PROT_READ_PASS: |
| 789 | case SCSI_PROT_WRITE_PASS: |
| 790 | ret_prof = LPFC_PROF_C1; |
| 791 | break; |
| 792 | |
| 793 | case SCSI_PROT_READ_CONVERT: |
| 794 | case SCSI_PROT_WRITE_CONVERT: |
| 795 | case SCSI_PROT_READ_INSERT: |
| 796 | case SCSI_PROT_WRITE_STRIP: |
| 797 | case SCSI_PROT_NORMAL: |
| 798 | default: |
| 799 | printk(KERN_ERR "Bad op/guard:%d/%d combination\n", |
| 800 | scsi_get_prot_op(sc), guard_type); |
| 801 | break; |
| 802 | } |
| 803 | } else { |
| 804 | /* unsupported format */ |
| 805 | BUG(); |
| 806 | } |
| 807 | |
| 808 | return ret_prof; |
| 809 | } |
| 810 | |
| 811 | struct scsi_dif_tuple { |
| 812 | __be16 guard_tag; /* Checksum */ |
| 813 | __be16 app_tag; /* Opaque storage */ |
| 814 | __be32 ref_tag; /* Target LBA or indirect LBA */ |
| 815 | }; |
| 816 | |
| 817 | static inline unsigned |
| 818 | lpfc_cmd_blksize(struct scsi_cmnd *sc) |
| 819 | { |
| 820 | return sc->device->sector_size; |
| 821 | } |
| 822 | |
| 823 | /** |
| 824 | * lpfc_get_cmd_dif_parms - Extract DIF parameters from SCSI command |
| 825 | * @sc: in: SCSI command |
| 826 | * @apptagmask out: app tag mask |
| 827 | * @apptagval out: app tag value |
| 828 | * @reftag out: ref tag (reference tag) |
| 829 | * |
| 830 | * Description: |
| 831 | * Extract DIF paramters from the command if possible. Otherwise, |
| 832 | * use default paratmers. |
| 833 | * |
| 834 | **/ |
| 835 | static inline void |
| 836 | lpfc_get_cmd_dif_parms(struct scsi_cmnd *sc, uint16_t *apptagmask, |
| 837 | uint16_t *apptagval, uint32_t *reftag) |
| 838 | { |
| 839 | struct scsi_dif_tuple *spt; |
| 840 | unsigned char op = scsi_get_prot_op(sc); |
| 841 | unsigned int protcnt = scsi_prot_sg_count(sc); |
| 842 | static int cnt; |
| 843 | |
| 844 | if (protcnt && (op == SCSI_PROT_WRITE_STRIP || |
| 845 | op == SCSI_PROT_WRITE_PASS || |
| 846 | op == SCSI_PROT_WRITE_CONVERT)) { |
| 847 | |
| 848 | cnt++; |
| 849 | spt = page_address(sg_page(scsi_prot_sglist(sc))) + |
| 850 | scsi_prot_sglist(sc)[0].offset; |
| 851 | *apptagmask = 0; |
| 852 | *apptagval = 0; |
| 853 | *reftag = cpu_to_be32(spt->ref_tag); |
| 854 | |
| 855 | } else { |
| 856 | /* SBC defines ref tag to be lower 32bits of LBA */ |
| 857 | *reftag = (uint32_t) (0xffffffff & scsi_get_lba(sc)); |
| 858 | *apptagmask = 0; |
| 859 | *apptagval = 0; |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | /* |
| 864 | * This function sets up buffer list for protection groups of |
| 865 | * type LPFC_PG_TYPE_NO_DIF |
| 866 | * |
| 867 | * This is usually used when the HBA is instructed to generate |
| 868 | * DIFs and insert them into data stream (or strip DIF from |
| 869 | * incoming data stream) |
| 870 | * |
| 871 | * The buffer list consists of just one protection group described |
| 872 | * below: |
| 873 | * +-------------------------+ |
| 874 | * start of prot group --> | PDE_1 | |
| 875 | * +-------------------------+ |
| 876 | * | Data BDE | |
| 877 | * +-------------------------+ |
| 878 | * |more Data BDE's ... (opt)| |
| 879 | * +-------------------------+ |
| 880 | * |
| 881 | * @sc: pointer to scsi command we're working on |
| 882 | * @bpl: pointer to buffer list for protection groups |
| 883 | * @datacnt: number of segments of data that have been dma mapped |
| 884 | * |
| 885 | * Note: Data s/g buffers have been dma mapped |
| 886 | */ |
| 887 | static int |
| 888 | lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 889 | struct ulp_bde64 *bpl, int datasegcnt) |
| 890 | { |
| 891 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 892 | struct lpfc_pde *pde1 = NULL; |
| 893 | dma_addr_t physaddr; |
| 894 | int i = 0, num_bde = 0; |
| 895 | int datadir = sc->sc_data_direction; |
| 896 | int prof = LPFC_PROF_INVALID; |
| 897 | unsigned blksize; |
| 898 | uint32_t reftag; |
| 899 | uint16_t apptagmask, apptagval; |
| 900 | |
| 901 | pde1 = (struct lpfc_pde *) bpl; |
| 902 | prof = lpfc_sc_to_sli_prof(sc); |
| 903 | |
| 904 | if (prof == LPFC_PROF_INVALID) |
| 905 | goto out; |
| 906 | |
| 907 | /* extract some info from the scsi command for PDE1*/ |
| 908 | blksize = lpfc_cmd_blksize(sc); |
| 909 | lpfc_get_cmd_dif_parms(sc, &apptagmask, &apptagval, &reftag); |
| 910 | |
| 911 | /* setup PDE1 with what we have */ |
| 912 | lpfc_pde_set_bg_parms(pde1, LPFC_PDE1_DESCRIPTOR, prof, blksize, |
| 913 | BG_EC_STOP_ERR); |
| 914 | lpfc_pde_set_dif_parms(pde1, apptagmask, apptagval, reftag); |
| 915 | |
| 916 | num_bde++; |
| 917 | bpl++; |
| 918 | |
| 919 | /* assumption: caller has already run dma_map_sg on command data */ |
| 920 | scsi_for_each_sg(sc, sgde, datasegcnt, i) { |
| 921 | physaddr = sg_dma_address(sgde); |
| 922 | bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
| 923 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 924 | bpl->tus.f.bdeSize = sg_dma_len(sgde); |
| 925 | if (datadir == DMA_TO_DEVICE) |
| 926 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 927 | else |
| 928 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
| 929 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 930 | bpl++; |
| 931 | num_bde++; |
| 932 | } |
| 933 | |
| 934 | out: |
| 935 | return num_bde; |
| 936 | } |
| 937 | |
| 938 | /* |
| 939 | * This function sets up buffer list for protection groups of |
| 940 | * type LPFC_PG_TYPE_DIF_BUF |
| 941 | * |
| 942 | * This is usually used when DIFs are in their own buffers, |
| 943 | * separate from the data. The HBA can then by instructed |
| 944 | * to place the DIFs in the outgoing stream. For read operations, |
| 945 | * The HBA could extract the DIFs and place it in DIF buffers. |
| 946 | * |
| 947 | * The buffer list for this type consists of one or more of the |
| 948 | * protection groups described below: |
| 949 | * +-------------------------+ |
| 950 | * start of first prot group --> | PDE_1 | |
| 951 | * +-------------------------+ |
| 952 | * | PDE_3 (Prot BDE) | |
| 953 | * +-------------------------+ |
| 954 | * | Data BDE | |
| 955 | * +-------------------------+ |
| 956 | * |more Data BDE's ... (opt)| |
| 957 | * +-------------------------+ |
| 958 | * start of new prot group --> | PDE_1 | |
| 959 | * +-------------------------+ |
| 960 | * | ... | |
| 961 | * +-------------------------+ |
| 962 | * |
| 963 | * @sc: pointer to scsi command we're working on |
| 964 | * @bpl: pointer to buffer list for protection groups |
| 965 | * @datacnt: number of segments of data that have been dma mapped |
| 966 | * @protcnt: number of segment of protection data that have been dma mapped |
| 967 | * |
| 968 | * Note: It is assumed that both data and protection s/g buffers have been |
| 969 | * mapped for DMA |
| 970 | */ |
| 971 | static int |
| 972 | lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 973 | struct ulp_bde64 *bpl, int datacnt, int protcnt) |
| 974 | { |
| 975 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 976 | struct scatterlist *sgpe = NULL; /* s/g prot entry */ |
| 977 | struct lpfc_pde *pde1 = NULL; |
| 978 | struct ulp_bde64 *prot_bde = NULL; |
| 979 | dma_addr_t dataphysaddr, protphysaddr; |
| 980 | unsigned short curr_data = 0, curr_prot = 0; |
| 981 | unsigned int split_offset, protgroup_len; |
| 982 | unsigned int protgrp_blks, protgrp_bytes; |
| 983 | unsigned int remainder, subtotal; |
| 984 | int prof = LPFC_PROF_INVALID; |
| 985 | int datadir = sc->sc_data_direction; |
| 986 | unsigned char pgdone = 0, alldone = 0; |
| 987 | unsigned blksize; |
| 988 | uint32_t reftag; |
| 989 | uint16_t apptagmask, apptagval; |
| 990 | int num_bde = 0; |
| 991 | |
| 992 | sgpe = scsi_prot_sglist(sc); |
| 993 | sgde = scsi_sglist(sc); |
| 994 | |
| 995 | if (!sgpe || !sgde) { |
| 996 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 997 | "9020 Invalid s/g entry: data=0x%p prot=0x%p\n", |
| 998 | sgpe, sgde); |
| 999 | return 0; |
| 1000 | } |
| 1001 | |
| 1002 | prof = lpfc_sc_to_sli_prof(sc); |
| 1003 | if (prof == LPFC_PROF_INVALID) |
| 1004 | goto out; |
| 1005 | |
| 1006 | /* extract some info from the scsi command for PDE1*/ |
| 1007 | blksize = lpfc_cmd_blksize(sc); |
| 1008 | lpfc_get_cmd_dif_parms(sc, &apptagmask, &apptagval, &reftag); |
| 1009 | |
| 1010 | split_offset = 0; |
| 1011 | do { |
| 1012 | /* setup the first PDE_1 */ |
| 1013 | pde1 = (struct lpfc_pde *) bpl; |
| 1014 | |
| 1015 | lpfc_pde_set_bg_parms(pde1, LPFC_PDE1_DESCRIPTOR, prof, blksize, |
| 1016 | BG_EC_STOP_ERR); |
| 1017 | lpfc_pde_set_dif_parms(pde1, apptagmask, apptagval, reftag); |
| 1018 | |
| 1019 | num_bde++; |
| 1020 | bpl++; |
| 1021 | |
| 1022 | /* setup the first BDE that points to protection buffer */ |
| 1023 | prot_bde = (struct ulp_bde64 *) bpl; |
| 1024 | protphysaddr = sg_dma_address(sgpe); |
| 1025 | prot_bde->addrLow = le32_to_cpu(putPaddrLow(protphysaddr)); |
| 1026 | prot_bde->addrHigh = le32_to_cpu(putPaddrHigh(protphysaddr)); |
| 1027 | protgroup_len = sg_dma_len(sgpe); |
| 1028 | |
| 1029 | |
| 1030 | /* must be integer multiple of the DIF block length */ |
| 1031 | BUG_ON(protgroup_len % 8); |
| 1032 | |
| 1033 | protgrp_blks = protgroup_len / 8; |
| 1034 | protgrp_bytes = protgrp_blks * blksize; |
| 1035 | |
| 1036 | prot_bde->tus.f.bdeSize = protgroup_len; |
| 1037 | if (datadir == DMA_TO_DEVICE) |
| 1038 | prot_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1039 | else |
| 1040 | prot_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
| 1041 | prot_bde->tus.w = le32_to_cpu(bpl->tus.w); |
| 1042 | |
| 1043 | curr_prot++; |
| 1044 | num_bde++; |
| 1045 | |
| 1046 | /* setup BDE's for data blocks associated with DIF data */ |
| 1047 | pgdone = 0; |
| 1048 | subtotal = 0; /* total bytes processed for current prot grp */ |
| 1049 | while (!pgdone) { |
| 1050 | if (!sgde) { |
| 1051 | printk(KERN_ERR "%s Invalid data segment\n", |
| 1052 | __func__); |
| 1053 | return 0; |
| 1054 | } |
| 1055 | bpl++; |
| 1056 | dataphysaddr = sg_dma_address(sgde) + split_offset; |
| 1057 | bpl->addrLow = le32_to_cpu(putPaddrLow(dataphysaddr)); |
| 1058 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(dataphysaddr)); |
| 1059 | |
| 1060 | remainder = sg_dma_len(sgde) - split_offset; |
| 1061 | |
| 1062 | if ((subtotal + remainder) <= protgrp_bytes) { |
| 1063 | /* we can use this whole buffer */ |
| 1064 | bpl->tus.f.bdeSize = remainder; |
| 1065 | split_offset = 0; |
| 1066 | |
| 1067 | if ((subtotal + remainder) == protgrp_bytes) |
| 1068 | pgdone = 1; |
| 1069 | } else { |
| 1070 | /* must split this buffer with next prot grp */ |
| 1071 | bpl->tus.f.bdeSize = protgrp_bytes - subtotal; |
| 1072 | split_offset += bpl->tus.f.bdeSize; |
| 1073 | } |
| 1074 | |
| 1075 | subtotal += bpl->tus.f.bdeSize; |
| 1076 | |
| 1077 | if (datadir == DMA_TO_DEVICE) |
| 1078 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1079 | else |
| 1080 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
| 1081 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 1082 | |
| 1083 | num_bde++; |
| 1084 | curr_data++; |
| 1085 | |
| 1086 | if (split_offset) |
| 1087 | break; |
| 1088 | |
| 1089 | /* Move to the next s/g segment if possible */ |
| 1090 | sgde = sg_next(sgde); |
| 1091 | } |
| 1092 | |
| 1093 | /* are we done ? */ |
| 1094 | if (curr_prot == protcnt) { |
| 1095 | alldone = 1; |
| 1096 | } else if (curr_prot < protcnt) { |
| 1097 | /* advance to next prot buffer */ |
| 1098 | sgpe = sg_next(sgpe); |
| 1099 | bpl++; |
| 1100 | |
| 1101 | /* update the reference tag */ |
| 1102 | reftag += protgrp_blks; |
| 1103 | } else { |
| 1104 | /* if we're here, we have a bug */ |
| 1105 | printk(KERN_ERR "BLKGRD: bug in %s\n", __func__); |
| 1106 | } |
| 1107 | |
| 1108 | } while (!alldone); |
| 1109 | |
| 1110 | out: |
| 1111 | |
| 1112 | |
| 1113 | return num_bde; |
| 1114 | } |
| 1115 | /* |
| 1116 | * Given a SCSI command that supports DIF, determine composition of protection |
| 1117 | * groups involved in setting up buffer lists |
| 1118 | * |
| 1119 | * Returns: |
| 1120 | * for DIF (for both read and write) |
| 1121 | * */ |
| 1122 | static int |
| 1123 | lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc) |
| 1124 | { |
| 1125 | int ret = LPFC_PG_TYPE_INVALID; |
| 1126 | unsigned char op = scsi_get_prot_op(sc); |
| 1127 | |
| 1128 | switch (op) { |
| 1129 | case SCSI_PROT_READ_STRIP: |
| 1130 | case SCSI_PROT_WRITE_INSERT: |
| 1131 | ret = LPFC_PG_TYPE_NO_DIF; |
| 1132 | break; |
| 1133 | case SCSI_PROT_READ_INSERT: |
| 1134 | case SCSI_PROT_WRITE_STRIP: |
| 1135 | case SCSI_PROT_READ_PASS: |
| 1136 | case SCSI_PROT_WRITE_PASS: |
| 1137 | case SCSI_PROT_WRITE_CONVERT: |
| 1138 | case SCSI_PROT_READ_CONVERT: |
| 1139 | ret = LPFC_PG_TYPE_DIF_BUF; |
| 1140 | break; |
| 1141 | default: |
| 1142 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 1143 | "9021 Unsupported protection op:%d\n", op); |
| 1144 | break; |
| 1145 | } |
| 1146 | |
| 1147 | return ret; |
| 1148 | } |
| 1149 | |
| 1150 | /* |
| 1151 | * This is the protection/DIF aware version of |
| 1152 | * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the |
| 1153 | * two functions eventually, but for now, it's here |
| 1154 | */ |
| 1155 | static int |
| 1156 | lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba *phba, |
| 1157 | struct lpfc_scsi_buf *lpfc_cmd) |
| 1158 | { |
| 1159 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 1160 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 1161 | struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl; |
| 1162 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 1163 | uint32_t num_bde = 0; |
| 1164 | int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction; |
| 1165 | int prot_group_type = 0; |
| 1166 | int diflen, fcpdl; |
| 1167 | unsigned blksize; |
| 1168 | |
| 1169 | /* |
| 1170 | * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd |
| 1171 | * fcp_rsp regions to the first data bde entry |
| 1172 | */ |
| 1173 | bpl += 2; |
| 1174 | if (scsi_sg_count(scsi_cmnd)) { |
| 1175 | /* |
| 1176 | * The driver stores the segment count returned from pci_map_sg |
| 1177 | * because this a count of dma-mappings used to map the use_sg |
| 1178 | * pages. They are not guaranteed to be the same for those |
| 1179 | * architectures that implement an IOMMU. |
| 1180 | */ |
| 1181 | datasegcnt = dma_map_sg(&phba->pcidev->dev, |
| 1182 | scsi_sglist(scsi_cmnd), |
| 1183 | scsi_sg_count(scsi_cmnd), datadir); |
| 1184 | if (unlikely(!datasegcnt)) |
| 1185 | return 1; |
| 1186 | |
| 1187 | lpfc_cmd->seg_cnt = datasegcnt; |
| 1188 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
| 1189 | printk(KERN_ERR "%s: Too many sg segments from " |
| 1190 | "dma_map_sg. Config %d, seg_cnt %d\n", |
| 1191 | __func__, phba->cfg_sg_seg_cnt, |
| 1192 | lpfc_cmd->seg_cnt); |
| 1193 | scsi_dma_unmap(scsi_cmnd); |
| 1194 | return 1; |
| 1195 | } |
| 1196 | |
| 1197 | prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd); |
| 1198 | |
| 1199 | switch (prot_group_type) { |
| 1200 | case LPFC_PG_TYPE_NO_DIF: |
| 1201 | num_bde = lpfc_bg_setup_bpl(phba, scsi_cmnd, bpl, |
| 1202 | datasegcnt); |
| 1203 | /* we shoud have 2 or more entries in buffer list */ |
| 1204 | if (num_bde < 2) |
| 1205 | goto err; |
| 1206 | break; |
| 1207 | case LPFC_PG_TYPE_DIF_BUF:{ |
| 1208 | /* |
| 1209 | * This type indicates that protection buffers are |
| 1210 | * passed to the driver, so that needs to be prepared |
| 1211 | * for DMA |
| 1212 | */ |
| 1213 | protsegcnt = dma_map_sg(&phba->pcidev->dev, |
| 1214 | scsi_prot_sglist(scsi_cmnd), |
| 1215 | scsi_prot_sg_count(scsi_cmnd), datadir); |
| 1216 | if (unlikely(!protsegcnt)) { |
| 1217 | scsi_dma_unmap(scsi_cmnd); |
| 1218 | return 1; |
| 1219 | } |
| 1220 | |
| 1221 | lpfc_cmd->prot_seg_cnt = protsegcnt; |
| 1222 | if (lpfc_cmd->prot_seg_cnt |
| 1223 | > phba->cfg_prot_sg_seg_cnt) { |
| 1224 | printk(KERN_ERR "%s: Too many prot sg segments " |
| 1225 | "from dma_map_sg. Config %d," |
| 1226 | "prot_seg_cnt %d\n", __func__, |
| 1227 | phba->cfg_prot_sg_seg_cnt, |
| 1228 | lpfc_cmd->prot_seg_cnt); |
| 1229 | dma_unmap_sg(&phba->pcidev->dev, |
| 1230 | scsi_prot_sglist(scsi_cmnd), |
| 1231 | scsi_prot_sg_count(scsi_cmnd), |
| 1232 | datadir); |
| 1233 | scsi_dma_unmap(scsi_cmnd); |
| 1234 | return 1; |
| 1235 | } |
| 1236 | |
| 1237 | num_bde = lpfc_bg_setup_bpl_prot(phba, scsi_cmnd, bpl, |
| 1238 | datasegcnt, protsegcnt); |
| 1239 | /* we shoud have 3 or more entries in buffer list */ |
| 1240 | if (num_bde < 3) |
| 1241 | goto err; |
| 1242 | break; |
| 1243 | } |
| 1244 | case LPFC_PG_TYPE_INVALID: |
| 1245 | default: |
| 1246 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 1247 | "9022 Unexpected protection group %i\n", |
| 1248 | prot_group_type); |
| 1249 | return 1; |
| 1250 | } |
| 1251 | } |
| 1252 | |
| 1253 | /* |
| 1254 | * Finish initializing those IOCB fields that are dependent on the |
| 1255 | * scsi_cmnd request_buffer. Note that the bdeSize is explicitly |
| 1256 | * reinitialized since all iocb memory resources are used many times |
| 1257 | * for transmit, receive, and continuation bpl's. |
| 1258 | */ |
| 1259 | iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| 1260 | iocb_cmd->un.fcpi64.bdl.bdeSize += (num_bde * sizeof(struct ulp_bde64)); |
| 1261 | iocb_cmd->ulpBdeCount = 1; |
| 1262 | iocb_cmd->ulpLe = 1; |
| 1263 | |
| 1264 | fcpdl = scsi_bufflen(scsi_cmnd); |
| 1265 | |
| 1266 | if (scsi_get_prot_type(scsi_cmnd) == SCSI_PROT_DIF_TYPE1) { |
| 1267 | /* |
| 1268 | * We are in DIF Type 1 mode |
| 1269 | * Every data block has a 8 byte DIF (trailer) |
| 1270 | * attached to it. Must ajust FCP data length |
| 1271 | */ |
| 1272 | blksize = lpfc_cmd_blksize(scsi_cmnd); |
| 1273 | diflen = (fcpdl / blksize) * 8; |
| 1274 | fcpdl += diflen; |
| 1275 | } |
| 1276 | fcp_cmnd->fcpDl = be32_to_cpu(fcpdl); |
| 1277 | |
| 1278 | /* |
| 1279 | * Due to difference in data length between DIF/non-DIF paths, |
| 1280 | * we need to set word 4 of IOCB here |
| 1281 | */ |
| 1282 | iocb_cmd->un.fcpi.fcpi_parm = fcpdl; |
| 1283 | |
| 1284 | return 0; |
| 1285 | err: |
| 1286 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 1287 | "9023 Could not setup all needed BDE's" |
| 1288 | "prot_group_type=%d, num_bde=%d\n", |
| 1289 | prot_group_type, num_bde); |
| 1290 | return 1; |
| 1291 | } |
| 1292 | |
| 1293 | /* |
| 1294 | * This function checks for BlockGuard errors detected by |
| 1295 | * the HBA. In case of errors, the ASC/ASCQ fields in the |
| 1296 | * sense buffer will be set accordingly, paired with |
| 1297 | * ILLEGAL_REQUEST to signal to the kernel that the HBA |
| 1298 | * detected corruption. |
| 1299 | * |
| 1300 | * Returns: |
| 1301 | * 0 - No error found |
| 1302 | * 1 - BlockGuard error found |
| 1303 | * -1 - Internal error (bad profile, ...etc) |
| 1304 | */ |
| 1305 | static int |
| 1306 | lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd, |
| 1307 | struct lpfc_iocbq *pIocbOut) |
| 1308 | { |
| 1309 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 1310 | struct sli3_bg_fields *bgf = &pIocbOut->iocb.unsli3.sli3_bg; |
| 1311 | int ret = 0; |
| 1312 | uint32_t bghm = bgf->bghm; |
| 1313 | uint32_t bgstat = bgf->bgstat; |
| 1314 | uint64_t failing_sector = 0; |
| 1315 | |
| 1316 | printk(KERN_ERR "BG ERROR in cmd 0x%x lba 0x%llx blk cnt 0x%lx " |
| 1317 | "bgstat=0x%x bghm=0x%x\n", |
James Smart | 87b5c32 | 2008-12-16 10:34:09 -0500 | [diff] [blame^] | 1318 | cmd->cmnd[0], (unsigned long long)scsi_get_lba(cmd), |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1319 | cmd->request->nr_sectors, bgstat, bghm); |
| 1320 | |
| 1321 | spin_lock(&_dump_buf_lock); |
| 1322 | if (!_dump_buf_done) { |
| 1323 | printk(KERN_ERR "Saving Data for %u blocks to debugfs\n", |
| 1324 | (cmd->cmnd[7] << 8 | cmd->cmnd[8])); |
| 1325 | lpfc_debug_save_data(cmd); |
| 1326 | |
| 1327 | /* If we have a prot sgl, save the DIF buffer */ |
| 1328 | if (lpfc_prot_group_type(phba, cmd) == |
| 1329 | LPFC_PG_TYPE_DIF_BUF) { |
| 1330 | printk(KERN_ERR "Saving DIF for %u blocks to debugfs\n", |
| 1331 | (cmd->cmnd[7] << 8 | cmd->cmnd[8])); |
| 1332 | lpfc_debug_save_dif(cmd); |
| 1333 | } |
| 1334 | |
| 1335 | _dump_buf_done = 1; |
| 1336 | } |
| 1337 | spin_unlock(&_dump_buf_lock); |
| 1338 | |
| 1339 | if (lpfc_bgs_get_invalid_prof(bgstat)) { |
| 1340 | cmd->result = ScsiResult(DID_ERROR, 0); |
| 1341 | printk(KERN_ERR "Invalid BlockGuard profile. bgstat:0x%x\n", |
| 1342 | bgstat); |
| 1343 | ret = (-1); |
| 1344 | goto out; |
| 1345 | } |
| 1346 | |
| 1347 | if (lpfc_bgs_get_uninit_dif_block(bgstat)) { |
| 1348 | cmd->result = ScsiResult(DID_ERROR, 0); |
| 1349 | printk(KERN_ERR "Invalid BlockGuard DIF Block. bgstat:0x%x\n", |
| 1350 | bgstat); |
| 1351 | ret = (-1); |
| 1352 | goto out; |
| 1353 | } |
| 1354 | |
| 1355 | if (lpfc_bgs_get_guard_err(bgstat)) { |
| 1356 | ret = 1; |
| 1357 | |
| 1358 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 1359 | 0x10, 0x1); |
| 1360 | cmd->result = (DRIVER_SENSE|SUGGEST_DIE) << 24 |
| 1361 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 1362 | phba->bg_guard_err_cnt++; |
| 1363 | printk(KERN_ERR "BLKGRD: guard_tag error\n"); |
| 1364 | } |
| 1365 | |
| 1366 | if (lpfc_bgs_get_reftag_err(bgstat)) { |
| 1367 | ret = 1; |
| 1368 | |
| 1369 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 1370 | 0x10, 0x3); |
| 1371 | cmd->result = (DRIVER_SENSE|SUGGEST_DIE) << 24 |
| 1372 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 1373 | |
| 1374 | phba->bg_reftag_err_cnt++; |
| 1375 | printk(KERN_ERR "BLKGRD: ref_tag error\n"); |
| 1376 | } |
| 1377 | |
| 1378 | if (lpfc_bgs_get_apptag_err(bgstat)) { |
| 1379 | ret = 1; |
| 1380 | |
| 1381 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 1382 | 0x10, 0x2); |
| 1383 | cmd->result = (DRIVER_SENSE|SUGGEST_DIE) << 24 |
| 1384 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 1385 | |
| 1386 | phba->bg_apptag_err_cnt++; |
| 1387 | printk(KERN_ERR "BLKGRD: app_tag error\n"); |
| 1388 | } |
| 1389 | |
| 1390 | if (lpfc_bgs_get_hi_water_mark_present(bgstat)) { |
| 1391 | /* |
| 1392 | * setup sense data descriptor 0 per SPC-4 as an information |
| 1393 | * field, and put the failing LBA in it |
| 1394 | */ |
| 1395 | cmd->sense_buffer[8] = 0; /* Information */ |
| 1396 | cmd->sense_buffer[9] = 0xa; /* Add. length */ |
| 1397 | do_div(bghm, cmd->device->sector_size); |
| 1398 | |
| 1399 | failing_sector = scsi_get_lba(cmd); |
| 1400 | failing_sector += bghm; |
| 1401 | |
| 1402 | put_unaligned_be64(failing_sector, &cmd->sense_buffer[10]); |
| 1403 | } |
| 1404 | |
| 1405 | if (!ret) { |
| 1406 | /* No error was reported - problem in FW? */ |
| 1407 | cmd->result = ScsiResult(DID_ERROR, 0); |
| 1408 | printk(KERN_ERR "BLKGRD: no errors reported!\n"); |
| 1409 | } |
| 1410 | |
| 1411 | out: |
| 1412 | return ret; |
| 1413 | } |
| 1414 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1415 | /** |
| 1416 | * lpfc_send_scsi_error_event: Posts an event when there is SCSI error. |
| 1417 | * @phba: Pointer to hba context object. |
| 1418 | * @vport: Pointer to vport object. |
| 1419 | * @lpfc_cmd: Pointer to lpfc scsi command which reported the error. |
| 1420 | * @rsp_iocb: Pointer to response iocb object which reported error. |
| 1421 | * |
| 1422 | * This function posts an event when there is a SCSI command reporting |
| 1423 | * error from the scsi device. |
| 1424 | **/ |
| 1425 | static void |
| 1426 | lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 1427 | struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_iocbq *rsp_iocb) { |
| 1428 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 1429 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
| 1430 | uint32_t resp_info = fcprsp->rspStatus2; |
| 1431 | uint32_t scsi_status = fcprsp->rspStatus3; |
| 1432 | uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; |
| 1433 | struct lpfc_fast_path_event *fast_path_evt = NULL; |
| 1434 | struct lpfc_nodelist *pnode = lpfc_cmd->rdata->pnode; |
| 1435 | unsigned long flags; |
| 1436 | |
| 1437 | /* If there is queuefull or busy condition send a scsi event */ |
| 1438 | if ((cmnd->result == SAM_STAT_TASK_SET_FULL) || |
| 1439 | (cmnd->result == SAM_STAT_BUSY)) { |
| 1440 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 1441 | if (!fast_path_evt) |
| 1442 | return; |
| 1443 | fast_path_evt->un.scsi_evt.event_type = |
| 1444 | FC_REG_SCSI_EVENT; |
| 1445 | fast_path_evt->un.scsi_evt.subcategory = |
| 1446 | (cmnd->result == SAM_STAT_TASK_SET_FULL) ? |
| 1447 | LPFC_EVENT_QFULL : LPFC_EVENT_DEVBSY; |
| 1448 | fast_path_evt->un.scsi_evt.lun = cmnd->device->lun; |
| 1449 | memcpy(&fast_path_evt->un.scsi_evt.wwpn, |
| 1450 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 1451 | memcpy(&fast_path_evt->un.scsi_evt.wwnn, |
| 1452 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 1453 | } else if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen && |
| 1454 | ((cmnd->cmnd[0] == READ_10) || (cmnd->cmnd[0] == WRITE_10))) { |
| 1455 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 1456 | if (!fast_path_evt) |
| 1457 | return; |
| 1458 | fast_path_evt->un.check_cond_evt.scsi_event.event_type = |
| 1459 | FC_REG_SCSI_EVENT; |
| 1460 | fast_path_evt->un.check_cond_evt.scsi_event.subcategory = |
| 1461 | LPFC_EVENT_CHECK_COND; |
| 1462 | fast_path_evt->un.check_cond_evt.scsi_event.lun = |
| 1463 | cmnd->device->lun; |
| 1464 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwpn, |
| 1465 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 1466 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwnn, |
| 1467 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 1468 | fast_path_evt->un.check_cond_evt.sense_key = |
| 1469 | cmnd->sense_buffer[2] & 0xf; |
| 1470 | fast_path_evt->un.check_cond_evt.asc = cmnd->sense_buffer[12]; |
| 1471 | fast_path_evt->un.check_cond_evt.ascq = cmnd->sense_buffer[13]; |
| 1472 | } else if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) && |
| 1473 | fcpi_parm && |
| 1474 | ((be32_to_cpu(fcprsp->rspResId) != fcpi_parm) || |
| 1475 | ((scsi_status == SAM_STAT_GOOD) && |
| 1476 | !(resp_info & (RESID_UNDER | RESID_OVER))))) { |
| 1477 | /* |
| 1478 | * If status is good or resid does not match with fcp_param and |
| 1479 | * there is valid fcpi_parm, then there is a read_check error |
| 1480 | */ |
| 1481 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 1482 | if (!fast_path_evt) |
| 1483 | return; |
| 1484 | fast_path_evt->un.read_check_error.header.event_type = |
| 1485 | FC_REG_FABRIC_EVENT; |
| 1486 | fast_path_evt->un.read_check_error.header.subcategory = |
| 1487 | LPFC_EVENT_FCPRDCHKERR; |
| 1488 | memcpy(&fast_path_evt->un.read_check_error.header.wwpn, |
| 1489 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 1490 | memcpy(&fast_path_evt->un.read_check_error.header.wwnn, |
| 1491 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 1492 | fast_path_evt->un.read_check_error.lun = cmnd->device->lun; |
| 1493 | fast_path_evt->un.read_check_error.opcode = cmnd->cmnd[0]; |
| 1494 | fast_path_evt->un.read_check_error.fcpiparam = |
| 1495 | fcpi_parm; |
| 1496 | } else |
| 1497 | return; |
| 1498 | |
| 1499 | fast_path_evt->vport = vport; |
| 1500 | spin_lock_irqsave(&phba->hbalock, flags); |
| 1501 | list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list); |
| 1502 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1503 | lpfc_worker_wake_up(phba); |
| 1504 | return; |
| 1505 | } |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 1506 | |
| 1507 | /** |
| 1508 | * lpfc_scsi_unprep_dma_buf: Routine to un-map DMA mapping of scatter gather. |
| 1509 | * @phba: The Hba for which this call is being executed. |
| 1510 | * @psb: The scsi buffer which is going to be un-mapped. |
| 1511 | * |
| 1512 | * This routine does DMA un-mapping of scatter gather list of scsi command |
| 1513 | * field of @lpfc_cmd. |
| 1514 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1515 | static void |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 1516 | lpfc_scsi_unprep_dma_buf(struct lpfc_hba * phba, struct lpfc_scsi_buf * psb) |
| 1517 | { |
| 1518 | /* |
| 1519 | * There are only two special cases to consider. (1) the scsi command |
| 1520 | * requested scatter-gather usage or (2) the scsi command allocated |
| 1521 | * a request buffer, but did not request use_sg. There is a third |
| 1522 | * case, but it does not require resource deallocation. |
| 1523 | */ |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1524 | if (psb->seg_cnt > 0) |
| 1525 | scsi_dma_unmap(psb->pCmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1526 | if (psb->prot_seg_cnt > 0) |
| 1527 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(psb->pCmd), |
| 1528 | scsi_prot_sg_count(psb->pCmd), |
| 1529 | psb->pCmd->sc_data_direction); |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 1530 | } |
| 1531 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 1532 | /** |
| 1533 | * lpfc_handler_fcp_err: FCP response handler. |
| 1534 | * @vport: The virtual port for which this call is being executed. |
| 1535 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. |
| 1536 | * @rsp_iocb: The response IOCB which contains FCP error. |
| 1537 | * |
| 1538 | * This routine is called to process response IOCB with status field |
| 1539 | * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command |
| 1540 | * based upon SCSI and FCP error. |
| 1541 | **/ |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 1542 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1543 | lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd, |
| 1544 | struct lpfc_iocbq *rsp_iocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1545 | { |
| 1546 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 1547 | struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd; |
| 1548 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1549 | uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1550 | uint32_t resp_info = fcprsp->rspStatus2; |
| 1551 | uint32_t scsi_status = fcprsp->rspStatus3; |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 1552 | uint32_t *lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1553 | uint32_t host_status = DID_OK; |
| 1554 | uint32_t rsplen = 0; |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 1555 | uint32_t logit = LOG_FCP | LOG_FCP_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1556 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1557 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1558 | /* |
| 1559 | * If this is a task management command, there is no |
| 1560 | * scsi packet associated with this lpfc_cmd. The driver |
| 1561 | * consumes it. |
| 1562 | */ |
| 1563 | if (fcpcmd->fcpCntl2) { |
| 1564 | scsi_status = 0; |
| 1565 | goto out; |
| 1566 | } |
| 1567 | |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 1568 | if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) { |
| 1569 | uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen); |
| 1570 | if (snslen > SCSI_SENSE_BUFFERSIZE) |
| 1571 | snslen = SCSI_SENSE_BUFFERSIZE; |
| 1572 | |
| 1573 | if (resp_info & RSP_LEN_VALID) |
| 1574 | rsplen = be32_to_cpu(fcprsp->rspRspLen); |
| 1575 | memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen); |
| 1576 | } |
| 1577 | lp = (uint32_t *)cmnd->sense_buffer; |
| 1578 | |
| 1579 | if (!scsi_status && (resp_info & RESID_UNDER)) |
| 1580 | logit = LOG_FCP; |
| 1581 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1582 | lpfc_printf_vlog(vport, KERN_WARNING, logit, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1583 | "9024 FCP command x%x failed: x%x SNS x%x x%x " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1584 | "Data: x%x x%x x%x x%x x%x\n", |
| 1585 | cmnd->cmnd[0], scsi_status, |
| 1586 | be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info, |
| 1587 | be32_to_cpu(fcprsp->rspResId), |
| 1588 | be32_to_cpu(fcprsp->rspSnsLen), |
| 1589 | be32_to_cpu(fcprsp->rspRspLen), |
| 1590 | fcprsp->rspInfo3); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1591 | |
| 1592 | if (resp_info & RSP_LEN_VALID) { |
| 1593 | rsplen = be32_to_cpu(fcprsp->rspRspLen); |
| 1594 | if ((rsplen != 0 && rsplen != 4 && rsplen != 8) || |
| 1595 | (fcprsp->rspInfo3 != RSP_NO_FAILURE)) { |
| 1596 | host_status = DID_ERROR; |
| 1597 | goto out; |
| 1598 | } |
| 1599 | } |
| 1600 | |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1601 | scsi_set_resid(cmnd, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1602 | if (resp_info & RESID_UNDER) { |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1603 | scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1604 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1605 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1606 | "9025 FCP Read Underrun, expected %d, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1607 | "residual %d Data: x%x x%x x%x\n", |
| 1608 | be32_to_cpu(fcpcmd->fcpDl), |
| 1609 | scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0], |
| 1610 | cmnd->underflow); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1611 | |
| 1612 | /* |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1613 | * If there is an under run check if under run reported by |
| 1614 | * storage array is same as the under run reported by HBA. |
| 1615 | * If this is not same, there is a dropped frame. |
| 1616 | */ |
| 1617 | if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) && |
| 1618 | fcpi_parm && |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1619 | (scsi_get_resid(cmnd) != fcpi_parm)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1620 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 1621 | LOG_FCP | LOG_FCP_ERROR, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1622 | "9026 FCP Read Check Error " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1623 | "and Underrun Data: x%x x%x x%x x%x\n", |
| 1624 | be32_to_cpu(fcpcmd->fcpDl), |
| 1625 | scsi_get_resid(cmnd), fcpi_parm, |
| 1626 | cmnd->cmnd[0]); |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1627 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1628 | host_status = DID_ERROR; |
| 1629 | } |
| 1630 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1631 | * The cmnd->underflow is the minimum number of bytes that must |
| 1632 | * be transfered for this command. Provided a sense condition |
| 1633 | * is not present, make sure the actual amount transferred is at |
| 1634 | * least the underflow value or fail. |
| 1635 | */ |
| 1636 | if (!(resp_info & SNS_LEN_VALID) && |
| 1637 | (scsi_status == SAM_STAT_GOOD) && |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1638 | (scsi_bufflen(cmnd) - scsi_get_resid(cmnd) |
| 1639 | < cmnd->underflow)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1640 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1641 | "9027 FCP command x%x residual " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1642 | "underrun converted to error " |
| 1643 | "Data: x%x x%x x%x\n", |
James Smart | 66dbfbe | 2007-08-05 06:08:38 -0400 | [diff] [blame] | 1644 | cmnd->cmnd[0], scsi_bufflen(cmnd), |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1645 | scsi_get_resid(cmnd), cmnd->underflow); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1646 | host_status = DID_ERROR; |
| 1647 | } |
| 1648 | } else if (resp_info & RESID_OVER) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1649 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1650 | "9028 FCP command x%x residual overrun error. " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1651 | "Data: x%x x%x \n", cmnd->cmnd[0], |
| 1652 | scsi_bufflen(cmnd), scsi_get_resid(cmnd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1653 | host_status = DID_ERROR; |
| 1654 | |
| 1655 | /* |
| 1656 | * Check SLI validation that all the transfer was actually done |
| 1657 | * (fcpi_parm should be zero). Apply check only to reads. |
| 1658 | */ |
| 1659 | } else if ((scsi_status == SAM_STAT_GOOD) && fcpi_parm && |
| 1660 | (cmnd->sc_data_direction == DMA_FROM_DEVICE)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1661 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1662 | "9029 FCP Read Check Error Data: " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1663 | "x%x x%x x%x x%x\n", |
| 1664 | be32_to_cpu(fcpcmd->fcpDl), |
| 1665 | be32_to_cpu(fcprsp->rspResId), |
| 1666 | fcpi_parm, cmnd->cmnd[0]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1667 | host_status = DID_ERROR; |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1668 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1669 | } |
| 1670 | |
| 1671 | out: |
| 1672 | cmnd->result = ScsiResult(host_status, scsi_status); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1673 | lpfc_send_scsi_error_event(vport->phba, vport, lpfc_cmd, rsp_iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1674 | } |
| 1675 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 1676 | /** |
| 1677 | * lpfc_scsi_cmd_iocb_cmpl: Scsi cmnd IOCB completion routine. |
| 1678 | * @phba: The Hba for which this call is being executed. |
| 1679 | * @pIocbIn: The command IOCBQ for the scsi cmnd. |
| 1680 | * @pIocbOut: The response IOCBQ for the scsi cmnd . |
| 1681 | * |
| 1682 | * This routine assigns scsi command result by looking into response IOCB |
| 1683 | * status field appropriately. This routine handles QUEUE FULL condition as |
| 1684 | * well by ramping down device queue depth. |
| 1685 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1686 | static void |
| 1687 | lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn, |
| 1688 | struct lpfc_iocbq *pIocbOut) |
| 1689 | { |
| 1690 | struct lpfc_scsi_buf *lpfc_cmd = |
| 1691 | (struct lpfc_scsi_buf *) pIocbIn->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1692 | struct lpfc_vport *vport = pIocbIn->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1693 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| 1694 | struct lpfc_nodelist *pnode = rdata->pnode; |
| 1695 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
James.Smart@Emulex.Com | 445cf4f | 2005-11-28 11:42:38 -0500 | [diff] [blame] | 1696 | int result; |
| 1697 | struct scsi_device *sdev, *tmp_sdev; |
| 1698 | int depth = 0; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 1699 | unsigned long flags; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1700 | struct lpfc_fast_path_event *fast_path_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1701 | |
| 1702 | lpfc_cmd->result = pIocbOut->iocb.un.ulpWord[4]; |
| 1703 | lpfc_cmd->status = pIocbOut->iocb.ulpStatus; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 1704 | if (pnode && NLP_CHK_NODE_ACT(pnode)) |
| 1705 | atomic_dec(&pnode->cmd_pending); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1706 | |
| 1707 | if (lpfc_cmd->status) { |
| 1708 | if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT && |
| 1709 | (lpfc_cmd->result & IOERR_DRVR_MASK)) |
| 1710 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; |
| 1711 | else if (lpfc_cmd->status >= IOSTAT_CNT) |
| 1712 | lpfc_cmd->status = IOSTAT_DEFAULT; |
| 1713 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1714 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1715 | "9030 FCP cmd x%x failed <%d/%d> " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1716 | "status: x%x result: x%x Data: x%x x%x\n", |
| 1717 | cmd->cmnd[0], |
| 1718 | cmd->device ? cmd->device->id : 0xffff, |
| 1719 | cmd->device ? cmd->device->lun : 0xffff, |
| 1720 | lpfc_cmd->status, lpfc_cmd->result, |
| 1721 | pIocbOut->iocb.ulpContext, |
| 1722 | lpfc_cmd->cur_iocbq.iocb.ulpIoTag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1723 | |
| 1724 | switch (lpfc_cmd->status) { |
| 1725 | case IOSTAT_FCP_RSP_ERROR: |
| 1726 | /* Call FCP RSP handler to determine result */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1727 | lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1728 | break; |
| 1729 | case IOSTAT_NPORT_BSY: |
| 1730 | case IOSTAT_FABRIC_BSY: |
James Smart | 0f1f53a | 2008-08-24 21:50:18 -0400 | [diff] [blame] | 1731 | cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 0); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1732 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 1733 | if (!fast_path_evt) |
| 1734 | break; |
| 1735 | fast_path_evt->un.fabric_evt.event_type = |
| 1736 | FC_REG_FABRIC_EVENT; |
| 1737 | fast_path_evt->un.fabric_evt.subcategory = |
| 1738 | (lpfc_cmd->status == IOSTAT_NPORT_BSY) ? |
| 1739 | LPFC_EVENT_PORT_BUSY : LPFC_EVENT_FABRIC_BUSY; |
| 1740 | if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
| 1741 | memcpy(&fast_path_evt->un.fabric_evt.wwpn, |
| 1742 | &pnode->nlp_portname, |
| 1743 | sizeof(struct lpfc_name)); |
| 1744 | memcpy(&fast_path_evt->un.fabric_evt.wwnn, |
| 1745 | &pnode->nlp_nodename, |
| 1746 | sizeof(struct lpfc_name)); |
| 1747 | } |
| 1748 | fast_path_evt->vport = vport; |
| 1749 | fast_path_evt->work_evt.evt = |
| 1750 | LPFC_EVT_FASTPATH_MGMT_EVT; |
| 1751 | spin_lock_irqsave(&phba->hbalock, flags); |
| 1752 | list_add_tail(&fast_path_evt->work_evt.evt_listp, |
| 1753 | &phba->work_list); |
| 1754 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1755 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1756 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1757 | case IOSTAT_LOCAL_REJECT: |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1758 | if (lpfc_cmd->result == IOERR_INVALID_RPI || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1759 | lpfc_cmd->result == IOERR_NO_RESOURCES || |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1760 | lpfc_cmd->result == IOERR_ABORT_REQUESTED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1761 | cmd->result = ScsiResult(DID_REQUEUE, 0); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1762 | break; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED || |
| 1766 | lpfc_cmd->result == IOERR_TX_DMA_FAILED) && |
| 1767 | pIocbOut->iocb.unsli3.sli3_bg.bgstat) { |
| 1768 | if (scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) { |
| 1769 | /* |
| 1770 | * This is a response for a BG enabled |
| 1771 | * cmd. Parse BG error |
| 1772 | */ |
| 1773 | lpfc_parse_bg_err(phba, lpfc_cmd, |
| 1774 | pIocbOut); |
| 1775 | break; |
| 1776 | } else { |
| 1777 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 1778 | LOG_BG, |
| 1779 | "9031 non-zero BGSTAT " |
| 1780 | "on unprotected cmd"); |
| 1781 | } |
| 1782 | } |
| 1783 | |
| 1784 | /* else: fall through */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1785 | default: |
| 1786 | cmd->result = ScsiResult(DID_ERROR, 0); |
| 1787 | break; |
| 1788 | } |
| 1789 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1790 | if (!pnode || !NLP_CHK_NODE_ACT(pnode) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 1791 | || (pnode->nlp_state != NLP_STE_MAPPED_NODE)) |
James Smart | 0f1f53a | 2008-08-24 21:50:18 -0400 | [diff] [blame] | 1792 | cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, |
| 1793 | SAM_STAT_BUSY); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1794 | } else { |
| 1795 | cmd->result = ScsiResult(DID_OK, 0); |
| 1796 | } |
| 1797 | |
| 1798 | if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) { |
| 1799 | uint32_t *lp = (uint32_t *)cmd->sense_buffer; |
| 1800 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1801 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 1802 | "0710 Iodone <%d/%d> cmd %p, error " |
| 1803 | "x%x SNS x%x x%x Data: x%x x%x\n", |
| 1804 | cmd->device->id, cmd->device->lun, cmd, |
| 1805 | cmd->result, *lp, *(lp + 3), cmd->retries, |
| 1806 | scsi_get_resid(cmd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1807 | } |
| 1808 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1809 | lpfc_update_stats(phba, lpfc_cmd); |
James.Smart@Emulex.Com | 445cf4f | 2005-11-28 11:42:38 -0500 | [diff] [blame] | 1810 | result = cmd->result; |
| 1811 | sdev = cmd->device; |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 1812 | if (vport->cfg_max_scsicmpl_time && |
| 1813 | time_after(jiffies, lpfc_cmd->start_time + |
| 1814 | msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) { |
| 1815 | spin_lock_irqsave(sdev->host->host_lock, flags); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 1816 | if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
| 1817 | if (pnode->cmd_qdepth > |
| 1818 | atomic_read(&pnode->cmd_pending) && |
| 1819 | (atomic_read(&pnode->cmd_pending) > |
| 1820 | LPFC_MIN_TGT_QDEPTH) && |
| 1821 | ((cmd->cmnd[0] == READ_10) || |
| 1822 | (cmd->cmnd[0] == WRITE_10))) |
| 1823 | pnode->cmd_qdepth = |
| 1824 | atomic_read(&pnode->cmd_pending); |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 1825 | |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 1826 | pnode->last_change_time = jiffies; |
| 1827 | } |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 1828 | spin_unlock_irqrestore(sdev->host->host_lock, flags); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 1829 | } else if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
| 1830 | if ((pnode->cmd_qdepth < LPFC_MAX_TGT_QDEPTH) && |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 1831 | time_after(jiffies, pnode->last_change_time + |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 1832 | msecs_to_jiffies(LPFC_TGTQ_INTERVAL))) { |
| 1833 | spin_lock_irqsave(sdev->host->host_lock, flags); |
| 1834 | pnode->cmd_qdepth += pnode->cmd_qdepth * |
| 1835 | LPFC_TGTQ_RAMPUP_PCENT / 100; |
| 1836 | if (pnode->cmd_qdepth > LPFC_MAX_TGT_QDEPTH) |
| 1837 | pnode->cmd_qdepth = LPFC_MAX_TGT_QDEPTH; |
| 1838 | pnode->last_change_time = jiffies; |
| 1839 | spin_unlock_irqrestore(sdev->host->host_lock, flags); |
| 1840 | } |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 1841 | } |
| 1842 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 1843 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1844 | cmd->scsi_done(cmd); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1845 | |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 1846 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 1847 | /* |
| 1848 | * If there is a thread waiting for command completion |
| 1849 | * wake up the thread. |
| 1850 | */ |
| 1851 | spin_lock_irqsave(sdev->host->host_lock, flags); |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 1852 | lpfc_cmd->pCmd = NULL; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 1853 | if (lpfc_cmd->waitq) |
| 1854 | wake_up(lpfc_cmd->waitq); |
| 1855 | spin_unlock_irqrestore(sdev->host->host_lock, flags); |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 1856 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 1857 | return; |
| 1858 | } |
| 1859 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1860 | |
| 1861 | if (!result) |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1862 | lpfc_rampup_queue_depth(vport, sdev); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1863 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1864 | if (!result && pnode && NLP_CHK_NODE_ACT(pnode) && |
James.Smart@Emulex.Com | 445cf4f | 2005-11-28 11:42:38 -0500 | [diff] [blame] | 1865 | ((jiffies - pnode->last_ramp_up_time) > |
| 1866 | LPFC_Q_RAMP_UP_INTERVAL * HZ) && |
| 1867 | ((jiffies - pnode->last_q_full_time) > |
| 1868 | LPFC_Q_RAMP_UP_INTERVAL * HZ) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1869 | (vport->cfg_lun_queue_depth > sdev->queue_depth)) { |
James.Smart@Emulex.Com | 445cf4f | 2005-11-28 11:42:38 -0500 | [diff] [blame] | 1870 | shost_for_each_device(tmp_sdev, sdev->host) { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1871 | if (vport->cfg_lun_queue_depth > tmp_sdev->queue_depth){ |
James.Smart@Emulex.Com | 445cf4f | 2005-11-28 11:42:38 -0500 | [diff] [blame] | 1872 | if (tmp_sdev->id != sdev->id) |
| 1873 | continue; |
| 1874 | if (tmp_sdev->ordered_tags) |
| 1875 | scsi_adjust_queue_depth(tmp_sdev, |
| 1876 | MSG_ORDERED_TAG, |
| 1877 | tmp_sdev->queue_depth+1); |
| 1878 | else |
| 1879 | scsi_adjust_queue_depth(tmp_sdev, |
| 1880 | MSG_SIMPLE_TAG, |
| 1881 | tmp_sdev->queue_depth+1); |
| 1882 | |
| 1883 | pnode->last_ramp_up_time = jiffies; |
| 1884 | } |
| 1885 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1886 | lpfc_send_sdev_queuedepth_change_event(phba, vport, pnode, |
| 1887 | 0xFFFFFFFF, |
| 1888 | sdev->queue_depth - 1, sdev->queue_depth); |
James.Smart@Emulex.Com | 445cf4f | 2005-11-28 11:42:38 -0500 | [diff] [blame] | 1889 | } |
| 1890 | |
| 1891 | /* |
| 1892 | * Check for queue full. If the lun is reporting queue full, then |
| 1893 | * back off the lun queue depth to prevent target overloads. |
| 1894 | */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1895 | if (result == SAM_STAT_TASK_SET_FULL && pnode && |
| 1896 | NLP_CHK_NODE_ACT(pnode)) { |
James.Smart@Emulex.Com | 445cf4f | 2005-11-28 11:42:38 -0500 | [diff] [blame] | 1897 | pnode->last_q_full_time = jiffies; |
| 1898 | |
| 1899 | shost_for_each_device(tmp_sdev, sdev->host) { |
| 1900 | if (tmp_sdev->id != sdev->id) |
| 1901 | continue; |
| 1902 | depth = scsi_track_queue_full(tmp_sdev, |
| 1903 | tmp_sdev->queue_depth - 1); |
| 1904 | } |
| 1905 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1906 | * The queue depth cannot be lowered any more. |
James.Smart@Emulex.Com | 445cf4f | 2005-11-28 11:42:38 -0500 | [diff] [blame] | 1907 | * Modify the returned error code to store |
| 1908 | * the final depth value set by |
| 1909 | * scsi_track_queue_full. |
| 1910 | */ |
| 1911 | if (depth == -1) |
| 1912 | depth = sdev->host->cmd_per_lun; |
| 1913 | |
| 1914 | if (depth) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1915 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 1916 | "0711 detected queue full - lun queue " |
| 1917 | "depth adjusted to %d.\n", depth); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1918 | lpfc_send_sdev_queuedepth_change_event(phba, vport, |
| 1919 | pnode, 0xFFFFFFFF, |
| 1920 | depth+1, depth); |
James.Smart@Emulex.Com | 445cf4f | 2005-11-28 11:42:38 -0500 | [diff] [blame] | 1921 | } |
| 1922 | } |
| 1923 | |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 1924 | /* |
| 1925 | * If there is a thread waiting for command completion |
| 1926 | * wake up the thread. |
| 1927 | */ |
| 1928 | spin_lock_irqsave(sdev->host->host_lock, flags); |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 1929 | lpfc_cmd->pCmd = NULL; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 1930 | if (lpfc_cmd->waitq) |
| 1931 | wake_up(lpfc_cmd->waitq); |
| 1932 | spin_unlock_irqrestore(sdev->host->host_lock, flags); |
| 1933 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1934 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1935 | } |
| 1936 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1937 | /** |
| 1938 | * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB. |
| 1939 | * @data: A pointer to the immediate command data portion of the IOCB. |
| 1940 | * @fcp_cmnd: The FCP Command that is provided by the SCSI layer. |
| 1941 | * |
| 1942 | * The routine copies the entire FCP command from @fcp_cmnd to @data while |
| 1943 | * byte swapping the data to big endian format for transmission on the wire. |
| 1944 | **/ |
| 1945 | static void |
| 1946 | lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd) |
| 1947 | { |
| 1948 | int i, j; |
| 1949 | for (i = 0, j = 0; i < sizeof(struct fcp_cmnd); |
| 1950 | i += sizeof(uint32_t), j++) { |
| 1951 | ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]); |
| 1952 | } |
| 1953 | } |
| 1954 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 1955 | /** |
| 1956 | * lpfc_scsi_prep_cmnd: Routine to convert scsi cmnd to FCP information unit. |
| 1957 | * @vport: The virtual port for which this call is being executed. |
| 1958 | * @lpfc_cmd: The scsi command which needs to send. |
| 1959 | * @pnode: Pointer to lpfc_nodelist. |
| 1960 | * |
| 1961 | * This routine initializes fcp_cmnd and iocb data structure from scsi command |
| 1962 | * to transfer. |
| 1963 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1964 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1965 | lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd, |
| 1966 | struct lpfc_nodelist *pnode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1967 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1968 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1969 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 1970 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 1971 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 1972 | struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq); |
| 1973 | int datadir = scsi_cmnd->sc_data_direction; |
James Smart | 7e2b19f | 2007-10-29 11:00:39 -0400 | [diff] [blame] | 1974 | char tag[2]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1975 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1976 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 1977 | return; |
| 1978 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1979 | lpfc_cmd->fcp_rsp->rspSnsLen = 0; |
James.Smart@Emulex.Com | 69859dc | 2005-08-10 15:02:37 -0400 | [diff] [blame] | 1980 | /* clear task management bits */ |
| 1981 | lpfc_cmd->fcp_cmnd->fcpCntl2 = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1982 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 1983 | int_to_scsilun(lpfc_cmd->pCmd->device->lun, |
| 1984 | &lpfc_cmd->fcp_cmnd->fcp_lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1985 | |
| 1986 | memcpy(&fcp_cmnd->fcpCdb[0], scsi_cmnd->cmnd, 16); |
| 1987 | |
James Smart | 7e2b19f | 2007-10-29 11:00:39 -0400 | [diff] [blame] | 1988 | if (scsi_populate_tag_msg(scsi_cmnd, tag)) { |
| 1989 | switch (tag[0]) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1990 | case HEAD_OF_QUEUE_TAG: |
| 1991 | fcp_cmnd->fcpCntl1 = HEAD_OF_Q; |
| 1992 | break; |
| 1993 | case ORDERED_QUEUE_TAG: |
| 1994 | fcp_cmnd->fcpCntl1 = ORDERED_Q; |
| 1995 | break; |
| 1996 | default: |
| 1997 | fcp_cmnd->fcpCntl1 = SIMPLE_Q; |
| 1998 | break; |
| 1999 | } |
| 2000 | } else |
| 2001 | fcp_cmnd->fcpCntl1 = 0; |
| 2002 | |
| 2003 | /* |
| 2004 | * There are three possibilities here - use scatter-gather segment, use |
| 2005 | * the single mapping, or neither. Start the lpfc command prep by |
| 2006 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 2007 | * data bde entry. |
| 2008 | */ |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2009 | if (scsi_sg_count(scsi_cmnd)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2010 | if (datadir == DMA_TO_DEVICE) { |
| 2011 | iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR; |
| 2012 | iocb_cmd->un.fcpi.fcpi_parm = 0; |
| 2013 | iocb_cmd->ulpPU = 0; |
| 2014 | fcp_cmnd->fcpCntl3 = WRITE_DATA; |
| 2015 | phba->fc4OutputRequests++; |
| 2016 | } else { |
| 2017 | iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR; |
| 2018 | iocb_cmd->ulpPU = PARM_READ_CHECK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2019 | fcp_cmnd->fcpCntl3 = READ_DATA; |
| 2020 | phba->fc4InputRequests++; |
| 2021 | } |
| 2022 | } else { |
| 2023 | iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR; |
| 2024 | iocb_cmd->un.fcpi.fcpi_parm = 0; |
| 2025 | iocb_cmd->ulpPU = 0; |
| 2026 | fcp_cmnd->fcpCntl3 = 0; |
| 2027 | phba->fc4ControlRequests++; |
| 2028 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2029 | if (phba->sli_rev == 3 && |
| 2030 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2031 | lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2032 | /* |
| 2033 | * Finish initializing those IOCB fields that are independent |
| 2034 | * of the scsi_cmnd request_buffer |
| 2035 | */ |
| 2036 | piocbq->iocb.ulpContext = pnode->nlp_rpi; |
| 2037 | if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE) |
| 2038 | piocbq->iocb.ulpFCP2Rcvy = 1; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2039 | else |
| 2040 | piocbq->iocb.ulpFCP2Rcvy = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2041 | |
| 2042 | piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f); |
| 2043 | piocbq->context1 = lpfc_cmd; |
| 2044 | piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; |
| 2045 | piocbq->iocb.ulpTimeout = lpfc_cmd->timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2046 | piocbq->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2047 | } |
| 2048 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2049 | /** |
| 2050 | * lpfc_scsi_prep_task_mgmt_cmnd: Convert scsi TM cmnd to FCP information unit. |
| 2051 | * @vport: The virtual port for which this call is being executed. |
| 2052 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. |
| 2053 | * @lun: Logical unit number. |
| 2054 | * @task_mgmt_cmd: SCSI task management command. |
| 2055 | * |
| 2056 | * This routine creates FCP information unit corresponding to @task_mgmt_cmd. |
| 2057 | * |
| 2058 | * Return codes: |
| 2059 | * 0 - Error |
| 2060 | * 1 - Success |
| 2061 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2062 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2063 | lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2064 | struct lpfc_scsi_buf *lpfc_cmd, |
James Smart | 420b630d | 2006-07-06 15:50:16 -0400 | [diff] [blame] | 2065 | unsigned int lun, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2066 | uint8_t task_mgmt_cmd) |
| 2067 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2068 | struct lpfc_iocbq *piocbq; |
| 2069 | IOCB_t *piocb; |
| 2070 | struct fcp_cmnd *fcp_cmnd; |
James Smart | 0b18ac4 | 2006-05-01 21:50:40 -0400 | [diff] [blame] | 2071 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2072 | struct lpfc_nodelist *ndlp = rdata->pnode; |
| 2073 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2074 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || |
| 2075 | ndlp->nlp_state != NLP_STE_MAPPED_NODE) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2076 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2077 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2078 | piocbq = &(lpfc_cmd->cur_iocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2079 | piocbq->vport = vport; |
| 2080 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2081 | piocb = &piocbq->iocb; |
| 2082 | |
| 2083 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2084 | /* Clear out any old data in the FCP command area */ |
| 2085 | memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd)); |
| 2086 | int_to_scsilun(lun, &fcp_cmnd->fcp_lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2087 | fcp_cmnd->fcpCntl2 = task_mgmt_cmd; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2088 | if (vport->phba->sli_rev == 3 && |
| 2089 | !(vport->phba->sli3_options & LPFC_SLI3_BG_ENABLED)) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2090 | lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2091 | piocb->ulpCommand = CMD_FCP_ICMND64_CR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2092 | piocb->ulpContext = ndlp->nlp_rpi; |
| 2093 | if (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) { |
| 2094 | piocb->ulpFCP2Rcvy = 1; |
| 2095 | } |
| 2096 | piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f); |
| 2097 | |
| 2098 | /* ulpTimeout is only one byte */ |
| 2099 | if (lpfc_cmd->timeout > 0xff) { |
| 2100 | /* |
| 2101 | * Do not timeout the command at the firmware level. |
| 2102 | * The driver will provide the timeout mechanism. |
| 2103 | */ |
| 2104 | piocb->ulpTimeout = 0; |
| 2105 | } else { |
| 2106 | piocb->ulpTimeout = lpfc_cmd->timeout; |
| 2107 | } |
| 2108 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2109 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2110 | } |
| 2111 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2112 | /** |
| 2113 | * lpc_taskmgmt_def_cmpl: IOCB completion routine for task management command. |
| 2114 | * @phba: The Hba for which this call is being executed. |
| 2115 | * @cmdiocbq: Pointer to lpfc_iocbq data structure. |
| 2116 | * @rspiocbq: Pointer to lpfc_iocbq data structure. |
| 2117 | * |
| 2118 | * This routine is IOCB completion routine for device reset and target reset |
| 2119 | * routine. This routine release scsi buffer associated with lpfc_cmd. |
| 2120 | **/ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2121 | static void |
| 2122 | lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba, |
| 2123 | struct lpfc_iocbq *cmdiocbq, |
| 2124 | struct lpfc_iocbq *rspiocbq) |
| 2125 | { |
| 2126 | struct lpfc_scsi_buf *lpfc_cmd = |
| 2127 | (struct lpfc_scsi_buf *) cmdiocbq->context1; |
| 2128 | if (lpfc_cmd) |
| 2129 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 2130 | return; |
| 2131 | } |
| 2132 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2133 | /** |
| 2134 | * lpfc_scsi_tgt_reset: Target reset handler. |
| 2135 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure |
| 2136 | * @vport: The virtual port for which this call is being executed. |
| 2137 | * @tgt_id: Target ID. |
| 2138 | * @lun: Lun number. |
| 2139 | * @rdata: Pointer to lpfc_rport_data. |
| 2140 | * |
| 2141 | * This routine issues a TARGET RESET iocb to reset a target with @tgt_id ID. |
| 2142 | * |
| 2143 | * Return Code: |
| 2144 | * 0x2003 - Error |
| 2145 | * 0x2002 - Success. |
| 2146 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2147 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2148 | 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] | 2149 | unsigned tgt_id, unsigned int lun, |
| 2150 | struct lpfc_rport_data *rdata) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2151 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2152 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2153 | struct lpfc_iocbq *iocbq; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2154 | struct lpfc_iocbq *iocbqrsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2155 | int ret; |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 2156 | int status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2157 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2158 | if (!rdata->pnode || !NLP_CHK_NODE_ACT(rdata->pnode)) |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 2159 | return FAILED; |
| 2160 | |
James Smart | 0b18ac4 | 2006-05-01 21:50:40 -0400 | [diff] [blame] | 2161 | lpfc_cmd->rdata = rdata; |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 2162 | status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun, |
James Smart | 420b630d | 2006-07-06 15:50:16 -0400 | [diff] [blame] | 2163 | FCP_TARGET_RESET); |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 2164 | if (!status) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2165 | return FAILED; |
| 2166 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2167 | iocbq = &lpfc_cmd->cur_iocbq; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2168 | iocbqrsp = lpfc_sli_get_iocbq(phba); |
| 2169 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2170 | if (!iocbqrsp) |
| 2171 | return FAILED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2172 | |
James Smart | 0b18ac4 | 2006-05-01 21:50:40 -0400 | [diff] [blame] | 2173 | /* Issue Target Reset to TGT <num> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2174 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 2175 | "0702 Issue Target Reset to TGT %d Data: x%x x%x\n", |
| 2176 | tgt_id, rdata->pnode->nlp_rpi, rdata->pnode->nlp_flag); |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 2177 | status = lpfc_sli_issue_iocb_wait(phba, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 2178 | &phba->sli.ring[phba->sli.fcp_ring], |
| 2179 | iocbq, iocbqrsp, lpfc_cmd->timeout); |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 2180 | if (status != IOCB_SUCCESS) { |
| 2181 | if (status == IOCB_TIMEDOUT) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2182 | iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl; |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 2183 | ret = TIMEOUT_ERROR; |
| 2184 | } else |
| 2185 | ret = FAILED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2186 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2187 | } else { |
| 2188 | ret = SUCCESS; |
| 2189 | lpfc_cmd->result = iocbqrsp->iocb.un.ulpWord[4]; |
| 2190 | lpfc_cmd->status = iocbqrsp->iocb.ulpStatus; |
| 2191 | if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT && |
| 2192 | (lpfc_cmd->result & IOERR_DRVR_MASK)) |
| 2193 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; |
| 2194 | } |
| 2195 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2196 | lpfc_sli_release_iocbq(phba, iocbqrsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2197 | return ret; |
| 2198 | } |
| 2199 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2200 | /** |
| 2201 | * lpfc_info: Info entry point of scsi_host_template data structure. |
| 2202 | * @host: The scsi host for which this call is being executed. |
| 2203 | * |
| 2204 | * This routine provides module information about hba. |
| 2205 | * |
| 2206 | * Reutrn code: |
| 2207 | * Pointer to char - Success. |
| 2208 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2209 | const char * |
| 2210 | lpfc_info(struct Scsi_Host *host) |
| 2211 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2212 | struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata; |
| 2213 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2214 | int len; |
| 2215 | static char lpfcinfobuf[384]; |
| 2216 | |
| 2217 | memset(lpfcinfobuf,0,384); |
| 2218 | if (phba && phba->pcidev){ |
| 2219 | strncpy(lpfcinfobuf, phba->ModelDesc, 256); |
| 2220 | len = strlen(lpfcinfobuf); |
| 2221 | snprintf(lpfcinfobuf + len, |
| 2222 | 384-len, |
| 2223 | " on PCI bus %02x device %02x irq %d", |
| 2224 | phba->pcidev->bus->number, |
| 2225 | phba->pcidev->devfn, |
| 2226 | phba->pcidev->irq); |
| 2227 | len = strlen(lpfcinfobuf); |
| 2228 | if (phba->Port[0]) { |
| 2229 | snprintf(lpfcinfobuf + len, |
| 2230 | 384-len, |
| 2231 | " port %s", |
| 2232 | phba->Port); |
| 2233 | } |
| 2234 | } |
| 2235 | return lpfcinfobuf; |
| 2236 | } |
| 2237 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2238 | /** |
| 2239 | * lpfc_poll_rearm_time: Routine to modify fcp_poll timer of hba. |
| 2240 | * @phba: The Hba for which this call is being executed. |
| 2241 | * |
| 2242 | * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo. |
| 2243 | * The default value of cfg_poll_tmo is 10 milliseconds. |
| 2244 | **/ |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2245 | static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba) |
| 2246 | { |
| 2247 | unsigned long poll_tmo_expires = |
| 2248 | (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo)); |
| 2249 | |
| 2250 | if (phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt) |
| 2251 | mod_timer(&phba->fcp_poll_timer, |
| 2252 | poll_tmo_expires); |
| 2253 | } |
| 2254 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2255 | /** |
| 2256 | * lpfc_poll_start_timer: Routine to start fcp_poll_timer of HBA. |
| 2257 | * @phba: The Hba for which this call is being executed. |
| 2258 | * |
| 2259 | * This routine starts the fcp_poll_timer of @phba. |
| 2260 | **/ |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2261 | void lpfc_poll_start_timer(struct lpfc_hba * phba) |
| 2262 | { |
| 2263 | lpfc_poll_rearm_timer(phba); |
| 2264 | } |
| 2265 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2266 | /** |
| 2267 | * lpfc_poll_timeout: Restart polling timer. |
| 2268 | * @ptr: Map to lpfc_hba data structure pointer. |
| 2269 | * |
| 2270 | * This routine restarts fcp_poll timer, when FCP ring polling is enable |
| 2271 | * and FCP Ring interrupt is disable. |
| 2272 | **/ |
| 2273 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2274 | void lpfc_poll_timeout(unsigned long ptr) |
| 2275 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2276 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2277 | |
| 2278 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
| 2279 | lpfc_sli_poll_fcp_ring (phba); |
| 2280 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 2281 | lpfc_poll_rearm_timer(phba); |
| 2282 | } |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2283 | } |
| 2284 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2285 | /** |
| 2286 | * lpfc_queuecommand: Queuecommand entry point of Scsi Host Templater data |
| 2287 | * structure. |
| 2288 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 2289 | * @done: Pointer to done routine. |
| 2290 | * |
| 2291 | * Driver registers this routine to scsi midlayer to submit a @cmd to process. |
| 2292 | * This routine prepares an IOCB from scsi command and provides to firmware. |
| 2293 | * The @done callback is invoked after driver finished processing the command. |
| 2294 | * |
| 2295 | * Return value : |
| 2296 | * 0 - Success |
| 2297 | * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily. |
| 2298 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2299 | static int |
| 2300 | lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *)) |
| 2301 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2302 | struct Scsi_Host *shost = cmnd->device->host; |
| 2303 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 2304 | struct lpfc_hba *phba = vport->phba; |
| 2305 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2306 | struct lpfc_rport_data *rdata = cmnd->device->hostdata; |
| 2307 | struct lpfc_nodelist *ndlp = rdata->pnode; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2308 | struct lpfc_scsi_buf *lpfc_cmd; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2309 | 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] | 2310 | int err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2311 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2312 | err = fc_remote_port_chkready(rport); |
| 2313 | if (err) { |
| 2314 | cmnd->result = err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2315 | goto out_fail_command; |
| 2316 | } |
| 2317 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2318 | if (!(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
| 2319 | scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) { |
| 2320 | |
| 2321 | printk(KERN_ERR "BLKGRD ERROR: rcvd protected cmd:%02x op:%02x " |
| 2322 | "str=%s without registering for BlockGuard - " |
| 2323 | "Rejecting command\n", |
| 2324 | cmnd->cmnd[0], scsi_get_prot_op(cmnd), |
| 2325 | dif_op_str[scsi_get_prot_op(cmnd)]); |
| 2326 | goto out_fail_command; |
| 2327 | } |
| 2328 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2329 | /* |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2330 | * Catch race where our node has transitioned, but the |
| 2331 | * transport is still transitioning. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2332 | */ |
James Smart | b522d7d | 2008-09-07 11:51:56 -0400 | [diff] [blame] | 2333 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
| 2334 | cmnd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 0); |
| 2335 | goto out_fail_command; |
| 2336 | } |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 2337 | if (vport->cfg_max_scsicmpl_time && |
| 2338 | (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth)) |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 2339 | goto out_host_busy; |
Mike Christie | a93ce02 | 2008-08-17 15:24:41 -0500 | [diff] [blame] | 2340 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2341 | lpfc_cmd = lpfc_get_scsi_buf(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2342 | if (lpfc_cmd == NULL) { |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2343 | lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2344 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2345 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 2346 | "0707 driver's buffer pool is empty, " |
| 2347 | "IO busied\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2348 | goto out_host_busy; |
| 2349 | } |
| 2350 | |
| 2351 | /* |
| 2352 | * Store the midlayer's command structure for the completion phase |
| 2353 | * and complete the command initialization. |
| 2354 | */ |
| 2355 | lpfc_cmd->pCmd = cmnd; |
| 2356 | lpfc_cmd->rdata = rdata; |
| 2357 | lpfc_cmd->timeout = 0; |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 2358 | lpfc_cmd->start_time = jiffies; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2359 | cmnd->host_scribble = (unsigned char *)lpfc_cmd; |
| 2360 | cmnd->scsi_done = done; |
| 2361 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2362 | if (scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) { |
| 2363 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
| 2364 | "9033 BLKGRD: rcvd protected cmd:%02x op:%02x " |
| 2365 | "str=%s\n", |
| 2366 | cmnd->cmnd[0], scsi_get_prot_op(cmnd), |
| 2367 | dif_op_str[scsi_get_prot_op(cmnd)]); |
| 2368 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
| 2369 | "9034 BLKGRD: CDB: %02x %02x %02x %02x %02x " |
| 2370 | "%02x %02x %02x %02x %02x \n", |
| 2371 | cmnd->cmnd[0], cmnd->cmnd[1], cmnd->cmnd[2], |
| 2372 | cmnd->cmnd[3], cmnd->cmnd[4], cmnd->cmnd[5], |
| 2373 | cmnd->cmnd[6], cmnd->cmnd[7], cmnd->cmnd[8], |
| 2374 | cmnd->cmnd[9]); |
| 2375 | if (cmnd->cmnd[0] == READ_10) |
| 2376 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
| 2377 | "9035 BLKGRD: READ @ sector %llu, " |
| 2378 | "count %lu\n", |
James Smart | 87b5c32 | 2008-12-16 10:34:09 -0500 | [diff] [blame^] | 2379 | (unsigned long long)scsi_get_lba(cmnd), |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2380 | cmnd->request->nr_sectors); |
| 2381 | else if (cmnd->cmnd[0] == WRITE_10) |
| 2382 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
| 2383 | "9036 BLKGRD: WRITE @ sector %llu, " |
| 2384 | "count %lu cmd=%p\n", |
James Smart | 87b5c32 | 2008-12-16 10:34:09 -0500 | [diff] [blame^] | 2385 | (unsigned long long)scsi_get_lba(cmnd), |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2386 | cmnd->request->nr_sectors, |
| 2387 | cmnd); |
| 2388 | |
| 2389 | err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 2390 | } else { |
| 2391 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
| 2392 | "9038 BLKGRD: rcvd unprotected cmd:%02x op:%02x" |
| 2393 | " str=%s\n", |
| 2394 | cmnd->cmnd[0], scsi_get_prot_op(cmnd), |
| 2395 | dif_op_str[scsi_get_prot_op(cmnd)]); |
| 2396 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
| 2397 | "9039 BLKGRD: CDB: %02x %02x %02x %02x %02x " |
| 2398 | "%02x %02x %02x %02x %02x \n", |
| 2399 | cmnd->cmnd[0], cmnd->cmnd[1], cmnd->cmnd[2], |
| 2400 | cmnd->cmnd[3], cmnd->cmnd[4], cmnd->cmnd[5], |
| 2401 | cmnd->cmnd[6], cmnd->cmnd[7], cmnd->cmnd[8], |
| 2402 | cmnd->cmnd[9]); |
| 2403 | if (cmnd->cmnd[0] == READ_10) |
| 2404 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
| 2405 | "9040 dbg: READ @ sector %llu, " |
James Smart | 87b5c32 | 2008-12-16 10:34:09 -0500 | [diff] [blame^] | 2406 | "count %lu\n", |
| 2407 | (unsigned long long)scsi_get_lba(cmnd), |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2408 | cmnd->request->nr_sectors); |
| 2409 | else if (cmnd->cmnd[0] == WRITE_10) |
| 2410 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
| 2411 | "9041 dbg: WRITE @ sector %llu, " |
| 2412 | "count %lu cmd=%p\n", |
James Smart | 87b5c32 | 2008-12-16 10:34:09 -0500 | [diff] [blame^] | 2413 | (unsigned long long)scsi_get_lba(cmnd), |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2414 | cmnd->request->nr_sectors, cmnd); |
| 2415 | else |
| 2416 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
| 2417 | "9042 dbg: parser not implemented\n"); |
| 2418 | err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 2419 | } |
| 2420 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2421 | if (err) |
| 2422 | goto out_host_busy_free_buf; |
| 2423 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2424 | lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2425 | |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 2426 | atomic_inc(&ndlp->cmd_pending); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2427 | err = lpfc_sli_issue_iocb(phba, &phba->sli.ring[psli->fcp_ring], |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2428 | &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2429 | if (err) { |
| 2430 | atomic_dec(&ndlp->cmd_pending); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2431 | goto out_host_busy_free_buf; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2432 | } |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2433 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
| 2434 | lpfc_sli_poll_fcp_ring(phba); |
| 2435 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 2436 | lpfc_poll_rearm_timer(phba); |
| 2437 | } |
| 2438 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2439 | return 0; |
| 2440 | |
| 2441 | out_host_busy_free_buf: |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 2442 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2443 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2444 | out_host_busy: |
| 2445 | return SCSI_MLQUEUE_HOST_BUSY; |
| 2446 | |
| 2447 | out_fail_command: |
| 2448 | done(cmnd); |
| 2449 | return 0; |
| 2450 | } |
| 2451 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2452 | /** |
| 2453 | * lpfc_block_error_handler: Routine to block error handler. |
| 2454 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 2455 | * |
| 2456 | * This routine blocks execution till fc_rport state is not FC_PORSTAT_BLCOEKD. |
| 2457 | **/ |
James Smart | a90f568 | 2006-08-17 11:58:04 -0400 | [diff] [blame] | 2458 | static void |
| 2459 | lpfc_block_error_handler(struct scsi_cmnd *cmnd) |
| 2460 | { |
| 2461 | struct Scsi_Host *shost = cmnd->device->host; |
| 2462 | struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device)); |
| 2463 | |
| 2464 | spin_lock_irq(shost->host_lock); |
| 2465 | while (rport->port_state == FC_PORTSTATE_BLOCKED) { |
| 2466 | spin_unlock_irq(shost->host_lock); |
| 2467 | msleep(1000); |
| 2468 | spin_lock_irq(shost->host_lock); |
| 2469 | } |
| 2470 | spin_unlock_irq(shost->host_lock); |
| 2471 | return; |
| 2472 | } |
James.Smart@Emulex.Com | 63c59c3 | 2005-11-28 11:41:53 -0500 | [diff] [blame] | 2473 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2474 | /** |
| 2475 | * lpfc_abort_handler: Eh_abort_handler entry point of Scsi Host Template data |
| 2476 | *structure. |
| 2477 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 2478 | * |
| 2479 | * This routine aborts @cmnd pending in base driver. |
| 2480 | * |
| 2481 | * Return code : |
| 2482 | * 0x2003 - Error |
| 2483 | * 0x2002 - Success |
| 2484 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2485 | static int |
James.Smart@Emulex.Com | 63c59c3 | 2005-11-28 11:41:53 -0500 | [diff] [blame] | 2486 | lpfc_abort_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2487 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2488 | struct Scsi_Host *shost = cmnd->device->host; |
| 2489 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 2490 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2491 | 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] | 2492 | struct lpfc_iocbq *iocb; |
| 2493 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2494 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2495 | IOCB_t *cmd, *icmd; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2496 | int ret = SUCCESS; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 2497 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2498 | |
James Smart | a90f568 | 2006-08-17 11:58:04 -0400 | [diff] [blame] | 2499 | lpfc_block_error_handler(cmnd); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2500 | lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble; |
| 2501 | BUG_ON(!lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2502 | |
| 2503 | /* |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2504 | * If pCmd field of the corresponding lpfc_scsi_buf structure |
| 2505 | * points to a different SCSI command, then the driver has |
| 2506 | * already completed this command, but the midlayer did not |
| 2507 | * see the completion before the eh fired. Just return |
| 2508 | * SUCCESS. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2509 | */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2510 | iocb = &lpfc_cmd->cur_iocbq; |
| 2511 | if (lpfc_cmd->pCmd != cmnd) |
| 2512 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2513 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2514 | BUG_ON(iocb->context1 != lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2515 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2516 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| 2517 | if (abtsiocb == NULL) { |
| 2518 | ret = FAILED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2519 | goto out; |
| 2520 | } |
| 2521 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2522 | /* |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2523 | * The scsi command can not be in txq and it is in flight because the |
| 2524 | * pCmd is still pointig at the SCSI command we have to abort. There |
| 2525 | * is no need to search the txcmplq. Just send an abort to the FW. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2526 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2527 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2528 | cmd = &iocb->iocb; |
| 2529 | icmd = &abtsiocb->iocb; |
| 2530 | icmd->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 2531 | icmd->un.acxri.abortContextTag = cmd->ulpContext; |
| 2532 | icmd->un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2533 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2534 | icmd->ulpLe = 1; |
| 2535 | icmd->ulpClass = cmd->ulpClass; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2536 | if (lpfc_is_link_up(phba)) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2537 | icmd->ulpCommand = CMD_ABORT_XRI_CN; |
| 2538 | else |
| 2539 | icmd->ulpCommand = CMD_CLOSE_XRI_CN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2540 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2541 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2542 | abtsiocb->vport = vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2543 | if (lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0) == IOCB_ERROR) { |
| 2544 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| 2545 | ret = FAILED; |
| 2546 | goto out; |
| 2547 | } |
| 2548 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2549 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 2550 | lpfc_sli_poll_fcp_ring (phba); |
| 2551 | |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 2552 | lpfc_cmd->waitq = &waitq; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2553 | /* Wait for abort to complete */ |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 2554 | wait_event_timeout(waitq, |
| 2555 | (lpfc_cmd->pCmd != cmnd), |
| 2556 | (2*vport->cfg_devloss_tmo*HZ)); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2557 | |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 2558 | spin_lock_irq(shost->host_lock); |
| 2559 | lpfc_cmd->waitq = NULL; |
| 2560 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2561 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2562 | if (lpfc_cmd->pCmd == cmnd) { |
| 2563 | ret = FAILED; |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2564 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 2565 | "0748 abort handler timed out waiting " |
| 2566 | "for abort to complete: ret %#x, ID %d, " |
| 2567 | "LUN %d, snum %#lx\n", |
| 2568 | ret, cmnd->device->id, cmnd->device->lun, |
| 2569 | cmnd->serial_number); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2570 | } |
| 2571 | |
| 2572 | out: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2573 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 2574 | "0749 SCSI Layer I/O Abort Request Status x%x ID %d " |
| 2575 | "LUN %d snum %#lx\n", ret, cmnd->device->id, |
| 2576 | cmnd->device->lun, cmnd->serial_number); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2577 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2578 | } |
| 2579 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2580 | /** |
| 2581 | * lpfc_device_reset_handler: eh_device_reset entry point of Scsi Host Template |
| 2582 | *data structure. |
| 2583 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 2584 | * |
| 2585 | * This routine does a device reset by sending a TARGET_RESET task management |
| 2586 | * command. |
| 2587 | * |
| 2588 | * Return code : |
| 2589 | * 0x2003 - Error |
| 2590 | * 0ex2002 - Success |
| 2591 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2592 | static int |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2593 | lpfc_device_reset_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2594 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2595 | struct Scsi_Host *shost = cmnd->device->host; |
| 2596 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 2597 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2598 | struct lpfc_scsi_buf *lpfc_cmd; |
| 2599 | struct lpfc_iocbq *iocbq, *iocbqrsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2600 | struct lpfc_rport_data *rdata = cmnd->device->hostdata; |
| 2601 | struct lpfc_nodelist *pnode = rdata->pnode; |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 2602 | unsigned long later; |
| 2603 | int ret = SUCCESS; |
| 2604 | int status; |
| 2605 | int cnt; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2606 | struct lpfc_scsi_event_header scsi_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2607 | |
James Smart | a90f568 | 2006-08-17 11:58:04 -0400 | [diff] [blame] | 2608 | lpfc_block_error_handler(cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2609 | /* |
| 2610 | * If target is not in a MAPPED state, delay the reset until |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2611 | * target is rediscovered or devloss timeout expires. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2612 | */ |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 2613 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; |
| 2614 | while (time_after(later, jiffies)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2615 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 2616 | return FAILED; |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 2617 | if (pnode->nlp_state == NLP_STE_MAPPED_NODE) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2618 | break; |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 2619 | schedule_timeout_uninterruptible(msecs_to_jiffies(500)); |
| 2620 | rdata = cmnd->device->hostdata; |
| 2621 | if (!rdata) |
| 2622 | break; |
| 2623 | pnode = rdata->pnode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2624 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2625 | |
| 2626 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 2627 | scsi_event.subcategory = LPFC_EVENT_TGTRESET; |
| 2628 | scsi_event.lun = 0; |
| 2629 | memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 2630 | memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 2631 | |
| 2632 | fc_host_post_vendor_event(shost, |
| 2633 | fc_get_event_number(), |
| 2634 | sizeof(scsi_event), |
| 2635 | (char *)&scsi_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 2636 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2637 | |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 2638 | if (!rdata || pnode->nlp_state != NLP_STE_MAPPED_NODE) { |
| 2639 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 2640 | "0721 LUN Reset rport " |
| 2641 | "failure: msec x%x rdata x%p\n", |
| 2642 | jiffies_to_msecs(jiffies - later), rdata); |
| 2643 | return FAILED; |
| 2644 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2645 | lpfc_cmd = lpfc_get_scsi_buf(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2646 | if (lpfc_cmd == NULL) |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 2647 | return FAILED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2648 | lpfc_cmd->timeout = 60; |
James Smart | 0b18ac4 | 2006-05-01 21:50:40 -0400 | [diff] [blame] | 2649 | lpfc_cmd->rdata = rdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2650 | |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 2651 | status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, |
| 2652 | cmnd->device->lun, |
| 2653 | FCP_TARGET_RESET); |
| 2654 | if (!status) { |
| 2655 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 2656 | return FAILED; |
| 2657 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2658 | iocbq = &lpfc_cmd->cur_iocbq; |
| 2659 | |
| 2660 | /* get a buffer for this IOCB command response */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2661 | iocbqrsp = lpfc_sli_get_iocbq(phba); |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 2662 | if (iocbqrsp == NULL) { |
| 2663 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 2664 | return FAILED; |
| 2665 | } |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2666 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 2667 | "0703 Issue target reset to TGT %d LUN %d " |
| 2668 | "rpi x%x nlp_flag x%x\n", cmnd->device->id, |
| 2669 | cmnd->device->lun, pnode->nlp_rpi, pnode->nlp_flag); |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 2670 | status = lpfc_sli_issue_iocb_wait(phba, |
| 2671 | &phba->sli.ring[phba->sli.fcp_ring], |
| 2672 | iocbq, iocbqrsp, lpfc_cmd->timeout); |
| 2673 | if (status == IOCB_TIMEDOUT) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2674 | iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl; |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 2675 | ret = TIMEOUT_ERROR; |
| 2676 | } else { |
| 2677 | if (status != IOCB_SUCCESS) |
| 2678 | ret = FAILED; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2679 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 2680 | } |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2681 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 2682 | "0713 SCSI layer issued device reset (%d, %d) " |
| 2683 | "return x%x status x%x result x%x\n", |
| 2684 | cmnd->device->id, cmnd->device->lun, ret, |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 2685 | iocbqrsp->iocb.ulpStatus, |
| 2686 | iocbqrsp->iocb.un.ulpWord[4]); |
| 2687 | lpfc_sli_release_iocbq(phba, iocbqrsp); |
| 2688 | cnt = lpfc_sli_sum_iocb(vport, cmnd->device->id, cmnd->device->lun, |
| 2689 | LPFC_CTX_TGT); |
| 2690 | if (cnt) |
| 2691 | lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring], |
| 2692 | cmnd->device->id, cmnd->device->lun, |
| 2693 | LPFC_CTX_TGT); |
| 2694 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; |
| 2695 | while (time_after(later, jiffies) && cnt) { |
| 2696 | schedule_timeout_uninterruptible(msecs_to_jiffies(20)); |
| 2697 | cnt = lpfc_sli_sum_iocb(vport, cmnd->device->id, |
| 2698 | cmnd->device->lun, LPFC_CTX_TGT); |
| 2699 | } |
| 2700 | if (cnt) { |
| 2701 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 2702 | "0719 device reset I/O flush failure: " |
| 2703 | "cnt x%x\n", cnt); |
| 2704 | ret = FAILED; |
| 2705 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2706 | return ret; |
| 2707 | } |
| 2708 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2709 | /** |
| 2710 | * lpfc_bus_reset_handler: eh_bus_reset_handler entry point of Scsi Host |
| 2711 | * Template data structure. |
| 2712 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 2713 | * |
| 2714 | * This routine does target reset to all target on @cmnd->device->host. |
| 2715 | * |
| 2716 | * Return Code: |
| 2717 | * 0x2003 - Error |
| 2718 | * 0x2002 - Success |
| 2719 | **/ |
Jeff Garzik | 94d0e7b8 | 2005-05-28 07:55:48 -0400 | [diff] [blame] | 2720 | static int |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2721 | lpfc_bus_reset_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2722 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2723 | struct Scsi_Host *shost = cmnd->device->host; |
| 2724 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 2725 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2726 | struct lpfc_nodelist *ndlp = NULL; |
| 2727 | int match; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2728 | int ret = SUCCESS, status = SUCCESS, i; |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 2729 | int cnt; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2730 | struct lpfc_scsi_buf * lpfc_cmd; |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 2731 | unsigned long later; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2732 | struct lpfc_scsi_event_header scsi_event; |
| 2733 | |
| 2734 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 2735 | scsi_event.subcategory = LPFC_EVENT_BUSRESET; |
| 2736 | scsi_event.lun = 0; |
| 2737 | memcpy(scsi_event.wwpn, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2738 | memcpy(scsi_event.wwnn, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| 2739 | |
| 2740 | fc_host_post_vendor_event(shost, |
| 2741 | fc_get_event_number(), |
| 2742 | sizeof(scsi_event), |
| 2743 | (char *)&scsi_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 2744 | LPFC_NL_VENDOR_ID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2745 | |
James Smart | a90f568 | 2006-08-17 11:58:04 -0400 | [diff] [blame] | 2746 | lpfc_block_error_handler(cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2747 | /* |
| 2748 | * Since the driver manages a single bus device, reset all |
| 2749 | * targets known to the driver. Should any target reset |
| 2750 | * fail, this routine returns failure to the midlayer. |
| 2751 | */ |
James Smart | e17da18 | 2006-07-06 15:49:25 -0400 | [diff] [blame] | 2752 | for (i = 0; i < LPFC_MAX_TARGET; i++) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2753 | /* Search for mapped node by target ID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2754 | match = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2755 | spin_lock_irq(shost->host_lock); |
| 2756 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2757 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 2758 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2759 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE && |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 2760 | ndlp->nlp_sid == i && |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2761 | ndlp->rport) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2762 | match = 1; |
| 2763 | break; |
| 2764 | } |
| 2765 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2766 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2767 | if (!match) |
| 2768 | continue; |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 2769 | lpfc_cmd = lpfc_get_scsi_buf(phba); |
| 2770 | if (lpfc_cmd) { |
| 2771 | lpfc_cmd->timeout = 60; |
| 2772 | status = lpfc_scsi_tgt_reset(lpfc_cmd, vport, i, |
| 2773 | cmnd->device->lun, |
| 2774 | ndlp->rport->dd_data); |
| 2775 | if (status != TIMEOUT_ERROR) |
| 2776 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 2777 | } |
| 2778 | if (!lpfc_cmd || status != SUCCESS) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2779 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 2780 | "0700 Bus Reset on target %d failed\n", |
| 2781 | i); |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 2782 | ret = FAILED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2783 | } |
| 2784 | } |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 2785 | /* |
| 2786 | * All outstanding txcmplq I/Os should have been aborted by |
| 2787 | * the targets. Unfortunately, some targets do not abide by |
| 2788 | * this forcing the driver to double check. |
| 2789 | */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2790 | 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] | 2791 | if (cnt) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2792 | lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring], |
| 2793 | 0, 0, LPFC_CTX_HOST); |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 2794 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; |
| 2795 | while (time_after(later, jiffies) && cnt) { |
| 2796 | schedule_timeout_uninterruptible(msecs_to_jiffies(20)); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2797 | cnt = lpfc_sli_sum_iocb(vport, 0, 0, LPFC_CTX_HOST); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2798 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2799 | if (cnt) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2800 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 2801 | "0715 Bus Reset I/O flush failure: " |
| 2802 | "cnt x%x left x%x\n", cnt, i); |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 2803 | ret = FAILED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2804 | } |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2805 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 2806 | "0714 SCSI layer issued Bus Reset Data: x%x\n", ret); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2807 | return ret; |
| 2808 | } |
| 2809 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2810 | /** |
| 2811 | * lpfc_slave_alloc: slave_alloc entry point of Scsi Host Template data |
| 2812 | * structure. |
| 2813 | * @sdev: Pointer to scsi_device. |
| 2814 | * |
| 2815 | * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's |
| 2816 | * globally available list of scsi buffers. This routine also makes sure scsi |
| 2817 | * buffer is not allocated more than HBA limit conveyed to midlayer. This list |
| 2818 | * of scsi buffer exists for the lifetime of the driver. |
| 2819 | * |
| 2820 | * Return codes: |
| 2821 | * non-0 - Error |
| 2822 | * 0 - Success |
| 2823 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2824 | static int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2825 | lpfc_slave_alloc(struct scsi_device *sdev) |
| 2826 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2827 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 2828 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2829 | struct lpfc_scsi_buf *scsi_buf = NULL; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2830 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2831 | uint32_t total = 0, i; |
| 2832 | uint32_t num_to_alloc = 0; |
| 2833 | unsigned long flags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2834 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2835 | if (!rport || fc_remote_port_chkready(rport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2836 | return -ENXIO; |
| 2837 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2838 | sdev->hostdata = rport->dd_data; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2839 | |
| 2840 | /* |
| 2841 | * Populate the cmds_per_lun count scsi_bufs into this host's globally |
| 2842 | * 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] | 2843 | * HBA limit conveyed to the midlayer via the host structure. The |
| 2844 | * formula accounts for the lun_queue_depth + error handlers + 1 |
| 2845 | * extra. This list of scsi bufs exists for the lifetime of the driver. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2846 | */ |
| 2847 | total = phba->total_scsi_bufs; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2848 | num_to_alloc = vport->cfg_lun_queue_depth + 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2849 | |
| 2850 | /* Allow some exchanges to be available always to complete discovery */ |
| 2851 | if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2852 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 2853 | "0704 At limitation of %d preallocated " |
| 2854 | "command buffers\n", total); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2855 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2856 | /* Allow some exchanges to be available always to complete discovery */ |
| 2857 | } else if (total + num_to_alloc > |
| 2858 | phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2859 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 2860 | "0705 Allocation request of %d " |
| 2861 | "command buffers will exceed max of %d. " |
| 2862 | "Reducing allocation request to %d.\n", |
| 2863 | num_to_alloc, phba->cfg_hba_queue_depth, |
| 2864 | (phba->cfg_hba_queue_depth - total)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2865 | num_to_alloc = phba->cfg_hba_queue_depth - total; |
| 2866 | } |
| 2867 | |
| 2868 | for (i = 0; i < num_to_alloc; i++) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2869 | scsi_buf = lpfc_new_scsi_buf(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2870 | if (!scsi_buf) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2871 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 2872 | "0706 Failed to allocate " |
| 2873 | "command buffer\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2874 | break; |
| 2875 | } |
| 2876 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2877 | spin_lock_irqsave(&phba->scsi_buf_list_lock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2878 | phba->total_scsi_bufs++; |
| 2879 | 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] | 2880 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2881 | } |
| 2882 | return 0; |
| 2883 | } |
| 2884 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2885 | /** |
| 2886 | * lpfc_slave_configure: slave_configure entry point of Scsi Host Templater data |
| 2887 | * structure. |
| 2888 | * @sdev: Pointer to scsi_device. |
| 2889 | * |
| 2890 | * This routine configures following items |
| 2891 | * - Tag command queuing support for @sdev if supported. |
| 2892 | * - Dev loss time out value of fc_rport. |
| 2893 | * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set. |
| 2894 | * |
| 2895 | * Return codes: |
| 2896 | * 0 - Success |
| 2897 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2898 | static int |
| 2899 | lpfc_slave_configure(struct scsi_device *sdev) |
| 2900 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2901 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 2902 | struct lpfc_hba *phba = vport->phba; |
| 2903 | struct fc_rport *rport = starget_to_rport(sdev->sdev_target); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2904 | |
| 2905 | if (sdev->tagged_supported) |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2906 | scsi_activate_tcq(sdev, vport->cfg_lun_queue_depth); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2907 | else |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2908 | scsi_deactivate_tcq(sdev, vport->cfg_lun_queue_depth); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2909 | |
| 2910 | /* |
| 2911 | * Initialize the fc transport attributes for the target |
| 2912 | * containing this scsi device. Also note that the driver's |
| 2913 | * target pointer is stored in the starget_data for the |
| 2914 | * driver's sysfs entry point functions. |
| 2915 | */ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2916 | rport->dev_loss_tmo = vport->cfg_devloss_tmo; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2917 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2918 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
| 2919 | lpfc_sli_poll_fcp_ring(phba); |
| 2920 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 2921 | lpfc_poll_rearm_timer(phba); |
| 2922 | } |
| 2923 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2924 | return 0; |
| 2925 | } |
| 2926 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 2927 | /** |
| 2928 | * lpfc_slave_destroy: slave_destroy entry point of SHT data structure. |
| 2929 | * @sdev: Pointer to scsi_device. |
| 2930 | * |
| 2931 | * This routine sets @sdev hostatdata filed to null. |
| 2932 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2933 | static void |
| 2934 | lpfc_slave_destroy(struct scsi_device *sdev) |
| 2935 | { |
| 2936 | sdev->hostdata = NULL; |
| 2937 | return; |
| 2938 | } |
| 2939 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2940 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2941 | struct scsi_host_template lpfc_template = { |
| 2942 | .module = THIS_MODULE, |
| 2943 | .name = LPFC_DRIVER_NAME, |
| 2944 | .info = lpfc_info, |
| 2945 | .queuecommand = lpfc_queuecommand, |
| 2946 | .eh_abort_handler = lpfc_abort_handler, |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2947 | .eh_device_reset_handler= lpfc_device_reset_handler, |
| 2948 | .eh_bus_reset_handler = lpfc_bus_reset_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2949 | .slave_alloc = lpfc_slave_alloc, |
| 2950 | .slave_configure = lpfc_slave_configure, |
| 2951 | .slave_destroy = lpfc_slave_destroy, |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2952 | .scan_finished = lpfc_scan_finished, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2953 | .this_id = -1, |
James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 2954 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2955 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
| 2956 | .use_clustering = ENABLE_CLUSTERING, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2957 | .shost_attrs = lpfc_hba_attrs, |
James.Smart@Emulex.Com | 564b296 | 2005-06-25 10:34:17 -0400 | [diff] [blame] | 2958 | .max_sectors = 0xFFFF, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2959 | }; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2960 | |
| 2961 | struct scsi_host_template lpfc_vport_template = { |
| 2962 | .module = THIS_MODULE, |
| 2963 | .name = LPFC_DRIVER_NAME, |
| 2964 | .info = lpfc_info, |
| 2965 | .queuecommand = lpfc_queuecommand, |
| 2966 | .eh_abort_handler = lpfc_abort_handler, |
| 2967 | .eh_device_reset_handler= lpfc_device_reset_handler, |
| 2968 | .eh_bus_reset_handler = lpfc_bus_reset_handler, |
| 2969 | .slave_alloc = lpfc_slave_alloc, |
| 2970 | .slave_configure = lpfc_slave_configure, |
| 2971 | .slave_destroy = lpfc_slave_destroy, |
| 2972 | .scan_finished = lpfc_scan_finished, |
| 2973 | .this_id = -1, |
James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 2974 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2975 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
| 2976 | .use_clustering = ENABLE_CLUSTERING, |
| 2977 | .shost_attrs = lpfc_vport_attrs, |
| 2978 | .max_sectors = 0xFFFF, |
| 2979 | }; |