| 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 | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4 | * Copyright (C) 2004-2012 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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/slab.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 23 | #include <linux/interrupt.h> |
Paul Gortmaker | 0970366 | 2011-05-27 09:37:25 -0400 | [diff] [blame] | 24 | #include <linux/export.h> |
James Smart | a90f568 | 2006-08-17 11:58:04 -0400 | [diff] [blame] | 25 | #include <linux/delay.h> |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 26 | #include <asm/unaligned.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 27 | |
| 28 | #include <scsi/scsi.h> |
| 29 | #include <scsi/scsi_device.h> |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 30 | #include <scsi/scsi_eh.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 31 | #include <scsi/scsi_host.h> |
| 32 | #include <scsi/scsi_tcq.h> |
| 33 | #include <scsi/scsi_transport_fc.h> |
| 34 | |
| 35 | #include "lpfc_version.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 36 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 37 | #include "lpfc_hw.h" |
| 38 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 39 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 40 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 41 | #include "lpfc_disc.h" |
| 42 | #include "lpfc_scsi.h" |
| 43 | #include "lpfc.h" |
| 44 | #include "lpfc_logmsg.h" |
| 45 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 46 | #include "lpfc_vport.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 47 | |
| 48 | #define LPFC_RESET_WAIT 2 |
| 49 | #define LPFC_ABORT_WAIT 2 |
| 50 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 51 | int _dump_buf_done; |
| 52 | |
| 53 | static char *dif_op_str[] = { |
| 54 | "SCSI_PROT_NORMAL", |
| 55 | "SCSI_PROT_READ_INSERT", |
| 56 | "SCSI_PROT_WRITE_STRIP", |
| 57 | "SCSI_PROT_READ_STRIP", |
| 58 | "SCSI_PROT_WRITE_INSERT", |
| 59 | "SCSI_PROT_READ_PASS", |
| 60 | "SCSI_PROT_WRITE_PASS", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 61 | }; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 62 | |
| 63 | struct scsi_dif_tuple { |
| 64 | __be16 guard_tag; /* Checksum */ |
| 65 | __be16 app_tag; /* Opaque storage */ |
| 66 | __be32 ref_tag; /* Target LBA or indirect LBA */ |
| 67 | }; |
| 68 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 69 | static void |
| 70 | lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 71 | static void |
| 72 | lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 73 | |
| 74 | static void |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 75 | lpfc_debug_save_data(struct lpfc_hba *phba, struct scsi_cmnd *cmnd) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 76 | { |
| 77 | void *src, *dst; |
| 78 | struct scatterlist *sgde = scsi_sglist(cmnd); |
| 79 | |
| 80 | if (!_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 81 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 82 | "9050 BLKGRD: ERROR %s _dump_buf_data is NULL\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 83 | __func__); |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | |
| 88 | if (!sgde) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 89 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 90 | "9051 BLKGRD: ERROR: data scatterlist is null\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 91 | return; |
| 92 | } |
| 93 | |
| 94 | dst = (void *) _dump_buf_data; |
| 95 | while (sgde) { |
| 96 | src = sg_virt(sgde); |
| 97 | memcpy(dst, src, sgde->length); |
| 98 | dst += sgde->length; |
| 99 | sgde = sg_next(sgde); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | static void |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 104 | lpfc_debug_save_dif(struct lpfc_hba *phba, struct scsi_cmnd *cmnd) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 105 | { |
| 106 | void *src, *dst; |
| 107 | struct scatterlist *sgde = scsi_prot_sglist(cmnd); |
| 108 | |
| 109 | if (!_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 110 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 111 | "9052 BLKGRD: ERROR %s _dump_buf_data is NULL\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 112 | __func__); |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | if (!sgde) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 117 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 118 | "9053 BLKGRD: ERROR: prot scatterlist is null\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 119 | return; |
| 120 | } |
| 121 | |
| 122 | dst = _dump_buf_dif; |
| 123 | while (sgde) { |
| 124 | src = sg_virt(sgde); |
| 125 | memcpy(dst, src, sgde->length); |
| 126 | dst += sgde->length; |
| 127 | sgde = sg_next(sgde); |
| 128 | } |
| 129 | } |
| 130 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 131 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 132 | * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge. |
| 133 | * @phba: Pointer to HBA object. |
| 134 | * @lpfc_cmd: lpfc scsi command object pointer. |
| 135 | * |
| 136 | * This function is called from the lpfc_prep_task_mgmt_cmd function to |
| 137 | * set the last bit in the response sge entry. |
| 138 | **/ |
| 139 | static void |
| 140 | lpfc_sli4_set_rsp_sgl_last(struct lpfc_hba *phba, |
| 141 | struct lpfc_scsi_buf *lpfc_cmd) |
| 142 | { |
| 143 | struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 144 | if (sgl) { |
| 145 | sgl += 1; |
| 146 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 147 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 148 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 153 | * lpfc_update_stats - Update statistical data for the command completion |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 154 | * @phba: Pointer to HBA object. |
| 155 | * @lpfc_cmd: lpfc scsi command object pointer. |
| 156 | * |
| 157 | * This function is called when there is a command completion and this |
| 158 | * function updates the statistical data for the command completion. |
| 159 | **/ |
| 160 | static void |
| 161 | lpfc_update_stats(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 162 | { |
| 163 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| 164 | struct lpfc_nodelist *pnode = rdata->pnode; |
| 165 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 166 | unsigned long flags; |
| 167 | struct Scsi_Host *shost = cmd->device->host; |
| 168 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 169 | unsigned long latency; |
| 170 | int i; |
| 171 | |
| 172 | if (cmd->result) |
| 173 | return; |
| 174 | |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 175 | latency = jiffies_to_msecs((long)jiffies - (long)lpfc_cmd->start_time); |
| 176 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 177 | spin_lock_irqsave(shost->host_lock, flags); |
| 178 | if (!vport->stat_data_enabled || |
| 179 | vport->stat_data_blocked || |
James Smart | 5989b8d | 2010-10-22 11:06:56 -0400 | [diff] [blame] | 180 | !pnode || |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 181 | !pnode->lat_data || |
| 182 | (phba->bucket_type == LPFC_NO_BUCKET)) { |
| 183 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 184 | return; |
| 185 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 186 | |
| 187 | if (phba->bucket_type == LPFC_LINEAR_BUCKET) { |
| 188 | i = (latency + phba->bucket_step - 1 - phba->bucket_base)/ |
| 189 | phba->bucket_step; |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 190 | /* check array subscript bounds */ |
| 191 | if (i < 0) |
| 192 | i = 0; |
| 193 | else if (i >= LPFC_MAX_BUCKET_COUNT) |
| 194 | i = LPFC_MAX_BUCKET_COUNT - 1; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 195 | } else { |
| 196 | for (i = 0; i < LPFC_MAX_BUCKET_COUNT-1; i++) |
| 197 | if (latency <= (phba->bucket_base + |
| 198 | ((1<<i)*phba->bucket_step))) |
| 199 | break; |
| 200 | } |
| 201 | |
| 202 | pnode->lat_data[i].cmd_count++; |
| 203 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 204 | } |
| 205 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 206 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 207 | * lpfc_send_sdev_queuedepth_change_event - Posts a queuedepth change event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 208 | * @phba: Pointer to HBA context object. |
| 209 | * @vport: Pointer to vport object. |
| 210 | * @ndlp: Pointer to FC node associated with the target. |
| 211 | * @lun: Lun number of the scsi device. |
| 212 | * @old_val: Old value of the queue depth. |
| 213 | * @new_val: New value of the queue depth. |
| 214 | * |
| 215 | * This function sends an event to the mgmt application indicating |
| 216 | * there is a change in the scsi device queue depth. |
| 217 | **/ |
| 218 | static void |
| 219 | lpfc_send_sdev_queuedepth_change_event(struct lpfc_hba *phba, |
| 220 | struct lpfc_vport *vport, |
| 221 | struct lpfc_nodelist *ndlp, |
| 222 | uint32_t lun, |
| 223 | uint32_t old_val, |
| 224 | uint32_t new_val) |
| 225 | { |
| 226 | struct lpfc_fast_path_event *fast_path_evt; |
| 227 | unsigned long flags; |
| 228 | |
| 229 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 230 | if (!fast_path_evt) |
| 231 | return; |
| 232 | |
| 233 | fast_path_evt->un.queue_depth_evt.scsi_event.event_type = |
| 234 | FC_REG_SCSI_EVENT; |
| 235 | fast_path_evt->un.queue_depth_evt.scsi_event.subcategory = |
| 236 | LPFC_EVENT_VARQUEDEPTH; |
| 237 | |
| 238 | /* Report all luns with change in queue depth */ |
| 239 | fast_path_evt->un.queue_depth_evt.scsi_event.lun = lun; |
| 240 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
| 241 | memcpy(&fast_path_evt->un.queue_depth_evt.scsi_event.wwpn, |
| 242 | &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 243 | memcpy(&fast_path_evt->un.queue_depth_evt.scsi_event.wwnn, |
| 244 | &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 245 | } |
| 246 | |
| 247 | fast_path_evt->un.queue_depth_evt.oldval = old_val; |
| 248 | fast_path_evt->un.queue_depth_evt.newval = new_val; |
| 249 | fast_path_evt->vport = vport; |
| 250 | |
| 251 | fast_path_evt->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT; |
| 252 | spin_lock_irqsave(&phba->hbalock, flags); |
| 253 | list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list); |
| 254 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 255 | lpfc_worker_wake_up(phba); |
| 256 | |
| 257 | return; |
| 258 | } |
| 259 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 260 | /** |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 261 | * lpfc_change_queue_depth - Alter scsi device queue depth |
| 262 | * @sdev: Pointer the scsi device on which to change the queue depth. |
| 263 | * @qdepth: New queue depth to set the sdev to. |
| 264 | * @reason: The reason for the queue depth change. |
| 265 | * |
| 266 | * This function is called by the midlayer and the LLD to alter the queue |
| 267 | * depth for a scsi device. This function sets the queue depth to the new |
| 268 | * value and sends an event out to log the queue depth change. |
| 269 | **/ |
| 270 | int |
| 271 | lpfc_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason) |
| 272 | { |
| 273 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 274 | struct lpfc_hba *phba = vport->phba; |
| 275 | struct lpfc_rport_data *rdata; |
| 276 | unsigned long new_queue_depth, old_queue_depth; |
| 277 | |
| 278 | old_queue_depth = sdev->queue_depth; |
| 279 | scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); |
| 280 | new_queue_depth = sdev->queue_depth; |
| 281 | rdata = sdev->hostdata; |
| 282 | if (rdata) |
| 283 | lpfc_send_sdev_queuedepth_change_event(phba, vport, |
| 284 | rdata->pnode, sdev->lun, |
| 285 | old_queue_depth, |
| 286 | new_queue_depth); |
| 287 | return sdev->queue_depth; |
| 288 | } |
| 289 | |
| 290 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 291 | * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 292 | * @phba: The Hba for which this call is being executed. |
| 293 | * |
| 294 | * This routine is called when there is resource error in driver or firmware. |
| 295 | * This routine posts WORKER_RAMP_DOWN_QUEUE event for @phba. This routine |
| 296 | * posts at most 1 event each second. This routine wakes up worker thread of |
| 297 | * @phba to process WORKER_RAM_DOWN_EVENT event. |
| 298 | * |
| 299 | * This routine should be called with no lock held. |
| 300 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 301 | void |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 302 | lpfc_rampdown_queue_depth(struct lpfc_hba *phba) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 303 | { |
| 304 | unsigned long flags; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 305 | uint32_t evt_posted; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 306 | |
| 307 | spin_lock_irqsave(&phba->hbalock, flags); |
| 308 | atomic_inc(&phba->num_rsrc_err); |
| 309 | phba->last_rsrc_error_time = jiffies; |
| 310 | |
| 311 | if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) { |
| 312 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 313 | return; |
| 314 | } |
| 315 | |
| 316 | phba->last_ramp_down_time = jiffies; |
| 317 | |
| 318 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 319 | |
| 320 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 321 | evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE; |
| 322 | if (!evt_posted) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 323 | phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 324 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
| 325 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 326 | if (!evt_posted) |
| 327 | lpfc_worker_wake_up(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 328 | return; |
| 329 | } |
| 330 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 331 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 332 | * lpfc_rampup_queue_depth - Post RAMP_UP_QUEUE event for worker thread |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 333 | * @phba: The Hba for which this call is being executed. |
| 334 | * |
| 335 | * This routine post WORKER_RAMP_UP_QUEUE event for @phba vport. This routine |
| 336 | * post at most 1 event every 5 minute after last_ramp_up_time or |
| 337 | * last_rsrc_error_time. This routine wakes up worker thread of @phba |
| 338 | * to process WORKER_RAM_DOWN_EVENT event. |
| 339 | * |
| 340 | * This routine should be called with no lock held. |
| 341 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 342 | static inline void |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 343 | lpfc_rampup_queue_depth(struct lpfc_vport *vport, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 344 | uint32_t queue_depth) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 345 | { |
| 346 | unsigned long flags; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 347 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 348 | uint32_t evt_posted; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 349 | atomic_inc(&phba->num_cmd_success); |
| 350 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 351 | if (vport->cfg_lun_queue_depth <= queue_depth) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 352 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 353 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 354 | if (time_before(jiffies, |
| 355 | phba->last_ramp_up_time + QUEUE_RAMP_UP_INTERVAL) || |
| 356 | time_before(jiffies, |
| 357 | phba->last_rsrc_error_time + QUEUE_RAMP_UP_INTERVAL)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 358 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 359 | return; |
| 360 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 361 | phba->last_ramp_up_time = jiffies; |
| 362 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 363 | |
| 364 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 365 | evt_posted = phba->pport->work_port_events & WORKER_RAMP_UP_QUEUE; |
| 366 | if (!evt_posted) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 367 | phba->pport->work_port_events |= WORKER_RAMP_UP_QUEUE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 368 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
| 369 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 370 | if (!evt_posted) |
| 371 | lpfc_worker_wake_up(phba); |
| 372 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 373 | } |
| 374 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 375 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 376 | * lpfc_ramp_down_queue_handler - WORKER_RAMP_DOWN_QUEUE event handler |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 377 | * @phba: The Hba for which this call is being executed. |
| 378 | * |
| 379 | * This routine is called to process WORKER_RAMP_DOWN_QUEUE event for worker |
| 380 | * thread.This routine reduces queue depth for all scsi device on each vport |
| 381 | * associated with @phba. |
| 382 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 383 | void |
| 384 | lpfc_ramp_down_queue_handler(struct lpfc_hba *phba) |
| 385 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 386 | struct lpfc_vport **vports; |
| 387 | struct Scsi_Host *shost; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 388 | struct scsi_device *sdev; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 389 | unsigned long new_queue_depth; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 390 | unsigned long num_rsrc_err, num_cmd_success; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 391 | int i; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 392 | |
| 393 | num_rsrc_err = atomic_read(&phba->num_rsrc_err); |
| 394 | num_cmd_success = atomic_read(&phba->num_cmd_success); |
| 395 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 396 | vports = lpfc_create_vport_work_array(phba); |
| 397 | if (vports != NULL) |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 398 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 399 | shost = lpfc_shost_from_vport(vports[i]); |
| 400 | shost_for_each_device(sdev, shost) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 401 | new_queue_depth = |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 402 | sdev->queue_depth * num_rsrc_err / |
| 403 | (num_rsrc_err + num_cmd_success); |
| 404 | if (!new_queue_depth) |
| 405 | new_queue_depth = sdev->queue_depth - 1; |
| 406 | else |
| 407 | new_queue_depth = sdev->queue_depth - |
| 408 | new_queue_depth; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 409 | lpfc_change_queue_depth(sdev, new_queue_depth, |
| 410 | SCSI_QDEPTH_DEFAULT); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 411 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 412 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 413 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 414 | atomic_set(&phba->num_rsrc_err, 0); |
| 415 | atomic_set(&phba->num_cmd_success, 0); |
| 416 | } |
| 417 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 418 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 419 | * lpfc_ramp_up_queue_handler - WORKER_RAMP_UP_QUEUE event handler |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 420 | * @phba: The Hba for which this call is being executed. |
| 421 | * |
| 422 | * This routine is called to process WORKER_RAMP_UP_QUEUE event for worker |
| 423 | * thread.This routine increases queue depth for all scsi device on each vport |
| 424 | * associated with @phba by 1. This routine also sets @phba num_rsrc_err and |
| 425 | * num_cmd_success to zero. |
| 426 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 427 | void |
| 428 | lpfc_ramp_up_queue_handler(struct lpfc_hba *phba) |
| 429 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 430 | struct lpfc_vport **vports; |
| 431 | struct Scsi_Host *shost; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 432 | struct scsi_device *sdev; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 433 | int i; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 434 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 435 | vports = lpfc_create_vport_work_array(phba); |
| 436 | if (vports != NULL) |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 437 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 438 | shost = lpfc_shost_from_vport(vports[i]); |
| 439 | shost_for_each_device(sdev, shost) { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 440 | if (vports[i]->cfg_lun_queue_depth <= |
| 441 | sdev->queue_depth) |
| 442 | continue; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 443 | lpfc_change_queue_depth(sdev, |
| 444 | sdev->queue_depth+1, |
| 445 | SCSI_QDEPTH_RAMP_UP); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 446 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 447 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 448 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 449 | atomic_set(&phba->num_rsrc_err, 0); |
| 450 | atomic_set(&phba->num_cmd_success, 0); |
| 451 | } |
| 452 | |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 453 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 454 | * lpfc_scsi_dev_block - set all scsi hosts to block state |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 455 | * @phba: Pointer to HBA context object. |
| 456 | * |
| 457 | * This function walks vport list and set each SCSI host to block state |
| 458 | * by invoking fc_remote_port_delete() routine. This function is invoked |
| 459 | * with EEH when device's PCI slot has been permanently disabled. |
| 460 | **/ |
| 461 | void |
| 462 | lpfc_scsi_dev_block(struct lpfc_hba *phba) |
| 463 | { |
| 464 | struct lpfc_vport **vports; |
| 465 | struct Scsi_Host *shost; |
| 466 | struct scsi_device *sdev; |
| 467 | struct fc_rport *rport; |
| 468 | int i; |
| 469 | |
| 470 | vports = lpfc_create_vport_work_array(phba); |
| 471 | if (vports != NULL) |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 472 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 473 | shost = lpfc_shost_from_vport(vports[i]); |
| 474 | shost_for_each_device(sdev, shost) { |
| 475 | rport = starget_to_rport(scsi_target(sdev)); |
| 476 | fc_remote_port_delete(rport); |
| 477 | } |
| 478 | } |
| 479 | lpfc_destroy_vport_work_array(phba, vports); |
| 480 | } |
| 481 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 482 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 483 | * 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] | 484 | * @vport: The virtual port for which this call being executed. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 485 | * @num_to_allocate: The requested number of buffers to allocate. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 486 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 487 | * This routine allocates a scsi buffer for device with SLI-3 interface spec, |
| 488 | * the scsi buffer contains all the necessary information needed to initiate |
| 489 | * a SCSI I/O. The non-DMAable buffer region contains information to build |
| 490 | * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP, |
| 491 | * and the initial BPL. In addition to allocating memory, the FCP CMND and |
| 492 | * 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] | 493 | * |
| 494 | * Return codes: |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 495 | * int - number of scsi buffers that were allocated. |
| 496 | * 0 = failure, less than num_to_alloc is a partial failure. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 497 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 498 | static int |
| 499 | lpfc_new_scsi_buf_s3(struct lpfc_vport *vport, int num_to_alloc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 500 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 501 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 502 | struct lpfc_scsi_buf *psb; |
| 503 | struct ulp_bde64 *bpl; |
| 504 | IOCB_t *iocb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 505 | dma_addr_t pdma_phys_fcp_cmd; |
| 506 | dma_addr_t pdma_phys_fcp_rsp; |
| 507 | dma_addr_t pdma_phys_bpl; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 508 | uint16_t iotag; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 509 | int bcnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 510 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 511 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
| 512 | psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL); |
| 513 | if (!psb) |
| 514 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 515 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 516 | /* |
| 517 | * Get memory from the pci pool to map the virt space to pci |
| 518 | * bus space for an I/O. The DMA buffer includes space for the |
| 519 | * struct fcp_cmnd, struct fcp_rsp and the number of bde's |
| 520 | * necessary to support the sg_tablesize. |
| 521 | */ |
| 522 | psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool, |
| 523 | GFP_KERNEL, &psb->dma_handle); |
| 524 | if (!psb->data) { |
| 525 | kfree(psb); |
| 526 | break; |
| 527 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 528 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 529 | /* Initialize virtual ptrs to dma_buf region. */ |
| 530 | memset(psb->data, 0, phba->cfg_sg_dma_buf_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 531 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 532 | /* Allocate iotag for psb->cur_iocbq. */ |
| 533 | iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq); |
| 534 | if (iotag == 0) { |
| 535 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, |
| 536 | psb->data, psb->dma_handle); |
| 537 | kfree(psb); |
| 538 | break; |
| 539 | } |
| 540 | psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 541 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 542 | psb->fcp_cmnd = psb->data; |
| 543 | psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd); |
| 544 | psb->fcp_bpl = psb->data + sizeof(struct fcp_cmnd) + |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 545 | sizeof(struct fcp_rsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 546 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 547 | /* Initialize local short-hand pointers. */ |
| 548 | bpl = psb->fcp_bpl; |
| 549 | pdma_phys_fcp_cmd = psb->dma_handle; |
| 550 | pdma_phys_fcp_rsp = psb->dma_handle + sizeof(struct fcp_cmnd); |
| 551 | pdma_phys_bpl = psb->dma_handle + sizeof(struct fcp_cmnd) + |
| 552 | sizeof(struct fcp_rsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 553 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 554 | /* |
| 555 | * The first two bdes are the FCP_CMD and FCP_RSP. The balance |
| 556 | * are sg list bdes. Initialize the first two and leave the |
| 557 | * rest for queuecommand. |
| 558 | */ |
| 559 | bpl[0].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd)); |
| 560 | bpl[0].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd)); |
| 561 | bpl[0].tus.f.bdeSize = sizeof(struct fcp_cmnd); |
| 562 | bpl[0].tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 563 | bpl[0].tus.w = le32_to_cpu(bpl[0].tus.w); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 564 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 565 | /* Setup the physical region for the FCP RSP */ |
| 566 | bpl[1].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp)); |
| 567 | bpl[1].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp)); |
| 568 | bpl[1].tus.f.bdeSize = sizeof(struct fcp_rsp); |
| 569 | bpl[1].tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 570 | bpl[1].tus.w = le32_to_cpu(bpl[1].tus.w); |
| 571 | |
| 572 | /* |
| 573 | * Since the IOCB for the FCP I/O is built into this |
| 574 | * lpfc_scsi_buf, initialize it with all known data now. |
| 575 | */ |
| 576 | iocb = &psb->cur_iocbq.iocb; |
| 577 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; |
| 578 | if ((phba->sli_rev == 3) && |
| 579 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) { |
| 580 | /* fill in immediate fcp command BDE */ |
| 581 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_IMMED; |
| 582 | iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); |
| 583 | iocb->un.fcpi64.bdl.addrLow = offsetof(IOCB_t, |
| 584 | unsli3.fcp_ext.icd); |
| 585 | iocb->un.fcpi64.bdl.addrHigh = 0; |
| 586 | iocb->ulpBdeCount = 0; |
| 587 | iocb->ulpLe = 0; |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 588 | /* fill in response BDE */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 589 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeFlags = |
| 590 | BUFF_TYPE_BDE_64; |
| 591 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeSize = |
| 592 | sizeof(struct fcp_rsp); |
| 593 | iocb->unsli3.fcp_ext.rbde.addrLow = |
| 594 | putPaddrLow(pdma_phys_fcp_rsp); |
| 595 | iocb->unsli3.fcp_ext.rbde.addrHigh = |
| 596 | putPaddrHigh(pdma_phys_fcp_rsp); |
| 597 | } else { |
| 598 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
| 599 | iocb->un.fcpi64.bdl.bdeSize = |
| 600 | (2 * sizeof(struct ulp_bde64)); |
| 601 | iocb->un.fcpi64.bdl.addrLow = |
| 602 | putPaddrLow(pdma_phys_bpl); |
| 603 | iocb->un.fcpi64.bdl.addrHigh = |
| 604 | putPaddrHigh(pdma_phys_bpl); |
| 605 | iocb->ulpBdeCount = 1; |
| 606 | iocb->ulpLe = 1; |
| 607 | } |
| 608 | iocb->ulpClass = CLASS3; |
| 609 | psb->status = IOSTAT_SUCCESS; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 610 | /* Put it back into the SCSI buffer list */ |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 611 | psb->cur_iocbq.context1 = psb; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 612 | lpfc_release_scsi_buf_s3(phba, psb); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 613 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 614 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 615 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 616 | return bcnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 617 | } |
| 618 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 619 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 620 | * lpfc_sli4_vport_delete_fcp_xri_aborted -Remove all ndlp references for vport |
| 621 | * @vport: pointer to lpfc vport data structure. |
| 622 | * |
| 623 | * This routine is invoked by the vport cleanup for deletions and the cleanup |
| 624 | * for an ndlp on removal. |
| 625 | **/ |
| 626 | void |
| 627 | lpfc_sli4_vport_delete_fcp_xri_aborted(struct lpfc_vport *vport) |
| 628 | { |
| 629 | struct lpfc_hba *phba = vport->phba; |
| 630 | struct lpfc_scsi_buf *psb, *next_psb; |
| 631 | unsigned long iflag = 0; |
| 632 | |
| 633 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 634 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 635 | list_for_each_entry_safe(psb, next_psb, |
| 636 | &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) { |
| 637 | if (psb->rdata && psb->rdata->pnode |
| 638 | && psb->rdata->pnode->vport == vport) |
| 639 | psb->rdata = NULL; |
| 640 | } |
| 641 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 642 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 643 | } |
| 644 | |
| 645 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 646 | * lpfc_sli4_fcp_xri_aborted - Fast-path process of fcp xri abort |
| 647 | * @phba: pointer to lpfc hba data structure. |
| 648 | * @axri: pointer to the fcp xri abort wcqe structure. |
| 649 | * |
| 650 | * This routine is invoked by the worker thread to process a SLI4 fast-path |
| 651 | * FCP aborted xri. |
| 652 | **/ |
| 653 | void |
| 654 | lpfc_sli4_fcp_xri_aborted(struct lpfc_hba *phba, |
| 655 | struct sli4_wcqe_xri_aborted *axri) |
| 656 | { |
| 657 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 658 | uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 659 | struct lpfc_scsi_buf *psb, *next_psb; |
| 660 | unsigned long iflag = 0; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 661 | struct lpfc_iocbq *iocbq; |
| 662 | int i; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 663 | struct lpfc_nodelist *ndlp; |
| 664 | int rrq_empty = 0; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 665 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 666 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 667 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 668 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 669 | list_for_each_entry_safe(psb, next_psb, |
| 670 | &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) { |
| 671 | if (psb->cur_iocbq.sli4_xritag == xri) { |
| 672 | list_del(&psb->list); |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 673 | psb->exch_busy = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 674 | psb->status = IOSTAT_SUCCESS; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 675 | spin_unlock( |
| 676 | &phba->sli4_hba.abts_scsi_buf_list_lock); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 677 | if (psb->rdata && psb->rdata->pnode) |
| 678 | ndlp = psb->rdata->pnode; |
| 679 | else |
| 680 | ndlp = NULL; |
| 681 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 682 | rrq_empty = list_empty(&phba->active_rrq_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 683 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 684 | if (ndlp) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 685 | lpfc_set_rrq_active(phba, ndlp, xri, rxid, 1); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 686 | lpfc_sli4_abts_err_handler(phba, ndlp, axri); |
| 687 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 688 | lpfc_release_scsi_buf_s4(phba, psb); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 689 | if (rrq_empty) |
| 690 | lpfc_worker_wake_up(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 691 | return; |
| 692 | } |
| 693 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 694 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 695 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 696 | iocbq = phba->sli.iocbq_lookup[i]; |
| 697 | |
| 698 | if (!(iocbq->iocb_flag & LPFC_IO_FCP) || |
| 699 | (iocbq->iocb_flag & LPFC_IO_LIBDFC)) |
| 700 | continue; |
| 701 | if (iocbq->sli4_xritag != xri) |
| 702 | continue; |
| 703 | psb = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
| 704 | psb->exch_busy = 0; |
| 705 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 706 | if (pring->txq_cnt) |
| 707 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 708 | return; |
| 709 | |
| 710 | } |
| 711 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | /** |
| 715 | * lpfc_sli4_repost_scsi_sgl_list - Repsot the Scsi buffers sgl pages as block |
| 716 | * @phba: pointer to lpfc hba data structure. |
| 717 | * |
| 718 | * This routine walks the list of scsi buffers that have been allocated and |
| 719 | * repost them to the HBA by using SGL block post. This is needed after a |
| 720 | * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine |
| 721 | * is responsible for moving all scsi buffers on the lpfc_abts_scsi_sgl_list |
| 722 | * to the lpfc_scsi_buf_list. If the repost fails, reject all scsi buffers. |
| 723 | * |
| 724 | * Returns: 0 = success, non-zero failure. |
| 725 | **/ |
| 726 | int |
| 727 | lpfc_sli4_repost_scsi_sgl_list(struct lpfc_hba *phba) |
| 728 | { |
| 729 | struct lpfc_scsi_buf *psb; |
| 730 | int index, status, bcnt = 0, rcnt = 0, rc = 0; |
| 731 | LIST_HEAD(sblist); |
| 732 | |
| 733 | for (index = 0; index < phba->sli4_hba.scsi_xri_cnt; index++) { |
| 734 | psb = phba->sli4_hba.lpfc_scsi_psb_array[index]; |
| 735 | if (psb) { |
| 736 | /* Remove from SCSI buffer list */ |
| 737 | list_del(&psb->list); |
| 738 | /* Add it to a local SCSI buffer list */ |
| 739 | list_add_tail(&psb->list, &sblist); |
| 740 | if (++rcnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 741 | bcnt = rcnt; |
| 742 | rcnt = 0; |
| 743 | } |
| 744 | } else |
| 745 | /* A hole present in the XRI array, need to skip */ |
| 746 | bcnt = rcnt; |
| 747 | |
| 748 | if (index == phba->sli4_hba.scsi_xri_cnt - 1) |
| 749 | /* End of XRI array for SCSI buffer, complete */ |
| 750 | bcnt = rcnt; |
| 751 | |
| 752 | /* Continue until collect up to a nembed page worth of sgls */ |
| 753 | if (bcnt == 0) |
| 754 | continue; |
| 755 | /* Now, post the SCSI buffer list sgls as a block */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 756 | if (!phba->sli4_hba.extents_in_use) |
| 757 | status = lpfc_sli4_post_scsi_sgl_block(phba, |
| 758 | &sblist, |
| 759 | bcnt); |
| 760 | else |
| 761 | status = lpfc_sli4_post_scsi_sgl_blk_ext(phba, |
| 762 | &sblist, |
| 763 | bcnt); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 764 | /* Reset SCSI buffer count for next round of posting */ |
| 765 | bcnt = 0; |
| 766 | while (!list_empty(&sblist)) { |
| 767 | list_remove_head(&sblist, psb, struct lpfc_scsi_buf, |
| 768 | list); |
| 769 | if (status) { |
| 770 | /* Put this back on the abort scsi list */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 771 | psb->exch_busy = 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 772 | rc++; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 773 | } else { |
| 774 | psb->exch_busy = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 775 | psb->status = IOSTAT_SUCCESS; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 776 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 777 | /* Put it back into the SCSI buffer list */ |
| 778 | lpfc_release_scsi_buf_s4(phba, psb); |
| 779 | } |
| 780 | } |
| 781 | return rc; |
| 782 | } |
| 783 | |
| 784 | /** |
| 785 | * lpfc_new_scsi_buf_s4 - Scsi buffer allocator for HBA with SLI4 IF spec |
| 786 | * @vport: The virtual port for which this call being executed. |
| 787 | * @num_to_allocate: The requested number of buffers to allocate. |
| 788 | * |
| 789 | * This routine allocates a scsi buffer for device with SLI-4 interface spec, |
| 790 | * the scsi buffer contains all the necessary information needed to initiate |
| 791 | * a SCSI I/O. |
| 792 | * |
| 793 | * Return codes: |
| 794 | * int - number of scsi buffers that were allocated. |
| 795 | * 0 = failure, less than num_to_alloc is a partial failure. |
| 796 | **/ |
| 797 | static int |
| 798 | lpfc_new_scsi_buf_s4(struct lpfc_vport *vport, int num_to_alloc) |
| 799 | { |
| 800 | struct lpfc_hba *phba = vport->phba; |
| 801 | struct lpfc_scsi_buf *psb; |
| 802 | struct sli4_sge *sgl; |
| 803 | IOCB_t *iocb; |
| 804 | dma_addr_t pdma_phys_fcp_cmd; |
| 805 | dma_addr_t pdma_phys_fcp_rsp; |
| 806 | dma_addr_t pdma_phys_bpl, pdma_phys_bpl1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 807 | uint16_t iotag, last_xritag = NO_XRI, lxri = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 808 | int status = 0, index; |
| 809 | int bcnt; |
| 810 | int non_sequential_xri = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 811 | LIST_HEAD(sblist); |
| 812 | |
| 813 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
| 814 | psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL); |
| 815 | if (!psb) |
| 816 | break; |
| 817 | |
| 818 | /* |
| 819 | * Get memory from the pci pool to map the virt space to pci bus |
| 820 | * space for an I/O. The DMA buffer includes space for the |
| 821 | * struct fcp_cmnd, struct fcp_rsp and the number of bde's |
| 822 | * necessary to support the sg_tablesize. |
| 823 | */ |
| 824 | psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool, |
| 825 | GFP_KERNEL, &psb->dma_handle); |
| 826 | if (!psb->data) { |
| 827 | kfree(psb); |
| 828 | break; |
| 829 | } |
| 830 | |
| 831 | /* Initialize virtual ptrs to dma_buf region. */ |
| 832 | memset(psb->data, 0, phba->cfg_sg_dma_buf_size); |
| 833 | |
| 834 | /* Allocate iotag for psb->cur_iocbq. */ |
| 835 | iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq); |
| 836 | if (iotag == 0) { |
James Smart | b92938b | 2010-06-07 15:24:12 -0400 | [diff] [blame] | 837 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, |
| 838 | psb->data, psb->dma_handle); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 839 | kfree(psb); |
| 840 | break; |
| 841 | } |
| 842 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 843 | lxri = lpfc_sli4_next_xritag(phba); |
| 844 | if (lxri == NO_XRI) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 845 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, |
| 846 | psb->data, psb->dma_handle); |
| 847 | kfree(psb); |
| 848 | break; |
| 849 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 850 | psb->cur_iocbq.sli4_lxritag = lxri; |
| 851 | psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 852 | if (last_xritag != NO_XRI |
| 853 | && psb->cur_iocbq.sli4_xritag != (last_xritag+1)) { |
| 854 | non_sequential_xri = 1; |
| 855 | } else |
| 856 | list_add_tail(&psb->list, &sblist); |
| 857 | last_xritag = psb->cur_iocbq.sli4_xritag; |
| 858 | |
| 859 | index = phba->sli4_hba.scsi_xri_cnt++; |
| 860 | psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP; |
| 861 | |
| 862 | psb->fcp_bpl = psb->data; |
| 863 | psb->fcp_cmnd = (psb->data + phba->cfg_sg_dma_buf_size) |
| 864 | - (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); |
| 865 | psb->fcp_rsp = (struct fcp_rsp *)((uint8_t *)psb->fcp_cmnd + |
| 866 | sizeof(struct fcp_cmnd)); |
| 867 | |
| 868 | /* Initialize local short-hand pointers. */ |
| 869 | sgl = (struct sli4_sge *)psb->fcp_bpl; |
| 870 | pdma_phys_bpl = psb->dma_handle; |
| 871 | pdma_phys_fcp_cmd = |
| 872 | (psb->dma_handle + phba->cfg_sg_dma_buf_size) |
| 873 | - (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); |
| 874 | pdma_phys_fcp_rsp = pdma_phys_fcp_cmd + sizeof(struct fcp_cmnd); |
| 875 | |
| 876 | /* |
| 877 | * The first two bdes are the FCP_CMD and FCP_RSP. The balance |
| 878 | * are sg list bdes. Initialize the first two and leave the |
| 879 | * rest for queuecommand. |
| 880 | */ |
| 881 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd)); |
| 882 | sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd)); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 883 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 884 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 885 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 886 | sgl->sge_len = cpu_to_le32(sizeof(struct fcp_cmnd)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 887 | sgl++; |
| 888 | |
| 889 | /* Setup the physical region for the FCP RSP */ |
| 890 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp)); |
| 891 | sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp)); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 892 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 893 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 894 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 895 | sgl->sge_len = cpu_to_le32(sizeof(struct fcp_rsp)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 896 | |
| 897 | /* |
| 898 | * Since the IOCB for the FCP I/O is built into this |
| 899 | * lpfc_scsi_buf, initialize it with all known data now. |
| 900 | */ |
| 901 | iocb = &psb->cur_iocbq.iocb; |
| 902 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; |
| 903 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_64; |
| 904 | /* setting the BLP size to 2 * sizeof BDE may not be correct. |
| 905 | * We are setting the bpl to point to out sgl. An sgl's |
| 906 | * entries are 16 bytes, a bpl entries are 12 bytes. |
| 907 | */ |
| 908 | iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); |
| 909 | iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys_fcp_cmd); |
| 910 | iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys_fcp_cmd); |
| 911 | iocb->ulpBdeCount = 1; |
| 912 | iocb->ulpLe = 1; |
| 913 | iocb->ulpClass = CLASS3; |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 914 | psb->cur_iocbq.context1 = psb; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 915 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
| 916 | pdma_phys_bpl1 = pdma_phys_bpl + SGL_PAGE_SIZE; |
| 917 | else |
| 918 | pdma_phys_bpl1 = 0; |
| 919 | psb->dma_phys_bpl = pdma_phys_bpl; |
| 920 | phba->sli4_hba.lpfc_scsi_psb_array[index] = psb; |
| 921 | if (non_sequential_xri) { |
| 922 | status = lpfc_sli4_post_sgl(phba, pdma_phys_bpl, |
| 923 | pdma_phys_bpl1, |
| 924 | psb->cur_iocbq.sli4_xritag); |
| 925 | if (status) { |
| 926 | /* Put this back on the abort scsi list */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 927 | psb->exch_busy = 1; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 928 | } else { |
| 929 | psb->exch_busy = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 930 | psb->status = IOSTAT_SUCCESS; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 931 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 932 | /* Put it back into the SCSI buffer list */ |
| 933 | lpfc_release_scsi_buf_s4(phba, psb); |
| 934 | break; |
| 935 | } |
| 936 | } |
| 937 | if (bcnt) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 938 | if (!phba->sli4_hba.extents_in_use) |
| 939 | status = lpfc_sli4_post_scsi_sgl_block(phba, |
| 940 | &sblist, |
| 941 | bcnt); |
| 942 | else |
| 943 | status = lpfc_sli4_post_scsi_sgl_blk_ext(phba, |
| 944 | &sblist, |
| 945 | bcnt); |
| 946 | |
| 947 | if (status) { |
| 948 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 949 | "3021 SCSI SGL post error %d\n", |
| 950 | status); |
| 951 | bcnt = 0; |
| 952 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 953 | /* Reset SCSI buffer count for next round of posting */ |
| 954 | while (!list_empty(&sblist)) { |
| 955 | list_remove_head(&sblist, psb, struct lpfc_scsi_buf, |
| 956 | list); |
| 957 | if (status) { |
| 958 | /* Put this back on the abort scsi list */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 959 | psb->exch_busy = 1; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 960 | } else { |
| 961 | psb->exch_busy = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 962 | psb->status = IOSTAT_SUCCESS; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 963 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 964 | /* Put it back into the SCSI buffer list */ |
| 965 | lpfc_release_scsi_buf_s4(phba, psb); |
| 966 | } |
| 967 | } |
| 968 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 969 | return bcnt + non_sequential_xri; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 973 | * lpfc_new_scsi_buf - Wrapper funciton for scsi buffer allocator |
| 974 | * @vport: The virtual port for which this call being executed. |
| 975 | * @num_to_allocate: The requested number of buffers to allocate. |
| 976 | * |
| 977 | * This routine wraps the actual SCSI buffer allocator function pointer from |
| 978 | * the lpfc_hba struct. |
| 979 | * |
| 980 | * Return codes: |
| 981 | * int - number of scsi buffers that were allocated. |
| 982 | * 0 = failure, less than num_to_alloc is a partial failure. |
| 983 | **/ |
| 984 | static inline int |
| 985 | lpfc_new_scsi_buf(struct lpfc_vport *vport, int num_to_alloc) |
| 986 | { |
| 987 | return vport->phba->lpfc_new_scsi_buf(vport, num_to_alloc); |
| 988 | } |
| 989 | |
| 990 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 991 | * lpfc_get_scsi_buf_s3 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 992 | * @phba: The HBA for which this call is being executed. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 993 | * |
| 994 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list |
| 995 | * and returns to caller. |
| 996 | * |
| 997 | * Return codes: |
| 998 | * NULL - Error |
| 999 | * Pointer to lpfc_scsi_buf - Success |
| 1000 | **/ |
Adrian Bunk | 455c53e | 2006-01-06 20:21:28 +0100 | [diff] [blame] | 1001 | static struct lpfc_scsi_buf* |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1002 | lpfc_get_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1003 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1004 | struct lpfc_scsi_buf * lpfc_cmd = NULL; |
| 1005 | 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] | 1006 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1007 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1008 | spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1009 | 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] | 1010 | if (lpfc_cmd) { |
| 1011 | lpfc_cmd->seg_cnt = 0; |
| 1012 | lpfc_cmd->nonsg_phys = 0; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1013 | lpfc_cmd->prot_seg_cnt = 0; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 1014 | } |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1015 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1016 | return lpfc_cmd; |
| 1017 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1018 | /** |
| 1019 | * lpfc_get_scsi_buf_s4 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA |
| 1020 | * @phba: The HBA for which this call is being executed. |
| 1021 | * |
| 1022 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list |
| 1023 | * and returns to caller. |
| 1024 | * |
| 1025 | * Return codes: |
| 1026 | * NULL - Error |
| 1027 | * Pointer to lpfc_scsi_buf - Success |
| 1028 | **/ |
| 1029 | static struct lpfc_scsi_buf* |
| 1030 | lpfc_get_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| 1031 | { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1032 | struct lpfc_scsi_buf *lpfc_cmd ; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1033 | unsigned long iflag = 0; |
| 1034 | int found = 0; |
| 1035 | |
| 1036 | spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1037 | list_for_each_entry(lpfc_cmd, &phba->lpfc_scsi_buf_list, |
| 1038 | list) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1039 | if (lpfc_test_rrq_active(phba, ndlp, |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1040 | lpfc_cmd->cur_iocbq.sli4_xritag)) |
| 1041 | continue; |
| 1042 | list_del(&lpfc_cmd->list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1043 | found = 1; |
| 1044 | lpfc_cmd->seg_cnt = 0; |
| 1045 | lpfc_cmd->nonsg_phys = 0; |
| 1046 | lpfc_cmd->prot_seg_cnt = 0; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1047 | break; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1048 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1049 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, |
| 1050 | iflag); |
| 1051 | if (!found) |
| 1052 | return NULL; |
| 1053 | else |
| 1054 | return lpfc_cmd; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1055 | } |
| 1056 | /** |
| 1057 | * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA |
| 1058 | * @phba: The HBA for which this call is being executed. |
| 1059 | * |
| 1060 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list |
| 1061 | * and returns to caller. |
| 1062 | * |
| 1063 | * Return codes: |
| 1064 | * NULL - Error |
| 1065 | * Pointer to lpfc_scsi_buf - Success |
| 1066 | **/ |
| 1067 | static struct lpfc_scsi_buf* |
| 1068 | lpfc_get_scsi_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| 1069 | { |
| 1070 | return phba->lpfc_get_scsi_buf(phba, ndlp); |
| 1071 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1072 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 1073 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1074 | * 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] | 1075 | * @phba: The Hba for which this call is being executed. |
| 1076 | * @psb: The scsi buffer which is being released. |
| 1077 | * |
| 1078 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
| 1079 | * lpfc_scsi_buf_list list. |
| 1080 | **/ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1081 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1082 | 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] | 1083 | { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1084 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1085 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1086 | spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1087 | psb->pCmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1088 | list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1089 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1090 | } |
| 1091 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 1092 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1093 | * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list. |
| 1094 | * @phba: The Hba for which this call is being executed. |
| 1095 | * @psb: The scsi buffer which is being released. |
| 1096 | * |
| 1097 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
| 1098 | * lpfc_scsi_buf_list list. For SLI4 XRI's are tied to the scsi buffer |
| 1099 | * and cannot be reused for at least RA_TOV amount of time if it was |
| 1100 | * aborted. |
| 1101 | **/ |
| 1102 | static void |
| 1103 | lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) |
| 1104 | { |
| 1105 | unsigned long iflag = 0; |
| 1106 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 1107 | if (psb->exch_busy) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1108 | spin_lock_irqsave(&phba->sli4_hba.abts_scsi_buf_list_lock, |
| 1109 | iflag); |
| 1110 | psb->pCmd = NULL; |
| 1111 | list_add_tail(&psb->list, |
| 1112 | &phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 1113 | spin_unlock_irqrestore(&phba->sli4_hba.abts_scsi_buf_list_lock, |
| 1114 | iflag); |
| 1115 | } else { |
| 1116 | |
| 1117 | spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); |
| 1118 | psb->pCmd = NULL; |
| 1119 | list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list); |
| 1120 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); |
| 1121 | } |
| 1122 | } |
| 1123 | |
| 1124 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1125 | * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list. |
| 1126 | * @phba: The Hba for which this call is being executed. |
| 1127 | * @psb: The scsi buffer which is being released. |
| 1128 | * |
| 1129 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
| 1130 | * lpfc_scsi_buf_list list. |
| 1131 | **/ |
| 1132 | static void |
| 1133 | lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) |
| 1134 | { |
| 1135 | |
| 1136 | phba->lpfc_release_scsi_buf(phba, psb); |
| 1137 | } |
| 1138 | |
| 1139 | /** |
| 1140 | * 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] | 1141 | * @phba: The Hba for which this call is being executed. |
| 1142 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 1143 | * |
| 1144 | * 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] | 1145 | * field of @lpfc_cmd for device with SLI-3 interface spec. This routine scans |
| 1146 | * through sg elements and format the bdea. This routine also initializes all |
| 1147 | * IOCB fields which are dependent on scsi command request buffer. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 1148 | * |
| 1149 | * Return codes: |
| 1150 | * 1 - Error |
| 1151 | * 0 - Success |
| 1152 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1153 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1154 | 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] | 1155 | { |
| 1156 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 1157 | struct scatterlist *sgel = NULL; |
| 1158 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 1159 | struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1160 | struct lpfc_iocbq *iocbq = &lpfc_cmd->cur_iocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1161 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1162 | struct ulp_bde64 *data_bde = iocb_cmd->unsli3.fcp_ext.dbde; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1163 | dma_addr_t physaddr; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1164 | uint32_t num_bde = 0; |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1165 | int nseg, datadir = scsi_cmnd->sc_data_direction; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1166 | |
| 1167 | /* |
| 1168 | * There are three possibilities here - use scatter-gather segment, use |
| 1169 | * the single mapping, or neither. Start the lpfc command prep by |
| 1170 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 1171 | * data bde entry. |
| 1172 | */ |
| 1173 | bpl += 2; |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 1174 | if (scsi_sg_count(scsi_cmnd)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1175 | /* |
| 1176 | * The driver stores the segment count returned from pci_map_sg |
| 1177 | * because this a count of dma-mappings used to map the use_sg |
| 1178 | * pages. They are not guaranteed to be the same for those |
| 1179 | * architectures that implement an IOMMU. |
| 1180 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1181 | |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 1182 | nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd), |
| 1183 | scsi_sg_count(scsi_cmnd), datadir); |
| 1184 | if (unlikely(!nseg)) |
| 1185 | return 1; |
| 1186 | |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1187 | lpfc_cmd->seg_cnt = nseg; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1188 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1189 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1190 | "9064 BLKGRD: %s: Too many sg segments from " |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1191 | "dma_map_sg. Config %d, seg_cnt %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1192 | __func__, phba->cfg_sg_seg_cnt, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1193 | lpfc_cmd->seg_cnt); |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1194 | scsi_dma_unmap(scsi_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1195 | return 1; |
| 1196 | } |
| 1197 | |
| 1198 | /* |
| 1199 | * The driver established a maximum scatter-gather segment count |
| 1200 | * during probe that limits the number of sg elements in any |
| 1201 | * single scsi command. Just run through the seg_cnt and format |
| 1202 | * the bde's. |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1203 | * When using SLI-3 the driver will try to fit all the BDEs into |
| 1204 | * the IOCB. If it can't then the BDEs get added to a BPL as it |
| 1205 | * does for SLI-2 mode. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1206 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1207 | scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1208 | physaddr = sg_dma_address(sgel); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1209 | if (phba->sli_rev == 3 && |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1210 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1211 | !(iocbq->iocb_flag & DSS_SECURITY_OP) && |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1212 | nseg <= LPFC_EXT_DATA_BDE_COUNT) { |
| 1213 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1214 | data_bde->tus.f.bdeSize = sg_dma_len(sgel); |
| 1215 | data_bde->addrLow = putPaddrLow(physaddr); |
| 1216 | data_bde->addrHigh = putPaddrHigh(physaddr); |
| 1217 | data_bde++; |
| 1218 | } else { |
| 1219 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1220 | bpl->tus.f.bdeSize = sg_dma_len(sgel); |
| 1221 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 1222 | bpl->addrLow = |
| 1223 | le32_to_cpu(putPaddrLow(physaddr)); |
| 1224 | bpl->addrHigh = |
| 1225 | le32_to_cpu(putPaddrHigh(physaddr)); |
| 1226 | bpl++; |
| 1227 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1228 | } |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 1229 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1230 | |
| 1231 | /* |
| 1232 | * Finish initializing those IOCB fields that are dependent on the |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1233 | * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is |
| 1234 | * explicitly reinitialized and for SLI-3 the extended bde count is |
| 1235 | * explicitly reinitialized since all iocb memory resources are reused. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1236 | */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1237 | if (phba->sli_rev == 3 && |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1238 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
| 1239 | !(iocbq->iocb_flag & DSS_SECURITY_OP)) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1240 | if (num_bde > LPFC_EXT_DATA_BDE_COUNT) { |
| 1241 | /* |
| 1242 | * The extended IOCB format can only fit 3 BDE or a BPL. |
| 1243 | * This I/O has more than 3 BDE so the 1st data bde will |
| 1244 | * be a BPL that is filled in here. |
| 1245 | */ |
| 1246 | physaddr = lpfc_cmd->dma_handle; |
| 1247 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BLP_64; |
| 1248 | data_bde->tus.f.bdeSize = (num_bde * |
| 1249 | sizeof(struct ulp_bde64)); |
| 1250 | physaddr += (sizeof(struct fcp_cmnd) + |
| 1251 | sizeof(struct fcp_rsp) + |
| 1252 | (2 * sizeof(struct ulp_bde64))); |
| 1253 | data_bde->addrHigh = putPaddrHigh(physaddr); |
| 1254 | data_bde->addrLow = putPaddrLow(physaddr); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1255 | /* ebde count includes the response bde and data bpl */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1256 | iocb_cmd->unsli3.fcp_ext.ebde_count = 2; |
| 1257 | } else { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1258 | /* ebde count includes the response bde and data bdes */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1259 | iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); |
| 1260 | } |
| 1261 | } else { |
| 1262 | iocb_cmd->un.fcpi64.bdl.bdeSize = |
| 1263 | ((num_bde + 2) * sizeof(struct ulp_bde64)); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1264 | iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1265 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1266 | fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1267 | |
| 1268 | /* |
| 1269 | * Due to difference in data length between DIF/non-DIF paths, |
| 1270 | * we need to set word 4 of IOCB here |
| 1271 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1272 | iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1273 | return 0; |
| 1274 | } |
| 1275 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1276 | static inline unsigned |
| 1277 | lpfc_cmd_blksize(struct scsi_cmnd *sc) |
| 1278 | { |
| 1279 | return sc->device->sector_size; |
| 1280 | } |
| 1281 | |
| 1282 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1283 | |
| 1284 | #define BG_ERR_INIT 1 |
| 1285 | #define BG_ERR_TGT 2 |
| 1286 | #define BG_ERR_SWAP 3 |
| 1287 | #define BG_ERR_CHECK 4 |
| 1288 | |
| 1289 | /** |
| 1290 | * lpfc_bg_err_inject - Determine if we should inject an error |
| 1291 | * @phba: The Hba for which this call is being executed. |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1292 | * @sc: The SCSI command to examine |
| 1293 | * @reftag: (out) BlockGuard reference tag for transmitted data |
| 1294 | * @apptag: (out) BlockGuard application tag for transmitted data |
| 1295 | * @new_guard (in) Value to replace CRC with if needed |
| 1296 | * |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1297 | * Returns (1) if error injection is detected by Initiator |
| 1298 | * Returns (2) if error injection is detected by Target |
| 1299 | * Returns (3) if swapping CSUM->CRC is required for error injection |
| 1300 | * Returns (4) disabling Guard/Ref/App checking is required for error injection |
| 1301 | **/ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1302 | static int |
| 1303 | lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1304 | uint32_t *reftag, uint16_t *apptag, uint32_t new_guard) |
| 1305 | { |
| 1306 | struct scatterlist *sgpe; /* s/g prot entry */ |
| 1307 | struct scatterlist *sgde; /* s/g data entry */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1308 | struct scsi_dif_tuple *src = NULL; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1309 | uint32_t op = scsi_get_prot_op(sc); |
| 1310 | uint32_t blksize; |
| 1311 | uint32_t numblks; |
| 1312 | sector_t lba; |
| 1313 | int rc = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1314 | int blockoff = 0; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1315 | |
| 1316 | if (op == SCSI_PROT_NORMAL) |
| 1317 | return 0; |
| 1318 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1319 | sgpe = scsi_prot_sglist(sc); |
| 1320 | sgde = scsi_sglist(sc); |
| 1321 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1322 | lba = scsi_get_lba(sc); |
| 1323 | if (phba->lpfc_injerr_lba != LPFC_INJERR_LBA_OFF) { |
| 1324 | blksize = lpfc_cmd_blksize(sc); |
| 1325 | numblks = (scsi_bufflen(sc) + blksize - 1) / blksize; |
| 1326 | |
| 1327 | /* Make sure we have the right LBA if one is specified */ |
| 1328 | if ((phba->lpfc_injerr_lba < lba) || |
| 1329 | (phba->lpfc_injerr_lba >= (lba + numblks))) |
| 1330 | return 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1331 | if (sgpe) { |
| 1332 | blockoff = phba->lpfc_injerr_lba - lba; |
| 1333 | numblks = sg_dma_len(sgpe) / |
| 1334 | sizeof(struct scsi_dif_tuple); |
| 1335 | if (numblks < blockoff) |
| 1336 | blockoff = numblks; |
| 1337 | src = (struct scsi_dif_tuple *)sg_virt(sgpe); |
| 1338 | src += blockoff; |
| 1339 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1340 | } |
| 1341 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1342 | /* Should we change the Reference Tag */ |
| 1343 | if (reftag) { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1344 | if (phba->lpfc_injerr_wref_cnt) { |
| 1345 | switch (op) { |
| 1346 | case SCSI_PROT_WRITE_PASS: |
| 1347 | if (blockoff && src) { |
| 1348 | /* Insert error in middle of the IO */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1349 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1350 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1351 | "9076 BLKGRD: Injecting reftag error: " |
| 1352 | "write lba x%lx + x%x oldrefTag x%x\n", |
| 1353 | (unsigned long)lba, blockoff, |
| 1354 | src->ref_tag); |
| 1355 | |
| 1356 | /* |
| 1357 | * NOTE, this will change ref tag in |
| 1358 | * the memory location forever! |
| 1359 | */ |
| 1360 | src->ref_tag = 0xDEADBEEF; |
| 1361 | phba->lpfc_injerr_wref_cnt--; |
| 1362 | phba->lpfc_injerr_lba = |
| 1363 | LPFC_INJERR_LBA_OFF; |
| 1364 | rc = BG_ERR_CHECK; |
| 1365 | break; |
| 1366 | } |
| 1367 | /* Drop thru */ |
| 1368 | case SCSI_PROT_WRITE_STRIP: |
| 1369 | /* |
| 1370 | * For WRITE_STRIP and WRITE_PASS, |
| 1371 | * force the error on data |
| 1372 | * being copied from SLI-Host to SLI-Port. |
| 1373 | */ |
| 1374 | *reftag = 0xDEADBEEF; |
| 1375 | phba->lpfc_injerr_wref_cnt--; |
| 1376 | phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF; |
| 1377 | rc = BG_ERR_INIT; |
| 1378 | |
| 1379 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1380 | "9077 BLKGRD: Injecting reftag error: " |
| 1381 | "write lba x%lx\n", (unsigned long)lba); |
| 1382 | break; |
| 1383 | case SCSI_PROT_WRITE_INSERT: |
| 1384 | /* |
| 1385 | * For WRITE_INSERT, force the |
| 1386 | * error to be sent on the wire. It should be |
| 1387 | * detected by the Target. |
| 1388 | */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1389 | /* DEADBEEF will be the reftag on the wire */ |
| 1390 | *reftag = 0xDEADBEEF; |
| 1391 | phba->lpfc_injerr_wref_cnt--; |
| 1392 | phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1393 | rc = BG_ERR_TGT; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1394 | |
| 1395 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1396 | "9078 BLKGRD: Injecting reftag error: " |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1397 | "write lba x%lx\n", (unsigned long)lba); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1398 | break; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1399 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1400 | } |
| 1401 | if (phba->lpfc_injerr_rref_cnt) { |
| 1402 | switch (op) { |
| 1403 | case SCSI_PROT_READ_INSERT: |
| 1404 | /* |
| 1405 | * For READ_INSERT, it doesn't make sense |
| 1406 | * to change the reftag. |
| 1407 | */ |
| 1408 | break; |
| 1409 | case SCSI_PROT_READ_STRIP: |
| 1410 | case SCSI_PROT_READ_PASS: |
| 1411 | /* |
| 1412 | * For READ_STRIP and READ_PASS, force the |
| 1413 | * error on data being read off the wire. It |
| 1414 | * should force an IO error to the driver. |
| 1415 | */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1416 | *reftag = 0xDEADBEEF; |
| 1417 | phba->lpfc_injerr_rref_cnt--; |
| 1418 | phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1419 | rc = BG_ERR_INIT; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1420 | |
| 1421 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1422 | "9079 BLKGRD: Injecting reftag error: " |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1423 | "read lba x%lx\n", (unsigned long)lba); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1424 | break; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1425 | } |
| 1426 | } |
| 1427 | } |
| 1428 | |
| 1429 | /* Should we change the Application Tag */ |
| 1430 | if (apptag) { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1431 | if (phba->lpfc_injerr_wapp_cnt) { |
| 1432 | switch (op) { |
| 1433 | case SCSI_PROT_WRITE_PASS: |
| 1434 | if (blockoff && src) { |
| 1435 | /* Insert error in middle of the IO */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1436 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1437 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1438 | "9080 BLKGRD: Injecting apptag error: " |
| 1439 | "write lba x%lx + x%x oldappTag x%x\n", |
| 1440 | (unsigned long)lba, blockoff, |
| 1441 | src->app_tag); |
| 1442 | |
| 1443 | /* |
| 1444 | * NOTE, this will change app tag in |
| 1445 | * the memory location forever! |
| 1446 | */ |
| 1447 | src->app_tag = 0xDEAD; |
| 1448 | phba->lpfc_injerr_wapp_cnt--; |
| 1449 | phba->lpfc_injerr_lba = |
| 1450 | LPFC_INJERR_LBA_OFF; |
| 1451 | rc = BG_ERR_CHECK; |
| 1452 | break; |
| 1453 | } |
| 1454 | /* Drop thru */ |
| 1455 | case SCSI_PROT_WRITE_STRIP: |
| 1456 | /* |
| 1457 | * For WRITE_STRIP and WRITE_PASS, |
| 1458 | * force the error on data |
| 1459 | * being copied from SLI-Host to SLI-Port. |
| 1460 | */ |
| 1461 | *apptag = 0xDEAD; |
| 1462 | phba->lpfc_injerr_wapp_cnt--; |
| 1463 | phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF; |
| 1464 | rc = BG_ERR_INIT; |
| 1465 | |
| 1466 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1467 | "0812 BLKGRD: Injecting apptag error: " |
| 1468 | "write lba x%lx\n", (unsigned long)lba); |
| 1469 | break; |
| 1470 | case SCSI_PROT_WRITE_INSERT: |
| 1471 | /* |
| 1472 | * For WRITE_INSERT, force the |
| 1473 | * error to be sent on the wire. It should be |
| 1474 | * detected by the Target. |
| 1475 | */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1476 | /* DEAD will be the apptag on the wire */ |
| 1477 | *apptag = 0xDEAD; |
| 1478 | phba->lpfc_injerr_wapp_cnt--; |
| 1479 | phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1480 | rc = BG_ERR_TGT; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1481 | |
| 1482 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1483 | "0813 BLKGRD: Injecting apptag error: " |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1484 | "write lba x%lx\n", (unsigned long)lba); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1485 | break; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1486 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1487 | } |
| 1488 | if (phba->lpfc_injerr_rapp_cnt) { |
| 1489 | switch (op) { |
| 1490 | case SCSI_PROT_READ_INSERT: |
| 1491 | /* |
| 1492 | * For READ_INSERT, it doesn't make sense |
| 1493 | * to change the apptag. |
| 1494 | */ |
| 1495 | break; |
| 1496 | case SCSI_PROT_READ_STRIP: |
| 1497 | case SCSI_PROT_READ_PASS: |
| 1498 | /* |
| 1499 | * For READ_STRIP and READ_PASS, force the |
| 1500 | * error on data being read off the wire. It |
| 1501 | * should force an IO error to the driver. |
| 1502 | */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1503 | *apptag = 0xDEAD; |
| 1504 | phba->lpfc_injerr_rapp_cnt--; |
| 1505 | phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1506 | rc = BG_ERR_INIT; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1507 | |
| 1508 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1509 | "0814 BLKGRD: Injecting apptag error: " |
| 1510 | "read lba x%lx\n", (unsigned long)lba); |
| 1511 | break; |
| 1512 | } |
| 1513 | } |
| 1514 | } |
| 1515 | |
| 1516 | |
| 1517 | /* Should we change the Guard Tag */ |
| 1518 | if (new_guard) { |
| 1519 | if (phba->lpfc_injerr_wgrd_cnt) { |
| 1520 | switch (op) { |
| 1521 | case SCSI_PROT_WRITE_PASS: |
| 1522 | if (blockoff && src) { |
| 1523 | /* Insert error in middle of the IO */ |
| 1524 | |
| 1525 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1526 | "0815 BLKGRD: Injecting guard error: " |
| 1527 | "write lba x%lx + x%x oldgrdTag x%x\n", |
| 1528 | (unsigned long)lba, blockoff, |
| 1529 | src->guard_tag); |
| 1530 | |
| 1531 | /* |
| 1532 | * NOTE, this will change guard tag in |
| 1533 | * the memory location forever! |
| 1534 | */ |
| 1535 | src->guard_tag = 0xDEAD; |
| 1536 | phba->lpfc_injerr_wgrd_cnt--; |
| 1537 | phba->lpfc_injerr_lba = |
| 1538 | LPFC_INJERR_LBA_OFF; |
| 1539 | rc = BG_ERR_CHECK; |
| 1540 | break; |
| 1541 | } |
| 1542 | /* Drop thru */ |
| 1543 | case SCSI_PROT_WRITE_STRIP: |
| 1544 | /* |
| 1545 | * For WRITE_STRIP and WRITE_PASS, |
| 1546 | * force the error on data |
| 1547 | * being copied from SLI-Host to SLI-Port. |
| 1548 | */ |
| 1549 | phba->lpfc_injerr_wgrd_cnt--; |
| 1550 | phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF; |
| 1551 | |
| 1552 | rc = BG_ERR_SWAP; |
| 1553 | /* Signals the caller to swap CRC->CSUM */ |
| 1554 | |
| 1555 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1556 | "0816 BLKGRD: Injecting guard error: " |
| 1557 | "write lba x%lx\n", (unsigned long)lba); |
| 1558 | break; |
| 1559 | case SCSI_PROT_WRITE_INSERT: |
| 1560 | /* |
| 1561 | * For WRITE_INSERT, force the |
| 1562 | * error to be sent on the wire. It should be |
| 1563 | * detected by the Target. |
| 1564 | */ |
| 1565 | phba->lpfc_injerr_wgrd_cnt--; |
| 1566 | phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF; |
| 1567 | |
| 1568 | rc = BG_ERR_SWAP; |
| 1569 | /* Signals the caller to swap CRC->CSUM */ |
| 1570 | |
| 1571 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1572 | "0817 BLKGRD: Injecting guard error: " |
| 1573 | "write lba x%lx\n", (unsigned long)lba); |
| 1574 | break; |
| 1575 | } |
| 1576 | } |
| 1577 | if (phba->lpfc_injerr_rgrd_cnt) { |
| 1578 | switch (op) { |
| 1579 | case SCSI_PROT_READ_INSERT: |
| 1580 | /* |
| 1581 | * For READ_INSERT, it doesn't make sense |
| 1582 | * to change the guard tag. |
| 1583 | */ |
| 1584 | break; |
| 1585 | case SCSI_PROT_READ_STRIP: |
| 1586 | case SCSI_PROT_READ_PASS: |
| 1587 | /* |
| 1588 | * For READ_STRIP and READ_PASS, force the |
| 1589 | * error on data being read off the wire. It |
| 1590 | * should force an IO error to the driver. |
| 1591 | */ |
| 1592 | *apptag = 0xDEAD; |
| 1593 | phba->lpfc_injerr_rgrd_cnt--; |
| 1594 | phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF; |
| 1595 | |
| 1596 | rc = BG_ERR_SWAP; |
| 1597 | /* Signals the caller to swap CRC->CSUM */ |
| 1598 | |
| 1599 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1600 | "0818 BLKGRD: Injecting guard error: " |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1601 | "read lba x%lx\n", (unsigned long)lba); |
| 1602 | } |
| 1603 | } |
| 1604 | } |
| 1605 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1606 | return rc; |
| 1607 | } |
| 1608 | #endif |
| 1609 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1610 | /** |
| 1611 | * lpfc_sc_to_bg_opcodes - Determine the BlockGuard opcodes to be used with |
| 1612 | * the specified SCSI command. |
| 1613 | * @phba: The Hba for which this call is being executed. |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1614 | * @sc: The SCSI command to examine |
| 1615 | * @txopt: (out) BlockGuard operation for transmitted data |
| 1616 | * @rxopt: (out) BlockGuard operation for received data |
| 1617 | * |
| 1618 | * Returns: zero on success; non-zero if tx and/or rx op cannot be determined |
| 1619 | * |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1620 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1621 | static int |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1622 | lpfc_sc_to_bg_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1623 | uint8_t *txop, uint8_t *rxop) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1624 | { |
| 1625 | uint8_t guard_type = scsi_host_get_guard(sc->device->host); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1626 | uint8_t ret = 0; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1627 | |
| 1628 | if (guard_type == SHOST_DIX_GUARD_IP) { |
| 1629 | switch (scsi_get_prot_op(sc)) { |
| 1630 | case SCSI_PROT_READ_INSERT: |
| 1631 | case SCSI_PROT_WRITE_STRIP: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1632 | *txop = BG_OP_IN_CSUM_OUT_NODIF; |
| 1633 | *rxop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1634 | break; |
| 1635 | |
| 1636 | case SCSI_PROT_READ_STRIP: |
| 1637 | case SCSI_PROT_WRITE_INSERT: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1638 | *txop = BG_OP_IN_NODIF_OUT_CRC; |
| 1639 | *rxop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1640 | break; |
| 1641 | |
Martin K. Petersen | c6af404 | 2009-09-18 17:32:59 -0400 | [diff] [blame] | 1642 | case SCSI_PROT_READ_PASS: |
| 1643 | case SCSI_PROT_WRITE_PASS: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1644 | *txop = BG_OP_IN_CSUM_OUT_CRC; |
| 1645 | *rxop = BG_OP_IN_CRC_OUT_CSUM; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1646 | break; |
| 1647 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1648 | case SCSI_PROT_NORMAL: |
| 1649 | default: |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1650 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1651 | "9063 BLKGRD: Bad op/guard:%d/IP combination\n", |
| 1652 | scsi_get_prot_op(sc)); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1653 | ret = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1654 | break; |
| 1655 | |
| 1656 | } |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1657 | } else { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1658 | switch (scsi_get_prot_op(sc)) { |
| 1659 | case SCSI_PROT_READ_STRIP: |
| 1660 | case SCSI_PROT_WRITE_INSERT: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1661 | *txop = BG_OP_IN_NODIF_OUT_CRC; |
| 1662 | *rxop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1663 | break; |
| 1664 | |
| 1665 | case SCSI_PROT_READ_PASS: |
| 1666 | case SCSI_PROT_WRITE_PASS: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1667 | *txop = BG_OP_IN_CRC_OUT_CRC; |
| 1668 | *rxop = BG_OP_IN_CRC_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1669 | break; |
| 1670 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1671 | case SCSI_PROT_READ_INSERT: |
| 1672 | case SCSI_PROT_WRITE_STRIP: |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1673 | *txop = BG_OP_IN_CRC_OUT_NODIF; |
| 1674 | *rxop = BG_OP_IN_NODIF_OUT_CRC; |
| 1675 | break; |
| 1676 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1677 | case SCSI_PROT_NORMAL: |
| 1678 | default: |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1679 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1680 | "9075 BLKGRD: Bad op/guard:%d/CRC combination\n", |
| 1681 | scsi_get_prot_op(sc)); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1682 | ret = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1683 | break; |
| 1684 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1685 | } |
| 1686 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1687 | return ret; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1688 | } |
| 1689 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1690 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 1691 | /** |
| 1692 | * lpfc_bg_err_opcodes - reDetermine the BlockGuard opcodes to be used with |
| 1693 | * the specified SCSI command in order to force a guard tag error. |
| 1694 | * @phba: The Hba for which this call is being executed. |
| 1695 | * @sc: The SCSI command to examine |
| 1696 | * @txopt: (out) BlockGuard operation for transmitted data |
| 1697 | * @rxopt: (out) BlockGuard operation for received data |
| 1698 | * |
| 1699 | * Returns: zero on success; non-zero if tx and/or rx op cannot be determined |
| 1700 | * |
| 1701 | **/ |
| 1702 | static int |
| 1703 | lpfc_bg_err_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1704 | uint8_t *txop, uint8_t *rxop) |
| 1705 | { |
| 1706 | uint8_t guard_type = scsi_host_get_guard(sc->device->host); |
| 1707 | uint8_t ret = 0; |
| 1708 | |
| 1709 | if (guard_type == SHOST_DIX_GUARD_IP) { |
| 1710 | switch (scsi_get_prot_op(sc)) { |
| 1711 | case SCSI_PROT_READ_INSERT: |
| 1712 | case SCSI_PROT_WRITE_STRIP: |
| 1713 | *txop = BG_OP_IN_CRC_OUT_NODIF; |
| 1714 | *rxop = BG_OP_IN_NODIF_OUT_CRC; |
| 1715 | break; |
| 1716 | |
| 1717 | case SCSI_PROT_READ_STRIP: |
| 1718 | case SCSI_PROT_WRITE_INSERT: |
| 1719 | *txop = BG_OP_IN_NODIF_OUT_CSUM; |
| 1720 | *rxop = BG_OP_IN_CSUM_OUT_NODIF; |
| 1721 | break; |
| 1722 | |
| 1723 | case SCSI_PROT_READ_PASS: |
| 1724 | case SCSI_PROT_WRITE_PASS: |
| 1725 | *txop = BG_OP_IN_CRC_OUT_CRC; |
| 1726 | *rxop = BG_OP_IN_CRC_OUT_CRC; |
| 1727 | break; |
| 1728 | |
| 1729 | case SCSI_PROT_NORMAL: |
| 1730 | default: |
| 1731 | break; |
| 1732 | |
| 1733 | } |
| 1734 | } else { |
| 1735 | switch (scsi_get_prot_op(sc)) { |
| 1736 | case SCSI_PROT_READ_STRIP: |
| 1737 | case SCSI_PROT_WRITE_INSERT: |
| 1738 | *txop = BG_OP_IN_NODIF_OUT_CSUM; |
| 1739 | *rxop = BG_OP_IN_CSUM_OUT_NODIF; |
| 1740 | break; |
| 1741 | |
| 1742 | case SCSI_PROT_READ_PASS: |
| 1743 | case SCSI_PROT_WRITE_PASS: |
| 1744 | *txop = BG_OP_IN_CSUM_OUT_CRC; |
| 1745 | *rxop = BG_OP_IN_CRC_OUT_CSUM; |
| 1746 | break; |
| 1747 | |
| 1748 | case SCSI_PROT_READ_INSERT: |
| 1749 | case SCSI_PROT_WRITE_STRIP: |
| 1750 | *txop = BG_OP_IN_CSUM_OUT_NODIF; |
| 1751 | *rxop = BG_OP_IN_NODIF_OUT_CSUM; |
| 1752 | break; |
| 1753 | |
| 1754 | case SCSI_PROT_NORMAL: |
| 1755 | default: |
| 1756 | break; |
| 1757 | } |
| 1758 | } |
| 1759 | |
| 1760 | return ret; |
| 1761 | } |
| 1762 | #endif |
| 1763 | |
| 1764 | /** |
| 1765 | * lpfc_bg_setup_bpl - Setup BlockGuard BPL with no protection data |
| 1766 | * @phba: The Hba for which this call is being executed. |
| 1767 | * @sc: pointer to scsi command we're working on |
| 1768 | * @bpl: pointer to buffer list for protection groups |
| 1769 | * @datacnt: number of segments of data that have been dma mapped |
| 1770 | * |
| 1771 | * This function sets up BPL buffer list for protection groups of |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1772 | * type LPFC_PG_TYPE_NO_DIF |
| 1773 | * |
| 1774 | * This is usually used when the HBA is instructed to generate |
| 1775 | * DIFs and insert them into data stream (or strip DIF from |
| 1776 | * incoming data stream) |
| 1777 | * |
| 1778 | * The buffer list consists of just one protection group described |
| 1779 | * below: |
| 1780 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1781 | * start of prot group --> | PDE_5 | |
| 1782 | * +-------------------------+ |
| 1783 | * | PDE_6 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1784 | * +-------------------------+ |
| 1785 | * | Data BDE | |
| 1786 | * +-------------------------+ |
| 1787 | * |more Data BDE's ... (opt)| |
| 1788 | * +-------------------------+ |
| 1789 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1790 | * |
| 1791 | * Note: Data s/g buffers have been dma mapped |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1792 | * |
| 1793 | * Returns the number of BDEs added to the BPL. |
| 1794 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1795 | static int |
| 1796 | lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1797 | struct ulp_bde64 *bpl, int datasegcnt) |
| 1798 | { |
| 1799 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1800 | struct lpfc_pde5 *pde5 = NULL; |
| 1801 | struct lpfc_pde6 *pde6 = NULL; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1802 | dma_addr_t physaddr; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1803 | int i = 0, num_bde = 0, status; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1804 | int datadir = sc->sc_data_direction; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1805 | uint32_t rc; |
| 1806 | uint32_t checking = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1807 | uint32_t reftag; |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1808 | unsigned blksize; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1809 | uint8_t txop, rxop; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1810 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1811 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 1812 | if (status) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1813 | goto out; |
| 1814 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1815 | /* extract some info from the scsi command for pde*/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1816 | blksize = lpfc_cmd_blksize(sc); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1817 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1818 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1819 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1820 | rc = lpfc_bg_err_inject(phba, sc, &reftag, 0, 1); |
| 1821 | if (rc) { |
| 1822 | if (rc == BG_ERR_SWAP) |
| 1823 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
| 1824 | if (rc == BG_ERR_CHECK) |
| 1825 | checking = 0; |
| 1826 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1827 | #endif |
| 1828 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1829 | /* setup PDE5 with what we have */ |
| 1830 | pde5 = (struct lpfc_pde5 *) bpl; |
| 1831 | memset(pde5, 0, sizeof(struct lpfc_pde5)); |
| 1832 | bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1833 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1834 | /* Endianness conversion if necessary for PDE5 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1835 | pde5->word0 = cpu_to_le32(pde5->word0); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1836 | pde5->reftag = cpu_to_le32(reftag); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1837 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1838 | /* advance bpl and increment bde count */ |
| 1839 | num_bde++; |
| 1840 | bpl++; |
| 1841 | pde6 = (struct lpfc_pde6 *) bpl; |
| 1842 | |
| 1843 | /* setup PDE6 with the rest of the info */ |
| 1844 | memset(pde6, 0, sizeof(struct lpfc_pde6)); |
| 1845 | bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR); |
| 1846 | bf_set(pde6_optx, pde6, txop); |
| 1847 | bf_set(pde6_oprx, pde6, rxop); |
| 1848 | if (datadir == DMA_FROM_DEVICE) { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1849 | bf_set(pde6_ce, pde6, checking); |
| 1850 | bf_set(pde6_re, pde6, checking); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1851 | } |
| 1852 | bf_set(pde6_ai, pde6, 1); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1853 | bf_set(pde6_ae, pde6, 0); |
| 1854 | bf_set(pde6_apptagval, pde6, 0); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1855 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1856 | /* Endianness conversion if necessary for PDE6 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1857 | pde6->word0 = cpu_to_le32(pde6->word0); |
| 1858 | pde6->word1 = cpu_to_le32(pde6->word1); |
| 1859 | pde6->word2 = cpu_to_le32(pde6->word2); |
| 1860 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1861 | /* advance bpl and increment bde count */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1862 | num_bde++; |
| 1863 | bpl++; |
| 1864 | |
| 1865 | /* assumption: caller has already run dma_map_sg on command data */ |
| 1866 | scsi_for_each_sg(sc, sgde, datasegcnt, i) { |
| 1867 | physaddr = sg_dma_address(sgde); |
| 1868 | bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
| 1869 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 1870 | bpl->tus.f.bdeSize = sg_dma_len(sgde); |
| 1871 | if (datadir == DMA_TO_DEVICE) |
| 1872 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1873 | else |
| 1874 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
| 1875 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 1876 | bpl++; |
| 1877 | num_bde++; |
| 1878 | } |
| 1879 | |
| 1880 | out: |
| 1881 | return num_bde; |
| 1882 | } |
| 1883 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1884 | /** |
| 1885 | * lpfc_bg_setup_bpl_prot - Setup BlockGuard BPL with protection data |
| 1886 | * @phba: The Hba for which this call is being executed. |
| 1887 | * @sc: pointer to scsi command we're working on |
| 1888 | * @bpl: pointer to buffer list for protection groups |
| 1889 | * @datacnt: number of segments of data that have been dma mapped |
| 1890 | * @protcnt: number of segment of protection data that have been dma mapped |
| 1891 | * |
| 1892 | * This function sets up BPL buffer list for protection groups of |
| 1893 | * type LPFC_PG_TYPE_DIF |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1894 | * |
| 1895 | * This is usually used when DIFs are in their own buffers, |
| 1896 | * separate from the data. The HBA can then by instructed |
| 1897 | * to place the DIFs in the outgoing stream. For read operations, |
| 1898 | * The HBA could extract the DIFs and place it in DIF buffers. |
| 1899 | * |
| 1900 | * The buffer list for this type consists of one or more of the |
| 1901 | * protection groups described below: |
| 1902 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1903 | * start of first prot group --> | PDE_5 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1904 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1905 | * | PDE_6 | |
| 1906 | * +-------------------------+ |
| 1907 | * | PDE_7 (Prot BDE) | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1908 | * +-------------------------+ |
| 1909 | * | Data BDE | |
| 1910 | * +-------------------------+ |
| 1911 | * |more Data BDE's ... (opt)| |
| 1912 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1913 | * start of new prot group --> | PDE_5 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1914 | * +-------------------------+ |
| 1915 | * | ... | |
| 1916 | * +-------------------------+ |
| 1917 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1918 | * Note: It is assumed that both data and protection s/g buffers have been |
| 1919 | * mapped for DMA |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1920 | * |
| 1921 | * Returns the number of BDEs added to the BPL. |
| 1922 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1923 | static int |
| 1924 | lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1925 | struct ulp_bde64 *bpl, int datacnt, int protcnt) |
| 1926 | { |
| 1927 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 1928 | struct scatterlist *sgpe = NULL; /* s/g prot entry */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1929 | struct lpfc_pde5 *pde5 = NULL; |
| 1930 | struct lpfc_pde6 *pde6 = NULL; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1931 | struct lpfc_pde7 *pde7 = NULL; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1932 | dma_addr_t dataphysaddr, protphysaddr; |
| 1933 | unsigned short curr_data = 0, curr_prot = 0; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1934 | unsigned int split_offset; |
| 1935 | unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1936 | unsigned int protgrp_blks, protgrp_bytes; |
| 1937 | unsigned int remainder, subtotal; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1938 | int status; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1939 | int datadir = sc->sc_data_direction; |
| 1940 | unsigned char pgdone = 0, alldone = 0; |
| 1941 | unsigned blksize; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1942 | uint32_t rc; |
| 1943 | uint32_t checking = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1944 | uint32_t reftag; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1945 | uint8_t txop, rxop; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1946 | int num_bde = 0; |
| 1947 | |
| 1948 | sgpe = scsi_prot_sglist(sc); |
| 1949 | sgde = scsi_sglist(sc); |
| 1950 | |
| 1951 | if (!sgpe || !sgde) { |
| 1952 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 1953 | "9020 Invalid s/g entry: data=0x%p prot=0x%p\n", |
| 1954 | sgpe, sgde); |
| 1955 | return 0; |
| 1956 | } |
| 1957 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1958 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 1959 | if (status) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1960 | goto out; |
| 1961 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1962 | /* extract some info from the scsi command */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1963 | blksize = lpfc_cmd_blksize(sc); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1964 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1965 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1966 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1967 | rc = lpfc_bg_err_inject(phba, sc, &reftag, 0, 1); |
| 1968 | if (rc) { |
| 1969 | if (rc == BG_ERR_SWAP) |
| 1970 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
| 1971 | if (rc == BG_ERR_CHECK) |
| 1972 | checking = 0; |
| 1973 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1974 | #endif |
| 1975 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1976 | split_offset = 0; |
| 1977 | do { |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1978 | /* setup PDE5 with what we have */ |
| 1979 | pde5 = (struct lpfc_pde5 *) bpl; |
| 1980 | memset(pde5, 0, sizeof(struct lpfc_pde5)); |
| 1981 | bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1982 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1983 | /* Endianness conversion if necessary for PDE5 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1984 | pde5->word0 = cpu_to_le32(pde5->word0); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1985 | pde5->reftag = cpu_to_le32(reftag); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1986 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1987 | /* advance bpl and increment bde count */ |
| 1988 | num_bde++; |
| 1989 | bpl++; |
| 1990 | pde6 = (struct lpfc_pde6 *) bpl; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1991 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1992 | /* setup PDE6 with the rest of the info */ |
| 1993 | memset(pde6, 0, sizeof(struct lpfc_pde6)); |
| 1994 | bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR); |
| 1995 | bf_set(pde6_optx, pde6, txop); |
| 1996 | bf_set(pde6_oprx, pde6, rxop); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1997 | bf_set(pde6_ce, pde6, checking); |
| 1998 | bf_set(pde6_re, pde6, checking); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1999 | bf_set(pde6_ai, pde6, 1); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2000 | bf_set(pde6_ae, pde6, 0); |
| 2001 | bf_set(pde6_apptagval, pde6, 0); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2002 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 2003 | /* Endianness conversion if necessary for PDE6 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 2004 | pde6->word0 = cpu_to_le32(pde6->word0); |
| 2005 | pde6->word1 = cpu_to_le32(pde6->word1); |
| 2006 | pde6->word2 = cpu_to_le32(pde6->word2); |
| 2007 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2008 | /* advance bpl and increment bde count */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2009 | num_bde++; |
| 2010 | bpl++; |
| 2011 | |
| 2012 | /* setup the first BDE that points to protection buffer */ |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2013 | protphysaddr = sg_dma_address(sgpe) + protgroup_offset; |
| 2014 | protgroup_len = sg_dma_len(sgpe) - protgroup_offset; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2015 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2016 | /* must be integer multiple of the DIF block length */ |
| 2017 | BUG_ON(protgroup_len % 8); |
| 2018 | |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2019 | pde7 = (struct lpfc_pde7 *) bpl; |
| 2020 | memset(pde7, 0, sizeof(struct lpfc_pde7)); |
| 2021 | bf_set(pde7_type, pde7, LPFC_PDE7_DESCRIPTOR); |
| 2022 | |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2023 | pde7->addrHigh = le32_to_cpu(putPaddrHigh(protphysaddr)); |
| 2024 | pde7->addrLow = le32_to_cpu(putPaddrLow(protphysaddr)); |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2025 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2026 | protgrp_blks = protgroup_len / 8; |
| 2027 | protgrp_bytes = protgrp_blks * blksize; |
| 2028 | |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2029 | /* check if this pde is crossing the 4K boundary; if so split */ |
| 2030 | if ((pde7->addrLow & 0xfff) + protgroup_len > 0x1000) { |
| 2031 | protgroup_remainder = 0x1000 - (pde7->addrLow & 0xfff); |
| 2032 | protgroup_offset += protgroup_remainder; |
| 2033 | protgrp_blks = protgroup_remainder / 8; |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2034 | protgrp_bytes = protgrp_blks * blksize; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2035 | } else { |
| 2036 | protgroup_offset = 0; |
| 2037 | curr_prot++; |
| 2038 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2039 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2040 | num_bde++; |
| 2041 | |
| 2042 | /* setup BDE's for data blocks associated with DIF data */ |
| 2043 | pgdone = 0; |
| 2044 | subtotal = 0; /* total bytes processed for current prot grp */ |
| 2045 | while (!pgdone) { |
| 2046 | if (!sgde) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2047 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2048 | "9065 BLKGRD:%s Invalid data segment\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2049 | __func__); |
| 2050 | return 0; |
| 2051 | } |
| 2052 | bpl++; |
| 2053 | dataphysaddr = sg_dma_address(sgde) + split_offset; |
| 2054 | bpl->addrLow = le32_to_cpu(putPaddrLow(dataphysaddr)); |
| 2055 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(dataphysaddr)); |
| 2056 | |
| 2057 | remainder = sg_dma_len(sgde) - split_offset; |
| 2058 | |
| 2059 | if ((subtotal + remainder) <= protgrp_bytes) { |
| 2060 | /* we can use this whole buffer */ |
| 2061 | bpl->tus.f.bdeSize = remainder; |
| 2062 | split_offset = 0; |
| 2063 | |
| 2064 | if ((subtotal + remainder) == protgrp_bytes) |
| 2065 | pgdone = 1; |
| 2066 | } else { |
| 2067 | /* must split this buffer with next prot grp */ |
| 2068 | bpl->tus.f.bdeSize = protgrp_bytes - subtotal; |
| 2069 | split_offset += bpl->tus.f.bdeSize; |
| 2070 | } |
| 2071 | |
| 2072 | subtotal += bpl->tus.f.bdeSize; |
| 2073 | |
| 2074 | if (datadir == DMA_TO_DEVICE) |
| 2075 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 2076 | else |
| 2077 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
| 2078 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 2079 | |
| 2080 | num_bde++; |
| 2081 | curr_data++; |
| 2082 | |
| 2083 | if (split_offset) |
| 2084 | break; |
| 2085 | |
| 2086 | /* Move to the next s/g segment if possible */ |
| 2087 | sgde = sg_next(sgde); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2088 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2089 | } |
| 2090 | |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2091 | if (protgroup_offset) { |
| 2092 | /* update the reference tag */ |
| 2093 | reftag += protgrp_blks; |
| 2094 | bpl++; |
| 2095 | continue; |
| 2096 | } |
| 2097 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2098 | /* are we done ? */ |
| 2099 | if (curr_prot == protcnt) { |
| 2100 | alldone = 1; |
| 2101 | } else if (curr_prot < protcnt) { |
| 2102 | /* advance to next prot buffer */ |
| 2103 | sgpe = sg_next(sgpe); |
| 2104 | bpl++; |
| 2105 | |
| 2106 | /* update the reference tag */ |
| 2107 | reftag += protgrp_blks; |
| 2108 | } else { |
| 2109 | /* if we're here, we have a bug */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2110 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2111 | "9054 BLKGRD: bug in %s\n", __func__); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2112 | } |
| 2113 | |
| 2114 | } while (!alldone); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2115 | out: |
| 2116 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2117 | return num_bde; |
| 2118 | } |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2119 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2120 | /** |
| 2121 | * lpfc_bg_setup_sgl - Setup BlockGuard SGL with no protection data |
| 2122 | * @phba: The Hba for which this call is being executed. |
| 2123 | * @sc: pointer to scsi command we're working on |
| 2124 | * @sgl: pointer to buffer list for protection groups |
| 2125 | * @datacnt: number of segments of data that have been dma mapped |
| 2126 | * |
| 2127 | * This function sets up SGL buffer list for protection groups of |
| 2128 | * type LPFC_PG_TYPE_NO_DIF |
| 2129 | * |
| 2130 | * This is usually used when the HBA is instructed to generate |
| 2131 | * DIFs and insert them into data stream (or strip DIF from |
| 2132 | * incoming data stream) |
| 2133 | * |
| 2134 | * The buffer list consists of just one protection group described |
| 2135 | * below: |
| 2136 | * +-------------------------+ |
| 2137 | * start of prot group --> | DI_SEED | |
| 2138 | * +-------------------------+ |
| 2139 | * | Data SGE | |
| 2140 | * +-------------------------+ |
| 2141 | * |more Data SGE's ... (opt)| |
| 2142 | * +-------------------------+ |
| 2143 | * |
| 2144 | * |
| 2145 | * Note: Data s/g buffers have been dma mapped |
| 2146 | * |
| 2147 | * Returns the number of SGEs added to the SGL. |
| 2148 | **/ |
| 2149 | static int |
| 2150 | lpfc_bg_setup_sgl(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 2151 | struct sli4_sge *sgl, int datasegcnt) |
| 2152 | { |
| 2153 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 2154 | struct sli4_sge_diseed *diseed = NULL; |
| 2155 | dma_addr_t physaddr; |
| 2156 | int i = 0, num_sge = 0, status; |
| 2157 | int datadir = sc->sc_data_direction; |
| 2158 | uint32_t reftag; |
| 2159 | unsigned blksize; |
| 2160 | uint8_t txop, rxop; |
| 2161 | uint32_t rc; |
| 2162 | uint32_t checking = 1; |
| 2163 | uint32_t dma_len; |
| 2164 | uint32_t dma_offset = 0; |
| 2165 | |
| 2166 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 2167 | if (status) |
| 2168 | goto out; |
| 2169 | |
| 2170 | /* extract some info from the scsi command for pde*/ |
| 2171 | blksize = lpfc_cmd_blksize(sc); |
| 2172 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
| 2173 | |
| 2174 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 2175 | rc = lpfc_bg_err_inject(phba, sc, &reftag, 0, 1); |
| 2176 | if (rc) { |
| 2177 | if (rc == BG_ERR_SWAP) |
| 2178 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
| 2179 | if (rc == BG_ERR_CHECK) |
| 2180 | checking = 0; |
| 2181 | } |
| 2182 | #endif |
| 2183 | |
| 2184 | /* setup DISEED with what we have */ |
| 2185 | diseed = (struct sli4_sge_diseed *) sgl; |
| 2186 | memset(diseed, 0, sizeof(struct sli4_sge_diseed)); |
| 2187 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED); |
| 2188 | |
| 2189 | /* Endianness conversion if necessary */ |
| 2190 | diseed->ref_tag = cpu_to_le32(reftag); |
| 2191 | diseed->ref_tag_tran = diseed->ref_tag; |
| 2192 | |
| 2193 | /* setup DISEED with the rest of the info */ |
| 2194 | bf_set(lpfc_sli4_sge_dif_optx, diseed, txop); |
| 2195 | bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop); |
| 2196 | if (datadir == DMA_FROM_DEVICE) { |
| 2197 | bf_set(lpfc_sli4_sge_dif_ce, diseed, checking); |
| 2198 | bf_set(lpfc_sli4_sge_dif_re, diseed, checking); |
| 2199 | } |
| 2200 | bf_set(lpfc_sli4_sge_dif_ai, diseed, 1); |
| 2201 | bf_set(lpfc_sli4_sge_dif_me, diseed, 0); |
| 2202 | |
| 2203 | /* Endianness conversion if necessary for DISEED */ |
| 2204 | diseed->word2 = cpu_to_le32(diseed->word2); |
| 2205 | diseed->word3 = cpu_to_le32(diseed->word3); |
| 2206 | |
| 2207 | /* advance bpl and increment sge count */ |
| 2208 | num_sge++; |
| 2209 | sgl++; |
| 2210 | |
| 2211 | /* assumption: caller has already run dma_map_sg on command data */ |
| 2212 | scsi_for_each_sg(sc, sgde, datasegcnt, i) { |
| 2213 | physaddr = sg_dma_address(sgde); |
| 2214 | dma_len = sg_dma_len(sgde); |
| 2215 | sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr)); |
| 2216 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr)); |
| 2217 | if ((i + 1) == datasegcnt) |
| 2218 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 2219 | else |
| 2220 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 2221 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
| 2222 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); |
| 2223 | |
| 2224 | sgl->sge_len = cpu_to_le32(dma_len); |
| 2225 | dma_offset += dma_len; |
| 2226 | |
| 2227 | sgl++; |
| 2228 | num_sge++; |
| 2229 | } |
| 2230 | |
| 2231 | out: |
| 2232 | return num_sge; |
| 2233 | } |
| 2234 | |
| 2235 | /** |
| 2236 | * lpfc_bg_setup_sgl_prot - Setup BlockGuard SGL with protection data |
| 2237 | * @phba: The Hba for which this call is being executed. |
| 2238 | * @sc: pointer to scsi command we're working on |
| 2239 | * @sgl: pointer to buffer list for protection groups |
| 2240 | * @datacnt: number of segments of data that have been dma mapped |
| 2241 | * @protcnt: number of segment of protection data that have been dma mapped |
| 2242 | * |
| 2243 | * This function sets up SGL buffer list for protection groups of |
| 2244 | * type LPFC_PG_TYPE_DIF |
| 2245 | * |
| 2246 | * This is usually used when DIFs are in their own buffers, |
| 2247 | * separate from the data. The HBA can then by instructed |
| 2248 | * to place the DIFs in the outgoing stream. For read operations, |
| 2249 | * The HBA could extract the DIFs and place it in DIF buffers. |
| 2250 | * |
| 2251 | * The buffer list for this type consists of one or more of the |
| 2252 | * protection groups described below: |
| 2253 | * +-------------------------+ |
| 2254 | * start of first prot group --> | DISEED | |
| 2255 | * +-------------------------+ |
| 2256 | * | DIF (Prot SGE) | |
| 2257 | * +-------------------------+ |
| 2258 | * | Data SGE | |
| 2259 | * +-------------------------+ |
| 2260 | * |more Data SGE's ... (opt)| |
| 2261 | * +-------------------------+ |
| 2262 | * start of new prot group --> | DISEED | |
| 2263 | * +-------------------------+ |
| 2264 | * | ... | |
| 2265 | * +-------------------------+ |
| 2266 | * |
| 2267 | * Note: It is assumed that both data and protection s/g buffers have been |
| 2268 | * mapped for DMA |
| 2269 | * |
| 2270 | * Returns the number of SGEs added to the SGL. |
| 2271 | **/ |
| 2272 | static int |
| 2273 | lpfc_bg_setup_sgl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 2274 | struct sli4_sge *sgl, int datacnt, int protcnt) |
| 2275 | { |
| 2276 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 2277 | struct scatterlist *sgpe = NULL; /* s/g prot entry */ |
| 2278 | struct sli4_sge_diseed *diseed = NULL; |
| 2279 | dma_addr_t dataphysaddr, protphysaddr; |
| 2280 | unsigned short curr_data = 0, curr_prot = 0; |
| 2281 | unsigned int split_offset; |
| 2282 | unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder; |
| 2283 | unsigned int protgrp_blks, protgrp_bytes; |
| 2284 | unsigned int remainder, subtotal; |
| 2285 | int status; |
| 2286 | unsigned char pgdone = 0, alldone = 0; |
| 2287 | unsigned blksize; |
| 2288 | uint32_t reftag; |
| 2289 | uint8_t txop, rxop; |
| 2290 | uint32_t dma_len; |
| 2291 | uint32_t rc; |
| 2292 | uint32_t checking = 1; |
| 2293 | uint32_t dma_offset = 0; |
| 2294 | int num_sge = 0; |
| 2295 | |
| 2296 | sgpe = scsi_prot_sglist(sc); |
| 2297 | sgde = scsi_sglist(sc); |
| 2298 | |
| 2299 | if (!sgpe || !sgde) { |
| 2300 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2301 | "9082 Invalid s/g entry: data=0x%p prot=0x%p\n", |
| 2302 | sgpe, sgde); |
| 2303 | return 0; |
| 2304 | } |
| 2305 | |
| 2306 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 2307 | if (status) |
| 2308 | goto out; |
| 2309 | |
| 2310 | /* extract some info from the scsi command */ |
| 2311 | blksize = lpfc_cmd_blksize(sc); |
| 2312 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
| 2313 | |
| 2314 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 2315 | rc = lpfc_bg_err_inject(phba, sc, &reftag, 0, 1); |
| 2316 | if (rc) { |
| 2317 | if (rc == BG_ERR_SWAP) |
| 2318 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
| 2319 | if (rc == BG_ERR_CHECK) |
| 2320 | checking = 0; |
| 2321 | } |
| 2322 | #endif |
| 2323 | |
| 2324 | split_offset = 0; |
| 2325 | do { |
| 2326 | /* setup DISEED with what we have */ |
| 2327 | diseed = (struct sli4_sge_diseed *) sgl; |
| 2328 | memset(diseed, 0, sizeof(struct sli4_sge_diseed)); |
| 2329 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED); |
| 2330 | |
| 2331 | /* Endianness conversion if necessary */ |
| 2332 | diseed->ref_tag = cpu_to_le32(reftag); |
| 2333 | diseed->ref_tag_tran = diseed->ref_tag; |
| 2334 | |
| 2335 | /* setup DISEED with the rest of the info */ |
| 2336 | bf_set(lpfc_sli4_sge_dif_optx, diseed, txop); |
| 2337 | bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop); |
| 2338 | bf_set(lpfc_sli4_sge_dif_ce, diseed, checking); |
| 2339 | bf_set(lpfc_sli4_sge_dif_re, diseed, checking); |
| 2340 | bf_set(lpfc_sli4_sge_dif_ai, diseed, 1); |
| 2341 | bf_set(lpfc_sli4_sge_dif_me, diseed, 0); |
| 2342 | |
| 2343 | /* Endianness conversion if necessary for DISEED */ |
| 2344 | diseed->word2 = cpu_to_le32(diseed->word2); |
| 2345 | diseed->word3 = cpu_to_le32(diseed->word3); |
| 2346 | |
| 2347 | /* advance sgl and increment bde count */ |
| 2348 | num_sge++; |
| 2349 | sgl++; |
| 2350 | |
| 2351 | /* setup the first BDE that points to protection buffer */ |
| 2352 | protphysaddr = sg_dma_address(sgpe) + protgroup_offset; |
| 2353 | protgroup_len = sg_dma_len(sgpe) - protgroup_offset; |
| 2354 | |
| 2355 | /* must be integer multiple of the DIF block length */ |
| 2356 | BUG_ON(protgroup_len % 8); |
| 2357 | |
| 2358 | /* Now setup DIF SGE */ |
| 2359 | sgl->word2 = 0; |
| 2360 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DIF); |
| 2361 | sgl->addr_hi = le32_to_cpu(putPaddrHigh(protphysaddr)); |
| 2362 | sgl->addr_lo = le32_to_cpu(putPaddrLow(protphysaddr)); |
| 2363 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 2364 | |
| 2365 | protgrp_blks = protgroup_len / 8; |
| 2366 | protgrp_bytes = protgrp_blks * blksize; |
| 2367 | |
| 2368 | /* check if DIF SGE is crossing the 4K boundary; if so split */ |
| 2369 | if ((sgl->addr_lo & 0xfff) + protgroup_len > 0x1000) { |
| 2370 | protgroup_remainder = 0x1000 - (sgl->addr_lo & 0xfff); |
| 2371 | protgroup_offset += protgroup_remainder; |
| 2372 | protgrp_blks = protgroup_remainder / 8; |
| 2373 | protgrp_bytes = protgrp_blks * blksize; |
| 2374 | } else { |
| 2375 | protgroup_offset = 0; |
| 2376 | curr_prot++; |
| 2377 | } |
| 2378 | |
| 2379 | num_sge++; |
| 2380 | |
| 2381 | /* setup SGE's for data blocks associated with DIF data */ |
| 2382 | pgdone = 0; |
| 2383 | subtotal = 0; /* total bytes processed for current prot grp */ |
| 2384 | while (!pgdone) { |
| 2385 | if (!sgde) { |
| 2386 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2387 | "9086 BLKGRD:%s Invalid data segment\n", |
| 2388 | __func__); |
| 2389 | return 0; |
| 2390 | } |
| 2391 | sgl++; |
| 2392 | dataphysaddr = sg_dma_address(sgde) + split_offset; |
| 2393 | |
| 2394 | remainder = sg_dma_len(sgde) - split_offset; |
| 2395 | |
| 2396 | if ((subtotal + remainder) <= protgrp_bytes) { |
| 2397 | /* we can use this whole buffer */ |
| 2398 | dma_len = remainder; |
| 2399 | split_offset = 0; |
| 2400 | |
| 2401 | if ((subtotal + remainder) == protgrp_bytes) |
| 2402 | pgdone = 1; |
| 2403 | } else { |
| 2404 | /* must split this buffer with next prot grp */ |
| 2405 | dma_len = protgrp_bytes - subtotal; |
| 2406 | split_offset += dma_len; |
| 2407 | } |
| 2408 | |
| 2409 | subtotal += dma_len; |
| 2410 | |
| 2411 | sgl->addr_lo = cpu_to_le32(putPaddrLow(dataphysaddr)); |
| 2412 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(dataphysaddr)); |
| 2413 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 2414 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
| 2415 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); |
| 2416 | |
| 2417 | sgl->sge_len = cpu_to_le32(dma_len); |
| 2418 | dma_offset += dma_len; |
| 2419 | |
| 2420 | num_sge++; |
| 2421 | curr_data++; |
| 2422 | |
| 2423 | if (split_offset) |
| 2424 | break; |
| 2425 | |
| 2426 | /* Move to the next s/g segment if possible */ |
| 2427 | sgde = sg_next(sgde); |
| 2428 | } |
| 2429 | |
| 2430 | if (protgroup_offset) { |
| 2431 | /* update the reference tag */ |
| 2432 | reftag += protgrp_blks; |
| 2433 | sgl++; |
| 2434 | continue; |
| 2435 | } |
| 2436 | |
| 2437 | /* are we done ? */ |
| 2438 | if (curr_prot == protcnt) { |
| 2439 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 2440 | alldone = 1; |
| 2441 | } else if (curr_prot < protcnt) { |
| 2442 | /* advance to next prot buffer */ |
| 2443 | sgpe = sg_next(sgpe); |
| 2444 | sgl++; |
| 2445 | |
| 2446 | /* update the reference tag */ |
| 2447 | reftag += protgrp_blks; |
| 2448 | } else { |
| 2449 | /* if we're here, we have a bug */ |
| 2450 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2451 | "9085 BLKGRD: bug in %s\n", __func__); |
| 2452 | } |
| 2453 | |
| 2454 | } while (!alldone); |
| 2455 | |
| 2456 | out: |
| 2457 | |
| 2458 | return num_sge; |
| 2459 | } |
| 2460 | |
| 2461 | /** |
| 2462 | * lpfc_prot_group_type - Get prtotection group type of SCSI command |
| 2463 | * @phba: The Hba for which this call is being executed. |
| 2464 | * @sc: pointer to scsi command we're working on |
| 2465 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2466 | * Given a SCSI command that supports DIF, determine composition of protection |
| 2467 | * groups involved in setting up buffer lists |
| 2468 | * |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2469 | * Returns: Protection group type (with or without DIF) |
| 2470 | * |
| 2471 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2472 | static int |
| 2473 | lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc) |
| 2474 | { |
| 2475 | int ret = LPFC_PG_TYPE_INVALID; |
| 2476 | unsigned char op = scsi_get_prot_op(sc); |
| 2477 | |
| 2478 | switch (op) { |
| 2479 | case SCSI_PROT_READ_STRIP: |
| 2480 | case SCSI_PROT_WRITE_INSERT: |
| 2481 | ret = LPFC_PG_TYPE_NO_DIF; |
| 2482 | break; |
| 2483 | case SCSI_PROT_READ_INSERT: |
| 2484 | case SCSI_PROT_WRITE_STRIP: |
| 2485 | case SCSI_PROT_READ_PASS: |
| 2486 | case SCSI_PROT_WRITE_PASS: |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2487 | ret = LPFC_PG_TYPE_DIF_BUF; |
| 2488 | break; |
| 2489 | default: |
| 2490 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2491 | "9021 Unsupported protection op:%d\n", op); |
| 2492 | break; |
| 2493 | } |
| 2494 | |
| 2495 | return ret; |
| 2496 | } |
| 2497 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2498 | /** |
| 2499 | * lpfc_bg_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec |
| 2500 | * @phba: The Hba for which this call is being executed. |
| 2501 | * @lpfc_cmd: The scsi buffer which is going to be prep'ed. |
| 2502 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2503 | * This is the protection/DIF aware version of |
| 2504 | * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the |
| 2505 | * two functions eventually, but for now, it's here |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2506 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2507 | static int |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2508 | lpfc_bg_scsi_prep_dma_buf_s3(struct lpfc_hba *phba, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2509 | struct lpfc_scsi_buf *lpfc_cmd) |
| 2510 | { |
| 2511 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 2512 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 2513 | struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl; |
| 2514 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 2515 | uint32_t num_bde = 0; |
| 2516 | int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction; |
| 2517 | int prot_group_type = 0; |
| 2518 | int diflen, fcpdl; |
| 2519 | unsigned blksize; |
| 2520 | |
| 2521 | /* |
| 2522 | * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd |
| 2523 | * fcp_rsp regions to the first data bde entry |
| 2524 | */ |
| 2525 | bpl += 2; |
| 2526 | if (scsi_sg_count(scsi_cmnd)) { |
| 2527 | /* |
| 2528 | * The driver stores the segment count returned from pci_map_sg |
| 2529 | * because this a count of dma-mappings used to map the use_sg |
| 2530 | * pages. They are not guaranteed to be the same for those |
| 2531 | * architectures that implement an IOMMU. |
| 2532 | */ |
| 2533 | datasegcnt = dma_map_sg(&phba->pcidev->dev, |
| 2534 | scsi_sglist(scsi_cmnd), |
| 2535 | scsi_sg_count(scsi_cmnd), datadir); |
| 2536 | if (unlikely(!datasegcnt)) |
| 2537 | return 1; |
| 2538 | |
| 2539 | lpfc_cmd->seg_cnt = datasegcnt; |
| 2540 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2541 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2542 | "9067 BLKGRD: %s: Too many sg segments" |
| 2543 | " from dma_map_sg. Config %d, seg_cnt" |
| 2544 | " %d\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2545 | __func__, phba->cfg_sg_seg_cnt, |
| 2546 | lpfc_cmd->seg_cnt); |
| 2547 | scsi_dma_unmap(scsi_cmnd); |
| 2548 | return 1; |
| 2549 | } |
| 2550 | |
| 2551 | prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd); |
| 2552 | |
| 2553 | switch (prot_group_type) { |
| 2554 | case LPFC_PG_TYPE_NO_DIF: |
| 2555 | num_bde = lpfc_bg_setup_bpl(phba, scsi_cmnd, bpl, |
| 2556 | datasegcnt); |
Adam Buchbinder | c9404c9 | 2009-12-18 15:40:42 -0500 | [diff] [blame] | 2557 | /* we should have 2 or more entries in buffer list */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2558 | if (num_bde < 2) |
| 2559 | goto err; |
| 2560 | break; |
| 2561 | case LPFC_PG_TYPE_DIF_BUF:{ |
| 2562 | /* |
| 2563 | * This type indicates that protection buffers are |
| 2564 | * passed to the driver, so that needs to be prepared |
| 2565 | * for DMA |
| 2566 | */ |
| 2567 | protsegcnt = dma_map_sg(&phba->pcidev->dev, |
| 2568 | scsi_prot_sglist(scsi_cmnd), |
| 2569 | scsi_prot_sg_count(scsi_cmnd), datadir); |
| 2570 | if (unlikely(!protsegcnt)) { |
| 2571 | scsi_dma_unmap(scsi_cmnd); |
| 2572 | return 1; |
| 2573 | } |
| 2574 | |
| 2575 | lpfc_cmd->prot_seg_cnt = protsegcnt; |
| 2576 | if (lpfc_cmd->prot_seg_cnt |
| 2577 | > phba->cfg_prot_sg_seg_cnt) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2578 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2579 | "9068 BLKGRD: %s: Too many prot sg " |
| 2580 | "segments from dma_map_sg. Config %d," |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2581 | "prot_seg_cnt %d\n", __func__, |
| 2582 | phba->cfg_prot_sg_seg_cnt, |
| 2583 | lpfc_cmd->prot_seg_cnt); |
| 2584 | dma_unmap_sg(&phba->pcidev->dev, |
| 2585 | scsi_prot_sglist(scsi_cmnd), |
| 2586 | scsi_prot_sg_count(scsi_cmnd), |
| 2587 | datadir); |
| 2588 | scsi_dma_unmap(scsi_cmnd); |
| 2589 | return 1; |
| 2590 | } |
| 2591 | |
| 2592 | num_bde = lpfc_bg_setup_bpl_prot(phba, scsi_cmnd, bpl, |
| 2593 | datasegcnt, protsegcnt); |
Adam Buchbinder | c9404c9 | 2009-12-18 15:40:42 -0500 | [diff] [blame] | 2594 | /* we should have 3 or more entries in buffer list */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2595 | if (num_bde < 3) |
| 2596 | goto err; |
| 2597 | break; |
| 2598 | } |
| 2599 | case LPFC_PG_TYPE_INVALID: |
| 2600 | default: |
| 2601 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2602 | "9022 Unexpected protection group %i\n", |
| 2603 | prot_group_type); |
| 2604 | return 1; |
| 2605 | } |
| 2606 | } |
| 2607 | |
| 2608 | /* |
| 2609 | * Finish initializing those IOCB fields that are dependent on the |
| 2610 | * scsi_cmnd request_buffer. Note that the bdeSize is explicitly |
| 2611 | * reinitialized since all iocb memory resources are used many times |
| 2612 | * for transmit, receive, and continuation bpl's. |
| 2613 | */ |
| 2614 | iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| 2615 | iocb_cmd->un.fcpi64.bdl.bdeSize += (num_bde * sizeof(struct ulp_bde64)); |
| 2616 | iocb_cmd->ulpBdeCount = 1; |
| 2617 | iocb_cmd->ulpLe = 1; |
| 2618 | |
| 2619 | fcpdl = scsi_bufflen(scsi_cmnd); |
| 2620 | |
| 2621 | if (scsi_get_prot_type(scsi_cmnd) == SCSI_PROT_DIF_TYPE1) { |
| 2622 | /* |
| 2623 | * We are in DIF Type 1 mode |
| 2624 | * Every data block has a 8 byte DIF (trailer) |
| 2625 | * attached to it. Must ajust FCP data length |
| 2626 | */ |
| 2627 | blksize = lpfc_cmd_blksize(scsi_cmnd); |
| 2628 | diflen = (fcpdl / blksize) * 8; |
| 2629 | fcpdl += diflen; |
| 2630 | } |
| 2631 | fcp_cmnd->fcpDl = be32_to_cpu(fcpdl); |
| 2632 | |
| 2633 | /* |
| 2634 | * Due to difference in data length between DIF/non-DIF paths, |
| 2635 | * we need to set word 4 of IOCB here |
| 2636 | */ |
| 2637 | iocb_cmd->un.fcpi.fcpi_parm = fcpdl; |
| 2638 | |
| 2639 | return 0; |
| 2640 | err: |
| 2641 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2642 | "9023 Could not setup all needed BDE's" |
| 2643 | "prot_group_type=%d, num_bde=%d\n", |
| 2644 | prot_group_type, num_bde); |
| 2645 | return 1; |
| 2646 | } |
| 2647 | |
| 2648 | /* |
| 2649 | * This function checks for BlockGuard errors detected by |
| 2650 | * the HBA. In case of errors, the ASC/ASCQ fields in the |
| 2651 | * sense buffer will be set accordingly, paired with |
| 2652 | * ILLEGAL_REQUEST to signal to the kernel that the HBA |
| 2653 | * detected corruption. |
| 2654 | * |
| 2655 | * Returns: |
| 2656 | * 0 - No error found |
| 2657 | * 1 - BlockGuard error found |
| 2658 | * -1 - Internal error (bad profile, ...etc) |
| 2659 | */ |
| 2660 | static int |
| 2661 | lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd, |
| 2662 | struct lpfc_iocbq *pIocbOut) |
| 2663 | { |
| 2664 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 2665 | struct sli3_bg_fields *bgf = &pIocbOut->iocb.unsli3.sli3_bg; |
| 2666 | int ret = 0; |
| 2667 | uint32_t bghm = bgf->bghm; |
| 2668 | uint32_t bgstat = bgf->bgstat; |
| 2669 | uint64_t failing_sector = 0; |
| 2670 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2671 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9069 BLKGRD: BG ERROR in cmd" |
| 2672 | " 0x%x lba 0x%llx blk cnt 0x%x " |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2673 | "bgstat=0x%x bghm=0x%x\n", |
James Smart | 87b5c32 | 2008-12-16 10:34:09 -0500 | [diff] [blame] | 2674 | cmd->cmnd[0], (unsigned long long)scsi_get_lba(cmd), |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 2675 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2676 | |
| 2677 | spin_lock(&_dump_buf_lock); |
| 2678 | if (!_dump_buf_done) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2679 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9070 BLKGRD: Saving" |
| 2680 | " Data for %u blocks to debugfs\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2681 | (cmd->cmnd[7] << 8 | cmd->cmnd[8])); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2682 | lpfc_debug_save_data(phba, cmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2683 | |
| 2684 | /* If we have a prot sgl, save the DIF buffer */ |
| 2685 | if (lpfc_prot_group_type(phba, cmd) == |
| 2686 | LPFC_PG_TYPE_DIF_BUF) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2687 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9071 BLKGRD: " |
| 2688 | "Saving DIF for %u blocks to debugfs\n", |
| 2689 | (cmd->cmnd[7] << 8 | cmd->cmnd[8])); |
| 2690 | lpfc_debug_save_dif(phba, cmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2691 | } |
| 2692 | |
| 2693 | _dump_buf_done = 1; |
| 2694 | } |
| 2695 | spin_unlock(&_dump_buf_lock); |
| 2696 | |
| 2697 | if (lpfc_bgs_get_invalid_prof(bgstat)) { |
| 2698 | cmd->result = ScsiResult(DID_ERROR, 0); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2699 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9072 BLKGRD: Invalid" |
| 2700 | " BlockGuard profile. bgstat:0x%x\n", |
| 2701 | bgstat); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2702 | ret = (-1); |
| 2703 | goto out; |
| 2704 | } |
| 2705 | |
| 2706 | if (lpfc_bgs_get_uninit_dif_block(bgstat)) { |
| 2707 | cmd->result = ScsiResult(DID_ERROR, 0); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2708 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9073 BLKGRD: " |
| 2709 | "Invalid BlockGuard DIF Block. bgstat:0x%x\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2710 | bgstat); |
| 2711 | ret = (-1); |
| 2712 | goto out; |
| 2713 | } |
| 2714 | |
| 2715 | if (lpfc_bgs_get_guard_err(bgstat)) { |
| 2716 | ret = 1; |
| 2717 | |
| 2718 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 2719 | 0x10, 0x1); |
Martin K. Petersen | 1c9fbaf | 2009-01-04 03:14:11 -0500 | [diff] [blame] | 2720 | cmd->result = DRIVER_SENSE << 24 |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2721 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 2722 | phba->bg_guard_err_cnt++; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2723 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2724 | "9055 BLKGRD: guard_tag error\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2725 | } |
| 2726 | |
| 2727 | if (lpfc_bgs_get_reftag_err(bgstat)) { |
| 2728 | ret = 1; |
| 2729 | |
| 2730 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 2731 | 0x10, 0x3); |
Martin K. Petersen | 1c9fbaf | 2009-01-04 03:14:11 -0500 | [diff] [blame] | 2732 | cmd->result = DRIVER_SENSE << 24 |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2733 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 2734 | |
| 2735 | phba->bg_reftag_err_cnt++; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2736 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2737 | "9056 BLKGRD: ref_tag error\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2738 | } |
| 2739 | |
| 2740 | if (lpfc_bgs_get_apptag_err(bgstat)) { |
| 2741 | ret = 1; |
| 2742 | |
| 2743 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 2744 | 0x10, 0x2); |
Martin K. Petersen | 1c9fbaf | 2009-01-04 03:14:11 -0500 | [diff] [blame] | 2745 | cmd->result = DRIVER_SENSE << 24 |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2746 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 2747 | |
| 2748 | phba->bg_apptag_err_cnt++; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2749 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2750 | "9061 BLKGRD: app_tag error\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2751 | } |
| 2752 | |
| 2753 | if (lpfc_bgs_get_hi_water_mark_present(bgstat)) { |
| 2754 | /* |
| 2755 | * setup sense data descriptor 0 per SPC-4 as an information |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2756 | * field, and put the failing LBA in it. |
| 2757 | * This code assumes there was also a guard/app/ref tag error |
| 2758 | * indication. |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2759 | */ |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2760 | cmd->sense_buffer[7] = 0xc; /* Additional sense length */ |
| 2761 | cmd->sense_buffer[8] = 0; /* Information descriptor type */ |
| 2762 | cmd->sense_buffer[9] = 0xa; /* Additional descriptor length */ |
| 2763 | cmd->sense_buffer[10] = 0x80; /* Validity bit */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2764 | |
| 2765 | /* bghm is a "on the wire" FC frame based count */ |
| 2766 | switch (scsi_get_prot_op(cmd)) { |
| 2767 | case SCSI_PROT_READ_INSERT: |
| 2768 | case SCSI_PROT_WRITE_STRIP: |
| 2769 | bghm /= cmd->device->sector_size; |
| 2770 | break; |
| 2771 | case SCSI_PROT_READ_STRIP: |
| 2772 | case SCSI_PROT_WRITE_INSERT: |
| 2773 | case SCSI_PROT_READ_PASS: |
| 2774 | case SCSI_PROT_WRITE_PASS: |
| 2775 | bghm /= (cmd->device->sector_size + |
| 2776 | sizeof(struct scsi_dif_tuple)); |
| 2777 | break; |
| 2778 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2779 | |
| 2780 | failing_sector = scsi_get_lba(cmd); |
| 2781 | failing_sector += bghm; |
| 2782 | |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2783 | /* Descriptor Information */ |
| 2784 | put_unaligned_be64(failing_sector, &cmd->sense_buffer[12]); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2785 | } |
| 2786 | |
| 2787 | if (!ret) { |
| 2788 | /* No error was reported - problem in FW? */ |
| 2789 | cmd->result = ScsiResult(DID_ERROR, 0); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2790 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2791 | "9057 BLKGRD: no errors reported!\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2792 | } |
| 2793 | |
| 2794 | out: |
| 2795 | return ret; |
| 2796 | } |
| 2797 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2798 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2799 | * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec |
| 2800 | * @phba: The Hba for which this call is being executed. |
| 2801 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 2802 | * |
| 2803 | * This routine does the pci dma mapping for scatter-gather list of scsi cmnd |
| 2804 | * field of @lpfc_cmd for device with SLI-4 interface spec. |
| 2805 | * |
| 2806 | * Return codes: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2807 | * 1 - Error |
| 2808 | * 0 - Success |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2809 | **/ |
| 2810 | static int |
| 2811 | lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 2812 | { |
| 2813 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 2814 | struct scatterlist *sgel = NULL; |
| 2815 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 2816 | struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 2817 | struct sli4_sge *first_data_sgl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2818 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 2819 | dma_addr_t physaddr; |
| 2820 | uint32_t num_bde = 0; |
| 2821 | uint32_t dma_len; |
| 2822 | uint32_t dma_offset = 0; |
| 2823 | int nseg; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 2824 | struct ulp_bde64 *bde; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2825 | |
| 2826 | /* |
| 2827 | * There are three possibilities here - use scatter-gather segment, use |
| 2828 | * the single mapping, or neither. Start the lpfc command prep by |
| 2829 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 2830 | * data bde entry. |
| 2831 | */ |
| 2832 | if (scsi_sg_count(scsi_cmnd)) { |
| 2833 | /* |
| 2834 | * The driver stores the segment count returned from pci_map_sg |
| 2835 | * because this a count of dma-mappings used to map the use_sg |
| 2836 | * pages. They are not guaranteed to be the same for those |
| 2837 | * architectures that implement an IOMMU. |
| 2838 | */ |
| 2839 | |
| 2840 | nseg = scsi_dma_map(scsi_cmnd); |
| 2841 | if (unlikely(!nseg)) |
| 2842 | return 1; |
| 2843 | sgl += 1; |
| 2844 | /* clear the last flag in the fcp_rsp map entry */ |
| 2845 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 2846 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 2847 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 2848 | sgl += 1; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 2849 | first_data_sgl = sgl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2850 | lpfc_cmd->seg_cnt = nseg; |
| 2851 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2852 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9074 BLKGRD:" |
| 2853 | " %s: Too many sg segments from " |
| 2854 | "dma_map_sg. Config %d, seg_cnt %d\n", |
| 2855 | __func__, phba->cfg_sg_seg_cnt, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2856 | lpfc_cmd->seg_cnt); |
| 2857 | scsi_dma_unmap(scsi_cmnd); |
| 2858 | return 1; |
| 2859 | } |
| 2860 | |
| 2861 | /* |
| 2862 | * The driver established a maximum scatter-gather segment count |
| 2863 | * during probe that limits the number of sg elements in any |
| 2864 | * single scsi command. Just run through the seg_cnt and format |
| 2865 | * the sge's. |
| 2866 | * When using SLI-3 the driver will try to fit all the BDEs into |
| 2867 | * the IOCB. If it can't then the BDEs get added to a BPL as it |
| 2868 | * does for SLI-2 mode. |
| 2869 | */ |
| 2870 | scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) { |
| 2871 | physaddr = sg_dma_address(sgel); |
| 2872 | dma_len = sg_dma_len(sgel); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2873 | sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr)); |
| 2874 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr)); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 2875 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2876 | if ((num_bde + 1) == nseg) |
| 2877 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 2878 | else |
| 2879 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 2880 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 2881 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2882 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 2883 | sgl->sge_len = cpu_to_le32(dma_len); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2884 | dma_offset += dma_len; |
| 2885 | sgl++; |
| 2886 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 2887 | /* setup the performance hint (first data BDE) if enabled */ |
| 2888 | if (phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) { |
| 2889 | bde = (struct ulp_bde64 *) |
| 2890 | &(iocb_cmd->unsli3.sli3Words[5]); |
| 2891 | bde->addrLow = first_data_sgl->addr_lo; |
| 2892 | bde->addrHigh = first_data_sgl->addr_hi; |
| 2893 | bde->tus.f.bdeSize = |
| 2894 | le32_to_cpu(first_data_sgl->sge_len); |
| 2895 | bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 2896 | bde->tus.w = cpu_to_le32(bde->tus.w); |
| 2897 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2898 | } else { |
| 2899 | sgl += 1; |
| 2900 | /* clear the last flag in the fcp_rsp map entry */ |
| 2901 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 2902 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 2903 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 2904 | } |
| 2905 | |
| 2906 | /* |
| 2907 | * Finish initializing those IOCB fields that are dependent on the |
| 2908 | * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is |
| 2909 | * explicitly reinitialized. |
| 2910 | * all iocb memory resources are reused. |
| 2911 | */ |
| 2912 | fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); |
| 2913 | |
| 2914 | /* |
| 2915 | * Due to difference in data length between DIF/non-DIF paths, |
| 2916 | * we need to set word 4 of IOCB here |
| 2917 | */ |
| 2918 | iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd); |
| 2919 | return 0; |
| 2920 | } |
| 2921 | |
| 2922 | /** |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2923 | * lpfc_bg_scsi_adjust_dl - Adjust SCSI data length for BlockGuard |
| 2924 | * @phba: The Hba for which this call is being executed. |
| 2925 | * @lpfc_cmd: The scsi buffer which is going to be adjusted. |
| 2926 | * |
| 2927 | * Adjust the data length to account for how much data |
| 2928 | * is actually on the wire. |
| 2929 | * |
| 2930 | * returns the adjusted data length |
| 2931 | **/ |
| 2932 | static int |
| 2933 | lpfc_bg_scsi_adjust_dl(struct lpfc_hba *phba, |
| 2934 | struct lpfc_scsi_buf *lpfc_cmd) |
| 2935 | { |
| 2936 | struct scsi_cmnd *sc = lpfc_cmd->pCmd; |
| 2937 | int diflen, fcpdl; |
| 2938 | unsigned blksize; |
| 2939 | |
| 2940 | fcpdl = scsi_bufflen(sc); |
| 2941 | |
| 2942 | /* Check if there is protection data on the wire */ |
| 2943 | if (sc->sc_data_direction == DMA_FROM_DEVICE) { |
| 2944 | /* Read */ |
| 2945 | if (scsi_get_prot_op(sc) == SCSI_PROT_READ_INSERT) |
| 2946 | return fcpdl; |
| 2947 | |
| 2948 | } else { |
| 2949 | /* Write */ |
| 2950 | if (scsi_get_prot_op(sc) == SCSI_PROT_WRITE_STRIP) |
| 2951 | return fcpdl; |
| 2952 | } |
| 2953 | |
| 2954 | /* If protection data on the wire, adjust the count accordingly */ |
| 2955 | blksize = lpfc_cmd_blksize(sc); |
| 2956 | diflen = (fcpdl / blksize) * 8; |
| 2957 | fcpdl += diflen; |
| 2958 | return fcpdl; |
| 2959 | } |
| 2960 | |
| 2961 | /** |
| 2962 | * lpfc_bg_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec |
| 2963 | * @phba: The Hba for which this call is being executed. |
| 2964 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 2965 | * |
| 2966 | * This is the protection/DIF aware version of |
| 2967 | * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the |
| 2968 | * two functions eventually, but for now, it's here |
| 2969 | **/ |
| 2970 | static int |
| 2971 | lpfc_bg_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, |
| 2972 | struct lpfc_scsi_buf *lpfc_cmd) |
| 2973 | { |
| 2974 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 2975 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 2976 | struct sli4_sge *sgl = (struct sli4_sge *)(lpfc_cmd->fcp_bpl); |
| 2977 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 2978 | uint32_t num_bde = 0; |
| 2979 | int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction; |
| 2980 | int prot_group_type = 0; |
| 2981 | int fcpdl; |
| 2982 | |
| 2983 | /* |
| 2984 | * Start the lpfc command prep by bumping the sgl beyond fcp_cmnd |
| 2985 | * fcp_rsp regions to the first data bde entry |
| 2986 | */ |
| 2987 | if (scsi_sg_count(scsi_cmnd)) { |
| 2988 | /* |
| 2989 | * The driver stores the segment count returned from pci_map_sg |
| 2990 | * because this a count of dma-mappings used to map the use_sg |
| 2991 | * pages. They are not guaranteed to be the same for those |
| 2992 | * architectures that implement an IOMMU. |
| 2993 | */ |
| 2994 | datasegcnt = dma_map_sg(&phba->pcidev->dev, |
| 2995 | scsi_sglist(scsi_cmnd), |
| 2996 | scsi_sg_count(scsi_cmnd), datadir); |
| 2997 | if (unlikely(!datasegcnt)) |
| 2998 | return 1; |
| 2999 | |
| 3000 | sgl += 1; |
| 3001 | /* clear the last flag in the fcp_rsp map entry */ |
| 3002 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 3003 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 3004 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 3005 | |
| 3006 | sgl += 1; |
| 3007 | lpfc_cmd->seg_cnt = datasegcnt; |
| 3008 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
| 3009 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 3010 | "9087 BLKGRD: %s: Too many sg segments" |
| 3011 | " from dma_map_sg. Config %d, seg_cnt" |
| 3012 | " %d\n", |
| 3013 | __func__, phba->cfg_sg_seg_cnt, |
| 3014 | lpfc_cmd->seg_cnt); |
| 3015 | scsi_dma_unmap(scsi_cmnd); |
| 3016 | return 1; |
| 3017 | } |
| 3018 | |
| 3019 | prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd); |
| 3020 | |
| 3021 | switch (prot_group_type) { |
| 3022 | case LPFC_PG_TYPE_NO_DIF: |
| 3023 | num_bde = lpfc_bg_setup_sgl(phba, scsi_cmnd, sgl, |
| 3024 | datasegcnt); |
| 3025 | /* we should have 2 or more entries in buffer list */ |
| 3026 | if (num_bde < 2) |
| 3027 | goto err; |
| 3028 | break; |
| 3029 | case LPFC_PG_TYPE_DIF_BUF:{ |
| 3030 | /* |
| 3031 | * This type indicates that protection buffers are |
| 3032 | * passed to the driver, so that needs to be prepared |
| 3033 | * for DMA |
| 3034 | */ |
| 3035 | protsegcnt = dma_map_sg(&phba->pcidev->dev, |
| 3036 | scsi_prot_sglist(scsi_cmnd), |
| 3037 | scsi_prot_sg_count(scsi_cmnd), datadir); |
| 3038 | if (unlikely(!protsegcnt)) { |
| 3039 | scsi_dma_unmap(scsi_cmnd); |
| 3040 | return 1; |
| 3041 | } |
| 3042 | |
| 3043 | lpfc_cmd->prot_seg_cnt = protsegcnt; |
| 3044 | if (lpfc_cmd->prot_seg_cnt |
| 3045 | > phba->cfg_prot_sg_seg_cnt) { |
| 3046 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 3047 | "9088 BLKGRD: %s: Too many prot sg " |
| 3048 | "segments from dma_map_sg. Config %d," |
| 3049 | "prot_seg_cnt %d\n", __func__, |
| 3050 | phba->cfg_prot_sg_seg_cnt, |
| 3051 | lpfc_cmd->prot_seg_cnt); |
| 3052 | dma_unmap_sg(&phba->pcidev->dev, |
| 3053 | scsi_prot_sglist(scsi_cmnd), |
| 3054 | scsi_prot_sg_count(scsi_cmnd), |
| 3055 | datadir); |
| 3056 | scsi_dma_unmap(scsi_cmnd); |
| 3057 | return 1; |
| 3058 | } |
| 3059 | |
| 3060 | num_bde = lpfc_bg_setup_sgl_prot(phba, scsi_cmnd, sgl, |
| 3061 | datasegcnt, protsegcnt); |
| 3062 | /* we should have 3 or more entries in buffer list */ |
| 3063 | if (num_bde < 3) |
| 3064 | goto err; |
| 3065 | break; |
| 3066 | } |
| 3067 | case LPFC_PG_TYPE_INVALID: |
| 3068 | default: |
| 3069 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 3070 | "9083 Unexpected protection group %i\n", |
| 3071 | prot_group_type); |
| 3072 | return 1; |
| 3073 | } |
| 3074 | } |
| 3075 | |
| 3076 | fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd); |
| 3077 | |
| 3078 | fcp_cmnd->fcpDl = be32_to_cpu(fcpdl); |
| 3079 | |
| 3080 | /* |
| 3081 | * Due to difference in data length between DIF/non-DIF paths, |
| 3082 | * we need to set word 4 of IOCB here |
| 3083 | */ |
| 3084 | iocb_cmd->un.fcpi.fcpi_parm = fcpdl; |
| 3085 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF; |
| 3086 | |
| 3087 | return 0; |
| 3088 | err: |
| 3089 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 3090 | "9084 Could not setup all needed BDE's" |
| 3091 | "prot_group_type=%d, num_bde=%d\n", |
| 3092 | prot_group_type, num_bde); |
| 3093 | return 1; |
| 3094 | } |
| 3095 | |
| 3096 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3097 | * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer |
| 3098 | * @phba: The Hba for which this call is being executed. |
| 3099 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3100 | * |
| 3101 | * This routine wraps the actual DMA mapping function pointer from the |
| 3102 | * lpfc_hba struct. |
| 3103 | * |
| 3104 | * Return codes: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 3105 | * 1 - Error |
| 3106 | * 0 - Success |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3107 | **/ |
| 3108 | static inline int |
| 3109 | lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 3110 | { |
| 3111 | return phba->lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 3112 | } |
| 3113 | |
| 3114 | /** |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3115 | * lpfc_bg_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer |
| 3116 | * using BlockGuard. |
| 3117 | * @phba: The Hba for which this call is being executed. |
| 3118 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3119 | * |
| 3120 | * This routine wraps the actual DMA mapping function pointer from the |
| 3121 | * lpfc_hba struct. |
| 3122 | * |
| 3123 | * Return codes: |
| 3124 | * 1 - Error |
| 3125 | * 0 - Success |
| 3126 | **/ |
| 3127 | static inline int |
| 3128 | lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 3129 | { |
| 3130 | return phba->lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 3131 | } |
| 3132 | |
| 3133 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3134 | * 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] | 3135 | * @phba: Pointer to hba context object. |
| 3136 | * @vport: Pointer to vport object. |
| 3137 | * @lpfc_cmd: Pointer to lpfc scsi command which reported the error. |
| 3138 | * @rsp_iocb: Pointer to response iocb object which reported error. |
| 3139 | * |
| 3140 | * This function posts an event when there is a SCSI command reporting |
| 3141 | * error from the scsi device. |
| 3142 | **/ |
| 3143 | static void |
| 3144 | lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 3145 | struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_iocbq *rsp_iocb) { |
| 3146 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 3147 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
| 3148 | uint32_t resp_info = fcprsp->rspStatus2; |
| 3149 | uint32_t scsi_status = fcprsp->rspStatus3; |
| 3150 | uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; |
| 3151 | struct lpfc_fast_path_event *fast_path_evt = NULL; |
| 3152 | struct lpfc_nodelist *pnode = lpfc_cmd->rdata->pnode; |
| 3153 | unsigned long flags; |
| 3154 | |
James Smart | 5989b8d | 2010-10-22 11:06:56 -0400 | [diff] [blame] | 3155 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 3156 | return; |
| 3157 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3158 | /* If there is queuefull or busy condition send a scsi event */ |
| 3159 | if ((cmnd->result == SAM_STAT_TASK_SET_FULL) || |
| 3160 | (cmnd->result == SAM_STAT_BUSY)) { |
| 3161 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3162 | if (!fast_path_evt) |
| 3163 | return; |
| 3164 | fast_path_evt->un.scsi_evt.event_type = |
| 3165 | FC_REG_SCSI_EVENT; |
| 3166 | fast_path_evt->un.scsi_evt.subcategory = |
| 3167 | (cmnd->result == SAM_STAT_TASK_SET_FULL) ? |
| 3168 | LPFC_EVENT_QFULL : LPFC_EVENT_DEVBSY; |
| 3169 | fast_path_evt->un.scsi_evt.lun = cmnd->device->lun; |
| 3170 | memcpy(&fast_path_evt->un.scsi_evt.wwpn, |
| 3171 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3172 | memcpy(&fast_path_evt->un.scsi_evt.wwnn, |
| 3173 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3174 | } else if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen && |
| 3175 | ((cmnd->cmnd[0] == READ_10) || (cmnd->cmnd[0] == WRITE_10))) { |
| 3176 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3177 | if (!fast_path_evt) |
| 3178 | return; |
| 3179 | fast_path_evt->un.check_cond_evt.scsi_event.event_type = |
| 3180 | FC_REG_SCSI_EVENT; |
| 3181 | fast_path_evt->un.check_cond_evt.scsi_event.subcategory = |
| 3182 | LPFC_EVENT_CHECK_COND; |
| 3183 | fast_path_evt->un.check_cond_evt.scsi_event.lun = |
| 3184 | cmnd->device->lun; |
| 3185 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwpn, |
| 3186 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3187 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwnn, |
| 3188 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3189 | fast_path_evt->un.check_cond_evt.sense_key = |
| 3190 | cmnd->sense_buffer[2] & 0xf; |
| 3191 | fast_path_evt->un.check_cond_evt.asc = cmnd->sense_buffer[12]; |
| 3192 | fast_path_evt->un.check_cond_evt.ascq = cmnd->sense_buffer[13]; |
| 3193 | } else if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) && |
| 3194 | fcpi_parm && |
| 3195 | ((be32_to_cpu(fcprsp->rspResId) != fcpi_parm) || |
| 3196 | ((scsi_status == SAM_STAT_GOOD) && |
| 3197 | !(resp_info & (RESID_UNDER | RESID_OVER))))) { |
| 3198 | /* |
| 3199 | * If status is good or resid does not match with fcp_param and |
| 3200 | * there is valid fcpi_parm, then there is a read_check error |
| 3201 | */ |
| 3202 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3203 | if (!fast_path_evt) |
| 3204 | return; |
| 3205 | fast_path_evt->un.read_check_error.header.event_type = |
| 3206 | FC_REG_FABRIC_EVENT; |
| 3207 | fast_path_evt->un.read_check_error.header.subcategory = |
| 3208 | LPFC_EVENT_FCPRDCHKERR; |
| 3209 | memcpy(&fast_path_evt->un.read_check_error.header.wwpn, |
| 3210 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3211 | memcpy(&fast_path_evt->un.read_check_error.header.wwnn, |
| 3212 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3213 | fast_path_evt->un.read_check_error.lun = cmnd->device->lun; |
| 3214 | fast_path_evt->un.read_check_error.opcode = cmnd->cmnd[0]; |
| 3215 | fast_path_evt->un.read_check_error.fcpiparam = |
| 3216 | fcpi_parm; |
| 3217 | } else |
| 3218 | return; |
| 3219 | |
| 3220 | fast_path_evt->vport = vport; |
| 3221 | spin_lock_irqsave(&phba->hbalock, flags); |
| 3222 | list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list); |
| 3223 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 3224 | lpfc_worker_wake_up(phba); |
| 3225 | return; |
| 3226 | } |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3227 | |
| 3228 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3229 | * 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] | 3230 | * @phba: The HBA for which this call is being executed. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3231 | * @psb: The scsi buffer which is going to be un-mapped. |
| 3232 | * |
| 3233 | * 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] | 3234 | * field of @lpfc_cmd for device with SLI-3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3235 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3236 | static void |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3237 | 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] | 3238 | { |
| 3239 | /* |
| 3240 | * There are only two special cases to consider. (1) the scsi command |
| 3241 | * requested scatter-gather usage or (2) the scsi command allocated |
| 3242 | * a request buffer, but did not request use_sg. There is a third |
| 3243 | * case, but it does not require resource deallocation. |
| 3244 | */ |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3245 | if (psb->seg_cnt > 0) |
| 3246 | scsi_dma_unmap(psb->pCmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3247 | if (psb->prot_seg_cnt > 0) |
| 3248 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(psb->pCmd), |
| 3249 | scsi_prot_sg_count(psb->pCmd), |
| 3250 | psb->pCmd->sc_data_direction); |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 3251 | } |
| 3252 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3253 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3254 | * lpfc_handler_fcp_err - FCP response handler |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3255 | * @vport: The virtual port for which this call is being executed. |
| 3256 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. |
| 3257 | * @rsp_iocb: The response IOCB which contains FCP error. |
| 3258 | * |
| 3259 | * This routine is called to process response IOCB with status field |
| 3260 | * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command |
| 3261 | * based upon SCSI and FCP error. |
| 3262 | **/ |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 3263 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3264 | lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd, |
| 3265 | struct lpfc_iocbq *rsp_iocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3266 | { |
| 3267 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 3268 | struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd; |
| 3269 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3270 | uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3271 | uint32_t resp_info = fcprsp->rspStatus2; |
| 3272 | uint32_t scsi_status = fcprsp->rspStatus3; |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3273 | uint32_t *lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3274 | uint32_t host_status = DID_OK; |
| 3275 | uint32_t rsplen = 0; |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3276 | uint32_t logit = LOG_FCP | LOG_FCP_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3277 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3278 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3279 | /* |
| 3280 | * If this is a task management command, there is no |
| 3281 | * scsi packet associated with this lpfc_cmd. The driver |
| 3282 | * consumes it. |
| 3283 | */ |
| 3284 | if (fcpcmd->fcpCntl2) { |
| 3285 | scsi_status = 0; |
| 3286 | goto out; |
| 3287 | } |
| 3288 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3289 | if (resp_info & RSP_LEN_VALID) { |
| 3290 | rsplen = be32_to_cpu(fcprsp->rspRspLen); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3291 | if (rsplen != 0 && rsplen != 4 && rsplen != 8) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3292 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 3293 | "2719 Invalid response length: " |
| 3294 | "tgt x%x lun x%x cmnd x%x rsplen x%x\n", |
| 3295 | cmnd->device->id, |
| 3296 | cmnd->device->lun, cmnd->cmnd[0], |
| 3297 | rsplen); |
| 3298 | host_status = DID_ERROR; |
| 3299 | goto out; |
| 3300 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3301 | if (fcprsp->rspInfo3 != RSP_NO_FAILURE) { |
| 3302 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 3303 | "2757 Protocol failure detected during " |
| 3304 | "processing of FCP I/O op: " |
| 3305 | "tgt x%x lun x%x cmnd x%x rspInfo3 x%x\n", |
| 3306 | cmnd->device->id, |
| 3307 | cmnd->device->lun, cmnd->cmnd[0], |
| 3308 | fcprsp->rspInfo3); |
| 3309 | host_status = DID_ERROR; |
| 3310 | goto out; |
| 3311 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3312 | } |
| 3313 | |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3314 | if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) { |
| 3315 | uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen); |
| 3316 | if (snslen > SCSI_SENSE_BUFFERSIZE) |
| 3317 | snslen = SCSI_SENSE_BUFFERSIZE; |
| 3318 | |
| 3319 | if (resp_info & RSP_LEN_VALID) |
| 3320 | rsplen = be32_to_cpu(fcprsp->rspRspLen); |
| 3321 | memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen); |
| 3322 | } |
| 3323 | lp = (uint32_t *)cmnd->sense_buffer; |
| 3324 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3325 | if (!scsi_status && (resp_info & RESID_UNDER) && |
| 3326 | vport->cfg_log_verbose & LOG_FCP_UNDER) |
| 3327 | logit = LOG_FCP_UNDER; |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3328 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3329 | lpfc_printf_vlog(vport, KERN_WARNING, logit, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3330 | "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] | 3331 | "Data: x%x x%x x%x x%x x%x\n", |
| 3332 | cmnd->cmnd[0], scsi_status, |
| 3333 | be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info, |
| 3334 | be32_to_cpu(fcprsp->rspResId), |
| 3335 | be32_to_cpu(fcprsp->rspSnsLen), |
| 3336 | be32_to_cpu(fcprsp->rspRspLen), |
| 3337 | fcprsp->rspInfo3); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3338 | |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3339 | scsi_set_resid(cmnd, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3340 | if (resp_info & RESID_UNDER) { |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3341 | scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3342 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3343 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_UNDER, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3344 | "9025 FCP Read Underrun, expected %d, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3345 | "residual %d Data: x%x x%x x%x\n", |
| 3346 | be32_to_cpu(fcpcmd->fcpDl), |
| 3347 | scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0], |
| 3348 | cmnd->underflow); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3349 | |
| 3350 | /* |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3351 | * If there is an under run check if under run reported by |
| 3352 | * storage array is same as the under run reported by HBA. |
| 3353 | * If this is not same, there is a dropped frame. |
| 3354 | */ |
| 3355 | if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) && |
| 3356 | fcpi_parm && |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3357 | (scsi_get_resid(cmnd) != fcpi_parm)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3358 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 3359 | LOG_FCP | LOG_FCP_ERROR, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3360 | "9026 FCP Read Check Error " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3361 | "and Underrun Data: x%x x%x x%x x%x\n", |
| 3362 | be32_to_cpu(fcpcmd->fcpDl), |
| 3363 | scsi_get_resid(cmnd), fcpi_parm, |
| 3364 | cmnd->cmnd[0]); |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3365 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3366 | host_status = DID_ERROR; |
| 3367 | } |
| 3368 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3369 | * The cmnd->underflow is the minimum number of bytes that must |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3370 | * be transferred for this command. Provided a sense condition |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3371 | * is not present, make sure the actual amount transferred is at |
| 3372 | * least the underflow value or fail. |
| 3373 | */ |
| 3374 | if (!(resp_info & SNS_LEN_VALID) && |
| 3375 | (scsi_status == SAM_STAT_GOOD) && |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3376 | (scsi_bufflen(cmnd) - scsi_get_resid(cmnd) |
| 3377 | < cmnd->underflow)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3378 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3379 | "9027 FCP command x%x residual " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3380 | "underrun converted to error " |
| 3381 | "Data: x%x x%x x%x\n", |
James Smart | 66dbfbe | 2007-08-05 06:08:38 -0400 | [diff] [blame] | 3382 | cmnd->cmnd[0], scsi_bufflen(cmnd), |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3383 | scsi_get_resid(cmnd), cmnd->underflow); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3384 | host_status = DID_ERROR; |
| 3385 | } |
| 3386 | } else if (resp_info & RESID_OVER) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3387 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3388 | "9028 FCP command x%x residual overrun error. " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 3389 | "Data: x%x x%x\n", cmnd->cmnd[0], |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3390 | scsi_bufflen(cmnd), scsi_get_resid(cmnd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3391 | host_status = DID_ERROR; |
| 3392 | |
| 3393 | /* |
| 3394 | * Check SLI validation that all the transfer was actually done |
| 3395 | * (fcpi_parm should be zero). Apply check only to reads. |
| 3396 | */ |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 3397 | } else if (fcpi_parm && (cmnd->sc_data_direction == DMA_FROM_DEVICE)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3398 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3399 | "9029 FCP Read Check Error Data: " |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 3400 | "x%x x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3401 | be32_to_cpu(fcpcmd->fcpDl), |
| 3402 | be32_to_cpu(fcprsp->rspResId), |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 3403 | fcpi_parm, cmnd->cmnd[0], scsi_status); |
| 3404 | switch (scsi_status) { |
| 3405 | case SAM_STAT_GOOD: |
| 3406 | case SAM_STAT_CHECK_CONDITION: |
| 3407 | /* Fabric dropped a data frame. Fail any successful |
| 3408 | * command in which we detected dropped frames. |
| 3409 | * A status of good or some check conditions could |
| 3410 | * be considered a successful command. |
| 3411 | */ |
| 3412 | host_status = DID_ERROR; |
| 3413 | break; |
| 3414 | } |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3415 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3416 | } |
| 3417 | |
| 3418 | out: |
| 3419 | cmnd->result = ScsiResult(host_status, scsi_status); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3420 | lpfc_send_scsi_error_event(vport->phba, vport, lpfc_cmd, rsp_iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3421 | } |
| 3422 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3423 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3424 | * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3425 | * @phba: The Hba for which this call is being executed. |
| 3426 | * @pIocbIn: The command IOCBQ for the scsi cmnd. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3427 | * @pIocbOut: The response IOCBQ for the scsi cmnd. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3428 | * |
| 3429 | * This routine assigns scsi command result by looking into response IOCB |
| 3430 | * status field appropriately. This routine handles QUEUE FULL condition as |
| 3431 | * well by ramping down device queue depth. |
| 3432 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3433 | static void |
| 3434 | lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn, |
| 3435 | struct lpfc_iocbq *pIocbOut) |
| 3436 | { |
| 3437 | struct lpfc_scsi_buf *lpfc_cmd = |
| 3438 | (struct lpfc_scsi_buf *) pIocbIn->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3439 | struct lpfc_vport *vport = pIocbIn->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3440 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| 3441 | struct lpfc_nodelist *pnode = rdata->pnode; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3442 | struct scsi_cmnd *cmd; |
James.Smart@Emulex.Com | 445cf4f | 2005-11-28 11:42:38 -0500 | [diff] [blame] | 3443 | int result; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3444 | struct scsi_device *tmp_sdev; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 3445 | int depth; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 3446 | unsigned long flags; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3447 | struct lpfc_fast_path_event *fast_path_evt; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3448 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3449 | uint32_t queue_depth, scsi_id; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3450 | uint32_t logit = LOG_FCP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3451 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3452 | /* Sanity check on return of outstanding command */ |
| 3453 | if (!(lpfc_cmd->pCmd)) |
| 3454 | return; |
| 3455 | cmd = lpfc_cmd->pCmd; |
| 3456 | shost = cmd->device->host; |
| 3457 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3458 | lpfc_cmd->result = pIocbOut->iocb.un.ulpWord[4]; |
| 3459 | lpfc_cmd->status = pIocbOut->iocb.ulpStatus; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3460 | /* pick up SLI4 exhange busy status from HBA */ |
| 3461 | lpfc_cmd->exch_busy = pIocbOut->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 3462 | |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3463 | if (pnode && NLP_CHK_NODE_ACT(pnode)) |
| 3464 | atomic_dec(&pnode->cmd_pending); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3465 | |
| 3466 | if (lpfc_cmd->status) { |
| 3467 | if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT && |
| 3468 | (lpfc_cmd->result & IOERR_DRVR_MASK)) |
| 3469 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; |
| 3470 | else if (lpfc_cmd->status >= IOSTAT_CNT) |
| 3471 | lpfc_cmd->status = IOSTAT_DEFAULT; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3472 | if (lpfc_cmd->status == IOSTAT_FCP_RSP_ERROR |
| 3473 | && !lpfc_cmd->fcp_rsp->rspStatus3 |
| 3474 | && (lpfc_cmd->fcp_rsp->rspStatus2 & RESID_UNDER) |
| 3475 | && !(phba->cfg_log_verbose & LOG_FCP_UNDER)) |
| 3476 | logit = 0; |
| 3477 | else |
| 3478 | logit = LOG_FCP | LOG_FCP_UNDER; |
| 3479 | lpfc_printf_vlog(vport, KERN_WARNING, logit, |
| 3480 | "9030 FCP cmd x%x failed <%d/%d> " |
| 3481 | "status: x%x result: x%x Data: x%x x%x\n", |
| 3482 | cmd->cmnd[0], |
| 3483 | cmd->device ? cmd->device->id : 0xffff, |
| 3484 | cmd->device ? cmd->device->lun : 0xffff, |
| 3485 | lpfc_cmd->status, lpfc_cmd->result, |
| 3486 | pIocbOut->iocb.ulpContext, |
| 3487 | lpfc_cmd->cur_iocbq.iocb.ulpIoTag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3488 | |
| 3489 | switch (lpfc_cmd->status) { |
| 3490 | case IOSTAT_FCP_RSP_ERROR: |
| 3491 | /* Call FCP RSP handler to determine result */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3492 | lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3493 | break; |
| 3494 | case IOSTAT_NPORT_BSY: |
| 3495 | case IOSTAT_FABRIC_BSY: |
James Smart | 0f1f53a | 2008-08-24 21:50:18 -0400 | [diff] [blame] | 3496 | cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 0); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3497 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3498 | if (!fast_path_evt) |
| 3499 | break; |
| 3500 | fast_path_evt->un.fabric_evt.event_type = |
| 3501 | FC_REG_FABRIC_EVENT; |
| 3502 | fast_path_evt->un.fabric_evt.subcategory = |
| 3503 | (lpfc_cmd->status == IOSTAT_NPORT_BSY) ? |
| 3504 | LPFC_EVENT_PORT_BUSY : LPFC_EVENT_FABRIC_BUSY; |
| 3505 | if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
| 3506 | memcpy(&fast_path_evt->un.fabric_evt.wwpn, |
| 3507 | &pnode->nlp_portname, |
| 3508 | sizeof(struct lpfc_name)); |
| 3509 | memcpy(&fast_path_evt->un.fabric_evt.wwnn, |
| 3510 | &pnode->nlp_nodename, |
| 3511 | sizeof(struct lpfc_name)); |
| 3512 | } |
| 3513 | fast_path_evt->vport = vport; |
| 3514 | fast_path_evt->work_evt.evt = |
| 3515 | LPFC_EVT_FASTPATH_MGMT_EVT; |
| 3516 | spin_lock_irqsave(&phba->hbalock, flags); |
| 3517 | list_add_tail(&fast_path_evt->work_evt.evt_listp, |
| 3518 | &phba->work_list); |
| 3519 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 3520 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3521 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3522 | case IOSTAT_LOCAL_REJECT: |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3523 | case IOSTAT_REMOTE_STOP: |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 3524 | if (lpfc_cmd->result == IOERR_ELXSEC_KEY_UNWRAP_ERROR || |
| 3525 | lpfc_cmd->result == |
| 3526 | IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR || |
| 3527 | lpfc_cmd->result == IOERR_ELXSEC_CRYPTO_ERROR || |
| 3528 | lpfc_cmd->result == |
| 3529 | IOERR_ELXSEC_CRYPTO_COMPARE_ERROR) { |
| 3530 | cmd->result = ScsiResult(DID_NO_CONNECT, 0); |
| 3531 | break; |
| 3532 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3533 | if (lpfc_cmd->result == IOERR_INVALID_RPI || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3534 | lpfc_cmd->result == IOERR_NO_RESOURCES || |
James Smart | b92938b | 2010-06-07 15:24:12 -0400 | [diff] [blame] | 3535 | lpfc_cmd->result == IOERR_ABORT_REQUESTED || |
| 3536 | lpfc_cmd->result == IOERR_SLER_CMD_RCV_FAILURE) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3537 | cmd->result = ScsiResult(DID_REQUEUE, 0); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3538 | break; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3539 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3540 | if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED || |
| 3541 | lpfc_cmd->result == IOERR_TX_DMA_FAILED) && |
| 3542 | pIocbOut->iocb.unsli3.sli3_bg.bgstat) { |
| 3543 | if (scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) { |
| 3544 | /* |
| 3545 | * This is a response for a BG enabled |
| 3546 | * cmd. Parse BG error |
| 3547 | */ |
| 3548 | lpfc_parse_bg_err(phba, lpfc_cmd, |
| 3549 | pIocbOut); |
| 3550 | break; |
| 3551 | } else { |
| 3552 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 3553 | LOG_BG, |
| 3554 | "9031 non-zero BGSTAT " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3555 | "on unprotected cmd\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3556 | } |
| 3557 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3558 | if ((lpfc_cmd->status == IOSTAT_REMOTE_STOP) |
| 3559 | && (phba->sli_rev == LPFC_SLI_REV4) |
| 3560 | && (pnode && NLP_CHK_NODE_ACT(pnode))) { |
| 3561 | /* This IO was aborted by the target, we don't |
| 3562 | * know the rxid and because we did not send the |
| 3563 | * ABTS we cannot generate and RRQ. |
| 3564 | */ |
| 3565 | lpfc_set_rrq_active(phba, pnode, |
| 3566 | lpfc_cmd->cur_iocbq.sli4_xritag, |
| 3567 | 0, 0); |
| 3568 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3569 | /* else: fall through */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3570 | default: |
| 3571 | cmd->result = ScsiResult(DID_ERROR, 0); |
| 3572 | break; |
| 3573 | } |
| 3574 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3575 | if (!pnode || !NLP_CHK_NODE_ACT(pnode) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3576 | || (pnode->nlp_state != NLP_STE_MAPPED_NODE)) |
James Smart | 0f1f53a | 2008-08-24 21:50:18 -0400 | [diff] [blame] | 3577 | cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, |
| 3578 | SAM_STAT_BUSY); |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 3579 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3580 | cmd->result = ScsiResult(DID_OK, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3581 | |
| 3582 | if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) { |
| 3583 | uint32_t *lp = (uint32_t *)cmd->sense_buffer; |
| 3584 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3585 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 3586 | "0710 Iodone <%d/%d> cmd %p, error " |
| 3587 | "x%x SNS x%x x%x Data: x%x x%x\n", |
| 3588 | cmd->device->id, cmd->device->lun, cmd, |
| 3589 | cmd->result, *lp, *(lp + 3), cmd->retries, |
| 3590 | scsi_get_resid(cmd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3591 | } |
| 3592 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3593 | lpfc_update_stats(phba, lpfc_cmd); |
James.Smart@Emulex.Com | 445cf4f | 2005-11-28 11:42:38 -0500 | [diff] [blame] | 3594 | result = cmd->result; |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 3595 | if (vport->cfg_max_scsicmpl_time && |
| 3596 | time_after(jiffies, lpfc_cmd->start_time + |
| 3597 | msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3598 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3599 | if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
| 3600 | if (pnode->cmd_qdepth > |
| 3601 | atomic_read(&pnode->cmd_pending) && |
| 3602 | (atomic_read(&pnode->cmd_pending) > |
| 3603 | LPFC_MIN_TGT_QDEPTH) && |
| 3604 | ((cmd->cmnd[0] == READ_10) || |
| 3605 | (cmd->cmnd[0] == WRITE_10))) |
| 3606 | pnode->cmd_qdepth = |
| 3607 | atomic_read(&pnode->cmd_pending); |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 3608 | |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3609 | pnode->last_change_time = jiffies; |
| 3610 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3611 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3612 | } else if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 3613 | if ((pnode->cmd_qdepth < vport->cfg_tgt_queue_depth) && |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 3614 | time_after(jiffies, pnode->last_change_time + |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3615 | msecs_to_jiffies(LPFC_TGTQ_INTERVAL))) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3616 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 3617 | depth = pnode->cmd_qdepth * LPFC_TGTQ_RAMPUP_PCENT |
| 3618 | / 100; |
| 3619 | depth = depth ? depth : 1; |
| 3620 | pnode->cmd_qdepth += depth; |
| 3621 | if (pnode->cmd_qdepth > vport->cfg_tgt_queue_depth) |
| 3622 | pnode->cmd_qdepth = vport->cfg_tgt_queue_depth; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3623 | pnode->last_change_time = jiffies; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3624 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3625 | } |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 3626 | } |
| 3627 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3628 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3629 | |
| 3630 | /* The sdev is not guaranteed to be valid post scsi_done upcall. */ |
| 3631 | queue_depth = cmd->device->queue_depth; |
| 3632 | scsi_id = cmd->device->id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3633 | cmd->scsi_done(cmd); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3634 | |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 3635 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 3636 | /* |
| 3637 | * If there is a thread waiting for command completion |
| 3638 | * wake up the thread. |
| 3639 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3640 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 3641 | lpfc_cmd->pCmd = NULL; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 3642 | if (lpfc_cmd->waitq) |
| 3643 | wake_up(lpfc_cmd->waitq); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3644 | spin_unlock_irqrestore(shost->host_lock, flags); |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 3645 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 3646 | return; |
| 3647 | } |
| 3648 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3649 | if (!result) |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3650 | lpfc_rampup_queue_depth(vport, queue_depth); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3651 | |
James.Smart@Emulex.Com | 445cf4f | 2005-11-28 11:42:38 -0500 | [diff] [blame] | 3652 | /* |
| 3653 | * Check for queue full. If the lun is reporting queue full, then |
| 3654 | * back off the lun queue depth to prevent target overloads. |
| 3655 | */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3656 | if (result == SAM_STAT_TASK_SET_FULL && pnode && |
| 3657 | NLP_CHK_NODE_ACT(pnode)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3658 | shost_for_each_device(tmp_sdev, shost) { |
| 3659 | if (tmp_sdev->id != scsi_id) |
James.Smart@Emulex.Com | 445cf4f | 2005-11-28 11:42:38 -0500 | [diff] [blame] | 3660 | continue; |
| 3661 | depth = scsi_track_queue_full(tmp_sdev, |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 3662 | tmp_sdev->queue_depth-1); |
| 3663 | if (depth <= 0) |
| 3664 | continue; |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3665 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 3666 | "0711 detected queue full - lun queue " |
| 3667 | "depth adjusted to %d.\n", depth); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3668 | lpfc_send_sdev_queuedepth_change_event(phba, vport, |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 3669 | pnode, |
| 3670 | tmp_sdev->lun, |
| 3671 | depth+1, depth); |
James.Smart@Emulex.Com | 445cf4f | 2005-11-28 11:42:38 -0500 | [diff] [blame] | 3672 | } |
| 3673 | } |
| 3674 | |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 3675 | /* |
| 3676 | * If there is a thread waiting for command completion |
| 3677 | * wake up the thread. |
| 3678 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3679 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 3680 | lpfc_cmd->pCmd = NULL; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 3681 | if (lpfc_cmd->waitq) |
| 3682 | wake_up(lpfc_cmd->waitq); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3683 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 3684 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3685 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3686 | } |
| 3687 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3688 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3689 | * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3690 | * @data: A pointer to the immediate command data portion of the IOCB. |
| 3691 | * @fcp_cmnd: The FCP Command that is provided by the SCSI layer. |
| 3692 | * |
| 3693 | * The routine copies the entire FCP command from @fcp_cmnd to @data while |
| 3694 | * byte swapping the data to big endian format for transmission on the wire. |
| 3695 | **/ |
| 3696 | static void |
| 3697 | lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd) |
| 3698 | { |
| 3699 | int i, j; |
| 3700 | for (i = 0, j = 0; i < sizeof(struct fcp_cmnd); |
| 3701 | i += sizeof(uint32_t), j++) { |
| 3702 | ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]); |
| 3703 | } |
| 3704 | } |
| 3705 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3706 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3707 | * 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] | 3708 | * @vport: The virtual port for which this call is being executed. |
| 3709 | * @lpfc_cmd: The scsi command which needs to send. |
| 3710 | * @pnode: Pointer to lpfc_nodelist. |
| 3711 | * |
| 3712 | * This routine initializes fcp_cmnd and iocb data structure from scsi command |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3713 | * to transfer for device with SLI3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3714 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3715 | static void |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3716 | 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] | 3717 | struct lpfc_nodelist *pnode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3718 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3719 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3720 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 3721 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 3722 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 3723 | struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq); |
| 3724 | int datadir = scsi_cmnd->sc_data_direction; |
James Smart | 7e2b19f | 2007-10-29 11:00:39 -0400 | [diff] [blame] | 3725 | char tag[2]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3726 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3727 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 3728 | return; |
| 3729 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3730 | lpfc_cmd->fcp_rsp->rspSnsLen = 0; |
James.Smart@Emulex.Com | 69859dc | 2005-08-10 15:02:37 -0400 | [diff] [blame] | 3731 | /* clear task management bits */ |
| 3732 | lpfc_cmd->fcp_cmnd->fcpCntl2 = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3733 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 3734 | int_to_scsilun(lpfc_cmd->pCmd->device->lun, |
| 3735 | &lpfc_cmd->fcp_cmnd->fcp_lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3736 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3737 | memset(&fcp_cmnd->fcpCdb[0], 0, LPFC_FCP_CDB_LEN); |
| 3738 | memcpy(&fcp_cmnd->fcpCdb[0], scsi_cmnd->cmnd, scsi_cmnd->cmd_len); |
James Smart | 7e2b19f | 2007-10-29 11:00:39 -0400 | [diff] [blame] | 3739 | if (scsi_populate_tag_msg(scsi_cmnd, tag)) { |
| 3740 | switch (tag[0]) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3741 | case HEAD_OF_QUEUE_TAG: |
| 3742 | fcp_cmnd->fcpCntl1 = HEAD_OF_Q; |
| 3743 | break; |
| 3744 | case ORDERED_QUEUE_TAG: |
| 3745 | fcp_cmnd->fcpCntl1 = ORDERED_Q; |
| 3746 | break; |
| 3747 | default: |
| 3748 | fcp_cmnd->fcpCntl1 = SIMPLE_Q; |
| 3749 | break; |
| 3750 | } |
| 3751 | } else |
| 3752 | fcp_cmnd->fcpCntl1 = 0; |
| 3753 | |
| 3754 | /* |
| 3755 | * There are three possibilities here - use scatter-gather segment, use |
| 3756 | * the single mapping, or neither. Start the lpfc command prep by |
| 3757 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 3758 | * data bde entry. |
| 3759 | */ |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3760 | if (scsi_sg_count(scsi_cmnd)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3761 | if (datadir == DMA_TO_DEVICE) { |
| 3762 | iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3763 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 3764 | iocb_cmd->un.fcpi.fcpi_parm = 0; |
| 3765 | iocb_cmd->ulpPU = 0; |
| 3766 | } else |
| 3767 | iocb_cmd->ulpPU = PARM_READ_CHECK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3768 | fcp_cmnd->fcpCntl3 = WRITE_DATA; |
| 3769 | phba->fc4OutputRequests++; |
| 3770 | } else { |
| 3771 | iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR; |
| 3772 | iocb_cmd->ulpPU = PARM_READ_CHECK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3773 | fcp_cmnd->fcpCntl3 = READ_DATA; |
| 3774 | phba->fc4InputRequests++; |
| 3775 | } |
| 3776 | } else { |
| 3777 | iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR; |
| 3778 | iocb_cmd->un.fcpi.fcpi_parm = 0; |
| 3779 | iocb_cmd->ulpPU = 0; |
| 3780 | fcp_cmnd->fcpCntl3 = 0; |
| 3781 | phba->fc4ControlRequests++; |
| 3782 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3783 | if (phba->sli_rev == 3 && |
| 3784 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3785 | lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3786 | /* |
| 3787 | * Finish initializing those IOCB fields that are independent |
| 3788 | * of the scsi_cmnd request_buffer |
| 3789 | */ |
| 3790 | piocbq->iocb.ulpContext = pnode->nlp_rpi; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 3791 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 3792 | piocbq->iocb.ulpContext = |
| 3793 | phba->sli4_hba.rpi_ids[pnode->nlp_rpi]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3794 | if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE) |
| 3795 | piocbq->iocb.ulpFCP2Rcvy = 1; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3796 | else |
| 3797 | piocbq->iocb.ulpFCP2Rcvy = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3798 | |
| 3799 | piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f); |
| 3800 | piocbq->context1 = lpfc_cmd; |
| 3801 | piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; |
| 3802 | piocbq->iocb.ulpTimeout = lpfc_cmd->timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3803 | piocbq->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3804 | } |
| 3805 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3806 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 3807 | * lpfc_scsi_prep_task_mgmt_cmd - Convert SLI3 scsi TM cmd to FCP info unit |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3808 | * @vport: The virtual port for which this call is being executed. |
| 3809 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. |
| 3810 | * @lun: Logical unit number. |
| 3811 | * @task_mgmt_cmd: SCSI task management command. |
| 3812 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3813 | * This routine creates FCP information unit corresponding to @task_mgmt_cmd |
| 3814 | * for device with SLI-3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3815 | * |
| 3816 | * Return codes: |
| 3817 | * 0 - Error |
| 3818 | * 1 - Success |
| 3819 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3820 | static int |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3821 | lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3822 | struct lpfc_scsi_buf *lpfc_cmd, |
James Smart | 420b630d | 2006-07-06 15:50:16 -0400 | [diff] [blame] | 3823 | unsigned int lun, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3824 | uint8_t task_mgmt_cmd) |
| 3825 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3826 | struct lpfc_iocbq *piocbq; |
| 3827 | IOCB_t *piocb; |
| 3828 | struct fcp_cmnd *fcp_cmnd; |
James Smart | 0b18ac4 | 2006-05-01 21:50:40 -0400 | [diff] [blame] | 3829 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3830 | struct lpfc_nodelist *ndlp = rdata->pnode; |
| 3831 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3832 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || |
| 3833 | ndlp->nlp_state != NLP_STE_MAPPED_NODE) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3834 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3835 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3836 | piocbq = &(lpfc_cmd->cur_iocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3837 | piocbq->vport = vport; |
| 3838 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3839 | piocb = &piocbq->iocb; |
| 3840 | |
| 3841 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3842 | /* Clear out any old data in the FCP command area */ |
| 3843 | memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd)); |
| 3844 | int_to_scsilun(lun, &fcp_cmnd->fcp_lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3845 | fcp_cmnd->fcpCntl2 = task_mgmt_cmd; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3846 | if (vport->phba->sli_rev == 3 && |
| 3847 | !(vport->phba->sli3_options & LPFC_SLI3_BG_ENABLED)) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3848 | lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3849 | piocb->ulpCommand = CMD_FCP_ICMND64_CR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3850 | piocb->ulpContext = ndlp->nlp_rpi; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 3851 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
| 3852 | piocb->ulpContext = |
| 3853 | vport->phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
| 3854 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3855 | if (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) { |
| 3856 | piocb->ulpFCP2Rcvy = 1; |
| 3857 | } |
| 3858 | piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f); |
| 3859 | |
| 3860 | /* ulpTimeout is only one byte */ |
| 3861 | if (lpfc_cmd->timeout > 0xff) { |
| 3862 | /* |
| 3863 | * Do not timeout the command at the firmware level. |
| 3864 | * The driver will provide the timeout mechanism. |
| 3865 | */ |
| 3866 | piocb->ulpTimeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3867 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3868 | piocb->ulpTimeout = lpfc_cmd->timeout; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3869 | |
| 3870 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 3871 | lpfc_sli4_set_rsp_sgl_last(vport->phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3872 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3873 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3874 | } |
| 3875 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3876 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3877 | * lpfc_scsi_api_table_setup - Set up scsi api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3878 | * @phba: The hba struct for which this call is being executed. |
| 3879 | * @dev_grp: The HBA PCI-Device group number. |
| 3880 | * |
| 3881 | * This routine sets up the SCSI interface API function jump table in @phba |
| 3882 | * struct. |
| 3883 | * Returns: 0 - success, -ENODEV - failure. |
| 3884 | **/ |
| 3885 | int |
| 3886 | lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 3887 | { |
| 3888 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3889 | phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf; |
| 3890 | phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3891 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3892 | switch (dev_grp) { |
| 3893 | case LPFC_PCI_DEV_LP: |
| 3894 | phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s3; |
| 3895 | phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3896 | phba->lpfc_bg_scsi_prep_dma_buf = lpfc_bg_scsi_prep_dma_buf_s3; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3897 | phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 3898 | phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s3; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3899 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3900 | case LPFC_PCI_DEV_OC: |
| 3901 | phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s4; |
| 3902 | phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s4; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3903 | phba->lpfc_bg_scsi_prep_dma_buf = lpfc_bg_scsi_prep_dma_buf_s4; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3904 | phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s4; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 3905 | phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s4; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3906 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3907 | default: |
| 3908 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3909 | "1418 Invalid HBA PCI-device group: 0x%x\n", |
| 3910 | dev_grp); |
| 3911 | return -ENODEV; |
| 3912 | break; |
| 3913 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3914 | phba->lpfc_rampdown_queue_depth = lpfc_rampdown_queue_depth; |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 3915 | phba->lpfc_scsi_cmd_iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3916 | return 0; |
| 3917 | } |
| 3918 | |
| 3919 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3920 | * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3921 | * @phba: The Hba for which this call is being executed. |
| 3922 | * @cmdiocbq: Pointer to lpfc_iocbq data structure. |
| 3923 | * @rspiocbq: Pointer to lpfc_iocbq data structure. |
| 3924 | * |
| 3925 | * This routine is IOCB completion routine for device reset and target reset |
| 3926 | * routine. This routine release scsi buffer associated with lpfc_cmd. |
| 3927 | **/ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3928 | static void |
| 3929 | lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba, |
| 3930 | struct lpfc_iocbq *cmdiocbq, |
| 3931 | struct lpfc_iocbq *rspiocbq) |
| 3932 | { |
| 3933 | struct lpfc_scsi_buf *lpfc_cmd = |
| 3934 | (struct lpfc_scsi_buf *) cmdiocbq->context1; |
| 3935 | if (lpfc_cmd) |
| 3936 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 3937 | return; |
| 3938 | } |
| 3939 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3940 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3941 | * lpfc_info - Info entry point of scsi_host_template data structure |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3942 | * @host: The scsi host for which this call is being executed. |
| 3943 | * |
| 3944 | * This routine provides module information about hba. |
| 3945 | * |
| 3946 | * Reutrn code: |
| 3947 | * Pointer to char - Success. |
| 3948 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3949 | const char * |
| 3950 | lpfc_info(struct Scsi_Host *host) |
| 3951 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3952 | struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata; |
| 3953 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3954 | int len; |
| 3955 | static char lpfcinfobuf[384]; |
| 3956 | |
| 3957 | memset(lpfcinfobuf,0,384); |
| 3958 | if (phba && phba->pcidev){ |
| 3959 | strncpy(lpfcinfobuf, phba->ModelDesc, 256); |
| 3960 | len = strlen(lpfcinfobuf); |
| 3961 | snprintf(lpfcinfobuf + len, |
| 3962 | 384-len, |
| 3963 | " on PCI bus %02x device %02x irq %d", |
| 3964 | phba->pcidev->bus->number, |
| 3965 | phba->pcidev->devfn, |
| 3966 | phba->pcidev->irq); |
| 3967 | len = strlen(lpfcinfobuf); |
| 3968 | if (phba->Port[0]) { |
| 3969 | snprintf(lpfcinfobuf + len, |
| 3970 | 384-len, |
| 3971 | " port %s", |
| 3972 | phba->Port); |
| 3973 | } |
James Smart | 65467b6 | 2010-01-26 23:08:29 -0500 | [diff] [blame] | 3974 | len = strlen(lpfcinfobuf); |
| 3975 | if (phba->sli4_hba.link_state.logical_speed) { |
| 3976 | snprintf(lpfcinfobuf + len, |
| 3977 | 384-len, |
| 3978 | " Logical Link Speed: %d Mbps", |
| 3979 | phba->sli4_hba.link_state.logical_speed * 10); |
| 3980 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3981 | } |
| 3982 | return lpfcinfobuf; |
| 3983 | } |
| 3984 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3985 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3986 | * lpfc_poll_rearm_time - Routine to modify fcp_poll timer of hba |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3987 | * @phba: The Hba for which this call is being executed. |
| 3988 | * |
| 3989 | * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo. |
| 3990 | * The default value of cfg_poll_tmo is 10 milliseconds. |
| 3991 | **/ |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3992 | static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba) |
| 3993 | { |
| 3994 | unsigned long poll_tmo_expires = |
| 3995 | (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo)); |
| 3996 | |
| 3997 | if (phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt) |
| 3998 | mod_timer(&phba->fcp_poll_timer, |
| 3999 | poll_tmo_expires); |
| 4000 | } |
| 4001 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4002 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4003 | * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4004 | * @phba: The Hba for which this call is being executed. |
| 4005 | * |
| 4006 | * This routine starts the fcp_poll_timer of @phba. |
| 4007 | **/ |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4008 | void lpfc_poll_start_timer(struct lpfc_hba * phba) |
| 4009 | { |
| 4010 | lpfc_poll_rearm_timer(phba); |
| 4011 | } |
| 4012 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4013 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4014 | * lpfc_poll_timeout - Restart polling timer |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4015 | * @ptr: Map to lpfc_hba data structure pointer. |
| 4016 | * |
| 4017 | * This routine restarts fcp_poll timer, when FCP ring polling is enable |
| 4018 | * and FCP Ring interrupt is disable. |
| 4019 | **/ |
| 4020 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4021 | void lpfc_poll_timeout(unsigned long ptr) |
| 4022 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4023 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4024 | |
| 4025 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4026 | lpfc_sli_handle_fast_ring_event(phba, |
| 4027 | &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ); |
| 4028 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4029 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 4030 | lpfc_poll_rearm_timer(phba); |
| 4031 | } |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4032 | } |
| 4033 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4034 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4035 | * lpfc_queuecommand - scsi_host_template queuecommand entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4036 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 4037 | * @done: Pointer to done routine. |
| 4038 | * |
| 4039 | * Driver registers this routine to scsi midlayer to submit a @cmd to process. |
| 4040 | * This routine prepares an IOCB from scsi command and provides to firmware. |
| 4041 | * The @done callback is invoked after driver finished processing the command. |
| 4042 | * |
| 4043 | * Return value : |
| 4044 | * 0 - Success |
| 4045 | * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily. |
| 4046 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4047 | static int |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 4048 | lpfc_queuecommand_lck(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4049 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4050 | struct Scsi_Host *shost = cmnd->device->host; |
| 4051 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4052 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4053 | struct lpfc_rport_data *rdata = cmnd->device->hostdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 4054 | struct lpfc_nodelist *ndlp; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4055 | struct lpfc_scsi_buf *lpfc_cmd; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4056 | 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] | 4057 | int err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4058 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4059 | err = fc_remote_port_chkready(rport); |
| 4060 | if (err) { |
| 4061 | cmnd->result = err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4062 | goto out_fail_command; |
| 4063 | } |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 4064 | /* |
| 4065 | * Do not let the mid-layer retry I/O too fast. If an I/O is retried |
| 4066 | * without waiting a bit then indicate that the device is busy. |
| 4067 | */ |
| 4068 | if (cmnd->retries && |
| 4069 | time_before(jiffies, (cmnd->jiffies_at_alloc + |
| 4070 | msecs_to_jiffies(LPFC_RETRY_PAUSE * |
| 4071 | cmnd->retries)))) |
| 4072 | return SCSI_MLQUEUE_DEVICE_BUSY; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 4073 | ndlp = rdata->pnode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4074 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 4075 | if ((scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) && |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4076 | (!(phba->sli3_options & LPFC_SLI3_BG_ENABLED))) { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4077 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4078 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 4079 | "9058 BLKGRD: ERROR: rcvd protected cmd:%02x" |
| 4080 | " op:%02x str=%s without registering for" |
| 4081 | " BlockGuard - Rejecting command\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4082 | cmnd->cmnd[0], scsi_get_prot_op(cmnd), |
| 4083 | dif_op_str[scsi_get_prot_op(cmnd)]); |
| 4084 | goto out_fail_command; |
| 4085 | } |
| 4086 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4087 | /* |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4088 | * Catch race where our node has transitioned, but the |
| 4089 | * transport is still transitioning. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4090 | */ |
James Smart | b522d7d | 2008-09-07 11:51:56 -0400 | [diff] [blame] | 4091 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
Mike Christie | f55ca84d | 2011-02-25 14:04:27 -0600 | [diff] [blame] | 4092 | cmnd->result = ScsiResult(DID_IMM_RETRY, 0); |
James Smart | b522d7d | 2008-09-07 11:51:56 -0400 | [diff] [blame] | 4093 | goto out_fail_command; |
| 4094 | } |
James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 4095 | if (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth) |
Mike Christie | 3496343 | 2011-02-25 14:04:28 -0600 | [diff] [blame] | 4096 | goto out_tgt_busy; |
Mike Christie | a93ce02 | 2008-08-17 15:24:41 -0500 | [diff] [blame] | 4097 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4098 | lpfc_cmd = lpfc_get_scsi_buf(phba, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4099 | if (lpfc_cmd == NULL) { |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4100 | lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4101 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4102 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4103 | "0707 driver's buffer pool is empty, " |
| 4104 | "IO busied\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4105 | goto out_host_busy; |
| 4106 | } |
| 4107 | |
| 4108 | /* |
| 4109 | * Store the midlayer's command structure for the completion phase |
| 4110 | * and complete the command initialization. |
| 4111 | */ |
| 4112 | lpfc_cmd->pCmd = cmnd; |
| 4113 | lpfc_cmd->rdata = rdata; |
| 4114 | lpfc_cmd->timeout = 0; |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4115 | lpfc_cmd->start_time = jiffies; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4116 | cmnd->host_scribble = (unsigned char *)lpfc_cmd; |
| 4117 | cmnd->scsi_done = done; |
| 4118 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4119 | if (scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4120 | if (vport->phba->cfg_enable_bg) { |
| 4121 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4122 | "9033 BLKGRD: rcvd protected cmd:%02x op:%02x " |
| 4123 | "str=%s\n", |
| 4124 | cmnd->cmnd[0], scsi_get_prot_op(cmnd), |
| 4125 | dif_op_str[scsi_get_prot_op(cmnd)]); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4126 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4127 | "9034 BLKGRD: CDB: %02x %02x %02x %02x %02x " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 4128 | "%02x %02x %02x %02x %02x\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4129 | cmnd->cmnd[0], cmnd->cmnd[1], cmnd->cmnd[2], |
| 4130 | cmnd->cmnd[3], cmnd->cmnd[4], cmnd->cmnd[5], |
| 4131 | cmnd->cmnd[6], cmnd->cmnd[7], cmnd->cmnd[8], |
| 4132 | cmnd->cmnd[9]); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4133 | if (cmnd->cmnd[0] == READ_10) |
| 4134 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4135 | "9035 BLKGRD: READ @ sector %llu, " |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 4136 | "count %u\n", |
| 4137 | (unsigned long long)scsi_get_lba(cmnd), |
| 4138 | blk_rq_sectors(cmnd->request)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4139 | else if (cmnd->cmnd[0] == WRITE_10) |
| 4140 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4141 | "9036 BLKGRD: WRITE @ sector %llu, " |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 4142 | "count %u cmd=%p\n", |
James Smart | 87b5c32 | 2008-12-16 10:34:09 -0500 | [diff] [blame] | 4143 | (unsigned long long)scsi_get_lba(cmnd), |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 4144 | blk_rq_sectors(cmnd->request), |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4145 | cmnd); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4146 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4147 | |
| 4148 | err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 4149 | } else { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4150 | if (vport->phba->cfg_enable_bg) { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4151 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4152 | "9038 BLKGRD: rcvd unprotected cmd:" |
| 4153 | "%02x op:%02x str=%s\n", |
| 4154 | cmnd->cmnd[0], scsi_get_prot_op(cmnd), |
| 4155 | dif_op_str[scsi_get_prot_op(cmnd)]); |
| 4156 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
| 4157 | "9039 BLKGRD: CDB: %02x %02x %02x " |
| 4158 | "%02x %02x %02x %02x %02x %02x %02x\n", |
| 4159 | cmnd->cmnd[0], cmnd->cmnd[1], |
| 4160 | cmnd->cmnd[2], cmnd->cmnd[3], |
| 4161 | cmnd->cmnd[4], cmnd->cmnd[5], |
| 4162 | cmnd->cmnd[6], cmnd->cmnd[7], |
| 4163 | cmnd->cmnd[8], cmnd->cmnd[9]); |
| 4164 | if (cmnd->cmnd[0] == READ_10) |
| 4165 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
| 4166 | "9040 dbg: READ @ sector %llu, " |
| 4167 | "count %u\n", |
| 4168 | (unsigned long long)scsi_get_lba(cmnd), |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 4169 | blk_rq_sectors(cmnd->request)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4170 | else if (cmnd->cmnd[0] == WRITE_10) |
| 4171 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4172 | "9041 dbg: WRITE @ sector %llu, " |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 4173 | "count %u cmd=%p\n", |
James Smart | 87b5c32 | 2008-12-16 10:34:09 -0500 | [diff] [blame] | 4174 | (unsigned long long)scsi_get_lba(cmnd), |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 4175 | blk_rq_sectors(cmnd->request), cmnd); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4176 | else |
| 4177 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4178 | "9042 dbg: parser not implemented\n"); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4179 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4180 | err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 4181 | } |
| 4182 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4183 | if (err) |
| 4184 | goto out_host_busy_free_buf; |
| 4185 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4186 | lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4187 | |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4188 | atomic_inc(&ndlp->cmd_pending); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4189 | err = lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4190 | &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4191 | if (err) { |
| 4192 | atomic_dec(&ndlp->cmd_pending); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4193 | goto out_host_busy_free_buf; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4194 | } |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4195 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4196 | spin_unlock(shost->host_lock); |
| 4197 | lpfc_sli_handle_fast_ring_event(phba, |
| 4198 | &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ); |
| 4199 | |
| 4200 | spin_lock(shost->host_lock); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4201 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 4202 | lpfc_poll_rearm_timer(phba); |
| 4203 | } |
| 4204 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4205 | return 0; |
| 4206 | |
| 4207 | out_host_busy_free_buf: |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 4208 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4209 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4210 | out_host_busy: |
| 4211 | return SCSI_MLQUEUE_HOST_BUSY; |
| 4212 | |
Mike Christie | 3496343 | 2011-02-25 14:04:28 -0600 | [diff] [blame] | 4213 | out_tgt_busy: |
| 4214 | return SCSI_MLQUEUE_TARGET_BUSY; |
| 4215 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4216 | out_fail_command: |
| 4217 | done(cmnd); |
| 4218 | return 0; |
| 4219 | } |
| 4220 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 4221 | static DEF_SCSI_QCMD(lpfc_queuecommand) |
| 4222 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4223 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4224 | * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4225 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 4226 | * |
| 4227 | * This routine aborts @cmnd pending in base driver. |
| 4228 | * |
| 4229 | * Return code : |
| 4230 | * 0x2003 - Error |
| 4231 | * 0x2002 - Success |
| 4232 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4233 | static int |
James.Smart@Emulex.Com | 63c59c3 | 2005-11-28 11:41:53 -0500 | [diff] [blame] | 4234 | lpfc_abort_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4235 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4236 | struct Scsi_Host *shost = cmnd->device->host; |
| 4237 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4238 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4239 | struct lpfc_iocbq *iocb; |
| 4240 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4241 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4242 | IOCB_t *cmd, *icmd; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4243 | int ret = SUCCESS; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4244 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4245 | |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 4246 | ret = fc_block_scsi_eh(cmnd); |
| 4247 | if (ret) |
| 4248 | return ret; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4249 | lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble; |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 4250 | if (!lpfc_cmd) { |
| 4251 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4252 | "2873 SCSI Layer I/O Abort Request IO CMPL Status " |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 4253 | "x%x ID %d LUN %d\n", |
| 4254 | ret, cmnd->device->id, cmnd->device->lun); |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 4255 | return SUCCESS; |
| 4256 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4257 | |
| 4258 | /* |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4259 | * If pCmd field of the corresponding lpfc_scsi_buf structure |
| 4260 | * points to a different SCSI command, then the driver has |
| 4261 | * already completed this command, but the midlayer did not |
| 4262 | * see the completion before the eh fired. Just return |
| 4263 | * SUCCESS. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4264 | */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4265 | iocb = &lpfc_cmd->cur_iocbq; |
| 4266 | if (lpfc_cmd->pCmd != cmnd) |
| 4267 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4268 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4269 | BUG_ON(iocb->context1 != lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4270 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4271 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| 4272 | if (abtsiocb == NULL) { |
| 4273 | ret = FAILED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4274 | goto out; |
| 4275 | } |
| 4276 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4277 | /* |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4278 | * The scsi command can not be in txq and it is in flight because the |
| 4279 | * pCmd is still pointig at the SCSI command we have to abort. There |
| 4280 | * is no need to search the txcmplq. Just send an abort to the FW. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4281 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4282 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4283 | cmd = &iocb->iocb; |
| 4284 | icmd = &abtsiocb->iocb; |
| 4285 | icmd->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 4286 | icmd->un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4287 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4288 | icmd->un.acxri.abortIoTag = iocb->sli4_xritag; |
| 4289 | else |
| 4290 | icmd->un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4291 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4292 | icmd->ulpLe = 1; |
| 4293 | icmd->ulpClass = cmd->ulpClass; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4294 | |
| 4295 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 4296 | abtsiocb->fcp_wqidx = iocb->fcp_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 4297 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4298 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4299 | if (lpfc_is_link_up(phba)) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4300 | icmd->ulpCommand = CMD_ABORT_XRI_CN; |
| 4301 | else |
| 4302 | icmd->ulpCommand = CMD_CLOSE_XRI_CN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4303 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4304 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4305 | abtsiocb->vport = vport; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4306 | if (lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, abtsiocb, 0) == |
| 4307 | IOCB_ERROR) { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4308 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| 4309 | ret = FAILED; |
| 4310 | goto out; |
| 4311 | } |
| 4312 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4313 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4314 | lpfc_sli_handle_fast_ring_event(phba, |
| 4315 | &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4316 | |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4317 | lpfc_cmd->waitq = &waitq; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4318 | /* Wait for abort to complete */ |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4319 | wait_event_timeout(waitq, |
| 4320 | (lpfc_cmd->pCmd != cmnd), |
| 4321 | (2*vport->cfg_devloss_tmo*HZ)); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4322 | |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4323 | spin_lock_irq(shost->host_lock); |
| 4324 | lpfc_cmd->waitq = NULL; |
| 4325 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4326 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4327 | if (lpfc_cmd->pCmd == cmnd) { |
| 4328 | ret = FAILED; |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4329 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 4330 | "0748 abort handler timed out waiting " |
| 4331 | "for abort to complete: ret %#x, ID %d, " |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 4332 | "LUN %d\n", |
| 4333 | ret, cmnd->device->id, cmnd->device->lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4334 | } |
| 4335 | |
| 4336 | out: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4337 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4338 | "0749 SCSI Layer I/O Abort Request Status x%x ID %d " |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 4339 | "LUN %d\n", ret, cmnd->device->id, |
| 4340 | cmnd->device->lun); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4341 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4342 | } |
| 4343 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4344 | static char * |
| 4345 | lpfc_taskmgmt_name(uint8_t task_mgmt_cmd) |
| 4346 | { |
| 4347 | switch (task_mgmt_cmd) { |
| 4348 | case FCP_ABORT_TASK_SET: |
| 4349 | return "ABORT_TASK_SET"; |
| 4350 | case FCP_CLEAR_TASK_SET: |
| 4351 | return "FCP_CLEAR_TASK_SET"; |
| 4352 | case FCP_BUS_RESET: |
| 4353 | return "FCP_BUS_RESET"; |
| 4354 | case FCP_LUN_RESET: |
| 4355 | return "FCP_LUN_RESET"; |
| 4356 | case FCP_TARGET_RESET: |
| 4357 | return "FCP_TARGET_RESET"; |
| 4358 | case FCP_CLEAR_ACA: |
| 4359 | return "FCP_CLEAR_ACA"; |
| 4360 | case FCP_TERMINATE_TASK: |
| 4361 | return "FCP_TERMINATE_TASK"; |
| 4362 | default: |
| 4363 | return "unknown"; |
| 4364 | } |
| 4365 | } |
| 4366 | |
| 4367 | /** |
| 4368 | * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler |
| 4369 | * @vport: The virtual port for which this call is being executed. |
| 4370 | * @rdata: Pointer to remote port local data |
| 4371 | * @tgt_id: Target ID of remote device. |
| 4372 | * @lun_id: Lun number for the TMF |
| 4373 | * @task_mgmt_cmd: type of TMF to send |
| 4374 | * |
| 4375 | * This routine builds and sends a TMF (SCSI Task Mgmt Function) to |
| 4376 | * a remote port. |
| 4377 | * |
| 4378 | * Return Code: |
| 4379 | * 0x2003 - Error |
| 4380 | * 0x2002 - Success. |
| 4381 | **/ |
| 4382 | static int |
| 4383 | lpfc_send_taskmgmt(struct lpfc_vport *vport, struct lpfc_rport_data *rdata, |
| 4384 | unsigned tgt_id, unsigned int lun_id, |
| 4385 | uint8_t task_mgmt_cmd) |
| 4386 | { |
| 4387 | struct lpfc_hba *phba = vport->phba; |
| 4388 | struct lpfc_scsi_buf *lpfc_cmd; |
| 4389 | struct lpfc_iocbq *iocbq; |
| 4390 | struct lpfc_iocbq *iocbqrsp; |
James Smart | 5989b8d | 2010-10-22 11:06:56 -0400 | [diff] [blame] | 4391 | struct lpfc_nodelist *pnode = rdata->pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4392 | int ret; |
| 4393 | int status; |
| 4394 | |
James Smart | 5989b8d | 2010-10-22 11:06:56 -0400 | [diff] [blame] | 4395 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4396 | return FAILED; |
| 4397 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4398 | lpfc_cmd = lpfc_get_scsi_buf(phba, rdata->pnode); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4399 | if (lpfc_cmd == NULL) |
| 4400 | return FAILED; |
| 4401 | lpfc_cmd->timeout = 60; |
| 4402 | lpfc_cmd->rdata = rdata; |
| 4403 | |
| 4404 | status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun_id, |
| 4405 | task_mgmt_cmd); |
| 4406 | if (!status) { |
| 4407 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 4408 | return FAILED; |
| 4409 | } |
| 4410 | |
| 4411 | iocbq = &lpfc_cmd->cur_iocbq; |
| 4412 | iocbqrsp = lpfc_sli_get_iocbq(phba); |
| 4413 | if (iocbqrsp == NULL) { |
| 4414 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 4415 | return FAILED; |
| 4416 | } |
| 4417 | |
| 4418 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4419 | "0702 Issue %s to TGT %d LUN %d " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4420 | "rpi x%x nlp_flag x%x Data: x%x x%x\n", |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4421 | lpfc_taskmgmt_name(task_mgmt_cmd), tgt_id, lun_id, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4422 | pnode->nlp_rpi, pnode->nlp_flag, iocbq->sli4_xritag, |
| 4423 | iocbq->iocb_flag); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4424 | |
| 4425 | status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING, |
| 4426 | iocbq, iocbqrsp, lpfc_cmd->timeout); |
| 4427 | if (status != IOCB_SUCCESS) { |
| 4428 | if (status == IOCB_TIMEDOUT) { |
| 4429 | iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl; |
| 4430 | ret = TIMEOUT_ERROR; |
| 4431 | } else |
| 4432 | ret = FAILED; |
| 4433 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; |
| 4434 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4435 | "0727 TMF %s to TGT %d LUN %d failed (%d, %d) " |
| 4436 | "iocb_flag x%x\n", |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4437 | lpfc_taskmgmt_name(task_mgmt_cmd), |
| 4438 | tgt_id, lun_id, iocbqrsp->iocb.ulpStatus, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4439 | iocbqrsp->iocb.un.ulpWord[4], |
| 4440 | iocbq->iocb_flag); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 4441 | } else if (status == IOCB_BUSY) |
| 4442 | ret = FAILED; |
| 4443 | else |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4444 | ret = SUCCESS; |
| 4445 | |
| 4446 | lpfc_sli_release_iocbq(phba, iocbqrsp); |
| 4447 | |
| 4448 | if (ret != TIMEOUT_ERROR) |
| 4449 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 4450 | |
| 4451 | return ret; |
| 4452 | } |
| 4453 | |
| 4454 | /** |
| 4455 | * lpfc_chk_tgt_mapped - |
| 4456 | * @vport: The virtual port to check on |
| 4457 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 4458 | * |
| 4459 | * This routine delays until the scsi target (aka rport) for the |
| 4460 | * command exists (is present and logged in) or we declare it non-existent. |
| 4461 | * |
| 4462 | * Return code : |
| 4463 | * 0x2003 - Error |
| 4464 | * 0x2002 - Success |
| 4465 | **/ |
| 4466 | static int |
| 4467 | lpfc_chk_tgt_mapped(struct lpfc_vport *vport, struct scsi_cmnd *cmnd) |
| 4468 | { |
| 4469 | struct lpfc_rport_data *rdata = cmnd->device->hostdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 4470 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4471 | unsigned long later; |
| 4472 | |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 4473 | if (!rdata) { |
| 4474 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4475 | "0797 Tgt Map rport failure: rdata x%p\n", rdata); |
| 4476 | return FAILED; |
| 4477 | } |
| 4478 | pnode = rdata->pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4479 | /* |
| 4480 | * If target is not in a MAPPED state, delay until |
| 4481 | * target is rediscovered or devloss timeout expires. |
| 4482 | */ |
| 4483 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; |
| 4484 | while (time_after(later, jiffies)) { |
| 4485 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 4486 | return FAILED; |
| 4487 | if (pnode->nlp_state == NLP_STE_MAPPED_NODE) |
| 4488 | return SUCCESS; |
| 4489 | schedule_timeout_uninterruptible(msecs_to_jiffies(500)); |
| 4490 | rdata = cmnd->device->hostdata; |
| 4491 | if (!rdata) |
| 4492 | return FAILED; |
| 4493 | pnode = rdata->pnode; |
| 4494 | } |
| 4495 | if (!pnode || !NLP_CHK_NODE_ACT(pnode) || |
| 4496 | (pnode->nlp_state != NLP_STE_MAPPED_NODE)) |
| 4497 | return FAILED; |
| 4498 | return SUCCESS; |
| 4499 | } |
| 4500 | |
| 4501 | /** |
| 4502 | * lpfc_reset_flush_io_context - |
| 4503 | * @vport: The virtual port (scsi_host) for the flush context |
| 4504 | * @tgt_id: If aborting by Target contect - specifies the target id |
| 4505 | * @lun_id: If aborting by Lun context - specifies the lun id |
| 4506 | * @context: specifies the context level to flush at. |
| 4507 | * |
| 4508 | * After a reset condition via TMF, we need to flush orphaned i/o |
| 4509 | * contexts from the adapter. This routine aborts any contexts |
| 4510 | * outstanding, then waits for their completions. The wait is |
| 4511 | * bounded by devloss_tmo though. |
| 4512 | * |
| 4513 | * Return code : |
| 4514 | * 0x2003 - Error |
| 4515 | * 0x2002 - Success |
| 4516 | **/ |
| 4517 | static int |
| 4518 | lpfc_reset_flush_io_context(struct lpfc_vport *vport, uint16_t tgt_id, |
| 4519 | uint64_t lun_id, lpfc_ctx_cmd context) |
| 4520 | { |
| 4521 | struct lpfc_hba *phba = vport->phba; |
| 4522 | unsigned long later; |
| 4523 | int cnt; |
| 4524 | |
| 4525 | cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context); |
| 4526 | if (cnt) |
| 4527 | lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring], |
| 4528 | tgt_id, lun_id, context); |
| 4529 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; |
| 4530 | while (time_after(later, jiffies) && cnt) { |
| 4531 | schedule_timeout_uninterruptible(msecs_to_jiffies(20)); |
| 4532 | cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context); |
| 4533 | } |
| 4534 | if (cnt) { |
| 4535 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 4536 | "0724 I/O flush failure for context %s : cnt x%x\n", |
| 4537 | ((context == LPFC_CTX_LUN) ? "LUN" : |
| 4538 | ((context == LPFC_CTX_TGT) ? "TGT" : |
| 4539 | ((context == LPFC_CTX_HOST) ? "HOST" : "Unknown"))), |
| 4540 | cnt); |
| 4541 | return FAILED; |
| 4542 | } |
| 4543 | return SUCCESS; |
| 4544 | } |
| 4545 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4546 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4547 | * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4548 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 4549 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4550 | * 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] | 4551 | * command. |
| 4552 | * |
| 4553 | * Return code : |
| 4554 | * 0x2003 - Error |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4555 | * 0x2002 - Success |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4556 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4557 | static int |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4558 | lpfc_device_reset_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4559 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4560 | struct Scsi_Host *shost = cmnd->device->host; |
| 4561 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4562 | struct lpfc_rport_data *rdata = cmnd->device->hostdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 4563 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4564 | unsigned tgt_id = cmnd->device->id; |
| 4565 | unsigned int lun_id = cmnd->device->lun; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4566 | struct lpfc_scsi_event_header scsi_event; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4567 | int status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4568 | |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 4569 | if (!rdata) { |
| 4570 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 4571 | "0798 Device Reset rport failure: rdata x%p\n", rdata); |
| 4572 | return FAILED; |
| 4573 | } |
| 4574 | pnode = rdata->pnode; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 4575 | status = fc_block_scsi_eh(cmnd); |
| 4576 | if (status) |
| 4577 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4578 | |
| 4579 | status = lpfc_chk_tgt_mapped(vport, cmnd); |
| 4580 | if (status == FAILED) { |
| 4581 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 4582 | "0721 Device Reset rport failure: rdata x%p\n", rdata); |
| 4583 | return FAILED; |
| 4584 | } |
| 4585 | |
| 4586 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 4587 | scsi_event.subcategory = LPFC_EVENT_LUNRESET; |
| 4588 | scsi_event.lun = lun_id; |
| 4589 | memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 4590 | memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 4591 | |
| 4592 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 4593 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
| 4594 | |
| 4595 | status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id, |
| 4596 | FCP_LUN_RESET); |
| 4597 | |
| 4598 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 4599 | "0713 SCSI layer issued Device Reset (%d, %d) " |
| 4600 | "return x%x\n", tgt_id, lun_id, status); |
| 4601 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4602 | /* |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4603 | * We have to clean up i/o as : they may be orphaned by the TMF; |
| 4604 | * or if the TMF failed, they may be in an indeterminate state. |
| 4605 | * So, continue on. |
| 4606 | * We will report success if all the i/o aborts successfully. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4607 | */ |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4608 | status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
| 4609 | LPFC_CTX_LUN); |
| 4610 | return status; |
| 4611 | } |
| 4612 | |
| 4613 | /** |
| 4614 | * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point |
| 4615 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 4616 | * |
| 4617 | * This routine does a target reset by sending a TARGET_RESET task management |
| 4618 | * command. |
| 4619 | * |
| 4620 | * Return code : |
| 4621 | * 0x2003 - Error |
| 4622 | * 0x2002 - Success |
| 4623 | **/ |
| 4624 | static int |
| 4625 | lpfc_target_reset_handler(struct scsi_cmnd *cmnd) |
| 4626 | { |
| 4627 | struct Scsi_Host *shost = cmnd->device->host; |
| 4628 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4629 | struct lpfc_rport_data *rdata = cmnd->device->hostdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 4630 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4631 | unsigned tgt_id = cmnd->device->id; |
| 4632 | unsigned int lun_id = cmnd->device->lun; |
| 4633 | struct lpfc_scsi_event_header scsi_event; |
| 4634 | int status; |
| 4635 | |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 4636 | if (!rdata) { |
| 4637 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 4638 | "0799 Target Reset rport failure: rdata x%p\n", rdata); |
| 4639 | return FAILED; |
| 4640 | } |
| 4641 | pnode = rdata->pnode; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 4642 | status = fc_block_scsi_eh(cmnd); |
| 4643 | if (status) |
| 4644 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4645 | |
| 4646 | status = lpfc_chk_tgt_mapped(vport, cmnd); |
| 4647 | if (status == FAILED) { |
| 4648 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 4649 | "0722 Target Reset rport failure: rdata x%p\n", rdata); |
| 4650 | return FAILED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4651 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4652 | |
| 4653 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 4654 | scsi_event.subcategory = LPFC_EVENT_TGTRESET; |
| 4655 | scsi_event.lun = 0; |
| 4656 | memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 4657 | memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 4658 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4659 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 4660 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4661 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4662 | status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id, |
| 4663 | FCP_TARGET_RESET); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4664 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4665 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4666 | "0723 SCSI layer issued Target Reset (%d, %d) " |
| 4667 | "return x%x\n", tgt_id, lun_id, status); |
| 4668 | |
| 4669 | /* |
| 4670 | * We have to clean up i/o as : they may be orphaned by the TMF; |
| 4671 | * or if the TMF failed, they may be in an indeterminate state. |
| 4672 | * So, continue on. |
| 4673 | * We will report success if all the i/o aborts successfully. |
| 4674 | */ |
| 4675 | status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
| 4676 | LPFC_CTX_TGT); |
| 4677 | return status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4678 | } |
| 4679 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4680 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4681 | * 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] | 4682 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 4683 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4684 | * This routine does target reset to all targets on @cmnd->device->host. |
| 4685 | * This emulates Parallel SCSI Bus Reset Semantics. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4686 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4687 | * Return code : |
| 4688 | * 0x2003 - Error |
| 4689 | * 0x2002 - Success |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4690 | **/ |
Jeff Garzik | 94d0e7b8 | 2005-05-28 07:55:48 -0400 | [diff] [blame] | 4691 | static int |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4692 | lpfc_bus_reset_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4693 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4694 | struct Scsi_Host *shost = cmnd->device->host; |
| 4695 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4696 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4697 | struct lpfc_scsi_event_header scsi_event; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4698 | int match; |
| 4699 | int ret = SUCCESS, status, i; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4700 | |
| 4701 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 4702 | scsi_event.subcategory = LPFC_EVENT_BUSRESET; |
| 4703 | scsi_event.lun = 0; |
| 4704 | memcpy(scsi_event.wwpn, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 4705 | memcpy(scsi_event.wwnn, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| 4706 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4707 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 4708 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4709 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 4710 | status = fc_block_scsi_eh(cmnd); |
| 4711 | if (status) |
| 4712 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4713 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4714 | /* |
| 4715 | * Since the driver manages a single bus device, reset all |
| 4716 | * targets known to the driver. Should any target reset |
| 4717 | * fail, this routine returns failure to the midlayer. |
| 4718 | */ |
James Smart | e17da18 | 2006-07-06 15:49:25 -0400 | [diff] [blame] | 4719 | for (i = 0; i < LPFC_MAX_TARGET; i++) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4720 | /* Search for mapped node by target ID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4721 | match = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4722 | spin_lock_irq(shost->host_lock); |
| 4723 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4724 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4725 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4726 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE && |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 4727 | ndlp->nlp_sid == i && |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4728 | ndlp->rport) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4729 | match = 1; |
| 4730 | break; |
| 4731 | } |
| 4732 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4733 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4734 | if (!match) |
| 4735 | continue; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4736 | |
| 4737 | status = lpfc_send_taskmgmt(vport, ndlp->rport->dd_data, |
| 4738 | i, 0, FCP_TARGET_RESET); |
| 4739 | |
| 4740 | if (status != SUCCESS) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4741 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 4742 | "0700 Bus Reset on target %d failed\n", |
| 4743 | i); |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 4744 | ret = FAILED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4745 | } |
| 4746 | } |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 4747 | /* |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4748 | * We have to clean up i/o as : they may be orphaned by the TMFs |
| 4749 | * above; or if any of the TMFs failed, they may be in an |
| 4750 | * indeterminate state. |
| 4751 | * 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] | 4752 | */ |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4753 | |
| 4754 | status = lpfc_reset_flush_io_context(vport, 0, 0, LPFC_CTX_HOST); |
| 4755 | if (status != SUCCESS) |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 4756 | ret = FAILED; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4757 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4758 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 4759 | "0714 SCSI layer issued Bus Reset Data: x%x\n", ret); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4760 | return ret; |
| 4761 | } |
| 4762 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4763 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4764 | * lpfc_slave_alloc - scsi_host_template slave_alloc entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4765 | * @sdev: Pointer to scsi_device. |
| 4766 | * |
| 4767 | * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's |
| 4768 | * globally available list of scsi buffers. This routine also makes sure scsi |
| 4769 | * buffer is not allocated more than HBA limit conveyed to midlayer. This list |
| 4770 | * of scsi buffer exists for the lifetime of the driver. |
| 4771 | * |
| 4772 | * Return codes: |
| 4773 | * non-0 - Error |
| 4774 | * 0 - Success |
| 4775 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4776 | static int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4777 | lpfc_slave_alloc(struct scsi_device *sdev) |
| 4778 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4779 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 4780 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4781 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4782 | uint32_t total = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4783 | uint32_t num_to_alloc = 0; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4784 | int num_allocated = 0; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 4785 | uint32_t sdev_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4786 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4787 | if (!rport || fc_remote_port_chkready(rport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4788 | return -ENXIO; |
| 4789 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4790 | sdev->hostdata = rport->dd_data; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 4791 | sdev_cnt = atomic_inc_return(&phba->sdev_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4792 | |
| 4793 | /* |
| 4794 | * Populate the cmds_per_lun count scsi_bufs into this host's globally |
| 4795 | * 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] | 4796 | * HBA limit conveyed to the midlayer via the host structure. The |
| 4797 | * formula accounts for the lun_queue_depth + error handlers + 1 |
| 4798 | * extra. This list of scsi bufs exists for the lifetime of the driver. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4799 | */ |
| 4800 | total = phba->total_scsi_bufs; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4801 | num_to_alloc = vport->cfg_lun_queue_depth + 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4802 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 4803 | /* If allocated buffers are enough do nothing */ |
| 4804 | if ((sdev_cnt * (vport->cfg_lun_queue_depth + 2)) < total) |
| 4805 | return 0; |
| 4806 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4807 | /* Allow some exchanges to be available always to complete discovery */ |
| 4808 | if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4809 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4810 | "0704 At limitation of %d preallocated " |
| 4811 | "command buffers\n", total); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4812 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4813 | /* Allow some exchanges to be available always to complete discovery */ |
| 4814 | } else if (total + num_to_alloc > |
| 4815 | phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4816 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4817 | "0705 Allocation request of %d " |
| 4818 | "command buffers will exceed max of %d. " |
| 4819 | "Reducing allocation request to %d.\n", |
| 4820 | num_to_alloc, phba->cfg_hba_queue_depth, |
| 4821 | (phba->cfg_hba_queue_depth - total)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4822 | num_to_alloc = phba->cfg_hba_queue_depth - total; |
| 4823 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4824 | num_allocated = lpfc_new_scsi_buf(vport, num_to_alloc); |
| 4825 | if (num_to_alloc != num_allocated) { |
| 4826 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4827 | "0708 Allocation request of %d " |
| 4828 | "command buffers did not succeed. " |
| 4829 | "Allocated %d buffers.\n", |
| 4830 | num_to_alloc, num_allocated); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4831 | } |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 4832 | if (num_allocated > 0) |
| 4833 | phba->total_scsi_bufs += num_allocated; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4834 | return 0; |
| 4835 | } |
| 4836 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4837 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4838 | * lpfc_slave_configure - scsi_host_template slave_configure entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4839 | * @sdev: Pointer to scsi_device. |
| 4840 | * |
| 4841 | * This routine configures following items |
| 4842 | * - Tag command queuing support for @sdev if supported. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4843 | * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set. |
| 4844 | * |
| 4845 | * Return codes: |
| 4846 | * 0 - Success |
| 4847 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4848 | static int |
| 4849 | lpfc_slave_configure(struct scsi_device *sdev) |
| 4850 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4851 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 4852 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4853 | |
| 4854 | if (sdev->tagged_supported) |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4855 | scsi_activate_tcq(sdev, vport->cfg_lun_queue_depth); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4856 | else |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4857 | scsi_deactivate_tcq(sdev, vport->cfg_lun_queue_depth); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4858 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4859 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4860 | lpfc_sli_handle_fast_ring_event(phba, |
| 4861 | &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4862 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 4863 | lpfc_poll_rearm_timer(phba); |
| 4864 | } |
| 4865 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4866 | return 0; |
| 4867 | } |
| 4868 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4869 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4870 | * lpfc_slave_destroy - slave_destroy entry point of SHT data structure |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4871 | * @sdev: Pointer to scsi_device. |
| 4872 | * |
| 4873 | * This routine sets @sdev hostatdata filed to null. |
| 4874 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4875 | static void |
| 4876 | lpfc_slave_destroy(struct scsi_device *sdev) |
| 4877 | { |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 4878 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 4879 | struct lpfc_hba *phba = vport->phba; |
| 4880 | atomic_dec(&phba->sdev_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4881 | sdev->hostdata = NULL; |
| 4882 | return; |
| 4883 | } |
| 4884 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4885 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4886 | struct scsi_host_template lpfc_template = { |
| 4887 | .module = THIS_MODULE, |
| 4888 | .name = LPFC_DRIVER_NAME, |
| 4889 | .info = lpfc_info, |
| 4890 | .queuecommand = lpfc_queuecommand, |
| 4891 | .eh_abort_handler = lpfc_abort_handler, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4892 | .eh_device_reset_handler = lpfc_device_reset_handler, |
| 4893 | .eh_target_reset_handler = lpfc_target_reset_handler, |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4894 | .eh_bus_reset_handler = lpfc_bus_reset_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4895 | .slave_alloc = lpfc_slave_alloc, |
| 4896 | .slave_configure = lpfc_slave_configure, |
| 4897 | .slave_destroy = lpfc_slave_destroy, |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4898 | .scan_finished = lpfc_scan_finished, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4899 | .this_id = -1, |
James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 4900 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4901 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
| 4902 | .use_clustering = ENABLE_CLUSTERING, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4903 | .shost_attrs = lpfc_hba_attrs, |
James.Smart@Emulex.Com | 564b296 | 2005-06-25 10:34:17 -0400 | [diff] [blame] | 4904 | .max_sectors = 0xFFFF, |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 4905 | .vendor_id = LPFC_NL_VENDOR_ID, |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4906 | .change_queue_depth = lpfc_change_queue_depth, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4907 | }; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4908 | |
| 4909 | struct scsi_host_template lpfc_vport_template = { |
| 4910 | .module = THIS_MODULE, |
| 4911 | .name = LPFC_DRIVER_NAME, |
| 4912 | .info = lpfc_info, |
| 4913 | .queuecommand = lpfc_queuecommand, |
| 4914 | .eh_abort_handler = lpfc_abort_handler, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4915 | .eh_device_reset_handler = lpfc_device_reset_handler, |
| 4916 | .eh_target_reset_handler = lpfc_target_reset_handler, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4917 | .eh_bus_reset_handler = lpfc_bus_reset_handler, |
| 4918 | .slave_alloc = lpfc_slave_alloc, |
| 4919 | .slave_configure = lpfc_slave_configure, |
| 4920 | .slave_destroy = lpfc_slave_destroy, |
| 4921 | .scan_finished = lpfc_scan_finished, |
| 4922 | .this_id = -1, |
James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 4923 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4924 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
| 4925 | .use_clustering = ENABLE_CLUSTERING, |
| 4926 | .shost_attrs = lpfc_vport_attrs, |
| 4927 | .max_sectors = 0xFFFF, |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4928 | .change_queue_depth = lpfc_change_queue_depth, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4929 | }; |