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 | 67073c6 | 2021-03-01 09:18:21 -0800 | [diff] [blame] | 4 | * Copyright (C) 2017-2021 Broadcom. All Rights Reserved. The term * |
| 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> |
Gaurav Srivastava | dc50715 | 2021-06-08 10:05:51 +0530 | [diff] [blame] | 31 | #include <linux/blk-cgroup.h> |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 32 | #include <net/checksum.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 33 | |
| 34 | #include <scsi/scsi.h> |
| 35 | #include <scsi/scsi_device.h> |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 36 | #include <scsi/scsi_eh.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 37 | #include <scsi/scsi_host.h> |
| 38 | #include <scsi/scsi_tcq.h> |
| 39 | #include <scsi/scsi_transport_fc.h> |
| 40 | |
| 41 | #include "lpfc_version.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 42 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 43 | #include "lpfc_hw.h" |
| 44 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 45 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 46 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 47 | #include "lpfc_disc.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 48 | #include "lpfc.h" |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 49 | #include "lpfc_scsi.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 50 | #include "lpfc_logmsg.h" |
| 51 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 52 | #include "lpfc_vport.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 53 | |
| 54 | #define LPFC_RESET_WAIT 2 |
| 55 | #define LPFC_ABORT_WAIT 2 |
| 56 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 57 | static char *dif_op_str[] = { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 58 | "PROT_NORMAL", |
| 59 | "PROT_READ_INSERT", |
| 60 | "PROT_WRITE_STRIP", |
| 61 | "PROT_READ_STRIP", |
| 62 | "PROT_WRITE_INSERT", |
| 63 | "PROT_READ_PASS", |
| 64 | "PROT_WRITE_PASS", |
| 65 | }; |
| 66 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 67 | struct scsi_dif_tuple { |
| 68 | __be16 guard_tag; /* Checksum */ |
| 69 | __be16 app_tag; /* Opaque storage */ |
| 70 | __be32 ref_tag; /* Target LBA or indirect LBA */ |
| 71 | }; |
| 72 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 73 | static struct lpfc_rport_data * |
| 74 | lpfc_rport_data_from_scsi_device(struct scsi_device *sdev) |
| 75 | { |
| 76 | struct lpfc_vport *vport = (struct lpfc_vport *)sdev->host->hostdata; |
| 77 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 78 | if (vport->phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 79 | return ((struct lpfc_device_data *)sdev->hostdata)->rport_data; |
| 80 | else |
| 81 | return (struct lpfc_rport_data *)sdev->hostdata; |
| 82 | } |
| 83 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 84 | static void |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 85 | 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] | 86 | static void |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 87 | 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] | 88 | static int |
| 89 | lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc); |
Gaurav Srivastava | dc50715 | 2021-06-08 10:05:51 +0530 | [diff] [blame] | 90 | static void |
| 91 | lpfc_put_vmid_in_hashtable(struct lpfc_vport *vport, u32 hash, |
| 92 | struct lpfc_vmid *vmp); |
| 93 | static void lpfc_vmid_update_entry(struct lpfc_vport *vport, struct scsi_cmnd |
| 94 | *cmd, struct lpfc_vmid *vmp, |
| 95 | union lpfc_vmid_io_tag *tag); |
| 96 | static void lpfc_vmid_assign_cs_ctl(struct lpfc_vport *vport, |
| 97 | struct lpfc_vmid *vmid); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 98 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 99 | static inline unsigned |
| 100 | lpfc_cmd_blksize(struct scsi_cmnd *sc) |
| 101 | { |
| 102 | return sc->device->sector_size; |
| 103 | } |
| 104 | |
| 105 | #define LPFC_CHECK_PROTECT_GUARD 1 |
| 106 | #define LPFC_CHECK_PROTECT_REF 2 |
| 107 | static inline unsigned |
| 108 | lpfc_cmd_protect(struct scsi_cmnd *sc, int flag) |
| 109 | { |
| 110 | return 1; |
| 111 | } |
| 112 | |
| 113 | static inline unsigned |
| 114 | lpfc_cmd_guard_csum(struct scsi_cmnd *sc) |
| 115 | { |
| 116 | if (lpfc_prot_group_type(NULL, sc) == LPFC_PG_TYPE_NO_DIF) |
| 117 | return 0; |
| 118 | if (scsi_host_get_guard(sc->device->host) == SHOST_DIX_GUARD_IP) |
| 119 | return 1; |
| 120 | return 0; |
| 121 | } |
| 122 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 123 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 124 | * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge. |
| 125 | * @phba: Pointer to HBA object. |
| 126 | * @lpfc_cmd: lpfc scsi command object pointer. |
| 127 | * |
| 128 | * This function is called from the lpfc_prep_task_mgmt_cmd function to |
| 129 | * set the last bit in the response sge entry. |
| 130 | **/ |
| 131 | static void |
| 132 | lpfc_sli4_set_rsp_sgl_last(struct lpfc_hba *phba, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 133 | struct lpfc_io_buf *lpfc_cmd) |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 134 | { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 135 | struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 136 | if (sgl) { |
| 137 | sgl += 1; |
| 138 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 139 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 140 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 141 | } |
| 142 | } |
| 143 | |
James Smart | 68a6a66 | 2021-03-01 09:18:02 -0800 | [diff] [blame] | 144 | #define LPFC_INVALID_REFTAG ((u32)-1) |
| 145 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 146 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 147 | * lpfc_update_stats - Update statistical data for the command completion |
James Smart | 9df0a03 | 2019-09-21 20:58:54 -0700 | [diff] [blame] | 148 | * @vport: The virtual port on which this call is executing. |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 149 | * @lpfc_cmd: lpfc scsi command object pointer. |
| 150 | * |
| 151 | * This function is called when there is a command completion and this |
| 152 | * function updates the statistical data for the command completion. |
| 153 | **/ |
| 154 | static void |
James Smart | 9df0a03 | 2019-09-21 20:58:54 -0700 | [diff] [blame] | 155 | lpfc_update_stats(struct lpfc_vport *vport, struct lpfc_io_buf *lpfc_cmd) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 156 | { |
James Smart | 9df0a03 | 2019-09-21 20:58:54 -0700 | [diff] [blame] | 157 | struct lpfc_hba *phba = vport->phba; |
James Smart | 18027a8 | 2018-09-10 10:30:49 -0700 | [diff] [blame] | 158 | struct lpfc_rport_data *rdata; |
| 159 | struct lpfc_nodelist *pnode; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 160 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 161 | unsigned long flags; |
James Smart | 9df0a03 | 2019-09-21 20:58:54 -0700 | [diff] [blame] | 162 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 163 | unsigned long latency; |
| 164 | int i; |
| 165 | |
James Smart | 18027a8 | 2018-09-10 10:30:49 -0700 | [diff] [blame] | 166 | if (!vport->stat_data_enabled || |
| 167 | vport->stat_data_blocked || |
| 168 | (cmd->result)) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 169 | return; |
| 170 | |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 171 | latency = jiffies_to_msecs((long)jiffies - (long)lpfc_cmd->start_time); |
James Smart | 18027a8 | 2018-09-10 10:30:49 -0700 | [diff] [blame] | 172 | rdata = lpfc_cmd->rdata; |
| 173 | pnode = rdata->pnode; |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 174 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 175 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | 18027a8 | 2018-09-10 10:30:49 -0700 | [diff] [blame] | 176 | if (!pnode || |
| 177 | !pnode->lat_data || |
| 178 | (phba->bucket_type == LPFC_NO_BUCKET)) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 179 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 180 | return; |
| 181 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 182 | |
| 183 | if (phba->bucket_type == LPFC_LINEAR_BUCKET) { |
| 184 | i = (latency + phba->bucket_step - 1 - phba->bucket_base)/ |
| 185 | phba->bucket_step; |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 186 | /* check array subscript bounds */ |
| 187 | if (i < 0) |
| 188 | i = 0; |
| 189 | else if (i >= LPFC_MAX_BUCKET_COUNT) |
| 190 | i = LPFC_MAX_BUCKET_COUNT - 1; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 191 | } else { |
| 192 | for (i = 0; i < LPFC_MAX_BUCKET_COUNT-1; i++) |
| 193 | if (latency <= (phba->bucket_base + |
| 194 | ((1<<i)*phba->bucket_step))) |
| 195 | break; |
| 196 | } |
| 197 | |
| 198 | pnode->lat_data[i].cmd_count++; |
| 199 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 200 | } |
| 201 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 202 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 203 | * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 204 | * @phba: The Hba for which this call is being executed. |
| 205 | * |
| 206 | * This routine is called when there is resource error in driver or firmware. |
| 207 | * This routine posts WORKER_RAMP_DOWN_QUEUE event for @phba. This routine |
| 208 | * posts at most 1 event each second. This routine wakes up worker thread of |
| 209 | * @phba to process WORKER_RAM_DOWN_EVENT event. |
| 210 | * |
| 211 | * This routine should be called with no lock held. |
| 212 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 213 | void |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 214 | lpfc_rampdown_queue_depth(struct lpfc_hba *phba) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 215 | { |
| 216 | unsigned long flags; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 217 | uint32_t evt_posted; |
Manuel Schölling | 0d4aec1 | 2014-09-03 12:55:58 -0400 | [diff] [blame] | 218 | unsigned long expires; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 219 | |
| 220 | spin_lock_irqsave(&phba->hbalock, flags); |
| 221 | atomic_inc(&phba->num_rsrc_err); |
| 222 | phba->last_rsrc_error_time = jiffies; |
| 223 | |
Manuel Schölling | 0d4aec1 | 2014-09-03 12:55:58 -0400 | [diff] [blame] | 224 | expires = phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL; |
| 225 | if (time_after(expires, jiffies)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 226 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 227 | return; |
| 228 | } |
| 229 | |
| 230 | phba->last_ramp_down_time = jiffies; |
| 231 | |
| 232 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 233 | |
| 234 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 235 | evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE; |
| 236 | if (!evt_posted) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 237 | phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 238 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
| 239 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 240 | if (!evt_posted) |
| 241 | lpfc_worker_wake_up(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 242 | return; |
| 243 | } |
| 244 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 245 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 246 | * lpfc_ramp_down_queue_handler - WORKER_RAMP_DOWN_QUEUE event handler |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 247 | * @phba: The Hba for which this call is being executed. |
| 248 | * |
| 249 | * This routine is called to process WORKER_RAMP_DOWN_QUEUE event for worker |
| 250 | * thread.This routine reduces queue depth for all scsi device on each vport |
| 251 | * associated with @phba. |
| 252 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 253 | void |
| 254 | lpfc_ramp_down_queue_handler(struct lpfc_hba *phba) |
| 255 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 256 | struct lpfc_vport **vports; |
| 257 | struct Scsi_Host *shost; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 258 | struct scsi_device *sdev; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 259 | unsigned long new_queue_depth; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 260 | unsigned long num_rsrc_err, num_cmd_success; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 261 | int i; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 262 | |
| 263 | num_rsrc_err = atomic_read(&phba->num_rsrc_err); |
| 264 | num_cmd_success = atomic_read(&phba->num_cmd_success); |
| 265 | |
James Smart | 75ad83a | 2012-05-09 21:18:40 -0400 | [diff] [blame] | 266 | /* |
| 267 | * The error and success command counters are global per |
| 268 | * driver instance. If another handler has already |
| 269 | * operated on this error event, just exit. |
| 270 | */ |
| 271 | if (num_rsrc_err == 0) |
| 272 | return; |
| 273 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 274 | vports = lpfc_create_vport_work_array(phba); |
| 275 | if (vports != NULL) |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 276 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 277 | shost = lpfc_shost_from_vport(vports[i]); |
| 278 | shost_for_each_device(sdev, shost) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 279 | new_queue_depth = |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 280 | sdev->queue_depth * num_rsrc_err / |
| 281 | (num_rsrc_err + num_cmd_success); |
| 282 | if (!new_queue_depth) |
| 283 | new_queue_depth = sdev->queue_depth - 1; |
| 284 | else |
| 285 | new_queue_depth = sdev->queue_depth - |
| 286 | new_queue_depth; |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 287 | scsi_change_queue_depth(sdev, new_queue_depth); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 288 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 289 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 290 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 291 | atomic_set(&phba->num_rsrc_err, 0); |
| 292 | atomic_set(&phba->num_cmd_success, 0); |
| 293 | } |
| 294 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 295 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 296 | * lpfc_scsi_dev_block - set all scsi hosts to block state |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 297 | * @phba: Pointer to HBA context object. |
| 298 | * |
| 299 | * This function walks vport list and set each SCSI host to block state |
| 300 | * by invoking fc_remote_port_delete() routine. This function is invoked |
| 301 | * with EEH when device's PCI slot has been permanently disabled. |
| 302 | **/ |
| 303 | void |
| 304 | lpfc_scsi_dev_block(struct lpfc_hba *phba) |
| 305 | { |
| 306 | struct lpfc_vport **vports; |
| 307 | struct Scsi_Host *shost; |
| 308 | struct scsi_device *sdev; |
| 309 | struct fc_rport *rport; |
| 310 | int i; |
| 311 | |
| 312 | vports = lpfc_create_vport_work_array(phba); |
| 313 | if (vports != NULL) |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 314 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 315 | shost = lpfc_shost_from_vport(vports[i]); |
| 316 | shost_for_each_device(sdev, shost) { |
| 317 | rport = starget_to_rport(scsi_target(sdev)); |
| 318 | fc_remote_port_delete(rport); |
| 319 | } |
| 320 | } |
| 321 | lpfc_destroy_vport_work_array(phba, vports); |
| 322 | } |
| 323 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 324 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 325 | * 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] | 326 | * @vport: The virtual port for which this call being executed. |
Lee Jones | eceee00 | 2020-11-02 14:23:43 +0000 | [diff] [blame] | 327 | * @num_to_alloc: The requested number of buffers to allocate. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 328 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 329 | * This routine allocates a scsi buffer for device with SLI-3 interface spec, |
| 330 | * the scsi buffer contains all the necessary information needed to initiate |
| 331 | * a SCSI I/O. The non-DMAable buffer region contains information to build |
| 332 | * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP, |
| 333 | * and the initial BPL. In addition to allocating memory, the FCP CMND and |
| 334 | * 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] | 335 | * |
| 336 | * Return codes: |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 337 | * int - number of scsi buffers that were allocated. |
| 338 | * 0 = failure, less than num_to_alloc is a partial failure. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 339 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 340 | static int |
| 341 | lpfc_new_scsi_buf_s3(struct lpfc_vport *vport, int num_to_alloc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 342 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 343 | struct lpfc_hba *phba = vport->phba; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 344 | struct lpfc_io_buf *psb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 345 | struct ulp_bde64 *bpl; |
| 346 | IOCB_t *iocb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 347 | dma_addr_t pdma_phys_fcp_cmd; |
| 348 | dma_addr_t pdma_phys_fcp_rsp; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 349 | dma_addr_t pdma_phys_sgl; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 350 | uint16_t iotag; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 351 | int bcnt, bpl_size; |
| 352 | |
| 353 | bpl_size = phba->cfg_sg_dma_buf_size - |
| 354 | (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); |
| 355 | |
| 356 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 357 | "9067 ALLOC %d scsi_bufs: %d (%d + %d + %d)\n", |
| 358 | num_to_alloc, phba->cfg_sg_dma_buf_size, |
| 359 | (int)sizeof(struct fcp_cmnd), |
| 360 | (int)sizeof(struct fcp_rsp), bpl_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 361 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 362 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 363 | psb = kzalloc(sizeof(struct lpfc_io_buf), GFP_KERNEL); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 364 | if (!psb) |
| 365 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 366 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 367 | /* |
| 368 | * Get memory from the pci pool to map the virt space to pci |
| 369 | * bus space for an I/O. The DMA buffer includes space for the |
| 370 | * struct fcp_cmnd, struct fcp_rsp and the number of bde's |
| 371 | * necessary to support the sg_tablesize. |
| 372 | */ |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 373 | psb->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 374 | GFP_KERNEL, &psb->dma_handle); |
| 375 | if (!psb->data) { |
| 376 | kfree(psb); |
| 377 | break; |
| 378 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 379 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 380 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 381 | /* Allocate iotag for psb->cur_iocbq. */ |
| 382 | iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq); |
| 383 | if (iotag == 0) { |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 384 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 385 | psb->data, psb->dma_handle); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 386 | kfree(psb); |
| 387 | break; |
| 388 | } |
| 389 | psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 390 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 391 | psb->fcp_cmnd = psb->data; |
| 392 | psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 393 | psb->dma_sgl = psb->data + sizeof(struct fcp_cmnd) + |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 394 | sizeof(struct fcp_rsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 395 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 396 | /* Initialize local short-hand pointers. */ |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 397 | bpl = (struct ulp_bde64 *)psb->dma_sgl; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 398 | pdma_phys_fcp_cmd = psb->dma_handle; |
| 399 | pdma_phys_fcp_rsp = psb->dma_handle + sizeof(struct fcp_cmnd); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 400 | pdma_phys_sgl = psb->dma_handle + sizeof(struct fcp_cmnd) + |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 401 | sizeof(struct fcp_rsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 402 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 403 | /* |
| 404 | * The first two bdes are the FCP_CMD and FCP_RSP. The balance |
| 405 | * are sg list bdes. Initialize the first two and leave the |
| 406 | * rest for queuecommand. |
| 407 | */ |
| 408 | bpl[0].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd)); |
| 409 | bpl[0].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd)); |
| 410 | bpl[0].tus.f.bdeSize = sizeof(struct fcp_cmnd); |
| 411 | bpl[0].tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 412 | bpl[0].tus.w = le32_to_cpu(bpl[0].tus.w); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 413 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 414 | /* Setup the physical region for the FCP RSP */ |
| 415 | bpl[1].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp)); |
| 416 | bpl[1].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp)); |
| 417 | bpl[1].tus.f.bdeSize = sizeof(struct fcp_rsp); |
| 418 | bpl[1].tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 419 | bpl[1].tus.w = le32_to_cpu(bpl[1].tus.w); |
| 420 | |
| 421 | /* |
| 422 | * Since the IOCB for the FCP I/O is built into this |
| 423 | * lpfc_scsi_buf, initialize it with all known data now. |
| 424 | */ |
| 425 | iocb = &psb->cur_iocbq.iocb; |
| 426 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; |
| 427 | if ((phba->sli_rev == 3) && |
| 428 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) { |
| 429 | /* fill in immediate fcp command BDE */ |
| 430 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_IMMED; |
| 431 | iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); |
| 432 | iocb->un.fcpi64.bdl.addrLow = offsetof(IOCB_t, |
| 433 | unsli3.fcp_ext.icd); |
| 434 | iocb->un.fcpi64.bdl.addrHigh = 0; |
| 435 | iocb->ulpBdeCount = 0; |
| 436 | iocb->ulpLe = 0; |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 437 | /* fill in response BDE */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 438 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeFlags = |
| 439 | BUFF_TYPE_BDE_64; |
| 440 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeSize = |
| 441 | sizeof(struct fcp_rsp); |
| 442 | iocb->unsli3.fcp_ext.rbde.addrLow = |
| 443 | putPaddrLow(pdma_phys_fcp_rsp); |
| 444 | iocb->unsli3.fcp_ext.rbde.addrHigh = |
| 445 | putPaddrHigh(pdma_phys_fcp_rsp); |
| 446 | } else { |
| 447 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
| 448 | iocb->un.fcpi64.bdl.bdeSize = |
| 449 | (2 * sizeof(struct ulp_bde64)); |
| 450 | iocb->un.fcpi64.bdl.addrLow = |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 451 | putPaddrLow(pdma_phys_sgl); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 452 | iocb->un.fcpi64.bdl.addrHigh = |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 453 | putPaddrHigh(pdma_phys_sgl); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 454 | iocb->ulpBdeCount = 1; |
| 455 | iocb->ulpLe = 1; |
| 456 | } |
| 457 | iocb->ulpClass = CLASS3; |
| 458 | psb->status = IOSTAT_SUCCESS; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 459 | /* Put it back into the SCSI buffer list */ |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 460 | psb->cur_iocbq.context1 = psb; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 461 | spin_lock_init(&psb->buf_lock); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 462 | lpfc_release_scsi_buf_s3(phba, psb); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 463 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 464 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 465 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 466 | return bcnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 467 | } |
| 468 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 469 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 470 | * lpfc_sli4_vport_delete_fcp_xri_aborted -Remove all ndlp references for vport |
| 471 | * @vport: pointer to lpfc vport data structure. |
| 472 | * |
| 473 | * This routine is invoked by the vport cleanup for deletions and the cleanup |
| 474 | * for an ndlp on removal. |
| 475 | **/ |
| 476 | void |
| 477 | lpfc_sli4_vport_delete_fcp_xri_aborted(struct lpfc_vport *vport) |
| 478 | { |
| 479 | struct lpfc_hba *phba = vport->phba; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 480 | struct lpfc_io_buf *psb, *next_psb; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 481 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 482 | unsigned long iflag = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 483 | int idx; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 484 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 485 | if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 486 | return; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 487 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 488 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 489 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 490 | qp = &phba->sli4_hba.hdwq[idx]; |
| 491 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 492 | spin_lock(&qp->abts_io_buf_list_lock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 493 | list_for_each_entry_safe(psb, next_psb, |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 494 | &qp->lpfc_abts_io_buf_list, list) { |
James Smart | c438d06 | 2019-12-18 15:58:07 -0800 | [diff] [blame] | 495 | if (psb->cur_iocbq.iocb_flag & LPFC_IO_NVME) |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 496 | continue; |
| 497 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 498 | if (psb->rdata && psb->rdata->pnode && |
| 499 | psb->rdata->pnode->vport == vport) |
| 500 | psb->rdata = NULL; |
| 501 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 502 | spin_unlock(&qp->abts_io_buf_list_lock); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 503 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 504 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 505 | } |
| 506 | |
| 507 | /** |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 508 | * lpfc_sli4_io_xri_aborted - Fast-path process of fcp xri abort |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 509 | * @phba: pointer to lpfc hba data structure. |
| 510 | * @axri: pointer to the fcp xri abort wcqe structure. |
Lee Jones | eceee00 | 2020-11-02 14:23:43 +0000 | [diff] [blame] | 511 | * @idx: index into hdwq |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 512 | * |
| 513 | * This routine is invoked by the worker thread to process a SLI4 fast-path |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 514 | * FCP or NVME aborted xri. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 515 | **/ |
| 516 | void |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 517 | lpfc_sli4_io_xri_aborted(struct lpfc_hba *phba, |
| 518 | struct sli4_wcqe_xri_aborted *axri, int idx) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 519 | { |
| 520 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 521 | uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 522 | struct lpfc_io_buf *psb, *next_psb; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 523 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 524 | unsigned long iflag = 0; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 525 | struct lpfc_iocbq *iocbq; |
| 526 | int i; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 527 | struct lpfc_nodelist *ndlp; |
| 528 | int rrq_empty = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 529 | struct lpfc_sli_ring *pring = phba->sli4_hba.els_wq->pring; |
James Smart | 3e49af9 | 2021-05-14 12:55:57 -0700 | [diff] [blame] | 530 | struct scsi_cmnd *cmd; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [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 | |
| 535 | qp = &phba->sli4_hba.hdwq[idx]; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 536 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 537 | spin_lock(&qp->abts_io_buf_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 538 | list_for_each_entry_safe(psb, next_psb, |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 539 | &qp->lpfc_abts_io_buf_list, list) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 540 | if (psb->cur_iocbq.sli4_xritag == xri) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 541 | list_del_init(&psb->list); |
James Smart | 324e1c4 | 2019-10-18 14:18:21 -0700 | [diff] [blame] | 542 | psb->flags &= ~LPFC_SBUF_XBUSY; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 543 | psb->status = IOSTAT_SUCCESS; |
James Smart | c438d06 | 2019-12-18 15:58:07 -0800 | [diff] [blame] | 544 | if (psb->cur_iocbq.iocb_flag & LPFC_IO_NVME) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 545 | qp->abts_nvme_io_bufs--; |
| 546 | spin_unlock(&qp->abts_io_buf_list_lock); |
| 547 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 548 | lpfc_sli4_nvme_xri_aborted(phba, axri, psb); |
| 549 | return; |
| 550 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 551 | qp->abts_scsi_io_bufs--; |
| 552 | spin_unlock(&qp->abts_io_buf_list_lock); |
| 553 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 554 | if (psb->rdata && psb->rdata->pnode) |
| 555 | ndlp = psb->rdata->pnode; |
| 556 | else |
| 557 | ndlp = NULL; |
| 558 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 559 | rrq_empty = list_empty(&phba->active_rrq_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 560 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 561 | if (ndlp) { |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 562 | lpfc_set_rrq_active(phba, ndlp, |
| 563 | psb->cur_iocbq.sli4_lxritag, rxid, 1); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 564 | lpfc_sli4_abts_err_handler(phba, ndlp, axri); |
| 565 | } |
James Smart | 3e49af9 | 2021-05-14 12:55:57 -0700 | [diff] [blame] | 566 | |
| 567 | if (phba->cfg_fcp_wait_abts_rsp) { |
| 568 | spin_lock_irqsave(&psb->buf_lock, iflag); |
| 569 | cmd = psb->pCmd; |
| 570 | psb->pCmd = NULL; |
| 571 | spin_unlock_irqrestore(&psb->buf_lock, iflag); |
| 572 | |
| 573 | /* The sdev is not guaranteed to be valid post |
| 574 | * scsi_done upcall. |
| 575 | */ |
| 576 | if (cmd) |
| 577 | cmd->scsi_done(cmd); |
| 578 | |
| 579 | /* |
| 580 | * We expect there is an abort thread waiting |
| 581 | * for command completion wake up the thread. |
| 582 | */ |
| 583 | spin_lock_irqsave(&psb->buf_lock, iflag); |
| 584 | psb->cur_iocbq.iocb_flag &= |
| 585 | ~LPFC_DRIVER_ABORTED; |
| 586 | if (psb->waitq) |
| 587 | wake_up(psb->waitq); |
| 588 | spin_unlock_irqrestore(&psb->buf_lock, iflag); |
| 589 | } |
| 590 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 591 | lpfc_release_scsi_buf_s4(phba, psb); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 592 | if (rrq_empty) |
| 593 | lpfc_worker_wake_up(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 594 | return; |
| 595 | } |
| 596 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 597 | spin_unlock(&qp->abts_io_buf_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 598 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 599 | iocbq = phba->sli.iocbq_lookup[i]; |
| 600 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 601 | if (!(iocbq->iocb_flag & LPFC_IO_FCP) || |
| 602 | (iocbq->iocb_flag & LPFC_IO_LIBDFC)) |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 603 | continue; |
| 604 | if (iocbq->sli4_xritag != xri) |
| 605 | continue; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 606 | psb = container_of(iocbq, struct lpfc_io_buf, cur_iocbq); |
James Smart | 324e1c4 | 2019-10-18 14:18:21 -0700 | [diff] [blame] | 607 | psb->flags &= ~LPFC_SBUF_XBUSY; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 608 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 609 | if (!list_empty(&pring->txq)) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 610 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 611 | return; |
| 612 | |
| 613 | } |
| 614 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 618 | * 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] | 619 | * @phba: The HBA for which this call is being executed. |
Lee Jones | eceee00 | 2020-11-02 14:23:43 +0000 | [diff] [blame] | 620 | * @ndlp: pointer to a node-list data structure. |
| 621 | * @cmnd: Pointer to scsi_cmnd data structure. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 622 | * |
| 623 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list |
| 624 | * and returns to caller. |
| 625 | * |
| 626 | * Return codes: |
| 627 | * NULL - Error |
| 628 | * Pointer to lpfc_scsi_buf - Success |
| 629 | **/ |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 630 | static struct lpfc_io_buf * |
James Smart | ace44e4 | 2019-01-28 11:14:27 -0800 | [diff] [blame] | 631 | lpfc_get_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
| 632 | struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 633 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 634 | struct lpfc_io_buf *lpfc_cmd = NULL; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 635 | 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] | 636 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 637 | |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 638 | spin_lock_irqsave(&phba->scsi_buf_list_get_lock, iflag); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 639 | 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] | 640 | list); |
| 641 | if (!lpfc_cmd) { |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 642 | spin_lock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 643 | list_splice(&phba->lpfc_scsi_buf_list_put, |
| 644 | &phba->lpfc_scsi_buf_list_get); |
| 645 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
| 646 | list_remove_head(scsi_buf_list_get, lpfc_cmd, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 647 | struct lpfc_io_buf, list); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 648 | spin_unlock(&phba->scsi_buf_list_put_lock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 649 | } |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 650 | spin_unlock_irqrestore(&phba->scsi_buf_list_get_lock, iflag); |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 651 | |
| 652 | if (lpfc_ndlp_check_qdepth(phba, ndlp) && lpfc_cmd) { |
| 653 | atomic_inc(&ndlp->cmd_pending); |
| 654 | lpfc_cmd->flags |= LPFC_SBUF_BUMP_QDEPTH; |
| 655 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 656 | return lpfc_cmd; |
| 657 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 658 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 659 | * 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] | 660 | * @phba: The HBA for which this call is being executed. |
Lee Jones | eceee00 | 2020-11-02 14:23:43 +0000 | [diff] [blame] | 661 | * @ndlp: pointer to a node-list data structure. |
| 662 | * @cmnd: Pointer to scsi_cmnd data structure. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 663 | * |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 664 | * 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] | 665 | * and returns to caller. |
| 666 | * |
| 667 | * Return codes: |
| 668 | * NULL - Error |
| 669 | * Pointer to lpfc_scsi_buf - Success |
| 670 | **/ |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 671 | static struct lpfc_io_buf * |
James Smart | ace44e4 | 2019-01-28 11:14:27 -0800 | [diff] [blame] | 672 | lpfc_get_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
| 673 | struct scsi_cmnd *cmnd) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 674 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 675 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 676 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 677 | struct sli4_sge *sgl; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 678 | dma_addr_t pdma_phys_fcp_rsp; |
| 679 | dma_addr_t pdma_phys_fcp_cmd; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 680 | uint32_t cpu, idx; |
James Smart | ace44e4 | 2019-01-28 11:14:27 -0800 | [diff] [blame] | 681 | int tag; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 682 | struct fcp_cmd_rsp_buf *tmp = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 683 | |
Bart Van Assche | d6d189c | 2019-03-28 11:06:22 -0700 | [diff] [blame] | 684 | cpu = raw_smp_processor_id(); |
James Smart | 45aa312 | 2019-01-28 11:14:29 -0800 | [diff] [blame] | 685 | if (cmnd && phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_HDWQ) { |
Bart Van Assche | 4221c8a | 2021-08-09 16:03:30 -0700 | [diff] [blame] | 686 | tag = blk_mq_unique_tag(scsi_cmd_to_rq(cmnd)); |
James Smart | ace44e4 | 2019-01-28 11:14:27 -0800 | [diff] [blame] | 687 | idx = blk_mq_unique_tag_to_hwq(tag); |
| 688 | } else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 689 | idx = phba->sli4_hba.cpu_map[cpu].hdwq; |
James Smart | ace44e4 | 2019-01-28 11:14:27 -0800 | [diff] [blame] | 690 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 691 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 692 | lpfc_cmd = lpfc_get_io_buf(phba, ndlp, idx, |
| 693 | !phba->cfg_xri_rebalancing); |
| 694 | if (!lpfc_cmd) { |
| 695 | qp = &phba->sli4_hba.hdwq[idx]; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 696 | qp->empty_io_bufs++; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 697 | return NULL; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 698 | } |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 699 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 700 | /* Setup key fields in buffer that may have been changed |
| 701 | * if other protocols used this buffer. |
| 702 | */ |
| 703 | lpfc_cmd->cur_iocbq.iocb_flag = LPFC_IO_FCP; |
| 704 | lpfc_cmd->prot_seg_cnt = 0; |
| 705 | lpfc_cmd->seg_cnt = 0; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 706 | lpfc_cmd->timeout = 0; |
| 707 | lpfc_cmd->flags = 0; |
| 708 | lpfc_cmd->start_time = jiffies; |
| 709 | lpfc_cmd->waitq = NULL; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 710 | lpfc_cmd->cpu = cpu; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 711 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 712 | lpfc_cmd->prot_data_type = 0; |
| 713 | #endif |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 714 | tmp = lpfc_get_cmd_rsp_buf_per_hdwq(phba, lpfc_cmd); |
James Smart | 0ab384a | 2020-01-27 16:23:02 -0800 | [diff] [blame] | 715 | if (!tmp) { |
| 716 | lpfc_release_io_buf(phba, lpfc_cmd, lpfc_cmd->hdwq); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 717 | return NULL; |
James Smart | 0ab384a | 2020-01-27 16:23:02 -0800 | [diff] [blame] | 718 | } |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 719 | |
| 720 | lpfc_cmd->fcp_cmnd = tmp->fcp_cmnd; |
| 721 | lpfc_cmd->fcp_rsp = tmp->fcp_rsp; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 722 | |
| 723 | /* |
| 724 | * The first two SGEs are the FCP_CMD and FCP_RSP. |
| 725 | * The balance are sg list bdes. Initialize the |
| 726 | * first two and leave the rest for queuecommand. |
| 727 | */ |
| 728 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 729 | pdma_phys_fcp_cmd = tmp->fcp_cmd_rsp_dma_handle; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 730 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd)); |
| 731 | sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd)); |
| 732 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 733 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 734 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 735 | sgl->sge_len = cpu_to_le32(sizeof(struct fcp_cmnd)); |
| 736 | sgl++; |
| 737 | |
| 738 | /* Setup the physical region for the FCP RSP */ |
| 739 | pdma_phys_fcp_rsp = pdma_phys_fcp_cmd + sizeof(struct fcp_cmnd); |
| 740 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp)); |
| 741 | sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp)); |
| 742 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 743 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 744 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 745 | sgl->sge_len = cpu_to_le32(sizeof(struct fcp_rsp)); |
| 746 | |
Dan Carpenter | 26c724a | 2018-08-23 16:56:33 +0300 | [diff] [blame] | 747 | if (lpfc_ndlp_check_qdepth(phba, ndlp)) { |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 748 | atomic_inc(&ndlp->cmd_pending); |
| 749 | lpfc_cmd->flags |= LPFC_SBUF_BUMP_QDEPTH; |
| 750 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 751 | return lpfc_cmd; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 752 | } |
| 753 | /** |
| 754 | * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA |
| 755 | * @phba: The HBA for which this call is being executed. |
Lee Jones | eceee00 | 2020-11-02 14:23:43 +0000 | [diff] [blame] | 756 | * @ndlp: pointer to a node-list data structure. |
| 757 | * @cmnd: Pointer to scsi_cmnd data structure. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 758 | * |
| 759 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list |
| 760 | * and returns to caller. |
| 761 | * |
| 762 | * Return codes: |
| 763 | * NULL - Error |
| 764 | * Pointer to lpfc_scsi_buf - Success |
| 765 | **/ |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 766 | static struct lpfc_io_buf* |
James Smart | ace44e4 | 2019-01-28 11:14:27 -0800 | [diff] [blame] | 767 | lpfc_get_scsi_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
| 768 | struct scsi_cmnd *cmnd) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 769 | { |
James Smart | ace44e4 | 2019-01-28 11:14:27 -0800 | [diff] [blame] | 770 | return phba->lpfc_get_scsi_buf(phba, ndlp, cmnd); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 771 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 772 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 773 | /** |
Lee Jones | 0bb87e0 | 2021-03-12 09:47:11 +0000 | [diff] [blame] | 774 | * lpfc_release_scsi_buf_s3 - Return a scsi buffer back to hba scsi buf list |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 775 | * @phba: The Hba for which this call is being executed. |
| 776 | * @psb: The scsi buffer which is being released. |
| 777 | * |
| 778 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
| 779 | * lpfc_scsi_buf_list list. |
| 780 | **/ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 781 | static void |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 782 | 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] | 783 | { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 784 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 785 | |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 786 | psb->seg_cnt = 0; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 787 | psb->prot_seg_cnt = 0; |
| 788 | |
| 789 | spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 790 | psb->pCmd = NULL; |
James Smart | 6a485eb | 2013-04-17 20:19:00 -0400 | [diff] [blame] | 791 | psb->cur_iocbq.iocb_flag = LPFC_IO_FCP; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 792 | list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list_put); |
| 793 | spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 794 | } |
| 795 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 796 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 797 | * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list. |
| 798 | * @phba: The Hba for which this call is being executed. |
| 799 | * @psb: The scsi buffer which is being released. |
| 800 | * |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 801 | * This routine releases @psb scsi buffer by adding it to tail of @hdwq |
| 802 | * 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] | 803 | * and cannot be reused for at least RA_TOV amount of time if it was |
| 804 | * aborted. |
| 805 | **/ |
| 806 | static void |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 807 | 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] | 808 | { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 809 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 810 | unsigned long iflag = 0; |
| 811 | |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 812 | psb->seg_cnt = 0; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 813 | psb->prot_seg_cnt = 0; |
| 814 | |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 815 | qp = psb->hdwq; |
James Smart | 324e1c4 | 2019-10-18 14:18:21 -0700 | [diff] [blame] | 816 | if (psb->flags & LPFC_SBUF_XBUSY) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 817 | spin_lock_irqsave(&qp->abts_io_buf_list_lock, iflag); |
James Smart | 3e49af9 | 2021-05-14 12:55:57 -0700 | [diff] [blame] | 818 | if (!phba->cfg_fcp_wait_abts_rsp) |
| 819 | psb->pCmd = NULL; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 820 | list_add_tail(&psb->list, &qp->lpfc_abts_io_buf_list); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 821 | qp->abts_scsi_io_bufs++; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 822 | spin_unlock_irqrestore(&qp->abts_io_buf_list_lock, iflag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 823 | } else { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 824 | lpfc_release_io_buf(phba, (struct lpfc_io_buf *)psb, qp); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 825 | } |
| 826 | } |
| 827 | |
| 828 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 829 | * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list. |
| 830 | * @phba: The Hba for which this call is being executed. |
| 831 | * @psb: The scsi buffer which is being released. |
| 832 | * |
| 833 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
| 834 | * lpfc_scsi_buf_list list. |
| 835 | **/ |
| 836 | static void |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 837 | 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] | 838 | { |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 839 | if ((psb->flags & LPFC_SBUF_BUMP_QDEPTH) && psb->ndlp) |
| 840 | atomic_dec(&psb->ndlp->cmd_pending); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 841 | |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 842 | psb->flags &= ~LPFC_SBUF_BUMP_QDEPTH; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 843 | phba->lpfc_release_scsi_buf(phba, psb); |
| 844 | } |
| 845 | |
| 846 | /** |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 847 | * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB |
| 848 | * @data: A pointer to the immediate command data portion of the IOCB. |
| 849 | * @fcp_cmnd: The FCP Command that is provided by the SCSI layer. |
| 850 | * |
| 851 | * The routine copies the entire FCP command from @fcp_cmnd to @data while |
| 852 | * byte swapping the data to big endian format for transmission on the wire. |
| 853 | **/ |
| 854 | static void |
| 855 | lpfc_fcpcmd_to_iocb(u8 *data, struct fcp_cmnd *fcp_cmnd) |
| 856 | { |
| 857 | int i, j; |
| 858 | |
| 859 | for (i = 0, j = 0; i < sizeof(struct fcp_cmnd); |
| 860 | i += sizeof(uint32_t), j++) { |
| 861 | ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]); |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 866 | * 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] | 867 | * @phba: The Hba for which this call is being executed. |
| 868 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 869 | * |
| 870 | * 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] | 871 | * 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] | 872 | * through sg elements and format the bde. This routine also initializes all |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 873 | * IOCB fields which are dependent on scsi command request buffer. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 874 | * |
| 875 | * Return codes: |
| 876 | * 1 - Error |
| 877 | * 0 - Success |
| 878 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 879 | static int |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 880 | 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] | 881 | { |
| 882 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 883 | struct scatterlist *sgel = NULL; |
| 884 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 885 | struct ulp_bde64 *bpl = (struct ulp_bde64 *)lpfc_cmd->dma_sgl; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 886 | struct lpfc_iocbq *iocbq = &lpfc_cmd->cur_iocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 887 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 888 | struct ulp_bde64 *data_bde = iocb_cmd->unsli3.fcp_ext.dbde; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 889 | dma_addr_t physaddr; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 890 | uint32_t num_bde = 0; |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 891 | int nseg, datadir = scsi_cmnd->sc_data_direction; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 892 | |
| 893 | /* |
| 894 | * There are three possibilities here - use scatter-gather segment, use |
| 895 | * the single mapping, or neither. Start the lpfc command prep by |
| 896 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 897 | * data bde entry. |
| 898 | */ |
| 899 | bpl += 2; |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 900 | if (scsi_sg_count(scsi_cmnd)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 901 | /* |
| 902 | * The driver stores the segment count returned from pci_map_sg |
| 903 | * because this a count of dma-mappings used to map the use_sg |
| 904 | * pages. They are not guaranteed to be the same for those |
| 905 | * architectures that implement an IOMMU. |
| 906 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 907 | |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 908 | nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd), |
| 909 | scsi_sg_count(scsi_cmnd), datadir); |
| 910 | if (unlikely(!nseg)) |
| 911 | return 1; |
| 912 | |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 913 | lpfc_cmd->seg_cnt = nseg; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 914 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 915 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 916 | "9064 BLKGRD: %s: Too many sg segments" |
| 917 | " from dma_map_sg. Config %d, seg_cnt" |
| 918 | " %d\n", __func__, phba->cfg_sg_seg_cnt, |
| 919 | lpfc_cmd->seg_cnt); |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 920 | WARN_ON_ONCE(lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 921 | lpfc_cmd->seg_cnt = 0; |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 922 | scsi_dma_unmap(scsi_cmnd); |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 923 | return 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | /* |
| 927 | * The driver established a maximum scatter-gather segment count |
| 928 | * during probe that limits the number of sg elements in any |
| 929 | * single scsi command. Just run through the seg_cnt and format |
| 930 | * the bde's. |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 931 | * When using SLI-3 the driver will try to fit all the BDEs into |
| 932 | * the IOCB. If it can't then the BDEs get added to a BPL as it |
| 933 | * does for SLI-2 mode. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 934 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 935 | scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 936 | physaddr = sg_dma_address(sgel); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 937 | if (phba->sli_rev == 3 && |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 938 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 939 | !(iocbq->iocb_flag & DSS_SECURITY_OP) && |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 940 | nseg <= LPFC_EXT_DATA_BDE_COUNT) { |
| 941 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 942 | data_bde->tus.f.bdeSize = sg_dma_len(sgel); |
| 943 | data_bde->addrLow = putPaddrLow(physaddr); |
| 944 | data_bde->addrHigh = putPaddrHigh(physaddr); |
| 945 | data_bde++; |
| 946 | } else { |
| 947 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 948 | bpl->tus.f.bdeSize = sg_dma_len(sgel); |
| 949 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 950 | bpl->addrLow = |
| 951 | le32_to_cpu(putPaddrLow(physaddr)); |
| 952 | bpl->addrHigh = |
| 953 | le32_to_cpu(putPaddrHigh(physaddr)); |
| 954 | bpl++; |
| 955 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 956 | } |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 957 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 958 | |
| 959 | /* |
| 960 | * Finish initializing those IOCB fields that are dependent on the |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 961 | * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is |
| 962 | * explicitly reinitialized and for SLI-3 the extended bde count is |
| 963 | * explicitly reinitialized since all iocb memory resources are reused. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 964 | */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 965 | if (phba->sli_rev == 3 && |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 966 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
| 967 | !(iocbq->iocb_flag & DSS_SECURITY_OP)) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 968 | if (num_bde > LPFC_EXT_DATA_BDE_COUNT) { |
| 969 | /* |
| 970 | * The extended IOCB format can only fit 3 BDE or a BPL. |
| 971 | * This I/O has more than 3 BDE so the 1st data bde will |
| 972 | * be a BPL that is filled in here. |
| 973 | */ |
| 974 | physaddr = lpfc_cmd->dma_handle; |
| 975 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BLP_64; |
| 976 | data_bde->tus.f.bdeSize = (num_bde * |
| 977 | sizeof(struct ulp_bde64)); |
| 978 | physaddr += (sizeof(struct fcp_cmnd) + |
| 979 | sizeof(struct fcp_rsp) + |
| 980 | (2 * sizeof(struct ulp_bde64))); |
| 981 | data_bde->addrHigh = putPaddrHigh(physaddr); |
| 982 | data_bde->addrLow = putPaddrLow(physaddr); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 983 | /* ebde count includes the response bde and data bpl */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 984 | iocb_cmd->unsli3.fcp_ext.ebde_count = 2; |
| 985 | } else { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 986 | /* ebde count includes the response bde and data bdes */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 987 | iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); |
| 988 | } |
| 989 | } else { |
| 990 | iocb_cmd->un.fcpi64.bdl.bdeSize = |
| 991 | ((num_bde + 2) * sizeof(struct ulp_bde64)); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 992 | iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 993 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 994 | fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 995 | |
| 996 | /* |
| 997 | * Due to difference in data length between DIF/non-DIF paths, |
| 998 | * we need to set word 4 of IOCB here |
| 999 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1000 | iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd); |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 1001 | lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1002 | return 0; |
| 1003 | } |
| 1004 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1005 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1006 | |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1007 | /* Return BG_ERR_INIT if error injection is detected by Initiator */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1008 | #define BG_ERR_INIT 0x1 |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1009 | /* Return BG_ERR_TGT if error injection is detected by Target */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1010 | #define BG_ERR_TGT 0x2 |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1011 | /* 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] | 1012 | #define BG_ERR_SWAP 0x10 |
Lee Jones | 0bb87e0 | 2021-03-12 09:47:11 +0000 | [diff] [blame] | 1013 | /* |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1014 | * Return BG_ERR_CHECK if disabling Guard/Ref/App checking is required for |
| 1015 | * error injection |
Lee Jones | 0bb87e0 | 2021-03-12 09:47:11 +0000 | [diff] [blame] | 1016 | */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1017 | #define BG_ERR_CHECK 0x20 |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1018 | |
| 1019 | /** |
| 1020 | * lpfc_bg_err_inject - Determine if we should inject an error |
| 1021 | * @phba: The Hba for which this call is being executed. |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1022 | * @sc: The SCSI command to examine |
| 1023 | * @reftag: (out) BlockGuard reference tag for transmitted data |
| 1024 | * @apptag: (out) BlockGuard application tag for transmitted data |
Lee Jones | eceee00 | 2020-11-02 14:23:43 +0000 | [diff] [blame] | 1025 | * @new_guard: (in) Value to replace CRC with if needed |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1026 | * |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1027 | * Returns BG_ERR_* bit mask or 0 if request ignored |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1028 | **/ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1029 | static int |
| 1030 | lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1031 | uint32_t *reftag, uint16_t *apptag, uint32_t new_guard) |
| 1032 | { |
| 1033 | struct scatterlist *sgpe; /* s/g prot entry */ |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1034 | struct lpfc_io_buf *lpfc_cmd = NULL; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1035 | struct scsi_dif_tuple *src = NULL; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1036 | struct lpfc_nodelist *ndlp; |
| 1037 | struct lpfc_rport_data *rdata; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1038 | uint32_t op = scsi_get_prot_op(sc); |
| 1039 | uint32_t blksize; |
| 1040 | uint32_t numblks; |
James Smart | 68a6a66 | 2021-03-01 09:18:02 -0800 | [diff] [blame] | 1041 | u32 lba; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1042 | int rc = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1043 | int blockoff = 0; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1044 | |
| 1045 | if (op == SCSI_PROT_NORMAL) |
| 1046 | return 0; |
| 1047 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1048 | sgpe = scsi_prot_sglist(sc); |
Bart Van Assche | 4221c8a | 2021-08-09 16:03:30 -0700 | [diff] [blame] | 1049 | lba = t10_pi_ref_tag(scsi_cmd_to_rq(sc)); |
James Smart | 68a6a66 | 2021-03-01 09:18:02 -0800 | [diff] [blame] | 1050 | if (lba == LPFC_INVALID_REFTAG) |
| 1051 | return 0; |
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 */ |
James Smart | 68a6a66 | 2021-03-01 09:18:02 -0800 | [diff] [blame] | 1059 | if (phba->lpfc_injerr_lba < (u64)lba || |
| 1060 | (phba->lpfc_injerr_lba >= (u64)(lba + numblks))) |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1061 | return 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1062 | if (sgpe) { |
James Smart | 68a6a66 | 2021-03-01 09:18:02 -0800 | [diff] [blame] | 1063 | blockoff = phba->lpfc_injerr_lba - (u64)lba; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 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 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1112 | lpfc_printf_log(phba, KERN_ERR, |
| 1113 | LOG_TRACE_EVENT, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1114 | "9076 BLKGRD: Injecting reftag error: " |
| 1115 | "write lba x%lx + x%x oldrefTag x%x\n", |
| 1116 | (unsigned long)lba, blockoff, |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1117 | be32_to_cpu(src->ref_tag)); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1118 | |
| 1119 | /* |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1120 | * Save the old ref_tag so we can |
| 1121 | * restore it on completion. |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1122 | */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1123 | if (lpfc_cmd) { |
| 1124 | lpfc_cmd->prot_data_type = |
| 1125 | LPFC_INJERR_REFTAG; |
| 1126 | lpfc_cmd->prot_data_segment = |
| 1127 | src; |
| 1128 | lpfc_cmd->prot_data = |
| 1129 | src->ref_tag; |
| 1130 | } |
| 1131 | src->ref_tag = cpu_to_be32(0xDEADBEEF); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1132 | phba->lpfc_injerr_wref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1133 | if (phba->lpfc_injerr_wref_cnt == 0) { |
| 1134 | phba->lpfc_injerr_nportid = 0; |
| 1135 | phba->lpfc_injerr_lba = |
| 1136 | LPFC_INJERR_LBA_OFF; |
| 1137 | memset(&phba->lpfc_injerr_wwpn, |
| 1138 | 0, sizeof(struct lpfc_name)); |
| 1139 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1140 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
| 1141 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1142 | break; |
| 1143 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1144 | fallthrough; |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1145 | case SCSI_PROT_WRITE_INSERT: |
| 1146 | /* |
| 1147 | * For WRITE_INSERT, force the error |
| 1148 | * to be sent on the wire. It should be |
| 1149 | * detected by the Target. |
| 1150 | */ |
| 1151 | /* DEADBEEF will be the reftag on the wire */ |
| 1152 | *reftag = 0xDEADBEEF; |
| 1153 | phba->lpfc_injerr_wref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1154 | if (phba->lpfc_injerr_wref_cnt == 0) { |
| 1155 | phba->lpfc_injerr_nportid = 0; |
| 1156 | phba->lpfc_injerr_lba = |
| 1157 | LPFC_INJERR_LBA_OFF; |
| 1158 | memset(&phba->lpfc_injerr_wwpn, |
| 1159 | 0, sizeof(struct lpfc_name)); |
| 1160 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1161 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
| 1162 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1163 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1164 | "9078 BLKGRD: Injecting reftag error: " |
| 1165 | "write lba x%lx\n", (unsigned long)lba); |
| 1166 | break; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1167 | case SCSI_PROT_WRITE_STRIP: |
| 1168 | /* |
| 1169 | * For WRITE_STRIP and WRITE_PASS, |
| 1170 | * force the error on data |
| 1171 | * being copied from SLI-Host to SLI-Port. |
| 1172 | */ |
| 1173 | *reftag = 0xDEADBEEF; |
| 1174 | phba->lpfc_injerr_wref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1175 | if (phba->lpfc_injerr_wref_cnt == 0) { |
| 1176 | phba->lpfc_injerr_nportid = 0; |
| 1177 | phba->lpfc_injerr_lba = |
| 1178 | LPFC_INJERR_LBA_OFF; |
| 1179 | memset(&phba->lpfc_injerr_wwpn, |
| 1180 | 0, sizeof(struct lpfc_name)); |
| 1181 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1182 | rc = BG_ERR_INIT; |
| 1183 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1184 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1185 | "9077 BLKGRD: Injecting reftag error: " |
| 1186 | "write lba x%lx\n", (unsigned long)lba); |
| 1187 | break; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1188 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1189 | } |
| 1190 | if (phba->lpfc_injerr_rref_cnt) { |
| 1191 | switch (op) { |
| 1192 | case SCSI_PROT_READ_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1193 | case SCSI_PROT_READ_STRIP: |
| 1194 | case SCSI_PROT_READ_PASS: |
| 1195 | /* |
| 1196 | * For READ_STRIP and READ_PASS, force the |
| 1197 | * error on data being read off the wire. It |
| 1198 | * should force an IO error to the driver. |
| 1199 | */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1200 | *reftag = 0xDEADBEEF; |
| 1201 | phba->lpfc_injerr_rref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1202 | if (phba->lpfc_injerr_rref_cnt == 0) { |
| 1203 | phba->lpfc_injerr_nportid = 0; |
| 1204 | phba->lpfc_injerr_lba = |
| 1205 | LPFC_INJERR_LBA_OFF; |
| 1206 | memset(&phba->lpfc_injerr_wwpn, |
| 1207 | 0, sizeof(struct lpfc_name)); |
| 1208 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1209 | rc = BG_ERR_INIT; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1210 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1211 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1212 | "9079 BLKGRD: Injecting reftag error: " |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1213 | "read lba x%lx\n", (unsigned long)lba); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1214 | break; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1215 | } |
| 1216 | } |
| 1217 | } |
| 1218 | |
| 1219 | /* Should we change the Application Tag */ |
| 1220 | if (apptag) { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1221 | if (phba->lpfc_injerr_wapp_cnt) { |
| 1222 | switch (op) { |
| 1223 | case SCSI_PROT_WRITE_PASS: |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1224 | if (src) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1225 | /* |
| 1226 | * For WRITE_PASS, force the error |
| 1227 | * to be sent on the wire. It should |
| 1228 | * be detected by the Target. |
| 1229 | * If blockoff != 0 error will be |
| 1230 | * inserted in middle of the IO. |
| 1231 | */ |
| 1232 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1233 | lpfc_printf_log(phba, KERN_ERR, |
| 1234 | LOG_TRACE_EVENT, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1235 | "9080 BLKGRD: Injecting apptag error: " |
| 1236 | "write lba x%lx + x%x oldappTag x%x\n", |
| 1237 | (unsigned long)lba, blockoff, |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1238 | be16_to_cpu(src->app_tag)); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1239 | |
| 1240 | /* |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1241 | * Save the old app_tag so we can |
| 1242 | * restore it on completion. |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1243 | */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1244 | if (lpfc_cmd) { |
| 1245 | lpfc_cmd->prot_data_type = |
| 1246 | LPFC_INJERR_APPTAG; |
| 1247 | lpfc_cmd->prot_data_segment = |
| 1248 | src; |
| 1249 | lpfc_cmd->prot_data = |
| 1250 | src->app_tag; |
| 1251 | } |
| 1252 | src->app_tag = cpu_to_be16(0xDEAD); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1253 | phba->lpfc_injerr_wapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1254 | if (phba->lpfc_injerr_wapp_cnt == 0) { |
| 1255 | phba->lpfc_injerr_nportid = 0; |
| 1256 | phba->lpfc_injerr_lba = |
| 1257 | LPFC_INJERR_LBA_OFF; |
| 1258 | memset(&phba->lpfc_injerr_wwpn, |
| 1259 | 0, sizeof(struct lpfc_name)); |
| 1260 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1261 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1262 | break; |
| 1263 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1264 | fallthrough; |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1265 | case SCSI_PROT_WRITE_INSERT: |
| 1266 | /* |
| 1267 | * For WRITE_INSERT, force the |
| 1268 | * error to be sent on the wire. It should be |
| 1269 | * detected by the Target. |
| 1270 | */ |
| 1271 | /* DEAD will be the apptag on the wire */ |
| 1272 | *apptag = 0xDEAD; |
| 1273 | phba->lpfc_injerr_wapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1274 | if (phba->lpfc_injerr_wapp_cnt == 0) { |
| 1275 | phba->lpfc_injerr_nportid = 0; |
| 1276 | phba->lpfc_injerr_lba = |
| 1277 | LPFC_INJERR_LBA_OFF; |
| 1278 | memset(&phba->lpfc_injerr_wwpn, |
| 1279 | 0, sizeof(struct lpfc_name)); |
| 1280 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1281 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
| 1282 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1283 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1284 | "0813 BLKGRD: Injecting apptag error: " |
| 1285 | "write lba x%lx\n", (unsigned long)lba); |
| 1286 | break; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1287 | case SCSI_PROT_WRITE_STRIP: |
| 1288 | /* |
| 1289 | * For WRITE_STRIP and WRITE_PASS, |
| 1290 | * force the error on data |
| 1291 | * being copied from SLI-Host to SLI-Port. |
| 1292 | */ |
| 1293 | *apptag = 0xDEAD; |
| 1294 | phba->lpfc_injerr_wapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1295 | if (phba->lpfc_injerr_wapp_cnt == 0) { |
| 1296 | phba->lpfc_injerr_nportid = 0; |
| 1297 | phba->lpfc_injerr_lba = |
| 1298 | LPFC_INJERR_LBA_OFF; |
| 1299 | memset(&phba->lpfc_injerr_wwpn, |
| 1300 | 0, sizeof(struct lpfc_name)); |
| 1301 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1302 | rc = BG_ERR_INIT; |
| 1303 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1304 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1305 | "0812 BLKGRD: Injecting apptag error: " |
| 1306 | "write lba x%lx\n", (unsigned long)lba); |
| 1307 | break; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1308 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1309 | } |
| 1310 | if (phba->lpfc_injerr_rapp_cnt) { |
| 1311 | switch (op) { |
| 1312 | case SCSI_PROT_READ_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1313 | case SCSI_PROT_READ_STRIP: |
| 1314 | case SCSI_PROT_READ_PASS: |
| 1315 | /* |
| 1316 | * For READ_STRIP and READ_PASS, force the |
| 1317 | * error on data being read off the wire. It |
| 1318 | * should force an IO error to the driver. |
| 1319 | */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1320 | *apptag = 0xDEAD; |
| 1321 | phba->lpfc_injerr_rapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1322 | if (phba->lpfc_injerr_rapp_cnt == 0) { |
| 1323 | phba->lpfc_injerr_nportid = 0; |
| 1324 | phba->lpfc_injerr_lba = |
| 1325 | LPFC_INJERR_LBA_OFF; |
| 1326 | memset(&phba->lpfc_injerr_wwpn, |
| 1327 | 0, sizeof(struct lpfc_name)); |
| 1328 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1329 | rc = BG_ERR_INIT; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1330 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1331 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1332 | "0814 BLKGRD: Injecting apptag error: " |
| 1333 | "read lba x%lx\n", (unsigned long)lba); |
| 1334 | break; |
| 1335 | } |
| 1336 | } |
| 1337 | } |
| 1338 | |
| 1339 | |
| 1340 | /* Should we change the Guard Tag */ |
| 1341 | if (new_guard) { |
| 1342 | if (phba->lpfc_injerr_wgrd_cnt) { |
| 1343 | switch (op) { |
| 1344 | case SCSI_PROT_WRITE_PASS: |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1345 | rc = BG_ERR_CHECK; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1346 | fallthrough; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1347 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1348 | case SCSI_PROT_WRITE_INSERT: |
| 1349 | /* |
| 1350 | * For WRITE_INSERT, force the |
| 1351 | * error to be sent on the wire. It should be |
| 1352 | * detected by the Target. |
| 1353 | */ |
| 1354 | phba->lpfc_injerr_wgrd_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1355 | if (phba->lpfc_injerr_wgrd_cnt == 0) { |
| 1356 | phba->lpfc_injerr_nportid = 0; |
| 1357 | phba->lpfc_injerr_lba = |
| 1358 | LPFC_INJERR_LBA_OFF; |
| 1359 | memset(&phba->lpfc_injerr_wwpn, |
| 1360 | 0, sizeof(struct lpfc_name)); |
| 1361 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1362 | |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1363 | rc |= BG_ERR_TGT | BG_ERR_SWAP; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1364 | /* Signals the caller to swap CRC->CSUM */ |
| 1365 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1366 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1367 | "0817 BLKGRD: Injecting guard error: " |
| 1368 | "write lba x%lx\n", (unsigned long)lba); |
| 1369 | break; |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1370 | case SCSI_PROT_WRITE_STRIP: |
| 1371 | /* |
| 1372 | * For WRITE_STRIP and WRITE_PASS, |
| 1373 | * force the error on data |
| 1374 | * being copied from SLI-Host to SLI-Port. |
| 1375 | */ |
| 1376 | phba->lpfc_injerr_wgrd_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1377 | if (phba->lpfc_injerr_wgrd_cnt == 0) { |
| 1378 | phba->lpfc_injerr_nportid = 0; |
| 1379 | phba->lpfc_injerr_lba = |
| 1380 | LPFC_INJERR_LBA_OFF; |
| 1381 | memset(&phba->lpfc_injerr_wwpn, |
| 1382 | 0, sizeof(struct lpfc_name)); |
| 1383 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1384 | |
| 1385 | rc = BG_ERR_INIT | BG_ERR_SWAP; |
| 1386 | /* Signals the caller to swap CRC->CSUM */ |
| 1387 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1388 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1389 | "0816 BLKGRD: Injecting guard error: " |
| 1390 | "write lba x%lx\n", (unsigned long)lba); |
| 1391 | break; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1392 | } |
| 1393 | } |
| 1394 | if (phba->lpfc_injerr_rgrd_cnt) { |
| 1395 | switch (op) { |
| 1396 | case SCSI_PROT_READ_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1397 | case SCSI_PROT_READ_STRIP: |
| 1398 | case SCSI_PROT_READ_PASS: |
| 1399 | /* |
| 1400 | * For READ_STRIP and READ_PASS, force the |
| 1401 | * error on data being read off the wire. It |
| 1402 | * should force an IO error to the driver. |
| 1403 | */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1404 | phba->lpfc_injerr_rgrd_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1405 | if (phba->lpfc_injerr_rgrd_cnt == 0) { |
| 1406 | phba->lpfc_injerr_nportid = 0; |
| 1407 | phba->lpfc_injerr_lba = |
| 1408 | LPFC_INJERR_LBA_OFF; |
| 1409 | memset(&phba->lpfc_injerr_wwpn, |
| 1410 | 0, sizeof(struct lpfc_name)); |
| 1411 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1412 | |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1413 | rc = BG_ERR_INIT | BG_ERR_SWAP; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1414 | /* Signals the caller to swap CRC->CSUM */ |
| 1415 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1416 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1417 | "0818 BLKGRD: Injecting guard error: " |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1418 | "read lba x%lx\n", (unsigned long)lba); |
| 1419 | } |
| 1420 | } |
| 1421 | } |
| 1422 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1423 | return rc; |
| 1424 | } |
| 1425 | #endif |
| 1426 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1427 | /** |
| 1428 | * lpfc_sc_to_bg_opcodes - Determine the BlockGuard opcodes to be used with |
| 1429 | * the specified SCSI command. |
| 1430 | * @phba: The Hba for which this call is being executed. |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1431 | * @sc: The SCSI command to examine |
Lee Jones | eceee00 | 2020-11-02 14:23:43 +0000 | [diff] [blame] | 1432 | * @txop: (out) BlockGuard operation for transmitted data |
| 1433 | * @rxop: (out) BlockGuard operation for received data |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1434 | * |
| 1435 | * Returns: zero on success; non-zero if tx and/or rx op cannot be determined |
| 1436 | * |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1437 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1438 | static int |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1439 | lpfc_sc_to_bg_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1440 | uint8_t *txop, uint8_t *rxop) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1441 | { |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1442 | uint8_t ret = 0; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1443 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1444 | if (lpfc_cmd_guard_csum(sc)) { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1445 | switch (scsi_get_prot_op(sc)) { |
| 1446 | case SCSI_PROT_READ_INSERT: |
| 1447 | case SCSI_PROT_WRITE_STRIP: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1448 | *rxop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1449 | *txop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1450 | break; |
| 1451 | |
| 1452 | case SCSI_PROT_READ_STRIP: |
| 1453 | case SCSI_PROT_WRITE_INSERT: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1454 | *rxop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1455 | *txop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1456 | break; |
| 1457 | |
Martin K. Petersen | c6af404 | 2009-09-18 17:32:59 -0400 | [diff] [blame] | 1458 | case SCSI_PROT_READ_PASS: |
| 1459 | case SCSI_PROT_WRITE_PASS: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1460 | *rxop = BG_OP_IN_CRC_OUT_CSUM; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1461 | *txop = BG_OP_IN_CSUM_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1462 | break; |
| 1463 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1464 | case SCSI_PROT_NORMAL: |
| 1465 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1466 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1467 | "9063 BLKGRD: Bad op/guard:%d/IP combination\n", |
| 1468 | scsi_get_prot_op(sc)); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1469 | ret = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1470 | break; |
| 1471 | |
| 1472 | } |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1473 | } else { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1474 | switch (scsi_get_prot_op(sc)) { |
| 1475 | case SCSI_PROT_READ_STRIP: |
| 1476 | case SCSI_PROT_WRITE_INSERT: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1477 | *rxop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1478 | *txop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1479 | break; |
| 1480 | |
| 1481 | case SCSI_PROT_READ_PASS: |
| 1482 | case SCSI_PROT_WRITE_PASS: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1483 | *rxop = BG_OP_IN_CRC_OUT_CRC; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1484 | *txop = BG_OP_IN_CRC_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1485 | break; |
| 1486 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1487 | case SCSI_PROT_READ_INSERT: |
| 1488 | case SCSI_PROT_WRITE_STRIP: |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1489 | *rxop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1490 | *txop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1491 | break; |
| 1492 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1493 | case SCSI_PROT_NORMAL: |
| 1494 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1495 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1496 | "9075 BLKGRD: Bad op/guard:%d/CRC combination\n", |
| 1497 | scsi_get_prot_op(sc)); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1498 | ret = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1499 | break; |
| 1500 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1501 | } |
| 1502 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1503 | return ret; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1504 | } |
| 1505 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1506 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 1507 | /** |
| 1508 | * lpfc_bg_err_opcodes - reDetermine the BlockGuard opcodes to be used with |
| 1509 | * the specified SCSI command in order to force a guard tag error. |
| 1510 | * @phba: The Hba for which this call is being executed. |
| 1511 | * @sc: The SCSI command to examine |
Lee Jones | eceee00 | 2020-11-02 14:23:43 +0000 | [diff] [blame] | 1512 | * @txop: (out) BlockGuard operation for transmitted data |
| 1513 | * @rxop: (out) BlockGuard operation for received data |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1514 | * |
| 1515 | * Returns: zero on success; non-zero if tx and/or rx op cannot be determined |
| 1516 | * |
| 1517 | **/ |
| 1518 | static int |
| 1519 | lpfc_bg_err_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1520 | uint8_t *txop, uint8_t *rxop) |
| 1521 | { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1522 | uint8_t ret = 0; |
| 1523 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1524 | if (lpfc_cmd_guard_csum(sc)) { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1525 | switch (scsi_get_prot_op(sc)) { |
| 1526 | case SCSI_PROT_READ_INSERT: |
| 1527 | case SCSI_PROT_WRITE_STRIP: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1528 | *rxop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1529 | *txop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1530 | break; |
| 1531 | |
| 1532 | case SCSI_PROT_READ_STRIP: |
| 1533 | case SCSI_PROT_WRITE_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1534 | *rxop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1535 | *txop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1536 | break; |
| 1537 | |
| 1538 | case SCSI_PROT_READ_PASS: |
| 1539 | case SCSI_PROT_WRITE_PASS: |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1540 | *rxop = BG_OP_IN_CSUM_OUT_CRC; |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1541 | *txop = BG_OP_IN_CRC_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1542 | break; |
| 1543 | |
| 1544 | case SCSI_PROT_NORMAL: |
| 1545 | default: |
| 1546 | break; |
| 1547 | |
| 1548 | } |
| 1549 | } else { |
| 1550 | switch (scsi_get_prot_op(sc)) { |
| 1551 | case SCSI_PROT_READ_STRIP: |
| 1552 | case SCSI_PROT_WRITE_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1553 | *rxop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1554 | *txop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1555 | break; |
| 1556 | |
| 1557 | case SCSI_PROT_READ_PASS: |
| 1558 | case SCSI_PROT_WRITE_PASS: |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1559 | *rxop = BG_OP_IN_CSUM_OUT_CSUM; |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1560 | *txop = BG_OP_IN_CSUM_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1561 | break; |
| 1562 | |
| 1563 | case SCSI_PROT_READ_INSERT: |
| 1564 | case SCSI_PROT_WRITE_STRIP: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1565 | *rxop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1566 | *txop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1567 | break; |
| 1568 | |
| 1569 | case SCSI_PROT_NORMAL: |
| 1570 | default: |
| 1571 | break; |
| 1572 | } |
| 1573 | } |
| 1574 | |
| 1575 | return ret; |
| 1576 | } |
| 1577 | #endif |
| 1578 | |
| 1579 | /** |
| 1580 | * lpfc_bg_setup_bpl - Setup BlockGuard BPL with no protection data |
| 1581 | * @phba: The Hba for which this call is being executed. |
| 1582 | * @sc: pointer to scsi command we're working on |
| 1583 | * @bpl: pointer to buffer list for protection groups |
Lee Jones | eceee00 | 2020-11-02 14:23:43 +0000 | [diff] [blame] | 1584 | * @datasegcnt: number of segments of data that have been dma mapped |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1585 | * |
| 1586 | * This function sets up BPL buffer list for protection groups of |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1587 | * type LPFC_PG_TYPE_NO_DIF |
| 1588 | * |
| 1589 | * This is usually used when the HBA is instructed to generate |
| 1590 | * DIFs and insert them into data stream (or strip DIF from |
| 1591 | * incoming data stream) |
| 1592 | * |
| 1593 | * The buffer list consists of just one protection group described |
| 1594 | * below: |
| 1595 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1596 | * start of prot group --> | PDE_5 | |
| 1597 | * +-------------------------+ |
| 1598 | * | PDE_6 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1599 | * +-------------------------+ |
| 1600 | * | Data BDE | |
| 1601 | * +-------------------------+ |
| 1602 | * |more Data BDE's ... (opt)| |
| 1603 | * +-------------------------+ |
| 1604 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1605 | * |
| 1606 | * Note: Data s/g buffers have been dma mapped |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1607 | * |
| 1608 | * Returns the number of BDEs added to the BPL. |
| 1609 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1610 | static int |
| 1611 | lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1612 | struct ulp_bde64 *bpl, int datasegcnt) |
| 1613 | { |
| 1614 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1615 | struct lpfc_pde5 *pde5 = NULL; |
| 1616 | struct lpfc_pde6 *pde6 = NULL; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1617 | dma_addr_t physaddr; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1618 | int i = 0, num_bde = 0, status; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1619 | int datadir = sc->sc_data_direction; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 1620 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1621 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 1622 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1623 | uint32_t checking = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1624 | uint32_t reftag; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1625 | uint8_t txop, rxop; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1626 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1627 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 1628 | if (status) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1629 | goto out; |
| 1630 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1631 | /* extract some info from the scsi command for pde*/ |
Bart Van Assche | 4221c8a | 2021-08-09 16:03:30 -0700 | [diff] [blame] | 1632 | reftag = t10_pi_ref_tag(scsi_cmd_to_rq(sc)); |
James Smart | 68a6a66 | 2021-03-01 09:18:02 -0800 | [diff] [blame] | 1633 | if (reftag == LPFC_INVALID_REFTAG) |
| 1634 | goto out; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1635 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1636 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1637 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1638 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1639 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1640 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1641 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1642 | checking = 0; |
| 1643 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1644 | #endif |
| 1645 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1646 | /* setup PDE5 with what we have */ |
| 1647 | pde5 = (struct lpfc_pde5 *) bpl; |
| 1648 | memset(pde5, 0, sizeof(struct lpfc_pde5)); |
| 1649 | bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1650 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1651 | /* Endianness conversion if necessary for PDE5 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1652 | pde5->word0 = cpu_to_le32(pde5->word0); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1653 | pde5->reftag = cpu_to_le32(reftag); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1654 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1655 | /* advance bpl and increment bde count */ |
| 1656 | num_bde++; |
| 1657 | bpl++; |
| 1658 | pde6 = (struct lpfc_pde6 *) bpl; |
| 1659 | |
| 1660 | /* setup PDE6 with the rest of the info */ |
| 1661 | memset(pde6, 0, sizeof(struct lpfc_pde6)); |
| 1662 | bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR); |
| 1663 | bf_set(pde6_optx, pde6, txop); |
| 1664 | bf_set(pde6_oprx, pde6, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1665 | |
| 1666 | /* |
| 1667 | * We only need to check the data on READs, for WRITEs |
| 1668 | * protection data is automatically generated, not checked. |
| 1669 | */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1670 | if (datadir == DMA_FROM_DEVICE) { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1671 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1672 | bf_set(pde6_ce, pde6, checking); |
| 1673 | else |
| 1674 | bf_set(pde6_ce, pde6, 0); |
| 1675 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1676 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1677 | bf_set(pde6_re, pde6, checking); |
| 1678 | else |
| 1679 | bf_set(pde6_re, pde6, 0); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1680 | } |
| 1681 | bf_set(pde6_ai, pde6, 1); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1682 | bf_set(pde6_ae, pde6, 0); |
| 1683 | bf_set(pde6_apptagval, pde6, 0); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1684 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1685 | /* Endianness conversion if necessary for PDE6 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1686 | pde6->word0 = cpu_to_le32(pde6->word0); |
| 1687 | pde6->word1 = cpu_to_le32(pde6->word1); |
| 1688 | pde6->word2 = cpu_to_le32(pde6->word2); |
| 1689 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1690 | /* advance bpl and increment bde count */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1691 | num_bde++; |
| 1692 | bpl++; |
| 1693 | |
| 1694 | /* assumption: caller has already run dma_map_sg on command data */ |
| 1695 | scsi_for_each_sg(sc, sgde, datasegcnt, i) { |
| 1696 | physaddr = sg_dma_address(sgde); |
| 1697 | bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
| 1698 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 1699 | bpl->tus.f.bdeSize = sg_dma_len(sgde); |
| 1700 | if (datadir == DMA_TO_DEVICE) |
| 1701 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1702 | else |
| 1703 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
| 1704 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 1705 | bpl++; |
| 1706 | num_bde++; |
| 1707 | } |
| 1708 | |
| 1709 | out: |
| 1710 | return num_bde; |
| 1711 | } |
| 1712 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1713 | /** |
| 1714 | * lpfc_bg_setup_bpl_prot - Setup BlockGuard BPL with protection data |
| 1715 | * @phba: The Hba for which this call is being executed. |
| 1716 | * @sc: pointer to scsi command we're working on |
| 1717 | * @bpl: pointer to buffer list for protection groups |
| 1718 | * @datacnt: number of segments of data that have been dma mapped |
| 1719 | * @protcnt: number of segment of protection data that have been dma mapped |
| 1720 | * |
| 1721 | * This function sets up BPL buffer list for protection groups of |
| 1722 | * type LPFC_PG_TYPE_DIF |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1723 | * |
| 1724 | * This is usually used when DIFs are in their own buffers, |
| 1725 | * separate from the data. The HBA can then by instructed |
| 1726 | * to place the DIFs in the outgoing stream. For read operations, |
| 1727 | * The HBA could extract the DIFs and place it in DIF buffers. |
| 1728 | * |
| 1729 | * The buffer list for this type consists of one or more of the |
| 1730 | * protection groups described below: |
| 1731 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1732 | * start of first prot group --> | PDE_5 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1733 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1734 | * | PDE_6 | |
| 1735 | * +-------------------------+ |
| 1736 | * | PDE_7 (Prot BDE) | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1737 | * +-------------------------+ |
| 1738 | * | Data BDE | |
| 1739 | * +-------------------------+ |
| 1740 | * |more Data BDE's ... (opt)| |
| 1741 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1742 | * start of new prot group --> | PDE_5 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1743 | * +-------------------------+ |
| 1744 | * | ... | |
| 1745 | * +-------------------------+ |
| 1746 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1747 | * Note: It is assumed that both data and protection s/g buffers have been |
| 1748 | * mapped for DMA |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1749 | * |
| 1750 | * Returns the number of BDEs added to the BPL. |
| 1751 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1752 | static int |
| 1753 | lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1754 | struct ulp_bde64 *bpl, int datacnt, int protcnt) |
| 1755 | { |
| 1756 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 1757 | struct scatterlist *sgpe = NULL; /* s/g prot entry */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1758 | struct lpfc_pde5 *pde5 = NULL; |
| 1759 | struct lpfc_pde6 *pde6 = NULL; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1760 | struct lpfc_pde7 *pde7 = NULL; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1761 | dma_addr_t dataphysaddr, protphysaddr; |
| 1762 | unsigned short curr_data = 0, curr_prot = 0; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1763 | unsigned int split_offset; |
| 1764 | unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1765 | unsigned int protgrp_blks, protgrp_bytes; |
| 1766 | unsigned int remainder, subtotal; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1767 | int status; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1768 | int datadir = sc->sc_data_direction; |
| 1769 | unsigned char pgdone = 0, alldone = 0; |
| 1770 | unsigned blksize; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 1771 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1772 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 1773 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1774 | uint32_t checking = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1775 | uint32_t reftag; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1776 | uint8_t txop, rxop; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1777 | int num_bde = 0; |
| 1778 | |
| 1779 | sgpe = scsi_prot_sglist(sc); |
| 1780 | sgde = scsi_sglist(sc); |
| 1781 | |
| 1782 | if (!sgpe || !sgde) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1783 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 1784 | "9020 Invalid s/g entry: data=x%px prot=x%px\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1785 | sgpe, sgde); |
| 1786 | return 0; |
| 1787 | } |
| 1788 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1789 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 1790 | if (status) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1791 | goto out; |
| 1792 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1793 | /* extract some info from the scsi command */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1794 | blksize = lpfc_cmd_blksize(sc); |
Bart Van Assche | 4221c8a | 2021-08-09 16:03:30 -0700 | [diff] [blame] | 1795 | reftag = t10_pi_ref_tag(scsi_cmd_to_rq(sc)); |
James Smart | 68a6a66 | 2021-03-01 09:18:02 -0800 | [diff] [blame] | 1796 | if (reftag == LPFC_INVALID_REFTAG) |
| 1797 | goto out; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1798 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1799 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1800 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1801 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1802 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1803 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1804 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1805 | checking = 0; |
| 1806 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1807 | #endif |
| 1808 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1809 | split_offset = 0; |
| 1810 | do { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 1811 | /* Check to see if we ran out of space */ |
| 1812 | if (num_bde >= (phba->cfg_total_seg_cnt - 2)) |
| 1813 | return num_bde + 3; |
| 1814 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1815 | /* setup PDE5 with what we have */ |
| 1816 | pde5 = (struct lpfc_pde5 *) bpl; |
| 1817 | memset(pde5, 0, sizeof(struct lpfc_pde5)); |
| 1818 | bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1819 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1820 | /* Endianness conversion if necessary for PDE5 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1821 | pde5->word0 = cpu_to_le32(pde5->word0); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1822 | pde5->reftag = cpu_to_le32(reftag); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1823 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1824 | /* advance bpl and increment bde count */ |
| 1825 | num_bde++; |
| 1826 | bpl++; |
| 1827 | pde6 = (struct lpfc_pde6 *) bpl; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1828 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1829 | /* setup PDE6 with the rest of the info */ |
| 1830 | memset(pde6, 0, sizeof(struct lpfc_pde6)); |
| 1831 | bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR); |
| 1832 | bf_set(pde6_optx, pde6, txop); |
| 1833 | bf_set(pde6_oprx, pde6, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1834 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1835 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1836 | bf_set(pde6_ce, pde6, checking); |
| 1837 | else |
| 1838 | bf_set(pde6_ce, pde6, 0); |
| 1839 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1840 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1841 | bf_set(pde6_re, pde6, checking); |
| 1842 | else |
| 1843 | bf_set(pde6_re, pde6, 0); |
| 1844 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1845 | bf_set(pde6_ai, pde6, 1); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1846 | bf_set(pde6_ae, pde6, 0); |
| 1847 | bf_set(pde6_apptagval, pde6, 0); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1848 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1849 | /* Endianness conversion if necessary for PDE6 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1850 | pde6->word0 = cpu_to_le32(pde6->word0); |
| 1851 | pde6->word1 = cpu_to_le32(pde6->word1); |
| 1852 | pde6->word2 = cpu_to_le32(pde6->word2); |
| 1853 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1854 | /* advance bpl and increment bde count */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1855 | num_bde++; |
| 1856 | bpl++; |
| 1857 | |
| 1858 | /* setup the first BDE that points to protection buffer */ |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1859 | protphysaddr = sg_dma_address(sgpe) + protgroup_offset; |
| 1860 | protgroup_len = sg_dma_len(sgpe) - protgroup_offset; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1861 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1862 | /* must be integer multiple of the DIF block length */ |
| 1863 | BUG_ON(protgroup_len % 8); |
| 1864 | |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1865 | pde7 = (struct lpfc_pde7 *) bpl; |
| 1866 | memset(pde7, 0, sizeof(struct lpfc_pde7)); |
| 1867 | bf_set(pde7_type, pde7, LPFC_PDE7_DESCRIPTOR); |
| 1868 | |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1869 | pde7->addrHigh = le32_to_cpu(putPaddrHigh(protphysaddr)); |
| 1870 | pde7->addrLow = le32_to_cpu(putPaddrLow(protphysaddr)); |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1871 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1872 | protgrp_blks = protgroup_len / 8; |
| 1873 | protgrp_bytes = protgrp_blks * blksize; |
| 1874 | |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1875 | /* check if this pde is crossing the 4K boundary; if so split */ |
| 1876 | if ((pde7->addrLow & 0xfff) + protgroup_len > 0x1000) { |
| 1877 | protgroup_remainder = 0x1000 - (pde7->addrLow & 0xfff); |
| 1878 | protgroup_offset += protgroup_remainder; |
| 1879 | protgrp_blks = protgroup_remainder / 8; |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1880 | protgrp_bytes = protgrp_blks * blksize; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1881 | } else { |
| 1882 | protgroup_offset = 0; |
| 1883 | curr_prot++; |
| 1884 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1885 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1886 | num_bde++; |
| 1887 | |
| 1888 | /* setup BDE's for data blocks associated with DIF data */ |
| 1889 | pgdone = 0; |
| 1890 | subtotal = 0; /* total bytes processed for current prot grp */ |
| 1891 | while (!pgdone) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 1892 | /* Check to see if we ran out of space */ |
| 1893 | if (num_bde >= phba->cfg_total_seg_cnt) |
| 1894 | return num_bde + 1; |
| 1895 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1896 | if (!sgde) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1897 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1898 | "9065 BLKGRD:%s Invalid data segment\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1899 | __func__); |
| 1900 | return 0; |
| 1901 | } |
| 1902 | bpl++; |
| 1903 | dataphysaddr = sg_dma_address(sgde) + split_offset; |
| 1904 | bpl->addrLow = le32_to_cpu(putPaddrLow(dataphysaddr)); |
| 1905 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(dataphysaddr)); |
| 1906 | |
| 1907 | remainder = sg_dma_len(sgde) - split_offset; |
| 1908 | |
| 1909 | if ((subtotal + remainder) <= protgrp_bytes) { |
| 1910 | /* we can use this whole buffer */ |
| 1911 | bpl->tus.f.bdeSize = remainder; |
| 1912 | split_offset = 0; |
| 1913 | |
| 1914 | if ((subtotal + remainder) == protgrp_bytes) |
| 1915 | pgdone = 1; |
| 1916 | } else { |
| 1917 | /* must split this buffer with next prot grp */ |
| 1918 | bpl->tus.f.bdeSize = protgrp_bytes - subtotal; |
| 1919 | split_offset += bpl->tus.f.bdeSize; |
| 1920 | } |
| 1921 | |
| 1922 | subtotal += bpl->tus.f.bdeSize; |
| 1923 | |
| 1924 | if (datadir == DMA_TO_DEVICE) |
| 1925 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1926 | else |
| 1927 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
| 1928 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 1929 | |
| 1930 | num_bde++; |
| 1931 | curr_data++; |
| 1932 | |
| 1933 | if (split_offset) |
| 1934 | break; |
| 1935 | |
| 1936 | /* Move to the next s/g segment if possible */ |
| 1937 | sgde = sg_next(sgde); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1938 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1939 | } |
| 1940 | |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1941 | if (protgroup_offset) { |
| 1942 | /* update the reference tag */ |
| 1943 | reftag += protgrp_blks; |
| 1944 | bpl++; |
| 1945 | continue; |
| 1946 | } |
| 1947 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1948 | /* are we done ? */ |
| 1949 | if (curr_prot == protcnt) { |
| 1950 | alldone = 1; |
| 1951 | } else if (curr_prot < protcnt) { |
| 1952 | /* advance to next prot buffer */ |
| 1953 | sgpe = sg_next(sgpe); |
| 1954 | bpl++; |
| 1955 | |
| 1956 | /* update the reference tag */ |
| 1957 | reftag += protgrp_blks; |
| 1958 | } else { |
| 1959 | /* if we're here, we have a bug */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1960 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 1961 | "9054 BLKGRD: bug in %s\n", __func__); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | } while (!alldone); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1965 | out: |
| 1966 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1967 | return num_bde; |
| 1968 | } |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1969 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1970 | /** |
| 1971 | * lpfc_bg_setup_sgl - Setup BlockGuard SGL with no protection data |
| 1972 | * @phba: The Hba for which this call is being executed. |
| 1973 | * @sc: pointer to scsi command we're working on |
| 1974 | * @sgl: pointer to buffer list for protection groups |
Lee Jones | eceee00 | 2020-11-02 14:23:43 +0000 | [diff] [blame] | 1975 | * @datasegcnt: number of segments of data that have been dma mapped |
| 1976 | * @lpfc_cmd: lpfc scsi command object pointer. |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1977 | * |
| 1978 | * This function sets up SGL buffer list for protection groups of |
| 1979 | * type LPFC_PG_TYPE_NO_DIF |
| 1980 | * |
| 1981 | * This is usually used when the HBA is instructed to generate |
| 1982 | * DIFs and insert them into data stream (or strip DIF from |
| 1983 | * incoming data stream) |
| 1984 | * |
| 1985 | * The buffer list consists of just one protection group described |
| 1986 | * below: |
| 1987 | * +-------------------------+ |
| 1988 | * start of prot group --> | DI_SEED | |
| 1989 | * +-------------------------+ |
| 1990 | * | Data SGE | |
| 1991 | * +-------------------------+ |
| 1992 | * |more Data SGE's ... (opt)| |
| 1993 | * +-------------------------+ |
| 1994 | * |
| 1995 | * |
| 1996 | * Note: Data s/g buffers have been dma mapped |
| 1997 | * |
| 1998 | * Returns the number of SGEs added to the SGL. |
| 1999 | **/ |
| 2000 | static int |
| 2001 | lpfc_bg_setup_sgl(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2002 | struct sli4_sge *sgl, int datasegcnt, |
| 2003 | struct lpfc_io_buf *lpfc_cmd) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2004 | { |
| 2005 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 2006 | struct sli4_sge_diseed *diseed = NULL; |
| 2007 | dma_addr_t physaddr; |
| 2008 | int i = 0, num_sge = 0, status; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2009 | uint32_t reftag; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2010 | uint8_t txop, rxop; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2011 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2012 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2013 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2014 | uint32_t checking = 1; |
| 2015 | uint32_t dma_len; |
| 2016 | uint32_t dma_offset = 0; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2017 | struct sli4_hybrid_sgl *sgl_xtra = NULL; |
| 2018 | int j; |
| 2019 | bool lsp_just_set = false; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2020 | |
| 2021 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 2022 | if (status) |
| 2023 | goto out; |
| 2024 | |
| 2025 | /* extract some info from the scsi command for pde*/ |
Bart Van Assche | 4221c8a | 2021-08-09 16:03:30 -0700 | [diff] [blame] | 2026 | reftag = t10_pi_ref_tag(scsi_cmd_to_rq(sc)); |
James Smart | 68a6a66 | 2021-03-01 09:18:02 -0800 | [diff] [blame] | 2027 | if (reftag == LPFC_INVALID_REFTAG) |
| 2028 | goto out; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2029 | |
| 2030 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 2031 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2032 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2033 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2034 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2035 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2036 | checking = 0; |
| 2037 | } |
| 2038 | #endif |
| 2039 | |
| 2040 | /* setup DISEED with what we have */ |
| 2041 | diseed = (struct sli4_sge_diseed *) sgl; |
| 2042 | memset(diseed, 0, sizeof(struct sli4_sge_diseed)); |
| 2043 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED); |
| 2044 | |
| 2045 | /* Endianness conversion if necessary */ |
| 2046 | diseed->ref_tag = cpu_to_le32(reftag); |
| 2047 | diseed->ref_tag_tran = diseed->ref_tag; |
| 2048 | |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2049 | /* |
| 2050 | * We only need to check the data on READs, for WRITEs |
| 2051 | * protection data is automatically generated, not checked. |
| 2052 | */ |
| 2053 | if (sc->sc_data_direction == DMA_FROM_DEVICE) { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2054 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2055 | bf_set(lpfc_sli4_sge_dif_ce, diseed, checking); |
| 2056 | else |
| 2057 | bf_set(lpfc_sli4_sge_dif_ce, diseed, 0); |
| 2058 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2059 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2060 | bf_set(lpfc_sli4_sge_dif_re, diseed, checking); |
| 2061 | else |
| 2062 | bf_set(lpfc_sli4_sge_dif_re, diseed, 0); |
| 2063 | } |
| 2064 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2065 | /* setup DISEED with the rest of the info */ |
| 2066 | bf_set(lpfc_sli4_sge_dif_optx, diseed, txop); |
| 2067 | bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2068 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2069 | bf_set(lpfc_sli4_sge_dif_ai, diseed, 1); |
| 2070 | bf_set(lpfc_sli4_sge_dif_me, diseed, 0); |
| 2071 | |
| 2072 | /* Endianness conversion if necessary for DISEED */ |
| 2073 | diseed->word2 = cpu_to_le32(diseed->word2); |
| 2074 | diseed->word3 = cpu_to_le32(diseed->word3); |
| 2075 | |
| 2076 | /* advance bpl and increment sge count */ |
| 2077 | num_sge++; |
| 2078 | sgl++; |
| 2079 | |
| 2080 | /* assumption: caller has already run dma_map_sg on command data */ |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2081 | sgde = scsi_sglist(sc); |
| 2082 | j = 3; |
| 2083 | for (i = 0; i < datasegcnt; i++) { |
| 2084 | /* clear it */ |
| 2085 | sgl->word2 = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2086 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2087 | /* do we need to expand the segment */ |
| 2088 | if (!lsp_just_set && !((j + 1) % phba->border_sge_num) && |
| 2089 | ((datasegcnt - 1) != i)) { |
| 2090 | /* set LSP type */ |
| 2091 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_LSP); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2092 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2093 | sgl_xtra = lpfc_get_sgl_per_hdwq(phba, lpfc_cmd); |
| 2094 | |
| 2095 | if (unlikely(!sgl_xtra)) { |
| 2096 | lpfc_cmd->seg_cnt = 0; |
| 2097 | return 0; |
| 2098 | } |
| 2099 | sgl->addr_lo = cpu_to_le32(putPaddrLow( |
| 2100 | sgl_xtra->dma_phys_sgl)); |
| 2101 | sgl->addr_hi = cpu_to_le32(putPaddrHigh( |
| 2102 | sgl_xtra->dma_phys_sgl)); |
| 2103 | |
| 2104 | } else { |
| 2105 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); |
| 2106 | } |
| 2107 | |
| 2108 | if (!(bf_get(lpfc_sli4_sge_type, sgl) & LPFC_SGE_TYPE_LSP)) { |
| 2109 | if ((datasegcnt - 1) == i) |
| 2110 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 2111 | physaddr = sg_dma_address(sgde); |
| 2112 | dma_len = sg_dma_len(sgde); |
| 2113 | sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr)); |
| 2114 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr)); |
| 2115 | |
| 2116 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
| 2117 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 2118 | sgl->sge_len = cpu_to_le32(dma_len); |
| 2119 | |
| 2120 | dma_offset += dma_len; |
| 2121 | sgde = sg_next(sgde); |
| 2122 | |
| 2123 | sgl++; |
| 2124 | num_sge++; |
| 2125 | lsp_just_set = false; |
| 2126 | |
| 2127 | } else { |
| 2128 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 2129 | sgl->sge_len = cpu_to_le32(phba->cfg_sg_dma_buf_size); |
| 2130 | |
| 2131 | sgl = (struct sli4_sge *)sgl_xtra->dma_sgl; |
| 2132 | i = i - 1; |
| 2133 | |
| 2134 | lsp_just_set = true; |
| 2135 | } |
| 2136 | |
| 2137 | j++; |
| 2138 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2139 | } |
| 2140 | |
| 2141 | out: |
| 2142 | return num_sge; |
| 2143 | } |
| 2144 | |
| 2145 | /** |
| 2146 | * lpfc_bg_setup_sgl_prot - Setup BlockGuard SGL with protection data |
| 2147 | * @phba: The Hba for which this call is being executed. |
| 2148 | * @sc: pointer to scsi command we're working on |
| 2149 | * @sgl: pointer to buffer list for protection groups |
| 2150 | * @datacnt: number of segments of data that have been dma mapped |
| 2151 | * @protcnt: number of segment of protection data that have been dma mapped |
Lee Jones | eceee00 | 2020-11-02 14:23:43 +0000 | [diff] [blame] | 2152 | * @lpfc_cmd: lpfc scsi command object pointer. |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2153 | * |
| 2154 | * This function sets up SGL buffer list for protection groups of |
| 2155 | * type LPFC_PG_TYPE_DIF |
| 2156 | * |
| 2157 | * This is usually used when DIFs are in their own buffers, |
| 2158 | * separate from the data. The HBA can then by instructed |
| 2159 | * to place the DIFs in the outgoing stream. For read operations, |
| 2160 | * The HBA could extract the DIFs and place it in DIF buffers. |
| 2161 | * |
| 2162 | * The buffer list for this type consists of one or more of the |
| 2163 | * protection groups described below: |
| 2164 | * +-------------------------+ |
| 2165 | * start of first prot group --> | DISEED | |
| 2166 | * +-------------------------+ |
| 2167 | * | DIF (Prot SGE) | |
| 2168 | * +-------------------------+ |
| 2169 | * | Data SGE | |
| 2170 | * +-------------------------+ |
| 2171 | * |more Data SGE's ... (opt)| |
| 2172 | * +-------------------------+ |
| 2173 | * start of new prot group --> | DISEED | |
| 2174 | * +-------------------------+ |
| 2175 | * | ... | |
| 2176 | * +-------------------------+ |
| 2177 | * |
| 2178 | * Note: It is assumed that both data and protection s/g buffers have been |
| 2179 | * mapped for DMA |
| 2180 | * |
| 2181 | * Returns the number of SGEs added to the SGL. |
| 2182 | **/ |
| 2183 | static int |
| 2184 | lpfc_bg_setup_sgl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2185 | struct sli4_sge *sgl, int datacnt, int protcnt, |
| 2186 | struct lpfc_io_buf *lpfc_cmd) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2187 | { |
| 2188 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 2189 | struct scatterlist *sgpe = NULL; /* s/g prot entry */ |
| 2190 | struct sli4_sge_diseed *diseed = NULL; |
| 2191 | dma_addr_t dataphysaddr, protphysaddr; |
| 2192 | unsigned short curr_data = 0, curr_prot = 0; |
| 2193 | unsigned int split_offset; |
| 2194 | unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder; |
| 2195 | unsigned int protgrp_blks, protgrp_bytes; |
| 2196 | unsigned int remainder, subtotal; |
| 2197 | int status; |
| 2198 | unsigned char pgdone = 0, alldone = 0; |
| 2199 | unsigned blksize; |
| 2200 | uint32_t reftag; |
| 2201 | uint8_t txop, rxop; |
| 2202 | uint32_t dma_len; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2203 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2204 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2205 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2206 | uint32_t checking = 1; |
| 2207 | uint32_t dma_offset = 0; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2208 | int num_sge = 0, j = 2; |
| 2209 | struct sli4_hybrid_sgl *sgl_xtra = NULL; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2210 | |
| 2211 | sgpe = scsi_prot_sglist(sc); |
| 2212 | sgde = scsi_sglist(sc); |
| 2213 | |
| 2214 | if (!sgpe || !sgde) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2215 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 2216 | "9082 Invalid s/g entry: data=x%px prot=x%px\n", |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2217 | sgpe, sgde); |
| 2218 | return 0; |
| 2219 | } |
| 2220 | |
| 2221 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 2222 | if (status) |
| 2223 | goto out; |
| 2224 | |
| 2225 | /* extract some info from the scsi command */ |
| 2226 | blksize = lpfc_cmd_blksize(sc); |
Bart Van Assche | 4221c8a | 2021-08-09 16:03:30 -0700 | [diff] [blame] | 2227 | reftag = t10_pi_ref_tag(scsi_cmd_to_rq(sc)); |
James Smart | 68a6a66 | 2021-03-01 09:18:02 -0800 | [diff] [blame] | 2228 | if (reftag == LPFC_INVALID_REFTAG) |
| 2229 | goto out; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2230 | |
| 2231 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 2232 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2233 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2234 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2235 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2236 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2237 | checking = 0; |
| 2238 | } |
| 2239 | #endif |
| 2240 | |
| 2241 | split_offset = 0; |
| 2242 | do { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2243 | /* Check to see if we ran out of space */ |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2244 | if ((num_sge >= (phba->cfg_total_seg_cnt - 2)) && |
| 2245 | !(phba->cfg_xpsgl)) |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2246 | return num_sge + 3; |
| 2247 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2248 | /* DISEED and DIF have to be together */ |
| 2249 | if (!((j + 1) % phba->border_sge_num) || |
| 2250 | !((j + 2) % phba->border_sge_num) || |
| 2251 | !((j + 3) % phba->border_sge_num)) { |
| 2252 | sgl->word2 = 0; |
| 2253 | |
| 2254 | /* set LSP type */ |
| 2255 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_LSP); |
| 2256 | |
| 2257 | sgl_xtra = lpfc_get_sgl_per_hdwq(phba, lpfc_cmd); |
| 2258 | |
| 2259 | if (unlikely(!sgl_xtra)) { |
| 2260 | goto out; |
| 2261 | } else { |
| 2262 | sgl->addr_lo = cpu_to_le32(putPaddrLow( |
| 2263 | sgl_xtra->dma_phys_sgl)); |
| 2264 | sgl->addr_hi = cpu_to_le32(putPaddrHigh( |
| 2265 | sgl_xtra->dma_phys_sgl)); |
| 2266 | } |
| 2267 | |
| 2268 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 2269 | sgl->sge_len = cpu_to_le32(phba->cfg_sg_dma_buf_size); |
| 2270 | |
| 2271 | sgl = (struct sli4_sge *)sgl_xtra->dma_sgl; |
| 2272 | j = 0; |
| 2273 | } |
| 2274 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2275 | /* setup DISEED with what we have */ |
| 2276 | diseed = (struct sli4_sge_diseed *) sgl; |
| 2277 | memset(diseed, 0, sizeof(struct sli4_sge_diseed)); |
| 2278 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED); |
| 2279 | |
| 2280 | /* Endianness conversion if necessary */ |
| 2281 | diseed->ref_tag = cpu_to_le32(reftag); |
| 2282 | diseed->ref_tag_tran = diseed->ref_tag; |
| 2283 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2284 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) { |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2285 | bf_set(lpfc_sli4_sge_dif_ce, diseed, checking); |
| 2286 | |
| 2287 | } else { |
| 2288 | bf_set(lpfc_sli4_sge_dif_ce, diseed, 0); |
| 2289 | /* |
| 2290 | * When in this mode, the hardware will replace |
| 2291 | * the guard tag from the host with a |
| 2292 | * newly generated good CRC for the wire. |
| 2293 | * Switch to raw mode here to avoid this |
| 2294 | * behavior. What the host sends gets put on the wire. |
| 2295 | */ |
| 2296 | if (txop == BG_OP_IN_CRC_OUT_CRC) { |
| 2297 | txop = BG_OP_RAW_MODE; |
| 2298 | rxop = BG_OP_RAW_MODE; |
| 2299 | } |
| 2300 | } |
| 2301 | |
| 2302 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2303 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2304 | bf_set(lpfc_sli4_sge_dif_re, diseed, checking); |
| 2305 | else |
| 2306 | bf_set(lpfc_sli4_sge_dif_re, diseed, 0); |
| 2307 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2308 | /* setup DISEED with the rest of the info */ |
| 2309 | bf_set(lpfc_sli4_sge_dif_optx, diseed, txop); |
| 2310 | bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2311 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2312 | bf_set(lpfc_sli4_sge_dif_ai, diseed, 1); |
| 2313 | bf_set(lpfc_sli4_sge_dif_me, diseed, 0); |
| 2314 | |
| 2315 | /* Endianness conversion if necessary for DISEED */ |
| 2316 | diseed->word2 = cpu_to_le32(diseed->word2); |
| 2317 | diseed->word3 = cpu_to_le32(diseed->word3); |
| 2318 | |
| 2319 | /* advance sgl and increment bde count */ |
| 2320 | num_sge++; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2321 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2322 | sgl++; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2323 | j++; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2324 | |
| 2325 | /* setup the first BDE that points to protection buffer */ |
| 2326 | protphysaddr = sg_dma_address(sgpe) + protgroup_offset; |
| 2327 | protgroup_len = sg_dma_len(sgpe) - protgroup_offset; |
| 2328 | |
| 2329 | /* must be integer multiple of the DIF block length */ |
| 2330 | BUG_ON(protgroup_len % 8); |
| 2331 | |
| 2332 | /* Now setup DIF SGE */ |
| 2333 | sgl->word2 = 0; |
| 2334 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DIF); |
| 2335 | sgl->addr_hi = le32_to_cpu(putPaddrHigh(protphysaddr)); |
| 2336 | sgl->addr_lo = le32_to_cpu(putPaddrLow(protphysaddr)); |
| 2337 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2338 | sgl->sge_len = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2339 | |
| 2340 | protgrp_blks = protgroup_len / 8; |
| 2341 | protgrp_bytes = protgrp_blks * blksize; |
| 2342 | |
| 2343 | /* check if DIF SGE is crossing the 4K boundary; if so split */ |
| 2344 | if ((sgl->addr_lo & 0xfff) + protgroup_len > 0x1000) { |
| 2345 | protgroup_remainder = 0x1000 - (sgl->addr_lo & 0xfff); |
| 2346 | protgroup_offset += protgroup_remainder; |
| 2347 | protgrp_blks = protgroup_remainder / 8; |
| 2348 | protgrp_bytes = protgrp_blks * blksize; |
| 2349 | } else { |
| 2350 | protgroup_offset = 0; |
| 2351 | curr_prot++; |
| 2352 | } |
| 2353 | |
| 2354 | num_sge++; |
| 2355 | |
| 2356 | /* setup SGE's for data blocks associated with DIF data */ |
| 2357 | pgdone = 0; |
| 2358 | subtotal = 0; /* total bytes processed for current prot grp */ |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2359 | |
| 2360 | sgl++; |
| 2361 | j++; |
| 2362 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2363 | while (!pgdone) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2364 | /* Check to see if we ran out of space */ |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2365 | if ((num_sge >= phba->cfg_total_seg_cnt) && |
| 2366 | !phba->cfg_xpsgl) |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2367 | return num_sge + 1; |
| 2368 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2369 | if (!sgde) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2370 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2371 | "9086 BLKGRD:%s Invalid data segment\n", |
| 2372 | __func__); |
| 2373 | return 0; |
| 2374 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2375 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2376 | if (!((j + 1) % phba->border_sge_num)) { |
| 2377 | sgl->word2 = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2378 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2379 | /* set LSP type */ |
| 2380 | bf_set(lpfc_sli4_sge_type, sgl, |
| 2381 | LPFC_SGE_TYPE_LSP); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2382 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2383 | sgl_xtra = lpfc_get_sgl_per_hdwq(phba, |
| 2384 | lpfc_cmd); |
| 2385 | |
| 2386 | if (unlikely(!sgl_xtra)) { |
| 2387 | goto out; |
| 2388 | } else { |
| 2389 | sgl->addr_lo = cpu_to_le32( |
| 2390 | putPaddrLow(sgl_xtra->dma_phys_sgl)); |
| 2391 | sgl->addr_hi = cpu_to_le32( |
| 2392 | putPaddrHigh(sgl_xtra->dma_phys_sgl)); |
| 2393 | } |
| 2394 | |
| 2395 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 2396 | sgl->sge_len = cpu_to_le32( |
| 2397 | phba->cfg_sg_dma_buf_size); |
| 2398 | |
| 2399 | sgl = (struct sli4_sge *)sgl_xtra->dma_sgl; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2400 | } else { |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2401 | dataphysaddr = sg_dma_address(sgde) + |
| 2402 | split_offset; |
| 2403 | |
| 2404 | remainder = sg_dma_len(sgde) - split_offset; |
| 2405 | |
| 2406 | if ((subtotal + remainder) <= protgrp_bytes) { |
| 2407 | /* we can use this whole buffer */ |
| 2408 | dma_len = remainder; |
| 2409 | split_offset = 0; |
| 2410 | |
| 2411 | if ((subtotal + remainder) == |
| 2412 | protgrp_bytes) |
| 2413 | pgdone = 1; |
| 2414 | } else { |
| 2415 | /* must split this buffer with next |
| 2416 | * prot grp |
| 2417 | */ |
| 2418 | dma_len = protgrp_bytes - subtotal; |
| 2419 | split_offset += dma_len; |
| 2420 | } |
| 2421 | |
| 2422 | subtotal += dma_len; |
| 2423 | |
| 2424 | sgl->word2 = 0; |
| 2425 | sgl->addr_lo = cpu_to_le32(putPaddrLow( |
| 2426 | dataphysaddr)); |
| 2427 | sgl->addr_hi = cpu_to_le32(putPaddrHigh( |
| 2428 | dataphysaddr)); |
| 2429 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 2430 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
| 2431 | bf_set(lpfc_sli4_sge_type, sgl, |
| 2432 | LPFC_SGE_TYPE_DATA); |
| 2433 | |
| 2434 | sgl->sge_len = cpu_to_le32(dma_len); |
| 2435 | dma_offset += dma_len; |
| 2436 | |
| 2437 | num_sge++; |
| 2438 | curr_data++; |
| 2439 | |
| 2440 | if (split_offset) { |
| 2441 | sgl++; |
| 2442 | j++; |
| 2443 | break; |
| 2444 | } |
| 2445 | |
| 2446 | /* Move to the next s/g segment if possible */ |
| 2447 | sgde = sg_next(sgde); |
| 2448 | |
| 2449 | sgl++; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2450 | } |
| 2451 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2452 | j++; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2453 | } |
| 2454 | |
| 2455 | if (protgroup_offset) { |
| 2456 | /* update the reference tag */ |
| 2457 | reftag += protgrp_blks; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2458 | continue; |
| 2459 | } |
| 2460 | |
| 2461 | /* are we done ? */ |
| 2462 | if (curr_prot == protcnt) { |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 2463 | /* mark the last SGL */ |
| 2464 | sgl--; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2465 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 2466 | alldone = 1; |
| 2467 | } else if (curr_prot < protcnt) { |
| 2468 | /* advance to next prot buffer */ |
| 2469 | sgpe = sg_next(sgpe); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2470 | |
| 2471 | /* update the reference tag */ |
| 2472 | reftag += protgrp_blks; |
| 2473 | } else { |
| 2474 | /* if we're here, we have a bug */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2475 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 2476 | "9085 BLKGRD: bug in %s\n", __func__); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2477 | } |
| 2478 | |
| 2479 | } while (!alldone); |
| 2480 | |
| 2481 | out: |
| 2482 | |
| 2483 | return num_sge; |
| 2484 | } |
| 2485 | |
| 2486 | /** |
| 2487 | * lpfc_prot_group_type - Get prtotection group type of SCSI command |
| 2488 | * @phba: The Hba for which this call is being executed. |
| 2489 | * @sc: pointer to scsi command we're working on |
| 2490 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2491 | * Given a SCSI command that supports DIF, determine composition of protection |
| 2492 | * groups involved in setting up buffer lists |
| 2493 | * |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2494 | * Returns: Protection group type (with or without DIF) |
| 2495 | * |
| 2496 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2497 | static int |
| 2498 | lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc) |
| 2499 | { |
| 2500 | int ret = LPFC_PG_TYPE_INVALID; |
| 2501 | unsigned char op = scsi_get_prot_op(sc); |
| 2502 | |
| 2503 | switch (op) { |
| 2504 | case SCSI_PROT_READ_STRIP: |
| 2505 | case SCSI_PROT_WRITE_INSERT: |
| 2506 | ret = LPFC_PG_TYPE_NO_DIF; |
| 2507 | break; |
| 2508 | case SCSI_PROT_READ_INSERT: |
| 2509 | case SCSI_PROT_WRITE_STRIP: |
| 2510 | case SCSI_PROT_READ_PASS: |
| 2511 | case SCSI_PROT_WRITE_PASS: |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2512 | ret = LPFC_PG_TYPE_DIF_BUF; |
| 2513 | break; |
| 2514 | default: |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2515 | if (phba) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2516 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2517 | "9021 Unsupported protection op:%d\n", |
| 2518 | op); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2519 | break; |
| 2520 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2521 | return ret; |
| 2522 | } |
| 2523 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2524 | /** |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2525 | * lpfc_bg_scsi_adjust_dl - Adjust SCSI data length for BlockGuard |
| 2526 | * @phba: The Hba for which this call is being executed. |
| 2527 | * @lpfc_cmd: The scsi buffer which is going to be adjusted. |
| 2528 | * |
| 2529 | * Adjust the data length to account for how much data |
| 2530 | * is actually on the wire. |
| 2531 | * |
| 2532 | * returns the adjusted data length |
| 2533 | **/ |
| 2534 | static int |
| 2535 | lpfc_bg_scsi_adjust_dl(struct lpfc_hba *phba, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 2536 | struct lpfc_io_buf *lpfc_cmd) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2537 | { |
| 2538 | struct scsi_cmnd *sc = lpfc_cmd->pCmd; |
| 2539 | int fcpdl; |
| 2540 | |
| 2541 | fcpdl = scsi_bufflen(sc); |
| 2542 | |
| 2543 | /* Check if there is protection data on the wire */ |
| 2544 | if (sc->sc_data_direction == DMA_FROM_DEVICE) { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2545 | /* Read check for protection data */ |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2546 | if (scsi_get_prot_op(sc) == SCSI_PROT_READ_INSERT) |
| 2547 | return fcpdl; |
| 2548 | |
| 2549 | } else { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2550 | /* Write check for protection data */ |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2551 | if (scsi_get_prot_op(sc) == SCSI_PROT_WRITE_STRIP) |
| 2552 | return fcpdl; |
| 2553 | } |
| 2554 | |
| 2555 | /* |
| 2556 | * 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] | 2557 | * DIF (trailer) attached to it. Must ajust FCP data length |
| 2558 | * to account for the protection data. |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2559 | */ |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2560 | fcpdl += (fcpdl / lpfc_cmd_blksize(sc)) * 8; |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2561 | |
| 2562 | return fcpdl; |
| 2563 | } |
| 2564 | |
| 2565 | /** |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2566 | * lpfc_bg_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec |
| 2567 | * @phba: The Hba for which this call is being executed. |
| 2568 | * @lpfc_cmd: The scsi buffer which is going to be prep'ed. |
| 2569 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2570 | * This is the protection/DIF aware version of |
| 2571 | * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2572 | * two functions eventually, but for now, it's here. |
| 2573 | * RETURNS 0 - SUCCESS, |
| 2574 | * 1 - Failed DMA map, retry. |
| 2575 | * 2 - Invalid scsi cmd or prot-type. Do not rety. |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2576 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2577 | static int |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2578 | lpfc_bg_scsi_prep_dma_buf_s3(struct lpfc_hba *phba, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 2579 | struct lpfc_io_buf *lpfc_cmd) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2580 | { |
| 2581 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 2582 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 2583 | struct ulp_bde64 *bpl = (struct ulp_bde64 *)lpfc_cmd->dma_sgl; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2584 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 2585 | uint32_t num_bde = 0; |
| 2586 | int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction; |
| 2587 | int prot_group_type = 0; |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2588 | int fcpdl; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2589 | int ret = 1; |
James Smart | 7c4042a | 2018-11-29 16:09:40 -0800 | [diff] [blame] | 2590 | struct lpfc_vport *vport = phba->pport; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2591 | |
| 2592 | /* |
| 2593 | * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd |
| 2594 | * fcp_rsp regions to the first data bde entry |
| 2595 | */ |
| 2596 | bpl += 2; |
| 2597 | if (scsi_sg_count(scsi_cmnd)) { |
| 2598 | /* |
| 2599 | * The driver stores the segment count returned from pci_map_sg |
| 2600 | * because this a count of dma-mappings used to map the use_sg |
| 2601 | * pages. They are not guaranteed to be the same for those |
| 2602 | * architectures that implement an IOMMU. |
| 2603 | */ |
| 2604 | datasegcnt = dma_map_sg(&phba->pcidev->dev, |
| 2605 | scsi_sglist(scsi_cmnd), |
| 2606 | scsi_sg_count(scsi_cmnd), datadir); |
| 2607 | if (unlikely(!datasegcnt)) |
| 2608 | return 1; |
| 2609 | |
| 2610 | lpfc_cmd->seg_cnt = datasegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2611 | |
| 2612 | /* First check if data segment count from SCSI Layer is good */ |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2613 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
| 2614 | WARN_ON_ONCE(lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt); |
| 2615 | ret = 2; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2616 | goto err; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2617 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2618 | |
| 2619 | prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd); |
| 2620 | |
| 2621 | switch (prot_group_type) { |
| 2622 | case LPFC_PG_TYPE_NO_DIF: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2623 | |
| 2624 | /* Here we need to add a PDE5 and PDE6 to the count */ |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2625 | if ((lpfc_cmd->seg_cnt + 2) > phba->cfg_total_seg_cnt) { |
| 2626 | ret = 2; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2627 | goto err; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2628 | } |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2629 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2630 | num_bde = lpfc_bg_setup_bpl(phba, scsi_cmnd, bpl, |
| 2631 | datasegcnt); |
Adam Buchbinder | c9404c9 | 2009-12-18 15:40:42 -0500 | [diff] [blame] | 2632 | /* we should have 2 or more entries in buffer list */ |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2633 | if (num_bde < 2) { |
| 2634 | ret = 2; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2635 | goto err; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2636 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2637 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2638 | |
| 2639 | case LPFC_PG_TYPE_DIF_BUF: |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2640 | /* |
| 2641 | * This type indicates that protection buffers are |
| 2642 | * passed to the driver, so that needs to be prepared |
| 2643 | * for DMA |
| 2644 | */ |
| 2645 | protsegcnt = dma_map_sg(&phba->pcidev->dev, |
| 2646 | scsi_prot_sglist(scsi_cmnd), |
| 2647 | scsi_prot_sg_count(scsi_cmnd), datadir); |
| 2648 | if (unlikely(!protsegcnt)) { |
| 2649 | scsi_dma_unmap(scsi_cmnd); |
| 2650 | return 1; |
| 2651 | } |
| 2652 | |
| 2653 | lpfc_cmd->prot_seg_cnt = protsegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2654 | |
| 2655 | /* |
| 2656 | * There is a minimun of 4 BPLs used for every |
| 2657 | * protection data segment. |
| 2658 | */ |
| 2659 | if ((lpfc_cmd->prot_seg_cnt * 4) > |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2660 | (phba->cfg_total_seg_cnt - 2)) { |
| 2661 | ret = 2; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2662 | goto err; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2663 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2664 | |
| 2665 | num_bde = lpfc_bg_setup_bpl_prot(phba, scsi_cmnd, bpl, |
| 2666 | datasegcnt, protsegcnt); |
Adam Buchbinder | c9404c9 | 2009-12-18 15:40:42 -0500 | [diff] [blame] | 2667 | /* we should have 3 or more entries in buffer list */ |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2668 | if ((num_bde < 3) || |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2669 | (num_bde > phba->cfg_total_seg_cnt)) { |
| 2670 | ret = 2; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2671 | goto err; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2672 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2673 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2674 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2675 | case LPFC_PG_TYPE_INVALID: |
| 2676 | default: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2677 | scsi_dma_unmap(scsi_cmnd); |
| 2678 | lpfc_cmd->seg_cnt = 0; |
| 2679 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2680 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2681 | "9022 Unexpected protection group %i\n", |
| 2682 | prot_group_type); |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2683 | return 2; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2684 | } |
| 2685 | } |
| 2686 | |
| 2687 | /* |
| 2688 | * Finish initializing those IOCB fields that are dependent on the |
| 2689 | * scsi_cmnd request_buffer. Note that the bdeSize is explicitly |
| 2690 | * reinitialized since all iocb memory resources are used many times |
| 2691 | * for transmit, receive, and continuation bpl's. |
| 2692 | */ |
| 2693 | iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| 2694 | iocb_cmd->un.fcpi64.bdl.bdeSize += (num_bde * sizeof(struct ulp_bde64)); |
| 2695 | iocb_cmd->ulpBdeCount = 1; |
| 2696 | iocb_cmd->ulpLe = 1; |
| 2697 | |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2698 | fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2699 | fcp_cmnd->fcpDl = be32_to_cpu(fcpdl); |
| 2700 | |
| 2701 | /* |
| 2702 | * Due to difference in data length between DIF/non-DIF paths, |
| 2703 | * we need to set word 4 of IOCB here |
| 2704 | */ |
| 2705 | iocb_cmd->un.fcpi.fcpi_parm = fcpdl; |
| 2706 | |
James Smart | 7c4042a | 2018-11-29 16:09:40 -0800 | [diff] [blame] | 2707 | /* |
| 2708 | * For First burst, we may need to adjust the initial transfer |
| 2709 | * length for DIF |
| 2710 | */ |
| 2711 | if (iocb_cmd->un.fcpi.fcpi_XRdy && |
| 2712 | (fcpdl < vport->cfg_first_burst_size)) |
| 2713 | iocb_cmd->un.fcpi.fcpi_XRdy = fcpdl; |
| 2714 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2715 | return 0; |
| 2716 | err: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2717 | if (lpfc_cmd->seg_cnt) |
| 2718 | scsi_dma_unmap(scsi_cmnd); |
| 2719 | if (lpfc_cmd->prot_seg_cnt) |
| 2720 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd), |
| 2721 | scsi_prot_sg_count(scsi_cmnd), |
| 2722 | scsi_cmnd->sc_data_direction); |
| 2723 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2724 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2725 | "9023 Cannot setup S/G List for HBA" |
| 2726 | "IO segs %d/%d BPL %d SCSI %d: %d %d\n", |
| 2727 | lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt, |
| 2728 | phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2729 | prot_group_type, num_bde); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2730 | |
| 2731 | lpfc_cmd->seg_cnt = 0; |
| 2732 | lpfc_cmd->prot_seg_cnt = 0; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 2733 | return ret; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2734 | } |
| 2735 | |
| 2736 | /* |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2737 | * This function calcuates the T10 DIF guard tag |
| 2738 | * on the specified data using a CRC algorithmn |
| 2739 | * using crc_t10dif. |
| 2740 | */ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 2741 | static uint16_t |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2742 | lpfc_bg_crc(uint8_t *data, int count) |
| 2743 | { |
| 2744 | uint16_t crc = 0; |
| 2745 | uint16_t x; |
| 2746 | |
| 2747 | crc = crc_t10dif(data, count); |
| 2748 | x = cpu_to_be16(crc); |
| 2749 | return x; |
| 2750 | } |
| 2751 | |
| 2752 | /* |
| 2753 | * This function calcuates the T10 DIF guard tag |
| 2754 | * on the specified data using a CSUM algorithmn |
| 2755 | * using ip_compute_csum. |
| 2756 | */ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 2757 | static uint16_t |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2758 | lpfc_bg_csum(uint8_t *data, int count) |
| 2759 | { |
| 2760 | uint16_t ret; |
| 2761 | |
| 2762 | ret = ip_compute_csum(data, count); |
| 2763 | return ret; |
| 2764 | } |
| 2765 | |
| 2766 | /* |
| 2767 | * This function examines the protection data to try to determine |
| 2768 | * what type of T10-DIF error occurred. |
| 2769 | */ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 2770 | static void |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 2771 | 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] | 2772 | { |
| 2773 | struct scatterlist *sgpe; /* s/g prot entry */ |
| 2774 | struct scatterlist *sgde; /* s/g data entry */ |
| 2775 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 2776 | struct scsi_dif_tuple *src = NULL; |
| 2777 | uint8_t *data_src = NULL; |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 2778 | uint16_t guard_tag; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2779 | uint16_t start_app_tag, app_tag; |
| 2780 | uint32_t start_ref_tag, ref_tag; |
| 2781 | int prot, protsegcnt; |
| 2782 | int err_type, len, data_len; |
| 2783 | int chk_ref, chk_app, chk_guard; |
| 2784 | uint16_t sum; |
| 2785 | unsigned blksize; |
| 2786 | |
| 2787 | err_type = BGS_GUARD_ERR_MASK; |
| 2788 | sum = 0; |
| 2789 | guard_tag = 0; |
| 2790 | |
| 2791 | /* First check to see if there is protection data to examine */ |
| 2792 | prot = scsi_get_prot_op(cmd); |
| 2793 | if ((prot == SCSI_PROT_READ_STRIP) || |
| 2794 | (prot == SCSI_PROT_WRITE_INSERT) || |
| 2795 | (prot == SCSI_PROT_NORMAL)) |
| 2796 | goto out; |
| 2797 | |
| 2798 | /* Currently the driver just supports ref_tag and guard_tag checking */ |
| 2799 | chk_ref = 1; |
| 2800 | chk_app = 0; |
| 2801 | chk_guard = 0; |
| 2802 | |
| 2803 | /* Setup a ptr to the protection data provided by the SCSI host */ |
| 2804 | sgpe = scsi_prot_sglist(cmd); |
| 2805 | protsegcnt = lpfc_cmd->prot_seg_cnt; |
| 2806 | |
| 2807 | if (sgpe && protsegcnt) { |
| 2808 | |
| 2809 | /* |
| 2810 | * We will only try to verify guard tag if the segment |
| 2811 | * data length is a multiple of the blksize. |
| 2812 | */ |
| 2813 | sgde = scsi_sglist(cmd); |
| 2814 | blksize = lpfc_cmd_blksize(cmd); |
| 2815 | data_src = (uint8_t *)sg_virt(sgde); |
| 2816 | data_len = sgde->length; |
| 2817 | if ((data_len & (blksize - 1)) == 0) |
| 2818 | chk_guard = 1; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2819 | |
James Smart | e85d8f9 | 2013-05-31 17:04:10 -0400 | [diff] [blame] | 2820 | src = (struct scsi_dif_tuple *)sg_virt(sgpe); |
Bart Van Assche | 4221c8a | 2021-08-09 16:03:30 -0700 | [diff] [blame] | 2821 | start_ref_tag = t10_pi_ref_tag(scsi_cmd_to_rq(cmd)); |
James Smart | 68a6a66 | 2021-03-01 09:18:02 -0800 | [diff] [blame] | 2822 | if (start_ref_tag == LPFC_INVALID_REFTAG) |
| 2823 | goto out; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2824 | start_app_tag = src->app_tag; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2825 | len = sgpe->length; |
| 2826 | while (src && protsegcnt) { |
| 2827 | while (len) { |
| 2828 | |
| 2829 | /* |
| 2830 | * First check to see if a protection data |
| 2831 | * check is valid |
| 2832 | */ |
Dmitry Monakhov | 128b6f9 | 2017-06-29 11:31:12 -0700 | [diff] [blame] | 2833 | if ((src->ref_tag == T10_PI_REF_ESCAPE) || |
| 2834 | (src->app_tag == T10_PI_APP_ESCAPE)) { |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2835 | start_ref_tag++; |
| 2836 | goto skipit; |
| 2837 | } |
| 2838 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2839 | /* First Guard Tag checking */ |
| 2840 | if (chk_guard) { |
| 2841 | guard_tag = src->guard_tag; |
| 2842 | if (lpfc_cmd_guard_csum(cmd)) |
| 2843 | sum = lpfc_bg_csum(data_src, |
| 2844 | blksize); |
| 2845 | else |
| 2846 | sum = lpfc_bg_crc(data_src, |
| 2847 | blksize); |
| 2848 | if ((guard_tag != sum)) { |
| 2849 | err_type = BGS_GUARD_ERR_MASK; |
| 2850 | goto out; |
| 2851 | } |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2852 | } |
| 2853 | |
| 2854 | /* Reference Tag checking */ |
| 2855 | ref_tag = be32_to_cpu(src->ref_tag); |
| 2856 | if (chk_ref && (ref_tag != start_ref_tag)) { |
| 2857 | err_type = BGS_REFTAG_ERR_MASK; |
| 2858 | goto out; |
| 2859 | } |
| 2860 | start_ref_tag++; |
| 2861 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2862 | /* App Tag checking */ |
| 2863 | app_tag = src->app_tag; |
| 2864 | if (chk_app && (app_tag != start_app_tag)) { |
| 2865 | err_type = BGS_APPTAG_ERR_MASK; |
| 2866 | goto out; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2867 | } |
| 2868 | skipit: |
| 2869 | len -= sizeof(struct scsi_dif_tuple); |
| 2870 | if (len < 0) |
| 2871 | len = 0; |
| 2872 | src++; |
| 2873 | |
| 2874 | data_src += blksize; |
| 2875 | data_len -= blksize; |
| 2876 | |
| 2877 | /* |
| 2878 | * Are we at the end of the Data segment? |
| 2879 | * The data segment is only used for Guard |
| 2880 | * tag checking. |
| 2881 | */ |
| 2882 | if (chk_guard && (data_len == 0)) { |
| 2883 | chk_guard = 0; |
| 2884 | sgde = sg_next(sgde); |
| 2885 | if (!sgde) |
| 2886 | goto out; |
| 2887 | |
| 2888 | data_src = (uint8_t *)sg_virt(sgde); |
| 2889 | data_len = sgde->length; |
| 2890 | if ((data_len & (blksize - 1)) == 0) |
| 2891 | chk_guard = 1; |
| 2892 | } |
| 2893 | } |
| 2894 | |
| 2895 | /* Goto the next Protection data segment */ |
| 2896 | sgpe = sg_next(sgpe); |
| 2897 | if (sgpe) { |
| 2898 | src = (struct scsi_dif_tuple *)sg_virt(sgpe); |
| 2899 | len = sgpe->length; |
| 2900 | } else { |
| 2901 | src = NULL; |
| 2902 | } |
| 2903 | protsegcnt--; |
| 2904 | } |
| 2905 | } |
| 2906 | out: |
| 2907 | if (err_type == BGS_GUARD_ERR_MASK) { |
Hannes Reinecke | f2b1e9c | 2021-04-27 10:30:13 +0200 | [diff] [blame] | 2908 | scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x1); |
| 2909 | set_host_byte(cmd, DID_ABORT); |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2910 | phba->bg_guard_err_cnt++; |
| 2911 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
James Smart | 68a6a66 | 2021-03-01 09:18:02 -0800 | [diff] [blame] | 2912 | "9069 BLKGRD: reftag %x grd_tag err %x != %x\n", |
Bart Van Assche | 4221c8a | 2021-08-09 16:03:30 -0700 | [diff] [blame] | 2913 | t10_pi_ref_tag(scsi_cmd_to_rq(cmd)), |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2914 | sum, guard_tag); |
| 2915 | |
| 2916 | } else if (err_type == BGS_REFTAG_ERR_MASK) { |
Hannes Reinecke | f2b1e9c | 2021-04-27 10:30:13 +0200 | [diff] [blame] | 2917 | scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x3); |
| 2918 | set_host_byte(cmd, DID_ABORT); |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2919 | |
| 2920 | phba->bg_reftag_err_cnt++; |
| 2921 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
James Smart | 68a6a66 | 2021-03-01 09:18:02 -0800 | [diff] [blame] | 2922 | "9066 BLKGRD: reftag %x ref_tag err %x != %x\n", |
Bart Van Assche | 4221c8a | 2021-08-09 16:03:30 -0700 | [diff] [blame] | 2923 | t10_pi_ref_tag(scsi_cmd_to_rq(cmd)), |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2924 | ref_tag, start_ref_tag); |
| 2925 | |
| 2926 | } else if (err_type == BGS_APPTAG_ERR_MASK) { |
Hannes Reinecke | f2b1e9c | 2021-04-27 10:30:13 +0200 | [diff] [blame] | 2927 | scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x2); |
| 2928 | set_host_byte(cmd, DID_ABORT); |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2929 | |
| 2930 | phba->bg_apptag_err_cnt++; |
| 2931 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
James Smart | 68a6a66 | 2021-03-01 09:18:02 -0800 | [diff] [blame] | 2932 | "9041 BLKGRD: reftag %x app_tag err %x != %x\n", |
Bart Van Assche | 4221c8a | 2021-08-09 16:03:30 -0700 | [diff] [blame] | 2933 | t10_pi_ref_tag(scsi_cmd_to_rq(cmd)), |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2934 | app_tag, start_app_tag); |
| 2935 | } |
| 2936 | } |
| 2937 | |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 2938 | /* |
| 2939 | * This function checks for BlockGuard errors detected by |
| 2940 | * the HBA. In case of errors, the ASC/ASCQ fields in the |
| 2941 | * sense buffer will be set accordingly, paired with |
| 2942 | * ILLEGAL_REQUEST to signal to the kernel that the HBA |
| 2943 | * detected corruption. |
| 2944 | * |
| 2945 | * Returns: |
| 2946 | * 0 - No error found |
| 2947 | * 1 - BlockGuard error found |
| 2948 | * -1 - Internal error (bad profile, ...etc) |
| 2949 | */ |
| 2950 | static int |
| 2951 | lpfc_sli4_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd, |
| 2952 | struct lpfc_wcqe_complete *wcqe) |
| 2953 | { |
| 2954 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 2955 | int ret = 0; |
| 2956 | u32 status = bf_get(lpfc_wcqe_c_status, wcqe); |
| 2957 | u32 bghm = 0; |
| 2958 | u32 bgstat = 0; |
| 2959 | u64 failing_sector = 0; |
| 2960 | |
| 2961 | if (status == CQE_STATUS_DI_ERROR) { |
| 2962 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ |
| 2963 | bgstat |= BGS_GUARD_ERR_MASK; |
| 2964 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* AppTag Check failed */ |
| 2965 | bgstat |= BGS_APPTAG_ERR_MASK; |
| 2966 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* RefTag Check failed */ |
| 2967 | bgstat |= BGS_REFTAG_ERR_MASK; |
| 2968 | |
| 2969 | /* Check to see if there was any good data before the error */ |
| 2970 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { |
| 2971 | bgstat |= BGS_HI_WATER_MARK_PRESENT_MASK; |
| 2972 | bghm = wcqe->total_data_placed; |
| 2973 | } |
| 2974 | |
| 2975 | /* |
| 2976 | * Set ALL the error bits to indicate we don't know what |
| 2977 | * type of error it is. |
| 2978 | */ |
| 2979 | if (!bgstat) |
| 2980 | bgstat |= (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | |
| 2981 | BGS_GUARD_ERR_MASK); |
| 2982 | } |
| 2983 | |
| 2984 | if (lpfc_bgs_get_guard_err(bgstat)) { |
| 2985 | ret = 1; |
| 2986 | |
Hannes Reinecke | f2b1e9c | 2021-04-27 10:30:13 +0200 | [diff] [blame] | 2987 | scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x1); |
| 2988 | set_host_byte(cmd, DID_ABORT); |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 2989 | phba->bg_guard_err_cnt++; |
| 2990 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 2991 | "9059 BLKGRD: Guard Tag error in cmd" |
| 2992 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 2993 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 2994 | (unsigned long long)scsi_get_lba(cmd), |
Bart Van Assche | 4221c8a | 2021-08-09 16:03:30 -0700 | [diff] [blame] | 2995 | blk_rq_sectors(scsi_cmd_to_rq(cmd)), bgstat, bghm); |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 2996 | } |
| 2997 | |
| 2998 | if (lpfc_bgs_get_reftag_err(bgstat)) { |
| 2999 | ret = 1; |
| 3000 | |
Hannes Reinecke | f2b1e9c | 2021-04-27 10:30:13 +0200 | [diff] [blame] | 3001 | scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x3); |
| 3002 | set_host_byte(cmd, DID_ABORT); |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 3003 | |
| 3004 | phba->bg_reftag_err_cnt++; |
| 3005 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3006 | "9060 BLKGRD: Ref Tag error in cmd" |
| 3007 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3008 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3009 | (unsigned long long)scsi_get_lba(cmd), |
Bart Van Assche | 4221c8a | 2021-08-09 16:03:30 -0700 | [diff] [blame] | 3010 | blk_rq_sectors(scsi_cmd_to_rq(cmd)), bgstat, bghm); |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 3011 | } |
| 3012 | |
| 3013 | if (lpfc_bgs_get_apptag_err(bgstat)) { |
| 3014 | ret = 1; |
| 3015 | |
Hannes Reinecke | f2b1e9c | 2021-04-27 10:30:13 +0200 | [diff] [blame] | 3016 | scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x2); |
| 3017 | set_host_byte(cmd, DID_ABORT); |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 3018 | |
| 3019 | phba->bg_apptag_err_cnt++; |
| 3020 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3021 | "9062 BLKGRD: App Tag error in cmd" |
| 3022 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3023 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3024 | (unsigned long long)scsi_get_lba(cmd), |
Bart Van Assche | 4221c8a | 2021-08-09 16:03:30 -0700 | [diff] [blame] | 3025 | blk_rq_sectors(scsi_cmd_to_rq(cmd)), bgstat, bghm); |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 3026 | } |
| 3027 | |
| 3028 | if (lpfc_bgs_get_hi_water_mark_present(bgstat)) { |
| 3029 | /* |
| 3030 | * setup sense data descriptor 0 per SPC-4 as an information |
| 3031 | * field, and put the failing LBA in it. |
| 3032 | * This code assumes there was also a guard/app/ref tag error |
| 3033 | * indication. |
| 3034 | */ |
| 3035 | cmd->sense_buffer[7] = 0xc; /* Additional sense length */ |
| 3036 | cmd->sense_buffer[8] = 0; /* Information descriptor type */ |
| 3037 | cmd->sense_buffer[9] = 0xa; /* Additional descriptor length */ |
| 3038 | cmd->sense_buffer[10] = 0x80; /* Validity bit */ |
| 3039 | |
| 3040 | /* bghm is a "on the wire" FC frame based count */ |
| 3041 | switch (scsi_get_prot_op(cmd)) { |
| 3042 | case SCSI_PROT_READ_INSERT: |
| 3043 | case SCSI_PROT_WRITE_STRIP: |
| 3044 | bghm /= cmd->device->sector_size; |
| 3045 | break; |
| 3046 | case SCSI_PROT_READ_STRIP: |
| 3047 | case SCSI_PROT_WRITE_INSERT: |
| 3048 | case SCSI_PROT_READ_PASS: |
| 3049 | case SCSI_PROT_WRITE_PASS: |
| 3050 | bghm /= (cmd->device->sector_size + |
| 3051 | sizeof(struct scsi_dif_tuple)); |
| 3052 | break; |
| 3053 | } |
| 3054 | |
| 3055 | failing_sector = scsi_get_lba(cmd); |
| 3056 | failing_sector += bghm; |
| 3057 | |
| 3058 | /* Descriptor Information */ |
| 3059 | put_unaligned_be64(failing_sector, &cmd->sense_buffer[12]); |
| 3060 | } |
| 3061 | |
| 3062 | if (!ret) { |
| 3063 | /* No error was reported - problem in FW? */ |
| 3064 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3065 | "9068 BLKGRD: Unknown error in cmd" |
| 3066 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3067 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3068 | (unsigned long long)scsi_get_lba(cmd), |
Bart Van Assche | 4221c8a | 2021-08-09 16:03:30 -0700 | [diff] [blame] | 3069 | blk_rq_sectors(scsi_cmd_to_rq(cmd)), bgstat, bghm); |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 3070 | |
| 3071 | /* Calcuate what type of error it was */ |
| 3072 | lpfc_calc_bg_err(phba, lpfc_cmd); |
| 3073 | } |
| 3074 | return ret; |
| 3075 | } |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3076 | |
| 3077 | /* |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3078 | * This function checks for BlockGuard errors detected by |
| 3079 | * the HBA. In case of errors, the ASC/ASCQ fields in the |
| 3080 | * sense buffer will be set accordingly, paired with |
| 3081 | * ILLEGAL_REQUEST to signal to the kernel that the HBA |
| 3082 | * detected corruption. |
| 3083 | * |
| 3084 | * Returns: |
| 3085 | * 0 - No error found |
| 3086 | * 1 - BlockGuard error found |
| 3087 | * -1 - Internal error (bad profile, ...etc) |
| 3088 | */ |
| 3089 | static int |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3090 | lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd, |
| 3091 | struct lpfc_iocbq *pIocbOut) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3092 | { |
| 3093 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 3094 | struct sli3_bg_fields *bgf = &pIocbOut->iocb.unsli3.sli3_bg; |
| 3095 | int ret = 0; |
| 3096 | uint32_t bghm = bgf->bghm; |
| 3097 | uint32_t bgstat = bgf->bgstat; |
| 3098 | uint64_t failing_sector = 0; |
| 3099 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3100 | if (lpfc_bgs_get_invalid_prof(bgstat)) { |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 3101 | cmd->result = DID_ERROR << 16; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3102 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
James Smart | 68a6a66 | 2021-03-01 09:18:02 -0800 | [diff] [blame] | 3103 | "9072 BLKGRD: Invalid BG Profile in cmd " |
| 3104 | "0x%x reftag 0x%x blk cnt 0x%x " |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3105 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
Bart Van Assche | 4221c8a | 2021-08-09 16:03:30 -0700 | [diff] [blame] | 3106 | t10_pi_ref_tag(scsi_cmd_to_rq(cmd)), |
| 3107 | blk_rq_sectors(scsi_cmd_to_rq(cmd)), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3108 | ret = (-1); |
| 3109 | goto out; |
| 3110 | } |
| 3111 | |
| 3112 | if (lpfc_bgs_get_uninit_dif_block(bgstat)) { |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 3113 | cmd->result = DID_ERROR << 16; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3114 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
James Smart | 68a6a66 | 2021-03-01 09:18:02 -0800 | [diff] [blame] | 3115 | "9073 BLKGRD: Invalid BG PDIF Block in cmd " |
| 3116 | "0x%x reftag 0x%x blk cnt 0x%x " |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3117 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
Bart Van Assche | 4221c8a | 2021-08-09 16:03:30 -0700 | [diff] [blame] | 3118 | t10_pi_ref_tag(scsi_cmd_to_rq(cmd)), |
| 3119 | blk_rq_sectors(scsi_cmd_to_rq(cmd)), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3120 | ret = (-1); |
| 3121 | goto out; |
| 3122 | } |
| 3123 | |
| 3124 | if (lpfc_bgs_get_guard_err(bgstat)) { |
| 3125 | ret = 1; |
| 3126 | |
Hannes Reinecke | f2b1e9c | 2021-04-27 10:30:13 +0200 | [diff] [blame] | 3127 | scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x1); |
| 3128 | set_host_byte(cmd, DID_ABORT); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3129 | phba->bg_guard_err_cnt++; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3130 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
James Smart | 68a6a66 | 2021-03-01 09:18:02 -0800 | [diff] [blame] | 3131 | "9055 BLKGRD: Guard Tag error in cmd " |
| 3132 | "0x%x reftag 0x%x blk cnt 0x%x " |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3133 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
Bart Van Assche | 4221c8a | 2021-08-09 16:03:30 -0700 | [diff] [blame] | 3134 | t10_pi_ref_tag(scsi_cmd_to_rq(cmd)), |
| 3135 | blk_rq_sectors(scsi_cmd_to_rq(cmd)), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3136 | } |
| 3137 | |
| 3138 | if (lpfc_bgs_get_reftag_err(bgstat)) { |
| 3139 | ret = 1; |
| 3140 | |
Hannes Reinecke | f2b1e9c | 2021-04-27 10:30:13 +0200 | [diff] [blame] | 3141 | scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x3); |
| 3142 | set_host_byte(cmd, DID_ABORT); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3143 | |
| 3144 | phba->bg_reftag_err_cnt++; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3145 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
James Smart | 68a6a66 | 2021-03-01 09:18:02 -0800 | [diff] [blame] | 3146 | "9056 BLKGRD: Ref Tag error in cmd " |
| 3147 | "0x%x reftag 0x%x blk cnt 0x%x " |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3148 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
Bart Van Assche | 4221c8a | 2021-08-09 16:03:30 -0700 | [diff] [blame] | 3149 | t10_pi_ref_tag(scsi_cmd_to_rq(cmd)), |
| 3150 | blk_rq_sectors(scsi_cmd_to_rq(cmd)), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3151 | } |
| 3152 | |
| 3153 | if (lpfc_bgs_get_apptag_err(bgstat)) { |
| 3154 | ret = 1; |
| 3155 | |
Hannes Reinecke | f2b1e9c | 2021-04-27 10:30:13 +0200 | [diff] [blame] | 3156 | scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x2); |
| 3157 | set_host_byte(cmd, DID_ABORT); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3158 | |
| 3159 | phba->bg_apptag_err_cnt++; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3160 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
James Smart | 68a6a66 | 2021-03-01 09:18:02 -0800 | [diff] [blame] | 3161 | "9061 BLKGRD: App Tag error in cmd " |
| 3162 | "0x%x reftag 0x%x blk cnt 0x%x " |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3163 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
Bart Van Assche | 4221c8a | 2021-08-09 16:03:30 -0700 | [diff] [blame] | 3164 | t10_pi_ref_tag(scsi_cmd_to_rq(cmd)), |
| 3165 | blk_rq_sectors(scsi_cmd_to_rq(cmd)), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3166 | } |
| 3167 | |
| 3168 | if (lpfc_bgs_get_hi_water_mark_present(bgstat)) { |
| 3169 | /* |
| 3170 | * setup sense data descriptor 0 per SPC-4 as an information |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 3171 | * field, and put the failing LBA in it. |
| 3172 | * This code assumes there was also a guard/app/ref tag error |
| 3173 | * indication. |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3174 | */ |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 3175 | cmd->sense_buffer[7] = 0xc; /* Additional sense length */ |
| 3176 | cmd->sense_buffer[8] = 0; /* Information descriptor type */ |
| 3177 | cmd->sense_buffer[9] = 0xa; /* Additional descriptor length */ |
| 3178 | cmd->sense_buffer[10] = 0x80; /* Validity bit */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3179 | |
| 3180 | /* bghm is a "on the wire" FC frame based count */ |
| 3181 | switch (scsi_get_prot_op(cmd)) { |
| 3182 | case SCSI_PROT_READ_INSERT: |
| 3183 | case SCSI_PROT_WRITE_STRIP: |
| 3184 | bghm /= cmd->device->sector_size; |
| 3185 | break; |
| 3186 | case SCSI_PROT_READ_STRIP: |
| 3187 | case SCSI_PROT_WRITE_INSERT: |
| 3188 | case SCSI_PROT_READ_PASS: |
| 3189 | case SCSI_PROT_WRITE_PASS: |
| 3190 | bghm /= (cmd->device->sector_size + |
| 3191 | sizeof(struct scsi_dif_tuple)); |
| 3192 | break; |
| 3193 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3194 | |
| 3195 | failing_sector = scsi_get_lba(cmd); |
| 3196 | failing_sector += bghm; |
| 3197 | |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 3198 | /* Descriptor Information */ |
| 3199 | put_unaligned_be64(failing_sector, &cmd->sense_buffer[12]); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3200 | } |
| 3201 | |
| 3202 | if (!ret) { |
| 3203 | /* No error was reported - problem in FW? */ |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3204 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
James Smart | 68a6a66 | 2021-03-01 09:18:02 -0800 | [diff] [blame] | 3205 | "9057 BLKGRD: Unknown error in cmd " |
| 3206 | "0x%x reftag 0x%x blk cnt 0x%x " |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3207 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
Bart Van Assche | 4221c8a | 2021-08-09 16:03:30 -0700 | [diff] [blame] | 3208 | t10_pi_ref_tag(scsi_cmd_to_rq(cmd)), |
| 3209 | blk_rq_sectors(scsi_cmd_to_rq(cmd)), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3210 | |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3211 | /* Calcuate what type of error it was */ |
| 3212 | lpfc_calc_bg_err(phba, lpfc_cmd); |
| 3213 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3214 | out: |
| 3215 | return ret; |
| 3216 | } |
| 3217 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3218 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3219 | * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec |
| 3220 | * @phba: The Hba for which this call is being executed. |
| 3221 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3222 | * |
| 3223 | * This routine does the pci dma mapping for scatter-gather list of scsi cmnd |
| 3224 | * field of @lpfc_cmd for device with SLI-4 interface spec. |
| 3225 | * |
| 3226 | * Return codes: |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3227 | * 2 - Error - Do not retry |
| 3228 | * 1 - Error - Retry |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 3229 | * 0 - Success |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3230 | **/ |
| 3231 | static int |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3232 | 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] | 3233 | { |
| 3234 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 3235 | struct scatterlist *sgel = NULL; |
| 3236 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3237 | struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3238 | struct sli4_sge *first_data_sgl; |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 3239 | struct lpfc_iocbq *pwqeq = &lpfc_cmd->cur_iocbq; |
| 3240 | struct lpfc_vport *vport = phba->pport; |
| 3241 | union lpfc_wqe128 *wqe = &pwqeq->wqe; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3242 | dma_addr_t physaddr; |
| 3243 | uint32_t num_bde = 0; |
| 3244 | uint32_t dma_len; |
| 3245 | uint32_t dma_offset = 0; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3246 | int nseg, i, j; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3247 | struct ulp_bde64 *bde; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3248 | bool lsp_just_set = false; |
| 3249 | struct sli4_hybrid_sgl *sgl_xtra = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3250 | |
| 3251 | /* |
| 3252 | * There are three possibilities here - use scatter-gather segment, use |
| 3253 | * the single mapping, or neither. Start the lpfc command prep by |
| 3254 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 3255 | * data bde entry. |
| 3256 | */ |
| 3257 | if (scsi_sg_count(scsi_cmnd)) { |
| 3258 | /* |
| 3259 | * The driver stores the segment count returned from pci_map_sg |
| 3260 | * because this a count of dma-mappings used to map the use_sg |
| 3261 | * pages. They are not guaranteed to be the same for those |
| 3262 | * architectures that implement an IOMMU. |
| 3263 | */ |
| 3264 | |
| 3265 | nseg = scsi_dma_map(scsi_cmnd); |
James Smart | 5116fbf | 2015-05-22 10:42:39 -0400 | [diff] [blame] | 3266 | if (unlikely(nseg <= 0)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3267 | return 1; |
| 3268 | sgl += 1; |
| 3269 | /* clear the last flag in the fcp_rsp map entry */ |
| 3270 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 3271 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 3272 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 3273 | sgl += 1; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3274 | first_data_sgl = sgl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3275 | lpfc_cmd->seg_cnt = nseg; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3276 | if (!phba->cfg_xpsgl && |
| 3277 | lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3278 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 3279 | "9074 BLKGRD:" |
| 3280 | " %s: Too many sg segments from " |
| 3281 | "dma_map_sg. Config %d, seg_cnt %d\n", |
| 3282 | __func__, phba->cfg_sg_seg_cnt, |
| 3283 | lpfc_cmd->seg_cnt); |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3284 | WARN_ON_ONCE(lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3285 | lpfc_cmd->seg_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3286 | scsi_dma_unmap(scsi_cmnd); |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3287 | return 2; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3288 | } |
| 3289 | |
| 3290 | /* |
| 3291 | * The driver established a maximum scatter-gather segment count |
| 3292 | * during probe that limits the number of sg elements in any |
| 3293 | * single scsi command. Just run through the seg_cnt and format |
| 3294 | * the sge's. |
| 3295 | * When using SLI-3 the driver will try to fit all the BDEs into |
| 3296 | * the IOCB. If it can't then the BDEs get added to a BPL as it |
| 3297 | * does for SLI-2 mode. |
| 3298 | */ |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3299 | |
| 3300 | /* for tracking segment boundaries */ |
| 3301 | sgel = scsi_sglist(scsi_cmnd); |
| 3302 | j = 2; |
| 3303 | for (i = 0; i < nseg; i++) { |
| 3304 | sgl->word2 = 0; |
| 3305 | if ((num_bde + 1) == nseg) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3306 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3307 | bf_set(lpfc_sli4_sge_type, sgl, |
| 3308 | LPFC_SGE_TYPE_DATA); |
| 3309 | } else { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3310 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3311 | |
| 3312 | /* do we need to expand the segment */ |
| 3313 | if (!lsp_just_set && |
| 3314 | !((j + 1) % phba->border_sge_num) && |
| 3315 | ((nseg - 1) != i)) { |
| 3316 | /* set LSP type */ |
| 3317 | bf_set(lpfc_sli4_sge_type, sgl, |
| 3318 | LPFC_SGE_TYPE_LSP); |
| 3319 | |
| 3320 | sgl_xtra = lpfc_get_sgl_per_hdwq( |
| 3321 | phba, lpfc_cmd); |
| 3322 | |
| 3323 | if (unlikely(!sgl_xtra)) { |
| 3324 | lpfc_cmd->seg_cnt = 0; |
| 3325 | scsi_dma_unmap(scsi_cmnd); |
| 3326 | return 1; |
| 3327 | } |
| 3328 | sgl->addr_lo = cpu_to_le32(putPaddrLow( |
| 3329 | sgl_xtra->dma_phys_sgl)); |
| 3330 | sgl->addr_hi = cpu_to_le32(putPaddrHigh( |
| 3331 | sgl_xtra->dma_phys_sgl)); |
| 3332 | |
| 3333 | } else { |
| 3334 | bf_set(lpfc_sli4_sge_type, sgl, |
| 3335 | LPFC_SGE_TYPE_DATA); |
| 3336 | } |
| 3337 | } |
| 3338 | |
| 3339 | if (!(bf_get(lpfc_sli4_sge_type, sgl) & |
| 3340 | LPFC_SGE_TYPE_LSP)) { |
| 3341 | if ((nseg - 1) == i) |
| 3342 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 3343 | |
| 3344 | physaddr = sg_dma_address(sgel); |
| 3345 | dma_len = sg_dma_len(sgel); |
| 3346 | sgl->addr_lo = cpu_to_le32(putPaddrLow( |
| 3347 | physaddr)); |
| 3348 | sgl->addr_hi = cpu_to_le32(putPaddrHigh( |
| 3349 | physaddr)); |
| 3350 | |
| 3351 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
| 3352 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 3353 | sgl->sge_len = cpu_to_le32(dma_len); |
| 3354 | |
| 3355 | dma_offset += dma_len; |
| 3356 | sgel = sg_next(sgel); |
| 3357 | |
| 3358 | sgl++; |
| 3359 | lsp_just_set = false; |
| 3360 | |
| 3361 | } else { |
| 3362 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 3363 | sgl->sge_len = cpu_to_le32( |
| 3364 | phba->cfg_sg_dma_buf_size); |
| 3365 | |
| 3366 | sgl = (struct sli4_sge *)sgl_xtra->dma_sgl; |
| 3367 | i = i - 1; |
| 3368 | |
| 3369 | lsp_just_set = true; |
| 3370 | } |
| 3371 | |
| 3372 | j++; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3373 | } |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 3374 | /* |
| 3375 | * Setup the first Payload BDE. For FCoE we just key off |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 3376 | * Performance Hints, for FC we use lpfc_enable_pbde. |
| 3377 | * We populate words 13-15 of IOCB/WQE. |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 3378 | */ |
| 3379 | if ((phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) || |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 3380 | phba->cfg_enable_pbde) { |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3381 | bde = (struct ulp_bde64 *) |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 3382 | &wqe->words[13]; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3383 | bde->addrLow = first_data_sgl->addr_lo; |
| 3384 | bde->addrHigh = first_data_sgl->addr_hi; |
| 3385 | bde->tus.f.bdeSize = |
| 3386 | le32_to_cpu(first_data_sgl->sge_len); |
| 3387 | bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 3388 | bde->tus.w = cpu_to_le32(bde->tus.w); |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 3389 | |
| 3390 | } else { |
| 3391 | memset(&wqe->words[13], 0, (sizeof(uint32_t) * 3)); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3392 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3393 | } else { |
| 3394 | sgl += 1; |
| 3395 | /* clear the last flag in the fcp_rsp map entry */ |
| 3396 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 3397 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 3398 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 3399 | |
| 3400 | if ((phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) || |
| 3401 | phba->cfg_enable_pbde) { |
| 3402 | bde = (struct ulp_bde64 *) |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 3403 | &wqe->words[13]; |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 3404 | memset(bde, 0, (sizeof(uint32_t) * 3)); |
| 3405 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3406 | } |
| 3407 | |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 3408 | /* Word 11 */ |
| 3409 | if (phba->cfg_enable_pbde) |
| 3410 | bf_set(wqe_pbde, &wqe->generic.wqe_com, 1); |
| 3411 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3412 | /* |
| 3413 | * Finish initializing those IOCB fields that are dependent on the |
| 3414 | * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is |
| 3415 | * explicitly reinitialized. |
| 3416 | * all iocb memory resources are reused. |
| 3417 | */ |
| 3418 | fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 3419 | /* Set first-burst provided it was successfully negotiated */ |
| 3420 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
| 3421 | vport->cfg_first_burst_size && |
| 3422 | scsi_cmnd->sc_data_direction == DMA_TO_DEVICE) { |
| 3423 | u32 init_len, total_len; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3424 | |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 3425 | total_len = be32_to_cpu(fcp_cmnd->fcpDl); |
| 3426 | init_len = min(total_len, vport->cfg_first_burst_size); |
| 3427 | |
| 3428 | /* Word 4 & 5 */ |
| 3429 | wqe->fcp_iwrite.initial_xfer_len = init_len; |
| 3430 | wqe->fcp_iwrite.total_xfer_len = total_len; |
| 3431 | } else { |
| 3432 | /* Word 4 */ |
| 3433 | wqe->fcp_iwrite.total_xfer_len = |
| 3434 | be32_to_cpu(fcp_cmnd->fcpDl); |
| 3435 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 3436 | |
| 3437 | /* |
| 3438 | * If the OAS driver feature is enabled and the lun is enabled for |
| 3439 | * OAS, set the oas iocb related flags. |
| 3440 | */ |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 3441 | if ((phba->cfg_fof) && ((struct lpfc_device_data *) |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 3442 | scsi_cmnd->device->hostdata)->oas_enabled) { |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 3443 | lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 3444 | lpfc_cmd->cur_iocbq.priority = ((struct lpfc_device_data *) |
| 3445 | scsi_cmnd->device->hostdata)->priority; |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 3446 | |
| 3447 | /* Word 10 */ |
| 3448 | bf_set(wqe_oas, &wqe->generic.wqe_com, 1); |
| 3449 | bf_set(wqe_ccpe, &wqe->generic.wqe_com, 1); |
| 3450 | |
| 3451 | if (lpfc_cmd->cur_iocbq.priority) |
| 3452 | bf_set(wqe_ccp, &wqe->generic.wqe_com, |
| 3453 | (lpfc_cmd->cur_iocbq.priority << 1)); |
| 3454 | else |
| 3455 | bf_set(wqe_ccp, &wqe->generic.wqe_com, |
| 3456 | (phba->cfg_XLanePriority << 1)); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 3457 | } |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3458 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3459 | return 0; |
| 3460 | } |
| 3461 | |
| 3462 | /** |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3463 | * lpfc_bg_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec |
| 3464 | * @phba: The Hba for which this call is being executed. |
| 3465 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3466 | * |
| 3467 | * This is the protection/DIF aware version of |
| 3468 | * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the |
| 3469 | * two functions eventually, but for now, it's here |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3470 | * Return codes: |
| 3471 | * 2 - Error - Do not retry |
| 3472 | * 1 - Error - Retry |
| 3473 | * 0 - Success |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3474 | **/ |
| 3475 | static int |
| 3476 | lpfc_bg_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3477 | struct lpfc_io_buf *lpfc_cmd) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3478 | { |
| 3479 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 3480 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3481 | struct sli4_sge *sgl = (struct sli4_sge *)(lpfc_cmd->dma_sgl); |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 3482 | struct lpfc_iocbq *pwqeq = &lpfc_cmd->cur_iocbq; |
| 3483 | union lpfc_wqe128 *wqe = &pwqeq->wqe; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3484 | uint32_t num_sge = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3485 | int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction; |
| 3486 | int prot_group_type = 0; |
| 3487 | int fcpdl; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3488 | int ret = 1; |
James Smart | 7c4042a | 2018-11-29 16:09:40 -0800 | [diff] [blame] | 3489 | struct lpfc_vport *vport = phba->pport; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3490 | |
| 3491 | /* |
| 3492 | * Start the lpfc command prep by bumping the sgl beyond fcp_cmnd |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3493 | * fcp_rsp regions to the first data sge entry |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3494 | */ |
| 3495 | if (scsi_sg_count(scsi_cmnd)) { |
| 3496 | /* |
| 3497 | * The driver stores the segment count returned from pci_map_sg |
| 3498 | * because this a count of dma-mappings used to map the use_sg |
| 3499 | * pages. They are not guaranteed to be the same for those |
| 3500 | * architectures that implement an IOMMU. |
| 3501 | */ |
| 3502 | datasegcnt = dma_map_sg(&phba->pcidev->dev, |
| 3503 | scsi_sglist(scsi_cmnd), |
| 3504 | scsi_sg_count(scsi_cmnd), datadir); |
| 3505 | if (unlikely(!datasegcnt)) |
| 3506 | return 1; |
| 3507 | |
| 3508 | sgl += 1; |
| 3509 | /* clear the last flag in the fcp_rsp map entry */ |
| 3510 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 3511 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 3512 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 3513 | |
| 3514 | sgl += 1; |
| 3515 | lpfc_cmd->seg_cnt = datasegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3516 | |
| 3517 | /* First check if data segment count from SCSI Layer is good */ |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3518 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt && |
| 3519 | !phba->cfg_xpsgl) { |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3520 | WARN_ON_ONCE(lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt); |
| 3521 | ret = 2; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3522 | goto err; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3523 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3524 | |
| 3525 | prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd); |
| 3526 | |
| 3527 | switch (prot_group_type) { |
| 3528 | case LPFC_PG_TYPE_NO_DIF: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3529 | /* Here we need to add a DISEED to the count */ |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3530 | if (((lpfc_cmd->seg_cnt + 1) > |
| 3531 | phba->cfg_total_seg_cnt) && |
| 3532 | !phba->cfg_xpsgl) { |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3533 | ret = 2; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3534 | goto err; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3535 | } |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3536 | |
| 3537 | num_sge = lpfc_bg_setup_sgl(phba, scsi_cmnd, sgl, |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3538 | datasegcnt, lpfc_cmd); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3539 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3540 | /* we should have 2 or more entries in buffer list */ |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3541 | if (num_sge < 2) { |
| 3542 | ret = 2; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3543 | goto err; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3544 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3545 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3546 | |
| 3547 | case LPFC_PG_TYPE_DIF_BUF: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3548 | /* |
| 3549 | * This type indicates that protection buffers are |
| 3550 | * passed to the driver, so that needs to be prepared |
| 3551 | * for DMA |
| 3552 | */ |
| 3553 | protsegcnt = dma_map_sg(&phba->pcidev->dev, |
| 3554 | scsi_prot_sglist(scsi_cmnd), |
| 3555 | scsi_prot_sg_count(scsi_cmnd), datadir); |
| 3556 | if (unlikely(!protsegcnt)) { |
| 3557 | scsi_dma_unmap(scsi_cmnd); |
| 3558 | return 1; |
| 3559 | } |
| 3560 | |
| 3561 | lpfc_cmd->prot_seg_cnt = protsegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3562 | /* |
| 3563 | * There is a minimun of 3 SGEs used for every |
| 3564 | * protection data segment. |
| 3565 | */ |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3566 | if (((lpfc_cmd->prot_seg_cnt * 3) > |
| 3567 | (phba->cfg_total_seg_cnt - 2)) && |
| 3568 | !phba->cfg_xpsgl) { |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3569 | ret = 2; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3570 | goto err; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3571 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3572 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3573 | num_sge = lpfc_bg_setup_sgl_prot(phba, scsi_cmnd, sgl, |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3574 | datasegcnt, protsegcnt, lpfc_cmd); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3575 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3576 | /* we should have 3 or more entries in buffer list */ |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3577 | if (num_sge < 3 || |
| 3578 | (num_sge > phba->cfg_total_seg_cnt && |
| 3579 | !phba->cfg_xpsgl)) { |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3580 | ret = 2; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3581 | goto err; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3582 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3583 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3584 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3585 | case LPFC_PG_TYPE_INVALID: |
| 3586 | default: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3587 | scsi_dma_unmap(scsi_cmnd); |
| 3588 | lpfc_cmd->seg_cnt = 0; |
| 3589 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3590 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3591 | "9083 Unexpected protection group %i\n", |
| 3592 | prot_group_type); |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3593 | return 2; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3594 | } |
| 3595 | } |
| 3596 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 3597 | switch (scsi_get_prot_op(scsi_cmnd)) { |
| 3598 | case SCSI_PROT_WRITE_STRIP: |
| 3599 | case SCSI_PROT_READ_STRIP: |
| 3600 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_STRIP; |
| 3601 | break; |
| 3602 | case SCSI_PROT_WRITE_INSERT: |
| 3603 | case SCSI_PROT_READ_INSERT: |
| 3604 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_INSERT; |
| 3605 | break; |
| 3606 | case SCSI_PROT_WRITE_PASS: |
| 3607 | case SCSI_PROT_READ_PASS: |
| 3608 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_PASS; |
| 3609 | break; |
| 3610 | } |
| 3611 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3612 | fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3613 | fcp_cmnd->fcpDl = be32_to_cpu(fcpdl); |
| 3614 | |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 3615 | /* Set first-burst provided it was successfully negotiated */ |
| 3616 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
| 3617 | vport->cfg_first_burst_size && |
| 3618 | scsi_cmnd->sc_data_direction == DMA_TO_DEVICE) { |
| 3619 | u32 init_len, total_len; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3620 | |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 3621 | total_len = be32_to_cpu(fcp_cmnd->fcpDl); |
| 3622 | init_len = min(total_len, vport->cfg_first_burst_size); |
| 3623 | |
| 3624 | /* Word 4 & 5 */ |
| 3625 | wqe->fcp_iwrite.initial_xfer_len = init_len; |
| 3626 | wqe->fcp_iwrite.total_xfer_len = total_len; |
| 3627 | } else { |
| 3628 | /* Word 4 */ |
| 3629 | wqe->fcp_iwrite.total_xfer_len = |
| 3630 | be32_to_cpu(fcp_cmnd->fcpDl); |
| 3631 | } |
James Smart | 7c4042a | 2018-11-29 16:09:40 -0800 | [diff] [blame] | 3632 | |
| 3633 | /* |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 3634 | * If the OAS driver feature is enabled and the lun is enabled for |
| 3635 | * OAS, set the oas iocb related flags. |
| 3636 | */ |
| 3637 | if ((phba->cfg_fof) && ((struct lpfc_device_data *) |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 3638 | scsi_cmnd->device->hostdata)->oas_enabled) { |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 3639 | lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF); |
| 3640 | |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 3641 | /* Word 10 */ |
| 3642 | bf_set(wqe_oas, &wqe->generic.wqe_com, 1); |
| 3643 | bf_set(wqe_ccpe, &wqe->generic.wqe_com, 1); |
| 3644 | bf_set(wqe_ccp, &wqe->generic.wqe_com, |
| 3645 | (phba->cfg_XLanePriority << 1)); |
| 3646 | } |
| 3647 | |
| 3648 | /* Word 7. DIF Flags */ |
| 3649 | if (lpfc_cmd->cur_iocbq.iocb_flag & LPFC_IO_DIF_PASS) |
| 3650 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU); |
| 3651 | else if (lpfc_cmd->cur_iocbq.iocb_flag & LPFC_IO_DIF_STRIP) |
| 3652 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP); |
| 3653 | else if (lpfc_cmd->cur_iocbq.iocb_flag & LPFC_IO_DIF_INSERT) |
| 3654 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT); |
| 3655 | |
| 3656 | lpfc_cmd->cur_iocbq.iocb_flag &= ~(LPFC_IO_DIF_PASS | |
| 3657 | LPFC_IO_DIF_STRIP | LPFC_IO_DIF_INSERT); |
| 3658 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3659 | return 0; |
| 3660 | err: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3661 | if (lpfc_cmd->seg_cnt) |
| 3662 | scsi_dma_unmap(scsi_cmnd); |
| 3663 | if (lpfc_cmd->prot_seg_cnt) |
| 3664 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd), |
| 3665 | scsi_prot_sg_count(scsi_cmnd), |
| 3666 | scsi_cmnd->sc_data_direction); |
| 3667 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3668 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3669 | "9084 Cannot setup S/G List for HBA" |
| 3670 | "IO segs %d/%d SGL %d SCSI %d: %d %d\n", |
| 3671 | lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt, |
| 3672 | phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt, |
| 3673 | prot_group_type, num_sge); |
| 3674 | |
| 3675 | lpfc_cmd->seg_cnt = 0; |
| 3676 | lpfc_cmd->prot_seg_cnt = 0; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 3677 | return ret; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3678 | } |
| 3679 | |
| 3680 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3681 | * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer |
| 3682 | * @phba: The Hba for which this call is being executed. |
| 3683 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3684 | * |
| 3685 | * This routine wraps the actual DMA mapping function pointer from the |
| 3686 | * lpfc_hba struct. |
| 3687 | * |
| 3688 | * Return codes: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 3689 | * 1 - Error |
| 3690 | * 0 - Success |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3691 | **/ |
| 3692 | static inline int |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3693 | 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] | 3694 | { |
| 3695 | return phba->lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 3696 | } |
| 3697 | |
| 3698 | /** |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3699 | * lpfc_bg_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer |
| 3700 | * using BlockGuard. |
| 3701 | * @phba: The Hba for which this call is being executed. |
| 3702 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3703 | * |
| 3704 | * This routine wraps the actual DMA mapping function pointer from the |
| 3705 | * lpfc_hba struct. |
| 3706 | * |
| 3707 | * Return codes: |
| 3708 | * 1 - Error |
| 3709 | * 0 - Success |
| 3710 | **/ |
| 3711 | static inline int |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3712 | 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] | 3713 | { |
| 3714 | return phba->lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 3715 | } |
| 3716 | |
| 3717 | /** |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 3718 | * lpfc_scsi_prep_cmnd_buf - Wrapper function for IOCB/WQE mapping of scsi |
| 3719 | * buffer |
Lee Jones | 0bb87e0 | 2021-03-12 09:47:11 +0000 | [diff] [blame] | 3720 | * @vport: Pointer to vport object. |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 3721 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3722 | * @tmo: Timeout value for IO |
| 3723 | * |
| 3724 | * This routine initializes IOCB/WQE data structure from scsi command |
| 3725 | * |
| 3726 | * Return codes: |
| 3727 | * 1 - Error |
| 3728 | * 0 - Success |
| 3729 | **/ |
| 3730 | static inline int |
| 3731 | lpfc_scsi_prep_cmnd_buf(struct lpfc_vport *vport, struct lpfc_io_buf *lpfc_cmd, |
| 3732 | uint8_t tmo) |
| 3733 | { |
| 3734 | return vport->phba->lpfc_scsi_prep_cmnd_buf(vport, lpfc_cmd, tmo); |
| 3735 | } |
| 3736 | |
| 3737 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3738 | * 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] | 3739 | * @phba: Pointer to hba context object. |
| 3740 | * @vport: Pointer to vport object. |
| 3741 | * @lpfc_cmd: Pointer to lpfc scsi command which reported the error. |
Lee Jones | 0bb87e0 | 2021-03-12 09:47:11 +0000 | [diff] [blame] | 3742 | * @fcpi_parm: FCP Initiator parameter. |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3743 | * |
| 3744 | * This function posts an event when there is a SCSI command reporting |
| 3745 | * error from the scsi device. |
| 3746 | **/ |
| 3747 | static void |
| 3748 | lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport, |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 3749 | struct lpfc_io_buf *lpfc_cmd, uint32_t fcpi_parm) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3750 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 3751 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
| 3752 | uint32_t resp_info = fcprsp->rspStatus2; |
| 3753 | uint32_t scsi_status = fcprsp->rspStatus3; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3754 | struct lpfc_fast_path_event *fast_path_evt = NULL; |
| 3755 | struct lpfc_nodelist *pnode = lpfc_cmd->rdata->pnode; |
| 3756 | unsigned long flags; |
| 3757 | |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3758 | if (!pnode) |
James Smart | 5989b8d | 2010-10-22 11:06:56 -0400 | [diff] [blame] | 3759 | return; |
| 3760 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3761 | /* If there is queuefull or busy condition send a scsi event */ |
| 3762 | if ((cmnd->result == SAM_STAT_TASK_SET_FULL) || |
| 3763 | (cmnd->result == SAM_STAT_BUSY)) { |
| 3764 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3765 | if (!fast_path_evt) |
| 3766 | return; |
| 3767 | fast_path_evt->un.scsi_evt.event_type = |
| 3768 | FC_REG_SCSI_EVENT; |
| 3769 | fast_path_evt->un.scsi_evt.subcategory = |
| 3770 | (cmnd->result == SAM_STAT_TASK_SET_FULL) ? |
| 3771 | LPFC_EVENT_QFULL : LPFC_EVENT_DEVBSY; |
| 3772 | fast_path_evt->un.scsi_evt.lun = cmnd->device->lun; |
| 3773 | memcpy(&fast_path_evt->un.scsi_evt.wwpn, |
| 3774 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3775 | memcpy(&fast_path_evt->un.scsi_evt.wwnn, |
| 3776 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3777 | } else if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen && |
| 3778 | ((cmnd->cmnd[0] == READ_10) || (cmnd->cmnd[0] == WRITE_10))) { |
| 3779 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3780 | if (!fast_path_evt) |
| 3781 | return; |
| 3782 | fast_path_evt->un.check_cond_evt.scsi_event.event_type = |
| 3783 | FC_REG_SCSI_EVENT; |
| 3784 | fast_path_evt->un.check_cond_evt.scsi_event.subcategory = |
| 3785 | LPFC_EVENT_CHECK_COND; |
| 3786 | fast_path_evt->un.check_cond_evt.scsi_event.lun = |
| 3787 | cmnd->device->lun; |
| 3788 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwpn, |
| 3789 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3790 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwnn, |
| 3791 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3792 | fast_path_evt->un.check_cond_evt.sense_key = |
| 3793 | cmnd->sense_buffer[2] & 0xf; |
| 3794 | fast_path_evt->un.check_cond_evt.asc = cmnd->sense_buffer[12]; |
| 3795 | fast_path_evt->un.check_cond_evt.ascq = cmnd->sense_buffer[13]; |
| 3796 | } else if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) && |
| 3797 | fcpi_parm && |
| 3798 | ((be32_to_cpu(fcprsp->rspResId) != fcpi_parm) || |
| 3799 | ((scsi_status == SAM_STAT_GOOD) && |
| 3800 | !(resp_info & (RESID_UNDER | RESID_OVER))))) { |
| 3801 | /* |
| 3802 | * If status is good or resid does not match with fcp_param and |
| 3803 | * there is valid fcpi_parm, then there is a read_check error |
| 3804 | */ |
| 3805 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3806 | if (!fast_path_evt) |
| 3807 | return; |
| 3808 | fast_path_evt->un.read_check_error.header.event_type = |
| 3809 | FC_REG_FABRIC_EVENT; |
| 3810 | fast_path_evt->un.read_check_error.header.subcategory = |
| 3811 | LPFC_EVENT_FCPRDCHKERR; |
| 3812 | memcpy(&fast_path_evt->un.read_check_error.header.wwpn, |
| 3813 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3814 | memcpy(&fast_path_evt->un.read_check_error.header.wwnn, |
| 3815 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3816 | fast_path_evt->un.read_check_error.lun = cmnd->device->lun; |
| 3817 | fast_path_evt->un.read_check_error.opcode = cmnd->cmnd[0]; |
| 3818 | fast_path_evt->un.read_check_error.fcpiparam = |
| 3819 | fcpi_parm; |
| 3820 | } else |
| 3821 | return; |
| 3822 | |
| 3823 | fast_path_evt->vport = vport; |
| 3824 | spin_lock_irqsave(&phba->hbalock, flags); |
| 3825 | list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list); |
| 3826 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 3827 | lpfc_worker_wake_up(phba); |
| 3828 | return; |
| 3829 | } |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3830 | |
| 3831 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3832 | * 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] | 3833 | * @phba: The HBA for which this call is being executed. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3834 | * @psb: The scsi buffer which is going to be un-mapped. |
| 3835 | * |
| 3836 | * 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] | 3837 | * field of @lpfc_cmd for device with SLI-3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3838 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3839 | static void |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3840 | 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] | 3841 | { |
| 3842 | /* |
| 3843 | * There are only two special cases to consider. (1) the scsi command |
| 3844 | * requested scatter-gather usage or (2) the scsi command allocated |
| 3845 | * a request buffer, but did not request use_sg. There is a third |
| 3846 | * case, but it does not require resource deallocation. |
| 3847 | */ |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3848 | if (psb->seg_cnt > 0) |
| 3849 | scsi_dma_unmap(psb->pCmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3850 | if (psb->prot_seg_cnt > 0) |
| 3851 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(psb->pCmd), |
| 3852 | scsi_prot_sg_count(psb->pCmd), |
| 3853 | psb->pCmd->sc_data_direction); |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 3854 | } |
| 3855 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3856 | /** |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 3857 | * lpfc_unblock_requests - allow further commands to be queued. |
| 3858 | * @phba: pointer to phba object |
| 3859 | * |
| 3860 | * For single vport, just call scsi_unblock_requests on physical port. |
| 3861 | * For multiple vports, send scsi_unblock_requests for all the vports. |
| 3862 | */ |
| 3863 | void |
| 3864 | lpfc_unblock_requests(struct lpfc_hba *phba) |
| 3865 | { |
| 3866 | struct lpfc_vport **vports; |
| 3867 | struct Scsi_Host *shost; |
| 3868 | int i; |
| 3869 | |
| 3870 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 3871 | !phba->sli4_hba.max_cfg_param.vpi_used) { |
| 3872 | shost = lpfc_shost_from_vport(phba->pport); |
| 3873 | scsi_unblock_requests(shost); |
| 3874 | return; |
| 3875 | } |
| 3876 | |
| 3877 | vports = lpfc_create_vport_work_array(phba); |
| 3878 | if (vports != NULL) |
| 3879 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 3880 | shost = lpfc_shost_from_vport(vports[i]); |
| 3881 | scsi_unblock_requests(shost); |
| 3882 | } |
| 3883 | lpfc_destroy_vport_work_array(phba, vports); |
| 3884 | } |
| 3885 | |
| 3886 | /** |
| 3887 | * lpfc_block_requests - prevent further commands from being queued. |
| 3888 | * @phba: pointer to phba object |
| 3889 | * |
| 3890 | * For single vport, just call scsi_block_requests on physical port. |
| 3891 | * For multiple vports, send scsi_block_requests for all the vports. |
| 3892 | */ |
| 3893 | void |
| 3894 | lpfc_block_requests(struct lpfc_hba *phba) |
| 3895 | { |
| 3896 | struct lpfc_vport **vports; |
| 3897 | struct Scsi_Host *shost; |
| 3898 | int i; |
| 3899 | |
| 3900 | if (atomic_read(&phba->cmf_stop_io)) |
| 3901 | return; |
| 3902 | |
| 3903 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 3904 | !phba->sli4_hba.max_cfg_param.vpi_used) { |
| 3905 | shost = lpfc_shost_from_vport(phba->pport); |
| 3906 | scsi_block_requests(shost); |
| 3907 | return; |
| 3908 | } |
| 3909 | |
| 3910 | vports = lpfc_create_vport_work_array(phba); |
| 3911 | if (vports != NULL) |
| 3912 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 3913 | shost = lpfc_shost_from_vport(vports[i]); |
| 3914 | scsi_block_requests(shost); |
| 3915 | } |
| 3916 | lpfc_destroy_vport_work_array(phba, vports); |
| 3917 | } |
| 3918 | |
| 3919 | /** |
| 3920 | * lpfc_update_cmf_cmpl - Adjust CMF counters for IO completion |
| 3921 | * @phba: The HBA for which this call is being executed. |
| 3922 | * @time: The latency of the IO that completed (in ns) |
| 3923 | * @size: The size of the IO that completed |
| 3924 | * @shost: SCSI host the IO completed on (NULL for a NVME IO) |
| 3925 | * |
| 3926 | * The routine adjusts the various Burst and Bandwidth counters used in |
| 3927 | * Congestion management and E2E. If time is set to LPFC_CGN_NOT_SENT, |
| 3928 | * that means the IO was never issued to the HBA, so this routine is |
| 3929 | * just being called to cleanup the counter from a previous |
| 3930 | * lpfc_update_cmf_cmd call. |
| 3931 | */ |
| 3932 | int |
| 3933 | lpfc_update_cmf_cmpl(struct lpfc_hba *phba, |
| 3934 | uint64_t time, uint32_t size, struct Scsi_Host *shost) |
| 3935 | { |
| 3936 | struct lpfc_cgn_stat *cgs; |
| 3937 | |
| 3938 | if (time != LPFC_CGN_NOT_SENT) { |
| 3939 | /* lat is ns coming in, save latency in us */ |
| 3940 | if (time < 1000) |
| 3941 | time = 1; |
| 3942 | else |
| 3943 | time = div_u64(time + 500, 1000); /* round it */ |
| 3944 | |
| 3945 | cgs = this_cpu_ptr(phba->cmf_stat); |
| 3946 | atomic64_add(size, &cgs->rcv_bytes); |
| 3947 | atomic64_add(time, &cgs->rx_latency); |
| 3948 | atomic_inc(&cgs->rx_io_cnt); |
| 3949 | } |
| 3950 | return 0; |
| 3951 | } |
| 3952 | |
| 3953 | /** |
| 3954 | * lpfc_update_cmf_cmd - Adjust CMF counters for IO submission |
| 3955 | * @phba: The HBA for which this call is being executed. |
| 3956 | * @size: The size of the IO that will be issued |
| 3957 | * |
| 3958 | * The routine adjusts the various Burst and Bandwidth counters used in |
| 3959 | * Congestion management and E2E. |
| 3960 | */ |
| 3961 | int |
| 3962 | lpfc_update_cmf_cmd(struct lpfc_hba *phba, uint32_t size) |
| 3963 | { |
| 3964 | uint64_t total; |
| 3965 | struct lpfc_cgn_stat *cgs; |
| 3966 | int cpu; |
| 3967 | |
| 3968 | /* At this point we are either LPFC_CFG_MANAGED or LPFC_CFG_MONITOR */ |
| 3969 | if (phba->cmf_active_mode == LPFC_CFG_MANAGED) { |
| 3970 | total = 0; |
| 3971 | for_each_present_cpu(cpu) { |
| 3972 | cgs = per_cpu_ptr(phba->cmf_stat, cpu); |
| 3973 | total += atomic64_read(&cgs->total_bytes); |
| 3974 | } |
| 3975 | if (total >= phba->cmf_max_bytes_per_interval) { |
| 3976 | if (!atomic_xchg(&phba->cmf_bw_wait, 1)) { |
| 3977 | lpfc_block_requests(phba); |
| 3978 | phba->cmf_last_ts = |
| 3979 | lpfc_calc_cmf_latency(phba); |
| 3980 | } |
| 3981 | atomic_inc(&phba->cmf_busy); |
| 3982 | return -EBUSY; |
| 3983 | } |
| 3984 | } |
| 3985 | |
| 3986 | cgs = this_cpu_ptr(phba->cmf_stat); |
| 3987 | atomic64_add(size, &cgs->total_bytes); |
| 3988 | return 0; |
| 3989 | } |
| 3990 | |
| 3991 | /** |
Lee Jones | 0bb87e0 | 2021-03-12 09:47:11 +0000 | [diff] [blame] | 3992 | * lpfc_handle_fcp_err - FCP response handler |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3993 | * @vport: The virtual port for which this call is being executed. |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3994 | * @lpfc_cmd: Pointer to lpfc_io_buf data structure. |
Lee Jones | 0bb87e0 | 2021-03-12 09:47:11 +0000 | [diff] [blame] | 3995 | * @fcpi_parm: FCP Initiator parameter. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3996 | * |
| 3997 | * This routine is called to process response IOCB with status field |
| 3998 | * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command |
| 3999 | * based upon SCSI and FCP error. |
| 4000 | **/ |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 4001 | static void |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4002 | lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_io_buf *lpfc_cmd, |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 4003 | uint32_t fcpi_parm) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4004 | { |
| 4005 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 4006 | struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd; |
| 4007 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4008 | uint32_t resp_info = fcprsp->rspStatus2; |
| 4009 | uint32_t scsi_status = fcprsp->rspStatus3; |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 4010 | uint32_t *lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4011 | uint32_t host_status = DID_OK; |
| 4012 | uint32_t rsplen = 0; |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 4013 | uint32_t fcpDl; |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 4014 | uint32_t logit = LOG_FCP | LOG_FCP_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4015 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4016 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4017 | /* |
| 4018 | * If this is a task management command, there is no |
| 4019 | * scsi packet associated with this lpfc_cmd. The driver |
| 4020 | * consumes it. |
| 4021 | */ |
| 4022 | if (fcpcmd->fcpCntl2) { |
| 4023 | scsi_status = 0; |
| 4024 | goto out; |
| 4025 | } |
| 4026 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4027 | if (resp_info & RSP_LEN_VALID) { |
| 4028 | rsplen = be32_to_cpu(fcprsp->rspRspLen); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4029 | if (rsplen != 0 && rsplen != 4 && rsplen != 8) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4030 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 4031 | "2719 Invalid response length: " |
| 4032 | "tgt x%x lun x%llx cmnd x%x rsplen " |
| 4033 | "x%x\n", cmnd->device->id, |
| 4034 | cmnd->device->lun, cmnd->cmnd[0], |
| 4035 | rsplen); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4036 | host_status = DID_ERROR; |
| 4037 | goto out; |
| 4038 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4039 | if (fcprsp->rspInfo3 != RSP_NO_FAILURE) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4040 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4041 | "2757 Protocol failure detected during " |
| 4042 | "processing of FCP I/O op: " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4043 | "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] | 4044 | cmnd->device->id, |
| 4045 | cmnd->device->lun, cmnd->cmnd[0], |
| 4046 | fcprsp->rspInfo3); |
| 4047 | host_status = DID_ERROR; |
| 4048 | goto out; |
| 4049 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4050 | } |
| 4051 | |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 4052 | if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) { |
| 4053 | uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen); |
| 4054 | if (snslen > SCSI_SENSE_BUFFERSIZE) |
| 4055 | snslen = SCSI_SENSE_BUFFERSIZE; |
| 4056 | |
| 4057 | if (resp_info & RSP_LEN_VALID) |
| 4058 | rsplen = be32_to_cpu(fcprsp->rspRspLen); |
| 4059 | memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen); |
| 4060 | } |
| 4061 | lp = (uint32_t *)cmnd->sense_buffer; |
| 4062 | |
James Smart | aa1c7ee | 2012-08-14 14:26:06 -0400 | [diff] [blame] | 4063 | /* special handling for under run conditions */ |
| 4064 | if (!scsi_status && (resp_info & RESID_UNDER)) { |
| 4065 | /* don't log under runs if fcp set... */ |
| 4066 | if (vport->cfg_log_verbose & LOG_FCP) |
| 4067 | logit = LOG_FCP_ERROR; |
| 4068 | /* unless operator says so */ |
| 4069 | if (vport->cfg_log_verbose & LOG_FCP_UNDER) |
| 4070 | logit = LOG_FCP_UNDER; |
| 4071 | } |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 4072 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4073 | lpfc_printf_vlog(vport, KERN_WARNING, logit, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4074 | "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] | 4075 | "Data: x%x x%x x%x x%x x%x\n", |
| 4076 | cmnd->cmnd[0], scsi_status, |
| 4077 | be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info, |
| 4078 | be32_to_cpu(fcprsp->rspResId), |
| 4079 | be32_to_cpu(fcprsp->rspSnsLen), |
| 4080 | be32_to_cpu(fcprsp->rspRspLen), |
| 4081 | fcprsp->rspInfo3); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4082 | |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4083 | scsi_set_resid(cmnd, 0); |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 4084 | fcpDl = be32_to_cpu(fcpcmd->fcpDl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4085 | if (resp_info & RESID_UNDER) { |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4086 | scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4087 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 4088 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_UNDER, |
James Smart | 45634a86 | 2018-01-30 15:59:00 -0800 | [diff] [blame] | 4089 | "9025 FCP Underrun, expected %d, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4090 | "residual %d Data: x%x x%x x%x\n", |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 4091 | fcpDl, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4092 | scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0], |
| 4093 | cmnd->underflow); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4094 | |
| 4095 | /* |
James Smart | 45634a86 | 2018-01-30 15:59:00 -0800 | [diff] [blame] | 4096 | * If there is an under run, check if under run reported by |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4097 | * storage array is same as the under run reported by HBA. |
| 4098 | * If this is not same, there is a dropped frame. |
| 4099 | */ |
James Smart | 45634a86 | 2018-01-30 15:59:00 -0800 | [diff] [blame] | 4100 | if (fcpi_parm && (scsi_get_resid(cmnd) != fcpi_parm)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4101 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 4102 | LOG_FCP | LOG_FCP_ERROR, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4103 | "9026 FCP Read Check Error " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4104 | "and Underrun Data: x%x x%x x%x x%x\n", |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 4105 | fcpDl, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4106 | scsi_get_resid(cmnd), fcpi_parm, |
| 4107 | cmnd->cmnd[0]); |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4108 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4109 | host_status = DID_ERROR; |
| 4110 | } |
| 4111 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4112 | * The cmnd->underflow is the minimum number of bytes that must |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4113 | * be transferred for this command. Provided a sense condition |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4114 | * is not present, make sure the actual amount transferred is at |
| 4115 | * least the underflow value or fail. |
| 4116 | */ |
| 4117 | if (!(resp_info & SNS_LEN_VALID) && |
| 4118 | (scsi_status == SAM_STAT_GOOD) && |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4119 | (scsi_bufflen(cmnd) - scsi_get_resid(cmnd) |
| 4120 | < cmnd->underflow)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4121 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4122 | "9027 FCP command x%x residual " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4123 | "underrun converted to error " |
| 4124 | "Data: x%x x%x x%x\n", |
James Smart | 66dbfbe | 2007-08-05 06:08:38 -0400 | [diff] [blame] | 4125 | cmnd->cmnd[0], scsi_bufflen(cmnd), |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4126 | scsi_get_resid(cmnd), cmnd->underflow); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4127 | host_status = DID_ERROR; |
| 4128 | } |
| 4129 | } else if (resp_info & RESID_OVER) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4130 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4131 | "9028 FCP command x%x residual overrun error. " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 4132 | "Data: x%x x%x\n", cmnd->cmnd[0], |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4133 | scsi_bufflen(cmnd), scsi_get_resid(cmnd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4134 | host_status = DID_ERROR; |
| 4135 | |
| 4136 | /* |
| 4137 | * Check SLI validation that all the transfer was actually done |
James Smart | 26373d2 | 2013-09-06 12:19:17 -0400 | [diff] [blame] | 4138 | * (fcpi_parm should be zero). Apply check only to reads. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4139 | */ |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 4140 | } else if (fcpi_parm) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4141 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR, |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 4142 | "9029 FCP %s Check Error Data: " |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 4143 | "x%x x%x x%x x%x x%x\n", |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 4144 | ((cmnd->sc_data_direction == DMA_FROM_DEVICE) ? |
| 4145 | "Read" : "Write"), |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 4146 | fcpDl, be32_to_cpu(fcprsp->rspResId), |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 4147 | fcpi_parm, cmnd->cmnd[0], scsi_status); |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 4148 | |
| 4149 | /* There is some issue with the LPe12000 that causes it |
| 4150 | * to miscalculate the fcpi_parm and falsely trip this |
| 4151 | * recovery logic. Detect this case and don't error when true. |
| 4152 | */ |
| 4153 | if (fcpi_parm > fcpDl) |
| 4154 | goto out; |
| 4155 | |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 4156 | switch (scsi_status) { |
| 4157 | case SAM_STAT_GOOD: |
| 4158 | case SAM_STAT_CHECK_CONDITION: |
| 4159 | /* Fabric dropped a data frame. Fail any successful |
| 4160 | * command in which we detected dropped frames. |
| 4161 | * A status of good or some check conditions could |
| 4162 | * be considered a successful command. |
| 4163 | */ |
| 4164 | host_status = DID_ERROR; |
| 4165 | break; |
| 4166 | } |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4167 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4168 | } |
| 4169 | |
| 4170 | out: |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 4171 | cmnd->result = host_status << 16 | scsi_status; |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 4172 | lpfc_send_scsi_error_event(vport->phba, vport, lpfc_cmd, fcpi_parm); |
| 4173 | } |
| 4174 | |
| 4175 | /** |
| 4176 | * lpfc_fcp_io_cmd_wqe_cmpl - Complete a FCP IO |
| 4177 | * @phba: The hba for which this call is being executed. |
| 4178 | * @pwqeIn: The command WQE for the scsi cmnd. |
Lee Jones | 0bb87e0 | 2021-03-12 09:47:11 +0000 | [diff] [blame] | 4179 | * @wcqe: Pointer to driver response CQE object. |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 4180 | * |
| 4181 | * This routine assigns scsi command result by looking into response WQE |
| 4182 | * status field appropriately. This routine handles QUEUE FULL condition as |
| 4183 | * well by ramping down device queue depth. |
| 4184 | **/ |
| 4185 | static void |
| 4186 | lpfc_fcp_io_cmd_wqe_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeIn, |
| 4187 | struct lpfc_wcqe_complete *wcqe) |
| 4188 | { |
| 4189 | struct lpfc_io_buf *lpfc_cmd = |
| 4190 | (struct lpfc_io_buf *)pwqeIn->context1; |
| 4191 | struct lpfc_vport *vport = pwqeIn->vport; |
Colin Ian King | 1e7dddb2 | 2020-11-18 13:13:45 +0000 | [diff] [blame] | 4192 | struct lpfc_rport_data *rdata; |
| 4193 | struct lpfc_nodelist *ndlp; |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 4194 | struct scsi_cmnd *cmd; |
| 4195 | unsigned long flags; |
| 4196 | struct lpfc_fast_path_event *fast_path_evt; |
| 4197 | struct Scsi_Host *shost; |
| 4198 | u32 logit = LOG_FCP; |
| 4199 | u32 status, idx; |
| 4200 | unsigned long iflags = 0; |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 4201 | u32 lat; |
James Smart | 3e49af9 | 2021-05-14 12:55:57 -0700 | [diff] [blame] | 4202 | u8 wait_xb_clr = 0; |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 4203 | |
| 4204 | /* Sanity check on return of outstanding command */ |
| 4205 | if (!lpfc_cmd) { |
| 4206 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 4207 | "9032 Null lpfc_cmd pointer. No " |
| 4208 | "release, skip completion\n"); |
| 4209 | return; |
| 4210 | } |
| 4211 | |
Colin Ian King | 1e7dddb2 | 2020-11-18 13:13:45 +0000 | [diff] [blame] | 4212 | rdata = lpfc_cmd->rdata; |
| 4213 | ndlp = rdata->pnode; |
| 4214 | |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 4215 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { |
| 4216 | /* TOREMOVE - currently this flag is checked during |
| 4217 | * the release of lpfc_iocbq. Remove once we move |
| 4218 | * to lpfc_wqe_job construct. |
| 4219 | * |
| 4220 | * This needs to be done outside buf_lock |
| 4221 | */ |
| 4222 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 4223 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_EXCHANGE_BUSY; |
| 4224 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 4225 | } |
| 4226 | |
| 4227 | /* Guard against abort handler being called at same time */ |
| 4228 | spin_lock(&lpfc_cmd->buf_lock); |
| 4229 | |
| 4230 | /* Sanity check on return of outstanding command */ |
| 4231 | cmd = lpfc_cmd->pCmd; |
James Smart | ae960d7 | 2021-03-01 09:18:07 -0800 | [diff] [blame] | 4232 | if (!cmd) { |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 4233 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
| 4234 | "9042 I/O completion: Not an active IO\n"); |
| 4235 | spin_unlock(&lpfc_cmd->buf_lock); |
| 4236 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 4237 | return; |
| 4238 | } |
| 4239 | idx = lpfc_cmd->cur_iocbq.hba_wqidx; |
| 4240 | if (phba->sli4_hba.hdwq) |
| 4241 | phba->sli4_hba.hdwq[idx].scsi_cstat.io_cmpls++; |
| 4242 | |
| 4243 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 4244 | if (unlikely(phba->hdwqstat_on & LPFC_CHECK_SCSI_IO)) |
| 4245 | this_cpu_inc(phba->sli4_hba.c_stat->cmpl_io); |
| 4246 | #endif |
| 4247 | shost = cmd->device->host; |
| 4248 | |
| 4249 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
| 4250 | lpfc_cmd->status = (status & LPFC_IOCB_STATUS_MASK); |
| 4251 | lpfc_cmd->result = (wcqe->parameter & IOERR_PARAM_MASK); |
| 4252 | |
| 4253 | lpfc_cmd->flags &= ~LPFC_SBUF_XBUSY; |
James Smart | 3e49af9 | 2021-05-14 12:55:57 -0700 | [diff] [blame] | 4254 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 4255 | lpfc_cmd->flags |= LPFC_SBUF_XBUSY; |
James Smart | 3e49af9 | 2021-05-14 12:55:57 -0700 | [diff] [blame] | 4256 | if (phba->cfg_fcp_wait_abts_rsp) |
| 4257 | wait_xb_clr = 1; |
| 4258 | } |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 4259 | |
| 4260 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 4261 | if (lpfc_cmd->prot_data_type) { |
| 4262 | struct scsi_dif_tuple *src = NULL; |
| 4263 | |
| 4264 | src = (struct scsi_dif_tuple *)lpfc_cmd->prot_data_segment; |
| 4265 | /* |
| 4266 | * Used to restore any changes to protection |
| 4267 | * data for error injection. |
| 4268 | */ |
| 4269 | switch (lpfc_cmd->prot_data_type) { |
| 4270 | case LPFC_INJERR_REFTAG: |
| 4271 | src->ref_tag = |
| 4272 | lpfc_cmd->prot_data; |
| 4273 | break; |
| 4274 | case LPFC_INJERR_APPTAG: |
| 4275 | src->app_tag = |
| 4276 | (uint16_t)lpfc_cmd->prot_data; |
| 4277 | break; |
| 4278 | case LPFC_INJERR_GUARD: |
| 4279 | src->guard_tag = |
| 4280 | (uint16_t)lpfc_cmd->prot_data; |
| 4281 | break; |
| 4282 | default: |
| 4283 | break; |
| 4284 | } |
| 4285 | |
| 4286 | lpfc_cmd->prot_data = 0; |
| 4287 | lpfc_cmd->prot_data_type = 0; |
| 4288 | lpfc_cmd->prot_data_segment = NULL; |
| 4289 | } |
| 4290 | #endif |
| 4291 | if (unlikely(lpfc_cmd->status)) { |
| 4292 | if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT && |
| 4293 | (lpfc_cmd->result & IOERR_DRVR_MASK)) |
| 4294 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; |
| 4295 | else if (lpfc_cmd->status >= IOSTAT_CNT) |
| 4296 | lpfc_cmd->status = IOSTAT_DEFAULT; |
| 4297 | if (lpfc_cmd->status == IOSTAT_FCP_RSP_ERROR && |
| 4298 | !lpfc_cmd->fcp_rsp->rspStatus3 && |
| 4299 | (lpfc_cmd->fcp_rsp->rspStatus2 & RESID_UNDER) && |
| 4300 | !(vport->cfg_log_verbose & LOG_FCP_UNDER)) |
| 4301 | logit = 0; |
| 4302 | else |
| 4303 | logit = LOG_FCP | LOG_FCP_UNDER; |
| 4304 | lpfc_printf_vlog(vport, KERN_WARNING, logit, |
| 4305 | "9034 FCP cmd x%x failed <%d/%lld> " |
| 4306 | "status: x%x result: x%x " |
| 4307 | "sid: x%x did: x%x oxid: x%x " |
| 4308 | "Data: x%x x%x x%x\n", |
| 4309 | cmd->cmnd[0], |
| 4310 | cmd->device ? cmd->device->id : 0xffff, |
| 4311 | cmd->device ? cmd->device->lun : 0xffff, |
| 4312 | lpfc_cmd->status, lpfc_cmd->result, |
| 4313 | vport->fc_myDID, |
| 4314 | (ndlp) ? ndlp->nlp_DID : 0, |
| 4315 | lpfc_cmd->cur_iocbq.sli4_xritag, |
| 4316 | wcqe->parameter, wcqe->total_data_placed, |
| 4317 | lpfc_cmd->cur_iocbq.iotag); |
| 4318 | } |
| 4319 | |
| 4320 | switch (lpfc_cmd->status) { |
| 4321 | case IOSTAT_SUCCESS: |
| 4322 | cmd->result = DID_OK << 16; |
| 4323 | break; |
| 4324 | case IOSTAT_FCP_RSP_ERROR: |
| 4325 | lpfc_handle_fcp_err(vport, lpfc_cmd, |
| 4326 | pwqeIn->wqe.fcp_iread.total_xfer_len - |
| 4327 | wcqe->total_data_placed); |
| 4328 | break; |
| 4329 | case IOSTAT_NPORT_BSY: |
| 4330 | case IOSTAT_FABRIC_BSY: |
| 4331 | cmd->result = DID_TRANSPORT_DISRUPTED << 16; |
| 4332 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 4333 | if (!fast_path_evt) |
| 4334 | break; |
| 4335 | fast_path_evt->un.fabric_evt.event_type = |
| 4336 | FC_REG_FABRIC_EVENT; |
| 4337 | fast_path_evt->un.fabric_evt.subcategory = |
| 4338 | (lpfc_cmd->status == IOSTAT_NPORT_BSY) ? |
| 4339 | LPFC_EVENT_PORT_BUSY : LPFC_EVENT_FABRIC_BUSY; |
| 4340 | if (ndlp) { |
| 4341 | memcpy(&fast_path_evt->un.fabric_evt.wwpn, |
| 4342 | &ndlp->nlp_portname, |
| 4343 | sizeof(struct lpfc_name)); |
| 4344 | memcpy(&fast_path_evt->un.fabric_evt.wwnn, |
| 4345 | &ndlp->nlp_nodename, |
| 4346 | sizeof(struct lpfc_name)); |
| 4347 | } |
| 4348 | fast_path_evt->vport = vport; |
| 4349 | fast_path_evt->work_evt.evt = |
| 4350 | LPFC_EVT_FASTPATH_MGMT_EVT; |
| 4351 | spin_lock_irqsave(&phba->hbalock, flags); |
| 4352 | list_add_tail(&fast_path_evt->work_evt.evt_listp, |
| 4353 | &phba->work_list); |
| 4354 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4355 | lpfc_worker_wake_up(phba); |
| 4356 | lpfc_printf_vlog(vport, KERN_WARNING, logit, |
| 4357 | "9035 Fabric/Node busy FCP cmd x%x failed" |
| 4358 | " <%d/%lld> " |
| 4359 | "status: x%x result: x%x " |
| 4360 | "sid: x%x did: x%x oxid: x%x " |
| 4361 | "Data: x%x x%x x%x\n", |
| 4362 | cmd->cmnd[0], |
| 4363 | cmd->device ? cmd->device->id : 0xffff, |
| 4364 | cmd->device ? cmd->device->lun : 0xffff, |
| 4365 | lpfc_cmd->status, lpfc_cmd->result, |
| 4366 | vport->fc_myDID, |
| 4367 | (ndlp) ? ndlp->nlp_DID : 0, |
| 4368 | lpfc_cmd->cur_iocbq.sli4_xritag, |
| 4369 | wcqe->parameter, |
| 4370 | wcqe->total_data_placed, |
| 4371 | lpfc_cmd->cur_iocbq.iocb.ulpIoTag); |
| 4372 | break; |
| 4373 | case IOSTAT_REMOTE_STOP: |
| 4374 | if (ndlp) { |
| 4375 | /* This I/O was aborted by the target, we don't |
| 4376 | * know the rxid and because we did not send the |
| 4377 | * ABTS we cannot generate and RRQ. |
| 4378 | */ |
| 4379 | lpfc_set_rrq_active(phba, ndlp, |
| 4380 | lpfc_cmd->cur_iocbq.sli4_lxritag, |
| 4381 | 0, 0); |
| 4382 | } |
| 4383 | fallthrough; |
| 4384 | case IOSTAT_LOCAL_REJECT: |
| 4385 | if (lpfc_cmd->result & IOERR_DRVR_MASK) |
| 4386 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; |
| 4387 | if (lpfc_cmd->result == IOERR_ELXSEC_KEY_UNWRAP_ERROR || |
| 4388 | lpfc_cmd->result == |
| 4389 | IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR || |
| 4390 | lpfc_cmd->result == IOERR_ELXSEC_CRYPTO_ERROR || |
| 4391 | lpfc_cmd->result == |
| 4392 | IOERR_ELXSEC_CRYPTO_COMPARE_ERROR) { |
| 4393 | cmd->result = DID_NO_CONNECT << 16; |
| 4394 | break; |
| 4395 | } |
| 4396 | if (lpfc_cmd->result == IOERR_INVALID_RPI || |
| 4397 | lpfc_cmd->result == IOERR_NO_RESOURCES || |
| 4398 | lpfc_cmd->result == IOERR_ABORT_REQUESTED || |
| 4399 | lpfc_cmd->result == IOERR_SLER_CMD_RCV_FAILURE) { |
| 4400 | cmd->result = DID_REQUEUE << 16; |
| 4401 | break; |
| 4402 | } |
| 4403 | if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED || |
| 4404 | lpfc_cmd->result == IOERR_TX_DMA_FAILED) && |
| 4405 | status == CQE_STATUS_DI_ERROR) { |
| 4406 | if (scsi_get_prot_op(cmd) != |
| 4407 | SCSI_PROT_NORMAL) { |
| 4408 | /* |
| 4409 | * This is a response for a BG enabled |
| 4410 | * cmd. Parse BG error |
| 4411 | */ |
| 4412 | lpfc_sli4_parse_bg_err(phba, lpfc_cmd, |
| 4413 | wcqe); |
| 4414 | break; |
| 4415 | } |
| 4416 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
| 4417 | "9040 non-zero BGSTAT on unprotected cmd\n"); |
| 4418 | } |
| 4419 | lpfc_printf_vlog(vport, KERN_WARNING, logit, |
| 4420 | "9036 Local Reject FCP cmd x%x failed" |
| 4421 | " <%d/%lld> " |
| 4422 | "status: x%x result: x%x " |
| 4423 | "sid: x%x did: x%x oxid: x%x " |
| 4424 | "Data: x%x x%x x%x\n", |
| 4425 | cmd->cmnd[0], |
| 4426 | cmd->device ? cmd->device->id : 0xffff, |
| 4427 | cmd->device ? cmd->device->lun : 0xffff, |
| 4428 | lpfc_cmd->status, lpfc_cmd->result, |
| 4429 | vport->fc_myDID, |
| 4430 | (ndlp) ? ndlp->nlp_DID : 0, |
| 4431 | lpfc_cmd->cur_iocbq.sli4_xritag, |
| 4432 | wcqe->parameter, |
| 4433 | wcqe->total_data_placed, |
| 4434 | lpfc_cmd->cur_iocbq.iocb.ulpIoTag); |
| 4435 | fallthrough; |
| 4436 | default: |
| 4437 | if (lpfc_cmd->status >= IOSTAT_CNT) |
| 4438 | lpfc_cmd->status = IOSTAT_DEFAULT; |
| 4439 | cmd->result = DID_ERROR << 16; |
| 4440 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR, |
| 4441 | "9037 FCP Completion Error: xri %x " |
| 4442 | "status x%x result x%x [x%x] " |
| 4443 | "placed x%x\n", |
| 4444 | lpfc_cmd->cur_iocbq.sli4_xritag, |
| 4445 | lpfc_cmd->status, lpfc_cmd->result, |
| 4446 | wcqe->parameter, |
| 4447 | wcqe->total_data_placed); |
| 4448 | } |
| 4449 | if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) { |
| 4450 | u32 *lp = (u32 *)cmd->sense_buffer; |
| 4451 | |
| 4452 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
James Smart | f115612 | 2021-04-11 18:31:24 -0700 | [diff] [blame] | 4453 | "9039 Iodone <%d/%llu> cmd x%px, error " |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 4454 | "x%x SNS x%x x%x Data: x%x x%x\n", |
| 4455 | cmd->device->id, cmd->device->lun, cmd, |
| 4456 | cmd->result, *lp, *(lp + 3), cmd->retries, |
| 4457 | scsi_get_resid(cmd)); |
| 4458 | } |
| 4459 | |
| 4460 | lpfc_update_stats(vport, lpfc_cmd); |
| 4461 | |
| 4462 | if (vport->cfg_max_scsicmpl_time && |
| 4463 | time_after(jiffies, lpfc_cmd->start_time + |
| 4464 | msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) { |
| 4465 | spin_lock_irqsave(shost->host_lock, flags); |
| 4466 | if (ndlp) { |
| 4467 | if (ndlp->cmd_qdepth > |
| 4468 | atomic_read(&ndlp->cmd_pending) && |
| 4469 | (atomic_read(&ndlp->cmd_pending) > |
| 4470 | LPFC_MIN_TGT_QDEPTH) && |
| 4471 | (cmd->cmnd[0] == READ_10 || |
| 4472 | cmd->cmnd[0] == WRITE_10)) |
| 4473 | ndlp->cmd_qdepth = |
| 4474 | atomic_read(&ndlp->cmd_pending); |
| 4475 | |
| 4476 | ndlp->last_change_time = jiffies; |
| 4477 | } |
| 4478 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 4479 | } |
| 4480 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
| 4481 | |
| 4482 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 4483 | if (lpfc_cmd->ts_cmd_start) { |
| 4484 | lpfc_cmd->ts_isr_cmpl = lpfc_cmd->cur_iocbq.isr_timestamp; |
| 4485 | lpfc_cmd->ts_data_io = ktime_get_ns(); |
| 4486 | phba->ktime_last_cmd = lpfc_cmd->ts_data_io; |
| 4487 | lpfc_io_ktime(phba, lpfc_cmd); |
| 4488 | } |
| 4489 | #endif |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 4490 | if (likely(!wait_xb_clr)) |
| 4491 | lpfc_cmd->pCmd = NULL; |
| 4492 | spin_unlock(&lpfc_cmd->buf_lock); |
| 4493 | |
| 4494 | /* Check if IO qualified for CMF */ |
| 4495 | if (phba->cmf_active_mode != LPFC_CFG_OFF && |
| 4496 | cmd->sc_data_direction == DMA_FROM_DEVICE && |
| 4497 | (scsi_sg_count(cmd))) { |
| 4498 | /* Used when calculating average latency */ |
| 4499 | lat = ktime_get_ns() - lpfc_cmd->rx_cmd_start; |
| 4500 | lpfc_update_cmf_cmpl(phba, lat, scsi_bufflen(cmd), shost); |
| 4501 | } |
| 4502 | |
James Smart | 3e49af9 | 2021-05-14 12:55:57 -0700 | [diff] [blame] | 4503 | if (wait_xb_clr) |
| 4504 | goto out; |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 4505 | |
| 4506 | /* The sdev is not guaranteed to be valid post scsi_done upcall. */ |
| 4507 | cmd->scsi_done(cmd); |
| 4508 | |
| 4509 | /* |
| 4510 | * If there is an abort thread waiting for command completion |
| 4511 | * wake up the thread. |
| 4512 | */ |
| 4513 | spin_lock(&lpfc_cmd->buf_lock); |
| 4514 | lpfc_cmd->cur_iocbq.iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 4515 | if (lpfc_cmd->waitq) |
| 4516 | wake_up(lpfc_cmd->waitq); |
| 4517 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 4518 | out: |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 4519 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4520 | } |
| 4521 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4522 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4523 | * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4524 | * @phba: The Hba for which this call is being executed. |
| 4525 | * @pIocbIn: The command IOCBQ for the scsi cmnd. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4526 | * @pIocbOut: The response IOCBQ for the scsi cmnd. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4527 | * |
| 4528 | * This routine assigns scsi command result by looking into response IOCB |
| 4529 | * status field appropriately. This routine handles QUEUE FULL condition as |
| 4530 | * well by ramping down device queue depth. |
| 4531 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4532 | static void |
| 4533 | lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn, |
| 4534 | struct lpfc_iocbq *pIocbOut) |
| 4535 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4536 | struct lpfc_io_buf *lpfc_cmd = |
| 4537 | (struct lpfc_io_buf *) pIocbIn->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4538 | struct lpfc_vport *vport = pIocbIn->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4539 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| 4540 | struct lpfc_nodelist *pnode = rdata->pnode; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4541 | struct scsi_cmnd *cmd; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4542 | unsigned long flags; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4543 | struct lpfc_fast_path_event *fast_path_evt; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4544 | struct Scsi_Host *shost; |
James Smart | 4c47efc | 2019-01-28 11:14:25 -0800 | [diff] [blame] | 4545 | int idx; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 4546 | uint32_t logit = LOG_FCP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4547 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4548 | /* Guard against abort handler being called at same time */ |
| 4549 | spin_lock(&lpfc_cmd->buf_lock); |
| 4550 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4551 | /* Sanity check on return of outstanding command */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4552 | cmd = lpfc_cmd->pCmd; |
James Smart | 43bfea1 | 2019-09-21 20:58:57 -0700 | [diff] [blame] | 4553 | if (!cmd || !phba) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4554 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4555 | "2621 IO completion: Not an active IO\n"); |
| 4556 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | c90261d | 2015-12-16 18:11:57 -0500 | [diff] [blame] | 4557 | return; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4558 | } |
James Smart | 4c47efc | 2019-01-28 11:14:25 -0800 | [diff] [blame] | 4559 | |
| 4560 | idx = lpfc_cmd->cur_iocbq.hba_wqidx; |
| 4561 | if (phba->sli4_hba.hdwq) |
| 4562 | phba->sli4_hba.hdwq[idx].scsi_cstat.io_cmpls++; |
| 4563 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 4564 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 4565 | if (unlikely(phba->hdwqstat_on & LPFC_CHECK_SCSI_IO)) |
| 4566 | this_cpu_inc(phba->sli4_hba.c_stat->cmpl_io); |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 4567 | #endif |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4568 | shost = cmd->device->host; |
| 4569 | |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 4570 | lpfc_cmd->result = (pIocbOut->iocb.un.ulpWord[4] & IOERR_PARAM_MASK); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4571 | lpfc_cmd->status = pIocbOut->iocb.ulpStatus; |
James Smart | 3e49af9 | 2021-05-14 12:55:57 -0700 | [diff] [blame] | 4572 | /* pick up SLI4 exchange busy status from HBA */ |
| 4573 | lpfc_cmd->flags &= ~LPFC_SBUF_XBUSY; |
James Smart | 324e1c4 | 2019-10-18 14:18:21 -0700 | [diff] [blame] | 4574 | if (pIocbOut->iocb_flag & LPFC_EXCHANGE_BUSY) |
| 4575 | lpfc_cmd->flags |= LPFC_SBUF_XBUSY; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 4576 | |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 4577 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 4578 | if (lpfc_cmd->prot_data_type) { |
| 4579 | struct scsi_dif_tuple *src = NULL; |
| 4580 | |
| 4581 | src = (struct scsi_dif_tuple *)lpfc_cmd->prot_data_segment; |
| 4582 | /* |
| 4583 | * Used to restore any changes to protection |
| 4584 | * data for error injection. |
| 4585 | */ |
| 4586 | switch (lpfc_cmd->prot_data_type) { |
| 4587 | case LPFC_INJERR_REFTAG: |
| 4588 | src->ref_tag = |
| 4589 | lpfc_cmd->prot_data; |
| 4590 | break; |
| 4591 | case LPFC_INJERR_APPTAG: |
| 4592 | src->app_tag = |
| 4593 | (uint16_t)lpfc_cmd->prot_data; |
| 4594 | break; |
| 4595 | case LPFC_INJERR_GUARD: |
| 4596 | src->guard_tag = |
| 4597 | (uint16_t)lpfc_cmd->prot_data; |
| 4598 | break; |
| 4599 | default: |
| 4600 | break; |
| 4601 | } |
| 4602 | |
| 4603 | lpfc_cmd->prot_data = 0; |
| 4604 | lpfc_cmd->prot_data_type = 0; |
| 4605 | lpfc_cmd->prot_data_segment = NULL; |
| 4606 | } |
| 4607 | #endif |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4608 | |
James Smart | 22770cb | 2019-10-18 14:18:24 -0700 | [diff] [blame] | 4609 | if (unlikely(lpfc_cmd->status)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4610 | if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT && |
| 4611 | (lpfc_cmd->result & IOERR_DRVR_MASK)) |
| 4612 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; |
| 4613 | else if (lpfc_cmd->status >= IOSTAT_CNT) |
| 4614 | lpfc_cmd->status = IOSTAT_DEFAULT; |
James Smart | aa1c7ee | 2012-08-14 14:26:06 -0400 | [diff] [blame] | 4615 | if (lpfc_cmd->status == IOSTAT_FCP_RSP_ERROR && |
| 4616 | !lpfc_cmd->fcp_rsp->rspStatus3 && |
| 4617 | (lpfc_cmd->fcp_rsp->rspStatus2 & RESID_UNDER) && |
| 4618 | !(vport->cfg_log_verbose & LOG_FCP_UNDER)) |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 4619 | logit = 0; |
| 4620 | else |
| 4621 | logit = LOG_FCP | LOG_FCP_UNDER; |
| 4622 | lpfc_printf_vlog(vport, KERN_WARNING, logit, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4623 | "9030 FCP cmd x%x failed <%d/%lld> " |
James Smart | 5a0d80f | 2012-05-09 21:18:20 -0400 | [diff] [blame] | 4624 | "status: x%x result: x%x " |
| 4625 | "sid: x%x did: x%x oxid: x%x " |
| 4626 | "Data: x%x x%x\n", |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 4627 | cmd->cmnd[0], |
| 4628 | cmd->device ? cmd->device->id : 0xffff, |
| 4629 | cmd->device ? cmd->device->lun : 0xffff, |
| 4630 | lpfc_cmd->status, lpfc_cmd->result, |
James Smart | 3bf41ba | 2013-05-31 17:03:18 -0400 | [diff] [blame] | 4631 | vport->fc_myDID, |
| 4632 | (pnode) ? pnode->nlp_DID : 0, |
James Smart | 5a0d80f | 2012-05-09 21:18:20 -0400 | [diff] [blame] | 4633 | phba->sli_rev == LPFC_SLI_REV4 ? |
| 4634 | lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 4635 | pIocbOut->iocb.ulpContext, |
| 4636 | lpfc_cmd->cur_iocbq.iocb.ulpIoTag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4637 | |
| 4638 | switch (lpfc_cmd->status) { |
| 4639 | case IOSTAT_FCP_RSP_ERROR: |
| 4640 | /* Call FCP RSP handler to determine result */ |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 4641 | lpfc_handle_fcp_err(vport, lpfc_cmd, |
| 4642 | pIocbOut->iocb.un.fcpi.fcpi_parm); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4643 | break; |
| 4644 | case IOSTAT_NPORT_BSY: |
| 4645 | case IOSTAT_FABRIC_BSY: |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 4646 | cmd->result = DID_TRANSPORT_DISRUPTED << 16; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4647 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 4648 | if (!fast_path_evt) |
| 4649 | break; |
| 4650 | fast_path_evt->un.fabric_evt.event_type = |
| 4651 | FC_REG_FABRIC_EVENT; |
| 4652 | fast_path_evt->un.fabric_evt.subcategory = |
| 4653 | (lpfc_cmd->status == IOSTAT_NPORT_BSY) ? |
| 4654 | LPFC_EVENT_PORT_BUSY : LPFC_EVENT_FABRIC_BUSY; |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4655 | if (pnode) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4656 | memcpy(&fast_path_evt->un.fabric_evt.wwpn, |
| 4657 | &pnode->nlp_portname, |
| 4658 | sizeof(struct lpfc_name)); |
| 4659 | memcpy(&fast_path_evt->un.fabric_evt.wwnn, |
| 4660 | &pnode->nlp_nodename, |
| 4661 | sizeof(struct lpfc_name)); |
| 4662 | } |
| 4663 | fast_path_evt->vport = vport; |
| 4664 | fast_path_evt->work_evt.evt = |
| 4665 | LPFC_EVT_FASTPATH_MGMT_EVT; |
| 4666 | spin_lock_irqsave(&phba->hbalock, flags); |
| 4667 | list_add_tail(&fast_path_evt->work_evt.evt_listp, |
| 4668 | &phba->work_list); |
| 4669 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4670 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4671 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4672 | case IOSTAT_LOCAL_REJECT: |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4673 | case IOSTAT_REMOTE_STOP: |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 4674 | if (lpfc_cmd->result == IOERR_ELXSEC_KEY_UNWRAP_ERROR || |
| 4675 | lpfc_cmd->result == |
| 4676 | IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR || |
| 4677 | lpfc_cmd->result == IOERR_ELXSEC_CRYPTO_ERROR || |
| 4678 | lpfc_cmd->result == |
| 4679 | IOERR_ELXSEC_CRYPTO_COMPARE_ERROR) { |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 4680 | cmd->result = DID_NO_CONNECT << 16; |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 4681 | break; |
| 4682 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4683 | if (lpfc_cmd->result == IOERR_INVALID_RPI || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4684 | lpfc_cmd->result == IOERR_NO_RESOURCES || |
James Smart | b92938b | 2010-06-07 15:24:12 -0400 | [diff] [blame] | 4685 | lpfc_cmd->result == IOERR_ABORT_REQUESTED || |
| 4686 | lpfc_cmd->result == IOERR_SLER_CMD_RCV_FAILURE) { |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 4687 | cmd->result = DID_REQUEUE << 16; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4688 | break; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4689 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4690 | if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED || |
| 4691 | lpfc_cmd->result == IOERR_TX_DMA_FAILED) && |
| 4692 | pIocbOut->iocb.unsli3.sli3_bg.bgstat) { |
| 4693 | if (scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) { |
| 4694 | /* |
| 4695 | * This is a response for a BG enabled |
| 4696 | * cmd. Parse BG error |
| 4697 | */ |
| 4698 | lpfc_parse_bg_err(phba, lpfc_cmd, |
| 4699 | pIocbOut); |
| 4700 | break; |
| 4701 | } else { |
| 4702 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 4703 | LOG_BG, |
| 4704 | "9031 non-zero BGSTAT " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4705 | "on unprotected cmd\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4706 | } |
| 4707 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4708 | if ((lpfc_cmd->status == IOSTAT_REMOTE_STOP) |
| 4709 | && (phba->sli_rev == LPFC_SLI_REV4) |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4710 | && pnode) { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4711 | /* This IO was aborted by the target, we don't |
| 4712 | * know the rxid and because we did not send the |
| 4713 | * ABTS we cannot generate and RRQ. |
| 4714 | */ |
| 4715 | lpfc_set_rrq_active(phba, pnode, |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 4716 | lpfc_cmd->cur_iocbq.sli4_lxritag, |
| 4717 | 0, 0); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4718 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 4719 | fallthrough; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4720 | default: |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 4721 | cmd->result = DID_ERROR << 16; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4722 | break; |
| 4723 | } |
| 4724 | |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4725 | if (!pnode || (pnode->nlp_state != NLP_STE_MAPPED_NODE)) |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 4726 | cmd->result = DID_TRANSPORT_DISRUPTED << 16 | |
| 4727 | SAM_STAT_BUSY; |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 4728 | } else |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 4729 | cmd->result = DID_OK << 16; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4730 | |
| 4731 | if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) { |
| 4732 | uint32_t *lp = (uint32_t *)cmd->sense_buffer; |
| 4733 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4734 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 4735 | "0710 Iodone <%d/%llu> cmd x%px, error " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4736 | "x%x SNS x%x x%x Data: x%x x%x\n", |
| 4737 | cmd->device->id, cmd->device->lun, cmd, |
| 4738 | cmd->result, *lp, *(lp + 3), cmd->retries, |
| 4739 | scsi_get_resid(cmd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4740 | } |
| 4741 | |
James Smart | 9df0a03 | 2019-09-21 20:58:54 -0700 | [diff] [blame] | 4742 | lpfc_update_stats(vport, lpfc_cmd); |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4743 | if (vport->cfg_max_scsicmpl_time && |
| 4744 | time_after(jiffies, lpfc_cmd->start_time + |
| 4745 | msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4746 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 4747 | if (pnode) { |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4748 | if (pnode->cmd_qdepth > |
| 4749 | atomic_read(&pnode->cmd_pending) && |
| 4750 | (atomic_read(&pnode->cmd_pending) > |
| 4751 | LPFC_MIN_TGT_QDEPTH) && |
| 4752 | ((cmd->cmnd[0] == READ_10) || |
| 4753 | (cmd->cmnd[0] == WRITE_10))) |
| 4754 | pnode->cmd_qdepth = |
| 4755 | atomic_read(&pnode->cmd_pending); |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4756 | |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4757 | pnode->last_change_time = jiffies; |
| 4758 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4759 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4760 | } |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4761 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4762 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4763 | lpfc_cmd->pCmd = NULL; |
| 4764 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 92e3af6 | 2012-08-14 14:26:28 -0400 | [diff] [blame] | 4765 | |
James Smart | 2fcbc56 | 2020-03-22 11:13:02 -0700 | [diff] [blame] | 4766 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 4767 | if (lpfc_cmd->ts_cmd_start) { |
| 4768 | lpfc_cmd->ts_isr_cmpl = pIocbIn->isr_timestamp; |
| 4769 | lpfc_cmd->ts_data_io = ktime_get_ns(); |
| 4770 | phba->ktime_last_cmd = lpfc_cmd->ts_data_io; |
| 4771 | lpfc_io_ktime(phba, lpfc_cmd); |
| 4772 | } |
| 4773 | #endif |
James Smart | 3e49af9 | 2021-05-14 12:55:57 -0700 | [diff] [blame] | 4774 | |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 4775 | /* The sdev is not guaranteed to be valid post scsi_done upcall. */ |
| 4776 | cmd->scsi_done(cmd); |
| 4777 | |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4778 | /* |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4779 | * If there is an abort thread waiting for command completion |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4780 | * wake up the thread. |
| 4781 | */ |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4782 | spin_lock(&lpfc_cmd->buf_lock); |
James Smart | 4eb0153 | 2019-04-03 11:10:34 -0700 | [diff] [blame] | 4783 | lpfc_cmd->cur_iocbq.iocb_flag &= ~LPFC_DRIVER_ABORTED; |
James Smart | b9e5a2d | 2019-05-21 17:49:01 -0700 | [diff] [blame] | 4784 | if (lpfc_cmd->waitq) |
James Smart | 4eb0153 | 2019-04-03 11:10:34 -0700 | [diff] [blame] | 4785 | wake_up(lpfc_cmd->waitq); |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4786 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4787 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4788 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4789 | } |
| 4790 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4791 | /** |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 4792 | * lpfc_scsi_prep_cmnd_buf_s3 - SLI-3 IOCB init for the IO |
Lee Jones | 0bb87e0 | 2021-03-12 09:47:11 +0000 | [diff] [blame] | 4793 | * @vport: Pointer to vport object. |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 4794 | * @lpfc_cmd: The scsi buffer which is going to be prep'ed. |
| 4795 | * @tmo: timeout value for the IO |
Alexey Kardashevskiy | 8b2564e | 2015-04-28 18:26:22 +1000 | [diff] [blame] | 4796 | * |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 4797 | * Based on the data-direction of the command, initialize IOCB |
| 4798 | * in the I/O buffer. Fill in the IOCB fields which are independent |
| 4799 | * of the scsi buffer |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4800 | * |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 4801 | * RETURNS 0 - SUCCESS, |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4802 | **/ |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 4803 | static int lpfc_scsi_prep_cmnd_buf_s3(struct lpfc_vport *vport, |
| 4804 | struct lpfc_io_buf *lpfc_cmd, |
| 4805 | uint8_t tmo) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4806 | { |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 4807 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 4808 | struct lpfc_iocbq *piocbq = &lpfc_cmd->cur_iocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4809 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 4810 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 4811 | struct lpfc_nodelist *pnode = lpfc_cmd->ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4812 | int datadir = scsi_cmnd->sc_data_direction; |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 4813 | u32 fcpdl; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4814 | |
James Smart | 6acb348 | 2014-04-04 13:51:25 -0400 | [diff] [blame] | 4815 | piocbq->iocb.un.fcpi.fcpi_XRdy = 0; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4816 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4817 | /* |
| 4818 | * There are three possibilities here - use scatter-gather segment, use |
| 4819 | * the single mapping, or neither. Start the lpfc command prep by |
| 4820 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 4821 | * data bde entry. |
| 4822 | */ |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4823 | if (scsi_sg_count(scsi_cmnd)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4824 | if (datadir == DMA_TO_DEVICE) { |
| 4825 | iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR; |
James Smart | 182ba75 | 2013-07-15 18:34:05 -0400 | [diff] [blame] | 4826 | iocb_cmd->ulpPU = PARM_READ_CHECK; |
James Smart | 3cb01c5 | 2013-07-15 18:35:04 -0400 | [diff] [blame] | 4827 | if (vport->cfg_first_burst_size && |
| 4828 | (pnode->nlp_flag & NLP_FIRSTBURST)) { |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 4829 | u32 xrdy_len; |
| 4830 | |
James Smart | 98bbf5f | 2013-09-06 12:18:45 -0400 | [diff] [blame] | 4831 | fcpdl = scsi_bufflen(scsi_cmnd); |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 4832 | xrdy_len = min(fcpdl, |
| 4833 | vport->cfg_first_burst_size); |
| 4834 | piocbq->iocb.un.fcpi.fcpi_XRdy = xrdy_len; |
James Smart | 3cb01c5 | 2013-07-15 18:35:04 -0400 | [diff] [blame] | 4835 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4836 | fcp_cmnd->fcpCntl3 = WRITE_DATA; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4837 | } else { |
| 4838 | iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR; |
| 4839 | iocb_cmd->ulpPU = PARM_READ_CHECK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4840 | fcp_cmnd->fcpCntl3 = READ_DATA; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4841 | } |
| 4842 | } else { |
| 4843 | iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR; |
| 4844 | iocb_cmd->un.fcpi.fcpi_parm = 0; |
| 4845 | iocb_cmd->ulpPU = 0; |
| 4846 | fcp_cmnd->fcpCntl3 = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4847 | } |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 4848 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4849 | /* |
| 4850 | * Finish initializing those IOCB fields that are independent |
| 4851 | * of the scsi_cmnd request_buffer |
| 4852 | */ |
| 4853 | piocbq->iocb.ulpContext = pnode->nlp_rpi; |
| 4854 | if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE) |
| 4855 | piocbq->iocb.ulpFCP2Rcvy = 1; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4856 | else |
| 4857 | piocbq->iocb.ulpFCP2Rcvy = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4858 | |
| 4859 | piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f); |
| 4860 | piocbq->context1 = lpfc_cmd; |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 4861 | if (!piocbq->iocb_cmpl) |
| 4862 | piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; |
| 4863 | piocbq->iocb.ulpTimeout = tmo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4864 | piocbq->vport = vport; |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 4865 | return 0; |
| 4866 | } |
| 4867 | |
| 4868 | /** |
| 4869 | * lpfc_scsi_prep_cmnd_buf_s4 - SLI-4 WQE init for the IO |
Lee Jones | 0bb87e0 | 2021-03-12 09:47:11 +0000 | [diff] [blame] | 4870 | * @vport: Pointer to vport object. |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 4871 | * @lpfc_cmd: The scsi buffer which is going to be prep'ed. |
| 4872 | * @tmo: timeout value for the IO |
| 4873 | * |
| 4874 | * Based on the data-direction of the command copy WQE template |
| 4875 | * to I/O buffer WQE. Fill in the WQE fields which are independent |
| 4876 | * of the scsi buffer |
| 4877 | * |
| 4878 | * RETURNS 0 - SUCCESS, |
| 4879 | **/ |
| 4880 | static int lpfc_scsi_prep_cmnd_buf_s4(struct lpfc_vport *vport, |
| 4881 | struct lpfc_io_buf *lpfc_cmd, |
| 4882 | uint8_t tmo) |
| 4883 | { |
| 4884 | struct lpfc_hba *phba = vport->phba; |
| 4885 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 4886 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 4887 | struct lpfc_sli4_hdw_queue *hdwq = NULL; |
| 4888 | struct lpfc_iocbq *pwqeq = &lpfc_cmd->cur_iocbq; |
| 4889 | struct lpfc_nodelist *pnode = lpfc_cmd->ndlp; |
| 4890 | union lpfc_wqe128 *wqe = &pwqeq->wqe; |
| 4891 | u16 idx = lpfc_cmd->hdwq_no; |
| 4892 | int datadir = scsi_cmnd->sc_data_direction; |
| 4893 | |
| 4894 | hdwq = &phba->sli4_hba.hdwq[idx]; |
| 4895 | |
| 4896 | /* Initialize 64 bytes only */ |
| 4897 | memset(wqe, 0, sizeof(union lpfc_wqe128)); |
| 4898 | |
| 4899 | /* |
| 4900 | * There are three possibilities here - use scatter-gather segment, use |
| 4901 | * the single mapping, or neither. |
| 4902 | */ |
| 4903 | if (scsi_sg_count(scsi_cmnd)) { |
| 4904 | if (datadir == DMA_TO_DEVICE) { |
| 4905 | /* From the iwrite template, initialize words 7 - 11 */ |
| 4906 | memcpy(&wqe->words[7], |
| 4907 | &lpfc_iwrite_cmd_template.words[7], |
| 4908 | sizeof(uint32_t) * 5); |
| 4909 | |
| 4910 | fcp_cmnd->fcpCntl3 = WRITE_DATA; |
| 4911 | if (hdwq) |
| 4912 | hdwq->scsi_cstat.output_requests++; |
| 4913 | } else { |
| 4914 | /* From the iread template, initialize words 7 - 11 */ |
| 4915 | memcpy(&wqe->words[7], |
| 4916 | &lpfc_iread_cmd_template.words[7], |
| 4917 | sizeof(uint32_t) * 5); |
| 4918 | |
| 4919 | /* Word 7 */ |
| 4920 | bf_set(wqe_tmo, &wqe->fcp_iread.wqe_com, tmo); |
| 4921 | |
| 4922 | fcp_cmnd->fcpCntl3 = READ_DATA; |
| 4923 | if (hdwq) |
| 4924 | hdwq->scsi_cstat.input_requests++; |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 4925 | |
| 4926 | /* For a CMF Managed port, iod must be zero'ed */ |
| 4927 | if (phba->cmf_active_mode == LPFC_CFG_MANAGED) |
| 4928 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, |
| 4929 | LPFC_WQE_IOD_NONE); |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 4930 | } |
| 4931 | } else { |
| 4932 | /* From the icmnd template, initialize words 4 - 11 */ |
| 4933 | memcpy(&wqe->words[4], &lpfc_icmnd_cmd_template.words[4], |
| 4934 | sizeof(uint32_t) * 8); |
| 4935 | |
| 4936 | /* Word 7 */ |
| 4937 | bf_set(wqe_tmo, &wqe->fcp_icmd.wqe_com, tmo); |
| 4938 | |
| 4939 | fcp_cmnd->fcpCntl3 = 0; |
| 4940 | if (hdwq) |
| 4941 | hdwq->scsi_cstat.control_requests++; |
| 4942 | } |
| 4943 | |
| 4944 | /* |
| 4945 | * Finish initializing those WQE fields that are independent |
| 4946 | * of the request_buffer |
| 4947 | */ |
| 4948 | |
| 4949 | /* Word 3 */ |
| 4950 | bf_set(payload_offset_len, &wqe->fcp_icmd, |
| 4951 | sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); |
| 4952 | |
| 4953 | /* Word 6 */ |
| 4954 | bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, |
| 4955 | phba->sli4_hba.rpi_ids[pnode->nlp_rpi]); |
| 4956 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, pwqeq->sli4_xritag); |
| 4957 | |
| 4958 | /* Word 7*/ |
| 4959 | if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE) |
| 4960 | bf_set(wqe_erp, &wqe->generic.wqe_com, 1); |
| 4961 | |
| 4962 | bf_set(wqe_class, &wqe->generic.wqe_com, |
| 4963 | (pnode->nlp_fcp_info & 0x0f)); |
| 4964 | |
| 4965 | /* Word 8 */ |
| 4966 | wqe->generic.wqe_com.abort_tag = pwqeq->iotag; |
| 4967 | |
| 4968 | /* Word 9 */ |
| 4969 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, pwqeq->iotag); |
| 4970 | |
| 4971 | pwqeq->vport = vport; |
| 4972 | pwqeq->vport = vport; |
| 4973 | pwqeq->context1 = lpfc_cmd; |
| 4974 | pwqeq->hba_wqidx = lpfc_cmd->hdwq_no; |
James Smart | 96e209b | 2020-11-15 11:26:43 -0800 | [diff] [blame] | 4975 | pwqeq->wqe_cmpl = lpfc_fcp_io_cmd_wqe_cmpl; |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 4976 | |
| 4977 | return 0; |
| 4978 | } |
| 4979 | |
| 4980 | /** |
| 4981 | * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit |
| 4982 | * @vport: The virtual port for which this call is being executed. |
| 4983 | * @lpfc_cmd: The scsi command which needs to send. |
| 4984 | * @pnode: Pointer to lpfc_nodelist. |
| 4985 | * |
| 4986 | * This routine initializes fcp_cmnd and iocb data structure from scsi command |
| 4987 | * to transfer for device with SLI3 interface spec. |
| 4988 | **/ |
| 4989 | static int |
| 4990 | lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_io_buf *lpfc_cmd, |
| 4991 | struct lpfc_nodelist *pnode) |
| 4992 | { |
| 4993 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 4994 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 4995 | u8 *ptr; |
| 4996 | |
| 4997 | if (!pnode) |
| 4998 | return 0; |
| 4999 | |
| 5000 | lpfc_cmd->fcp_rsp->rspSnsLen = 0; |
| 5001 | /* clear task management bits */ |
| 5002 | lpfc_cmd->fcp_cmnd->fcpCntl2 = 0; |
| 5003 | |
| 5004 | int_to_scsilun(lpfc_cmd->pCmd->device->lun, |
| 5005 | &lpfc_cmd->fcp_cmnd->fcp_lun); |
| 5006 | |
| 5007 | ptr = &fcp_cmnd->fcpCdb[0]; |
| 5008 | memcpy(ptr, scsi_cmnd->cmnd, scsi_cmnd->cmd_len); |
| 5009 | if (scsi_cmnd->cmd_len < LPFC_FCP_CDB_LEN) { |
| 5010 | ptr += scsi_cmnd->cmd_len; |
| 5011 | memset(ptr, 0, (LPFC_FCP_CDB_LEN - scsi_cmnd->cmd_len)); |
| 5012 | } |
| 5013 | |
| 5014 | fcp_cmnd->fcpCntl1 = SIMPLE_Q; |
| 5015 | |
| 5016 | lpfc_scsi_prep_cmnd_buf(vport, lpfc_cmd, lpfc_cmd->timeout); |
| 5017 | |
| 5018 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5019 | } |
| 5020 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5021 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5022 | * 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] | 5023 | * @vport: The virtual port for which this call is being executed. |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 5024 | * @lpfc_cmd: Pointer to lpfc_io_buf data structure. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5025 | * @lun: Logical unit number. |
| 5026 | * @task_mgmt_cmd: SCSI task management command. |
| 5027 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5028 | * This routine creates FCP information unit corresponding to @task_mgmt_cmd |
| 5029 | * for device with SLI-3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5030 | * |
| 5031 | * Return codes: |
| 5032 | * 0 - Error |
| 5033 | * 1 - Success |
| 5034 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5035 | static int |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 5036 | lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 5037 | struct lpfc_io_buf *lpfc_cmd, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5038 | uint64_t lun, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5039 | uint8_t task_mgmt_cmd) |
| 5040 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5041 | struct lpfc_iocbq *piocbq; |
| 5042 | IOCB_t *piocb; |
| 5043 | struct fcp_cmnd *fcp_cmnd; |
James Smart | 0b18ac4 | 2006-05-01 21:50:40 -0400 | [diff] [blame] | 5044 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5045 | struct lpfc_nodelist *ndlp = rdata->pnode; |
| 5046 | |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 5047 | if (!ndlp || ndlp->nlp_state != NLP_STE_MAPPED_NODE) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5048 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5049 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5050 | piocbq = &(lpfc_cmd->cur_iocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5051 | piocbq->vport = vport; |
| 5052 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5053 | piocb = &piocbq->iocb; |
| 5054 | |
| 5055 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5056 | /* Clear out any old data in the FCP command area */ |
| 5057 | memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd)); |
| 5058 | int_to_scsilun(lun, &fcp_cmnd->fcp_lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5059 | fcp_cmnd->fcpCntl2 = task_mgmt_cmd; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5060 | if (vport->phba->sli_rev == 3 && |
| 5061 | !(vport->phba->sli3_options & LPFC_SLI3_BG_ENABLED)) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5062 | lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5063 | piocb->ulpCommand = CMD_FCP_ICMND64_CR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5064 | piocb->ulpContext = ndlp->nlp_rpi; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5065 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
| 5066 | piocb->ulpContext = |
| 5067 | vport->phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
| 5068 | } |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5069 | piocb->ulpFCP2Rcvy = (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) ? 1 : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5070 | piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f); |
James Smart | f9226c2 | 2014-02-20 09:57:28 -0500 | [diff] [blame] | 5071 | piocb->ulpPU = 0; |
| 5072 | piocb->un.fcpi.fcpi_parm = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5073 | |
| 5074 | /* ulpTimeout is only one byte */ |
| 5075 | if (lpfc_cmd->timeout > 0xff) { |
| 5076 | /* |
| 5077 | * Do not timeout the command at the firmware level. |
| 5078 | * The driver will provide the timeout mechanism. |
| 5079 | */ |
| 5080 | piocb->ulpTimeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 5081 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5082 | piocb->ulpTimeout = lpfc_cmd->timeout; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 5083 | |
| 5084 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 5085 | lpfc_sli4_set_rsp_sgl_last(vport->phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5086 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5087 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5088 | } |
| 5089 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5090 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5091 | * lpfc_scsi_api_table_setup - Set up scsi api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5092 | * @phba: The hba struct for which this call is being executed. |
| 5093 | * @dev_grp: The HBA PCI-Device group number. |
| 5094 | * |
| 5095 | * This routine sets up the SCSI interface API function jump table in @phba |
| 5096 | * struct. |
| 5097 | * Returns: 0 - success, -ENODEV - failure. |
| 5098 | **/ |
| 5099 | int |
| 5100 | lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 5101 | { |
| 5102 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 5103 | phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 5104 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5105 | switch (dev_grp) { |
| 5106 | case LPFC_PCI_DEV_LP: |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5107 | phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 5108 | 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] | 5109 | phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5110 | phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s3; |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 5111 | phba->lpfc_scsi_prep_cmnd_buf = lpfc_scsi_prep_cmnd_buf_s3; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5112 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5113 | case LPFC_PCI_DEV_OC: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5114 | phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s4; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 5115 | 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] | 5116 | phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s4; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5117 | phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s4; |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 5118 | phba->lpfc_scsi_prep_cmnd_buf = lpfc_scsi_prep_cmnd_buf_s4; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5119 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5120 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5121 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5122 | "1418 Invalid HBA PCI-device group: 0x%x\n", |
| 5123 | dev_grp); |
| 5124 | return -ENODEV; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5125 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5126 | phba->lpfc_rampdown_queue_depth = lpfc_rampdown_queue_depth; |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 5127 | phba->lpfc_scsi_cmd_iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5128 | return 0; |
| 5129 | } |
| 5130 | |
| 5131 | /** |
Lee Jones | 0bb87e0 | 2021-03-12 09:47:11 +0000 | [diff] [blame] | 5132 | * lpfc_tskmgmt_def_cmpl - IOCB completion routine for task management command |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5133 | * @phba: The Hba for which this call is being executed. |
| 5134 | * @cmdiocbq: Pointer to lpfc_iocbq data structure. |
| 5135 | * @rspiocbq: Pointer to lpfc_iocbq data structure. |
| 5136 | * |
| 5137 | * This routine is IOCB completion routine for device reset and target reset |
| 5138 | * routine. This routine release scsi buffer associated with lpfc_cmd. |
| 5139 | **/ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5140 | static void |
| 5141 | lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba, |
| 5142 | struct lpfc_iocbq *cmdiocbq, |
| 5143 | struct lpfc_iocbq *rspiocbq) |
| 5144 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 5145 | struct lpfc_io_buf *lpfc_cmd = |
| 5146 | (struct lpfc_io_buf *) cmdiocbq->context1; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5147 | if (lpfc_cmd) |
| 5148 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 5149 | return; |
| 5150 | } |
| 5151 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5152 | /** |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 5153 | * lpfc_check_pci_resettable - Walks list of devices on pci_dev's bus to check |
| 5154 | * if issuing a pci_bus_reset is possibly unsafe |
| 5155 | * @phba: lpfc_hba pointer. |
| 5156 | * |
| 5157 | * Description: |
| 5158 | * Walks the bus_list to ensure only PCI devices with Emulex |
| 5159 | * vendor id, device ids that support hot reset, and only one occurrence |
| 5160 | * of function 0. |
| 5161 | * |
| 5162 | * Returns: |
| 5163 | * -EBADSLT, detected invalid device |
| 5164 | * 0, successful |
| 5165 | */ |
| 5166 | int |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5167 | lpfc_check_pci_resettable(struct lpfc_hba *phba) |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 5168 | { |
| 5169 | const struct pci_dev *pdev = phba->pcidev; |
| 5170 | struct pci_dev *ptr = NULL; |
| 5171 | u8 counter = 0; |
| 5172 | |
| 5173 | /* Walk the list of devices on the pci_dev's bus */ |
| 5174 | list_for_each_entry(ptr, &pdev->bus->devices, bus_list) { |
| 5175 | /* Check for Emulex Vendor ID */ |
| 5176 | if (ptr->vendor != PCI_VENDOR_ID_EMULEX) { |
| 5177 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5178 | "8346 Non-Emulex vendor found: " |
| 5179 | "0x%04x\n", ptr->vendor); |
| 5180 | return -EBADSLT; |
| 5181 | } |
| 5182 | |
| 5183 | /* Check for valid Emulex Device ID */ |
James Smart | f6c5e6c | 2021-07-22 15:17:18 -0700 | [diff] [blame] | 5184 | if (phba->sli_rev != LPFC_SLI_REV4 || |
| 5185 | phba->hba_flag & HBA_FCOE_MODE) { |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 5186 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a94a40e | 2021-03-01 09:18:17 -0800 | [diff] [blame] | 5187 | "8347 Incapable PCI reset device: " |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 5188 | "0x%04x\n", ptr->device); |
| 5189 | return -EBADSLT; |
| 5190 | } |
| 5191 | |
| 5192 | /* Check for only one function 0 ID to ensure only one HBA on |
| 5193 | * secondary bus |
| 5194 | */ |
| 5195 | if (ptr->devfn == 0) { |
| 5196 | if (++counter > 1) { |
| 5197 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5198 | "8348 More than one device on " |
| 5199 | "secondary bus found\n"); |
| 5200 | return -EBADSLT; |
| 5201 | } |
| 5202 | } |
| 5203 | } |
| 5204 | |
| 5205 | return 0; |
| 5206 | } |
| 5207 | |
| 5208 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5209 | * lpfc_info - Info entry point of scsi_host_template data structure |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5210 | * @host: The scsi host for which this call is being executed. |
| 5211 | * |
| 5212 | * This routine provides module information about hba. |
| 5213 | * |
| 5214 | * Reutrn code: |
| 5215 | * Pointer to char - Success. |
| 5216 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5217 | const char * |
| 5218 | lpfc_info(struct Scsi_Host *host) |
| 5219 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5220 | struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata; |
| 5221 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 5222 | int link_speed = 0; |
| 5223 | static char lpfcinfobuf[384]; |
| 5224 | char tmp[384] = {0}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5225 | |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 5226 | memset(lpfcinfobuf, 0, sizeof(lpfcinfobuf)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5227 | if (phba && phba->pcidev){ |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 5228 | /* Model Description */ |
| 5229 | scnprintf(tmp, sizeof(tmp), phba->ModelDesc); |
| 5230 | if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >= |
| 5231 | sizeof(lpfcinfobuf)) |
| 5232 | goto buffer_done; |
| 5233 | |
| 5234 | /* PCI Info */ |
| 5235 | scnprintf(tmp, sizeof(tmp), |
| 5236 | " on PCI bus %02x device %02x irq %d", |
| 5237 | phba->pcidev->bus->number, phba->pcidev->devfn, |
| 5238 | phba->pcidev->irq); |
| 5239 | if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >= |
| 5240 | sizeof(lpfcinfobuf)) |
| 5241 | goto buffer_done; |
| 5242 | |
| 5243 | /* Port Number */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5244 | if (phba->Port[0]) { |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 5245 | scnprintf(tmp, sizeof(tmp), " port %s", phba->Port); |
| 5246 | if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >= |
| 5247 | sizeof(lpfcinfobuf)) |
| 5248 | goto buffer_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5249 | } |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 5250 | |
| 5251 | /* Link Speed */ |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 5252 | link_speed = lpfc_sli_port_speed_get(phba); |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 5253 | if (link_speed != 0) { |
| 5254 | scnprintf(tmp, sizeof(tmp), |
| 5255 | " Logical Link Speed: %d Mbps", link_speed); |
| 5256 | if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >= |
| 5257 | sizeof(lpfcinfobuf)) |
| 5258 | goto buffer_done; |
| 5259 | } |
| 5260 | |
| 5261 | /* PCI resettable */ |
| 5262 | if (!lpfc_check_pci_resettable(phba)) { |
| 5263 | scnprintf(tmp, sizeof(tmp), " PCI resettable"); |
| 5264 | strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)); |
| 5265 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5266 | } |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 5267 | |
| 5268 | buffer_done: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5269 | return lpfcinfobuf; |
| 5270 | } |
| 5271 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5272 | /** |
Lee Jones | 0bb87e0 | 2021-03-12 09:47:11 +0000 | [diff] [blame] | 5273 | * lpfc_poll_rearm_timer - Routine to modify fcp_poll timer of hba |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5274 | * @phba: The Hba for which this call is being executed. |
| 5275 | * |
| 5276 | * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo. |
| 5277 | * The default value of cfg_poll_tmo is 10 milliseconds. |
| 5278 | **/ |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5279 | static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba) |
| 5280 | { |
| 5281 | unsigned long poll_tmo_expires = |
| 5282 | (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo)); |
| 5283 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5284 | 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] | 5285 | mod_timer(&phba->fcp_poll_timer, |
| 5286 | poll_tmo_expires); |
| 5287 | } |
| 5288 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5289 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5290 | * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5291 | * @phba: The Hba for which this call is being executed. |
| 5292 | * |
| 5293 | * This routine starts the fcp_poll_timer of @phba. |
| 5294 | **/ |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5295 | void lpfc_poll_start_timer(struct lpfc_hba * phba) |
| 5296 | { |
| 5297 | lpfc_poll_rearm_timer(phba); |
| 5298 | } |
| 5299 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5300 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5301 | * lpfc_poll_timeout - Restart polling timer |
Lee Jones | eceee00 | 2020-11-02 14:23:43 +0000 | [diff] [blame] | 5302 | * @t: Timer construct where lpfc_hba data structure pointer is obtained. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5303 | * |
| 5304 | * This routine restarts fcp_poll timer, when FCP ring polling is enable |
| 5305 | * and FCP Ring interrupt is disable. |
| 5306 | **/ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 5307 | void lpfc_poll_timeout(struct timer_list *t) |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5308 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 5309 | 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] | 5310 | |
| 5311 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 5312 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5313 | &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 5314 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5315 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 5316 | lpfc_poll_rearm_timer(phba); |
| 5317 | } |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5318 | } |
| 5319 | |
Gaurav Srivastava | dc50715 | 2021-06-08 10:05:51 +0530 | [diff] [blame] | 5320 | /* |
| 5321 | * lpfc_get_vmid_from_hashtable - search the UUID in the hash table |
| 5322 | * @vport: The virtual port for which this call is being executed. |
| 5323 | * @hash: calculated hash value |
| 5324 | * @buf: uuid associated with the VE |
| 5325 | * Return the VMID entry associated with the UUID |
| 5326 | * Make sure to acquire the appropriate lock before invoking this routine. |
| 5327 | */ |
| 5328 | struct lpfc_vmid *lpfc_get_vmid_from_hashtable(struct lpfc_vport *vport, |
| 5329 | u32 hash, u8 *buf) |
| 5330 | { |
| 5331 | struct lpfc_vmid *vmp; |
| 5332 | |
| 5333 | hash_for_each_possible(vport->hash_table, vmp, hnode, hash) { |
| 5334 | if (memcmp(&vmp->host_vmid[0], buf, 16) == 0) |
| 5335 | return vmp; |
| 5336 | } |
| 5337 | return NULL; |
| 5338 | } |
| 5339 | |
| 5340 | /* |
| 5341 | * lpfc_put_vmid_in_hashtable - put the VMID in the hash table |
| 5342 | * @vport: The virtual port for which this call is being executed. |
| 5343 | * @hash - calculated hash value |
| 5344 | * @vmp: Pointer to a VMID entry representing a VM sending I/O |
| 5345 | * |
| 5346 | * This routine will insert the newly acquired VMID entity in the hash table. |
| 5347 | * Make sure to acquire the appropriate lock before invoking this routine. |
| 5348 | */ |
| 5349 | static void |
| 5350 | lpfc_put_vmid_in_hashtable(struct lpfc_vport *vport, u32 hash, |
| 5351 | struct lpfc_vmid *vmp) |
| 5352 | { |
| 5353 | hash_add(vport->hash_table, &vmp->hnode, hash); |
| 5354 | } |
| 5355 | |
| 5356 | /* |
| 5357 | * lpfc_vmid_hash_fn - create a hash value of the UUID |
| 5358 | * @vmid: uuid associated with the VE |
| 5359 | * @len: length of the VMID string |
| 5360 | * Returns the calculated hash value |
| 5361 | */ |
| 5362 | int lpfc_vmid_hash_fn(const char *vmid, int len) |
| 5363 | { |
| 5364 | int c; |
| 5365 | int hash = 0; |
| 5366 | |
| 5367 | if (len == 0) |
| 5368 | return 0; |
| 5369 | while (len--) { |
| 5370 | c = *vmid++; |
| 5371 | if (c >= 'A' && c <= 'Z') |
| 5372 | c += 'a' - 'A'; |
| 5373 | |
| 5374 | hash = (hash + (c << LPFC_VMID_HASH_SHIFT) + |
| 5375 | (c >> LPFC_VMID_HASH_SHIFT)) * 19; |
| 5376 | } |
| 5377 | |
| 5378 | return hash & LPFC_VMID_HASH_MASK; |
| 5379 | } |
| 5380 | |
| 5381 | /* |
| 5382 | * lpfc_vmid_update_entry - update the vmid entry in the hash table |
| 5383 | * @vport: The virtual port for which this call is being executed. |
| 5384 | * @cmd: address of scsi cmd descriptor |
| 5385 | * @vmp: Pointer to a VMID entry representing a VM sending I/O |
| 5386 | * @tag: VMID tag |
| 5387 | */ |
| 5388 | static void lpfc_vmid_update_entry(struct lpfc_vport *vport, struct scsi_cmnd |
| 5389 | *cmd, struct lpfc_vmid *vmp, |
| 5390 | union lpfc_vmid_io_tag *tag) |
| 5391 | { |
| 5392 | u64 *lta; |
| 5393 | |
| 5394 | if (vport->vmid_priority_tagging) |
| 5395 | tag->cs_ctl_vmid = vmp->un.cs_ctl_vmid; |
| 5396 | else |
| 5397 | tag->app_id = vmp->un.app_id; |
| 5398 | |
| 5399 | if (cmd->sc_data_direction == DMA_TO_DEVICE) |
| 5400 | vmp->io_wr_cnt++; |
| 5401 | else |
| 5402 | vmp->io_rd_cnt++; |
| 5403 | |
| 5404 | /* update the last access timestamp in the table */ |
| 5405 | lta = per_cpu_ptr(vmp->last_io_time, raw_smp_processor_id()); |
| 5406 | *lta = jiffies; |
| 5407 | } |
| 5408 | |
| 5409 | static void lpfc_vmid_assign_cs_ctl(struct lpfc_vport *vport, |
| 5410 | struct lpfc_vmid *vmid) |
| 5411 | { |
| 5412 | u32 hash; |
| 5413 | struct lpfc_vmid *pvmid; |
| 5414 | |
| 5415 | if (vport->port_type == LPFC_PHYSICAL_PORT) { |
| 5416 | vmid->un.cs_ctl_vmid = lpfc_vmid_get_cs_ctl(vport); |
| 5417 | } else { |
| 5418 | hash = lpfc_vmid_hash_fn(vmid->host_vmid, vmid->vmid_len); |
| 5419 | pvmid = |
| 5420 | lpfc_get_vmid_from_hashtable(vport->phba->pport, hash, |
| 5421 | vmid->host_vmid); |
| 5422 | if (pvmid) |
| 5423 | vmid->un.cs_ctl_vmid = pvmid->un.cs_ctl_vmid; |
| 5424 | else |
| 5425 | vmid->un.cs_ctl_vmid = lpfc_vmid_get_cs_ctl(vport); |
| 5426 | } |
| 5427 | } |
| 5428 | |
Gaurav Srivastava | 33c7974 | 2021-06-08 10:05:56 +0530 | [diff] [blame] | 5429 | /* |
| 5430 | * lpfc_vmid_get_appid - get the VMID associated with the UUID |
| 5431 | * @vport: The virtual port for which this call is being executed. |
| 5432 | * @uuid: UUID associated with the VE |
| 5433 | * @cmd: address of scsi_cmd descriptor |
| 5434 | * @tag: VMID tag |
| 5435 | * Returns status of the function |
| 5436 | */ |
| 5437 | static int lpfc_vmid_get_appid(struct lpfc_vport *vport, char *uuid, struct |
| 5438 | scsi_cmnd * cmd, union lpfc_vmid_io_tag *tag) |
| 5439 | { |
| 5440 | struct lpfc_vmid *vmp = NULL; |
| 5441 | int hash, len, rc, i; |
| 5442 | |
| 5443 | /* check if QFPA is complete */ |
| 5444 | if (lpfc_vmid_is_type_priority_tag(vport) && !(vport->vmid_flag & |
| 5445 | LPFC_VMID_QFPA_CMPL)) { |
| 5446 | vport->work_port_events |= WORKER_CHECK_VMID_ISSUE_QFPA; |
| 5447 | return -EAGAIN; |
| 5448 | } |
| 5449 | |
| 5450 | /* search if the UUID has already been mapped to the VMID */ |
| 5451 | len = strlen(uuid); |
| 5452 | hash = lpfc_vmid_hash_fn(uuid, len); |
| 5453 | |
| 5454 | /* search for the VMID in the table */ |
| 5455 | read_lock(&vport->vmid_lock); |
| 5456 | vmp = lpfc_get_vmid_from_hashtable(vport, hash, uuid); |
| 5457 | |
| 5458 | /* if found, check if its already registered */ |
| 5459 | if (vmp && vmp->flag & LPFC_VMID_REGISTERED) { |
| 5460 | read_unlock(&vport->vmid_lock); |
| 5461 | lpfc_vmid_update_entry(vport, cmd, vmp, tag); |
| 5462 | rc = 0; |
| 5463 | } else if (vmp && (vmp->flag & LPFC_VMID_REQ_REGISTER || |
| 5464 | vmp->flag & LPFC_VMID_DE_REGISTER)) { |
| 5465 | /* else if register or dereg request has already been sent */ |
| 5466 | /* Hence VMID tag will not be added for this I/O */ |
| 5467 | read_unlock(&vport->vmid_lock); |
| 5468 | rc = -EBUSY; |
| 5469 | } else { |
| 5470 | /* The VMID was not found in the hashtable. At this point, */ |
| 5471 | /* drop the read lock first before proceeding further */ |
| 5472 | read_unlock(&vport->vmid_lock); |
| 5473 | /* start the process to obtain one as per the */ |
| 5474 | /* type of the VMID indicated */ |
| 5475 | write_lock(&vport->vmid_lock); |
| 5476 | vmp = lpfc_get_vmid_from_hashtable(vport, hash, uuid); |
| 5477 | |
| 5478 | /* while the read lock was released, in case the entry was */ |
| 5479 | /* added by other context or is in process of being added */ |
| 5480 | if (vmp && vmp->flag & LPFC_VMID_REGISTERED) { |
| 5481 | lpfc_vmid_update_entry(vport, cmd, vmp, tag); |
| 5482 | write_unlock(&vport->vmid_lock); |
| 5483 | return 0; |
| 5484 | } else if (vmp && vmp->flag & LPFC_VMID_REQ_REGISTER) { |
| 5485 | write_unlock(&vport->vmid_lock); |
| 5486 | return -EBUSY; |
| 5487 | } |
| 5488 | |
| 5489 | /* else search and allocate a free slot in the hash table */ |
| 5490 | if (vport->cur_vmid_cnt < vport->max_vmid) { |
| 5491 | for (i = 0; i < vport->max_vmid; i++) { |
| 5492 | vmp = vport->vmid + i; |
| 5493 | if (vmp->flag == LPFC_VMID_SLOT_FREE) |
| 5494 | break; |
| 5495 | } |
| 5496 | if (i == vport->max_vmid) |
| 5497 | vmp = NULL; |
| 5498 | } else { |
| 5499 | vmp = NULL; |
| 5500 | } |
| 5501 | |
| 5502 | if (!vmp) { |
| 5503 | write_unlock(&vport->vmid_lock); |
| 5504 | return -ENOMEM; |
| 5505 | } |
| 5506 | |
| 5507 | /* Add the vmid and register */ |
| 5508 | lpfc_put_vmid_in_hashtable(vport, hash, vmp); |
| 5509 | vmp->vmid_len = len; |
| 5510 | memcpy(vmp->host_vmid, uuid, vmp->vmid_len); |
| 5511 | vmp->io_rd_cnt = 0; |
| 5512 | vmp->io_wr_cnt = 0; |
| 5513 | vmp->flag = LPFC_VMID_SLOT_USED; |
| 5514 | |
| 5515 | vmp->delete_inactive = |
| 5516 | vport->vmid_inactivity_timeout ? 1 : 0; |
| 5517 | |
| 5518 | /* if type priority tag, get next available VMID */ |
| 5519 | if (lpfc_vmid_is_type_priority_tag(vport)) |
| 5520 | lpfc_vmid_assign_cs_ctl(vport, vmp); |
| 5521 | |
| 5522 | /* allocate the per cpu variable for holding */ |
| 5523 | /* the last access time stamp only if VMID is enabled */ |
| 5524 | if (!vmp->last_io_time) |
| 5525 | vmp->last_io_time = __alloc_percpu(sizeof(u64), |
| 5526 | __alignof__(struct |
| 5527 | lpfc_vmid)); |
| 5528 | if (!vmp->last_io_time) { |
| 5529 | hash_del(&vmp->hnode); |
| 5530 | vmp->flag = LPFC_VMID_SLOT_FREE; |
| 5531 | write_unlock(&vport->vmid_lock); |
| 5532 | return -EIO; |
| 5533 | } |
| 5534 | |
| 5535 | write_unlock(&vport->vmid_lock); |
| 5536 | |
| 5537 | /* complete transaction with switch */ |
| 5538 | if (lpfc_vmid_is_type_priority_tag(vport)) |
| 5539 | rc = lpfc_vmid_uvem(vport, vmp, true); |
| 5540 | else |
| 5541 | rc = lpfc_vmid_cmd(vport, SLI_CTAS_RAPP_IDENT, vmp); |
| 5542 | if (!rc) { |
| 5543 | write_lock(&vport->vmid_lock); |
| 5544 | vport->cur_vmid_cnt++; |
| 5545 | vmp->flag |= LPFC_VMID_REQ_REGISTER; |
| 5546 | write_unlock(&vport->vmid_lock); |
| 5547 | } else { |
| 5548 | write_lock(&vport->vmid_lock); |
| 5549 | hash_del(&vmp->hnode); |
| 5550 | vmp->flag = LPFC_VMID_SLOT_FREE; |
| 5551 | free_percpu(vmp->last_io_time); |
| 5552 | write_unlock(&vport->vmid_lock); |
| 5553 | return -EIO; |
| 5554 | } |
| 5555 | |
| 5556 | /* finally, enable the idle timer once */ |
| 5557 | if (!(vport->phba->pport->vmid_flag & LPFC_VMID_TIMER_ENBLD)) { |
| 5558 | mod_timer(&vport->phba->inactive_vmid_poll, |
| 5559 | jiffies + |
| 5560 | msecs_to_jiffies(1000 * LPFC_VMID_TIMER)); |
| 5561 | vport->phba->pport->vmid_flag |= LPFC_VMID_TIMER_ENBLD; |
| 5562 | } |
| 5563 | } |
| 5564 | return rc; |
| 5565 | } |
| 5566 | |
| 5567 | /* |
| 5568 | * lpfc_is_command_vm_io - get the UUID from blk cgroup |
| 5569 | * @cmd: Pointer to scsi_cmnd data structure |
| 5570 | * Returns UUID if present, otherwise NULL |
| 5571 | */ |
| 5572 | static char *lpfc_is_command_vm_io(struct scsi_cmnd *cmd) |
| 5573 | { |
Bart Van Assche | 4221c8a | 2021-08-09 16:03:30 -0700 | [diff] [blame] | 5574 | struct bio *bio = scsi_cmd_to_rq(cmd)->bio; |
Gaurav Srivastava | 33c7974 | 2021-06-08 10:05:56 +0530 | [diff] [blame] | 5575 | |
Bart Van Assche | 4221c8a | 2021-08-09 16:03:30 -0700 | [diff] [blame] | 5576 | return bio ? blkcg_get_fc_appid(bio) : NULL; |
Gaurav Srivastava | 33c7974 | 2021-06-08 10:05:56 +0530 | [diff] [blame] | 5577 | } |
| 5578 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5579 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5580 | * lpfc_queuecommand - scsi_host_template queuecommand entry point |
Lee Jones | eceee00 | 2020-11-02 14:23:43 +0000 | [diff] [blame] | 5581 | * @shost: kernel scsi host pointer. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5582 | * @cmnd: Pointer to scsi_cmnd data structure. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5583 | * |
| 5584 | * Driver registers this routine to scsi midlayer to submit a @cmd to process. |
| 5585 | * This routine prepares an IOCB from scsi command and provides to firmware. |
| 5586 | * The @done callback is invoked after driver finished processing the command. |
| 5587 | * |
| 5588 | * Return value : |
| 5589 | * 0 - Success |
| 5590 | * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily. |
| 5591 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5592 | static int |
James Smart | b9a7c63 | 2012-08-03 12:35:24 -0400 | [diff] [blame] | 5593 | lpfc_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5594 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5595 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 5596 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5597 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5598 | struct lpfc_nodelist *ndlp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 5599 | struct lpfc_io_buf *lpfc_cmd; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 5600 | struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device)); |
James Smart | 4c47efc | 2019-01-28 11:14:25 -0800 | [diff] [blame] | 5601 | int err, idx; |
James Smart | 66b4d63 | 2021-06-18 10:18:42 -0700 | [diff] [blame] | 5602 | u8 *uuid = NULL; |
James Smart | 2fcbc56 | 2020-03-22 11:13:02 -0700 | [diff] [blame] | 5603 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 5604 | uint64_t start = 0L; |
| 5605 | |
| 5606 | if (phba->ktime_on) |
| 5607 | start = ktime_get_ns(); |
| 5608 | #endif |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 5609 | start = ktime_get_ns(); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5610 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 5611 | |
| 5612 | /* sanity check on references */ |
| 5613 | if (unlikely(!rdata) || unlikely(!rport)) |
| 5614 | goto out_fail_command; |
| 5615 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 5616 | err = fc_remote_port_chkready(rport); |
| 5617 | if (err) { |
| 5618 | cmnd->result = err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5619 | goto out_fail_command; |
| 5620 | } |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5621 | ndlp = rdata->pnode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5622 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 5623 | if ((scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) && |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 5624 | (!(phba->sli3_options & LPFC_SLI3_BG_ENABLED))) { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5625 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5626 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5627 | "9058 BLKGRD: ERROR: rcvd protected cmd:%02x" |
| 5628 | " op:%02x str=%s without registering for" |
| 5629 | " BlockGuard - Rejecting command\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5630 | cmnd->cmnd[0], scsi_get_prot_op(cmnd), |
| 5631 | dif_op_str[scsi_get_prot_op(cmnd)]); |
| 5632 | goto out_fail_command; |
| 5633 | } |
| 5634 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5635 | /* |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 5636 | * Catch race where our node has transitioned, but the |
| 5637 | * transport is still transitioning. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5638 | */ |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 5639 | if (!ndlp) |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 5640 | goto out_tgt_busy1; |
| 5641 | |
| 5642 | /* Check if IO qualifies for CMF */ |
| 5643 | if (phba->cmf_active_mode != LPFC_CFG_OFF && |
| 5644 | cmnd->sc_data_direction == DMA_FROM_DEVICE && |
| 5645 | (scsi_sg_count(cmnd))) { |
| 5646 | /* Latency start time saved in rx_cmd_start later in routine */ |
| 5647 | err = lpfc_update_cmf_cmd(phba, scsi_bufflen(cmnd)); |
| 5648 | if (err) |
| 5649 | goto out_tgt_busy1; |
| 5650 | } |
| 5651 | |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 5652 | if (lpfc_ndlp_check_qdepth(phba, ndlp)) { |
| 5653 | if (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth) { |
| 5654 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_ERROR, |
| 5655 | "3377 Target Queue Full, scsi Id:%d " |
| 5656 | "Qdepth:%d Pending command:%d" |
| 5657 | " WWNN:%02x:%02x:%02x:%02x:" |
| 5658 | "%02x:%02x:%02x:%02x, " |
| 5659 | " WWPN:%02x:%02x:%02x:%02x:" |
| 5660 | "%02x:%02x:%02x:%02x", |
| 5661 | ndlp->nlp_sid, ndlp->cmd_qdepth, |
| 5662 | atomic_read(&ndlp->cmd_pending), |
| 5663 | ndlp->nlp_nodename.u.wwn[0], |
| 5664 | ndlp->nlp_nodename.u.wwn[1], |
| 5665 | ndlp->nlp_nodename.u.wwn[2], |
| 5666 | ndlp->nlp_nodename.u.wwn[3], |
| 5667 | ndlp->nlp_nodename.u.wwn[4], |
| 5668 | ndlp->nlp_nodename.u.wwn[5], |
| 5669 | ndlp->nlp_nodename.u.wwn[6], |
| 5670 | ndlp->nlp_nodename.u.wwn[7], |
| 5671 | ndlp->nlp_portname.u.wwn[0], |
| 5672 | ndlp->nlp_portname.u.wwn[1], |
| 5673 | ndlp->nlp_portname.u.wwn[2], |
| 5674 | ndlp->nlp_portname.u.wwn[3], |
| 5675 | ndlp->nlp_portname.u.wwn[4], |
| 5676 | ndlp->nlp_portname.u.wwn[5], |
| 5677 | ndlp->nlp_portname.u.wwn[6], |
| 5678 | ndlp->nlp_portname.u.wwn[7]); |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 5679 | goto out_tgt_busy2; |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 5680 | } |
James Smart | 64bf009 | 2018-01-30 15:58:53 -0800 | [diff] [blame] | 5681 | } |
James Smart | f91bc59 | 2018-04-09 14:24:22 -0700 | [diff] [blame] | 5682 | |
James Smart | ace44e4 | 2019-01-28 11:14:27 -0800 | [diff] [blame] | 5683 | lpfc_cmd = lpfc_get_scsi_buf(phba, ndlp, cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5684 | if (lpfc_cmd == NULL) { |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5685 | lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5686 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5687 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_ERROR, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5688 | "0707 driver's buffer pool is empty, " |
| 5689 | "IO busied\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5690 | goto out_host_busy; |
| 5691 | } |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 5692 | lpfc_cmd->rx_cmd_start = start; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5693 | |
| 5694 | /* |
| 5695 | * Store the midlayer's command structure for the completion phase |
| 5696 | * and complete the command initialization. |
| 5697 | */ |
| 5698 | lpfc_cmd->pCmd = cmnd; |
| 5699 | lpfc_cmd->rdata = rdata; |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 5700 | lpfc_cmd->ndlp = ndlp; |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 5701 | lpfc_cmd->cur_iocbq.iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5702 | cmnd->host_scribble = (unsigned char *)lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5703 | |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 5704 | err = lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp); |
| 5705 | if (err) |
| 5706 | goto out_host_busy_release_buf; |
| 5707 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5708 | if (scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5709 | if (vport->phba->cfg_enable_bg) { |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 5710 | lpfc_printf_vlog(vport, |
| 5711 | KERN_INFO, LOG_SCSI_CMD, |
James Smart | 2613470 | 2012-08-14 14:25:50 -0400 | [diff] [blame] | 5712 | "9033 BLKGRD: rcvd %s cmd:x%x " |
James Smart | 68a6a66 | 2021-03-01 09:18:02 -0800 | [diff] [blame] | 5713 | "reftag x%x cnt %u pt %x\n", |
James Smart | 2613470 | 2012-08-14 14:25:50 -0400 | [diff] [blame] | 5714 | dif_op_str[scsi_get_prot_op(cmnd)], |
| 5715 | cmnd->cmnd[0], |
Bart Van Assche | 4221c8a | 2021-08-09 16:03:30 -0700 | [diff] [blame] | 5716 | t10_pi_ref_tag(scsi_cmd_to_rq(cmnd)), |
| 5717 | blk_rq_sectors(scsi_cmd_to_rq(cmnd)), |
James Smart | 2613470 | 2012-08-14 14:25:50 -0400 | [diff] [blame] | 5718 | (cmnd->cmnd[1]>>5)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5719 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5720 | err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 5721 | } else { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5722 | if (vport->phba->cfg_enable_bg) { |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 5723 | lpfc_printf_vlog(vport, |
| 5724 | KERN_INFO, LOG_SCSI_CMD, |
James Smart | 2613470 | 2012-08-14 14:25:50 -0400 | [diff] [blame] | 5725 | "9038 BLKGRD: rcvd PROT_NORMAL cmd: " |
James Smart | 68a6a66 | 2021-03-01 09:18:02 -0800 | [diff] [blame] | 5726 | "x%x reftag x%x cnt %u pt %x\n", |
James Smart | 2613470 | 2012-08-14 14:25:50 -0400 | [diff] [blame] | 5727 | cmnd->cmnd[0], |
Bart Van Assche | 4221c8a | 2021-08-09 16:03:30 -0700 | [diff] [blame] | 5728 | t10_pi_ref_tag(scsi_cmd_to_rq(cmnd)), |
| 5729 | blk_rq_sectors(scsi_cmd_to_rq(cmnd)), |
James Smart | 2613470 | 2012-08-14 14:25:50 -0400 | [diff] [blame] | 5730 | (cmnd->cmnd[1]>>5)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5731 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5732 | err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 5733 | } |
| 5734 | |
James Smart | 22770cb | 2019-10-18 14:18:24 -0700 | [diff] [blame] | 5735 | if (unlikely(err)) { |
| 5736 | if (err == 2) { |
| 5737 | cmnd->result = DID_ERROR << 16; |
| 5738 | goto out_fail_command_release_buf; |
| 5739 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5740 | goto out_host_busy_free_buf; |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 5741 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5742 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5743 | |
Gaurav Srivastava | 33c7974 | 2021-06-08 10:05:56 +0530 | [diff] [blame] | 5744 | /* check the necessary and sufficient condition to support VMID */ |
| 5745 | if (lpfc_is_vmid_enabled(phba) && |
| 5746 | (ndlp->vmid_support || |
| 5747 | phba->pport->vmid_priority_tagging == |
| 5748 | LPFC_VMID_PRIO_TAG_ALL_TARGETS)) { |
| 5749 | /* is the I/O generated by a VM, get the associated virtual */ |
| 5750 | /* entity id */ |
| 5751 | uuid = lpfc_is_command_vm_io(cmnd); |
| 5752 | |
| 5753 | if (uuid) { |
| 5754 | err = lpfc_vmid_get_appid(vport, uuid, cmnd, |
| 5755 | (union lpfc_vmid_io_tag *) |
| 5756 | &lpfc_cmd->cur_iocbq.vmid_tag); |
| 5757 | if (!err) |
| 5758 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_VMID; |
| 5759 | } |
| 5760 | } |
| 5761 | |
| 5762 | atomic_inc(&ndlp->cmd_pending); |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 5763 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 5764 | if (unlikely(phba->hdwqstat_on & LPFC_CHECK_SCSI_IO)) |
| 5765 | this_cpu_inc(phba->sli4_hba.c_stat->xmt_io); |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 5766 | #endif |
James Smart | 47ff4c5 | 2020-11-15 11:26:41 -0800 | [diff] [blame] | 5767 | /* Issue I/O to adapter */ |
| 5768 | err = lpfc_sli_issue_fcp_io(phba, LPFC_FCP_RING, |
| 5769 | &lpfc_cmd->cur_iocbq, |
| 5770 | SLI_IOCB_RET_IOCB); |
James Smart | 2fcbc56 | 2020-03-22 11:13:02 -0700 | [diff] [blame] | 5771 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 5772 | if (start) { |
| 5773 | lpfc_cmd->ts_cmd_start = start; |
| 5774 | lpfc_cmd->ts_last_cmd = phba->ktime_last_cmd; |
| 5775 | lpfc_cmd->ts_cmd_wqput = ktime_get_ns(); |
| 5776 | } else { |
| 5777 | lpfc_cmd->ts_cmd_start = 0; |
| 5778 | } |
| 5779 | #endif |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5780 | if (err) { |
James Smart | 76f96b6 | 2013-12-17 20:29:01 -0500 | [diff] [blame] | 5781 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 5782 | "3376 FCP could not issue IOCB err %x " |
| 5783 | "FCP cmd x%x <%d/%llu> " |
| 5784 | "sid: x%x did: x%x oxid: x%x " |
| 5785 | "Data: x%x x%x x%x x%x\n", |
| 5786 | err, cmnd->cmnd[0], |
| 5787 | cmnd->device ? cmnd->device->id : 0xffff, |
| 5788 | cmnd->device ? cmnd->device->lun : (u64)-1, |
| 5789 | vport->fc_myDID, ndlp->nlp_DID, |
| 5790 | phba->sli_rev == LPFC_SLI_REV4 ? |
| 5791 | lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff, |
| 5792 | phba->sli_rev == LPFC_SLI_REV4 ? |
| 5793 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi] : |
| 5794 | lpfc_cmd->cur_iocbq.iocb.ulpContext, |
| 5795 | lpfc_cmd->cur_iocbq.iotag, |
| 5796 | phba->sli_rev == LPFC_SLI_REV4 ? |
| 5797 | bf_get(wqe_tmo, |
| 5798 | &lpfc_cmd->cur_iocbq.wqe.generic.wqe_com) : |
| 5799 | lpfc_cmd->cur_iocbq.iocb.ulpTimeout, |
Bart Van Assche | 4221c8a | 2021-08-09 16:03:30 -0700 | [diff] [blame] | 5800 | (uint32_t)(scsi_cmd_to_rq(cmnd)->timeout / 1000)); |
James Smart | 76f96b6 | 2013-12-17 20:29:01 -0500 | [diff] [blame] | 5801 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5802 | goto out_host_busy_free_buf; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5803 | } |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 5804 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5805 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 5806 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5807 | &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 5808 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5809 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 5810 | lpfc_poll_rearm_timer(phba); |
| 5811 | } |
| 5812 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 5813 | if (phba->cfg_xri_rebalancing) |
| 5814 | lpfc_keep_pvt_pool_above_lowwm(phba, lpfc_cmd->hdwq_no); |
| 5815 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5816 | return 0; |
| 5817 | |
| 5818 | out_host_busy_free_buf: |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 5819 | idx = lpfc_cmd->hdwq_no; |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 5820 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
James Smart | 4c47efc | 2019-01-28 11:14:25 -0800 | [diff] [blame] | 5821 | if (phba->sli4_hba.hdwq) { |
| 5822 | switch (lpfc_cmd->fcp_cmnd->fcpCntl3) { |
| 5823 | case WRITE_DATA: |
| 5824 | phba->sli4_hba.hdwq[idx].scsi_cstat.output_requests--; |
| 5825 | break; |
| 5826 | case READ_DATA: |
| 5827 | phba->sli4_hba.hdwq[idx].scsi_cstat.input_requests--; |
| 5828 | break; |
| 5829 | default: |
| 5830 | phba->sli4_hba.hdwq[idx].scsi_cstat.control_requests--; |
| 5831 | } |
| 5832 | } |
James Smart | da255e2 | 2020-11-15 11:26:42 -0800 | [diff] [blame] | 5833 | out_host_busy_release_buf: |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 5834 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5835 | out_host_busy: |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 5836 | lpfc_update_cmf_cmpl(phba, LPFC_CGN_NOT_SENT, scsi_bufflen(cmnd), |
| 5837 | shost); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5838 | return SCSI_MLQUEUE_HOST_BUSY; |
| 5839 | |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 5840 | out_tgt_busy2: |
| 5841 | lpfc_update_cmf_cmpl(phba, LPFC_CGN_NOT_SENT, scsi_bufflen(cmnd), |
| 5842 | shost); |
| 5843 | out_tgt_busy1: |
Mike Christie | 3496343 | 2011-02-25 14:04:28 -0600 | [diff] [blame] | 5844 | return SCSI_MLQUEUE_TARGET_BUSY; |
| 5845 | |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 5846 | out_fail_command_release_buf: |
| 5847 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame^] | 5848 | lpfc_update_cmf_cmpl(phba, LPFC_CGN_NOT_SENT, scsi_bufflen(cmnd), |
| 5849 | shost); |
James Smart | 5e0e231 | 2019-08-14 16:56:54 -0700 | [diff] [blame] | 5850 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5851 | out_fail_command: |
James Smart | b9a7c63 | 2012-08-03 12:35:24 -0400 | [diff] [blame] | 5852 | cmnd->scsi_done(cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5853 | return 0; |
| 5854 | } |
| 5855 | |
Gaurav Srivastava | 5e63330 | 2021-06-08 10:05:49 +0530 | [diff] [blame] | 5856 | /* |
| 5857 | * lpfc_vmid_vport_cleanup - cleans up the resources associated with a vport |
| 5858 | * @vport: The virtual port for which this call is being executed. |
| 5859 | */ |
| 5860 | void lpfc_vmid_vport_cleanup(struct lpfc_vport *vport) |
| 5861 | { |
| 5862 | u32 bucket; |
| 5863 | struct lpfc_vmid *cur; |
| 5864 | |
| 5865 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 5866 | del_timer_sync(&vport->phba->inactive_vmid_poll); |
| 5867 | |
| 5868 | kfree(vport->qfpa_res); |
| 5869 | kfree(vport->vmid_priority.vmid_range); |
| 5870 | kfree(vport->vmid); |
| 5871 | |
| 5872 | if (!hash_empty(vport->hash_table)) |
| 5873 | hash_for_each(vport->hash_table, bucket, cur, hnode) |
| 5874 | hash_del(&cur->hnode); |
| 5875 | |
| 5876 | vport->qfpa_res = NULL; |
| 5877 | vport->vmid_priority.vmid_range = NULL; |
| 5878 | vport->vmid = NULL; |
| 5879 | vport->cur_vmid_cnt = 0; |
| 5880 | } |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 5881 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5882 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5883 | * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5884 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5885 | * |
| 5886 | * This routine aborts @cmnd pending in base driver. |
| 5887 | * |
| 5888 | * Return code : |
| 5889 | * 0x2003 - Error |
| 5890 | * 0x2002 - Success |
| 5891 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5892 | static int |
James.Smart@Emulex.Com | 63c59c3 | 2005-11-28 11:41:53 -0500 | [diff] [blame] | 5893 | lpfc_abort_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5894 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5895 | struct Scsi_Host *shost = cmnd->device->host; |
| 5896 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 5897 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 5898 | struct lpfc_iocbq *iocb; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 5899 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 5900 | int ret = SUCCESS, status = 0; |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 5901 | struct lpfc_sli_ring *pring_s4 = NULL; |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 5902 | struct lpfc_sli_ring *pring = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5903 | int ret_val; |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 5904 | unsigned long flags; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 5905 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 5906 | |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 5907 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 5908 | if (status != 0 && status != SUCCESS) |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 5909 | return status; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 5910 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 5911 | lpfc_cmd = (struct lpfc_io_buf *)cmnd->host_scribble; |
| 5912 | if (!lpfc_cmd) |
| 5913 | return ret; |
| 5914 | |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 5915 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 5916 | /* driver queued commands are in process of being flushed */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 5917 | if (phba->hba_flag & HBA_IOQ_FLUSH) { |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 5918 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 5919 | "3168 SCSI Layer abort requested I/O has been " |
| 5920 | "flushed by LLD.\n"); |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 5921 | ret = FAILED; |
| 5922 | goto out_unlock; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 5923 | } |
| 5924 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 5925 | /* Guard against IO completion being called at same time */ |
| 5926 | spin_lock(&lpfc_cmd->buf_lock); |
| 5927 | |
| 5928 | if (!lpfc_cmd->pCmd) { |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 5929 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 5930 | "2873 SCSI Layer I/O Abort Request IO CMPL Status " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5931 | "x%x ID %d LUN %llu\n", |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 5932 | SUCCESS, cmnd->device->id, cmnd->device->lun); |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 5933 | goto out_unlock_buf; |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 5934 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5935 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 5936 | iocb = &lpfc_cmd->cur_iocbq; |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 5937 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 5938 | pring_s4 = phba->sli4_hba.hdwq[iocb->hba_wqidx].io_wq->pring; |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 5939 | if (!pring_s4) { |
| 5940 | ret = FAILED; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 5941 | goto out_unlock_buf; |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 5942 | } |
| 5943 | spin_lock(&pring_s4->ring_lock); |
| 5944 | } |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 5945 | /* the command is in process of being cancelled */ |
| 5946 | if (!(iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ)) { |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 5947 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 5948 | "3169 SCSI Layer abort requested I/O has been " |
| 5949 | "cancelled by LLD.\n"); |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 5950 | ret = FAILED; |
| 5951 | goto out_unlock_ring; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 5952 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5953 | /* |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 5954 | * If pCmd field of the corresponding lpfc_io_buf structure |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 5955 | * points to a different SCSI command, then the driver has |
| 5956 | * already completed this command, but the midlayer did not |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 5957 | * see the completion before the eh fired. Just return SUCCESS. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5958 | */ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 5959 | if (lpfc_cmd->pCmd != cmnd) { |
| 5960 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 5961 | "3170 SCSI Layer abort requested I/O has been " |
| 5962 | "completed by LLD.\n"); |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 5963 | goto out_unlock_ring; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 5964 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5965 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 5966 | BUG_ON(iocb->context1 != lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5967 | |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 5968 | /* abort issued in recovery is still in progress */ |
| 5969 | if (iocb->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 5970 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 5971 | "3389 SCSI Layer I/O Abort Request is pending\n"); |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 5972 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 5973 | spin_unlock(&pring_s4->ring_lock); |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 5974 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 5975 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 5976 | goto wait_for_cmpl; |
| 5977 | } |
| 5978 | |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 5979 | lpfc_cmd->waitq = &waitq; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 5980 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 5981 | spin_unlock(&pring_s4->ring_lock); |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 5982 | ret_val = lpfc_sli4_issue_abort_iotag(phba, iocb, |
| 5983 | lpfc_sli4_abort_fcp_cmpl); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 5984 | } else { |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 5985 | pring = &phba->sli.sli3_ring[LPFC_FCP_RING]; |
| 5986 | ret_val = lpfc_sli_issue_abort_iotag(phba, pring, iocb, |
| 5987 | lpfc_sli_abort_fcp_cmpl); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 5988 | } |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 5989 | |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 5990 | /* Make sure HBA is alive */ |
| 5991 | lpfc_issue_hb_tmo(phba); |
| 5992 | |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 5993 | if (ret_val != IOCB_SUCCESS) { |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 5994 | /* Indicate the IO is not being aborted by the driver. */ |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 5995 | lpfc_cmd->waitq = NULL; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 5996 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 91a52b6 | 2019-10-18 14:18:22 -0700 | [diff] [blame] | 5997 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 5998 | ret = FAILED; |
| 5999 | goto out; |
| 6000 | } |
| 6001 | |
James Smart | 91a52b6 | 2019-10-18 14:18:22 -0700 | [diff] [blame] | 6002 | /* no longer need the lock after this point */ |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 6003 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 91a52b6 | 2019-10-18 14:18:22 -0700 | [diff] [blame] | 6004 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 6005 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 6006 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 6007 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6008 | &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 6009 | |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 6010 | wait_for_cmpl: |
James Smart | db7531d | 2020-11-15 11:26:44 -0800 | [diff] [blame] | 6011 | /* |
| 6012 | * iocb_flag is set to LPFC_DRIVER_ABORTED before we wait |
| 6013 | * for abort to complete. |
| 6014 | */ |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 6015 | wait_event_timeout(waitq, |
| 6016 | (lpfc_cmd->pCmd != cmnd), |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 6017 | msecs_to_jiffies(2*vport->cfg_devloss_tmo*1000)); |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 6018 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 6019 | spin_lock(&lpfc_cmd->buf_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6020 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 6021 | if (lpfc_cmd->pCmd == cmnd) { |
| 6022 | ret = FAILED; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6023 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6024 | "0748 abort handler timed out waiting " |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 6025 | "for aborting I/O (xri:x%x) to complete: " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 6026 | "ret %#x, ID %d, LUN %llu\n", |
James Smart | 247ca94 | 2012-08-14 14:26:13 -0400 | [diff] [blame] | 6027 | iocb->sli4_xritag, ret, |
| 6028 | cmnd->device->id, cmnd->device->lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6029 | } |
James Smart | b9e5a2d | 2019-05-21 17:49:01 -0700 | [diff] [blame] | 6030 | |
| 6031 | lpfc_cmd->waitq = NULL; |
| 6032 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 6033 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 6034 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6035 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 6036 | out_unlock_ring: |
| 6037 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6038 | spin_unlock(&pring_s4->ring_lock); |
| 6039 | out_unlock_buf: |
| 6040 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 6041 | out_unlock: |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 6042 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 6043 | out: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6044 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 6045 | "0749 SCSI Layer I/O Abort Request Status x%x ID %d " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 6046 | "LUN %llu\n", ret, cmnd->device->id, |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 6047 | cmnd->device->lun); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 6048 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6049 | } |
| 6050 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6051 | static char * |
| 6052 | lpfc_taskmgmt_name(uint8_t task_mgmt_cmd) |
| 6053 | { |
| 6054 | switch (task_mgmt_cmd) { |
| 6055 | case FCP_ABORT_TASK_SET: |
| 6056 | return "ABORT_TASK_SET"; |
| 6057 | case FCP_CLEAR_TASK_SET: |
| 6058 | return "FCP_CLEAR_TASK_SET"; |
| 6059 | case FCP_BUS_RESET: |
| 6060 | return "FCP_BUS_RESET"; |
| 6061 | case FCP_LUN_RESET: |
| 6062 | return "FCP_LUN_RESET"; |
| 6063 | case FCP_TARGET_RESET: |
| 6064 | return "FCP_TARGET_RESET"; |
| 6065 | case FCP_CLEAR_ACA: |
| 6066 | return "FCP_CLEAR_ACA"; |
| 6067 | case FCP_TERMINATE_TASK: |
| 6068 | return "FCP_TERMINATE_TASK"; |
| 6069 | default: |
| 6070 | return "unknown"; |
| 6071 | } |
| 6072 | } |
| 6073 | |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 6074 | |
| 6075 | /** |
| 6076 | * lpfc_check_fcp_rsp - check the returned fcp_rsp to see if task failed |
| 6077 | * @vport: The virtual port for which this call is being executed. |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 6078 | * @lpfc_cmd: Pointer to lpfc_io_buf data structure. |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 6079 | * |
| 6080 | * This routine checks the FCP RSP INFO to see if the tsk mgmt command succeded |
| 6081 | * |
| 6082 | * Return code : |
| 6083 | * 0x2003 - Error |
| 6084 | * 0x2002 - Success |
| 6085 | **/ |
| 6086 | static int |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 6087 | 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] | 6088 | { |
| 6089 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
| 6090 | uint32_t rsp_info; |
| 6091 | uint32_t rsp_len; |
| 6092 | uint8_t rsp_info_code; |
| 6093 | int ret = FAILED; |
| 6094 | |
| 6095 | |
| 6096 | if (fcprsp == NULL) |
| 6097 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 6098 | "0703 fcp_rsp is missing\n"); |
| 6099 | else { |
| 6100 | rsp_info = fcprsp->rspStatus2; |
| 6101 | rsp_len = be32_to_cpu(fcprsp->rspRspLen); |
| 6102 | rsp_info_code = fcprsp->rspInfo3; |
| 6103 | |
| 6104 | |
| 6105 | lpfc_printf_vlog(vport, KERN_INFO, |
| 6106 | LOG_FCP, |
| 6107 | "0706 fcp_rsp valid 0x%x," |
| 6108 | " rsp len=%d code 0x%x\n", |
| 6109 | rsp_info, |
| 6110 | rsp_len, rsp_info_code); |
| 6111 | |
James Smart | 996a02a | 2019-05-21 17:49:07 -0700 | [diff] [blame] | 6112 | /* If FCP_RSP_LEN_VALID bit is one, then the FCP_RSP_LEN |
| 6113 | * field specifies the number of valid bytes of FCP_RSP_INFO. |
| 6114 | * The FCP_RSP_LEN field shall be set to 0x04 or 0x08 |
| 6115 | */ |
| 6116 | if ((fcprsp->rspStatus2 & RSP_LEN_VALID) && |
| 6117 | ((rsp_len == 8) || (rsp_len == 4))) { |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 6118 | switch (rsp_info_code) { |
| 6119 | case RSP_NO_FAILURE: |
| 6120 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 6121 | "0715 Task Mgmt No Failure\n"); |
| 6122 | ret = SUCCESS; |
| 6123 | break; |
| 6124 | case RSP_TM_NOT_SUPPORTED: /* TM rejected */ |
| 6125 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 6126 | "0716 Task Mgmt Target " |
| 6127 | "reject\n"); |
| 6128 | break; |
| 6129 | case RSP_TM_NOT_COMPLETED: /* TM failed */ |
| 6130 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 6131 | "0717 Task Mgmt Target " |
| 6132 | "failed TM\n"); |
| 6133 | break; |
| 6134 | case RSP_TM_INVALID_LU: /* TM to invalid LU! */ |
| 6135 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 6136 | "0718 Task Mgmt to invalid " |
| 6137 | "LUN\n"); |
| 6138 | break; |
| 6139 | } |
| 6140 | } |
| 6141 | } |
| 6142 | return ret; |
| 6143 | } |
| 6144 | |
| 6145 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6146 | /** |
| 6147 | * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler |
| 6148 | * @vport: The virtual port for which this call is being executed. |
Lee Jones | eceee00 | 2020-11-02 14:23:43 +0000 | [diff] [blame] | 6149 | * @cmnd: Pointer to scsi_cmnd data structure. |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6150 | * @tgt_id: Target ID of remote device. |
| 6151 | * @lun_id: Lun number for the TMF |
| 6152 | * @task_mgmt_cmd: type of TMF to send |
| 6153 | * |
| 6154 | * This routine builds and sends a TMF (SCSI Task Mgmt Function) to |
| 6155 | * a remote port. |
| 6156 | * |
| 6157 | * Return Code: |
| 6158 | * 0x2003 - Error |
| 6159 | * 0x2002 - Success. |
| 6160 | **/ |
| 6161 | static int |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 6162 | lpfc_send_taskmgmt(struct lpfc_vport *vport, struct scsi_cmnd *cmnd, |
| 6163 | unsigned int tgt_id, uint64_t lun_id, |
| 6164 | uint8_t task_mgmt_cmd) |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6165 | { |
| 6166 | struct lpfc_hba *phba = vport->phba; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 6167 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6168 | struct lpfc_iocbq *iocbq; |
| 6169 | struct lpfc_iocbq *iocbqrsp; |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 6170 | struct lpfc_rport_data *rdata; |
| 6171 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6172 | int ret; |
| 6173 | int status; |
| 6174 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 6175 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6176 | if (!rdata || !rdata->pnode) |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6177 | return FAILED; |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 6178 | pnode = rdata->pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6179 | |
James Smart | ace44e4 | 2019-01-28 11:14:27 -0800 | [diff] [blame] | 6180 | lpfc_cmd = lpfc_get_scsi_buf(phba, pnode, NULL); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6181 | if (lpfc_cmd == NULL) |
| 6182 | return FAILED; |
James Smart | 0c41122 | 2013-09-06 12:22:46 -0400 | [diff] [blame] | 6183 | lpfc_cmd->timeout = phba->cfg_task_mgmt_tmo; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6184 | lpfc_cmd->rdata = rdata; |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 6185 | lpfc_cmd->pCmd = cmnd; |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 6186 | lpfc_cmd->ndlp = pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6187 | |
| 6188 | status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun_id, |
| 6189 | task_mgmt_cmd); |
| 6190 | if (!status) { |
| 6191 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 6192 | return FAILED; |
| 6193 | } |
| 6194 | |
| 6195 | iocbq = &lpfc_cmd->cur_iocbq; |
| 6196 | iocbqrsp = lpfc_sli_get_iocbq(phba); |
| 6197 | if (iocbqrsp == NULL) { |
| 6198 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 6199 | return FAILED; |
| 6200 | } |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 6201 | iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6202 | |
| 6203 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 6204 | "0702 Issue %s to TGT %d LUN %llu " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6205 | "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] | 6206 | lpfc_taskmgmt_name(task_mgmt_cmd), tgt_id, lun_id, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6207 | pnode->nlp_rpi, pnode->nlp_flag, iocbq->sli4_xritag, |
| 6208 | iocbq->iocb_flag); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6209 | |
| 6210 | status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING, |
| 6211 | iocbq, iocbqrsp, lpfc_cmd->timeout); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 6212 | if ((status != IOCB_SUCCESS) || |
| 6213 | (iocbqrsp->iocb.ulpStatus != IOSTAT_SUCCESS)) { |
James Smart | ae374a3 | 2015-05-22 10:42:41 -0400 | [diff] [blame] | 6214 | if (status != IOCB_SUCCESS || |
| 6215 | iocbqrsp->iocb.ulpStatus != IOSTAT_FCP_RSP_ERROR) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6216 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | ae374a3 | 2015-05-22 10:42:41 -0400 | [diff] [blame] | 6217 | "0727 TMF %s to TGT %d LUN %llu " |
| 6218 | "failed (%d, %d) iocb_flag x%x\n", |
| 6219 | lpfc_taskmgmt_name(task_mgmt_cmd), |
| 6220 | tgt_id, lun_id, |
| 6221 | iocbqrsp->iocb.ulpStatus, |
| 6222 | iocbqrsp->iocb.un.ulpWord[4], |
| 6223 | iocbq->iocb_flag); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 6224 | /* if ulpStatus != IOCB_SUCCESS, then status == IOCB_SUCCESS */ |
| 6225 | if (status == IOCB_SUCCESS) { |
| 6226 | if (iocbqrsp->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 6227 | /* Something in the FCP_RSP was invalid. |
| 6228 | * Check conditions */ |
| 6229 | ret = lpfc_check_fcp_rsp(vport, lpfc_cmd); |
| 6230 | else |
| 6231 | ret = FAILED; |
| 6232 | } else if (status == IOCB_TIMEDOUT) { |
| 6233 | ret = TIMEOUT_ERROR; |
| 6234 | } else { |
| 6235 | ret = FAILED; |
| 6236 | } |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 6237 | } else |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6238 | ret = SUCCESS; |
| 6239 | |
| 6240 | lpfc_sli_release_iocbq(phba, iocbqrsp); |
| 6241 | |
| 6242 | if (ret != TIMEOUT_ERROR) |
| 6243 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 6244 | |
| 6245 | return ret; |
| 6246 | } |
| 6247 | |
| 6248 | /** |
| 6249 | * lpfc_chk_tgt_mapped - |
| 6250 | * @vport: The virtual port to check on |
| 6251 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 6252 | * |
| 6253 | * This routine delays until the scsi target (aka rport) for the |
| 6254 | * command exists (is present and logged in) or we declare it non-existent. |
| 6255 | * |
| 6256 | * Return code : |
| 6257 | * 0x2003 - Error |
| 6258 | * 0x2002 - Success |
| 6259 | **/ |
| 6260 | static int |
| 6261 | lpfc_chk_tgt_mapped(struct lpfc_vport *vport, struct scsi_cmnd *cmnd) |
| 6262 | { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6263 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 6264 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6265 | unsigned long later; |
| 6266 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6267 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 6268 | if (!rdata) { |
| 6269 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 6270 | "0797 Tgt Map rport failure: rdata x%px\n", rdata); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 6271 | return FAILED; |
| 6272 | } |
| 6273 | pnode = rdata->pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6274 | /* |
| 6275 | * If target is not in a MAPPED state, delay until |
| 6276 | * target is rediscovered or devloss timeout expires. |
| 6277 | */ |
| 6278 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; |
| 6279 | while (time_after(later, jiffies)) { |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6280 | if (!pnode) |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6281 | return FAILED; |
| 6282 | if (pnode->nlp_state == NLP_STE_MAPPED_NODE) |
| 6283 | return SUCCESS; |
| 6284 | schedule_timeout_uninterruptible(msecs_to_jiffies(500)); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6285 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6286 | if (!rdata) |
| 6287 | return FAILED; |
| 6288 | pnode = rdata->pnode; |
| 6289 | } |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6290 | if (!pnode || (pnode->nlp_state != NLP_STE_MAPPED_NODE)) |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6291 | return FAILED; |
| 6292 | return SUCCESS; |
| 6293 | } |
| 6294 | |
| 6295 | /** |
| 6296 | * lpfc_reset_flush_io_context - |
| 6297 | * @vport: The virtual port (scsi_host) for the flush context |
| 6298 | * @tgt_id: If aborting by Target contect - specifies the target id |
| 6299 | * @lun_id: If aborting by Lun context - specifies the lun id |
| 6300 | * @context: specifies the context level to flush at. |
| 6301 | * |
| 6302 | * After a reset condition via TMF, we need to flush orphaned i/o |
| 6303 | * contexts from the adapter. This routine aborts any contexts |
| 6304 | * outstanding, then waits for their completions. The wait is |
| 6305 | * bounded by devloss_tmo though. |
| 6306 | * |
| 6307 | * Return code : |
| 6308 | * 0x2003 - Error |
| 6309 | * 0x2002 - Success |
| 6310 | **/ |
| 6311 | static int |
| 6312 | lpfc_reset_flush_io_context(struct lpfc_vport *vport, uint16_t tgt_id, |
| 6313 | uint64_t lun_id, lpfc_ctx_cmd context) |
| 6314 | { |
| 6315 | struct lpfc_hba *phba = vport->phba; |
| 6316 | unsigned long later; |
| 6317 | int cnt; |
| 6318 | |
| 6319 | cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context); |
| 6320 | if (cnt) |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 6321 | lpfc_sli_abort_taskmgmt(vport, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6322 | &phba->sli.sli3_ring[LPFC_FCP_RING], |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 6323 | tgt_id, lun_id, context); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6324 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; |
| 6325 | while (time_after(later, jiffies) && cnt) { |
| 6326 | schedule_timeout_uninterruptible(msecs_to_jiffies(20)); |
| 6327 | cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context); |
| 6328 | } |
| 6329 | if (cnt) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6330 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6331 | "0724 I/O flush failure for context %s : cnt x%x\n", |
| 6332 | ((context == LPFC_CTX_LUN) ? "LUN" : |
| 6333 | ((context == LPFC_CTX_TGT) ? "TGT" : |
| 6334 | ((context == LPFC_CTX_HOST) ? "HOST" : "Unknown"))), |
| 6335 | cnt); |
| 6336 | return FAILED; |
| 6337 | } |
| 6338 | return SUCCESS; |
| 6339 | } |
| 6340 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 6341 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6342 | * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 6343 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 6344 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6345 | * 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] | 6346 | * command. |
| 6347 | * |
| 6348 | * Return code : |
| 6349 | * 0x2003 - Error |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6350 | * 0x2002 - Success |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 6351 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6352 | static int |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 6353 | lpfc_device_reset_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6354 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6355 | struct Scsi_Host *shost = cmnd->device->host; |
| 6356 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6357 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 6358 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6359 | unsigned tgt_id = cmnd->device->id; |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 6360 | uint64_t lun_id = cmnd->device->lun; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6361 | struct lpfc_scsi_event_header scsi_event; |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 6362 | int status; |
James Smart | da09ae4 | 2021-01-04 10:02:33 -0800 | [diff] [blame] | 6363 | u32 logit = LOG_FCP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6364 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6365 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | ad490b6 | 2015-04-07 15:07:26 -0400 | [diff] [blame] | 6366 | if (!rdata || !rdata->pnode) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6367 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 6368 | "0798 Device Reset rdata failure: rdata x%px\n", |
James Smart | ad490b6 | 2015-04-07 15:07:26 -0400 | [diff] [blame] | 6369 | rdata); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 6370 | return FAILED; |
| 6371 | } |
| 6372 | pnode = rdata->pnode; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 6373 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 6374 | if (status != 0 && status != SUCCESS) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 6375 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6376 | |
| 6377 | status = lpfc_chk_tgt_mapped(vport, cmnd); |
| 6378 | if (status == FAILED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6379 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 6380 | "0721 Device Reset rport failure: rdata x%px\n", rdata); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6381 | return FAILED; |
| 6382 | } |
| 6383 | |
| 6384 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 6385 | scsi_event.subcategory = LPFC_EVENT_LUNRESET; |
| 6386 | scsi_event.lun = lun_id; |
| 6387 | memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 6388 | memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 6389 | |
| 6390 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 6391 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
| 6392 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 6393 | status = lpfc_send_taskmgmt(vport, cmnd, tgt_id, lun_id, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6394 | FCP_LUN_RESET); |
James Smart | da09ae4 | 2021-01-04 10:02:33 -0800 | [diff] [blame] | 6395 | if (status != SUCCESS) |
| 6396 | logit = LOG_TRACE_EVENT; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6397 | |
James Smart | da09ae4 | 2021-01-04 10:02:33 -0800 | [diff] [blame] | 6398 | lpfc_printf_vlog(vport, KERN_ERR, logit, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 6399 | "0713 SCSI layer issued Device Reset (%d, %llu) " |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6400 | "return x%x\n", tgt_id, lun_id, status); |
| 6401 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6402 | /* |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6403 | * We have to clean up i/o as : they may be orphaned by the TMF; |
| 6404 | * or if the TMF failed, they may be in an indeterminate state. |
| 6405 | * So, continue on. |
| 6406 | * We will report success if all the i/o aborts successfully. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6407 | */ |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 6408 | if (status == SUCCESS) |
| 6409 | status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6410 | LPFC_CTX_LUN); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 6411 | |
| 6412 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6413 | } |
| 6414 | |
| 6415 | /** |
| 6416 | * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point |
| 6417 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 6418 | * |
| 6419 | * This routine does a target reset by sending a TARGET_RESET task management |
| 6420 | * command. |
| 6421 | * |
| 6422 | * Return code : |
| 6423 | * 0x2003 - Error |
| 6424 | * 0x2002 - Success |
| 6425 | **/ |
| 6426 | static int |
| 6427 | lpfc_target_reset_handler(struct scsi_cmnd *cmnd) |
| 6428 | { |
| 6429 | struct Scsi_Host *shost = cmnd->device->host; |
| 6430 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6431 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 6432 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6433 | unsigned tgt_id = cmnd->device->id; |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 6434 | uint64_t lun_id = cmnd->device->lun; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6435 | struct lpfc_scsi_event_header scsi_event; |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 6436 | int status; |
James Smart | da09ae4 | 2021-01-04 10:02:33 -0800 | [diff] [blame] | 6437 | u32 logit = LOG_FCP; |
James Smart | 21990d3 | 2021-07-07 11:43:37 -0700 | [diff] [blame] | 6438 | u32 dev_loss_tmo = vport->cfg_devloss_tmo; |
James Smart | 3105124 | 2021-01-04 10:02:34 -0800 | [diff] [blame] | 6439 | unsigned long flags; |
| 6440 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6441 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6442 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | bbd3d73 | 2019-03-12 16:30:17 -0700 | [diff] [blame] | 6443 | if (!rdata || !rdata->pnode) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6444 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 6445 | "0799 Target Reset rdata failure: rdata x%px\n", |
James Smart | bbd3d73 | 2019-03-12 16:30:17 -0700 | [diff] [blame] | 6446 | rdata); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 6447 | return FAILED; |
| 6448 | } |
| 6449 | pnode = rdata->pnode; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 6450 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 6451 | if (status != 0 && status != SUCCESS) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 6452 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6453 | |
| 6454 | status = lpfc_chk_tgt_mapped(vport, cmnd); |
| 6455 | if (status == FAILED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6456 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 6457 | "0722 Target Reset rport failure: rdata x%px\n", rdata); |
James Smart | 63e480f | 2015-04-07 15:07:20 -0400 | [diff] [blame] | 6458 | if (pnode) { |
James Smart | 3105124 | 2021-01-04 10:02:34 -0800 | [diff] [blame] | 6459 | spin_lock_irqsave(&pnode->lock, flags); |
James Smart | 63e480f | 2015-04-07 15:07:20 -0400 | [diff] [blame] | 6460 | pnode->nlp_flag &= ~NLP_NPR_ADISC; |
| 6461 | pnode->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; |
James Smart | 3105124 | 2021-01-04 10:02:34 -0800 | [diff] [blame] | 6462 | spin_unlock_irqrestore(&pnode->lock, flags); |
James Smart | 63e480f | 2015-04-07 15:07:20 -0400 | [diff] [blame] | 6463 | } |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 6464 | lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
| 6465 | LPFC_CTX_TGT); |
| 6466 | return FAST_IO_FAIL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6467 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6468 | |
| 6469 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 6470 | scsi_event.subcategory = LPFC_EVENT_TGTRESET; |
| 6471 | scsi_event.lun = 0; |
| 6472 | memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 6473 | memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 6474 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6475 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 6476 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6477 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 6478 | status = lpfc_send_taskmgmt(vport, cmnd, tgt_id, lun_id, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6479 | FCP_TARGET_RESET); |
James Smart | 21990d3 | 2021-07-07 11:43:37 -0700 | [diff] [blame] | 6480 | if (status != SUCCESS) { |
| 6481 | logit = LOG_TRACE_EVENT; |
James Smart | 3105124 | 2021-01-04 10:02:34 -0800 | [diff] [blame] | 6482 | |
James Smart | 21990d3 | 2021-07-07 11:43:37 -0700 | [diff] [blame] | 6483 | /* Issue LOGO, if no LOGO is outstanding */ |
| 6484 | spin_lock_irqsave(&pnode->lock, flags); |
| 6485 | if (!(pnode->upcall_flags & NLP_WAIT_FOR_LOGO) && |
| 6486 | !pnode->logo_waitq) { |
| 6487 | pnode->logo_waitq = &waitq; |
| 6488 | pnode->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; |
| 6489 | pnode->nlp_flag |= NLP_ISSUE_LOGO; |
| 6490 | pnode->upcall_flags |= NLP_WAIT_FOR_LOGO; |
| 6491 | spin_unlock_irqrestore(&pnode->lock, flags); |
| 6492 | lpfc_unreg_rpi(vport, pnode); |
| 6493 | wait_event_timeout(waitq, |
| 6494 | (!(pnode->upcall_flags & |
| 6495 | NLP_WAIT_FOR_LOGO)), |
| 6496 | msecs_to_jiffies(dev_loss_tmo * |
| 6497 | 1000)); |
| 6498 | |
| 6499 | if (pnode->upcall_flags & NLP_WAIT_FOR_LOGO) { |
| 6500 | lpfc_printf_vlog(vport, KERN_ERR, logit, |
| 6501 | "0725 SCSI layer TGTRST " |
| 6502 | "failed & LOGO TMO (%d, %llu) " |
| 6503 | "return x%x\n", |
| 6504 | tgt_id, lun_id, status); |
| 6505 | spin_lock_irqsave(&pnode->lock, flags); |
| 6506 | pnode->upcall_flags &= ~NLP_WAIT_FOR_LOGO; |
| 6507 | } else { |
| 6508 | spin_lock_irqsave(&pnode->lock, flags); |
| 6509 | } |
| 6510 | pnode->logo_waitq = NULL; |
| 6511 | spin_unlock_irqrestore(&pnode->lock, flags); |
| 6512 | status = SUCCESS; |
| 6513 | |
James Smart | 3105124 | 2021-01-04 10:02:34 -0800 | [diff] [blame] | 6514 | } else { |
James Smart | 21990d3 | 2021-07-07 11:43:37 -0700 | [diff] [blame] | 6515 | spin_unlock_irqrestore(&pnode->lock, flags); |
| 6516 | status = FAILED; |
James Smart | 3105124 | 2021-01-04 10:02:34 -0800 | [diff] [blame] | 6517 | } |
James Smart | 3105124 | 2021-01-04 10:02:34 -0800 | [diff] [blame] | 6518 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6519 | |
James Smart | da09ae4 | 2021-01-04 10:02:33 -0800 | [diff] [blame] | 6520 | lpfc_printf_vlog(vport, KERN_ERR, logit, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 6521 | "0723 SCSI layer issued Target Reset (%d, %llu) " |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6522 | "return x%x\n", tgt_id, lun_id, status); |
| 6523 | |
| 6524 | /* |
| 6525 | * We have to clean up i/o as : they may be orphaned by the TMF; |
| 6526 | * or if the TMF failed, they may be in an indeterminate state. |
| 6527 | * So, continue on. |
| 6528 | * We will report success if all the i/o aborts successfully. |
| 6529 | */ |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 6530 | if (status == SUCCESS) |
| 6531 | status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 6532 | LPFC_CTX_TGT); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 6533 | return status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6534 | } |
| 6535 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 6536 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6537 | * 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] | 6538 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 6539 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6540 | * This routine does target reset to all targets on @cmnd->device->host. |
| 6541 | * This emulates Parallel SCSI Bus Reset Semantics. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 6542 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6543 | * Return code : |
| 6544 | * 0x2003 - Error |
| 6545 | * 0x2002 - Success |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 6546 | **/ |
Jeff Garzik | 94d0e7b8 | 2005-05-28 07:55:48 -0400 | [diff] [blame] | 6547 | static int |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 6548 | lpfc_bus_reset_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6549 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6550 | struct Scsi_Host *shost = cmnd->device->host; |
| 6551 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6552 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6553 | struct lpfc_scsi_event_header scsi_event; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6554 | int match; |
| 6555 | int ret = SUCCESS, status, i; |
James Smart | da09ae4 | 2021-01-04 10:02:33 -0800 | [diff] [blame] | 6556 | u32 logit = LOG_FCP; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6557 | |
| 6558 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 6559 | scsi_event.subcategory = LPFC_EVENT_BUSRESET; |
| 6560 | scsi_event.lun = 0; |
| 6561 | memcpy(scsi_event.wwpn, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 6562 | memcpy(scsi_event.wwnn, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| 6563 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6564 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 6565 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6566 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 6567 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 6568 | if (status != 0 && status != SUCCESS) |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 6569 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6570 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6571 | /* |
| 6572 | * Since the driver manages a single bus device, reset all |
| 6573 | * targets known to the driver. Should any target reset |
| 6574 | * fail, this routine returns failure to the midlayer. |
| 6575 | */ |
James Smart | e17da18 | 2006-07-06 15:49:25 -0400 | [diff] [blame] | 6576 | for (i = 0; i < LPFC_MAX_TARGET; i++) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6577 | /* Search for mapped node by target ID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6578 | match = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6579 | spin_lock_irq(shost->host_lock); |
| 6580 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 6581 | |
James Smart | a6571c6 | 2012-10-31 14:44:42 -0400 | [diff] [blame] | 6582 | if (vport->phba->cfg_fcp2_no_tgt_reset && |
| 6583 | (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE)) |
| 6584 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 6585 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE && |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 6586 | ndlp->nlp_sid == i && |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 6587 | ndlp->rport && |
| 6588 | ndlp->nlp_type & NLP_FCP_TARGET) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6589 | match = 1; |
| 6590 | break; |
| 6591 | } |
| 6592 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6593 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6594 | if (!match) |
| 6595 | continue; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6596 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 6597 | status = lpfc_send_taskmgmt(vport, cmnd, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6598 | i, 0, FCP_TARGET_RESET); |
| 6599 | |
| 6600 | if (status != SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6601 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6602 | "0700 Bus Reset on target %d failed\n", |
| 6603 | i); |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 6604 | ret = FAILED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6605 | } |
| 6606 | } |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 6607 | /* |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6608 | * We have to clean up i/o as : they may be orphaned by the TMFs |
| 6609 | * above; or if any of the TMFs failed, they may be in an |
| 6610 | * indeterminate state. |
| 6611 | * 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] | 6612 | */ |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6613 | |
| 6614 | status = lpfc_reset_flush_io_context(vport, 0, 0, LPFC_CTX_HOST); |
| 6615 | if (status != SUCCESS) |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 6616 | ret = FAILED; |
James Smart | da09ae4 | 2021-01-04 10:02:33 -0800 | [diff] [blame] | 6617 | if (ret == FAILED) |
| 6618 | logit = LOG_TRACE_EVENT; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6619 | |
James Smart | da09ae4 | 2021-01-04 10:02:33 -0800 | [diff] [blame] | 6620 | lpfc_printf_vlog(vport, KERN_ERR, logit, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6621 | "0714 SCSI layer issued Bus Reset Data: x%x\n", ret); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6622 | return ret; |
| 6623 | } |
| 6624 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 6625 | /** |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 6626 | * lpfc_host_reset_handler - scsi_host_template eh_host_reset_handler entry pt |
| 6627 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 6628 | * |
| 6629 | * This routine does host reset to the adaptor port. It brings the HBA |
| 6630 | * offline, performs a board restart, and then brings the board back online. |
| 6631 | * The lpfc_offline calls lpfc_sli_hba_down which will abort and local |
| 6632 | * reject all outstanding SCSI commands to the host and error returned |
| 6633 | * back to SCSI mid-level. As this will be SCSI mid-level's last resort |
| 6634 | * of error handling, it will only return error if resetting of the adapter |
| 6635 | * is not successful; in all other cases, will return success. |
| 6636 | * |
| 6637 | * Return code : |
| 6638 | * 0x2003 - Error |
| 6639 | * 0x2002 - Success |
| 6640 | **/ |
| 6641 | static int |
| 6642 | lpfc_host_reset_handler(struct scsi_cmnd *cmnd) |
| 6643 | { |
| 6644 | struct Scsi_Host *shost = cmnd->device->host; |
| 6645 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 6646 | struct lpfc_hba *phba = vport->phba; |
| 6647 | int rc, ret = SUCCESS; |
| 6648 | |
James Smart | da09ae4 | 2021-01-04 10:02:33 -0800 | [diff] [blame] | 6649 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 6650 | "3172 SCSI layer issued Host Reset Data:\n"); |
| 6651 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 6652 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 6653 | lpfc_offline(phba); |
| 6654 | rc = lpfc_sli_brdrestart(phba); |
| 6655 | if (rc) |
James Smart | 8c24a4f | 2019-08-14 16:56:53 -0700 | [diff] [blame] | 6656 | goto error; |
| 6657 | |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 6658 | rc = lpfc_online(phba); |
| 6659 | if (rc) |
James Smart | 8c24a4f | 2019-08-14 16:56:53 -0700 | [diff] [blame] | 6660 | goto error; |
| 6661 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 6662 | lpfc_unblock_mgmt_io(phba); |
| 6663 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 6664 | return ret; |
James Smart | 8c24a4f | 2019-08-14 16:56:53 -0700 | [diff] [blame] | 6665 | error: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6666 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 8c24a4f | 2019-08-14 16:56:53 -0700 | [diff] [blame] | 6667 | "3323 Failed host reset\n"); |
| 6668 | lpfc_unblock_mgmt_io(phba); |
| 6669 | return FAILED; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 6670 | } |
| 6671 | |
| 6672 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6673 | * lpfc_slave_alloc - scsi_host_template slave_alloc entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 6674 | * @sdev: Pointer to scsi_device. |
| 6675 | * |
| 6676 | * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's |
| 6677 | * globally available list of scsi buffers. This routine also makes sure scsi |
| 6678 | * buffer is not allocated more than HBA limit conveyed to midlayer. This list |
| 6679 | * of scsi buffer exists for the lifetime of the driver. |
| 6680 | * |
| 6681 | * Return codes: |
| 6682 | * non-0 - Error |
| 6683 | * 0 - Success |
| 6684 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6685 | static int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6686 | lpfc_slave_alloc(struct scsi_device *sdev) |
| 6687 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6688 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 6689 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 6690 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6691 | uint32_t total = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6692 | uint32_t num_to_alloc = 0; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6693 | int num_allocated = 0; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 6694 | uint32_t sdev_cnt; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6695 | struct lpfc_device_data *device_data; |
| 6696 | unsigned long flags; |
| 6697 | struct lpfc_name target_wwpn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6698 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 6699 | if (!rport || fc_remote_port_chkready(rport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6700 | return -ENXIO; |
| 6701 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 6702 | if (phba->cfg_fof) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6703 | |
| 6704 | /* |
| 6705 | * Check to see if the device data structure for the lun |
| 6706 | * exists. If not, create one. |
| 6707 | */ |
| 6708 | |
| 6709 | u64_to_wwn(rport->port_name, target_wwpn.u.wwn); |
| 6710 | spin_lock_irqsave(&phba->devicelock, flags); |
| 6711 | device_data = __lpfc_get_device_data(phba, |
| 6712 | &phba->luns, |
| 6713 | &vport->fc_portname, |
| 6714 | &target_wwpn, |
| 6715 | sdev->lun); |
| 6716 | if (!device_data) { |
| 6717 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 6718 | device_data = lpfc_create_device_data(phba, |
| 6719 | &vport->fc_portname, |
| 6720 | &target_wwpn, |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 6721 | sdev->lun, |
| 6722 | phba->cfg_XLanePriority, |
| 6723 | true); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6724 | if (!device_data) |
| 6725 | return -ENOMEM; |
| 6726 | spin_lock_irqsave(&phba->devicelock, flags); |
| 6727 | list_add_tail(&device_data->listentry, &phba->luns); |
| 6728 | } |
| 6729 | device_data->rport_data = rport->dd_data; |
| 6730 | device_data->available = true; |
| 6731 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 6732 | sdev->hostdata = device_data; |
| 6733 | } else { |
| 6734 | sdev->hostdata = rport->dd_data; |
| 6735 | } |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 6736 | sdev_cnt = atomic_inc_return(&phba->sdev_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6737 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6738 | /* For SLI4, all IO buffers are pre-allocated */ |
| 6739 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6740 | return 0; |
| 6741 | |
| 6742 | /* This code path is now ONLY for SLI3 adapters */ |
| 6743 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6744 | /* |
| 6745 | * Populate the cmds_per_lun count scsi_bufs into this host's globally |
| 6746 | * 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] | 6747 | * HBA limit conveyed to the midlayer via the host structure. The |
| 6748 | * formula accounts for the lun_queue_depth + error handlers + 1 |
| 6749 | * extra. This list of scsi bufs exists for the lifetime of the driver. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6750 | */ |
| 6751 | total = phba->total_scsi_bufs; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6752 | num_to_alloc = vport->cfg_lun_queue_depth + 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6753 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 6754 | /* If allocated buffers are enough do nothing */ |
| 6755 | if ((sdev_cnt * (vport->cfg_lun_queue_depth + 2)) < total) |
| 6756 | return 0; |
| 6757 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6758 | /* Allow some exchanges to be available always to complete discovery */ |
| 6759 | if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6760 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 6761 | "0704 At limitation of %d preallocated " |
| 6762 | "command buffers\n", total); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6763 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6764 | /* Allow some exchanges to be available always to complete discovery */ |
| 6765 | } else if (total + num_to_alloc > |
| 6766 | phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6767 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 6768 | "0705 Allocation request of %d " |
| 6769 | "command buffers will exceed max of %d. " |
| 6770 | "Reducing allocation request to %d.\n", |
| 6771 | num_to_alloc, phba->cfg_hba_queue_depth, |
| 6772 | (phba->cfg_hba_queue_depth - total)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6773 | num_to_alloc = phba->cfg_hba_queue_depth - total; |
| 6774 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6775 | num_allocated = lpfc_new_scsi_buf_s3(vport, num_to_alloc); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6776 | if (num_to_alloc != num_allocated) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6777 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6778 | "0708 Allocation request of %d " |
| 6779 | "command buffers did not succeed. " |
| 6780 | "Allocated %d buffers.\n", |
| 6781 | num_to_alloc, num_allocated); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6782 | } |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 6783 | if (num_allocated > 0) |
| 6784 | phba->total_scsi_bufs += num_allocated; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6785 | return 0; |
| 6786 | } |
| 6787 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 6788 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6789 | * lpfc_slave_configure - scsi_host_template slave_configure entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 6790 | * @sdev: Pointer to scsi_device. |
| 6791 | * |
| 6792 | * This routine configures following items |
| 6793 | * - Tag command queuing support for @sdev if supported. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 6794 | * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set. |
| 6795 | * |
| 6796 | * Return codes: |
| 6797 | * 0 - Success |
| 6798 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6799 | static int |
| 6800 | lpfc_slave_configure(struct scsi_device *sdev) |
| 6801 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6802 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 6803 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6804 | |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 6805 | scsi_change_queue_depth(sdev, vport->cfg_lun_queue_depth); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6806 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 6807 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 6808 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6809 | &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 6810 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 6811 | lpfc_poll_rearm_timer(phba); |
| 6812 | } |
| 6813 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6814 | return 0; |
| 6815 | } |
| 6816 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 6817 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6818 | * lpfc_slave_destroy - slave_destroy entry point of SHT data structure |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 6819 | * @sdev: Pointer to scsi_device. |
| 6820 | * |
| 6821 | * This routine sets @sdev hostatdata filed to null. |
| 6822 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6823 | static void |
| 6824 | lpfc_slave_destroy(struct scsi_device *sdev) |
| 6825 | { |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 6826 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 6827 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6828 | unsigned long flags; |
| 6829 | struct lpfc_device_data *device_data = sdev->hostdata; |
| 6830 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 6831 | atomic_dec(&phba->sdev_cnt); |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 6832 | if ((phba->cfg_fof) && (device_data)) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6833 | spin_lock_irqsave(&phba->devicelock, flags); |
| 6834 | device_data->available = false; |
| 6835 | if (!device_data->oas_enabled) |
| 6836 | lpfc_delete_device_data(phba, device_data); |
| 6837 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 6838 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6839 | sdev->hostdata = NULL; |
| 6840 | return; |
| 6841 | } |
| 6842 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6843 | /** |
| 6844 | * lpfc_create_device_data - creates and initializes device data structure for OAS |
Lee Jones | eceee00 | 2020-11-02 14:23:43 +0000 | [diff] [blame] | 6845 | * @phba: Pointer to host bus adapter structure. |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6846 | * @vport_wwpn: Pointer to vport's wwpn information |
| 6847 | * @target_wwpn: Pointer to target's wwpn information |
| 6848 | * @lun: Lun on target |
Lee Jones | eceee00 | 2020-11-02 14:23:43 +0000 | [diff] [blame] | 6849 | * @pri: Priority |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6850 | * @atomic_create: Flag to indicate if memory should be allocated using the |
| 6851 | * GFP_ATOMIC flag or not. |
| 6852 | * |
| 6853 | * This routine creates a device data structure which will contain identifying |
| 6854 | * information for the device (host wwpn, target wwpn, lun), state of OAS, |
| 6855 | * whether or not the corresponding lun is available by the system, |
| 6856 | * and pointer to the rport data. |
| 6857 | * |
| 6858 | * Return codes: |
| 6859 | * NULL - Error |
| 6860 | * Pointer to lpfc_device_data - Success |
| 6861 | **/ |
| 6862 | struct lpfc_device_data* |
| 6863 | lpfc_create_device_data(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn, |
| 6864 | struct lpfc_name *target_wwpn, uint64_t lun, |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 6865 | uint32_t pri, bool atomic_create) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6866 | { |
| 6867 | |
| 6868 | struct lpfc_device_data *lun_info; |
| 6869 | int memory_flags; |
| 6870 | |
| 6871 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 6872 | !(phba->cfg_fof)) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6873 | return NULL; |
| 6874 | |
| 6875 | /* Attempt to create the device data to contain lun info */ |
| 6876 | |
| 6877 | if (atomic_create) |
| 6878 | memory_flags = GFP_ATOMIC; |
| 6879 | else |
| 6880 | memory_flags = GFP_KERNEL; |
| 6881 | lun_info = mempool_alloc(phba->device_data_mem_pool, memory_flags); |
| 6882 | if (!lun_info) |
| 6883 | return NULL; |
| 6884 | INIT_LIST_HEAD(&lun_info->listentry); |
| 6885 | lun_info->rport_data = NULL; |
| 6886 | memcpy(&lun_info->device_id.vport_wwpn, vport_wwpn, |
| 6887 | sizeof(struct lpfc_name)); |
| 6888 | memcpy(&lun_info->device_id.target_wwpn, target_wwpn, |
| 6889 | sizeof(struct lpfc_name)); |
| 6890 | lun_info->device_id.lun = lun; |
| 6891 | lun_info->oas_enabled = false; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 6892 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6893 | lun_info->available = false; |
| 6894 | return lun_info; |
| 6895 | } |
| 6896 | |
| 6897 | /** |
| 6898 | * lpfc_delete_device_data - frees a device data structure for OAS |
Lee Jones | eceee00 | 2020-11-02 14:23:43 +0000 | [diff] [blame] | 6899 | * @phba: Pointer to host bus adapter structure. |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6900 | * @lun_info: Pointer to device data structure to free. |
| 6901 | * |
| 6902 | * This routine frees the previously allocated device data structure passed. |
| 6903 | * |
| 6904 | **/ |
| 6905 | void |
| 6906 | lpfc_delete_device_data(struct lpfc_hba *phba, |
| 6907 | struct lpfc_device_data *lun_info) |
| 6908 | { |
| 6909 | |
| 6910 | if (unlikely(!phba) || !lun_info || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 6911 | !(phba->cfg_fof)) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6912 | return; |
| 6913 | |
| 6914 | if (!list_empty(&lun_info->listentry)) |
| 6915 | list_del(&lun_info->listentry); |
| 6916 | mempool_free(lun_info, phba->device_data_mem_pool); |
| 6917 | return; |
| 6918 | } |
| 6919 | |
| 6920 | /** |
| 6921 | * __lpfc_get_device_data - returns the device data for the specified lun |
Lee Jones | eceee00 | 2020-11-02 14:23:43 +0000 | [diff] [blame] | 6922 | * @phba: Pointer to host bus adapter structure. |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6923 | * @list: Point to list to search. |
| 6924 | * @vport_wwpn: Pointer to vport's wwpn information |
| 6925 | * @target_wwpn: Pointer to target's wwpn information |
| 6926 | * @lun: Lun on target |
| 6927 | * |
| 6928 | * This routine searches the list passed for the specified lun's device data. |
| 6929 | * This function does not hold locks, it is the responsibility of the caller |
| 6930 | * to ensure the proper lock is held before calling the function. |
| 6931 | * |
| 6932 | * Return codes: |
| 6933 | * NULL - Error |
| 6934 | * Pointer to lpfc_device_data - Success |
| 6935 | **/ |
| 6936 | struct lpfc_device_data* |
| 6937 | __lpfc_get_device_data(struct lpfc_hba *phba, struct list_head *list, |
| 6938 | struct lpfc_name *vport_wwpn, |
| 6939 | struct lpfc_name *target_wwpn, uint64_t lun) |
| 6940 | { |
| 6941 | |
| 6942 | struct lpfc_device_data *lun_info; |
| 6943 | |
| 6944 | if (unlikely(!phba) || !list || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 6945 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6946 | return NULL; |
| 6947 | |
| 6948 | /* Check to see if the lun is already enabled for OAS. */ |
| 6949 | |
| 6950 | list_for_each_entry(lun_info, list, listentry) { |
| 6951 | if ((memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn, |
| 6952 | sizeof(struct lpfc_name)) == 0) && |
| 6953 | (memcmp(&lun_info->device_id.target_wwpn, target_wwpn, |
| 6954 | sizeof(struct lpfc_name)) == 0) && |
| 6955 | (lun_info->device_id.lun == lun)) |
| 6956 | return lun_info; |
| 6957 | } |
| 6958 | |
| 6959 | return NULL; |
| 6960 | } |
| 6961 | |
| 6962 | /** |
| 6963 | * lpfc_find_next_oas_lun - searches for the next oas lun |
Lee Jones | eceee00 | 2020-11-02 14:23:43 +0000 | [diff] [blame] | 6964 | * @phba: Pointer to host bus adapter structure. |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6965 | * @vport_wwpn: Pointer to vport's wwpn information |
| 6966 | * @target_wwpn: Pointer to target's wwpn information |
| 6967 | * @starting_lun: Pointer to the lun to start searching for |
| 6968 | * @found_vport_wwpn: Pointer to the found lun's vport wwpn information |
| 6969 | * @found_target_wwpn: Pointer to the found lun's target wwpn information |
| 6970 | * @found_lun: Pointer to the found lun. |
| 6971 | * @found_lun_status: Pointer to status of the found lun. |
Lee Jones | eceee00 | 2020-11-02 14:23:43 +0000 | [diff] [blame] | 6972 | * @found_lun_pri: Pointer to priority of the found lun. |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6973 | * |
| 6974 | * This routine searches the luns list for the specified lun |
| 6975 | * or the first lun for the vport/target. If the vport wwpn contains |
| 6976 | * a zero value then a specific vport is not specified. In this case |
| 6977 | * any vport which contains the lun will be considered a match. If the |
| 6978 | * target wwpn contains a zero value then a specific target is not specified. |
| 6979 | * In this case any target which contains the lun will be considered a |
| 6980 | * match. If the lun is found, the lun, vport wwpn, target wwpn and lun status |
| 6981 | * are returned. The function will also return the next lun if available. |
| 6982 | * If the next lun is not found, starting_lun parameter will be set to |
| 6983 | * NO_MORE_OAS_LUN. |
| 6984 | * |
| 6985 | * Return codes: |
| 6986 | * non-0 - Error |
| 6987 | * 0 - Success |
| 6988 | **/ |
| 6989 | bool |
| 6990 | lpfc_find_next_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn, |
| 6991 | struct lpfc_name *target_wwpn, uint64_t *starting_lun, |
| 6992 | struct lpfc_name *found_vport_wwpn, |
| 6993 | struct lpfc_name *found_target_wwpn, |
| 6994 | uint64_t *found_lun, |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 6995 | uint32_t *found_lun_status, |
| 6996 | uint32_t *found_lun_pri) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6997 | { |
| 6998 | |
| 6999 | unsigned long flags; |
| 7000 | struct lpfc_device_data *lun_info; |
| 7001 | struct lpfc_device_id *device_id; |
| 7002 | uint64_t lun; |
| 7003 | bool found = false; |
| 7004 | |
| 7005 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
| 7006 | !starting_lun || !found_vport_wwpn || |
| 7007 | !found_target_wwpn || !found_lun || !found_lun_status || |
| 7008 | (*starting_lun == NO_MORE_OAS_LUN) || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 7009 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7010 | return false; |
| 7011 | |
| 7012 | lun = *starting_lun; |
| 7013 | *found_lun = NO_MORE_OAS_LUN; |
| 7014 | *starting_lun = NO_MORE_OAS_LUN; |
| 7015 | |
| 7016 | /* Search for lun or the lun closet in value */ |
| 7017 | |
| 7018 | spin_lock_irqsave(&phba->devicelock, flags); |
| 7019 | list_for_each_entry(lun_info, &phba->luns, listentry) { |
| 7020 | if (((wwn_to_u64(vport_wwpn->u.wwn) == 0) || |
| 7021 | (memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn, |
| 7022 | sizeof(struct lpfc_name)) == 0)) && |
| 7023 | ((wwn_to_u64(target_wwpn->u.wwn) == 0) || |
| 7024 | (memcmp(&lun_info->device_id.target_wwpn, target_wwpn, |
| 7025 | sizeof(struct lpfc_name)) == 0)) && |
| 7026 | (lun_info->oas_enabled)) { |
| 7027 | device_id = &lun_info->device_id; |
| 7028 | if ((!found) && |
| 7029 | ((lun == FIND_FIRST_OAS_LUN) || |
| 7030 | (device_id->lun == lun))) { |
| 7031 | *found_lun = device_id->lun; |
| 7032 | memcpy(found_vport_wwpn, |
| 7033 | &device_id->vport_wwpn, |
| 7034 | sizeof(struct lpfc_name)); |
| 7035 | memcpy(found_target_wwpn, |
| 7036 | &device_id->target_wwpn, |
| 7037 | sizeof(struct lpfc_name)); |
| 7038 | if (lun_info->available) |
| 7039 | *found_lun_status = |
| 7040 | OAS_LUN_STATUS_EXISTS; |
| 7041 | else |
| 7042 | *found_lun_status = 0; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 7043 | *found_lun_pri = lun_info->priority; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7044 | if (phba->cfg_oas_flags & OAS_FIND_ANY_VPORT) |
| 7045 | memset(vport_wwpn, 0x0, |
| 7046 | sizeof(struct lpfc_name)); |
| 7047 | if (phba->cfg_oas_flags & OAS_FIND_ANY_TARGET) |
| 7048 | memset(target_wwpn, 0x0, |
| 7049 | sizeof(struct lpfc_name)); |
| 7050 | found = true; |
| 7051 | } else if (found) { |
| 7052 | *starting_lun = device_id->lun; |
| 7053 | memcpy(vport_wwpn, &device_id->vport_wwpn, |
| 7054 | sizeof(struct lpfc_name)); |
| 7055 | memcpy(target_wwpn, &device_id->target_wwpn, |
| 7056 | sizeof(struct lpfc_name)); |
| 7057 | break; |
| 7058 | } |
| 7059 | } |
| 7060 | } |
| 7061 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 7062 | return found; |
| 7063 | } |
| 7064 | |
| 7065 | /** |
| 7066 | * lpfc_enable_oas_lun - enables a lun for OAS operations |
Lee Jones | eceee00 | 2020-11-02 14:23:43 +0000 | [diff] [blame] | 7067 | * @phba: Pointer to host bus adapter structure. |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7068 | * @vport_wwpn: Pointer to vport's wwpn information |
| 7069 | * @target_wwpn: Pointer to target's wwpn information |
| 7070 | * @lun: Lun |
Lee Jones | eceee00 | 2020-11-02 14:23:43 +0000 | [diff] [blame] | 7071 | * @pri: Priority |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7072 | * |
| 7073 | * This routine enables a lun for oas operations. The routines does so by |
| 7074 | * doing the following : |
| 7075 | * |
| 7076 | * 1) Checks to see if the device data for the lun has been created. |
| 7077 | * 2) If found, sets the OAS enabled flag if not set and returns. |
| 7078 | * 3) Otherwise, creates a device data structure. |
| 7079 | * 4) If successfully created, indicates the device data is for an OAS lun, |
| 7080 | * indicates the lun is not available and add to the list of luns. |
| 7081 | * |
| 7082 | * Return codes: |
| 7083 | * false - Error |
| 7084 | * true - Success |
| 7085 | **/ |
| 7086 | bool |
| 7087 | 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] | 7088 | struct lpfc_name *target_wwpn, uint64_t lun, uint8_t pri) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7089 | { |
| 7090 | |
| 7091 | struct lpfc_device_data *lun_info; |
| 7092 | unsigned long flags; |
| 7093 | |
| 7094 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 7095 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7096 | return false; |
| 7097 | |
| 7098 | spin_lock_irqsave(&phba->devicelock, flags); |
| 7099 | |
| 7100 | /* Check to see if the device data for the lun has been created */ |
| 7101 | lun_info = __lpfc_get_device_data(phba, &phba->luns, vport_wwpn, |
| 7102 | target_wwpn, lun); |
| 7103 | if (lun_info) { |
| 7104 | if (!lun_info->oas_enabled) |
| 7105 | lun_info->oas_enabled = true; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 7106 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7107 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 7108 | return true; |
| 7109 | } |
| 7110 | |
| 7111 | /* Create an lun info structure and add to list of luns */ |
| 7112 | lun_info = lpfc_create_device_data(phba, vport_wwpn, target_wwpn, lun, |
James Smart | 2d71dc8 | 2019-05-21 17:48:51 -0700 | [diff] [blame] | 7113 | pri, true); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7114 | if (lun_info) { |
| 7115 | lun_info->oas_enabled = true; |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 7116 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7117 | lun_info->available = false; |
| 7118 | list_add_tail(&lun_info->listentry, &phba->luns); |
| 7119 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 7120 | return true; |
| 7121 | } |
| 7122 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 7123 | return false; |
| 7124 | } |
| 7125 | |
| 7126 | /** |
| 7127 | * lpfc_disable_oas_lun - disables a lun for OAS operations |
Lee Jones | eceee00 | 2020-11-02 14:23:43 +0000 | [diff] [blame] | 7128 | * @phba: Pointer to host bus adapter structure. |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7129 | * @vport_wwpn: Pointer to vport's wwpn information |
| 7130 | * @target_wwpn: Pointer to target's wwpn information |
| 7131 | * @lun: Lun |
Lee Jones | eceee00 | 2020-11-02 14:23:43 +0000 | [diff] [blame] | 7132 | * @pri: Priority |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7133 | * |
| 7134 | * This routine disables a lun for oas operations. The routines does so by |
| 7135 | * doing the following : |
| 7136 | * |
| 7137 | * 1) Checks to see if the device data for the lun is created. |
| 7138 | * 2) If present, clears the flag indicating this lun is for OAS. |
| 7139 | * 3) If the lun is not available by the system, the device data is |
| 7140 | * freed. |
| 7141 | * |
| 7142 | * Return codes: |
| 7143 | * false - Error |
| 7144 | * true - Success |
| 7145 | **/ |
| 7146 | bool |
| 7147 | 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] | 7148 | struct lpfc_name *target_wwpn, uint64_t lun, uint8_t pri) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7149 | { |
| 7150 | |
| 7151 | struct lpfc_device_data *lun_info; |
| 7152 | unsigned long flags; |
| 7153 | |
| 7154 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 7155 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7156 | return false; |
| 7157 | |
| 7158 | spin_lock_irqsave(&phba->devicelock, flags); |
| 7159 | |
| 7160 | /* Check to see if the lun is available. */ |
| 7161 | lun_info = __lpfc_get_device_data(phba, |
| 7162 | &phba->luns, vport_wwpn, |
| 7163 | target_wwpn, lun); |
| 7164 | if (lun_info) { |
| 7165 | lun_info->oas_enabled = false; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 7166 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7167 | if (!lun_info->available) |
| 7168 | lpfc_delete_device_data(phba, lun_info); |
| 7169 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 7170 | return true; |
| 7171 | } |
| 7172 | |
| 7173 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 7174 | return false; |
| 7175 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7176 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7177 | static int |
| 7178 | lpfc_no_command(struct Scsi_Host *shost, struct scsi_cmnd *cmnd) |
| 7179 | { |
| 7180 | return SCSI_MLQUEUE_HOST_BUSY; |
| 7181 | } |
| 7182 | |
| 7183 | static int |
| 7184 | lpfc_no_handler(struct scsi_cmnd *cmnd) |
| 7185 | { |
| 7186 | return FAILED; |
| 7187 | } |
| 7188 | |
| 7189 | static int |
| 7190 | lpfc_no_slave(struct scsi_device *sdev) |
| 7191 | { |
| 7192 | return -ENODEV; |
| 7193 | } |
| 7194 | |
| 7195 | struct scsi_host_template lpfc_template_nvme = { |
| 7196 | .module = THIS_MODULE, |
| 7197 | .name = LPFC_DRIVER_NAME, |
| 7198 | .proc_name = LPFC_DRIVER_NAME, |
| 7199 | .info = lpfc_info, |
| 7200 | .queuecommand = lpfc_no_command, |
| 7201 | .eh_abort_handler = lpfc_no_handler, |
| 7202 | .eh_device_reset_handler = lpfc_no_handler, |
| 7203 | .eh_target_reset_handler = lpfc_no_handler, |
| 7204 | .eh_bus_reset_handler = lpfc_no_handler, |
| 7205 | .eh_host_reset_handler = lpfc_no_handler, |
| 7206 | .slave_alloc = lpfc_no_slave, |
| 7207 | .slave_configure = lpfc_no_slave, |
| 7208 | .scan_finished = lpfc_scan_finished, |
| 7209 | .this_id = -1, |
| 7210 | .sg_tablesize = 1, |
| 7211 | .cmd_per_lun = 1, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7212 | .shost_attrs = lpfc_hba_attrs, |
James Smart | 7c30bb6 | 2020-10-20 13:27:16 -0700 | [diff] [blame] | 7213 | .max_sectors = 0xFFFFFFFF, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7214 | .vendor_id = LPFC_NL_VENDOR_ID, |
| 7215 | .track_queue_depth = 0, |
| 7216 | }; |
| 7217 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7218 | struct scsi_host_template lpfc_template = { |
| 7219 | .module = THIS_MODULE, |
| 7220 | .name = LPFC_DRIVER_NAME, |
James Smart | 08dcd4c | 2016-07-06 12:35:59 -0700 | [diff] [blame] | 7221 | .proc_name = LPFC_DRIVER_NAME, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7222 | .info = lpfc_info, |
| 7223 | .queuecommand = lpfc_queuecommand, |
Christoph Hellwig | b6a05c8 | 2017-01-30 13:18:58 +0100 | [diff] [blame] | 7224 | .eh_timed_out = fc_eh_timed_out, |
Muneendra Kumar | 7f3a79a | 2021-01-07 03:19:08 +0530 | [diff] [blame] | 7225 | .eh_should_retry_cmd = fc_eh_should_retry_cmd, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7226 | .eh_abort_handler = lpfc_abort_handler, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 7227 | .eh_device_reset_handler = lpfc_device_reset_handler, |
| 7228 | .eh_target_reset_handler = lpfc_target_reset_handler, |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 7229 | .eh_bus_reset_handler = lpfc_bus_reset_handler, |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 7230 | .eh_host_reset_handler = lpfc_host_reset_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7231 | .slave_alloc = lpfc_slave_alloc, |
| 7232 | .slave_configure = lpfc_slave_configure, |
| 7233 | .slave_destroy = lpfc_slave_destroy, |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 7234 | .scan_finished = lpfc_scan_finished, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7235 | .this_id = -1, |
James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 7236 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7237 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7238 | .shost_attrs = lpfc_hba_attrs, |
James Smart | 7c30bb6 | 2020-10-20 13:27:16 -0700 | [diff] [blame] | 7239 | .max_sectors = 0xFFFFFFFF, |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 7240 | .vendor_id = LPFC_NL_VENDOR_ID, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 7241 | .change_queue_depth = scsi_change_queue_depth, |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 7242 | .track_queue_depth = 1, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7243 | }; |