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