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