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