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