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 | 16a59fb | 2014-04-04 13:52:41 -0400 | [diff] [blame] | 4 | * Copyright (C) 2004-2014 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> |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 27 | #include <linux/crc-t10dif.h> |
| 28 | #include <net/checksum.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 29 | |
| 30 | #include <scsi/scsi.h> |
| 31 | #include <scsi/scsi_device.h> |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 32 | #include <scsi/scsi_eh.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 33 | #include <scsi/scsi_host.h> |
| 34 | #include <scsi/scsi_tcq.h> |
| 35 | #include <scsi/scsi_transport_fc.h> |
| 36 | |
| 37 | #include "lpfc_version.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 38 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 39 | #include "lpfc_hw.h" |
| 40 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 41 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 42 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 43 | #include "lpfc_disc.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 44 | #include "lpfc.h" |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 45 | #include "lpfc_scsi.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 46 | #include "lpfc_logmsg.h" |
| 47 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 48 | #include "lpfc_vport.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 49 | |
| 50 | #define LPFC_RESET_WAIT 2 |
| 51 | #define LPFC_ABORT_WAIT 2 |
| 52 | |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 53 | int _dump_buf_done = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 54 | |
| 55 | static char *dif_op_str[] = { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 56 | "PROT_NORMAL", |
| 57 | "PROT_READ_INSERT", |
| 58 | "PROT_WRITE_STRIP", |
| 59 | "PROT_READ_STRIP", |
| 60 | "PROT_WRITE_INSERT", |
| 61 | "PROT_READ_PASS", |
| 62 | "PROT_WRITE_PASS", |
| 63 | }; |
| 64 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 65 | struct scsi_dif_tuple { |
| 66 | __be16 guard_tag; /* Checksum */ |
| 67 | __be16 app_tag; /* Opaque storage */ |
| 68 | __be32 ref_tag; /* Target LBA or indirect LBA */ |
| 69 | }; |
| 70 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 71 | static struct lpfc_rport_data * |
| 72 | lpfc_rport_data_from_scsi_device(struct scsi_device *sdev) |
| 73 | { |
| 74 | struct lpfc_vport *vport = (struct lpfc_vport *)sdev->host->hostdata; |
| 75 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 76 | if (vport->phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 77 | return ((struct lpfc_device_data *)sdev->hostdata)->rport_data; |
| 78 | else |
| 79 | return (struct lpfc_rport_data *)sdev->hostdata; |
| 80 | } |
| 81 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 82 | static void |
| 83 | 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] | 84 | static void |
| 85 | lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb); |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 86 | static int |
| 87 | lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 88 | |
| 89 | static void |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 90 | lpfc_debug_save_data(struct lpfc_hba *phba, struct scsi_cmnd *cmnd) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 91 | { |
| 92 | void *src, *dst; |
| 93 | struct scatterlist *sgde = scsi_sglist(cmnd); |
| 94 | |
| 95 | if (!_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 96 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 97 | "9050 BLKGRD: ERROR %s _dump_buf_data is NULL\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 98 | __func__); |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | |
| 103 | if (!sgde) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 104 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 105 | "9051 BLKGRD: ERROR: data scatterlist is null\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 106 | return; |
| 107 | } |
| 108 | |
| 109 | dst = (void *) _dump_buf_data; |
| 110 | while (sgde) { |
| 111 | src = sg_virt(sgde); |
| 112 | memcpy(dst, src, sgde->length); |
| 113 | dst += sgde->length; |
| 114 | sgde = sg_next(sgde); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | static void |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 119 | lpfc_debug_save_dif(struct lpfc_hba *phba, struct scsi_cmnd *cmnd) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 120 | { |
| 121 | void *src, *dst; |
| 122 | struct scatterlist *sgde = scsi_prot_sglist(cmnd); |
| 123 | |
| 124 | if (!_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 125 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 126 | "9052 BLKGRD: ERROR %s _dump_buf_data is NULL\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 127 | __func__); |
| 128 | return; |
| 129 | } |
| 130 | |
| 131 | if (!sgde) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 132 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 133 | "9053 BLKGRD: ERROR: prot scatterlist is null\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 134 | return; |
| 135 | } |
| 136 | |
| 137 | dst = _dump_buf_dif; |
| 138 | while (sgde) { |
| 139 | src = sg_virt(sgde); |
| 140 | memcpy(dst, src, sgde->length); |
| 141 | dst += sgde->length; |
| 142 | sgde = sg_next(sgde); |
| 143 | } |
| 144 | } |
| 145 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 146 | static inline unsigned |
| 147 | lpfc_cmd_blksize(struct scsi_cmnd *sc) |
| 148 | { |
| 149 | return sc->device->sector_size; |
| 150 | } |
| 151 | |
| 152 | #define LPFC_CHECK_PROTECT_GUARD 1 |
| 153 | #define LPFC_CHECK_PROTECT_REF 2 |
| 154 | static inline unsigned |
| 155 | lpfc_cmd_protect(struct scsi_cmnd *sc, int flag) |
| 156 | { |
| 157 | return 1; |
| 158 | } |
| 159 | |
| 160 | static inline unsigned |
| 161 | lpfc_cmd_guard_csum(struct scsi_cmnd *sc) |
| 162 | { |
| 163 | if (lpfc_prot_group_type(NULL, sc) == LPFC_PG_TYPE_NO_DIF) |
| 164 | return 0; |
| 165 | if (scsi_host_get_guard(sc->device->host) == SHOST_DIX_GUARD_IP) |
| 166 | return 1; |
| 167 | return 0; |
| 168 | } |
| 169 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 170 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 171 | * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge. |
| 172 | * @phba: Pointer to HBA object. |
| 173 | * @lpfc_cmd: lpfc scsi command object pointer. |
| 174 | * |
| 175 | * This function is called from the lpfc_prep_task_mgmt_cmd function to |
| 176 | * set the last bit in the response sge entry. |
| 177 | **/ |
| 178 | static void |
| 179 | lpfc_sli4_set_rsp_sgl_last(struct lpfc_hba *phba, |
| 180 | struct lpfc_scsi_buf *lpfc_cmd) |
| 181 | { |
| 182 | struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 183 | if (sgl) { |
| 184 | sgl += 1; |
| 185 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 186 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 187 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 192 | * lpfc_update_stats - Update statistical data for the command completion |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 193 | * @phba: Pointer to HBA object. |
| 194 | * @lpfc_cmd: lpfc scsi command object pointer. |
| 195 | * |
| 196 | * This function is called when there is a command completion and this |
| 197 | * function updates the statistical data for the command completion. |
| 198 | **/ |
| 199 | static void |
| 200 | lpfc_update_stats(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 201 | { |
| 202 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| 203 | struct lpfc_nodelist *pnode = rdata->pnode; |
| 204 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 205 | unsigned long flags; |
| 206 | struct Scsi_Host *shost = cmd->device->host; |
| 207 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 208 | unsigned long latency; |
| 209 | int i; |
| 210 | |
| 211 | if (cmd->result) |
| 212 | return; |
| 213 | |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 214 | latency = jiffies_to_msecs((long)jiffies - (long)lpfc_cmd->start_time); |
| 215 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 216 | spin_lock_irqsave(shost->host_lock, flags); |
| 217 | if (!vport->stat_data_enabled || |
| 218 | vport->stat_data_blocked || |
James Smart | 5989b8d | 2010-10-22 11:06:56 -0400 | [diff] [blame] | 219 | !pnode || |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 220 | !pnode->lat_data || |
| 221 | (phba->bucket_type == LPFC_NO_BUCKET)) { |
| 222 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 223 | return; |
| 224 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 225 | |
| 226 | if (phba->bucket_type == LPFC_LINEAR_BUCKET) { |
| 227 | i = (latency + phba->bucket_step - 1 - phba->bucket_base)/ |
| 228 | phba->bucket_step; |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 229 | /* check array subscript bounds */ |
| 230 | if (i < 0) |
| 231 | i = 0; |
| 232 | else if (i >= LPFC_MAX_BUCKET_COUNT) |
| 233 | i = LPFC_MAX_BUCKET_COUNT - 1; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 234 | } else { |
| 235 | for (i = 0; i < LPFC_MAX_BUCKET_COUNT-1; i++) |
| 236 | if (latency <= (phba->bucket_base + |
| 237 | ((1<<i)*phba->bucket_step))) |
| 238 | break; |
| 239 | } |
| 240 | |
| 241 | pnode->lat_data[i].cmd_count++; |
| 242 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 243 | } |
| 244 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 245 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 246 | * lpfc_send_sdev_queuedepth_change_event - Posts a queuedepth change event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 247 | * @phba: Pointer to HBA context object. |
| 248 | * @vport: Pointer to vport object. |
| 249 | * @ndlp: Pointer to FC node associated with the target. |
| 250 | * @lun: Lun number of the scsi device. |
| 251 | * @old_val: Old value of the queue depth. |
| 252 | * @new_val: New value of the queue depth. |
| 253 | * |
| 254 | * This function sends an event to the mgmt application indicating |
| 255 | * there is a change in the scsi device queue depth. |
| 256 | **/ |
| 257 | static void |
| 258 | lpfc_send_sdev_queuedepth_change_event(struct lpfc_hba *phba, |
| 259 | struct lpfc_vport *vport, |
| 260 | struct lpfc_nodelist *ndlp, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 261 | uint64_t lun, |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 262 | uint32_t old_val, |
| 263 | uint32_t new_val) |
| 264 | { |
| 265 | struct lpfc_fast_path_event *fast_path_evt; |
| 266 | unsigned long flags; |
| 267 | |
| 268 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 269 | if (!fast_path_evt) |
| 270 | return; |
| 271 | |
| 272 | fast_path_evt->un.queue_depth_evt.scsi_event.event_type = |
| 273 | FC_REG_SCSI_EVENT; |
| 274 | fast_path_evt->un.queue_depth_evt.scsi_event.subcategory = |
| 275 | LPFC_EVENT_VARQUEDEPTH; |
| 276 | |
| 277 | /* Report all luns with change in queue depth */ |
| 278 | fast_path_evt->un.queue_depth_evt.scsi_event.lun = lun; |
| 279 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
| 280 | memcpy(&fast_path_evt->un.queue_depth_evt.scsi_event.wwpn, |
| 281 | &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 282 | memcpy(&fast_path_evt->un.queue_depth_evt.scsi_event.wwnn, |
| 283 | &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 284 | } |
| 285 | |
| 286 | fast_path_evt->un.queue_depth_evt.oldval = old_val; |
| 287 | fast_path_evt->un.queue_depth_evt.newval = new_val; |
| 288 | fast_path_evt->vport = vport; |
| 289 | |
| 290 | fast_path_evt->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT; |
| 291 | spin_lock_irqsave(&phba->hbalock, flags); |
| 292 | list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list); |
| 293 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 294 | lpfc_worker_wake_up(phba); |
| 295 | |
| 296 | return; |
| 297 | } |
| 298 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 299 | /** |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 300 | * lpfc_change_queue_depth - Alter scsi device queue depth |
| 301 | * @sdev: Pointer the scsi device on which to change the queue depth. |
| 302 | * @qdepth: New queue depth to set the sdev to. |
| 303 | * @reason: The reason for the queue depth change. |
| 304 | * |
| 305 | * This function is called by the midlayer and the LLD to alter the queue |
| 306 | * depth for a scsi device. This function sets the queue depth to the new |
| 307 | * value and sends an event out to log the queue depth change. |
| 308 | **/ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 309 | static int |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 310 | lpfc_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason) |
| 311 | { |
| 312 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 313 | struct lpfc_hba *phba = vport->phba; |
| 314 | struct lpfc_rport_data *rdata; |
| 315 | unsigned long new_queue_depth, old_queue_depth; |
| 316 | |
| 317 | old_queue_depth = sdev->queue_depth; |
James Smart | 6ff8556 | 2014-02-20 09:57:08 -0500 | [diff] [blame] | 318 | |
| 319 | switch (reason) { |
| 320 | case SCSI_QDEPTH_DEFAULT: |
| 321 | /* change request from sysfs, fall through */ |
| 322 | case SCSI_QDEPTH_RAMP_UP: |
Christoph Hellwig | c8b09f6 | 2014-11-03 20:15:14 +0100 | [diff] [blame] | 323 | scsi_adjust_queue_depth(sdev, qdepth); |
James Smart | 6ff8556 | 2014-02-20 09:57:08 -0500 | [diff] [blame] | 324 | break; |
| 325 | case SCSI_QDEPTH_QFULL: |
| 326 | if (scsi_track_queue_full(sdev, qdepth) == 0) |
| 327 | return sdev->queue_depth; |
| 328 | |
| 329 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 330 | "0711 detected queue full - lun queue " |
| 331 | "depth adjusted to %d.\n", sdev->queue_depth); |
| 332 | break; |
| 333 | default: |
| 334 | return -EOPNOTSUPP; |
| 335 | } |
| 336 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 337 | new_queue_depth = sdev->queue_depth; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 338 | rdata = lpfc_rport_data_from_scsi_device(sdev); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 339 | if (rdata) |
| 340 | lpfc_send_sdev_queuedepth_change_event(phba, vport, |
| 341 | rdata->pnode, sdev->lun, |
| 342 | old_queue_depth, |
| 343 | new_queue_depth); |
| 344 | return sdev->queue_depth; |
| 345 | } |
| 346 | |
| 347 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 348 | * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 349 | * @phba: The Hba for which this call is being executed. |
| 350 | * |
| 351 | * This routine is called when there is resource error in driver or firmware. |
| 352 | * This routine posts WORKER_RAMP_DOWN_QUEUE event for @phba. This routine |
| 353 | * posts at most 1 event each second. This routine wakes up worker thread of |
| 354 | * @phba to process WORKER_RAM_DOWN_EVENT event. |
| 355 | * |
| 356 | * This routine should be called with no lock held. |
| 357 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 358 | void |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 359 | lpfc_rampdown_queue_depth(struct lpfc_hba *phba) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 360 | { |
| 361 | unsigned long flags; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 362 | uint32_t evt_posted; |
Manuel Schölling | 0d4aec1 | 2014-09-03 12:55:58 -0400 | [diff] [blame] | 363 | unsigned long expires; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 364 | |
| 365 | spin_lock_irqsave(&phba->hbalock, flags); |
| 366 | atomic_inc(&phba->num_rsrc_err); |
| 367 | phba->last_rsrc_error_time = jiffies; |
| 368 | |
Manuel Schölling | 0d4aec1 | 2014-09-03 12:55:58 -0400 | [diff] [blame] | 369 | expires = phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL; |
| 370 | if (time_after(expires, jiffies)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 371 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 372 | return; |
| 373 | } |
| 374 | |
| 375 | phba->last_ramp_down_time = jiffies; |
| 376 | |
| 377 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 378 | |
| 379 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 380 | evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE; |
| 381 | if (!evt_posted) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 382 | phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 383 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
| 384 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 385 | if (!evt_posted) |
| 386 | lpfc_worker_wake_up(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 387 | return; |
| 388 | } |
| 389 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 390 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 391 | * lpfc_ramp_down_queue_handler - WORKER_RAMP_DOWN_QUEUE event handler |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 392 | * @phba: The Hba for which this call is being executed. |
| 393 | * |
| 394 | * This routine is called to process WORKER_RAMP_DOWN_QUEUE event for worker |
| 395 | * thread.This routine reduces queue depth for all scsi device on each vport |
| 396 | * associated with @phba. |
| 397 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 398 | void |
| 399 | lpfc_ramp_down_queue_handler(struct lpfc_hba *phba) |
| 400 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 401 | struct lpfc_vport **vports; |
| 402 | struct Scsi_Host *shost; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 403 | struct scsi_device *sdev; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 404 | unsigned long new_queue_depth; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 405 | unsigned long num_rsrc_err, num_cmd_success; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 406 | int i; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 407 | |
| 408 | num_rsrc_err = atomic_read(&phba->num_rsrc_err); |
| 409 | num_cmd_success = atomic_read(&phba->num_cmd_success); |
| 410 | |
James Smart | 75ad83a | 2012-05-09 21:18:40 -0400 | [diff] [blame] | 411 | /* |
| 412 | * The error and success command counters are global per |
| 413 | * driver instance. If another handler has already |
| 414 | * operated on this error event, just exit. |
| 415 | */ |
| 416 | if (num_rsrc_err == 0) |
| 417 | return; |
| 418 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 419 | vports = lpfc_create_vport_work_array(phba); |
| 420 | if (vports != NULL) |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 421 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 422 | shost = lpfc_shost_from_vport(vports[i]); |
| 423 | shost_for_each_device(sdev, shost) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 424 | new_queue_depth = |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 425 | sdev->queue_depth * num_rsrc_err / |
| 426 | (num_rsrc_err + num_cmd_success); |
| 427 | if (!new_queue_depth) |
| 428 | new_queue_depth = sdev->queue_depth - 1; |
| 429 | else |
| 430 | new_queue_depth = sdev->queue_depth - |
| 431 | new_queue_depth; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 432 | lpfc_change_queue_depth(sdev, new_queue_depth, |
| 433 | SCSI_QDEPTH_DEFAULT); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 434 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 435 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 436 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 437 | atomic_set(&phba->num_rsrc_err, 0); |
| 438 | atomic_set(&phba->num_cmd_success, 0); |
| 439 | } |
| 440 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 441 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 442 | * lpfc_scsi_dev_block - set all scsi hosts to block state |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 443 | * @phba: Pointer to HBA context object. |
| 444 | * |
| 445 | * This function walks vport list and set each SCSI host to block state |
| 446 | * by invoking fc_remote_port_delete() routine. This function is invoked |
| 447 | * with EEH when device's PCI slot has been permanently disabled. |
| 448 | **/ |
| 449 | void |
| 450 | lpfc_scsi_dev_block(struct lpfc_hba *phba) |
| 451 | { |
| 452 | struct lpfc_vport **vports; |
| 453 | struct Scsi_Host *shost; |
| 454 | struct scsi_device *sdev; |
| 455 | struct fc_rport *rport; |
| 456 | int i; |
| 457 | |
| 458 | vports = lpfc_create_vport_work_array(phba); |
| 459 | if (vports != NULL) |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 460 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 461 | shost = lpfc_shost_from_vport(vports[i]); |
| 462 | shost_for_each_device(sdev, shost) { |
| 463 | rport = starget_to_rport(scsi_target(sdev)); |
| 464 | fc_remote_port_delete(rport); |
| 465 | } |
| 466 | } |
| 467 | lpfc_destroy_vport_work_array(phba, vports); |
| 468 | } |
| 469 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 470 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 471 | * 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] | 472 | * @vport: The virtual port for which this call being executed. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 473 | * @num_to_allocate: The requested number of buffers to allocate. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 474 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 475 | * This routine allocates a scsi buffer for device with SLI-3 interface spec, |
| 476 | * the scsi buffer contains all the necessary information needed to initiate |
| 477 | * a SCSI I/O. The non-DMAable buffer region contains information to build |
| 478 | * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP, |
| 479 | * and the initial BPL. In addition to allocating memory, the FCP CMND and |
| 480 | * 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] | 481 | * |
| 482 | * Return codes: |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 483 | * int - number of scsi buffers that were allocated. |
| 484 | * 0 = failure, less than num_to_alloc is a partial failure. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 485 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 486 | static int |
| 487 | lpfc_new_scsi_buf_s3(struct lpfc_vport *vport, int num_to_alloc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 488 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 489 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 490 | struct lpfc_scsi_buf *psb; |
| 491 | struct ulp_bde64 *bpl; |
| 492 | IOCB_t *iocb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 493 | dma_addr_t pdma_phys_fcp_cmd; |
| 494 | dma_addr_t pdma_phys_fcp_rsp; |
| 495 | dma_addr_t pdma_phys_bpl; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 496 | uint16_t iotag; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 497 | int bcnt, bpl_size; |
| 498 | |
| 499 | bpl_size = phba->cfg_sg_dma_buf_size - |
| 500 | (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); |
| 501 | |
| 502 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 503 | "9067 ALLOC %d scsi_bufs: %d (%d + %d + %d)\n", |
| 504 | num_to_alloc, phba->cfg_sg_dma_buf_size, |
| 505 | (int)sizeof(struct fcp_cmnd), |
| 506 | (int)sizeof(struct fcp_rsp), bpl_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 507 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 508 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
| 509 | psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL); |
| 510 | if (!psb) |
| 511 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 512 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 513 | /* |
| 514 | * Get memory from the pci pool to map the virt space to pci |
| 515 | * bus space for an I/O. The DMA buffer includes space for the |
| 516 | * struct fcp_cmnd, struct fcp_rsp and the number of bde's |
| 517 | * necessary to support the sg_tablesize. |
| 518 | */ |
| 519 | psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool, |
| 520 | GFP_KERNEL, &psb->dma_handle); |
| 521 | if (!psb->data) { |
| 522 | kfree(psb); |
| 523 | break; |
| 524 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 525 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 526 | /* Initialize virtual ptrs to dma_buf region. */ |
| 527 | memset(psb->data, 0, phba->cfg_sg_dma_buf_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 528 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 529 | /* Allocate iotag for psb->cur_iocbq. */ |
| 530 | iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq); |
| 531 | if (iotag == 0) { |
| 532 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, |
| 533 | psb->data, psb->dma_handle); |
| 534 | kfree(psb); |
| 535 | break; |
| 536 | } |
| 537 | psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 538 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 539 | psb->fcp_cmnd = psb->data; |
| 540 | psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd); |
| 541 | psb->fcp_bpl = psb->data + sizeof(struct fcp_cmnd) + |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 542 | sizeof(struct fcp_rsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 543 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 544 | /* Initialize local short-hand pointers. */ |
| 545 | bpl = psb->fcp_bpl; |
| 546 | pdma_phys_fcp_cmd = psb->dma_handle; |
| 547 | pdma_phys_fcp_rsp = psb->dma_handle + sizeof(struct fcp_cmnd); |
| 548 | pdma_phys_bpl = psb->dma_handle + sizeof(struct fcp_cmnd) + |
| 549 | sizeof(struct fcp_rsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 550 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 551 | /* |
| 552 | * The first two bdes are the FCP_CMD and FCP_RSP. The balance |
| 553 | * are sg list bdes. Initialize the first two and leave the |
| 554 | * rest for queuecommand. |
| 555 | */ |
| 556 | bpl[0].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd)); |
| 557 | bpl[0].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd)); |
| 558 | bpl[0].tus.f.bdeSize = sizeof(struct fcp_cmnd); |
| 559 | bpl[0].tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 560 | bpl[0].tus.w = le32_to_cpu(bpl[0].tus.w); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 561 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 562 | /* Setup the physical region for the FCP RSP */ |
| 563 | bpl[1].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp)); |
| 564 | bpl[1].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp)); |
| 565 | bpl[1].tus.f.bdeSize = sizeof(struct fcp_rsp); |
| 566 | bpl[1].tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 567 | bpl[1].tus.w = le32_to_cpu(bpl[1].tus.w); |
| 568 | |
| 569 | /* |
| 570 | * Since the IOCB for the FCP I/O is built into this |
| 571 | * lpfc_scsi_buf, initialize it with all known data now. |
| 572 | */ |
| 573 | iocb = &psb->cur_iocbq.iocb; |
| 574 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; |
| 575 | if ((phba->sli_rev == 3) && |
| 576 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) { |
| 577 | /* fill in immediate fcp command BDE */ |
| 578 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_IMMED; |
| 579 | iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); |
| 580 | iocb->un.fcpi64.bdl.addrLow = offsetof(IOCB_t, |
| 581 | unsli3.fcp_ext.icd); |
| 582 | iocb->un.fcpi64.bdl.addrHigh = 0; |
| 583 | iocb->ulpBdeCount = 0; |
| 584 | iocb->ulpLe = 0; |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 585 | /* fill in response BDE */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 586 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeFlags = |
| 587 | BUFF_TYPE_BDE_64; |
| 588 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeSize = |
| 589 | sizeof(struct fcp_rsp); |
| 590 | iocb->unsli3.fcp_ext.rbde.addrLow = |
| 591 | putPaddrLow(pdma_phys_fcp_rsp); |
| 592 | iocb->unsli3.fcp_ext.rbde.addrHigh = |
| 593 | putPaddrHigh(pdma_phys_fcp_rsp); |
| 594 | } else { |
| 595 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
| 596 | iocb->un.fcpi64.bdl.bdeSize = |
| 597 | (2 * sizeof(struct ulp_bde64)); |
| 598 | iocb->un.fcpi64.bdl.addrLow = |
| 599 | putPaddrLow(pdma_phys_bpl); |
| 600 | iocb->un.fcpi64.bdl.addrHigh = |
| 601 | putPaddrHigh(pdma_phys_bpl); |
| 602 | iocb->ulpBdeCount = 1; |
| 603 | iocb->ulpLe = 1; |
| 604 | } |
| 605 | iocb->ulpClass = CLASS3; |
| 606 | psb->status = IOSTAT_SUCCESS; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 607 | /* Put it back into the SCSI buffer list */ |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 608 | psb->cur_iocbq.context1 = psb; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 609 | lpfc_release_scsi_buf_s3(phba, psb); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 610 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 611 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 612 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 613 | return bcnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 614 | } |
| 615 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 616 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 617 | * lpfc_sli4_vport_delete_fcp_xri_aborted -Remove all ndlp references for vport |
| 618 | * @vport: pointer to lpfc vport data structure. |
| 619 | * |
| 620 | * This routine is invoked by the vport cleanup for deletions and the cleanup |
| 621 | * for an ndlp on removal. |
| 622 | **/ |
| 623 | void |
| 624 | lpfc_sli4_vport_delete_fcp_xri_aborted(struct lpfc_vport *vport) |
| 625 | { |
| 626 | struct lpfc_hba *phba = vport->phba; |
| 627 | struct lpfc_scsi_buf *psb, *next_psb; |
| 628 | unsigned long iflag = 0; |
| 629 | |
| 630 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 631 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 632 | list_for_each_entry_safe(psb, next_psb, |
| 633 | &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) { |
| 634 | if (psb->rdata && psb->rdata->pnode |
| 635 | && psb->rdata->pnode->vport == vport) |
| 636 | psb->rdata = NULL; |
| 637 | } |
| 638 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 639 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 640 | } |
| 641 | |
| 642 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 643 | * lpfc_sli4_fcp_xri_aborted - Fast-path process of fcp xri abort |
| 644 | * @phba: pointer to lpfc hba data structure. |
| 645 | * @axri: pointer to the fcp xri abort wcqe structure. |
| 646 | * |
| 647 | * This routine is invoked by the worker thread to process a SLI4 fast-path |
| 648 | * FCP aborted xri. |
| 649 | **/ |
| 650 | void |
| 651 | lpfc_sli4_fcp_xri_aborted(struct lpfc_hba *phba, |
| 652 | struct sli4_wcqe_xri_aborted *axri) |
| 653 | { |
| 654 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 655 | uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 656 | struct lpfc_scsi_buf *psb, *next_psb; |
| 657 | unsigned long iflag = 0; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 658 | struct lpfc_iocbq *iocbq; |
| 659 | int i; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 660 | struct lpfc_nodelist *ndlp; |
| 661 | int rrq_empty = 0; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 662 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 663 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 664 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 665 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 666 | list_for_each_entry_safe(psb, next_psb, |
| 667 | &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) { |
| 668 | if (psb->cur_iocbq.sli4_xritag == xri) { |
| 669 | list_del(&psb->list); |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 670 | psb->exch_busy = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 671 | psb->status = IOSTAT_SUCCESS; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 672 | spin_unlock( |
| 673 | &phba->sli4_hba.abts_scsi_buf_list_lock); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 674 | if (psb->rdata && psb->rdata->pnode) |
| 675 | ndlp = psb->rdata->pnode; |
| 676 | else |
| 677 | ndlp = NULL; |
| 678 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 679 | rrq_empty = list_empty(&phba->active_rrq_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 680 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 681 | if (ndlp) { |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 682 | lpfc_set_rrq_active(phba, ndlp, |
| 683 | psb->cur_iocbq.sli4_lxritag, rxid, 1); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 684 | lpfc_sli4_abts_err_handler(phba, ndlp, axri); |
| 685 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 686 | lpfc_release_scsi_buf_s4(phba, psb); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 687 | if (rrq_empty) |
| 688 | lpfc_worker_wake_up(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 689 | return; |
| 690 | } |
| 691 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 692 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 693 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 694 | iocbq = phba->sli.iocbq_lookup[i]; |
| 695 | |
| 696 | if (!(iocbq->iocb_flag & LPFC_IO_FCP) || |
| 697 | (iocbq->iocb_flag & LPFC_IO_LIBDFC)) |
| 698 | continue; |
| 699 | if (iocbq->sli4_xritag != xri) |
| 700 | continue; |
| 701 | psb = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
| 702 | psb->exch_busy = 0; |
| 703 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 704 | if (!list_empty(&pring->txq)) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 705 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 706 | return; |
| 707 | |
| 708 | } |
| 709 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 713 | * lpfc_sli4_post_scsi_sgl_list - Psot blocks of scsi buffer sgls from a list |
| 714 | * @phba: pointer to lpfc hba data structure. |
| 715 | * @post_sblist: pointer to the scsi buffer list. |
| 716 | * |
| 717 | * This routine walks a list of scsi buffers that was passed in. It attempts |
| 718 | * to construct blocks of scsi buffer sgls which contains contiguous xris and |
| 719 | * uses the non-embedded SGL block post mailbox commands to post to the port. |
| 720 | * For single SCSI buffer sgl with non-contiguous xri, if any, it shall use |
| 721 | * embedded SGL post mailbox command for posting. The @post_sblist passed in |
| 722 | * must be local list, thus no lock is needed when manipulate the list. |
| 723 | * |
| 724 | * Returns: 0 = failure, non-zero number of successfully posted buffers. |
| 725 | **/ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 726 | static int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 727 | lpfc_sli4_post_scsi_sgl_list(struct lpfc_hba *phba, |
| 728 | struct list_head *post_sblist, int sb_count) |
| 729 | { |
| 730 | struct lpfc_scsi_buf *psb, *psb_next; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 731 | int status, sgl_size; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 732 | int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0; |
| 733 | dma_addr_t pdma_phys_bpl1; |
| 734 | int last_xritag = NO_XRI; |
| 735 | LIST_HEAD(prep_sblist); |
| 736 | LIST_HEAD(blck_sblist); |
| 737 | LIST_HEAD(scsi_sblist); |
| 738 | |
| 739 | /* sanity check */ |
| 740 | if (sb_count <= 0) |
| 741 | return -EINVAL; |
| 742 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 743 | sgl_size = phba->cfg_sg_dma_buf_size - |
| 744 | (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); |
| 745 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 746 | list_for_each_entry_safe(psb, psb_next, post_sblist, list) { |
| 747 | list_del_init(&psb->list); |
| 748 | block_cnt++; |
| 749 | if ((last_xritag != NO_XRI) && |
| 750 | (psb->cur_iocbq.sli4_xritag != last_xritag + 1)) { |
| 751 | /* a hole in xri block, form a sgl posting block */ |
| 752 | list_splice_init(&prep_sblist, &blck_sblist); |
| 753 | post_cnt = block_cnt - 1; |
| 754 | /* prepare list for next posting block */ |
| 755 | list_add_tail(&psb->list, &prep_sblist); |
| 756 | block_cnt = 1; |
| 757 | } else { |
| 758 | /* prepare list for next posting block */ |
| 759 | list_add_tail(&psb->list, &prep_sblist); |
| 760 | /* enough sgls for non-embed sgl mbox command */ |
| 761 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 762 | list_splice_init(&prep_sblist, &blck_sblist); |
| 763 | post_cnt = block_cnt; |
| 764 | block_cnt = 0; |
| 765 | } |
| 766 | } |
| 767 | num_posting++; |
| 768 | last_xritag = psb->cur_iocbq.sli4_xritag; |
| 769 | |
| 770 | /* end of repost sgl list condition for SCSI buffers */ |
| 771 | if (num_posting == sb_count) { |
| 772 | if (post_cnt == 0) { |
| 773 | /* last sgl posting block */ |
| 774 | list_splice_init(&prep_sblist, &blck_sblist); |
| 775 | post_cnt = block_cnt; |
| 776 | } else if (block_cnt == 1) { |
| 777 | /* last single sgl with non-contiguous xri */ |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 778 | if (sgl_size > SGL_PAGE_SIZE) |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 779 | pdma_phys_bpl1 = psb->dma_phys_bpl + |
| 780 | SGL_PAGE_SIZE; |
| 781 | else |
| 782 | pdma_phys_bpl1 = 0; |
| 783 | status = lpfc_sli4_post_sgl(phba, |
| 784 | psb->dma_phys_bpl, |
| 785 | pdma_phys_bpl1, |
| 786 | psb->cur_iocbq.sli4_xritag); |
| 787 | if (status) { |
| 788 | /* failure, put on abort scsi list */ |
| 789 | psb->exch_busy = 1; |
| 790 | } else { |
| 791 | /* success, put on SCSI buffer list */ |
| 792 | psb->exch_busy = 0; |
| 793 | psb->status = IOSTAT_SUCCESS; |
| 794 | num_posted++; |
| 795 | } |
| 796 | /* success, put on SCSI buffer sgl list */ |
| 797 | list_add_tail(&psb->list, &scsi_sblist); |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | /* continue until a nembed page worth of sgls */ |
| 802 | if (post_cnt == 0) |
| 803 | continue; |
| 804 | |
| 805 | /* post block of SCSI buffer list sgls */ |
| 806 | status = lpfc_sli4_post_scsi_sgl_block(phba, &blck_sblist, |
| 807 | post_cnt); |
| 808 | |
| 809 | /* don't reset xirtag due to hole in xri block */ |
| 810 | if (block_cnt == 0) |
| 811 | last_xritag = NO_XRI; |
| 812 | |
| 813 | /* reset SCSI buffer post count for next round of posting */ |
| 814 | post_cnt = 0; |
| 815 | |
| 816 | /* put posted SCSI buffer-sgl posted on SCSI buffer sgl list */ |
| 817 | while (!list_empty(&blck_sblist)) { |
| 818 | list_remove_head(&blck_sblist, psb, |
| 819 | struct lpfc_scsi_buf, list); |
| 820 | if (status) { |
| 821 | /* failure, put on abort scsi list */ |
| 822 | psb->exch_busy = 1; |
| 823 | } else { |
| 824 | /* success, put on SCSI buffer list */ |
| 825 | psb->exch_busy = 0; |
| 826 | psb->status = IOSTAT_SUCCESS; |
| 827 | num_posted++; |
| 828 | } |
| 829 | list_add_tail(&psb->list, &scsi_sblist); |
| 830 | } |
| 831 | } |
| 832 | /* Push SCSI buffers with sgl posted to the availble list */ |
| 833 | while (!list_empty(&scsi_sblist)) { |
| 834 | list_remove_head(&scsi_sblist, psb, |
| 835 | struct lpfc_scsi_buf, list); |
| 836 | lpfc_release_scsi_buf_s4(phba, psb); |
| 837 | } |
| 838 | return num_posted; |
| 839 | } |
| 840 | |
| 841 | /** |
| 842 | * lpfc_sli4_repost_scsi_sgl_list - Repsot all the allocated scsi buffer sgls |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 843 | * @phba: pointer to lpfc hba data structure. |
| 844 | * |
| 845 | * This routine walks the list of scsi buffers that have been allocated and |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 846 | * repost them to the port by using SGL block post. This is needed after a |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 847 | * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine |
| 848 | * is responsible for moving all scsi buffers on the lpfc_abts_scsi_sgl_list |
| 849 | * to the lpfc_scsi_buf_list. If the repost fails, reject all scsi buffers. |
| 850 | * |
| 851 | * Returns: 0 = success, non-zero failure. |
| 852 | **/ |
| 853 | int |
| 854 | lpfc_sli4_repost_scsi_sgl_list(struct lpfc_hba *phba) |
| 855 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 856 | LIST_HEAD(post_sblist); |
| 857 | int num_posted, rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 858 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 859 | /* get all SCSI buffers need to repost to a local list */ |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 860 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 861 | spin_lock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 862 | list_splice_init(&phba->lpfc_scsi_buf_list_get, &post_sblist); |
| 863 | list_splice(&phba->lpfc_scsi_buf_list_put, &post_sblist); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 864 | spin_unlock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 865 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 866 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 867 | /* post the list of scsi buffer sgls to port if available */ |
| 868 | if (!list_empty(&post_sblist)) { |
| 869 | num_posted = lpfc_sli4_post_scsi_sgl_list(phba, &post_sblist, |
| 870 | phba->sli4_hba.scsi_xri_cnt); |
| 871 | /* failed to post any scsi buffer, return error */ |
| 872 | if (num_posted == 0) |
| 873 | rc = -EIO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 874 | } |
| 875 | return rc; |
| 876 | } |
| 877 | |
| 878 | /** |
| 879 | * lpfc_new_scsi_buf_s4 - Scsi buffer allocator for HBA with SLI4 IF spec |
| 880 | * @vport: The virtual port for which this call being executed. |
| 881 | * @num_to_allocate: The requested number of buffers to allocate. |
| 882 | * |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 883 | * This routine allocates scsi buffers for device with SLI-4 interface spec, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 884 | * the scsi buffer contains all the necessary information needed to initiate |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 885 | * a SCSI I/O. After allocating up to @num_to_allocate SCSI buffers and put |
| 886 | * them on a list, it post them to the port by using SGL block post. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 887 | * |
| 888 | * Return codes: |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 889 | * int - number of scsi buffers that were allocated and posted. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 890 | * 0 = failure, less than num_to_alloc is a partial failure. |
| 891 | **/ |
| 892 | static int |
| 893 | lpfc_new_scsi_buf_s4(struct lpfc_vport *vport, int num_to_alloc) |
| 894 | { |
| 895 | struct lpfc_hba *phba = vport->phba; |
| 896 | struct lpfc_scsi_buf *psb; |
| 897 | struct sli4_sge *sgl; |
| 898 | IOCB_t *iocb; |
| 899 | dma_addr_t pdma_phys_fcp_cmd; |
| 900 | dma_addr_t pdma_phys_fcp_rsp; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 901 | dma_addr_t pdma_phys_bpl; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 902 | uint16_t iotag, lxri = 0; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 903 | int bcnt, num_posted, sgl_size; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 904 | LIST_HEAD(prep_sblist); |
| 905 | LIST_HEAD(post_sblist); |
| 906 | LIST_HEAD(scsi_sblist); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 907 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 908 | sgl_size = phba->cfg_sg_dma_buf_size - |
| 909 | (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); |
| 910 | |
| 911 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 912 | "9068 ALLOC %d scsi_bufs: %d (%d + %d + %d)\n", |
| 913 | num_to_alloc, phba->cfg_sg_dma_buf_size, sgl_size, |
| 914 | (int)sizeof(struct fcp_cmnd), |
| 915 | (int)sizeof(struct fcp_rsp)); |
| 916 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 917 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
| 918 | psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL); |
| 919 | if (!psb) |
| 920 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 921 | /* |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 922 | * Get memory from the pci pool to map the virt space to |
| 923 | * pci bus space for an I/O. The DMA buffer includes space |
| 924 | * for the struct fcp_cmnd, struct fcp_rsp and the number |
| 925 | * of bde's necessary to support the sg_tablesize. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 926 | */ |
| 927 | psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool, |
| 928 | GFP_KERNEL, &psb->dma_handle); |
| 929 | if (!psb->data) { |
| 930 | kfree(psb); |
| 931 | break; |
| 932 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 933 | memset(psb->data, 0, phba->cfg_sg_dma_buf_size); |
| 934 | |
James Smart | 092cb03 | 2013-09-06 12:21:50 -0400 | [diff] [blame] | 935 | /* |
| 936 | * 4K Page alignment is CRITICAL to BlockGuard, double check |
| 937 | * to be sure. |
| 938 | */ |
| 939 | if (phba->cfg_enable_bg && (((unsigned long)(psb->data) & |
| 940 | (unsigned long)(SLI4_PAGE_SIZE - 1)) != 0)) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 941 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, |
| 942 | psb->data, psb->dma_handle); |
| 943 | kfree(psb); |
| 944 | break; |
| 945 | } |
| 946 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 947 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 948 | lxri = lpfc_sli4_next_xritag(phba); |
| 949 | if (lxri == NO_XRI) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 950 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, |
| 951 | psb->data, psb->dma_handle); |
| 952 | kfree(psb); |
| 953 | break; |
| 954 | } |
James Smart | f7bc643 | 2013-10-10 12:19:53 -0400 | [diff] [blame] | 955 | |
| 956 | /* Allocate iotag for psb->cur_iocbq. */ |
| 957 | iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq); |
| 958 | if (iotag == 0) { |
| 959 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, |
| 960 | psb->data, psb->dma_handle); |
| 961 | kfree(psb); |
| 962 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 963 | "3368 Failed to allocated IOTAG for" |
| 964 | " XRI:0x%x\n", lxri); |
| 965 | lpfc_sli4_free_xri(phba, lxri); |
| 966 | break; |
| 967 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 968 | psb->cur_iocbq.sli4_lxritag = lxri; |
| 969 | psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 970 | psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 971 | psb->fcp_bpl = psb->data; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 972 | psb->fcp_cmnd = (psb->data + sgl_size); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 973 | psb->fcp_rsp = (struct fcp_rsp *)((uint8_t *)psb->fcp_cmnd + |
| 974 | sizeof(struct fcp_cmnd)); |
| 975 | |
| 976 | /* Initialize local short-hand pointers. */ |
| 977 | sgl = (struct sli4_sge *)psb->fcp_bpl; |
| 978 | pdma_phys_bpl = psb->dma_handle; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 979 | pdma_phys_fcp_cmd = (psb->dma_handle + sgl_size); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 980 | pdma_phys_fcp_rsp = pdma_phys_fcp_cmd + sizeof(struct fcp_cmnd); |
| 981 | |
| 982 | /* |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 983 | * The first two bdes are the FCP_CMD and FCP_RSP. |
| 984 | * The balance are sg list bdes. Initialize the |
| 985 | * first two and leave the rest for queuecommand. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 986 | */ |
| 987 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd)); |
| 988 | sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd)); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 989 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 990 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 991 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 992 | sgl->sge_len = cpu_to_le32(sizeof(struct fcp_cmnd)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 993 | sgl++; |
| 994 | |
| 995 | /* Setup the physical region for the FCP RSP */ |
| 996 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp)); |
| 997 | sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp)); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 998 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 999 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 1000 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 1001 | sgl->sge_len = cpu_to_le32(sizeof(struct fcp_rsp)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1002 | |
| 1003 | /* |
| 1004 | * Since the IOCB for the FCP I/O is built into this |
| 1005 | * lpfc_scsi_buf, initialize it with all known data now. |
| 1006 | */ |
| 1007 | iocb = &psb->cur_iocbq.iocb; |
| 1008 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; |
| 1009 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_64; |
| 1010 | /* setting the BLP size to 2 * sizeof BDE may not be correct. |
| 1011 | * We are setting the bpl to point to out sgl. An sgl's |
| 1012 | * entries are 16 bytes, a bpl entries are 12 bytes. |
| 1013 | */ |
| 1014 | iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); |
| 1015 | iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys_fcp_cmd); |
| 1016 | iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys_fcp_cmd); |
| 1017 | iocb->ulpBdeCount = 1; |
| 1018 | iocb->ulpLe = 1; |
| 1019 | iocb->ulpClass = CLASS3; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 1020 | psb->cur_iocbq.context1 = psb; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1021 | psb->dma_phys_bpl = pdma_phys_bpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1022 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 1023 | /* add the scsi buffer to a post list */ |
| 1024 | list_add_tail(&psb->list, &post_sblist); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1025 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 1026 | phba->sli4_hba.scsi_xri_cnt++; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1027 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1028 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 1029 | lpfc_printf_log(phba, KERN_INFO, LOG_BG, |
| 1030 | "3021 Allocate %d out of %d requested new SCSI " |
| 1031 | "buffers\n", bcnt, num_to_alloc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1032 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 1033 | /* post the list of scsi buffer sgls to port if available */ |
| 1034 | if (!list_empty(&post_sblist)) |
| 1035 | num_posted = lpfc_sli4_post_scsi_sgl_list(phba, |
| 1036 | &post_sblist, bcnt); |
| 1037 | else |
| 1038 | num_posted = 0; |
| 1039 | |
| 1040 | return num_posted; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1044 | * lpfc_new_scsi_buf - Wrapper funciton for scsi buffer allocator |
| 1045 | * @vport: The virtual port for which this call being executed. |
| 1046 | * @num_to_allocate: The requested number of buffers to allocate. |
| 1047 | * |
| 1048 | * This routine wraps the actual SCSI buffer allocator function pointer from |
| 1049 | * the lpfc_hba struct. |
| 1050 | * |
| 1051 | * Return codes: |
| 1052 | * int - number of scsi buffers that were allocated. |
| 1053 | * 0 = failure, less than num_to_alloc is a partial failure. |
| 1054 | **/ |
| 1055 | static inline int |
| 1056 | lpfc_new_scsi_buf(struct lpfc_vport *vport, int num_to_alloc) |
| 1057 | { |
| 1058 | return vport->phba->lpfc_new_scsi_buf(vport, num_to_alloc); |
| 1059 | } |
| 1060 | |
| 1061 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1062 | * 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] | 1063 | * @phba: The HBA for which this call is being executed. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 1064 | * |
| 1065 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list |
| 1066 | * and returns to caller. |
| 1067 | * |
| 1068 | * Return codes: |
| 1069 | * NULL - Error |
| 1070 | * Pointer to lpfc_scsi_buf - Success |
| 1071 | **/ |
Adrian Bunk | 455c53e | 2006-01-06 20:21:28 +0100 | [diff] [blame] | 1072 | static struct lpfc_scsi_buf* |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1073 | lpfc_get_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1074 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1075 | struct lpfc_scsi_buf * lpfc_cmd = NULL; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1076 | struct list_head *scsi_buf_list_get = &phba->lpfc_scsi_buf_list_get; |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 1077 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1078 | |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 1079 | spin_lock_irqsave(&phba->scsi_buf_list_get_lock, iflag); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1080 | list_remove_head(scsi_buf_list_get, lpfc_cmd, struct lpfc_scsi_buf, |
| 1081 | list); |
| 1082 | if (!lpfc_cmd) { |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 1083 | spin_lock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1084 | list_splice(&phba->lpfc_scsi_buf_list_put, |
| 1085 | &phba->lpfc_scsi_buf_list_get); |
| 1086 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
| 1087 | list_remove_head(scsi_buf_list_get, lpfc_cmd, |
| 1088 | struct lpfc_scsi_buf, list); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 1089 | spin_unlock(&phba->scsi_buf_list_put_lock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 1090 | } |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 1091 | spin_unlock_irqrestore(&phba->scsi_buf_list_get_lock, iflag); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1092 | return lpfc_cmd; |
| 1093 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1094 | /** |
| 1095 | * lpfc_get_scsi_buf_s4 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA |
| 1096 | * @phba: The HBA for which this call is being executed. |
| 1097 | * |
| 1098 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list |
| 1099 | * and returns to caller. |
| 1100 | * |
| 1101 | * Return codes: |
| 1102 | * NULL - Error |
| 1103 | * Pointer to lpfc_scsi_buf - Success |
| 1104 | **/ |
| 1105 | static struct lpfc_scsi_buf* |
| 1106 | lpfc_get_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| 1107 | { |
James Smart | 3be30e0 | 2013-05-31 17:05:17 -0400 | [diff] [blame] | 1108 | struct lpfc_scsi_buf *lpfc_cmd, *lpfc_cmd_next; |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 1109 | unsigned long iflag = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1110 | int found = 0; |
| 1111 | |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 1112 | spin_lock_irqsave(&phba->scsi_buf_list_get_lock, iflag); |
James Smart | 3be30e0 | 2013-05-31 17:05:17 -0400 | [diff] [blame] | 1113 | list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next, |
| 1114 | &phba->lpfc_scsi_buf_list_get, list) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1115 | if (lpfc_test_rrq_active(phba, ndlp, |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 1116 | lpfc_cmd->cur_iocbq.sli4_lxritag)) |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1117 | continue; |
| 1118 | list_del(&lpfc_cmd->list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1119 | found = 1; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1120 | break; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1121 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1122 | if (!found) { |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 1123 | spin_lock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1124 | list_splice(&phba->lpfc_scsi_buf_list_put, |
| 1125 | &phba->lpfc_scsi_buf_list_get); |
| 1126 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 1127 | spin_unlock(&phba->scsi_buf_list_put_lock); |
James Smart | 3be30e0 | 2013-05-31 17:05:17 -0400 | [diff] [blame] | 1128 | list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next, |
| 1129 | &phba->lpfc_scsi_buf_list_get, list) { |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1130 | if (lpfc_test_rrq_active( |
| 1131 | phba, ndlp, lpfc_cmd->cur_iocbq.sli4_lxritag)) |
| 1132 | continue; |
| 1133 | list_del(&lpfc_cmd->list); |
| 1134 | found = 1; |
| 1135 | break; |
| 1136 | } |
| 1137 | } |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 1138 | spin_unlock_irqrestore(&phba->scsi_buf_list_get_lock, iflag); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1139 | if (!found) |
| 1140 | return NULL; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1141 | return lpfc_cmd; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1142 | } |
| 1143 | /** |
| 1144 | * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA |
| 1145 | * @phba: The HBA for which this call is being executed. |
| 1146 | * |
| 1147 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list |
| 1148 | * and returns to caller. |
| 1149 | * |
| 1150 | * Return codes: |
| 1151 | * NULL - Error |
| 1152 | * Pointer to lpfc_scsi_buf - Success |
| 1153 | **/ |
| 1154 | static struct lpfc_scsi_buf* |
| 1155 | lpfc_get_scsi_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| 1156 | { |
| 1157 | return phba->lpfc_get_scsi_buf(phba, ndlp); |
| 1158 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1159 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 1160 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1161 | * 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] | 1162 | * @phba: The Hba for which this call is being executed. |
| 1163 | * @psb: The scsi buffer which is being released. |
| 1164 | * |
| 1165 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
| 1166 | * lpfc_scsi_buf_list list. |
| 1167 | **/ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1168 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1169 | 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] | 1170 | { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1171 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1172 | |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1173 | psb->seg_cnt = 0; |
| 1174 | psb->nonsg_phys = 0; |
| 1175 | psb->prot_seg_cnt = 0; |
| 1176 | |
| 1177 | spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1178 | psb->pCmd = NULL; |
James Smart | 6a485eb | 2013-04-17 20:19:00 -0400 | [diff] [blame] | 1179 | psb->cur_iocbq.iocb_flag = LPFC_IO_FCP; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1180 | list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list_put); |
| 1181 | spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1182 | } |
| 1183 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 1184 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1185 | * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list. |
| 1186 | * @phba: The Hba for which this call is being executed. |
| 1187 | * @psb: The scsi buffer which is being released. |
| 1188 | * |
| 1189 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
| 1190 | * lpfc_scsi_buf_list list. For SLI4 XRI's are tied to the scsi buffer |
| 1191 | * and cannot be reused for at least RA_TOV amount of time if it was |
| 1192 | * aborted. |
| 1193 | **/ |
| 1194 | static void |
| 1195 | lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) |
| 1196 | { |
| 1197 | unsigned long iflag = 0; |
| 1198 | |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1199 | psb->seg_cnt = 0; |
| 1200 | psb->nonsg_phys = 0; |
| 1201 | psb->prot_seg_cnt = 0; |
| 1202 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 1203 | if (psb->exch_busy) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1204 | spin_lock_irqsave(&phba->sli4_hba.abts_scsi_buf_list_lock, |
| 1205 | iflag); |
| 1206 | psb->pCmd = NULL; |
| 1207 | list_add_tail(&psb->list, |
| 1208 | &phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 1209 | spin_unlock_irqrestore(&phba->sli4_hba.abts_scsi_buf_list_lock, |
| 1210 | iflag); |
| 1211 | } else { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1212 | psb->pCmd = NULL; |
James Smart | 6a485eb | 2013-04-17 20:19:00 -0400 | [diff] [blame] | 1213 | psb->cur_iocbq.iocb_flag = LPFC_IO_FCP; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1214 | spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag); |
| 1215 | list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list_put); |
| 1216 | spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1221 | * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list. |
| 1222 | * @phba: The Hba for which this call is being executed. |
| 1223 | * @psb: The scsi buffer which is being released. |
| 1224 | * |
| 1225 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
| 1226 | * lpfc_scsi_buf_list list. |
| 1227 | **/ |
| 1228 | static void |
| 1229 | lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) |
| 1230 | { |
| 1231 | |
| 1232 | phba->lpfc_release_scsi_buf(phba, psb); |
| 1233 | } |
| 1234 | |
| 1235 | /** |
| 1236 | * 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] | 1237 | * @phba: The Hba for which this call is being executed. |
| 1238 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 1239 | * |
| 1240 | * 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] | 1241 | * field of @lpfc_cmd for device with SLI-3 interface spec. This routine scans |
| 1242 | * through sg elements and format the bdea. This routine also initializes all |
| 1243 | * IOCB fields which are dependent on scsi command request buffer. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 1244 | * |
| 1245 | * Return codes: |
| 1246 | * 1 - Error |
| 1247 | * 0 - Success |
| 1248 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1249 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1250 | 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] | 1251 | { |
| 1252 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 1253 | struct scatterlist *sgel = NULL; |
| 1254 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 1255 | struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1256 | struct lpfc_iocbq *iocbq = &lpfc_cmd->cur_iocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1257 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1258 | struct ulp_bde64 *data_bde = iocb_cmd->unsli3.fcp_ext.dbde; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1259 | dma_addr_t physaddr; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1260 | uint32_t num_bde = 0; |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1261 | int nseg, datadir = scsi_cmnd->sc_data_direction; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1262 | |
| 1263 | /* |
| 1264 | * There are three possibilities here - use scatter-gather segment, use |
| 1265 | * the single mapping, or neither. Start the lpfc command prep by |
| 1266 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 1267 | * data bde entry. |
| 1268 | */ |
| 1269 | bpl += 2; |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 1270 | if (scsi_sg_count(scsi_cmnd)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1271 | /* |
| 1272 | * The driver stores the segment count returned from pci_map_sg |
| 1273 | * because this a count of dma-mappings used to map the use_sg |
| 1274 | * pages. They are not guaranteed to be the same for those |
| 1275 | * architectures that implement an IOMMU. |
| 1276 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1277 | |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 1278 | nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd), |
| 1279 | scsi_sg_count(scsi_cmnd), datadir); |
| 1280 | if (unlikely(!nseg)) |
| 1281 | return 1; |
| 1282 | |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1283 | lpfc_cmd->seg_cnt = nseg; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1284 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1285 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1286 | "9064 BLKGRD: %s: Too many sg segments from " |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1287 | "dma_map_sg. Config %d, seg_cnt %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1288 | __func__, phba->cfg_sg_seg_cnt, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1289 | lpfc_cmd->seg_cnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 1290 | lpfc_cmd->seg_cnt = 0; |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1291 | scsi_dma_unmap(scsi_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1292 | return 1; |
| 1293 | } |
| 1294 | |
| 1295 | /* |
| 1296 | * The driver established a maximum scatter-gather segment count |
| 1297 | * during probe that limits the number of sg elements in any |
| 1298 | * single scsi command. Just run through the seg_cnt and format |
| 1299 | * the bde's. |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1300 | * When using SLI-3 the driver will try to fit all the BDEs into |
| 1301 | * the IOCB. If it can't then the BDEs get added to a BPL as it |
| 1302 | * does for SLI-2 mode. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1303 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1304 | scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1305 | physaddr = sg_dma_address(sgel); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1306 | if (phba->sli_rev == 3 && |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1307 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1308 | !(iocbq->iocb_flag & DSS_SECURITY_OP) && |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1309 | nseg <= LPFC_EXT_DATA_BDE_COUNT) { |
| 1310 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1311 | data_bde->tus.f.bdeSize = sg_dma_len(sgel); |
| 1312 | data_bde->addrLow = putPaddrLow(physaddr); |
| 1313 | data_bde->addrHigh = putPaddrHigh(physaddr); |
| 1314 | data_bde++; |
| 1315 | } else { |
| 1316 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1317 | bpl->tus.f.bdeSize = sg_dma_len(sgel); |
| 1318 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 1319 | bpl->addrLow = |
| 1320 | le32_to_cpu(putPaddrLow(physaddr)); |
| 1321 | bpl->addrHigh = |
| 1322 | le32_to_cpu(putPaddrHigh(physaddr)); |
| 1323 | bpl++; |
| 1324 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1325 | } |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 1326 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1327 | |
| 1328 | /* |
| 1329 | * Finish initializing those IOCB fields that are dependent on the |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1330 | * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is |
| 1331 | * explicitly reinitialized and for SLI-3 the extended bde count is |
| 1332 | * explicitly reinitialized since all iocb memory resources are reused. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1333 | */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1334 | if (phba->sli_rev == 3 && |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1335 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
| 1336 | !(iocbq->iocb_flag & DSS_SECURITY_OP)) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1337 | if (num_bde > LPFC_EXT_DATA_BDE_COUNT) { |
| 1338 | /* |
| 1339 | * The extended IOCB format can only fit 3 BDE or a BPL. |
| 1340 | * This I/O has more than 3 BDE so the 1st data bde will |
| 1341 | * be a BPL that is filled in here. |
| 1342 | */ |
| 1343 | physaddr = lpfc_cmd->dma_handle; |
| 1344 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BLP_64; |
| 1345 | data_bde->tus.f.bdeSize = (num_bde * |
| 1346 | sizeof(struct ulp_bde64)); |
| 1347 | physaddr += (sizeof(struct fcp_cmnd) + |
| 1348 | sizeof(struct fcp_rsp) + |
| 1349 | (2 * sizeof(struct ulp_bde64))); |
| 1350 | data_bde->addrHigh = putPaddrHigh(physaddr); |
| 1351 | data_bde->addrLow = putPaddrLow(physaddr); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1352 | /* ebde count includes the response bde and data bpl */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1353 | iocb_cmd->unsli3.fcp_ext.ebde_count = 2; |
| 1354 | } else { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1355 | /* ebde count includes the response bde and data bdes */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1356 | iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); |
| 1357 | } |
| 1358 | } else { |
| 1359 | iocb_cmd->un.fcpi64.bdl.bdeSize = |
| 1360 | ((num_bde + 2) * sizeof(struct ulp_bde64)); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1361 | iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1362 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1363 | fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1364 | |
| 1365 | /* |
| 1366 | * Due to difference in data length between DIF/non-DIF paths, |
| 1367 | * we need to set word 4 of IOCB here |
| 1368 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1369 | iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1370 | return 0; |
| 1371 | } |
| 1372 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1373 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1374 | |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1375 | /* Return if if error injection is detected by Initiator */ |
| 1376 | #define BG_ERR_INIT 0x1 |
| 1377 | /* Return if if error injection is detected by Target */ |
| 1378 | #define BG_ERR_TGT 0x2 |
| 1379 | /* Return if if swapping CSUM<-->CRC is required for error injection */ |
| 1380 | #define BG_ERR_SWAP 0x10 |
| 1381 | /* Return if disabling Guard/Ref/App checking is required for error injection */ |
| 1382 | #define BG_ERR_CHECK 0x20 |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1383 | |
| 1384 | /** |
| 1385 | * lpfc_bg_err_inject - Determine if we should inject an error |
| 1386 | * @phba: The Hba for which this call is being executed. |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1387 | * @sc: The SCSI command to examine |
| 1388 | * @reftag: (out) BlockGuard reference tag for transmitted data |
| 1389 | * @apptag: (out) BlockGuard application tag for transmitted data |
| 1390 | * @new_guard (in) Value to replace CRC with if needed |
| 1391 | * |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1392 | * Returns BG_ERR_* bit mask or 0 if request ignored |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1393 | **/ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1394 | static int |
| 1395 | lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1396 | uint32_t *reftag, uint16_t *apptag, uint32_t new_guard) |
| 1397 | { |
| 1398 | struct scatterlist *sgpe; /* s/g prot entry */ |
| 1399 | struct scatterlist *sgde; /* s/g data entry */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1400 | struct lpfc_scsi_buf *lpfc_cmd = NULL; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1401 | struct scsi_dif_tuple *src = NULL; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1402 | struct lpfc_nodelist *ndlp; |
| 1403 | struct lpfc_rport_data *rdata; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1404 | uint32_t op = scsi_get_prot_op(sc); |
| 1405 | uint32_t blksize; |
| 1406 | uint32_t numblks; |
| 1407 | sector_t lba; |
| 1408 | int rc = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1409 | int blockoff = 0; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1410 | |
| 1411 | if (op == SCSI_PROT_NORMAL) |
| 1412 | return 0; |
| 1413 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1414 | sgpe = scsi_prot_sglist(sc); |
| 1415 | sgde = scsi_sglist(sc); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1416 | lba = scsi_get_lba(sc); |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1417 | |
| 1418 | /* First check if we need to match the LBA */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1419 | if (phba->lpfc_injerr_lba != LPFC_INJERR_LBA_OFF) { |
| 1420 | blksize = lpfc_cmd_blksize(sc); |
| 1421 | numblks = (scsi_bufflen(sc) + blksize - 1) / blksize; |
| 1422 | |
| 1423 | /* Make sure we have the right LBA if one is specified */ |
| 1424 | if ((phba->lpfc_injerr_lba < lba) || |
| 1425 | (phba->lpfc_injerr_lba >= (lba + numblks))) |
| 1426 | return 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1427 | if (sgpe) { |
| 1428 | blockoff = phba->lpfc_injerr_lba - lba; |
| 1429 | numblks = sg_dma_len(sgpe) / |
| 1430 | sizeof(struct scsi_dif_tuple); |
| 1431 | if (numblks < blockoff) |
| 1432 | blockoff = numblks; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1433 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1434 | } |
| 1435 | |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1436 | /* Next check if we need to match the remote NPortID or WWPN */ |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 1437 | rdata = lpfc_rport_data_from_scsi_device(sc->device); |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1438 | if (rdata && rdata->pnode) { |
| 1439 | ndlp = rdata->pnode; |
| 1440 | |
| 1441 | /* Make sure we have the right NPortID if one is specified */ |
| 1442 | if (phba->lpfc_injerr_nportid && |
| 1443 | (phba->lpfc_injerr_nportid != ndlp->nlp_DID)) |
| 1444 | return 0; |
| 1445 | |
| 1446 | /* |
| 1447 | * Make sure we have the right WWPN if one is specified. |
| 1448 | * wwn[0] should be a non-zero NAA in a good WWPN. |
| 1449 | */ |
| 1450 | if (phba->lpfc_injerr_wwpn.u.wwn[0] && |
| 1451 | (memcmp(&ndlp->nlp_portname, &phba->lpfc_injerr_wwpn, |
| 1452 | sizeof(struct lpfc_name)) != 0)) |
| 1453 | return 0; |
| 1454 | } |
| 1455 | |
| 1456 | /* Setup a ptr to the protection data if the SCSI host provides it */ |
| 1457 | if (sgpe) { |
| 1458 | src = (struct scsi_dif_tuple *)sg_virt(sgpe); |
| 1459 | src += blockoff; |
| 1460 | lpfc_cmd = (struct lpfc_scsi_buf *)sc->host_scribble; |
| 1461 | } |
| 1462 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1463 | /* Should we change the Reference Tag */ |
| 1464 | if (reftag) { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1465 | if (phba->lpfc_injerr_wref_cnt) { |
| 1466 | switch (op) { |
| 1467 | case SCSI_PROT_WRITE_PASS: |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1468 | if (src) { |
| 1469 | /* |
| 1470 | * For WRITE_PASS, force the error |
| 1471 | * to be sent on the wire. It should |
| 1472 | * be detected by the Target. |
| 1473 | * If blockoff != 0 error will be |
| 1474 | * inserted in middle of the IO. |
| 1475 | */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1476 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1477 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1478 | "9076 BLKGRD: Injecting reftag error: " |
| 1479 | "write lba x%lx + x%x oldrefTag x%x\n", |
| 1480 | (unsigned long)lba, blockoff, |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1481 | be32_to_cpu(src->ref_tag)); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1482 | |
| 1483 | /* |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1484 | * Save the old ref_tag so we can |
| 1485 | * restore it on completion. |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1486 | */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1487 | if (lpfc_cmd) { |
| 1488 | lpfc_cmd->prot_data_type = |
| 1489 | LPFC_INJERR_REFTAG; |
| 1490 | lpfc_cmd->prot_data_segment = |
| 1491 | src; |
| 1492 | lpfc_cmd->prot_data = |
| 1493 | src->ref_tag; |
| 1494 | } |
| 1495 | src->ref_tag = cpu_to_be32(0xDEADBEEF); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1496 | phba->lpfc_injerr_wref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1497 | if (phba->lpfc_injerr_wref_cnt == 0) { |
| 1498 | phba->lpfc_injerr_nportid = 0; |
| 1499 | phba->lpfc_injerr_lba = |
| 1500 | LPFC_INJERR_LBA_OFF; |
| 1501 | memset(&phba->lpfc_injerr_wwpn, |
| 1502 | 0, sizeof(struct lpfc_name)); |
| 1503 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1504 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
| 1505 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1506 | break; |
| 1507 | } |
| 1508 | /* Drop thru */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1509 | case SCSI_PROT_WRITE_INSERT: |
| 1510 | /* |
| 1511 | * For WRITE_INSERT, force the error |
| 1512 | * to be sent on the wire. It should be |
| 1513 | * detected by the Target. |
| 1514 | */ |
| 1515 | /* DEADBEEF will be the reftag on the wire */ |
| 1516 | *reftag = 0xDEADBEEF; |
| 1517 | phba->lpfc_injerr_wref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1518 | if (phba->lpfc_injerr_wref_cnt == 0) { |
| 1519 | phba->lpfc_injerr_nportid = 0; |
| 1520 | phba->lpfc_injerr_lba = |
| 1521 | LPFC_INJERR_LBA_OFF; |
| 1522 | memset(&phba->lpfc_injerr_wwpn, |
| 1523 | 0, sizeof(struct lpfc_name)); |
| 1524 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1525 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
| 1526 | |
| 1527 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1528 | "9078 BLKGRD: Injecting reftag error: " |
| 1529 | "write lba x%lx\n", (unsigned long)lba); |
| 1530 | break; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1531 | case SCSI_PROT_WRITE_STRIP: |
| 1532 | /* |
| 1533 | * For WRITE_STRIP and WRITE_PASS, |
| 1534 | * force the error on data |
| 1535 | * being copied from SLI-Host to SLI-Port. |
| 1536 | */ |
| 1537 | *reftag = 0xDEADBEEF; |
| 1538 | phba->lpfc_injerr_wref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1539 | if (phba->lpfc_injerr_wref_cnt == 0) { |
| 1540 | phba->lpfc_injerr_nportid = 0; |
| 1541 | phba->lpfc_injerr_lba = |
| 1542 | LPFC_INJERR_LBA_OFF; |
| 1543 | memset(&phba->lpfc_injerr_wwpn, |
| 1544 | 0, sizeof(struct lpfc_name)); |
| 1545 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1546 | rc = BG_ERR_INIT; |
| 1547 | |
| 1548 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1549 | "9077 BLKGRD: Injecting reftag error: " |
| 1550 | "write lba x%lx\n", (unsigned long)lba); |
| 1551 | break; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1552 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1553 | } |
| 1554 | if (phba->lpfc_injerr_rref_cnt) { |
| 1555 | switch (op) { |
| 1556 | case SCSI_PROT_READ_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1557 | case SCSI_PROT_READ_STRIP: |
| 1558 | case SCSI_PROT_READ_PASS: |
| 1559 | /* |
| 1560 | * For READ_STRIP and READ_PASS, force the |
| 1561 | * error on data being read off the wire. It |
| 1562 | * should force an IO error to the driver. |
| 1563 | */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1564 | *reftag = 0xDEADBEEF; |
| 1565 | phba->lpfc_injerr_rref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1566 | if (phba->lpfc_injerr_rref_cnt == 0) { |
| 1567 | phba->lpfc_injerr_nportid = 0; |
| 1568 | phba->lpfc_injerr_lba = |
| 1569 | LPFC_INJERR_LBA_OFF; |
| 1570 | memset(&phba->lpfc_injerr_wwpn, |
| 1571 | 0, sizeof(struct lpfc_name)); |
| 1572 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1573 | rc = BG_ERR_INIT; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1574 | |
| 1575 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1576 | "9079 BLKGRD: Injecting reftag error: " |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1577 | "read lba x%lx\n", (unsigned long)lba); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1578 | break; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1579 | } |
| 1580 | } |
| 1581 | } |
| 1582 | |
| 1583 | /* Should we change the Application Tag */ |
| 1584 | if (apptag) { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1585 | if (phba->lpfc_injerr_wapp_cnt) { |
| 1586 | switch (op) { |
| 1587 | case SCSI_PROT_WRITE_PASS: |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1588 | if (src) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1589 | /* |
| 1590 | * For WRITE_PASS, force the error |
| 1591 | * to be sent on the wire. It should |
| 1592 | * be detected by the Target. |
| 1593 | * If blockoff != 0 error will be |
| 1594 | * inserted in middle of the IO. |
| 1595 | */ |
| 1596 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1597 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1598 | "9080 BLKGRD: Injecting apptag error: " |
| 1599 | "write lba x%lx + x%x oldappTag x%x\n", |
| 1600 | (unsigned long)lba, blockoff, |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1601 | be16_to_cpu(src->app_tag)); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1602 | |
| 1603 | /* |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1604 | * Save the old app_tag so we can |
| 1605 | * restore it on completion. |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1606 | */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1607 | if (lpfc_cmd) { |
| 1608 | lpfc_cmd->prot_data_type = |
| 1609 | LPFC_INJERR_APPTAG; |
| 1610 | lpfc_cmd->prot_data_segment = |
| 1611 | src; |
| 1612 | lpfc_cmd->prot_data = |
| 1613 | src->app_tag; |
| 1614 | } |
| 1615 | src->app_tag = cpu_to_be16(0xDEAD); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1616 | phba->lpfc_injerr_wapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1617 | if (phba->lpfc_injerr_wapp_cnt == 0) { |
| 1618 | phba->lpfc_injerr_nportid = 0; |
| 1619 | phba->lpfc_injerr_lba = |
| 1620 | LPFC_INJERR_LBA_OFF; |
| 1621 | memset(&phba->lpfc_injerr_wwpn, |
| 1622 | 0, sizeof(struct lpfc_name)); |
| 1623 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1624 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1625 | break; |
| 1626 | } |
| 1627 | /* Drop thru */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1628 | case SCSI_PROT_WRITE_INSERT: |
| 1629 | /* |
| 1630 | * For WRITE_INSERT, force the |
| 1631 | * error to be sent on the wire. It should be |
| 1632 | * detected by the Target. |
| 1633 | */ |
| 1634 | /* DEAD will be the apptag on the wire */ |
| 1635 | *apptag = 0xDEAD; |
| 1636 | phba->lpfc_injerr_wapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1637 | if (phba->lpfc_injerr_wapp_cnt == 0) { |
| 1638 | phba->lpfc_injerr_nportid = 0; |
| 1639 | phba->lpfc_injerr_lba = |
| 1640 | LPFC_INJERR_LBA_OFF; |
| 1641 | memset(&phba->lpfc_injerr_wwpn, |
| 1642 | 0, sizeof(struct lpfc_name)); |
| 1643 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1644 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
| 1645 | |
| 1646 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1647 | "0813 BLKGRD: Injecting apptag error: " |
| 1648 | "write lba x%lx\n", (unsigned long)lba); |
| 1649 | break; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1650 | case SCSI_PROT_WRITE_STRIP: |
| 1651 | /* |
| 1652 | * For WRITE_STRIP and WRITE_PASS, |
| 1653 | * force the error on data |
| 1654 | * being copied from SLI-Host to SLI-Port. |
| 1655 | */ |
| 1656 | *apptag = 0xDEAD; |
| 1657 | phba->lpfc_injerr_wapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1658 | if (phba->lpfc_injerr_wapp_cnt == 0) { |
| 1659 | phba->lpfc_injerr_nportid = 0; |
| 1660 | phba->lpfc_injerr_lba = |
| 1661 | LPFC_INJERR_LBA_OFF; |
| 1662 | memset(&phba->lpfc_injerr_wwpn, |
| 1663 | 0, sizeof(struct lpfc_name)); |
| 1664 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1665 | rc = BG_ERR_INIT; |
| 1666 | |
| 1667 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1668 | "0812 BLKGRD: Injecting apptag error: " |
| 1669 | "write lba x%lx\n", (unsigned long)lba); |
| 1670 | break; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1671 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1672 | } |
| 1673 | if (phba->lpfc_injerr_rapp_cnt) { |
| 1674 | switch (op) { |
| 1675 | case SCSI_PROT_READ_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1676 | case SCSI_PROT_READ_STRIP: |
| 1677 | case SCSI_PROT_READ_PASS: |
| 1678 | /* |
| 1679 | * For READ_STRIP and READ_PASS, force the |
| 1680 | * error on data being read off the wire. It |
| 1681 | * should force an IO error to the driver. |
| 1682 | */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1683 | *apptag = 0xDEAD; |
| 1684 | phba->lpfc_injerr_rapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1685 | if (phba->lpfc_injerr_rapp_cnt == 0) { |
| 1686 | phba->lpfc_injerr_nportid = 0; |
| 1687 | phba->lpfc_injerr_lba = |
| 1688 | LPFC_INJERR_LBA_OFF; |
| 1689 | memset(&phba->lpfc_injerr_wwpn, |
| 1690 | 0, sizeof(struct lpfc_name)); |
| 1691 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1692 | rc = BG_ERR_INIT; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1693 | |
| 1694 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1695 | "0814 BLKGRD: Injecting apptag error: " |
| 1696 | "read lba x%lx\n", (unsigned long)lba); |
| 1697 | break; |
| 1698 | } |
| 1699 | } |
| 1700 | } |
| 1701 | |
| 1702 | |
| 1703 | /* Should we change the Guard Tag */ |
| 1704 | if (new_guard) { |
| 1705 | if (phba->lpfc_injerr_wgrd_cnt) { |
| 1706 | switch (op) { |
| 1707 | case SCSI_PROT_WRITE_PASS: |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1708 | rc = BG_ERR_CHECK; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1709 | /* Drop thru */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1710 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1711 | case SCSI_PROT_WRITE_INSERT: |
| 1712 | /* |
| 1713 | * For WRITE_INSERT, force the |
| 1714 | * error to be sent on the wire. It should be |
| 1715 | * detected by the Target. |
| 1716 | */ |
| 1717 | phba->lpfc_injerr_wgrd_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1718 | if (phba->lpfc_injerr_wgrd_cnt == 0) { |
| 1719 | phba->lpfc_injerr_nportid = 0; |
| 1720 | phba->lpfc_injerr_lba = |
| 1721 | LPFC_INJERR_LBA_OFF; |
| 1722 | memset(&phba->lpfc_injerr_wwpn, |
| 1723 | 0, sizeof(struct lpfc_name)); |
| 1724 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1725 | |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1726 | rc |= BG_ERR_TGT | BG_ERR_SWAP; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1727 | /* Signals the caller to swap CRC->CSUM */ |
| 1728 | |
| 1729 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1730 | "0817 BLKGRD: Injecting guard error: " |
| 1731 | "write lba x%lx\n", (unsigned long)lba); |
| 1732 | break; |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1733 | case SCSI_PROT_WRITE_STRIP: |
| 1734 | /* |
| 1735 | * For WRITE_STRIP and WRITE_PASS, |
| 1736 | * force the error on data |
| 1737 | * being copied from SLI-Host to SLI-Port. |
| 1738 | */ |
| 1739 | phba->lpfc_injerr_wgrd_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1740 | if (phba->lpfc_injerr_wgrd_cnt == 0) { |
| 1741 | phba->lpfc_injerr_nportid = 0; |
| 1742 | phba->lpfc_injerr_lba = |
| 1743 | LPFC_INJERR_LBA_OFF; |
| 1744 | memset(&phba->lpfc_injerr_wwpn, |
| 1745 | 0, sizeof(struct lpfc_name)); |
| 1746 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1747 | |
| 1748 | rc = BG_ERR_INIT | BG_ERR_SWAP; |
| 1749 | /* Signals the caller to swap CRC->CSUM */ |
| 1750 | |
| 1751 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1752 | "0816 BLKGRD: Injecting guard error: " |
| 1753 | "write lba x%lx\n", (unsigned long)lba); |
| 1754 | break; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1755 | } |
| 1756 | } |
| 1757 | if (phba->lpfc_injerr_rgrd_cnt) { |
| 1758 | switch (op) { |
| 1759 | case SCSI_PROT_READ_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1760 | case SCSI_PROT_READ_STRIP: |
| 1761 | case SCSI_PROT_READ_PASS: |
| 1762 | /* |
| 1763 | * For READ_STRIP and READ_PASS, force the |
| 1764 | * error on data being read off the wire. It |
| 1765 | * should force an IO error to the driver. |
| 1766 | */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1767 | phba->lpfc_injerr_rgrd_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1768 | if (phba->lpfc_injerr_rgrd_cnt == 0) { |
| 1769 | phba->lpfc_injerr_nportid = 0; |
| 1770 | phba->lpfc_injerr_lba = |
| 1771 | LPFC_INJERR_LBA_OFF; |
| 1772 | memset(&phba->lpfc_injerr_wwpn, |
| 1773 | 0, sizeof(struct lpfc_name)); |
| 1774 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1775 | |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1776 | rc = BG_ERR_INIT | BG_ERR_SWAP; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1777 | /* Signals the caller to swap CRC->CSUM */ |
| 1778 | |
| 1779 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1780 | "0818 BLKGRD: Injecting guard error: " |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1781 | "read lba x%lx\n", (unsigned long)lba); |
| 1782 | } |
| 1783 | } |
| 1784 | } |
| 1785 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1786 | return rc; |
| 1787 | } |
| 1788 | #endif |
| 1789 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1790 | /** |
| 1791 | * lpfc_sc_to_bg_opcodes - Determine the BlockGuard opcodes to be used with |
| 1792 | * the specified SCSI command. |
| 1793 | * @phba: The Hba for which this call is being executed. |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1794 | * @sc: The SCSI command to examine |
| 1795 | * @txopt: (out) BlockGuard operation for transmitted data |
| 1796 | * @rxopt: (out) BlockGuard operation for received data |
| 1797 | * |
| 1798 | * Returns: zero on success; non-zero if tx and/or rx op cannot be determined |
| 1799 | * |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1800 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1801 | static int |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1802 | lpfc_sc_to_bg_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1803 | uint8_t *txop, uint8_t *rxop) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1804 | { |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1805 | uint8_t ret = 0; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1806 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1807 | if (lpfc_cmd_guard_csum(sc)) { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1808 | switch (scsi_get_prot_op(sc)) { |
| 1809 | case SCSI_PROT_READ_INSERT: |
| 1810 | case SCSI_PROT_WRITE_STRIP: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1811 | *rxop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1812 | *txop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1813 | break; |
| 1814 | |
| 1815 | case SCSI_PROT_READ_STRIP: |
| 1816 | case SCSI_PROT_WRITE_INSERT: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1817 | *rxop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1818 | *txop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1819 | break; |
| 1820 | |
Martin K. Petersen | c6af404 | 2009-09-18 17:32:59 -0400 | [diff] [blame] | 1821 | case SCSI_PROT_READ_PASS: |
| 1822 | case SCSI_PROT_WRITE_PASS: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1823 | *rxop = BG_OP_IN_CRC_OUT_CSUM; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1824 | *txop = BG_OP_IN_CSUM_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1825 | break; |
| 1826 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1827 | case SCSI_PROT_NORMAL: |
| 1828 | default: |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1829 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1830 | "9063 BLKGRD: Bad op/guard:%d/IP combination\n", |
| 1831 | scsi_get_prot_op(sc)); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1832 | ret = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1833 | break; |
| 1834 | |
| 1835 | } |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1836 | } else { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1837 | switch (scsi_get_prot_op(sc)) { |
| 1838 | case SCSI_PROT_READ_STRIP: |
| 1839 | case SCSI_PROT_WRITE_INSERT: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1840 | *rxop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1841 | *txop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1842 | break; |
| 1843 | |
| 1844 | case SCSI_PROT_READ_PASS: |
| 1845 | case SCSI_PROT_WRITE_PASS: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1846 | *rxop = BG_OP_IN_CRC_OUT_CRC; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1847 | *txop = BG_OP_IN_CRC_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1848 | break; |
| 1849 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1850 | case SCSI_PROT_READ_INSERT: |
| 1851 | case SCSI_PROT_WRITE_STRIP: |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1852 | *rxop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1853 | *txop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1854 | break; |
| 1855 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1856 | case SCSI_PROT_NORMAL: |
| 1857 | default: |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1858 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1859 | "9075 BLKGRD: Bad op/guard:%d/CRC combination\n", |
| 1860 | scsi_get_prot_op(sc)); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1861 | ret = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1862 | break; |
| 1863 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1864 | } |
| 1865 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1866 | return ret; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1867 | } |
| 1868 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1869 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 1870 | /** |
| 1871 | * lpfc_bg_err_opcodes - reDetermine the BlockGuard opcodes to be used with |
| 1872 | * the specified SCSI command in order to force a guard tag error. |
| 1873 | * @phba: The Hba for which this call is being executed. |
| 1874 | * @sc: The SCSI command to examine |
| 1875 | * @txopt: (out) BlockGuard operation for transmitted data |
| 1876 | * @rxopt: (out) BlockGuard operation for received data |
| 1877 | * |
| 1878 | * Returns: zero on success; non-zero if tx and/or rx op cannot be determined |
| 1879 | * |
| 1880 | **/ |
| 1881 | static int |
| 1882 | lpfc_bg_err_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1883 | uint8_t *txop, uint8_t *rxop) |
| 1884 | { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1885 | uint8_t ret = 0; |
| 1886 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1887 | if (lpfc_cmd_guard_csum(sc)) { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1888 | switch (scsi_get_prot_op(sc)) { |
| 1889 | case SCSI_PROT_READ_INSERT: |
| 1890 | case SCSI_PROT_WRITE_STRIP: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1891 | *rxop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1892 | *txop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1893 | break; |
| 1894 | |
| 1895 | case SCSI_PROT_READ_STRIP: |
| 1896 | case SCSI_PROT_WRITE_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1897 | *rxop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1898 | *txop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1899 | break; |
| 1900 | |
| 1901 | case SCSI_PROT_READ_PASS: |
| 1902 | case SCSI_PROT_WRITE_PASS: |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1903 | *rxop = BG_OP_IN_CSUM_OUT_CRC; |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1904 | *txop = BG_OP_IN_CRC_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1905 | break; |
| 1906 | |
| 1907 | case SCSI_PROT_NORMAL: |
| 1908 | default: |
| 1909 | break; |
| 1910 | |
| 1911 | } |
| 1912 | } else { |
| 1913 | switch (scsi_get_prot_op(sc)) { |
| 1914 | case SCSI_PROT_READ_STRIP: |
| 1915 | case SCSI_PROT_WRITE_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1916 | *rxop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1917 | *txop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1918 | break; |
| 1919 | |
| 1920 | case SCSI_PROT_READ_PASS: |
| 1921 | case SCSI_PROT_WRITE_PASS: |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1922 | *rxop = BG_OP_IN_CSUM_OUT_CSUM; |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1923 | *txop = BG_OP_IN_CSUM_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1924 | break; |
| 1925 | |
| 1926 | case SCSI_PROT_READ_INSERT: |
| 1927 | case SCSI_PROT_WRITE_STRIP: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1928 | *rxop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1929 | *txop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1930 | break; |
| 1931 | |
| 1932 | case SCSI_PROT_NORMAL: |
| 1933 | default: |
| 1934 | break; |
| 1935 | } |
| 1936 | } |
| 1937 | |
| 1938 | return ret; |
| 1939 | } |
| 1940 | #endif |
| 1941 | |
| 1942 | /** |
| 1943 | * lpfc_bg_setup_bpl - Setup BlockGuard BPL with no protection data |
| 1944 | * @phba: The Hba for which this call is being executed. |
| 1945 | * @sc: pointer to scsi command we're working on |
| 1946 | * @bpl: pointer to buffer list for protection groups |
| 1947 | * @datacnt: number of segments of data that have been dma mapped |
| 1948 | * |
| 1949 | * This function sets up BPL buffer list for protection groups of |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1950 | * type LPFC_PG_TYPE_NO_DIF |
| 1951 | * |
| 1952 | * This is usually used when the HBA is instructed to generate |
| 1953 | * DIFs and insert them into data stream (or strip DIF from |
| 1954 | * incoming data stream) |
| 1955 | * |
| 1956 | * The buffer list consists of just one protection group described |
| 1957 | * below: |
| 1958 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1959 | * start of prot group --> | PDE_5 | |
| 1960 | * +-------------------------+ |
| 1961 | * | PDE_6 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1962 | * +-------------------------+ |
| 1963 | * | Data BDE | |
| 1964 | * +-------------------------+ |
| 1965 | * |more Data BDE's ... (opt)| |
| 1966 | * +-------------------------+ |
| 1967 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1968 | * |
| 1969 | * Note: Data s/g buffers have been dma mapped |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1970 | * |
| 1971 | * Returns the number of BDEs added to the BPL. |
| 1972 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1973 | static int |
| 1974 | lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1975 | struct ulp_bde64 *bpl, int datasegcnt) |
| 1976 | { |
| 1977 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1978 | struct lpfc_pde5 *pde5 = NULL; |
| 1979 | struct lpfc_pde6 *pde6 = NULL; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1980 | dma_addr_t physaddr; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1981 | int i = 0, num_bde = 0, status; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1982 | int datadir = sc->sc_data_direction; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 1983 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1984 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 1985 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1986 | uint32_t checking = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1987 | uint32_t reftag; |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1988 | unsigned blksize; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1989 | uint8_t txop, rxop; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1990 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1991 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 1992 | if (status) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1993 | goto out; |
| 1994 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1995 | /* extract some info from the scsi command for pde*/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1996 | blksize = lpfc_cmd_blksize(sc); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1997 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1998 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1999 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 2000 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2001 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2002 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2003 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2004 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2005 | checking = 0; |
| 2006 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 2007 | #endif |
| 2008 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2009 | /* setup PDE5 with what we have */ |
| 2010 | pde5 = (struct lpfc_pde5 *) bpl; |
| 2011 | memset(pde5, 0, sizeof(struct lpfc_pde5)); |
| 2012 | bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2013 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 2014 | /* Endianness conversion if necessary for PDE5 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 2015 | pde5->word0 = cpu_to_le32(pde5->word0); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2016 | pde5->reftag = cpu_to_le32(reftag); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 2017 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2018 | /* advance bpl and increment bde count */ |
| 2019 | num_bde++; |
| 2020 | bpl++; |
| 2021 | pde6 = (struct lpfc_pde6 *) bpl; |
| 2022 | |
| 2023 | /* setup PDE6 with the rest of the info */ |
| 2024 | memset(pde6, 0, sizeof(struct lpfc_pde6)); |
| 2025 | bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR); |
| 2026 | bf_set(pde6_optx, pde6, txop); |
| 2027 | bf_set(pde6_oprx, pde6, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2028 | |
| 2029 | /* |
| 2030 | * We only need to check the data on READs, for WRITEs |
| 2031 | * protection data is automatically generated, not checked. |
| 2032 | */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2033 | if (datadir == DMA_FROM_DEVICE) { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2034 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2035 | bf_set(pde6_ce, pde6, checking); |
| 2036 | else |
| 2037 | bf_set(pde6_ce, pde6, 0); |
| 2038 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2039 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2040 | bf_set(pde6_re, pde6, checking); |
| 2041 | else |
| 2042 | bf_set(pde6_re, pde6, 0); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2043 | } |
| 2044 | bf_set(pde6_ai, pde6, 1); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2045 | bf_set(pde6_ae, pde6, 0); |
| 2046 | bf_set(pde6_apptagval, pde6, 0); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2047 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 2048 | /* Endianness conversion if necessary for PDE6 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 2049 | pde6->word0 = cpu_to_le32(pde6->word0); |
| 2050 | pde6->word1 = cpu_to_le32(pde6->word1); |
| 2051 | pde6->word2 = cpu_to_le32(pde6->word2); |
| 2052 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2053 | /* advance bpl and increment bde count */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2054 | num_bde++; |
| 2055 | bpl++; |
| 2056 | |
| 2057 | /* assumption: caller has already run dma_map_sg on command data */ |
| 2058 | scsi_for_each_sg(sc, sgde, datasegcnt, i) { |
| 2059 | physaddr = sg_dma_address(sgde); |
| 2060 | bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
| 2061 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 2062 | bpl->tus.f.bdeSize = sg_dma_len(sgde); |
| 2063 | if (datadir == DMA_TO_DEVICE) |
| 2064 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 2065 | else |
| 2066 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
| 2067 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 2068 | bpl++; |
| 2069 | num_bde++; |
| 2070 | } |
| 2071 | |
| 2072 | out: |
| 2073 | return num_bde; |
| 2074 | } |
| 2075 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2076 | /** |
| 2077 | * lpfc_bg_setup_bpl_prot - Setup BlockGuard BPL with protection data |
| 2078 | * @phba: The Hba for which this call is being executed. |
| 2079 | * @sc: pointer to scsi command we're working on |
| 2080 | * @bpl: pointer to buffer list for protection groups |
| 2081 | * @datacnt: number of segments of data that have been dma mapped |
| 2082 | * @protcnt: number of segment of protection data that have been dma mapped |
| 2083 | * |
| 2084 | * This function sets up BPL buffer list for protection groups of |
| 2085 | * type LPFC_PG_TYPE_DIF |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2086 | * |
| 2087 | * This is usually used when DIFs are in their own buffers, |
| 2088 | * separate from the data. The HBA can then by instructed |
| 2089 | * to place the DIFs in the outgoing stream. For read operations, |
| 2090 | * The HBA could extract the DIFs and place it in DIF buffers. |
| 2091 | * |
| 2092 | * The buffer list for this type consists of one or more of the |
| 2093 | * protection groups described below: |
| 2094 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2095 | * start of first prot group --> | PDE_5 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2096 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2097 | * | PDE_6 | |
| 2098 | * +-------------------------+ |
| 2099 | * | PDE_7 (Prot BDE) | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2100 | * +-------------------------+ |
| 2101 | * | Data BDE | |
| 2102 | * +-------------------------+ |
| 2103 | * |more Data BDE's ... (opt)| |
| 2104 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2105 | * start of new prot group --> | PDE_5 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2106 | * +-------------------------+ |
| 2107 | * | ... | |
| 2108 | * +-------------------------+ |
| 2109 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2110 | * Note: It is assumed that both data and protection s/g buffers have been |
| 2111 | * mapped for DMA |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2112 | * |
| 2113 | * Returns the number of BDEs added to the BPL. |
| 2114 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2115 | static int |
| 2116 | lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 2117 | struct ulp_bde64 *bpl, int datacnt, int protcnt) |
| 2118 | { |
| 2119 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 2120 | struct scatterlist *sgpe = NULL; /* s/g prot entry */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2121 | struct lpfc_pde5 *pde5 = NULL; |
| 2122 | struct lpfc_pde6 *pde6 = NULL; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2123 | struct lpfc_pde7 *pde7 = NULL; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2124 | dma_addr_t dataphysaddr, protphysaddr; |
| 2125 | unsigned short curr_data = 0, curr_prot = 0; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2126 | unsigned int split_offset; |
| 2127 | unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2128 | unsigned int protgrp_blks, protgrp_bytes; |
| 2129 | unsigned int remainder, subtotal; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2130 | int status; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2131 | int datadir = sc->sc_data_direction; |
| 2132 | unsigned char pgdone = 0, alldone = 0; |
| 2133 | unsigned blksize; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2134 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2135 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2136 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2137 | uint32_t checking = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2138 | uint32_t reftag; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2139 | uint8_t txop, rxop; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2140 | int num_bde = 0; |
| 2141 | |
| 2142 | sgpe = scsi_prot_sglist(sc); |
| 2143 | sgde = scsi_sglist(sc); |
| 2144 | |
| 2145 | if (!sgpe || !sgde) { |
| 2146 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2147 | "9020 Invalid s/g entry: data=0x%p prot=0x%p\n", |
| 2148 | sgpe, sgde); |
| 2149 | return 0; |
| 2150 | } |
| 2151 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2152 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 2153 | if (status) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2154 | goto out; |
| 2155 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2156 | /* extract some info from the scsi command */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2157 | blksize = lpfc_cmd_blksize(sc); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2158 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2159 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 2160 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 2161 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2162 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2163 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2164 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2165 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2166 | checking = 0; |
| 2167 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 2168 | #endif |
| 2169 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2170 | split_offset = 0; |
| 2171 | do { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2172 | /* Check to see if we ran out of space */ |
| 2173 | if (num_bde >= (phba->cfg_total_seg_cnt - 2)) |
| 2174 | return num_bde + 3; |
| 2175 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2176 | /* setup PDE5 with what we have */ |
| 2177 | pde5 = (struct lpfc_pde5 *) bpl; |
| 2178 | memset(pde5, 0, sizeof(struct lpfc_pde5)); |
| 2179 | bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2180 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 2181 | /* Endianness conversion if necessary for PDE5 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 2182 | pde5->word0 = cpu_to_le32(pde5->word0); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2183 | pde5->reftag = cpu_to_le32(reftag); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 2184 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2185 | /* advance bpl and increment bde count */ |
| 2186 | num_bde++; |
| 2187 | bpl++; |
| 2188 | pde6 = (struct lpfc_pde6 *) bpl; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2189 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2190 | /* setup PDE6 with the rest of the info */ |
| 2191 | memset(pde6, 0, sizeof(struct lpfc_pde6)); |
| 2192 | bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR); |
| 2193 | bf_set(pde6_optx, pde6, txop); |
| 2194 | bf_set(pde6_oprx, pde6, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2195 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2196 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2197 | bf_set(pde6_ce, pde6, checking); |
| 2198 | else |
| 2199 | bf_set(pde6_ce, pde6, 0); |
| 2200 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2201 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2202 | bf_set(pde6_re, pde6, checking); |
| 2203 | else |
| 2204 | bf_set(pde6_re, pde6, 0); |
| 2205 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2206 | bf_set(pde6_ai, pde6, 1); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2207 | bf_set(pde6_ae, pde6, 0); |
| 2208 | bf_set(pde6_apptagval, pde6, 0); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2209 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 2210 | /* Endianness conversion if necessary for PDE6 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 2211 | pde6->word0 = cpu_to_le32(pde6->word0); |
| 2212 | pde6->word1 = cpu_to_le32(pde6->word1); |
| 2213 | pde6->word2 = cpu_to_le32(pde6->word2); |
| 2214 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2215 | /* advance bpl and increment bde count */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2216 | num_bde++; |
| 2217 | bpl++; |
| 2218 | |
| 2219 | /* setup the first BDE that points to protection buffer */ |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2220 | protphysaddr = sg_dma_address(sgpe) + protgroup_offset; |
| 2221 | protgroup_len = sg_dma_len(sgpe) - protgroup_offset; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2222 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2223 | /* must be integer multiple of the DIF block length */ |
| 2224 | BUG_ON(protgroup_len % 8); |
| 2225 | |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2226 | pde7 = (struct lpfc_pde7 *) bpl; |
| 2227 | memset(pde7, 0, sizeof(struct lpfc_pde7)); |
| 2228 | bf_set(pde7_type, pde7, LPFC_PDE7_DESCRIPTOR); |
| 2229 | |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2230 | pde7->addrHigh = le32_to_cpu(putPaddrHigh(protphysaddr)); |
| 2231 | pde7->addrLow = le32_to_cpu(putPaddrLow(protphysaddr)); |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2232 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2233 | protgrp_blks = protgroup_len / 8; |
| 2234 | protgrp_bytes = protgrp_blks * blksize; |
| 2235 | |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2236 | /* check if this pde is crossing the 4K boundary; if so split */ |
| 2237 | if ((pde7->addrLow & 0xfff) + protgroup_len > 0x1000) { |
| 2238 | protgroup_remainder = 0x1000 - (pde7->addrLow & 0xfff); |
| 2239 | protgroup_offset += protgroup_remainder; |
| 2240 | protgrp_blks = protgroup_remainder / 8; |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2241 | protgrp_bytes = protgrp_blks * blksize; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2242 | } else { |
| 2243 | protgroup_offset = 0; |
| 2244 | curr_prot++; |
| 2245 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2246 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2247 | num_bde++; |
| 2248 | |
| 2249 | /* setup BDE's for data blocks associated with DIF data */ |
| 2250 | pgdone = 0; |
| 2251 | subtotal = 0; /* total bytes processed for current prot grp */ |
| 2252 | while (!pgdone) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2253 | /* Check to see if we ran out of space */ |
| 2254 | if (num_bde >= phba->cfg_total_seg_cnt) |
| 2255 | return num_bde + 1; |
| 2256 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2257 | if (!sgde) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2258 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2259 | "9065 BLKGRD:%s Invalid data segment\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2260 | __func__); |
| 2261 | return 0; |
| 2262 | } |
| 2263 | bpl++; |
| 2264 | dataphysaddr = sg_dma_address(sgde) + split_offset; |
| 2265 | bpl->addrLow = le32_to_cpu(putPaddrLow(dataphysaddr)); |
| 2266 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(dataphysaddr)); |
| 2267 | |
| 2268 | remainder = sg_dma_len(sgde) - split_offset; |
| 2269 | |
| 2270 | if ((subtotal + remainder) <= protgrp_bytes) { |
| 2271 | /* we can use this whole buffer */ |
| 2272 | bpl->tus.f.bdeSize = remainder; |
| 2273 | split_offset = 0; |
| 2274 | |
| 2275 | if ((subtotal + remainder) == protgrp_bytes) |
| 2276 | pgdone = 1; |
| 2277 | } else { |
| 2278 | /* must split this buffer with next prot grp */ |
| 2279 | bpl->tus.f.bdeSize = protgrp_bytes - subtotal; |
| 2280 | split_offset += bpl->tus.f.bdeSize; |
| 2281 | } |
| 2282 | |
| 2283 | subtotal += bpl->tus.f.bdeSize; |
| 2284 | |
| 2285 | if (datadir == DMA_TO_DEVICE) |
| 2286 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 2287 | else |
| 2288 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
| 2289 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 2290 | |
| 2291 | num_bde++; |
| 2292 | curr_data++; |
| 2293 | |
| 2294 | if (split_offset) |
| 2295 | break; |
| 2296 | |
| 2297 | /* Move to the next s/g segment if possible */ |
| 2298 | sgde = sg_next(sgde); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2299 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2300 | } |
| 2301 | |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2302 | if (protgroup_offset) { |
| 2303 | /* update the reference tag */ |
| 2304 | reftag += protgrp_blks; |
| 2305 | bpl++; |
| 2306 | continue; |
| 2307 | } |
| 2308 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2309 | /* are we done ? */ |
| 2310 | if (curr_prot == protcnt) { |
| 2311 | alldone = 1; |
| 2312 | } else if (curr_prot < protcnt) { |
| 2313 | /* advance to next prot buffer */ |
| 2314 | sgpe = sg_next(sgpe); |
| 2315 | bpl++; |
| 2316 | |
| 2317 | /* update the reference tag */ |
| 2318 | reftag += protgrp_blks; |
| 2319 | } else { |
| 2320 | /* if we're here, we have a bug */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2321 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2322 | "9054 BLKGRD: bug in %s\n", __func__); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2323 | } |
| 2324 | |
| 2325 | } while (!alldone); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2326 | out: |
| 2327 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2328 | return num_bde; |
| 2329 | } |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2330 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2331 | /** |
| 2332 | * lpfc_bg_setup_sgl - Setup BlockGuard SGL with no protection data |
| 2333 | * @phba: The Hba for which this call is being executed. |
| 2334 | * @sc: pointer to scsi command we're working on |
| 2335 | * @sgl: pointer to buffer list for protection groups |
| 2336 | * @datacnt: number of segments of data that have been dma mapped |
| 2337 | * |
| 2338 | * This function sets up SGL buffer list for protection groups of |
| 2339 | * type LPFC_PG_TYPE_NO_DIF |
| 2340 | * |
| 2341 | * This is usually used when the HBA is instructed to generate |
| 2342 | * DIFs and insert them into data stream (or strip DIF from |
| 2343 | * incoming data stream) |
| 2344 | * |
| 2345 | * The buffer list consists of just one protection group described |
| 2346 | * below: |
| 2347 | * +-------------------------+ |
| 2348 | * start of prot group --> | DI_SEED | |
| 2349 | * +-------------------------+ |
| 2350 | * | Data SGE | |
| 2351 | * +-------------------------+ |
| 2352 | * |more Data SGE's ... (opt)| |
| 2353 | * +-------------------------+ |
| 2354 | * |
| 2355 | * |
| 2356 | * Note: Data s/g buffers have been dma mapped |
| 2357 | * |
| 2358 | * Returns the number of SGEs added to the SGL. |
| 2359 | **/ |
| 2360 | static int |
| 2361 | lpfc_bg_setup_sgl(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 2362 | struct sli4_sge *sgl, int datasegcnt) |
| 2363 | { |
| 2364 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 2365 | struct sli4_sge_diseed *diseed = NULL; |
| 2366 | dma_addr_t physaddr; |
| 2367 | int i = 0, num_sge = 0, status; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2368 | uint32_t reftag; |
| 2369 | unsigned blksize; |
| 2370 | uint8_t txop, rxop; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2371 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2372 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2373 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2374 | uint32_t checking = 1; |
| 2375 | uint32_t dma_len; |
| 2376 | uint32_t dma_offset = 0; |
| 2377 | |
| 2378 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 2379 | if (status) |
| 2380 | goto out; |
| 2381 | |
| 2382 | /* extract some info from the scsi command for pde*/ |
| 2383 | blksize = lpfc_cmd_blksize(sc); |
| 2384 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
| 2385 | |
| 2386 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 2387 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2388 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2389 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2390 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2391 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2392 | checking = 0; |
| 2393 | } |
| 2394 | #endif |
| 2395 | |
| 2396 | /* setup DISEED with what we have */ |
| 2397 | diseed = (struct sli4_sge_diseed *) sgl; |
| 2398 | memset(diseed, 0, sizeof(struct sli4_sge_diseed)); |
| 2399 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED); |
| 2400 | |
| 2401 | /* Endianness conversion if necessary */ |
| 2402 | diseed->ref_tag = cpu_to_le32(reftag); |
| 2403 | diseed->ref_tag_tran = diseed->ref_tag; |
| 2404 | |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2405 | /* |
| 2406 | * We only need to check the data on READs, for WRITEs |
| 2407 | * protection data is automatically generated, not checked. |
| 2408 | */ |
| 2409 | if (sc->sc_data_direction == DMA_FROM_DEVICE) { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2410 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2411 | bf_set(lpfc_sli4_sge_dif_ce, diseed, checking); |
| 2412 | else |
| 2413 | bf_set(lpfc_sli4_sge_dif_ce, diseed, 0); |
| 2414 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2415 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2416 | bf_set(lpfc_sli4_sge_dif_re, diseed, checking); |
| 2417 | else |
| 2418 | bf_set(lpfc_sli4_sge_dif_re, diseed, 0); |
| 2419 | } |
| 2420 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2421 | /* setup DISEED with the rest of the info */ |
| 2422 | bf_set(lpfc_sli4_sge_dif_optx, diseed, txop); |
| 2423 | bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2424 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2425 | bf_set(lpfc_sli4_sge_dif_ai, diseed, 1); |
| 2426 | bf_set(lpfc_sli4_sge_dif_me, diseed, 0); |
| 2427 | |
| 2428 | /* Endianness conversion if necessary for DISEED */ |
| 2429 | diseed->word2 = cpu_to_le32(diseed->word2); |
| 2430 | diseed->word3 = cpu_to_le32(diseed->word3); |
| 2431 | |
| 2432 | /* advance bpl and increment sge count */ |
| 2433 | num_sge++; |
| 2434 | sgl++; |
| 2435 | |
| 2436 | /* assumption: caller has already run dma_map_sg on command data */ |
| 2437 | scsi_for_each_sg(sc, sgde, datasegcnt, i) { |
| 2438 | physaddr = sg_dma_address(sgde); |
| 2439 | dma_len = sg_dma_len(sgde); |
| 2440 | sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr)); |
| 2441 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr)); |
| 2442 | if ((i + 1) == datasegcnt) |
| 2443 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 2444 | else |
| 2445 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 2446 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
| 2447 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); |
| 2448 | |
| 2449 | sgl->sge_len = cpu_to_le32(dma_len); |
| 2450 | dma_offset += dma_len; |
| 2451 | |
| 2452 | sgl++; |
| 2453 | num_sge++; |
| 2454 | } |
| 2455 | |
| 2456 | out: |
| 2457 | return num_sge; |
| 2458 | } |
| 2459 | |
| 2460 | /** |
| 2461 | * lpfc_bg_setup_sgl_prot - Setup BlockGuard SGL with protection data |
| 2462 | * @phba: The Hba for which this call is being executed. |
| 2463 | * @sc: pointer to scsi command we're working on |
| 2464 | * @sgl: pointer to buffer list for protection groups |
| 2465 | * @datacnt: number of segments of data that have been dma mapped |
| 2466 | * @protcnt: number of segment of protection data that have been dma mapped |
| 2467 | * |
| 2468 | * This function sets up SGL buffer list for protection groups of |
| 2469 | * type LPFC_PG_TYPE_DIF |
| 2470 | * |
| 2471 | * This is usually used when DIFs are in their own buffers, |
| 2472 | * separate from the data. The HBA can then by instructed |
| 2473 | * to place the DIFs in the outgoing stream. For read operations, |
| 2474 | * The HBA could extract the DIFs and place it in DIF buffers. |
| 2475 | * |
| 2476 | * The buffer list for this type consists of one or more of the |
| 2477 | * protection groups described below: |
| 2478 | * +-------------------------+ |
| 2479 | * start of first prot group --> | DISEED | |
| 2480 | * +-------------------------+ |
| 2481 | * | DIF (Prot SGE) | |
| 2482 | * +-------------------------+ |
| 2483 | * | Data SGE | |
| 2484 | * +-------------------------+ |
| 2485 | * |more Data SGE's ... (opt)| |
| 2486 | * +-------------------------+ |
| 2487 | * start of new prot group --> | DISEED | |
| 2488 | * +-------------------------+ |
| 2489 | * | ... | |
| 2490 | * +-------------------------+ |
| 2491 | * |
| 2492 | * Note: It is assumed that both data and protection s/g buffers have been |
| 2493 | * mapped for DMA |
| 2494 | * |
| 2495 | * Returns the number of SGEs added to the SGL. |
| 2496 | **/ |
| 2497 | static int |
| 2498 | lpfc_bg_setup_sgl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 2499 | struct sli4_sge *sgl, int datacnt, int protcnt) |
| 2500 | { |
| 2501 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 2502 | struct scatterlist *sgpe = NULL; /* s/g prot entry */ |
| 2503 | struct sli4_sge_diseed *diseed = NULL; |
| 2504 | dma_addr_t dataphysaddr, protphysaddr; |
| 2505 | unsigned short curr_data = 0, curr_prot = 0; |
| 2506 | unsigned int split_offset; |
| 2507 | unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder; |
| 2508 | unsigned int protgrp_blks, protgrp_bytes; |
| 2509 | unsigned int remainder, subtotal; |
| 2510 | int status; |
| 2511 | unsigned char pgdone = 0, alldone = 0; |
| 2512 | unsigned blksize; |
| 2513 | uint32_t reftag; |
| 2514 | uint8_t txop, rxop; |
| 2515 | uint32_t dma_len; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2516 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2517 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2518 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2519 | uint32_t checking = 1; |
| 2520 | uint32_t dma_offset = 0; |
| 2521 | int num_sge = 0; |
| 2522 | |
| 2523 | sgpe = scsi_prot_sglist(sc); |
| 2524 | sgde = scsi_sglist(sc); |
| 2525 | |
| 2526 | if (!sgpe || !sgde) { |
| 2527 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2528 | "9082 Invalid s/g entry: data=0x%p prot=0x%p\n", |
| 2529 | sgpe, sgde); |
| 2530 | return 0; |
| 2531 | } |
| 2532 | |
| 2533 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 2534 | if (status) |
| 2535 | goto out; |
| 2536 | |
| 2537 | /* extract some info from the scsi command */ |
| 2538 | blksize = lpfc_cmd_blksize(sc); |
| 2539 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
| 2540 | |
| 2541 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 2542 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2543 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2544 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2545 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2546 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2547 | checking = 0; |
| 2548 | } |
| 2549 | #endif |
| 2550 | |
| 2551 | split_offset = 0; |
| 2552 | do { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2553 | /* Check to see if we ran out of space */ |
| 2554 | if (num_sge >= (phba->cfg_total_seg_cnt - 2)) |
| 2555 | return num_sge + 3; |
| 2556 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2557 | /* setup DISEED with what we have */ |
| 2558 | diseed = (struct sli4_sge_diseed *) sgl; |
| 2559 | memset(diseed, 0, sizeof(struct sli4_sge_diseed)); |
| 2560 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED); |
| 2561 | |
| 2562 | /* Endianness conversion if necessary */ |
| 2563 | diseed->ref_tag = cpu_to_le32(reftag); |
| 2564 | diseed->ref_tag_tran = diseed->ref_tag; |
| 2565 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2566 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) { |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2567 | bf_set(lpfc_sli4_sge_dif_ce, diseed, checking); |
| 2568 | |
| 2569 | } else { |
| 2570 | bf_set(lpfc_sli4_sge_dif_ce, diseed, 0); |
| 2571 | /* |
| 2572 | * When in this mode, the hardware will replace |
| 2573 | * the guard tag from the host with a |
| 2574 | * newly generated good CRC for the wire. |
| 2575 | * Switch to raw mode here to avoid this |
| 2576 | * behavior. What the host sends gets put on the wire. |
| 2577 | */ |
| 2578 | if (txop == BG_OP_IN_CRC_OUT_CRC) { |
| 2579 | txop = BG_OP_RAW_MODE; |
| 2580 | rxop = BG_OP_RAW_MODE; |
| 2581 | } |
| 2582 | } |
| 2583 | |
| 2584 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2585 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2586 | bf_set(lpfc_sli4_sge_dif_re, diseed, checking); |
| 2587 | else |
| 2588 | bf_set(lpfc_sli4_sge_dif_re, diseed, 0); |
| 2589 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2590 | /* setup DISEED with the rest of the info */ |
| 2591 | bf_set(lpfc_sli4_sge_dif_optx, diseed, txop); |
| 2592 | bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2593 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2594 | bf_set(lpfc_sli4_sge_dif_ai, diseed, 1); |
| 2595 | bf_set(lpfc_sli4_sge_dif_me, diseed, 0); |
| 2596 | |
| 2597 | /* Endianness conversion if necessary for DISEED */ |
| 2598 | diseed->word2 = cpu_to_le32(diseed->word2); |
| 2599 | diseed->word3 = cpu_to_le32(diseed->word3); |
| 2600 | |
| 2601 | /* advance sgl and increment bde count */ |
| 2602 | num_sge++; |
| 2603 | sgl++; |
| 2604 | |
| 2605 | /* setup the first BDE that points to protection buffer */ |
| 2606 | protphysaddr = sg_dma_address(sgpe) + protgroup_offset; |
| 2607 | protgroup_len = sg_dma_len(sgpe) - protgroup_offset; |
| 2608 | |
| 2609 | /* must be integer multiple of the DIF block length */ |
| 2610 | BUG_ON(protgroup_len % 8); |
| 2611 | |
| 2612 | /* Now setup DIF SGE */ |
| 2613 | sgl->word2 = 0; |
| 2614 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DIF); |
| 2615 | sgl->addr_hi = le32_to_cpu(putPaddrHigh(protphysaddr)); |
| 2616 | sgl->addr_lo = le32_to_cpu(putPaddrLow(protphysaddr)); |
| 2617 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 2618 | |
| 2619 | protgrp_blks = protgroup_len / 8; |
| 2620 | protgrp_bytes = protgrp_blks * blksize; |
| 2621 | |
| 2622 | /* check if DIF SGE is crossing the 4K boundary; if so split */ |
| 2623 | if ((sgl->addr_lo & 0xfff) + protgroup_len > 0x1000) { |
| 2624 | protgroup_remainder = 0x1000 - (sgl->addr_lo & 0xfff); |
| 2625 | protgroup_offset += protgroup_remainder; |
| 2626 | protgrp_blks = protgroup_remainder / 8; |
| 2627 | protgrp_bytes = protgrp_blks * blksize; |
| 2628 | } else { |
| 2629 | protgroup_offset = 0; |
| 2630 | curr_prot++; |
| 2631 | } |
| 2632 | |
| 2633 | num_sge++; |
| 2634 | |
| 2635 | /* setup SGE's for data blocks associated with DIF data */ |
| 2636 | pgdone = 0; |
| 2637 | subtotal = 0; /* total bytes processed for current prot grp */ |
| 2638 | while (!pgdone) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2639 | /* Check to see if we ran out of space */ |
| 2640 | if (num_sge >= phba->cfg_total_seg_cnt) |
| 2641 | return num_sge + 1; |
| 2642 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2643 | if (!sgde) { |
| 2644 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2645 | "9086 BLKGRD:%s Invalid data segment\n", |
| 2646 | __func__); |
| 2647 | return 0; |
| 2648 | } |
| 2649 | sgl++; |
| 2650 | dataphysaddr = sg_dma_address(sgde) + split_offset; |
| 2651 | |
| 2652 | remainder = sg_dma_len(sgde) - split_offset; |
| 2653 | |
| 2654 | if ((subtotal + remainder) <= protgrp_bytes) { |
| 2655 | /* we can use this whole buffer */ |
| 2656 | dma_len = remainder; |
| 2657 | split_offset = 0; |
| 2658 | |
| 2659 | if ((subtotal + remainder) == protgrp_bytes) |
| 2660 | pgdone = 1; |
| 2661 | } else { |
| 2662 | /* must split this buffer with next prot grp */ |
| 2663 | dma_len = protgrp_bytes - subtotal; |
| 2664 | split_offset += dma_len; |
| 2665 | } |
| 2666 | |
| 2667 | subtotal += dma_len; |
| 2668 | |
| 2669 | sgl->addr_lo = cpu_to_le32(putPaddrLow(dataphysaddr)); |
| 2670 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(dataphysaddr)); |
| 2671 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 2672 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
| 2673 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); |
| 2674 | |
| 2675 | sgl->sge_len = cpu_to_le32(dma_len); |
| 2676 | dma_offset += dma_len; |
| 2677 | |
| 2678 | num_sge++; |
| 2679 | curr_data++; |
| 2680 | |
| 2681 | if (split_offset) |
| 2682 | break; |
| 2683 | |
| 2684 | /* Move to the next s/g segment if possible */ |
| 2685 | sgde = sg_next(sgde); |
| 2686 | } |
| 2687 | |
| 2688 | if (protgroup_offset) { |
| 2689 | /* update the reference tag */ |
| 2690 | reftag += protgrp_blks; |
| 2691 | sgl++; |
| 2692 | continue; |
| 2693 | } |
| 2694 | |
| 2695 | /* are we done ? */ |
| 2696 | if (curr_prot == protcnt) { |
| 2697 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 2698 | alldone = 1; |
| 2699 | } else if (curr_prot < protcnt) { |
| 2700 | /* advance to next prot buffer */ |
| 2701 | sgpe = sg_next(sgpe); |
| 2702 | sgl++; |
| 2703 | |
| 2704 | /* update the reference tag */ |
| 2705 | reftag += protgrp_blks; |
| 2706 | } else { |
| 2707 | /* if we're here, we have a bug */ |
| 2708 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2709 | "9085 BLKGRD: bug in %s\n", __func__); |
| 2710 | } |
| 2711 | |
| 2712 | } while (!alldone); |
| 2713 | |
| 2714 | out: |
| 2715 | |
| 2716 | return num_sge; |
| 2717 | } |
| 2718 | |
| 2719 | /** |
| 2720 | * lpfc_prot_group_type - Get prtotection group type of SCSI command |
| 2721 | * @phba: The Hba for which this call is being executed. |
| 2722 | * @sc: pointer to scsi command we're working on |
| 2723 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2724 | * Given a SCSI command that supports DIF, determine composition of protection |
| 2725 | * groups involved in setting up buffer lists |
| 2726 | * |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2727 | * Returns: Protection group type (with or without DIF) |
| 2728 | * |
| 2729 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2730 | static int |
| 2731 | lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc) |
| 2732 | { |
| 2733 | int ret = LPFC_PG_TYPE_INVALID; |
| 2734 | unsigned char op = scsi_get_prot_op(sc); |
| 2735 | |
| 2736 | switch (op) { |
| 2737 | case SCSI_PROT_READ_STRIP: |
| 2738 | case SCSI_PROT_WRITE_INSERT: |
| 2739 | ret = LPFC_PG_TYPE_NO_DIF; |
| 2740 | break; |
| 2741 | case SCSI_PROT_READ_INSERT: |
| 2742 | case SCSI_PROT_WRITE_STRIP: |
| 2743 | case SCSI_PROT_READ_PASS: |
| 2744 | case SCSI_PROT_WRITE_PASS: |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2745 | ret = LPFC_PG_TYPE_DIF_BUF; |
| 2746 | break; |
| 2747 | default: |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2748 | if (phba) |
| 2749 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2750 | "9021 Unsupported protection op:%d\n", |
| 2751 | op); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2752 | break; |
| 2753 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2754 | return ret; |
| 2755 | } |
| 2756 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2757 | /** |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2758 | * lpfc_bg_scsi_adjust_dl - Adjust SCSI data length for BlockGuard |
| 2759 | * @phba: The Hba for which this call is being executed. |
| 2760 | * @lpfc_cmd: The scsi buffer which is going to be adjusted. |
| 2761 | * |
| 2762 | * Adjust the data length to account for how much data |
| 2763 | * is actually on the wire. |
| 2764 | * |
| 2765 | * returns the adjusted data length |
| 2766 | **/ |
| 2767 | static int |
| 2768 | lpfc_bg_scsi_adjust_dl(struct lpfc_hba *phba, |
| 2769 | struct lpfc_scsi_buf *lpfc_cmd) |
| 2770 | { |
| 2771 | struct scsi_cmnd *sc = lpfc_cmd->pCmd; |
| 2772 | int fcpdl; |
| 2773 | |
| 2774 | fcpdl = scsi_bufflen(sc); |
| 2775 | |
| 2776 | /* Check if there is protection data on the wire */ |
| 2777 | if (sc->sc_data_direction == DMA_FROM_DEVICE) { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2778 | /* Read check for protection data */ |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2779 | if (scsi_get_prot_op(sc) == SCSI_PROT_READ_INSERT) |
| 2780 | return fcpdl; |
| 2781 | |
| 2782 | } else { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2783 | /* Write check for protection data */ |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2784 | if (scsi_get_prot_op(sc) == SCSI_PROT_WRITE_STRIP) |
| 2785 | return fcpdl; |
| 2786 | } |
| 2787 | |
| 2788 | /* |
| 2789 | * If we are in DIF Type 1 mode every data block has a 8 byte |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2790 | * DIF (trailer) attached to it. Must ajust FCP data length |
| 2791 | * to account for the protection data. |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2792 | */ |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2793 | fcpdl += (fcpdl / lpfc_cmd_blksize(sc)) * 8; |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2794 | |
| 2795 | return fcpdl; |
| 2796 | } |
| 2797 | |
| 2798 | /** |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2799 | * lpfc_bg_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec |
| 2800 | * @phba: The Hba for which this call is being executed. |
| 2801 | * @lpfc_cmd: The scsi buffer which is going to be prep'ed. |
| 2802 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2803 | * This is the protection/DIF aware version of |
| 2804 | * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the |
| 2805 | * two functions eventually, but for now, it's here |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2806 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2807 | static int |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2808 | lpfc_bg_scsi_prep_dma_buf_s3(struct lpfc_hba *phba, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2809 | struct lpfc_scsi_buf *lpfc_cmd) |
| 2810 | { |
| 2811 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 2812 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 2813 | struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl; |
| 2814 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 2815 | uint32_t num_bde = 0; |
| 2816 | int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction; |
| 2817 | int prot_group_type = 0; |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2818 | int fcpdl; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2819 | |
| 2820 | /* |
| 2821 | * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd |
| 2822 | * fcp_rsp regions to the first data bde entry |
| 2823 | */ |
| 2824 | bpl += 2; |
| 2825 | if (scsi_sg_count(scsi_cmnd)) { |
| 2826 | /* |
| 2827 | * The driver stores the segment count returned from pci_map_sg |
| 2828 | * because this a count of dma-mappings used to map the use_sg |
| 2829 | * pages. They are not guaranteed to be the same for those |
| 2830 | * architectures that implement an IOMMU. |
| 2831 | */ |
| 2832 | datasegcnt = dma_map_sg(&phba->pcidev->dev, |
| 2833 | scsi_sglist(scsi_cmnd), |
| 2834 | scsi_sg_count(scsi_cmnd), datadir); |
| 2835 | if (unlikely(!datasegcnt)) |
| 2836 | return 1; |
| 2837 | |
| 2838 | lpfc_cmd->seg_cnt = datasegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2839 | |
| 2840 | /* First check if data segment count from SCSI Layer is good */ |
| 2841 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) |
| 2842 | goto err; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2843 | |
| 2844 | prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd); |
| 2845 | |
| 2846 | switch (prot_group_type) { |
| 2847 | case LPFC_PG_TYPE_NO_DIF: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2848 | |
| 2849 | /* Here we need to add a PDE5 and PDE6 to the count */ |
| 2850 | if ((lpfc_cmd->seg_cnt + 2) > phba->cfg_total_seg_cnt) |
| 2851 | goto err; |
| 2852 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2853 | num_bde = lpfc_bg_setup_bpl(phba, scsi_cmnd, bpl, |
| 2854 | datasegcnt); |
Adam Buchbinder | c9404c9 | 2009-12-18 15:40:42 -0500 | [diff] [blame] | 2855 | /* we should have 2 or more entries in buffer list */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2856 | if (num_bde < 2) |
| 2857 | goto err; |
| 2858 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2859 | |
| 2860 | case LPFC_PG_TYPE_DIF_BUF: |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2861 | /* |
| 2862 | * This type indicates that protection buffers are |
| 2863 | * passed to the driver, so that needs to be prepared |
| 2864 | * for DMA |
| 2865 | */ |
| 2866 | protsegcnt = dma_map_sg(&phba->pcidev->dev, |
| 2867 | scsi_prot_sglist(scsi_cmnd), |
| 2868 | scsi_prot_sg_count(scsi_cmnd), datadir); |
| 2869 | if (unlikely(!protsegcnt)) { |
| 2870 | scsi_dma_unmap(scsi_cmnd); |
| 2871 | return 1; |
| 2872 | } |
| 2873 | |
| 2874 | lpfc_cmd->prot_seg_cnt = protsegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2875 | |
| 2876 | /* |
| 2877 | * There is a minimun of 4 BPLs used for every |
| 2878 | * protection data segment. |
| 2879 | */ |
| 2880 | if ((lpfc_cmd->prot_seg_cnt * 4) > |
| 2881 | (phba->cfg_total_seg_cnt - 2)) |
| 2882 | goto err; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2883 | |
| 2884 | num_bde = lpfc_bg_setup_bpl_prot(phba, scsi_cmnd, bpl, |
| 2885 | datasegcnt, protsegcnt); |
Adam Buchbinder | c9404c9 | 2009-12-18 15:40:42 -0500 | [diff] [blame] | 2886 | /* we should have 3 or more entries in buffer list */ |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2887 | if ((num_bde < 3) || |
| 2888 | (num_bde > phba->cfg_total_seg_cnt)) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2889 | goto err; |
| 2890 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2891 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2892 | case LPFC_PG_TYPE_INVALID: |
| 2893 | default: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2894 | scsi_dma_unmap(scsi_cmnd); |
| 2895 | lpfc_cmd->seg_cnt = 0; |
| 2896 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2897 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2898 | "9022 Unexpected protection group %i\n", |
| 2899 | prot_group_type); |
| 2900 | return 1; |
| 2901 | } |
| 2902 | } |
| 2903 | |
| 2904 | /* |
| 2905 | * Finish initializing those IOCB fields that are dependent on the |
| 2906 | * scsi_cmnd request_buffer. Note that the bdeSize is explicitly |
| 2907 | * reinitialized since all iocb memory resources are used many times |
| 2908 | * for transmit, receive, and continuation bpl's. |
| 2909 | */ |
| 2910 | iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| 2911 | iocb_cmd->un.fcpi64.bdl.bdeSize += (num_bde * sizeof(struct ulp_bde64)); |
| 2912 | iocb_cmd->ulpBdeCount = 1; |
| 2913 | iocb_cmd->ulpLe = 1; |
| 2914 | |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2915 | fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2916 | fcp_cmnd->fcpDl = be32_to_cpu(fcpdl); |
| 2917 | |
| 2918 | /* |
| 2919 | * Due to difference in data length between DIF/non-DIF paths, |
| 2920 | * we need to set word 4 of IOCB here |
| 2921 | */ |
| 2922 | iocb_cmd->un.fcpi.fcpi_parm = fcpdl; |
| 2923 | |
| 2924 | return 0; |
| 2925 | err: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2926 | if (lpfc_cmd->seg_cnt) |
| 2927 | scsi_dma_unmap(scsi_cmnd); |
| 2928 | if (lpfc_cmd->prot_seg_cnt) |
| 2929 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd), |
| 2930 | scsi_prot_sg_count(scsi_cmnd), |
| 2931 | scsi_cmnd->sc_data_direction); |
| 2932 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2933 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2934 | "9023 Cannot setup S/G List for HBA" |
| 2935 | "IO segs %d/%d BPL %d SCSI %d: %d %d\n", |
| 2936 | lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt, |
| 2937 | phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2938 | prot_group_type, num_bde); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2939 | |
| 2940 | lpfc_cmd->seg_cnt = 0; |
| 2941 | lpfc_cmd->prot_seg_cnt = 0; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2942 | return 1; |
| 2943 | } |
| 2944 | |
| 2945 | /* |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2946 | * This function calcuates the T10 DIF guard tag |
| 2947 | * on the specified data using a CRC algorithmn |
| 2948 | * using crc_t10dif. |
| 2949 | */ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 2950 | static uint16_t |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2951 | lpfc_bg_crc(uint8_t *data, int count) |
| 2952 | { |
| 2953 | uint16_t crc = 0; |
| 2954 | uint16_t x; |
| 2955 | |
| 2956 | crc = crc_t10dif(data, count); |
| 2957 | x = cpu_to_be16(crc); |
| 2958 | return x; |
| 2959 | } |
| 2960 | |
| 2961 | /* |
| 2962 | * This function calcuates the T10 DIF guard tag |
| 2963 | * on the specified data using a CSUM algorithmn |
| 2964 | * using ip_compute_csum. |
| 2965 | */ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 2966 | static uint16_t |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2967 | lpfc_bg_csum(uint8_t *data, int count) |
| 2968 | { |
| 2969 | uint16_t ret; |
| 2970 | |
| 2971 | ret = ip_compute_csum(data, count); |
| 2972 | return ret; |
| 2973 | } |
| 2974 | |
| 2975 | /* |
| 2976 | * This function examines the protection data to try to determine |
| 2977 | * what type of T10-DIF error occurred. |
| 2978 | */ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 2979 | static void |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2980 | lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 2981 | { |
| 2982 | struct scatterlist *sgpe; /* s/g prot entry */ |
| 2983 | struct scatterlist *sgde; /* s/g data entry */ |
| 2984 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 2985 | struct scsi_dif_tuple *src = NULL; |
| 2986 | uint8_t *data_src = NULL; |
| 2987 | uint16_t guard_tag, guard_type; |
| 2988 | uint16_t start_app_tag, app_tag; |
| 2989 | uint32_t start_ref_tag, ref_tag; |
| 2990 | int prot, protsegcnt; |
| 2991 | int err_type, len, data_len; |
| 2992 | int chk_ref, chk_app, chk_guard; |
| 2993 | uint16_t sum; |
| 2994 | unsigned blksize; |
| 2995 | |
| 2996 | err_type = BGS_GUARD_ERR_MASK; |
| 2997 | sum = 0; |
| 2998 | guard_tag = 0; |
| 2999 | |
| 3000 | /* First check to see if there is protection data to examine */ |
| 3001 | prot = scsi_get_prot_op(cmd); |
| 3002 | if ((prot == SCSI_PROT_READ_STRIP) || |
| 3003 | (prot == SCSI_PROT_WRITE_INSERT) || |
| 3004 | (prot == SCSI_PROT_NORMAL)) |
| 3005 | goto out; |
| 3006 | |
| 3007 | /* Currently the driver just supports ref_tag and guard_tag checking */ |
| 3008 | chk_ref = 1; |
| 3009 | chk_app = 0; |
| 3010 | chk_guard = 0; |
| 3011 | |
| 3012 | /* Setup a ptr to the protection data provided by the SCSI host */ |
| 3013 | sgpe = scsi_prot_sglist(cmd); |
| 3014 | protsegcnt = lpfc_cmd->prot_seg_cnt; |
| 3015 | |
| 3016 | if (sgpe && protsegcnt) { |
| 3017 | |
| 3018 | /* |
| 3019 | * We will only try to verify guard tag if the segment |
| 3020 | * data length is a multiple of the blksize. |
| 3021 | */ |
| 3022 | sgde = scsi_sglist(cmd); |
| 3023 | blksize = lpfc_cmd_blksize(cmd); |
| 3024 | data_src = (uint8_t *)sg_virt(sgde); |
| 3025 | data_len = sgde->length; |
| 3026 | if ((data_len & (blksize - 1)) == 0) |
| 3027 | chk_guard = 1; |
| 3028 | guard_type = scsi_host_get_guard(cmd->device->host); |
| 3029 | |
James Smart | e85d8f9 | 2013-05-31 17:04:10 -0400 | [diff] [blame] | 3030 | src = (struct scsi_dif_tuple *)sg_virt(sgpe); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 3031 | start_ref_tag = (uint32_t)scsi_get_lba(cmd); /* Truncate LBA */ |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3032 | start_app_tag = src->app_tag; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3033 | len = sgpe->length; |
| 3034 | while (src && protsegcnt) { |
| 3035 | while (len) { |
| 3036 | |
| 3037 | /* |
| 3038 | * First check to see if a protection data |
| 3039 | * check is valid |
| 3040 | */ |
| 3041 | if ((src->ref_tag == 0xffffffff) || |
| 3042 | (src->app_tag == 0xffff)) { |
| 3043 | start_ref_tag++; |
| 3044 | goto skipit; |
| 3045 | } |
| 3046 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 3047 | /* First Guard Tag checking */ |
| 3048 | if (chk_guard) { |
| 3049 | guard_tag = src->guard_tag; |
| 3050 | if (lpfc_cmd_guard_csum(cmd)) |
| 3051 | sum = lpfc_bg_csum(data_src, |
| 3052 | blksize); |
| 3053 | else |
| 3054 | sum = lpfc_bg_crc(data_src, |
| 3055 | blksize); |
| 3056 | if ((guard_tag != sum)) { |
| 3057 | err_type = BGS_GUARD_ERR_MASK; |
| 3058 | goto out; |
| 3059 | } |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3060 | } |
| 3061 | |
| 3062 | /* Reference Tag checking */ |
| 3063 | ref_tag = be32_to_cpu(src->ref_tag); |
| 3064 | if (chk_ref && (ref_tag != start_ref_tag)) { |
| 3065 | err_type = BGS_REFTAG_ERR_MASK; |
| 3066 | goto out; |
| 3067 | } |
| 3068 | start_ref_tag++; |
| 3069 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 3070 | /* App Tag checking */ |
| 3071 | app_tag = src->app_tag; |
| 3072 | if (chk_app && (app_tag != start_app_tag)) { |
| 3073 | err_type = BGS_APPTAG_ERR_MASK; |
| 3074 | goto out; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3075 | } |
| 3076 | skipit: |
| 3077 | len -= sizeof(struct scsi_dif_tuple); |
| 3078 | if (len < 0) |
| 3079 | len = 0; |
| 3080 | src++; |
| 3081 | |
| 3082 | data_src += blksize; |
| 3083 | data_len -= blksize; |
| 3084 | |
| 3085 | /* |
| 3086 | * Are we at the end of the Data segment? |
| 3087 | * The data segment is only used for Guard |
| 3088 | * tag checking. |
| 3089 | */ |
| 3090 | if (chk_guard && (data_len == 0)) { |
| 3091 | chk_guard = 0; |
| 3092 | sgde = sg_next(sgde); |
| 3093 | if (!sgde) |
| 3094 | goto out; |
| 3095 | |
| 3096 | data_src = (uint8_t *)sg_virt(sgde); |
| 3097 | data_len = sgde->length; |
| 3098 | if ((data_len & (blksize - 1)) == 0) |
| 3099 | chk_guard = 1; |
| 3100 | } |
| 3101 | } |
| 3102 | |
| 3103 | /* Goto the next Protection data segment */ |
| 3104 | sgpe = sg_next(sgpe); |
| 3105 | if (sgpe) { |
| 3106 | src = (struct scsi_dif_tuple *)sg_virt(sgpe); |
| 3107 | len = sgpe->length; |
| 3108 | } else { |
| 3109 | src = NULL; |
| 3110 | } |
| 3111 | protsegcnt--; |
| 3112 | } |
| 3113 | } |
| 3114 | out: |
| 3115 | if (err_type == BGS_GUARD_ERR_MASK) { |
| 3116 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 3117 | 0x10, 0x1); |
| 3118 | cmd->result = DRIVER_SENSE << 24 |
| 3119 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 3120 | phba->bg_guard_err_cnt++; |
| 3121 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3122 | "9069 BLKGRD: LBA %lx grd_tag error %x != %x\n", |
| 3123 | (unsigned long)scsi_get_lba(cmd), |
| 3124 | sum, guard_tag); |
| 3125 | |
| 3126 | } else if (err_type == BGS_REFTAG_ERR_MASK) { |
| 3127 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 3128 | 0x10, 0x3); |
| 3129 | cmd->result = DRIVER_SENSE << 24 |
| 3130 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 3131 | |
| 3132 | phba->bg_reftag_err_cnt++; |
| 3133 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3134 | "9066 BLKGRD: LBA %lx ref_tag error %x != %x\n", |
| 3135 | (unsigned long)scsi_get_lba(cmd), |
| 3136 | ref_tag, start_ref_tag); |
| 3137 | |
| 3138 | } else if (err_type == BGS_APPTAG_ERR_MASK) { |
| 3139 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 3140 | 0x10, 0x2); |
| 3141 | cmd->result = DRIVER_SENSE << 24 |
| 3142 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 3143 | |
| 3144 | phba->bg_apptag_err_cnt++; |
| 3145 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3146 | "9041 BLKGRD: LBA %lx app_tag error %x != %x\n", |
| 3147 | (unsigned long)scsi_get_lba(cmd), |
| 3148 | app_tag, start_app_tag); |
| 3149 | } |
| 3150 | } |
| 3151 | |
| 3152 | |
| 3153 | /* |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3154 | * This function checks for BlockGuard errors detected by |
| 3155 | * the HBA. In case of errors, the ASC/ASCQ fields in the |
| 3156 | * sense buffer will be set accordingly, paired with |
| 3157 | * ILLEGAL_REQUEST to signal to the kernel that the HBA |
| 3158 | * detected corruption. |
| 3159 | * |
| 3160 | * Returns: |
| 3161 | * 0 - No error found |
| 3162 | * 1 - BlockGuard error found |
| 3163 | * -1 - Internal error (bad profile, ...etc) |
| 3164 | */ |
| 3165 | static int |
| 3166 | lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd, |
| 3167 | struct lpfc_iocbq *pIocbOut) |
| 3168 | { |
| 3169 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 3170 | struct sli3_bg_fields *bgf = &pIocbOut->iocb.unsli3.sli3_bg; |
| 3171 | int ret = 0; |
| 3172 | uint32_t bghm = bgf->bghm; |
| 3173 | uint32_t bgstat = bgf->bgstat; |
| 3174 | uint64_t failing_sector = 0; |
| 3175 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3176 | spin_lock(&_dump_buf_lock); |
| 3177 | if (!_dump_buf_done) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3178 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9070 BLKGRD: Saving" |
| 3179 | " Data for %u blocks to debugfs\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3180 | (cmd->cmnd[7] << 8 | cmd->cmnd[8])); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3181 | lpfc_debug_save_data(phba, cmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3182 | |
| 3183 | /* If we have a prot sgl, save the DIF buffer */ |
| 3184 | if (lpfc_prot_group_type(phba, cmd) == |
| 3185 | LPFC_PG_TYPE_DIF_BUF) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3186 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9071 BLKGRD: " |
| 3187 | "Saving DIF for %u blocks to debugfs\n", |
| 3188 | (cmd->cmnd[7] << 8 | cmd->cmnd[8])); |
| 3189 | lpfc_debug_save_dif(phba, cmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3190 | } |
| 3191 | |
| 3192 | _dump_buf_done = 1; |
| 3193 | } |
| 3194 | spin_unlock(&_dump_buf_lock); |
| 3195 | |
| 3196 | if (lpfc_bgs_get_invalid_prof(bgstat)) { |
| 3197 | cmd->result = ScsiResult(DID_ERROR, 0); |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3198 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3199 | "9072 BLKGRD: Invalid BG Profile in cmd" |
| 3200 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3201 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3202 | (unsigned long long)scsi_get_lba(cmd), |
| 3203 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3204 | ret = (-1); |
| 3205 | goto out; |
| 3206 | } |
| 3207 | |
| 3208 | if (lpfc_bgs_get_uninit_dif_block(bgstat)) { |
| 3209 | cmd->result = ScsiResult(DID_ERROR, 0); |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3210 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3211 | "9073 BLKGRD: Invalid BG PDIF Block in cmd" |
| 3212 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3213 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3214 | (unsigned long long)scsi_get_lba(cmd), |
| 3215 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3216 | ret = (-1); |
| 3217 | goto out; |
| 3218 | } |
| 3219 | |
| 3220 | if (lpfc_bgs_get_guard_err(bgstat)) { |
| 3221 | ret = 1; |
| 3222 | |
| 3223 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 3224 | 0x10, 0x1); |
Martin K. Petersen | 1c9fbaf | 2009-01-04 03:14:11 -0500 | [diff] [blame] | 3225 | cmd->result = DRIVER_SENSE << 24 |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3226 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 3227 | phba->bg_guard_err_cnt++; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3228 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3229 | "9055 BLKGRD: Guard Tag error in cmd" |
| 3230 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3231 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3232 | (unsigned long long)scsi_get_lba(cmd), |
| 3233 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3234 | } |
| 3235 | |
| 3236 | if (lpfc_bgs_get_reftag_err(bgstat)) { |
| 3237 | ret = 1; |
| 3238 | |
| 3239 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 3240 | 0x10, 0x3); |
Martin K. Petersen | 1c9fbaf | 2009-01-04 03:14:11 -0500 | [diff] [blame] | 3241 | cmd->result = DRIVER_SENSE << 24 |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3242 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 3243 | |
| 3244 | phba->bg_reftag_err_cnt++; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3245 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3246 | "9056 BLKGRD: Ref Tag error in cmd" |
| 3247 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3248 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3249 | (unsigned long long)scsi_get_lba(cmd), |
| 3250 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3251 | } |
| 3252 | |
| 3253 | if (lpfc_bgs_get_apptag_err(bgstat)) { |
| 3254 | ret = 1; |
| 3255 | |
| 3256 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 3257 | 0x10, 0x2); |
Martin K. Petersen | 1c9fbaf | 2009-01-04 03:14:11 -0500 | [diff] [blame] | 3258 | cmd->result = DRIVER_SENSE << 24 |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3259 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 3260 | |
| 3261 | phba->bg_apptag_err_cnt++; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3262 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3263 | "9061 BLKGRD: App Tag error in cmd" |
| 3264 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3265 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3266 | (unsigned long long)scsi_get_lba(cmd), |
| 3267 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3268 | } |
| 3269 | |
| 3270 | if (lpfc_bgs_get_hi_water_mark_present(bgstat)) { |
| 3271 | /* |
| 3272 | * setup sense data descriptor 0 per SPC-4 as an information |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 3273 | * field, and put the failing LBA in it. |
| 3274 | * This code assumes there was also a guard/app/ref tag error |
| 3275 | * indication. |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3276 | */ |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 3277 | cmd->sense_buffer[7] = 0xc; /* Additional sense length */ |
| 3278 | cmd->sense_buffer[8] = 0; /* Information descriptor type */ |
| 3279 | cmd->sense_buffer[9] = 0xa; /* Additional descriptor length */ |
| 3280 | cmd->sense_buffer[10] = 0x80; /* Validity bit */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3281 | |
| 3282 | /* bghm is a "on the wire" FC frame based count */ |
| 3283 | switch (scsi_get_prot_op(cmd)) { |
| 3284 | case SCSI_PROT_READ_INSERT: |
| 3285 | case SCSI_PROT_WRITE_STRIP: |
| 3286 | bghm /= cmd->device->sector_size; |
| 3287 | break; |
| 3288 | case SCSI_PROT_READ_STRIP: |
| 3289 | case SCSI_PROT_WRITE_INSERT: |
| 3290 | case SCSI_PROT_READ_PASS: |
| 3291 | case SCSI_PROT_WRITE_PASS: |
| 3292 | bghm /= (cmd->device->sector_size + |
| 3293 | sizeof(struct scsi_dif_tuple)); |
| 3294 | break; |
| 3295 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3296 | |
| 3297 | failing_sector = scsi_get_lba(cmd); |
| 3298 | failing_sector += bghm; |
| 3299 | |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 3300 | /* Descriptor Information */ |
| 3301 | put_unaligned_be64(failing_sector, &cmd->sense_buffer[12]); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3302 | } |
| 3303 | |
| 3304 | if (!ret) { |
| 3305 | /* No error was reported - problem in FW? */ |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3306 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3307 | "9057 BLKGRD: Unknown error in cmd" |
| 3308 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3309 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3310 | (unsigned long long)scsi_get_lba(cmd), |
| 3311 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3312 | |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3313 | /* Calcuate what type of error it was */ |
| 3314 | lpfc_calc_bg_err(phba, lpfc_cmd); |
| 3315 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3316 | out: |
| 3317 | return ret; |
| 3318 | } |
| 3319 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3320 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3321 | * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec |
| 3322 | * @phba: The Hba for which this call is being executed. |
| 3323 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3324 | * |
| 3325 | * This routine does the pci dma mapping for scatter-gather list of scsi cmnd |
| 3326 | * field of @lpfc_cmd for device with SLI-4 interface spec. |
| 3327 | * |
| 3328 | * Return codes: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 3329 | * 1 - Error |
| 3330 | * 0 - Success |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3331 | **/ |
| 3332 | static int |
| 3333 | lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 3334 | { |
| 3335 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 3336 | struct scatterlist *sgel = NULL; |
| 3337 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 3338 | struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3339 | struct sli4_sge *first_data_sgl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3340 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 3341 | dma_addr_t physaddr; |
| 3342 | uint32_t num_bde = 0; |
| 3343 | uint32_t dma_len; |
| 3344 | uint32_t dma_offset = 0; |
| 3345 | int nseg; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3346 | struct ulp_bde64 *bde; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3347 | |
| 3348 | /* |
| 3349 | * There are three possibilities here - use scatter-gather segment, use |
| 3350 | * the single mapping, or neither. Start the lpfc command prep by |
| 3351 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 3352 | * data bde entry. |
| 3353 | */ |
| 3354 | if (scsi_sg_count(scsi_cmnd)) { |
| 3355 | /* |
| 3356 | * The driver stores the segment count returned from pci_map_sg |
| 3357 | * because this a count of dma-mappings used to map the use_sg |
| 3358 | * pages. They are not guaranteed to be the same for those |
| 3359 | * architectures that implement an IOMMU. |
| 3360 | */ |
| 3361 | |
| 3362 | nseg = scsi_dma_map(scsi_cmnd); |
| 3363 | if (unlikely(!nseg)) |
| 3364 | return 1; |
| 3365 | sgl += 1; |
| 3366 | /* clear the last flag in the fcp_rsp map entry */ |
| 3367 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 3368 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 3369 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 3370 | sgl += 1; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3371 | first_data_sgl = sgl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3372 | lpfc_cmd->seg_cnt = nseg; |
| 3373 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3374 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9074 BLKGRD:" |
| 3375 | " %s: Too many sg segments from " |
| 3376 | "dma_map_sg. Config %d, seg_cnt %d\n", |
| 3377 | __func__, phba->cfg_sg_seg_cnt, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3378 | lpfc_cmd->seg_cnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3379 | lpfc_cmd->seg_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3380 | scsi_dma_unmap(scsi_cmnd); |
| 3381 | return 1; |
| 3382 | } |
| 3383 | |
| 3384 | /* |
| 3385 | * The driver established a maximum scatter-gather segment count |
| 3386 | * during probe that limits the number of sg elements in any |
| 3387 | * single scsi command. Just run through the seg_cnt and format |
| 3388 | * the sge's. |
| 3389 | * When using SLI-3 the driver will try to fit all the BDEs into |
| 3390 | * the IOCB. If it can't then the BDEs get added to a BPL as it |
| 3391 | * does for SLI-2 mode. |
| 3392 | */ |
| 3393 | scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) { |
| 3394 | physaddr = sg_dma_address(sgel); |
| 3395 | dma_len = sg_dma_len(sgel); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3396 | sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr)); |
| 3397 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr)); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 3398 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3399 | if ((num_bde + 1) == nseg) |
| 3400 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 3401 | else |
| 3402 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 3403 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 3404 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3405 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 3406 | sgl->sge_len = cpu_to_le32(dma_len); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3407 | dma_offset += dma_len; |
| 3408 | sgl++; |
| 3409 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3410 | /* setup the performance hint (first data BDE) if enabled */ |
| 3411 | if (phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) { |
| 3412 | bde = (struct ulp_bde64 *) |
| 3413 | &(iocb_cmd->unsli3.sli3Words[5]); |
| 3414 | bde->addrLow = first_data_sgl->addr_lo; |
| 3415 | bde->addrHigh = first_data_sgl->addr_hi; |
| 3416 | bde->tus.f.bdeSize = |
| 3417 | le32_to_cpu(first_data_sgl->sge_len); |
| 3418 | bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 3419 | bde->tus.w = cpu_to_le32(bde->tus.w); |
| 3420 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3421 | } else { |
| 3422 | sgl += 1; |
| 3423 | /* clear the last flag in the fcp_rsp map entry */ |
| 3424 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 3425 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 3426 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 3427 | } |
| 3428 | |
| 3429 | /* |
| 3430 | * Finish initializing those IOCB fields that are dependent on the |
| 3431 | * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is |
| 3432 | * explicitly reinitialized. |
| 3433 | * all iocb memory resources are reused. |
| 3434 | */ |
| 3435 | fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); |
| 3436 | |
| 3437 | /* |
| 3438 | * Due to difference in data length between DIF/non-DIF paths, |
| 3439 | * we need to set word 4 of IOCB here |
| 3440 | */ |
| 3441 | iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 3442 | |
| 3443 | /* |
| 3444 | * If the OAS driver feature is enabled and the lun is enabled for |
| 3445 | * OAS, set the oas iocb related flags. |
| 3446 | */ |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 3447 | if ((phba->cfg_fof) && ((struct lpfc_device_data *) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 3448 | scsi_cmnd->device->hostdata)->oas_enabled) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 3449 | lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3450 | return 0; |
| 3451 | } |
| 3452 | |
| 3453 | /** |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3454 | * lpfc_bg_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec |
| 3455 | * @phba: The Hba for which this call is being executed. |
| 3456 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3457 | * |
| 3458 | * This is the protection/DIF aware version of |
| 3459 | * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the |
| 3460 | * two functions eventually, but for now, it's here |
| 3461 | **/ |
| 3462 | static int |
| 3463 | lpfc_bg_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, |
| 3464 | struct lpfc_scsi_buf *lpfc_cmd) |
| 3465 | { |
| 3466 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 3467 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 3468 | struct sli4_sge *sgl = (struct sli4_sge *)(lpfc_cmd->fcp_bpl); |
| 3469 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3470 | uint32_t num_sge = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3471 | int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction; |
| 3472 | int prot_group_type = 0; |
| 3473 | int fcpdl; |
| 3474 | |
| 3475 | /* |
| 3476 | * Start the lpfc command prep by bumping the sgl beyond fcp_cmnd |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3477 | * fcp_rsp regions to the first data sge entry |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3478 | */ |
| 3479 | if (scsi_sg_count(scsi_cmnd)) { |
| 3480 | /* |
| 3481 | * The driver stores the segment count returned from pci_map_sg |
| 3482 | * because this a count of dma-mappings used to map the use_sg |
| 3483 | * pages. They are not guaranteed to be the same for those |
| 3484 | * architectures that implement an IOMMU. |
| 3485 | */ |
| 3486 | datasegcnt = dma_map_sg(&phba->pcidev->dev, |
| 3487 | scsi_sglist(scsi_cmnd), |
| 3488 | scsi_sg_count(scsi_cmnd), datadir); |
| 3489 | if (unlikely(!datasegcnt)) |
| 3490 | return 1; |
| 3491 | |
| 3492 | sgl += 1; |
| 3493 | /* clear the last flag in the fcp_rsp map entry */ |
| 3494 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 3495 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 3496 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 3497 | |
| 3498 | sgl += 1; |
| 3499 | lpfc_cmd->seg_cnt = datasegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3500 | |
| 3501 | /* First check if data segment count from SCSI Layer is good */ |
| 3502 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) |
| 3503 | goto err; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3504 | |
| 3505 | prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd); |
| 3506 | |
| 3507 | switch (prot_group_type) { |
| 3508 | case LPFC_PG_TYPE_NO_DIF: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3509 | /* Here we need to add a DISEED to the count */ |
| 3510 | if ((lpfc_cmd->seg_cnt + 1) > phba->cfg_total_seg_cnt) |
| 3511 | goto err; |
| 3512 | |
| 3513 | num_sge = lpfc_bg_setup_sgl(phba, scsi_cmnd, sgl, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3514 | datasegcnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3515 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3516 | /* we should have 2 or more entries in buffer list */ |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3517 | if (num_sge < 2) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3518 | goto err; |
| 3519 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3520 | |
| 3521 | case LPFC_PG_TYPE_DIF_BUF: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3522 | /* |
| 3523 | * This type indicates that protection buffers are |
| 3524 | * passed to the driver, so that needs to be prepared |
| 3525 | * for DMA |
| 3526 | */ |
| 3527 | protsegcnt = dma_map_sg(&phba->pcidev->dev, |
| 3528 | scsi_prot_sglist(scsi_cmnd), |
| 3529 | scsi_prot_sg_count(scsi_cmnd), datadir); |
| 3530 | if (unlikely(!protsegcnt)) { |
| 3531 | scsi_dma_unmap(scsi_cmnd); |
| 3532 | return 1; |
| 3533 | } |
| 3534 | |
| 3535 | lpfc_cmd->prot_seg_cnt = protsegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3536 | /* |
| 3537 | * There is a minimun of 3 SGEs used for every |
| 3538 | * protection data segment. |
| 3539 | */ |
| 3540 | if ((lpfc_cmd->prot_seg_cnt * 3) > |
| 3541 | (phba->cfg_total_seg_cnt - 2)) |
| 3542 | goto err; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3543 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3544 | num_sge = lpfc_bg_setup_sgl_prot(phba, scsi_cmnd, sgl, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3545 | datasegcnt, protsegcnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3546 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3547 | /* we should have 3 or more entries in buffer list */ |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3548 | if ((num_sge < 3) || |
| 3549 | (num_sge > phba->cfg_total_seg_cnt)) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3550 | goto err; |
| 3551 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3552 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3553 | case LPFC_PG_TYPE_INVALID: |
| 3554 | default: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3555 | scsi_dma_unmap(scsi_cmnd); |
| 3556 | lpfc_cmd->seg_cnt = 0; |
| 3557 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3558 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 3559 | "9083 Unexpected protection group %i\n", |
| 3560 | prot_group_type); |
| 3561 | return 1; |
| 3562 | } |
| 3563 | } |
| 3564 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 3565 | switch (scsi_get_prot_op(scsi_cmnd)) { |
| 3566 | case SCSI_PROT_WRITE_STRIP: |
| 3567 | case SCSI_PROT_READ_STRIP: |
| 3568 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_STRIP; |
| 3569 | break; |
| 3570 | case SCSI_PROT_WRITE_INSERT: |
| 3571 | case SCSI_PROT_READ_INSERT: |
| 3572 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_INSERT; |
| 3573 | break; |
| 3574 | case SCSI_PROT_WRITE_PASS: |
| 3575 | case SCSI_PROT_READ_PASS: |
| 3576 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_PASS; |
| 3577 | break; |
| 3578 | } |
| 3579 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3580 | fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3581 | fcp_cmnd->fcpDl = be32_to_cpu(fcpdl); |
| 3582 | |
| 3583 | /* |
| 3584 | * Due to difference in data length between DIF/non-DIF paths, |
| 3585 | * we need to set word 4 of IOCB here |
| 3586 | */ |
| 3587 | iocb_cmd->un.fcpi.fcpi_parm = fcpdl; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3588 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 3589 | /* |
| 3590 | * If the OAS driver feature is enabled and the lun is enabled for |
| 3591 | * OAS, set the oas iocb related flags. |
| 3592 | */ |
| 3593 | if ((phba->cfg_fof) && ((struct lpfc_device_data *) |
| 3594 | scsi_cmnd->device->hostdata)->oas_enabled) |
| 3595 | lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF); |
| 3596 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3597 | return 0; |
| 3598 | err: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3599 | if (lpfc_cmd->seg_cnt) |
| 3600 | scsi_dma_unmap(scsi_cmnd); |
| 3601 | if (lpfc_cmd->prot_seg_cnt) |
| 3602 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd), |
| 3603 | scsi_prot_sg_count(scsi_cmnd), |
| 3604 | scsi_cmnd->sc_data_direction); |
| 3605 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3606 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3607 | "9084 Cannot setup S/G List for HBA" |
| 3608 | "IO segs %d/%d SGL %d SCSI %d: %d %d\n", |
| 3609 | lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt, |
| 3610 | phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt, |
| 3611 | prot_group_type, num_sge); |
| 3612 | |
| 3613 | lpfc_cmd->seg_cnt = 0; |
| 3614 | lpfc_cmd->prot_seg_cnt = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3615 | return 1; |
| 3616 | } |
| 3617 | |
| 3618 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3619 | * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer |
| 3620 | * @phba: The Hba for which this call is being executed. |
| 3621 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3622 | * |
| 3623 | * This routine wraps the actual DMA mapping function pointer from the |
| 3624 | * lpfc_hba struct. |
| 3625 | * |
| 3626 | * Return codes: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 3627 | * 1 - Error |
| 3628 | * 0 - Success |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3629 | **/ |
| 3630 | static inline int |
| 3631 | lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 3632 | { |
| 3633 | return phba->lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 3634 | } |
| 3635 | |
| 3636 | /** |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3637 | * lpfc_bg_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer |
| 3638 | * using BlockGuard. |
| 3639 | * @phba: The Hba for which this call is being executed. |
| 3640 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3641 | * |
| 3642 | * This routine wraps the actual DMA mapping function pointer from the |
| 3643 | * lpfc_hba struct. |
| 3644 | * |
| 3645 | * Return codes: |
| 3646 | * 1 - Error |
| 3647 | * 0 - Success |
| 3648 | **/ |
| 3649 | static inline int |
| 3650 | lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 3651 | { |
| 3652 | return phba->lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 3653 | } |
| 3654 | |
| 3655 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3656 | * 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] | 3657 | * @phba: Pointer to hba context object. |
| 3658 | * @vport: Pointer to vport object. |
| 3659 | * @lpfc_cmd: Pointer to lpfc scsi command which reported the error. |
| 3660 | * @rsp_iocb: Pointer to response iocb object which reported error. |
| 3661 | * |
| 3662 | * This function posts an event when there is a SCSI command reporting |
| 3663 | * error from the scsi device. |
| 3664 | **/ |
| 3665 | static void |
| 3666 | lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 3667 | struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_iocbq *rsp_iocb) { |
| 3668 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 3669 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
| 3670 | uint32_t resp_info = fcprsp->rspStatus2; |
| 3671 | uint32_t scsi_status = fcprsp->rspStatus3; |
| 3672 | uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; |
| 3673 | struct lpfc_fast_path_event *fast_path_evt = NULL; |
| 3674 | struct lpfc_nodelist *pnode = lpfc_cmd->rdata->pnode; |
| 3675 | unsigned long flags; |
| 3676 | |
James Smart | 5989b8d | 2010-10-22 11:06:56 -0400 | [diff] [blame] | 3677 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 3678 | return; |
| 3679 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3680 | /* If there is queuefull or busy condition send a scsi event */ |
| 3681 | if ((cmnd->result == SAM_STAT_TASK_SET_FULL) || |
| 3682 | (cmnd->result == SAM_STAT_BUSY)) { |
| 3683 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3684 | if (!fast_path_evt) |
| 3685 | return; |
| 3686 | fast_path_evt->un.scsi_evt.event_type = |
| 3687 | FC_REG_SCSI_EVENT; |
| 3688 | fast_path_evt->un.scsi_evt.subcategory = |
| 3689 | (cmnd->result == SAM_STAT_TASK_SET_FULL) ? |
| 3690 | LPFC_EVENT_QFULL : LPFC_EVENT_DEVBSY; |
| 3691 | fast_path_evt->un.scsi_evt.lun = cmnd->device->lun; |
| 3692 | memcpy(&fast_path_evt->un.scsi_evt.wwpn, |
| 3693 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3694 | memcpy(&fast_path_evt->un.scsi_evt.wwnn, |
| 3695 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3696 | } else if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen && |
| 3697 | ((cmnd->cmnd[0] == READ_10) || (cmnd->cmnd[0] == WRITE_10))) { |
| 3698 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3699 | if (!fast_path_evt) |
| 3700 | return; |
| 3701 | fast_path_evt->un.check_cond_evt.scsi_event.event_type = |
| 3702 | FC_REG_SCSI_EVENT; |
| 3703 | fast_path_evt->un.check_cond_evt.scsi_event.subcategory = |
| 3704 | LPFC_EVENT_CHECK_COND; |
| 3705 | fast_path_evt->un.check_cond_evt.scsi_event.lun = |
| 3706 | cmnd->device->lun; |
| 3707 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwpn, |
| 3708 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3709 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwnn, |
| 3710 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3711 | fast_path_evt->un.check_cond_evt.sense_key = |
| 3712 | cmnd->sense_buffer[2] & 0xf; |
| 3713 | fast_path_evt->un.check_cond_evt.asc = cmnd->sense_buffer[12]; |
| 3714 | fast_path_evt->un.check_cond_evt.ascq = cmnd->sense_buffer[13]; |
| 3715 | } else if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) && |
| 3716 | fcpi_parm && |
| 3717 | ((be32_to_cpu(fcprsp->rspResId) != fcpi_parm) || |
| 3718 | ((scsi_status == SAM_STAT_GOOD) && |
| 3719 | !(resp_info & (RESID_UNDER | RESID_OVER))))) { |
| 3720 | /* |
| 3721 | * If status is good or resid does not match with fcp_param and |
| 3722 | * there is valid fcpi_parm, then there is a read_check error |
| 3723 | */ |
| 3724 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3725 | if (!fast_path_evt) |
| 3726 | return; |
| 3727 | fast_path_evt->un.read_check_error.header.event_type = |
| 3728 | FC_REG_FABRIC_EVENT; |
| 3729 | fast_path_evt->un.read_check_error.header.subcategory = |
| 3730 | LPFC_EVENT_FCPRDCHKERR; |
| 3731 | memcpy(&fast_path_evt->un.read_check_error.header.wwpn, |
| 3732 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3733 | memcpy(&fast_path_evt->un.read_check_error.header.wwnn, |
| 3734 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3735 | fast_path_evt->un.read_check_error.lun = cmnd->device->lun; |
| 3736 | fast_path_evt->un.read_check_error.opcode = cmnd->cmnd[0]; |
| 3737 | fast_path_evt->un.read_check_error.fcpiparam = |
| 3738 | fcpi_parm; |
| 3739 | } else |
| 3740 | return; |
| 3741 | |
| 3742 | fast_path_evt->vport = vport; |
| 3743 | spin_lock_irqsave(&phba->hbalock, flags); |
| 3744 | list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list); |
| 3745 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 3746 | lpfc_worker_wake_up(phba); |
| 3747 | return; |
| 3748 | } |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3749 | |
| 3750 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3751 | * 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] | 3752 | * @phba: The HBA for which this call is being executed. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3753 | * @psb: The scsi buffer which is going to be un-mapped. |
| 3754 | * |
| 3755 | * 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] | 3756 | * field of @lpfc_cmd for device with SLI-3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3757 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3758 | static void |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3759 | 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] | 3760 | { |
| 3761 | /* |
| 3762 | * There are only two special cases to consider. (1) the scsi command |
| 3763 | * requested scatter-gather usage or (2) the scsi command allocated |
| 3764 | * a request buffer, but did not request use_sg. There is a third |
| 3765 | * case, but it does not require resource deallocation. |
| 3766 | */ |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3767 | if (psb->seg_cnt > 0) |
| 3768 | scsi_dma_unmap(psb->pCmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3769 | if (psb->prot_seg_cnt > 0) |
| 3770 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(psb->pCmd), |
| 3771 | scsi_prot_sg_count(psb->pCmd), |
| 3772 | psb->pCmd->sc_data_direction); |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 3773 | } |
| 3774 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3775 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3776 | * lpfc_handler_fcp_err - FCP response handler |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3777 | * @vport: The virtual port for which this call is being executed. |
| 3778 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. |
| 3779 | * @rsp_iocb: The response IOCB which contains FCP error. |
| 3780 | * |
| 3781 | * This routine is called to process response IOCB with status field |
| 3782 | * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command |
| 3783 | * based upon SCSI and FCP error. |
| 3784 | **/ |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 3785 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3786 | lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd, |
| 3787 | struct lpfc_iocbq *rsp_iocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3788 | { |
| 3789 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 3790 | struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd; |
| 3791 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3792 | uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3793 | uint32_t resp_info = fcprsp->rspStatus2; |
| 3794 | uint32_t scsi_status = fcprsp->rspStatus3; |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3795 | uint32_t *lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3796 | uint32_t host_status = DID_OK; |
| 3797 | uint32_t rsplen = 0; |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3798 | uint32_t logit = LOG_FCP | LOG_FCP_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3799 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3800 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3801 | /* |
| 3802 | * If this is a task management command, there is no |
| 3803 | * scsi packet associated with this lpfc_cmd. The driver |
| 3804 | * consumes it. |
| 3805 | */ |
| 3806 | if (fcpcmd->fcpCntl2) { |
| 3807 | scsi_status = 0; |
| 3808 | goto out; |
| 3809 | } |
| 3810 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3811 | if (resp_info & RSP_LEN_VALID) { |
| 3812 | rsplen = be32_to_cpu(fcprsp->rspRspLen); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3813 | if (rsplen != 0 && rsplen != 4 && rsplen != 8) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3814 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 3815 | "2719 Invalid response length: " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 3816 | "tgt x%x lun x%llx cmnd x%x rsplen x%x\n", |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3817 | cmnd->device->id, |
| 3818 | cmnd->device->lun, cmnd->cmnd[0], |
| 3819 | rsplen); |
| 3820 | host_status = DID_ERROR; |
| 3821 | goto out; |
| 3822 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3823 | if (fcprsp->rspInfo3 != RSP_NO_FAILURE) { |
| 3824 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 3825 | "2757 Protocol failure detected during " |
| 3826 | "processing of FCP I/O op: " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 3827 | "tgt x%x lun x%llx cmnd x%x rspInfo3 x%x\n", |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3828 | cmnd->device->id, |
| 3829 | cmnd->device->lun, cmnd->cmnd[0], |
| 3830 | fcprsp->rspInfo3); |
| 3831 | host_status = DID_ERROR; |
| 3832 | goto out; |
| 3833 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3834 | } |
| 3835 | |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3836 | if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) { |
| 3837 | uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen); |
| 3838 | if (snslen > SCSI_SENSE_BUFFERSIZE) |
| 3839 | snslen = SCSI_SENSE_BUFFERSIZE; |
| 3840 | |
| 3841 | if (resp_info & RSP_LEN_VALID) |
| 3842 | rsplen = be32_to_cpu(fcprsp->rspRspLen); |
| 3843 | memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen); |
| 3844 | } |
| 3845 | lp = (uint32_t *)cmnd->sense_buffer; |
| 3846 | |
James Smart | aa1c7ee | 2012-08-14 14:26:06 -0400 | [diff] [blame] | 3847 | /* special handling for under run conditions */ |
| 3848 | if (!scsi_status && (resp_info & RESID_UNDER)) { |
| 3849 | /* don't log under runs if fcp set... */ |
| 3850 | if (vport->cfg_log_verbose & LOG_FCP) |
| 3851 | logit = LOG_FCP_ERROR; |
| 3852 | /* unless operator says so */ |
| 3853 | if (vport->cfg_log_verbose & LOG_FCP_UNDER) |
| 3854 | logit = LOG_FCP_UNDER; |
| 3855 | } |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3856 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3857 | lpfc_printf_vlog(vport, KERN_WARNING, logit, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3858 | "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] | 3859 | "Data: x%x x%x x%x x%x x%x\n", |
| 3860 | cmnd->cmnd[0], scsi_status, |
| 3861 | be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info, |
| 3862 | be32_to_cpu(fcprsp->rspResId), |
| 3863 | be32_to_cpu(fcprsp->rspSnsLen), |
| 3864 | be32_to_cpu(fcprsp->rspRspLen), |
| 3865 | fcprsp->rspInfo3); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3866 | |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3867 | scsi_set_resid(cmnd, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3868 | if (resp_info & RESID_UNDER) { |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3869 | scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3870 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3871 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_UNDER, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3872 | "9025 FCP Read Underrun, expected %d, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3873 | "residual %d Data: x%x x%x x%x\n", |
| 3874 | be32_to_cpu(fcpcmd->fcpDl), |
| 3875 | scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0], |
| 3876 | cmnd->underflow); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3877 | |
| 3878 | /* |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3879 | * If there is an under run check if under run reported by |
| 3880 | * storage array is same as the under run reported by HBA. |
| 3881 | * If this is not same, there is a dropped frame. |
| 3882 | */ |
| 3883 | if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) && |
| 3884 | fcpi_parm && |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3885 | (scsi_get_resid(cmnd) != fcpi_parm)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3886 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 3887 | LOG_FCP | LOG_FCP_ERROR, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3888 | "9026 FCP Read Check Error " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3889 | "and Underrun Data: x%x x%x x%x x%x\n", |
| 3890 | be32_to_cpu(fcpcmd->fcpDl), |
| 3891 | scsi_get_resid(cmnd), fcpi_parm, |
| 3892 | cmnd->cmnd[0]); |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3893 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3894 | host_status = DID_ERROR; |
| 3895 | } |
| 3896 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3897 | * The cmnd->underflow is the minimum number of bytes that must |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3898 | * be transferred for this command. Provided a sense condition |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3899 | * is not present, make sure the actual amount transferred is at |
| 3900 | * least the underflow value or fail. |
| 3901 | */ |
| 3902 | if (!(resp_info & SNS_LEN_VALID) && |
| 3903 | (scsi_status == SAM_STAT_GOOD) && |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3904 | (scsi_bufflen(cmnd) - scsi_get_resid(cmnd) |
| 3905 | < cmnd->underflow)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3906 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3907 | "9027 FCP command x%x residual " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3908 | "underrun converted to error " |
| 3909 | "Data: x%x x%x x%x\n", |
James Smart | 66dbfbe | 2007-08-05 06:08:38 -0400 | [diff] [blame] | 3910 | cmnd->cmnd[0], scsi_bufflen(cmnd), |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3911 | scsi_get_resid(cmnd), cmnd->underflow); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3912 | host_status = DID_ERROR; |
| 3913 | } |
| 3914 | } else if (resp_info & RESID_OVER) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3915 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3916 | "9028 FCP command x%x residual overrun error. " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 3917 | "Data: x%x x%x\n", cmnd->cmnd[0], |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3918 | scsi_bufflen(cmnd), scsi_get_resid(cmnd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3919 | host_status = DID_ERROR; |
| 3920 | |
| 3921 | /* |
| 3922 | * Check SLI validation that all the transfer was actually done |
James Smart | 26373d2 | 2013-09-06 12:19:17 -0400 | [diff] [blame] | 3923 | * (fcpi_parm should be zero). Apply check only to reads. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3924 | */ |
James Smart | 26373d2 | 2013-09-06 12:19:17 -0400 | [diff] [blame] | 3925 | } else if (fcpi_parm && (cmnd->sc_data_direction == DMA_FROM_DEVICE)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3926 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR, |
James Smart | 26373d2 | 2013-09-06 12:19:17 -0400 | [diff] [blame] | 3927 | "9029 FCP Read Check Error Data: " |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 3928 | "x%x x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3929 | be32_to_cpu(fcpcmd->fcpDl), |
| 3930 | be32_to_cpu(fcprsp->rspResId), |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 3931 | fcpi_parm, cmnd->cmnd[0], scsi_status); |
| 3932 | switch (scsi_status) { |
| 3933 | case SAM_STAT_GOOD: |
| 3934 | case SAM_STAT_CHECK_CONDITION: |
| 3935 | /* Fabric dropped a data frame. Fail any successful |
| 3936 | * command in which we detected dropped frames. |
| 3937 | * A status of good or some check conditions could |
| 3938 | * be considered a successful command. |
| 3939 | */ |
| 3940 | host_status = DID_ERROR; |
| 3941 | break; |
| 3942 | } |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3943 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3944 | } |
| 3945 | |
| 3946 | out: |
| 3947 | cmnd->result = ScsiResult(host_status, scsi_status); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3948 | lpfc_send_scsi_error_event(vport->phba, vport, lpfc_cmd, rsp_iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3949 | } |
| 3950 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3951 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3952 | * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3953 | * @phba: The Hba for which this call is being executed. |
| 3954 | * @pIocbIn: The command IOCBQ for the scsi cmnd. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3955 | * @pIocbOut: The response IOCBQ for the scsi cmnd. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3956 | * |
| 3957 | * This routine assigns scsi command result by looking into response IOCB |
| 3958 | * status field appropriately. This routine handles QUEUE FULL condition as |
| 3959 | * well by ramping down device queue depth. |
| 3960 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3961 | static void |
| 3962 | lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn, |
| 3963 | struct lpfc_iocbq *pIocbOut) |
| 3964 | { |
| 3965 | struct lpfc_scsi_buf *lpfc_cmd = |
| 3966 | (struct lpfc_scsi_buf *) pIocbIn->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3967 | struct lpfc_vport *vport = pIocbIn->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3968 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| 3969 | struct lpfc_nodelist *pnode = rdata->pnode; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3970 | struct scsi_cmnd *cmd; |
James.Smart@Emulex.Com | 445cf4f | 2005-11-28 11:42:38 -0500 | [diff] [blame] | 3971 | int result; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 3972 | int depth; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 3973 | unsigned long flags; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3974 | struct lpfc_fast_path_event *fast_path_evt; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3975 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3976 | uint32_t queue_depth, scsi_id; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3977 | uint32_t logit = LOG_FCP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3978 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3979 | /* Sanity check on return of outstanding command */ |
| 3980 | if (!(lpfc_cmd->pCmd)) |
| 3981 | return; |
| 3982 | cmd = lpfc_cmd->pCmd; |
| 3983 | shost = cmd->device->host; |
| 3984 | |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3985 | lpfc_cmd->result = (pIocbOut->iocb.un.ulpWord[4] & IOERR_PARAM_MASK); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3986 | lpfc_cmd->status = pIocbOut->iocb.ulpStatus; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3987 | /* pick up SLI4 exhange busy status from HBA */ |
| 3988 | lpfc_cmd->exch_busy = pIocbOut->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 3989 | |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 3990 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 3991 | if (lpfc_cmd->prot_data_type) { |
| 3992 | struct scsi_dif_tuple *src = NULL; |
| 3993 | |
| 3994 | src = (struct scsi_dif_tuple *)lpfc_cmd->prot_data_segment; |
| 3995 | /* |
| 3996 | * Used to restore any changes to protection |
| 3997 | * data for error injection. |
| 3998 | */ |
| 3999 | switch (lpfc_cmd->prot_data_type) { |
| 4000 | case LPFC_INJERR_REFTAG: |
| 4001 | src->ref_tag = |
| 4002 | lpfc_cmd->prot_data; |
| 4003 | break; |
| 4004 | case LPFC_INJERR_APPTAG: |
| 4005 | src->app_tag = |
| 4006 | (uint16_t)lpfc_cmd->prot_data; |
| 4007 | break; |
| 4008 | case LPFC_INJERR_GUARD: |
| 4009 | src->guard_tag = |
| 4010 | (uint16_t)lpfc_cmd->prot_data; |
| 4011 | break; |
| 4012 | default: |
| 4013 | break; |
| 4014 | } |
| 4015 | |
| 4016 | lpfc_cmd->prot_data = 0; |
| 4017 | lpfc_cmd->prot_data_type = 0; |
| 4018 | lpfc_cmd->prot_data_segment = NULL; |
| 4019 | } |
| 4020 | #endif |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4021 | if (pnode && NLP_CHK_NODE_ACT(pnode)) |
| 4022 | atomic_dec(&pnode->cmd_pending); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4023 | |
| 4024 | if (lpfc_cmd->status) { |
| 4025 | if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT && |
| 4026 | (lpfc_cmd->result & IOERR_DRVR_MASK)) |
| 4027 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; |
| 4028 | else if (lpfc_cmd->status >= IOSTAT_CNT) |
| 4029 | lpfc_cmd->status = IOSTAT_DEFAULT; |
James Smart | aa1c7ee | 2012-08-14 14:26:06 -0400 | [diff] [blame] | 4030 | if (lpfc_cmd->status == IOSTAT_FCP_RSP_ERROR && |
| 4031 | !lpfc_cmd->fcp_rsp->rspStatus3 && |
| 4032 | (lpfc_cmd->fcp_rsp->rspStatus2 & RESID_UNDER) && |
| 4033 | !(vport->cfg_log_verbose & LOG_FCP_UNDER)) |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 4034 | logit = 0; |
| 4035 | else |
| 4036 | logit = LOG_FCP | LOG_FCP_UNDER; |
| 4037 | lpfc_printf_vlog(vport, KERN_WARNING, logit, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4038 | "9030 FCP cmd x%x failed <%d/%lld> " |
James Smart | 5a0d80f | 2012-05-09 21:18:20 -0400 | [diff] [blame] | 4039 | "status: x%x result: x%x " |
| 4040 | "sid: x%x did: x%x oxid: x%x " |
| 4041 | "Data: x%x x%x\n", |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 4042 | cmd->cmnd[0], |
| 4043 | cmd->device ? cmd->device->id : 0xffff, |
| 4044 | cmd->device ? cmd->device->lun : 0xffff, |
| 4045 | lpfc_cmd->status, lpfc_cmd->result, |
James Smart | 3bf41ba | 2013-05-31 17:03:18 -0400 | [diff] [blame] | 4046 | vport->fc_myDID, |
| 4047 | (pnode) ? pnode->nlp_DID : 0, |
James Smart | 5a0d80f | 2012-05-09 21:18:20 -0400 | [diff] [blame] | 4048 | phba->sli_rev == LPFC_SLI_REV4 ? |
| 4049 | lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 4050 | pIocbOut->iocb.ulpContext, |
| 4051 | lpfc_cmd->cur_iocbq.iocb.ulpIoTag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4052 | |
| 4053 | switch (lpfc_cmd->status) { |
| 4054 | case IOSTAT_FCP_RSP_ERROR: |
| 4055 | /* Call FCP RSP handler to determine result */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4056 | lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4057 | break; |
| 4058 | case IOSTAT_NPORT_BSY: |
| 4059 | case IOSTAT_FABRIC_BSY: |
James Smart | 0f1f53a | 2008-08-24 21:50:18 -0400 | [diff] [blame] | 4060 | cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 0); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4061 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 4062 | if (!fast_path_evt) |
| 4063 | break; |
| 4064 | fast_path_evt->un.fabric_evt.event_type = |
| 4065 | FC_REG_FABRIC_EVENT; |
| 4066 | fast_path_evt->un.fabric_evt.subcategory = |
| 4067 | (lpfc_cmd->status == IOSTAT_NPORT_BSY) ? |
| 4068 | LPFC_EVENT_PORT_BUSY : LPFC_EVENT_FABRIC_BUSY; |
| 4069 | if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
| 4070 | memcpy(&fast_path_evt->un.fabric_evt.wwpn, |
| 4071 | &pnode->nlp_portname, |
| 4072 | sizeof(struct lpfc_name)); |
| 4073 | memcpy(&fast_path_evt->un.fabric_evt.wwnn, |
| 4074 | &pnode->nlp_nodename, |
| 4075 | sizeof(struct lpfc_name)); |
| 4076 | } |
| 4077 | fast_path_evt->vport = vport; |
| 4078 | fast_path_evt->work_evt.evt = |
| 4079 | LPFC_EVT_FASTPATH_MGMT_EVT; |
| 4080 | spin_lock_irqsave(&phba->hbalock, flags); |
| 4081 | list_add_tail(&fast_path_evt->work_evt.evt_listp, |
| 4082 | &phba->work_list); |
| 4083 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4084 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4085 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4086 | case IOSTAT_LOCAL_REJECT: |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4087 | case IOSTAT_REMOTE_STOP: |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 4088 | if (lpfc_cmd->result == IOERR_ELXSEC_KEY_UNWRAP_ERROR || |
| 4089 | lpfc_cmd->result == |
| 4090 | IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR || |
| 4091 | lpfc_cmd->result == IOERR_ELXSEC_CRYPTO_ERROR || |
| 4092 | lpfc_cmd->result == |
| 4093 | IOERR_ELXSEC_CRYPTO_COMPARE_ERROR) { |
| 4094 | cmd->result = ScsiResult(DID_NO_CONNECT, 0); |
| 4095 | break; |
| 4096 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4097 | if (lpfc_cmd->result == IOERR_INVALID_RPI || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4098 | lpfc_cmd->result == IOERR_NO_RESOURCES || |
James Smart | b92938b | 2010-06-07 15:24:12 -0400 | [diff] [blame] | 4099 | lpfc_cmd->result == IOERR_ABORT_REQUESTED || |
| 4100 | lpfc_cmd->result == IOERR_SLER_CMD_RCV_FAILURE) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4101 | cmd->result = ScsiResult(DID_REQUEUE, 0); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4102 | break; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4103 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4104 | if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED || |
| 4105 | lpfc_cmd->result == IOERR_TX_DMA_FAILED) && |
| 4106 | pIocbOut->iocb.unsli3.sli3_bg.bgstat) { |
| 4107 | if (scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) { |
| 4108 | /* |
| 4109 | * This is a response for a BG enabled |
| 4110 | * cmd. Parse BG error |
| 4111 | */ |
| 4112 | lpfc_parse_bg_err(phba, lpfc_cmd, |
| 4113 | pIocbOut); |
| 4114 | break; |
| 4115 | } else { |
| 4116 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 4117 | LOG_BG, |
| 4118 | "9031 non-zero BGSTAT " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4119 | "on unprotected cmd\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4120 | } |
| 4121 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4122 | if ((lpfc_cmd->status == IOSTAT_REMOTE_STOP) |
| 4123 | && (phba->sli_rev == LPFC_SLI_REV4) |
| 4124 | && (pnode && NLP_CHK_NODE_ACT(pnode))) { |
| 4125 | /* This IO was aborted by the target, we don't |
| 4126 | * know the rxid and because we did not send the |
| 4127 | * ABTS we cannot generate and RRQ. |
| 4128 | */ |
| 4129 | lpfc_set_rrq_active(phba, pnode, |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 4130 | lpfc_cmd->cur_iocbq.sli4_lxritag, |
| 4131 | 0, 0); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4132 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4133 | /* else: fall through */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4134 | default: |
| 4135 | cmd->result = ScsiResult(DID_ERROR, 0); |
| 4136 | break; |
| 4137 | } |
| 4138 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4139 | if (!pnode || !NLP_CHK_NODE_ACT(pnode) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4140 | || (pnode->nlp_state != NLP_STE_MAPPED_NODE)) |
James Smart | 0f1f53a | 2008-08-24 21:50:18 -0400 | [diff] [blame] | 4141 | cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, |
| 4142 | SAM_STAT_BUSY); |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 4143 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4144 | cmd->result = ScsiResult(DID_OK, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4145 | |
| 4146 | if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) { |
| 4147 | uint32_t *lp = (uint32_t *)cmd->sense_buffer; |
| 4148 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4149 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4150 | "0710 Iodone <%d/%llu> cmd %p, error " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4151 | "x%x SNS x%x x%x Data: x%x x%x\n", |
| 4152 | cmd->device->id, cmd->device->lun, cmd, |
| 4153 | cmd->result, *lp, *(lp + 3), cmd->retries, |
| 4154 | scsi_get_resid(cmd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4155 | } |
| 4156 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4157 | lpfc_update_stats(phba, lpfc_cmd); |
James.Smart@Emulex.Com | 445cf4f | 2005-11-28 11:42:38 -0500 | [diff] [blame] | 4158 | result = cmd->result; |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4159 | if (vport->cfg_max_scsicmpl_time && |
| 4160 | time_after(jiffies, lpfc_cmd->start_time + |
| 4161 | msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4162 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4163 | if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
| 4164 | if (pnode->cmd_qdepth > |
| 4165 | atomic_read(&pnode->cmd_pending) && |
| 4166 | (atomic_read(&pnode->cmd_pending) > |
| 4167 | LPFC_MIN_TGT_QDEPTH) && |
| 4168 | ((cmd->cmnd[0] == READ_10) || |
| 4169 | (cmd->cmnd[0] == WRITE_10))) |
| 4170 | pnode->cmd_qdepth = |
| 4171 | atomic_read(&pnode->cmd_pending); |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4172 | |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4173 | pnode->last_change_time = jiffies; |
| 4174 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4175 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4176 | } else if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 4177 | if ((pnode->cmd_qdepth < vport->cfg_tgt_queue_depth) && |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4178 | time_after(jiffies, pnode->last_change_time + |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4179 | msecs_to_jiffies(LPFC_TGTQ_INTERVAL))) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4180 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 4181 | depth = pnode->cmd_qdepth * LPFC_TGTQ_RAMPUP_PCENT |
| 4182 | / 100; |
| 4183 | depth = depth ? depth : 1; |
| 4184 | pnode->cmd_qdepth += depth; |
| 4185 | if (pnode->cmd_qdepth > vport->cfg_tgt_queue_depth) |
| 4186 | pnode->cmd_qdepth = vport->cfg_tgt_queue_depth; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4187 | pnode->last_change_time = jiffies; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4188 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4189 | } |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4190 | } |
| 4191 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4192 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4193 | |
| 4194 | /* The sdev is not guaranteed to be valid post scsi_done upcall. */ |
| 4195 | queue_depth = cmd->device->queue_depth; |
| 4196 | scsi_id = cmd->device->id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4197 | cmd->scsi_done(cmd); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4198 | |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 4199 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4200 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92e3af6 | 2012-08-14 14:26:28 -0400 | [diff] [blame] | 4201 | lpfc_cmd->pCmd = NULL; |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4202 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92e3af6 | 2012-08-14 14:26:28 -0400 | [diff] [blame] | 4203 | |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4204 | /* |
| 4205 | * If there is a thread waiting for command completion |
| 4206 | * wake up the thread. |
| 4207 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4208 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4209 | if (lpfc_cmd->waitq) |
| 4210 | wake_up(lpfc_cmd->waitq); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4211 | spin_unlock_irqrestore(shost->host_lock, flags); |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 4212 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 4213 | return; |
| 4214 | } |
| 4215 | |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4216 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92e3af6 | 2012-08-14 14:26:28 -0400 | [diff] [blame] | 4217 | lpfc_cmd->pCmd = NULL; |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4218 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92e3af6 | 2012-08-14 14:26:28 -0400 | [diff] [blame] | 4219 | |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4220 | /* |
| 4221 | * If there is a thread waiting for command completion |
| 4222 | * wake up the thread. |
| 4223 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4224 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4225 | if (lpfc_cmd->waitq) |
| 4226 | wake_up(lpfc_cmd->waitq); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4227 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4228 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4229 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4230 | } |
| 4231 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4232 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4233 | * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4234 | * @data: A pointer to the immediate command data portion of the IOCB. |
| 4235 | * @fcp_cmnd: The FCP Command that is provided by the SCSI layer. |
| 4236 | * |
| 4237 | * The routine copies the entire FCP command from @fcp_cmnd to @data while |
| 4238 | * byte swapping the data to big endian format for transmission on the wire. |
| 4239 | **/ |
| 4240 | static void |
| 4241 | lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd) |
| 4242 | { |
| 4243 | int i, j; |
| 4244 | for (i = 0, j = 0; i < sizeof(struct fcp_cmnd); |
| 4245 | i += sizeof(uint32_t), j++) { |
| 4246 | ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]); |
| 4247 | } |
| 4248 | } |
| 4249 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4250 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4251 | * 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] | 4252 | * @vport: The virtual port for which this call is being executed. |
| 4253 | * @lpfc_cmd: The scsi command which needs to send. |
| 4254 | * @pnode: Pointer to lpfc_nodelist. |
| 4255 | * |
| 4256 | * This routine initializes fcp_cmnd and iocb data structure from scsi command |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4257 | * to transfer for device with SLI3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4258 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4259 | static void |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4260 | 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] | 4261 | struct lpfc_nodelist *pnode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4262 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4263 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4264 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 4265 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 4266 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 4267 | struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq); |
| 4268 | int datadir = scsi_cmnd->sc_data_direction; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4269 | uint8_t *ptr; |
| 4270 | bool sli4; |
James Smart | 98bbf5f | 2013-09-06 12:18:45 -0400 | [diff] [blame] | 4271 | uint32_t fcpdl; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4272 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4273 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 4274 | return; |
| 4275 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4276 | lpfc_cmd->fcp_rsp->rspSnsLen = 0; |
James.Smart@Emulex.Com | 69859dc | 2005-08-10 15:02:37 -0400 | [diff] [blame] | 4277 | /* clear task management bits */ |
| 4278 | lpfc_cmd->fcp_cmnd->fcpCntl2 = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4279 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 4280 | int_to_scsilun(lpfc_cmd->pCmd->device->lun, |
| 4281 | &lpfc_cmd->fcp_cmnd->fcp_lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4282 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4283 | ptr = &fcp_cmnd->fcpCdb[0]; |
| 4284 | memcpy(ptr, scsi_cmnd->cmnd, scsi_cmnd->cmd_len); |
| 4285 | if (scsi_cmnd->cmd_len < LPFC_FCP_CDB_LEN) { |
| 4286 | ptr += scsi_cmnd->cmd_len; |
| 4287 | memset(ptr, 0, (LPFC_FCP_CDB_LEN - scsi_cmnd->cmd_len)); |
| 4288 | } |
| 4289 | |
Christoph Hellwig | 5066863 | 2014-10-30 14:30:06 +0100 | [diff] [blame] | 4290 | fcp_cmnd->fcpCntl1 = SIMPLE_Q; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4291 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4292 | sli4 = (phba->sli_rev == LPFC_SLI_REV4); |
James Smart | 6acb348 | 2014-04-04 13:51:25 -0400 | [diff] [blame] | 4293 | piocbq->iocb.un.fcpi.fcpi_XRdy = 0; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4294 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4295 | /* |
| 4296 | * There are three possibilities here - use scatter-gather segment, use |
| 4297 | * the single mapping, or neither. Start the lpfc command prep by |
| 4298 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 4299 | * data bde entry. |
| 4300 | */ |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4301 | if (scsi_sg_count(scsi_cmnd)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4302 | if (datadir == DMA_TO_DEVICE) { |
| 4303 | iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR; |
James Smart | 182ba75 | 2013-07-15 18:34:05 -0400 | [diff] [blame] | 4304 | iocb_cmd->ulpPU = PARM_READ_CHECK; |
James Smart | 3cb01c5 | 2013-07-15 18:35:04 -0400 | [diff] [blame] | 4305 | if (vport->cfg_first_burst_size && |
| 4306 | (pnode->nlp_flag & NLP_FIRSTBURST)) { |
James Smart | 98bbf5f | 2013-09-06 12:18:45 -0400 | [diff] [blame] | 4307 | fcpdl = scsi_bufflen(scsi_cmnd); |
| 4308 | if (fcpdl < vport->cfg_first_burst_size) |
| 4309 | piocbq->iocb.un.fcpi.fcpi_XRdy = fcpdl; |
| 4310 | else |
| 4311 | piocbq->iocb.un.fcpi.fcpi_XRdy = |
| 4312 | vport->cfg_first_burst_size; |
James Smart | 3cb01c5 | 2013-07-15 18:35:04 -0400 | [diff] [blame] | 4313 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4314 | fcp_cmnd->fcpCntl3 = WRITE_DATA; |
| 4315 | phba->fc4OutputRequests++; |
| 4316 | } else { |
| 4317 | iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR; |
| 4318 | iocb_cmd->ulpPU = PARM_READ_CHECK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4319 | fcp_cmnd->fcpCntl3 = READ_DATA; |
| 4320 | phba->fc4InputRequests++; |
| 4321 | } |
| 4322 | } else { |
| 4323 | iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR; |
| 4324 | iocb_cmd->un.fcpi.fcpi_parm = 0; |
| 4325 | iocb_cmd->ulpPU = 0; |
| 4326 | fcp_cmnd->fcpCntl3 = 0; |
| 4327 | phba->fc4ControlRequests++; |
| 4328 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4329 | if (phba->sli_rev == 3 && |
| 4330 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4331 | lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4332 | /* |
| 4333 | * Finish initializing those IOCB fields that are independent |
| 4334 | * of the scsi_cmnd request_buffer |
| 4335 | */ |
| 4336 | piocbq->iocb.ulpContext = pnode->nlp_rpi; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4337 | if (sli4) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4338 | piocbq->iocb.ulpContext = |
| 4339 | phba->sli4_hba.rpi_ids[pnode->nlp_rpi]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4340 | if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE) |
| 4341 | piocbq->iocb.ulpFCP2Rcvy = 1; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4342 | else |
| 4343 | piocbq->iocb.ulpFCP2Rcvy = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4344 | |
| 4345 | piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f); |
| 4346 | piocbq->context1 = lpfc_cmd; |
| 4347 | piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; |
| 4348 | piocbq->iocb.ulpTimeout = lpfc_cmd->timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4349 | piocbq->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4350 | } |
| 4351 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4352 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4353 | * 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] | 4354 | * @vport: The virtual port for which this call is being executed. |
| 4355 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. |
| 4356 | * @lun: Logical unit number. |
| 4357 | * @task_mgmt_cmd: SCSI task management command. |
| 4358 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4359 | * This routine creates FCP information unit corresponding to @task_mgmt_cmd |
| 4360 | * for device with SLI-3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4361 | * |
| 4362 | * Return codes: |
| 4363 | * 0 - Error |
| 4364 | * 1 - Success |
| 4365 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4366 | static int |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4367 | lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4368 | struct lpfc_scsi_buf *lpfc_cmd, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4369 | uint64_t lun, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4370 | uint8_t task_mgmt_cmd) |
| 4371 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4372 | struct lpfc_iocbq *piocbq; |
| 4373 | IOCB_t *piocb; |
| 4374 | struct fcp_cmnd *fcp_cmnd; |
James Smart | 0b18ac4 | 2006-05-01 21:50:40 -0400 | [diff] [blame] | 4375 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4376 | struct lpfc_nodelist *ndlp = rdata->pnode; |
| 4377 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4378 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || |
| 4379 | ndlp->nlp_state != NLP_STE_MAPPED_NODE) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4380 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4381 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4382 | piocbq = &(lpfc_cmd->cur_iocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4383 | piocbq->vport = vport; |
| 4384 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4385 | piocb = &piocbq->iocb; |
| 4386 | |
| 4387 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4388 | /* Clear out any old data in the FCP command area */ |
| 4389 | memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd)); |
| 4390 | int_to_scsilun(lun, &fcp_cmnd->fcp_lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4391 | fcp_cmnd->fcpCntl2 = task_mgmt_cmd; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4392 | if (vport->phba->sli_rev == 3 && |
| 4393 | !(vport->phba->sli3_options & LPFC_SLI3_BG_ENABLED)) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4394 | lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4395 | piocb->ulpCommand = CMD_FCP_ICMND64_CR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4396 | piocb->ulpContext = ndlp->nlp_rpi; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4397 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
| 4398 | piocb->ulpContext = |
| 4399 | vport->phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
| 4400 | } |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 4401 | piocb->ulpFCP2Rcvy = (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) ? 1 : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4402 | piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f); |
James Smart | f9226c2 | 2014-02-20 09:57:28 -0500 | [diff] [blame] | 4403 | piocb->ulpPU = 0; |
| 4404 | piocb->un.fcpi.fcpi_parm = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4405 | |
| 4406 | /* ulpTimeout is only one byte */ |
| 4407 | if (lpfc_cmd->timeout > 0xff) { |
| 4408 | /* |
| 4409 | * Do not timeout the command at the firmware level. |
| 4410 | * The driver will provide the timeout mechanism. |
| 4411 | */ |
| 4412 | piocb->ulpTimeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4413 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4414 | piocb->ulpTimeout = lpfc_cmd->timeout; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4415 | |
| 4416 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 4417 | lpfc_sli4_set_rsp_sgl_last(vport->phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4418 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4419 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4420 | } |
| 4421 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4422 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4423 | * lpfc_scsi_api_table_setup - Set up scsi api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4424 | * @phba: The hba struct for which this call is being executed. |
| 4425 | * @dev_grp: The HBA PCI-Device group number. |
| 4426 | * |
| 4427 | * This routine sets up the SCSI interface API function jump table in @phba |
| 4428 | * struct. |
| 4429 | * Returns: 0 - success, -ENODEV - failure. |
| 4430 | **/ |
| 4431 | int |
| 4432 | lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 4433 | { |
| 4434 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4435 | phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf; |
| 4436 | phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4437 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4438 | switch (dev_grp) { |
| 4439 | case LPFC_PCI_DEV_LP: |
| 4440 | phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s3; |
| 4441 | phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4442 | 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] | 4443 | phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4444 | phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s3; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4445 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4446 | case LPFC_PCI_DEV_OC: |
| 4447 | phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s4; |
| 4448 | phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s4; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4449 | 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] | 4450 | phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s4; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4451 | phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s4; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4452 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4453 | default: |
| 4454 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4455 | "1418 Invalid HBA PCI-device group: 0x%x\n", |
| 4456 | dev_grp); |
| 4457 | return -ENODEV; |
| 4458 | break; |
| 4459 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4460 | phba->lpfc_rampdown_queue_depth = lpfc_rampdown_queue_depth; |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 4461 | phba->lpfc_scsi_cmd_iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4462 | return 0; |
| 4463 | } |
| 4464 | |
| 4465 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4466 | * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4467 | * @phba: The Hba for which this call is being executed. |
| 4468 | * @cmdiocbq: Pointer to lpfc_iocbq data structure. |
| 4469 | * @rspiocbq: Pointer to lpfc_iocbq data structure. |
| 4470 | * |
| 4471 | * This routine is IOCB completion routine for device reset and target reset |
| 4472 | * routine. This routine release scsi buffer associated with lpfc_cmd. |
| 4473 | **/ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4474 | static void |
| 4475 | lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba, |
| 4476 | struct lpfc_iocbq *cmdiocbq, |
| 4477 | struct lpfc_iocbq *rspiocbq) |
| 4478 | { |
| 4479 | struct lpfc_scsi_buf *lpfc_cmd = |
| 4480 | (struct lpfc_scsi_buf *) cmdiocbq->context1; |
| 4481 | if (lpfc_cmd) |
| 4482 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 4483 | return; |
| 4484 | } |
| 4485 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4486 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4487 | * lpfc_info - Info entry point of scsi_host_template data structure |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4488 | * @host: The scsi host for which this call is being executed. |
| 4489 | * |
| 4490 | * This routine provides module information about hba. |
| 4491 | * |
| 4492 | * Reutrn code: |
| 4493 | * Pointer to char - Success. |
| 4494 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4495 | const char * |
| 4496 | lpfc_info(struct Scsi_Host *host) |
| 4497 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4498 | struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata; |
| 4499 | struct lpfc_hba *phba = vport->phba; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4500 | int len, link_speed = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4501 | static char lpfcinfobuf[384]; |
| 4502 | |
| 4503 | memset(lpfcinfobuf,0,384); |
| 4504 | if (phba && phba->pcidev){ |
| 4505 | strncpy(lpfcinfobuf, phba->ModelDesc, 256); |
| 4506 | len = strlen(lpfcinfobuf); |
| 4507 | snprintf(lpfcinfobuf + len, |
| 4508 | 384-len, |
| 4509 | " on PCI bus %02x device %02x irq %d", |
| 4510 | phba->pcidev->bus->number, |
| 4511 | phba->pcidev->devfn, |
| 4512 | phba->pcidev->irq); |
| 4513 | len = strlen(lpfcinfobuf); |
| 4514 | if (phba->Port[0]) { |
| 4515 | snprintf(lpfcinfobuf + len, |
| 4516 | 384-len, |
| 4517 | " port %s", |
| 4518 | phba->Port); |
| 4519 | } |
James Smart | 65467b6 | 2010-01-26 23:08:29 -0500 | [diff] [blame] | 4520 | len = strlen(lpfcinfobuf); |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4521 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 4522 | link_speed = lpfc_sli_port_speed_get(phba); |
| 4523 | } else { |
| 4524 | if (phba->sli4_hba.link_state.logical_speed) |
| 4525 | link_speed = |
| 4526 | phba->sli4_hba.link_state.logical_speed; |
| 4527 | else |
| 4528 | link_speed = phba->sli4_hba.link_state.speed; |
James Smart | 65467b6 | 2010-01-26 23:08:29 -0500 | [diff] [blame] | 4529 | } |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4530 | if (link_speed != 0) |
| 4531 | snprintf(lpfcinfobuf + len, 384-len, |
| 4532 | " Logical Link Speed: %d Mbps", link_speed); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4533 | } |
| 4534 | return lpfcinfobuf; |
| 4535 | } |
| 4536 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4537 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4538 | * lpfc_poll_rearm_time - Routine to modify fcp_poll timer of hba |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4539 | * @phba: The Hba for which this call is being executed. |
| 4540 | * |
| 4541 | * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo. |
| 4542 | * The default value of cfg_poll_tmo is 10 milliseconds. |
| 4543 | **/ |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4544 | static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba) |
| 4545 | { |
| 4546 | unsigned long poll_tmo_expires = |
| 4547 | (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo)); |
| 4548 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 4549 | if (!list_empty(&phba->sli.ring[LPFC_FCP_RING].txcmplq)) |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4550 | mod_timer(&phba->fcp_poll_timer, |
| 4551 | poll_tmo_expires); |
| 4552 | } |
| 4553 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4554 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4555 | * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4556 | * @phba: The Hba for which this call is being executed. |
| 4557 | * |
| 4558 | * This routine starts the fcp_poll_timer of @phba. |
| 4559 | **/ |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4560 | void lpfc_poll_start_timer(struct lpfc_hba * phba) |
| 4561 | { |
| 4562 | lpfc_poll_rearm_timer(phba); |
| 4563 | } |
| 4564 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4565 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4566 | * lpfc_poll_timeout - Restart polling timer |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4567 | * @ptr: Map to lpfc_hba data structure pointer. |
| 4568 | * |
| 4569 | * This routine restarts fcp_poll timer, when FCP ring polling is enable |
| 4570 | * and FCP Ring interrupt is disable. |
| 4571 | **/ |
| 4572 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4573 | void lpfc_poll_timeout(unsigned long ptr) |
| 4574 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4575 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4576 | |
| 4577 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4578 | lpfc_sli_handle_fast_ring_event(phba, |
| 4579 | &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ); |
| 4580 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4581 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 4582 | lpfc_poll_rearm_timer(phba); |
| 4583 | } |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4584 | } |
| 4585 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4586 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4587 | * lpfc_queuecommand - scsi_host_template queuecommand entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4588 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 4589 | * @done: Pointer to done routine. |
| 4590 | * |
| 4591 | * Driver registers this routine to scsi midlayer to submit a @cmd to process. |
| 4592 | * This routine prepares an IOCB from scsi command and provides to firmware. |
| 4593 | * The @done callback is invoked after driver finished processing the command. |
| 4594 | * |
| 4595 | * Return value : |
| 4596 | * 0 - Success |
| 4597 | * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily. |
| 4598 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4599 | static int |
James Smart | b9a7c63 | 2012-08-03 12:35:24 -0400 | [diff] [blame] | 4600 | lpfc_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4601 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4602 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4603 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 4604 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 4605 | struct lpfc_nodelist *ndlp; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4606 | struct lpfc_scsi_buf *lpfc_cmd; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4607 | 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] | 4608 | int err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4609 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 4610 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4611 | err = fc_remote_port_chkready(rport); |
| 4612 | if (err) { |
| 4613 | cmnd->result = err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4614 | goto out_fail_command; |
| 4615 | } |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 4616 | ndlp = rdata->pnode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4617 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 4618 | if ((scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) && |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4619 | (!(phba->sli3_options & LPFC_SLI3_BG_ENABLED))) { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4620 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4621 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 4622 | "9058 BLKGRD: ERROR: rcvd protected cmd:%02x" |
| 4623 | " op:%02x str=%s without registering for" |
| 4624 | " BlockGuard - Rejecting command\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4625 | cmnd->cmnd[0], scsi_get_prot_op(cmnd), |
| 4626 | dif_op_str[scsi_get_prot_op(cmnd)]); |
| 4627 | goto out_fail_command; |
| 4628 | } |
| 4629 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4630 | /* |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4631 | * Catch race where our node has transitioned, but the |
| 4632 | * transport is still transitioning. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4633 | */ |
James Smart | 6b415f5 | 2012-06-12 13:54:59 -0400 | [diff] [blame] | 4634 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 4635 | goto out_tgt_busy; |
James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 4636 | if (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth) |
Mike Christie | 3496343 | 2011-02-25 14:04:28 -0600 | [diff] [blame] | 4637 | goto out_tgt_busy; |
Mike Christie | a93ce02 | 2008-08-17 15:24:41 -0500 | [diff] [blame] | 4638 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4639 | lpfc_cmd = lpfc_get_scsi_buf(phba, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4640 | if (lpfc_cmd == NULL) { |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4641 | lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4642 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4643 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4644 | "0707 driver's buffer pool is empty, " |
| 4645 | "IO busied\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4646 | goto out_host_busy; |
| 4647 | } |
| 4648 | |
| 4649 | /* |
| 4650 | * Store the midlayer's command structure for the completion phase |
| 4651 | * and complete the command initialization. |
| 4652 | */ |
| 4653 | lpfc_cmd->pCmd = cmnd; |
| 4654 | lpfc_cmd->rdata = rdata; |
| 4655 | lpfc_cmd->timeout = 0; |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4656 | lpfc_cmd->start_time = jiffies; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4657 | cmnd->host_scribble = (unsigned char *)lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4658 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4659 | if (scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4660 | if (vport->phba->cfg_enable_bg) { |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 4661 | lpfc_printf_vlog(vport, |
| 4662 | KERN_INFO, LOG_SCSI_CMD, |
James Smart | 2613470 | 2012-08-14 14:25:50 -0400 | [diff] [blame] | 4663 | "9033 BLKGRD: rcvd %s cmd:x%x " |
| 4664 | "sector x%llx cnt %u pt %x\n", |
| 4665 | dif_op_str[scsi_get_prot_op(cmnd)], |
| 4666 | cmnd->cmnd[0], |
| 4667 | (unsigned long long)scsi_get_lba(cmnd), |
| 4668 | blk_rq_sectors(cmnd->request), |
| 4669 | (cmnd->cmnd[1]>>5)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4670 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4671 | err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 4672 | } else { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4673 | if (vport->phba->cfg_enable_bg) { |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 4674 | lpfc_printf_vlog(vport, |
| 4675 | KERN_INFO, LOG_SCSI_CMD, |
James Smart | 2613470 | 2012-08-14 14:25:50 -0400 | [diff] [blame] | 4676 | "9038 BLKGRD: rcvd PROT_NORMAL cmd: " |
| 4677 | "x%x sector x%llx cnt %u pt %x\n", |
| 4678 | cmnd->cmnd[0], |
| 4679 | (unsigned long long)scsi_get_lba(cmnd), |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 4680 | blk_rq_sectors(cmnd->request), |
James Smart | 2613470 | 2012-08-14 14:25:50 -0400 | [diff] [blame] | 4681 | (cmnd->cmnd[1]>>5)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4682 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4683 | err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 4684 | } |
| 4685 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4686 | if (err) |
| 4687 | goto out_host_busy_free_buf; |
| 4688 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4689 | lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4690 | |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4691 | atomic_inc(&ndlp->cmd_pending); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4692 | err = lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4693 | &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4694 | if (err) { |
| 4695 | atomic_dec(&ndlp->cmd_pending); |
James Smart | 76f96b6 | 2013-12-17 20:29:01 -0500 | [diff] [blame] | 4696 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4697 | "3376 FCP could not issue IOCB err %x" |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4698 | "FCP cmd x%x <%d/%llu> " |
James Smart | 76f96b6 | 2013-12-17 20:29:01 -0500 | [diff] [blame] | 4699 | "sid: x%x did: x%x oxid: x%x " |
| 4700 | "Data: x%x x%x x%x x%x\n", |
| 4701 | err, cmnd->cmnd[0], |
| 4702 | cmnd->device ? cmnd->device->id : 0xffff, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4703 | cmnd->device ? cmnd->device->lun : (u64) -1, |
James Smart | 76f96b6 | 2013-12-17 20:29:01 -0500 | [diff] [blame] | 4704 | vport->fc_myDID, ndlp->nlp_DID, |
| 4705 | phba->sli_rev == LPFC_SLI_REV4 ? |
| 4706 | lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff, |
| 4707 | lpfc_cmd->cur_iocbq.iocb.ulpContext, |
| 4708 | lpfc_cmd->cur_iocbq.iocb.ulpIoTag, |
| 4709 | lpfc_cmd->cur_iocbq.iocb.ulpTimeout, |
| 4710 | (uint32_t) |
| 4711 | (cmnd->request->timeout / 1000)); |
| 4712 | |
| 4713 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4714 | goto out_host_busy_free_buf; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4715 | } |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4716 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4717 | lpfc_sli_handle_fast_ring_event(phba, |
| 4718 | &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ); |
| 4719 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4720 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 4721 | lpfc_poll_rearm_timer(phba); |
| 4722 | } |
| 4723 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4724 | return 0; |
| 4725 | |
| 4726 | out_host_busy_free_buf: |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 4727 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4728 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4729 | out_host_busy: |
| 4730 | return SCSI_MLQUEUE_HOST_BUSY; |
| 4731 | |
Mike Christie | 3496343 | 2011-02-25 14:04:28 -0600 | [diff] [blame] | 4732 | out_tgt_busy: |
| 4733 | return SCSI_MLQUEUE_TARGET_BUSY; |
| 4734 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4735 | out_fail_command: |
James Smart | b9a7c63 | 2012-08-03 12:35:24 -0400 | [diff] [blame] | 4736 | cmnd->scsi_done(cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4737 | return 0; |
| 4738 | } |
| 4739 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 4740 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4741 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4742 | * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4743 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 4744 | * |
| 4745 | * This routine aborts @cmnd pending in base driver. |
| 4746 | * |
| 4747 | * Return code : |
| 4748 | * 0x2003 - Error |
| 4749 | * 0x2002 - Success |
| 4750 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4751 | static int |
James.Smart@Emulex.Com | 63c59c3 | 2005-11-28 11:41:53 -0500 | [diff] [blame] | 4752 | lpfc_abort_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4753 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4754 | struct Scsi_Host *shost = cmnd->device->host; |
| 4755 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4756 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4757 | struct lpfc_iocbq *iocb; |
| 4758 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4759 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4760 | IOCB_t *cmd, *icmd; |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4761 | int ret = SUCCESS, status = 0; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4762 | struct lpfc_sli_ring *pring_s4; |
| 4763 | int ring_number, ret_val; |
| 4764 | unsigned long flags, iflags; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4765 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4766 | |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4767 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 4768 | if (status != 0 && status != SUCCESS) |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4769 | return status; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4770 | |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4771 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4772 | /* driver queued commands are in process of being flushed */ |
| 4773 | if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) { |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4774 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4775 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4776 | "3168 SCSI Layer abort requested I/O has been " |
| 4777 | "flushed by LLD.\n"); |
| 4778 | return FAILED; |
| 4779 | } |
| 4780 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4781 | lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble; |
James Smart | 92e3af6 | 2012-08-14 14:26:28 -0400 | [diff] [blame] | 4782 | if (!lpfc_cmd || !lpfc_cmd->pCmd) { |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4783 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 4784 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4785 | "2873 SCSI Layer I/O Abort Request IO CMPL Status " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4786 | "x%x ID %d LUN %llu\n", |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4787 | SUCCESS, cmnd->device->id, cmnd->device->lun); |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 4788 | return SUCCESS; |
| 4789 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4790 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4791 | iocb = &lpfc_cmd->cur_iocbq; |
| 4792 | /* the command is in process of being cancelled */ |
| 4793 | if (!(iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ)) { |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4794 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4795 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4796 | "3169 SCSI Layer abort requested I/O has been " |
| 4797 | "cancelled by LLD.\n"); |
| 4798 | return FAILED; |
| 4799 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4800 | /* |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4801 | * If pCmd field of the corresponding lpfc_scsi_buf structure |
| 4802 | * points to a different SCSI command, then the driver has |
| 4803 | * already completed this command, but the midlayer did not |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4804 | * see the completion before the eh fired. Just return SUCCESS. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4805 | */ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4806 | if (lpfc_cmd->pCmd != cmnd) { |
| 4807 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4808 | "3170 SCSI Layer abort requested I/O has been " |
| 4809 | "completed by LLD.\n"); |
| 4810 | goto out_unlock; |
| 4811 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4812 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4813 | BUG_ON(iocb->context1 != lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4814 | |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4815 | /* abort issued in recovery is still in progress */ |
| 4816 | if (iocb->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 4817 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4818 | "3389 SCSI Layer I/O Abort Request is pending\n"); |
| 4819 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4820 | goto wait_for_cmpl; |
| 4821 | } |
| 4822 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4823 | abtsiocb = __lpfc_sli_get_iocbq(phba); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4824 | if (abtsiocb == NULL) { |
| 4825 | ret = FAILED; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4826 | goto out_unlock; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4827 | } |
| 4828 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 4829 | /* Indicate the IO is being aborted by the driver. */ |
| 4830 | iocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 4831 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4832 | /* |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4833 | * The scsi command can not be in txq and it is in flight because the |
| 4834 | * pCmd is still pointig at the SCSI command we have to abort. There |
| 4835 | * is no need to search the txcmplq. Just send an abort to the FW. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4836 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4837 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4838 | cmd = &iocb->iocb; |
| 4839 | icmd = &abtsiocb->iocb; |
| 4840 | icmd->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 4841 | icmd->un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4842 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4843 | icmd->un.acxri.abortIoTag = iocb->sli4_xritag; |
| 4844 | else |
| 4845 | icmd->un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4846 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4847 | icmd->ulpLe = 1; |
| 4848 | icmd->ulpClass = cmd->ulpClass; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4849 | |
| 4850 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 4851 | abtsiocb->fcp_wqidx = iocb->fcp_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 4852 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 4853 | if (iocb->iocb_flag & LPFC_IO_FOF) |
| 4854 | abtsiocb->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4855 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4856 | if (lpfc_is_link_up(phba)) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4857 | icmd->ulpCommand = CMD_ABORT_XRI_CN; |
| 4858 | else |
| 4859 | icmd->ulpCommand = CMD_CLOSE_XRI_CN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4860 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4861 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4862 | abtsiocb->vport = vport; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4863 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 4864 | ring_number = MAX_SLI3_CONFIGURED_RINGS + iocb->fcp_wqidx; |
| 4865 | pring_s4 = &phba->sli.ring[ring_number]; |
| 4866 | /* Note: both hbalock and ring_lock must be set here */ |
| 4867 | spin_lock_irqsave(&pring_s4->ring_lock, iflags); |
| 4868 | ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 4869 | abtsiocb, 0); |
| 4870 | spin_unlock_irqrestore(&pring_s4->ring_lock, iflags); |
| 4871 | } else { |
| 4872 | ret_val = __lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, |
| 4873 | abtsiocb, 0); |
| 4874 | } |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4875 | /* no longer need the lock after this point */ |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4876 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4877 | |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4878 | |
| 4879 | if (ret_val == IOCB_ERROR) { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4880 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| 4881 | ret = FAILED; |
| 4882 | goto out; |
| 4883 | } |
| 4884 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4885 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4886 | lpfc_sli_handle_fast_ring_event(phba, |
| 4887 | &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4888 | |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4889 | wait_for_cmpl: |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4890 | lpfc_cmd->waitq = &waitq; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4891 | /* Wait for abort to complete */ |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4892 | wait_event_timeout(waitq, |
| 4893 | (lpfc_cmd->pCmd != cmnd), |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4894 | msecs_to_jiffies(2*vport->cfg_devloss_tmo*1000)); |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4895 | |
| 4896 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4897 | lpfc_cmd->waitq = NULL; |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4898 | spin_unlock_irqrestore(shost->host_lock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4899 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4900 | if (lpfc_cmd->pCmd == cmnd) { |
| 4901 | ret = FAILED; |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4902 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 4903 | "0748 abort handler timed out waiting " |
James Smart | 247ca94 | 2012-08-14 14:26:13 -0400 | [diff] [blame] | 4904 | "for abortng I/O (xri:x%x) to complete: " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4905 | "ret %#x, ID %d, LUN %llu\n", |
James Smart | 247ca94 | 2012-08-14 14:26:13 -0400 | [diff] [blame] | 4906 | iocb->sli4_xritag, ret, |
| 4907 | cmnd->device->id, cmnd->device->lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4908 | } |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4909 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4910 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4911 | out_unlock: |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4912 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4913 | out: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4914 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4915 | "0749 SCSI Layer I/O Abort Request Status x%x ID %d " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4916 | "LUN %llu\n", ret, cmnd->device->id, |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 4917 | cmnd->device->lun); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4918 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4919 | } |
| 4920 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4921 | static char * |
| 4922 | lpfc_taskmgmt_name(uint8_t task_mgmt_cmd) |
| 4923 | { |
| 4924 | switch (task_mgmt_cmd) { |
| 4925 | case FCP_ABORT_TASK_SET: |
| 4926 | return "ABORT_TASK_SET"; |
| 4927 | case FCP_CLEAR_TASK_SET: |
| 4928 | return "FCP_CLEAR_TASK_SET"; |
| 4929 | case FCP_BUS_RESET: |
| 4930 | return "FCP_BUS_RESET"; |
| 4931 | case FCP_LUN_RESET: |
| 4932 | return "FCP_LUN_RESET"; |
| 4933 | case FCP_TARGET_RESET: |
| 4934 | return "FCP_TARGET_RESET"; |
| 4935 | case FCP_CLEAR_ACA: |
| 4936 | return "FCP_CLEAR_ACA"; |
| 4937 | case FCP_TERMINATE_TASK: |
| 4938 | return "FCP_TERMINATE_TASK"; |
| 4939 | default: |
| 4940 | return "unknown"; |
| 4941 | } |
| 4942 | } |
| 4943 | |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 4944 | |
| 4945 | /** |
| 4946 | * lpfc_check_fcp_rsp - check the returned fcp_rsp to see if task failed |
| 4947 | * @vport: The virtual port for which this call is being executed. |
| 4948 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. |
| 4949 | * |
| 4950 | * This routine checks the FCP RSP INFO to see if the tsk mgmt command succeded |
| 4951 | * |
| 4952 | * Return code : |
| 4953 | * 0x2003 - Error |
| 4954 | * 0x2002 - Success |
| 4955 | **/ |
| 4956 | static int |
| 4957 | lpfc_check_fcp_rsp(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd) |
| 4958 | { |
| 4959 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
| 4960 | uint32_t rsp_info; |
| 4961 | uint32_t rsp_len; |
| 4962 | uint8_t rsp_info_code; |
| 4963 | int ret = FAILED; |
| 4964 | |
| 4965 | |
| 4966 | if (fcprsp == NULL) |
| 4967 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4968 | "0703 fcp_rsp is missing\n"); |
| 4969 | else { |
| 4970 | rsp_info = fcprsp->rspStatus2; |
| 4971 | rsp_len = be32_to_cpu(fcprsp->rspRspLen); |
| 4972 | rsp_info_code = fcprsp->rspInfo3; |
| 4973 | |
| 4974 | |
| 4975 | lpfc_printf_vlog(vport, KERN_INFO, |
| 4976 | LOG_FCP, |
| 4977 | "0706 fcp_rsp valid 0x%x," |
| 4978 | " rsp len=%d code 0x%x\n", |
| 4979 | rsp_info, |
| 4980 | rsp_len, rsp_info_code); |
| 4981 | |
| 4982 | if ((fcprsp->rspStatus2&RSP_LEN_VALID) && (rsp_len == 8)) { |
| 4983 | switch (rsp_info_code) { |
| 4984 | case RSP_NO_FAILURE: |
| 4985 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4986 | "0715 Task Mgmt No Failure\n"); |
| 4987 | ret = SUCCESS; |
| 4988 | break; |
| 4989 | case RSP_TM_NOT_SUPPORTED: /* TM rejected */ |
| 4990 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4991 | "0716 Task Mgmt Target " |
| 4992 | "reject\n"); |
| 4993 | break; |
| 4994 | case RSP_TM_NOT_COMPLETED: /* TM failed */ |
| 4995 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4996 | "0717 Task Mgmt Target " |
| 4997 | "failed TM\n"); |
| 4998 | break; |
| 4999 | case RSP_TM_INVALID_LU: /* TM to invalid LU! */ |
| 5000 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 5001 | "0718 Task Mgmt to invalid " |
| 5002 | "LUN\n"); |
| 5003 | break; |
| 5004 | } |
| 5005 | } |
| 5006 | } |
| 5007 | return ret; |
| 5008 | } |
| 5009 | |
| 5010 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5011 | /** |
| 5012 | * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler |
| 5013 | * @vport: The virtual port for which this call is being executed. |
| 5014 | * @rdata: Pointer to remote port local data |
| 5015 | * @tgt_id: Target ID of remote device. |
| 5016 | * @lun_id: Lun number for the TMF |
| 5017 | * @task_mgmt_cmd: type of TMF to send |
| 5018 | * |
| 5019 | * This routine builds and sends a TMF (SCSI Task Mgmt Function) to |
| 5020 | * a remote port. |
| 5021 | * |
| 5022 | * Return Code: |
| 5023 | * 0x2003 - Error |
| 5024 | * 0x2002 - Success. |
| 5025 | **/ |
| 5026 | static int |
| 5027 | lpfc_send_taskmgmt(struct lpfc_vport *vport, struct lpfc_rport_data *rdata, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5028 | unsigned tgt_id, uint64_t lun_id, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5029 | uint8_t task_mgmt_cmd) |
| 5030 | { |
| 5031 | struct lpfc_hba *phba = vport->phba; |
| 5032 | struct lpfc_scsi_buf *lpfc_cmd; |
| 5033 | struct lpfc_iocbq *iocbq; |
| 5034 | struct lpfc_iocbq *iocbqrsp; |
James Smart | 5989b8d | 2010-10-22 11:06:56 -0400 | [diff] [blame] | 5035 | struct lpfc_nodelist *pnode = rdata->pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5036 | int ret; |
| 5037 | int status; |
| 5038 | |
James Smart | 5989b8d | 2010-10-22 11:06:56 -0400 | [diff] [blame] | 5039 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5040 | return FAILED; |
| 5041 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5042 | lpfc_cmd = lpfc_get_scsi_buf(phba, rdata->pnode); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5043 | if (lpfc_cmd == NULL) |
| 5044 | return FAILED; |
James Smart | 0c41122 | 2013-09-06 12:22:46 -0400 | [diff] [blame] | 5045 | lpfc_cmd->timeout = phba->cfg_task_mgmt_tmo; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5046 | lpfc_cmd->rdata = rdata; |
| 5047 | |
| 5048 | status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun_id, |
| 5049 | task_mgmt_cmd); |
| 5050 | if (!status) { |
| 5051 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 5052 | return FAILED; |
| 5053 | } |
| 5054 | |
| 5055 | iocbq = &lpfc_cmd->cur_iocbq; |
| 5056 | iocbqrsp = lpfc_sli_get_iocbq(phba); |
| 5057 | if (iocbqrsp == NULL) { |
| 5058 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 5059 | return FAILED; |
| 5060 | } |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 5061 | iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5062 | |
| 5063 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5064 | "0702 Issue %s to TGT %d LUN %llu " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5065 | "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] | 5066 | lpfc_taskmgmt_name(task_mgmt_cmd), tgt_id, lun_id, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5067 | pnode->nlp_rpi, pnode->nlp_flag, iocbq->sli4_xritag, |
| 5068 | iocbq->iocb_flag); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5069 | |
| 5070 | status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING, |
| 5071 | iocbq, iocbqrsp, lpfc_cmd->timeout); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5072 | if ((status != IOCB_SUCCESS) || |
| 5073 | (iocbqrsp->iocb.ulpStatus != IOSTAT_SUCCESS)) { |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5074 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5075 | "0727 TMF %s to TGT %d LUN %llu failed (%d, %d) " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5076 | "iocb_flag x%x\n", |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5077 | lpfc_taskmgmt_name(task_mgmt_cmd), |
| 5078 | tgt_id, lun_id, iocbqrsp->iocb.ulpStatus, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5079 | iocbqrsp->iocb.un.ulpWord[4], |
| 5080 | iocbq->iocb_flag); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5081 | /* if ulpStatus != IOCB_SUCCESS, then status == IOCB_SUCCESS */ |
| 5082 | if (status == IOCB_SUCCESS) { |
| 5083 | if (iocbqrsp->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 5084 | /* Something in the FCP_RSP was invalid. |
| 5085 | * Check conditions */ |
| 5086 | ret = lpfc_check_fcp_rsp(vport, lpfc_cmd); |
| 5087 | else |
| 5088 | ret = FAILED; |
| 5089 | } else if (status == IOCB_TIMEDOUT) { |
| 5090 | ret = TIMEOUT_ERROR; |
| 5091 | } else { |
| 5092 | ret = FAILED; |
| 5093 | } |
| 5094 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; |
| 5095 | } else |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5096 | ret = SUCCESS; |
| 5097 | |
| 5098 | lpfc_sli_release_iocbq(phba, iocbqrsp); |
| 5099 | |
| 5100 | if (ret != TIMEOUT_ERROR) |
| 5101 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 5102 | |
| 5103 | return ret; |
| 5104 | } |
| 5105 | |
| 5106 | /** |
| 5107 | * lpfc_chk_tgt_mapped - |
| 5108 | * @vport: The virtual port to check on |
| 5109 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5110 | * |
| 5111 | * This routine delays until the scsi target (aka rport) for the |
| 5112 | * command exists (is present and logged in) or we declare it non-existent. |
| 5113 | * |
| 5114 | * Return code : |
| 5115 | * 0x2003 - Error |
| 5116 | * 0x2002 - Success |
| 5117 | **/ |
| 5118 | static int |
| 5119 | lpfc_chk_tgt_mapped(struct lpfc_vport *vport, struct scsi_cmnd *cmnd) |
| 5120 | { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5121 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5122 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5123 | unsigned long later; |
| 5124 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5125 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5126 | if (!rdata) { |
| 5127 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 5128 | "0797 Tgt Map rport failure: rdata x%p\n", rdata); |
| 5129 | return FAILED; |
| 5130 | } |
| 5131 | pnode = rdata->pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5132 | /* |
| 5133 | * If target is not in a MAPPED state, delay until |
| 5134 | * target is rediscovered or devloss timeout expires. |
| 5135 | */ |
| 5136 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; |
| 5137 | while (time_after(later, jiffies)) { |
| 5138 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 5139 | return FAILED; |
| 5140 | if (pnode->nlp_state == NLP_STE_MAPPED_NODE) |
| 5141 | return SUCCESS; |
| 5142 | schedule_timeout_uninterruptible(msecs_to_jiffies(500)); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5143 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5144 | if (!rdata) |
| 5145 | return FAILED; |
| 5146 | pnode = rdata->pnode; |
| 5147 | } |
| 5148 | if (!pnode || !NLP_CHK_NODE_ACT(pnode) || |
| 5149 | (pnode->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5150 | return FAILED; |
| 5151 | return SUCCESS; |
| 5152 | } |
| 5153 | |
| 5154 | /** |
| 5155 | * lpfc_reset_flush_io_context - |
| 5156 | * @vport: The virtual port (scsi_host) for the flush context |
| 5157 | * @tgt_id: If aborting by Target contect - specifies the target id |
| 5158 | * @lun_id: If aborting by Lun context - specifies the lun id |
| 5159 | * @context: specifies the context level to flush at. |
| 5160 | * |
| 5161 | * After a reset condition via TMF, we need to flush orphaned i/o |
| 5162 | * contexts from the adapter. This routine aborts any contexts |
| 5163 | * outstanding, then waits for their completions. The wait is |
| 5164 | * bounded by devloss_tmo though. |
| 5165 | * |
| 5166 | * Return code : |
| 5167 | * 0x2003 - Error |
| 5168 | * 0x2002 - Success |
| 5169 | **/ |
| 5170 | static int |
| 5171 | lpfc_reset_flush_io_context(struct lpfc_vport *vport, uint16_t tgt_id, |
| 5172 | uint64_t lun_id, lpfc_ctx_cmd context) |
| 5173 | { |
| 5174 | struct lpfc_hba *phba = vport->phba; |
| 5175 | unsigned long later; |
| 5176 | int cnt; |
| 5177 | |
| 5178 | cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context); |
| 5179 | if (cnt) |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 5180 | lpfc_sli_abort_taskmgmt(vport, |
| 5181 | &phba->sli.ring[phba->sli.fcp_ring], |
| 5182 | tgt_id, lun_id, context); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5183 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; |
| 5184 | while (time_after(later, jiffies) && cnt) { |
| 5185 | schedule_timeout_uninterruptible(msecs_to_jiffies(20)); |
| 5186 | cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context); |
| 5187 | } |
| 5188 | if (cnt) { |
| 5189 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5190 | "0724 I/O flush failure for context %s : cnt x%x\n", |
| 5191 | ((context == LPFC_CTX_LUN) ? "LUN" : |
| 5192 | ((context == LPFC_CTX_TGT) ? "TGT" : |
| 5193 | ((context == LPFC_CTX_HOST) ? "HOST" : "Unknown"))), |
| 5194 | cnt); |
| 5195 | return FAILED; |
| 5196 | } |
| 5197 | return SUCCESS; |
| 5198 | } |
| 5199 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5200 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5201 | * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5202 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5203 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5204 | * 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] | 5205 | * command. |
| 5206 | * |
| 5207 | * Return code : |
| 5208 | * 0x2003 - Error |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5209 | * 0x2002 - Success |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5210 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5211 | static int |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5212 | lpfc_device_reset_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5213 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5214 | struct Scsi_Host *shost = cmnd->device->host; |
| 5215 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5216 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5217 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5218 | unsigned tgt_id = cmnd->device->id; |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5219 | uint64_t lun_id = cmnd->device->lun; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5220 | struct lpfc_scsi_event_header scsi_event; |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5221 | int status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5222 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5223 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5224 | if (!rdata) { |
| 5225 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5226 | "0798 Device Reset rport failure: rdata x%p\n", rdata); |
| 5227 | return FAILED; |
| 5228 | } |
| 5229 | pnode = rdata->pnode; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5230 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 5231 | if (status != 0 && status != SUCCESS) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5232 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5233 | |
| 5234 | status = lpfc_chk_tgt_mapped(vport, cmnd); |
| 5235 | if (status == FAILED) { |
| 5236 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5237 | "0721 Device Reset rport failure: rdata x%p\n", rdata); |
| 5238 | return FAILED; |
| 5239 | } |
| 5240 | |
| 5241 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 5242 | scsi_event.subcategory = LPFC_EVENT_LUNRESET; |
| 5243 | scsi_event.lun = lun_id; |
| 5244 | memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 5245 | memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 5246 | |
| 5247 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5248 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
| 5249 | |
| 5250 | status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id, |
| 5251 | FCP_LUN_RESET); |
| 5252 | |
| 5253 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5254 | "0713 SCSI layer issued Device Reset (%d, %llu) " |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5255 | "return x%x\n", tgt_id, lun_id, status); |
| 5256 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5257 | /* |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5258 | * We have to clean up i/o as : they may be orphaned by the TMF; |
| 5259 | * or if the TMF failed, they may be in an indeterminate state. |
| 5260 | * So, continue on. |
| 5261 | * We will report success if all the i/o aborts successfully. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5262 | */ |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5263 | if (status == SUCCESS) |
| 5264 | status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5265 | LPFC_CTX_LUN); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5266 | |
| 5267 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5268 | } |
| 5269 | |
| 5270 | /** |
| 5271 | * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point |
| 5272 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5273 | * |
| 5274 | * This routine does a target reset by sending a TARGET_RESET task management |
| 5275 | * command. |
| 5276 | * |
| 5277 | * Return code : |
| 5278 | * 0x2003 - Error |
| 5279 | * 0x2002 - Success |
| 5280 | **/ |
| 5281 | static int |
| 5282 | lpfc_target_reset_handler(struct scsi_cmnd *cmnd) |
| 5283 | { |
| 5284 | struct Scsi_Host *shost = cmnd->device->host; |
| 5285 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5286 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5287 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5288 | unsigned tgt_id = cmnd->device->id; |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5289 | uint64_t lun_id = cmnd->device->lun; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5290 | struct lpfc_scsi_event_header scsi_event; |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5291 | int status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5292 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5293 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5294 | if (!rdata) { |
| 5295 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5296 | "0799 Target Reset rport failure: rdata x%p\n", rdata); |
| 5297 | return FAILED; |
| 5298 | } |
| 5299 | pnode = rdata->pnode; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5300 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 5301 | if (status != 0 && status != SUCCESS) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5302 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5303 | |
| 5304 | status = lpfc_chk_tgt_mapped(vport, cmnd); |
| 5305 | if (status == FAILED) { |
| 5306 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5307 | "0722 Target Reset rport failure: rdata x%p\n", rdata); |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 5308 | spin_lock_irq(shost->host_lock); |
| 5309 | pnode->nlp_flag &= ~NLP_NPR_ADISC; |
| 5310 | pnode->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; |
| 5311 | spin_unlock_irq(shost->host_lock); |
| 5312 | lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
| 5313 | LPFC_CTX_TGT); |
| 5314 | return FAST_IO_FAIL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5315 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5316 | |
| 5317 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 5318 | scsi_event.subcategory = LPFC_EVENT_TGTRESET; |
| 5319 | scsi_event.lun = 0; |
| 5320 | memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 5321 | memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 5322 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5323 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5324 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5325 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5326 | status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id, |
| 5327 | FCP_TARGET_RESET); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5328 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5329 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5330 | "0723 SCSI layer issued Target Reset (%d, %llu) " |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5331 | "return x%x\n", tgt_id, lun_id, status); |
| 5332 | |
| 5333 | /* |
| 5334 | * We have to clean up i/o as : they may be orphaned by the TMF; |
| 5335 | * or if the TMF failed, they may be in an indeterminate state. |
| 5336 | * So, continue on. |
| 5337 | * We will report success if all the i/o aborts successfully. |
| 5338 | */ |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5339 | if (status == SUCCESS) |
| 5340 | status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 5341 | LPFC_CTX_TGT); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5342 | return status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5343 | } |
| 5344 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5345 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5346 | * 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] | 5347 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5348 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5349 | * This routine does target reset to all targets on @cmnd->device->host. |
| 5350 | * This emulates Parallel SCSI Bus Reset Semantics. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5351 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5352 | * Return code : |
| 5353 | * 0x2003 - Error |
| 5354 | * 0x2002 - Success |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5355 | **/ |
Jeff Garzik | 94d0e7b8 | 2005-05-28 07:55:48 -0400 | [diff] [blame] | 5356 | static int |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5357 | lpfc_bus_reset_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5358 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5359 | struct Scsi_Host *shost = cmnd->device->host; |
| 5360 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5361 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5362 | struct lpfc_scsi_event_header scsi_event; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5363 | int match; |
| 5364 | int ret = SUCCESS, status, i; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5365 | |
| 5366 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 5367 | scsi_event.subcategory = LPFC_EVENT_BUSRESET; |
| 5368 | scsi_event.lun = 0; |
| 5369 | memcpy(scsi_event.wwpn, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 5370 | memcpy(scsi_event.wwnn, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| 5371 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5372 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5373 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5374 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 5375 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 5376 | if (status != 0 && status != SUCCESS) |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 5377 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5378 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5379 | /* |
| 5380 | * Since the driver manages a single bus device, reset all |
| 5381 | * targets known to the driver. Should any target reset |
| 5382 | * fail, this routine returns failure to the midlayer. |
| 5383 | */ |
James Smart | e17da18 | 2006-07-06 15:49:25 -0400 | [diff] [blame] | 5384 | for (i = 0; i < LPFC_MAX_TARGET; i++) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5385 | /* Search for mapped node by target ID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5386 | match = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5387 | spin_lock_irq(shost->host_lock); |
| 5388 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5389 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5390 | continue; |
James Smart | a6571c6 | 2012-10-31 14:44:42 -0400 | [diff] [blame] | 5391 | if (vport->phba->cfg_fcp2_no_tgt_reset && |
| 5392 | (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE)) |
| 5393 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5394 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE && |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 5395 | ndlp->nlp_sid == i && |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5396 | ndlp->rport) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5397 | match = 1; |
| 5398 | break; |
| 5399 | } |
| 5400 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5401 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5402 | if (!match) |
| 5403 | continue; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5404 | |
| 5405 | status = lpfc_send_taskmgmt(vport, ndlp->rport->dd_data, |
| 5406 | i, 0, FCP_TARGET_RESET); |
| 5407 | |
| 5408 | if (status != SUCCESS) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5409 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5410 | "0700 Bus Reset on target %d failed\n", |
| 5411 | i); |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 5412 | ret = FAILED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5413 | } |
| 5414 | } |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 5415 | /* |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5416 | * We have to clean up i/o as : they may be orphaned by the TMFs |
| 5417 | * above; or if any of the TMFs failed, they may be in an |
| 5418 | * indeterminate state. |
| 5419 | * 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] | 5420 | */ |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5421 | |
| 5422 | status = lpfc_reset_flush_io_context(vport, 0, 0, LPFC_CTX_HOST); |
| 5423 | if (status != SUCCESS) |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 5424 | ret = FAILED; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5425 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5426 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5427 | "0714 SCSI layer issued Bus Reset Data: x%x\n", ret); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5428 | return ret; |
| 5429 | } |
| 5430 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5431 | /** |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5432 | * lpfc_host_reset_handler - scsi_host_template eh_host_reset_handler entry pt |
| 5433 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5434 | * |
| 5435 | * This routine does host reset to the adaptor port. It brings the HBA |
| 5436 | * offline, performs a board restart, and then brings the board back online. |
| 5437 | * The lpfc_offline calls lpfc_sli_hba_down which will abort and local |
| 5438 | * reject all outstanding SCSI commands to the host and error returned |
| 5439 | * back to SCSI mid-level. As this will be SCSI mid-level's last resort |
| 5440 | * of error handling, it will only return error if resetting of the adapter |
| 5441 | * is not successful; in all other cases, will return success. |
| 5442 | * |
| 5443 | * Return code : |
| 5444 | * 0x2003 - Error |
| 5445 | * 0x2002 - Success |
| 5446 | **/ |
| 5447 | static int |
| 5448 | lpfc_host_reset_handler(struct scsi_cmnd *cmnd) |
| 5449 | { |
| 5450 | struct Scsi_Host *shost = cmnd->device->host; |
| 5451 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 5452 | struct lpfc_hba *phba = vport->phba; |
| 5453 | int rc, ret = SUCCESS; |
| 5454 | |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 5455 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5456 | "3172 SCSI layer issued Host Reset Data:\n"); |
| 5457 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 5458 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5459 | lpfc_offline(phba); |
| 5460 | rc = lpfc_sli_brdrestart(phba); |
| 5461 | if (rc) |
| 5462 | ret = FAILED; |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 5463 | rc = lpfc_online(phba); |
| 5464 | if (rc) |
| 5465 | ret = FAILED; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5466 | lpfc_unblock_mgmt_io(phba); |
| 5467 | |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 5468 | if (ret == FAILED) { |
| 5469 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5470 | "3323 Failed host reset, bring it offline\n"); |
| 5471 | lpfc_sli4_offline_eratt(phba); |
| 5472 | } |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5473 | return ret; |
| 5474 | } |
| 5475 | |
| 5476 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5477 | * lpfc_slave_alloc - scsi_host_template slave_alloc entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5478 | * @sdev: Pointer to scsi_device. |
| 5479 | * |
| 5480 | * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's |
| 5481 | * globally available list of scsi buffers. This routine also makes sure scsi |
| 5482 | * buffer is not allocated more than HBA limit conveyed to midlayer. This list |
| 5483 | * of scsi buffer exists for the lifetime of the driver. |
| 5484 | * |
| 5485 | * Return codes: |
| 5486 | * non-0 - Error |
| 5487 | * 0 - Success |
| 5488 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5489 | static int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5490 | lpfc_slave_alloc(struct scsi_device *sdev) |
| 5491 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5492 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 5493 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 5494 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5495 | uint32_t total = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5496 | uint32_t num_to_alloc = 0; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5497 | int num_allocated = 0; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5498 | uint32_t sdev_cnt; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5499 | struct lpfc_device_data *device_data; |
| 5500 | unsigned long flags; |
| 5501 | struct lpfc_name target_wwpn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5502 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 5503 | if (!rport || fc_remote_port_chkready(rport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5504 | return -ENXIO; |
| 5505 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5506 | if (phba->cfg_fof) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5507 | |
| 5508 | /* |
| 5509 | * Check to see if the device data structure for the lun |
| 5510 | * exists. If not, create one. |
| 5511 | */ |
| 5512 | |
| 5513 | u64_to_wwn(rport->port_name, target_wwpn.u.wwn); |
| 5514 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5515 | device_data = __lpfc_get_device_data(phba, |
| 5516 | &phba->luns, |
| 5517 | &vport->fc_portname, |
| 5518 | &target_wwpn, |
| 5519 | sdev->lun); |
| 5520 | if (!device_data) { |
| 5521 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5522 | device_data = lpfc_create_device_data(phba, |
| 5523 | &vport->fc_portname, |
| 5524 | &target_wwpn, |
| 5525 | sdev->lun, true); |
| 5526 | if (!device_data) |
| 5527 | return -ENOMEM; |
| 5528 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5529 | list_add_tail(&device_data->listentry, &phba->luns); |
| 5530 | } |
| 5531 | device_data->rport_data = rport->dd_data; |
| 5532 | device_data->available = true; |
| 5533 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5534 | sdev->hostdata = device_data; |
| 5535 | } else { |
| 5536 | sdev->hostdata = rport->dd_data; |
| 5537 | } |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5538 | sdev_cnt = atomic_inc_return(&phba->sdev_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5539 | |
| 5540 | /* |
| 5541 | * Populate the cmds_per_lun count scsi_bufs into this host's globally |
| 5542 | * 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] | 5543 | * HBA limit conveyed to the midlayer via the host structure. The |
| 5544 | * formula accounts for the lun_queue_depth + error handlers + 1 |
| 5545 | * extra. This list of scsi bufs exists for the lifetime of the driver. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5546 | */ |
| 5547 | total = phba->total_scsi_bufs; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5548 | num_to_alloc = vport->cfg_lun_queue_depth + 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5549 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5550 | /* If allocated buffers are enough do nothing */ |
| 5551 | if ((sdev_cnt * (vport->cfg_lun_queue_depth + 2)) < total) |
| 5552 | return 0; |
| 5553 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5554 | /* Allow some exchanges to be available always to complete discovery */ |
| 5555 | if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5556 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 5557 | "0704 At limitation of %d preallocated " |
| 5558 | "command buffers\n", total); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5559 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5560 | /* Allow some exchanges to be available always to complete discovery */ |
| 5561 | } else if (total + num_to_alloc > |
| 5562 | phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5563 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 5564 | "0705 Allocation request of %d " |
| 5565 | "command buffers will exceed max of %d. " |
| 5566 | "Reducing allocation request to %d.\n", |
| 5567 | num_to_alloc, phba->cfg_hba_queue_depth, |
| 5568 | (phba->cfg_hba_queue_depth - total)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5569 | num_to_alloc = phba->cfg_hba_queue_depth - total; |
| 5570 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5571 | num_allocated = lpfc_new_scsi_buf(vport, num_to_alloc); |
| 5572 | if (num_to_alloc != num_allocated) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5573 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5574 | "0708 Allocation request of %d " |
| 5575 | "command buffers did not succeed. " |
| 5576 | "Allocated %d buffers.\n", |
| 5577 | num_to_alloc, num_allocated); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5578 | } |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5579 | if (num_allocated > 0) |
| 5580 | phba->total_scsi_bufs += num_allocated; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5581 | return 0; |
| 5582 | } |
| 5583 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5584 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5585 | * lpfc_slave_configure - scsi_host_template slave_configure entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5586 | * @sdev: Pointer to scsi_device. |
| 5587 | * |
| 5588 | * This routine configures following items |
| 5589 | * - Tag command queuing support for @sdev if supported. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5590 | * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set. |
| 5591 | * |
| 5592 | * Return codes: |
| 5593 | * 0 - Success |
| 5594 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5595 | static int |
| 5596 | lpfc_slave_configure(struct scsi_device *sdev) |
| 5597 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5598 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 5599 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5600 | |
Christoph Hellwig | c8b09f6 | 2014-11-03 20:15:14 +0100 | [diff] [blame] | 5601 | scsi_adjust_queue_depth(sdev, vport->cfg_lun_queue_depth); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5602 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5603 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 5604 | lpfc_sli_handle_fast_ring_event(phba, |
| 5605 | &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5606 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 5607 | lpfc_poll_rearm_timer(phba); |
| 5608 | } |
| 5609 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5610 | return 0; |
| 5611 | } |
| 5612 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5613 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5614 | * lpfc_slave_destroy - slave_destroy entry point of SHT data structure |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5615 | * @sdev: Pointer to scsi_device. |
| 5616 | * |
| 5617 | * This routine sets @sdev hostatdata filed to null. |
| 5618 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5619 | static void |
| 5620 | lpfc_slave_destroy(struct scsi_device *sdev) |
| 5621 | { |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5622 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 5623 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5624 | unsigned long flags; |
| 5625 | struct lpfc_device_data *device_data = sdev->hostdata; |
| 5626 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5627 | atomic_dec(&phba->sdev_cnt); |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5628 | if ((phba->cfg_fof) && (device_data)) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5629 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5630 | device_data->available = false; |
| 5631 | if (!device_data->oas_enabled) |
| 5632 | lpfc_delete_device_data(phba, device_data); |
| 5633 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5634 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5635 | sdev->hostdata = NULL; |
| 5636 | return; |
| 5637 | } |
| 5638 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5639 | /** |
| 5640 | * lpfc_create_device_data - creates and initializes device data structure for OAS |
| 5641 | * @pha: Pointer to host bus adapter structure. |
| 5642 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5643 | * @target_wwpn: Pointer to target's wwpn information |
| 5644 | * @lun: Lun on target |
| 5645 | * @atomic_create: Flag to indicate if memory should be allocated using the |
| 5646 | * GFP_ATOMIC flag or not. |
| 5647 | * |
| 5648 | * This routine creates a device data structure which will contain identifying |
| 5649 | * information for the device (host wwpn, target wwpn, lun), state of OAS, |
| 5650 | * whether or not the corresponding lun is available by the system, |
| 5651 | * and pointer to the rport data. |
| 5652 | * |
| 5653 | * Return codes: |
| 5654 | * NULL - Error |
| 5655 | * Pointer to lpfc_device_data - Success |
| 5656 | **/ |
| 5657 | struct lpfc_device_data* |
| 5658 | lpfc_create_device_data(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn, |
| 5659 | struct lpfc_name *target_wwpn, uint64_t lun, |
| 5660 | bool atomic_create) |
| 5661 | { |
| 5662 | |
| 5663 | struct lpfc_device_data *lun_info; |
| 5664 | int memory_flags; |
| 5665 | |
| 5666 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5667 | !(phba->cfg_fof)) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5668 | return NULL; |
| 5669 | |
| 5670 | /* Attempt to create the device data to contain lun info */ |
| 5671 | |
| 5672 | if (atomic_create) |
| 5673 | memory_flags = GFP_ATOMIC; |
| 5674 | else |
| 5675 | memory_flags = GFP_KERNEL; |
| 5676 | lun_info = mempool_alloc(phba->device_data_mem_pool, memory_flags); |
| 5677 | if (!lun_info) |
| 5678 | return NULL; |
| 5679 | INIT_LIST_HEAD(&lun_info->listentry); |
| 5680 | lun_info->rport_data = NULL; |
| 5681 | memcpy(&lun_info->device_id.vport_wwpn, vport_wwpn, |
| 5682 | sizeof(struct lpfc_name)); |
| 5683 | memcpy(&lun_info->device_id.target_wwpn, target_wwpn, |
| 5684 | sizeof(struct lpfc_name)); |
| 5685 | lun_info->device_id.lun = lun; |
| 5686 | lun_info->oas_enabled = false; |
| 5687 | lun_info->available = false; |
| 5688 | return lun_info; |
| 5689 | } |
| 5690 | |
| 5691 | /** |
| 5692 | * lpfc_delete_device_data - frees a device data structure for OAS |
| 5693 | * @pha: Pointer to host bus adapter structure. |
| 5694 | * @lun_info: Pointer to device data structure to free. |
| 5695 | * |
| 5696 | * This routine frees the previously allocated device data structure passed. |
| 5697 | * |
| 5698 | **/ |
| 5699 | void |
| 5700 | lpfc_delete_device_data(struct lpfc_hba *phba, |
| 5701 | struct lpfc_device_data *lun_info) |
| 5702 | { |
| 5703 | |
| 5704 | if (unlikely(!phba) || !lun_info || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5705 | !(phba->cfg_fof)) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5706 | return; |
| 5707 | |
| 5708 | if (!list_empty(&lun_info->listentry)) |
| 5709 | list_del(&lun_info->listentry); |
| 5710 | mempool_free(lun_info, phba->device_data_mem_pool); |
| 5711 | return; |
| 5712 | } |
| 5713 | |
| 5714 | /** |
| 5715 | * __lpfc_get_device_data - returns the device data for the specified lun |
| 5716 | * @pha: Pointer to host bus adapter structure. |
| 5717 | * @list: Point to list to search. |
| 5718 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5719 | * @target_wwpn: Pointer to target's wwpn information |
| 5720 | * @lun: Lun on target |
| 5721 | * |
| 5722 | * This routine searches the list passed for the specified lun's device data. |
| 5723 | * This function does not hold locks, it is the responsibility of the caller |
| 5724 | * to ensure the proper lock is held before calling the function. |
| 5725 | * |
| 5726 | * Return codes: |
| 5727 | * NULL - Error |
| 5728 | * Pointer to lpfc_device_data - Success |
| 5729 | **/ |
| 5730 | struct lpfc_device_data* |
| 5731 | __lpfc_get_device_data(struct lpfc_hba *phba, struct list_head *list, |
| 5732 | struct lpfc_name *vport_wwpn, |
| 5733 | struct lpfc_name *target_wwpn, uint64_t lun) |
| 5734 | { |
| 5735 | |
| 5736 | struct lpfc_device_data *lun_info; |
| 5737 | |
| 5738 | if (unlikely(!phba) || !list || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5739 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5740 | return NULL; |
| 5741 | |
| 5742 | /* Check to see if the lun is already enabled for OAS. */ |
| 5743 | |
| 5744 | list_for_each_entry(lun_info, list, listentry) { |
| 5745 | if ((memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn, |
| 5746 | sizeof(struct lpfc_name)) == 0) && |
| 5747 | (memcmp(&lun_info->device_id.target_wwpn, target_wwpn, |
| 5748 | sizeof(struct lpfc_name)) == 0) && |
| 5749 | (lun_info->device_id.lun == lun)) |
| 5750 | return lun_info; |
| 5751 | } |
| 5752 | |
| 5753 | return NULL; |
| 5754 | } |
| 5755 | |
| 5756 | /** |
| 5757 | * lpfc_find_next_oas_lun - searches for the next oas lun |
| 5758 | * @pha: Pointer to host bus adapter structure. |
| 5759 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5760 | * @target_wwpn: Pointer to target's wwpn information |
| 5761 | * @starting_lun: Pointer to the lun to start searching for |
| 5762 | * @found_vport_wwpn: Pointer to the found lun's vport wwpn information |
| 5763 | * @found_target_wwpn: Pointer to the found lun's target wwpn information |
| 5764 | * @found_lun: Pointer to the found lun. |
| 5765 | * @found_lun_status: Pointer to status of the found lun. |
| 5766 | * |
| 5767 | * This routine searches the luns list for the specified lun |
| 5768 | * or the first lun for the vport/target. If the vport wwpn contains |
| 5769 | * a zero value then a specific vport is not specified. In this case |
| 5770 | * any vport which contains the lun will be considered a match. If the |
| 5771 | * target wwpn contains a zero value then a specific target is not specified. |
| 5772 | * In this case any target which contains the lun will be considered a |
| 5773 | * match. If the lun is found, the lun, vport wwpn, target wwpn and lun status |
| 5774 | * are returned. The function will also return the next lun if available. |
| 5775 | * If the next lun is not found, starting_lun parameter will be set to |
| 5776 | * NO_MORE_OAS_LUN. |
| 5777 | * |
| 5778 | * Return codes: |
| 5779 | * non-0 - Error |
| 5780 | * 0 - Success |
| 5781 | **/ |
| 5782 | bool |
| 5783 | lpfc_find_next_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn, |
| 5784 | struct lpfc_name *target_wwpn, uint64_t *starting_lun, |
| 5785 | struct lpfc_name *found_vport_wwpn, |
| 5786 | struct lpfc_name *found_target_wwpn, |
| 5787 | uint64_t *found_lun, |
| 5788 | uint32_t *found_lun_status) |
| 5789 | { |
| 5790 | |
| 5791 | unsigned long flags; |
| 5792 | struct lpfc_device_data *lun_info; |
| 5793 | struct lpfc_device_id *device_id; |
| 5794 | uint64_t lun; |
| 5795 | bool found = false; |
| 5796 | |
| 5797 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
| 5798 | !starting_lun || !found_vport_wwpn || |
| 5799 | !found_target_wwpn || !found_lun || !found_lun_status || |
| 5800 | (*starting_lun == NO_MORE_OAS_LUN) || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5801 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5802 | return false; |
| 5803 | |
| 5804 | lun = *starting_lun; |
| 5805 | *found_lun = NO_MORE_OAS_LUN; |
| 5806 | *starting_lun = NO_MORE_OAS_LUN; |
| 5807 | |
| 5808 | /* Search for lun or the lun closet in value */ |
| 5809 | |
| 5810 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5811 | list_for_each_entry(lun_info, &phba->luns, listentry) { |
| 5812 | if (((wwn_to_u64(vport_wwpn->u.wwn) == 0) || |
| 5813 | (memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn, |
| 5814 | sizeof(struct lpfc_name)) == 0)) && |
| 5815 | ((wwn_to_u64(target_wwpn->u.wwn) == 0) || |
| 5816 | (memcmp(&lun_info->device_id.target_wwpn, target_wwpn, |
| 5817 | sizeof(struct lpfc_name)) == 0)) && |
| 5818 | (lun_info->oas_enabled)) { |
| 5819 | device_id = &lun_info->device_id; |
| 5820 | if ((!found) && |
| 5821 | ((lun == FIND_FIRST_OAS_LUN) || |
| 5822 | (device_id->lun == lun))) { |
| 5823 | *found_lun = device_id->lun; |
| 5824 | memcpy(found_vport_wwpn, |
| 5825 | &device_id->vport_wwpn, |
| 5826 | sizeof(struct lpfc_name)); |
| 5827 | memcpy(found_target_wwpn, |
| 5828 | &device_id->target_wwpn, |
| 5829 | sizeof(struct lpfc_name)); |
| 5830 | if (lun_info->available) |
| 5831 | *found_lun_status = |
| 5832 | OAS_LUN_STATUS_EXISTS; |
| 5833 | else |
| 5834 | *found_lun_status = 0; |
| 5835 | if (phba->cfg_oas_flags & OAS_FIND_ANY_VPORT) |
| 5836 | memset(vport_wwpn, 0x0, |
| 5837 | sizeof(struct lpfc_name)); |
| 5838 | if (phba->cfg_oas_flags & OAS_FIND_ANY_TARGET) |
| 5839 | memset(target_wwpn, 0x0, |
| 5840 | sizeof(struct lpfc_name)); |
| 5841 | found = true; |
| 5842 | } else if (found) { |
| 5843 | *starting_lun = device_id->lun; |
| 5844 | memcpy(vport_wwpn, &device_id->vport_wwpn, |
| 5845 | sizeof(struct lpfc_name)); |
| 5846 | memcpy(target_wwpn, &device_id->target_wwpn, |
| 5847 | sizeof(struct lpfc_name)); |
| 5848 | break; |
| 5849 | } |
| 5850 | } |
| 5851 | } |
| 5852 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5853 | return found; |
| 5854 | } |
| 5855 | |
| 5856 | /** |
| 5857 | * lpfc_enable_oas_lun - enables a lun for OAS operations |
| 5858 | * @pha: Pointer to host bus adapter structure. |
| 5859 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5860 | * @target_wwpn: Pointer to target's wwpn information |
| 5861 | * @lun: Lun |
| 5862 | * |
| 5863 | * This routine enables a lun for oas operations. The routines does so by |
| 5864 | * doing the following : |
| 5865 | * |
| 5866 | * 1) Checks to see if the device data for the lun has been created. |
| 5867 | * 2) If found, sets the OAS enabled flag if not set and returns. |
| 5868 | * 3) Otherwise, creates a device data structure. |
| 5869 | * 4) If successfully created, indicates the device data is for an OAS lun, |
| 5870 | * indicates the lun is not available and add to the list of luns. |
| 5871 | * |
| 5872 | * Return codes: |
| 5873 | * false - Error |
| 5874 | * true - Success |
| 5875 | **/ |
| 5876 | bool |
| 5877 | lpfc_enable_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn, |
| 5878 | struct lpfc_name *target_wwpn, uint64_t lun) |
| 5879 | { |
| 5880 | |
| 5881 | struct lpfc_device_data *lun_info; |
| 5882 | unsigned long flags; |
| 5883 | |
| 5884 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5885 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5886 | return false; |
| 5887 | |
| 5888 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5889 | |
| 5890 | /* Check to see if the device data for the lun has been created */ |
| 5891 | lun_info = __lpfc_get_device_data(phba, &phba->luns, vport_wwpn, |
| 5892 | target_wwpn, lun); |
| 5893 | if (lun_info) { |
| 5894 | if (!lun_info->oas_enabled) |
| 5895 | lun_info->oas_enabled = true; |
| 5896 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5897 | return true; |
| 5898 | } |
| 5899 | |
| 5900 | /* Create an lun info structure and add to list of luns */ |
| 5901 | lun_info = lpfc_create_device_data(phba, vport_wwpn, target_wwpn, lun, |
| 5902 | false); |
| 5903 | if (lun_info) { |
| 5904 | lun_info->oas_enabled = true; |
| 5905 | lun_info->available = false; |
| 5906 | list_add_tail(&lun_info->listentry, &phba->luns); |
| 5907 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5908 | return true; |
| 5909 | } |
| 5910 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5911 | return false; |
| 5912 | } |
| 5913 | |
| 5914 | /** |
| 5915 | * lpfc_disable_oas_lun - disables a lun for OAS operations |
| 5916 | * @pha: Pointer to host bus adapter structure. |
| 5917 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5918 | * @target_wwpn: Pointer to target's wwpn information |
| 5919 | * @lun: Lun |
| 5920 | * |
| 5921 | * This routine disables a lun for oas operations. The routines does so by |
| 5922 | * doing the following : |
| 5923 | * |
| 5924 | * 1) Checks to see if the device data for the lun is created. |
| 5925 | * 2) If present, clears the flag indicating this lun is for OAS. |
| 5926 | * 3) If the lun is not available by the system, the device data is |
| 5927 | * freed. |
| 5928 | * |
| 5929 | * Return codes: |
| 5930 | * false - Error |
| 5931 | * true - Success |
| 5932 | **/ |
| 5933 | bool |
| 5934 | lpfc_disable_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn, |
| 5935 | struct lpfc_name *target_wwpn, uint64_t lun) |
| 5936 | { |
| 5937 | |
| 5938 | struct lpfc_device_data *lun_info; |
| 5939 | unsigned long flags; |
| 5940 | |
| 5941 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5942 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5943 | return false; |
| 5944 | |
| 5945 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5946 | |
| 5947 | /* Check to see if the lun is available. */ |
| 5948 | lun_info = __lpfc_get_device_data(phba, |
| 5949 | &phba->luns, vport_wwpn, |
| 5950 | target_wwpn, lun); |
| 5951 | if (lun_info) { |
| 5952 | lun_info->oas_enabled = false; |
| 5953 | if (!lun_info->available) |
| 5954 | lpfc_delete_device_data(phba, lun_info); |
| 5955 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5956 | return true; |
| 5957 | } |
| 5958 | |
| 5959 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5960 | return false; |
| 5961 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5962 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5963 | struct scsi_host_template lpfc_template = { |
| 5964 | .module = THIS_MODULE, |
| 5965 | .name = LPFC_DRIVER_NAME, |
| 5966 | .info = lpfc_info, |
| 5967 | .queuecommand = lpfc_queuecommand, |
| 5968 | .eh_abort_handler = lpfc_abort_handler, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5969 | .eh_device_reset_handler = lpfc_device_reset_handler, |
| 5970 | .eh_target_reset_handler = lpfc_target_reset_handler, |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5971 | .eh_bus_reset_handler = lpfc_bus_reset_handler, |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5972 | .eh_host_reset_handler = lpfc_host_reset_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5973 | .slave_alloc = lpfc_slave_alloc, |
| 5974 | .slave_configure = lpfc_slave_configure, |
| 5975 | .slave_destroy = lpfc_slave_destroy, |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 5976 | .scan_finished = lpfc_scan_finished, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5977 | .this_id = -1, |
James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 5978 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5979 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
| 5980 | .use_clustering = ENABLE_CLUSTERING, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5981 | .shost_attrs = lpfc_hba_attrs, |
James.Smart@Emulex.Com | 564b296 | 2005-06-25 10:34:17 -0400 | [diff] [blame] | 5982 | .max_sectors = 0xFFFF, |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5983 | .vendor_id = LPFC_NL_VENDOR_ID, |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 5984 | .change_queue_depth = lpfc_change_queue_depth, |
Christoph Hellwig | a62182f | 2014-10-02 14:39:55 +0200 | [diff] [blame] | 5985 | .change_queue_type = scsi_change_queue_type, |
Christoph Hellwig | 2ecb204 | 2014-11-03 14:09:02 +0100 | [diff] [blame] | 5986 | .use_blk_tags = 1, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5987 | }; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5988 | |
| 5989 | struct scsi_host_template lpfc_vport_template = { |
| 5990 | .module = THIS_MODULE, |
| 5991 | .name = LPFC_DRIVER_NAME, |
| 5992 | .info = lpfc_info, |
| 5993 | .queuecommand = lpfc_queuecommand, |
| 5994 | .eh_abort_handler = lpfc_abort_handler, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5995 | .eh_device_reset_handler = lpfc_device_reset_handler, |
| 5996 | .eh_target_reset_handler = lpfc_target_reset_handler, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5997 | .eh_bus_reset_handler = lpfc_bus_reset_handler, |
| 5998 | .slave_alloc = lpfc_slave_alloc, |
| 5999 | .slave_configure = lpfc_slave_configure, |
| 6000 | .slave_destroy = lpfc_slave_destroy, |
| 6001 | .scan_finished = lpfc_scan_finished, |
| 6002 | .this_id = -1, |
James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 6003 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6004 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
| 6005 | .use_clustering = ENABLE_CLUSTERING, |
| 6006 | .shost_attrs = lpfc_vport_attrs, |
| 6007 | .max_sectors = 0xFFFF, |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6008 | .change_queue_depth = lpfc_change_queue_depth, |
Christoph Hellwig | a62182f | 2014-10-02 14:39:55 +0200 | [diff] [blame] | 6009 | .change_queue_type = scsi_change_queue_type, |
Christoph Hellwig | 2ecb204 | 2014-11-03 14:09:02 +0100 | [diff] [blame] | 6010 | .use_blk_tags = 1, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6011 | }; |