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