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 | 0d04121 | 2019-01-28 11:14:41 -0800 | [diff] [blame] | 4 | * Copyright (C) 2017-2019 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 |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 86 | lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_io_buf *psb); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 87 | static void |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 88 | lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_io_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, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 183 | struct lpfc_io_buf *lpfc_cmd) |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 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 |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 203 | lpfc_update_stats(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 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; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 392 | struct lpfc_io_buf *psb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 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++) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 411 | psb = kzalloc(sizeof(struct lpfc_io_buf), GFP_KERNEL); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 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 | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 445 | bpl = (struct ulp_bde64 *)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 | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 509 | spin_lock_init(&psb->buf_lock); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 510 | lpfc_release_scsi_buf_s3(phba, psb); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 511 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 512 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 513 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 514 | return bcnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 515 | } |
| 516 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 517 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 518 | * lpfc_sli4_vport_delete_fcp_xri_aborted -Remove all ndlp references for vport |
| 519 | * @vport: pointer to lpfc vport data structure. |
| 520 | * |
| 521 | * This routine is invoked by the vport cleanup for deletions and the cleanup |
| 522 | * for an ndlp on removal. |
| 523 | **/ |
| 524 | void |
| 525 | lpfc_sli4_vport_delete_fcp_xri_aborted(struct lpfc_vport *vport) |
| 526 | { |
| 527 | struct lpfc_hba *phba = vport->phba; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 528 | struct lpfc_io_buf *psb, *next_psb; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 529 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 530 | unsigned long iflag = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 531 | int idx; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 532 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 533 | if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 534 | return; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 535 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 536 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 537 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 538 | qp = &phba->sli4_hba.hdwq[idx]; |
| 539 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame^] | 540 | spin_lock(&qp->abts_io_buf_list_lock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 541 | list_for_each_entry_safe(psb, next_psb, |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame^] | 542 | &qp->lpfc_abts_io_buf_list, list) { |
| 543 | if (psb->cur_iocbq.iocb_flag == LPFC_IO_NVME) |
| 544 | continue; |
| 545 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 546 | if (psb->rdata && psb->rdata->pnode && |
| 547 | psb->rdata->pnode->vport == vport) |
| 548 | psb->rdata = NULL; |
| 549 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame^] | 550 | spin_unlock(&qp->abts_io_buf_list_lock); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 551 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 552 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 553 | } |
| 554 | |
| 555 | /** |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame^] | 556 | * lpfc_sli4_io_xri_aborted - Fast-path process of fcp xri abort |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 557 | * @phba: pointer to lpfc hba data structure. |
| 558 | * @axri: pointer to the fcp xri abort wcqe structure. |
| 559 | * |
| 560 | * This routine is invoked by the worker thread to process a SLI4 fast-path |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame^] | 561 | * FCP or NVME aborted xri. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 562 | **/ |
| 563 | void |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame^] | 564 | lpfc_sli4_io_xri_aborted(struct lpfc_hba *phba, |
| 565 | struct sli4_wcqe_xri_aborted *axri, int idx) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 566 | { |
| 567 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 568 | uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 569 | struct lpfc_io_buf *psb, *next_psb; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 570 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 571 | unsigned long iflag = 0; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 572 | struct lpfc_iocbq *iocbq; |
| 573 | int i; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 574 | struct lpfc_nodelist *ndlp; |
| 575 | int rrq_empty = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 576 | struct lpfc_sli_ring *pring = phba->sli4_hba.els_wq->pring; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 577 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 578 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 579 | return; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 580 | |
| 581 | qp = &phba->sli4_hba.hdwq[idx]; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 582 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame^] | 583 | spin_lock(&qp->abts_io_buf_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 584 | list_for_each_entry_safe(psb, next_psb, |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame^] | 585 | &qp->lpfc_abts_io_buf_list, list) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 586 | if (psb->cur_iocbq.sli4_xritag == xri) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame^] | 587 | list_del_init(&psb->list); |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 588 | psb->exch_busy = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 589 | psb->status = IOSTAT_SUCCESS; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame^] | 590 | #ifdef BUILD_NVME |
| 591 | if (psb->cur_iocbq.iocb_flag == LPFC_IO_NVME) { |
| 592 | qp->abts_nvme_io_bufs--; |
| 593 | spin_unlock(&qp->abts_io_buf_list_lock); |
| 594 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 595 | lpfc_sli4_nvme_xri_aborted(phba, axri, psb); |
| 596 | return; |
| 597 | } |
| 598 | #endif |
| 599 | qp->abts_scsi_io_bufs--; |
| 600 | spin_unlock(&qp->abts_io_buf_list_lock); |
| 601 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 602 | if (psb->rdata && psb->rdata->pnode) |
| 603 | ndlp = psb->rdata->pnode; |
| 604 | else |
| 605 | ndlp = NULL; |
| 606 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 607 | rrq_empty = list_empty(&phba->active_rrq_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 608 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 609 | if (ndlp) { |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 610 | lpfc_set_rrq_active(phba, ndlp, |
| 611 | psb->cur_iocbq.sli4_lxritag, rxid, 1); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 612 | lpfc_sli4_abts_err_handler(phba, ndlp, axri); |
| 613 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 614 | lpfc_release_scsi_buf_s4(phba, psb); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 615 | if (rrq_empty) |
| 616 | lpfc_worker_wake_up(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 617 | return; |
| 618 | } |
| 619 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame^] | 620 | spin_unlock(&qp->abts_io_buf_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 621 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 622 | iocbq = phba->sli.iocbq_lookup[i]; |
| 623 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame^] | 624 | if (!(iocbq->iocb_flag & LPFC_IO_FCP) || |
| 625 | (iocbq->iocb_flag & LPFC_IO_LIBDFC)) |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 626 | continue; |
| 627 | if (iocbq->sli4_xritag != xri) |
| 628 | continue; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 629 | psb = container_of(iocbq, struct lpfc_io_buf, cur_iocbq); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 630 | psb->exch_busy = 0; |
| 631 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 632 | if (!list_empty(&pring->txq)) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 633 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 634 | return; |
| 635 | |
| 636 | } |
| 637 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 641 | * 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] | 642 | * @phba: The HBA for which this call is being executed. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 643 | * |
| 644 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list |
| 645 | * and returns to caller. |
| 646 | * |
| 647 | * Return codes: |
| 648 | * NULL - Error |
| 649 | * Pointer to lpfc_scsi_buf - Success |
| 650 | **/ |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 651 | static struct lpfc_io_buf * |
James Smart | ace44e4 | 2019-01-28 11:14:27 -0800 | [diff] [blame] | 652 | lpfc_get_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
| 653 | struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 654 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 655 | struct lpfc_io_buf *lpfc_cmd = NULL; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 656 | 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] | 657 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 658 | |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 659 | spin_lock_irqsave(&phba->scsi_buf_list_get_lock, iflag); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 660 | list_remove_head(scsi_buf_list_get, lpfc_cmd, struct lpfc_io_buf, |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 661 | list); |
| 662 | if (!lpfc_cmd) { |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 663 | spin_lock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 664 | list_splice(&phba->lpfc_scsi_buf_list_put, |
| 665 | &phba->lpfc_scsi_buf_list_get); |
| 666 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
| 667 | list_remove_head(scsi_buf_list_get, lpfc_cmd, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 668 | struct lpfc_io_buf, list); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 669 | spin_unlock(&phba->scsi_buf_list_put_lock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 670 | } |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 671 | spin_unlock_irqrestore(&phba->scsi_buf_list_get_lock, iflag); |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 672 | |
| 673 | if (lpfc_ndlp_check_qdepth(phba, ndlp) && lpfc_cmd) { |
| 674 | atomic_inc(&ndlp->cmd_pending); |
| 675 | lpfc_cmd->flags |= LPFC_SBUF_BUMP_QDEPTH; |
| 676 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 677 | return lpfc_cmd; |
| 678 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 679 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 680 | * 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] | 681 | * @phba: The HBA for which this call is being executed. |
| 682 | * |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 683 | * 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] | 684 | * and returns to caller. |
| 685 | * |
| 686 | * Return codes: |
| 687 | * NULL - Error |
| 688 | * Pointer to lpfc_scsi_buf - Success |
| 689 | **/ |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 690 | static struct lpfc_io_buf * |
James Smart | ace44e4 | 2019-01-28 11:14:27 -0800 | [diff] [blame] | 691 | lpfc_get_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
| 692 | struct scsi_cmnd *cmnd) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 693 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 694 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 695 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 696 | struct sli4_sge *sgl; |
| 697 | IOCB_t *iocb; |
| 698 | dma_addr_t pdma_phys_fcp_rsp; |
| 699 | dma_addr_t pdma_phys_fcp_cmd; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 700 | uint32_t cpu, idx; |
James Smart | ace44e4 | 2019-01-28 11:14:27 -0800 | [diff] [blame] | 701 | int tag; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 702 | struct fcp_cmd_rsp_buf *tmp = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 703 | |
Bart Van Assche | d6d189c | 2019-03-28 11:06:22 -0700 | [diff] [blame] | 704 | cpu = raw_smp_processor_id(); |
James Smart | 45aa312 | 2019-01-28 11:14:29 -0800 | [diff] [blame] | 705 | if (cmnd && phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_HDWQ) { |
James Smart | ace44e4 | 2019-01-28 11:14:27 -0800 | [diff] [blame] | 706 | tag = blk_mq_unique_tag(cmnd->request); |
| 707 | idx = blk_mq_unique_tag_to_hwq(tag); |
| 708 | } else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 709 | idx = phba->sli4_hba.cpu_map[cpu].hdwq; |
James Smart | ace44e4 | 2019-01-28 11:14:27 -0800 | [diff] [blame] | 710 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 711 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 712 | lpfc_cmd = lpfc_get_io_buf(phba, ndlp, idx, |
| 713 | !phba->cfg_xri_rebalancing); |
| 714 | if (!lpfc_cmd) { |
| 715 | qp = &phba->sli4_hba.hdwq[idx]; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 716 | qp->empty_io_bufs++; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 717 | return NULL; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 718 | } |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 719 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 720 | /* Setup key fields in buffer that may have been changed |
| 721 | * if other protocols used this buffer. |
| 722 | */ |
| 723 | lpfc_cmd->cur_iocbq.iocb_flag = LPFC_IO_FCP; |
| 724 | lpfc_cmd->prot_seg_cnt = 0; |
| 725 | lpfc_cmd->seg_cnt = 0; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 726 | lpfc_cmd->timeout = 0; |
| 727 | lpfc_cmd->flags = 0; |
| 728 | lpfc_cmd->start_time = jiffies; |
| 729 | lpfc_cmd->waitq = NULL; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 730 | lpfc_cmd->cpu = cpu; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 731 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 732 | lpfc_cmd->prot_data_type = 0; |
| 733 | #endif |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 734 | tmp = lpfc_get_cmd_rsp_buf_per_hdwq(phba, lpfc_cmd); |
| 735 | if (!tmp) |
| 736 | return NULL; |
| 737 | |
| 738 | lpfc_cmd->fcp_cmnd = tmp->fcp_cmnd; |
| 739 | lpfc_cmd->fcp_rsp = tmp->fcp_rsp; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 740 | |
| 741 | /* |
| 742 | * The first two SGEs are the FCP_CMD and FCP_RSP. |
| 743 | * The balance are sg list bdes. Initialize the |
| 744 | * first two and leave the rest for queuecommand. |
| 745 | */ |
| 746 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 747 | pdma_phys_fcp_cmd = tmp->fcp_cmd_rsp_dma_handle; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 748 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd)); |
| 749 | sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd)); |
| 750 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 751 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 752 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 753 | sgl->sge_len = cpu_to_le32(sizeof(struct fcp_cmnd)); |
| 754 | sgl++; |
| 755 | |
| 756 | /* Setup the physical region for the FCP RSP */ |
| 757 | pdma_phys_fcp_rsp = pdma_phys_fcp_cmd + sizeof(struct fcp_cmnd); |
| 758 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp)); |
| 759 | sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp)); |
| 760 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 761 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 762 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 763 | sgl->sge_len = cpu_to_le32(sizeof(struct fcp_rsp)); |
| 764 | |
| 765 | /* |
| 766 | * Since the IOCB for the FCP I/O is built into this |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 767 | * lpfc_io_buf, initialize it with all known data now. |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 768 | */ |
| 769 | iocb = &lpfc_cmd->cur_iocbq.iocb; |
| 770 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; |
| 771 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_64; |
| 772 | /* setting the BLP size to 2 * sizeof BDE may not be correct. |
| 773 | * We are setting the bpl to point to out sgl. An sgl's |
| 774 | * entries are 16 bytes, a bpl entries are 12 bytes. |
| 775 | */ |
| 776 | iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); |
| 777 | iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys_fcp_cmd); |
| 778 | iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys_fcp_cmd); |
| 779 | iocb->ulpBdeCount = 1; |
| 780 | iocb->ulpLe = 1; |
| 781 | iocb->ulpClass = CLASS3; |
| 782 | |
Dan Carpenter | 26c724a | 2018-08-23 16:56:33 +0300 | [diff] [blame] | 783 | if (lpfc_ndlp_check_qdepth(phba, ndlp)) { |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 784 | atomic_inc(&ndlp->cmd_pending); |
| 785 | lpfc_cmd->flags |= LPFC_SBUF_BUMP_QDEPTH; |
| 786 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 787 | return lpfc_cmd; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 788 | } |
| 789 | /** |
| 790 | * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA |
| 791 | * @phba: The HBA for which this call is being executed. |
| 792 | * |
| 793 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list |
| 794 | * and returns to caller. |
| 795 | * |
| 796 | * Return codes: |
| 797 | * NULL - Error |
| 798 | * Pointer to lpfc_scsi_buf - Success |
| 799 | **/ |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 800 | static struct lpfc_io_buf* |
James Smart | ace44e4 | 2019-01-28 11:14:27 -0800 | [diff] [blame] | 801 | lpfc_get_scsi_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
| 802 | struct scsi_cmnd *cmnd) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 803 | { |
James Smart | ace44e4 | 2019-01-28 11:14:27 -0800 | [diff] [blame] | 804 | return phba->lpfc_get_scsi_buf(phba, ndlp, cmnd); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 805 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 806 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 807 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 808 | * 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] | 809 | * @phba: The Hba for which this call is being executed. |
| 810 | * @psb: The scsi buffer which is being released. |
| 811 | * |
| 812 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
| 813 | * lpfc_scsi_buf_list list. |
| 814 | **/ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 815 | static void |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 816 | lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_io_buf *psb) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 817 | { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 818 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 819 | |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 820 | psb->seg_cnt = 0; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 821 | psb->prot_seg_cnt = 0; |
| 822 | |
| 823 | spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 824 | psb->pCmd = NULL; |
James Smart | 6a485eb | 2013-04-17 20:19:00 -0400 | [diff] [blame] | 825 | psb->cur_iocbq.iocb_flag = LPFC_IO_FCP; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 826 | list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list_put); |
| 827 | spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 828 | } |
| 829 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 830 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 831 | * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list. |
| 832 | * @phba: The Hba for which this call is being executed. |
| 833 | * @psb: The scsi buffer which is being released. |
| 834 | * |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 835 | * This routine releases @psb scsi buffer by adding it to tail of @hdwq |
| 836 | * 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] | 837 | * and cannot be reused for at least RA_TOV amount of time if it was |
| 838 | * aborted. |
| 839 | **/ |
| 840 | static void |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 841 | lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_io_buf *psb) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 842 | { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 843 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 844 | unsigned long iflag = 0; |
| 845 | |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 846 | psb->seg_cnt = 0; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 847 | psb->prot_seg_cnt = 0; |
| 848 | |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 849 | qp = psb->hdwq; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 850 | if (psb->exch_busy) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame^] | 851 | spin_lock_irqsave(&qp->abts_io_buf_list_lock, iflag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 852 | psb->pCmd = NULL; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame^] | 853 | list_add_tail(&psb->list, &qp->lpfc_abts_io_buf_list); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 854 | qp->abts_scsi_io_bufs++; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame^] | 855 | spin_unlock_irqrestore(&qp->abts_io_buf_list_lock, iflag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 856 | } else { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 857 | lpfc_release_io_buf(phba, (struct lpfc_io_buf *)psb, qp); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 858 | } |
| 859 | } |
| 860 | |
| 861 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 862 | * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list. |
| 863 | * @phba: The Hba for which this call is being executed. |
| 864 | * @psb: The scsi buffer which is being released. |
| 865 | * |
| 866 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
| 867 | * lpfc_scsi_buf_list list. |
| 868 | **/ |
| 869 | static void |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 870 | lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_io_buf *psb) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 871 | { |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 872 | if ((psb->flags & LPFC_SBUF_BUMP_QDEPTH) && psb->ndlp) |
| 873 | atomic_dec(&psb->ndlp->cmd_pending); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 874 | |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 875 | psb->flags &= ~LPFC_SBUF_BUMP_QDEPTH; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 876 | phba->lpfc_release_scsi_buf(phba, psb); |
| 877 | } |
| 878 | |
| 879 | /** |
| 880 | * 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] | 881 | * @phba: The Hba for which this call is being executed. |
| 882 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 883 | * |
| 884 | * 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] | 885 | * 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] | 886 | * through sg elements and format the bde. This routine also initializes all |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 887 | * IOCB fields which are dependent on scsi command request buffer. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 888 | * |
| 889 | * Return codes: |
| 890 | * 1 - Error |
| 891 | * 0 - Success |
| 892 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 893 | static int |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 894 | lpfc_scsi_prep_dma_buf_s3(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 895 | { |
| 896 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 897 | struct scatterlist *sgel = NULL; |
| 898 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 899 | struct ulp_bde64 *bpl = (struct ulp_bde64 *)lpfc_cmd->dma_sgl; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 900 | struct lpfc_iocbq *iocbq = &lpfc_cmd->cur_iocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 901 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 902 | struct ulp_bde64 *data_bde = iocb_cmd->unsli3.fcp_ext.dbde; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 903 | dma_addr_t physaddr; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 904 | uint32_t num_bde = 0; |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 905 | int nseg, datadir = scsi_cmnd->sc_data_direction; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 906 | |
| 907 | /* |
| 908 | * There are three possibilities here - use scatter-gather segment, use |
| 909 | * the single mapping, or neither. Start the lpfc command prep by |
| 910 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 911 | * data bde entry. |
| 912 | */ |
| 913 | bpl += 2; |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 914 | if (scsi_sg_count(scsi_cmnd)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 915 | /* |
| 916 | * The driver stores the segment count returned from pci_map_sg |
| 917 | * because this a count of dma-mappings used to map the use_sg |
| 918 | * pages. They are not guaranteed to be the same for those |
| 919 | * architectures that implement an IOMMU. |
| 920 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 921 | |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 922 | nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd), |
| 923 | scsi_sg_count(scsi_cmnd), datadir); |
| 924 | if (unlikely(!nseg)) |
| 925 | return 1; |
| 926 | |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 927 | lpfc_cmd->seg_cnt = nseg; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 928 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 929 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 930 | "9064 BLKGRD: %s: Too many sg segments from " |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 931 | "dma_map_sg. Config %d, seg_cnt %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 932 | __func__, phba->cfg_sg_seg_cnt, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 933 | lpfc_cmd->seg_cnt); |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 934 | WARN_ON_ONCE(lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 935 | lpfc_cmd->seg_cnt = 0; |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 936 | scsi_dma_unmap(scsi_cmnd); |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 937 | return 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | /* |
| 941 | * The driver established a maximum scatter-gather segment count |
| 942 | * during probe that limits the number of sg elements in any |
| 943 | * single scsi command. Just run through the seg_cnt and format |
| 944 | * the bde's. |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 945 | * When using SLI-3 the driver will try to fit all the BDEs into |
| 946 | * the IOCB. If it can't then the BDEs get added to a BPL as it |
| 947 | * does for SLI-2 mode. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 948 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 949 | scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 950 | physaddr = sg_dma_address(sgel); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 951 | if (phba->sli_rev == 3 && |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 952 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 953 | !(iocbq->iocb_flag & DSS_SECURITY_OP) && |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 954 | nseg <= LPFC_EXT_DATA_BDE_COUNT) { |
| 955 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 956 | data_bde->tus.f.bdeSize = sg_dma_len(sgel); |
| 957 | data_bde->addrLow = putPaddrLow(physaddr); |
| 958 | data_bde->addrHigh = putPaddrHigh(physaddr); |
| 959 | data_bde++; |
| 960 | } else { |
| 961 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 962 | bpl->tus.f.bdeSize = sg_dma_len(sgel); |
| 963 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 964 | bpl->addrLow = |
| 965 | le32_to_cpu(putPaddrLow(physaddr)); |
| 966 | bpl->addrHigh = |
| 967 | le32_to_cpu(putPaddrHigh(physaddr)); |
| 968 | bpl++; |
| 969 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 970 | } |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 971 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 972 | |
| 973 | /* |
| 974 | * Finish initializing those IOCB fields that are dependent on the |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 975 | * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is |
| 976 | * explicitly reinitialized and for SLI-3 the extended bde count is |
| 977 | * explicitly reinitialized since all iocb memory resources are reused. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 978 | */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 979 | if (phba->sli_rev == 3 && |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 980 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
| 981 | !(iocbq->iocb_flag & DSS_SECURITY_OP)) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 982 | if (num_bde > LPFC_EXT_DATA_BDE_COUNT) { |
| 983 | /* |
| 984 | * The extended IOCB format can only fit 3 BDE or a BPL. |
| 985 | * This I/O has more than 3 BDE so the 1st data bde will |
| 986 | * be a BPL that is filled in here. |
| 987 | */ |
| 988 | physaddr = lpfc_cmd->dma_handle; |
| 989 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BLP_64; |
| 990 | data_bde->tus.f.bdeSize = (num_bde * |
| 991 | sizeof(struct ulp_bde64)); |
| 992 | physaddr += (sizeof(struct fcp_cmnd) + |
| 993 | sizeof(struct fcp_rsp) + |
| 994 | (2 * sizeof(struct ulp_bde64))); |
| 995 | data_bde->addrHigh = putPaddrHigh(physaddr); |
| 996 | data_bde->addrLow = putPaddrLow(physaddr); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 997 | /* ebde count includes the response bde and data bpl */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 998 | iocb_cmd->unsli3.fcp_ext.ebde_count = 2; |
| 999 | } else { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1000 | /* ebde count includes the response bde and data bdes */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1001 | iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); |
| 1002 | } |
| 1003 | } else { |
| 1004 | iocb_cmd->un.fcpi64.bdl.bdeSize = |
| 1005 | ((num_bde + 2) * sizeof(struct ulp_bde64)); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1006 | iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1007 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1008 | fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1009 | |
| 1010 | /* |
| 1011 | * Due to difference in data length between DIF/non-DIF paths, |
| 1012 | * we need to set word 4 of IOCB here |
| 1013 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1014 | iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1015 | return 0; |
| 1016 | } |
| 1017 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1018 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1019 | |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1020 | /* Return BG_ERR_INIT if error injection is detected by Initiator */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1021 | #define BG_ERR_INIT 0x1 |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1022 | /* Return BG_ERR_TGT if error injection is detected by Target */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1023 | #define BG_ERR_TGT 0x2 |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1024 | /* 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] | 1025 | #define BG_ERR_SWAP 0x10 |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1026 | /** |
| 1027 | * Return BG_ERR_CHECK if disabling Guard/Ref/App checking is required for |
| 1028 | * error injection |
| 1029 | **/ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1030 | #define BG_ERR_CHECK 0x20 |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1031 | |
| 1032 | /** |
| 1033 | * lpfc_bg_err_inject - Determine if we should inject an error |
| 1034 | * @phba: The Hba for which this call is being executed. |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1035 | * @sc: The SCSI command to examine |
| 1036 | * @reftag: (out) BlockGuard reference tag for transmitted data |
| 1037 | * @apptag: (out) BlockGuard application tag for transmitted data |
| 1038 | * @new_guard (in) Value to replace CRC with if needed |
| 1039 | * |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1040 | * Returns BG_ERR_* bit mask or 0 if request ignored |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1041 | **/ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1042 | static int |
| 1043 | lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1044 | uint32_t *reftag, uint16_t *apptag, uint32_t new_guard) |
| 1045 | { |
| 1046 | struct scatterlist *sgpe; /* s/g prot entry */ |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1047 | struct lpfc_io_buf *lpfc_cmd = NULL; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1048 | struct scsi_dif_tuple *src = NULL; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1049 | struct lpfc_nodelist *ndlp; |
| 1050 | struct lpfc_rport_data *rdata; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1051 | uint32_t op = scsi_get_prot_op(sc); |
| 1052 | uint32_t blksize; |
| 1053 | uint32_t numblks; |
| 1054 | sector_t lba; |
| 1055 | int rc = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1056 | int blockoff = 0; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1057 | |
| 1058 | if (op == SCSI_PROT_NORMAL) |
| 1059 | return 0; |
| 1060 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1061 | sgpe = scsi_prot_sglist(sc); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1062 | lba = scsi_get_lba(sc); |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1063 | |
| 1064 | /* First check if we need to match the LBA */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1065 | if (phba->lpfc_injerr_lba != LPFC_INJERR_LBA_OFF) { |
| 1066 | blksize = lpfc_cmd_blksize(sc); |
| 1067 | numblks = (scsi_bufflen(sc) + blksize - 1) / blksize; |
| 1068 | |
| 1069 | /* Make sure we have the right LBA if one is specified */ |
| 1070 | if ((phba->lpfc_injerr_lba < lba) || |
| 1071 | (phba->lpfc_injerr_lba >= (lba + numblks))) |
| 1072 | return 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1073 | if (sgpe) { |
| 1074 | blockoff = phba->lpfc_injerr_lba - lba; |
| 1075 | numblks = sg_dma_len(sgpe) / |
| 1076 | sizeof(struct scsi_dif_tuple); |
| 1077 | if (numblks < blockoff) |
| 1078 | blockoff = numblks; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1079 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1080 | } |
| 1081 | |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1082 | /* Next check if we need to match the remote NPortID or WWPN */ |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 1083 | rdata = lpfc_rport_data_from_scsi_device(sc->device); |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1084 | if (rdata && rdata->pnode) { |
| 1085 | ndlp = rdata->pnode; |
| 1086 | |
| 1087 | /* Make sure we have the right NPortID if one is specified */ |
| 1088 | if (phba->lpfc_injerr_nportid && |
| 1089 | (phba->lpfc_injerr_nportid != ndlp->nlp_DID)) |
| 1090 | return 0; |
| 1091 | |
| 1092 | /* |
| 1093 | * Make sure we have the right WWPN if one is specified. |
| 1094 | * wwn[0] should be a non-zero NAA in a good WWPN. |
| 1095 | */ |
| 1096 | if (phba->lpfc_injerr_wwpn.u.wwn[0] && |
| 1097 | (memcmp(&ndlp->nlp_portname, &phba->lpfc_injerr_wwpn, |
| 1098 | sizeof(struct lpfc_name)) != 0)) |
| 1099 | return 0; |
| 1100 | } |
| 1101 | |
| 1102 | /* Setup a ptr to the protection data if the SCSI host provides it */ |
| 1103 | if (sgpe) { |
| 1104 | src = (struct scsi_dif_tuple *)sg_virt(sgpe); |
| 1105 | src += blockoff; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1106 | lpfc_cmd = (struct lpfc_io_buf *)sc->host_scribble; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1107 | } |
| 1108 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1109 | /* Should we change the Reference Tag */ |
| 1110 | if (reftag) { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1111 | if (phba->lpfc_injerr_wref_cnt) { |
| 1112 | switch (op) { |
| 1113 | case SCSI_PROT_WRITE_PASS: |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1114 | if (src) { |
| 1115 | /* |
| 1116 | * For WRITE_PASS, force the error |
| 1117 | * to be sent on the wire. It should |
| 1118 | * be detected by the Target. |
| 1119 | * If blockoff != 0 error will be |
| 1120 | * inserted in middle of the IO. |
| 1121 | */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1122 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1123 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1124 | "9076 BLKGRD: Injecting reftag error: " |
| 1125 | "write lba x%lx + x%x oldrefTag x%x\n", |
| 1126 | (unsigned long)lba, blockoff, |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1127 | be32_to_cpu(src->ref_tag)); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1128 | |
| 1129 | /* |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1130 | * Save the old ref_tag so we can |
| 1131 | * restore it on completion. |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1132 | */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1133 | if (lpfc_cmd) { |
| 1134 | lpfc_cmd->prot_data_type = |
| 1135 | LPFC_INJERR_REFTAG; |
| 1136 | lpfc_cmd->prot_data_segment = |
| 1137 | src; |
| 1138 | lpfc_cmd->prot_data = |
| 1139 | src->ref_tag; |
| 1140 | } |
| 1141 | src->ref_tag = cpu_to_be32(0xDEADBEEF); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1142 | phba->lpfc_injerr_wref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1143 | if (phba->lpfc_injerr_wref_cnt == 0) { |
| 1144 | phba->lpfc_injerr_nportid = 0; |
| 1145 | phba->lpfc_injerr_lba = |
| 1146 | LPFC_INJERR_LBA_OFF; |
| 1147 | memset(&phba->lpfc_injerr_wwpn, |
| 1148 | 0, sizeof(struct lpfc_name)); |
| 1149 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1150 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
| 1151 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1152 | break; |
| 1153 | } |
Bart Van Assche | cd05c15 | 2019-03-28 11:06:18 -0700 | [diff] [blame] | 1154 | /* fall through */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1155 | case SCSI_PROT_WRITE_INSERT: |
| 1156 | /* |
| 1157 | * For WRITE_INSERT, force the error |
| 1158 | * to be sent on the wire. It should be |
| 1159 | * detected by the Target. |
| 1160 | */ |
| 1161 | /* DEADBEEF will be the reftag on the wire */ |
| 1162 | *reftag = 0xDEADBEEF; |
| 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 | |
| 1173 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1174 | "9078 BLKGRD: Injecting reftag error: " |
| 1175 | "write lba x%lx\n", (unsigned long)lba); |
| 1176 | break; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1177 | case SCSI_PROT_WRITE_STRIP: |
| 1178 | /* |
| 1179 | * For WRITE_STRIP and WRITE_PASS, |
| 1180 | * force the error on data |
| 1181 | * being copied from SLI-Host to SLI-Port. |
| 1182 | */ |
| 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 | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1192 | rc = BG_ERR_INIT; |
| 1193 | |
| 1194 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1195 | "9077 BLKGRD: Injecting reftag error: " |
| 1196 | "write lba x%lx\n", (unsigned long)lba); |
| 1197 | break; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1198 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1199 | } |
| 1200 | if (phba->lpfc_injerr_rref_cnt) { |
| 1201 | switch (op) { |
| 1202 | case SCSI_PROT_READ_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1203 | case SCSI_PROT_READ_STRIP: |
| 1204 | case SCSI_PROT_READ_PASS: |
| 1205 | /* |
| 1206 | * For READ_STRIP and READ_PASS, force the |
| 1207 | * error on data being read off the wire. It |
| 1208 | * should force an IO error to the driver. |
| 1209 | */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1210 | *reftag = 0xDEADBEEF; |
| 1211 | phba->lpfc_injerr_rref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1212 | if (phba->lpfc_injerr_rref_cnt == 0) { |
| 1213 | phba->lpfc_injerr_nportid = 0; |
| 1214 | phba->lpfc_injerr_lba = |
| 1215 | LPFC_INJERR_LBA_OFF; |
| 1216 | memset(&phba->lpfc_injerr_wwpn, |
| 1217 | 0, sizeof(struct lpfc_name)); |
| 1218 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1219 | rc = BG_ERR_INIT; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1220 | |
| 1221 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1222 | "9079 BLKGRD: Injecting reftag error: " |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1223 | "read lba x%lx\n", (unsigned long)lba); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1224 | break; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1225 | } |
| 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | /* Should we change the Application Tag */ |
| 1230 | if (apptag) { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1231 | if (phba->lpfc_injerr_wapp_cnt) { |
| 1232 | switch (op) { |
| 1233 | case SCSI_PROT_WRITE_PASS: |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1234 | if (src) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1235 | /* |
| 1236 | * For WRITE_PASS, force the error |
| 1237 | * to be sent on the wire. It should |
| 1238 | * be detected by the Target. |
| 1239 | * If blockoff != 0 error will be |
| 1240 | * inserted in middle of the IO. |
| 1241 | */ |
| 1242 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1243 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1244 | "9080 BLKGRD: Injecting apptag error: " |
| 1245 | "write lba x%lx + x%x oldappTag x%x\n", |
| 1246 | (unsigned long)lba, blockoff, |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1247 | be16_to_cpu(src->app_tag)); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1248 | |
| 1249 | /* |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1250 | * Save the old app_tag so we can |
| 1251 | * restore it on completion. |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1252 | */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1253 | if (lpfc_cmd) { |
| 1254 | lpfc_cmd->prot_data_type = |
| 1255 | LPFC_INJERR_APPTAG; |
| 1256 | lpfc_cmd->prot_data_segment = |
| 1257 | src; |
| 1258 | lpfc_cmd->prot_data = |
| 1259 | src->app_tag; |
| 1260 | } |
| 1261 | src->app_tag = cpu_to_be16(0xDEAD); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1262 | phba->lpfc_injerr_wapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1263 | if (phba->lpfc_injerr_wapp_cnt == 0) { |
| 1264 | phba->lpfc_injerr_nportid = 0; |
| 1265 | phba->lpfc_injerr_lba = |
| 1266 | LPFC_INJERR_LBA_OFF; |
| 1267 | memset(&phba->lpfc_injerr_wwpn, |
| 1268 | 0, sizeof(struct lpfc_name)); |
| 1269 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1270 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1271 | break; |
| 1272 | } |
Bart Van Assche | cd05c15 | 2019-03-28 11:06:18 -0700 | [diff] [blame] | 1273 | /* fall through */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1274 | case SCSI_PROT_WRITE_INSERT: |
| 1275 | /* |
| 1276 | * For WRITE_INSERT, force the |
| 1277 | * error to be sent on the wire. It should be |
| 1278 | * detected by the Target. |
| 1279 | */ |
| 1280 | /* DEAD will be the apptag on the wire */ |
| 1281 | *apptag = 0xDEAD; |
| 1282 | phba->lpfc_injerr_wapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1283 | if (phba->lpfc_injerr_wapp_cnt == 0) { |
| 1284 | phba->lpfc_injerr_nportid = 0; |
| 1285 | phba->lpfc_injerr_lba = |
| 1286 | LPFC_INJERR_LBA_OFF; |
| 1287 | memset(&phba->lpfc_injerr_wwpn, |
| 1288 | 0, sizeof(struct lpfc_name)); |
| 1289 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1290 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
| 1291 | |
| 1292 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1293 | "0813 BLKGRD: Injecting apptag error: " |
| 1294 | "write lba x%lx\n", (unsigned long)lba); |
| 1295 | break; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1296 | case SCSI_PROT_WRITE_STRIP: |
| 1297 | /* |
| 1298 | * For WRITE_STRIP and WRITE_PASS, |
| 1299 | * force the error on data |
| 1300 | * being copied from SLI-Host to SLI-Port. |
| 1301 | */ |
| 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 | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1311 | rc = BG_ERR_INIT; |
| 1312 | |
| 1313 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1314 | "0812 BLKGRD: Injecting apptag error: " |
| 1315 | "write lba x%lx\n", (unsigned long)lba); |
| 1316 | break; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1317 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1318 | } |
| 1319 | if (phba->lpfc_injerr_rapp_cnt) { |
| 1320 | switch (op) { |
| 1321 | case SCSI_PROT_READ_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1322 | case SCSI_PROT_READ_STRIP: |
| 1323 | case SCSI_PROT_READ_PASS: |
| 1324 | /* |
| 1325 | * For READ_STRIP and READ_PASS, force the |
| 1326 | * error on data being read off the wire. It |
| 1327 | * should force an IO error to the driver. |
| 1328 | */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1329 | *apptag = 0xDEAD; |
| 1330 | phba->lpfc_injerr_rapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1331 | if (phba->lpfc_injerr_rapp_cnt == 0) { |
| 1332 | phba->lpfc_injerr_nportid = 0; |
| 1333 | phba->lpfc_injerr_lba = |
| 1334 | LPFC_INJERR_LBA_OFF; |
| 1335 | memset(&phba->lpfc_injerr_wwpn, |
| 1336 | 0, sizeof(struct lpfc_name)); |
| 1337 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1338 | rc = BG_ERR_INIT; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1339 | |
| 1340 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1341 | "0814 BLKGRD: Injecting apptag error: " |
| 1342 | "read lba x%lx\n", (unsigned long)lba); |
| 1343 | break; |
| 1344 | } |
| 1345 | } |
| 1346 | } |
| 1347 | |
| 1348 | |
| 1349 | /* Should we change the Guard Tag */ |
| 1350 | if (new_guard) { |
| 1351 | if (phba->lpfc_injerr_wgrd_cnt) { |
| 1352 | switch (op) { |
| 1353 | case SCSI_PROT_WRITE_PASS: |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1354 | rc = BG_ERR_CHECK; |
Bart Van Assche | cd05c15 | 2019-03-28 11:06:18 -0700 | [diff] [blame] | 1355 | /* fall through */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1356 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1357 | case SCSI_PROT_WRITE_INSERT: |
| 1358 | /* |
| 1359 | * For WRITE_INSERT, force the |
| 1360 | * error to be sent on the wire. It should be |
| 1361 | * detected by the Target. |
| 1362 | */ |
| 1363 | phba->lpfc_injerr_wgrd_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1364 | if (phba->lpfc_injerr_wgrd_cnt == 0) { |
| 1365 | phba->lpfc_injerr_nportid = 0; |
| 1366 | phba->lpfc_injerr_lba = |
| 1367 | LPFC_INJERR_LBA_OFF; |
| 1368 | memset(&phba->lpfc_injerr_wwpn, |
| 1369 | 0, sizeof(struct lpfc_name)); |
| 1370 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1371 | |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1372 | rc |= BG_ERR_TGT | BG_ERR_SWAP; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1373 | /* Signals the caller to swap CRC->CSUM */ |
| 1374 | |
| 1375 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1376 | "0817 BLKGRD: Injecting guard error: " |
| 1377 | "write lba x%lx\n", (unsigned long)lba); |
| 1378 | break; |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1379 | case SCSI_PROT_WRITE_STRIP: |
| 1380 | /* |
| 1381 | * For WRITE_STRIP and WRITE_PASS, |
| 1382 | * force the error on data |
| 1383 | * being copied from SLI-Host to SLI-Port. |
| 1384 | */ |
| 1385 | phba->lpfc_injerr_wgrd_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1386 | if (phba->lpfc_injerr_wgrd_cnt == 0) { |
| 1387 | phba->lpfc_injerr_nportid = 0; |
| 1388 | phba->lpfc_injerr_lba = |
| 1389 | LPFC_INJERR_LBA_OFF; |
| 1390 | memset(&phba->lpfc_injerr_wwpn, |
| 1391 | 0, sizeof(struct lpfc_name)); |
| 1392 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1393 | |
| 1394 | rc = BG_ERR_INIT | BG_ERR_SWAP; |
| 1395 | /* Signals the caller to swap CRC->CSUM */ |
| 1396 | |
| 1397 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1398 | "0816 BLKGRD: Injecting guard error: " |
| 1399 | "write lba x%lx\n", (unsigned long)lba); |
| 1400 | break; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1401 | } |
| 1402 | } |
| 1403 | if (phba->lpfc_injerr_rgrd_cnt) { |
| 1404 | switch (op) { |
| 1405 | case SCSI_PROT_READ_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1406 | case SCSI_PROT_READ_STRIP: |
| 1407 | case SCSI_PROT_READ_PASS: |
| 1408 | /* |
| 1409 | * For READ_STRIP and READ_PASS, force the |
| 1410 | * error on data being read off the wire. It |
| 1411 | * should force an IO error to the driver. |
| 1412 | */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1413 | phba->lpfc_injerr_rgrd_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1414 | if (phba->lpfc_injerr_rgrd_cnt == 0) { |
| 1415 | phba->lpfc_injerr_nportid = 0; |
| 1416 | phba->lpfc_injerr_lba = |
| 1417 | LPFC_INJERR_LBA_OFF; |
| 1418 | memset(&phba->lpfc_injerr_wwpn, |
| 1419 | 0, sizeof(struct lpfc_name)); |
| 1420 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1421 | |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1422 | rc = BG_ERR_INIT | BG_ERR_SWAP; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1423 | /* Signals the caller to swap CRC->CSUM */ |
| 1424 | |
| 1425 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1426 | "0818 BLKGRD: Injecting guard error: " |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1427 | "read lba x%lx\n", (unsigned long)lba); |
| 1428 | } |
| 1429 | } |
| 1430 | } |
| 1431 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1432 | return rc; |
| 1433 | } |
| 1434 | #endif |
| 1435 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1436 | /** |
| 1437 | * lpfc_sc_to_bg_opcodes - Determine the BlockGuard opcodes to be used with |
| 1438 | * the specified SCSI command. |
| 1439 | * @phba: The Hba for which this call is being executed. |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1440 | * @sc: The SCSI command to examine |
| 1441 | * @txopt: (out) BlockGuard operation for transmitted data |
| 1442 | * @rxopt: (out) BlockGuard operation for received data |
| 1443 | * |
| 1444 | * Returns: zero on success; non-zero if tx and/or rx op cannot be determined |
| 1445 | * |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1446 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1447 | static int |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1448 | lpfc_sc_to_bg_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1449 | uint8_t *txop, uint8_t *rxop) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1450 | { |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1451 | uint8_t ret = 0; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1452 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1453 | if (lpfc_cmd_guard_csum(sc)) { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1454 | switch (scsi_get_prot_op(sc)) { |
| 1455 | case SCSI_PROT_READ_INSERT: |
| 1456 | case SCSI_PROT_WRITE_STRIP: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1457 | *rxop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1458 | *txop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1459 | break; |
| 1460 | |
| 1461 | case SCSI_PROT_READ_STRIP: |
| 1462 | case SCSI_PROT_WRITE_INSERT: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1463 | *rxop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1464 | *txop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1465 | break; |
| 1466 | |
Martin K. Petersen | c6af404 | 2009-09-18 17:32:59 -0400 | [diff] [blame] | 1467 | case SCSI_PROT_READ_PASS: |
| 1468 | case SCSI_PROT_WRITE_PASS: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1469 | *rxop = BG_OP_IN_CRC_OUT_CSUM; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1470 | *txop = BG_OP_IN_CSUM_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1471 | break; |
| 1472 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1473 | case SCSI_PROT_NORMAL: |
| 1474 | default: |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1475 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1476 | "9063 BLKGRD: Bad op/guard:%d/IP combination\n", |
| 1477 | scsi_get_prot_op(sc)); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1478 | ret = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1479 | break; |
| 1480 | |
| 1481 | } |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1482 | } else { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1483 | switch (scsi_get_prot_op(sc)) { |
| 1484 | case SCSI_PROT_READ_STRIP: |
| 1485 | case SCSI_PROT_WRITE_INSERT: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1486 | *rxop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1487 | *txop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1488 | break; |
| 1489 | |
| 1490 | case SCSI_PROT_READ_PASS: |
| 1491 | case SCSI_PROT_WRITE_PASS: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1492 | *rxop = BG_OP_IN_CRC_OUT_CRC; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1493 | *txop = BG_OP_IN_CRC_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1494 | break; |
| 1495 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1496 | case SCSI_PROT_READ_INSERT: |
| 1497 | case SCSI_PROT_WRITE_STRIP: |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1498 | *rxop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1499 | *txop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1500 | break; |
| 1501 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1502 | case SCSI_PROT_NORMAL: |
| 1503 | default: |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1504 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1505 | "9075 BLKGRD: Bad op/guard:%d/CRC combination\n", |
| 1506 | scsi_get_prot_op(sc)); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1507 | ret = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1508 | break; |
| 1509 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1510 | } |
| 1511 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1512 | return ret; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1513 | } |
| 1514 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1515 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 1516 | /** |
| 1517 | * lpfc_bg_err_opcodes - reDetermine the BlockGuard opcodes to be used with |
| 1518 | * the specified SCSI command in order to force a guard tag error. |
| 1519 | * @phba: The Hba for which this call is being executed. |
| 1520 | * @sc: The SCSI command to examine |
| 1521 | * @txopt: (out) BlockGuard operation for transmitted data |
| 1522 | * @rxopt: (out) BlockGuard operation for received data |
| 1523 | * |
| 1524 | * Returns: zero on success; non-zero if tx and/or rx op cannot be determined |
| 1525 | * |
| 1526 | **/ |
| 1527 | static int |
| 1528 | lpfc_bg_err_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1529 | uint8_t *txop, uint8_t *rxop) |
| 1530 | { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1531 | uint8_t ret = 0; |
| 1532 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1533 | if (lpfc_cmd_guard_csum(sc)) { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1534 | switch (scsi_get_prot_op(sc)) { |
| 1535 | case SCSI_PROT_READ_INSERT: |
| 1536 | case SCSI_PROT_WRITE_STRIP: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1537 | *rxop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1538 | *txop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1539 | break; |
| 1540 | |
| 1541 | case SCSI_PROT_READ_STRIP: |
| 1542 | case SCSI_PROT_WRITE_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1543 | *rxop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1544 | *txop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1545 | break; |
| 1546 | |
| 1547 | case SCSI_PROT_READ_PASS: |
| 1548 | case SCSI_PROT_WRITE_PASS: |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1549 | *rxop = BG_OP_IN_CSUM_OUT_CRC; |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1550 | *txop = BG_OP_IN_CRC_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1551 | break; |
| 1552 | |
| 1553 | case SCSI_PROT_NORMAL: |
| 1554 | default: |
| 1555 | break; |
| 1556 | |
| 1557 | } |
| 1558 | } else { |
| 1559 | switch (scsi_get_prot_op(sc)) { |
| 1560 | case SCSI_PROT_READ_STRIP: |
| 1561 | case SCSI_PROT_WRITE_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1562 | *rxop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1563 | *txop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1564 | break; |
| 1565 | |
| 1566 | case SCSI_PROT_READ_PASS: |
| 1567 | case SCSI_PROT_WRITE_PASS: |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1568 | *rxop = BG_OP_IN_CSUM_OUT_CSUM; |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1569 | *txop = BG_OP_IN_CSUM_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1570 | break; |
| 1571 | |
| 1572 | case SCSI_PROT_READ_INSERT: |
| 1573 | case SCSI_PROT_WRITE_STRIP: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1574 | *rxop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1575 | *txop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1576 | break; |
| 1577 | |
| 1578 | case SCSI_PROT_NORMAL: |
| 1579 | default: |
| 1580 | break; |
| 1581 | } |
| 1582 | } |
| 1583 | |
| 1584 | return ret; |
| 1585 | } |
| 1586 | #endif |
| 1587 | |
| 1588 | /** |
| 1589 | * lpfc_bg_setup_bpl - Setup BlockGuard BPL with no protection data |
| 1590 | * @phba: The Hba for which this call is being executed. |
| 1591 | * @sc: pointer to scsi command we're working on |
| 1592 | * @bpl: pointer to buffer list for protection groups |
| 1593 | * @datacnt: number of segments of data that have been dma mapped |
| 1594 | * |
| 1595 | * This function sets up BPL buffer list for protection groups of |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1596 | * type LPFC_PG_TYPE_NO_DIF |
| 1597 | * |
| 1598 | * This is usually used when the HBA is instructed to generate |
| 1599 | * DIFs and insert them into data stream (or strip DIF from |
| 1600 | * incoming data stream) |
| 1601 | * |
| 1602 | * The buffer list consists of just one protection group described |
| 1603 | * below: |
| 1604 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1605 | * start of prot group --> | PDE_5 | |
| 1606 | * +-------------------------+ |
| 1607 | * | PDE_6 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1608 | * +-------------------------+ |
| 1609 | * | Data BDE | |
| 1610 | * +-------------------------+ |
| 1611 | * |more Data BDE's ... (opt)| |
| 1612 | * +-------------------------+ |
| 1613 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1614 | * |
| 1615 | * Note: Data s/g buffers have been dma mapped |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1616 | * |
| 1617 | * Returns the number of BDEs added to the BPL. |
| 1618 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1619 | static int |
| 1620 | lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1621 | struct ulp_bde64 *bpl, int datasegcnt) |
| 1622 | { |
| 1623 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1624 | struct lpfc_pde5 *pde5 = NULL; |
| 1625 | struct lpfc_pde6 *pde6 = NULL; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1626 | dma_addr_t physaddr; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1627 | int i = 0, num_bde = 0, status; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1628 | int datadir = sc->sc_data_direction; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 1629 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1630 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 1631 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1632 | uint32_t checking = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1633 | uint32_t reftag; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1634 | uint8_t txop, rxop; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1635 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1636 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 1637 | if (status) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1638 | goto out; |
| 1639 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1640 | /* extract some info from the scsi command for pde*/ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1641 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1642 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1643 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1644 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1645 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1646 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1647 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1648 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1649 | checking = 0; |
| 1650 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1651 | #endif |
| 1652 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1653 | /* setup PDE5 with what we have */ |
| 1654 | pde5 = (struct lpfc_pde5 *) bpl; |
| 1655 | memset(pde5, 0, sizeof(struct lpfc_pde5)); |
| 1656 | bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1657 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1658 | /* Endianness conversion if necessary for PDE5 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1659 | pde5->word0 = cpu_to_le32(pde5->word0); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1660 | pde5->reftag = cpu_to_le32(reftag); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1661 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1662 | /* advance bpl and increment bde count */ |
| 1663 | num_bde++; |
| 1664 | bpl++; |
| 1665 | pde6 = (struct lpfc_pde6 *) bpl; |
| 1666 | |
| 1667 | /* setup PDE6 with the rest of the info */ |
| 1668 | memset(pde6, 0, sizeof(struct lpfc_pde6)); |
| 1669 | bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR); |
| 1670 | bf_set(pde6_optx, pde6, txop); |
| 1671 | bf_set(pde6_oprx, pde6, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1672 | |
| 1673 | /* |
| 1674 | * We only need to check the data on READs, for WRITEs |
| 1675 | * protection data is automatically generated, not checked. |
| 1676 | */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1677 | if (datadir == DMA_FROM_DEVICE) { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1678 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1679 | bf_set(pde6_ce, pde6, checking); |
| 1680 | else |
| 1681 | bf_set(pde6_ce, pde6, 0); |
| 1682 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1683 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1684 | bf_set(pde6_re, pde6, checking); |
| 1685 | else |
| 1686 | bf_set(pde6_re, pde6, 0); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1687 | } |
| 1688 | bf_set(pde6_ai, pde6, 1); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1689 | bf_set(pde6_ae, pde6, 0); |
| 1690 | bf_set(pde6_apptagval, pde6, 0); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1691 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1692 | /* Endianness conversion if necessary for PDE6 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1693 | pde6->word0 = cpu_to_le32(pde6->word0); |
| 1694 | pde6->word1 = cpu_to_le32(pde6->word1); |
| 1695 | pde6->word2 = cpu_to_le32(pde6->word2); |
| 1696 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1697 | /* advance bpl and increment bde count */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1698 | num_bde++; |
| 1699 | bpl++; |
| 1700 | |
| 1701 | /* assumption: caller has already run dma_map_sg on command data */ |
| 1702 | scsi_for_each_sg(sc, sgde, datasegcnt, i) { |
| 1703 | physaddr = sg_dma_address(sgde); |
| 1704 | bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
| 1705 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 1706 | bpl->tus.f.bdeSize = sg_dma_len(sgde); |
| 1707 | if (datadir == DMA_TO_DEVICE) |
| 1708 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1709 | else |
| 1710 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
| 1711 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 1712 | bpl++; |
| 1713 | num_bde++; |
| 1714 | } |
| 1715 | |
| 1716 | out: |
| 1717 | return num_bde; |
| 1718 | } |
| 1719 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1720 | /** |
| 1721 | * lpfc_bg_setup_bpl_prot - Setup BlockGuard BPL with protection data |
| 1722 | * @phba: The Hba for which this call is being executed. |
| 1723 | * @sc: pointer to scsi command we're working on |
| 1724 | * @bpl: pointer to buffer list for protection groups |
| 1725 | * @datacnt: number of segments of data that have been dma mapped |
| 1726 | * @protcnt: number of segment of protection data that have been dma mapped |
| 1727 | * |
| 1728 | * This function sets up BPL buffer list for protection groups of |
| 1729 | * type LPFC_PG_TYPE_DIF |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1730 | * |
| 1731 | * This is usually used when DIFs are in their own buffers, |
| 1732 | * separate from the data. The HBA can then by instructed |
| 1733 | * to place the DIFs in the outgoing stream. For read operations, |
| 1734 | * The HBA could extract the DIFs and place it in DIF buffers. |
| 1735 | * |
| 1736 | * The buffer list for this type consists of one or more of the |
| 1737 | * protection groups described below: |
| 1738 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1739 | * start of first prot group --> | PDE_5 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1740 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1741 | * | PDE_6 | |
| 1742 | * +-------------------------+ |
| 1743 | * | PDE_7 (Prot BDE) | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1744 | * +-------------------------+ |
| 1745 | * | Data BDE | |
| 1746 | * +-------------------------+ |
| 1747 | * |more Data BDE's ... (opt)| |
| 1748 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1749 | * start of new prot group --> | PDE_5 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1750 | * +-------------------------+ |
| 1751 | * | ... | |
| 1752 | * +-------------------------+ |
| 1753 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1754 | * Note: It is assumed that both data and protection s/g buffers have been |
| 1755 | * mapped for DMA |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1756 | * |
| 1757 | * Returns the number of BDEs added to the BPL. |
| 1758 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1759 | static int |
| 1760 | lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1761 | struct ulp_bde64 *bpl, int datacnt, int protcnt) |
| 1762 | { |
| 1763 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 1764 | struct scatterlist *sgpe = NULL; /* s/g prot entry */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1765 | struct lpfc_pde5 *pde5 = NULL; |
| 1766 | struct lpfc_pde6 *pde6 = NULL; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1767 | struct lpfc_pde7 *pde7 = NULL; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1768 | dma_addr_t dataphysaddr, protphysaddr; |
| 1769 | unsigned short curr_data = 0, curr_prot = 0; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1770 | unsigned int split_offset; |
| 1771 | unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1772 | unsigned int protgrp_blks, protgrp_bytes; |
| 1773 | unsigned int remainder, subtotal; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1774 | int status; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1775 | int datadir = sc->sc_data_direction; |
| 1776 | unsigned char pgdone = 0, alldone = 0; |
| 1777 | unsigned blksize; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 1778 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1779 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 1780 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1781 | uint32_t checking = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1782 | uint32_t reftag; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1783 | uint8_t txop, rxop; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1784 | int num_bde = 0; |
| 1785 | |
| 1786 | sgpe = scsi_prot_sglist(sc); |
| 1787 | sgde = scsi_sglist(sc); |
| 1788 | |
| 1789 | if (!sgpe || !sgde) { |
| 1790 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 1791 | "9020 Invalid s/g entry: data=x%px prot=x%px\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1792 | sgpe, sgde); |
| 1793 | return 0; |
| 1794 | } |
| 1795 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1796 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 1797 | if (status) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1798 | goto out; |
| 1799 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1800 | /* extract some info from the scsi command */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1801 | blksize = lpfc_cmd_blksize(sc); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1802 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1803 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1804 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1805 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1806 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1807 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1808 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1809 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1810 | checking = 0; |
| 1811 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1812 | #endif |
| 1813 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1814 | split_offset = 0; |
| 1815 | do { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 1816 | /* Check to see if we ran out of space */ |
| 1817 | if (num_bde >= (phba->cfg_total_seg_cnt - 2)) |
| 1818 | return num_bde + 3; |
| 1819 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1820 | /* setup PDE5 with what we have */ |
| 1821 | pde5 = (struct lpfc_pde5 *) bpl; |
| 1822 | memset(pde5, 0, sizeof(struct lpfc_pde5)); |
| 1823 | bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1824 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1825 | /* Endianness conversion if necessary for PDE5 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1826 | pde5->word0 = cpu_to_le32(pde5->word0); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1827 | pde5->reftag = cpu_to_le32(reftag); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1828 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1829 | /* advance bpl and increment bde count */ |
| 1830 | num_bde++; |
| 1831 | bpl++; |
| 1832 | pde6 = (struct lpfc_pde6 *) bpl; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1833 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1834 | /* setup PDE6 with the rest of the info */ |
| 1835 | memset(pde6, 0, sizeof(struct lpfc_pde6)); |
| 1836 | bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR); |
| 1837 | bf_set(pde6_optx, pde6, txop); |
| 1838 | bf_set(pde6_oprx, pde6, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1839 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1840 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1841 | bf_set(pde6_ce, pde6, checking); |
| 1842 | else |
| 1843 | bf_set(pde6_ce, pde6, 0); |
| 1844 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1845 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1846 | bf_set(pde6_re, pde6, checking); |
| 1847 | else |
| 1848 | bf_set(pde6_re, pde6, 0); |
| 1849 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1850 | bf_set(pde6_ai, pde6, 1); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1851 | bf_set(pde6_ae, pde6, 0); |
| 1852 | bf_set(pde6_apptagval, pde6, 0); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1853 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1854 | /* Endianness conversion if necessary for PDE6 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1855 | pde6->word0 = cpu_to_le32(pde6->word0); |
| 1856 | pde6->word1 = cpu_to_le32(pde6->word1); |
| 1857 | pde6->word2 = cpu_to_le32(pde6->word2); |
| 1858 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1859 | /* advance bpl and increment bde count */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1860 | num_bde++; |
| 1861 | bpl++; |
| 1862 | |
| 1863 | /* setup the first BDE that points to protection buffer */ |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1864 | protphysaddr = sg_dma_address(sgpe) + protgroup_offset; |
| 1865 | protgroup_len = sg_dma_len(sgpe) - protgroup_offset; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1866 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1867 | /* must be integer multiple of the DIF block length */ |
| 1868 | BUG_ON(protgroup_len % 8); |
| 1869 | |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1870 | pde7 = (struct lpfc_pde7 *) bpl; |
| 1871 | memset(pde7, 0, sizeof(struct lpfc_pde7)); |
| 1872 | bf_set(pde7_type, pde7, LPFC_PDE7_DESCRIPTOR); |
| 1873 | |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1874 | pde7->addrHigh = le32_to_cpu(putPaddrHigh(protphysaddr)); |
| 1875 | pde7->addrLow = le32_to_cpu(putPaddrLow(protphysaddr)); |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1876 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1877 | protgrp_blks = protgroup_len / 8; |
| 1878 | protgrp_bytes = protgrp_blks * blksize; |
| 1879 | |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1880 | /* check if this pde is crossing the 4K boundary; if so split */ |
| 1881 | if ((pde7->addrLow & 0xfff) + protgroup_len > 0x1000) { |
| 1882 | protgroup_remainder = 0x1000 - (pde7->addrLow & 0xfff); |
| 1883 | protgroup_offset += protgroup_remainder; |
| 1884 | protgrp_blks = protgroup_remainder / 8; |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1885 | protgrp_bytes = protgrp_blks * blksize; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1886 | } else { |
| 1887 | protgroup_offset = 0; |
| 1888 | curr_prot++; |
| 1889 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1890 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1891 | num_bde++; |
| 1892 | |
| 1893 | /* setup BDE's for data blocks associated with DIF data */ |
| 1894 | pgdone = 0; |
| 1895 | subtotal = 0; /* total bytes processed for current prot grp */ |
| 1896 | while (!pgdone) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 1897 | /* Check to see if we ran out of space */ |
| 1898 | if (num_bde >= phba->cfg_total_seg_cnt) |
| 1899 | return num_bde + 1; |
| 1900 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1901 | if (!sgde) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1902 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1903 | "9065 BLKGRD:%s Invalid data segment\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1904 | __func__); |
| 1905 | return 0; |
| 1906 | } |
| 1907 | bpl++; |
| 1908 | dataphysaddr = sg_dma_address(sgde) + split_offset; |
| 1909 | bpl->addrLow = le32_to_cpu(putPaddrLow(dataphysaddr)); |
| 1910 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(dataphysaddr)); |
| 1911 | |
| 1912 | remainder = sg_dma_len(sgde) - split_offset; |
| 1913 | |
| 1914 | if ((subtotal + remainder) <= protgrp_bytes) { |
| 1915 | /* we can use this whole buffer */ |
| 1916 | bpl->tus.f.bdeSize = remainder; |
| 1917 | split_offset = 0; |
| 1918 | |
| 1919 | if ((subtotal + remainder) == protgrp_bytes) |
| 1920 | pgdone = 1; |
| 1921 | } else { |
| 1922 | /* must split this buffer with next prot grp */ |
| 1923 | bpl->tus.f.bdeSize = protgrp_bytes - subtotal; |
| 1924 | split_offset += bpl->tus.f.bdeSize; |
| 1925 | } |
| 1926 | |
| 1927 | subtotal += bpl->tus.f.bdeSize; |
| 1928 | |
| 1929 | if (datadir == DMA_TO_DEVICE) |
| 1930 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1931 | else |
| 1932 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
| 1933 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 1934 | |
| 1935 | num_bde++; |
| 1936 | curr_data++; |
| 1937 | |
| 1938 | if (split_offset) |
| 1939 | break; |
| 1940 | |
| 1941 | /* Move to the next s/g segment if possible */ |
| 1942 | sgde = sg_next(sgde); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1943 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1944 | } |
| 1945 | |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1946 | if (protgroup_offset) { |
| 1947 | /* update the reference tag */ |
| 1948 | reftag += protgrp_blks; |
| 1949 | bpl++; |
| 1950 | continue; |
| 1951 | } |
| 1952 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1953 | /* are we done ? */ |
| 1954 | if (curr_prot == protcnt) { |
| 1955 | alldone = 1; |
| 1956 | } else if (curr_prot < protcnt) { |
| 1957 | /* advance to next prot buffer */ |
| 1958 | sgpe = sg_next(sgpe); |
| 1959 | bpl++; |
| 1960 | |
| 1961 | /* update the reference tag */ |
| 1962 | reftag += protgrp_blks; |
| 1963 | } else { |
| 1964 | /* if we're here, we have a bug */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1965 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1966 | "9054 BLKGRD: bug in %s\n", __func__); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | } while (!alldone); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1970 | out: |
| 1971 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1972 | return num_bde; |
| 1973 | } |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1974 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1975 | /** |
| 1976 | * lpfc_bg_setup_sgl - Setup BlockGuard SGL with no protection data |
| 1977 | * @phba: The Hba for which this call is being executed. |
| 1978 | * @sc: pointer to scsi command we're working on |
| 1979 | * @sgl: pointer to buffer list for protection groups |
| 1980 | * @datacnt: number of segments of data that have been dma mapped |
| 1981 | * |
| 1982 | * This function sets up SGL buffer list for protection groups of |
| 1983 | * type LPFC_PG_TYPE_NO_DIF |
| 1984 | * |
| 1985 | * This is usually used when the HBA is instructed to generate |
| 1986 | * DIFs and insert them into data stream (or strip DIF from |
| 1987 | * incoming data stream) |
| 1988 | * |
| 1989 | * The buffer list consists of just one protection group described |
| 1990 | * below: |
| 1991 | * +-------------------------+ |
| 1992 | * start of prot group --> | DI_SEED | |
| 1993 | * +-------------------------+ |
| 1994 | * | Data SGE | |
| 1995 | * +-------------------------+ |
| 1996 | * |more Data SGE's ... (opt)| |
| 1997 | * +-------------------------+ |
| 1998 | * |
| 1999 | * |
| 2000 | * Note: Data s/g buffers have been dma mapped |
| 2001 | * |
| 2002 | * Returns the number of SGEs added to the SGL. |
| 2003 | **/ |
| 2004 | static int |
| 2005 | lpfc_bg_setup_sgl(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2006 | struct sli4_sge *sgl, int datasegcnt, |
| 2007 | struct lpfc_io_buf *lpfc_cmd) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2008 | { |
| 2009 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 2010 | struct sli4_sge_diseed *diseed = NULL; |
| 2011 | dma_addr_t physaddr; |
| 2012 | int i = 0, num_sge = 0, status; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2013 | uint32_t reftag; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2014 | uint8_t txop, rxop; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2015 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2016 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2017 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2018 | uint32_t checking = 1; |
| 2019 | uint32_t dma_len; |
| 2020 | uint32_t dma_offset = 0; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2021 | struct sli4_hybrid_sgl *sgl_xtra = NULL; |
| 2022 | int j; |
| 2023 | bool lsp_just_set = false; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2024 | |
| 2025 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 2026 | if (status) |
| 2027 | goto out; |
| 2028 | |
| 2029 | /* extract some info from the scsi command for pde*/ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2030 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
| 2031 | |
| 2032 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 2033 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2034 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2035 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2036 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2037 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2038 | checking = 0; |
| 2039 | } |
| 2040 | #endif |
| 2041 | |
| 2042 | /* setup DISEED with what we have */ |
| 2043 | diseed = (struct sli4_sge_diseed *) sgl; |
| 2044 | memset(diseed, 0, sizeof(struct sli4_sge_diseed)); |
| 2045 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED); |
| 2046 | |
| 2047 | /* Endianness conversion if necessary */ |
| 2048 | diseed->ref_tag = cpu_to_le32(reftag); |
| 2049 | diseed->ref_tag_tran = diseed->ref_tag; |
| 2050 | |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2051 | /* |
| 2052 | * We only need to check the data on READs, for WRITEs |
| 2053 | * protection data is automatically generated, not checked. |
| 2054 | */ |
| 2055 | if (sc->sc_data_direction == DMA_FROM_DEVICE) { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2056 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2057 | bf_set(lpfc_sli4_sge_dif_ce, diseed, checking); |
| 2058 | else |
| 2059 | bf_set(lpfc_sli4_sge_dif_ce, diseed, 0); |
| 2060 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2061 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2062 | bf_set(lpfc_sli4_sge_dif_re, diseed, checking); |
| 2063 | else |
| 2064 | bf_set(lpfc_sli4_sge_dif_re, diseed, 0); |
| 2065 | } |
| 2066 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2067 | /* setup DISEED with the rest of the info */ |
| 2068 | bf_set(lpfc_sli4_sge_dif_optx, diseed, txop); |
| 2069 | bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2070 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2071 | bf_set(lpfc_sli4_sge_dif_ai, diseed, 1); |
| 2072 | bf_set(lpfc_sli4_sge_dif_me, diseed, 0); |
| 2073 | |
| 2074 | /* Endianness conversion if necessary for DISEED */ |
| 2075 | diseed->word2 = cpu_to_le32(diseed->word2); |
| 2076 | diseed->word3 = cpu_to_le32(diseed->word3); |
| 2077 | |
| 2078 | /* advance bpl and increment sge count */ |
| 2079 | num_sge++; |
| 2080 | sgl++; |
| 2081 | |
| 2082 | /* assumption: caller has already run dma_map_sg on command data */ |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2083 | sgde = scsi_sglist(sc); |
| 2084 | j = 3; |
| 2085 | for (i = 0; i < datasegcnt; i++) { |
| 2086 | /* clear it */ |
| 2087 | sgl->word2 = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2088 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2089 | /* do we need to expand the segment */ |
| 2090 | if (!lsp_just_set && !((j + 1) % phba->border_sge_num) && |
| 2091 | ((datasegcnt - 1) != i)) { |
| 2092 | /* set LSP type */ |
| 2093 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_LSP); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2094 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2095 | sgl_xtra = lpfc_get_sgl_per_hdwq(phba, lpfc_cmd); |
| 2096 | |
| 2097 | if (unlikely(!sgl_xtra)) { |
| 2098 | lpfc_cmd->seg_cnt = 0; |
| 2099 | return 0; |
| 2100 | } |
| 2101 | sgl->addr_lo = cpu_to_le32(putPaddrLow( |
| 2102 | sgl_xtra->dma_phys_sgl)); |
| 2103 | sgl->addr_hi = cpu_to_le32(putPaddrHigh( |
| 2104 | sgl_xtra->dma_phys_sgl)); |
| 2105 | |
| 2106 | } else { |
| 2107 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); |
| 2108 | } |
| 2109 | |
| 2110 | if (!(bf_get(lpfc_sli4_sge_type, sgl) & LPFC_SGE_TYPE_LSP)) { |
| 2111 | if ((datasegcnt - 1) == i) |
| 2112 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 2113 | physaddr = sg_dma_address(sgde); |
| 2114 | dma_len = sg_dma_len(sgde); |
| 2115 | sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr)); |
| 2116 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr)); |
| 2117 | |
| 2118 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
| 2119 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 2120 | sgl->sge_len = cpu_to_le32(dma_len); |
| 2121 | |
| 2122 | dma_offset += dma_len; |
| 2123 | sgde = sg_next(sgde); |
| 2124 | |
| 2125 | sgl++; |
| 2126 | num_sge++; |
| 2127 | lsp_just_set = false; |
| 2128 | |
| 2129 | } else { |
| 2130 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 2131 | sgl->sge_len = cpu_to_le32(phba->cfg_sg_dma_buf_size); |
| 2132 | |
| 2133 | sgl = (struct sli4_sge *)sgl_xtra->dma_sgl; |
| 2134 | i = i - 1; |
| 2135 | |
| 2136 | lsp_just_set = true; |
| 2137 | } |
| 2138 | |
| 2139 | j++; |
| 2140 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2141 | } |
| 2142 | |
| 2143 | out: |
| 2144 | return num_sge; |
| 2145 | } |
| 2146 | |
| 2147 | /** |
| 2148 | * lpfc_bg_setup_sgl_prot - Setup BlockGuard SGL with protection data |
| 2149 | * @phba: The Hba for which this call is being executed. |
| 2150 | * @sc: pointer to scsi command we're working on |
| 2151 | * @sgl: pointer to buffer list for protection groups |
| 2152 | * @datacnt: number of segments of data that have been dma mapped |
| 2153 | * @protcnt: number of segment of protection data that have been dma mapped |
| 2154 | * |
| 2155 | * This function sets up SGL buffer list for protection groups of |
| 2156 | * type LPFC_PG_TYPE_DIF |
| 2157 | * |
| 2158 | * This is usually used when DIFs are in their own buffers, |
| 2159 | * separate from the data. The HBA can then by instructed |
| 2160 | * to place the DIFs in the outgoing stream. For read operations, |
| 2161 | * The HBA could extract the DIFs and place it in DIF buffers. |
| 2162 | * |
| 2163 | * The buffer list for this type consists of one or more of the |
| 2164 | * protection groups described below: |
| 2165 | * +-------------------------+ |
| 2166 | * start of first prot group --> | DISEED | |
| 2167 | * +-------------------------+ |
| 2168 | * | DIF (Prot SGE) | |
| 2169 | * +-------------------------+ |
| 2170 | * | Data SGE | |
| 2171 | * +-------------------------+ |
| 2172 | * |more Data SGE's ... (opt)| |
| 2173 | * +-------------------------+ |
| 2174 | * start of new prot group --> | DISEED | |
| 2175 | * +-------------------------+ |
| 2176 | * | ... | |
| 2177 | * +-------------------------+ |
| 2178 | * |
| 2179 | * Note: It is assumed that both data and protection s/g buffers have been |
| 2180 | * mapped for DMA |
| 2181 | * |
| 2182 | * Returns the number of SGEs added to the SGL. |
| 2183 | **/ |
| 2184 | static int |
| 2185 | lpfc_bg_setup_sgl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2186 | struct sli4_sge *sgl, int datacnt, int protcnt, |
| 2187 | struct lpfc_io_buf *lpfc_cmd) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2188 | { |
| 2189 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 2190 | struct scatterlist *sgpe = NULL; /* s/g prot entry */ |
| 2191 | struct sli4_sge_diseed *diseed = NULL; |
| 2192 | dma_addr_t dataphysaddr, protphysaddr; |
| 2193 | unsigned short curr_data = 0, curr_prot = 0; |
| 2194 | unsigned int split_offset; |
| 2195 | unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder; |
| 2196 | unsigned int protgrp_blks, protgrp_bytes; |
| 2197 | unsigned int remainder, subtotal; |
| 2198 | int status; |
| 2199 | unsigned char pgdone = 0, alldone = 0; |
| 2200 | unsigned blksize; |
| 2201 | uint32_t reftag; |
| 2202 | uint8_t txop, rxop; |
| 2203 | uint32_t dma_len; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2204 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2205 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2206 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2207 | uint32_t checking = 1; |
| 2208 | uint32_t dma_offset = 0; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2209 | int num_sge = 0, j = 2; |
| 2210 | struct sli4_hybrid_sgl *sgl_xtra = NULL; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2211 | |
| 2212 | sgpe = scsi_prot_sglist(sc); |
| 2213 | sgde = scsi_sglist(sc); |
| 2214 | |
| 2215 | if (!sgpe || !sgde) { |
| 2216 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 2217 | "9082 Invalid s/g entry: data=x%px prot=x%px\n", |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2218 | sgpe, sgde); |
| 2219 | return 0; |
| 2220 | } |
| 2221 | |
| 2222 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 2223 | if (status) |
| 2224 | goto out; |
| 2225 | |
| 2226 | /* extract some info from the scsi command */ |
| 2227 | blksize = lpfc_cmd_blksize(sc); |
| 2228 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
| 2229 | |
| 2230 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 2231 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2232 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2233 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2234 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2235 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2236 | checking = 0; |
| 2237 | } |
| 2238 | #endif |
| 2239 | |
| 2240 | split_offset = 0; |
| 2241 | do { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2242 | /* Check to see if we ran out of space */ |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2243 | if ((num_sge >= (phba->cfg_total_seg_cnt - 2)) && |
| 2244 | !(phba->cfg_xpsgl)) |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2245 | return num_sge + 3; |
| 2246 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2247 | /* DISEED and DIF have to be together */ |
| 2248 | if (!((j + 1) % phba->border_sge_num) || |
| 2249 | !((j + 2) % phba->border_sge_num) || |
| 2250 | !((j + 3) % phba->border_sge_num)) { |
| 2251 | sgl->word2 = 0; |
| 2252 | |
| 2253 | /* set LSP type */ |
| 2254 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_LSP); |
| 2255 | |
| 2256 | sgl_xtra = lpfc_get_sgl_per_hdwq(phba, lpfc_cmd); |
| 2257 | |
| 2258 | if (unlikely(!sgl_xtra)) { |
| 2259 | goto out; |
| 2260 | } else { |
| 2261 | sgl->addr_lo = cpu_to_le32(putPaddrLow( |
| 2262 | sgl_xtra->dma_phys_sgl)); |
| 2263 | sgl->addr_hi = cpu_to_le32(putPaddrHigh( |
| 2264 | sgl_xtra->dma_phys_sgl)); |
| 2265 | } |
| 2266 | |
| 2267 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 2268 | sgl->sge_len = cpu_to_le32(phba->cfg_sg_dma_buf_size); |
| 2269 | |
| 2270 | sgl = (struct sli4_sge *)sgl_xtra->dma_sgl; |
| 2271 | j = 0; |
| 2272 | } |
| 2273 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2274 | /* setup DISEED with what we have */ |
| 2275 | diseed = (struct sli4_sge_diseed *) sgl; |
| 2276 | memset(diseed, 0, sizeof(struct sli4_sge_diseed)); |
| 2277 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED); |
| 2278 | |
| 2279 | /* Endianness conversion if necessary */ |
| 2280 | diseed->ref_tag = cpu_to_le32(reftag); |
| 2281 | diseed->ref_tag_tran = diseed->ref_tag; |
| 2282 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2283 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) { |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2284 | bf_set(lpfc_sli4_sge_dif_ce, diseed, checking); |
| 2285 | |
| 2286 | } else { |
| 2287 | bf_set(lpfc_sli4_sge_dif_ce, diseed, 0); |
| 2288 | /* |
| 2289 | * When in this mode, the hardware will replace |
| 2290 | * the guard tag from the host with a |
| 2291 | * newly generated good CRC for the wire. |
| 2292 | * Switch to raw mode here to avoid this |
| 2293 | * behavior. What the host sends gets put on the wire. |
| 2294 | */ |
| 2295 | if (txop == BG_OP_IN_CRC_OUT_CRC) { |
| 2296 | txop = BG_OP_RAW_MODE; |
| 2297 | rxop = BG_OP_RAW_MODE; |
| 2298 | } |
| 2299 | } |
| 2300 | |
| 2301 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2302 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2303 | bf_set(lpfc_sli4_sge_dif_re, diseed, checking); |
| 2304 | else |
| 2305 | bf_set(lpfc_sli4_sge_dif_re, diseed, 0); |
| 2306 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2307 | /* setup DISEED with the rest of the info */ |
| 2308 | bf_set(lpfc_sli4_sge_dif_optx, diseed, txop); |
| 2309 | bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2310 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2311 | bf_set(lpfc_sli4_sge_dif_ai, diseed, 1); |
| 2312 | bf_set(lpfc_sli4_sge_dif_me, diseed, 0); |
| 2313 | |
| 2314 | /* Endianness conversion if necessary for DISEED */ |
| 2315 | diseed->word2 = cpu_to_le32(diseed->word2); |
| 2316 | diseed->word3 = cpu_to_le32(diseed->word3); |
| 2317 | |
| 2318 | /* advance sgl and increment bde count */ |
| 2319 | num_sge++; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2320 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2321 | sgl++; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2322 | j++; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2323 | |
| 2324 | /* setup the first BDE that points to protection buffer */ |
| 2325 | protphysaddr = sg_dma_address(sgpe) + protgroup_offset; |
| 2326 | protgroup_len = sg_dma_len(sgpe) - protgroup_offset; |
| 2327 | |
| 2328 | /* must be integer multiple of the DIF block length */ |
| 2329 | BUG_ON(protgroup_len % 8); |
| 2330 | |
| 2331 | /* Now setup DIF SGE */ |
| 2332 | sgl->word2 = 0; |
| 2333 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DIF); |
| 2334 | sgl->addr_hi = le32_to_cpu(putPaddrHigh(protphysaddr)); |
| 2335 | sgl->addr_lo = le32_to_cpu(putPaddrLow(protphysaddr)); |
| 2336 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2337 | sgl->sge_len = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2338 | |
| 2339 | protgrp_blks = protgroup_len / 8; |
| 2340 | protgrp_bytes = protgrp_blks * blksize; |
| 2341 | |
| 2342 | /* check if DIF SGE is crossing the 4K boundary; if so split */ |
| 2343 | if ((sgl->addr_lo & 0xfff) + protgroup_len > 0x1000) { |
| 2344 | protgroup_remainder = 0x1000 - (sgl->addr_lo & 0xfff); |
| 2345 | protgroup_offset += protgroup_remainder; |
| 2346 | protgrp_blks = protgroup_remainder / 8; |
| 2347 | protgrp_bytes = protgrp_blks * blksize; |
| 2348 | } else { |
| 2349 | protgroup_offset = 0; |
| 2350 | curr_prot++; |
| 2351 | } |
| 2352 | |
| 2353 | num_sge++; |
| 2354 | |
| 2355 | /* setup SGE's for data blocks associated with DIF data */ |
| 2356 | pgdone = 0; |
| 2357 | subtotal = 0; /* total bytes processed for current prot grp */ |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2358 | |
| 2359 | sgl++; |
| 2360 | j++; |
| 2361 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2362 | while (!pgdone) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2363 | /* Check to see if we ran out of space */ |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2364 | if ((num_sge >= phba->cfg_total_seg_cnt) && |
| 2365 | !phba->cfg_xpsgl) |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2366 | return num_sge + 1; |
| 2367 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2368 | if (!sgde) { |
| 2369 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2370 | "9086 BLKGRD:%s Invalid data segment\n", |
| 2371 | __func__); |
| 2372 | return 0; |
| 2373 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2374 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2375 | if (!((j + 1) % phba->border_sge_num)) { |
| 2376 | sgl->word2 = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2377 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2378 | /* set LSP type */ |
| 2379 | bf_set(lpfc_sli4_sge_type, sgl, |
| 2380 | LPFC_SGE_TYPE_LSP); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2381 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2382 | sgl_xtra = lpfc_get_sgl_per_hdwq(phba, |
| 2383 | lpfc_cmd); |
| 2384 | |
| 2385 | if (unlikely(!sgl_xtra)) { |
| 2386 | goto out; |
| 2387 | } else { |
| 2388 | sgl->addr_lo = cpu_to_le32( |
| 2389 | putPaddrLow(sgl_xtra->dma_phys_sgl)); |
| 2390 | sgl->addr_hi = cpu_to_le32( |
| 2391 | putPaddrHigh(sgl_xtra->dma_phys_sgl)); |
| 2392 | } |
| 2393 | |
| 2394 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 2395 | sgl->sge_len = cpu_to_le32( |
| 2396 | phba->cfg_sg_dma_buf_size); |
| 2397 | |
| 2398 | sgl = (struct sli4_sge *)sgl_xtra->dma_sgl; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2399 | } else { |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2400 | dataphysaddr = sg_dma_address(sgde) + |
| 2401 | split_offset; |
| 2402 | |
| 2403 | remainder = sg_dma_len(sgde) - split_offset; |
| 2404 | |
| 2405 | if ((subtotal + remainder) <= protgrp_bytes) { |
| 2406 | /* we can use this whole buffer */ |
| 2407 | dma_len = remainder; |
| 2408 | split_offset = 0; |
| 2409 | |
| 2410 | if ((subtotal + remainder) == |
| 2411 | protgrp_bytes) |
| 2412 | pgdone = 1; |
| 2413 | } else { |
| 2414 | /* must split this buffer with next |
| 2415 | * prot grp |
| 2416 | */ |
| 2417 | dma_len = protgrp_bytes - subtotal; |
| 2418 | split_offset += dma_len; |
| 2419 | } |
| 2420 | |
| 2421 | subtotal += dma_len; |
| 2422 | |
| 2423 | sgl->word2 = 0; |
| 2424 | sgl->addr_lo = cpu_to_le32(putPaddrLow( |
| 2425 | dataphysaddr)); |
| 2426 | sgl->addr_hi = cpu_to_le32(putPaddrHigh( |
| 2427 | dataphysaddr)); |
| 2428 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 2429 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
| 2430 | bf_set(lpfc_sli4_sge_type, sgl, |
| 2431 | LPFC_SGE_TYPE_DATA); |
| 2432 | |
| 2433 | sgl->sge_len = cpu_to_le32(dma_len); |
| 2434 | dma_offset += dma_len; |
| 2435 | |
| 2436 | num_sge++; |
| 2437 | curr_data++; |
| 2438 | |
| 2439 | if (split_offset) { |
| 2440 | sgl++; |
| 2441 | j++; |
| 2442 | break; |
| 2443 | } |
| 2444 | |
| 2445 | /* Move to the next s/g segment if possible */ |
| 2446 | sgde = sg_next(sgde); |
| 2447 | |
| 2448 | sgl++; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2449 | } |
| 2450 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2451 | j++; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2452 | } |
| 2453 | |
| 2454 | if (protgroup_offset) { |
| 2455 | /* update the reference tag */ |
| 2456 | reftag += protgrp_blks; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2457 | continue; |
| 2458 | } |
| 2459 | |
| 2460 | /* are we done ? */ |
| 2461 | if (curr_prot == protcnt) { |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2462 | /* mark the last SGL */ |
| 2463 | sgl--; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2464 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 2465 | alldone = 1; |
| 2466 | } else if (curr_prot < protcnt) { |
| 2467 | /* advance to next prot buffer */ |
| 2468 | sgpe = sg_next(sgpe); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2469 | |
| 2470 | /* update the reference tag */ |
| 2471 | reftag += protgrp_blks; |
| 2472 | } else { |
| 2473 | /* if we're here, we have a bug */ |
| 2474 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2475 | "9085 BLKGRD: bug in %s\n", __func__); |
| 2476 | } |
| 2477 | |
| 2478 | } while (!alldone); |
| 2479 | |
| 2480 | out: |
| 2481 | |
| 2482 | return num_sge; |
| 2483 | } |
| 2484 | |
| 2485 | /** |
| 2486 | * lpfc_prot_group_type - Get prtotection group type of SCSI command |
| 2487 | * @phba: The Hba for which this call is being executed. |
| 2488 | * @sc: pointer to scsi command we're working on |
| 2489 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2490 | * Given a SCSI command that supports DIF, determine composition of protection |
| 2491 | * groups involved in setting up buffer lists |
| 2492 | * |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2493 | * Returns: Protection group type (with or without DIF) |
| 2494 | * |
| 2495 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2496 | static int |
| 2497 | lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc) |
| 2498 | { |
| 2499 | int ret = LPFC_PG_TYPE_INVALID; |
| 2500 | unsigned char op = scsi_get_prot_op(sc); |
| 2501 | |
| 2502 | switch (op) { |
| 2503 | case SCSI_PROT_READ_STRIP: |
| 2504 | case SCSI_PROT_WRITE_INSERT: |
| 2505 | ret = LPFC_PG_TYPE_NO_DIF; |
| 2506 | break; |
| 2507 | case SCSI_PROT_READ_INSERT: |
| 2508 | case SCSI_PROT_WRITE_STRIP: |
| 2509 | case SCSI_PROT_READ_PASS: |
| 2510 | case SCSI_PROT_WRITE_PASS: |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2511 | ret = LPFC_PG_TYPE_DIF_BUF; |
| 2512 | break; |
| 2513 | default: |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2514 | if (phba) |
| 2515 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2516 | "9021 Unsupported protection op:%d\n", |
| 2517 | op); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2518 | break; |
| 2519 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2520 | return ret; |
| 2521 | } |
| 2522 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2523 | /** |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2524 | * lpfc_bg_scsi_adjust_dl - Adjust SCSI data length for BlockGuard |
| 2525 | * @phba: The Hba for which this call is being executed. |
| 2526 | * @lpfc_cmd: The scsi buffer which is going to be adjusted. |
| 2527 | * |
| 2528 | * Adjust the data length to account for how much data |
| 2529 | * is actually on the wire. |
| 2530 | * |
| 2531 | * returns the adjusted data length |
| 2532 | **/ |
| 2533 | static int |
| 2534 | lpfc_bg_scsi_adjust_dl(struct lpfc_hba *phba, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 2535 | struct lpfc_io_buf *lpfc_cmd) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2536 | { |
| 2537 | struct scsi_cmnd *sc = lpfc_cmd->pCmd; |
| 2538 | int fcpdl; |
| 2539 | |
| 2540 | fcpdl = scsi_bufflen(sc); |
| 2541 | |
| 2542 | /* Check if there is protection data on the wire */ |
| 2543 | if (sc->sc_data_direction == DMA_FROM_DEVICE) { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2544 | /* Read check for protection data */ |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2545 | if (scsi_get_prot_op(sc) == SCSI_PROT_READ_INSERT) |
| 2546 | return fcpdl; |
| 2547 | |
| 2548 | } else { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2549 | /* Write check for protection data */ |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2550 | if (scsi_get_prot_op(sc) == SCSI_PROT_WRITE_STRIP) |
| 2551 | return fcpdl; |
| 2552 | } |
| 2553 | |
| 2554 | /* |
| 2555 | * 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] | 2556 | * DIF (trailer) attached to it. Must ajust FCP data length |
| 2557 | * to account for the protection data. |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2558 | */ |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2559 | fcpdl += (fcpdl / lpfc_cmd_blksize(sc)) * 8; |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2560 | |
| 2561 | return fcpdl; |
| 2562 | } |
| 2563 | |
| 2564 | /** |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2565 | * lpfc_bg_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec |
| 2566 | * @phba: The Hba for which this call is being executed. |
| 2567 | * @lpfc_cmd: The scsi buffer which is going to be prep'ed. |
| 2568 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2569 | * This is the protection/DIF aware version of |
| 2570 | * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2571 | * two functions eventually, but for now, it's here. |
| 2572 | * RETURNS 0 - SUCCESS, |
| 2573 | * 1 - Failed DMA map, retry. |
| 2574 | * 2 - Invalid scsi cmd or prot-type. Do not rety. |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2575 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2576 | static int |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2577 | lpfc_bg_scsi_prep_dma_buf_s3(struct lpfc_hba *phba, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 2578 | struct lpfc_io_buf *lpfc_cmd) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2579 | { |
| 2580 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 2581 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 2582 | struct ulp_bde64 *bpl = (struct ulp_bde64 *)lpfc_cmd->dma_sgl; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2583 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 2584 | uint32_t num_bde = 0; |
| 2585 | int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction; |
| 2586 | int prot_group_type = 0; |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2587 | int fcpdl; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2588 | int ret = 1; |
James Smart | 7c4042a | 2018-11-29 16:09:40 -0800 | [diff] [blame] | 2589 | struct lpfc_vport *vport = phba->pport; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2590 | |
| 2591 | /* |
| 2592 | * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd |
| 2593 | * fcp_rsp regions to the first data bde entry |
| 2594 | */ |
| 2595 | bpl += 2; |
| 2596 | if (scsi_sg_count(scsi_cmnd)) { |
| 2597 | /* |
| 2598 | * The driver stores the segment count returned from pci_map_sg |
| 2599 | * because this a count of dma-mappings used to map the use_sg |
| 2600 | * pages. They are not guaranteed to be the same for those |
| 2601 | * architectures that implement an IOMMU. |
| 2602 | */ |
| 2603 | datasegcnt = dma_map_sg(&phba->pcidev->dev, |
| 2604 | scsi_sglist(scsi_cmnd), |
| 2605 | scsi_sg_count(scsi_cmnd), datadir); |
| 2606 | if (unlikely(!datasegcnt)) |
| 2607 | return 1; |
| 2608 | |
| 2609 | lpfc_cmd->seg_cnt = datasegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2610 | |
| 2611 | /* First check if data segment count from SCSI Layer is good */ |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2612 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
| 2613 | WARN_ON_ONCE(lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt); |
| 2614 | ret = 2; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2615 | goto err; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2616 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2617 | |
| 2618 | prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd); |
| 2619 | |
| 2620 | switch (prot_group_type) { |
| 2621 | case LPFC_PG_TYPE_NO_DIF: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2622 | |
| 2623 | /* Here we need to add a PDE5 and PDE6 to the count */ |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2624 | if ((lpfc_cmd->seg_cnt + 2) > phba->cfg_total_seg_cnt) { |
| 2625 | ret = 2; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2626 | goto err; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2627 | } |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2628 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2629 | num_bde = lpfc_bg_setup_bpl(phba, scsi_cmnd, bpl, |
| 2630 | datasegcnt); |
Adam Buchbinder | c9404c9 | 2009-12-18 15:40:42 -0500 | [diff] [blame] | 2631 | /* we should have 2 or more entries in buffer list */ |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2632 | if (num_bde < 2) { |
| 2633 | ret = 2; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2634 | goto err; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2635 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2636 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2637 | |
| 2638 | case LPFC_PG_TYPE_DIF_BUF: |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2639 | /* |
| 2640 | * This type indicates that protection buffers are |
| 2641 | * passed to the driver, so that needs to be prepared |
| 2642 | * for DMA |
| 2643 | */ |
| 2644 | protsegcnt = dma_map_sg(&phba->pcidev->dev, |
| 2645 | scsi_prot_sglist(scsi_cmnd), |
| 2646 | scsi_prot_sg_count(scsi_cmnd), datadir); |
| 2647 | if (unlikely(!protsegcnt)) { |
| 2648 | scsi_dma_unmap(scsi_cmnd); |
| 2649 | return 1; |
| 2650 | } |
| 2651 | |
| 2652 | lpfc_cmd->prot_seg_cnt = protsegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2653 | |
| 2654 | /* |
| 2655 | * There is a minimun of 4 BPLs used for every |
| 2656 | * protection data segment. |
| 2657 | */ |
| 2658 | if ((lpfc_cmd->prot_seg_cnt * 4) > |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2659 | (phba->cfg_total_seg_cnt - 2)) { |
| 2660 | ret = 2; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2661 | goto err; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2662 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2663 | |
| 2664 | num_bde = lpfc_bg_setup_bpl_prot(phba, scsi_cmnd, bpl, |
| 2665 | datasegcnt, protsegcnt); |
Adam Buchbinder | c9404c9 | 2009-12-18 15:40:42 -0500 | [diff] [blame] | 2666 | /* we should have 3 or more entries in buffer list */ |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2667 | if ((num_bde < 3) || |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2668 | (num_bde > phba->cfg_total_seg_cnt)) { |
| 2669 | ret = 2; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2670 | goto err; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2671 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2672 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2673 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2674 | case LPFC_PG_TYPE_INVALID: |
| 2675 | default: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2676 | scsi_dma_unmap(scsi_cmnd); |
| 2677 | lpfc_cmd->seg_cnt = 0; |
| 2678 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2679 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2680 | "9022 Unexpected protection group %i\n", |
| 2681 | prot_group_type); |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2682 | return 2; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2683 | } |
| 2684 | } |
| 2685 | |
| 2686 | /* |
| 2687 | * Finish initializing those IOCB fields that are dependent on the |
| 2688 | * scsi_cmnd request_buffer. Note that the bdeSize is explicitly |
| 2689 | * reinitialized since all iocb memory resources are used many times |
| 2690 | * for transmit, receive, and continuation bpl's. |
| 2691 | */ |
| 2692 | iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| 2693 | iocb_cmd->un.fcpi64.bdl.bdeSize += (num_bde * sizeof(struct ulp_bde64)); |
| 2694 | iocb_cmd->ulpBdeCount = 1; |
| 2695 | iocb_cmd->ulpLe = 1; |
| 2696 | |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2697 | fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2698 | fcp_cmnd->fcpDl = be32_to_cpu(fcpdl); |
| 2699 | |
| 2700 | /* |
| 2701 | * Due to difference in data length between DIF/non-DIF paths, |
| 2702 | * we need to set word 4 of IOCB here |
| 2703 | */ |
| 2704 | iocb_cmd->un.fcpi.fcpi_parm = fcpdl; |
| 2705 | |
James Smart | 7c4042a | 2018-11-29 16:09:40 -0800 | [diff] [blame] | 2706 | /* |
| 2707 | * For First burst, we may need to adjust the initial transfer |
| 2708 | * length for DIF |
| 2709 | */ |
| 2710 | if (iocb_cmd->un.fcpi.fcpi_XRdy && |
| 2711 | (fcpdl < vport->cfg_first_burst_size)) |
| 2712 | iocb_cmd->un.fcpi.fcpi_XRdy = fcpdl; |
| 2713 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2714 | return 0; |
| 2715 | err: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2716 | if (lpfc_cmd->seg_cnt) |
| 2717 | scsi_dma_unmap(scsi_cmnd); |
| 2718 | if (lpfc_cmd->prot_seg_cnt) |
| 2719 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd), |
| 2720 | scsi_prot_sg_count(scsi_cmnd), |
| 2721 | scsi_cmnd->sc_data_direction); |
| 2722 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2723 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2724 | "9023 Cannot setup S/G List for HBA" |
| 2725 | "IO segs %d/%d BPL %d SCSI %d: %d %d\n", |
| 2726 | lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt, |
| 2727 | phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2728 | prot_group_type, num_bde); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2729 | |
| 2730 | lpfc_cmd->seg_cnt = 0; |
| 2731 | lpfc_cmd->prot_seg_cnt = 0; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2732 | return ret; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2733 | } |
| 2734 | |
| 2735 | /* |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2736 | * This function calcuates the T10 DIF guard tag |
| 2737 | * on the specified data using a CRC algorithmn |
| 2738 | * using crc_t10dif. |
| 2739 | */ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 2740 | static uint16_t |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2741 | lpfc_bg_crc(uint8_t *data, int count) |
| 2742 | { |
| 2743 | uint16_t crc = 0; |
| 2744 | uint16_t x; |
| 2745 | |
| 2746 | crc = crc_t10dif(data, count); |
| 2747 | x = cpu_to_be16(crc); |
| 2748 | return x; |
| 2749 | } |
| 2750 | |
| 2751 | /* |
| 2752 | * This function calcuates the T10 DIF guard tag |
| 2753 | * on the specified data using a CSUM algorithmn |
| 2754 | * using ip_compute_csum. |
| 2755 | */ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 2756 | static uint16_t |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2757 | lpfc_bg_csum(uint8_t *data, int count) |
| 2758 | { |
| 2759 | uint16_t ret; |
| 2760 | |
| 2761 | ret = ip_compute_csum(data, count); |
| 2762 | return ret; |
| 2763 | } |
| 2764 | |
| 2765 | /* |
| 2766 | * This function examines the protection data to try to determine |
| 2767 | * what type of T10-DIF error occurred. |
| 2768 | */ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 2769 | static void |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 2770 | lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd) |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2771 | { |
| 2772 | struct scatterlist *sgpe; /* s/g prot entry */ |
| 2773 | struct scatterlist *sgde; /* s/g data entry */ |
| 2774 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 2775 | struct scsi_dif_tuple *src = NULL; |
| 2776 | uint8_t *data_src = NULL; |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 2777 | uint16_t guard_tag; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2778 | uint16_t start_app_tag, app_tag; |
| 2779 | uint32_t start_ref_tag, ref_tag; |
| 2780 | int prot, protsegcnt; |
| 2781 | int err_type, len, data_len; |
| 2782 | int chk_ref, chk_app, chk_guard; |
| 2783 | uint16_t sum; |
| 2784 | unsigned blksize; |
| 2785 | |
| 2786 | err_type = BGS_GUARD_ERR_MASK; |
| 2787 | sum = 0; |
| 2788 | guard_tag = 0; |
| 2789 | |
| 2790 | /* First check to see if there is protection data to examine */ |
| 2791 | prot = scsi_get_prot_op(cmd); |
| 2792 | if ((prot == SCSI_PROT_READ_STRIP) || |
| 2793 | (prot == SCSI_PROT_WRITE_INSERT) || |
| 2794 | (prot == SCSI_PROT_NORMAL)) |
| 2795 | goto out; |
| 2796 | |
| 2797 | /* Currently the driver just supports ref_tag and guard_tag checking */ |
| 2798 | chk_ref = 1; |
| 2799 | chk_app = 0; |
| 2800 | chk_guard = 0; |
| 2801 | |
| 2802 | /* Setup a ptr to the protection data provided by the SCSI host */ |
| 2803 | sgpe = scsi_prot_sglist(cmd); |
| 2804 | protsegcnt = lpfc_cmd->prot_seg_cnt; |
| 2805 | |
| 2806 | if (sgpe && protsegcnt) { |
| 2807 | |
| 2808 | /* |
| 2809 | * We will only try to verify guard tag if the segment |
| 2810 | * data length is a multiple of the blksize. |
| 2811 | */ |
| 2812 | sgde = scsi_sglist(cmd); |
| 2813 | blksize = lpfc_cmd_blksize(cmd); |
| 2814 | data_src = (uint8_t *)sg_virt(sgde); |
| 2815 | data_len = sgde->length; |
| 2816 | if ((data_len & (blksize - 1)) == 0) |
| 2817 | chk_guard = 1; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2818 | |
James Smart | e85d8f9 | 2013-05-31 17:04:10 -0400 | [diff] [blame] | 2819 | src = (struct scsi_dif_tuple *)sg_virt(sgpe); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2820 | start_ref_tag = (uint32_t)scsi_get_lba(cmd); /* Truncate LBA */ |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2821 | start_app_tag = src->app_tag; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2822 | len = sgpe->length; |
| 2823 | while (src && protsegcnt) { |
| 2824 | while (len) { |
| 2825 | |
| 2826 | /* |
| 2827 | * First check to see if a protection data |
| 2828 | * check is valid |
| 2829 | */ |
Dmitry Monakhov | 128b6f9 | 2017-06-29 11:31:12 -0700 | [diff] [blame] | 2830 | if ((src->ref_tag == T10_PI_REF_ESCAPE) || |
| 2831 | (src->app_tag == T10_PI_APP_ESCAPE)) { |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2832 | start_ref_tag++; |
| 2833 | goto skipit; |
| 2834 | } |
| 2835 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2836 | /* First Guard Tag checking */ |
| 2837 | if (chk_guard) { |
| 2838 | guard_tag = src->guard_tag; |
| 2839 | if (lpfc_cmd_guard_csum(cmd)) |
| 2840 | sum = lpfc_bg_csum(data_src, |
| 2841 | blksize); |
| 2842 | else |
| 2843 | sum = lpfc_bg_crc(data_src, |
| 2844 | blksize); |
| 2845 | if ((guard_tag != sum)) { |
| 2846 | err_type = BGS_GUARD_ERR_MASK; |
| 2847 | goto out; |
| 2848 | } |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2849 | } |
| 2850 | |
| 2851 | /* Reference Tag checking */ |
| 2852 | ref_tag = be32_to_cpu(src->ref_tag); |
| 2853 | if (chk_ref && (ref_tag != start_ref_tag)) { |
| 2854 | err_type = BGS_REFTAG_ERR_MASK; |
| 2855 | goto out; |
| 2856 | } |
| 2857 | start_ref_tag++; |
| 2858 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2859 | /* App Tag checking */ |
| 2860 | app_tag = src->app_tag; |
| 2861 | if (chk_app && (app_tag != start_app_tag)) { |
| 2862 | err_type = BGS_APPTAG_ERR_MASK; |
| 2863 | goto out; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2864 | } |
| 2865 | skipit: |
| 2866 | len -= sizeof(struct scsi_dif_tuple); |
| 2867 | if (len < 0) |
| 2868 | len = 0; |
| 2869 | src++; |
| 2870 | |
| 2871 | data_src += blksize; |
| 2872 | data_len -= blksize; |
| 2873 | |
| 2874 | /* |
| 2875 | * Are we at the end of the Data segment? |
| 2876 | * The data segment is only used for Guard |
| 2877 | * tag checking. |
| 2878 | */ |
| 2879 | if (chk_guard && (data_len == 0)) { |
| 2880 | chk_guard = 0; |
| 2881 | sgde = sg_next(sgde); |
| 2882 | if (!sgde) |
| 2883 | goto out; |
| 2884 | |
| 2885 | data_src = (uint8_t *)sg_virt(sgde); |
| 2886 | data_len = sgde->length; |
| 2887 | if ((data_len & (blksize - 1)) == 0) |
| 2888 | chk_guard = 1; |
| 2889 | } |
| 2890 | } |
| 2891 | |
| 2892 | /* Goto the next Protection data segment */ |
| 2893 | sgpe = sg_next(sgpe); |
| 2894 | if (sgpe) { |
| 2895 | src = (struct scsi_dif_tuple *)sg_virt(sgpe); |
| 2896 | len = sgpe->length; |
| 2897 | } else { |
| 2898 | src = NULL; |
| 2899 | } |
| 2900 | protsegcnt--; |
| 2901 | } |
| 2902 | } |
| 2903 | out: |
| 2904 | if (err_type == BGS_GUARD_ERR_MASK) { |
| 2905 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 2906 | 0x10, 0x1); |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 2907 | cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 | |
| 2908 | SAM_STAT_CHECK_CONDITION; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2909 | phba->bg_guard_err_cnt++; |
| 2910 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 2911 | "9069 BLKGRD: LBA %lx grd_tag error %x != %x\n", |
| 2912 | (unsigned long)scsi_get_lba(cmd), |
| 2913 | sum, guard_tag); |
| 2914 | |
| 2915 | } else if (err_type == BGS_REFTAG_ERR_MASK) { |
| 2916 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 2917 | 0x10, 0x3); |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 2918 | cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 | |
| 2919 | SAM_STAT_CHECK_CONDITION; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2920 | |
| 2921 | phba->bg_reftag_err_cnt++; |
| 2922 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 2923 | "9066 BLKGRD: LBA %lx ref_tag error %x != %x\n", |
| 2924 | (unsigned long)scsi_get_lba(cmd), |
| 2925 | ref_tag, start_ref_tag); |
| 2926 | |
| 2927 | } else if (err_type == BGS_APPTAG_ERR_MASK) { |
| 2928 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 2929 | 0x10, 0x2); |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 2930 | cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 | |
| 2931 | SAM_STAT_CHECK_CONDITION; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2932 | |
| 2933 | phba->bg_apptag_err_cnt++; |
| 2934 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 2935 | "9041 BLKGRD: LBA %lx app_tag error %x != %x\n", |
| 2936 | (unsigned long)scsi_get_lba(cmd), |
| 2937 | app_tag, start_app_tag); |
| 2938 | } |
| 2939 | } |
| 2940 | |
| 2941 | |
| 2942 | /* |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2943 | * This function checks for BlockGuard errors detected by |
| 2944 | * the HBA. In case of errors, the ASC/ASCQ fields in the |
| 2945 | * sense buffer will be set accordingly, paired with |
| 2946 | * ILLEGAL_REQUEST to signal to the kernel that the HBA |
| 2947 | * detected corruption. |
| 2948 | * |
| 2949 | * Returns: |
| 2950 | * 0 - No error found |
| 2951 | * 1 - BlockGuard error found |
| 2952 | * -1 - Internal error (bad profile, ...etc) |
| 2953 | */ |
| 2954 | static int |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 2955 | lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd, |
| 2956 | struct lpfc_iocbq *pIocbOut) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2957 | { |
| 2958 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 2959 | struct sli3_bg_fields *bgf = &pIocbOut->iocb.unsli3.sli3_bg; |
| 2960 | int ret = 0; |
| 2961 | uint32_t bghm = bgf->bghm; |
| 2962 | uint32_t bgstat = bgf->bgstat; |
| 2963 | uint64_t failing_sector = 0; |
| 2964 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2965 | spin_lock(&_dump_buf_lock); |
| 2966 | if (!_dump_buf_done) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2967 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9070 BLKGRD: Saving" |
| 2968 | " Data for %u blocks to debugfs\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2969 | (cmd->cmnd[7] << 8 | cmd->cmnd[8])); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2970 | lpfc_debug_save_data(phba, cmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2971 | |
| 2972 | /* If we have a prot sgl, save the DIF buffer */ |
| 2973 | if (lpfc_prot_group_type(phba, cmd) == |
| 2974 | LPFC_PG_TYPE_DIF_BUF) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2975 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9071 BLKGRD: " |
| 2976 | "Saving DIF for %u blocks to debugfs\n", |
| 2977 | (cmd->cmnd[7] << 8 | cmd->cmnd[8])); |
| 2978 | lpfc_debug_save_dif(phba, cmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2979 | } |
| 2980 | |
| 2981 | _dump_buf_done = 1; |
| 2982 | } |
| 2983 | spin_unlock(&_dump_buf_lock); |
| 2984 | |
| 2985 | if (lpfc_bgs_get_invalid_prof(bgstat)) { |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 2986 | cmd->result = DID_ERROR << 16; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2987 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 2988 | "9072 BLKGRD: Invalid BG Profile in cmd" |
| 2989 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 2990 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 2991 | (unsigned long long)scsi_get_lba(cmd), |
| 2992 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2993 | ret = (-1); |
| 2994 | goto out; |
| 2995 | } |
| 2996 | |
| 2997 | if (lpfc_bgs_get_uninit_dif_block(bgstat)) { |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 2998 | cmd->result = DID_ERROR << 16; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2999 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3000 | "9073 BLKGRD: Invalid BG PDIF Block in cmd" |
| 3001 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3002 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3003 | (unsigned long long)scsi_get_lba(cmd), |
| 3004 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3005 | ret = (-1); |
| 3006 | goto out; |
| 3007 | } |
| 3008 | |
| 3009 | if (lpfc_bgs_get_guard_err(bgstat)) { |
| 3010 | ret = 1; |
| 3011 | |
| 3012 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 3013 | 0x10, 0x1); |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 3014 | cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 | |
| 3015 | SAM_STAT_CHECK_CONDITION; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3016 | phba->bg_guard_err_cnt++; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3017 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3018 | "9055 BLKGRD: Guard Tag error in cmd" |
| 3019 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3020 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3021 | (unsigned long long)scsi_get_lba(cmd), |
| 3022 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3023 | } |
| 3024 | |
| 3025 | if (lpfc_bgs_get_reftag_err(bgstat)) { |
| 3026 | ret = 1; |
| 3027 | |
| 3028 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 3029 | 0x10, 0x3); |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 3030 | cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 | |
| 3031 | SAM_STAT_CHECK_CONDITION; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3032 | |
| 3033 | phba->bg_reftag_err_cnt++; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3034 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3035 | "9056 BLKGRD: Ref Tag error in cmd" |
| 3036 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3037 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3038 | (unsigned long long)scsi_get_lba(cmd), |
| 3039 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3040 | } |
| 3041 | |
| 3042 | if (lpfc_bgs_get_apptag_err(bgstat)) { |
| 3043 | ret = 1; |
| 3044 | |
| 3045 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 3046 | 0x10, 0x2); |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 3047 | cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 | |
| 3048 | SAM_STAT_CHECK_CONDITION; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3049 | |
| 3050 | phba->bg_apptag_err_cnt++; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3051 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3052 | "9061 BLKGRD: App Tag error in cmd" |
| 3053 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3054 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3055 | (unsigned long long)scsi_get_lba(cmd), |
| 3056 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3057 | } |
| 3058 | |
| 3059 | if (lpfc_bgs_get_hi_water_mark_present(bgstat)) { |
| 3060 | /* |
| 3061 | * setup sense data descriptor 0 per SPC-4 as an information |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 3062 | * field, and put the failing LBA in it. |
| 3063 | * This code assumes there was also a guard/app/ref tag error |
| 3064 | * indication. |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3065 | */ |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 3066 | cmd->sense_buffer[7] = 0xc; /* Additional sense length */ |
| 3067 | cmd->sense_buffer[8] = 0; /* Information descriptor type */ |
| 3068 | cmd->sense_buffer[9] = 0xa; /* Additional descriptor length */ |
| 3069 | cmd->sense_buffer[10] = 0x80; /* Validity bit */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3070 | |
| 3071 | /* bghm is a "on the wire" FC frame based count */ |
| 3072 | switch (scsi_get_prot_op(cmd)) { |
| 3073 | case SCSI_PROT_READ_INSERT: |
| 3074 | case SCSI_PROT_WRITE_STRIP: |
| 3075 | bghm /= cmd->device->sector_size; |
| 3076 | break; |
| 3077 | case SCSI_PROT_READ_STRIP: |
| 3078 | case SCSI_PROT_WRITE_INSERT: |
| 3079 | case SCSI_PROT_READ_PASS: |
| 3080 | case SCSI_PROT_WRITE_PASS: |
| 3081 | bghm /= (cmd->device->sector_size + |
| 3082 | sizeof(struct scsi_dif_tuple)); |
| 3083 | break; |
| 3084 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3085 | |
| 3086 | failing_sector = scsi_get_lba(cmd); |
| 3087 | failing_sector += bghm; |
| 3088 | |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 3089 | /* Descriptor Information */ |
| 3090 | put_unaligned_be64(failing_sector, &cmd->sense_buffer[12]); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3091 | } |
| 3092 | |
| 3093 | if (!ret) { |
| 3094 | /* No error was reported - problem in FW? */ |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3095 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3096 | "9057 BLKGRD: Unknown error in cmd" |
| 3097 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3098 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3099 | (unsigned long long)scsi_get_lba(cmd), |
| 3100 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3101 | |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3102 | /* Calcuate what type of error it was */ |
| 3103 | lpfc_calc_bg_err(phba, lpfc_cmd); |
| 3104 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3105 | out: |
| 3106 | return ret; |
| 3107 | } |
| 3108 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3109 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3110 | * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec |
| 3111 | * @phba: The Hba for which this call is being executed. |
| 3112 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3113 | * |
| 3114 | * This routine does the pci dma mapping for scatter-gather list of scsi cmnd |
| 3115 | * field of @lpfc_cmd for device with SLI-4 interface spec. |
| 3116 | * |
| 3117 | * Return codes: |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3118 | * 2 - Error - Do not retry |
| 3119 | * 1 - Error - Retry |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 3120 | * 0 - Success |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3121 | **/ |
| 3122 | static int |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3123 | lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3124 | { |
| 3125 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 3126 | struct scatterlist *sgel = NULL; |
| 3127 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3128 | struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3129 | struct sli4_sge *first_data_sgl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3130 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 3131 | dma_addr_t physaddr; |
| 3132 | uint32_t num_bde = 0; |
| 3133 | uint32_t dma_len; |
| 3134 | uint32_t dma_offset = 0; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3135 | int nseg, i, j; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3136 | struct ulp_bde64 *bde; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3137 | bool lsp_just_set = false; |
| 3138 | struct sli4_hybrid_sgl *sgl_xtra = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3139 | |
| 3140 | /* |
| 3141 | * There are three possibilities here - use scatter-gather segment, use |
| 3142 | * the single mapping, or neither. Start the lpfc command prep by |
| 3143 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 3144 | * data bde entry. |
| 3145 | */ |
| 3146 | if (scsi_sg_count(scsi_cmnd)) { |
| 3147 | /* |
| 3148 | * The driver stores the segment count returned from pci_map_sg |
| 3149 | * because this a count of dma-mappings used to map the use_sg |
| 3150 | * pages. They are not guaranteed to be the same for those |
| 3151 | * architectures that implement an IOMMU. |
| 3152 | */ |
| 3153 | |
| 3154 | nseg = scsi_dma_map(scsi_cmnd); |
James Smart | 5116fbf | 2015-05-22 10:42:39 -0400 | [diff] [blame] | 3155 | if (unlikely(nseg <= 0)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3156 | return 1; |
| 3157 | sgl += 1; |
| 3158 | /* clear the last flag in the fcp_rsp map entry */ |
| 3159 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 3160 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 3161 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 3162 | sgl += 1; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3163 | first_data_sgl = sgl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3164 | lpfc_cmd->seg_cnt = nseg; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3165 | if (!phba->cfg_xpsgl && |
| 3166 | lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3167 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9074 BLKGRD:" |
| 3168 | " %s: Too many sg segments from " |
| 3169 | "dma_map_sg. Config %d, seg_cnt %d\n", |
| 3170 | __func__, phba->cfg_sg_seg_cnt, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3171 | lpfc_cmd->seg_cnt); |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3172 | WARN_ON_ONCE(lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3173 | lpfc_cmd->seg_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3174 | scsi_dma_unmap(scsi_cmnd); |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3175 | return 2; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3176 | } |
| 3177 | |
| 3178 | /* |
| 3179 | * The driver established a maximum scatter-gather segment count |
| 3180 | * during probe that limits the number of sg elements in any |
| 3181 | * single scsi command. Just run through the seg_cnt and format |
| 3182 | * the sge's. |
| 3183 | * When using SLI-3 the driver will try to fit all the BDEs into |
| 3184 | * the IOCB. If it can't then the BDEs get added to a BPL as it |
| 3185 | * does for SLI-2 mode. |
| 3186 | */ |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3187 | |
| 3188 | /* for tracking segment boundaries */ |
| 3189 | sgel = scsi_sglist(scsi_cmnd); |
| 3190 | j = 2; |
| 3191 | for (i = 0; i < nseg; i++) { |
| 3192 | sgl->word2 = 0; |
| 3193 | if ((num_bde + 1) == nseg) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3194 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3195 | bf_set(lpfc_sli4_sge_type, sgl, |
| 3196 | LPFC_SGE_TYPE_DATA); |
| 3197 | } else { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3198 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3199 | |
| 3200 | /* do we need to expand the segment */ |
| 3201 | if (!lsp_just_set && |
| 3202 | !((j + 1) % phba->border_sge_num) && |
| 3203 | ((nseg - 1) != i)) { |
| 3204 | /* set LSP type */ |
| 3205 | bf_set(lpfc_sli4_sge_type, sgl, |
| 3206 | LPFC_SGE_TYPE_LSP); |
| 3207 | |
| 3208 | sgl_xtra = lpfc_get_sgl_per_hdwq( |
| 3209 | phba, lpfc_cmd); |
| 3210 | |
| 3211 | if (unlikely(!sgl_xtra)) { |
| 3212 | lpfc_cmd->seg_cnt = 0; |
| 3213 | scsi_dma_unmap(scsi_cmnd); |
| 3214 | return 1; |
| 3215 | } |
| 3216 | sgl->addr_lo = cpu_to_le32(putPaddrLow( |
| 3217 | sgl_xtra->dma_phys_sgl)); |
| 3218 | sgl->addr_hi = cpu_to_le32(putPaddrHigh( |
| 3219 | sgl_xtra->dma_phys_sgl)); |
| 3220 | |
| 3221 | } else { |
| 3222 | bf_set(lpfc_sli4_sge_type, sgl, |
| 3223 | LPFC_SGE_TYPE_DATA); |
| 3224 | } |
| 3225 | } |
| 3226 | |
| 3227 | if (!(bf_get(lpfc_sli4_sge_type, sgl) & |
| 3228 | LPFC_SGE_TYPE_LSP)) { |
| 3229 | if ((nseg - 1) == i) |
| 3230 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 3231 | |
| 3232 | physaddr = sg_dma_address(sgel); |
| 3233 | dma_len = sg_dma_len(sgel); |
| 3234 | sgl->addr_lo = cpu_to_le32(putPaddrLow( |
| 3235 | physaddr)); |
| 3236 | sgl->addr_hi = cpu_to_le32(putPaddrHigh( |
| 3237 | physaddr)); |
| 3238 | |
| 3239 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
| 3240 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 3241 | sgl->sge_len = cpu_to_le32(dma_len); |
| 3242 | |
| 3243 | dma_offset += dma_len; |
| 3244 | sgel = sg_next(sgel); |
| 3245 | |
| 3246 | sgl++; |
| 3247 | lsp_just_set = false; |
| 3248 | |
| 3249 | } else { |
| 3250 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 3251 | sgl->sge_len = cpu_to_le32( |
| 3252 | phba->cfg_sg_dma_buf_size); |
| 3253 | |
| 3254 | sgl = (struct sli4_sge *)sgl_xtra->dma_sgl; |
| 3255 | i = i - 1; |
| 3256 | |
| 3257 | lsp_just_set = true; |
| 3258 | } |
| 3259 | |
| 3260 | j++; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3261 | } |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 3262 | /* |
| 3263 | * Setup the first Payload BDE. For FCoE we just key off |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 3264 | * Performance Hints, for FC we use lpfc_enable_pbde. |
| 3265 | * We populate words 13-15 of IOCB/WQE. |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 3266 | */ |
| 3267 | if ((phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) || |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 3268 | phba->cfg_enable_pbde) { |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3269 | bde = (struct ulp_bde64 *) |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 3270 | &(iocb_cmd->unsli3.sli3Words[5]); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3271 | bde->addrLow = first_data_sgl->addr_lo; |
| 3272 | bde->addrHigh = first_data_sgl->addr_hi; |
| 3273 | bde->tus.f.bdeSize = |
| 3274 | le32_to_cpu(first_data_sgl->sge_len); |
| 3275 | bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 3276 | bde->tus.w = cpu_to_le32(bde->tus.w); |
| 3277 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3278 | } else { |
| 3279 | sgl += 1; |
| 3280 | /* clear the last flag in the fcp_rsp map entry */ |
| 3281 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 3282 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 3283 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 3284 | |
| 3285 | if ((phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) || |
| 3286 | phba->cfg_enable_pbde) { |
| 3287 | bde = (struct ulp_bde64 *) |
| 3288 | &(iocb_cmd->unsli3.sli3Words[5]); |
| 3289 | memset(bde, 0, (sizeof(uint32_t) * 3)); |
| 3290 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3291 | } |
| 3292 | |
| 3293 | /* |
| 3294 | * Finish initializing those IOCB fields that are dependent on the |
| 3295 | * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is |
| 3296 | * explicitly reinitialized. |
| 3297 | * all iocb memory resources are reused. |
| 3298 | */ |
| 3299 | fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); |
| 3300 | |
| 3301 | /* |
| 3302 | * Due to difference in data length between DIF/non-DIF paths, |
| 3303 | * we need to set word 4 of IOCB here |
| 3304 | */ |
| 3305 | iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 3306 | |
| 3307 | /* |
| 3308 | * If the OAS driver feature is enabled and the lun is enabled for |
| 3309 | * OAS, set the oas iocb related flags. |
| 3310 | */ |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 3311 | if ((phba->cfg_fof) && ((struct lpfc_device_data *) |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 3312 | scsi_cmnd->device->hostdata)->oas_enabled) { |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 3313 | lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 3314 | lpfc_cmd->cur_iocbq.priority = ((struct lpfc_device_data *) |
| 3315 | scsi_cmnd->device->hostdata)->priority; |
| 3316 | } |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3317 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3318 | return 0; |
| 3319 | } |
| 3320 | |
| 3321 | /** |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3322 | * lpfc_bg_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec |
| 3323 | * @phba: The Hba for which this call is being executed. |
| 3324 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3325 | * |
| 3326 | * This is the protection/DIF aware version of |
| 3327 | * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the |
| 3328 | * two functions eventually, but for now, it's here |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3329 | * Return codes: |
| 3330 | * 2 - Error - Do not retry |
| 3331 | * 1 - Error - Retry |
| 3332 | * 0 - Success |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3333 | **/ |
| 3334 | static int |
| 3335 | lpfc_bg_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3336 | struct lpfc_io_buf *lpfc_cmd) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3337 | { |
| 3338 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 3339 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3340 | struct sli4_sge *sgl = (struct sli4_sge *)(lpfc_cmd->dma_sgl); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3341 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3342 | uint32_t num_sge = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3343 | int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction; |
| 3344 | int prot_group_type = 0; |
| 3345 | int fcpdl; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3346 | int ret = 1; |
James Smart | 7c4042a | 2018-11-29 16:09:40 -0800 | [diff] [blame] | 3347 | struct lpfc_vport *vport = phba->pport; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3348 | |
| 3349 | /* |
| 3350 | * Start the lpfc command prep by bumping the sgl beyond fcp_cmnd |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3351 | * fcp_rsp regions to the first data sge entry |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3352 | */ |
| 3353 | if (scsi_sg_count(scsi_cmnd)) { |
| 3354 | /* |
| 3355 | * The driver stores the segment count returned from pci_map_sg |
| 3356 | * because this a count of dma-mappings used to map the use_sg |
| 3357 | * pages. They are not guaranteed to be the same for those |
| 3358 | * architectures that implement an IOMMU. |
| 3359 | */ |
| 3360 | datasegcnt = dma_map_sg(&phba->pcidev->dev, |
| 3361 | scsi_sglist(scsi_cmnd), |
| 3362 | scsi_sg_count(scsi_cmnd), datadir); |
| 3363 | if (unlikely(!datasegcnt)) |
| 3364 | return 1; |
| 3365 | |
| 3366 | sgl += 1; |
| 3367 | /* clear the last flag in the fcp_rsp map entry */ |
| 3368 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 3369 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 3370 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 3371 | |
| 3372 | sgl += 1; |
| 3373 | lpfc_cmd->seg_cnt = datasegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3374 | |
| 3375 | /* First check if data segment count from SCSI Layer is good */ |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3376 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt && |
| 3377 | !phba->cfg_xpsgl) { |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3378 | WARN_ON_ONCE(lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt); |
| 3379 | ret = 2; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3380 | goto err; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3381 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3382 | |
| 3383 | prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd); |
| 3384 | |
| 3385 | switch (prot_group_type) { |
| 3386 | case LPFC_PG_TYPE_NO_DIF: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3387 | /* Here we need to add a DISEED to the count */ |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3388 | if (((lpfc_cmd->seg_cnt + 1) > |
| 3389 | phba->cfg_total_seg_cnt) && |
| 3390 | !phba->cfg_xpsgl) { |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3391 | ret = 2; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3392 | goto err; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3393 | } |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3394 | |
| 3395 | num_sge = lpfc_bg_setup_sgl(phba, scsi_cmnd, sgl, |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3396 | datasegcnt, lpfc_cmd); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3397 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3398 | /* we should have 2 or more entries in buffer list */ |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3399 | if (num_sge < 2) { |
| 3400 | ret = 2; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3401 | goto err; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3402 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3403 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3404 | |
| 3405 | case LPFC_PG_TYPE_DIF_BUF: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3406 | /* |
| 3407 | * This type indicates that protection buffers are |
| 3408 | * passed to the driver, so that needs to be prepared |
| 3409 | * for DMA |
| 3410 | */ |
| 3411 | protsegcnt = dma_map_sg(&phba->pcidev->dev, |
| 3412 | scsi_prot_sglist(scsi_cmnd), |
| 3413 | scsi_prot_sg_count(scsi_cmnd), datadir); |
| 3414 | if (unlikely(!protsegcnt)) { |
| 3415 | scsi_dma_unmap(scsi_cmnd); |
| 3416 | return 1; |
| 3417 | } |
| 3418 | |
| 3419 | lpfc_cmd->prot_seg_cnt = protsegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3420 | /* |
| 3421 | * There is a minimun of 3 SGEs used for every |
| 3422 | * protection data segment. |
| 3423 | */ |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3424 | if (((lpfc_cmd->prot_seg_cnt * 3) > |
| 3425 | (phba->cfg_total_seg_cnt - 2)) && |
| 3426 | !phba->cfg_xpsgl) { |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3427 | ret = 2; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3428 | goto err; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3429 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3430 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3431 | num_sge = lpfc_bg_setup_sgl_prot(phba, scsi_cmnd, sgl, |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3432 | datasegcnt, protsegcnt, lpfc_cmd); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3433 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3434 | /* we should have 3 or more entries in buffer list */ |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3435 | if (num_sge < 3 || |
| 3436 | (num_sge > phba->cfg_total_seg_cnt && |
| 3437 | !phba->cfg_xpsgl)) { |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3438 | ret = 2; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3439 | goto err; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3440 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3441 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3442 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3443 | case LPFC_PG_TYPE_INVALID: |
| 3444 | default: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3445 | scsi_dma_unmap(scsi_cmnd); |
| 3446 | lpfc_cmd->seg_cnt = 0; |
| 3447 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3448 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 3449 | "9083 Unexpected protection group %i\n", |
| 3450 | prot_group_type); |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3451 | return 2; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3452 | } |
| 3453 | } |
| 3454 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 3455 | switch (scsi_get_prot_op(scsi_cmnd)) { |
| 3456 | case SCSI_PROT_WRITE_STRIP: |
| 3457 | case SCSI_PROT_READ_STRIP: |
| 3458 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_STRIP; |
| 3459 | break; |
| 3460 | case SCSI_PROT_WRITE_INSERT: |
| 3461 | case SCSI_PROT_READ_INSERT: |
| 3462 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_INSERT; |
| 3463 | break; |
| 3464 | case SCSI_PROT_WRITE_PASS: |
| 3465 | case SCSI_PROT_READ_PASS: |
| 3466 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_PASS; |
| 3467 | break; |
| 3468 | } |
| 3469 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3470 | fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3471 | fcp_cmnd->fcpDl = be32_to_cpu(fcpdl); |
| 3472 | |
| 3473 | /* |
| 3474 | * Due to difference in data length between DIF/non-DIF paths, |
| 3475 | * we need to set word 4 of IOCB here |
| 3476 | */ |
| 3477 | iocb_cmd->un.fcpi.fcpi_parm = fcpdl; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3478 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 3479 | /* |
James Smart | 7c4042a | 2018-11-29 16:09:40 -0800 | [diff] [blame] | 3480 | * For First burst, we may need to adjust the initial transfer |
| 3481 | * length for DIF |
| 3482 | */ |
| 3483 | if (iocb_cmd->un.fcpi.fcpi_XRdy && |
| 3484 | (fcpdl < vport->cfg_first_burst_size)) |
| 3485 | iocb_cmd->un.fcpi.fcpi_XRdy = fcpdl; |
| 3486 | |
| 3487 | /* |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 3488 | * If the OAS driver feature is enabled and the lun is enabled for |
| 3489 | * OAS, set the oas iocb related flags. |
| 3490 | */ |
| 3491 | if ((phba->cfg_fof) && ((struct lpfc_device_data *) |
| 3492 | scsi_cmnd->device->hostdata)->oas_enabled) |
| 3493 | lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF); |
| 3494 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3495 | return 0; |
| 3496 | err: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3497 | if (lpfc_cmd->seg_cnt) |
| 3498 | scsi_dma_unmap(scsi_cmnd); |
| 3499 | if (lpfc_cmd->prot_seg_cnt) |
| 3500 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd), |
| 3501 | scsi_prot_sg_count(scsi_cmnd), |
| 3502 | scsi_cmnd->sc_data_direction); |
| 3503 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3504 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3505 | "9084 Cannot setup S/G List for HBA" |
| 3506 | "IO segs %d/%d SGL %d SCSI %d: %d %d\n", |
| 3507 | lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt, |
| 3508 | phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt, |
| 3509 | prot_group_type, num_sge); |
| 3510 | |
| 3511 | lpfc_cmd->seg_cnt = 0; |
| 3512 | lpfc_cmd->prot_seg_cnt = 0; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3513 | return ret; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3514 | } |
| 3515 | |
| 3516 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3517 | * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer |
| 3518 | * @phba: The Hba for which this call is being executed. |
| 3519 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3520 | * |
| 3521 | * This routine wraps the actual DMA mapping function pointer from the |
| 3522 | * lpfc_hba struct. |
| 3523 | * |
| 3524 | * Return codes: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 3525 | * 1 - Error |
| 3526 | * 0 - Success |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3527 | **/ |
| 3528 | static inline int |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3529 | lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3530 | { |
| 3531 | return phba->lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 3532 | } |
| 3533 | |
| 3534 | /** |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3535 | * lpfc_bg_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer |
| 3536 | * using BlockGuard. |
| 3537 | * @phba: The Hba for which this call is being executed. |
| 3538 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3539 | * |
| 3540 | * This routine wraps the actual DMA mapping function pointer from the |
| 3541 | * lpfc_hba struct. |
| 3542 | * |
| 3543 | * Return codes: |
| 3544 | * 1 - Error |
| 3545 | * 0 - Success |
| 3546 | **/ |
| 3547 | static inline int |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3548 | lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3549 | { |
| 3550 | return phba->lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 3551 | } |
| 3552 | |
| 3553 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3554 | * 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] | 3555 | * @phba: Pointer to hba context object. |
| 3556 | * @vport: Pointer to vport object. |
| 3557 | * @lpfc_cmd: Pointer to lpfc scsi command which reported the error. |
| 3558 | * @rsp_iocb: Pointer to response iocb object which reported error. |
| 3559 | * |
| 3560 | * This function posts an event when there is a SCSI command reporting |
| 3561 | * error from the scsi device. |
| 3562 | **/ |
| 3563 | static void |
| 3564 | lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3565 | struct lpfc_io_buf *lpfc_cmd, struct lpfc_iocbq *rsp_iocb) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3566 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 3567 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
| 3568 | uint32_t resp_info = fcprsp->rspStatus2; |
| 3569 | uint32_t scsi_status = fcprsp->rspStatus3; |
| 3570 | uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; |
| 3571 | struct lpfc_fast_path_event *fast_path_evt = NULL; |
| 3572 | struct lpfc_nodelist *pnode = lpfc_cmd->rdata->pnode; |
| 3573 | unsigned long flags; |
| 3574 | |
James Smart | 5989b8d | 2010-10-22 11:06:56 -0400 | [diff] [blame] | 3575 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 3576 | return; |
| 3577 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3578 | /* If there is queuefull or busy condition send a scsi event */ |
| 3579 | if ((cmnd->result == SAM_STAT_TASK_SET_FULL) || |
| 3580 | (cmnd->result == SAM_STAT_BUSY)) { |
| 3581 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3582 | if (!fast_path_evt) |
| 3583 | return; |
| 3584 | fast_path_evt->un.scsi_evt.event_type = |
| 3585 | FC_REG_SCSI_EVENT; |
| 3586 | fast_path_evt->un.scsi_evt.subcategory = |
| 3587 | (cmnd->result == SAM_STAT_TASK_SET_FULL) ? |
| 3588 | LPFC_EVENT_QFULL : LPFC_EVENT_DEVBSY; |
| 3589 | fast_path_evt->un.scsi_evt.lun = cmnd->device->lun; |
| 3590 | memcpy(&fast_path_evt->un.scsi_evt.wwpn, |
| 3591 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3592 | memcpy(&fast_path_evt->un.scsi_evt.wwnn, |
| 3593 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3594 | } else if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen && |
| 3595 | ((cmnd->cmnd[0] == READ_10) || (cmnd->cmnd[0] == WRITE_10))) { |
| 3596 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3597 | if (!fast_path_evt) |
| 3598 | return; |
| 3599 | fast_path_evt->un.check_cond_evt.scsi_event.event_type = |
| 3600 | FC_REG_SCSI_EVENT; |
| 3601 | fast_path_evt->un.check_cond_evt.scsi_event.subcategory = |
| 3602 | LPFC_EVENT_CHECK_COND; |
| 3603 | fast_path_evt->un.check_cond_evt.scsi_event.lun = |
| 3604 | cmnd->device->lun; |
| 3605 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwpn, |
| 3606 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3607 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwnn, |
| 3608 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3609 | fast_path_evt->un.check_cond_evt.sense_key = |
| 3610 | cmnd->sense_buffer[2] & 0xf; |
| 3611 | fast_path_evt->un.check_cond_evt.asc = cmnd->sense_buffer[12]; |
| 3612 | fast_path_evt->un.check_cond_evt.ascq = cmnd->sense_buffer[13]; |
| 3613 | } else if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) && |
| 3614 | fcpi_parm && |
| 3615 | ((be32_to_cpu(fcprsp->rspResId) != fcpi_parm) || |
| 3616 | ((scsi_status == SAM_STAT_GOOD) && |
| 3617 | !(resp_info & (RESID_UNDER | RESID_OVER))))) { |
| 3618 | /* |
| 3619 | * If status is good or resid does not match with fcp_param and |
| 3620 | * there is valid fcpi_parm, then there is a read_check error |
| 3621 | */ |
| 3622 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3623 | if (!fast_path_evt) |
| 3624 | return; |
| 3625 | fast_path_evt->un.read_check_error.header.event_type = |
| 3626 | FC_REG_FABRIC_EVENT; |
| 3627 | fast_path_evt->un.read_check_error.header.subcategory = |
| 3628 | LPFC_EVENT_FCPRDCHKERR; |
| 3629 | memcpy(&fast_path_evt->un.read_check_error.header.wwpn, |
| 3630 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3631 | memcpy(&fast_path_evt->un.read_check_error.header.wwnn, |
| 3632 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3633 | fast_path_evt->un.read_check_error.lun = cmnd->device->lun; |
| 3634 | fast_path_evt->un.read_check_error.opcode = cmnd->cmnd[0]; |
| 3635 | fast_path_evt->un.read_check_error.fcpiparam = |
| 3636 | fcpi_parm; |
| 3637 | } else |
| 3638 | return; |
| 3639 | |
| 3640 | fast_path_evt->vport = vport; |
| 3641 | spin_lock_irqsave(&phba->hbalock, flags); |
| 3642 | list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list); |
| 3643 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 3644 | lpfc_worker_wake_up(phba); |
| 3645 | return; |
| 3646 | } |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3647 | |
| 3648 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3649 | * 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] | 3650 | * @phba: The HBA for which this call is being executed. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3651 | * @psb: The scsi buffer which is going to be un-mapped. |
| 3652 | * |
| 3653 | * 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] | 3654 | * field of @lpfc_cmd for device with SLI-3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3655 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3656 | static void |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3657 | lpfc_scsi_unprep_dma_buf(struct lpfc_hba *phba, struct lpfc_io_buf *psb) |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 3658 | { |
| 3659 | /* |
| 3660 | * There are only two special cases to consider. (1) the scsi command |
| 3661 | * requested scatter-gather usage or (2) the scsi command allocated |
| 3662 | * a request buffer, but did not request use_sg. There is a third |
| 3663 | * case, but it does not require resource deallocation. |
| 3664 | */ |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3665 | if (psb->seg_cnt > 0) |
| 3666 | scsi_dma_unmap(psb->pCmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3667 | if (psb->prot_seg_cnt > 0) |
| 3668 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(psb->pCmd), |
| 3669 | scsi_prot_sg_count(psb->pCmd), |
| 3670 | psb->pCmd->sc_data_direction); |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 3671 | } |
| 3672 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3673 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3674 | * lpfc_handler_fcp_err - FCP response handler |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3675 | * @vport: The virtual port for which this call is being executed. |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3676 | * @lpfc_cmd: Pointer to lpfc_io_buf data structure. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3677 | * @rsp_iocb: The response IOCB which contains FCP error. |
| 3678 | * |
| 3679 | * This routine is called to process response IOCB with status field |
| 3680 | * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command |
| 3681 | * based upon SCSI and FCP error. |
| 3682 | **/ |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 3683 | static void |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3684 | lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_io_buf *lpfc_cmd, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3685 | struct lpfc_iocbq *rsp_iocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3686 | { |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3687 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3688 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 3689 | struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd; |
| 3690 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3691 | uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3692 | uint32_t resp_info = fcprsp->rspStatus2; |
| 3693 | uint32_t scsi_status = fcprsp->rspStatus3; |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3694 | uint32_t *lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3695 | uint32_t host_status = DID_OK; |
| 3696 | uint32_t rsplen = 0; |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3697 | uint32_t fcpDl; |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3698 | uint32_t logit = LOG_FCP | LOG_FCP_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3699 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3700 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3701 | /* |
| 3702 | * If this is a task management command, there is no |
| 3703 | * scsi packet associated with this lpfc_cmd. The driver |
| 3704 | * consumes it. |
| 3705 | */ |
| 3706 | if (fcpcmd->fcpCntl2) { |
| 3707 | scsi_status = 0; |
| 3708 | goto out; |
| 3709 | } |
| 3710 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3711 | if (resp_info & RSP_LEN_VALID) { |
| 3712 | rsplen = be32_to_cpu(fcprsp->rspRspLen); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3713 | if (rsplen != 0 && rsplen != 4 && rsplen != 8) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3714 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 3715 | "2719 Invalid response length: " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 3716 | "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] | 3717 | cmnd->device->id, |
| 3718 | cmnd->device->lun, cmnd->cmnd[0], |
| 3719 | rsplen); |
| 3720 | host_status = DID_ERROR; |
| 3721 | goto out; |
| 3722 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3723 | if (fcprsp->rspInfo3 != RSP_NO_FAILURE) { |
| 3724 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 3725 | "2757 Protocol failure detected during " |
| 3726 | "processing of FCP I/O op: " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 3727 | "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] | 3728 | cmnd->device->id, |
| 3729 | cmnd->device->lun, cmnd->cmnd[0], |
| 3730 | fcprsp->rspInfo3); |
| 3731 | host_status = DID_ERROR; |
| 3732 | goto out; |
| 3733 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3734 | } |
| 3735 | |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3736 | if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) { |
| 3737 | uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen); |
| 3738 | if (snslen > SCSI_SENSE_BUFFERSIZE) |
| 3739 | snslen = SCSI_SENSE_BUFFERSIZE; |
| 3740 | |
| 3741 | if (resp_info & RSP_LEN_VALID) |
| 3742 | rsplen = be32_to_cpu(fcprsp->rspRspLen); |
| 3743 | memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen); |
| 3744 | } |
| 3745 | lp = (uint32_t *)cmnd->sense_buffer; |
| 3746 | |
James Smart | aa1c7ee | 2012-08-14 14:26:06 -0400 | [diff] [blame] | 3747 | /* special handling for under run conditions */ |
| 3748 | if (!scsi_status && (resp_info & RESID_UNDER)) { |
| 3749 | /* don't log under runs if fcp set... */ |
| 3750 | if (vport->cfg_log_verbose & LOG_FCP) |
| 3751 | logit = LOG_FCP_ERROR; |
| 3752 | /* unless operator says so */ |
| 3753 | if (vport->cfg_log_verbose & LOG_FCP_UNDER) |
| 3754 | logit = LOG_FCP_UNDER; |
| 3755 | } |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3756 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3757 | lpfc_printf_vlog(vport, KERN_WARNING, logit, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3758 | "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] | 3759 | "Data: x%x x%x x%x x%x x%x\n", |
| 3760 | cmnd->cmnd[0], scsi_status, |
| 3761 | be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info, |
| 3762 | be32_to_cpu(fcprsp->rspResId), |
| 3763 | be32_to_cpu(fcprsp->rspSnsLen), |
| 3764 | be32_to_cpu(fcprsp->rspRspLen), |
| 3765 | fcprsp->rspInfo3); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3766 | |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3767 | scsi_set_resid(cmnd, 0); |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3768 | fcpDl = be32_to_cpu(fcpcmd->fcpDl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3769 | if (resp_info & RESID_UNDER) { |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3770 | scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3771 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3772 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_UNDER, |
James Smart | 45634a86 | 2018-01-30 15:59:00 -0800 | [diff] [blame] | 3773 | "9025 FCP Underrun, expected %d, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3774 | "residual %d Data: x%x x%x x%x\n", |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3775 | fcpDl, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3776 | scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0], |
| 3777 | cmnd->underflow); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3778 | |
| 3779 | /* |
James Smart | 45634a86 | 2018-01-30 15:59:00 -0800 | [diff] [blame] | 3780 | * If there is an under run, check if under run reported by |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3781 | * storage array is same as the under run reported by HBA. |
| 3782 | * If this is not same, there is a dropped frame. |
| 3783 | */ |
James Smart | 45634a86 | 2018-01-30 15:59:00 -0800 | [diff] [blame] | 3784 | if (fcpi_parm && (scsi_get_resid(cmnd) != fcpi_parm)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3785 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 3786 | LOG_FCP | LOG_FCP_ERROR, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3787 | "9026 FCP Read Check Error " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3788 | "and Underrun Data: x%x x%x x%x x%x\n", |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3789 | fcpDl, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3790 | scsi_get_resid(cmnd), fcpi_parm, |
| 3791 | cmnd->cmnd[0]); |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3792 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3793 | host_status = DID_ERROR; |
| 3794 | } |
| 3795 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3796 | * The cmnd->underflow is the minimum number of bytes that must |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3797 | * be transferred for this command. Provided a sense condition |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3798 | * is not present, make sure the actual amount transferred is at |
| 3799 | * least the underflow value or fail. |
| 3800 | */ |
| 3801 | if (!(resp_info & SNS_LEN_VALID) && |
| 3802 | (scsi_status == SAM_STAT_GOOD) && |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3803 | (scsi_bufflen(cmnd) - scsi_get_resid(cmnd) |
| 3804 | < cmnd->underflow)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3805 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3806 | "9027 FCP command x%x residual " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3807 | "underrun converted to error " |
| 3808 | "Data: x%x x%x x%x\n", |
James Smart | 66dbfbe | 2007-08-05 06:08:38 -0400 | [diff] [blame] | 3809 | cmnd->cmnd[0], scsi_bufflen(cmnd), |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3810 | scsi_get_resid(cmnd), cmnd->underflow); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3811 | host_status = DID_ERROR; |
| 3812 | } |
| 3813 | } else if (resp_info & RESID_OVER) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3814 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3815 | "9028 FCP command x%x residual overrun error. " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 3816 | "Data: x%x x%x\n", cmnd->cmnd[0], |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3817 | scsi_bufflen(cmnd), scsi_get_resid(cmnd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3818 | host_status = DID_ERROR; |
| 3819 | |
| 3820 | /* |
| 3821 | * Check SLI validation that all the transfer was actually done |
James Smart | 26373d2 | 2013-09-06 12:19:17 -0400 | [diff] [blame] | 3822 | * (fcpi_parm should be zero). Apply check only to reads. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3823 | */ |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3824 | } else if (fcpi_parm) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3825 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR, |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3826 | "9029 FCP %s Check Error xri x%x Data: " |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 3827 | "x%x x%x x%x x%x x%x\n", |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3828 | ((cmnd->sc_data_direction == DMA_FROM_DEVICE) ? |
| 3829 | "Read" : "Write"), |
| 3830 | ((phba->sli_rev == LPFC_SLI_REV4) ? |
| 3831 | lpfc_cmd->cur_iocbq.sli4_xritag : |
| 3832 | rsp_iocb->iocb.ulpContext), |
| 3833 | fcpDl, be32_to_cpu(fcprsp->rspResId), |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 3834 | fcpi_parm, cmnd->cmnd[0], scsi_status); |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3835 | |
| 3836 | /* There is some issue with the LPe12000 that causes it |
| 3837 | * to miscalculate the fcpi_parm and falsely trip this |
| 3838 | * recovery logic. Detect this case and don't error when true. |
| 3839 | */ |
| 3840 | if (fcpi_parm > fcpDl) |
| 3841 | goto out; |
| 3842 | |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 3843 | switch (scsi_status) { |
| 3844 | case SAM_STAT_GOOD: |
| 3845 | case SAM_STAT_CHECK_CONDITION: |
| 3846 | /* Fabric dropped a data frame. Fail any successful |
| 3847 | * command in which we detected dropped frames. |
| 3848 | * A status of good or some check conditions could |
| 3849 | * be considered a successful command. |
| 3850 | */ |
| 3851 | host_status = DID_ERROR; |
| 3852 | break; |
| 3853 | } |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3854 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3855 | } |
| 3856 | |
| 3857 | out: |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 3858 | cmnd->result = host_status << 16 | scsi_status; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3859 | lpfc_send_scsi_error_event(vport->phba, vport, lpfc_cmd, rsp_iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3860 | } |
| 3861 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3862 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3863 | * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3864 | * @phba: The Hba for which this call is being executed. |
| 3865 | * @pIocbIn: The command IOCBQ for the scsi cmnd. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3866 | * @pIocbOut: The response IOCBQ for the scsi cmnd. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3867 | * |
| 3868 | * This routine assigns scsi command result by looking into response IOCB |
| 3869 | * status field appropriately. This routine handles QUEUE FULL condition as |
| 3870 | * well by ramping down device queue depth. |
| 3871 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3872 | static void |
| 3873 | lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn, |
| 3874 | struct lpfc_iocbq *pIocbOut) |
| 3875 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3876 | struct lpfc_io_buf *lpfc_cmd = |
| 3877 | (struct lpfc_io_buf *) pIocbIn->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3878 | struct lpfc_vport *vport = pIocbIn->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3879 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| 3880 | struct lpfc_nodelist *pnode = rdata->pnode; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3881 | struct scsi_cmnd *cmd; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 3882 | unsigned long flags; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3883 | struct lpfc_fast_path_event *fast_path_evt; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3884 | struct Scsi_Host *shost; |
James Smart | 4c47efc | 2019-01-28 11:14:25 -0800 | [diff] [blame] | 3885 | int idx; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3886 | uint32_t logit = LOG_FCP; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 3887 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 3888 | int cpu; |
| 3889 | #endif |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3890 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 3891 | /* Guard against abort handler being called at same time */ |
| 3892 | spin_lock(&lpfc_cmd->buf_lock); |
| 3893 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3894 | /* Sanity check on return of outstanding command */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3895 | cmd = lpfc_cmd->pCmd; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 3896 | if (!cmd) { |
| 3897 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 3898 | "2621 IO completion: Not an active IO\n"); |
| 3899 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | c90261d | 2015-12-16 18:11:57 -0500 | [diff] [blame] | 3900 | return; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 3901 | } |
James Smart | 4c47efc | 2019-01-28 11:14:25 -0800 | [diff] [blame] | 3902 | |
| 3903 | idx = lpfc_cmd->cur_iocbq.hba_wqidx; |
| 3904 | if (phba->sli4_hba.hdwq) |
| 3905 | phba->sli4_hba.hdwq[idx].scsi_cstat.io_cmpls++; |
| 3906 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 3907 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 3908 | if (phba->cpucheck_on & LPFC_CHECK_SCSI_IO) { |
Bart Van Assche | d6d189c | 2019-03-28 11:06:22 -0700 | [diff] [blame] | 3909 | cpu = raw_smp_processor_id(); |
James Smart | ff6bf89 | 2019-03-12 16:30:04 -0700 | [diff] [blame] | 3910 | if (cpu < LPFC_CHECK_CPU_CNT && phba->sli4_hba.hdwq) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 3911 | phba->sli4_hba.hdwq[idx].cpucheck_cmpl_io[cpu]++; |
| 3912 | } |
| 3913 | #endif |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3914 | shost = cmd->device->host; |
| 3915 | |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3916 | lpfc_cmd->result = (pIocbOut->iocb.un.ulpWord[4] & IOERR_PARAM_MASK); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3917 | lpfc_cmd->status = pIocbOut->iocb.ulpStatus; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3918 | /* pick up SLI4 exhange busy status from HBA */ |
| 3919 | lpfc_cmd->exch_busy = pIocbOut->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 3920 | |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 3921 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 3922 | if (lpfc_cmd->prot_data_type) { |
| 3923 | struct scsi_dif_tuple *src = NULL; |
| 3924 | |
| 3925 | src = (struct scsi_dif_tuple *)lpfc_cmd->prot_data_segment; |
| 3926 | /* |
| 3927 | * Used to restore any changes to protection |
| 3928 | * data for error injection. |
| 3929 | */ |
| 3930 | switch (lpfc_cmd->prot_data_type) { |
| 3931 | case LPFC_INJERR_REFTAG: |
| 3932 | src->ref_tag = |
| 3933 | lpfc_cmd->prot_data; |
| 3934 | break; |
| 3935 | case LPFC_INJERR_APPTAG: |
| 3936 | src->app_tag = |
| 3937 | (uint16_t)lpfc_cmd->prot_data; |
| 3938 | break; |
| 3939 | case LPFC_INJERR_GUARD: |
| 3940 | src->guard_tag = |
| 3941 | (uint16_t)lpfc_cmd->prot_data; |
| 3942 | break; |
| 3943 | default: |
| 3944 | break; |
| 3945 | } |
| 3946 | |
| 3947 | lpfc_cmd->prot_data = 0; |
| 3948 | lpfc_cmd->prot_data_type = 0; |
| 3949 | lpfc_cmd->prot_data_segment = NULL; |
| 3950 | } |
| 3951 | #endif |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 3952 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3953 | if (lpfc_cmd->status) { |
| 3954 | if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT && |
| 3955 | (lpfc_cmd->result & IOERR_DRVR_MASK)) |
| 3956 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; |
| 3957 | else if (lpfc_cmd->status >= IOSTAT_CNT) |
| 3958 | lpfc_cmd->status = IOSTAT_DEFAULT; |
James Smart | aa1c7ee | 2012-08-14 14:26:06 -0400 | [diff] [blame] | 3959 | if (lpfc_cmd->status == IOSTAT_FCP_RSP_ERROR && |
| 3960 | !lpfc_cmd->fcp_rsp->rspStatus3 && |
| 3961 | (lpfc_cmd->fcp_rsp->rspStatus2 & RESID_UNDER) && |
| 3962 | !(vport->cfg_log_verbose & LOG_FCP_UNDER)) |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3963 | logit = 0; |
| 3964 | else |
| 3965 | logit = LOG_FCP | LOG_FCP_UNDER; |
| 3966 | lpfc_printf_vlog(vport, KERN_WARNING, logit, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 3967 | "9030 FCP cmd x%x failed <%d/%lld> " |
James Smart | 5a0d80f | 2012-05-09 21:18:20 -0400 | [diff] [blame] | 3968 | "status: x%x result: x%x " |
| 3969 | "sid: x%x did: x%x oxid: x%x " |
| 3970 | "Data: x%x x%x\n", |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3971 | cmd->cmnd[0], |
| 3972 | cmd->device ? cmd->device->id : 0xffff, |
| 3973 | cmd->device ? cmd->device->lun : 0xffff, |
| 3974 | lpfc_cmd->status, lpfc_cmd->result, |
James Smart | 3bf41ba | 2013-05-31 17:03:18 -0400 | [diff] [blame] | 3975 | vport->fc_myDID, |
| 3976 | (pnode) ? pnode->nlp_DID : 0, |
James Smart | 5a0d80f | 2012-05-09 21:18:20 -0400 | [diff] [blame] | 3977 | phba->sli_rev == LPFC_SLI_REV4 ? |
| 3978 | lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3979 | pIocbOut->iocb.ulpContext, |
| 3980 | lpfc_cmd->cur_iocbq.iocb.ulpIoTag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3981 | |
| 3982 | switch (lpfc_cmd->status) { |
| 3983 | case IOSTAT_FCP_RSP_ERROR: |
| 3984 | /* Call FCP RSP handler to determine result */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3985 | lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3986 | break; |
| 3987 | case IOSTAT_NPORT_BSY: |
| 3988 | case IOSTAT_FABRIC_BSY: |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 3989 | cmd->result = DID_TRANSPORT_DISRUPTED << 16; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3990 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3991 | if (!fast_path_evt) |
| 3992 | break; |
| 3993 | fast_path_evt->un.fabric_evt.event_type = |
| 3994 | FC_REG_FABRIC_EVENT; |
| 3995 | fast_path_evt->un.fabric_evt.subcategory = |
| 3996 | (lpfc_cmd->status == IOSTAT_NPORT_BSY) ? |
| 3997 | LPFC_EVENT_PORT_BUSY : LPFC_EVENT_FABRIC_BUSY; |
| 3998 | if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
| 3999 | memcpy(&fast_path_evt->un.fabric_evt.wwpn, |
| 4000 | &pnode->nlp_portname, |
| 4001 | sizeof(struct lpfc_name)); |
| 4002 | memcpy(&fast_path_evt->un.fabric_evt.wwnn, |
| 4003 | &pnode->nlp_nodename, |
| 4004 | sizeof(struct lpfc_name)); |
| 4005 | } |
| 4006 | fast_path_evt->vport = vport; |
| 4007 | fast_path_evt->work_evt.evt = |
| 4008 | LPFC_EVT_FASTPATH_MGMT_EVT; |
| 4009 | spin_lock_irqsave(&phba->hbalock, flags); |
| 4010 | list_add_tail(&fast_path_evt->work_evt.evt_listp, |
| 4011 | &phba->work_list); |
| 4012 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4013 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4014 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4015 | case IOSTAT_LOCAL_REJECT: |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4016 | case IOSTAT_REMOTE_STOP: |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 4017 | if (lpfc_cmd->result == IOERR_ELXSEC_KEY_UNWRAP_ERROR || |
| 4018 | lpfc_cmd->result == |
| 4019 | IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR || |
| 4020 | lpfc_cmd->result == IOERR_ELXSEC_CRYPTO_ERROR || |
| 4021 | lpfc_cmd->result == |
| 4022 | IOERR_ELXSEC_CRYPTO_COMPARE_ERROR) { |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 4023 | cmd->result = DID_NO_CONNECT << 16; |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 4024 | break; |
| 4025 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4026 | if (lpfc_cmd->result == IOERR_INVALID_RPI || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4027 | lpfc_cmd->result == IOERR_NO_RESOURCES || |
James Smart | b92938b | 2010-06-07 15:24:12 -0400 | [diff] [blame] | 4028 | lpfc_cmd->result == IOERR_ABORT_REQUESTED || |
| 4029 | lpfc_cmd->result == IOERR_SLER_CMD_RCV_FAILURE) { |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 4030 | cmd->result = DID_REQUEUE << 16; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4031 | break; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4032 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4033 | if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED || |
| 4034 | lpfc_cmd->result == IOERR_TX_DMA_FAILED) && |
| 4035 | pIocbOut->iocb.unsli3.sli3_bg.bgstat) { |
| 4036 | if (scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) { |
| 4037 | /* |
| 4038 | * This is a response for a BG enabled |
| 4039 | * cmd. Parse BG error |
| 4040 | */ |
| 4041 | lpfc_parse_bg_err(phba, lpfc_cmd, |
| 4042 | pIocbOut); |
| 4043 | break; |
| 4044 | } else { |
| 4045 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 4046 | LOG_BG, |
| 4047 | "9031 non-zero BGSTAT " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4048 | "on unprotected cmd\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4049 | } |
| 4050 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4051 | if ((lpfc_cmd->status == IOSTAT_REMOTE_STOP) |
| 4052 | && (phba->sli_rev == LPFC_SLI_REV4) |
| 4053 | && (pnode && NLP_CHK_NODE_ACT(pnode))) { |
| 4054 | /* This IO was aborted by the target, we don't |
| 4055 | * know the rxid and because we did not send the |
| 4056 | * ABTS we cannot generate and RRQ. |
| 4057 | */ |
| 4058 | lpfc_set_rrq_active(phba, pnode, |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 4059 | lpfc_cmd->cur_iocbq.sli4_lxritag, |
| 4060 | 0, 0); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4061 | } |
Bart Van Assche | cd05c15 | 2019-03-28 11:06:18 -0700 | [diff] [blame] | 4062 | /* fall through */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4063 | default: |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 4064 | cmd->result = DID_ERROR << 16; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4065 | break; |
| 4066 | } |
| 4067 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4068 | if (!pnode || !NLP_CHK_NODE_ACT(pnode) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4069 | || (pnode->nlp_state != NLP_STE_MAPPED_NODE)) |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 4070 | cmd->result = DID_TRANSPORT_DISRUPTED << 16 | |
| 4071 | SAM_STAT_BUSY; |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 4072 | } else |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 4073 | cmd->result = DID_OK << 16; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4074 | |
| 4075 | if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) { |
| 4076 | uint32_t *lp = (uint32_t *)cmd->sense_buffer; |
| 4077 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4078 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 4079 | "0710 Iodone <%d/%llu> cmd x%px, error " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4080 | "x%x SNS x%x x%x Data: x%x x%x\n", |
| 4081 | cmd->device->id, cmd->device->lun, cmd, |
| 4082 | cmd->result, *lp, *(lp + 3), cmd->retries, |
| 4083 | scsi_get_resid(cmd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4084 | } |
| 4085 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4086 | lpfc_update_stats(phba, lpfc_cmd); |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4087 | if (vport->cfg_max_scsicmpl_time && |
| 4088 | time_after(jiffies, lpfc_cmd->start_time + |
| 4089 | msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4090 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4091 | if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
| 4092 | if (pnode->cmd_qdepth > |
| 4093 | atomic_read(&pnode->cmd_pending) && |
| 4094 | (atomic_read(&pnode->cmd_pending) > |
| 4095 | LPFC_MIN_TGT_QDEPTH) && |
| 4096 | ((cmd->cmnd[0] == READ_10) || |
| 4097 | (cmd->cmnd[0] == WRITE_10))) |
| 4098 | pnode->cmd_qdepth = |
| 4099 | atomic_read(&pnode->cmd_pending); |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4100 | |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4101 | pnode->last_change_time = jiffies; |
| 4102 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4103 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4104 | } |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4105 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4106 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4107 | lpfc_cmd->pCmd = NULL; |
| 4108 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 92e3af6 | 2012-08-14 14:26:28 -0400 | [diff] [blame] | 4109 | |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 4110 | /* The sdev is not guaranteed to be valid post scsi_done upcall. */ |
| 4111 | cmd->scsi_done(cmd); |
| 4112 | |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4113 | /* |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4114 | * If there is an abort thread waiting for command completion |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4115 | * wake up the thread. |
| 4116 | */ |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4117 | spin_lock(&lpfc_cmd->buf_lock); |
James Smart | 4eb0153 | 2019-04-03 11:10:34 -0700 | [diff] [blame] | 4118 | lpfc_cmd->cur_iocbq.iocb_flag &= ~LPFC_DRIVER_ABORTED; |
James Smart | b9e5a2d | 2019-05-21 17:49:01 -0700 | [diff] [blame] | 4119 | if (lpfc_cmd->waitq) |
James Smart | 4eb0153 | 2019-04-03 11:10:34 -0700 | [diff] [blame] | 4120 | wake_up(lpfc_cmd->waitq); |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4121 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4122 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4123 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4124 | } |
| 4125 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4126 | /** |
Alexey Kardashevskiy | 8b2564e | 2015-04-28 18:26:22 +1000 | [diff] [blame] | 4127 | * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB |
| 4128 | * @data: A pointer to the immediate command data portion of the IOCB. |
| 4129 | * @fcp_cmnd: The FCP Command that is provided by the SCSI layer. |
| 4130 | * |
| 4131 | * The routine copies the entire FCP command from @fcp_cmnd to @data while |
| 4132 | * byte swapping the data to big endian format for transmission on the wire. |
| 4133 | **/ |
| 4134 | static void |
| 4135 | lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd) |
| 4136 | { |
| 4137 | int i, j; |
| 4138 | for (i = 0, j = 0; i < sizeof(struct fcp_cmnd); |
| 4139 | i += sizeof(uint32_t), j++) { |
| 4140 | ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]); |
| 4141 | } |
| 4142 | } |
| 4143 | |
| 4144 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4145 | * 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] | 4146 | * @vport: The virtual port for which this call is being executed. |
| 4147 | * @lpfc_cmd: The scsi command which needs to send. |
| 4148 | * @pnode: Pointer to lpfc_nodelist. |
| 4149 | * |
| 4150 | * This routine initializes fcp_cmnd and iocb data structure from scsi command |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4151 | * to transfer for device with SLI3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4152 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4153 | static void |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4154 | lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_io_buf *lpfc_cmd, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4155 | struct lpfc_nodelist *pnode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4156 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4157 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4158 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 4159 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 4160 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 4161 | struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq); |
James Smart | 4c47efc | 2019-01-28 11:14:25 -0800 | [diff] [blame] | 4162 | struct lpfc_sli4_hdw_queue *hdwq = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4163 | int datadir = scsi_cmnd->sc_data_direction; |
James Smart | 4c47efc | 2019-01-28 11:14:25 -0800 | [diff] [blame] | 4164 | int idx; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4165 | uint8_t *ptr; |
| 4166 | bool sli4; |
James Smart | 98bbf5f | 2013-09-06 12:18:45 -0400 | [diff] [blame] | 4167 | uint32_t fcpdl; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4168 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4169 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 4170 | return; |
| 4171 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4172 | lpfc_cmd->fcp_rsp->rspSnsLen = 0; |
James.Smart@Emulex.Com | 69859dc | 2005-08-10 15:02:37 -0400 | [diff] [blame] | 4173 | /* clear task management bits */ |
| 4174 | lpfc_cmd->fcp_cmnd->fcpCntl2 = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4175 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 4176 | int_to_scsilun(lpfc_cmd->pCmd->device->lun, |
| 4177 | &lpfc_cmd->fcp_cmnd->fcp_lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4178 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4179 | ptr = &fcp_cmnd->fcpCdb[0]; |
| 4180 | memcpy(ptr, scsi_cmnd->cmnd, scsi_cmnd->cmd_len); |
| 4181 | if (scsi_cmnd->cmd_len < LPFC_FCP_CDB_LEN) { |
| 4182 | ptr += scsi_cmnd->cmd_len; |
| 4183 | memset(ptr, 0, (LPFC_FCP_CDB_LEN - scsi_cmnd->cmd_len)); |
| 4184 | } |
| 4185 | |
Christoph Hellwig | 5066863 | 2014-10-30 14:30:06 +0100 | [diff] [blame] | 4186 | fcp_cmnd->fcpCntl1 = SIMPLE_Q; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4187 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4188 | sli4 = (phba->sli_rev == LPFC_SLI_REV4); |
James Smart | 6acb348 | 2014-04-04 13:51:25 -0400 | [diff] [blame] | 4189 | piocbq->iocb.un.fcpi.fcpi_XRdy = 0; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 4190 | idx = lpfc_cmd->hdwq_no; |
James Smart | 4c47efc | 2019-01-28 11:14:25 -0800 | [diff] [blame] | 4191 | if (phba->sli4_hba.hdwq) |
| 4192 | hdwq = &phba->sli4_hba.hdwq[idx]; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4193 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4194 | /* |
| 4195 | * There are three possibilities here - use scatter-gather segment, use |
| 4196 | * the single mapping, or neither. Start the lpfc command prep by |
| 4197 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 4198 | * data bde entry. |
| 4199 | */ |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4200 | if (scsi_sg_count(scsi_cmnd)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4201 | if (datadir == DMA_TO_DEVICE) { |
| 4202 | iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR; |
James Smart | 182ba75 | 2013-07-15 18:34:05 -0400 | [diff] [blame] | 4203 | iocb_cmd->ulpPU = PARM_READ_CHECK; |
James Smart | 3cb01c5 | 2013-07-15 18:35:04 -0400 | [diff] [blame] | 4204 | if (vport->cfg_first_burst_size && |
| 4205 | (pnode->nlp_flag & NLP_FIRSTBURST)) { |
James Smart | 98bbf5f | 2013-09-06 12:18:45 -0400 | [diff] [blame] | 4206 | fcpdl = scsi_bufflen(scsi_cmnd); |
| 4207 | if (fcpdl < vport->cfg_first_burst_size) |
| 4208 | piocbq->iocb.un.fcpi.fcpi_XRdy = fcpdl; |
| 4209 | else |
| 4210 | piocbq->iocb.un.fcpi.fcpi_XRdy = |
| 4211 | vport->cfg_first_burst_size; |
James Smart | 3cb01c5 | 2013-07-15 18:35:04 -0400 | [diff] [blame] | 4212 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4213 | fcp_cmnd->fcpCntl3 = WRITE_DATA; |
James Smart | 4c47efc | 2019-01-28 11:14:25 -0800 | [diff] [blame] | 4214 | if (hdwq) |
| 4215 | hdwq->scsi_cstat.output_requests++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4216 | } else { |
| 4217 | iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR; |
| 4218 | iocb_cmd->ulpPU = PARM_READ_CHECK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4219 | fcp_cmnd->fcpCntl3 = READ_DATA; |
James Smart | 4c47efc | 2019-01-28 11:14:25 -0800 | [diff] [blame] | 4220 | if (hdwq) |
| 4221 | hdwq->scsi_cstat.input_requests++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4222 | } |
| 4223 | } else { |
| 4224 | iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR; |
| 4225 | iocb_cmd->un.fcpi.fcpi_parm = 0; |
| 4226 | iocb_cmd->ulpPU = 0; |
| 4227 | fcp_cmnd->fcpCntl3 = 0; |
James Smart | 4c47efc | 2019-01-28 11:14:25 -0800 | [diff] [blame] | 4228 | if (hdwq) |
| 4229 | hdwq->scsi_cstat.control_requests++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4230 | } |
Alexey Kardashevskiy | 8b2564e | 2015-04-28 18:26:22 +1000 | [diff] [blame] | 4231 | if (phba->sli_rev == 3 && |
| 4232 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) |
| 4233 | lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4234 | /* |
| 4235 | * Finish initializing those IOCB fields that are independent |
| 4236 | * of the scsi_cmnd request_buffer |
| 4237 | */ |
| 4238 | piocbq->iocb.ulpContext = pnode->nlp_rpi; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4239 | if (sli4) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4240 | piocbq->iocb.ulpContext = |
| 4241 | phba->sli4_hba.rpi_ids[pnode->nlp_rpi]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4242 | if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE) |
| 4243 | piocbq->iocb.ulpFCP2Rcvy = 1; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4244 | else |
| 4245 | piocbq->iocb.ulpFCP2Rcvy = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4246 | |
| 4247 | piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f); |
| 4248 | piocbq->context1 = lpfc_cmd; |
| 4249 | piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; |
| 4250 | piocbq->iocb.ulpTimeout = lpfc_cmd->timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4251 | piocbq->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4252 | } |
| 4253 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4254 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4255 | * 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] | 4256 | * @vport: The virtual port for which this call is being executed. |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4257 | * @lpfc_cmd: Pointer to lpfc_io_buf data structure. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4258 | * @lun: Logical unit number. |
| 4259 | * @task_mgmt_cmd: SCSI task management command. |
| 4260 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4261 | * This routine creates FCP information unit corresponding to @task_mgmt_cmd |
| 4262 | * for device with SLI-3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4263 | * |
| 4264 | * Return codes: |
| 4265 | * 0 - Error |
| 4266 | * 1 - Success |
| 4267 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4268 | static int |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4269 | lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4270 | struct lpfc_io_buf *lpfc_cmd, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4271 | uint64_t lun, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4272 | uint8_t task_mgmt_cmd) |
| 4273 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4274 | struct lpfc_iocbq *piocbq; |
| 4275 | IOCB_t *piocb; |
| 4276 | struct fcp_cmnd *fcp_cmnd; |
James Smart | 0b18ac4 | 2006-05-01 21:50:40 -0400 | [diff] [blame] | 4277 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4278 | struct lpfc_nodelist *ndlp = rdata->pnode; |
| 4279 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4280 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || |
| 4281 | ndlp->nlp_state != NLP_STE_MAPPED_NODE) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4282 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4283 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4284 | piocbq = &(lpfc_cmd->cur_iocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4285 | piocbq->vport = vport; |
| 4286 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4287 | piocb = &piocbq->iocb; |
| 4288 | |
| 4289 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4290 | /* Clear out any old data in the FCP command area */ |
| 4291 | memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd)); |
| 4292 | int_to_scsilun(lun, &fcp_cmnd->fcp_lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4293 | fcp_cmnd->fcpCntl2 = task_mgmt_cmd; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4294 | if (vport->phba->sli_rev == 3 && |
| 4295 | !(vport->phba->sli3_options & LPFC_SLI3_BG_ENABLED)) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4296 | lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4297 | piocb->ulpCommand = CMD_FCP_ICMND64_CR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4298 | piocb->ulpContext = ndlp->nlp_rpi; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4299 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
| 4300 | piocb->ulpContext = |
| 4301 | vport->phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
| 4302 | } |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 4303 | piocb->ulpFCP2Rcvy = (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) ? 1 : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4304 | piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f); |
James Smart | f9226c2 | 2014-02-20 09:57:28 -0500 | [diff] [blame] | 4305 | piocb->ulpPU = 0; |
| 4306 | piocb->un.fcpi.fcpi_parm = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4307 | |
| 4308 | /* ulpTimeout is only one byte */ |
| 4309 | if (lpfc_cmd->timeout > 0xff) { |
| 4310 | /* |
| 4311 | * Do not timeout the command at the firmware level. |
| 4312 | * The driver will provide the timeout mechanism. |
| 4313 | */ |
| 4314 | piocb->ulpTimeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4315 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4316 | piocb->ulpTimeout = lpfc_cmd->timeout; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4317 | |
| 4318 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 4319 | lpfc_sli4_set_rsp_sgl_last(vport->phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4320 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4321 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4322 | } |
| 4323 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4324 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4325 | * lpfc_scsi_api_table_setup - Set up scsi api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4326 | * @phba: The hba struct for which this call is being executed. |
| 4327 | * @dev_grp: The HBA PCI-Device group number. |
| 4328 | * |
| 4329 | * This routine sets up the SCSI interface API function jump table in @phba |
| 4330 | * struct. |
| 4331 | * Returns: 0 - success, -ENODEV - failure. |
| 4332 | **/ |
| 4333 | int |
| 4334 | lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 4335 | { |
| 4336 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4337 | phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf; |
| 4338 | phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4339 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4340 | switch (dev_grp) { |
| 4341 | case LPFC_PCI_DEV_LP: |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4342 | phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4343 | 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] | 4344 | phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4345 | phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s3; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4346 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4347 | case LPFC_PCI_DEV_OC: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4348 | phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s4; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4349 | 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] | 4350 | phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s4; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4351 | phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s4; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4352 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4353 | default: |
| 4354 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4355 | "1418 Invalid HBA PCI-device group: 0x%x\n", |
| 4356 | dev_grp); |
| 4357 | return -ENODEV; |
| 4358 | break; |
| 4359 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4360 | phba->lpfc_rampdown_queue_depth = lpfc_rampdown_queue_depth; |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 4361 | phba->lpfc_scsi_cmd_iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4362 | return 0; |
| 4363 | } |
| 4364 | |
| 4365 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4366 | * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4367 | * @phba: The Hba for which this call is being executed. |
| 4368 | * @cmdiocbq: Pointer to lpfc_iocbq data structure. |
| 4369 | * @rspiocbq: Pointer to lpfc_iocbq data structure. |
| 4370 | * |
| 4371 | * This routine is IOCB completion routine for device reset and target reset |
| 4372 | * routine. This routine release scsi buffer associated with lpfc_cmd. |
| 4373 | **/ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4374 | static void |
| 4375 | lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba, |
| 4376 | struct lpfc_iocbq *cmdiocbq, |
| 4377 | struct lpfc_iocbq *rspiocbq) |
| 4378 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4379 | struct lpfc_io_buf *lpfc_cmd = |
| 4380 | (struct lpfc_io_buf *) cmdiocbq->context1; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4381 | if (lpfc_cmd) |
| 4382 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 4383 | return; |
| 4384 | } |
| 4385 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4386 | /** |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 4387 | * lpfc_check_pci_resettable - Walks list of devices on pci_dev's bus to check |
| 4388 | * if issuing a pci_bus_reset is possibly unsafe |
| 4389 | * @phba: lpfc_hba pointer. |
| 4390 | * |
| 4391 | * Description: |
| 4392 | * Walks the bus_list to ensure only PCI devices with Emulex |
| 4393 | * vendor id, device ids that support hot reset, and only one occurrence |
| 4394 | * of function 0. |
| 4395 | * |
| 4396 | * Returns: |
| 4397 | * -EBADSLT, detected invalid device |
| 4398 | * 0, successful |
| 4399 | */ |
| 4400 | int |
| 4401 | lpfc_check_pci_resettable(const struct lpfc_hba *phba) |
| 4402 | { |
| 4403 | const struct pci_dev *pdev = phba->pcidev; |
| 4404 | struct pci_dev *ptr = NULL; |
| 4405 | u8 counter = 0; |
| 4406 | |
| 4407 | /* Walk the list of devices on the pci_dev's bus */ |
| 4408 | list_for_each_entry(ptr, &pdev->bus->devices, bus_list) { |
| 4409 | /* Check for Emulex Vendor ID */ |
| 4410 | if (ptr->vendor != PCI_VENDOR_ID_EMULEX) { |
| 4411 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4412 | "8346 Non-Emulex vendor found: " |
| 4413 | "0x%04x\n", ptr->vendor); |
| 4414 | return -EBADSLT; |
| 4415 | } |
| 4416 | |
| 4417 | /* Check for valid Emulex Device ID */ |
| 4418 | switch (ptr->device) { |
| 4419 | case PCI_DEVICE_ID_LANCER_FC: |
| 4420 | case PCI_DEVICE_ID_LANCER_G6_FC: |
| 4421 | case PCI_DEVICE_ID_LANCER_G7_FC: |
| 4422 | break; |
| 4423 | default: |
| 4424 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4425 | "8347 Invalid device found: " |
| 4426 | "0x%04x\n", ptr->device); |
| 4427 | return -EBADSLT; |
| 4428 | } |
| 4429 | |
| 4430 | /* Check for only one function 0 ID to ensure only one HBA on |
| 4431 | * secondary bus |
| 4432 | */ |
| 4433 | if (ptr->devfn == 0) { |
| 4434 | if (++counter > 1) { |
| 4435 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4436 | "8348 More than one device on " |
| 4437 | "secondary bus found\n"); |
| 4438 | return -EBADSLT; |
| 4439 | } |
| 4440 | } |
| 4441 | } |
| 4442 | |
| 4443 | return 0; |
| 4444 | } |
| 4445 | |
| 4446 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4447 | * lpfc_info - Info entry point of scsi_host_template data structure |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4448 | * @host: The scsi host for which this call is being executed. |
| 4449 | * |
| 4450 | * This routine provides module information about hba. |
| 4451 | * |
| 4452 | * Reutrn code: |
| 4453 | * Pointer to char - Success. |
| 4454 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4455 | const char * |
| 4456 | lpfc_info(struct Scsi_Host *host) |
| 4457 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4458 | struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata; |
| 4459 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 4460 | int link_speed = 0; |
| 4461 | static char lpfcinfobuf[384]; |
| 4462 | char tmp[384] = {0}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4463 | |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 4464 | memset(lpfcinfobuf, 0, sizeof(lpfcinfobuf)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4465 | if (phba && phba->pcidev){ |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 4466 | /* Model Description */ |
| 4467 | scnprintf(tmp, sizeof(tmp), phba->ModelDesc); |
| 4468 | if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >= |
| 4469 | sizeof(lpfcinfobuf)) |
| 4470 | goto buffer_done; |
| 4471 | |
| 4472 | /* PCI Info */ |
| 4473 | scnprintf(tmp, sizeof(tmp), |
| 4474 | " on PCI bus %02x device %02x irq %d", |
| 4475 | phba->pcidev->bus->number, phba->pcidev->devfn, |
| 4476 | phba->pcidev->irq); |
| 4477 | if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >= |
| 4478 | sizeof(lpfcinfobuf)) |
| 4479 | goto buffer_done; |
| 4480 | |
| 4481 | /* Port Number */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4482 | if (phba->Port[0]) { |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 4483 | scnprintf(tmp, sizeof(tmp), " port %s", phba->Port); |
| 4484 | if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >= |
| 4485 | sizeof(lpfcinfobuf)) |
| 4486 | goto buffer_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4487 | } |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 4488 | |
| 4489 | /* Link Speed */ |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 4490 | link_speed = lpfc_sli_port_speed_get(phba); |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 4491 | if (link_speed != 0) { |
| 4492 | scnprintf(tmp, sizeof(tmp), |
| 4493 | " Logical Link Speed: %d Mbps", link_speed); |
| 4494 | if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >= |
| 4495 | sizeof(lpfcinfobuf)) |
| 4496 | goto buffer_done; |
| 4497 | } |
| 4498 | |
| 4499 | /* PCI resettable */ |
| 4500 | if (!lpfc_check_pci_resettable(phba)) { |
| 4501 | scnprintf(tmp, sizeof(tmp), " PCI resettable"); |
| 4502 | strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)); |
| 4503 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4504 | } |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 4505 | |
| 4506 | buffer_done: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4507 | return lpfcinfobuf; |
| 4508 | } |
| 4509 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4510 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4511 | * lpfc_poll_rearm_time - Routine to modify fcp_poll timer of hba |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4512 | * @phba: The Hba for which this call is being executed. |
| 4513 | * |
| 4514 | * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo. |
| 4515 | * The default value of cfg_poll_tmo is 10 milliseconds. |
| 4516 | **/ |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4517 | static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba) |
| 4518 | { |
| 4519 | unsigned long poll_tmo_expires = |
| 4520 | (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo)); |
| 4521 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4522 | 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] | 4523 | mod_timer(&phba->fcp_poll_timer, |
| 4524 | poll_tmo_expires); |
| 4525 | } |
| 4526 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4527 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4528 | * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4529 | * @phba: The Hba for which this call is being executed. |
| 4530 | * |
| 4531 | * This routine starts the fcp_poll_timer of @phba. |
| 4532 | **/ |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4533 | void lpfc_poll_start_timer(struct lpfc_hba * phba) |
| 4534 | { |
| 4535 | lpfc_poll_rearm_timer(phba); |
| 4536 | } |
| 4537 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4538 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4539 | * lpfc_poll_timeout - Restart polling timer |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4540 | * @ptr: Map to lpfc_hba data structure pointer. |
| 4541 | * |
| 4542 | * This routine restarts fcp_poll timer, when FCP ring polling is enable |
| 4543 | * and FCP Ring interrupt is disable. |
| 4544 | **/ |
| 4545 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4546 | void lpfc_poll_timeout(struct timer_list *t) |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4547 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4548 | 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] | 4549 | |
| 4550 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4551 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4552 | &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4553 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4554 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 4555 | lpfc_poll_rearm_timer(phba); |
| 4556 | } |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4557 | } |
| 4558 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4559 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4560 | * lpfc_queuecommand - scsi_host_template queuecommand entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4561 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 4562 | * @done: Pointer to done routine. |
| 4563 | * |
| 4564 | * Driver registers this routine to scsi midlayer to submit a @cmd to process. |
| 4565 | * This routine prepares an IOCB from scsi command and provides to firmware. |
| 4566 | * The @done callback is invoked after driver finished processing the command. |
| 4567 | * |
| 4568 | * Return value : |
| 4569 | * 0 - Success |
| 4570 | * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily. |
| 4571 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4572 | static int |
James Smart | b9a7c63 | 2012-08-03 12:35:24 -0400 | [diff] [blame] | 4573 | lpfc_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4574 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4575 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4576 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 4577 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 4578 | struct lpfc_nodelist *ndlp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4579 | struct lpfc_io_buf *lpfc_cmd; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4580 | struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device)); |
James Smart | 4c47efc | 2019-01-28 11:14:25 -0800 | [diff] [blame] | 4581 | int err, idx; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 4582 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 4583 | int cpu; |
| 4584 | #endif |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4585 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 4586 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 4587 | |
| 4588 | /* sanity check on references */ |
| 4589 | if (unlikely(!rdata) || unlikely(!rport)) |
| 4590 | goto out_fail_command; |
| 4591 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4592 | err = fc_remote_port_chkready(rport); |
| 4593 | if (err) { |
| 4594 | cmnd->result = err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4595 | goto out_fail_command; |
| 4596 | } |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 4597 | ndlp = rdata->pnode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4598 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 4599 | if ((scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) && |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4600 | (!(phba->sli3_options & LPFC_SLI3_BG_ENABLED))) { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4601 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4602 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 4603 | "9058 BLKGRD: ERROR: rcvd protected cmd:%02x" |
| 4604 | " op:%02x str=%s without registering for" |
| 4605 | " BlockGuard - Rejecting command\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4606 | cmnd->cmnd[0], scsi_get_prot_op(cmnd), |
| 4607 | dif_op_str[scsi_get_prot_op(cmnd)]); |
| 4608 | goto out_fail_command; |
| 4609 | } |
| 4610 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4611 | /* |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4612 | * Catch race where our node has transitioned, but the |
| 4613 | * transport is still transitioning. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4614 | */ |
James Smart | 6b415f5 | 2012-06-12 13:54:59 -0400 | [diff] [blame] | 4615 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 4616 | goto out_tgt_busy; |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 4617 | if (lpfc_ndlp_check_qdepth(phba, ndlp)) { |
| 4618 | if (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth) { |
| 4619 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_ERROR, |
| 4620 | "3377 Target Queue Full, scsi Id:%d " |
| 4621 | "Qdepth:%d Pending command:%d" |
| 4622 | " WWNN:%02x:%02x:%02x:%02x:" |
| 4623 | "%02x:%02x:%02x:%02x, " |
| 4624 | " WWPN:%02x:%02x:%02x:%02x:" |
| 4625 | "%02x:%02x:%02x:%02x", |
| 4626 | ndlp->nlp_sid, ndlp->cmd_qdepth, |
| 4627 | atomic_read(&ndlp->cmd_pending), |
| 4628 | ndlp->nlp_nodename.u.wwn[0], |
| 4629 | ndlp->nlp_nodename.u.wwn[1], |
| 4630 | ndlp->nlp_nodename.u.wwn[2], |
| 4631 | ndlp->nlp_nodename.u.wwn[3], |
| 4632 | ndlp->nlp_nodename.u.wwn[4], |
| 4633 | ndlp->nlp_nodename.u.wwn[5], |
| 4634 | ndlp->nlp_nodename.u.wwn[6], |
| 4635 | ndlp->nlp_nodename.u.wwn[7], |
| 4636 | ndlp->nlp_portname.u.wwn[0], |
| 4637 | ndlp->nlp_portname.u.wwn[1], |
| 4638 | ndlp->nlp_portname.u.wwn[2], |
| 4639 | ndlp->nlp_portname.u.wwn[3], |
| 4640 | ndlp->nlp_portname.u.wwn[4], |
| 4641 | ndlp->nlp_portname.u.wwn[5], |
| 4642 | ndlp->nlp_portname.u.wwn[6], |
| 4643 | ndlp->nlp_portname.u.wwn[7]); |
| 4644 | goto out_tgt_busy; |
| 4645 | } |
James Smart | 64bf009 | 2018-01-30 15:58:53 -0800 | [diff] [blame] | 4646 | } |
James Smart | f91bc59 | 2018-04-09 14:24:22 -0700 | [diff] [blame] | 4647 | |
James Smart | ace44e4 | 2019-01-28 11:14:27 -0800 | [diff] [blame] | 4648 | lpfc_cmd = lpfc_get_scsi_buf(phba, ndlp, cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4649 | if (lpfc_cmd == NULL) { |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4650 | lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4651 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4652 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_ERROR, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4653 | "0707 driver's buffer pool is empty, " |
| 4654 | "IO busied\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4655 | goto out_host_busy; |
| 4656 | } |
| 4657 | |
| 4658 | /* |
| 4659 | * Store the midlayer's command structure for the completion phase |
| 4660 | * and complete the command initialization. |
| 4661 | */ |
| 4662 | lpfc_cmd->pCmd = cmnd; |
| 4663 | lpfc_cmd->rdata = rdata; |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 4664 | lpfc_cmd->ndlp = ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4665 | cmnd->host_scribble = (unsigned char *)lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4666 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4667 | if (scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4668 | if (vport->phba->cfg_enable_bg) { |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 4669 | lpfc_printf_vlog(vport, |
| 4670 | KERN_INFO, LOG_SCSI_CMD, |
James Smart | 2613470 | 2012-08-14 14:25:50 -0400 | [diff] [blame] | 4671 | "9033 BLKGRD: rcvd %s cmd:x%x " |
| 4672 | "sector x%llx cnt %u pt %x\n", |
| 4673 | dif_op_str[scsi_get_prot_op(cmnd)], |
| 4674 | cmnd->cmnd[0], |
| 4675 | (unsigned long long)scsi_get_lba(cmnd), |
| 4676 | blk_rq_sectors(cmnd->request), |
| 4677 | (cmnd->cmnd[1]>>5)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4678 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4679 | err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 4680 | } else { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4681 | if (vport->phba->cfg_enable_bg) { |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 4682 | lpfc_printf_vlog(vport, |
| 4683 | KERN_INFO, LOG_SCSI_CMD, |
James Smart | 2613470 | 2012-08-14 14:25:50 -0400 | [diff] [blame] | 4684 | "9038 BLKGRD: rcvd PROT_NORMAL cmd: " |
| 4685 | "x%x sector x%llx cnt %u pt %x\n", |
| 4686 | cmnd->cmnd[0], |
| 4687 | (unsigned long long)scsi_get_lba(cmnd), |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 4688 | blk_rq_sectors(cmnd->request), |
James Smart | 2613470 | 2012-08-14 14:25:50 -0400 | [diff] [blame] | 4689 | (cmnd->cmnd[1]>>5)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4690 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4691 | err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 4692 | } |
| 4693 | |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 4694 | if (err == 2) { |
| 4695 | cmnd->result = DID_ERROR << 16; |
| 4696 | goto out_fail_command_release_buf; |
| 4697 | } else if (err) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4698 | goto out_host_busy_free_buf; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 4699 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4700 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4701 | lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4702 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 4703 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 4704 | if (phba->cpucheck_on & LPFC_CHECK_SCSI_IO) { |
Bart Van Assche | d6d189c | 2019-03-28 11:06:22 -0700 | [diff] [blame] | 4705 | cpu = raw_smp_processor_id(); |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 4706 | if (cpu < LPFC_CHECK_CPU_CNT) { |
| 4707 | struct lpfc_sli4_hdw_queue *hdwq = |
| 4708 | &phba->sli4_hba.hdwq[lpfc_cmd->hdwq_no]; |
| 4709 | hdwq->cpucheck_xmt_io[cpu]++; |
| 4710 | } |
| 4711 | } |
| 4712 | #endif |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4713 | err = lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4714 | &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4715 | if (err) { |
James Smart | 76f96b6 | 2013-12-17 20:29:01 -0500 | [diff] [blame] | 4716 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4717 | "3376 FCP could not issue IOCB err %x" |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4718 | "FCP cmd x%x <%d/%llu> " |
James Smart | 76f96b6 | 2013-12-17 20:29:01 -0500 | [diff] [blame] | 4719 | "sid: x%x did: x%x oxid: x%x " |
| 4720 | "Data: x%x x%x x%x x%x\n", |
| 4721 | err, cmnd->cmnd[0], |
| 4722 | cmnd->device ? cmnd->device->id : 0xffff, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4723 | cmnd->device ? cmnd->device->lun : (u64) -1, |
James Smart | 76f96b6 | 2013-12-17 20:29:01 -0500 | [diff] [blame] | 4724 | vport->fc_myDID, ndlp->nlp_DID, |
| 4725 | phba->sli_rev == LPFC_SLI_REV4 ? |
| 4726 | lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff, |
| 4727 | lpfc_cmd->cur_iocbq.iocb.ulpContext, |
| 4728 | lpfc_cmd->cur_iocbq.iocb.ulpIoTag, |
| 4729 | lpfc_cmd->cur_iocbq.iocb.ulpTimeout, |
| 4730 | (uint32_t) |
| 4731 | (cmnd->request->timeout / 1000)); |
| 4732 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4733 | goto out_host_busy_free_buf; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4734 | } |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4735 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4736 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4737 | &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4738 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4739 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 4740 | lpfc_poll_rearm_timer(phba); |
| 4741 | } |
| 4742 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4743 | if (phba->cfg_xri_rebalancing) |
| 4744 | lpfc_keep_pvt_pool_above_lowwm(phba, lpfc_cmd->hdwq_no); |
| 4745 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4746 | return 0; |
| 4747 | |
| 4748 | out_host_busy_free_buf: |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 4749 | idx = lpfc_cmd->hdwq_no; |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 4750 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
James Smart | 4c47efc | 2019-01-28 11:14:25 -0800 | [diff] [blame] | 4751 | if (phba->sli4_hba.hdwq) { |
| 4752 | switch (lpfc_cmd->fcp_cmnd->fcpCntl3) { |
| 4753 | case WRITE_DATA: |
| 4754 | phba->sli4_hba.hdwq[idx].scsi_cstat.output_requests--; |
| 4755 | break; |
| 4756 | case READ_DATA: |
| 4757 | phba->sli4_hba.hdwq[idx].scsi_cstat.input_requests--; |
| 4758 | break; |
| 4759 | default: |
| 4760 | phba->sli4_hba.hdwq[idx].scsi_cstat.control_requests--; |
| 4761 | } |
| 4762 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4763 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4764 | out_host_busy: |
| 4765 | return SCSI_MLQUEUE_HOST_BUSY; |
| 4766 | |
Mike Christie | 3496343 | 2011-02-25 14:04:28 -0600 | [diff] [blame] | 4767 | out_tgt_busy: |
| 4768 | return SCSI_MLQUEUE_TARGET_BUSY; |
| 4769 | |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 4770 | out_fail_command_release_buf: |
| 4771 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 4772 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4773 | out_fail_command: |
James Smart | b9a7c63 | 2012-08-03 12:35:24 -0400 | [diff] [blame] | 4774 | cmnd->scsi_done(cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4775 | return 0; |
| 4776 | } |
| 4777 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 4778 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4779 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4780 | * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4781 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 4782 | * |
| 4783 | * This routine aborts @cmnd pending in base driver. |
| 4784 | * |
| 4785 | * Return code : |
| 4786 | * 0x2003 - Error |
| 4787 | * 0x2002 - Success |
| 4788 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4789 | static int |
James.Smart@Emulex.Com | 63c59c3 | 2005-11-28 11:41:53 -0500 | [diff] [blame] | 4790 | lpfc_abort_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4791 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4792 | struct Scsi_Host *shost = cmnd->device->host; |
| 4793 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4794 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4795 | struct lpfc_iocbq *iocb; |
| 4796 | struct lpfc_iocbq *abtsiocb; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4797 | struct lpfc_io_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4798 | IOCB_t *cmd, *icmd; |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4799 | int ret = SUCCESS, status = 0; |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 4800 | struct lpfc_sli_ring *pring_s4 = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4801 | int ret_val; |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 4802 | unsigned long flags; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4803 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4804 | |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4805 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 4806 | if (status != 0 && status != SUCCESS) |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4807 | return status; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4808 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4809 | lpfc_cmd = (struct lpfc_io_buf *)cmnd->host_scribble; |
| 4810 | if (!lpfc_cmd) |
| 4811 | return ret; |
| 4812 | |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4813 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4814 | /* driver queued commands are in process of being flushed */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame^] | 4815 | if (phba->hba_flag & HBA_IOQ_FLUSH) { |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4816 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4817 | "3168 SCSI Layer abort requested I/O has been " |
| 4818 | "flushed by LLD.\n"); |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4819 | ret = FAILED; |
| 4820 | goto out_unlock; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4821 | } |
| 4822 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4823 | /* Guard against IO completion being called at same time */ |
| 4824 | spin_lock(&lpfc_cmd->buf_lock); |
| 4825 | |
| 4826 | if (!lpfc_cmd->pCmd) { |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 4827 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4828 | "2873 SCSI Layer I/O Abort Request IO CMPL Status " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4829 | "x%x ID %d LUN %llu\n", |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4830 | SUCCESS, cmnd->device->id, cmnd->device->lun); |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4831 | goto out_unlock_buf; |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 4832 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4833 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4834 | iocb = &lpfc_cmd->cur_iocbq; |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 4835 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame^] | 4836 | pring_s4 = phba->sli4_hba.hdwq[iocb->hba_wqidx].io_wq->pring; |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 4837 | if (!pring_s4) { |
| 4838 | ret = FAILED; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4839 | goto out_unlock_buf; |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 4840 | } |
| 4841 | spin_lock(&pring_s4->ring_lock); |
| 4842 | } |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4843 | /* the command is in process of being cancelled */ |
| 4844 | if (!(iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ)) { |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4845 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4846 | "3169 SCSI Layer abort requested I/O has been " |
| 4847 | "cancelled by LLD.\n"); |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4848 | ret = FAILED; |
| 4849 | goto out_unlock_ring; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4850 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4851 | /* |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4852 | * If pCmd field of the corresponding lpfc_io_buf structure |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4853 | * points to a different SCSI command, then the driver has |
| 4854 | * already completed this command, but the midlayer did not |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4855 | * see the completion before the eh fired. Just return SUCCESS. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4856 | */ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4857 | if (lpfc_cmd->pCmd != cmnd) { |
| 4858 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4859 | "3170 SCSI Layer abort requested I/O has been " |
| 4860 | "completed by LLD.\n"); |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4861 | goto out_unlock_ring; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4862 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4863 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4864 | BUG_ON(iocb->context1 != lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4865 | |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4866 | /* abort issued in recovery is still in progress */ |
| 4867 | if (iocb->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 4868 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4869 | "3389 SCSI Layer I/O Abort Request is pending\n"); |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 4870 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4871 | spin_unlock(&pring_s4->ring_lock); |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4872 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4873 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4874 | goto wait_for_cmpl; |
| 4875 | } |
| 4876 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4877 | abtsiocb = __lpfc_sli_get_iocbq(phba); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4878 | if (abtsiocb == NULL) { |
| 4879 | ret = FAILED; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4880 | goto out_unlock_ring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4881 | } |
| 4882 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 4883 | /* Indicate the IO is being aborted by the driver. */ |
| 4884 | iocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 4885 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4886 | /* |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4887 | * The scsi command can not be in txq and it is in flight because the |
| 4888 | * pCmd is still pointig at the SCSI command we have to abort. There |
| 4889 | * is no need to search the txcmplq. Just send an abort to the FW. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4890 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4891 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4892 | cmd = &iocb->iocb; |
| 4893 | icmd = &abtsiocb->iocb; |
| 4894 | icmd->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 4895 | icmd->un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4896 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4897 | icmd->un.acxri.abortIoTag = iocb->sli4_xritag; |
| 4898 | else |
| 4899 | icmd->un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4900 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4901 | icmd->ulpLe = 1; |
| 4902 | icmd->ulpClass = cmd->ulpClass; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4903 | |
| 4904 | /* 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] | 4905 | abtsiocb->hba_wqidx = iocb->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 4906 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 4907 | if (iocb->iocb_flag & LPFC_IO_FOF) |
| 4908 | abtsiocb->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4909 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4910 | if (lpfc_is_link_up(phba)) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4911 | icmd->ulpCommand = CMD_ABORT_XRI_CN; |
| 4912 | else |
| 4913 | icmd->ulpCommand = CMD_CLOSE_XRI_CN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4914 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4915 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4916 | abtsiocb->vport = vport; |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 4917 | lpfc_cmd->waitq = &waitq; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4918 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4919 | /* Note: both hbalock and ring_lock must be set here */ |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4920 | ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 4921 | abtsiocb, 0); |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 4922 | spin_unlock(&pring_s4->ring_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4923 | } else { |
| 4924 | ret_val = __lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, |
| 4925 | abtsiocb, 0); |
| 4926 | } |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4927 | /* no longer need the lock after this point */ |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4928 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4929 | |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4930 | if (ret_val == IOCB_ERROR) { |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 4931 | /* Indicate the IO is not being aborted by the driver. */ |
| 4932 | iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 4933 | lpfc_cmd->waitq = NULL; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4934 | spin_unlock(&lpfc_cmd->buf_lock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4935 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| 4936 | ret = FAILED; |
| 4937 | goto out; |
| 4938 | } |
| 4939 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4940 | spin_unlock(&lpfc_cmd->buf_lock); |
| 4941 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4942 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4943 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4944 | &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4945 | |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4946 | wait_for_cmpl: |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4947 | /* Wait for abort to complete */ |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4948 | wait_event_timeout(waitq, |
| 4949 | (lpfc_cmd->pCmd != cmnd), |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4950 | msecs_to_jiffies(2*vport->cfg_devloss_tmo*1000)); |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4951 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4952 | spin_lock(&lpfc_cmd->buf_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4953 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4954 | if (lpfc_cmd->pCmd == cmnd) { |
| 4955 | ret = FAILED; |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4956 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 4957 | "0748 abort handler timed out waiting " |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 4958 | "for aborting I/O (xri:x%x) to complete: " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4959 | "ret %#x, ID %d, LUN %llu\n", |
James Smart | 247ca94 | 2012-08-14 14:26:13 -0400 | [diff] [blame] | 4960 | iocb->sli4_xritag, ret, |
| 4961 | cmnd->device->id, cmnd->device->lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4962 | } |
James Smart | b9e5a2d | 2019-05-21 17:49:01 -0700 | [diff] [blame] | 4963 | |
| 4964 | lpfc_cmd->waitq = NULL; |
| 4965 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4966 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4967 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4968 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4969 | out_unlock_ring: |
| 4970 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4971 | spin_unlock(&pring_s4->ring_lock); |
| 4972 | out_unlock_buf: |
| 4973 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4974 | out_unlock: |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4975 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4976 | out: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4977 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4978 | "0749 SCSI Layer I/O Abort Request Status x%x ID %d " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4979 | "LUN %llu\n", ret, cmnd->device->id, |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 4980 | cmnd->device->lun); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4981 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4982 | } |
| 4983 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4984 | static char * |
| 4985 | lpfc_taskmgmt_name(uint8_t task_mgmt_cmd) |
| 4986 | { |
| 4987 | switch (task_mgmt_cmd) { |
| 4988 | case FCP_ABORT_TASK_SET: |
| 4989 | return "ABORT_TASK_SET"; |
| 4990 | case FCP_CLEAR_TASK_SET: |
| 4991 | return "FCP_CLEAR_TASK_SET"; |
| 4992 | case FCP_BUS_RESET: |
| 4993 | return "FCP_BUS_RESET"; |
| 4994 | case FCP_LUN_RESET: |
| 4995 | return "FCP_LUN_RESET"; |
| 4996 | case FCP_TARGET_RESET: |
| 4997 | return "FCP_TARGET_RESET"; |
| 4998 | case FCP_CLEAR_ACA: |
| 4999 | return "FCP_CLEAR_ACA"; |
| 5000 | case FCP_TERMINATE_TASK: |
| 5001 | return "FCP_TERMINATE_TASK"; |
| 5002 | default: |
| 5003 | return "unknown"; |
| 5004 | } |
| 5005 | } |
| 5006 | |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5007 | |
| 5008 | /** |
| 5009 | * lpfc_check_fcp_rsp - check the returned fcp_rsp to see if task failed |
| 5010 | * @vport: The virtual port for which this call is being executed. |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 5011 | * @lpfc_cmd: Pointer to lpfc_io_buf data structure. |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5012 | * |
| 5013 | * This routine checks the FCP RSP INFO to see if the tsk mgmt command succeded |
| 5014 | * |
| 5015 | * Return code : |
| 5016 | * 0x2003 - Error |
| 5017 | * 0x2002 - Success |
| 5018 | **/ |
| 5019 | static int |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 5020 | lpfc_check_fcp_rsp(struct lpfc_vport *vport, struct lpfc_io_buf *lpfc_cmd) |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5021 | { |
| 5022 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
| 5023 | uint32_t rsp_info; |
| 5024 | uint32_t rsp_len; |
| 5025 | uint8_t rsp_info_code; |
| 5026 | int ret = FAILED; |
| 5027 | |
| 5028 | |
| 5029 | if (fcprsp == NULL) |
| 5030 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 5031 | "0703 fcp_rsp is missing\n"); |
| 5032 | else { |
| 5033 | rsp_info = fcprsp->rspStatus2; |
| 5034 | rsp_len = be32_to_cpu(fcprsp->rspRspLen); |
| 5035 | rsp_info_code = fcprsp->rspInfo3; |
| 5036 | |
| 5037 | |
| 5038 | lpfc_printf_vlog(vport, KERN_INFO, |
| 5039 | LOG_FCP, |
| 5040 | "0706 fcp_rsp valid 0x%x," |
| 5041 | " rsp len=%d code 0x%x\n", |
| 5042 | rsp_info, |
| 5043 | rsp_len, rsp_info_code); |
| 5044 | |
James Smart | 996a02a | 2019-05-21 17:49:07 -0700 | [diff] [blame] | 5045 | /* If FCP_RSP_LEN_VALID bit is one, then the FCP_RSP_LEN |
| 5046 | * field specifies the number of valid bytes of FCP_RSP_INFO. |
| 5047 | * The FCP_RSP_LEN field shall be set to 0x04 or 0x08 |
| 5048 | */ |
| 5049 | if ((fcprsp->rspStatus2 & RSP_LEN_VALID) && |
| 5050 | ((rsp_len == 8) || (rsp_len == 4))) { |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5051 | switch (rsp_info_code) { |
| 5052 | case RSP_NO_FAILURE: |
| 5053 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 5054 | "0715 Task Mgmt No Failure\n"); |
| 5055 | ret = SUCCESS; |
| 5056 | break; |
| 5057 | case RSP_TM_NOT_SUPPORTED: /* TM rejected */ |
| 5058 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 5059 | "0716 Task Mgmt Target " |
| 5060 | "reject\n"); |
| 5061 | break; |
| 5062 | case RSP_TM_NOT_COMPLETED: /* TM failed */ |
| 5063 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 5064 | "0717 Task Mgmt Target " |
| 5065 | "failed TM\n"); |
| 5066 | break; |
| 5067 | case RSP_TM_INVALID_LU: /* TM to invalid LU! */ |
| 5068 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 5069 | "0718 Task Mgmt to invalid " |
| 5070 | "LUN\n"); |
| 5071 | break; |
| 5072 | } |
| 5073 | } |
| 5074 | } |
| 5075 | return ret; |
| 5076 | } |
| 5077 | |
| 5078 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5079 | /** |
| 5080 | * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler |
| 5081 | * @vport: The virtual port for which this call is being executed. |
| 5082 | * @rdata: Pointer to remote port local data |
| 5083 | * @tgt_id: Target ID of remote device. |
| 5084 | * @lun_id: Lun number for the TMF |
| 5085 | * @task_mgmt_cmd: type of TMF to send |
| 5086 | * |
| 5087 | * This routine builds and sends a TMF (SCSI Task Mgmt Function) to |
| 5088 | * a remote port. |
| 5089 | * |
| 5090 | * Return Code: |
| 5091 | * 0x2003 - Error |
| 5092 | * 0x2002 - Success. |
| 5093 | **/ |
| 5094 | static int |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 5095 | lpfc_send_taskmgmt(struct lpfc_vport *vport, struct scsi_cmnd *cmnd, |
| 5096 | unsigned int tgt_id, uint64_t lun_id, |
| 5097 | uint8_t task_mgmt_cmd) |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5098 | { |
| 5099 | struct lpfc_hba *phba = vport->phba; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 5100 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5101 | struct lpfc_iocbq *iocbq; |
| 5102 | struct lpfc_iocbq *iocbqrsp; |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 5103 | struct lpfc_rport_data *rdata; |
| 5104 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5105 | int ret; |
| 5106 | int status; |
| 5107 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 5108 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
| 5109 | if (!rdata || !rdata->pnode || !NLP_CHK_NODE_ACT(rdata->pnode)) |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5110 | return FAILED; |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 5111 | pnode = rdata->pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5112 | |
James Smart | ace44e4 | 2019-01-28 11:14:27 -0800 | [diff] [blame] | 5113 | lpfc_cmd = lpfc_get_scsi_buf(phba, pnode, NULL); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5114 | if (lpfc_cmd == NULL) |
| 5115 | return FAILED; |
James Smart | 0c41122 | 2013-09-06 12:22:46 -0400 | [diff] [blame] | 5116 | lpfc_cmd->timeout = phba->cfg_task_mgmt_tmo; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5117 | lpfc_cmd->rdata = rdata; |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 5118 | lpfc_cmd->pCmd = cmnd; |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 5119 | lpfc_cmd->ndlp = pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5120 | |
| 5121 | status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun_id, |
| 5122 | task_mgmt_cmd); |
| 5123 | if (!status) { |
| 5124 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 5125 | return FAILED; |
| 5126 | } |
| 5127 | |
| 5128 | iocbq = &lpfc_cmd->cur_iocbq; |
| 5129 | iocbqrsp = lpfc_sli_get_iocbq(phba); |
| 5130 | if (iocbqrsp == NULL) { |
| 5131 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 5132 | return FAILED; |
| 5133 | } |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 5134 | iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5135 | |
| 5136 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5137 | "0702 Issue %s to TGT %d LUN %llu " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5138 | "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] | 5139 | lpfc_taskmgmt_name(task_mgmt_cmd), tgt_id, lun_id, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5140 | pnode->nlp_rpi, pnode->nlp_flag, iocbq->sli4_xritag, |
| 5141 | iocbq->iocb_flag); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5142 | |
| 5143 | status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING, |
| 5144 | iocbq, iocbqrsp, lpfc_cmd->timeout); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5145 | if ((status != IOCB_SUCCESS) || |
| 5146 | (iocbqrsp->iocb.ulpStatus != IOSTAT_SUCCESS)) { |
James Smart | ae374a3 | 2015-05-22 10:42:41 -0400 | [diff] [blame] | 5147 | if (status != IOCB_SUCCESS || |
| 5148 | iocbqrsp->iocb.ulpStatus != IOSTAT_FCP_RSP_ERROR) |
| 5149 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5150 | "0727 TMF %s to TGT %d LUN %llu " |
| 5151 | "failed (%d, %d) iocb_flag x%x\n", |
| 5152 | lpfc_taskmgmt_name(task_mgmt_cmd), |
| 5153 | tgt_id, lun_id, |
| 5154 | iocbqrsp->iocb.ulpStatus, |
| 5155 | iocbqrsp->iocb.un.ulpWord[4], |
| 5156 | iocbq->iocb_flag); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5157 | /* if ulpStatus != IOCB_SUCCESS, then status == IOCB_SUCCESS */ |
| 5158 | if (status == IOCB_SUCCESS) { |
| 5159 | if (iocbqrsp->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 5160 | /* Something in the FCP_RSP was invalid. |
| 5161 | * Check conditions */ |
| 5162 | ret = lpfc_check_fcp_rsp(vport, lpfc_cmd); |
| 5163 | else |
| 5164 | ret = FAILED; |
| 5165 | } else if (status == IOCB_TIMEDOUT) { |
| 5166 | ret = TIMEOUT_ERROR; |
| 5167 | } else { |
| 5168 | ret = FAILED; |
| 5169 | } |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5170 | } else |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5171 | ret = SUCCESS; |
| 5172 | |
| 5173 | lpfc_sli_release_iocbq(phba, iocbqrsp); |
| 5174 | |
| 5175 | if (ret != TIMEOUT_ERROR) |
| 5176 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 5177 | |
| 5178 | return ret; |
| 5179 | } |
| 5180 | |
| 5181 | /** |
| 5182 | * lpfc_chk_tgt_mapped - |
| 5183 | * @vport: The virtual port to check on |
| 5184 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5185 | * |
| 5186 | * This routine delays until the scsi target (aka rport) for the |
| 5187 | * command exists (is present and logged in) or we declare it non-existent. |
| 5188 | * |
| 5189 | * Return code : |
| 5190 | * 0x2003 - Error |
| 5191 | * 0x2002 - Success |
| 5192 | **/ |
| 5193 | static int |
| 5194 | lpfc_chk_tgt_mapped(struct lpfc_vport *vport, struct scsi_cmnd *cmnd) |
| 5195 | { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5196 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5197 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5198 | unsigned long later; |
| 5199 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5200 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5201 | if (!rdata) { |
| 5202 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 5203 | "0797 Tgt Map rport failure: rdata x%px\n", rdata); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5204 | return FAILED; |
| 5205 | } |
| 5206 | pnode = rdata->pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5207 | /* |
| 5208 | * If target is not in a MAPPED state, delay until |
| 5209 | * target is rediscovered or devloss timeout expires. |
| 5210 | */ |
| 5211 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; |
| 5212 | while (time_after(later, jiffies)) { |
| 5213 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 5214 | return FAILED; |
| 5215 | if (pnode->nlp_state == NLP_STE_MAPPED_NODE) |
| 5216 | return SUCCESS; |
| 5217 | schedule_timeout_uninterruptible(msecs_to_jiffies(500)); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5218 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5219 | if (!rdata) |
| 5220 | return FAILED; |
| 5221 | pnode = rdata->pnode; |
| 5222 | } |
| 5223 | if (!pnode || !NLP_CHK_NODE_ACT(pnode) || |
| 5224 | (pnode->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5225 | return FAILED; |
| 5226 | return SUCCESS; |
| 5227 | } |
| 5228 | |
| 5229 | /** |
| 5230 | * lpfc_reset_flush_io_context - |
| 5231 | * @vport: The virtual port (scsi_host) for the flush context |
| 5232 | * @tgt_id: If aborting by Target contect - specifies the target id |
| 5233 | * @lun_id: If aborting by Lun context - specifies the lun id |
| 5234 | * @context: specifies the context level to flush at. |
| 5235 | * |
| 5236 | * After a reset condition via TMF, we need to flush orphaned i/o |
| 5237 | * contexts from the adapter. This routine aborts any contexts |
| 5238 | * outstanding, then waits for their completions. The wait is |
| 5239 | * bounded by devloss_tmo though. |
| 5240 | * |
| 5241 | * Return code : |
| 5242 | * 0x2003 - Error |
| 5243 | * 0x2002 - Success |
| 5244 | **/ |
| 5245 | static int |
| 5246 | lpfc_reset_flush_io_context(struct lpfc_vport *vport, uint16_t tgt_id, |
| 5247 | uint64_t lun_id, lpfc_ctx_cmd context) |
| 5248 | { |
| 5249 | struct lpfc_hba *phba = vport->phba; |
| 5250 | unsigned long later; |
| 5251 | int cnt; |
| 5252 | |
| 5253 | cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context); |
| 5254 | if (cnt) |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 5255 | lpfc_sli_abort_taskmgmt(vport, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5256 | &phba->sli.sli3_ring[LPFC_FCP_RING], |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 5257 | tgt_id, lun_id, context); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5258 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; |
| 5259 | while (time_after(later, jiffies) && cnt) { |
| 5260 | schedule_timeout_uninterruptible(msecs_to_jiffies(20)); |
| 5261 | cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context); |
| 5262 | } |
| 5263 | if (cnt) { |
| 5264 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5265 | "0724 I/O flush failure for context %s : cnt x%x\n", |
| 5266 | ((context == LPFC_CTX_LUN) ? "LUN" : |
| 5267 | ((context == LPFC_CTX_TGT) ? "TGT" : |
| 5268 | ((context == LPFC_CTX_HOST) ? "HOST" : "Unknown"))), |
| 5269 | cnt); |
| 5270 | return FAILED; |
| 5271 | } |
| 5272 | return SUCCESS; |
| 5273 | } |
| 5274 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5275 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5276 | * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5277 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5278 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5279 | * 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] | 5280 | * command. |
| 5281 | * |
| 5282 | * Return code : |
| 5283 | * 0x2003 - Error |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5284 | * 0x2002 - Success |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5285 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5286 | static int |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5287 | lpfc_device_reset_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5288 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5289 | struct Scsi_Host *shost = cmnd->device->host; |
| 5290 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5291 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5292 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5293 | unsigned tgt_id = cmnd->device->id; |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5294 | uint64_t lun_id = cmnd->device->lun; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5295 | struct lpfc_scsi_event_header scsi_event; |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5296 | int status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5297 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5298 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | ad490b6 | 2015-04-07 15:07:26 -0400 | [diff] [blame] | 5299 | if (!rdata || !rdata->pnode) { |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5300 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 5301 | "0798 Device Reset rdata failure: rdata x%px\n", |
James Smart | ad490b6 | 2015-04-07 15:07:26 -0400 | [diff] [blame] | 5302 | rdata); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5303 | return FAILED; |
| 5304 | } |
| 5305 | pnode = rdata->pnode; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5306 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 5307 | if (status != 0 && status != SUCCESS) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5308 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5309 | |
| 5310 | status = lpfc_chk_tgt_mapped(vport, cmnd); |
| 5311 | if (status == FAILED) { |
| 5312 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 5313 | "0721 Device Reset rport failure: rdata x%px\n", rdata); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5314 | return FAILED; |
| 5315 | } |
| 5316 | |
| 5317 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 5318 | scsi_event.subcategory = LPFC_EVENT_LUNRESET; |
| 5319 | scsi_event.lun = lun_id; |
| 5320 | memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 5321 | memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 5322 | |
| 5323 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5324 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
| 5325 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 5326 | status = lpfc_send_taskmgmt(vport, cmnd, tgt_id, lun_id, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5327 | FCP_LUN_RESET); |
| 5328 | |
| 5329 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5330 | "0713 SCSI layer issued Device Reset (%d, %llu) " |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5331 | "return x%x\n", tgt_id, lun_id, status); |
| 5332 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5333 | /* |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5334 | * We have to clean up i/o as : they may be orphaned by the TMF; |
| 5335 | * or if the TMF failed, they may be in an indeterminate state. |
| 5336 | * So, continue on. |
| 5337 | * We will report success if all the i/o aborts successfully. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5338 | */ |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5339 | if (status == SUCCESS) |
| 5340 | status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5341 | LPFC_CTX_LUN); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5342 | |
| 5343 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5344 | } |
| 5345 | |
| 5346 | /** |
| 5347 | * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point |
| 5348 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5349 | * |
| 5350 | * This routine does a target reset by sending a TARGET_RESET task management |
| 5351 | * command. |
| 5352 | * |
| 5353 | * Return code : |
| 5354 | * 0x2003 - Error |
| 5355 | * 0x2002 - Success |
| 5356 | **/ |
| 5357 | static int |
| 5358 | lpfc_target_reset_handler(struct scsi_cmnd *cmnd) |
| 5359 | { |
| 5360 | struct Scsi_Host *shost = cmnd->device->host; |
| 5361 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5362 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5363 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5364 | unsigned tgt_id = cmnd->device->id; |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5365 | uint64_t lun_id = cmnd->device->lun; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5366 | struct lpfc_scsi_event_header scsi_event; |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5367 | int status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5368 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5369 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | bbd3d73 | 2019-03-12 16:30:17 -0700 | [diff] [blame] | 5370 | if (!rdata || !rdata->pnode) { |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5371 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 5372 | "0799 Target Reset rdata failure: rdata x%px\n", |
James Smart | bbd3d73 | 2019-03-12 16:30:17 -0700 | [diff] [blame] | 5373 | rdata); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5374 | return FAILED; |
| 5375 | } |
| 5376 | pnode = rdata->pnode; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5377 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 5378 | if (status != 0 && status != SUCCESS) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5379 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5380 | |
| 5381 | status = lpfc_chk_tgt_mapped(vport, cmnd); |
| 5382 | if (status == FAILED) { |
| 5383 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 5384 | "0722 Target Reset rport failure: rdata x%px\n", rdata); |
James Smart | 63e480f | 2015-04-07 15:07:20 -0400 | [diff] [blame] | 5385 | if (pnode) { |
| 5386 | spin_lock_irq(shost->host_lock); |
| 5387 | pnode->nlp_flag &= ~NLP_NPR_ADISC; |
| 5388 | pnode->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; |
| 5389 | spin_unlock_irq(shost->host_lock); |
| 5390 | } |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 5391 | lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
| 5392 | LPFC_CTX_TGT); |
| 5393 | return FAST_IO_FAIL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5394 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5395 | |
| 5396 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 5397 | scsi_event.subcategory = LPFC_EVENT_TGTRESET; |
| 5398 | scsi_event.lun = 0; |
| 5399 | memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 5400 | memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 5401 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5402 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5403 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5404 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 5405 | status = lpfc_send_taskmgmt(vport, cmnd, tgt_id, lun_id, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5406 | FCP_TARGET_RESET); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5407 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5408 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5409 | "0723 SCSI layer issued Target Reset (%d, %llu) " |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5410 | "return x%x\n", tgt_id, lun_id, status); |
| 5411 | |
| 5412 | /* |
| 5413 | * We have to clean up i/o as : they may be orphaned by the TMF; |
| 5414 | * or if the TMF failed, they may be in an indeterminate state. |
| 5415 | * So, continue on. |
| 5416 | * We will report success if all the i/o aborts successfully. |
| 5417 | */ |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5418 | if (status == SUCCESS) |
| 5419 | status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 5420 | LPFC_CTX_TGT); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5421 | return status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5422 | } |
| 5423 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5424 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5425 | * 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] | 5426 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5427 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5428 | * This routine does target reset to all targets on @cmnd->device->host. |
| 5429 | * This emulates Parallel SCSI Bus Reset Semantics. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5430 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5431 | * Return code : |
| 5432 | * 0x2003 - Error |
| 5433 | * 0x2002 - Success |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5434 | **/ |
Jeff Garzik | 94d0e7b8 | 2005-05-28 07:55:48 -0400 | [diff] [blame] | 5435 | static int |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5436 | lpfc_bus_reset_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5437 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5438 | struct Scsi_Host *shost = cmnd->device->host; |
| 5439 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5440 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5441 | struct lpfc_scsi_event_header scsi_event; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5442 | int match; |
| 5443 | int ret = SUCCESS, status, i; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5444 | |
| 5445 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 5446 | scsi_event.subcategory = LPFC_EVENT_BUSRESET; |
| 5447 | scsi_event.lun = 0; |
| 5448 | memcpy(scsi_event.wwpn, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 5449 | memcpy(scsi_event.wwnn, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| 5450 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5451 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5452 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5453 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 5454 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 5455 | if (status != 0 && status != SUCCESS) |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 5456 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5457 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5458 | /* |
| 5459 | * Since the driver manages a single bus device, reset all |
| 5460 | * targets known to the driver. Should any target reset |
| 5461 | * fail, this routine returns failure to the midlayer. |
| 5462 | */ |
James Smart | e17da18 | 2006-07-06 15:49:25 -0400 | [diff] [blame] | 5463 | for (i = 0; i < LPFC_MAX_TARGET; i++) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5464 | /* Search for mapped node by target ID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5465 | match = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5466 | spin_lock_irq(shost->host_lock); |
| 5467 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5468 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5469 | continue; |
James Smart | a6571c6 | 2012-10-31 14:44:42 -0400 | [diff] [blame] | 5470 | if (vport->phba->cfg_fcp2_no_tgt_reset && |
| 5471 | (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE)) |
| 5472 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5473 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE && |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 5474 | ndlp->nlp_sid == i && |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5475 | ndlp->rport && |
| 5476 | ndlp->nlp_type & NLP_FCP_TARGET) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5477 | match = 1; |
| 5478 | break; |
| 5479 | } |
| 5480 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5481 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5482 | if (!match) |
| 5483 | continue; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5484 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 5485 | status = lpfc_send_taskmgmt(vport, cmnd, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5486 | i, 0, FCP_TARGET_RESET); |
| 5487 | |
| 5488 | if (status != SUCCESS) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5489 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5490 | "0700 Bus Reset on target %d failed\n", |
| 5491 | i); |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 5492 | ret = FAILED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5493 | } |
| 5494 | } |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 5495 | /* |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5496 | * We have to clean up i/o as : they may be orphaned by the TMFs |
| 5497 | * above; or if any of the TMFs failed, they may be in an |
| 5498 | * indeterminate state. |
| 5499 | * 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] | 5500 | */ |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5501 | |
| 5502 | status = lpfc_reset_flush_io_context(vport, 0, 0, LPFC_CTX_HOST); |
| 5503 | if (status != SUCCESS) |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 5504 | ret = FAILED; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5505 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5506 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5507 | "0714 SCSI layer issued Bus Reset Data: x%x\n", ret); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5508 | return ret; |
| 5509 | } |
| 5510 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5511 | /** |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5512 | * lpfc_host_reset_handler - scsi_host_template eh_host_reset_handler entry pt |
| 5513 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5514 | * |
| 5515 | * This routine does host reset to the adaptor port. It brings the HBA |
| 5516 | * offline, performs a board restart, and then brings the board back online. |
| 5517 | * The lpfc_offline calls lpfc_sli_hba_down which will abort and local |
| 5518 | * reject all outstanding SCSI commands to the host and error returned |
| 5519 | * back to SCSI mid-level. As this will be SCSI mid-level's last resort |
| 5520 | * of error handling, it will only return error if resetting of the adapter |
| 5521 | * is not successful; in all other cases, will return success. |
| 5522 | * |
| 5523 | * Return code : |
| 5524 | * 0x2003 - Error |
| 5525 | * 0x2002 - Success |
| 5526 | **/ |
| 5527 | static int |
| 5528 | lpfc_host_reset_handler(struct scsi_cmnd *cmnd) |
| 5529 | { |
| 5530 | struct Scsi_Host *shost = cmnd->device->host; |
| 5531 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 5532 | struct lpfc_hba *phba = vport->phba; |
| 5533 | int rc, ret = SUCCESS; |
| 5534 | |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 5535 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5536 | "3172 SCSI layer issued Host Reset Data:\n"); |
| 5537 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 5538 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5539 | lpfc_offline(phba); |
| 5540 | rc = lpfc_sli_brdrestart(phba); |
| 5541 | if (rc) |
James Smart | 8c24a4f | 2019-08-14 16:56:53 -0700 | [diff] [blame] | 5542 | goto error; |
| 5543 | |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 5544 | rc = lpfc_online(phba); |
| 5545 | if (rc) |
James Smart | 8c24a4f | 2019-08-14 16:56:53 -0700 | [diff] [blame] | 5546 | goto error; |
| 5547 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5548 | lpfc_unblock_mgmt_io(phba); |
| 5549 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5550 | return ret; |
James Smart | 8c24a4f | 2019-08-14 16:56:53 -0700 | [diff] [blame] | 5551 | error: |
| 5552 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5553 | "3323 Failed host reset\n"); |
| 5554 | lpfc_unblock_mgmt_io(phba); |
| 5555 | return FAILED; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5556 | } |
| 5557 | |
| 5558 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5559 | * lpfc_slave_alloc - scsi_host_template slave_alloc entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5560 | * @sdev: Pointer to scsi_device. |
| 5561 | * |
| 5562 | * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's |
| 5563 | * globally available list of scsi buffers. This routine also makes sure scsi |
| 5564 | * buffer is not allocated more than HBA limit conveyed to midlayer. This list |
| 5565 | * of scsi buffer exists for the lifetime of the driver. |
| 5566 | * |
| 5567 | * Return codes: |
| 5568 | * non-0 - Error |
| 5569 | * 0 - Success |
| 5570 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5571 | static int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5572 | lpfc_slave_alloc(struct scsi_device *sdev) |
| 5573 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5574 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 5575 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 5576 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5577 | uint32_t total = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5578 | uint32_t num_to_alloc = 0; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5579 | int num_allocated = 0; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5580 | uint32_t sdev_cnt; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5581 | struct lpfc_device_data *device_data; |
| 5582 | unsigned long flags; |
| 5583 | struct lpfc_name target_wwpn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5584 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 5585 | if (!rport || fc_remote_port_chkready(rport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5586 | return -ENXIO; |
| 5587 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5588 | if (phba->cfg_fof) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5589 | |
| 5590 | /* |
| 5591 | * Check to see if the device data structure for the lun |
| 5592 | * exists. If not, create one. |
| 5593 | */ |
| 5594 | |
| 5595 | u64_to_wwn(rport->port_name, target_wwpn.u.wwn); |
| 5596 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5597 | device_data = __lpfc_get_device_data(phba, |
| 5598 | &phba->luns, |
| 5599 | &vport->fc_portname, |
| 5600 | &target_wwpn, |
| 5601 | sdev->lun); |
| 5602 | if (!device_data) { |
| 5603 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5604 | device_data = lpfc_create_device_data(phba, |
| 5605 | &vport->fc_portname, |
| 5606 | &target_wwpn, |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5607 | sdev->lun, |
| 5608 | phba->cfg_XLanePriority, |
| 5609 | true); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5610 | if (!device_data) |
| 5611 | return -ENOMEM; |
| 5612 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5613 | list_add_tail(&device_data->listentry, &phba->luns); |
| 5614 | } |
| 5615 | device_data->rport_data = rport->dd_data; |
| 5616 | device_data->available = true; |
| 5617 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5618 | sdev->hostdata = device_data; |
| 5619 | } else { |
| 5620 | sdev->hostdata = rport->dd_data; |
| 5621 | } |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5622 | sdev_cnt = atomic_inc_return(&phba->sdev_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5623 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 5624 | /* For SLI4, all IO buffers are pre-allocated */ |
| 5625 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 5626 | return 0; |
| 5627 | |
| 5628 | /* This code path is now ONLY for SLI3 adapters */ |
| 5629 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5630 | /* |
| 5631 | * Populate the cmds_per_lun count scsi_bufs into this host's globally |
| 5632 | * 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] | 5633 | * HBA limit conveyed to the midlayer via the host structure. The |
| 5634 | * formula accounts for the lun_queue_depth + error handlers + 1 |
| 5635 | * extra. This list of scsi bufs exists for the lifetime of the driver. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5636 | */ |
| 5637 | total = phba->total_scsi_bufs; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5638 | num_to_alloc = vport->cfg_lun_queue_depth + 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5639 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5640 | /* If allocated buffers are enough do nothing */ |
| 5641 | if ((sdev_cnt * (vport->cfg_lun_queue_depth + 2)) < total) |
| 5642 | return 0; |
| 5643 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5644 | /* Allow some exchanges to be available always to complete discovery */ |
| 5645 | if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5646 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 5647 | "0704 At limitation of %d preallocated " |
| 5648 | "command buffers\n", total); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5649 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5650 | /* Allow some exchanges to be available always to complete discovery */ |
| 5651 | } else if (total + num_to_alloc > |
| 5652 | phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5653 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 5654 | "0705 Allocation request of %d " |
| 5655 | "command buffers will exceed max of %d. " |
| 5656 | "Reducing allocation request to %d.\n", |
| 5657 | num_to_alloc, phba->cfg_hba_queue_depth, |
| 5658 | (phba->cfg_hba_queue_depth - total)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5659 | num_to_alloc = phba->cfg_hba_queue_depth - total; |
| 5660 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 5661 | num_allocated = lpfc_new_scsi_buf_s3(vport, num_to_alloc); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5662 | if (num_to_alloc != num_allocated) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5663 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5664 | "0708 Allocation request of %d " |
| 5665 | "command buffers did not succeed. " |
| 5666 | "Allocated %d buffers.\n", |
| 5667 | num_to_alloc, num_allocated); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5668 | } |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5669 | if (num_allocated > 0) |
| 5670 | phba->total_scsi_bufs += num_allocated; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5671 | return 0; |
| 5672 | } |
| 5673 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5674 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5675 | * lpfc_slave_configure - scsi_host_template slave_configure entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5676 | * @sdev: Pointer to scsi_device. |
| 5677 | * |
| 5678 | * This routine configures following items |
| 5679 | * - Tag command queuing support for @sdev if supported. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5680 | * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set. |
| 5681 | * |
| 5682 | * Return codes: |
| 5683 | * 0 - Success |
| 5684 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5685 | static int |
| 5686 | lpfc_slave_configure(struct scsi_device *sdev) |
| 5687 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5688 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 5689 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5690 | |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 5691 | scsi_change_queue_depth(sdev, vport->cfg_lun_queue_depth); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5692 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5693 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 5694 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5695 | &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5696 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 5697 | lpfc_poll_rearm_timer(phba); |
| 5698 | } |
| 5699 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5700 | return 0; |
| 5701 | } |
| 5702 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5703 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5704 | * lpfc_slave_destroy - slave_destroy entry point of SHT data structure |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5705 | * @sdev: Pointer to scsi_device. |
| 5706 | * |
| 5707 | * This routine sets @sdev hostatdata filed to null. |
| 5708 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5709 | static void |
| 5710 | lpfc_slave_destroy(struct scsi_device *sdev) |
| 5711 | { |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5712 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 5713 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5714 | unsigned long flags; |
| 5715 | struct lpfc_device_data *device_data = sdev->hostdata; |
| 5716 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5717 | atomic_dec(&phba->sdev_cnt); |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5718 | if ((phba->cfg_fof) && (device_data)) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5719 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5720 | device_data->available = false; |
| 5721 | if (!device_data->oas_enabled) |
| 5722 | lpfc_delete_device_data(phba, device_data); |
| 5723 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5724 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5725 | sdev->hostdata = NULL; |
| 5726 | return; |
| 5727 | } |
| 5728 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5729 | /** |
| 5730 | * lpfc_create_device_data - creates and initializes device data structure for OAS |
| 5731 | * @pha: Pointer to host bus adapter structure. |
| 5732 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5733 | * @target_wwpn: Pointer to target's wwpn information |
| 5734 | * @lun: Lun on target |
| 5735 | * @atomic_create: Flag to indicate if memory should be allocated using the |
| 5736 | * GFP_ATOMIC flag or not. |
| 5737 | * |
| 5738 | * This routine creates a device data structure which will contain identifying |
| 5739 | * information for the device (host wwpn, target wwpn, lun), state of OAS, |
| 5740 | * whether or not the corresponding lun is available by the system, |
| 5741 | * and pointer to the rport data. |
| 5742 | * |
| 5743 | * Return codes: |
| 5744 | * NULL - Error |
| 5745 | * Pointer to lpfc_device_data - Success |
| 5746 | **/ |
| 5747 | struct lpfc_device_data* |
| 5748 | lpfc_create_device_data(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn, |
| 5749 | struct lpfc_name *target_wwpn, uint64_t lun, |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5750 | uint32_t pri, bool atomic_create) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5751 | { |
| 5752 | |
| 5753 | struct lpfc_device_data *lun_info; |
| 5754 | int memory_flags; |
| 5755 | |
| 5756 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5757 | !(phba->cfg_fof)) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5758 | return NULL; |
| 5759 | |
| 5760 | /* Attempt to create the device data to contain lun info */ |
| 5761 | |
| 5762 | if (atomic_create) |
| 5763 | memory_flags = GFP_ATOMIC; |
| 5764 | else |
| 5765 | memory_flags = GFP_KERNEL; |
| 5766 | lun_info = mempool_alloc(phba->device_data_mem_pool, memory_flags); |
| 5767 | if (!lun_info) |
| 5768 | return NULL; |
| 5769 | INIT_LIST_HEAD(&lun_info->listentry); |
| 5770 | lun_info->rport_data = NULL; |
| 5771 | memcpy(&lun_info->device_id.vport_wwpn, vport_wwpn, |
| 5772 | sizeof(struct lpfc_name)); |
| 5773 | memcpy(&lun_info->device_id.target_wwpn, target_wwpn, |
| 5774 | sizeof(struct lpfc_name)); |
| 5775 | lun_info->device_id.lun = lun; |
| 5776 | lun_info->oas_enabled = false; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5777 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5778 | lun_info->available = false; |
| 5779 | return lun_info; |
| 5780 | } |
| 5781 | |
| 5782 | /** |
| 5783 | * lpfc_delete_device_data - frees a device data structure for OAS |
| 5784 | * @pha: Pointer to host bus adapter structure. |
| 5785 | * @lun_info: Pointer to device data structure to free. |
| 5786 | * |
| 5787 | * This routine frees the previously allocated device data structure passed. |
| 5788 | * |
| 5789 | **/ |
| 5790 | void |
| 5791 | lpfc_delete_device_data(struct lpfc_hba *phba, |
| 5792 | struct lpfc_device_data *lun_info) |
| 5793 | { |
| 5794 | |
| 5795 | if (unlikely(!phba) || !lun_info || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5796 | !(phba->cfg_fof)) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5797 | return; |
| 5798 | |
| 5799 | if (!list_empty(&lun_info->listentry)) |
| 5800 | list_del(&lun_info->listentry); |
| 5801 | mempool_free(lun_info, phba->device_data_mem_pool); |
| 5802 | return; |
| 5803 | } |
| 5804 | |
| 5805 | /** |
| 5806 | * __lpfc_get_device_data - returns the device data for the specified lun |
| 5807 | * @pha: Pointer to host bus adapter structure. |
| 5808 | * @list: Point to list to search. |
| 5809 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5810 | * @target_wwpn: Pointer to target's wwpn information |
| 5811 | * @lun: Lun on target |
| 5812 | * |
| 5813 | * This routine searches the list passed for the specified lun's device data. |
| 5814 | * This function does not hold locks, it is the responsibility of the caller |
| 5815 | * to ensure the proper lock is held before calling the function. |
| 5816 | * |
| 5817 | * Return codes: |
| 5818 | * NULL - Error |
| 5819 | * Pointer to lpfc_device_data - Success |
| 5820 | **/ |
| 5821 | struct lpfc_device_data* |
| 5822 | __lpfc_get_device_data(struct lpfc_hba *phba, struct list_head *list, |
| 5823 | struct lpfc_name *vport_wwpn, |
| 5824 | struct lpfc_name *target_wwpn, uint64_t lun) |
| 5825 | { |
| 5826 | |
| 5827 | struct lpfc_device_data *lun_info; |
| 5828 | |
| 5829 | if (unlikely(!phba) || !list || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5830 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5831 | return NULL; |
| 5832 | |
| 5833 | /* Check to see if the lun is already enabled for OAS. */ |
| 5834 | |
| 5835 | list_for_each_entry(lun_info, list, listentry) { |
| 5836 | if ((memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn, |
| 5837 | sizeof(struct lpfc_name)) == 0) && |
| 5838 | (memcmp(&lun_info->device_id.target_wwpn, target_wwpn, |
| 5839 | sizeof(struct lpfc_name)) == 0) && |
| 5840 | (lun_info->device_id.lun == lun)) |
| 5841 | return lun_info; |
| 5842 | } |
| 5843 | |
| 5844 | return NULL; |
| 5845 | } |
| 5846 | |
| 5847 | /** |
| 5848 | * lpfc_find_next_oas_lun - searches for the next oas lun |
| 5849 | * @pha: Pointer to host bus adapter structure. |
| 5850 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5851 | * @target_wwpn: Pointer to target's wwpn information |
| 5852 | * @starting_lun: Pointer to the lun to start searching for |
| 5853 | * @found_vport_wwpn: Pointer to the found lun's vport wwpn information |
| 5854 | * @found_target_wwpn: Pointer to the found lun's target wwpn information |
| 5855 | * @found_lun: Pointer to the found lun. |
| 5856 | * @found_lun_status: Pointer to status of the found lun. |
| 5857 | * |
| 5858 | * This routine searches the luns list for the specified lun |
| 5859 | * or the first lun for the vport/target. If the vport wwpn contains |
| 5860 | * a zero value then a specific vport is not specified. In this case |
| 5861 | * any vport which contains the lun will be considered a match. If the |
| 5862 | * target wwpn contains a zero value then a specific target is not specified. |
| 5863 | * In this case any target which contains the lun will be considered a |
| 5864 | * match. If the lun is found, the lun, vport wwpn, target wwpn and lun status |
| 5865 | * are returned. The function will also return the next lun if available. |
| 5866 | * If the next lun is not found, starting_lun parameter will be set to |
| 5867 | * NO_MORE_OAS_LUN. |
| 5868 | * |
| 5869 | * Return codes: |
| 5870 | * non-0 - Error |
| 5871 | * 0 - Success |
| 5872 | **/ |
| 5873 | bool |
| 5874 | lpfc_find_next_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn, |
| 5875 | struct lpfc_name *target_wwpn, uint64_t *starting_lun, |
| 5876 | struct lpfc_name *found_vport_wwpn, |
| 5877 | struct lpfc_name *found_target_wwpn, |
| 5878 | uint64_t *found_lun, |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5879 | uint32_t *found_lun_status, |
| 5880 | uint32_t *found_lun_pri) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5881 | { |
| 5882 | |
| 5883 | unsigned long flags; |
| 5884 | struct lpfc_device_data *lun_info; |
| 5885 | struct lpfc_device_id *device_id; |
| 5886 | uint64_t lun; |
| 5887 | bool found = false; |
| 5888 | |
| 5889 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
| 5890 | !starting_lun || !found_vport_wwpn || |
| 5891 | !found_target_wwpn || !found_lun || !found_lun_status || |
| 5892 | (*starting_lun == NO_MORE_OAS_LUN) || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5893 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5894 | return false; |
| 5895 | |
| 5896 | lun = *starting_lun; |
| 5897 | *found_lun = NO_MORE_OAS_LUN; |
| 5898 | *starting_lun = NO_MORE_OAS_LUN; |
| 5899 | |
| 5900 | /* Search for lun or the lun closet in value */ |
| 5901 | |
| 5902 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5903 | list_for_each_entry(lun_info, &phba->luns, listentry) { |
| 5904 | if (((wwn_to_u64(vport_wwpn->u.wwn) == 0) || |
| 5905 | (memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn, |
| 5906 | sizeof(struct lpfc_name)) == 0)) && |
| 5907 | ((wwn_to_u64(target_wwpn->u.wwn) == 0) || |
| 5908 | (memcmp(&lun_info->device_id.target_wwpn, target_wwpn, |
| 5909 | sizeof(struct lpfc_name)) == 0)) && |
| 5910 | (lun_info->oas_enabled)) { |
| 5911 | device_id = &lun_info->device_id; |
| 5912 | if ((!found) && |
| 5913 | ((lun == FIND_FIRST_OAS_LUN) || |
| 5914 | (device_id->lun == lun))) { |
| 5915 | *found_lun = device_id->lun; |
| 5916 | memcpy(found_vport_wwpn, |
| 5917 | &device_id->vport_wwpn, |
| 5918 | sizeof(struct lpfc_name)); |
| 5919 | memcpy(found_target_wwpn, |
| 5920 | &device_id->target_wwpn, |
| 5921 | sizeof(struct lpfc_name)); |
| 5922 | if (lun_info->available) |
| 5923 | *found_lun_status = |
| 5924 | OAS_LUN_STATUS_EXISTS; |
| 5925 | else |
| 5926 | *found_lun_status = 0; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5927 | *found_lun_pri = lun_info->priority; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5928 | if (phba->cfg_oas_flags & OAS_FIND_ANY_VPORT) |
| 5929 | memset(vport_wwpn, 0x0, |
| 5930 | sizeof(struct lpfc_name)); |
| 5931 | if (phba->cfg_oas_flags & OAS_FIND_ANY_TARGET) |
| 5932 | memset(target_wwpn, 0x0, |
| 5933 | sizeof(struct lpfc_name)); |
| 5934 | found = true; |
| 5935 | } else if (found) { |
| 5936 | *starting_lun = device_id->lun; |
| 5937 | memcpy(vport_wwpn, &device_id->vport_wwpn, |
| 5938 | sizeof(struct lpfc_name)); |
| 5939 | memcpy(target_wwpn, &device_id->target_wwpn, |
| 5940 | sizeof(struct lpfc_name)); |
| 5941 | break; |
| 5942 | } |
| 5943 | } |
| 5944 | } |
| 5945 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5946 | return found; |
| 5947 | } |
| 5948 | |
| 5949 | /** |
| 5950 | * lpfc_enable_oas_lun - enables a lun for OAS operations |
| 5951 | * @pha: Pointer to host bus adapter structure. |
| 5952 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5953 | * @target_wwpn: Pointer to target's wwpn information |
| 5954 | * @lun: Lun |
| 5955 | * |
| 5956 | * This routine enables a lun for oas operations. The routines does so by |
| 5957 | * doing the following : |
| 5958 | * |
| 5959 | * 1) Checks to see if the device data for the lun has been created. |
| 5960 | * 2) If found, sets the OAS enabled flag if not set and returns. |
| 5961 | * 3) Otherwise, creates a device data structure. |
| 5962 | * 4) If successfully created, indicates the device data is for an OAS lun, |
| 5963 | * indicates the lun is not available and add to the list of luns. |
| 5964 | * |
| 5965 | * Return codes: |
| 5966 | * false - Error |
| 5967 | * true - Success |
| 5968 | **/ |
| 5969 | bool |
| 5970 | 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] | 5971 | struct lpfc_name *target_wwpn, uint64_t lun, uint8_t pri) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5972 | { |
| 5973 | |
| 5974 | struct lpfc_device_data *lun_info; |
| 5975 | unsigned long flags; |
| 5976 | |
| 5977 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5978 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5979 | return false; |
| 5980 | |
| 5981 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5982 | |
| 5983 | /* Check to see if the device data for the lun has been created */ |
| 5984 | lun_info = __lpfc_get_device_data(phba, &phba->luns, vport_wwpn, |
| 5985 | target_wwpn, lun); |
| 5986 | if (lun_info) { |
| 5987 | if (!lun_info->oas_enabled) |
| 5988 | lun_info->oas_enabled = true; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5989 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5990 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5991 | return true; |
| 5992 | } |
| 5993 | |
| 5994 | /* Create an lun info structure and add to list of luns */ |
| 5995 | lun_info = lpfc_create_device_data(phba, vport_wwpn, target_wwpn, lun, |
James Smart | 2d71dc8 | 2019-05-21 17:48:51 -0700 | [diff] [blame] | 5996 | pri, true); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5997 | if (lun_info) { |
| 5998 | lun_info->oas_enabled = true; |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 5999 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6000 | lun_info->available = false; |
| 6001 | list_add_tail(&lun_info->listentry, &phba->luns); |
| 6002 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 6003 | return true; |
| 6004 | } |
| 6005 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 6006 | return false; |
| 6007 | } |
| 6008 | |
| 6009 | /** |
| 6010 | * lpfc_disable_oas_lun - disables a lun for OAS operations |
| 6011 | * @pha: Pointer to host bus adapter structure. |
| 6012 | * @vport_wwpn: Pointer to vport's wwpn information |
| 6013 | * @target_wwpn: Pointer to target's wwpn information |
| 6014 | * @lun: Lun |
| 6015 | * |
| 6016 | * This routine disables a lun for oas operations. The routines does so by |
| 6017 | * doing the following : |
| 6018 | * |
| 6019 | * 1) Checks to see if the device data for the lun is created. |
| 6020 | * 2) If present, clears the flag indicating this lun is for OAS. |
| 6021 | * 3) If the lun is not available by the system, the device data is |
| 6022 | * freed. |
| 6023 | * |
| 6024 | * Return codes: |
| 6025 | * false - Error |
| 6026 | * true - Success |
| 6027 | **/ |
| 6028 | bool |
| 6029 | 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] | 6030 | struct lpfc_name *target_wwpn, uint64_t lun, uint8_t pri) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6031 | { |
| 6032 | |
| 6033 | struct lpfc_device_data *lun_info; |
| 6034 | unsigned long flags; |
| 6035 | |
| 6036 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 6037 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6038 | return false; |
| 6039 | |
| 6040 | spin_lock_irqsave(&phba->devicelock, flags); |
| 6041 | |
| 6042 | /* Check to see if the lun is available. */ |
| 6043 | lun_info = __lpfc_get_device_data(phba, |
| 6044 | &phba->luns, vport_wwpn, |
| 6045 | target_wwpn, lun); |
| 6046 | if (lun_info) { |
| 6047 | lun_info->oas_enabled = false; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 6048 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6049 | if (!lun_info->available) |
| 6050 | lpfc_delete_device_data(phba, lun_info); |
| 6051 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 6052 | return true; |
| 6053 | } |
| 6054 | |
| 6055 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 6056 | return false; |
| 6057 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6058 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6059 | static int |
| 6060 | lpfc_no_command(struct Scsi_Host *shost, struct scsi_cmnd *cmnd) |
| 6061 | { |
| 6062 | return SCSI_MLQUEUE_HOST_BUSY; |
| 6063 | } |
| 6064 | |
| 6065 | static int |
| 6066 | lpfc_no_handler(struct scsi_cmnd *cmnd) |
| 6067 | { |
| 6068 | return FAILED; |
| 6069 | } |
| 6070 | |
| 6071 | static int |
| 6072 | lpfc_no_slave(struct scsi_device *sdev) |
| 6073 | { |
| 6074 | return -ENODEV; |
| 6075 | } |
| 6076 | |
| 6077 | struct scsi_host_template lpfc_template_nvme = { |
| 6078 | .module = THIS_MODULE, |
| 6079 | .name = LPFC_DRIVER_NAME, |
| 6080 | .proc_name = LPFC_DRIVER_NAME, |
| 6081 | .info = lpfc_info, |
| 6082 | .queuecommand = lpfc_no_command, |
| 6083 | .eh_abort_handler = lpfc_no_handler, |
| 6084 | .eh_device_reset_handler = lpfc_no_handler, |
| 6085 | .eh_target_reset_handler = lpfc_no_handler, |
| 6086 | .eh_bus_reset_handler = lpfc_no_handler, |
| 6087 | .eh_host_reset_handler = lpfc_no_handler, |
| 6088 | .slave_alloc = lpfc_no_slave, |
| 6089 | .slave_configure = lpfc_no_slave, |
| 6090 | .scan_finished = lpfc_scan_finished, |
| 6091 | .this_id = -1, |
| 6092 | .sg_tablesize = 1, |
| 6093 | .cmd_per_lun = 1, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6094 | .shost_attrs = lpfc_hba_attrs, |
| 6095 | .max_sectors = 0xFFFF, |
| 6096 | .vendor_id = LPFC_NL_VENDOR_ID, |
| 6097 | .track_queue_depth = 0, |
| 6098 | }; |
| 6099 | |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 6100 | struct scsi_host_template lpfc_template_no_hr = { |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 6101 | .module = THIS_MODULE, |
| 6102 | .name = LPFC_DRIVER_NAME, |
James Smart | 08dcd4c | 2016-07-06 12:35:59 -0700 | [diff] [blame] | 6103 | .proc_name = LPFC_DRIVER_NAME, |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 6104 | .info = lpfc_info, |
| 6105 | .queuecommand = lpfc_queuecommand, |
James Smart | 856984b | 2017-03-04 09:30:32 -0800 | [diff] [blame] | 6106 | .eh_timed_out = fc_eh_timed_out, |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 6107 | .eh_abort_handler = lpfc_abort_handler, |
| 6108 | .eh_device_reset_handler = lpfc_device_reset_handler, |
| 6109 | .eh_target_reset_handler = lpfc_target_reset_handler, |
| 6110 | .eh_bus_reset_handler = lpfc_bus_reset_handler, |
| 6111 | .slave_alloc = lpfc_slave_alloc, |
| 6112 | .slave_configure = lpfc_slave_configure, |
| 6113 | .slave_destroy = lpfc_slave_destroy, |
| 6114 | .scan_finished = lpfc_scan_finished, |
| 6115 | .this_id = -1, |
| 6116 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
| 6117 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 6118 | .shost_attrs = lpfc_hba_attrs, |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 6119 | .max_sectors = 0xFFFFFFFF, |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 6120 | .vendor_id = LPFC_NL_VENDOR_ID, |
| 6121 | .change_queue_depth = scsi_change_queue_depth, |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 6122 | .track_queue_depth = 1, |
| 6123 | }; |
| 6124 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6125 | struct scsi_host_template lpfc_template = { |
| 6126 | .module = THIS_MODULE, |
| 6127 | .name = LPFC_DRIVER_NAME, |
James Smart | 08dcd4c | 2016-07-06 12:35:59 -0700 | [diff] [blame] | 6128 | .proc_name = LPFC_DRIVER_NAME, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6129 | .info = lpfc_info, |
| 6130 | .queuecommand = lpfc_queuecommand, |
Christoph Hellwig | b6a05c8 | 2017-01-30 13:18:58 +0100 | [diff] [blame] | 6131 | .eh_timed_out = fc_eh_timed_out, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6132 | .eh_abort_handler = lpfc_abort_handler, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6133 | .eh_device_reset_handler = lpfc_device_reset_handler, |
| 6134 | .eh_target_reset_handler = lpfc_target_reset_handler, |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 6135 | .eh_bus_reset_handler = lpfc_bus_reset_handler, |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 6136 | .eh_host_reset_handler = lpfc_host_reset_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6137 | .slave_alloc = lpfc_slave_alloc, |
| 6138 | .slave_configure = lpfc_slave_configure, |
| 6139 | .slave_destroy = lpfc_slave_destroy, |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 6140 | .scan_finished = lpfc_scan_finished, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6141 | .this_id = -1, |
James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 6142 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6143 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6144 | .shost_attrs = lpfc_hba_attrs, |
James.Smart@Emulex.Com | 564b296 | 2005-06-25 10:34:17 -0400 | [diff] [blame] | 6145 | .max_sectors = 0xFFFF, |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 6146 | .vendor_id = LPFC_NL_VENDOR_ID, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 6147 | .change_queue_depth = scsi_change_queue_depth, |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 6148 | .track_queue_depth = 1, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6149 | }; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6150 | |
| 6151 | struct scsi_host_template lpfc_vport_template = { |
| 6152 | .module = THIS_MODULE, |
| 6153 | .name = LPFC_DRIVER_NAME, |
James Smart | 08dcd4c | 2016-07-06 12:35:59 -0700 | [diff] [blame] | 6154 | .proc_name = LPFC_DRIVER_NAME, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6155 | .info = lpfc_info, |
| 6156 | .queuecommand = lpfc_queuecommand, |
Christoph Hellwig | b6a05c8 | 2017-01-30 13:18:58 +0100 | [diff] [blame] | 6157 | .eh_timed_out = fc_eh_timed_out, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6158 | .eh_abort_handler = lpfc_abort_handler, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6159 | .eh_device_reset_handler = lpfc_device_reset_handler, |
| 6160 | .eh_target_reset_handler = lpfc_target_reset_handler, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6161 | .slave_alloc = lpfc_slave_alloc, |
| 6162 | .slave_configure = lpfc_slave_configure, |
| 6163 | .slave_destroy = lpfc_slave_destroy, |
| 6164 | .scan_finished = lpfc_scan_finished, |
| 6165 | .this_id = -1, |
James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 6166 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6167 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6168 | .shost_attrs = lpfc_vport_attrs, |
| 6169 | .max_sectors = 0xFFFF, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 6170 | .change_queue_depth = scsi_change_queue_depth, |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 6171 | .track_queue_depth = 1, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6172 | }; |