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 | 128bdda | 2018-01-30 15:59:03 -0800 | [diff] [blame] | 4 | * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term * |
James Smart | 3e21d1c | 2018-05-04 20:37:59 -0700 | [diff] [blame] | 5 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. * |
James Smart | 51f4ca3 | 2016-07-06 12:36:13 -0700 | [diff] [blame] | 6 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * EMULEX and SLI are trademarks of Emulex. * |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 8 | * www.broadcom.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 9 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10 | * * |
| 11 | * 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] | 12 | * modify it under the terms of version 2 of the GNU General * |
| 13 | * Public License as published by the Free Software Foundation. * |
| 14 | * This program is distributed in the hope that it will be useful. * |
| 15 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 16 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 18 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 19 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 20 | * more details, a copy of which can be found in the file COPYING * |
| 21 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | *******************************************************************/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 23 | #include <linux/pci.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 24 | #include <linux/slab.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 25 | #include <linux/interrupt.h> |
Paul Gortmaker | 0970366 | 2011-05-27 09:37:25 -0400 | [diff] [blame] | 26 | #include <linux/export.h> |
James Smart | a90f568 | 2006-08-17 11:58:04 -0400 | [diff] [blame] | 27 | #include <linux/delay.h> |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 28 | #include <asm/unaligned.h> |
Dmitry Monakhov | 128b6f9 | 2017-06-29 11:31:12 -0700 | [diff] [blame] | 29 | #include <linux/t10-pi.h> |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 30 | #include <linux/crc-t10dif.h> |
| 31 | #include <net/checksum.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 32 | |
| 33 | #include <scsi/scsi.h> |
| 34 | #include <scsi/scsi_device.h> |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 35 | #include <scsi/scsi_eh.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 36 | #include <scsi/scsi_host.h> |
| 37 | #include <scsi/scsi_tcq.h> |
| 38 | #include <scsi/scsi_transport_fc.h> |
| 39 | |
| 40 | #include "lpfc_version.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 41 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 42 | #include "lpfc_hw.h" |
| 43 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 44 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 45 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 46 | #include "lpfc_disc.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 47 | #include "lpfc.h" |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 48 | #include "lpfc_scsi.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 49 | #include "lpfc_logmsg.h" |
| 50 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 51 | #include "lpfc_vport.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 52 | |
| 53 | #define LPFC_RESET_WAIT 2 |
| 54 | #define LPFC_ABORT_WAIT 2 |
| 55 | |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 56 | int _dump_buf_done = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 57 | |
| 58 | static char *dif_op_str[] = { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 59 | "PROT_NORMAL", |
| 60 | "PROT_READ_INSERT", |
| 61 | "PROT_WRITE_STRIP", |
| 62 | "PROT_READ_STRIP", |
| 63 | "PROT_WRITE_INSERT", |
| 64 | "PROT_READ_PASS", |
| 65 | "PROT_WRITE_PASS", |
| 66 | }; |
| 67 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 68 | struct scsi_dif_tuple { |
| 69 | __be16 guard_tag; /* Checksum */ |
| 70 | __be16 app_tag; /* Opaque storage */ |
| 71 | __be32 ref_tag; /* Target LBA or indirect LBA */ |
| 72 | }; |
| 73 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 74 | static struct lpfc_rport_data * |
| 75 | lpfc_rport_data_from_scsi_device(struct scsi_device *sdev) |
| 76 | { |
| 77 | struct lpfc_vport *vport = (struct lpfc_vport *)sdev->host->hostdata; |
| 78 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 79 | if (vport->phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 80 | return ((struct lpfc_device_data *)sdev->hostdata)->rport_data; |
| 81 | else |
| 82 | return (struct lpfc_rport_data *)sdev->hostdata; |
| 83 | } |
| 84 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 85 | static void |
| 86 | 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] | 87 | static void |
| 88 | 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] | 89 | static int |
| 90 | lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 91 | |
| 92 | static void |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 93 | lpfc_debug_save_data(struct lpfc_hba *phba, struct scsi_cmnd *cmnd) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 94 | { |
| 95 | void *src, *dst; |
| 96 | struct scatterlist *sgde = scsi_sglist(cmnd); |
| 97 | |
| 98 | if (!_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 99 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 100 | "9050 BLKGRD: ERROR %s _dump_buf_data is NULL\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 101 | __func__); |
| 102 | return; |
| 103 | } |
| 104 | |
| 105 | |
| 106 | if (!sgde) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 107 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 108 | "9051 BLKGRD: ERROR: data scatterlist is null\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 109 | return; |
| 110 | } |
| 111 | |
| 112 | dst = (void *) _dump_buf_data; |
| 113 | while (sgde) { |
| 114 | src = sg_virt(sgde); |
| 115 | memcpy(dst, src, sgde->length); |
| 116 | dst += sgde->length; |
| 117 | sgde = sg_next(sgde); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | static void |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 122 | lpfc_debug_save_dif(struct lpfc_hba *phba, struct scsi_cmnd *cmnd) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 123 | { |
| 124 | void *src, *dst; |
| 125 | struct scatterlist *sgde = scsi_prot_sglist(cmnd); |
| 126 | |
| 127 | if (!_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 128 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 129 | "9052 BLKGRD: ERROR %s _dump_buf_data is NULL\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 130 | __func__); |
| 131 | return; |
| 132 | } |
| 133 | |
| 134 | if (!sgde) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 135 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 136 | "9053 BLKGRD: ERROR: prot scatterlist is null\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 137 | return; |
| 138 | } |
| 139 | |
| 140 | dst = _dump_buf_dif; |
| 141 | while (sgde) { |
| 142 | src = sg_virt(sgde); |
| 143 | memcpy(dst, src, sgde->length); |
| 144 | dst += sgde->length; |
| 145 | sgde = sg_next(sgde); |
| 146 | } |
| 147 | } |
| 148 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 149 | static inline unsigned |
| 150 | lpfc_cmd_blksize(struct scsi_cmnd *sc) |
| 151 | { |
| 152 | return sc->device->sector_size; |
| 153 | } |
| 154 | |
| 155 | #define LPFC_CHECK_PROTECT_GUARD 1 |
| 156 | #define LPFC_CHECK_PROTECT_REF 2 |
| 157 | static inline unsigned |
| 158 | lpfc_cmd_protect(struct scsi_cmnd *sc, int flag) |
| 159 | { |
| 160 | return 1; |
| 161 | } |
| 162 | |
| 163 | static inline unsigned |
| 164 | lpfc_cmd_guard_csum(struct scsi_cmnd *sc) |
| 165 | { |
| 166 | if (lpfc_prot_group_type(NULL, sc) == LPFC_PG_TYPE_NO_DIF) |
| 167 | return 0; |
| 168 | if (scsi_host_get_guard(sc->device->host) == SHOST_DIX_GUARD_IP) |
| 169 | return 1; |
| 170 | return 0; |
| 171 | } |
| 172 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 173 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 174 | * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge. |
| 175 | * @phba: Pointer to HBA object. |
| 176 | * @lpfc_cmd: lpfc scsi command object pointer. |
| 177 | * |
| 178 | * This function is called from the lpfc_prep_task_mgmt_cmd function to |
| 179 | * set the last bit in the response sge entry. |
| 180 | **/ |
| 181 | static void |
| 182 | lpfc_sli4_set_rsp_sgl_last(struct lpfc_hba *phba, |
| 183 | struct lpfc_scsi_buf *lpfc_cmd) |
| 184 | { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 185 | struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 186 | if (sgl) { |
| 187 | sgl += 1; |
| 188 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 189 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 190 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 195 | * lpfc_update_stats - Update statistical data for the command completion |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 196 | * @phba: Pointer to HBA object. |
| 197 | * @lpfc_cmd: lpfc scsi command object pointer. |
| 198 | * |
| 199 | * This function is called when there is a command completion and this |
| 200 | * function updates the statistical data for the command completion. |
| 201 | **/ |
| 202 | static void |
| 203 | lpfc_update_stats(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 204 | { |
James Smart | 18027a8 | 2018-09-10 10:30:49 -0700 | [diff] [blame] | 205 | struct lpfc_rport_data *rdata; |
| 206 | struct lpfc_nodelist *pnode; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 207 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 208 | unsigned long flags; |
| 209 | struct Scsi_Host *shost = cmd->device->host; |
| 210 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 211 | unsigned long latency; |
| 212 | int i; |
| 213 | |
James Smart | 18027a8 | 2018-09-10 10:30:49 -0700 | [diff] [blame] | 214 | if (!vport->stat_data_enabled || |
| 215 | vport->stat_data_blocked || |
| 216 | (cmd->result)) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 217 | return; |
| 218 | |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 219 | latency = jiffies_to_msecs((long)jiffies - (long)lpfc_cmd->start_time); |
James Smart | 18027a8 | 2018-09-10 10:30:49 -0700 | [diff] [blame] | 220 | rdata = lpfc_cmd->rdata; |
| 221 | pnode = rdata->pnode; |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 222 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 223 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | 18027a8 | 2018-09-10 10:30:49 -0700 | [diff] [blame] | 224 | if (!pnode || |
| 225 | !pnode->lat_data || |
| 226 | (phba->bucket_type == LPFC_NO_BUCKET)) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 227 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 228 | return; |
| 229 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 230 | |
| 231 | if (phba->bucket_type == LPFC_LINEAR_BUCKET) { |
| 232 | i = (latency + phba->bucket_step - 1 - phba->bucket_base)/ |
| 233 | phba->bucket_step; |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 234 | /* check array subscript bounds */ |
| 235 | if (i < 0) |
| 236 | i = 0; |
| 237 | else if (i >= LPFC_MAX_BUCKET_COUNT) |
| 238 | i = LPFC_MAX_BUCKET_COUNT - 1; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 239 | } else { |
| 240 | for (i = 0; i < LPFC_MAX_BUCKET_COUNT-1; i++) |
| 241 | if (latency <= (phba->bucket_base + |
| 242 | ((1<<i)*phba->bucket_step))) |
| 243 | break; |
| 244 | } |
| 245 | |
| 246 | pnode->lat_data[i].cmd_count++; |
| 247 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 248 | } |
| 249 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 250 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 251 | * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 252 | * @phba: The Hba for which this call is being executed. |
| 253 | * |
| 254 | * This routine is called when there is resource error in driver or firmware. |
| 255 | * This routine posts WORKER_RAMP_DOWN_QUEUE event for @phba. This routine |
| 256 | * posts at most 1 event each second. This routine wakes up worker thread of |
| 257 | * @phba to process WORKER_RAM_DOWN_EVENT event. |
| 258 | * |
| 259 | * This routine should be called with no lock held. |
| 260 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 261 | void |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 262 | lpfc_rampdown_queue_depth(struct lpfc_hba *phba) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 263 | { |
| 264 | unsigned long flags; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 265 | uint32_t evt_posted; |
Manuel Schölling | 0d4aec1 | 2014-09-03 12:55:58 -0400 | [diff] [blame] | 266 | unsigned long expires; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 267 | |
| 268 | spin_lock_irqsave(&phba->hbalock, flags); |
| 269 | atomic_inc(&phba->num_rsrc_err); |
| 270 | phba->last_rsrc_error_time = jiffies; |
| 271 | |
Manuel Schölling | 0d4aec1 | 2014-09-03 12:55:58 -0400 | [diff] [blame] | 272 | expires = phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL; |
| 273 | if (time_after(expires, jiffies)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 274 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 275 | return; |
| 276 | } |
| 277 | |
| 278 | phba->last_ramp_down_time = jiffies; |
| 279 | |
| 280 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 281 | |
| 282 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 283 | evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE; |
| 284 | if (!evt_posted) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 285 | phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 286 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
| 287 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 288 | if (!evt_posted) |
| 289 | lpfc_worker_wake_up(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 290 | return; |
| 291 | } |
| 292 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 293 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 294 | * lpfc_ramp_down_queue_handler - WORKER_RAMP_DOWN_QUEUE event handler |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 295 | * @phba: The Hba for which this call is being executed. |
| 296 | * |
| 297 | * This routine is called to process WORKER_RAMP_DOWN_QUEUE event for worker |
| 298 | * thread.This routine reduces queue depth for all scsi device on each vport |
| 299 | * associated with @phba. |
| 300 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 301 | void |
| 302 | lpfc_ramp_down_queue_handler(struct lpfc_hba *phba) |
| 303 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 304 | struct lpfc_vport **vports; |
| 305 | struct Scsi_Host *shost; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 306 | struct scsi_device *sdev; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 307 | unsigned long new_queue_depth; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 308 | unsigned long num_rsrc_err, num_cmd_success; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 309 | int i; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 310 | |
| 311 | num_rsrc_err = atomic_read(&phba->num_rsrc_err); |
| 312 | num_cmd_success = atomic_read(&phba->num_cmd_success); |
| 313 | |
James Smart | 75ad83a | 2012-05-09 21:18:40 -0400 | [diff] [blame] | 314 | /* |
| 315 | * The error and success command counters are global per |
| 316 | * driver instance. If another handler has already |
| 317 | * operated on this error event, just exit. |
| 318 | */ |
| 319 | if (num_rsrc_err == 0) |
| 320 | return; |
| 321 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 322 | vports = lpfc_create_vport_work_array(phba); |
| 323 | if (vports != NULL) |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 324 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 325 | shost = lpfc_shost_from_vport(vports[i]); |
| 326 | shost_for_each_device(sdev, shost) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 327 | new_queue_depth = |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 328 | sdev->queue_depth * num_rsrc_err / |
| 329 | (num_rsrc_err + num_cmd_success); |
| 330 | if (!new_queue_depth) |
| 331 | new_queue_depth = sdev->queue_depth - 1; |
| 332 | else |
| 333 | new_queue_depth = sdev->queue_depth - |
| 334 | new_queue_depth; |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 335 | scsi_change_queue_depth(sdev, new_queue_depth); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 336 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 337 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 338 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 339 | atomic_set(&phba->num_rsrc_err, 0); |
| 340 | atomic_set(&phba->num_cmd_success, 0); |
| 341 | } |
| 342 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 343 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 344 | * lpfc_scsi_dev_block - set all scsi hosts to block state |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 345 | * @phba: Pointer to HBA context object. |
| 346 | * |
| 347 | * This function walks vport list and set each SCSI host to block state |
| 348 | * by invoking fc_remote_port_delete() routine. This function is invoked |
| 349 | * with EEH when device's PCI slot has been permanently disabled. |
| 350 | **/ |
| 351 | void |
| 352 | lpfc_scsi_dev_block(struct lpfc_hba *phba) |
| 353 | { |
| 354 | struct lpfc_vport **vports; |
| 355 | struct Scsi_Host *shost; |
| 356 | struct scsi_device *sdev; |
| 357 | struct fc_rport *rport; |
| 358 | int i; |
| 359 | |
| 360 | vports = lpfc_create_vport_work_array(phba); |
| 361 | if (vports != NULL) |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 362 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 363 | shost = lpfc_shost_from_vport(vports[i]); |
| 364 | shost_for_each_device(sdev, shost) { |
| 365 | rport = starget_to_rport(scsi_target(sdev)); |
| 366 | fc_remote_port_delete(rport); |
| 367 | } |
| 368 | } |
| 369 | lpfc_destroy_vport_work_array(phba, vports); |
| 370 | } |
| 371 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 372 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 373 | * 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] | 374 | * @vport: The virtual port for which this call being executed. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 375 | * @num_to_allocate: The requested number of buffers to allocate. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 376 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 377 | * This routine allocates a scsi buffer for device with SLI-3 interface spec, |
| 378 | * the scsi buffer contains all the necessary information needed to initiate |
| 379 | * a SCSI I/O. The non-DMAable buffer region contains information to build |
| 380 | * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP, |
| 381 | * and the initial BPL. In addition to allocating memory, the FCP CMND and |
| 382 | * 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] | 383 | * |
| 384 | * Return codes: |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 385 | * int - number of scsi buffers that were allocated. |
| 386 | * 0 = failure, less than num_to_alloc is a partial failure. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 387 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 388 | static int |
| 389 | lpfc_new_scsi_buf_s3(struct lpfc_vport *vport, int num_to_alloc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 390 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 391 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 392 | struct lpfc_scsi_buf *psb; |
| 393 | struct ulp_bde64 *bpl; |
| 394 | IOCB_t *iocb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 395 | dma_addr_t pdma_phys_fcp_cmd; |
| 396 | dma_addr_t pdma_phys_fcp_rsp; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 397 | dma_addr_t pdma_phys_sgl; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 398 | uint16_t iotag; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 399 | int bcnt, bpl_size; |
| 400 | |
| 401 | bpl_size = phba->cfg_sg_dma_buf_size - |
| 402 | (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); |
| 403 | |
| 404 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 405 | "9067 ALLOC %d scsi_bufs: %d (%d + %d + %d)\n", |
| 406 | num_to_alloc, phba->cfg_sg_dma_buf_size, |
| 407 | (int)sizeof(struct fcp_cmnd), |
| 408 | (int)sizeof(struct fcp_rsp), bpl_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 409 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 410 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
| 411 | psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL); |
| 412 | if (!psb) |
| 413 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 414 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 415 | /* |
| 416 | * Get memory from the pci pool to map the virt space to pci |
| 417 | * bus space for an I/O. The DMA buffer includes space for the |
| 418 | * struct fcp_cmnd, struct fcp_rsp and the number of bde's |
| 419 | * necessary to support the sg_tablesize. |
| 420 | */ |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 421 | psb->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 422 | GFP_KERNEL, &psb->dma_handle); |
| 423 | if (!psb->data) { |
| 424 | kfree(psb); |
| 425 | break; |
| 426 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 427 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 428 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 429 | /* Allocate iotag for psb->cur_iocbq. */ |
| 430 | iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq); |
| 431 | if (iotag == 0) { |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 432 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 433 | psb->data, psb->dma_handle); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 434 | kfree(psb); |
| 435 | break; |
| 436 | } |
| 437 | psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 438 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 439 | psb->fcp_cmnd = psb->data; |
| 440 | psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 441 | psb->dma_sgl = psb->data + sizeof(struct fcp_cmnd) + |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 442 | sizeof(struct fcp_rsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 443 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 444 | /* Initialize local short-hand pointers. */ |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 445 | bpl = psb->dma_sgl; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 446 | pdma_phys_fcp_cmd = psb->dma_handle; |
| 447 | pdma_phys_fcp_rsp = psb->dma_handle + sizeof(struct fcp_cmnd); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 448 | pdma_phys_sgl = psb->dma_handle + sizeof(struct fcp_cmnd) + |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 449 | sizeof(struct fcp_rsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 450 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 451 | /* |
| 452 | * The first two bdes are the FCP_CMD and FCP_RSP. The balance |
| 453 | * are sg list bdes. Initialize the first two and leave the |
| 454 | * rest for queuecommand. |
| 455 | */ |
| 456 | bpl[0].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd)); |
| 457 | bpl[0].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd)); |
| 458 | bpl[0].tus.f.bdeSize = sizeof(struct fcp_cmnd); |
| 459 | bpl[0].tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 460 | bpl[0].tus.w = le32_to_cpu(bpl[0].tus.w); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 461 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 462 | /* Setup the physical region for the FCP RSP */ |
| 463 | bpl[1].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp)); |
| 464 | bpl[1].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp)); |
| 465 | bpl[1].tus.f.bdeSize = sizeof(struct fcp_rsp); |
| 466 | bpl[1].tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 467 | bpl[1].tus.w = le32_to_cpu(bpl[1].tus.w); |
| 468 | |
| 469 | /* |
| 470 | * Since the IOCB for the FCP I/O is built into this |
| 471 | * lpfc_scsi_buf, initialize it with all known data now. |
| 472 | */ |
| 473 | iocb = &psb->cur_iocbq.iocb; |
| 474 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; |
| 475 | if ((phba->sli_rev == 3) && |
| 476 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) { |
| 477 | /* fill in immediate fcp command BDE */ |
| 478 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_IMMED; |
| 479 | iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); |
| 480 | iocb->un.fcpi64.bdl.addrLow = offsetof(IOCB_t, |
| 481 | unsli3.fcp_ext.icd); |
| 482 | iocb->un.fcpi64.bdl.addrHigh = 0; |
| 483 | iocb->ulpBdeCount = 0; |
| 484 | iocb->ulpLe = 0; |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 485 | /* fill in response BDE */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 486 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeFlags = |
| 487 | BUFF_TYPE_BDE_64; |
| 488 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeSize = |
| 489 | sizeof(struct fcp_rsp); |
| 490 | iocb->unsli3.fcp_ext.rbde.addrLow = |
| 491 | putPaddrLow(pdma_phys_fcp_rsp); |
| 492 | iocb->unsli3.fcp_ext.rbde.addrHigh = |
| 493 | putPaddrHigh(pdma_phys_fcp_rsp); |
| 494 | } else { |
| 495 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
| 496 | iocb->un.fcpi64.bdl.bdeSize = |
| 497 | (2 * sizeof(struct ulp_bde64)); |
| 498 | iocb->un.fcpi64.bdl.addrLow = |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 499 | putPaddrLow(pdma_phys_sgl); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 500 | iocb->un.fcpi64.bdl.addrHigh = |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 501 | putPaddrHigh(pdma_phys_sgl); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 502 | iocb->ulpBdeCount = 1; |
| 503 | iocb->ulpLe = 1; |
| 504 | } |
| 505 | iocb->ulpClass = CLASS3; |
| 506 | psb->status = IOSTAT_SUCCESS; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 507 | /* Put it back into the SCSI buffer list */ |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 508 | psb->cur_iocbq.context1 = psb; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 509 | lpfc_release_scsi_buf_s3(phba, psb); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 510 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 511 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 512 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 513 | return bcnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 514 | } |
| 515 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 516 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 517 | * lpfc_sli4_vport_delete_fcp_xri_aborted -Remove all ndlp references for vport |
| 518 | * @vport: pointer to lpfc vport data structure. |
| 519 | * |
| 520 | * This routine is invoked by the vport cleanup for deletions and the cleanup |
| 521 | * for an ndlp on removal. |
| 522 | **/ |
| 523 | void |
| 524 | lpfc_sli4_vport_delete_fcp_xri_aborted(struct lpfc_vport *vport) |
| 525 | { |
| 526 | struct lpfc_hba *phba = vport->phba; |
| 527 | struct lpfc_scsi_buf *psb, *next_psb; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 528 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 529 | unsigned long iflag = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 530 | int idx; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 531 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 532 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 533 | return; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 534 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 535 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 536 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 537 | qp = &phba->sli4_hba.hdwq[idx]; |
| 538 | |
| 539 | spin_lock(&qp->abts_scsi_buf_list_lock); |
| 540 | list_for_each_entry_safe(psb, next_psb, |
| 541 | &qp->lpfc_abts_scsi_buf_list, list) { |
| 542 | if (psb->rdata && psb->rdata->pnode && |
| 543 | psb->rdata->pnode->vport == vport) |
| 544 | psb->rdata = NULL; |
| 545 | } |
| 546 | spin_unlock(&qp->abts_scsi_buf_list_lock); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 547 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 548 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 549 | } |
| 550 | |
| 551 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 552 | * lpfc_sli4_fcp_xri_aborted - Fast-path process of fcp xri abort |
| 553 | * @phba: pointer to lpfc hba data structure. |
| 554 | * @axri: pointer to the fcp xri abort wcqe structure. |
| 555 | * |
| 556 | * This routine is invoked by the worker thread to process a SLI4 fast-path |
| 557 | * FCP aborted xri. |
| 558 | **/ |
| 559 | void |
| 560 | lpfc_sli4_fcp_xri_aborted(struct lpfc_hba *phba, |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 561 | struct sli4_wcqe_xri_aborted *axri, int idx) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 562 | { |
| 563 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 564 | uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 565 | struct lpfc_scsi_buf *psb, *next_psb; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 566 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 567 | unsigned long iflag = 0; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 568 | struct lpfc_iocbq *iocbq; |
| 569 | int i; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 570 | struct lpfc_nodelist *ndlp; |
| 571 | int rrq_empty = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 572 | struct lpfc_sli_ring *pring = phba->sli4_hba.els_wq->pring; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 573 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 574 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 575 | return; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 576 | |
| 577 | qp = &phba->sli4_hba.hdwq[idx]; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 578 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 579 | spin_lock(&qp->abts_scsi_buf_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 580 | list_for_each_entry_safe(psb, next_psb, |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 581 | &qp->lpfc_abts_scsi_buf_list, list) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 582 | if (psb->cur_iocbq.sli4_xritag == xri) { |
| 583 | list_del(&psb->list); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 584 | qp->abts_scsi_io_bufs--; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 585 | psb->exch_busy = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 586 | psb->status = IOSTAT_SUCCESS; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 587 | spin_unlock( |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 588 | &qp->abts_scsi_buf_list_lock); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 589 | if (psb->rdata && psb->rdata->pnode) |
| 590 | ndlp = psb->rdata->pnode; |
| 591 | else |
| 592 | ndlp = NULL; |
| 593 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 594 | rrq_empty = list_empty(&phba->active_rrq_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 595 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 596 | if (ndlp) { |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 597 | lpfc_set_rrq_active(phba, ndlp, |
| 598 | psb->cur_iocbq.sli4_lxritag, rxid, 1); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 599 | lpfc_sli4_abts_err_handler(phba, ndlp, axri); |
| 600 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 601 | lpfc_release_scsi_buf_s4(phba, psb); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 602 | if (rrq_empty) |
| 603 | lpfc_worker_wake_up(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 604 | return; |
| 605 | } |
| 606 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 607 | spin_unlock(&qp->abts_scsi_buf_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 608 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 609 | iocbq = phba->sli.iocbq_lookup[i]; |
| 610 | |
| 611 | if (!(iocbq->iocb_flag & LPFC_IO_FCP) || |
| 612 | (iocbq->iocb_flag & LPFC_IO_LIBDFC)) |
| 613 | continue; |
| 614 | if (iocbq->sli4_xritag != xri) |
| 615 | continue; |
| 616 | psb = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
| 617 | psb->exch_busy = 0; |
| 618 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 619 | if (!list_empty(&pring->txq)) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 620 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 621 | return; |
| 622 | |
| 623 | } |
| 624 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 628 | * 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] | 629 | * @phba: The HBA for which this call is being executed. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 630 | * |
| 631 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list |
| 632 | * and returns to caller. |
| 633 | * |
| 634 | * Return codes: |
| 635 | * NULL - Error |
| 636 | * Pointer to lpfc_scsi_buf - Success |
| 637 | **/ |
Adrian Bunk | 455c53e | 2006-01-06 20:21:28 +0100 | [diff] [blame] | 638 | static struct lpfc_scsi_buf* |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 639 | lpfc_get_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 640 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 641 | struct lpfc_scsi_buf * lpfc_cmd = NULL; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 642 | 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] | 643 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 644 | |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 645 | spin_lock_irqsave(&phba->scsi_buf_list_get_lock, iflag); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 646 | list_remove_head(scsi_buf_list_get, lpfc_cmd, struct lpfc_scsi_buf, |
| 647 | list); |
| 648 | if (!lpfc_cmd) { |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 649 | spin_lock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 650 | list_splice(&phba->lpfc_scsi_buf_list_put, |
| 651 | &phba->lpfc_scsi_buf_list_get); |
| 652 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
| 653 | list_remove_head(scsi_buf_list_get, lpfc_cmd, |
| 654 | struct lpfc_scsi_buf, list); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 655 | spin_unlock(&phba->scsi_buf_list_put_lock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 656 | } |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 657 | spin_unlock_irqrestore(&phba->scsi_buf_list_get_lock, iflag); |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 658 | |
| 659 | if (lpfc_ndlp_check_qdepth(phba, ndlp) && lpfc_cmd) { |
| 660 | atomic_inc(&ndlp->cmd_pending); |
| 661 | lpfc_cmd->flags |= LPFC_SBUF_BUMP_QDEPTH; |
| 662 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 663 | return lpfc_cmd; |
| 664 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 665 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 666 | * lpfc_get_scsi_buf_s4 - Get a scsi buffer from io_buf_list of the HBA |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 667 | * @phba: The HBA for which this call is being executed. |
| 668 | * |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 669 | * This routine removes a scsi buffer from head of @hdwq io_buf_list |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 670 | * and returns to caller. |
| 671 | * |
| 672 | * Return codes: |
| 673 | * NULL - Error |
| 674 | * Pointer to lpfc_scsi_buf - Success |
| 675 | **/ |
| 676 | static struct lpfc_scsi_buf* |
| 677 | lpfc_get_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| 678 | { |
James Smart | 3be30e0 | 2013-05-31 17:05:17 -0400 | [diff] [blame] | 679 | struct lpfc_scsi_buf *lpfc_cmd, *lpfc_cmd_next; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 680 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 681 | unsigned long iflag = 0; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 682 | struct sli4_sge *sgl; |
| 683 | IOCB_t *iocb; |
| 684 | dma_addr_t pdma_phys_fcp_rsp; |
| 685 | dma_addr_t pdma_phys_fcp_cmd; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 686 | uint32_t sgl_size, cpu, idx; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 687 | int found = 0; |
| 688 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 689 | cpu = smp_processor_id(); |
| 690 | if (cpu < phba->cfg_hdw_queue) |
| 691 | idx = cpu; |
| 692 | else |
| 693 | idx = cpu % phba->cfg_hdw_queue; |
| 694 | |
| 695 | qp = &phba->sli4_hba.hdwq[idx]; |
| 696 | spin_lock_irqsave(&qp->io_buf_list_get_lock, iflag); |
James Smart | 3be30e0 | 2013-05-31 17:05:17 -0400 | [diff] [blame] | 697 | list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next, |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 698 | &qp->lpfc_io_buf_list_get, list) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 699 | if (lpfc_test_rrq_active(phba, ndlp, |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 700 | lpfc_cmd->cur_iocbq.sli4_lxritag)) |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 701 | continue; |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 702 | list_del_init(&lpfc_cmd->list); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 703 | qp->get_io_bufs--; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 704 | found = 1; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 705 | break; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 706 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 707 | if (!found) { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 708 | spin_lock(&qp->io_buf_list_put_lock); |
| 709 | list_splice(&qp->lpfc_io_buf_list_put, |
| 710 | &qp->lpfc_io_buf_list_get); |
| 711 | qp->get_io_bufs += qp->put_io_bufs; |
| 712 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put); |
| 713 | qp->put_io_bufs = 0; |
| 714 | spin_unlock(&qp->io_buf_list_put_lock); |
James Smart | 3be30e0 | 2013-05-31 17:05:17 -0400 | [diff] [blame] | 715 | list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next, |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 716 | &qp->lpfc_io_buf_list_get, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 717 | list) { |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 718 | if (lpfc_test_rrq_active( |
| 719 | phba, ndlp, lpfc_cmd->cur_iocbq.sli4_lxritag)) |
| 720 | continue; |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 721 | list_del_init(&lpfc_cmd->list); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 722 | qp->get_io_bufs--; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 723 | found = 1; |
| 724 | break; |
| 725 | } |
| 726 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 727 | spin_unlock_irqrestore(&qp->io_buf_list_get_lock, iflag); |
| 728 | if (!found) { |
| 729 | qp->empty_io_bufs++; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 730 | return NULL; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 731 | } |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 732 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 733 | sgl_size = phba->cfg_sg_dma_buf_size - |
| 734 | (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); |
| 735 | |
| 736 | /* Setup key fields in buffer that may have been changed |
| 737 | * if other protocols used this buffer. |
| 738 | */ |
| 739 | lpfc_cmd->cur_iocbq.iocb_flag = LPFC_IO_FCP; |
| 740 | lpfc_cmd->prot_seg_cnt = 0; |
| 741 | lpfc_cmd->seg_cnt = 0; |
| 742 | lpfc_cmd->waitq = NULL; |
| 743 | lpfc_cmd->timeout = 0; |
| 744 | lpfc_cmd->flags = 0; |
| 745 | lpfc_cmd->start_time = jiffies; |
| 746 | lpfc_cmd->waitq = NULL; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 747 | lpfc_cmd->cpu = cpu; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 748 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 749 | lpfc_cmd->prot_data_type = 0; |
| 750 | #endif |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 751 | lpfc_cmd->hdwq = idx; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 752 | |
| 753 | lpfc_cmd->fcp_cmnd = (lpfc_cmd->data + sgl_size); |
| 754 | lpfc_cmd->fcp_rsp = (struct fcp_rsp *)((uint8_t *)lpfc_cmd->fcp_cmnd + |
| 755 | sizeof(struct fcp_cmnd)); |
| 756 | |
| 757 | /* |
| 758 | * The first two SGEs are the FCP_CMD and FCP_RSP. |
| 759 | * The balance are sg list bdes. Initialize the |
| 760 | * first two and leave the rest for queuecommand. |
| 761 | */ |
| 762 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
| 763 | pdma_phys_fcp_cmd = (lpfc_cmd->dma_handle + sgl_size); |
| 764 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd)); |
| 765 | sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd)); |
| 766 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 767 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 768 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 769 | sgl->sge_len = cpu_to_le32(sizeof(struct fcp_cmnd)); |
| 770 | sgl++; |
| 771 | |
| 772 | /* Setup the physical region for the FCP RSP */ |
| 773 | pdma_phys_fcp_rsp = pdma_phys_fcp_cmd + sizeof(struct fcp_cmnd); |
| 774 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp)); |
| 775 | sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp)); |
| 776 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 777 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 778 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 779 | sgl->sge_len = cpu_to_le32(sizeof(struct fcp_rsp)); |
| 780 | |
| 781 | /* |
| 782 | * Since the IOCB for the FCP I/O is built into this |
| 783 | * lpfc_scsi_buf, initialize it with all known data now. |
| 784 | */ |
| 785 | iocb = &lpfc_cmd->cur_iocbq.iocb; |
| 786 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; |
| 787 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_64; |
| 788 | /* setting the BLP size to 2 * sizeof BDE may not be correct. |
| 789 | * We are setting the bpl to point to out sgl. An sgl's |
| 790 | * entries are 16 bytes, a bpl entries are 12 bytes. |
| 791 | */ |
| 792 | iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); |
| 793 | iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys_fcp_cmd); |
| 794 | iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys_fcp_cmd); |
| 795 | iocb->ulpBdeCount = 1; |
| 796 | iocb->ulpLe = 1; |
| 797 | iocb->ulpClass = CLASS3; |
| 798 | |
Dan Carpenter | 26c724a | 2018-08-23 16:56:33 +0300 | [diff] [blame] | 799 | if (lpfc_ndlp_check_qdepth(phba, ndlp)) { |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 800 | atomic_inc(&ndlp->cmd_pending); |
| 801 | lpfc_cmd->flags |= LPFC_SBUF_BUMP_QDEPTH; |
| 802 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 803 | return lpfc_cmd; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 804 | } |
| 805 | /** |
| 806 | * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA |
| 807 | * @phba: The HBA for which this call is being executed. |
| 808 | * |
| 809 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list |
| 810 | * and returns to caller. |
| 811 | * |
| 812 | * Return codes: |
| 813 | * NULL - Error |
| 814 | * Pointer to lpfc_scsi_buf - Success |
| 815 | **/ |
| 816 | static struct lpfc_scsi_buf* |
| 817 | lpfc_get_scsi_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| 818 | { |
| 819 | return phba->lpfc_get_scsi_buf(phba, ndlp); |
| 820 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 821 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 822 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 823 | * 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] | 824 | * @phba: The Hba for which this call is being executed. |
| 825 | * @psb: The scsi buffer which is being released. |
| 826 | * |
| 827 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
| 828 | * lpfc_scsi_buf_list list. |
| 829 | **/ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 830 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 831 | 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] | 832 | { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 833 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 834 | |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 835 | psb->seg_cnt = 0; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 836 | psb->prot_seg_cnt = 0; |
| 837 | |
| 838 | spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 839 | psb->pCmd = NULL; |
James Smart | 6a485eb | 2013-04-17 20:19:00 -0400 | [diff] [blame] | 840 | psb->cur_iocbq.iocb_flag = LPFC_IO_FCP; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 841 | list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list_put); |
| 842 | spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 843 | } |
| 844 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 845 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 846 | * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list. |
| 847 | * @phba: The Hba for which this call is being executed. |
| 848 | * @psb: The scsi buffer which is being released. |
| 849 | * |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 850 | * This routine releases @psb scsi buffer by adding it to tail of @hdwq |
| 851 | * io_buf_list list. For SLI4 XRI's are tied to the scsi buffer |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 852 | * and cannot be reused for at least RA_TOV amount of time if it was |
| 853 | * aborted. |
| 854 | **/ |
| 855 | static void |
| 856 | lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) |
| 857 | { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 858 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 859 | unsigned long iflag = 0; |
| 860 | |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 861 | psb->seg_cnt = 0; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 862 | psb->prot_seg_cnt = 0; |
| 863 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 864 | qp = &phba->sli4_hba.hdwq[psb->hdwq]; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 865 | if (psb->exch_busy) { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 866 | spin_lock_irqsave(&qp->abts_scsi_buf_list_lock, iflag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 867 | psb->pCmd = NULL; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 868 | list_add_tail(&psb->list, &qp->lpfc_abts_scsi_buf_list); |
| 869 | qp->abts_scsi_io_bufs++; |
| 870 | spin_unlock_irqrestore(&qp->abts_scsi_buf_list_lock, iflag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 871 | } else { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 872 | /* MUST zero fields if buffer is reused by another protocol */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 873 | psb->pCmd = NULL; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 874 | psb->cur_iocbq.iocb_cmpl = NULL; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame^] | 875 | |
| 876 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 877 | list_add_tail(&psb->list, &qp->lpfc_io_buf_list_put); |
| 878 | qp->put_io_bufs++; |
| 879 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 880 | } |
| 881 | } |
| 882 | |
| 883 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 884 | * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list. |
| 885 | * @phba: The Hba for which this call is being executed. |
| 886 | * @psb: The scsi buffer which is being released. |
| 887 | * |
| 888 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
| 889 | * lpfc_scsi_buf_list list. |
| 890 | **/ |
| 891 | static void |
| 892 | lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) |
| 893 | { |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 894 | if ((psb->flags & LPFC_SBUF_BUMP_QDEPTH) && psb->ndlp) |
| 895 | atomic_dec(&psb->ndlp->cmd_pending); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 896 | |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 897 | psb->flags &= ~LPFC_SBUF_BUMP_QDEPTH; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 898 | phba->lpfc_release_scsi_buf(phba, psb); |
| 899 | } |
| 900 | |
| 901 | /** |
| 902 | * 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] | 903 | * @phba: The Hba for which this call is being executed. |
| 904 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 905 | * |
| 906 | * 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] | 907 | * field of @lpfc_cmd for device with SLI-3 interface spec. This routine scans |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 908 | * through sg elements and format the bde. This routine also initializes all |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 909 | * IOCB fields which are dependent on scsi command request buffer. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 910 | * |
| 911 | * Return codes: |
| 912 | * 1 - Error |
| 913 | * 0 - Success |
| 914 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 915 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 916 | 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] | 917 | { |
| 918 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 919 | struct scatterlist *sgel = NULL; |
| 920 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 921 | struct ulp_bde64 *bpl = lpfc_cmd->dma_sgl; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 922 | struct lpfc_iocbq *iocbq = &lpfc_cmd->cur_iocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 923 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 924 | struct ulp_bde64 *data_bde = iocb_cmd->unsli3.fcp_ext.dbde; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 925 | dma_addr_t physaddr; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 926 | uint32_t num_bde = 0; |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 927 | int nseg, datadir = scsi_cmnd->sc_data_direction; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 928 | |
| 929 | /* |
| 930 | * There are three possibilities here - use scatter-gather segment, use |
| 931 | * the single mapping, or neither. Start the lpfc command prep by |
| 932 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 933 | * data bde entry. |
| 934 | */ |
| 935 | bpl += 2; |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 936 | if (scsi_sg_count(scsi_cmnd)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 937 | /* |
| 938 | * The driver stores the segment count returned from pci_map_sg |
| 939 | * because this a count of dma-mappings used to map the use_sg |
| 940 | * pages. They are not guaranteed to be the same for those |
| 941 | * architectures that implement an IOMMU. |
| 942 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 943 | |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 944 | nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd), |
| 945 | scsi_sg_count(scsi_cmnd), datadir); |
| 946 | if (unlikely(!nseg)) |
| 947 | return 1; |
| 948 | |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 949 | lpfc_cmd->seg_cnt = nseg; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 950 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 951 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 952 | "9064 BLKGRD: %s: Too many sg segments from " |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 953 | "dma_map_sg. Config %d, seg_cnt %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 954 | __func__, phba->cfg_sg_seg_cnt, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 955 | lpfc_cmd->seg_cnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 956 | lpfc_cmd->seg_cnt = 0; |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 957 | scsi_dma_unmap(scsi_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 958 | return 1; |
| 959 | } |
| 960 | |
| 961 | /* |
| 962 | * The driver established a maximum scatter-gather segment count |
| 963 | * during probe that limits the number of sg elements in any |
| 964 | * single scsi command. Just run through the seg_cnt and format |
| 965 | * the bde's. |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 966 | * When using SLI-3 the driver will try to fit all the BDEs into |
| 967 | * the IOCB. If it can't then the BDEs get added to a BPL as it |
| 968 | * does for SLI-2 mode. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 969 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 970 | scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 971 | physaddr = sg_dma_address(sgel); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 972 | if (phba->sli_rev == 3 && |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 973 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 974 | !(iocbq->iocb_flag & DSS_SECURITY_OP) && |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 975 | nseg <= LPFC_EXT_DATA_BDE_COUNT) { |
| 976 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 977 | data_bde->tus.f.bdeSize = sg_dma_len(sgel); |
| 978 | data_bde->addrLow = putPaddrLow(physaddr); |
| 979 | data_bde->addrHigh = putPaddrHigh(physaddr); |
| 980 | data_bde++; |
| 981 | } else { |
| 982 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 983 | bpl->tus.f.bdeSize = sg_dma_len(sgel); |
| 984 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 985 | bpl->addrLow = |
| 986 | le32_to_cpu(putPaddrLow(physaddr)); |
| 987 | bpl->addrHigh = |
| 988 | le32_to_cpu(putPaddrHigh(physaddr)); |
| 989 | bpl++; |
| 990 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 991 | } |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 992 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 993 | |
| 994 | /* |
| 995 | * Finish initializing those IOCB fields that are dependent on the |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 996 | * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is |
| 997 | * explicitly reinitialized and for SLI-3 the extended bde count is |
| 998 | * explicitly reinitialized since all iocb memory resources are reused. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 999 | */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1000 | if (phba->sli_rev == 3 && |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1001 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
| 1002 | !(iocbq->iocb_flag & DSS_SECURITY_OP)) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1003 | if (num_bde > LPFC_EXT_DATA_BDE_COUNT) { |
| 1004 | /* |
| 1005 | * The extended IOCB format can only fit 3 BDE or a BPL. |
| 1006 | * This I/O has more than 3 BDE so the 1st data bde will |
| 1007 | * be a BPL that is filled in here. |
| 1008 | */ |
| 1009 | physaddr = lpfc_cmd->dma_handle; |
| 1010 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BLP_64; |
| 1011 | data_bde->tus.f.bdeSize = (num_bde * |
| 1012 | sizeof(struct ulp_bde64)); |
| 1013 | physaddr += (sizeof(struct fcp_cmnd) + |
| 1014 | sizeof(struct fcp_rsp) + |
| 1015 | (2 * sizeof(struct ulp_bde64))); |
| 1016 | data_bde->addrHigh = putPaddrHigh(physaddr); |
| 1017 | data_bde->addrLow = putPaddrLow(physaddr); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1018 | /* ebde count includes the response bde and data bpl */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1019 | iocb_cmd->unsli3.fcp_ext.ebde_count = 2; |
| 1020 | } else { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1021 | /* ebde count includes the response bde and data bdes */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1022 | iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); |
| 1023 | } |
| 1024 | } else { |
| 1025 | iocb_cmd->un.fcpi64.bdl.bdeSize = |
| 1026 | ((num_bde + 2) * sizeof(struct ulp_bde64)); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1027 | iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1028 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1029 | fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1030 | |
| 1031 | /* |
| 1032 | * Due to difference in data length between DIF/non-DIF paths, |
| 1033 | * we need to set word 4 of IOCB here |
| 1034 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1035 | iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1036 | return 0; |
| 1037 | } |
| 1038 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1039 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1040 | |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1041 | /* Return BG_ERR_INIT if error injection is detected by Initiator */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1042 | #define BG_ERR_INIT 0x1 |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1043 | /* Return BG_ERR_TGT if error injection is detected by Target */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1044 | #define BG_ERR_TGT 0x2 |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1045 | /* Return BG_ERR_SWAP if swapping CSUM<-->CRC is required for error injection */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1046 | #define BG_ERR_SWAP 0x10 |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1047 | /** |
| 1048 | * Return BG_ERR_CHECK if disabling Guard/Ref/App checking is required for |
| 1049 | * error injection |
| 1050 | **/ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1051 | #define BG_ERR_CHECK 0x20 |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1052 | |
| 1053 | /** |
| 1054 | * lpfc_bg_err_inject - Determine if we should inject an error |
| 1055 | * @phba: The Hba for which this call is being executed. |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1056 | * @sc: The SCSI command to examine |
| 1057 | * @reftag: (out) BlockGuard reference tag for transmitted data |
| 1058 | * @apptag: (out) BlockGuard application tag for transmitted data |
| 1059 | * @new_guard (in) Value to replace CRC with if needed |
| 1060 | * |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1061 | * Returns BG_ERR_* bit mask or 0 if request ignored |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1062 | **/ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1063 | static int |
| 1064 | lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1065 | uint32_t *reftag, uint16_t *apptag, uint32_t new_guard) |
| 1066 | { |
| 1067 | struct scatterlist *sgpe; /* s/g prot entry */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1068 | struct lpfc_scsi_buf *lpfc_cmd = NULL; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1069 | struct scsi_dif_tuple *src = NULL; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1070 | struct lpfc_nodelist *ndlp; |
| 1071 | struct lpfc_rport_data *rdata; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1072 | uint32_t op = scsi_get_prot_op(sc); |
| 1073 | uint32_t blksize; |
| 1074 | uint32_t numblks; |
| 1075 | sector_t lba; |
| 1076 | int rc = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1077 | int blockoff = 0; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1078 | |
| 1079 | if (op == SCSI_PROT_NORMAL) |
| 1080 | return 0; |
| 1081 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1082 | sgpe = scsi_prot_sglist(sc); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1083 | lba = scsi_get_lba(sc); |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1084 | |
| 1085 | /* First check if we need to match the LBA */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1086 | if (phba->lpfc_injerr_lba != LPFC_INJERR_LBA_OFF) { |
| 1087 | blksize = lpfc_cmd_blksize(sc); |
| 1088 | numblks = (scsi_bufflen(sc) + blksize - 1) / blksize; |
| 1089 | |
| 1090 | /* Make sure we have the right LBA if one is specified */ |
| 1091 | if ((phba->lpfc_injerr_lba < lba) || |
| 1092 | (phba->lpfc_injerr_lba >= (lba + numblks))) |
| 1093 | return 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1094 | if (sgpe) { |
| 1095 | blockoff = phba->lpfc_injerr_lba - lba; |
| 1096 | numblks = sg_dma_len(sgpe) / |
| 1097 | sizeof(struct scsi_dif_tuple); |
| 1098 | if (numblks < blockoff) |
| 1099 | blockoff = numblks; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1100 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1101 | } |
| 1102 | |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1103 | /* Next check if we need to match the remote NPortID or WWPN */ |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 1104 | rdata = lpfc_rport_data_from_scsi_device(sc->device); |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1105 | if (rdata && rdata->pnode) { |
| 1106 | ndlp = rdata->pnode; |
| 1107 | |
| 1108 | /* Make sure we have the right NPortID if one is specified */ |
| 1109 | if (phba->lpfc_injerr_nportid && |
| 1110 | (phba->lpfc_injerr_nportid != ndlp->nlp_DID)) |
| 1111 | return 0; |
| 1112 | |
| 1113 | /* |
| 1114 | * Make sure we have the right WWPN if one is specified. |
| 1115 | * wwn[0] should be a non-zero NAA in a good WWPN. |
| 1116 | */ |
| 1117 | if (phba->lpfc_injerr_wwpn.u.wwn[0] && |
| 1118 | (memcmp(&ndlp->nlp_portname, &phba->lpfc_injerr_wwpn, |
| 1119 | sizeof(struct lpfc_name)) != 0)) |
| 1120 | return 0; |
| 1121 | } |
| 1122 | |
| 1123 | /* Setup a ptr to the protection data if the SCSI host provides it */ |
| 1124 | if (sgpe) { |
| 1125 | src = (struct scsi_dif_tuple *)sg_virt(sgpe); |
| 1126 | src += blockoff; |
| 1127 | lpfc_cmd = (struct lpfc_scsi_buf *)sc->host_scribble; |
| 1128 | } |
| 1129 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1130 | /* Should we change the Reference Tag */ |
| 1131 | if (reftag) { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1132 | if (phba->lpfc_injerr_wref_cnt) { |
| 1133 | switch (op) { |
| 1134 | case SCSI_PROT_WRITE_PASS: |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1135 | if (src) { |
| 1136 | /* |
| 1137 | * For WRITE_PASS, force the error |
| 1138 | * to be sent on the wire. It should |
| 1139 | * be detected by the Target. |
| 1140 | * If blockoff != 0 error will be |
| 1141 | * inserted in middle of the IO. |
| 1142 | */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1143 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1144 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1145 | "9076 BLKGRD: Injecting reftag error: " |
| 1146 | "write lba x%lx + x%x oldrefTag x%x\n", |
| 1147 | (unsigned long)lba, blockoff, |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1148 | be32_to_cpu(src->ref_tag)); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1149 | |
| 1150 | /* |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1151 | * Save the old ref_tag so we can |
| 1152 | * restore it on completion. |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1153 | */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1154 | if (lpfc_cmd) { |
| 1155 | lpfc_cmd->prot_data_type = |
| 1156 | LPFC_INJERR_REFTAG; |
| 1157 | lpfc_cmd->prot_data_segment = |
| 1158 | src; |
| 1159 | lpfc_cmd->prot_data = |
| 1160 | src->ref_tag; |
| 1161 | } |
| 1162 | src->ref_tag = cpu_to_be32(0xDEADBEEF); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1163 | phba->lpfc_injerr_wref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1164 | if (phba->lpfc_injerr_wref_cnt == 0) { |
| 1165 | phba->lpfc_injerr_nportid = 0; |
| 1166 | phba->lpfc_injerr_lba = |
| 1167 | LPFC_INJERR_LBA_OFF; |
| 1168 | memset(&phba->lpfc_injerr_wwpn, |
| 1169 | 0, sizeof(struct lpfc_name)); |
| 1170 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1171 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
| 1172 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1173 | break; |
| 1174 | } |
| 1175 | /* Drop thru */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1176 | case SCSI_PROT_WRITE_INSERT: |
| 1177 | /* |
| 1178 | * For WRITE_INSERT, force the error |
| 1179 | * to be sent on the wire. It should be |
| 1180 | * detected by the Target. |
| 1181 | */ |
| 1182 | /* DEADBEEF will be the reftag on the wire */ |
| 1183 | *reftag = 0xDEADBEEF; |
| 1184 | phba->lpfc_injerr_wref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1185 | if (phba->lpfc_injerr_wref_cnt == 0) { |
| 1186 | phba->lpfc_injerr_nportid = 0; |
| 1187 | phba->lpfc_injerr_lba = |
| 1188 | LPFC_INJERR_LBA_OFF; |
| 1189 | memset(&phba->lpfc_injerr_wwpn, |
| 1190 | 0, sizeof(struct lpfc_name)); |
| 1191 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1192 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
| 1193 | |
| 1194 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1195 | "9078 BLKGRD: Injecting reftag error: " |
| 1196 | "write lba x%lx\n", (unsigned long)lba); |
| 1197 | break; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1198 | case SCSI_PROT_WRITE_STRIP: |
| 1199 | /* |
| 1200 | * For WRITE_STRIP and WRITE_PASS, |
| 1201 | * force the error on data |
| 1202 | * being copied from SLI-Host to SLI-Port. |
| 1203 | */ |
| 1204 | *reftag = 0xDEADBEEF; |
| 1205 | phba->lpfc_injerr_wref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1206 | if (phba->lpfc_injerr_wref_cnt == 0) { |
| 1207 | phba->lpfc_injerr_nportid = 0; |
| 1208 | phba->lpfc_injerr_lba = |
| 1209 | LPFC_INJERR_LBA_OFF; |
| 1210 | memset(&phba->lpfc_injerr_wwpn, |
| 1211 | 0, sizeof(struct lpfc_name)); |
| 1212 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1213 | rc = BG_ERR_INIT; |
| 1214 | |
| 1215 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1216 | "9077 BLKGRD: Injecting reftag error: " |
| 1217 | "write lba x%lx\n", (unsigned long)lba); |
| 1218 | break; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1219 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1220 | } |
| 1221 | if (phba->lpfc_injerr_rref_cnt) { |
| 1222 | switch (op) { |
| 1223 | case SCSI_PROT_READ_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1224 | case SCSI_PROT_READ_STRIP: |
| 1225 | case SCSI_PROT_READ_PASS: |
| 1226 | /* |
| 1227 | * For READ_STRIP and READ_PASS, force the |
| 1228 | * error on data being read off the wire. It |
| 1229 | * should force an IO error to the driver. |
| 1230 | */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1231 | *reftag = 0xDEADBEEF; |
| 1232 | phba->lpfc_injerr_rref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1233 | if (phba->lpfc_injerr_rref_cnt == 0) { |
| 1234 | phba->lpfc_injerr_nportid = 0; |
| 1235 | phba->lpfc_injerr_lba = |
| 1236 | LPFC_INJERR_LBA_OFF; |
| 1237 | memset(&phba->lpfc_injerr_wwpn, |
| 1238 | 0, sizeof(struct lpfc_name)); |
| 1239 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1240 | rc = BG_ERR_INIT; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1241 | |
| 1242 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1243 | "9079 BLKGRD: Injecting reftag error: " |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1244 | "read lba x%lx\n", (unsigned long)lba); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1245 | break; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1246 | } |
| 1247 | } |
| 1248 | } |
| 1249 | |
| 1250 | /* Should we change the Application Tag */ |
| 1251 | if (apptag) { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1252 | if (phba->lpfc_injerr_wapp_cnt) { |
| 1253 | switch (op) { |
| 1254 | case SCSI_PROT_WRITE_PASS: |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1255 | if (src) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1256 | /* |
| 1257 | * For WRITE_PASS, force the error |
| 1258 | * to be sent on the wire. It should |
| 1259 | * be detected by the Target. |
| 1260 | * If blockoff != 0 error will be |
| 1261 | * inserted in middle of the IO. |
| 1262 | */ |
| 1263 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1264 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1265 | "9080 BLKGRD: Injecting apptag error: " |
| 1266 | "write lba x%lx + x%x oldappTag x%x\n", |
| 1267 | (unsigned long)lba, blockoff, |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1268 | be16_to_cpu(src->app_tag)); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1269 | |
| 1270 | /* |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1271 | * Save the old app_tag so we can |
| 1272 | * restore it on completion. |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1273 | */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1274 | if (lpfc_cmd) { |
| 1275 | lpfc_cmd->prot_data_type = |
| 1276 | LPFC_INJERR_APPTAG; |
| 1277 | lpfc_cmd->prot_data_segment = |
| 1278 | src; |
| 1279 | lpfc_cmd->prot_data = |
| 1280 | src->app_tag; |
| 1281 | } |
| 1282 | src->app_tag = cpu_to_be16(0xDEAD); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1283 | phba->lpfc_injerr_wapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1284 | if (phba->lpfc_injerr_wapp_cnt == 0) { |
| 1285 | phba->lpfc_injerr_nportid = 0; |
| 1286 | phba->lpfc_injerr_lba = |
| 1287 | LPFC_INJERR_LBA_OFF; |
| 1288 | memset(&phba->lpfc_injerr_wwpn, |
| 1289 | 0, sizeof(struct lpfc_name)); |
| 1290 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1291 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1292 | break; |
| 1293 | } |
| 1294 | /* Drop thru */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1295 | case SCSI_PROT_WRITE_INSERT: |
| 1296 | /* |
| 1297 | * For WRITE_INSERT, force the |
| 1298 | * error to be sent on the wire. It should be |
| 1299 | * detected by the Target. |
| 1300 | */ |
| 1301 | /* DEAD will be the apptag on the wire */ |
| 1302 | *apptag = 0xDEAD; |
| 1303 | phba->lpfc_injerr_wapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1304 | if (phba->lpfc_injerr_wapp_cnt == 0) { |
| 1305 | phba->lpfc_injerr_nportid = 0; |
| 1306 | phba->lpfc_injerr_lba = |
| 1307 | LPFC_INJERR_LBA_OFF; |
| 1308 | memset(&phba->lpfc_injerr_wwpn, |
| 1309 | 0, sizeof(struct lpfc_name)); |
| 1310 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1311 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
| 1312 | |
| 1313 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1314 | "0813 BLKGRD: Injecting apptag error: " |
| 1315 | "write lba x%lx\n", (unsigned long)lba); |
| 1316 | break; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1317 | case SCSI_PROT_WRITE_STRIP: |
| 1318 | /* |
| 1319 | * For WRITE_STRIP and WRITE_PASS, |
| 1320 | * force the error on data |
| 1321 | * being copied from SLI-Host to SLI-Port. |
| 1322 | */ |
| 1323 | *apptag = 0xDEAD; |
| 1324 | phba->lpfc_injerr_wapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1325 | if (phba->lpfc_injerr_wapp_cnt == 0) { |
| 1326 | phba->lpfc_injerr_nportid = 0; |
| 1327 | phba->lpfc_injerr_lba = |
| 1328 | LPFC_INJERR_LBA_OFF; |
| 1329 | memset(&phba->lpfc_injerr_wwpn, |
| 1330 | 0, sizeof(struct lpfc_name)); |
| 1331 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1332 | rc = BG_ERR_INIT; |
| 1333 | |
| 1334 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1335 | "0812 BLKGRD: Injecting apptag error: " |
| 1336 | "write lba x%lx\n", (unsigned long)lba); |
| 1337 | break; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1338 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1339 | } |
| 1340 | if (phba->lpfc_injerr_rapp_cnt) { |
| 1341 | switch (op) { |
| 1342 | case SCSI_PROT_READ_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1343 | case SCSI_PROT_READ_STRIP: |
| 1344 | case SCSI_PROT_READ_PASS: |
| 1345 | /* |
| 1346 | * For READ_STRIP and READ_PASS, force the |
| 1347 | * error on data being read off the wire. It |
| 1348 | * should force an IO error to the driver. |
| 1349 | */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1350 | *apptag = 0xDEAD; |
| 1351 | phba->lpfc_injerr_rapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1352 | if (phba->lpfc_injerr_rapp_cnt == 0) { |
| 1353 | phba->lpfc_injerr_nportid = 0; |
| 1354 | phba->lpfc_injerr_lba = |
| 1355 | LPFC_INJERR_LBA_OFF; |
| 1356 | memset(&phba->lpfc_injerr_wwpn, |
| 1357 | 0, sizeof(struct lpfc_name)); |
| 1358 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1359 | rc = BG_ERR_INIT; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1360 | |
| 1361 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1362 | "0814 BLKGRD: Injecting apptag error: " |
| 1363 | "read lba x%lx\n", (unsigned long)lba); |
| 1364 | break; |
| 1365 | } |
| 1366 | } |
| 1367 | } |
| 1368 | |
| 1369 | |
| 1370 | /* Should we change the Guard Tag */ |
| 1371 | if (new_guard) { |
| 1372 | if (phba->lpfc_injerr_wgrd_cnt) { |
| 1373 | switch (op) { |
| 1374 | case SCSI_PROT_WRITE_PASS: |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1375 | rc = BG_ERR_CHECK; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1376 | /* Drop thru */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1377 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1378 | case SCSI_PROT_WRITE_INSERT: |
| 1379 | /* |
| 1380 | * For WRITE_INSERT, force the |
| 1381 | * error to be sent on the wire. It should be |
| 1382 | * detected by the Target. |
| 1383 | */ |
| 1384 | phba->lpfc_injerr_wgrd_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1385 | if (phba->lpfc_injerr_wgrd_cnt == 0) { |
| 1386 | phba->lpfc_injerr_nportid = 0; |
| 1387 | phba->lpfc_injerr_lba = |
| 1388 | LPFC_INJERR_LBA_OFF; |
| 1389 | memset(&phba->lpfc_injerr_wwpn, |
| 1390 | 0, sizeof(struct lpfc_name)); |
| 1391 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1392 | |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1393 | rc |= BG_ERR_TGT | BG_ERR_SWAP; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1394 | /* Signals the caller to swap CRC->CSUM */ |
| 1395 | |
| 1396 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1397 | "0817 BLKGRD: Injecting guard error: " |
| 1398 | "write lba x%lx\n", (unsigned long)lba); |
| 1399 | break; |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1400 | case SCSI_PROT_WRITE_STRIP: |
| 1401 | /* |
| 1402 | * For WRITE_STRIP and WRITE_PASS, |
| 1403 | * force the error on data |
| 1404 | * being copied from SLI-Host to SLI-Port. |
| 1405 | */ |
| 1406 | phba->lpfc_injerr_wgrd_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1407 | if (phba->lpfc_injerr_wgrd_cnt == 0) { |
| 1408 | phba->lpfc_injerr_nportid = 0; |
| 1409 | phba->lpfc_injerr_lba = |
| 1410 | LPFC_INJERR_LBA_OFF; |
| 1411 | memset(&phba->lpfc_injerr_wwpn, |
| 1412 | 0, sizeof(struct lpfc_name)); |
| 1413 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1414 | |
| 1415 | rc = BG_ERR_INIT | BG_ERR_SWAP; |
| 1416 | /* Signals the caller to swap CRC->CSUM */ |
| 1417 | |
| 1418 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1419 | "0816 BLKGRD: Injecting guard error: " |
| 1420 | "write lba x%lx\n", (unsigned long)lba); |
| 1421 | break; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1422 | } |
| 1423 | } |
| 1424 | if (phba->lpfc_injerr_rgrd_cnt) { |
| 1425 | switch (op) { |
| 1426 | case SCSI_PROT_READ_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1427 | case SCSI_PROT_READ_STRIP: |
| 1428 | case SCSI_PROT_READ_PASS: |
| 1429 | /* |
| 1430 | * For READ_STRIP and READ_PASS, force the |
| 1431 | * error on data being read off the wire. It |
| 1432 | * should force an IO error to the driver. |
| 1433 | */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1434 | phba->lpfc_injerr_rgrd_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1435 | if (phba->lpfc_injerr_rgrd_cnt == 0) { |
| 1436 | phba->lpfc_injerr_nportid = 0; |
| 1437 | phba->lpfc_injerr_lba = |
| 1438 | LPFC_INJERR_LBA_OFF; |
| 1439 | memset(&phba->lpfc_injerr_wwpn, |
| 1440 | 0, sizeof(struct lpfc_name)); |
| 1441 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1442 | |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1443 | rc = BG_ERR_INIT | BG_ERR_SWAP; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1444 | /* Signals the caller to swap CRC->CSUM */ |
| 1445 | |
| 1446 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1447 | "0818 BLKGRD: Injecting guard error: " |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1448 | "read lba x%lx\n", (unsigned long)lba); |
| 1449 | } |
| 1450 | } |
| 1451 | } |
| 1452 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1453 | return rc; |
| 1454 | } |
| 1455 | #endif |
| 1456 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1457 | /** |
| 1458 | * lpfc_sc_to_bg_opcodes - Determine the BlockGuard opcodes to be used with |
| 1459 | * the specified SCSI command. |
| 1460 | * @phba: The Hba for which this call is being executed. |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1461 | * @sc: The SCSI command to examine |
| 1462 | * @txopt: (out) BlockGuard operation for transmitted data |
| 1463 | * @rxopt: (out) BlockGuard operation for received data |
| 1464 | * |
| 1465 | * Returns: zero on success; non-zero if tx and/or rx op cannot be determined |
| 1466 | * |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1467 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1468 | static int |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1469 | lpfc_sc_to_bg_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1470 | uint8_t *txop, uint8_t *rxop) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1471 | { |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1472 | uint8_t ret = 0; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1473 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1474 | if (lpfc_cmd_guard_csum(sc)) { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1475 | switch (scsi_get_prot_op(sc)) { |
| 1476 | case SCSI_PROT_READ_INSERT: |
| 1477 | case SCSI_PROT_WRITE_STRIP: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1478 | *rxop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1479 | *txop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1480 | break; |
| 1481 | |
| 1482 | case SCSI_PROT_READ_STRIP: |
| 1483 | case SCSI_PROT_WRITE_INSERT: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1484 | *rxop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1485 | *txop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1486 | break; |
| 1487 | |
Martin K. Petersen | c6af404 | 2009-09-18 17:32:59 -0400 | [diff] [blame] | 1488 | case SCSI_PROT_READ_PASS: |
| 1489 | case SCSI_PROT_WRITE_PASS: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1490 | *rxop = BG_OP_IN_CRC_OUT_CSUM; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1491 | *txop = BG_OP_IN_CSUM_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1492 | break; |
| 1493 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1494 | case SCSI_PROT_NORMAL: |
| 1495 | default: |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1496 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1497 | "9063 BLKGRD: Bad op/guard:%d/IP combination\n", |
| 1498 | scsi_get_prot_op(sc)); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1499 | ret = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1500 | break; |
| 1501 | |
| 1502 | } |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1503 | } else { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1504 | switch (scsi_get_prot_op(sc)) { |
| 1505 | case SCSI_PROT_READ_STRIP: |
| 1506 | case SCSI_PROT_WRITE_INSERT: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1507 | *rxop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1508 | *txop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1509 | break; |
| 1510 | |
| 1511 | case SCSI_PROT_READ_PASS: |
| 1512 | case SCSI_PROT_WRITE_PASS: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1513 | *rxop = BG_OP_IN_CRC_OUT_CRC; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1514 | *txop = BG_OP_IN_CRC_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1515 | break; |
| 1516 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1517 | case SCSI_PROT_READ_INSERT: |
| 1518 | case SCSI_PROT_WRITE_STRIP: |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1519 | *rxop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1520 | *txop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1521 | break; |
| 1522 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1523 | case SCSI_PROT_NORMAL: |
| 1524 | default: |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1525 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1526 | "9075 BLKGRD: Bad op/guard:%d/CRC combination\n", |
| 1527 | scsi_get_prot_op(sc)); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1528 | ret = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1529 | break; |
| 1530 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1531 | } |
| 1532 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1533 | return ret; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1534 | } |
| 1535 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1536 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 1537 | /** |
| 1538 | * lpfc_bg_err_opcodes - reDetermine the BlockGuard opcodes to be used with |
| 1539 | * the specified SCSI command in order to force a guard tag error. |
| 1540 | * @phba: The Hba for which this call is being executed. |
| 1541 | * @sc: The SCSI command to examine |
| 1542 | * @txopt: (out) BlockGuard operation for transmitted data |
| 1543 | * @rxopt: (out) BlockGuard operation for received data |
| 1544 | * |
| 1545 | * Returns: zero on success; non-zero if tx and/or rx op cannot be determined |
| 1546 | * |
| 1547 | **/ |
| 1548 | static int |
| 1549 | lpfc_bg_err_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1550 | uint8_t *txop, uint8_t *rxop) |
| 1551 | { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1552 | uint8_t ret = 0; |
| 1553 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1554 | if (lpfc_cmd_guard_csum(sc)) { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1555 | switch (scsi_get_prot_op(sc)) { |
| 1556 | case SCSI_PROT_READ_INSERT: |
| 1557 | case SCSI_PROT_WRITE_STRIP: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1558 | *rxop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1559 | *txop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1560 | break; |
| 1561 | |
| 1562 | case SCSI_PROT_READ_STRIP: |
| 1563 | case SCSI_PROT_WRITE_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1564 | *rxop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1565 | *txop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1566 | break; |
| 1567 | |
| 1568 | case SCSI_PROT_READ_PASS: |
| 1569 | case SCSI_PROT_WRITE_PASS: |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1570 | *rxop = BG_OP_IN_CSUM_OUT_CRC; |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1571 | *txop = BG_OP_IN_CRC_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1572 | break; |
| 1573 | |
| 1574 | case SCSI_PROT_NORMAL: |
| 1575 | default: |
| 1576 | break; |
| 1577 | |
| 1578 | } |
| 1579 | } else { |
| 1580 | switch (scsi_get_prot_op(sc)) { |
| 1581 | case SCSI_PROT_READ_STRIP: |
| 1582 | case SCSI_PROT_WRITE_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1583 | *rxop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1584 | *txop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1585 | break; |
| 1586 | |
| 1587 | case SCSI_PROT_READ_PASS: |
| 1588 | case SCSI_PROT_WRITE_PASS: |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1589 | *rxop = BG_OP_IN_CSUM_OUT_CSUM; |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1590 | *txop = BG_OP_IN_CSUM_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1591 | break; |
| 1592 | |
| 1593 | case SCSI_PROT_READ_INSERT: |
| 1594 | case SCSI_PROT_WRITE_STRIP: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1595 | *rxop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1596 | *txop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1597 | break; |
| 1598 | |
| 1599 | case SCSI_PROT_NORMAL: |
| 1600 | default: |
| 1601 | break; |
| 1602 | } |
| 1603 | } |
| 1604 | |
| 1605 | return ret; |
| 1606 | } |
| 1607 | #endif |
| 1608 | |
| 1609 | /** |
| 1610 | * lpfc_bg_setup_bpl - Setup BlockGuard BPL with no protection data |
| 1611 | * @phba: The Hba for which this call is being executed. |
| 1612 | * @sc: pointer to scsi command we're working on |
| 1613 | * @bpl: pointer to buffer list for protection groups |
| 1614 | * @datacnt: number of segments of data that have been dma mapped |
| 1615 | * |
| 1616 | * This function sets up BPL buffer list for protection groups of |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1617 | * type LPFC_PG_TYPE_NO_DIF |
| 1618 | * |
| 1619 | * This is usually used when the HBA is instructed to generate |
| 1620 | * DIFs and insert them into data stream (or strip DIF from |
| 1621 | * incoming data stream) |
| 1622 | * |
| 1623 | * The buffer list consists of just one protection group described |
| 1624 | * below: |
| 1625 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1626 | * start of prot group --> | PDE_5 | |
| 1627 | * +-------------------------+ |
| 1628 | * | PDE_6 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1629 | * +-------------------------+ |
| 1630 | * | Data BDE | |
| 1631 | * +-------------------------+ |
| 1632 | * |more Data BDE's ... (opt)| |
| 1633 | * +-------------------------+ |
| 1634 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1635 | * |
| 1636 | * Note: Data s/g buffers have been dma mapped |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1637 | * |
| 1638 | * Returns the number of BDEs added to the BPL. |
| 1639 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1640 | static int |
| 1641 | lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1642 | struct ulp_bde64 *bpl, int datasegcnt) |
| 1643 | { |
| 1644 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1645 | struct lpfc_pde5 *pde5 = NULL; |
| 1646 | struct lpfc_pde6 *pde6 = NULL; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1647 | dma_addr_t physaddr; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1648 | int i = 0, num_bde = 0, status; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1649 | int datadir = sc->sc_data_direction; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 1650 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1651 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 1652 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1653 | uint32_t checking = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1654 | uint32_t reftag; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1655 | uint8_t txop, rxop; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1656 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1657 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 1658 | if (status) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1659 | goto out; |
| 1660 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1661 | /* extract some info from the scsi command for pde*/ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1662 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1663 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1664 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1665 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1666 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1667 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1668 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1669 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1670 | checking = 0; |
| 1671 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1672 | #endif |
| 1673 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1674 | /* setup PDE5 with what we have */ |
| 1675 | pde5 = (struct lpfc_pde5 *) bpl; |
| 1676 | memset(pde5, 0, sizeof(struct lpfc_pde5)); |
| 1677 | bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1678 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1679 | /* Endianness conversion if necessary for PDE5 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1680 | pde5->word0 = cpu_to_le32(pde5->word0); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1681 | pde5->reftag = cpu_to_le32(reftag); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1682 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1683 | /* advance bpl and increment bde count */ |
| 1684 | num_bde++; |
| 1685 | bpl++; |
| 1686 | pde6 = (struct lpfc_pde6 *) bpl; |
| 1687 | |
| 1688 | /* setup PDE6 with the rest of the info */ |
| 1689 | memset(pde6, 0, sizeof(struct lpfc_pde6)); |
| 1690 | bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR); |
| 1691 | bf_set(pde6_optx, pde6, txop); |
| 1692 | bf_set(pde6_oprx, pde6, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1693 | |
| 1694 | /* |
| 1695 | * We only need to check the data on READs, for WRITEs |
| 1696 | * protection data is automatically generated, not checked. |
| 1697 | */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1698 | if (datadir == DMA_FROM_DEVICE) { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1699 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1700 | bf_set(pde6_ce, pde6, checking); |
| 1701 | else |
| 1702 | bf_set(pde6_ce, pde6, 0); |
| 1703 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1704 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1705 | bf_set(pde6_re, pde6, checking); |
| 1706 | else |
| 1707 | bf_set(pde6_re, pde6, 0); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1708 | } |
| 1709 | bf_set(pde6_ai, pde6, 1); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1710 | bf_set(pde6_ae, pde6, 0); |
| 1711 | bf_set(pde6_apptagval, pde6, 0); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1712 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1713 | /* Endianness conversion if necessary for PDE6 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1714 | pde6->word0 = cpu_to_le32(pde6->word0); |
| 1715 | pde6->word1 = cpu_to_le32(pde6->word1); |
| 1716 | pde6->word2 = cpu_to_le32(pde6->word2); |
| 1717 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1718 | /* advance bpl and increment bde count */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1719 | num_bde++; |
| 1720 | bpl++; |
| 1721 | |
| 1722 | /* assumption: caller has already run dma_map_sg on command data */ |
| 1723 | scsi_for_each_sg(sc, sgde, datasegcnt, i) { |
| 1724 | physaddr = sg_dma_address(sgde); |
| 1725 | bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
| 1726 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 1727 | bpl->tus.f.bdeSize = sg_dma_len(sgde); |
| 1728 | if (datadir == DMA_TO_DEVICE) |
| 1729 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1730 | else |
| 1731 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
| 1732 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 1733 | bpl++; |
| 1734 | num_bde++; |
| 1735 | } |
| 1736 | |
| 1737 | out: |
| 1738 | return num_bde; |
| 1739 | } |
| 1740 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1741 | /** |
| 1742 | * lpfc_bg_setup_bpl_prot - Setup BlockGuard BPL with protection data |
| 1743 | * @phba: The Hba for which this call is being executed. |
| 1744 | * @sc: pointer to scsi command we're working on |
| 1745 | * @bpl: pointer to buffer list for protection groups |
| 1746 | * @datacnt: number of segments of data that have been dma mapped |
| 1747 | * @protcnt: number of segment of protection data that have been dma mapped |
| 1748 | * |
| 1749 | * This function sets up BPL buffer list for protection groups of |
| 1750 | * type LPFC_PG_TYPE_DIF |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1751 | * |
| 1752 | * This is usually used when DIFs are in their own buffers, |
| 1753 | * separate from the data. The HBA can then by instructed |
| 1754 | * to place the DIFs in the outgoing stream. For read operations, |
| 1755 | * The HBA could extract the DIFs and place it in DIF buffers. |
| 1756 | * |
| 1757 | * The buffer list for this type consists of one or more of the |
| 1758 | * protection groups described below: |
| 1759 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1760 | * start of first prot group --> | PDE_5 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1761 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1762 | * | PDE_6 | |
| 1763 | * +-------------------------+ |
| 1764 | * | PDE_7 (Prot BDE) | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1765 | * +-------------------------+ |
| 1766 | * | Data BDE | |
| 1767 | * +-------------------------+ |
| 1768 | * |more Data BDE's ... (opt)| |
| 1769 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1770 | * start of new prot group --> | PDE_5 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1771 | * +-------------------------+ |
| 1772 | * | ... | |
| 1773 | * +-------------------------+ |
| 1774 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1775 | * Note: It is assumed that both data and protection s/g buffers have been |
| 1776 | * mapped for DMA |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1777 | * |
| 1778 | * Returns the number of BDEs added to the BPL. |
| 1779 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1780 | static int |
| 1781 | lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1782 | struct ulp_bde64 *bpl, int datacnt, int protcnt) |
| 1783 | { |
| 1784 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 1785 | struct scatterlist *sgpe = NULL; /* s/g prot entry */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1786 | struct lpfc_pde5 *pde5 = NULL; |
| 1787 | struct lpfc_pde6 *pde6 = NULL; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1788 | struct lpfc_pde7 *pde7 = NULL; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1789 | dma_addr_t dataphysaddr, protphysaddr; |
| 1790 | unsigned short curr_data = 0, curr_prot = 0; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1791 | unsigned int split_offset; |
| 1792 | unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1793 | unsigned int protgrp_blks, protgrp_bytes; |
| 1794 | unsigned int remainder, subtotal; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1795 | int status; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1796 | int datadir = sc->sc_data_direction; |
| 1797 | unsigned char pgdone = 0, alldone = 0; |
| 1798 | unsigned blksize; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 1799 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1800 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 1801 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1802 | uint32_t checking = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1803 | uint32_t reftag; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1804 | uint8_t txop, rxop; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1805 | int num_bde = 0; |
| 1806 | |
| 1807 | sgpe = scsi_prot_sglist(sc); |
| 1808 | sgde = scsi_sglist(sc); |
| 1809 | |
| 1810 | if (!sgpe || !sgde) { |
| 1811 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 1812 | "9020 Invalid s/g entry: data=0x%p prot=0x%p\n", |
| 1813 | sgpe, sgde); |
| 1814 | return 0; |
| 1815 | } |
| 1816 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1817 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 1818 | if (status) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1819 | goto out; |
| 1820 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1821 | /* extract some info from the scsi command */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1822 | blksize = lpfc_cmd_blksize(sc); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1823 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1824 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1825 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1826 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1827 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1828 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1829 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1830 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1831 | checking = 0; |
| 1832 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1833 | #endif |
| 1834 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1835 | split_offset = 0; |
| 1836 | do { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 1837 | /* Check to see if we ran out of space */ |
| 1838 | if (num_bde >= (phba->cfg_total_seg_cnt - 2)) |
| 1839 | return num_bde + 3; |
| 1840 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1841 | /* setup PDE5 with what we have */ |
| 1842 | pde5 = (struct lpfc_pde5 *) bpl; |
| 1843 | memset(pde5, 0, sizeof(struct lpfc_pde5)); |
| 1844 | bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1845 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1846 | /* Endianness conversion if necessary for PDE5 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1847 | pde5->word0 = cpu_to_le32(pde5->word0); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1848 | pde5->reftag = cpu_to_le32(reftag); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1849 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1850 | /* advance bpl and increment bde count */ |
| 1851 | num_bde++; |
| 1852 | bpl++; |
| 1853 | pde6 = (struct lpfc_pde6 *) bpl; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1854 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1855 | /* setup PDE6 with the rest of the info */ |
| 1856 | memset(pde6, 0, sizeof(struct lpfc_pde6)); |
| 1857 | bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR); |
| 1858 | bf_set(pde6_optx, pde6, txop); |
| 1859 | bf_set(pde6_oprx, pde6, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1860 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1861 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1862 | bf_set(pde6_ce, pde6, checking); |
| 1863 | else |
| 1864 | bf_set(pde6_ce, pde6, 0); |
| 1865 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1866 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1867 | bf_set(pde6_re, pde6, checking); |
| 1868 | else |
| 1869 | bf_set(pde6_re, pde6, 0); |
| 1870 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1871 | bf_set(pde6_ai, pde6, 1); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1872 | bf_set(pde6_ae, pde6, 0); |
| 1873 | bf_set(pde6_apptagval, pde6, 0); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1874 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1875 | /* Endianness conversion if necessary for PDE6 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1876 | pde6->word0 = cpu_to_le32(pde6->word0); |
| 1877 | pde6->word1 = cpu_to_le32(pde6->word1); |
| 1878 | pde6->word2 = cpu_to_le32(pde6->word2); |
| 1879 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1880 | /* advance bpl and increment bde count */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1881 | num_bde++; |
| 1882 | bpl++; |
| 1883 | |
| 1884 | /* setup the first BDE that points to protection buffer */ |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1885 | protphysaddr = sg_dma_address(sgpe) + protgroup_offset; |
| 1886 | protgroup_len = sg_dma_len(sgpe) - protgroup_offset; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1887 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1888 | /* must be integer multiple of the DIF block length */ |
| 1889 | BUG_ON(protgroup_len % 8); |
| 1890 | |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1891 | pde7 = (struct lpfc_pde7 *) bpl; |
| 1892 | memset(pde7, 0, sizeof(struct lpfc_pde7)); |
| 1893 | bf_set(pde7_type, pde7, LPFC_PDE7_DESCRIPTOR); |
| 1894 | |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1895 | pde7->addrHigh = le32_to_cpu(putPaddrHigh(protphysaddr)); |
| 1896 | pde7->addrLow = le32_to_cpu(putPaddrLow(protphysaddr)); |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1897 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1898 | protgrp_blks = protgroup_len / 8; |
| 1899 | protgrp_bytes = protgrp_blks * blksize; |
| 1900 | |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1901 | /* check if this pde is crossing the 4K boundary; if so split */ |
| 1902 | if ((pde7->addrLow & 0xfff) + protgroup_len > 0x1000) { |
| 1903 | protgroup_remainder = 0x1000 - (pde7->addrLow & 0xfff); |
| 1904 | protgroup_offset += protgroup_remainder; |
| 1905 | protgrp_blks = protgroup_remainder / 8; |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1906 | protgrp_bytes = protgrp_blks * blksize; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1907 | } else { |
| 1908 | protgroup_offset = 0; |
| 1909 | curr_prot++; |
| 1910 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1911 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1912 | num_bde++; |
| 1913 | |
| 1914 | /* setup BDE's for data blocks associated with DIF data */ |
| 1915 | pgdone = 0; |
| 1916 | subtotal = 0; /* total bytes processed for current prot grp */ |
| 1917 | while (!pgdone) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 1918 | /* Check to see if we ran out of space */ |
| 1919 | if (num_bde >= phba->cfg_total_seg_cnt) |
| 1920 | return num_bde + 1; |
| 1921 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1922 | if (!sgde) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1923 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1924 | "9065 BLKGRD:%s Invalid data segment\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1925 | __func__); |
| 1926 | return 0; |
| 1927 | } |
| 1928 | bpl++; |
| 1929 | dataphysaddr = sg_dma_address(sgde) + split_offset; |
| 1930 | bpl->addrLow = le32_to_cpu(putPaddrLow(dataphysaddr)); |
| 1931 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(dataphysaddr)); |
| 1932 | |
| 1933 | remainder = sg_dma_len(sgde) - split_offset; |
| 1934 | |
| 1935 | if ((subtotal + remainder) <= protgrp_bytes) { |
| 1936 | /* we can use this whole buffer */ |
| 1937 | bpl->tus.f.bdeSize = remainder; |
| 1938 | split_offset = 0; |
| 1939 | |
| 1940 | if ((subtotal + remainder) == protgrp_bytes) |
| 1941 | pgdone = 1; |
| 1942 | } else { |
| 1943 | /* must split this buffer with next prot grp */ |
| 1944 | bpl->tus.f.bdeSize = protgrp_bytes - subtotal; |
| 1945 | split_offset += bpl->tus.f.bdeSize; |
| 1946 | } |
| 1947 | |
| 1948 | subtotal += bpl->tus.f.bdeSize; |
| 1949 | |
| 1950 | if (datadir == DMA_TO_DEVICE) |
| 1951 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1952 | else |
| 1953 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
| 1954 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 1955 | |
| 1956 | num_bde++; |
| 1957 | curr_data++; |
| 1958 | |
| 1959 | if (split_offset) |
| 1960 | break; |
| 1961 | |
| 1962 | /* Move to the next s/g segment if possible */ |
| 1963 | sgde = sg_next(sgde); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1964 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1965 | } |
| 1966 | |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1967 | if (protgroup_offset) { |
| 1968 | /* update the reference tag */ |
| 1969 | reftag += protgrp_blks; |
| 1970 | bpl++; |
| 1971 | continue; |
| 1972 | } |
| 1973 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1974 | /* are we done ? */ |
| 1975 | if (curr_prot == protcnt) { |
| 1976 | alldone = 1; |
| 1977 | } else if (curr_prot < protcnt) { |
| 1978 | /* advance to next prot buffer */ |
| 1979 | sgpe = sg_next(sgpe); |
| 1980 | bpl++; |
| 1981 | |
| 1982 | /* update the reference tag */ |
| 1983 | reftag += protgrp_blks; |
| 1984 | } else { |
| 1985 | /* if we're here, we have a bug */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1986 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1987 | "9054 BLKGRD: bug in %s\n", __func__); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1988 | } |
| 1989 | |
| 1990 | } while (!alldone); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1991 | out: |
| 1992 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1993 | return num_bde; |
| 1994 | } |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1995 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1996 | /** |
| 1997 | * lpfc_bg_setup_sgl - Setup BlockGuard SGL with no protection data |
| 1998 | * @phba: The Hba for which this call is being executed. |
| 1999 | * @sc: pointer to scsi command we're working on |
| 2000 | * @sgl: pointer to buffer list for protection groups |
| 2001 | * @datacnt: number of segments of data that have been dma mapped |
| 2002 | * |
| 2003 | * This function sets up SGL buffer list for protection groups of |
| 2004 | * type LPFC_PG_TYPE_NO_DIF |
| 2005 | * |
| 2006 | * This is usually used when the HBA is instructed to generate |
| 2007 | * DIFs and insert them into data stream (or strip DIF from |
| 2008 | * incoming data stream) |
| 2009 | * |
| 2010 | * The buffer list consists of just one protection group described |
| 2011 | * below: |
| 2012 | * +-------------------------+ |
| 2013 | * start of prot group --> | DI_SEED | |
| 2014 | * +-------------------------+ |
| 2015 | * | Data SGE | |
| 2016 | * +-------------------------+ |
| 2017 | * |more Data SGE's ... (opt)| |
| 2018 | * +-------------------------+ |
| 2019 | * |
| 2020 | * |
| 2021 | * Note: Data s/g buffers have been dma mapped |
| 2022 | * |
| 2023 | * Returns the number of SGEs added to the SGL. |
| 2024 | **/ |
| 2025 | static int |
| 2026 | lpfc_bg_setup_sgl(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 2027 | struct sli4_sge *sgl, int datasegcnt) |
| 2028 | { |
| 2029 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 2030 | struct sli4_sge_diseed *diseed = NULL; |
| 2031 | dma_addr_t physaddr; |
| 2032 | int i = 0, num_sge = 0, status; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2033 | uint32_t reftag; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2034 | uint8_t txop, rxop; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2035 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2036 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2037 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2038 | uint32_t checking = 1; |
| 2039 | uint32_t dma_len; |
| 2040 | uint32_t dma_offset = 0; |
| 2041 | |
| 2042 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 2043 | if (status) |
| 2044 | goto out; |
| 2045 | |
| 2046 | /* extract some info from the scsi command for pde*/ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2047 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
| 2048 | |
| 2049 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 2050 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2051 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2052 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2053 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2054 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2055 | checking = 0; |
| 2056 | } |
| 2057 | #endif |
| 2058 | |
| 2059 | /* setup DISEED with what we have */ |
| 2060 | diseed = (struct sli4_sge_diseed *) sgl; |
| 2061 | memset(diseed, 0, sizeof(struct sli4_sge_diseed)); |
| 2062 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED); |
| 2063 | |
| 2064 | /* Endianness conversion if necessary */ |
| 2065 | diseed->ref_tag = cpu_to_le32(reftag); |
| 2066 | diseed->ref_tag_tran = diseed->ref_tag; |
| 2067 | |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2068 | /* |
| 2069 | * We only need to check the data on READs, for WRITEs |
| 2070 | * protection data is automatically generated, not checked. |
| 2071 | */ |
| 2072 | if (sc->sc_data_direction == DMA_FROM_DEVICE) { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2073 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2074 | bf_set(lpfc_sli4_sge_dif_ce, diseed, checking); |
| 2075 | else |
| 2076 | bf_set(lpfc_sli4_sge_dif_ce, diseed, 0); |
| 2077 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2078 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2079 | bf_set(lpfc_sli4_sge_dif_re, diseed, checking); |
| 2080 | else |
| 2081 | bf_set(lpfc_sli4_sge_dif_re, diseed, 0); |
| 2082 | } |
| 2083 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2084 | /* setup DISEED with the rest of the info */ |
| 2085 | bf_set(lpfc_sli4_sge_dif_optx, diseed, txop); |
| 2086 | bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2087 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2088 | bf_set(lpfc_sli4_sge_dif_ai, diseed, 1); |
| 2089 | bf_set(lpfc_sli4_sge_dif_me, diseed, 0); |
| 2090 | |
| 2091 | /* Endianness conversion if necessary for DISEED */ |
| 2092 | diseed->word2 = cpu_to_le32(diseed->word2); |
| 2093 | diseed->word3 = cpu_to_le32(diseed->word3); |
| 2094 | |
| 2095 | /* advance bpl and increment sge count */ |
| 2096 | num_sge++; |
| 2097 | sgl++; |
| 2098 | |
| 2099 | /* assumption: caller has already run dma_map_sg on command data */ |
| 2100 | scsi_for_each_sg(sc, sgde, datasegcnt, i) { |
| 2101 | physaddr = sg_dma_address(sgde); |
| 2102 | dma_len = sg_dma_len(sgde); |
| 2103 | sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr)); |
| 2104 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr)); |
| 2105 | if ((i + 1) == datasegcnt) |
| 2106 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 2107 | else |
| 2108 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 2109 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
| 2110 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); |
| 2111 | |
| 2112 | sgl->sge_len = cpu_to_le32(dma_len); |
| 2113 | dma_offset += dma_len; |
| 2114 | |
| 2115 | sgl++; |
| 2116 | num_sge++; |
| 2117 | } |
| 2118 | |
| 2119 | out: |
| 2120 | return num_sge; |
| 2121 | } |
| 2122 | |
| 2123 | /** |
| 2124 | * lpfc_bg_setup_sgl_prot - Setup BlockGuard SGL with protection data |
| 2125 | * @phba: The Hba for which this call is being executed. |
| 2126 | * @sc: pointer to scsi command we're working on |
| 2127 | * @sgl: pointer to buffer list for protection groups |
| 2128 | * @datacnt: number of segments of data that have been dma mapped |
| 2129 | * @protcnt: number of segment of protection data that have been dma mapped |
| 2130 | * |
| 2131 | * This function sets up SGL buffer list for protection groups of |
| 2132 | * type LPFC_PG_TYPE_DIF |
| 2133 | * |
| 2134 | * This is usually used when DIFs are in their own buffers, |
| 2135 | * separate from the data. The HBA can then by instructed |
| 2136 | * to place the DIFs in the outgoing stream. For read operations, |
| 2137 | * The HBA could extract the DIFs and place it in DIF buffers. |
| 2138 | * |
| 2139 | * The buffer list for this type consists of one or more of the |
| 2140 | * protection groups described below: |
| 2141 | * +-------------------------+ |
| 2142 | * start of first prot group --> | DISEED | |
| 2143 | * +-------------------------+ |
| 2144 | * | DIF (Prot SGE) | |
| 2145 | * +-------------------------+ |
| 2146 | * | Data SGE | |
| 2147 | * +-------------------------+ |
| 2148 | * |more Data SGE's ... (opt)| |
| 2149 | * +-------------------------+ |
| 2150 | * start of new prot group --> | DISEED | |
| 2151 | * +-------------------------+ |
| 2152 | * | ... | |
| 2153 | * +-------------------------+ |
| 2154 | * |
| 2155 | * Note: It is assumed that both data and protection s/g buffers have been |
| 2156 | * mapped for DMA |
| 2157 | * |
| 2158 | * Returns the number of SGEs added to the SGL. |
| 2159 | **/ |
| 2160 | static int |
| 2161 | lpfc_bg_setup_sgl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 2162 | struct sli4_sge *sgl, int datacnt, int protcnt) |
| 2163 | { |
| 2164 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 2165 | struct scatterlist *sgpe = NULL; /* s/g prot entry */ |
| 2166 | struct sli4_sge_diseed *diseed = NULL; |
| 2167 | dma_addr_t dataphysaddr, protphysaddr; |
| 2168 | unsigned short curr_data = 0, curr_prot = 0; |
| 2169 | unsigned int split_offset; |
| 2170 | unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder; |
| 2171 | unsigned int protgrp_blks, protgrp_bytes; |
| 2172 | unsigned int remainder, subtotal; |
| 2173 | int status; |
| 2174 | unsigned char pgdone = 0, alldone = 0; |
| 2175 | unsigned blksize; |
| 2176 | uint32_t reftag; |
| 2177 | uint8_t txop, rxop; |
| 2178 | uint32_t dma_len; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2179 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2180 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2181 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2182 | uint32_t checking = 1; |
| 2183 | uint32_t dma_offset = 0; |
| 2184 | int num_sge = 0; |
| 2185 | |
| 2186 | sgpe = scsi_prot_sglist(sc); |
| 2187 | sgde = scsi_sglist(sc); |
| 2188 | |
| 2189 | if (!sgpe || !sgde) { |
| 2190 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2191 | "9082 Invalid s/g entry: data=0x%p prot=0x%p\n", |
| 2192 | sgpe, sgde); |
| 2193 | return 0; |
| 2194 | } |
| 2195 | |
| 2196 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 2197 | if (status) |
| 2198 | goto out; |
| 2199 | |
| 2200 | /* extract some info from the scsi command */ |
| 2201 | blksize = lpfc_cmd_blksize(sc); |
| 2202 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
| 2203 | |
| 2204 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 2205 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2206 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2207 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2208 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2209 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2210 | checking = 0; |
| 2211 | } |
| 2212 | #endif |
| 2213 | |
| 2214 | split_offset = 0; |
| 2215 | do { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2216 | /* Check to see if we ran out of space */ |
| 2217 | if (num_sge >= (phba->cfg_total_seg_cnt - 2)) |
| 2218 | return num_sge + 3; |
| 2219 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2220 | /* setup DISEED with what we have */ |
| 2221 | diseed = (struct sli4_sge_diseed *) sgl; |
| 2222 | memset(diseed, 0, sizeof(struct sli4_sge_diseed)); |
| 2223 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED); |
| 2224 | |
| 2225 | /* Endianness conversion if necessary */ |
| 2226 | diseed->ref_tag = cpu_to_le32(reftag); |
| 2227 | diseed->ref_tag_tran = diseed->ref_tag; |
| 2228 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2229 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) { |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2230 | bf_set(lpfc_sli4_sge_dif_ce, diseed, checking); |
| 2231 | |
| 2232 | } else { |
| 2233 | bf_set(lpfc_sli4_sge_dif_ce, diseed, 0); |
| 2234 | /* |
| 2235 | * When in this mode, the hardware will replace |
| 2236 | * the guard tag from the host with a |
| 2237 | * newly generated good CRC for the wire. |
| 2238 | * Switch to raw mode here to avoid this |
| 2239 | * behavior. What the host sends gets put on the wire. |
| 2240 | */ |
| 2241 | if (txop == BG_OP_IN_CRC_OUT_CRC) { |
| 2242 | txop = BG_OP_RAW_MODE; |
| 2243 | rxop = BG_OP_RAW_MODE; |
| 2244 | } |
| 2245 | } |
| 2246 | |
| 2247 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2248 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2249 | bf_set(lpfc_sli4_sge_dif_re, diseed, checking); |
| 2250 | else |
| 2251 | bf_set(lpfc_sli4_sge_dif_re, diseed, 0); |
| 2252 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2253 | /* setup DISEED with the rest of the info */ |
| 2254 | bf_set(lpfc_sli4_sge_dif_optx, diseed, txop); |
| 2255 | bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2256 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2257 | bf_set(lpfc_sli4_sge_dif_ai, diseed, 1); |
| 2258 | bf_set(lpfc_sli4_sge_dif_me, diseed, 0); |
| 2259 | |
| 2260 | /* Endianness conversion if necessary for DISEED */ |
| 2261 | diseed->word2 = cpu_to_le32(diseed->word2); |
| 2262 | diseed->word3 = cpu_to_le32(diseed->word3); |
| 2263 | |
| 2264 | /* advance sgl and increment bde count */ |
| 2265 | num_sge++; |
| 2266 | sgl++; |
| 2267 | |
| 2268 | /* setup the first BDE that points to protection buffer */ |
| 2269 | protphysaddr = sg_dma_address(sgpe) + protgroup_offset; |
| 2270 | protgroup_len = sg_dma_len(sgpe) - protgroup_offset; |
| 2271 | |
| 2272 | /* must be integer multiple of the DIF block length */ |
| 2273 | BUG_ON(protgroup_len % 8); |
| 2274 | |
| 2275 | /* Now setup DIF SGE */ |
| 2276 | sgl->word2 = 0; |
| 2277 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DIF); |
| 2278 | sgl->addr_hi = le32_to_cpu(putPaddrHigh(protphysaddr)); |
| 2279 | sgl->addr_lo = le32_to_cpu(putPaddrLow(protphysaddr)); |
| 2280 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 2281 | |
| 2282 | protgrp_blks = protgroup_len / 8; |
| 2283 | protgrp_bytes = protgrp_blks * blksize; |
| 2284 | |
| 2285 | /* check if DIF SGE is crossing the 4K boundary; if so split */ |
| 2286 | if ((sgl->addr_lo & 0xfff) + protgroup_len > 0x1000) { |
| 2287 | protgroup_remainder = 0x1000 - (sgl->addr_lo & 0xfff); |
| 2288 | protgroup_offset += protgroup_remainder; |
| 2289 | protgrp_blks = protgroup_remainder / 8; |
| 2290 | protgrp_bytes = protgrp_blks * blksize; |
| 2291 | } else { |
| 2292 | protgroup_offset = 0; |
| 2293 | curr_prot++; |
| 2294 | } |
| 2295 | |
| 2296 | num_sge++; |
| 2297 | |
| 2298 | /* setup SGE's for data blocks associated with DIF data */ |
| 2299 | pgdone = 0; |
| 2300 | subtotal = 0; /* total bytes processed for current prot grp */ |
| 2301 | while (!pgdone) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2302 | /* Check to see if we ran out of space */ |
| 2303 | if (num_sge >= phba->cfg_total_seg_cnt) |
| 2304 | return num_sge + 1; |
| 2305 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2306 | if (!sgde) { |
| 2307 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2308 | "9086 BLKGRD:%s Invalid data segment\n", |
| 2309 | __func__); |
| 2310 | return 0; |
| 2311 | } |
| 2312 | sgl++; |
| 2313 | dataphysaddr = sg_dma_address(sgde) + split_offset; |
| 2314 | |
| 2315 | remainder = sg_dma_len(sgde) - split_offset; |
| 2316 | |
| 2317 | if ((subtotal + remainder) <= protgrp_bytes) { |
| 2318 | /* we can use this whole buffer */ |
| 2319 | dma_len = remainder; |
| 2320 | split_offset = 0; |
| 2321 | |
| 2322 | if ((subtotal + remainder) == protgrp_bytes) |
| 2323 | pgdone = 1; |
| 2324 | } else { |
| 2325 | /* must split this buffer with next prot grp */ |
| 2326 | dma_len = protgrp_bytes - subtotal; |
| 2327 | split_offset += dma_len; |
| 2328 | } |
| 2329 | |
| 2330 | subtotal += dma_len; |
| 2331 | |
| 2332 | sgl->addr_lo = cpu_to_le32(putPaddrLow(dataphysaddr)); |
| 2333 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(dataphysaddr)); |
| 2334 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 2335 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
| 2336 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); |
| 2337 | |
| 2338 | sgl->sge_len = cpu_to_le32(dma_len); |
| 2339 | dma_offset += dma_len; |
| 2340 | |
| 2341 | num_sge++; |
| 2342 | curr_data++; |
| 2343 | |
| 2344 | if (split_offset) |
| 2345 | break; |
| 2346 | |
| 2347 | /* Move to the next s/g segment if possible */ |
| 2348 | sgde = sg_next(sgde); |
| 2349 | } |
| 2350 | |
| 2351 | if (protgroup_offset) { |
| 2352 | /* update the reference tag */ |
| 2353 | reftag += protgrp_blks; |
| 2354 | sgl++; |
| 2355 | continue; |
| 2356 | } |
| 2357 | |
| 2358 | /* are we done ? */ |
| 2359 | if (curr_prot == protcnt) { |
| 2360 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 2361 | alldone = 1; |
| 2362 | } else if (curr_prot < protcnt) { |
| 2363 | /* advance to next prot buffer */ |
| 2364 | sgpe = sg_next(sgpe); |
| 2365 | sgl++; |
| 2366 | |
| 2367 | /* update the reference tag */ |
| 2368 | reftag += protgrp_blks; |
| 2369 | } else { |
| 2370 | /* if we're here, we have a bug */ |
| 2371 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2372 | "9085 BLKGRD: bug in %s\n", __func__); |
| 2373 | } |
| 2374 | |
| 2375 | } while (!alldone); |
| 2376 | |
| 2377 | out: |
| 2378 | |
| 2379 | return num_sge; |
| 2380 | } |
| 2381 | |
| 2382 | /** |
| 2383 | * lpfc_prot_group_type - Get prtotection group type of SCSI command |
| 2384 | * @phba: The Hba for which this call is being executed. |
| 2385 | * @sc: pointer to scsi command we're working on |
| 2386 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2387 | * Given a SCSI command that supports DIF, determine composition of protection |
| 2388 | * groups involved in setting up buffer lists |
| 2389 | * |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2390 | * Returns: Protection group type (with or without DIF) |
| 2391 | * |
| 2392 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2393 | static int |
| 2394 | lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc) |
| 2395 | { |
| 2396 | int ret = LPFC_PG_TYPE_INVALID; |
| 2397 | unsigned char op = scsi_get_prot_op(sc); |
| 2398 | |
| 2399 | switch (op) { |
| 2400 | case SCSI_PROT_READ_STRIP: |
| 2401 | case SCSI_PROT_WRITE_INSERT: |
| 2402 | ret = LPFC_PG_TYPE_NO_DIF; |
| 2403 | break; |
| 2404 | case SCSI_PROT_READ_INSERT: |
| 2405 | case SCSI_PROT_WRITE_STRIP: |
| 2406 | case SCSI_PROT_READ_PASS: |
| 2407 | case SCSI_PROT_WRITE_PASS: |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2408 | ret = LPFC_PG_TYPE_DIF_BUF; |
| 2409 | break; |
| 2410 | default: |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2411 | if (phba) |
| 2412 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2413 | "9021 Unsupported protection op:%d\n", |
| 2414 | op); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2415 | break; |
| 2416 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2417 | return ret; |
| 2418 | } |
| 2419 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2420 | /** |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2421 | * lpfc_bg_scsi_adjust_dl - Adjust SCSI data length for BlockGuard |
| 2422 | * @phba: The Hba for which this call is being executed. |
| 2423 | * @lpfc_cmd: The scsi buffer which is going to be adjusted. |
| 2424 | * |
| 2425 | * Adjust the data length to account for how much data |
| 2426 | * is actually on the wire. |
| 2427 | * |
| 2428 | * returns the adjusted data length |
| 2429 | **/ |
| 2430 | static int |
| 2431 | lpfc_bg_scsi_adjust_dl(struct lpfc_hba *phba, |
| 2432 | struct lpfc_scsi_buf *lpfc_cmd) |
| 2433 | { |
| 2434 | struct scsi_cmnd *sc = lpfc_cmd->pCmd; |
| 2435 | int fcpdl; |
| 2436 | |
| 2437 | fcpdl = scsi_bufflen(sc); |
| 2438 | |
| 2439 | /* Check if there is protection data on the wire */ |
| 2440 | if (sc->sc_data_direction == DMA_FROM_DEVICE) { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2441 | /* Read check for protection data */ |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2442 | if (scsi_get_prot_op(sc) == SCSI_PROT_READ_INSERT) |
| 2443 | return fcpdl; |
| 2444 | |
| 2445 | } else { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2446 | /* Write check for protection data */ |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2447 | if (scsi_get_prot_op(sc) == SCSI_PROT_WRITE_STRIP) |
| 2448 | return fcpdl; |
| 2449 | } |
| 2450 | |
| 2451 | /* |
| 2452 | * 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] | 2453 | * DIF (trailer) attached to it. Must ajust FCP data length |
| 2454 | * to account for the protection data. |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2455 | */ |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2456 | fcpdl += (fcpdl / lpfc_cmd_blksize(sc)) * 8; |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2457 | |
| 2458 | return fcpdl; |
| 2459 | } |
| 2460 | |
| 2461 | /** |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2462 | * lpfc_bg_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec |
| 2463 | * @phba: The Hba for which this call is being executed. |
| 2464 | * @lpfc_cmd: The scsi buffer which is going to be prep'ed. |
| 2465 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2466 | * This is the protection/DIF aware version of |
| 2467 | * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the |
| 2468 | * two functions eventually, but for now, it's here |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2469 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2470 | static int |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2471 | lpfc_bg_scsi_prep_dma_buf_s3(struct lpfc_hba *phba, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2472 | struct lpfc_scsi_buf *lpfc_cmd) |
| 2473 | { |
| 2474 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 2475 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 2476 | struct ulp_bde64 *bpl = lpfc_cmd->dma_sgl; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2477 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 2478 | uint32_t num_bde = 0; |
| 2479 | int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction; |
| 2480 | int prot_group_type = 0; |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2481 | int fcpdl; |
James Smart | 7c4042a | 2018-11-29 16:09:40 -0800 | [diff] [blame] | 2482 | struct lpfc_vport *vport = phba->pport; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2483 | |
| 2484 | /* |
| 2485 | * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd |
| 2486 | * fcp_rsp regions to the first data bde entry |
| 2487 | */ |
| 2488 | bpl += 2; |
| 2489 | if (scsi_sg_count(scsi_cmnd)) { |
| 2490 | /* |
| 2491 | * The driver stores the segment count returned from pci_map_sg |
| 2492 | * because this a count of dma-mappings used to map the use_sg |
| 2493 | * pages. They are not guaranteed to be the same for those |
| 2494 | * architectures that implement an IOMMU. |
| 2495 | */ |
| 2496 | datasegcnt = dma_map_sg(&phba->pcidev->dev, |
| 2497 | scsi_sglist(scsi_cmnd), |
| 2498 | scsi_sg_count(scsi_cmnd), datadir); |
| 2499 | if (unlikely(!datasegcnt)) |
| 2500 | return 1; |
| 2501 | |
| 2502 | lpfc_cmd->seg_cnt = datasegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2503 | |
| 2504 | /* First check if data segment count from SCSI Layer is good */ |
| 2505 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) |
| 2506 | goto err; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2507 | |
| 2508 | prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd); |
| 2509 | |
| 2510 | switch (prot_group_type) { |
| 2511 | case LPFC_PG_TYPE_NO_DIF: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2512 | |
| 2513 | /* Here we need to add a PDE5 and PDE6 to the count */ |
| 2514 | if ((lpfc_cmd->seg_cnt + 2) > phba->cfg_total_seg_cnt) |
| 2515 | goto err; |
| 2516 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2517 | num_bde = lpfc_bg_setup_bpl(phba, scsi_cmnd, bpl, |
| 2518 | datasegcnt); |
Adam Buchbinder | c9404c9 | 2009-12-18 15:40:42 -0500 | [diff] [blame] | 2519 | /* we should have 2 or more entries in buffer list */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2520 | if (num_bde < 2) |
| 2521 | goto err; |
| 2522 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2523 | |
| 2524 | case LPFC_PG_TYPE_DIF_BUF: |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2525 | /* |
| 2526 | * This type indicates that protection buffers are |
| 2527 | * passed to the driver, so that needs to be prepared |
| 2528 | * for DMA |
| 2529 | */ |
| 2530 | protsegcnt = dma_map_sg(&phba->pcidev->dev, |
| 2531 | scsi_prot_sglist(scsi_cmnd), |
| 2532 | scsi_prot_sg_count(scsi_cmnd), datadir); |
| 2533 | if (unlikely(!protsegcnt)) { |
| 2534 | scsi_dma_unmap(scsi_cmnd); |
| 2535 | return 1; |
| 2536 | } |
| 2537 | |
| 2538 | lpfc_cmd->prot_seg_cnt = protsegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2539 | |
| 2540 | /* |
| 2541 | * There is a minimun of 4 BPLs used for every |
| 2542 | * protection data segment. |
| 2543 | */ |
| 2544 | if ((lpfc_cmd->prot_seg_cnt * 4) > |
| 2545 | (phba->cfg_total_seg_cnt - 2)) |
| 2546 | goto err; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2547 | |
| 2548 | num_bde = lpfc_bg_setup_bpl_prot(phba, scsi_cmnd, bpl, |
| 2549 | datasegcnt, protsegcnt); |
Adam Buchbinder | c9404c9 | 2009-12-18 15:40:42 -0500 | [diff] [blame] | 2550 | /* we should have 3 or more entries in buffer list */ |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2551 | if ((num_bde < 3) || |
| 2552 | (num_bde > phba->cfg_total_seg_cnt)) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2553 | goto err; |
| 2554 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2555 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2556 | case LPFC_PG_TYPE_INVALID: |
| 2557 | default: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2558 | scsi_dma_unmap(scsi_cmnd); |
| 2559 | lpfc_cmd->seg_cnt = 0; |
| 2560 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2561 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2562 | "9022 Unexpected protection group %i\n", |
| 2563 | prot_group_type); |
| 2564 | return 1; |
| 2565 | } |
| 2566 | } |
| 2567 | |
| 2568 | /* |
| 2569 | * Finish initializing those IOCB fields that are dependent on the |
| 2570 | * scsi_cmnd request_buffer. Note that the bdeSize is explicitly |
| 2571 | * reinitialized since all iocb memory resources are used many times |
| 2572 | * for transmit, receive, and continuation bpl's. |
| 2573 | */ |
| 2574 | iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| 2575 | iocb_cmd->un.fcpi64.bdl.bdeSize += (num_bde * sizeof(struct ulp_bde64)); |
| 2576 | iocb_cmd->ulpBdeCount = 1; |
| 2577 | iocb_cmd->ulpLe = 1; |
| 2578 | |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2579 | fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2580 | fcp_cmnd->fcpDl = be32_to_cpu(fcpdl); |
| 2581 | |
| 2582 | /* |
| 2583 | * Due to difference in data length between DIF/non-DIF paths, |
| 2584 | * we need to set word 4 of IOCB here |
| 2585 | */ |
| 2586 | iocb_cmd->un.fcpi.fcpi_parm = fcpdl; |
| 2587 | |
James Smart | 7c4042a | 2018-11-29 16:09:40 -0800 | [diff] [blame] | 2588 | /* |
| 2589 | * For First burst, we may need to adjust the initial transfer |
| 2590 | * length for DIF |
| 2591 | */ |
| 2592 | if (iocb_cmd->un.fcpi.fcpi_XRdy && |
| 2593 | (fcpdl < vport->cfg_first_burst_size)) |
| 2594 | iocb_cmd->un.fcpi.fcpi_XRdy = fcpdl; |
| 2595 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2596 | return 0; |
| 2597 | err: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2598 | if (lpfc_cmd->seg_cnt) |
| 2599 | scsi_dma_unmap(scsi_cmnd); |
| 2600 | if (lpfc_cmd->prot_seg_cnt) |
| 2601 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd), |
| 2602 | scsi_prot_sg_count(scsi_cmnd), |
| 2603 | scsi_cmnd->sc_data_direction); |
| 2604 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2605 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2606 | "9023 Cannot setup S/G List for HBA" |
| 2607 | "IO segs %d/%d BPL %d SCSI %d: %d %d\n", |
| 2608 | lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt, |
| 2609 | phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2610 | prot_group_type, num_bde); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2611 | |
| 2612 | lpfc_cmd->seg_cnt = 0; |
| 2613 | lpfc_cmd->prot_seg_cnt = 0; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2614 | return 1; |
| 2615 | } |
| 2616 | |
| 2617 | /* |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2618 | * This function calcuates the T10 DIF guard tag |
| 2619 | * on the specified data using a CRC algorithmn |
| 2620 | * using crc_t10dif. |
| 2621 | */ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 2622 | static uint16_t |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2623 | lpfc_bg_crc(uint8_t *data, int count) |
| 2624 | { |
| 2625 | uint16_t crc = 0; |
| 2626 | uint16_t x; |
| 2627 | |
| 2628 | crc = crc_t10dif(data, count); |
| 2629 | x = cpu_to_be16(crc); |
| 2630 | return x; |
| 2631 | } |
| 2632 | |
| 2633 | /* |
| 2634 | * This function calcuates the T10 DIF guard tag |
| 2635 | * on the specified data using a CSUM algorithmn |
| 2636 | * using ip_compute_csum. |
| 2637 | */ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 2638 | static uint16_t |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2639 | lpfc_bg_csum(uint8_t *data, int count) |
| 2640 | { |
| 2641 | uint16_t ret; |
| 2642 | |
| 2643 | ret = ip_compute_csum(data, count); |
| 2644 | return ret; |
| 2645 | } |
| 2646 | |
| 2647 | /* |
| 2648 | * This function examines the protection data to try to determine |
| 2649 | * what type of T10-DIF error occurred. |
| 2650 | */ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 2651 | static void |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2652 | lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 2653 | { |
| 2654 | struct scatterlist *sgpe; /* s/g prot entry */ |
| 2655 | struct scatterlist *sgde; /* s/g data entry */ |
| 2656 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 2657 | struct scsi_dif_tuple *src = NULL; |
| 2658 | uint8_t *data_src = NULL; |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 2659 | uint16_t guard_tag; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2660 | uint16_t start_app_tag, app_tag; |
| 2661 | uint32_t start_ref_tag, ref_tag; |
| 2662 | int prot, protsegcnt; |
| 2663 | int err_type, len, data_len; |
| 2664 | int chk_ref, chk_app, chk_guard; |
| 2665 | uint16_t sum; |
| 2666 | unsigned blksize; |
| 2667 | |
| 2668 | err_type = BGS_GUARD_ERR_MASK; |
| 2669 | sum = 0; |
| 2670 | guard_tag = 0; |
| 2671 | |
| 2672 | /* First check to see if there is protection data to examine */ |
| 2673 | prot = scsi_get_prot_op(cmd); |
| 2674 | if ((prot == SCSI_PROT_READ_STRIP) || |
| 2675 | (prot == SCSI_PROT_WRITE_INSERT) || |
| 2676 | (prot == SCSI_PROT_NORMAL)) |
| 2677 | goto out; |
| 2678 | |
| 2679 | /* Currently the driver just supports ref_tag and guard_tag checking */ |
| 2680 | chk_ref = 1; |
| 2681 | chk_app = 0; |
| 2682 | chk_guard = 0; |
| 2683 | |
| 2684 | /* Setup a ptr to the protection data provided by the SCSI host */ |
| 2685 | sgpe = scsi_prot_sglist(cmd); |
| 2686 | protsegcnt = lpfc_cmd->prot_seg_cnt; |
| 2687 | |
| 2688 | if (sgpe && protsegcnt) { |
| 2689 | |
| 2690 | /* |
| 2691 | * We will only try to verify guard tag if the segment |
| 2692 | * data length is a multiple of the blksize. |
| 2693 | */ |
| 2694 | sgde = scsi_sglist(cmd); |
| 2695 | blksize = lpfc_cmd_blksize(cmd); |
| 2696 | data_src = (uint8_t *)sg_virt(sgde); |
| 2697 | data_len = sgde->length; |
| 2698 | if ((data_len & (blksize - 1)) == 0) |
| 2699 | chk_guard = 1; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2700 | |
James Smart | e85d8f9 | 2013-05-31 17:04:10 -0400 | [diff] [blame] | 2701 | src = (struct scsi_dif_tuple *)sg_virt(sgpe); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2702 | start_ref_tag = (uint32_t)scsi_get_lba(cmd); /* Truncate LBA */ |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2703 | start_app_tag = src->app_tag; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2704 | len = sgpe->length; |
| 2705 | while (src && protsegcnt) { |
| 2706 | while (len) { |
| 2707 | |
| 2708 | /* |
| 2709 | * First check to see if a protection data |
| 2710 | * check is valid |
| 2711 | */ |
Dmitry Monakhov | 128b6f9 | 2017-06-29 11:31:12 -0700 | [diff] [blame] | 2712 | if ((src->ref_tag == T10_PI_REF_ESCAPE) || |
| 2713 | (src->app_tag == T10_PI_APP_ESCAPE)) { |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2714 | start_ref_tag++; |
| 2715 | goto skipit; |
| 2716 | } |
| 2717 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2718 | /* First Guard Tag checking */ |
| 2719 | if (chk_guard) { |
| 2720 | guard_tag = src->guard_tag; |
| 2721 | if (lpfc_cmd_guard_csum(cmd)) |
| 2722 | sum = lpfc_bg_csum(data_src, |
| 2723 | blksize); |
| 2724 | else |
| 2725 | sum = lpfc_bg_crc(data_src, |
| 2726 | blksize); |
| 2727 | if ((guard_tag != sum)) { |
| 2728 | err_type = BGS_GUARD_ERR_MASK; |
| 2729 | goto out; |
| 2730 | } |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2731 | } |
| 2732 | |
| 2733 | /* Reference Tag checking */ |
| 2734 | ref_tag = be32_to_cpu(src->ref_tag); |
| 2735 | if (chk_ref && (ref_tag != start_ref_tag)) { |
| 2736 | err_type = BGS_REFTAG_ERR_MASK; |
| 2737 | goto out; |
| 2738 | } |
| 2739 | start_ref_tag++; |
| 2740 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2741 | /* App Tag checking */ |
| 2742 | app_tag = src->app_tag; |
| 2743 | if (chk_app && (app_tag != start_app_tag)) { |
| 2744 | err_type = BGS_APPTAG_ERR_MASK; |
| 2745 | goto out; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2746 | } |
| 2747 | skipit: |
| 2748 | len -= sizeof(struct scsi_dif_tuple); |
| 2749 | if (len < 0) |
| 2750 | len = 0; |
| 2751 | src++; |
| 2752 | |
| 2753 | data_src += blksize; |
| 2754 | data_len -= blksize; |
| 2755 | |
| 2756 | /* |
| 2757 | * Are we at the end of the Data segment? |
| 2758 | * The data segment is only used for Guard |
| 2759 | * tag checking. |
| 2760 | */ |
| 2761 | if (chk_guard && (data_len == 0)) { |
| 2762 | chk_guard = 0; |
| 2763 | sgde = sg_next(sgde); |
| 2764 | if (!sgde) |
| 2765 | goto out; |
| 2766 | |
| 2767 | data_src = (uint8_t *)sg_virt(sgde); |
| 2768 | data_len = sgde->length; |
| 2769 | if ((data_len & (blksize - 1)) == 0) |
| 2770 | chk_guard = 1; |
| 2771 | } |
| 2772 | } |
| 2773 | |
| 2774 | /* Goto the next Protection data segment */ |
| 2775 | sgpe = sg_next(sgpe); |
| 2776 | if (sgpe) { |
| 2777 | src = (struct scsi_dif_tuple *)sg_virt(sgpe); |
| 2778 | len = sgpe->length; |
| 2779 | } else { |
| 2780 | src = NULL; |
| 2781 | } |
| 2782 | protsegcnt--; |
| 2783 | } |
| 2784 | } |
| 2785 | out: |
| 2786 | if (err_type == BGS_GUARD_ERR_MASK) { |
| 2787 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 2788 | 0x10, 0x1); |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 2789 | cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 | |
| 2790 | SAM_STAT_CHECK_CONDITION; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2791 | phba->bg_guard_err_cnt++; |
| 2792 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 2793 | "9069 BLKGRD: LBA %lx grd_tag error %x != %x\n", |
| 2794 | (unsigned long)scsi_get_lba(cmd), |
| 2795 | sum, guard_tag); |
| 2796 | |
| 2797 | } else if (err_type == BGS_REFTAG_ERR_MASK) { |
| 2798 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 2799 | 0x10, 0x3); |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 2800 | cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 | |
| 2801 | SAM_STAT_CHECK_CONDITION; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2802 | |
| 2803 | phba->bg_reftag_err_cnt++; |
| 2804 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 2805 | "9066 BLKGRD: LBA %lx ref_tag error %x != %x\n", |
| 2806 | (unsigned long)scsi_get_lba(cmd), |
| 2807 | ref_tag, start_ref_tag); |
| 2808 | |
| 2809 | } else if (err_type == BGS_APPTAG_ERR_MASK) { |
| 2810 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 2811 | 0x10, 0x2); |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 2812 | cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 | |
| 2813 | SAM_STAT_CHECK_CONDITION; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2814 | |
| 2815 | phba->bg_apptag_err_cnt++; |
| 2816 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 2817 | "9041 BLKGRD: LBA %lx app_tag error %x != %x\n", |
| 2818 | (unsigned long)scsi_get_lba(cmd), |
| 2819 | app_tag, start_app_tag); |
| 2820 | } |
| 2821 | } |
| 2822 | |
| 2823 | |
| 2824 | /* |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2825 | * This function checks for BlockGuard errors detected by |
| 2826 | * the HBA. In case of errors, the ASC/ASCQ fields in the |
| 2827 | * sense buffer will be set accordingly, paired with |
| 2828 | * ILLEGAL_REQUEST to signal to the kernel that the HBA |
| 2829 | * detected corruption. |
| 2830 | * |
| 2831 | * Returns: |
| 2832 | * 0 - No error found |
| 2833 | * 1 - BlockGuard error found |
| 2834 | * -1 - Internal error (bad profile, ...etc) |
| 2835 | */ |
| 2836 | static int |
| 2837 | lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd, |
| 2838 | struct lpfc_iocbq *pIocbOut) |
| 2839 | { |
| 2840 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 2841 | struct sli3_bg_fields *bgf = &pIocbOut->iocb.unsli3.sli3_bg; |
| 2842 | int ret = 0; |
| 2843 | uint32_t bghm = bgf->bghm; |
| 2844 | uint32_t bgstat = bgf->bgstat; |
| 2845 | uint64_t failing_sector = 0; |
| 2846 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2847 | spin_lock(&_dump_buf_lock); |
| 2848 | if (!_dump_buf_done) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2849 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9070 BLKGRD: Saving" |
| 2850 | " Data for %u blocks to debugfs\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2851 | (cmd->cmnd[7] << 8 | cmd->cmnd[8])); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2852 | lpfc_debug_save_data(phba, cmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2853 | |
| 2854 | /* If we have a prot sgl, save the DIF buffer */ |
| 2855 | if (lpfc_prot_group_type(phba, cmd) == |
| 2856 | LPFC_PG_TYPE_DIF_BUF) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2857 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9071 BLKGRD: " |
| 2858 | "Saving DIF for %u blocks to debugfs\n", |
| 2859 | (cmd->cmnd[7] << 8 | cmd->cmnd[8])); |
| 2860 | lpfc_debug_save_dif(phba, cmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2861 | } |
| 2862 | |
| 2863 | _dump_buf_done = 1; |
| 2864 | } |
| 2865 | spin_unlock(&_dump_buf_lock); |
| 2866 | |
| 2867 | if (lpfc_bgs_get_invalid_prof(bgstat)) { |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 2868 | cmd->result = DID_ERROR << 16; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2869 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 2870 | "9072 BLKGRD: Invalid BG Profile in cmd" |
| 2871 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 2872 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 2873 | (unsigned long long)scsi_get_lba(cmd), |
| 2874 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2875 | ret = (-1); |
| 2876 | goto out; |
| 2877 | } |
| 2878 | |
| 2879 | if (lpfc_bgs_get_uninit_dif_block(bgstat)) { |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 2880 | cmd->result = DID_ERROR << 16; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2881 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 2882 | "9073 BLKGRD: Invalid BG PDIF Block in cmd" |
| 2883 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 2884 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 2885 | (unsigned long long)scsi_get_lba(cmd), |
| 2886 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2887 | ret = (-1); |
| 2888 | goto out; |
| 2889 | } |
| 2890 | |
| 2891 | if (lpfc_bgs_get_guard_err(bgstat)) { |
| 2892 | ret = 1; |
| 2893 | |
| 2894 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 2895 | 0x10, 0x1); |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 2896 | cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 | |
| 2897 | SAM_STAT_CHECK_CONDITION; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2898 | phba->bg_guard_err_cnt++; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2899 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 2900 | "9055 BLKGRD: Guard Tag error in cmd" |
| 2901 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 2902 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 2903 | (unsigned long long)scsi_get_lba(cmd), |
| 2904 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2905 | } |
| 2906 | |
| 2907 | if (lpfc_bgs_get_reftag_err(bgstat)) { |
| 2908 | ret = 1; |
| 2909 | |
| 2910 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 2911 | 0x10, 0x3); |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 2912 | cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 | |
| 2913 | SAM_STAT_CHECK_CONDITION; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2914 | |
| 2915 | phba->bg_reftag_err_cnt++; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2916 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 2917 | "9056 BLKGRD: Ref Tag error in cmd" |
| 2918 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 2919 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 2920 | (unsigned long long)scsi_get_lba(cmd), |
| 2921 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2922 | } |
| 2923 | |
| 2924 | if (lpfc_bgs_get_apptag_err(bgstat)) { |
| 2925 | ret = 1; |
| 2926 | |
| 2927 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 2928 | 0x10, 0x2); |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 2929 | cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 | |
| 2930 | SAM_STAT_CHECK_CONDITION; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2931 | |
| 2932 | phba->bg_apptag_err_cnt++; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2933 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 2934 | "9061 BLKGRD: App Tag error in cmd" |
| 2935 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 2936 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 2937 | (unsigned long long)scsi_get_lba(cmd), |
| 2938 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2939 | } |
| 2940 | |
| 2941 | if (lpfc_bgs_get_hi_water_mark_present(bgstat)) { |
| 2942 | /* |
| 2943 | * setup sense data descriptor 0 per SPC-4 as an information |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2944 | * field, and put the failing LBA in it. |
| 2945 | * This code assumes there was also a guard/app/ref tag error |
| 2946 | * indication. |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2947 | */ |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2948 | cmd->sense_buffer[7] = 0xc; /* Additional sense length */ |
| 2949 | cmd->sense_buffer[8] = 0; /* Information descriptor type */ |
| 2950 | cmd->sense_buffer[9] = 0xa; /* Additional descriptor length */ |
| 2951 | cmd->sense_buffer[10] = 0x80; /* Validity bit */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2952 | |
| 2953 | /* bghm is a "on the wire" FC frame based count */ |
| 2954 | switch (scsi_get_prot_op(cmd)) { |
| 2955 | case SCSI_PROT_READ_INSERT: |
| 2956 | case SCSI_PROT_WRITE_STRIP: |
| 2957 | bghm /= cmd->device->sector_size; |
| 2958 | break; |
| 2959 | case SCSI_PROT_READ_STRIP: |
| 2960 | case SCSI_PROT_WRITE_INSERT: |
| 2961 | case SCSI_PROT_READ_PASS: |
| 2962 | case SCSI_PROT_WRITE_PASS: |
| 2963 | bghm /= (cmd->device->sector_size + |
| 2964 | sizeof(struct scsi_dif_tuple)); |
| 2965 | break; |
| 2966 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2967 | |
| 2968 | failing_sector = scsi_get_lba(cmd); |
| 2969 | failing_sector += bghm; |
| 2970 | |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2971 | /* Descriptor Information */ |
| 2972 | put_unaligned_be64(failing_sector, &cmd->sense_buffer[12]); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2973 | } |
| 2974 | |
| 2975 | if (!ret) { |
| 2976 | /* No error was reported - problem in FW? */ |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2977 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 2978 | "9057 BLKGRD: Unknown error in cmd" |
| 2979 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 2980 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 2981 | (unsigned long long)scsi_get_lba(cmd), |
| 2982 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2983 | |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2984 | /* Calcuate what type of error it was */ |
| 2985 | lpfc_calc_bg_err(phba, lpfc_cmd); |
| 2986 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2987 | out: |
| 2988 | return ret; |
| 2989 | } |
| 2990 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2991 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2992 | * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec |
| 2993 | * @phba: The Hba for which this call is being executed. |
| 2994 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 2995 | * |
| 2996 | * This routine does the pci dma mapping for scatter-gather list of scsi cmnd |
| 2997 | * field of @lpfc_cmd for device with SLI-4 interface spec. |
| 2998 | * |
| 2999 | * Return codes: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 3000 | * 1 - Error |
| 3001 | * 0 - Success |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3002 | **/ |
| 3003 | static int |
| 3004 | lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 3005 | { |
| 3006 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 3007 | struct scatterlist *sgel = NULL; |
| 3008 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3009 | struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3010 | struct sli4_sge *first_data_sgl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3011 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 3012 | dma_addr_t physaddr; |
| 3013 | uint32_t num_bde = 0; |
| 3014 | uint32_t dma_len; |
| 3015 | uint32_t dma_offset = 0; |
| 3016 | int nseg; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3017 | struct ulp_bde64 *bde; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3018 | |
| 3019 | /* |
| 3020 | * There are three possibilities here - use scatter-gather segment, use |
| 3021 | * the single mapping, or neither. Start the lpfc command prep by |
| 3022 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 3023 | * data bde entry. |
| 3024 | */ |
| 3025 | if (scsi_sg_count(scsi_cmnd)) { |
| 3026 | /* |
| 3027 | * The driver stores the segment count returned from pci_map_sg |
| 3028 | * because this a count of dma-mappings used to map the use_sg |
| 3029 | * pages. They are not guaranteed to be the same for those |
| 3030 | * architectures that implement an IOMMU. |
| 3031 | */ |
| 3032 | |
| 3033 | nseg = scsi_dma_map(scsi_cmnd); |
James Smart | 5116fbf | 2015-05-22 10:42:39 -0400 | [diff] [blame] | 3034 | if (unlikely(nseg <= 0)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3035 | return 1; |
| 3036 | sgl += 1; |
| 3037 | /* clear the last flag in the fcp_rsp map entry */ |
| 3038 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 3039 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 3040 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 3041 | sgl += 1; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3042 | first_data_sgl = sgl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3043 | lpfc_cmd->seg_cnt = nseg; |
| 3044 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3045 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9074 BLKGRD:" |
| 3046 | " %s: Too many sg segments from " |
| 3047 | "dma_map_sg. Config %d, seg_cnt %d\n", |
| 3048 | __func__, phba->cfg_sg_seg_cnt, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3049 | lpfc_cmd->seg_cnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3050 | lpfc_cmd->seg_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3051 | scsi_dma_unmap(scsi_cmnd); |
| 3052 | return 1; |
| 3053 | } |
| 3054 | |
| 3055 | /* |
| 3056 | * The driver established a maximum scatter-gather segment count |
| 3057 | * during probe that limits the number of sg elements in any |
| 3058 | * single scsi command. Just run through the seg_cnt and format |
| 3059 | * the sge's. |
| 3060 | * When using SLI-3 the driver will try to fit all the BDEs into |
| 3061 | * the IOCB. If it can't then the BDEs get added to a BPL as it |
| 3062 | * does for SLI-2 mode. |
| 3063 | */ |
| 3064 | scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) { |
| 3065 | physaddr = sg_dma_address(sgel); |
| 3066 | dma_len = sg_dma_len(sgel); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3067 | sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr)); |
| 3068 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr)); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 3069 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3070 | if ((num_bde + 1) == nseg) |
| 3071 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 3072 | else |
| 3073 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 3074 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 3075 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3076 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 3077 | sgl->sge_len = cpu_to_le32(dma_len); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3078 | dma_offset += dma_len; |
| 3079 | sgl++; |
| 3080 | } |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 3081 | /* |
| 3082 | * Setup the first Payload BDE. For FCoE we just key off |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 3083 | * Performance Hints, for FC we use lpfc_enable_pbde. |
| 3084 | * We populate words 13-15 of IOCB/WQE. |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 3085 | */ |
| 3086 | if ((phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) || |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 3087 | phba->cfg_enable_pbde) { |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3088 | bde = (struct ulp_bde64 *) |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 3089 | &(iocb_cmd->unsli3.sli3Words[5]); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3090 | bde->addrLow = first_data_sgl->addr_lo; |
| 3091 | bde->addrHigh = first_data_sgl->addr_hi; |
| 3092 | bde->tus.f.bdeSize = |
| 3093 | le32_to_cpu(first_data_sgl->sge_len); |
| 3094 | bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 3095 | bde->tus.w = cpu_to_le32(bde->tus.w); |
| 3096 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3097 | } else { |
| 3098 | sgl += 1; |
| 3099 | /* clear the last flag in the fcp_rsp map entry */ |
| 3100 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 3101 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 3102 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 3103 | |
| 3104 | if ((phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) || |
| 3105 | phba->cfg_enable_pbde) { |
| 3106 | bde = (struct ulp_bde64 *) |
| 3107 | &(iocb_cmd->unsli3.sli3Words[5]); |
| 3108 | memset(bde, 0, (sizeof(uint32_t) * 3)); |
| 3109 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3110 | } |
| 3111 | |
| 3112 | /* |
| 3113 | * Finish initializing those IOCB fields that are dependent on the |
| 3114 | * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is |
| 3115 | * explicitly reinitialized. |
| 3116 | * all iocb memory resources are reused. |
| 3117 | */ |
| 3118 | fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); |
| 3119 | |
| 3120 | /* |
| 3121 | * Due to difference in data length between DIF/non-DIF paths, |
| 3122 | * we need to set word 4 of IOCB here |
| 3123 | */ |
| 3124 | iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 3125 | |
| 3126 | /* |
| 3127 | * If the OAS driver feature is enabled and the lun is enabled for |
| 3128 | * OAS, set the oas iocb related flags. |
| 3129 | */ |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 3130 | if ((phba->cfg_fof) && ((struct lpfc_device_data *) |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 3131 | scsi_cmnd->device->hostdata)->oas_enabled) { |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 3132 | lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 3133 | lpfc_cmd->cur_iocbq.priority = ((struct lpfc_device_data *) |
| 3134 | scsi_cmnd->device->hostdata)->priority; |
| 3135 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3136 | return 0; |
| 3137 | } |
| 3138 | |
| 3139 | /** |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3140 | * lpfc_bg_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec |
| 3141 | * @phba: The Hba for which this call is being executed. |
| 3142 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3143 | * |
| 3144 | * This is the protection/DIF aware version of |
| 3145 | * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the |
| 3146 | * two functions eventually, but for now, it's here |
| 3147 | **/ |
| 3148 | static int |
| 3149 | lpfc_bg_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, |
| 3150 | struct lpfc_scsi_buf *lpfc_cmd) |
| 3151 | { |
| 3152 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 3153 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3154 | struct sli4_sge *sgl = (struct sli4_sge *)(lpfc_cmd->dma_sgl); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3155 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3156 | uint32_t num_sge = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3157 | int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction; |
| 3158 | int prot_group_type = 0; |
| 3159 | int fcpdl; |
James Smart | 7c4042a | 2018-11-29 16:09:40 -0800 | [diff] [blame] | 3160 | struct lpfc_vport *vport = phba->pport; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3161 | |
| 3162 | /* |
| 3163 | * Start the lpfc command prep by bumping the sgl beyond fcp_cmnd |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3164 | * fcp_rsp regions to the first data sge entry |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3165 | */ |
| 3166 | if (scsi_sg_count(scsi_cmnd)) { |
| 3167 | /* |
| 3168 | * The driver stores the segment count returned from pci_map_sg |
| 3169 | * because this a count of dma-mappings used to map the use_sg |
| 3170 | * pages. They are not guaranteed to be the same for those |
| 3171 | * architectures that implement an IOMMU. |
| 3172 | */ |
| 3173 | datasegcnt = dma_map_sg(&phba->pcidev->dev, |
| 3174 | scsi_sglist(scsi_cmnd), |
| 3175 | scsi_sg_count(scsi_cmnd), datadir); |
| 3176 | if (unlikely(!datasegcnt)) |
| 3177 | return 1; |
| 3178 | |
| 3179 | sgl += 1; |
| 3180 | /* clear the last flag in the fcp_rsp map entry */ |
| 3181 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 3182 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 3183 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 3184 | |
| 3185 | sgl += 1; |
| 3186 | lpfc_cmd->seg_cnt = datasegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3187 | |
| 3188 | /* First check if data segment count from SCSI Layer is good */ |
| 3189 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) |
| 3190 | goto err; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3191 | |
| 3192 | prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd); |
| 3193 | |
| 3194 | switch (prot_group_type) { |
| 3195 | case LPFC_PG_TYPE_NO_DIF: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3196 | /* Here we need to add a DISEED to the count */ |
| 3197 | if ((lpfc_cmd->seg_cnt + 1) > phba->cfg_total_seg_cnt) |
| 3198 | goto err; |
| 3199 | |
| 3200 | num_sge = lpfc_bg_setup_sgl(phba, scsi_cmnd, sgl, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3201 | datasegcnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3202 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3203 | /* we should have 2 or more entries in buffer list */ |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3204 | if (num_sge < 2) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3205 | goto err; |
| 3206 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3207 | |
| 3208 | case LPFC_PG_TYPE_DIF_BUF: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3209 | /* |
| 3210 | * This type indicates that protection buffers are |
| 3211 | * passed to the driver, so that needs to be prepared |
| 3212 | * for DMA |
| 3213 | */ |
| 3214 | protsegcnt = dma_map_sg(&phba->pcidev->dev, |
| 3215 | scsi_prot_sglist(scsi_cmnd), |
| 3216 | scsi_prot_sg_count(scsi_cmnd), datadir); |
| 3217 | if (unlikely(!protsegcnt)) { |
| 3218 | scsi_dma_unmap(scsi_cmnd); |
| 3219 | return 1; |
| 3220 | } |
| 3221 | |
| 3222 | lpfc_cmd->prot_seg_cnt = protsegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3223 | /* |
| 3224 | * There is a minimun of 3 SGEs used for every |
| 3225 | * protection data segment. |
| 3226 | */ |
| 3227 | if ((lpfc_cmd->prot_seg_cnt * 3) > |
| 3228 | (phba->cfg_total_seg_cnt - 2)) |
| 3229 | goto err; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3230 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3231 | num_sge = lpfc_bg_setup_sgl_prot(phba, scsi_cmnd, sgl, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3232 | datasegcnt, protsegcnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3233 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3234 | /* we should have 3 or more entries in buffer list */ |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3235 | if ((num_sge < 3) || |
| 3236 | (num_sge > phba->cfg_total_seg_cnt)) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3237 | goto err; |
| 3238 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3239 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3240 | case LPFC_PG_TYPE_INVALID: |
| 3241 | default: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3242 | scsi_dma_unmap(scsi_cmnd); |
| 3243 | lpfc_cmd->seg_cnt = 0; |
| 3244 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3245 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 3246 | "9083 Unexpected protection group %i\n", |
| 3247 | prot_group_type); |
| 3248 | return 1; |
| 3249 | } |
| 3250 | } |
| 3251 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 3252 | switch (scsi_get_prot_op(scsi_cmnd)) { |
| 3253 | case SCSI_PROT_WRITE_STRIP: |
| 3254 | case SCSI_PROT_READ_STRIP: |
| 3255 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_STRIP; |
| 3256 | break; |
| 3257 | case SCSI_PROT_WRITE_INSERT: |
| 3258 | case SCSI_PROT_READ_INSERT: |
| 3259 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_INSERT; |
| 3260 | break; |
| 3261 | case SCSI_PROT_WRITE_PASS: |
| 3262 | case SCSI_PROT_READ_PASS: |
| 3263 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_PASS; |
| 3264 | break; |
| 3265 | } |
| 3266 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3267 | fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3268 | fcp_cmnd->fcpDl = be32_to_cpu(fcpdl); |
| 3269 | |
| 3270 | /* |
| 3271 | * Due to difference in data length between DIF/non-DIF paths, |
| 3272 | * we need to set word 4 of IOCB here |
| 3273 | */ |
| 3274 | iocb_cmd->un.fcpi.fcpi_parm = fcpdl; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3275 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 3276 | /* |
James Smart | 7c4042a | 2018-11-29 16:09:40 -0800 | [diff] [blame] | 3277 | * For First burst, we may need to adjust the initial transfer |
| 3278 | * length for DIF |
| 3279 | */ |
| 3280 | if (iocb_cmd->un.fcpi.fcpi_XRdy && |
| 3281 | (fcpdl < vport->cfg_first_burst_size)) |
| 3282 | iocb_cmd->un.fcpi.fcpi_XRdy = fcpdl; |
| 3283 | |
| 3284 | /* |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 3285 | * If the OAS driver feature is enabled and the lun is enabled for |
| 3286 | * OAS, set the oas iocb related flags. |
| 3287 | */ |
| 3288 | if ((phba->cfg_fof) && ((struct lpfc_device_data *) |
| 3289 | scsi_cmnd->device->hostdata)->oas_enabled) |
| 3290 | lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF); |
| 3291 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3292 | return 0; |
| 3293 | err: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3294 | if (lpfc_cmd->seg_cnt) |
| 3295 | scsi_dma_unmap(scsi_cmnd); |
| 3296 | if (lpfc_cmd->prot_seg_cnt) |
| 3297 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd), |
| 3298 | scsi_prot_sg_count(scsi_cmnd), |
| 3299 | scsi_cmnd->sc_data_direction); |
| 3300 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3301 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3302 | "9084 Cannot setup S/G List for HBA" |
| 3303 | "IO segs %d/%d SGL %d SCSI %d: %d %d\n", |
| 3304 | lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt, |
| 3305 | phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt, |
| 3306 | prot_group_type, num_sge); |
| 3307 | |
| 3308 | lpfc_cmd->seg_cnt = 0; |
| 3309 | lpfc_cmd->prot_seg_cnt = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3310 | return 1; |
| 3311 | } |
| 3312 | |
| 3313 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3314 | * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer |
| 3315 | * @phba: The Hba for which this call is being executed. |
| 3316 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3317 | * |
| 3318 | * This routine wraps the actual DMA mapping function pointer from the |
| 3319 | * lpfc_hba struct. |
| 3320 | * |
| 3321 | * Return codes: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 3322 | * 1 - Error |
| 3323 | * 0 - Success |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3324 | **/ |
| 3325 | static inline int |
| 3326 | lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 3327 | { |
| 3328 | return phba->lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 3329 | } |
| 3330 | |
| 3331 | /** |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3332 | * lpfc_bg_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer |
| 3333 | * using BlockGuard. |
| 3334 | * @phba: The Hba for which this call is being executed. |
| 3335 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3336 | * |
| 3337 | * This routine wraps the actual DMA mapping function pointer from the |
| 3338 | * lpfc_hba struct. |
| 3339 | * |
| 3340 | * Return codes: |
| 3341 | * 1 - Error |
| 3342 | * 0 - Success |
| 3343 | **/ |
| 3344 | static inline int |
| 3345 | lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 3346 | { |
| 3347 | return phba->lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 3348 | } |
| 3349 | |
| 3350 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3351 | * 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] | 3352 | * @phba: Pointer to hba context object. |
| 3353 | * @vport: Pointer to vport object. |
| 3354 | * @lpfc_cmd: Pointer to lpfc scsi command which reported the error. |
| 3355 | * @rsp_iocb: Pointer to response iocb object which reported error. |
| 3356 | * |
| 3357 | * This function posts an event when there is a SCSI command reporting |
| 3358 | * error from the scsi device. |
| 3359 | **/ |
| 3360 | static void |
| 3361 | lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 3362 | struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_iocbq *rsp_iocb) { |
| 3363 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 3364 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
| 3365 | uint32_t resp_info = fcprsp->rspStatus2; |
| 3366 | uint32_t scsi_status = fcprsp->rspStatus3; |
| 3367 | uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; |
| 3368 | struct lpfc_fast_path_event *fast_path_evt = NULL; |
| 3369 | struct lpfc_nodelist *pnode = lpfc_cmd->rdata->pnode; |
| 3370 | unsigned long flags; |
| 3371 | |
James Smart | 5989b8d | 2010-10-22 11:06:56 -0400 | [diff] [blame] | 3372 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 3373 | return; |
| 3374 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3375 | /* If there is queuefull or busy condition send a scsi event */ |
| 3376 | if ((cmnd->result == SAM_STAT_TASK_SET_FULL) || |
| 3377 | (cmnd->result == SAM_STAT_BUSY)) { |
| 3378 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3379 | if (!fast_path_evt) |
| 3380 | return; |
| 3381 | fast_path_evt->un.scsi_evt.event_type = |
| 3382 | FC_REG_SCSI_EVENT; |
| 3383 | fast_path_evt->un.scsi_evt.subcategory = |
| 3384 | (cmnd->result == SAM_STAT_TASK_SET_FULL) ? |
| 3385 | LPFC_EVENT_QFULL : LPFC_EVENT_DEVBSY; |
| 3386 | fast_path_evt->un.scsi_evt.lun = cmnd->device->lun; |
| 3387 | memcpy(&fast_path_evt->un.scsi_evt.wwpn, |
| 3388 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3389 | memcpy(&fast_path_evt->un.scsi_evt.wwnn, |
| 3390 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3391 | } else if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen && |
| 3392 | ((cmnd->cmnd[0] == READ_10) || (cmnd->cmnd[0] == WRITE_10))) { |
| 3393 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3394 | if (!fast_path_evt) |
| 3395 | return; |
| 3396 | fast_path_evt->un.check_cond_evt.scsi_event.event_type = |
| 3397 | FC_REG_SCSI_EVENT; |
| 3398 | fast_path_evt->un.check_cond_evt.scsi_event.subcategory = |
| 3399 | LPFC_EVENT_CHECK_COND; |
| 3400 | fast_path_evt->un.check_cond_evt.scsi_event.lun = |
| 3401 | cmnd->device->lun; |
| 3402 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwpn, |
| 3403 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3404 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwnn, |
| 3405 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3406 | fast_path_evt->un.check_cond_evt.sense_key = |
| 3407 | cmnd->sense_buffer[2] & 0xf; |
| 3408 | fast_path_evt->un.check_cond_evt.asc = cmnd->sense_buffer[12]; |
| 3409 | fast_path_evt->un.check_cond_evt.ascq = cmnd->sense_buffer[13]; |
| 3410 | } else if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) && |
| 3411 | fcpi_parm && |
| 3412 | ((be32_to_cpu(fcprsp->rspResId) != fcpi_parm) || |
| 3413 | ((scsi_status == SAM_STAT_GOOD) && |
| 3414 | !(resp_info & (RESID_UNDER | RESID_OVER))))) { |
| 3415 | /* |
| 3416 | * If status is good or resid does not match with fcp_param and |
| 3417 | * there is valid fcpi_parm, then there is a read_check error |
| 3418 | */ |
| 3419 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3420 | if (!fast_path_evt) |
| 3421 | return; |
| 3422 | fast_path_evt->un.read_check_error.header.event_type = |
| 3423 | FC_REG_FABRIC_EVENT; |
| 3424 | fast_path_evt->un.read_check_error.header.subcategory = |
| 3425 | LPFC_EVENT_FCPRDCHKERR; |
| 3426 | memcpy(&fast_path_evt->un.read_check_error.header.wwpn, |
| 3427 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3428 | memcpy(&fast_path_evt->un.read_check_error.header.wwnn, |
| 3429 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3430 | fast_path_evt->un.read_check_error.lun = cmnd->device->lun; |
| 3431 | fast_path_evt->un.read_check_error.opcode = cmnd->cmnd[0]; |
| 3432 | fast_path_evt->un.read_check_error.fcpiparam = |
| 3433 | fcpi_parm; |
| 3434 | } else |
| 3435 | return; |
| 3436 | |
| 3437 | fast_path_evt->vport = vport; |
| 3438 | spin_lock_irqsave(&phba->hbalock, flags); |
| 3439 | list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list); |
| 3440 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 3441 | lpfc_worker_wake_up(phba); |
| 3442 | return; |
| 3443 | } |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3444 | |
| 3445 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3446 | * 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] | 3447 | * @phba: The HBA for which this call is being executed. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3448 | * @psb: The scsi buffer which is going to be un-mapped. |
| 3449 | * |
| 3450 | * 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] | 3451 | * field of @lpfc_cmd for device with SLI-3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3452 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3453 | static void |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3454 | 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] | 3455 | { |
| 3456 | /* |
| 3457 | * There are only two special cases to consider. (1) the scsi command |
| 3458 | * requested scatter-gather usage or (2) the scsi command allocated |
| 3459 | * a request buffer, but did not request use_sg. There is a third |
| 3460 | * case, but it does not require resource deallocation. |
| 3461 | */ |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3462 | if (psb->seg_cnt > 0) |
| 3463 | scsi_dma_unmap(psb->pCmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3464 | if (psb->prot_seg_cnt > 0) |
| 3465 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(psb->pCmd), |
| 3466 | scsi_prot_sg_count(psb->pCmd), |
| 3467 | psb->pCmd->sc_data_direction); |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 3468 | } |
| 3469 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3470 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3471 | * lpfc_handler_fcp_err - FCP response handler |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3472 | * @vport: The virtual port for which this call is being executed. |
| 3473 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. |
| 3474 | * @rsp_iocb: The response IOCB which contains FCP error. |
| 3475 | * |
| 3476 | * This routine is called to process response IOCB with status field |
| 3477 | * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command |
| 3478 | * based upon SCSI and FCP error. |
| 3479 | **/ |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 3480 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3481 | lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd, |
| 3482 | struct lpfc_iocbq *rsp_iocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3483 | { |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3484 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3485 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 3486 | struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd; |
| 3487 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3488 | uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3489 | uint32_t resp_info = fcprsp->rspStatus2; |
| 3490 | uint32_t scsi_status = fcprsp->rspStatus3; |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3491 | uint32_t *lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3492 | uint32_t host_status = DID_OK; |
| 3493 | uint32_t rsplen = 0; |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3494 | uint32_t fcpDl; |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3495 | uint32_t logit = LOG_FCP | LOG_FCP_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3496 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3497 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3498 | /* |
| 3499 | * If this is a task management command, there is no |
| 3500 | * scsi packet associated with this lpfc_cmd. The driver |
| 3501 | * consumes it. |
| 3502 | */ |
| 3503 | if (fcpcmd->fcpCntl2) { |
| 3504 | scsi_status = 0; |
| 3505 | goto out; |
| 3506 | } |
| 3507 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3508 | if (resp_info & RSP_LEN_VALID) { |
| 3509 | rsplen = be32_to_cpu(fcprsp->rspRspLen); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3510 | if (rsplen != 0 && rsplen != 4 && rsplen != 8) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3511 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 3512 | "2719 Invalid response length: " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 3513 | "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] | 3514 | cmnd->device->id, |
| 3515 | cmnd->device->lun, cmnd->cmnd[0], |
| 3516 | rsplen); |
| 3517 | host_status = DID_ERROR; |
| 3518 | goto out; |
| 3519 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3520 | if (fcprsp->rspInfo3 != RSP_NO_FAILURE) { |
| 3521 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 3522 | "2757 Protocol failure detected during " |
| 3523 | "processing of FCP I/O op: " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 3524 | "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] | 3525 | cmnd->device->id, |
| 3526 | cmnd->device->lun, cmnd->cmnd[0], |
| 3527 | fcprsp->rspInfo3); |
| 3528 | host_status = DID_ERROR; |
| 3529 | goto out; |
| 3530 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3531 | } |
| 3532 | |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3533 | if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) { |
| 3534 | uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen); |
| 3535 | if (snslen > SCSI_SENSE_BUFFERSIZE) |
| 3536 | snslen = SCSI_SENSE_BUFFERSIZE; |
| 3537 | |
| 3538 | if (resp_info & RSP_LEN_VALID) |
| 3539 | rsplen = be32_to_cpu(fcprsp->rspRspLen); |
| 3540 | memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen); |
| 3541 | } |
| 3542 | lp = (uint32_t *)cmnd->sense_buffer; |
| 3543 | |
James Smart | aa1c7ee | 2012-08-14 14:26:06 -0400 | [diff] [blame] | 3544 | /* special handling for under run conditions */ |
| 3545 | if (!scsi_status && (resp_info & RESID_UNDER)) { |
| 3546 | /* don't log under runs if fcp set... */ |
| 3547 | if (vport->cfg_log_verbose & LOG_FCP) |
| 3548 | logit = LOG_FCP_ERROR; |
| 3549 | /* unless operator says so */ |
| 3550 | if (vport->cfg_log_verbose & LOG_FCP_UNDER) |
| 3551 | logit = LOG_FCP_UNDER; |
| 3552 | } |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3553 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3554 | lpfc_printf_vlog(vport, KERN_WARNING, logit, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3555 | "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] | 3556 | "Data: x%x x%x x%x x%x x%x\n", |
| 3557 | cmnd->cmnd[0], scsi_status, |
| 3558 | be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info, |
| 3559 | be32_to_cpu(fcprsp->rspResId), |
| 3560 | be32_to_cpu(fcprsp->rspSnsLen), |
| 3561 | be32_to_cpu(fcprsp->rspRspLen), |
| 3562 | fcprsp->rspInfo3); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3563 | |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3564 | scsi_set_resid(cmnd, 0); |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3565 | fcpDl = be32_to_cpu(fcpcmd->fcpDl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3566 | if (resp_info & RESID_UNDER) { |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3567 | scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3568 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3569 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_UNDER, |
James Smart | 45634a86 | 2018-01-30 15:59:00 -0800 | [diff] [blame] | 3570 | "9025 FCP Underrun, expected %d, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3571 | "residual %d Data: x%x x%x x%x\n", |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3572 | fcpDl, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3573 | scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0], |
| 3574 | cmnd->underflow); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3575 | |
| 3576 | /* |
James Smart | 45634a86 | 2018-01-30 15:59:00 -0800 | [diff] [blame] | 3577 | * If there is an under run, check if under run reported by |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3578 | * storage array is same as the under run reported by HBA. |
| 3579 | * If this is not same, there is a dropped frame. |
| 3580 | */ |
James Smart | 45634a86 | 2018-01-30 15:59:00 -0800 | [diff] [blame] | 3581 | if (fcpi_parm && (scsi_get_resid(cmnd) != fcpi_parm)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3582 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 3583 | LOG_FCP | LOG_FCP_ERROR, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3584 | "9026 FCP Read Check Error " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3585 | "and Underrun Data: x%x x%x x%x x%x\n", |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3586 | fcpDl, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3587 | scsi_get_resid(cmnd), fcpi_parm, |
| 3588 | cmnd->cmnd[0]); |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3589 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3590 | host_status = DID_ERROR; |
| 3591 | } |
| 3592 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3593 | * The cmnd->underflow is the minimum number of bytes that must |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3594 | * be transferred for this command. Provided a sense condition |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3595 | * is not present, make sure the actual amount transferred is at |
| 3596 | * least the underflow value or fail. |
| 3597 | */ |
| 3598 | if (!(resp_info & SNS_LEN_VALID) && |
| 3599 | (scsi_status == SAM_STAT_GOOD) && |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3600 | (scsi_bufflen(cmnd) - scsi_get_resid(cmnd) |
| 3601 | < cmnd->underflow)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3602 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3603 | "9027 FCP command x%x residual " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3604 | "underrun converted to error " |
| 3605 | "Data: x%x x%x x%x\n", |
James Smart | 66dbfbe | 2007-08-05 06:08:38 -0400 | [diff] [blame] | 3606 | cmnd->cmnd[0], scsi_bufflen(cmnd), |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3607 | scsi_get_resid(cmnd), cmnd->underflow); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3608 | host_status = DID_ERROR; |
| 3609 | } |
| 3610 | } else if (resp_info & RESID_OVER) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3611 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3612 | "9028 FCP command x%x residual overrun error. " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 3613 | "Data: x%x x%x\n", cmnd->cmnd[0], |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3614 | scsi_bufflen(cmnd), scsi_get_resid(cmnd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3615 | host_status = DID_ERROR; |
| 3616 | |
| 3617 | /* |
| 3618 | * Check SLI validation that all the transfer was actually done |
James Smart | 26373d2 | 2013-09-06 12:19:17 -0400 | [diff] [blame] | 3619 | * (fcpi_parm should be zero). Apply check only to reads. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3620 | */ |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3621 | } else if (fcpi_parm) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3622 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR, |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3623 | "9029 FCP %s Check Error xri x%x Data: " |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 3624 | "x%x x%x x%x x%x x%x\n", |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3625 | ((cmnd->sc_data_direction == DMA_FROM_DEVICE) ? |
| 3626 | "Read" : "Write"), |
| 3627 | ((phba->sli_rev == LPFC_SLI_REV4) ? |
| 3628 | lpfc_cmd->cur_iocbq.sli4_xritag : |
| 3629 | rsp_iocb->iocb.ulpContext), |
| 3630 | fcpDl, be32_to_cpu(fcprsp->rspResId), |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 3631 | fcpi_parm, cmnd->cmnd[0], scsi_status); |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3632 | |
| 3633 | /* There is some issue with the LPe12000 that causes it |
| 3634 | * to miscalculate the fcpi_parm and falsely trip this |
| 3635 | * recovery logic. Detect this case and don't error when true. |
| 3636 | */ |
| 3637 | if (fcpi_parm > fcpDl) |
| 3638 | goto out; |
| 3639 | |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 3640 | switch (scsi_status) { |
| 3641 | case SAM_STAT_GOOD: |
| 3642 | case SAM_STAT_CHECK_CONDITION: |
| 3643 | /* Fabric dropped a data frame. Fail any successful |
| 3644 | * command in which we detected dropped frames. |
| 3645 | * A status of good or some check conditions could |
| 3646 | * be considered a successful command. |
| 3647 | */ |
| 3648 | host_status = DID_ERROR; |
| 3649 | break; |
| 3650 | } |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3651 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3652 | } |
| 3653 | |
| 3654 | out: |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 3655 | cmnd->result = host_status << 16 | scsi_status; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3656 | lpfc_send_scsi_error_event(vport->phba, vport, lpfc_cmd, rsp_iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3657 | } |
| 3658 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3659 | /** |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 3660 | * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution |
| 3661 | * @phba: Pointer to HBA context object. |
| 3662 | * |
| 3663 | * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index |
| 3664 | * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock |
| 3665 | * held. |
| 3666 | * If scsi-mq is enabled, get the default block layer mapping of software queues |
| 3667 | * to hardware queues. This information is saved in request tag. |
| 3668 | * |
| 3669 | * Return: index into SLI4 fast-path FCP queue index. |
| 3670 | **/ |
| 3671 | int lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba, |
| 3672 | struct lpfc_scsi_buf *lpfc_cmd) |
| 3673 | { |
| 3674 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 3675 | struct lpfc_vector_map_info *cpup; |
| 3676 | int chann, cpu; |
| 3677 | uint32_t tag; |
| 3678 | uint16_t hwq; |
| 3679 | |
Jens Axboe | f664a3c | 2018-11-01 16:36:27 -0600 | [diff] [blame] | 3680 | if (cmnd) { |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 3681 | tag = blk_mq_unique_tag(cmnd->request); |
| 3682 | hwq = blk_mq_unique_tag_to_hwq(tag); |
| 3683 | |
| 3684 | return hwq; |
| 3685 | } |
| 3686 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 3687 | if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_CPU && |
| 3688 | phba->cfg_hdw_queue > 1) { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3689 | cpu = lpfc_cmd->cpu; |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 3690 | if (cpu < phba->sli4_hba.num_present_cpu) { |
| 3691 | cpup = phba->sli4_hba.cpu_map; |
| 3692 | cpup += cpu; |
| 3693 | return cpup->channel_id; |
| 3694 | } |
| 3695 | } |
| 3696 | chann = atomic_add_return(1, &phba->fcp_qidx); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 3697 | chann = chann % phba->cfg_hdw_queue; |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 3698 | return chann; |
| 3699 | } |
| 3700 | |
| 3701 | |
| 3702 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3703 | * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3704 | * @phba: The Hba for which this call is being executed. |
| 3705 | * @pIocbIn: The command IOCBQ for the scsi cmnd. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3706 | * @pIocbOut: The response IOCBQ for the scsi cmnd. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3707 | * |
| 3708 | * This routine assigns scsi command result by looking into response IOCB |
| 3709 | * status field appropriately. This routine handles QUEUE FULL condition as |
| 3710 | * well by ramping down device queue depth. |
| 3711 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3712 | static void |
| 3713 | lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn, |
| 3714 | struct lpfc_iocbq *pIocbOut) |
| 3715 | { |
| 3716 | struct lpfc_scsi_buf *lpfc_cmd = |
| 3717 | (struct lpfc_scsi_buf *) pIocbIn->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3718 | struct lpfc_vport *vport = pIocbIn->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3719 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| 3720 | struct lpfc_nodelist *pnode = rdata->pnode; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3721 | struct scsi_cmnd *cmd; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 3722 | unsigned long flags; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3723 | struct lpfc_fast_path_event *fast_path_evt; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3724 | struct Scsi_Host *shost; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3725 | uint32_t logit = LOG_FCP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3726 | |
James Smart | 2cee780 | 2017-06-01 21:07:02 -0700 | [diff] [blame] | 3727 | atomic_inc(&phba->fc4ScsiIoCmpls); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3728 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3729 | /* Sanity check on return of outstanding command */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3730 | cmd = lpfc_cmd->pCmd; |
James Smart | c90261d | 2015-12-16 18:11:57 -0500 | [diff] [blame] | 3731 | if (!cmd) |
| 3732 | return; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3733 | shost = cmd->device->host; |
| 3734 | |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3735 | lpfc_cmd->result = (pIocbOut->iocb.un.ulpWord[4] & IOERR_PARAM_MASK); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3736 | lpfc_cmd->status = pIocbOut->iocb.ulpStatus; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3737 | /* pick up SLI4 exhange busy status from HBA */ |
| 3738 | lpfc_cmd->exch_busy = pIocbOut->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 3739 | |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 3740 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 3741 | if (lpfc_cmd->prot_data_type) { |
| 3742 | struct scsi_dif_tuple *src = NULL; |
| 3743 | |
| 3744 | src = (struct scsi_dif_tuple *)lpfc_cmd->prot_data_segment; |
| 3745 | /* |
| 3746 | * Used to restore any changes to protection |
| 3747 | * data for error injection. |
| 3748 | */ |
| 3749 | switch (lpfc_cmd->prot_data_type) { |
| 3750 | case LPFC_INJERR_REFTAG: |
| 3751 | src->ref_tag = |
| 3752 | lpfc_cmd->prot_data; |
| 3753 | break; |
| 3754 | case LPFC_INJERR_APPTAG: |
| 3755 | src->app_tag = |
| 3756 | (uint16_t)lpfc_cmd->prot_data; |
| 3757 | break; |
| 3758 | case LPFC_INJERR_GUARD: |
| 3759 | src->guard_tag = |
| 3760 | (uint16_t)lpfc_cmd->prot_data; |
| 3761 | break; |
| 3762 | default: |
| 3763 | break; |
| 3764 | } |
| 3765 | |
| 3766 | lpfc_cmd->prot_data = 0; |
| 3767 | lpfc_cmd->prot_data_type = 0; |
| 3768 | lpfc_cmd->prot_data_segment = NULL; |
| 3769 | } |
| 3770 | #endif |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 3771 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3772 | if (lpfc_cmd->status) { |
| 3773 | if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT && |
| 3774 | (lpfc_cmd->result & IOERR_DRVR_MASK)) |
| 3775 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; |
| 3776 | else if (lpfc_cmd->status >= IOSTAT_CNT) |
| 3777 | lpfc_cmd->status = IOSTAT_DEFAULT; |
James Smart | aa1c7ee | 2012-08-14 14:26:06 -0400 | [diff] [blame] | 3778 | if (lpfc_cmd->status == IOSTAT_FCP_RSP_ERROR && |
| 3779 | !lpfc_cmd->fcp_rsp->rspStatus3 && |
| 3780 | (lpfc_cmd->fcp_rsp->rspStatus2 & RESID_UNDER) && |
| 3781 | !(vport->cfg_log_verbose & LOG_FCP_UNDER)) |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3782 | logit = 0; |
| 3783 | else |
| 3784 | logit = LOG_FCP | LOG_FCP_UNDER; |
| 3785 | lpfc_printf_vlog(vport, KERN_WARNING, logit, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 3786 | "9030 FCP cmd x%x failed <%d/%lld> " |
James Smart | 5a0d80f | 2012-05-09 21:18:20 -0400 | [diff] [blame] | 3787 | "status: x%x result: x%x " |
| 3788 | "sid: x%x did: x%x oxid: x%x " |
| 3789 | "Data: x%x x%x\n", |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3790 | cmd->cmnd[0], |
| 3791 | cmd->device ? cmd->device->id : 0xffff, |
| 3792 | cmd->device ? cmd->device->lun : 0xffff, |
| 3793 | lpfc_cmd->status, lpfc_cmd->result, |
James Smart | 3bf41ba | 2013-05-31 17:03:18 -0400 | [diff] [blame] | 3794 | vport->fc_myDID, |
| 3795 | (pnode) ? pnode->nlp_DID : 0, |
James Smart | 5a0d80f | 2012-05-09 21:18:20 -0400 | [diff] [blame] | 3796 | phba->sli_rev == LPFC_SLI_REV4 ? |
| 3797 | lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3798 | pIocbOut->iocb.ulpContext, |
| 3799 | lpfc_cmd->cur_iocbq.iocb.ulpIoTag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3800 | |
| 3801 | switch (lpfc_cmd->status) { |
| 3802 | case IOSTAT_FCP_RSP_ERROR: |
| 3803 | /* Call FCP RSP handler to determine result */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3804 | lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3805 | break; |
| 3806 | case IOSTAT_NPORT_BSY: |
| 3807 | case IOSTAT_FABRIC_BSY: |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 3808 | cmd->result = DID_TRANSPORT_DISRUPTED << 16; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3809 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3810 | if (!fast_path_evt) |
| 3811 | break; |
| 3812 | fast_path_evt->un.fabric_evt.event_type = |
| 3813 | FC_REG_FABRIC_EVENT; |
| 3814 | fast_path_evt->un.fabric_evt.subcategory = |
| 3815 | (lpfc_cmd->status == IOSTAT_NPORT_BSY) ? |
| 3816 | LPFC_EVENT_PORT_BUSY : LPFC_EVENT_FABRIC_BUSY; |
| 3817 | if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
| 3818 | memcpy(&fast_path_evt->un.fabric_evt.wwpn, |
| 3819 | &pnode->nlp_portname, |
| 3820 | sizeof(struct lpfc_name)); |
| 3821 | memcpy(&fast_path_evt->un.fabric_evt.wwnn, |
| 3822 | &pnode->nlp_nodename, |
| 3823 | sizeof(struct lpfc_name)); |
| 3824 | } |
| 3825 | fast_path_evt->vport = vport; |
| 3826 | fast_path_evt->work_evt.evt = |
| 3827 | LPFC_EVT_FASTPATH_MGMT_EVT; |
| 3828 | spin_lock_irqsave(&phba->hbalock, flags); |
| 3829 | list_add_tail(&fast_path_evt->work_evt.evt_listp, |
| 3830 | &phba->work_list); |
| 3831 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 3832 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3833 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3834 | case IOSTAT_LOCAL_REJECT: |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3835 | case IOSTAT_REMOTE_STOP: |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 3836 | if (lpfc_cmd->result == IOERR_ELXSEC_KEY_UNWRAP_ERROR || |
| 3837 | lpfc_cmd->result == |
| 3838 | IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR || |
| 3839 | lpfc_cmd->result == IOERR_ELXSEC_CRYPTO_ERROR || |
| 3840 | lpfc_cmd->result == |
| 3841 | IOERR_ELXSEC_CRYPTO_COMPARE_ERROR) { |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 3842 | cmd->result = DID_NO_CONNECT << 16; |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 3843 | break; |
| 3844 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3845 | if (lpfc_cmd->result == IOERR_INVALID_RPI || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3846 | lpfc_cmd->result == IOERR_NO_RESOURCES || |
James Smart | b92938b | 2010-06-07 15:24:12 -0400 | [diff] [blame] | 3847 | lpfc_cmd->result == IOERR_ABORT_REQUESTED || |
| 3848 | lpfc_cmd->result == IOERR_SLER_CMD_RCV_FAILURE) { |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 3849 | cmd->result = DID_REQUEUE << 16; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3850 | break; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3851 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3852 | if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED || |
| 3853 | lpfc_cmd->result == IOERR_TX_DMA_FAILED) && |
| 3854 | pIocbOut->iocb.unsli3.sli3_bg.bgstat) { |
| 3855 | if (scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) { |
| 3856 | /* |
| 3857 | * This is a response for a BG enabled |
| 3858 | * cmd. Parse BG error |
| 3859 | */ |
| 3860 | lpfc_parse_bg_err(phba, lpfc_cmd, |
| 3861 | pIocbOut); |
| 3862 | break; |
| 3863 | } else { |
| 3864 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 3865 | LOG_BG, |
| 3866 | "9031 non-zero BGSTAT " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3867 | "on unprotected cmd\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3868 | } |
| 3869 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3870 | if ((lpfc_cmd->status == IOSTAT_REMOTE_STOP) |
| 3871 | && (phba->sli_rev == LPFC_SLI_REV4) |
| 3872 | && (pnode && NLP_CHK_NODE_ACT(pnode))) { |
| 3873 | /* This IO was aborted by the target, we don't |
| 3874 | * know the rxid and because we did not send the |
| 3875 | * ABTS we cannot generate and RRQ. |
| 3876 | */ |
| 3877 | lpfc_set_rrq_active(phba, pnode, |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 3878 | lpfc_cmd->cur_iocbq.sli4_lxritag, |
| 3879 | 0, 0); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3880 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3881 | /* else: fall through */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3882 | default: |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 3883 | cmd->result = DID_ERROR << 16; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3884 | break; |
| 3885 | } |
| 3886 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3887 | if (!pnode || !NLP_CHK_NODE_ACT(pnode) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3888 | || (pnode->nlp_state != NLP_STE_MAPPED_NODE)) |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 3889 | cmd->result = DID_TRANSPORT_DISRUPTED << 16 | |
| 3890 | SAM_STAT_BUSY; |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 3891 | } else |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 3892 | cmd->result = DID_OK << 16; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3893 | |
| 3894 | if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) { |
| 3895 | uint32_t *lp = (uint32_t *)cmd->sense_buffer; |
| 3896 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3897 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 3898 | "0710 Iodone <%d/%llu> cmd %p, error " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3899 | "x%x SNS x%x x%x Data: x%x x%x\n", |
| 3900 | cmd->device->id, cmd->device->lun, cmd, |
| 3901 | cmd->result, *lp, *(lp + 3), cmd->retries, |
| 3902 | scsi_get_resid(cmd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3903 | } |
| 3904 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3905 | lpfc_update_stats(phba, lpfc_cmd); |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 3906 | if (vport->cfg_max_scsicmpl_time && |
| 3907 | time_after(jiffies, lpfc_cmd->start_time + |
| 3908 | msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3909 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3910 | if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
| 3911 | if (pnode->cmd_qdepth > |
| 3912 | atomic_read(&pnode->cmd_pending) && |
| 3913 | (atomic_read(&pnode->cmd_pending) > |
| 3914 | LPFC_MIN_TGT_QDEPTH) && |
| 3915 | ((cmd->cmnd[0] == READ_10) || |
| 3916 | (cmd->cmnd[0] == WRITE_10))) |
| 3917 | pnode->cmd_qdepth = |
| 3918 | atomic_read(&pnode->cmd_pending); |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 3919 | |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3920 | pnode->last_change_time = jiffies; |
| 3921 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3922 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 3923 | } |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3924 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3925 | |
James Smart | ca7fb76 | 2018-09-10 10:30:44 -0700 | [diff] [blame] | 3926 | /* If pCmd was set to NULL from abort path, do not call scsi_done */ |
| 3927 | if (xchg(&lpfc_cmd->pCmd, NULL) == NULL) { |
| 3928 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
James Smart | 2c4c914 | 2018-11-29 16:09:31 -0800 | [diff] [blame] | 3929 | "5688 FCP cmd already NULL, sid: 0x%06x, " |
James Smart | ca7fb76 | 2018-09-10 10:30:44 -0700 | [diff] [blame] | 3930 | "did: 0x%06x, oxid: 0x%04x\n", |
| 3931 | vport->fc_myDID, |
| 3932 | (pnode) ? pnode->nlp_DID : 0, |
| 3933 | phba->sli_rev == LPFC_SLI_REV4 ? |
| 3934 | lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff); |
| 3935 | return; |
| 3936 | } |
James Smart | 92e3af6 | 2012-08-14 14:26:28 -0400 | [diff] [blame] | 3937 | |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3938 | /* The sdev is not guaranteed to be valid post scsi_done upcall. */ |
| 3939 | cmd->scsi_done(cmd); |
| 3940 | |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 3941 | /* |
| 3942 | * If there is a thread waiting for command completion |
| 3943 | * wake up the thread. |
| 3944 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3945 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 3946 | if (lpfc_cmd->waitq) |
| 3947 | wake_up(lpfc_cmd->waitq); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3948 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 3949 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3950 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3951 | } |
| 3952 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3953 | /** |
Alexey Kardashevskiy | 8b2564e | 2015-04-28 18:26:22 +1000 | [diff] [blame] | 3954 | * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB |
| 3955 | * @data: A pointer to the immediate command data portion of the IOCB. |
| 3956 | * @fcp_cmnd: The FCP Command that is provided by the SCSI layer. |
| 3957 | * |
| 3958 | * The routine copies the entire FCP command from @fcp_cmnd to @data while |
| 3959 | * byte swapping the data to big endian format for transmission on the wire. |
| 3960 | **/ |
| 3961 | static void |
| 3962 | lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd) |
| 3963 | { |
| 3964 | int i, j; |
| 3965 | for (i = 0, j = 0; i < sizeof(struct fcp_cmnd); |
| 3966 | i += sizeof(uint32_t), j++) { |
| 3967 | ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]); |
| 3968 | } |
| 3969 | } |
| 3970 | |
| 3971 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3972 | * 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] | 3973 | * @vport: The virtual port for which this call is being executed. |
| 3974 | * @lpfc_cmd: The scsi command which needs to send. |
| 3975 | * @pnode: Pointer to lpfc_nodelist. |
| 3976 | * |
| 3977 | * This routine initializes fcp_cmnd and iocb data structure from scsi command |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3978 | * to transfer for device with SLI3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3979 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3980 | static void |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3981 | 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] | 3982 | struct lpfc_nodelist *pnode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3983 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3984 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3985 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 3986 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 3987 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 3988 | struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq); |
| 3989 | int datadir = scsi_cmnd->sc_data_direction; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 3990 | uint8_t *ptr; |
| 3991 | bool sli4; |
James Smart | 98bbf5f | 2013-09-06 12:18:45 -0400 | [diff] [blame] | 3992 | uint32_t fcpdl; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3993 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3994 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 3995 | return; |
| 3996 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3997 | lpfc_cmd->fcp_rsp->rspSnsLen = 0; |
James.Smart@Emulex.Com | 69859dc | 2005-08-10 15:02:37 -0400 | [diff] [blame] | 3998 | /* clear task management bits */ |
| 3999 | lpfc_cmd->fcp_cmnd->fcpCntl2 = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4000 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 4001 | int_to_scsilun(lpfc_cmd->pCmd->device->lun, |
| 4002 | &lpfc_cmd->fcp_cmnd->fcp_lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4003 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4004 | ptr = &fcp_cmnd->fcpCdb[0]; |
| 4005 | memcpy(ptr, scsi_cmnd->cmnd, scsi_cmnd->cmd_len); |
| 4006 | if (scsi_cmnd->cmd_len < LPFC_FCP_CDB_LEN) { |
| 4007 | ptr += scsi_cmnd->cmd_len; |
| 4008 | memset(ptr, 0, (LPFC_FCP_CDB_LEN - scsi_cmnd->cmd_len)); |
| 4009 | } |
| 4010 | |
Christoph Hellwig | 5066863 | 2014-10-30 14:30:06 +0100 | [diff] [blame] | 4011 | fcp_cmnd->fcpCntl1 = SIMPLE_Q; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4012 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4013 | sli4 = (phba->sli_rev == LPFC_SLI_REV4); |
James Smart | 6acb348 | 2014-04-04 13:51:25 -0400 | [diff] [blame] | 4014 | piocbq->iocb.un.fcpi.fcpi_XRdy = 0; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4015 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4016 | /* |
| 4017 | * There are three possibilities here - use scatter-gather segment, use |
| 4018 | * the single mapping, or neither. Start the lpfc command prep by |
| 4019 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 4020 | * data bde entry. |
| 4021 | */ |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4022 | if (scsi_sg_count(scsi_cmnd)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4023 | if (datadir == DMA_TO_DEVICE) { |
| 4024 | iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR; |
James Smart | 182ba75 | 2013-07-15 18:34:05 -0400 | [diff] [blame] | 4025 | iocb_cmd->ulpPU = PARM_READ_CHECK; |
James Smart | 3cb01c5 | 2013-07-15 18:35:04 -0400 | [diff] [blame] | 4026 | if (vport->cfg_first_burst_size && |
| 4027 | (pnode->nlp_flag & NLP_FIRSTBURST)) { |
James Smart | 98bbf5f | 2013-09-06 12:18:45 -0400 | [diff] [blame] | 4028 | fcpdl = scsi_bufflen(scsi_cmnd); |
| 4029 | if (fcpdl < vport->cfg_first_burst_size) |
| 4030 | piocbq->iocb.un.fcpi.fcpi_XRdy = fcpdl; |
| 4031 | else |
| 4032 | piocbq->iocb.un.fcpi.fcpi_XRdy = |
| 4033 | vport->cfg_first_burst_size; |
James Smart | 3cb01c5 | 2013-07-15 18:35:04 -0400 | [diff] [blame] | 4034 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4035 | fcp_cmnd->fcpCntl3 = WRITE_DATA; |
James Smart | 2cee780 | 2017-06-01 21:07:02 -0700 | [diff] [blame] | 4036 | atomic_inc(&phba->fc4ScsiOutputRequests); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4037 | } else { |
| 4038 | iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR; |
| 4039 | iocb_cmd->ulpPU = PARM_READ_CHECK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4040 | fcp_cmnd->fcpCntl3 = READ_DATA; |
James Smart | 2cee780 | 2017-06-01 21:07:02 -0700 | [diff] [blame] | 4041 | atomic_inc(&phba->fc4ScsiInputRequests); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4042 | } |
| 4043 | } else { |
| 4044 | iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR; |
| 4045 | iocb_cmd->un.fcpi.fcpi_parm = 0; |
| 4046 | iocb_cmd->ulpPU = 0; |
| 4047 | fcp_cmnd->fcpCntl3 = 0; |
James Smart | 2cee780 | 2017-06-01 21:07:02 -0700 | [diff] [blame] | 4048 | atomic_inc(&phba->fc4ScsiControlRequests); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4049 | } |
Alexey Kardashevskiy | 8b2564e | 2015-04-28 18:26:22 +1000 | [diff] [blame] | 4050 | if (phba->sli_rev == 3 && |
| 4051 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) |
| 4052 | lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4053 | /* |
| 4054 | * Finish initializing those IOCB fields that are independent |
| 4055 | * of the scsi_cmnd request_buffer |
| 4056 | */ |
| 4057 | piocbq->iocb.ulpContext = pnode->nlp_rpi; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4058 | if (sli4) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4059 | piocbq->iocb.ulpContext = |
| 4060 | phba->sli4_hba.rpi_ids[pnode->nlp_rpi]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4061 | if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE) |
| 4062 | piocbq->iocb.ulpFCP2Rcvy = 1; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4063 | else |
| 4064 | piocbq->iocb.ulpFCP2Rcvy = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4065 | |
| 4066 | piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f); |
| 4067 | piocbq->context1 = lpfc_cmd; |
| 4068 | piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; |
| 4069 | piocbq->iocb.ulpTimeout = lpfc_cmd->timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4070 | piocbq->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4071 | } |
| 4072 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4073 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4074 | * 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] | 4075 | * @vport: The virtual port for which this call is being executed. |
| 4076 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. |
| 4077 | * @lun: Logical unit number. |
| 4078 | * @task_mgmt_cmd: SCSI task management command. |
| 4079 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4080 | * This routine creates FCP information unit corresponding to @task_mgmt_cmd |
| 4081 | * for device with SLI-3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4082 | * |
| 4083 | * Return codes: |
| 4084 | * 0 - Error |
| 4085 | * 1 - Success |
| 4086 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4087 | static int |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4088 | lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4089 | struct lpfc_scsi_buf *lpfc_cmd, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4090 | uint64_t lun, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4091 | uint8_t task_mgmt_cmd) |
| 4092 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4093 | struct lpfc_iocbq *piocbq; |
| 4094 | IOCB_t *piocb; |
| 4095 | struct fcp_cmnd *fcp_cmnd; |
James Smart | 0b18ac4 | 2006-05-01 21:50:40 -0400 | [diff] [blame] | 4096 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4097 | struct lpfc_nodelist *ndlp = rdata->pnode; |
| 4098 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4099 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || |
| 4100 | ndlp->nlp_state != NLP_STE_MAPPED_NODE) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4101 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4102 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4103 | piocbq = &(lpfc_cmd->cur_iocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4104 | piocbq->vport = vport; |
| 4105 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4106 | piocb = &piocbq->iocb; |
| 4107 | |
| 4108 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4109 | /* Clear out any old data in the FCP command area */ |
| 4110 | memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd)); |
| 4111 | int_to_scsilun(lun, &fcp_cmnd->fcp_lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4112 | fcp_cmnd->fcpCntl2 = task_mgmt_cmd; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4113 | if (vport->phba->sli_rev == 3 && |
| 4114 | !(vport->phba->sli3_options & LPFC_SLI3_BG_ENABLED)) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4115 | lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4116 | piocb->ulpCommand = CMD_FCP_ICMND64_CR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4117 | piocb->ulpContext = ndlp->nlp_rpi; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4118 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
| 4119 | piocb->ulpContext = |
| 4120 | vport->phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
| 4121 | } |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 4122 | piocb->ulpFCP2Rcvy = (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) ? 1 : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4123 | piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f); |
James Smart | f9226c2 | 2014-02-20 09:57:28 -0500 | [diff] [blame] | 4124 | piocb->ulpPU = 0; |
| 4125 | piocb->un.fcpi.fcpi_parm = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4126 | |
| 4127 | /* ulpTimeout is only one byte */ |
| 4128 | if (lpfc_cmd->timeout > 0xff) { |
| 4129 | /* |
| 4130 | * Do not timeout the command at the firmware level. |
| 4131 | * The driver will provide the timeout mechanism. |
| 4132 | */ |
| 4133 | piocb->ulpTimeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4134 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4135 | piocb->ulpTimeout = lpfc_cmd->timeout; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4136 | |
| 4137 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 4138 | lpfc_sli4_set_rsp_sgl_last(vport->phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4139 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4140 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4141 | } |
| 4142 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4143 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4144 | * lpfc_scsi_api_table_setup - Set up scsi api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4145 | * @phba: The hba struct for which this call is being executed. |
| 4146 | * @dev_grp: The HBA PCI-Device group number. |
| 4147 | * |
| 4148 | * This routine sets up the SCSI interface API function jump table in @phba |
| 4149 | * struct. |
| 4150 | * Returns: 0 - success, -ENODEV - failure. |
| 4151 | **/ |
| 4152 | int |
| 4153 | lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 4154 | { |
| 4155 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4156 | phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf; |
| 4157 | phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4158 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4159 | switch (dev_grp) { |
| 4160 | case LPFC_PCI_DEV_LP: |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4161 | phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4162 | 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] | 4163 | phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4164 | phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s3; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4165 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4166 | case LPFC_PCI_DEV_OC: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4167 | phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s4; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4168 | 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] | 4169 | phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s4; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4170 | phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s4; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4171 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4172 | default: |
| 4173 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4174 | "1418 Invalid HBA PCI-device group: 0x%x\n", |
| 4175 | dev_grp); |
| 4176 | return -ENODEV; |
| 4177 | break; |
| 4178 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4179 | phba->lpfc_rampdown_queue_depth = lpfc_rampdown_queue_depth; |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 4180 | phba->lpfc_scsi_cmd_iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4181 | return 0; |
| 4182 | } |
| 4183 | |
| 4184 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4185 | * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4186 | * @phba: The Hba for which this call is being executed. |
| 4187 | * @cmdiocbq: Pointer to lpfc_iocbq data structure. |
| 4188 | * @rspiocbq: Pointer to lpfc_iocbq data structure. |
| 4189 | * |
| 4190 | * This routine is IOCB completion routine for device reset and target reset |
| 4191 | * routine. This routine release scsi buffer associated with lpfc_cmd. |
| 4192 | **/ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4193 | static void |
| 4194 | lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba, |
| 4195 | struct lpfc_iocbq *cmdiocbq, |
| 4196 | struct lpfc_iocbq *rspiocbq) |
| 4197 | { |
| 4198 | struct lpfc_scsi_buf *lpfc_cmd = |
| 4199 | (struct lpfc_scsi_buf *) cmdiocbq->context1; |
| 4200 | if (lpfc_cmd) |
| 4201 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 4202 | return; |
| 4203 | } |
| 4204 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4205 | /** |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 4206 | * lpfc_check_pci_resettable - Walks list of devices on pci_dev's bus to check |
| 4207 | * if issuing a pci_bus_reset is possibly unsafe |
| 4208 | * @phba: lpfc_hba pointer. |
| 4209 | * |
| 4210 | * Description: |
| 4211 | * Walks the bus_list to ensure only PCI devices with Emulex |
| 4212 | * vendor id, device ids that support hot reset, and only one occurrence |
| 4213 | * of function 0. |
| 4214 | * |
| 4215 | * Returns: |
| 4216 | * -EBADSLT, detected invalid device |
| 4217 | * 0, successful |
| 4218 | */ |
| 4219 | int |
| 4220 | lpfc_check_pci_resettable(const struct lpfc_hba *phba) |
| 4221 | { |
| 4222 | const struct pci_dev *pdev = phba->pcidev; |
| 4223 | struct pci_dev *ptr = NULL; |
| 4224 | u8 counter = 0; |
| 4225 | |
| 4226 | /* Walk the list of devices on the pci_dev's bus */ |
| 4227 | list_for_each_entry(ptr, &pdev->bus->devices, bus_list) { |
| 4228 | /* Check for Emulex Vendor ID */ |
| 4229 | if (ptr->vendor != PCI_VENDOR_ID_EMULEX) { |
| 4230 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4231 | "8346 Non-Emulex vendor found: " |
| 4232 | "0x%04x\n", ptr->vendor); |
| 4233 | return -EBADSLT; |
| 4234 | } |
| 4235 | |
| 4236 | /* Check for valid Emulex Device ID */ |
| 4237 | switch (ptr->device) { |
| 4238 | case PCI_DEVICE_ID_LANCER_FC: |
| 4239 | case PCI_DEVICE_ID_LANCER_G6_FC: |
| 4240 | case PCI_DEVICE_ID_LANCER_G7_FC: |
| 4241 | break; |
| 4242 | default: |
| 4243 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4244 | "8347 Invalid device found: " |
| 4245 | "0x%04x\n", ptr->device); |
| 4246 | return -EBADSLT; |
| 4247 | } |
| 4248 | |
| 4249 | /* Check for only one function 0 ID to ensure only one HBA on |
| 4250 | * secondary bus |
| 4251 | */ |
| 4252 | if (ptr->devfn == 0) { |
| 4253 | if (++counter > 1) { |
| 4254 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4255 | "8348 More than one device on " |
| 4256 | "secondary bus found\n"); |
| 4257 | return -EBADSLT; |
| 4258 | } |
| 4259 | } |
| 4260 | } |
| 4261 | |
| 4262 | return 0; |
| 4263 | } |
| 4264 | |
| 4265 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4266 | * lpfc_info - Info entry point of scsi_host_template data structure |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4267 | * @host: The scsi host for which this call is being executed. |
| 4268 | * |
| 4269 | * This routine provides module information about hba. |
| 4270 | * |
| 4271 | * Reutrn code: |
| 4272 | * Pointer to char - Success. |
| 4273 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4274 | const char * |
| 4275 | lpfc_info(struct Scsi_Host *host) |
| 4276 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4277 | struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata; |
| 4278 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 4279 | int link_speed = 0; |
| 4280 | static char lpfcinfobuf[384]; |
| 4281 | char tmp[384] = {0}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4282 | |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 4283 | memset(lpfcinfobuf, 0, sizeof(lpfcinfobuf)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4284 | if (phba && phba->pcidev){ |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 4285 | /* Model Description */ |
| 4286 | scnprintf(tmp, sizeof(tmp), phba->ModelDesc); |
| 4287 | if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >= |
| 4288 | sizeof(lpfcinfobuf)) |
| 4289 | goto buffer_done; |
| 4290 | |
| 4291 | /* PCI Info */ |
| 4292 | scnprintf(tmp, sizeof(tmp), |
| 4293 | " on PCI bus %02x device %02x irq %d", |
| 4294 | phba->pcidev->bus->number, phba->pcidev->devfn, |
| 4295 | phba->pcidev->irq); |
| 4296 | if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >= |
| 4297 | sizeof(lpfcinfobuf)) |
| 4298 | goto buffer_done; |
| 4299 | |
| 4300 | /* Port Number */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4301 | if (phba->Port[0]) { |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 4302 | scnprintf(tmp, sizeof(tmp), " port %s", phba->Port); |
| 4303 | if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >= |
| 4304 | sizeof(lpfcinfobuf)) |
| 4305 | goto buffer_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4306 | } |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 4307 | |
| 4308 | /* Link Speed */ |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 4309 | link_speed = lpfc_sli_port_speed_get(phba); |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 4310 | if (link_speed != 0) { |
| 4311 | scnprintf(tmp, sizeof(tmp), |
| 4312 | " Logical Link Speed: %d Mbps", link_speed); |
| 4313 | if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >= |
| 4314 | sizeof(lpfcinfobuf)) |
| 4315 | goto buffer_done; |
| 4316 | } |
| 4317 | |
| 4318 | /* PCI resettable */ |
| 4319 | if (!lpfc_check_pci_resettable(phba)) { |
| 4320 | scnprintf(tmp, sizeof(tmp), " PCI resettable"); |
| 4321 | strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)); |
| 4322 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4323 | } |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 4324 | |
| 4325 | buffer_done: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4326 | return lpfcinfobuf; |
| 4327 | } |
| 4328 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4329 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4330 | * lpfc_poll_rearm_time - Routine to modify fcp_poll timer of hba |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4331 | * @phba: The Hba for which this call is being executed. |
| 4332 | * |
| 4333 | * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo. |
| 4334 | * The default value of cfg_poll_tmo is 10 milliseconds. |
| 4335 | **/ |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4336 | static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba) |
| 4337 | { |
| 4338 | unsigned long poll_tmo_expires = |
| 4339 | (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo)); |
| 4340 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4341 | if (!list_empty(&phba->sli.sli3_ring[LPFC_FCP_RING].txcmplq)) |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4342 | mod_timer(&phba->fcp_poll_timer, |
| 4343 | poll_tmo_expires); |
| 4344 | } |
| 4345 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4346 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4347 | * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4348 | * @phba: The Hba for which this call is being executed. |
| 4349 | * |
| 4350 | * This routine starts the fcp_poll_timer of @phba. |
| 4351 | **/ |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4352 | void lpfc_poll_start_timer(struct lpfc_hba * phba) |
| 4353 | { |
| 4354 | lpfc_poll_rearm_timer(phba); |
| 4355 | } |
| 4356 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4357 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4358 | * lpfc_poll_timeout - Restart polling timer |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4359 | * @ptr: Map to lpfc_hba data structure pointer. |
| 4360 | * |
| 4361 | * This routine restarts fcp_poll timer, when FCP ring polling is enable |
| 4362 | * and FCP Ring interrupt is disable. |
| 4363 | **/ |
| 4364 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4365 | void lpfc_poll_timeout(struct timer_list *t) |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4366 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4367 | struct lpfc_hba *phba = from_timer(phba, t, fcp_poll_timer); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4368 | |
| 4369 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4370 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4371 | &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4372 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4373 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 4374 | lpfc_poll_rearm_timer(phba); |
| 4375 | } |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4376 | } |
| 4377 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4378 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4379 | * lpfc_queuecommand - scsi_host_template queuecommand entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4380 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 4381 | * @done: Pointer to done routine. |
| 4382 | * |
| 4383 | * Driver registers this routine to scsi midlayer to submit a @cmd to process. |
| 4384 | * This routine prepares an IOCB from scsi command and provides to firmware. |
| 4385 | * The @done callback is invoked after driver finished processing the command. |
| 4386 | * |
| 4387 | * Return value : |
| 4388 | * 0 - Success |
| 4389 | * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily. |
| 4390 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4391 | static int |
James Smart | b9a7c63 | 2012-08-03 12:35:24 -0400 | [diff] [blame] | 4392 | lpfc_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4393 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4394 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4395 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 4396 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 4397 | struct lpfc_nodelist *ndlp; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4398 | struct lpfc_scsi_buf *lpfc_cmd; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4399 | 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] | 4400 | int err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4401 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 4402 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 4403 | |
| 4404 | /* sanity check on references */ |
| 4405 | if (unlikely(!rdata) || unlikely(!rport)) |
| 4406 | goto out_fail_command; |
| 4407 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4408 | err = fc_remote_port_chkready(rport); |
| 4409 | if (err) { |
| 4410 | cmnd->result = err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4411 | goto out_fail_command; |
| 4412 | } |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 4413 | ndlp = rdata->pnode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4414 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 4415 | if ((scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) && |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4416 | (!(phba->sli3_options & LPFC_SLI3_BG_ENABLED))) { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4417 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4418 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 4419 | "9058 BLKGRD: ERROR: rcvd protected cmd:%02x" |
| 4420 | " op:%02x str=%s without registering for" |
| 4421 | " BlockGuard - Rejecting command\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4422 | cmnd->cmnd[0], scsi_get_prot_op(cmnd), |
| 4423 | dif_op_str[scsi_get_prot_op(cmnd)]); |
| 4424 | goto out_fail_command; |
| 4425 | } |
| 4426 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4427 | /* |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4428 | * Catch race where our node has transitioned, but the |
| 4429 | * transport is still transitioning. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4430 | */ |
James Smart | 6b415f5 | 2012-06-12 13:54:59 -0400 | [diff] [blame] | 4431 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 4432 | goto out_tgt_busy; |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 4433 | if (lpfc_ndlp_check_qdepth(phba, ndlp)) { |
| 4434 | if (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth) { |
| 4435 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_ERROR, |
| 4436 | "3377 Target Queue Full, scsi Id:%d " |
| 4437 | "Qdepth:%d Pending command:%d" |
| 4438 | " WWNN:%02x:%02x:%02x:%02x:" |
| 4439 | "%02x:%02x:%02x:%02x, " |
| 4440 | " WWPN:%02x:%02x:%02x:%02x:" |
| 4441 | "%02x:%02x:%02x:%02x", |
| 4442 | ndlp->nlp_sid, ndlp->cmd_qdepth, |
| 4443 | atomic_read(&ndlp->cmd_pending), |
| 4444 | ndlp->nlp_nodename.u.wwn[0], |
| 4445 | ndlp->nlp_nodename.u.wwn[1], |
| 4446 | ndlp->nlp_nodename.u.wwn[2], |
| 4447 | ndlp->nlp_nodename.u.wwn[3], |
| 4448 | ndlp->nlp_nodename.u.wwn[4], |
| 4449 | ndlp->nlp_nodename.u.wwn[5], |
| 4450 | ndlp->nlp_nodename.u.wwn[6], |
| 4451 | ndlp->nlp_nodename.u.wwn[7], |
| 4452 | ndlp->nlp_portname.u.wwn[0], |
| 4453 | ndlp->nlp_portname.u.wwn[1], |
| 4454 | ndlp->nlp_portname.u.wwn[2], |
| 4455 | ndlp->nlp_portname.u.wwn[3], |
| 4456 | ndlp->nlp_portname.u.wwn[4], |
| 4457 | ndlp->nlp_portname.u.wwn[5], |
| 4458 | ndlp->nlp_portname.u.wwn[6], |
| 4459 | ndlp->nlp_portname.u.wwn[7]); |
| 4460 | goto out_tgt_busy; |
| 4461 | } |
James Smart | 64bf009 | 2018-01-30 15:58:53 -0800 | [diff] [blame] | 4462 | } |
James Smart | f91bc59 | 2018-04-09 14:24:22 -0700 | [diff] [blame] | 4463 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4464 | lpfc_cmd = lpfc_get_scsi_buf(phba, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4465 | if (lpfc_cmd == NULL) { |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4466 | lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4467 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4468 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_ERROR, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4469 | "0707 driver's buffer pool is empty, " |
| 4470 | "IO busied\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4471 | goto out_host_busy; |
| 4472 | } |
| 4473 | |
| 4474 | /* |
| 4475 | * Store the midlayer's command structure for the completion phase |
| 4476 | * and complete the command initialization. |
| 4477 | */ |
| 4478 | lpfc_cmd->pCmd = cmnd; |
| 4479 | lpfc_cmd->rdata = rdata; |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 4480 | lpfc_cmd->ndlp = ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4481 | cmnd->host_scribble = (unsigned char *)lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4482 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4483 | if (scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4484 | if (vport->phba->cfg_enable_bg) { |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 4485 | lpfc_printf_vlog(vport, |
| 4486 | KERN_INFO, LOG_SCSI_CMD, |
James Smart | 2613470 | 2012-08-14 14:25:50 -0400 | [diff] [blame] | 4487 | "9033 BLKGRD: rcvd %s cmd:x%x " |
| 4488 | "sector x%llx cnt %u pt %x\n", |
| 4489 | dif_op_str[scsi_get_prot_op(cmnd)], |
| 4490 | cmnd->cmnd[0], |
| 4491 | (unsigned long long)scsi_get_lba(cmnd), |
| 4492 | blk_rq_sectors(cmnd->request), |
| 4493 | (cmnd->cmnd[1]>>5)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4494 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4495 | err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 4496 | } else { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4497 | if (vport->phba->cfg_enable_bg) { |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 4498 | lpfc_printf_vlog(vport, |
| 4499 | KERN_INFO, LOG_SCSI_CMD, |
James Smart | 2613470 | 2012-08-14 14:25:50 -0400 | [diff] [blame] | 4500 | "9038 BLKGRD: rcvd PROT_NORMAL cmd: " |
| 4501 | "x%x sector x%llx cnt %u pt %x\n", |
| 4502 | cmnd->cmnd[0], |
| 4503 | (unsigned long long)scsi_get_lba(cmnd), |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 4504 | blk_rq_sectors(cmnd->request), |
James Smart | 2613470 | 2012-08-14 14:25:50 -0400 | [diff] [blame] | 4505 | (cmnd->cmnd[1]>>5)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4506 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4507 | err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 4508 | } |
| 4509 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4510 | if (err) |
| 4511 | goto out_host_busy_free_buf; |
| 4512 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4513 | lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4514 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4515 | err = lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4516 | &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4517 | if (err) { |
James Smart | 76f96b6 | 2013-12-17 20:29:01 -0500 | [diff] [blame] | 4518 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4519 | "3376 FCP could not issue IOCB err %x" |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4520 | "FCP cmd x%x <%d/%llu> " |
James Smart | 76f96b6 | 2013-12-17 20:29:01 -0500 | [diff] [blame] | 4521 | "sid: x%x did: x%x oxid: x%x " |
| 4522 | "Data: x%x x%x x%x x%x\n", |
| 4523 | err, cmnd->cmnd[0], |
| 4524 | cmnd->device ? cmnd->device->id : 0xffff, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4525 | cmnd->device ? cmnd->device->lun : (u64) -1, |
James Smart | 76f96b6 | 2013-12-17 20:29:01 -0500 | [diff] [blame] | 4526 | vport->fc_myDID, ndlp->nlp_DID, |
| 4527 | phba->sli_rev == LPFC_SLI_REV4 ? |
| 4528 | lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff, |
| 4529 | lpfc_cmd->cur_iocbq.iocb.ulpContext, |
| 4530 | lpfc_cmd->cur_iocbq.iocb.ulpIoTag, |
| 4531 | lpfc_cmd->cur_iocbq.iocb.ulpTimeout, |
| 4532 | (uint32_t) |
| 4533 | (cmnd->request->timeout / 1000)); |
| 4534 | |
James Smart | 2cee780 | 2017-06-01 21:07:02 -0700 | [diff] [blame] | 4535 | switch (lpfc_cmd->fcp_cmnd->fcpCntl3) { |
| 4536 | case WRITE_DATA: |
| 4537 | atomic_dec(&phba->fc4ScsiOutputRequests); |
| 4538 | break; |
| 4539 | case READ_DATA: |
| 4540 | atomic_dec(&phba->fc4ScsiInputRequests); |
| 4541 | break; |
| 4542 | default: |
| 4543 | atomic_dec(&phba->fc4ScsiControlRequests); |
| 4544 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4545 | goto out_host_busy_free_buf; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4546 | } |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4547 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4548 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4549 | &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4550 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4551 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 4552 | lpfc_poll_rearm_timer(phba); |
| 4553 | } |
| 4554 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4555 | return 0; |
| 4556 | |
| 4557 | out_host_busy_free_buf: |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 4558 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4559 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4560 | out_host_busy: |
| 4561 | return SCSI_MLQUEUE_HOST_BUSY; |
| 4562 | |
Mike Christie | 3496343 | 2011-02-25 14:04:28 -0600 | [diff] [blame] | 4563 | out_tgt_busy: |
| 4564 | return SCSI_MLQUEUE_TARGET_BUSY; |
| 4565 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4566 | out_fail_command: |
James Smart | b9a7c63 | 2012-08-03 12:35:24 -0400 | [diff] [blame] | 4567 | cmnd->scsi_done(cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4568 | return 0; |
| 4569 | } |
| 4570 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 4571 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4572 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4573 | * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4574 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 4575 | * |
| 4576 | * This routine aborts @cmnd pending in base driver. |
| 4577 | * |
| 4578 | * Return code : |
| 4579 | * 0x2003 - Error |
| 4580 | * 0x2002 - Success |
| 4581 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4582 | static int |
James.Smart@Emulex.Com | 63c59c3 | 2005-11-28 11:41:53 -0500 | [diff] [blame] | 4583 | lpfc_abort_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4584 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4585 | struct Scsi_Host *shost = cmnd->device->host; |
| 4586 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4587 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4588 | struct lpfc_iocbq *iocb; |
| 4589 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4590 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4591 | IOCB_t *cmd, *icmd; |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4592 | int ret = SUCCESS, status = 0; |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 4593 | struct lpfc_sli_ring *pring_s4 = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4594 | int ret_val; |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 4595 | unsigned long flags; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4596 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4597 | |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4598 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 4599 | if (status != 0 && status != SUCCESS) |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4600 | return status; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4601 | |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4602 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4603 | /* driver queued commands are in process of being flushed */ |
| 4604 | if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) { |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4605 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4606 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4607 | "3168 SCSI Layer abort requested I/O has been " |
| 4608 | "flushed by LLD.\n"); |
| 4609 | return FAILED; |
| 4610 | } |
| 4611 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4612 | lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble; |
James Smart | 92e3af6 | 2012-08-14 14:26:28 -0400 | [diff] [blame] | 4613 | if (!lpfc_cmd || !lpfc_cmd->pCmd) { |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4614 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 4615 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4616 | "2873 SCSI Layer I/O Abort Request IO CMPL Status " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4617 | "x%x ID %d LUN %llu\n", |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4618 | SUCCESS, cmnd->device->id, cmnd->device->lun); |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 4619 | return SUCCESS; |
| 4620 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4621 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4622 | iocb = &lpfc_cmd->cur_iocbq; |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 4623 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4624 | pring_s4 = phba->sli4_hba.hdwq[iocb->hba_wqidx].fcp_wq->pring; |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 4625 | if (!pring_s4) { |
| 4626 | ret = FAILED; |
| 4627 | goto out_unlock; |
| 4628 | } |
| 4629 | spin_lock(&pring_s4->ring_lock); |
| 4630 | } |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4631 | /* the command is in process of being cancelled */ |
| 4632 | if (!(iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ)) { |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 4633 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4634 | spin_unlock(&pring_s4->ring_lock); |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4635 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4636 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4637 | "3169 SCSI Layer abort requested I/O has been " |
| 4638 | "cancelled by LLD.\n"); |
| 4639 | return FAILED; |
| 4640 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4641 | /* |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4642 | * If pCmd field of the corresponding lpfc_scsi_buf structure |
| 4643 | * points to a different SCSI command, then the driver has |
| 4644 | * already completed this command, but the midlayer did not |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4645 | * see the completion before the eh fired. Just return SUCCESS. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4646 | */ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4647 | if (lpfc_cmd->pCmd != cmnd) { |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 4648 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4649 | spin_unlock(&pring_s4->ring_lock); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4650 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4651 | "3170 SCSI Layer abort requested I/O has been " |
| 4652 | "completed by LLD.\n"); |
| 4653 | goto out_unlock; |
| 4654 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4655 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4656 | BUG_ON(iocb->context1 != lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4657 | |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4658 | /* abort issued in recovery is still in progress */ |
| 4659 | if (iocb->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 4660 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4661 | "3389 SCSI Layer I/O Abort Request is pending\n"); |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 4662 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4663 | spin_unlock(&pring_s4->ring_lock); |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4664 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4665 | goto wait_for_cmpl; |
| 4666 | } |
| 4667 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4668 | abtsiocb = __lpfc_sli_get_iocbq(phba); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4669 | if (abtsiocb == NULL) { |
| 4670 | ret = FAILED; |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 4671 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4672 | spin_unlock(&pring_s4->ring_lock); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4673 | goto out_unlock; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4674 | } |
| 4675 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 4676 | /* Indicate the IO is being aborted by the driver. */ |
| 4677 | iocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 4678 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4679 | /* |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4680 | * The scsi command can not be in txq and it is in flight because the |
| 4681 | * pCmd is still pointig at the SCSI command we have to abort. There |
| 4682 | * is no need to search the txcmplq. Just send an abort to the FW. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4683 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4684 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4685 | cmd = &iocb->iocb; |
| 4686 | icmd = &abtsiocb->iocb; |
| 4687 | icmd->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 4688 | icmd->un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4689 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4690 | icmd->un.acxri.abortIoTag = iocb->sli4_xritag; |
| 4691 | else |
| 4692 | icmd->un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4693 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4694 | icmd->ulpLe = 1; |
| 4695 | icmd->ulpClass = cmd->ulpClass; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4696 | |
| 4697 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4698 | abtsiocb->hba_wqidx = iocb->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 4699 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 4700 | if (iocb->iocb_flag & LPFC_IO_FOF) |
| 4701 | abtsiocb->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4702 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4703 | if (lpfc_is_link_up(phba)) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4704 | icmd->ulpCommand = CMD_ABORT_XRI_CN; |
| 4705 | else |
| 4706 | icmd->ulpCommand = CMD_CLOSE_XRI_CN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4707 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4708 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4709 | abtsiocb->vport = vport; |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 4710 | lpfc_cmd->waitq = &waitq; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4711 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4712 | /* Note: both hbalock and ring_lock must be set here */ |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4713 | ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 4714 | abtsiocb, 0); |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 4715 | spin_unlock(&pring_s4->ring_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4716 | } else { |
| 4717 | ret_val = __lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, |
| 4718 | abtsiocb, 0); |
| 4719 | } |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4720 | /* no longer need the lock after this point */ |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4721 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4722 | |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4723 | |
| 4724 | if (ret_val == IOCB_ERROR) { |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 4725 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4726 | spin_lock_irqsave(&pring_s4->ring_lock, flags); |
| 4727 | else |
| 4728 | spin_lock_irqsave(&phba->hbalock, flags); |
| 4729 | /* Indicate the IO is not being aborted by the driver. */ |
| 4730 | iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 4731 | lpfc_cmd->waitq = NULL; |
| 4732 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4733 | spin_unlock_irqrestore(&pring_s4->ring_lock, flags); |
| 4734 | else |
| 4735 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4736 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| 4737 | ret = FAILED; |
| 4738 | goto out; |
| 4739 | } |
| 4740 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4741 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4742 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4743 | &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4744 | |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4745 | wait_for_cmpl: |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4746 | /* Wait for abort to complete */ |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4747 | wait_event_timeout(waitq, |
| 4748 | (lpfc_cmd->pCmd != cmnd), |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4749 | msecs_to_jiffies(2*vport->cfg_devloss_tmo*1000)); |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4750 | |
| 4751 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4752 | lpfc_cmd->waitq = NULL; |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4753 | spin_unlock_irqrestore(shost->host_lock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4754 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4755 | if (lpfc_cmd->pCmd == cmnd) { |
| 4756 | ret = FAILED; |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4757 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 4758 | "0748 abort handler timed out waiting " |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 4759 | "for aborting I/O (xri:x%x) to complete: " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4760 | "ret %#x, ID %d, LUN %llu\n", |
James Smart | 247ca94 | 2012-08-14 14:26:13 -0400 | [diff] [blame] | 4761 | iocb->sli4_xritag, ret, |
| 4762 | cmnd->device->id, cmnd->device->lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4763 | } |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4764 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4765 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4766 | out_unlock: |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4767 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4768 | out: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4769 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4770 | "0749 SCSI Layer I/O Abort Request Status x%x ID %d " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4771 | "LUN %llu\n", ret, cmnd->device->id, |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 4772 | cmnd->device->lun); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4773 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4774 | } |
| 4775 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4776 | static char * |
| 4777 | lpfc_taskmgmt_name(uint8_t task_mgmt_cmd) |
| 4778 | { |
| 4779 | switch (task_mgmt_cmd) { |
| 4780 | case FCP_ABORT_TASK_SET: |
| 4781 | return "ABORT_TASK_SET"; |
| 4782 | case FCP_CLEAR_TASK_SET: |
| 4783 | return "FCP_CLEAR_TASK_SET"; |
| 4784 | case FCP_BUS_RESET: |
| 4785 | return "FCP_BUS_RESET"; |
| 4786 | case FCP_LUN_RESET: |
| 4787 | return "FCP_LUN_RESET"; |
| 4788 | case FCP_TARGET_RESET: |
| 4789 | return "FCP_TARGET_RESET"; |
| 4790 | case FCP_CLEAR_ACA: |
| 4791 | return "FCP_CLEAR_ACA"; |
| 4792 | case FCP_TERMINATE_TASK: |
| 4793 | return "FCP_TERMINATE_TASK"; |
| 4794 | default: |
| 4795 | return "unknown"; |
| 4796 | } |
| 4797 | } |
| 4798 | |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 4799 | |
| 4800 | /** |
| 4801 | * lpfc_check_fcp_rsp - check the returned fcp_rsp to see if task failed |
| 4802 | * @vport: The virtual port for which this call is being executed. |
| 4803 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. |
| 4804 | * |
| 4805 | * This routine checks the FCP RSP INFO to see if the tsk mgmt command succeded |
| 4806 | * |
| 4807 | * Return code : |
| 4808 | * 0x2003 - Error |
| 4809 | * 0x2002 - Success |
| 4810 | **/ |
| 4811 | static int |
| 4812 | lpfc_check_fcp_rsp(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd) |
| 4813 | { |
| 4814 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
| 4815 | uint32_t rsp_info; |
| 4816 | uint32_t rsp_len; |
| 4817 | uint8_t rsp_info_code; |
| 4818 | int ret = FAILED; |
| 4819 | |
| 4820 | |
| 4821 | if (fcprsp == NULL) |
| 4822 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4823 | "0703 fcp_rsp is missing\n"); |
| 4824 | else { |
| 4825 | rsp_info = fcprsp->rspStatus2; |
| 4826 | rsp_len = be32_to_cpu(fcprsp->rspRspLen); |
| 4827 | rsp_info_code = fcprsp->rspInfo3; |
| 4828 | |
| 4829 | |
| 4830 | lpfc_printf_vlog(vport, KERN_INFO, |
| 4831 | LOG_FCP, |
| 4832 | "0706 fcp_rsp valid 0x%x," |
| 4833 | " rsp len=%d code 0x%x\n", |
| 4834 | rsp_info, |
| 4835 | rsp_len, rsp_info_code); |
| 4836 | |
| 4837 | if ((fcprsp->rspStatus2&RSP_LEN_VALID) && (rsp_len == 8)) { |
| 4838 | switch (rsp_info_code) { |
| 4839 | case RSP_NO_FAILURE: |
| 4840 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4841 | "0715 Task Mgmt No Failure\n"); |
| 4842 | ret = SUCCESS; |
| 4843 | break; |
| 4844 | case RSP_TM_NOT_SUPPORTED: /* TM rejected */ |
| 4845 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4846 | "0716 Task Mgmt Target " |
| 4847 | "reject\n"); |
| 4848 | break; |
| 4849 | case RSP_TM_NOT_COMPLETED: /* TM failed */ |
| 4850 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4851 | "0717 Task Mgmt Target " |
| 4852 | "failed TM\n"); |
| 4853 | break; |
| 4854 | case RSP_TM_INVALID_LU: /* TM to invalid LU! */ |
| 4855 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4856 | "0718 Task Mgmt to invalid " |
| 4857 | "LUN\n"); |
| 4858 | break; |
| 4859 | } |
| 4860 | } |
| 4861 | } |
| 4862 | return ret; |
| 4863 | } |
| 4864 | |
| 4865 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4866 | /** |
| 4867 | * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler |
| 4868 | * @vport: The virtual port for which this call is being executed. |
| 4869 | * @rdata: Pointer to remote port local data |
| 4870 | * @tgt_id: Target ID of remote device. |
| 4871 | * @lun_id: Lun number for the TMF |
| 4872 | * @task_mgmt_cmd: type of TMF to send |
| 4873 | * |
| 4874 | * This routine builds and sends a TMF (SCSI Task Mgmt Function) to |
| 4875 | * a remote port. |
| 4876 | * |
| 4877 | * Return Code: |
| 4878 | * 0x2003 - Error |
| 4879 | * 0x2002 - Success. |
| 4880 | **/ |
| 4881 | static int |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 4882 | lpfc_send_taskmgmt(struct lpfc_vport *vport, struct scsi_cmnd *cmnd, |
| 4883 | unsigned int tgt_id, uint64_t lun_id, |
| 4884 | uint8_t task_mgmt_cmd) |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4885 | { |
| 4886 | struct lpfc_hba *phba = vport->phba; |
| 4887 | struct lpfc_scsi_buf *lpfc_cmd; |
| 4888 | struct lpfc_iocbq *iocbq; |
| 4889 | struct lpfc_iocbq *iocbqrsp; |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 4890 | struct lpfc_rport_data *rdata; |
| 4891 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4892 | int ret; |
| 4893 | int status; |
| 4894 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 4895 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
| 4896 | if (!rdata || !rdata->pnode || !NLP_CHK_NODE_ACT(rdata->pnode)) |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4897 | return FAILED; |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 4898 | pnode = rdata->pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4899 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 4900 | lpfc_cmd = lpfc_get_scsi_buf(phba, pnode); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4901 | if (lpfc_cmd == NULL) |
| 4902 | return FAILED; |
James Smart | 0c41122 | 2013-09-06 12:22:46 -0400 | [diff] [blame] | 4903 | lpfc_cmd->timeout = phba->cfg_task_mgmt_tmo; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4904 | lpfc_cmd->rdata = rdata; |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 4905 | lpfc_cmd->pCmd = cmnd; |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 4906 | lpfc_cmd->ndlp = pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4907 | |
| 4908 | status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun_id, |
| 4909 | task_mgmt_cmd); |
| 4910 | if (!status) { |
| 4911 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 4912 | return FAILED; |
| 4913 | } |
| 4914 | |
| 4915 | iocbq = &lpfc_cmd->cur_iocbq; |
| 4916 | iocbqrsp = lpfc_sli_get_iocbq(phba); |
| 4917 | if (iocbqrsp == NULL) { |
| 4918 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 4919 | return FAILED; |
| 4920 | } |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 4921 | iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4922 | |
| 4923 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4924 | "0702 Issue %s to TGT %d LUN %llu " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4925 | "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] | 4926 | lpfc_taskmgmt_name(task_mgmt_cmd), tgt_id, lun_id, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4927 | pnode->nlp_rpi, pnode->nlp_flag, iocbq->sli4_xritag, |
| 4928 | iocbq->iocb_flag); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4929 | |
| 4930 | status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING, |
| 4931 | iocbq, iocbqrsp, lpfc_cmd->timeout); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 4932 | if ((status != IOCB_SUCCESS) || |
| 4933 | (iocbqrsp->iocb.ulpStatus != IOSTAT_SUCCESS)) { |
James Smart | ae374a3 | 2015-05-22 10:42:41 -0400 | [diff] [blame] | 4934 | if (status != IOCB_SUCCESS || |
| 4935 | iocbqrsp->iocb.ulpStatus != IOSTAT_FCP_RSP_ERROR) |
| 4936 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 4937 | "0727 TMF %s to TGT %d LUN %llu " |
| 4938 | "failed (%d, %d) iocb_flag x%x\n", |
| 4939 | lpfc_taskmgmt_name(task_mgmt_cmd), |
| 4940 | tgt_id, lun_id, |
| 4941 | iocbqrsp->iocb.ulpStatus, |
| 4942 | iocbqrsp->iocb.un.ulpWord[4], |
| 4943 | iocbq->iocb_flag); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 4944 | /* if ulpStatus != IOCB_SUCCESS, then status == IOCB_SUCCESS */ |
| 4945 | if (status == IOCB_SUCCESS) { |
| 4946 | if (iocbqrsp->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 4947 | /* Something in the FCP_RSP was invalid. |
| 4948 | * Check conditions */ |
| 4949 | ret = lpfc_check_fcp_rsp(vport, lpfc_cmd); |
| 4950 | else |
| 4951 | ret = FAILED; |
| 4952 | } else if (status == IOCB_TIMEDOUT) { |
| 4953 | ret = TIMEOUT_ERROR; |
| 4954 | } else { |
| 4955 | ret = FAILED; |
| 4956 | } |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 4957 | } else |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4958 | ret = SUCCESS; |
| 4959 | |
| 4960 | lpfc_sli_release_iocbq(phba, iocbqrsp); |
| 4961 | |
| 4962 | if (ret != TIMEOUT_ERROR) |
| 4963 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 4964 | |
| 4965 | return ret; |
| 4966 | } |
| 4967 | |
| 4968 | /** |
| 4969 | * lpfc_chk_tgt_mapped - |
| 4970 | * @vport: The virtual port to check on |
| 4971 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 4972 | * |
| 4973 | * This routine delays until the scsi target (aka rport) for the |
| 4974 | * command exists (is present and logged in) or we declare it non-existent. |
| 4975 | * |
| 4976 | * Return code : |
| 4977 | * 0x2003 - Error |
| 4978 | * 0x2002 - Success |
| 4979 | **/ |
| 4980 | static int |
| 4981 | lpfc_chk_tgt_mapped(struct lpfc_vport *vport, struct scsi_cmnd *cmnd) |
| 4982 | { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 4983 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 4984 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4985 | unsigned long later; |
| 4986 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 4987 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 4988 | if (!rdata) { |
| 4989 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4990 | "0797 Tgt Map rport failure: rdata x%p\n", rdata); |
| 4991 | return FAILED; |
| 4992 | } |
| 4993 | pnode = rdata->pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4994 | /* |
| 4995 | * If target is not in a MAPPED state, delay until |
| 4996 | * target is rediscovered or devloss timeout expires. |
| 4997 | */ |
| 4998 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; |
| 4999 | while (time_after(later, jiffies)) { |
| 5000 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 5001 | return FAILED; |
| 5002 | if (pnode->nlp_state == NLP_STE_MAPPED_NODE) |
| 5003 | return SUCCESS; |
| 5004 | schedule_timeout_uninterruptible(msecs_to_jiffies(500)); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5005 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5006 | if (!rdata) |
| 5007 | return FAILED; |
| 5008 | pnode = rdata->pnode; |
| 5009 | } |
| 5010 | if (!pnode || !NLP_CHK_NODE_ACT(pnode) || |
| 5011 | (pnode->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5012 | return FAILED; |
| 5013 | return SUCCESS; |
| 5014 | } |
| 5015 | |
| 5016 | /** |
| 5017 | * lpfc_reset_flush_io_context - |
| 5018 | * @vport: The virtual port (scsi_host) for the flush context |
| 5019 | * @tgt_id: If aborting by Target contect - specifies the target id |
| 5020 | * @lun_id: If aborting by Lun context - specifies the lun id |
| 5021 | * @context: specifies the context level to flush at. |
| 5022 | * |
| 5023 | * After a reset condition via TMF, we need to flush orphaned i/o |
| 5024 | * contexts from the adapter. This routine aborts any contexts |
| 5025 | * outstanding, then waits for their completions. The wait is |
| 5026 | * bounded by devloss_tmo though. |
| 5027 | * |
| 5028 | * Return code : |
| 5029 | * 0x2003 - Error |
| 5030 | * 0x2002 - Success |
| 5031 | **/ |
| 5032 | static int |
| 5033 | lpfc_reset_flush_io_context(struct lpfc_vport *vport, uint16_t tgt_id, |
| 5034 | uint64_t lun_id, lpfc_ctx_cmd context) |
| 5035 | { |
| 5036 | struct lpfc_hba *phba = vport->phba; |
| 5037 | unsigned long later; |
| 5038 | int cnt; |
| 5039 | |
| 5040 | cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context); |
| 5041 | if (cnt) |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 5042 | lpfc_sli_abort_taskmgmt(vport, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5043 | &phba->sli.sli3_ring[LPFC_FCP_RING], |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 5044 | tgt_id, lun_id, context); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5045 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; |
| 5046 | while (time_after(later, jiffies) && cnt) { |
| 5047 | schedule_timeout_uninterruptible(msecs_to_jiffies(20)); |
| 5048 | cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context); |
| 5049 | } |
| 5050 | if (cnt) { |
| 5051 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5052 | "0724 I/O flush failure for context %s : cnt x%x\n", |
| 5053 | ((context == LPFC_CTX_LUN) ? "LUN" : |
| 5054 | ((context == LPFC_CTX_TGT) ? "TGT" : |
| 5055 | ((context == LPFC_CTX_HOST) ? "HOST" : "Unknown"))), |
| 5056 | cnt); |
| 5057 | return FAILED; |
| 5058 | } |
| 5059 | return SUCCESS; |
| 5060 | } |
| 5061 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5062 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5063 | * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5064 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5065 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5066 | * 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] | 5067 | * command. |
| 5068 | * |
| 5069 | * Return code : |
| 5070 | * 0x2003 - Error |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5071 | * 0x2002 - Success |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5072 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5073 | static int |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5074 | lpfc_device_reset_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5075 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5076 | struct Scsi_Host *shost = cmnd->device->host; |
| 5077 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5078 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5079 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5080 | unsigned tgt_id = cmnd->device->id; |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5081 | uint64_t lun_id = cmnd->device->lun; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5082 | struct lpfc_scsi_event_header scsi_event; |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5083 | int status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5084 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5085 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | ad490b6 | 2015-04-07 15:07:26 -0400 | [diff] [blame] | 5086 | if (!rdata || !rdata->pnode) { |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5087 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
James Smart | ad490b6 | 2015-04-07 15:07:26 -0400 | [diff] [blame] | 5088 | "0798 Device Reset rport failure: rdata x%p\n", |
| 5089 | rdata); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5090 | return FAILED; |
| 5091 | } |
| 5092 | pnode = rdata->pnode; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5093 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 5094 | if (status != 0 && status != SUCCESS) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5095 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5096 | |
| 5097 | status = lpfc_chk_tgt_mapped(vport, cmnd); |
| 5098 | if (status == FAILED) { |
| 5099 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5100 | "0721 Device Reset rport failure: rdata x%p\n", rdata); |
| 5101 | return FAILED; |
| 5102 | } |
| 5103 | |
| 5104 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 5105 | scsi_event.subcategory = LPFC_EVENT_LUNRESET; |
| 5106 | scsi_event.lun = lun_id; |
| 5107 | memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 5108 | memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 5109 | |
| 5110 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5111 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
| 5112 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 5113 | status = lpfc_send_taskmgmt(vport, cmnd, tgt_id, lun_id, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5114 | FCP_LUN_RESET); |
| 5115 | |
| 5116 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5117 | "0713 SCSI layer issued Device Reset (%d, %llu) " |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5118 | "return x%x\n", tgt_id, lun_id, status); |
| 5119 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5120 | /* |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5121 | * We have to clean up i/o as : they may be orphaned by the TMF; |
| 5122 | * or if the TMF failed, they may be in an indeterminate state. |
| 5123 | * So, continue on. |
| 5124 | * We will report success if all the i/o aborts successfully. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5125 | */ |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5126 | if (status == SUCCESS) |
| 5127 | status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5128 | LPFC_CTX_LUN); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5129 | |
| 5130 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5131 | } |
| 5132 | |
| 5133 | /** |
| 5134 | * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point |
| 5135 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5136 | * |
| 5137 | * This routine does a target reset by sending a TARGET_RESET task management |
| 5138 | * command. |
| 5139 | * |
| 5140 | * Return code : |
| 5141 | * 0x2003 - Error |
| 5142 | * 0x2002 - Success |
| 5143 | **/ |
| 5144 | static int |
| 5145 | lpfc_target_reset_handler(struct scsi_cmnd *cmnd) |
| 5146 | { |
| 5147 | struct Scsi_Host *shost = cmnd->device->host; |
| 5148 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5149 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5150 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5151 | unsigned tgt_id = cmnd->device->id; |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5152 | uint64_t lun_id = cmnd->device->lun; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5153 | struct lpfc_scsi_event_header scsi_event; |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5154 | int status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5155 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5156 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5157 | if (!rdata) { |
| 5158 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5159 | "0799 Target Reset rport failure: rdata x%p\n", rdata); |
| 5160 | return FAILED; |
| 5161 | } |
| 5162 | pnode = rdata->pnode; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5163 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 5164 | if (status != 0 && status != SUCCESS) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5165 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5166 | |
| 5167 | status = lpfc_chk_tgt_mapped(vport, cmnd); |
| 5168 | if (status == FAILED) { |
| 5169 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5170 | "0722 Target Reset rport failure: rdata x%p\n", rdata); |
James Smart | 63e480f | 2015-04-07 15:07:20 -0400 | [diff] [blame] | 5171 | if (pnode) { |
| 5172 | spin_lock_irq(shost->host_lock); |
| 5173 | pnode->nlp_flag &= ~NLP_NPR_ADISC; |
| 5174 | pnode->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; |
| 5175 | spin_unlock_irq(shost->host_lock); |
| 5176 | } |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 5177 | lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
| 5178 | LPFC_CTX_TGT); |
| 5179 | return FAST_IO_FAIL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5180 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5181 | |
| 5182 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 5183 | scsi_event.subcategory = LPFC_EVENT_TGTRESET; |
| 5184 | scsi_event.lun = 0; |
| 5185 | memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 5186 | memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 5187 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5188 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5189 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5190 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 5191 | status = lpfc_send_taskmgmt(vport, cmnd, tgt_id, lun_id, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5192 | FCP_TARGET_RESET); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5193 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5194 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5195 | "0723 SCSI layer issued Target Reset (%d, %llu) " |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5196 | "return x%x\n", tgt_id, lun_id, status); |
| 5197 | |
| 5198 | /* |
| 5199 | * We have to clean up i/o as : they may be orphaned by the TMF; |
| 5200 | * or if the TMF failed, they may be in an indeterminate state. |
| 5201 | * So, continue on. |
| 5202 | * We will report success if all the i/o aborts successfully. |
| 5203 | */ |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5204 | if (status == SUCCESS) |
| 5205 | status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 5206 | LPFC_CTX_TGT); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5207 | return status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5208 | } |
| 5209 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5210 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5211 | * 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] | 5212 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5213 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5214 | * This routine does target reset to all targets on @cmnd->device->host. |
| 5215 | * This emulates Parallel SCSI Bus Reset Semantics. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5216 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5217 | * Return code : |
| 5218 | * 0x2003 - Error |
| 5219 | * 0x2002 - Success |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5220 | **/ |
Jeff Garzik | 94d0e7b8 | 2005-05-28 07:55:48 -0400 | [diff] [blame] | 5221 | static int |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5222 | lpfc_bus_reset_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5223 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5224 | struct Scsi_Host *shost = cmnd->device->host; |
| 5225 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5226 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5227 | struct lpfc_scsi_event_header scsi_event; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5228 | int match; |
| 5229 | int ret = SUCCESS, status, i; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5230 | |
| 5231 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 5232 | scsi_event.subcategory = LPFC_EVENT_BUSRESET; |
| 5233 | scsi_event.lun = 0; |
| 5234 | memcpy(scsi_event.wwpn, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 5235 | memcpy(scsi_event.wwnn, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| 5236 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5237 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5238 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5239 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 5240 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 5241 | if (status != 0 && status != SUCCESS) |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 5242 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5243 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5244 | /* |
| 5245 | * Since the driver manages a single bus device, reset all |
| 5246 | * targets known to the driver. Should any target reset |
| 5247 | * fail, this routine returns failure to the midlayer. |
| 5248 | */ |
James Smart | e17da18 | 2006-07-06 15:49:25 -0400 | [diff] [blame] | 5249 | for (i = 0; i < LPFC_MAX_TARGET; i++) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5250 | /* Search for mapped node by target ID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5251 | match = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5252 | spin_lock_irq(shost->host_lock); |
| 5253 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5254 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5255 | continue; |
James Smart | a6571c6 | 2012-10-31 14:44:42 -0400 | [diff] [blame] | 5256 | if (vport->phba->cfg_fcp2_no_tgt_reset && |
| 5257 | (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE)) |
| 5258 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5259 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE && |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 5260 | ndlp->nlp_sid == i && |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5261 | ndlp->rport && |
| 5262 | ndlp->nlp_type & NLP_FCP_TARGET) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5263 | match = 1; |
| 5264 | break; |
| 5265 | } |
| 5266 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5267 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5268 | if (!match) |
| 5269 | continue; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5270 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 5271 | status = lpfc_send_taskmgmt(vport, cmnd, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5272 | i, 0, FCP_TARGET_RESET); |
| 5273 | |
| 5274 | if (status != SUCCESS) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5275 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5276 | "0700 Bus Reset on target %d failed\n", |
| 5277 | i); |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 5278 | ret = FAILED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5279 | } |
| 5280 | } |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -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 TMFs |
| 5283 | * above; or if any of the TMFs failed, they may be in an |
| 5284 | * indeterminate state. |
| 5285 | * 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] | 5286 | */ |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5287 | |
| 5288 | status = lpfc_reset_flush_io_context(vport, 0, 0, LPFC_CTX_HOST); |
| 5289 | if (status != SUCCESS) |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 5290 | ret = FAILED; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5291 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5292 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5293 | "0714 SCSI layer issued Bus Reset Data: x%x\n", ret); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5294 | return ret; |
| 5295 | } |
| 5296 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5297 | /** |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5298 | * lpfc_host_reset_handler - scsi_host_template eh_host_reset_handler entry pt |
| 5299 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5300 | * |
| 5301 | * This routine does host reset to the adaptor port. It brings the HBA |
| 5302 | * offline, performs a board restart, and then brings the board back online. |
| 5303 | * The lpfc_offline calls lpfc_sli_hba_down which will abort and local |
| 5304 | * reject all outstanding SCSI commands to the host and error returned |
| 5305 | * back to SCSI mid-level. As this will be SCSI mid-level's last resort |
| 5306 | * of error handling, it will only return error if resetting of the adapter |
| 5307 | * is not successful; in all other cases, will return success. |
| 5308 | * |
| 5309 | * Return code : |
| 5310 | * 0x2003 - Error |
| 5311 | * 0x2002 - Success |
| 5312 | **/ |
| 5313 | static int |
| 5314 | lpfc_host_reset_handler(struct scsi_cmnd *cmnd) |
| 5315 | { |
| 5316 | struct Scsi_Host *shost = cmnd->device->host; |
| 5317 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 5318 | struct lpfc_hba *phba = vport->phba; |
| 5319 | int rc, ret = SUCCESS; |
| 5320 | |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 5321 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5322 | "3172 SCSI layer issued Host Reset Data:\n"); |
| 5323 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 5324 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5325 | lpfc_offline(phba); |
| 5326 | rc = lpfc_sli_brdrestart(phba); |
| 5327 | if (rc) |
| 5328 | ret = FAILED; |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 5329 | rc = lpfc_online(phba); |
| 5330 | if (rc) |
| 5331 | ret = FAILED; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5332 | lpfc_unblock_mgmt_io(phba); |
| 5333 | |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 5334 | if (ret == FAILED) { |
| 5335 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5336 | "3323 Failed host reset, bring it offline\n"); |
| 5337 | lpfc_sli4_offline_eratt(phba); |
| 5338 | } |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5339 | return ret; |
| 5340 | } |
| 5341 | |
| 5342 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5343 | * lpfc_slave_alloc - scsi_host_template slave_alloc entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5344 | * @sdev: Pointer to scsi_device. |
| 5345 | * |
| 5346 | * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's |
| 5347 | * globally available list of scsi buffers. This routine also makes sure scsi |
| 5348 | * buffer is not allocated more than HBA limit conveyed to midlayer. This list |
| 5349 | * of scsi buffer exists for the lifetime of the driver. |
| 5350 | * |
| 5351 | * Return codes: |
| 5352 | * non-0 - Error |
| 5353 | * 0 - Success |
| 5354 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5355 | static int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5356 | lpfc_slave_alloc(struct scsi_device *sdev) |
| 5357 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5358 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 5359 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 5360 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5361 | uint32_t total = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5362 | uint32_t num_to_alloc = 0; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5363 | int num_allocated = 0; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5364 | uint32_t sdev_cnt; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5365 | struct lpfc_device_data *device_data; |
| 5366 | unsigned long flags; |
| 5367 | struct lpfc_name target_wwpn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5368 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 5369 | if (!rport || fc_remote_port_chkready(rport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5370 | return -ENXIO; |
| 5371 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5372 | if (phba->cfg_fof) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5373 | |
| 5374 | /* |
| 5375 | * Check to see if the device data structure for the lun |
| 5376 | * exists. If not, create one. |
| 5377 | */ |
| 5378 | |
| 5379 | u64_to_wwn(rport->port_name, target_wwpn.u.wwn); |
| 5380 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5381 | device_data = __lpfc_get_device_data(phba, |
| 5382 | &phba->luns, |
| 5383 | &vport->fc_portname, |
| 5384 | &target_wwpn, |
| 5385 | sdev->lun); |
| 5386 | if (!device_data) { |
| 5387 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5388 | device_data = lpfc_create_device_data(phba, |
| 5389 | &vport->fc_portname, |
| 5390 | &target_wwpn, |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5391 | sdev->lun, |
| 5392 | phba->cfg_XLanePriority, |
| 5393 | true); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5394 | if (!device_data) |
| 5395 | return -ENOMEM; |
| 5396 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5397 | list_add_tail(&device_data->listentry, &phba->luns); |
| 5398 | } |
| 5399 | device_data->rport_data = rport->dd_data; |
| 5400 | device_data->available = true; |
| 5401 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5402 | sdev->hostdata = device_data; |
| 5403 | } else { |
| 5404 | sdev->hostdata = rport->dd_data; |
| 5405 | } |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5406 | sdev_cnt = atomic_inc_return(&phba->sdev_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5407 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 5408 | /* For SLI4, all IO buffers are pre-allocated */ |
| 5409 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 5410 | return 0; |
| 5411 | |
| 5412 | /* This code path is now ONLY for SLI3 adapters */ |
| 5413 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5414 | /* |
| 5415 | * Populate the cmds_per_lun count scsi_bufs into this host's globally |
| 5416 | * 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] | 5417 | * HBA limit conveyed to the midlayer via the host structure. The |
| 5418 | * formula accounts for the lun_queue_depth + error handlers + 1 |
| 5419 | * extra. This list of scsi bufs exists for the lifetime of the driver. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5420 | */ |
| 5421 | total = phba->total_scsi_bufs; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5422 | num_to_alloc = vport->cfg_lun_queue_depth + 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5423 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5424 | /* If allocated buffers are enough do nothing */ |
| 5425 | if ((sdev_cnt * (vport->cfg_lun_queue_depth + 2)) < total) |
| 5426 | return 0; |
| 5427 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5428 | /* Allow some exchanges to be available always to complete discovery */ |
| 5429 | if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5430 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 5431 | "0704 At limitation of %d preallocated " |
| 5432 | "command buffers\n", total); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5433 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5434 | /* Allow some exchanges to be available always to complete discovery */ |
| 5435 | } else if (total + num_to_alloc > |
| 5436 | phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5437 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 5438 | "0705 Allocation request of %d " |
| 5439 | "command buffers will exceed max of %d. " |
| 5440 | "Reducing allocation request to %d.\n", |
| 5441 | num_to_alloc, phba->cfg_hba_queue_depth, |
| 5442 | (phba->cfg_hba_queue_depth - total)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5443 | num_to_alloc = phba->cfg_hba_queue_depth - total; |
| 5444 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 5445 | num_allocated = lpfc_new_scsi_buf_s3(vport, num_to_alloc); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5446 | if (num_to_alloc != num_allocated) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5447 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5448 | "0708 Allocation request of %d " |
| 5449 | "command buffers did not succeed. " |
| 5450 | "Allocated %d buffers.\n", |
| 5451 | num_to_alloc, num_allocated); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5452 | } |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5453 | if (num_allocated > 0) |
| 5454 | phba->total_scsi_bufs += num_allocated; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5455 | return 0; |
| 5456 | } |
| 5457 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5458 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5459 | * lpfc_slave_configure - scsi_host_template slave_configure entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5460 | * @sdev: Pointer to scsi_device. |
| 5461 | * |
| 5462 | * This routine configures following items |
| 5463 | * - Tag command queuing support for @sdev if supported. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5464 | * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set. |
| 5465 | * |
| 5466 | * Return codes: |
| 5467 | * 0 - Success |
| 5468 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5469 | static int |
| 5470 | lpfc_slave_configure(struct scsi_device *sdev) |
| 5471 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5472 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 5473 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5474 | |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 5475 | scsi_change_queue_depth(sdev, vport->cfg_lun_queue_depth); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5476 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5477 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 5478 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5479 | &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5480 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 5481 | lpfc_poll_rearm_timer(phba); |
| 5482 | } |
| 5483 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5484 | return 0; |
| 5485 | } |
| 5486 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5487 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5488 | * lpfc_slave_destroy - slave_destroy entry point of SHT data structure |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5489 | * @sdev: Pointer to scsi_device. |
| 5490 | * |
| 5491 | * This routine sets @sdev hostatdata filed to null. |
| 5492 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5493 | static void |
| 5494 | lpfc_slave_destroy(struct scsi_device *sdev) |
| 5495 | { |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5496 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 5497 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5498 | unsigned long flags; |
| 5499 | struct lpfc_device_data *device_data = sdev->hostdata; |
| 5500 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5501 | atomic_dec(&phba->sdev_cnt); |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5502 | if ((phba->cfg_fof) && (device_data)) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5503 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5504 | device_data->available = false; |
| 5505 | if (!device_data->oas_enabled) |
| 5506 | lpfc_delete_device_data(phba, device_data); |
| 5507 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5508 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5509 | sdev->hostdata = NULL; |
| 5510 | return; |
| 5511 | } |
| 5512 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5513 | /** |
| 5514 | * lpfc_create_device_data - creates and initializes device data structure for OAS |
| 5515 | * @pha: Pointer to host bus adapter structure. |
| 5516 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5517 | * @target_wwpn: Pointer to target's wwpn information |
| 5518 | * @lun: Lun on target |
| 5519 | * @atomic_create: Flag to indicate if memory should be allocated using the |
| 5520 | * GFP_ATOMIC flag or not. |
| 5521 | * |
| 5522 | * This routine creates a device data structure which will contain identifying |
| 5523 | * information for the device (host wwpn, target wwpn, lun), state of OAS, |
| 5524 | * whether or not the corresponding lun is available by the system, |
| 5525 | * and pointer to the rport data. |
| 5526 | * |
| 5527 | * Return codes: |
| 5528 | * NULL - Error |
| 5529 | * Pointer to lpfc_device_data - Success |
| 5530 | **/ |
| 5531 | struct lpfc_device_data* |
| 5532 | lpfc_create_device_data(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn, |
| 5533 | struct lpfc_name *target_wwpn, uint64_t lun, |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5534 | uint32_t pri, bool atomic_create) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5535 | { |
| 5536 | |
| 5537 | struct lpfc_device_data *lun_info; |
| 5538 | int memory_flags; |
| 5539 | |
| 5540 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5541 | !(phba->cfg_fof)) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5542 | return NULL; |
| 5543 | |
| 5544 | /* Attempt to create the device data to contain lun info */ |
| 5545 | |
| 5546 | if (atomic_create) |
| 5547 | memory_flags = GFP_ATOMIC; |
| 5548 | else |
| 5549 | memory_flags = GFP_KERNEL; |
| 5550 | lun_info = mempool_alloc(phba->device_data_mem_pool, memory_flags); |
| 5551 | if (!lun_info) |
| 5552 | return NULL; |
| 5553 | INIT_LIST_HEAD(&lun_info->listentry); |
| 5554 | lun_info->rport_data = NULL; |
| 5555 | memcpy(&lun_info->device_id.vport_wwpn, vport_wwpn, |
| 5556 | sizeof(struct lpfc_name)); |
| 5557 | memcpy(&lun_info->device_id.target_wwpn, target_wwpn, |
| 5558 | sizeof(struct lpfc_name)); |
| 5559 | lun_info->device_id.lun = lun; |
| 5560 | lun_info->oas_enabled = false; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5561 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5562 | lun_info->available = false; |
| 5563 | return lun_info; |
| 5564 | } |
| 5565 | |
| 5566 | /** |
| 5567 | * lpfc_delete_device_data - frees a device data structure for OAS |
| 5568 | * @pha: Pointer to host bus adapter structure. |
| 5569 | * @lun_info: Pointer to device data structure to free. |
| 5570 | * |
| 5571 | * This routine frees the previously allocated device data structure passed. |
| 5572 | * |
| 5573 | **/ |
| 5574 | void |
| 5575 | lpfc_delete_device_data(struct lpfc_hba *phba, |
| 5576 | struct lpfc_device_data *lun_info) |
| 5577 | { |
| 5578 | |
| 5579 | if (unlikely(!phba) || !lun_info || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5580 | !(phba->cfg_fof)) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5581 | return; |
| 5582 | |
| 5583 | if (!list_empty(&lun_info->listentry)) |
| 5584 | list_del(&lun_info->listentry); |
| 5585 | mempool_free(lun_info, phba->device_data_mem_pool); |
| 5586 | return; |
| 5587 | } |
| 5588 | |
| 5589 | /** |
| 5590 | * __lpfc_get_device_data - returns the device data for the specified lun |
| 5591 | * @pha: Pointer to host bus adapter structure. |
| 5592 | * @list: Point to list to search. |
| 5593 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5594 | * @target_wwpn: Pointer to target's wwpn information |
| 5595 | * @lun: Lun on target |
| 5596 | * |
| 5597 | * This routine searches the list passed for the specified lun's device data. |
| 5598 | * This function does not hold locks, it is the responsibility of the caller |
| 5599 | * to ensure the proper lock is held before calling the function. |
| 5600 | * |
| 5601 | * Return codes: |
| 5602 | * NULL - Error |
| 5603 | * Pointer to lpfc_device_data - Success |
| 5604 | **/ |
| 5605 | struct lpfc_device_data* |
| 5606 | __lpfc_get_device_data(struct lpfc_hba *phba, struct list_head *list, |
| 5607 | struct lpfc_name *vport_wwpn, |
| 5608 | struct lpfc_name *target_wwpn, uint64_t lun) |
| 5609 | { |
| 5610 | |
| 5611 | struct lpfc_device_data *lun_info; |
| 5612 | |
| 5613 | if (unlikely(!phba) || !list || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5614 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5615 | return NULL; |
| 5616 | |
| 5617 | /* Check to see if the lun is already enabled for OAS. */ |
| 5618 | |
| 5619 | list_for_each_entry(lun_info, list, listentry) { |
| 5620 | if ((memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn, |
| 5621 | sizeof(struct lpfc_name)) == 0) && |
| 5622 | (memcmp(&lun_info->device_id.target_wwpn, target_wwpn, |
| 5623 | sizeof(struct lpfc_name)) == 0) && |
| 5624 | (lun_info->device_id.lun == lun)) |
| 5625 | return lun_info; |
| 5626 | } |
| 5627 | |
| 5628 | return NULL; |
| 5629 | } |
| 5630 | |
| 5631 | /** |
| 5632 | * lpfc_find_next_oas_lun - searches for the next oas lun |
| 5633 | * @pha: Pointer to host bus adapter structure. |
| 5634 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5635 | * @target_wwpn: Pointer to target's wwpn information |
| 5636 | * @starting_lun: Pointer to the lun to start searching for |
| 5637 | * @found_vport_wwpn: Pointer to the found lun's vport wwpn information |
| 5638 | * @found_target_wwpn: Pointer to the found lun's target wwpn information |
| 5639 | * @found_lun: Pointer to the found lun. |
| 5640 | * @found_lun_status: Pointer to status of the found lun. |
| 5641 | * |
| 5642 | * This routine searches the luns list for the specified lun |
| 5643 | * or the first lun for the vport/target. If the vport wwpn contains |
| 5644 | * a zero value then a specific vport is not specified. In this case |
| 5645 | * any vport which contains the lun will be considered a match. If the |
| 5646 | * target wwpn contains a zero value then a specific target is not specified. |
| 5647 | * In this case any target which contains the lun will be considered a |
| 5648 | * match. If the lun is found, the lun, vport wwpn, target wwpn and lun status |
| 5649 | * are returned. The function will also return the next lun if available. |
| 5650 | * If the next lun is not found, starting_lun parameter will be set to |
| 5651 | * NO_MORE_OAS_LUN. |
| 5652 | * |
| 5653 | * Return codes: |
| 5654 | * non-0 - Error |
| 5655 | * 0 - Success |
| 5656 | **/ |
| 5657 | bool |
| 5658 | lpfc_find_next_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn, |
| 5659 | struct lpfc_name *target_wwpn, uint64_t *starting_lun, |
| 5660 | struct lpfc_name *found_vport_wwpn, |
| 5661 | struct lpfc_name *found_target_wwpn, |
| 5662 | uint64_t *found_lun, |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5663 | uint32_t *found_lun_status, |
| 5664 | uint32_t *found_lun_pri) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5665 | { |
| 5666 | |
| 5667 | unsigned long flags; |
| 5668 | struct lpfc_device_data *lun_info; |
| 5669 | struct lpfc_device_id *device_id; |
| 5670 | uint64_t lun; |
| 5671 | bool found = false; |
| 5672 | |
| 5673 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
| 5674 | !starting_lun || !found_vport_wwpn || |
| 5675 | !found_target_wwpn || !found_lun || !found_lun_status || |
| 5676 | (*starting_lun == NO_MORE_OAS_LUN) || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5677 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5678 | return false; |
| 5679 | |
| 5680 | lun = *starting_lun; |
| 5681 | *found_lun = NO_MORE_OAS_LUN; |
| 5682 | *starting_lun = NO_MORE_OAS_LUN; |
| 5683 | |
| 5684 | /* Search for lun or the lun closet in value */ |
| 5685 | |
| 5686 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5687 | list_for_each_entry(lun_info, &phba->luns, listentry) { |
| 5688 | if (((wwn_to_u64(vport_wwpn->u.wwn) == 0) || |
| 5689 | (memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn, |
| 5690 | sizeof(struct lpfc_name)) == 0)) && |
| 5691 | ((wwn_to_u64(target_wwpn->u.wwn) == 0) || |
| 5692 | (memcmp(&lun_info->device_id.target_wwpn, target_wwpn, |
| 5693 | sizeof(struct lpfc_name)) == 0)) && |
| 5694 | (lun_info->oas_enabled)) { |
| 5695 | device_id = &lun_info->device_id; |
| 5696 | if ((!found) && |
| 5697 | ((lun == FIND_FIRST_OAS_LUN) || |
| 5698 | (device_id->lun == lun))) { |
| 5699 | *found_lun = device_id->lun; |
| 5700 | memcpy(found_vport_wwpn, |
| 5701 | &device_id->vport_wwpn, |
| 5702 | sizeof(struct lpfc_name)); |
| 5703 | memcpy(found_target_wwpn, |
| 5704 | &device_id->target_wwpn, |
| 5705 | sizeof(struct lpfc_name)); |
| 5706 | if (lun_info->available) |
| 5707 | *found_lun_status = |
| 5708 | OAS_LUN_STATUS_EXISTS; |
| 5709 | else |
| 5710 | *found_lun_status = 0; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5711 | *found_lun_pri = lun_info->priority; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5712 | if (phba->cfg_oas_flags & OAS_FIND_ANY_VPORT) |
| 5713 | memset(vport_wwpn, 0x0, |
| 5714 | sizeof(struct lpfc_name)); |
| 5715 | if (phba->cfg_oas_flags & OAS_FIND_ANY_TARGET) |
| 5716 | memset(target_wwpn, 0x0, |
| 5717 | sizeof(struct lpfc_name)); |
| 5718 | found = true; |
| 5719 | } else if (found) { |
| 5720 | *starting_lun = device_id->lun; |
| 5721 | memcpy(vport_wwpn, &device_id->vport_wwpn, |
| 5722 | sizeof(struct lpfc_name)); |
| 5723 | memcpy(target_wwpn, &device_id->target_wwpn, |
| 5724 | sizeof(struct lpfc_name)); |
| 5725 | break; |
| 5726 | } |
| 5727 | } |
| 5728 | } |
| 5729 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5730 | return found; |
| 5731 | } |
| 5732 | |
| 5733 | /** |
| 5734 | * lpfc_enable_oas_lun - enables a lun for OAS operations |
| 5735 | * @pha: Pointer to host bus adapter structure. |
| 5736 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5737 | * @target_wwpn: Pointer to target's wwpn information |
| 5738 | * @lun: Lun |
| 5739 | * |
| 5740 | * This routine enables a lun for oas operations. The routines does so by |
| 5741 | * doing the following : |
| 5742 | * |
| 5743 | * 1) Checks to see if the device data for the lun has been created. |
| 5744 | * 2) If found, sets the OAS enabled flag if not set and returns. |
| 5745 | * 3) Otherwise, creates a device data structure. |
| 5746 | * 4) If successfully created, indicates the device data is for an OAS lun, |
| 5747 | * indicates the lun is not available and add to the list of luns. |
| 5748 | * |
| 5749 | * Return codes: |
| 5750 | * false - Error |
| 5751 | * true - Success |
| 5752 | **/ |
| 5753 | bool |
| 5754 | lpfc_enable_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn, |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 5755 | struct lpfc_name *target_wwpn, uint64_t lun, uint8_t pri) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5756 | { |
| 5757 | |
| 5758 | struct lpfc_device_data *lun_info; |
| 5759 | unsigned long flags; |
| 5760 | |
| 5761 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5762 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5763 | return false; |
| 5764 | |
| 5765 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5766 | |
| 5767 | /* Check to see if the device data for the lun has been created */ |
| 5768 | lun_info = __lpfc_get_device_data(phba, &phba->luns, vport_wwpn, |
| 5769 | target_wwpn, lun); |
| 5770 | if (lun_info) { |
| 5771 | if (!lun_info->oas_enabled) |
| 5772 | lun_info->oas_enabled = true; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5773 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5774 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5775 | return true; |
| 5776 | } |
| 5777 | |
| 5778 | /* Create an lun info structure and add to list of luns */ |
| 5779 | lun_info = lpfc_create_device_data(phba, vport_wwpn, target_wwpn, lun, |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5780 | pri, false); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5781 | if (lun_info) { |
| 5782 | lun_info->oas_enabled = true; |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 5783 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5784 | lun_info->available = false; |
| 5785 | list_add_tail(&lun_info->listentry, &phba->luns); |
| 5786 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5787 | return true; |
| 5788 | } |
| 5789 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5790 | return false; |
| 5791 | } |
| 5792 | |
| 5793 | /** |
| 5794 | * lpfc_disable_oas_lun - disables a lun for OAS operations |
| 5795 | * @pha: Pointer to host bus adapter structure. |
| 5796 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5797 | * @target_wwpn: Pointer to target's wwpn information |
| 5798 | * @lun: Lun |
| 5799 | * |
| 5800 | * This routine disables a lun for oas operations. The routines does so by |
| 5801 | * doing the following : |
| 5802 | * |
| 5803 | * 1) Checks to see if the device data for the lun is created. |
| 5804 | * 2) If present, clears the flag indicating this lun is for OAS. |
| 5805 | * 3) If the lun is not available by the system, the device data is |
| 5806 | * freed. |
| 5807 | * |
| 5808 | * Return codes: |
| 5809 | * false - Error |
| 5810 | * true - Success |
| 5811 | **/ |
| 5812 | bool |
| 5813 | lpfc_disable_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn, |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5814 | struct lpfc_name *target_wwpn, uint64_t lun, uint8_t pri) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5815 | { |
| 5816 | |
| 5817 | struct lpfc_device_data *lun_info; |
| 5818 | unsigned long flags; |
| 5819 | |
| 5820 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5821 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5822 | return false; |
| 5823 | |
| 5824 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5825 | |
| 5826 | /* Check to see if the lun is available. */ |
| 5827 | lun_info = __lpfc_get_device_data(phba, |
| 5828 | &phba->luns, vport_wwpn, |
| 5829 | target_wwpn, lun); |
| 5830 | if (lun_info) { |
| 5831 | lun_info->oas_enabled = false; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5832 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5833 | if (!lun_info->available) |
| 5834 | lpfc_delete_device_data(phba, lun_info); |
| 5835 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5836 | return true; |
| 5837 | } |
| 5838 | |
| 5839 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5840 | return false; |
| 5841 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5842 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5843 | static int |
| 5844 | lpfc_no_command(struct Scsi_Host *shost, struct scsi_cmnd *cmnd) |
| 5845 | { |
| 5846 | return SCSI_MLQUEUE_HOST_BUSY; |
| 5847 | } |
| 5848 | |
| 5849 | static int |
| 5850 | lpfc_no_handler(struct scsi_cmnd *cmnd) |
| 5851 | { |
| 5852 | return FAILED; |
| 5853 | } |
| 5854 | |
| 5855 | static int |
| 5856 | lpfc_no_slave(struct scsi_device *sdev) |
| 5857 | { |
| 5858 | return -ENODEV; |
| 5859 | } |
| 5860 | |
| 5861 | struct scsi_host_template lpfc_template_nvme = { |
| 5862 | .module = THIS_MODULE, |
| 5863 | .name = LPFC_DRIVER_NAME, |
| 5864 | .proc_name = LPFC_DRIVER_NAME, |
| 5865 | .info = lpfc_info, |
| 5866 | .queuecommand = lpfc_no_command, |
| 5867 | .eh_abort_handler = lpfc_no_handler, |
| 5868 | .eh_device_reset_handler = lpfc_no_handler, |
| 5869 | .eh_target_reset_handler = lpfc_no_handler, |
| 5870 | .eh_bus_reset_handler = lpfc_no_handler, |
| 5871 | .eh_host_reset_handler = lpfc_no_handler, |
| 5872 | .slave_alloc = lpfc_no_slave, |
| 5873 | .slave_configure = lpfc_no_slave, |
| 5874 | .scan_finished = lpfc_scan_finished, |
| 5875 | .this_id = -1, |
| 5876 | .sg_tablesize = 1, |
| 5877 | .cmd_per_lun = 1, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5878 | .shost_attrs = lpfc_hba_attrs, |
| 5879 | .max_sectors = 0xFFFF, |
| 5880 | .vendor_id = LPFC_NL_VENDOR_ID, |
| 5881 | .track_queue_depth = 0, |
| 5882 | }; |
| 5883 | |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 5884 | struct scsi_host_template lpfc_template_no_hr = { |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 5885 | .module = THIS_MODULE, |
| 5886 | .name = LPFC_DRIVER_NAME, |
James Smart | 08dcd4c | 2016-07-06 12:35:59 -0700 | [diff] [blame] | 5887 | .proc_name = LPFC_DRIVER_NAME, |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 5888 | .info = lpfc_info, |
| 5889 | .queuecommand = lpfc_queuecommand, |
James Smart | 856984b | 2017-03-04 09:30:32 -0800 | [diff] [blame] | 5890 | .eh_timed_out = fc_eh_timed_out, |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 5891 | .eh_abort_handler = lpfc_abort_handler, |
| 5892 | .eh_device_reset_handler = lpfc_device_reset_handler, |
| 5893 | .eh_target_reset_handler = lpfc_target_reset_handler, |
| 5894 | .eh_bus_reset_handler = lpfc_bus_reset_handler, |
| 5895 | .slave_alloc = lpfc_slave_alloc, |
| 5896 | .slave_configure = lpfc_slave_configure, |
| 5897 | .slave_destroy = lpfc_slave_destroy, |
| 5898 | .scan_finished = lpfc_scan_finished, |
| 5899 | .this_id = -1, |
| 5900 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
| 5901 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 5902 | .shost_attrs = lpfc_hba_attrs, |
| 5903 | .max_sectors = 0xFFFF, |
| 5904 | .vendor_id = LPFC_NL_VENDOR_ID, |
| 5905 | .change_queue_depth = scsi_change_queue_depth, |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 5906 | .track_queue_depth = 1, |
| 5907 | }; |
| 5908 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5909 | struct scsi_host_template lpfc_template = { |
| 5910 | .module = THIS_MODULE, |
| 5911 | .name = LPFC_DRIVER_NAME, |
James Smart | 08dcd4c | 2016-07-06 12:35:59 -0700 | [diff] [blame] | 5912 | .proc_name = LPFC_DRIVER_NAME, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5913 | .info = lpfc_info, |
| 5914 | .queuecommand = lpfc_queuecommand, |
Christoph Hellwig | b6a05c8 | 2017-01-30 13:18:58 +0100 | [diff] [blame] | 5915 | .eh_timed_out = fc_eh_timed_out, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5916 | .eh_abort_handler = lpfc_abort_handler, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5917 | .eh_device_reset_handler = lpfc_device_reset_handler, |
| 5918 | .eh_target_reset_handler = lpfc_target_reset_handler, |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5919 | .eh_bus_reset_handler = lpfc_bus_reset_handler, |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5920 | .eh_host_reset_handler = lpfc_host_reset_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5921 | .slave_alloc = lpfc_slave_alloc, |
| 5922 | .slave_configure = lpfc_slave_configure, |
| 5923 | .slave_destroy = lpfc_slave_destroy, |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 5924 | .scan_finished = lpfc_scan_finished, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5925 | .this_id = -1, |
James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 5926 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5927 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5928 | .shost_attrs = lpfc_hba_attrs, |
James.Smart@Emulex.Com | 564b296 | 2005-06-25 10:34:17 -0400 | [diff] [blame] | 5929 | .max_sectors = 0xFFFF, |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5930 | .vendor_id = LPFC_NL_VENDOR_ID, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 5931 | .change_queue_depth = scsi_change_queue_depth, |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 5932 | .track_queue_depth = 1, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5933 | }; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5934 | |
| 5935 | struct scsi_host_template lpfc_vport_template = { |
| 5936 | .module = THIS_MODULE, |
| 5937 | .name = LPFC_DRIVER_NAME, |
James Smart | 08dcd4c | 2016-07-06 12:35:59 -0700 | [diff] [blame] | 5938 | .proc_name = LPFC_DRIVER_NAME, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5939 | .info = lpfc_info, |
| 5940 | .queuecommand = lpfc_queuecommand, |
Christoph Hellwig | b6a05c8 | 2017-01-30 13:18:58 +0100 | [diff] [blame] | 5941 | .eh_timed_out = fc_eh_timed_out, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5942 | .eh_abort_handler = lpfc_abort_handler, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5943 | .eh_device_reset_handler = lpfc_device_reset_handler, |
| 5944 | .eh_target_reset_handler = lpfc_target_reset_handler, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5945 | .slave_alloc = lpfc_slave_alloc, |
| 5946 | .slave_configure = lpfc_slave_configure, |
| 5947 | .slave_destroy = lpfc_slave_destroy, |
| 5948 | .scan_finished = lpfc_scan_finished, |
| 5949 | .this_id = -1, |
James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 5950 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5951 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5952 | .shost_attrs = lpfc_vport_attrs, |
| 5953 | .max_sectors = 0xFFFF, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 5954 | .change_queue_depth = scsi_change_queue_depth, |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 5955 | .track_queue_depth = 1, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5956 | }; |