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