James Smart | d85296c | 2012-03-01 22:38:13 -0500 | [diff] [blame] | 1 | /******************************************************************* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2 | * This file is part of the Emulex Linux Device Driver for * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3 | * Fibre Channel Host Bus Adapters. * |
James Smart | 128bdda | 2018-01-30 15:59:03 -0800 | [diff] [blame] | 4 | * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term * |
James Smart | 3e21d1c | 2018-05-04 20:37:59 -0700 | [diff] [blame] | 5 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. * |
James Smart | 51f4ca3 | 2016-07-06 12:36:13 -0700 | [diff] [blame] | 6 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * EMULEX and SLI are trademarks of Emulex. * |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 8 | * www.broadcom.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 9 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10 | * * |
| 11 | * This program is free software; you can redistribute it and/or * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 12 | * modify it under the terms of version 2 of the GNU General * |
| 13 | * Public License as published by the Free Software Foundation. * |
| 14 | * This program is distributed in the hope that it will be useful. * |
| 15 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 16 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 18 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 19 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 20 | * more details, a copy of which can be found in the file COPYING * |
| 21 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | *******************************************************************/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 23 | #include <linux/pci.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 24 | #include <linux/slab.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 25 | #include <linux/interrupt.h> |
Paul Gortmaker | 0970366 | 2011-05-27 09:37:25 -0400 | [diff] [blame] | 26 | #include <linux/export.h> |
James Smart | a90f568 | 2006-08-17 11:58:04 -0400 | [diff] [blame] | 27 | #include <linux/delay.h> |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 28 | #include <asm/unaligned.h> |
Dmitry Monakhov | 128b6f9 | 2017-06-29 11:31:12 -0700 | [diff] [blame] | 29 | #include <linux/t10-pi.h> |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 30 | #include <linux/crc-t10dif.h> |
| 31 | #include <net/checksum.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 32 | |
| 33 | #include <scsi/scsi.h> |
| 34 | #include <scsi/scsi_device.h> |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 35 | #include <scsi/scsi_eh.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 36 | #include <scsi/scsi_host.h> |
| 37 | #include <scsi/scsi_tcq.h> |
| 38 | #include <scsi/scsi_transport_fc.h> |
| 39 | |
| 40 | #include "lpfc_version.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 41 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 42 | #include "lpfc_hw.h" |
| 43 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 44 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 45 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 46 | #include "lpfc_disc.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 47 | #include "lpfc.h" |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 48 | #include "lpfc_scsi.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 49 | #include "lpfc_logmsg.h" |
| 50 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 51 | #include "lpfc_vport.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 52 | |
| 53 | #define LPFC_RESET_WAIT 2 |
| 54 | #define LPFC_ABORT_WAIT 2 |
| 55 | |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 56 | int _dump_buf_done = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 57 | |
| 58 | static char *dif_op_str[] = { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 59 | "PROT_NORMAL", |
| 60 | "PROT_READ_INSERT", |
| 61 | "PROT_WRITE_STRIP", |
| 62 | "PROT_READ_STRIP", |
| 63 | "PROT_WRITE_INSERT", |
| 64 | "PROT_READ_PASS", |
| 65 | "PROT_WRITE_PASS", |
| 66 | }; |
| 67 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 68 | struct scsi_dif_tuple { |
| 69 | __be16 guard_tag; /* Checksum */ |
| 70 | __be16 app_tag; /* Opaque storage */ |
| 71 | __be32 ref_tag; /* Target LBA or indirect LBA */ |
| 72 | }; |
| 73 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 74 | static struct lpfc_rport_data * |
| 75 | lpfc_rport_data_from_scsi_device(struct scsi_device *sdev) |
| 76 | { |
| 77 | struct lpfc_vport *vport = (struct lpfc_vport *)sdev->host->hostdata; |
| 78 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 79 | if (vport->phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 80 | return ((struct lpfc_device_data *)sdev->hostdata)->rport_data; |
| 81 | else |
| 82 | return (struct lpfc_rport_data *)sdev->hostdata; |
| 83 | } |
| 84 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 85 | static void |
| 86 | lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 87 | static void |
| 88 | lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb); |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 89 | static int |
| 90 | lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 91 | |
| 92 | static void |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 93 | lpfc_debug_save_data(struct lpfc_hba *phba, struct scsi_cmnd *cmnd) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 94 | { |
| 95 | void *src, *dst; |
| 96 | struct scatterlist *sgde = scsi_sglist(cmnd); |
| 97 | |
| 98 | if (!_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 99 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 100 | "9050 BLKGRD: ERROR %s _dump_buf_data is NULL\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 101 | __func__); |
| 102 | return; |
| 103 | } |
| 104 | |
| 105 | |
| 106 | if (!sgde) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 107 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 108 | "9051 BLKGRD: ERROR: data scatterlist is null\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 109 | return; |
| 110 | } |
| 111 | |
| 112 | dst = (void *) _dump_buf_data; |
| 113 | while (sgde) { |
| 114 | src = sg_virt(sgde); |
| 115 | memcpy(dst, src, sgde->length); |
| 116 | dst += sgde->length; |
| 117 | sgde = sg_next(sgde); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | static void |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 122 | lpfc_debug_save_dif(struct lpfc_hba *phba, struct scsi_cmnd *cmnd) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 123 | { |
| 124 | void *src, *dst; |
| 125 | struct scatterlist *sgde = scsi_prot_sglist(cmnd); |
| 126 | |
| 127 | if (!_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 128 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 129 | "9052 BLKGRD: ERROR %s _dump_buf_data is NULL\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 130 | __func__); |
| 131 | return; |
| 132 | } |
| 133 | |
| 134 | if (!sgde) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 135 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 136 | "9053 BLKGRD: ERROR: prot scatterlist is null\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 137 | return; |
| 138 | } |
| 139 | |
| 140 | dst = _dump_buf_dif; |
| 141 | while (sgde) { |
| 142 | src = sg_virt(sgde); |
| 143 | memcpy(dst, src, sgde->length); |
| 144 | dst += sgde->length; |
| 145 | sgde = sg_next(sgde); |
| 146 | } |
| 147 | } |
| 148 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 149 | static inline unsigned |
| 150 | lpfc_cmd_blksize(struct scsi_cmnd *sc) |
| 151 | { |
| 152 | return sc->device->sector_size; |
| 153 | } |
| 154 | |
| 155 | #define LPFC_CHECK_PROTECT_GUARD 1 |
| 156 | #define LPFC_CHECK_PROTECT_REF 2 |
| 157 | static inline unsigned |
| 158 | lpfc_cmd_protect(struct scsi_cmnd *sc, int flag) |
| 159 | { |
| 160 | return 1; |
| 161 | } |
| 162 | |
| 163 | static inline unsigned |
| 164 | lpfc_cmd_guard_csum(struct scsi_cmnd *sc) |
| 165 | { |
| 166 | if (lpfc_prot_group_type(NULL, sc) == LPFC_PG_TYPE_NO_DIF) |
| 167 | return 0; |
| 168 | if (scsi_host_get_guard(sc->device->host) == SHOST_DIX_GUARD_IP) |
| 169 | return 1; |
| 170 | return 0; |
| 171 | } |
| 172 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 173 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 174 | * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge. |
| 175 | * @phba: Pointer to HBA object. |
| 176 | * @lpfc_cmd: lpfc scsi command object pointer. |
| 177 | * |
| 178 | * This function is called from the lpfc_prep_task_mgmt_cmd function to |
| 179 | * set the last bit in the response sge entry. |
| 180 | **/ |
| 181 | static void |
| 182 | lpfc_sli4_set_rsp_sgl_last(struct lpfc_hba *phba, |
| 183 | struct lpfc_scsi_buf *lpfc_cmd) |
| 184 | { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 185 | struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 186 | if (sgl) { |
| 187 | sgl += 1; |
| 188 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 189 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 190 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 195 | * lpfc_update_stats - Update statistical data for the command completion |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 196 | * @phba: Pointer to HBA object. |
| 197 | * @lpfc_cmd: lpfc scsi command object pointer. |
| 198 | * |
| 199 | * This function is called when there is a command completion and this |
| 200 | * function updates the statistical data for the command completion. |
| 201 | **/ |
| 202 | static void |
| 203 | lpfc_update_stats(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 204 | { |
James Smart | 18027a8 | 2018-09-10 10:30:49 -0700 | [diff] [blame] | 205 | struct lpfc_rport_data *rdata; |
| 206 | struct lpfc_nodelist *pnode; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 207 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 208 | unsigned long flags; |
| 209 | struct Scsi_Host *shost = cmd->device->host; |
| 210 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 211 | unsigned long latency; |
| 212 | int i; |
| 213 | |
James Smart | 18027a8 | 2018-09-10 10:30:49 -0700 | [diff] [blame] | 214 | if (!vport->stat_data_enabled || |
| 215 | vport->stat_data_blocked || |
| 216 | (cmd->result)) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 217 | return; |
| 218 | |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 219 | latency = jiffies_to_msecs((long)jiffies - (long)lpfc_cmd->start_time); |
James Smart | 18027a8 | 2018-09-10 10:30:49 -0700 | [diff] [blame] | 220 | rdata = lpfc_cmd->rdata; |
| 221 | pnode = rdata->pnode; |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 222 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 223 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | 18027a8 | 2018-09-10 10:30:49 -0700 | [diff] [blame] | 224 | if (!pnode || |
| 225 | !pnode->lat_data || |
| 226 | (phba->bucket_type == LPFC_NO_BUCKET)) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 227 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 228 | return; |
| 229 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 230 | |
| 231 | if (phba->bucket_type == LPFC_LINEAR_BUCKET) { |
| 232 | i = (latency + phba->bucket_step - 1 - phba->bucket_base)/ |
| 233 | phba->bucket_step; |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 234 | /* check array subscript bounds */ |
| 235 | if (i < 0) |
| 236 | i = 0; |
| 237 | else if (i >= LPFC_MAX_BUCKET_COUNT) |
| 238 | i = LPFC_MAX_BUCKET_COUNT - 1; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 239 | } else { |
| 240 | for (i = 0; i < LPFC_MAX_BUCKET_COUNT-1; i++) |
| 241 | if (latency <= (phba->bucket_base + |
| 242 | ((1<<i)*phba->bucket_step))) |
| 243 | break; |
| 244 | } |
| 245 | |
| 246 | pnode->lat_data[i].cmd_count++; |
| 247 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 248 | } |
| 249 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 250 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 251 | * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 252 | * @phba: The Hba for which this call is being executed. |
| 253 | * |
| 254 | * This routine is called when there is resource error in driver or firmware. |
| 255 | * This routine posts WORKER_RAMP_DOWN_QUEUE event for @phba. This routine |
| 256 | * posts at most 1 event each second. This routine wakes up worker thread of |
| 257 | * @phba to process WORKER_RAM_DOWN_EVENT event. |
| 258 | * |
| 259 | * This routine should be called with no lock held. |
| 260 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 261 | void |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 262 | lpfc_rampdown_queue_depth(struct lpfc_hba *phba) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 263 | { |
| 264 | unsigned long flags; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 265 | uint32_t evt_posted; |
Manuel Schölling | 0d4aec1 | 2014-09-03 12:55:58 -0400 | [diff] [blame] | 266 | unsigned long expires; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 267 | |
| 268 | spin_lock_irqsave(&phba->hbalock, flags); |
| 269 | atomic_inc(&phba->num_rsrc_err); |
| 270 | phba->last_rsrc_error_time = jiffies; |
| 271 | |
Manuel Schölling | 0d4aec1 | 2014-09-03 12:55:58 -0400 | [diff] [blame] | 272 | expires = phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL; |
| 273 | if (time_after(expires, jiffies)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 274 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 275 | return; |
| 276 | } |
| 277 | |
| 278 | phba->last_ramp_down_time = jiffies; |
| 279 | |
| 280 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 281 | |
| 282 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 283 | evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE; |
| 284 | if (!evt_posted) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 285 | phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 286 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
| 287 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 288 | if (!evt_posted) |
| 289 | lpfc_worker_wake_up(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 290 | return; |
| 291 | } |
| 292 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 293 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 294 | * lpfc_ramp_down_queue_handler - WORKER_RAMP_DOWN_QUEUE event handler |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 295 | * @phba: The Hba for which this call is being executed. |
| 296 | * |
| 297 | * This routine is called to process WORKER_RAMP_DOWN_QUEUE event for worker |
| 298 | * thread.This routine reduces queue depth for all scsi device on each vport |
| 299 | * associated with @phba. |
| 300 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 301 | void |
| 302 | lpfc_ramp_down_queue_handler(struct lpfc_hba *phba) |
| 303 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 304 | struct lpfc_vport **vports; |
| 305 | struct Scsi_Host *shost; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 306 | struct scsi_device *sdev; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 307 | unsigned long new_queue_depth; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 308 | unsigned long num_rsrc_err, num_cmd_success; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 309 | int i; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 310 | |
| 311 | num_rsrc_err = atomic_read(&phba->num_rsrc_err); |
| 312 | num_cmd_success = atomic_read(&phba->num_cmd_success); |
| 313 | |
James Smart | 75ad83a | 2012-05-09 21:18:40 -0400 | [diff] [blame] | 314 | /* |
| 315 | * The error and success command counters are global per |
| 316 | * driver instance. If another handler has already |
| 317 | * operated on this error event, just exit. |
| 318 | */ |
| 319 | if (num_rsrc_err == 0) |
| 320 | return; |
| 321 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 322 | vports = lpfc_create_vport_work_array(phba); |
| 323 | if (vports != NULL) |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 324 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 325 | shost = lpfc_shost_from_vport(vports[i]); |
| 326 | shost_for_each_device(sdev, shost) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 327 | new_queue_depth = |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 328 | sdev->queue_depth * num_rsrc_err / |
| 329 | (num_rsrc_err + num_cmd_success); |
| 330 | if (!new_queue_depth) |
| 331 | new_queue_depth = sdev->queue_depth - 1; |
| 332 | else |
| 333 | new_queue_depth = sdev->queue_depth - |
| 334 | new_queue_depth; |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 335 | scsi_change_queue_depth(sdev, new_queue_depth); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 336 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 337 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 338 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 339 | atomic_set(&phba->num_rsrc_err, 0); |
| 340 | atomic_set(&phba->num_cmd_success, 0); |
| 341 | } |
| 342 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 343 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 344 | * lpfc_scsi_dev_block - set all scsi hosts to block state |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 345 | * @phba: Pointer to HBA context object. |
| 346 | * |
| 347 | * This function walks vport list and set each SCSI host to block state |
| 348 | * by invoking fc_remote_port_delete() routine. This function is invoked |
| 349 | * with EEH when device's PCI slot has been permanently disabled. |
| 350 | **/ |
| 351 | void |
| 352 | lpfc_scsi_dev_block(struct lpfc_hba *phba) |
| 353 | { |
| 354 | struct lpfc_vport **vports; |
| 355 | struct Scsi_Host *shost; |
| 356 | struct scsi_device *sdev; |
| 357 | struct fc_rport *rport; |
| 358 | int i; |
| 359 | |
| 360 | vports = lpfc_create_vport_work_array(phba); |
| 361 | if (vports != NULL) |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 362 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 363 | shost = lpfc_shost_from_vport(vports[i]); |
| 364 | shost_for_each_device(sdev, shost) { |
| 365 | rport = starget_to_rport(scsi_target(sdev)); |
| 366 | fc_remote_port_delete(rport); |
| 367 | } |
| 368 | } |
| 369 | lpfc_destroy_vport_work_array(phba, vports); |
| 370 | } |
| 371 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 372 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 373 | * lpfc_new_scsi_buf_s3 - Scsi buffer allocator for HBA with SLI3 IF spec |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 374 | * @vport: The virtual port for which this call being executed. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 375 | * @num_to_allocate: The requested number of buffers to allocate. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 376 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 377 | * This routine allocates a scsi buffer for device with SLI-3 interface spec, |
| 378 | * the scsi buffer contains all the necessary information needed to initiate |
| 379 | * a SCSI I/O. The non-DMAable buffer region contains information to build |
| 380 | * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP, |
| 381 | * and the initial BPL. In addition to allocating memory, the FCP CMND and |
| 382 | * FCP RSP BDEs are setup in the BPL and the BPL BDE is setup in the IOCB. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 383 | * |
| 384 | * Return codes: |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 385 | * int - number of scsi buffers that were allocated. |
| 386 | * 0 = failure, less than num_to_alloc is a partial failure. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 387 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 388 | static int |
| 389 | lpfc_new_scsi_buf_s3(struct lpfc_vport *vport, int num_to_alloc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 390 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 391 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 392 | struct lpfc_scsi_buf *psb; |
| 393 | struct ulp_bde64 *bpl; |
| 394 | IOCB_t *iocb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 395 | dma_addr_t pdma_phys_fcp_cmd; |
| 396 | dma_addr_t pdma_phys_fcp_rsp; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 397 | dma_addr_t pdma_phys_sgl; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 398 | uint16_t iotag; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 399 | int bcnt, bpl_size; |
| 400 | |
| 401 | bpl_size = phba->cfg_sg_dma_buf_size - |
| 402 | (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); |
| 403 | |
| 404 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 405 | "9067 ALLOC %d scsi_bufs: %d (%d + %d + %d)\n", |
| 406 | num_to_alloc, phba->cfg_sg_dma_buf_size, |
| 407 | (int)sizeof(struct fcp_cmnd), |
| 408 | (int)sizeof(struct fcp_rsp), bpl_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 409 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 410 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
| 411 | psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL); |
| 412 | if (!psb) |
| 413 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 414 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 415 | /* |
| 416 | * Get memory from the pci pool to map the virt space to pci |
| 417 | * bus space for an I/O. The DMA buffer includes space for the |
| 418 | * struct fcp_cmnd, struct fcp_rsp and the number of bde's |
| 419 | * necessary to support the sg_tablesize. |
| 420 | */ |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 421 | psb->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 422 | GFP_KERNEL, &psb->dma_handle); |
| 423 | if (!psb->data) { |
| 424 | kfree(psb); |
| 425 | break; |
| 426 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 427 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 428 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 429 | /* Allocate iotag for psb->cur_iocbq. */ |
| 430 | iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq); |
| 431 | if (iotag == 0) { |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 432 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 433 | psb->data, psb->dma_handle); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 434 | kfree(psb); |
| 435 | break; |
| 436 | } |
| 437 | psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 438 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 439 | psb->fcp_cmnd = psb->data; |
| 440 | psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 441 | psb->dma_sgl = psb->data + sizeof(struct fcp_cmnd) + |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 442 | sizeof(struct fcp_rsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 443 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 444 | /* Initialize local short-hand pointers. */ |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 445 | bpl = psb->dma_sgl; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 446 | pdma_phys_fcp_cmd = psb->dma_handle; |
| 447 | pdma_phys_fcp_rsp = psb->dma_handle + sizeof(struct fcp_cmnd); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 448 | pdma_phys_sgl = psb->dma_handle + sizeof(struct fcp_cmnd) + |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 449 | sizeof(struct fcp_rsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 450 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 451 | /* |
| 452 | * The first two bdes are the FCP_CMD and FCP_RSP. The balance |
| 453 | * are sg list bdes. Initialize the first two and leave the |
| 454 | * rest for queuecommand. |
| 455 | */ |
| 456 | bpl[0].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd)); |
| 457 | bpl[0].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd)); |
| 458 | bpl[0].tus.f.bdeSize = sizeof(struct fcp_cmnd); |
| 459 | bpl[0].tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 460 | bpl[0].tus.w = le32_to_cpu(bpl[0].tus.w); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 461 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 462 | /* Setup the physical region for the FCP RSP */ |
| 463 | bpl[1].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp)); |
| 464 | bpl[1].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp)); |
| 465 | bpl[1].tus.f.bdeSize = sizeof(struct fcp_rsp); |
| 466 | bpl[1].tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 467 | bpl[1].tus.w = le32_to_cpu(bpl[1].tus.w); |
| 468 | |
| 469 | /* |
| 470 | * Since the IOCB for the FCP I/O is built into this |
| 471 | * lpfc_scsi_buf, initialize it with all known data now. |
| 472 | */ |
| 473 | iocb = &psb->cur_iocbq.iocb; |
| 474 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; |
| 475 | if ((phba->sli_rev == 3) && |
| 476 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) { |
| 477 | /* fill in immediate fcp command BDE */ |
| 478 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_IMMED; |
| 479 | iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); |
| 480 | iocb->un.fcpi64.bdl.addrLow = offsetof(IOCB_t, |
| 481 | unsli3.fcp_ext.icd); |
| 482 | iocb->un.fcpi64.bdl.addrHigh = 0; |
| 483 | iocb->ulpBdeCount = 0; |
| 484 | iocb->ulpLe = 0; |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 485 | /* fill in response BDE */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 486 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeFlags = |
| 487 | BUFF_TYPE_BDE_64; |
| 488 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeSize = |
| 489 | sizeof(struct fcp_rsp); |
| 490 | iocb->unsli3.fcp_ext.rbde.addrLow = |
| 491 | putPaddrLow(pdma_phys_fcp_rsp); |
| 492 | iocb->unsli3.fcp_ext.rbde.addrHigh = |
| 493 | putPaddrHigh(pdma_phys_fcp_rsp); |
| 494 | } else { |
| 495 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
| 496 | iocb->un.fcpi64.bdl.bdeSize = |
| 497 | (2 * sizeof(struct ulp_bde64)); |
| 498 | iocb->un.fcpi64.bdl.addrLow = |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 499 | putPaddrLow(pdma_phys_sgl); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 500 | iocb->un.fcpi64.bdl.addrHigh = |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 501 | putPaddrHigh(pdma_phys_sgl); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 502 | iocb->ulpBdeCount = 1; |
| 503 | iocb->ulpLe = 1; |
| 504 | } |
| 505 | iocb->ulpClass = CLASS3; |
| 506 | psb->status = IOSTAT_SUCCESS; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 507 | /* Put it back into the SCSI buffer list */ |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 508 | psb->cur_iocbq.context1 = psb; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 509 | lpfc_release_scsi_buf_s3(phba, psb); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 510 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 511 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 512 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 513 | return bcnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 514 | } |
| 515 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 516 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 517 | * lpfc_sli4_vport_delete_fcp_xri_aborted -Remove all ndlp references for vport |
| 518 | * @vport: pointer to lpfc vport data structure. |
| 519 | * |
| 520 | * This routine is invoked by the vport cleanup for deletions and the cleanup |
| 521 | * for an ndlp on removal. |
| 522 | **/ |
| 523 | void |
| 524 | lpfc_sli4_vport_delete_fcp_xri_aborted(struct lpfc_vport *vport) |
| 525 | { |
| 526 | struct lpfc_hba *phba = vport->phba; |
| 527 | struct lpfc_scsi_buf *psb, *next_psb; |
| 528 | unsigned long iflag = 0; |
| 529 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 530 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 531 | return; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 532 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 533 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 534 | list_for_each_entry_safe(psb, next_psb, |
| 535 | &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) { |
| 536 | if (psb->rdata && psb->rdata->pnode |
| 537 | && psb->rdata->pnode->vport == vport) |
| 538 | psb->rdata = NULL; |
| 539 | } |
| 540 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 541 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 542 | } |
| 543 | |
| 544 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 545 | * lpfc_sli4_fcp_xri_aborted - Fast-path process of fcp xri abort |
| 546 | * @phba: pointer to lpfc hba data structure. |
| 547 | * @axri: pointer to the fcp xri abort wcqe structure. |
| 548 | * |
| 549 | * This routine is invoked by the worker thread to process a SLI4 fast-path |
| 550 | * FCP aborted xri. |
| 551 | **/ |
| 552 | void |
| 553 | lpfc_sli4_fcp_xri_aborted(struct lpfc_hba *phba, |
| 554 | struct sli4_wcqe_xri_aborted *axri) |
| 555 | { |
| 556 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 557 | uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 558 | struct lpfc_scsi_buf *psb, *next_psb; |
| 559 | unsigned long iflag = 0; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 560 | struct lpfc_iocbq *iocbq; |
| 561 | int i; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 562 | struct lpfc_nodelist *ndlp; |
| 563 | int rrq_empty = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 564 | struct lpfc_sli_ring *pring = phba->sli4_hba.els_wq->pring; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 565 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 566 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 567 | return; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 568 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 569 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 570 | list_for_each_entry_safe(psb, next_psb, |
| 571 | &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) { |
| 572 | if (psb->cur_iocbq.sli4_xritag == xri) { |
| 573 | list_del(&psb->list); |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 574 | psb->exch_busy = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 575 | psb->status = IOSTAT_SUCCESS; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 576 | spin_unlock( |
| 577 | &phba->sli4_hba.abts_scsi_buf_list_lock); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 578 | if (psb->rdata && psb->rdata->pnode) |
| 579 | ndlp = psb->rdata->pnode; |
| 580 | else |
| 581 | ndlp = NULL; |
| 582 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 583 | rrq_empty = list_empty(&phba->active_rrq_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 584 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 585 | if (ndlp) { |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 586 | lpfc_set_rrq_active(phba, ndlp, |
| 587 | psb->cur_iocbq.sli4_lxritag, rxid, 1); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 588 | lpfc_sli4_abts_err_handler(phba, ndlp, axri); |
| 589 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 590 | lpfc_release_scsi_buf_s4(phba, psb); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 591 | if (rrq_empty) |
| 592 | lpfc_worker_wake_up(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 593 | return; |
| 594 | } |
| 595 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 596 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 597 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 598 | iocbq = phba->sli.iocbq_lookup[i]; |
| 599 | |
| 600 | if (!(iocbq->iocb_flag & LPFC_IO_FCP) || |
| 601 | (iocbq->iocb_flag & LPFC_IO_LIBDFC)) |
| 602 | continue; |
| 603 | if (iocbq->sli4_xritag != xri) |
| 604 | continue; |
| 605 | psb = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
| 606 | psb->exch_busy = 0; |
| 607 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 608 | if (!list_empty(&pring->txq)) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 609 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 610 | return; |
| 611 | |
| 612 | } |
| 613 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 617 | * 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] | 618 | * @phba: The HBA for which this call is being executed. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 619 | * |
| 620 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list |
| 621 | * and returns to caller. |
| 622 | * |
| 623 | * Return codes: |
| 624 | * NULL - Error |
| 625 | * Pointer to lpfc_scsi_buf - Success |
| 626 | **/ |
Adrian Bunk | 455c53e | 2006-01-06 20:21:28 +0100 | [diff] [blame] | 627 | static struct lpfc_scsi_buf* |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 628 | lpfc_get_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 629 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 630 | struct lpfc_scsi_buf * lpfc_cmd = NULL; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 631 | 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] | 632 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 633 | |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 634 | spin_lock_irqsave(&phba->scsi_buf_list_get_lock, iflag); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 635 | list_remove_head(scsi_buf_list_get, lpfc_cmd, struct lpfc_scsi_buf, |
| 636 | list); |
| 637 | if (!lpfc_cmd) { |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 638 | spin_lock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 639 | list_splice(&phba->lpfc_scsi_buf_list_put, |
| 640 | &phba->lpfc_scsi_buf_list_get); |
| 641 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
| 642 | list_remove_head(scsi_buf_list_get, lpfc_cmd, |
| 643 | struct lpfc_scsi_buf, list); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 644 | spin_unlock(&phba->scsi_buf_list_put_lock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 645 | } |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 646 | spin_unlock_irqrestore(&phba->scsi_buf_list_get_lock, iflag); |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 647 | |
| 648 | if (lpfc_ndlp_check_qdepth(phba, ndlp) && lpfc_cmd) { |
| 649 | atomic_inc(&ndlp->cmd_pending); |
| 650 | lpfc_cmd->flags |= LPFC_SBUF_BUMP_QDEPTH; |
| 651 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 652 | return lpfc_cmd; |
| 653 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 654 | /** |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 655 | * lpfc_get_scsi_buf_s4 - Get a scsi buffer from lpfc_common_buf_list of the HBA |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 656 | * @phba: The HBA for which this call is being executed. |
| 657 | * |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 658 | * This routine removes a scsi buffer from head of @phba lpfc_common_buf_list |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 659 | * and returns to caller. |
| 660 | * |
| 661 | * Return codes: |
| 662 | * NULL - Error |
| 663 | * Pointer to lpfc_scsi_buf - Success |
| 664 | **/ |
| 665 | static struct lpfc_scsi_buf* |
| 666 | lpfc_get_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| 667 | { |
James Smart | 3be30e0 | 2013-05-31 17:05:17 -0400 | [diff] [blame] | 668 | struct lpfc_scsi_buf *lpfc_cmd, *lpfc_cmd_next; |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 669 | unsigned long iflag = 0; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 670 | struct sli4_sge *sgl; |
| 671 | IOCB_t *iocb; |
| 672 | dma_addr_t pdma_phys_fcp_rsp; |
| 673 | dma_addr_t pdma_phys_fcp_cmd; |
| 674 | uint32_t sgl_size; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 675 | int found = 0; |
| 676 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 677 | spin_lock_irqsave(&phba->common_buf_list_get_lock, iflag); |
James Smart | 3be30e0 | 2013-05-31 17:05:17 -0400 | [diff] [blame] | 678 | list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 679 | &phba->lpfc_common_buf_list_get, list) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 680 | if (lpfc_test_rrq_active(phba, ndlp, |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 681 | lpfc_cmd->cur_iocbq.sli4_lxritag)) |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 682 | continue; |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 683 | list_del_init(&lpfc_cmd->list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 684 | phba->get_common_bufs--; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 685 | found = 1; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 686 | break; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 687 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 688 | if (!found) { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 689 | spin_lock(&phba->common_buf_list_put_lock); |
| 690 | list_splice(&phba->lpfc_common_buf_list_put, |
| 691 | &phba->lpfc_common_buf_list_get); |
| 692 | phba->get_common_bufs += phba->put_common_bufs; |
| 693 | INIT_LIST_HEAD(&phba->lpfc_common_buf_list_put); |
| 694 | phba->put_common_bufs = 0; |
| 695 | spin_unlock(&phba->common_buf_list_put_lock); |
James Smart | 3be30e0 | 2013-05-31 17:05:17 -0400 | [diff] [blame] | 696 | list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 697 | &phba->lpfc_common_buf_list_get, |
| 698 | list) { |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 699 | if (lpfc_test_rrq_active( |
| 700 | phba, ndlp, lpfc_cmd->cur_iocbq.sli4_lxritag)) |
| 701 | continue; |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 702 | list_del_init(&lpfc_cmd->list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 703 | phba->get_common_bufs--; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 704 | found = 1; |
| 705 | break; |
| 706 | } |
| 707 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 708 | spin_unlock_irqrestore(&phba->common_buf_list_get_lock, iflag); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 709 | if (!found) |
| 710 | return NULL; |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 711 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 712 | sgl_size = phba->cfg_sg_dma_buf_size - |
| 713 | (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); |
| 714 | |
| 715 | /* Setup key fields in buffer that may have been changed |
| 716 | * if other protocols used this buffer. |
| 717 | */ |
| 718 | lpfc_cmd->cur_iocbq.iocb_flag = LPFC_IO_FCP; |
| 719 | lpfc_cmd->prot_seg_cnt = 0; |
| 720 | lpfc_cmd->seg_cnt = 0; |
| 721 | lpfc_cmd->waitq = NULL; |
| 722 | lpfc_cmd->timeout = 0; |
| 723 | lpfc_cmd->flags = 0; |
| 724 | lpfc_cmd->start_time = jiffies; |
| 725 | lpfc_cmd->waitq = NULL; |
| 726 | lpfc_cmd->cpu = smp_processor_id(); |
| 727 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 728 | lpfc_cmd->prot_data_type = 0; |
| 729 | #endif |
| 730 | |
| 731 | lpfc_cmd->fcp_cmnd = (lpfc_cmd->data + sgl_size); |
| 732 | lpfc_cmd->fcp_rsp = (struct fcp_rsp *)((uint8_t *)lpfc_cmd->fcp_cmnd + |
| 733 | sizeof(struct fcp_cmnd)); |
| 734 | |
| 735 | /* |
| 736 | * The first two SGEs are the FCP_CMD and FCP_RSP. |
| 737 | * The balance are sg list bdes. Initialize the |
| 738 | * first two and leave the rest for queuecommand. |
| 739 | */ |
| 740 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
| 741 | pdma_phys_fcp_cmd = (lpfc_cmd->dma_handle + sgl_size); |
| 742 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd)); |
| 743 | sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd)); |
| 744 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 745 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 746 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 747 | sgl->sge_len = cpu_to_le32(sizeof(struct fcp_cmnd)); |
| 748 | sgl++; |
| 749 | |
| 750 | /* Setup the physical region for the FCP RSP */ |
| 751 | pdma_phys_fcp_rsp = pdma_phys_fcp_cmd + sizeof(struct fcp_cmnd); |
| 752 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp)); |
| 753 | sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp)); |
| 754 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 755 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 756 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 757 | sgl->sge_len = cpu_to_le32(sizeof(struct fcp_rsp)); |
| 758 | |
| 759 | /* |
| 760 | * Since the IOCB for the FCP I/O is built into this |
| 761 | * lpfc_scsi_buf, initialize it with all known data now. |
| 762 | */ |
| 763 | iocb = &lpfc_cmd->cur_iocbq.iocb; |
| 764 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; |
| 765 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_64; |
| 766 | /* setting the BLP size to 2 * sizeof BDE may not be correct. |
| 767 | * We are setting the bpl to point to out sgl. An sgl's |
| 768 | * entries are 16 bytes, a bpl entries are 12 bytes. |
| 769 | */ |
| 770 | iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); |
| 771 | iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys_fcp_cmd); |
| 772 | iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys_fcp_cmd); |
| 773 | iocb->ulpBdeCount = 1; |
| 774 | iocb->ulpLe = 1; |
| 775 | iocb->ulpClass = CLASS3; |
| 776 | |
Dan Carpenter | 26c724a | 2018-08-23 16:56:33 +0300 | [diff] [blame] | 777 | if (lpfc_ndlp_check_qdepth(phba, ndlp)) { |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 778 | atomic_inc(&ndlp->cmd_pending); |
| 779 | lpfc_cmd->flags |= LPFC_SBUF_BUMP_QDEPTH; |
| 780 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 781 | return lpfc_cmd; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 782 | } |
| 783 | /** |
| 784 | * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA |
| 785 | * @phba: The HBA for which this call is being executed. |
| 786 | * |
| 787 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list |
| 788 | * and returns to caller. |
| 789 | * |
| 790 | * Return codes: |
| 791 | * NULL - Error |
| 792 | * Pointer to lpfc_scsi_buf - Success |
| 793 | **/ |
| 794 | static struct lpfc_scsi_buf* |
| 795 | lpfc_get_scsi_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| 796 | { |
| 797 | return phba->lpfc_get_scsi_buf(phba, ndlp); |
| 798 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 799 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 800 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 801 | * lpfc_release_scsi_buf - Return a scsi buffer back to hba scsi buf list |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 802 | * @phba: The Hba for which this call is being executed. |
| 803 | * @psb: The scsi buffer which is being released. |
| 804 | * |
| 805 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
| 806 | * lpfc_scsi_buf_list list. |
| 807 | **/ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 808 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 809 | lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 810 | { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 811 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 812 | |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 813 | psb->seg_cnt = 0; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 814 | psb->prot_seg_cnt = 0; |
| 815 | |
| 816 | spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 817 | psb->pCmd = NULL; |
James Smart | 6a485eb | 2013-04-17 20:19:00 -0400 | [diff] [blame] | 818 | psb->cur_iocbq.iocb_flag = LPFC_IO_FCP; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 819 | list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list_put); |
| 820 | spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 821 | } |
| 822 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 823 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 824 | * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list. |
| 825 | * @phba: The Hba for which this call is being executed. |
| 826 | * @psb: The scsi buffer which is being released. |
| 827 | * |
| 828 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 829 | * lpfc_common_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] | 830 | * and cannot be reused for at least RA_TOV amount of time if it was |
| 831 | * aborted. |
| 832 | **/ |
| 833 | static void |
| 834 | lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) |
| 835 | { |
| 836 | unsigned long iflag = 0; |
| 837 | |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 838 | psb->seg_cnt = 0; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 839 | psb->prot_seg_cnt = 0; |
| 840 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 841 | if (psb->exch_busy) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 842 | spin_lock_irqsave(&phba->sli4_hba.abts_scsi_buf_list_lock, |
| 843 | iflag); |
| 844 | psb->pCmd = NULL; |
| 845 | list_add_tail(&psb->list, |
| 846 | &phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 847 | spin_unlock_irqrestore(&phba->sli4_hba.abts_scsi_buf_list_lock, |
| 848 | iflag); |
| 849 | } else { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 850 | /* MUST zero fields if buffer is reused by another protocol */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 851 | psb->pCmd = NULL; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 852 | psb->cur_iocbq.iocb_cmpl = NULL; |
| 853 | spin_lock_irqsave(&phba->common_buf_list_put_lock, iflag); |
| 854 | list_add_tail(&psb->list, &phba->lpfc_common_buf_list_put); |
| 855 | phba->put_common_bufs++; |
| 856 | spin_unlock_irqrestore(&phba->common_buf_list_put_lock, iflag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 857 | } |
| 858 | } |
| 859 | |
| 860 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 861 | * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list. |
| 862 | * @phba: The Hba for which this call is being executed. |
| 863 | * @psb: The scsi buffer which is being released. |
| 864 | * |
| 865 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
| 866 | * lpfc_scsi_buf_list list. |
| 867 | **/ |
| 868 | static void |
| 869 | lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) |
| 870 | { |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 871 | if ((psb->flags & LPFC_SBUF_BUMP_QDEPTH) && psb->ndlp) |
| 872 | atomic_dec(&psb->ndlp->cmd_pending); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 873 | |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 874 | psb->flags &= ~LPFC_SBUF_BUMP_QDEPTH; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 875 | phba->lpfc_release_scsi_buf(phba, psb); |
| 876 | } |
| 877 | |
| 878 | /** |
| 879 | * 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] | 880 | * @phba: The Hba for which this call is being executed. |
| 881 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 882 | * |
| 883 | * 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] | 884 | * 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] | 885 | * through sg elements and format the bde. This routine also initializes all |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 886 | * IOCB fields which are dependent on scsi command request buffer. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 887 | * |
| 888 | * Return codes: |
| 889 | * 1 - Error |
| 890 | * 0 - Success |
| 891 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 892 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 893 | lpfc_scsi_prep_dma_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 894 | { |
| 895 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 896 | struct scatterlist *sgel = NULL; |
| 897 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 898 | struct ulp_bde64 *bpl = lpfc_cmd->dma_sgl; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 899 | struct lpfc_iocbq *iocbq = &lpfc_cmd->cur_iocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 900 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 901 | struct ulp_bde64 *data_bde = iocb_cmd->unsli3.fcp_ext.dbde; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 902 | dma_addr_t physaddr; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 903 | uint32_t num_bde = 0; |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 904 | int nseg, datadir = scsi_cmnd->sc_data_direction; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 905 | |
| 906 | /* |
| 907 | * There are three possibilities here - use scatter-gather segment, use |
| 908 | * the single mapping, or neither. Start the lpfc command prep by |
| 909 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 910 | * data bde entry. |
| 911 | */ |
| 912 | bpl += 2; |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 913 | if (scsi_sg_count(scsi_cmnd)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 914 | /* |
| 915 | * The driver stores the segment count returned from pci_map_sg |
| 916 | * because this a count of dma-mappings used to map the use_sg |
| 917 | * pages. They are not guaranteed to be the same for those |
| 918 | * architectures that implement an IOMMU. |
| 919 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 920 | |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 921 | nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd), |
| 922 | scsi_sg_count(scsi_cmnd), datadir); |
| 923 | if (unlikely(!nseg)) |
| 924 | return 1; |
| 925 | |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 926 | lpfc_cmd->seg_cnt = nseg; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 927 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 928 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 929 | "9064 BLKGRD: %s: Too many sg segments from " |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 930 | "dma_map_sg. Config %d, seg_cnt %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 931 | __func__, phba->cfg_sg_seg_cnt, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 932 | lpfc_cmd->seg_cnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 933 | lpfc_cmd->seg_cnt = 0; |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 934 | scsi_dma_unmap(scsi_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 935 | return 1; |
| 936 | } |
| 937 | |
| 938 | /* |
| 939 | * The driver established a maximum scatter-gather segment count |
| 940 | * during probe that limits the number of sg elements in any |
| 941 | * single scsi command. Just run through the seg_cnt and format |
| 942 | * the bde's. |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 943 | * When using SLI-3 the driver will try to fit all the BDEs into |
| 944 | * the IOCB. If it can't then the BDEs get added to a BPL as it |
| 945 | * does for SLI-2 mode. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 946 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 947 | scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 948 | physaddr = sg_dma_address(sgel); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 949 | if (phba->sli_rev == 3 && |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 950 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 951 | !(iocbq->iocb_flag & DSS_SECURITY_OP) && |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 952 | nseg <= LPFC_EXT_DATA_BDE_COUNT) { |
| 953 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 954 | data_bde->tus.f.bdeSize = sg_dma_len(sgel); |
| 955 | data_bde->addrLow = putPaddrLow(physaddr); |
| 956 | data_bde->addrHigh = putPaddrHigh(physaddr); |
| 957 | data_bde++; |
| 958 | } else { |
| 959 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 960 | bpl->tus.f.bdeSize = sg_dma_len(sgel); |
| 961 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 962 | bpl->addrLow = |
| 963 | le32_to_cpu(putPaddrLow(physaddr)); |
| 964 | bpl->addrHigh = |
| 965 | le32_to_cpu(putPaddrHigh(physaddr)); |
| 966 | bpl++; |
| 967 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 968 | } |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 969 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 970 | |
| 971 | /* |
| 972 | * Finish initializing those IOCB fields that are dependent on the |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 973 | * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is |
| 974 | * explicitly reinitialized and for SLI-3 the extended bde count is |
| 975 | * explicitly reinitialized since all iocb memory resources are reused. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 976 | */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 977 | if (phba->sli_rev == 3 && |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 978 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
| 979 | !(iocbq->iocb_flag & DSS_SECURITY_OP)) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 980 | if (num_bde > LPFC_EXT_DATA_BDE_COUNT) { |
| 981 | /* |
| 982 | * The extended IOCB format can only fit 3 BDE or a BPL. |
| 983 | * This I/O has more than 3 BDE so the 1st data bde will |
| 984 | * be a BPL that is filled in here. |
| 985 | */ |
| 986 | physaddr = lpfc_cmd->dma_handle; |
| 987 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BLP_64; |
| 988 | data_bde->tus.f.bdeSize = (num_bde * |
| 989 | sizeof(struct ulp_bde64)); |
| 990 | physaddr += (sizeof(struct fcp_cmnd) + |
| 991 | sizeof(struct fcp_rsp) + |
| 992 | (2 * sizeof(struct ulp_bde64))); |
| 993 | data_bde->addrHigh = putPaddrHigh(physaddr); |
| 994 | data_bde->addrLow = putPaddrLow(physaddr); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 995 | /* ebde count includes the response bde and data bpl */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 996 | iocb_cmd->unsli3.fcp_ext.ebde_count = 2; |
| 997 | } else { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 998 | /* ebde count includes the response bde and data bdes */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 999 | iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); |
| 1000 | } |
| 1001 | } else { |
| 1002 | iocb_cmd->un.fcpi64.bdl.bdeSize = |
| 1003 | ((num_bde + 2) * sizeof(struct ulp_bde64)); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1004 | iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1005 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1006 | fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1007 | |
| 1008 | /* |
| 1009 | * Due to difference in data length between DIF/non-DIF paths, |
| 1010 | * we need to set word 4 of IOCB here |
| 1011 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1012 | iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1013 | return 0; |
| 1014 | } |
| 1015 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1016 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1017 | |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1018 | /* Return BG_ERR_INIT if error injection is detected by Initiator */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1019 | #define BG_ERR_INIT 0x1 |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1020 | /* Return BG_ERR_TGT if error injection is detected by Target */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1021 | #define BG_ERR_TGT 0x2 |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1022 | /* 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] | 1023 | #define BG_ERR_SWAP 0x10 |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1024 | /** |
| 1025 | * Return BG_ERR_CHECK if disabling Guard/Ref/App checking is required for |
| 1026 | * error injection |
| 1027 | **/ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1028 | #define BG_ERR_CHECK 0x20 |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1029 | |
| 1030 | /** |
| 1031 | * lpfc_bg_err_inject - Determine if we should inject an error |
| 1032 | * @phba: The Hba for which this call is being executed. |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1033 | * @sc: The SCSI command to examine |
| 1034 | * @reftag: (out) BlockGuard reference tag for transmitted data |
| 1035 | * @apptag: (out) BlockGuard application tag for transmitted data |
| 1036 | * @new_guard (in) Value to replace CRC with if needed |
| 1037 | * |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1038 | * Returns BG_ERR_* bit mask or 0 if request ignored |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1039 | **/ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1040 | static int |
| 1041 | lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1042 | uint32_t *reftag, uint16_t *apptag, uint32_t new_guard) |
| 1043 | { |
| 1044 | struct scatterlist *sgpe; /* s/g prot entry */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1045 | struct lpfc_scsi_buf *lpfc_cmd = NULL; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1046 | struct scsi_dif_tuple *src = NULL; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1047 | struct lpfc_nodelist *ndlp; |
| 1048 | struct lpfc_rport_data *rdata; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1049 | uint32_t op = scsi_get_prot_op(sc); |
| 1050 | uint32_t blksize; |
| 1051 | uint32_t numblks; |
| 1052 | sector_t lba; |
| 1053 | int rc = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1054 | int blockoff = 0; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1055 | |
| 1056 | if (op == SCSI_PROT_NORMAL) |
| 1057 | return 0; |
| 1058 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1059 | sgpe = scsi_prot_sglist(sc); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1060 | lba = scsi_get_lba(sc); |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1061 | |
| 1062 | /* First check if we need to match the LBA */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1063 | if (phba->lpfc_injerr_lba != LPFC_INJERR_LBA_OFF) { |
| 1064 | blksize = lpfc_cmd_blksize(sc); |
| 1065 | numblks = (scsi_bufflen(sc) + blksize - 1) / blksize; |
| 1066 | |
| 1067 | /* Make sure we have the right LBA if one is specified */ |
| 1068 | if ((phba->lpfc_injerr_lba < lba) || |
| 1069 | (phba->lpfc_injerr_lba >= (lba + numblks))) |
| 1070 | return 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1071 | if (sgpe) { |
| 1072 | blockoff = phba->lpfc_injerr_lba - lba; |
| 1073 | numblks = sg_dma_len(sgpe) / |
| 1074 | sizeof(struct scsi_dif_tuple); |
| 1075 | if (numblks < blockoff) |
| 1076 | blockoff = numblks; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1077 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1078 | } |
| 1079 | |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1080 | /* Next check if we need to match the remote NPortID or WWPN */ |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 1081 | rdata = lpfc_rport_data_from_scsi_device(sc->device); |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1082 | if (rdata && rdata->pnode) { |
| 1083 | ndlp = rdata->pnode; |
| 1084 | |
| 1085 | /* Make sure we have the right NPortID if one is specified */ |
| 1086 | if (phba->lpfc_injerr_nportid && |
| 1087 | (phba->lpfc_injerr_nportid != ndlp->nlp_DID)) |
| 1088 | return 0; |
| 1089 | |
| 1090 | /* |
| 1091 | * Make sure we have the right WWPN if one is specified. |
| 1092 | * wwn[0] should be a non-zero NAA in a good WWPN. |
| 1093 | */ |
| 1094 | if (phba->lpfc_injerr_wwpn.u.wwn[0] && |
| 1095 | (memcmp(&ndlp->nlp_portname, &phba->lpfc_injerr_wwpn, |
| 1096 | sizeof(struct lpfc_name)) != 0)) |
| 1097 | return 0; |
| 1098 | } |
| 1099 | |
| 1100 | /* Setup a ptr to the protection data if the SCSI host provides it */ |
| 1101 | if (sgpe) { |
| 1102 | src = (struct scsi_dif_tuple *)sg_virt(sgpe); |
| 1103 | src += blockoff; |
| 1104 | lpfc_cmd = (struct lpfc_scsi_buf *)sc->host_scribble; |
| 1105 | } |
| 1106 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1107 | /* Should we change the Reference Tag */ |
| 1108 | if (reftag) { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1109 | if (phba->lpfc_injerr_wref_cnt) { |
| 1110 | switch (op) { |
| 1111 | case SCSI_PROT_WRITE_PASS: |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1112 | if (src) { |
| 1113 | /* |
| 1114 | * For WRITE_PASS, force the error |
| 1115 | * to be sent on the wire. It should |
| 1116 | * be detected by the Target. |
| 1117 | * If blockoff != 0 error will be |
| 1118 | * inserted in middle of the IO. |
| 1119 | */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1120 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1121 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1122 | "9076 BLKGRD: Injecting reftag error: " |
| 1123 | "write lba x%lx + x%x oldrefTag x%x\n", |
| 1124 | (unsigned long)lba, blockoff, |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1125 | be32_to_cpu(src->ref_tag)); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1126 | |
| 1127 | /* |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1128 | * Save the old ref_tag so we can |
| 1129 | * restore it on completion. |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1130 | */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1131 | if (lpfc_cmd) { |
| 1132 | lpfc_cmd->prot_data_type = |
| 1133 | LPFC_INJERR_REFTAG; |
| 1134 | lpfc_cmd->prot_data_segment = |
| 1135 | src; |
| 1136 | lpfc_cmd->prot_data = |
| 1137 | src->ref_tag; |
| 1138 | } |
| 1139 | src->ref_tag = cpu_to_be32(0xDEADBEEF); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1140 | phba->lpfc_injerr_wref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1141 | if (phba->lpfc_injerr_wref_cnt == 0) { |
| 1142 | phba->lpfc_injerr_nportid = 0; |
| 1143 | phba->lpfc_injerr_lba = |
| 1144 | LPFC_INJERR_LBA_OFF; |
| 1145 | memset(&phba->lpfc_injerr_wwpn, |
| 1146 | 0, sizeof(struct lpfc_name)); |
| 1147 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1148 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
| 1149 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1150 | break; |
| 1151 | } |
| 1152 | /* Drop thru */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1153 | case SCSI_PROT_WRITE_INSERT: |
| 1154 | /* |
| 1155 | * For WRITE_INSERT, force the error |
| 1156 | * to be sent on the wire. It should be |
| 1157 | * detected by the Target. |
| 1158 | */ |
| 1159 | /* DEADBEEF will be the reftag on the wire */ |
| 1160 | *reftag = 0xDEADBEEF; |
| 1161 | phba->lpfc_injerr_wref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1162 | if (phba->lpfc_injerr_wref_cnt == 0) { |
| 1163 | phba->lpfc_injerr_nportid = 0; |
| 1164 | phba->lpfc_injerr_lba = |
| 1165 | LPFC_INJERR_LBA_OFF; |
| 1166 | memset(&phba->lpfc_injerr_wwpn, |
| 1167 | 0, sizeof(struct lpfc_name)); |
| 1168 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1169 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
| 1170 | |
| 1171 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1172 | "9078 BLKGRD: Injecting reftag error: " |
| 1173 | "write lba x%lx\n", (unsigned long)lba); |
| 1174 | break; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1175 | case SCSI_PROT_WRITE_STRIP: |
| 1176 | /* |
| 1177 | * For WRITE_STRIP and WRITE_PASS, |
| 1178 | * force the error on data |
| 1179 | * being copied from SLI-Host to SLI-Port. |
| 1180 | */ |
| 1181 | *reftag = 0xDEADBEEF; |
| 1182 | phba->lpfc_injerr_wref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1183 | if (phba->lpfc_injerr_wref_cnt == 0) { |
| 1184 | phba->lpfc_injerr_nportid = 0; |
| 1185 | phba->lpfc_injerr_lba = |
| 1186 | LPFC_INJERR_LBA_OFF; |
| 1187 | memset(&phba->lpfc_injerr_wwpn, |
| 1188 | 0, sizeof(struct lpfc_name)); |
| 1189 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1190 | rc = BG_ERR_INIT; |
| 1191 | |
| 1192 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1193 | "9077 BLKGRD: Injecting reftag error: " |
| 1194 | "write lba x%lx\n", (unsigned long)lba); |
| 1195 | break; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1196 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1197 | } |
| 1198 | if (phba->lpfc_injerr_rref_cnt) { |
| 1199 | switch (op) { |
| 1200 | case SCSI_PROT_READ_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1201 | case SCSI_PROT_READ_STRIP: |
| 1202 | case SCSI_PROT_READ_PASS: |
| 1203 | /* |
| 1204 | * For READ_STRIP and READ_PASS, force the |
| 1205 | * error on data being read off the wire. It |
| 1206 | * should force an IO error to the driver. |
| 1207 | */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1208 | *reftag = 0xDEADBEEF; |
| 1209 | phba->lpfc_injerr_rref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1210 | if (phba->lpfc_injerr_rref_cnt == 0) { |
| 1211 | phba->lpfc_injerr_nportid = 0; |
| 1212 | phba->lpfc_injerr_lba = |
| 1213 | LPFC_INJERR_LBA_OFF; |
| 1214 | memset(&phba->lpfc_injerr_wwpn, |
| 1215 | 0, sizeof(struct lpfc_name)); |
| 1216 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1217 | rc = BG_ERR_INIT; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1218 | |
| 1219 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1220 | "9079 BLKGRD: Injecting reftag error: " |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1221 | "read lba x%lx\n", (unsigned long)lba); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1222 | break; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1223 | } |
| 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | /* Should we change the Application Tag */ |
| 1228 | if (apptag) { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1229 | if (phba->lpfc_injerr_wapp_cnt) { |
| 1230 | switch (op) { |
| 1231 | case SCSI_PROT_WRITE_PASS: |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1232 | if (src) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1233 | /* |
| 1234 | * For WRITE_PASS, force the error |
| 1235 | * to be sent on the wire. It should |
| 1236 | * be detected by the Target. |
| 1237 | * If blockoff != 0 error will be |
| 1238 | * inserted in middle of the IO. |
| 1239 | */ |
| 1240 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1241 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1242 | "9080 BLKGRD: Injecting apptag error: " |
| 1243 | "write lba x%lx + x%x oldappTag x%x\n", |
| 1244 | (unsigned long)lba, blockoff, |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1245 | be16_to_cpu(src->app_tag)); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1246 | |
| 1247 | /* |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1248 | * Save the old app_tag so we can |
| 1249 | * restore it on completion. |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1250 | */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1251 | if (lpfc_cmd) { |
| 1252 | lpfc_cmd->prot_data_type = |
| 1253 | LPFC_INJERR_APPTAG; |
| 1254 | lpfc_cmd->prot_data_segment = |
| 1255 | src; |
| 1256 | lpfc_cmd->prot_data = |
| 1257 | src->app_tag; |
| 1258 | } |
| 1259 | src->app_tag = cpu_to_be16(0xDEAD); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1260 | phba->lpfc_injerr_wapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1261 | if (phba->lpfc_injerr_wapp_cnt == 0) { |
| 1262 | phba->lpfc_injerr_nportid = 0; |
| 1263 | phba->lpfc_injerr_lba = |
| 1264 | LPFC_INJERR_LBA_OFF; |
| 1265 | memset(&phba->lpfc_injerr_wwpn, |
| 1266 | 0, sizeof(struct lpfc_name)); |
| 1267 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1268 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1269 | break; |
| 1270 | } |
| 1271 | /* Drop thru */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1272 | case SCSI_PROT_WRITE_INSERT: |
| 1273 | /* |
| 1274 | * For WRITE_INSERT, force the |
| 1275 | * error to be sent on the wire. It should be |
| 1276 | * detected by the Target. |
| 1277 | */ |
| 1278 | /* DEAD will be the apptag on the wire */ |
| 1279 | *apptag = 0xDEAD; |
| 1280 | phba->lpfc_injerr_wapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1281 | if (phba->lpfc_injerr_wapp_cnt == 0) { |
| 1282 | phba->lpfc_injerr_nportid = 0; |
| 1283 | phba->lpfc_injerr_lba = |
| 1284 | LPFC_INJERR_LBA_OFF; |
| 1285 | memset(&phba->lpfc_injerr_wwpn, |
| 1286 | 0, sizeof(struct lpfc_name)); |
| 1287 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1288 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
| 1289 | |
| 1290 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1291 | "0813 BLKGRD: Injecting apptag error: " |
| 1292 | "write lba x%lx\n", (unsigned long)lba); |
| 1293 | break; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1294 | case SCSI_PROT_WRITE_STRIP: |
| 1295 | /* |
| 1296 | * For WRITE_STRIP and WRITE_PASS, |
| 1297 | * force the error on data |
| 1298 | * being copied from SLI-Host to SLI-Port. |
| 1299 | */ |
| 1300 | *apptag = 0xDEAD; |
| 1301 | phba->lpfc_injerr_wapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1302 | if (phba->lpfc_injerr_wapp_cnt == 0) { |
| 1303 | phba->lpfc_injerr_nportid = 0; |
| 1304 | phba->lpfc_injerr_lba = |
| 1305 | LPFC_INJERR_LBA_OFF; |
| 1306 | memset(&phba->lpfc_injerr_wwpn, |
| 1307 | 0, sizeof(struct lpfc_name)); |
| 1308 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1309 | rc = BG_ERR_INIT; |
| 1310 | |
| 1311 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1312 | "0812 BLKGRD: Injecting apptag error: " |
| 1313 | "write lba x%lx\n", (unsigned long)lba); |
| 1314 | break; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1315 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1316 | } |
| 1317 | if (phba->lpfc_injerr_rapp_cnt) { |
| 1318 | switch (op) { |
| 1319 | case SCSI_PROT_READ_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1320 | case SCSI_PROT_READ_STRIP: |
| 1321 | case SCSI_PROT_READ_PASS: |
| 1322 | /* |
| 1323 | * For READ_STRIP and READ_PASS, force the |
| 1324 | * error on data being read off the wire. It |
| 1325 | * should force an IO error to the driver. |
| 1326 | */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1327 | *apptag = 0xDEAD; |
| 1328 | phba->lpfc_injerr_rapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1329 | if (phba->lpfc_injerr_rapp_cnt == 0) { |
| 1330 | phba->lpfc_injerr_nportid = 0; |
| 1331 | phba->lpfc_injerr_lba = |
| 1332 | LPFC_INJERR_LBA_OFF; |
| 1333 | memset(&phba->lpfc_injerr_wwpn, |
| 1334 | 0, sizeof(struct lpfc_name)); |
| 1335 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1336 | rc = BG_ERR_INIT; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1337 | |
| 1338 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1339 | "0814 BLKGRD: Injecting apptag error: " |
| 1340 | "read lba x%lx\n", (unsigned long)lba); |
| 1341 | break; |
| 1342 | } |
| 1343 | } |
| 1344 | } |
| 1345 | |
| 1346 | |
| 1347 | /* Should we change the Guard Tag */ |
| 1348 | if (new_guard) { |
| 1349 | if (phba->lpfc_injerr_wgrd_cnt) { |
| 1350 | switch (op) { |
| 1351 | case SCSI_PROT_WRITE_PASS: |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1352 | rc = BG_ERR_CHECK; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1353 | /* Drop thru */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1354 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1355 | case SCSI_PROT_WRITE_INSERT: |
| 1356 | /* |
| 1357 | * For WRITE_INSERT, force the |
| 1358 | * error to be sent on the wire. It should be |
| 1359 | * detected by the Target. |
| 1360 | */ |
| 1361 | phba->lpfc_injerr_wgrd_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1362 | if (phba->lpfc_injerr_wgrd_cnt == 0) { |
| 1363 | phba->lpfc_injerr_nportid = 0; |
| 1364 | phba->lpfc_injerr_lba = |
| 1365 | LPFC_INJERR_LBA_OFF; |
| 1366 | memset(&phba->lpfc_injerr_wwpn, |
| 1367 | 0, sizeof(struct lpfc_name)); |
| 1368 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1369 | |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1370 | rc |= BG_ERR_TGT | BG_ERR_SWAP; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1371 | /* Signals the caller to swap CRC->CSUM */ |
| 1372 | |
| 1373 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1374 | "0817 BLKGRD: Injecting guard error: " |
| 1375 | "write lba x%lx\n", (unsigned long)lba); |
| 1376 | break; |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1377 | case SCSI_PROT_WRITE_STRIP: |
| 1378 | /* |
| 1379 | * For WRITE_STRIP and WRITE_PASS, |
| 1380 | * force the error on data |
| 1381 | * being copied from SLI-Host to SLI-Port. |
| 1382 | */ |
| 1383 | phba->lpfc_injerr_wgrd_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1384 | if (phba->lpfc_injerr_wgrd_cnt == 0) { |
| 1385 | phba->lpfc_injerr_nportid = 0; |
| 1386 | phba->lpfc_injerr_lba = |
| 1387 | LPFC_INJERR_LBA_OFF; |
| 1388 | memset(&phba->lpfc_injerr_wwpn, |
| 1389 | 0, sizeof(struct lpfc_name)); |
| 1390 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1391 | |
| 1392 | rc = BG_ERR_INIT | BG_ERR_SWAP; |
| 1393 | /* Signals the caller to swap CRC->CSUM */ |
| 1394 | |
| 1395 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1396 | "0816 BLKGRD: Injecting guard error: " |
| 1397 | "write lba x%lx\n", (unsigned long)lba); |
| 1398 | break; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1399 | } |
| 1400 | } |
| 1401 | if (phba->lpfc_injerr_rgrd_cnt) { |
| 1402 | switch (op) { |
| 1403 | case SCSI_PROT_READ_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1404 | case SCSI_PROT_READ_STRIP: |
| 1405 | case SCSI_PROT_READ_PASS: |
| 1406 | /* |
| 1407 | * For READ_STRIP and READ_PASS, force the |
| 1408 | * error on data being read off the wire. It |
| 1409 | * should force an IO error to the driver. |
| 1410 | */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1411 | phba->lpfc_injerr_rgrd_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1412 | if (phba->lpfc_injerr_rgrd_cnt == 0) { |
| 1413 | phba->lpfc_injerr_nportid = 0; |
| 1414 | phba->lpfc_injerr_lba = |
| 1415 | LPFC_INJERR_LBA_OFF; |
| 1416 | memset(&phba->lpfc_injerr_wwpn, |
| 1417 | 0, sizeof(struct lpfc_name)); |
| 1418 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1419 | |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1420 | rc = BG_ERR_INIT | BG_ERR_SWAP; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1421 | /* Signals the caller to swap CRC->CSUM */ |
| 1422 | |
| 1423 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1424 | "0818 BLKGRD: Injecting guard error: " |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1425 | "read lba x%lx\n", (unsigned long)lba); |
| 1426 | } |
| 1427 | } |
| 1428 | } |
| 1429 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1430 | return rc; |
| 1431 | } |
| 1432 | #endif |
| 1433 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1434 | /** |
| 1435 | * lpfc_sc_to_bg_opcodes - Determine the BlockGuard opcodes to be used with |
| 1436 | * the specified SCSI command. |
| 1437 | * @phba: The Hba for which this call is being executed. |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1438 | * @sc: The SCSI command to examine |
| 1439 | * @txopt: (out) BlockGuard operation for transmitted data |
| 1440 | * @rxopt: (out) BlockGuard operation for received data |
| 1441 | * |
| 1442 | * Returns: zero on success; non-zero if tx and/or rx op cannot be determined |
| 1443 | * |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1444 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1445 | static int |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1446 | lpfc_sc_to_bg_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1447 | uint8_t *txop, uint8_t *rxop) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1448 | { |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1449 | uint8_t ret = 0; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1450 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1451 | if (lpfc_cmd_guard_csum(sc)) { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1452 | switch (scsi_get_prot_op(sc)) { |
| 1453 | case SCSI_PROT_READ_INSERT: |
| 1454 | case SCSI_PROT_WRITE_STRIP: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1455 | *rxop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1456 | *txop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1457 | break; |
| 1458 | |
| 1459 | case SCSI_PROT_READ_STRIP: |
| 1460 | case SCSI_PROT_WRITE_INSERT: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1461 | *rxop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1462 | *txop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1463 | break; |
| 1464 | |
Martin K. Petersen | c6af404 | 2009-09-18 17:32:59 -0400 | [diff] [blame] | 1465 | case SCSI_PROT_READ_PASS: |
| 1466 | case SCSI_PROT_WRITE_PASS: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1467 | *rxop = BG_OP_IN_CRC_OUT_CSUM; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1468 | *txop = BG_OP_IN_CSUM_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1469 | break; |
| 1470 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1471 | case SCSI_PROT_NORMAL: |
| 1472 | default: |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1473 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1474 | "9063 BLKGRD: Bad op/guard:%d/IP combination\n", |
| 1475 | scsi_get_prot_op(sc)); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1476 | ret = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1477 | break; |
| 1478 | |
| 1479 | } |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1480 | } else { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1481 | switch (scsi_get_prot_op(sc)) { |
| 1482 | case SCSI_PROT_READ_STRIP: |
| 1483 | case SCSI_PROT_WRITE_INSERT: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1484 | *rxop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1485 | *txop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1486 | break; |
| 1487 | |
| 1488 | case SCSI_PROT_READ_PASS: |
| 1489 | case SCSI_PROT_WRITE_PASS: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1490 | *rxop = BG_OP_IN_CRC_OUT_CRC; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1491 | *txop = BG_OP_IN_CRC_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1492 | break; |
| 1493 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1494 | case SCSI_PROT_READ_INSERT: |
| 1495 | case SCSI_PROT_WRITE_STRIP: |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1496 | *rxop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1497 | *txop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1498 | break; |
| 1499 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1500 | case SCSI_PROT_NORMAL: |
| 1501 | default: |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1502 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1503 | "9075 BLKGRD: Bad op/guard:%d/CRC combination\n", |
| 1504 | scsi_get_prot_op(sc)); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1505 | ret = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1506 | break; |
| 1507 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1508 | } |
| 1509 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1510 | return ret; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1511 | } |
| 1512 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1513 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 1514 | /** |
| 1515 | * lpfc_bg_err_opcodes - reDetermine the BlockGuard opcodes to be used with |
| 1516 | * the specified SCSI command in order to force a guard tag error. |
| 1517 | * @phba: The Hba for which this call is being executed. |
| 1518 | * @sc: The SCSI command to examine |
| 1519 | * @txopt: (out) BlockGuard operation for transmitted data |
| 1520 | * @rxopt: (out) BlockGuard operation for received data |
| 1521 | * |
| 1522 | * Returns: zero on success; non-zero if tx and/or rx op cannot be determined |
| 1523 | * |
| 1524 | **/ |
| 1525 | static int |
| 1526 | lpfc_bg_err_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1527 | uint8_t *txop, uint8_t *rxop) |
| 1528 | { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1529 | uint8_t ret = 0; |
| 1530 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1531 | if (lpfc_cmd_guard_csum(sc)) { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1532 | switch (scsi_get_prot_op(sc)) { |
| 1533 | case SCSI_PROT_READ_INSERT: |
| 1534 | case SCSI_PROT_WRITE_STRIP: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1535 | *rxop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1536 | *txop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1537 | break; |
| 1538 | |
| 1539 | case SCSI_PROT_READ_STRIP: |
| 1540 | case SCSI_PROT_WRITE_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1541 | *rxop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1542 | *txop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1543 | break; |
| 1544 | |
| 1545 | case SCSI_PROT_READ_PASS: |
| 1546 | case SCSI_PROT_WRITE_PASS: |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1547 | *rxop = BG_OP_IN_CSUM_OUT_CRC; |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1548 | *txop = BG_OP_IN_CRC_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1549 | break; |
| 1550 | |
| 1551 | case SCSI_PROT_NORMAL: |
| 1552 | default: |
| 1553 | break; |
| 1554 | |
| 1555 | } |
| 1556 | } else { |
| 1557 | switch (scsi_get_prot_op(sc)) { |
| 1558 | case SCSI_PROT_READ_STRIP: |
| 1559 | case SCSI_PROT_WRITE_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1560 | *rxop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1561 | *txop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1562 | break; |
| 1563 | |
| 1564 | case SCSI_PROT_READ_PASS: |
| 1565 | case SCSI_PROT_WRITE_PASS: |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1566 | *rxop = BG_OP_IN_CSUM_OUT_CSUM; |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1567 | *txop = BG_OP_IN_CSUM_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1568 | break; |
| 1569 | |
| 1570 | case SCSI_PROT_READ_INSERT: |
| 1571 | case SCSI_PROT_WRITE_STRIP: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1572 | *rxop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1573 | *txop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1574 | break; |
| 1575 | |
| 1576 | case SCSI_PROT_NORMAL: |
| 1577 | default: |
| 1578 | break; |
| 1579 | } |
| 1580 | } |
| 1581 | |
| 1582 | return ret; |
| 1583 | } |
| 1584 | #endif |
| 1585 | |
| 1586 | /** |
| 1587 | * lpfc_bg_setup_bpl - Setup BlockGuard BPL with no protection data |
| 1588 | * @phba: The Hba for which this call is being executed. |
| 1589 | * @sc: pointer to scsi command we're working on |
| 1590 | * @bpl: pointer to buffer list for protection groups |
| 1591 | * @datacnt: number of segments of data that have been dma mapped |
| 1592 | * |
| 1593 | * This function sets up BPL buffer list for protection groups of |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1594 | * type LPFC_PG_TYPE_NO_DIF |
| 1595 | * |
| 1596 | * This is usually used when the HBA is instructed to generate |
| 1597 | * DIFs and insert them into data stream (or strip DIF from |
| 1598 | * incoming data stream) |
| 1599 | * |
| 1600 | * The buffer list consists of just one protection group described |
| 1601 | * below: |
| 1602 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1603 | * start of prot group --> | PDE_5 | |
| 1604 | * +-------------------------+ |
| 1605 | * | PDE_6 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1606 | * +-------------------------+ |
| 1607 | * | Data BDE | |
| 1608 | * +-------------------------+ |
| 1609 | * |more Data BDE's ... (opt)| |
| 1610 | * +-------------------------+ |
| 1611 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1612 | * |
| 1613 | * Note: Data s/g buffers have been dma mapped |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1614 | * |
| 1615 | * Returns the number of BDEs added to the BPL. |
| 1616 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1617 | static int |
| 1618 | lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1619 | struct ulp_bde64 *bpl, int datasegcnt) |
| 1620 | { |
| 1621 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1622 | struct lpfc_pde5 *pde5 = NULL; |
| 1623 | struct lpfc_pde6 *pde6 = NULL; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1624 | dma_addr_t physaddr; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1625 | int i = 0, num_bde = 0, status; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1626 | int datadir = sc->sc_data_direction; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 1627 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1628 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 1629 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1630 | uint32_t checking = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1631 | uint32_t reftag; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1632 | uint8_t txop, rxop; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1633 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1634 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 1635 | if (status) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1636 | goto out; |
| 1637 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1638 | /* extract some info from the scsi command for pde*/ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1639 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1640 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1641 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1642 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1643 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1644 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1645 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1646 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1647 | checking = 0; |
| 1648 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1649 | #endif |
| 1650 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1651 | /* setup PDE5 with what we have */ |
| 1652 | pde5 = (struct lpfc_pde5 *) bpl; |
| 1653 | memset(pde5, 0, sizeof(struct lpfc_pde5)); |
| 1654 | bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1655 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1656 | /* Endianness conversion if necessary for PDE5 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1657 | pde5->word0 = cpu_to_le32(pde5->word0); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1658 | pde5->reftag = cpu_to_le32(reftag); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1659 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1660 | /* advance bpl and increment bde count */ |
| 1661 | num_bde++; |
| 1662 | bpl++; |
| 1663 | pde6 = (struct lpfc_pde6 *) bpl; |
| 1664 | |
| 1665 | /* setup PDE6 with the rest of the info */ |
| 1666 | memset(pde6, 0, sizeof(struct lpfc_pde6)); |
| 1667 | bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR); |
| 1668 | bf_set(pde6_optx, pde6, txop); |
| 1669 | bf_set(pde6_oprx, pde6, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1670 | |
| 1671 | /* |
| 1672 | * We only need to check the data on READs, for WRITEs |
| 1673 | * protection data is automatically generated, not checked. |
| 1674 | */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1675 | if (datadir == DMA_FROM_DEVICE) { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1676 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1677 | bf_set(pde6_ce, pde6, checking); |
| 1678 | else |
| 1679 | bf_set(pde6_ce, pde6, 0); |
| 1680 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1681 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1682 | bf_set(pde6_re, pde6, checking); |
| 1683 | else |
| 1684 | bf_set(pde6_re, pde6, 0); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1685 | } |
| 1686 | bf_set(pde6_ai, pde6, 1); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1687 | bf_set(pde6_ae, pde6, 0); |
| 1688 | bf_set(pde6_apptagval, pde6, 0); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1689 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1690 | /* Endianness conversion if necessary for PDE6 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1691 | pde6->word0 = cpu_to_le32(pde6->word0); |
| 1692 | pde6->word1 = cpu_to_le32(pde6->word1); |
| 1693 | pde6->word2 = cpu_to_le32(pde6->word2); |
| 1694 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1695 | /* advance bpl and increment bde count */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1696 | num_bde++; |
| 1697 | bpl++; |
| 1698 | |
| 1699 | /* assumption: caller has already run dma_map_sg on command data */ |
| 1700 | scsi_for_each_sg(sc, sgde, datasegcnt, i) { |
| 1701 | physaddr = sg_dma_address(sgde); |
| 1702 | bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
| 1703 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 1704 | bpl->tus.f.bdeSize = sg_dma_len(sgde); |
| 1705 | if (datadir == DMA_TO_DEVICE) |
| 1706 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1707 | else |
| 1708 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
| 1709 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 1710 | bpl++; |
| 1711 | num_bde++; |
| 1712 | } |
| 1713 | |
| 1714 | out: |
| 1715 | return num_bde; |
| 1716 | } |
| 1717 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1718 | /** |
| 1719 | * lpfc_bg_setup_bpl_prot - Setup BlockGuard BPL with protection data |
| 1720 | * @phba: The Hba for which this call is being executed. |
| 1721 | * @sc: pointer to scsi command we're working on |
| 1722 | * @bpl: pointer to buffer list for protection groups |
| 1723 | * @datacnt: number of segments of data that have been dma mapped |
| 1724 | * @protcnt: number of segment of protection data that have been dma mapped |
| 1725 | * |
| 1726 | * This function sets up BPL buffer list for protection groups of |
| 1727 | * type LPFC_PG_TYPE_DIF |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1728 | * |
| 1729 | * This is usually used when DIFs are in their own buffers, |
| 1730 | * separate from the data. The HBA can then by instructed |
| 1731 | * to place the DIFs in the outgoing stream. For read operations, |
| 1732 | * The HBA could extract the DIFs and place it in DIF buffers. |
| 1733 | * |
| 1734 | * The buffer list for this type consists of one or more of the |
| 1735 | * protection groups described below: |
| 1736 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1737 | * start of first prot group --> | PDE_5 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1738 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1739 | * | PDE_6 | |
| 1740 | * +-------------------------+ |
| 1741 | * | PDE_7 (Prot BDE) | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1742 | * +-------------------------+ |
| 1743 | * | Data BDE | |
| 1744 | * +-------------------------+ |
| 1745 | * |more Data BDE's ... (opt)| |
| 1746 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1747 | * start of new prot group --> | PDE_5 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1748 | * +-------------------------+ |
| 1749 | * | ... | |
| 1750 | * +-------------------------+ |
| 1751 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1752 | * Note: It is assumed that both data and protection s/g buffers have been |
| 1753 | * mapped for DMA |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1754 | * |
| 1755 | * Returns the number of BDEs added to the BPL. |
| 1756 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1757 | static int |
| 1758 | lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1759 | struct ulp_bde64 *bpl, int datacnt, int protcnt) |
| 1760 | { |
| 1761 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 1762 | struct scatterlist *sgpe = NULL; /* s/g prot entry */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1763 | struct lpfc_pde5 *pde5 = NULL; |
| 1764 | struct lpfc_pde6 *pde6 = NULL; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1765 | struct lpfc_pde7 *pde7 = NULL; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1766 | dma_addr_t dataphysaddr, protphysaddr; |
| 1767 | unsigned short curr_data = 0, curr_prot = 0; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1768 | unsigned int split_offset; |
| 1769 | unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1770 | unsigned int protgrp_blks, protgrp_bytes; |
| 1771 | unsigned int remainder, subtotal; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1772 | int status; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1773 | int datadir = sc->sc_data_direction; |
| 1774 | unsigned char pgdone = 0, alldone = 0; |
| 1775 | unsigned blksize; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 1776 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1777 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 1778 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1779 | uint32_t checking = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1780 | uint32_t reftag; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1781 | uint8_t txop, rxop; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1782 | int num_bde = 0; |
| 1783 | |
| 1784 | sgpe = scsi_prot_sglist(sc); |
| 1785 | sgde = scsi_sglist(sc); |
| 1786 | |
| 1787 | if (!sgpe || !sgde) { |
| 1788 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 1789 | "9020 Invalid s/g entry: data=0x%p prot=0x%p\n", |
| 1790 | sgpe, sgde); |
| 1791 | return 0; |
| 1792 | } |
| 1793 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1794 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 1795 | if (status) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1796 | goto out; |
| 1797 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1798 | /* extract some info from the scsi command */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1799 | blksize = lpfc_cmd_blksize(sc); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1800 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1801 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1802 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1803 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1804 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1805 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1806 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1807 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1808 | checking = 0; |
| 1809 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1810 | #endif |
| 1811 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1812 | split_offset = 0; |
| 1813 | do { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 1814 | /* Check to see if we ran out of space */ |
| 1815 | if (num_bde >= (phba->cfg_total_seg_cnt - 2)) |
| 1816 | return num_bde + 3; |
| 1817 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1818 | /* setup PDE5 with what we have */ |
| 1819 | pde5 = (struct lpfc_pde5 *) bpl; |
| 1820 | memset(pde5, 0, sizeof(struct lpfc_pde5)); |
| 1821 | bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1822 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1823 | /* Endianness conversion if necessary for PDE5 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1824 | pde5->word0 = cpu_to_le32(pde5->word0); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1825 | pde5->reftag = cpu_to_le32(reftag); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1826 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1827 | /* advance bpl and increment bde count */ |
| 1828 | num_bde++; |
| 1829 | bpl++; |
| 1830 | pde6 = (struct lpfc_pde6 *) bpl; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1831 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1832 | /* setup PDE6 with the rest of the info */ |
| 1833 | memset(pde6, 0, sizeof(struct lpfc_pde6)); |
| 1834 | bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR); |
| 1835 | bf_set(pde6_optx, pde6, txop); |
| 1836 | bf_set(pde6_oprx, pde6, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1837 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1838 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1839 | bf_set(pde6_ce, pde6, checking); |
| 1840 | else |
| 1841 | bf_set(pde6_ce, pde6, 0); |
| 1842 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1843 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1844 | bf_set(pde6_re, pde6, checking); |
| 1845 | else |
| 1846 | bf_set(pde6_re, pde6, 0); |
| 1847 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1848 | bf_set(pde6_ai, pde6, 1); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1849 | bf_set(pde6_ae, pde6, 0); |
| 1850 | bf_set(pde6_apptagval, pde6, 0); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1851 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1852 | /* Endianness conversion if necessary for PDE6 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1853 | pde6->word0 = cpu_to_le32(pde6->word0); |
| 1854 | pde6->word1 = cpu_to_le32(pde6->word1); |
| 1855 | pde6->word2 = cpu_to_le32(pde6->word2); |
| 1856 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1857 | /* advance bpl and increment bde count */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1858 | num_bde++; |
| 1859 | bpl++; |
| 1860 | |
| 1861 | /* setup the first BDE that points to protection buffer */ |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1862 | protphysaddr = sg_dma_address(sgpe) + protgroup_offset; |
| 1863 | protgroup_len = sg_dma_len(sgpe) - protgroup_offset; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1864 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1865 | /* must be integer multiple of the DIF block length */ |
| 1866 | BUG_ON(protgroup_len % 8); |
| 1867 | |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1868 | pde7 = (struct lpfc_pde7 *) bpl; |
| 1869 | memset(pde7, 0, sizeof(struct lpfc_pde7)); |
| 1870 | bf_set(pde7_type, pde7, LPFC_PDE7_DESCRIPTOR); |
| 1871 | |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1872 | pde7->addrHigh = le32_to_cpu(putPaddrHigh(protphysaddr)); |
| 1873 | pde7->addrLow = le32_to_cpu(putPaddrLow(protphysaddr)); |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1874 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1875 | protgrp_blks = protgroup_len / 8; |
| 1876 | protgrp_bytes = protgrp_blks * blksize; |
| 1877 | |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1878 | /* check if this pde is crossing the 4K boundary; if so split */ |
| 1879 | if ((pde7->addrLow & 0xfff) + protgroup_len > 0x1000) { |
| 1880 | protgroup_remainder = 0x1000 - (pde7->addrLow & 0xfff); |
| 1881 | protgroup_offset += protgroup_remainder; |
| 1882 | protgrp_blks = protgroup_remainder / 8; |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1883 | protgrp_bytes = protgrp_blks * blksize; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1884 | } else { |
| 1885 | protgroup_offset = 0; |
| 1886 | curr_prot++; |
| 1887 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1888 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1889 | num_bde++; |
| 1890 | |
| 1891 | /* setup BDE's for data blocks associated with DIF data */ |
| 1892 | pgdone = 0; |
| 1893 | subtotal = 0; /* total bytes processed for current prot grp */ |
| 1894 | while (!pgdone) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 1895 | /* Check to see if we ran out of space */ |
| 1896 | if (num_bde >= phba->cfg_total_seg_cnt) |
| 1897 | return num_bde + 1; |
| 1898 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1899 | if (!sgde) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1900 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1901 | "9065 BLKGRD:%s Invalid data segment\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1902 | __func__); |
| 1903 | return 0; |
| 1904 | } |
| 1905 | bpl++; |
| 1906 | dataphysaddr = sg_dma_address(sgde) + split_offset; |
| 1907 | bpl->addrLow = le32_to_cpu(putPaddrLow(dataphysaddr)); |
| 1908 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(dataphysaddr)); |
| 1909 | |
| 1910 | remainder = sg_dma_len(sgde) - split_offset; |
| 1911 | |
| 1912 | if ((subtotal + remainder) <= protgrp_bytes) { |
| 1913 | /* we can use this whole buffer */ |
| 1914 | bpl->tus.f.bdeSize = remainder; |
| 1915 | split_offset = 0; |
| 1916 | |
| 1917 | if ((subtotal + remainder) == protgrp_bytes) |
| 1918 | pgdone = 1; |
| 1919 | } else { |
| 1920 | /* must split this buffer with next prot grp */ |
| 1921 | bpl->tus.f.bdeSize = protgrp_bytes - subtotal; |
| 1922 | split_offset += bpl->tus.f.bdeSize; |
| 1923 | } |
| 1924 | |
| 1925 | subtotal += bpl->tus.f.bdeSize; |
| 1926 | |
| 1927 | if (datadir == DMA_TO_DEVICE) |
| 1928 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1929 | else |
| 1930 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
| 1931 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 1932 | |
| 1933 | num_bde++; |
| 1934 | curr_data++; |
| 1935 | |
| 1936 | if (split_offset) |
| 1937 | break; |
| 1938 | |
| 1939 | /* Move to the next s/g segment if possible */ |
| 1940 | sgde = sg_next(sgde); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1941 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1942 | } |
| 1943 | |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1944 | if (protgroup_offset) { |
| 1945 | /* update the reference tag */ |
| 1946 | reftag += protgrp_blks; |
| 1947 | bpl++; |
| 1948 | continue; |
| 1949 | } |
| 1950 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1951 | /* are we done ? */ |
| 1952 | if (curr_prot == protcnt) { |
| 1953 | alldone = 1; |
| 1954 | } else if (curr_prot < protcnt) { |
| 1955 | /* advance to next prot buffer */ |
| 1956 | sgpe = sg_next(sgpe); |
| 1957 | bpl++; |
| 1958 | |
| 1959 | /* update the reference tag */ |
| 1960 | reftag += protgrp_blks; |
| 1961 | } else { |
| 1962 | /* if we're here, we have a bug */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1963 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1964 | "9054 BLKGRD: bug in %s\n", __func__); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | } while (!alldone); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1968 | out: |
| 1969 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1970 | return num_bde; |
| 1971 | } |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 1972 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1973 | /** |
| 1974 | * lpfc_bg_setup_sgl - Setup BlockGuard SGL with no protection data |
| 1975 | * @phba: The Hba for which this call is being executed. |
| 1976 | * @sc: pointer to scsi command we're working on |
| 1977 | * @sgl: pointer to buffer list for protection groups |
| 1978 | * @datacnt: number of segments of data that have been dma mapped |
| 1979 | * |
| 1980 | * This function sets up SGL buffer list for protection groups of |
| 1981 | * type LPFC_PG_TYPE_NO_DIF |
| 1982 | * |
| 1983 | * This is usually used when the HBA is instructed to generate |
| 1984 | * DIFs and insert them into data stream (or strip DIF from |
| 1985 | * incoming data stream) |
| 1986 | * |
| 1987 | * The buffer list consists of just one protection group described |
| 1988 | * below: |
| 1989 | * +-------------------------+ |
| 1990 | * start of prot group --> | DI_SEED | |
| 1991 | * +-------------------------+ |
| 1992 | * | Data SGE | |
| 1993 | * +-------------------------+ |
| 1994 | * |more Data SGE's ... (opt)| |
| 1995 | * +-------------------------+ |
| 1996 | * |
| 1997 | * |
| 1998 | * Note: Data s/g buffers have been dma mapped |
| 1999 | * |
| 2000 | * Returns the number of SGEs added to the SGL. |
| 2001 | **/ |
| 2002 | static int |
| 2003 | lpfc_bg_setup_sgl(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 2004 | struct sli4_sge *sgl, int datasegcnt) |
| 2005 | { |
| 2006 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 2007 | struct sli4_sge_diseed *diseed = NULL; |
| 2008 | dma_addr_t physaddr; |
| 2009 | int i = 0, num_sge = 0, status; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2010 | uint32_t reftag; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2011 | uint8_t txop, rxop; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2012 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2013 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2014 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2015 | uint32_t checking = 1; |
| 2016 | uint32_t dma_len; |
| 2017 | uint32_t dma_offset = 0; |
| 2018 | |
| 2019 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 2020 | if (status) |
| 2021 | goto out; |
| 2022 | |
| 2023 | /* extract some info from the scsi command for pde*/ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2024 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
| 2025 | |
| 2026 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 2027 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2028 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2029 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2030 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2031 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2032 | checking = 0; |
| 2033 | } |
| 2034 | #endif |
| 2035 | |
| 2036 | /* setup DISEED with what we have */ |
| 2037 | diseed = (struct sli4_sge_diseed *) sgl; |
| 2038 | memset(diseed, 0, sizeof(struct sli4_sge_diseed)); |
| 2039 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED); |
| 2040 | |
| 2041 | /* Endianness conversion if necessary */ |
| 2042 | diseed->ref_tag = cpu_to_le32(reftag); |
| 2043 | diseed->ref_tag_tran = diseed->ref_tag; |
| 2044 | |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2045 | /* |
| 2046 | * We only need to check the data on READs, for WRITEs |
| 2047 | * protection data is automatically generated, not checked. |
| 2048 | */ |
| 2049 | if (sc->sc_data_direction == DMA_FROM_DEVICE) { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2050 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2051 | bf_set(lpfc_sli4_sge_dif_ce, diseed, checking); |
| 2052 | else |
| 2053 | bf_set(lpfc_sli4_sge_dif_ce, diseed, 0); |
| 2054 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2055 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2056 | bf_set(lpfc_sli4_sge_dif_re, diseed, checking); |
| 2057 | else |
| 2058 | bf_set(lpfc_sli4_sge_dif_re, diseed, 0); |
| 2059 | } |
| 2060 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2061 | /* setup DISEED with the rest of the info */ |
| 2062 | bf_set(lpfc_sli4_sge_dif_optx, diseed, txop); |
| 2063 | bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2064 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2065 | bf_set(lpfc_sli4_sge_dif_ai, diseed, 1); |
| 2066 | bf_set(lpfc_sli4_sge_dif_me, diseed, 0); |
| 2067 | |
| 2068 | /* Endianness conversion if necessary for DISEED */ |
| 2069 | diseed->word2 = cpu_to_le32(diseed->word2); |
| 2070 | diseed->word3 = cpu_to_le32(diseed->word3); |
| 2071 | |
| 2072 | /* advance bpl and increment sge count */ |
| 2073 | num_sge++; |
| 2074 | sgl++; |
| 2075 | |
| 2076 | /* assumption: caller has already run dma_map_sg on command data */ |
| 2077 | scsi_for_each_sg(sc, sgde, datasegcnt, i) { |
| 2078 | physaddr = sg_dma_address(sgde); |
| 2079 | dma_len = sg_dma_len(sgde); |
| 2080 | sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr)); |
| 2081 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr)); |
| 2082 | if ((i + 1) == datasegcnt) |
| 2083 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 2084 | else |
| 2085 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 2086 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
| 2087 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); |
| 2088 | |
| 2089 | sgl->sge_len = cpu_to_le32(dma_len); |
| 2090 | dma_offset += dma_len; |
| 2091 | |
| 2092 | sgl++; |
| 2093 | num_sge++; |
| 2094 | } |
| 2095 | |
| 2096 | out: |
| 2097 | return num_sge; |
| 2098 | } |
| 2099 | |
| 2100 | /** |
| 2101 | * lpfc_bg_setup_sgl_prot - Setup BlockGuard SGL with protection data |
| 2102 | * @phba: The Hba for which this call is being executed. |
| 2103 | * @sc: pointer to scsi command we're working on |
| 2104 | * @sgl: pointer to buffer list for protection groups |
| 2105 | * @datacnt: number of segments of data that have been dma mapped |
| 2106 | * @protcnt: number of segment of protection data that have been dma mapped |
| 2107 | * |
| 2108 | * This function sets up SGL buffer list for protection groups of |
| 2109 | * type LPFC_PG_TYPE_DIF |
| 2110 | * |
| 2111 | * This is usually used when DIFs are in their own buffers, |
| 2112 | * separate from the data. The HBA can then by instructed |
| 2113 | * to place the DIFs in the outgoing stream. For read operations, |
| 2114 | * The HBA could extract the DIFs and place it in DIF buffers. |
| 2115 | * |
| 2116 | * The buffer list for this type consists of one or more of the |
| 2117 | * protection groups described below: |
| 2118 | * +-------------------------+ |
| 2119 | * start of first prot group --> | DISEED | |
| 2120 | * +-------------------------+ |
| 2121 | * | DIF (Prot SGE) | |
| 2122 | * +-------------------------+ |
| 2123 | * | Data SGE | |
| 2124 | * +-------------------------+ |
| 2125 | * |more Data SGE's ... (opt)| |
| 2126 | * +-------------------------+ |
| 2127 | * start of new prot group --> | DISEED | |
| 2128 | * +-------------------------+ |
| 2129 | * | ... | |
| 2130 | * +-------------------------+ |
| 2131 | * |
| 2132 | * Note: It is assumed that both data and protection s/g buffers have been |
| 2133 | * mapped for DMA |
| 2134 | * |
| 2135 | * Returns the number of SGEs added to the SGL. |
| 2136 | **/ |
| 2137 | static int |
| 2138 | lpfc_bg_setup_sgl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 2139 | struct sli4_sge *sgl, int datacnt, int protcnt) |
| 2140 | { |
| 2141 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 2142 | struct scatterlist *sgpe = NULL; /* s/g prot entry */ |
| 2143 | struct sli4_sge_diseed *diseed = NULL; |
| 2144 | dma_addr_t dataphysaddr, protphysaddr; |
| 2145 | unsigned short curr_data = 0, curr_prot = 0; |
| 2146 | unsigned int split_offset; |
| 2147 | unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder; |
| 2148 | unsigned int protgrp_blks, protgrp_bytes; |
| 2149 | unsigned int remainder, subtotal; |
| 2150 | int status; |
| 2151 | unsigned char pgdone = 0, alldone = 0; |
| 2152 | unsigned blksize; |
| 2153 | uint32_t reftag; |
| 2154 | uint8_t txop, rxop; |
| 2155 | uint32_t dma_len; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2156 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2157 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2158 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2159 | uint32_t checking = 1; |
| 2160 | uint32_t dma_offset = 0; |
| 2161 | int num_sge = 0; |
| 2162 | |
| 2163 | sgpe = scsi_prot_sglist(sc); |
| 2164 | sgde = scsi_sglist(sc); |
| 2165 | |
| 2166 | if (!sgpe || !sgde) { |
| 2167 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2168 | "9082 Invalid s/g entry: data=0x%p prot=0x%p\n", |
| 2169 | sgpe, sgde); |
| 2170 | return 0; |
| 2171 | } |
| 2172 | |
| 2173 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 2174 | if (status) |
| 2175 | goto out; |
| 2176 | |
| 2177 | /* extract some info from the scsi command */ |
| 2178 | blksize = lpfc_cmd_blksize(sc); |
| 2179 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
| 2180 | |
| 2181 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 2182 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2183 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2184 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2185 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2186 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2187 | checking = 0; |
| 2188 | } |
| 2189 | #endif |
| 2190 | |
| 2191 | split_offset = 0; |
| 2192 | do { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2193 | /* Check to see if we ran out of space */ |
| 2194 | if (num_sge >= (phba->cfg_total_seg_cnt - 2)) |
| 2195 | return num_sge + 3; |
| 2196 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2197 | /* setup DISEED with what we have */ |
| 2198 | diseed = (struct sli4_sge_diseed *) sgl; |
| 2199 | memset(diseed, 0, sizeof(struct sli4_sge_diseed)); |
| 2200 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED); |
| 2201 | |
| 2202 | /* Endianness conversion if necessary */ |
| 2203 | diseed->ref_tag = cpu_to_le32(reftag); |
| 2204 | diseed->ref_tag_tran = diseed->ref_tag; |
| 2205 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2206 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) { |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2207 | bf_set(lpfc_sli4_sge_dif_ce, diseed, checking); |
| 2208 | |
| 2209 | } else { |
| 2210 | bf_set(lpfc_sli4_sge_dif_ce, diseed, 0); |
| 2211 | /* |
| 2212 | * When in this mode, the hardware will replace |
| 2213 | * the guard tag from the host with a |
| 2214 | * newly generated good CRC for the wire. |
| 2215 | * Switch to raw mode here to avoid this |
| 2216 | * behavior. What the host sends gets put on the wire. |
| 2217 | */ |
| 2218 | if (txop == BG_OP_IN_CRC_OUT_CRC) { |
| 2219 | txop = BG_OP_RAW_MODE; |
| 2220 | rxop = BG_OP_RAW_MODE; |
| 2221 | } |
| 2222 | } |
| 2223 | |
| 2224 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2225 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2226 | bf_set(lpfc_sli4_sge_dif_re, diseed, checking); |
| 2227 | else |
| 2228 | bf_set(lpfc_sli4_sge_dif_re, diseed, 0); |
| 2229 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2230 | /* setup DISEED with the rest of the info */ |
| 2231 | bf_set(lpfc_sli4_sge_dif_optx, diseed, txop); |
| 2232 | bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2233 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2234 | bf_set(lpfc_sli4_sge_dif_ai, diseed, 1); |
| 2235 | bf_set(lpfc_sli4_sge_dif_me, diseed, 0); |
| 2236 | |
| 2237 | /* Endianness conversion if necessary for DISEED */ |
| 2238 | diseed->word2 = cpu_to_le32(diseed->word2); |
| 2239 | diseed->word3 = cpu_to_le32(diseed->word3); |
| 2240 | |
| 2241 | /* advance sgl and increment bde count */ |
| 2242 | num_sge++; |
| 2243 | sgl++; |
| 2244 | |
| 2245 | /* setup the first BDE that points to protection buffer */ |
| 2246 | protphysaddr = sg_dma_address(sgpe) + protgroup_offset; |
| 2247 | protgroup_len = sg_dma_len(sgpe) - protgroup_offset; |
| 2248 | |
| 2249 | /* must be integer multiple of the DIF block length */ |
| 2250 | BUG_ON(protgroup_len % 8); |
| 2251 | |
| 2252 | /* Now setup DIF SGE */ |
| 2253 | sgl->word2 = 0; |
| 2254 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DIF); |
| 2255 | sgl->addr_hi = le32_to_cpu(putPaddrHigh(protphysaddr)); |
| 2256 | sgl->addr_lo = le32_to_cpu(putPaddrLow(protphysaddr)); |
| 2257 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 2258 | |
| 2259 | protgrp_blks = protgroup_len / 8; |
| 2260 | protgrp_bytes = protgrp_blks * blksize; |
| 2261 | |
| 2262 | /* check if DIF SGE is crossing the 4K boundary; if so split */ |
| 2263 | if ((sgl->addr_lo & 0xfff) + protgroup_len > 0x1000) { |
| 2264 | protgroup_remainder = 0x1000 - (sgl->addr_lo & 0xfff); |
| 2265 | protgroup_offset += protgroup_remainder; |
| 2266 | protgrp_blks = protgroup_remainder / 8; |
| 2267 | protgrp_bytes = protgrp_blks * blksize; |
| 2268 | } else { |
| 2269 | protgroup_offset = 0; |
| 2270 | curr_prot++; |
| 2271 | } |
| 2272 | |
| 2273 | num_sge++; |
| 2274 | |
| 2275 | /* setup SGE's for data blocks associated with DIF data */ |
| 2276 | pgdone = 0; |
| 2277 | subtotal = 0; /* total bytes processed for current prot grp */ |
| 2278 | while (!pgdone) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2279 | /* Check to see if we ran out of space */ |
| 2280 | if (num_sge >= phba->cfg_total_seg_cnt) |
| 2281 | return num_sge + 1; |
| 2282 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2283 | if (!sgde) { |
| 2284 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2285 | "9086 BLKGRD:%s Invalid data segment\n", |
| 2286 | __func__); |
| 2287 | return 0; |
| 2288 | } |
| 2289 | sgl++; |
| 2290 | dataphysaddr = sg_dma_address(sgde) + split_offset; |
| 2291 | |
| 2292 | remainder = sg_dma_len(sgde) - split_offset; |
| 2293 | |
| 2294 | if ((subtotal + remainder) <= protgrp_bytes) { |
| 2295 | /* we can use this whole buffer */ |
| 2296 | dma_len = remainder; |
| 2297 | split_offset = 0; |
| 2298 | |
| 2299 | if ((subtotal + remainder) == protgrp_bytes) |
| 2300 | pgdone = 1; |
| 2301 | } else { |
| 2302 | /* must split this buffer with next prot grp */ |
| 2303 | dma_len = protgrp_bytes - subtotal; |
| 2304 | split_offset += dma_len; |
| 2305 | } |
| 2306 | |
| 2307 | subtotal += dma_len; |
| 2308 | |
| 2309 | sgl->addr_lo = cpu_to_le32(putPaddrLow(dataphysaddr)); |
| 2310 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(dataphysaddr)); |
| 2311 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 2312 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
| 2313 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); |
| 2314 | |
| 2315 | sgl->sge_len = cpu_to_le32(dma_len); |
| 2316 | dma_offset += dma_len; |
| 2317 | |
| 2318 | num_sge++; |
| 2319 | curr_data++; |
| 2320 | |
| 2321 | if (split_offset) |
| 2322 | break; |
| 2323 | |
| 2324 | /* Move to the next s/g segment if possible */ |
| 2325 | sgde = sg_next(sgde); |
| 2326 | } |
| 2327 | |
| 2328 | if (protgroup_offset) { |
| 2329 | /* update the reference tag */ |
| 2330 | reftag += protgrp_blks; |
| 2331 | sgl++; |
| 2332 | continue; |
| 2333 | } |
| 2334 | |
| 2335 | /* are we done ? */ |
| 2336 | if (curr_prot == protcnt) { |
| 2337 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 2338 | alldone = 1; |
| 2339 | } else if (curr_prot < protcnt) { |
| 2340 | /* advance to next prot buffer */ |
| 2341 | sgpe = sg_next(sgpe); |
| 2342 | sgl++; |
| 2343 | |
| 2344 | /* update the reference tag */ |
| 2345 | reftag += protgrp_blks; |
| 2346 | } else { |
| 2347 | /* if we're here, we have a bug */ |
| 2348 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2349 | "9085 BLKGRD: bug in %s\n", __func__); |
| 2350 | } |
| 2351 | |
| 2352 | } while (!alldone); |
| 2353 | |
| 2354 | out: |
| 2355 | |
| 2356 | return num_sge; |
| 2357 | } |
| 2358 | |
| 2359 | /** |
| 2360 | * lpfc_prot_group_type - Get prtotection group type of SCSI command |
| 2361 | * @phba: The Hba for which this call is being executed. |
| 2362 | * @sc: pointer to scsi command we're working on |
| 2363 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2364 | * Given a SCSI command that supports DIF, determine composition of protection |
| 2365 | * groups involved in setting up buffer lists |
| 2366 | * |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2367 | * Returns: Protection group type (with or without DIF) |
| 2368 | * |
| 2369 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2370 | static int |
| 2371 | lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc) |
| 2372 | { |
| 2373 | int ret = LPFC_PG_TYPE_INVALID; |
| 2374 | unsigned char op = scsi_get_prot_op(sc); |
| 2375 | |
| 2376 | switch (op) { |
| 2377 | case SCSI_PROT_READ_STRIP: |
| 2378 | case SCSI_PROT_WRITE_INSERT: |
| 2379 | ret = LPFC_PG_TYPE_NO_DIF; |
| 2380 | break; |
| 2381 | case SCSI_PROT_READ_INSERT: |
| 2382 | case SCSI_PROT_WRITE_STRIP: |
| 2383 | case SCSI_PROT_READ_PASS: |
| 2384 | case SCSI_PROT_WRITE_PASS: |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2385 | ret = LPFC_PG_TYPE_DIF_BUF; |
| 2386 | break; |
| 2387 | default: |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2388 | if (phba) |
| 2389 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2390 | "9021 Unsupported protection op:%d\n", |
| 2391 | op); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2392 | break; |
| 2393 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2394 | return ret; |
| 2395 | } |
| 2396 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2397 | /** |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2398 | * lpfc_bg_scsi_adjust_dl - Adjust SCSI data length for BlockGuard |
| 2399 | * @phba: The Hba for which this call is being executed. |
| 2400 | * @lpfc_cmd: The scsi buffer which is going to be adjusted. |
| 2401 | * |
| 2402 | * Adjust the data length to account for how much data |
| 2403 | * is actually on the wire. |
| 2404 | * |
| 2405 | * returns the adjusted data length |
| 2406 | **/ |
| 2407 | static int |
| 2408 | lpfc_bg_scsi_adjust_dl(struct lpfc_hba *phba, |
| 2409 | struct lpfc_scsi_buf *lpfc_cmd) |
| 2410 | { |
| 2411 | struct scsi_cmnd *sc = lpfc_cmd->pCmd; |
| 2412 | int fcpdl; |
| 2413 | |
| 2414 | fcpdl = scsi_bufflen(sc); |
| 2415 | |
| 2416 | /* Check if there is protection data on the wire */ |
| 2417 | if (sc->sc_data_direction == DMA_FROM_DEVICE) { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2418 | /* Read check for protection data */ |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2419 | if (scsi_get_prot_op(sc) == SCSI_PROT_READ_INSERT) |
| 2420 | return fcpdl; |
| 2421 | |
| 2422 | } else { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2423 | /* Write check for protection data */ |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2424 | if (scsi_get_prot_op(sc) == SCSI_PROT_WRITE_STRIP) |
| 2425 | return fcpdl; |
| 2426 | } |
| 2427 | |
| 2428 | /* |
| 2429 | * 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] | 2430 | * DIF (trailer) attached to it. Must ajust FCP data length |
| 2431 | * to account for the protection data. |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2432 | */ |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2433 | fcpdl += (fcpdl / lpfc_cmd_blksize(sc)) * 8; |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2434 | |
| 2435 | return fcpdl; |
| 2436 | } |
| 2437 | |
| 2438 | /** |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2439 | * lpfc_bg_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec |
| 2440 | * @phba: The Hba for which this call is being executed. |
| 2441 | * @lpfc_cmd: The scsi buffer which is going to be prep'ed. |
| 2442 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2443 | * This is the protection/DIF aware version of |
| 2444 | * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the |
| 2445 | * two functions eventually, but for now, it's here |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2446 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2447 | static int |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2448 | lpfc_bg_scsi_prep_dma_buf_s3(struct lpfc_hba *phba, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2449 | struct lpfc_scsi_buf *lpfc_cmd) |
| 2450 | { |
| 2451 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 2452 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 2453 | struct ulp_bde64 *bpl = lpfc_cmd->dma_sgl; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2454 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 2455 | uint32_t num_bde = 0; |
| 2456 | int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction; |
| 2457 | int prot_group_type = 0; |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2458 | int fcpdl; |
James Smart | 7c4042a | 2018-11-29 16:09:40 -0800 | [diff] [blame] | 2459 | struct lpfc_vport *vport = phba->pport; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2460 | |
| 2461 | /* |
| 2462 | * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd |
| 2463 | * fcp_rsp regions to the first data bde entry |
| 2464 | */ |
| 2465 | bpl += 2; |
| 2466 | if (scsi_sg_count(scsi_cmnd)) { |
| 2467 | /* |
| 2468 | * The driver stores the segment count returned from pci_map_sg |
| 2469 | * because this a count of dma-mappings used to map the use_sg |
| 2470 | * pages. They are not guaranteed to be the same for those |
| 2471 | * architectures that implement an IOMMU. |
| 2472 | */ |
| 2473 | datasegcnt = dma_map_sg(&phba->pcidev->dev, |
| 2474 | scsi_sglist(scsi_cmnd), |
| 2475 | scsi_sg_count(scsi_cmnd), datadir); |
| 2476 | if (unlikely(!datasegcnt)) |
| 2477 | return 1; |
| 2478 | |
| 2479 | lpfc_cmd->seg_cnt = datasegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2480 | |
| 2481 | /* First check if data segment count from SCSI Layer is good */ |
| 2482 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) |
| 2483 | goto err; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2484 | |
| 2485 | prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd); |
| 2486 | |
| 2487 | switch (prot_group_type) { |
| 2488 | case LPFC_PG_TYPE_NO_DIF: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2489 | |
| 2490 | /* Here we need to add a PDE5 and PDE6 to the count */ |
| 2491 | if ((lpfc_cmd->seg_cnt + 2) > phba->cfg_total_seg_cnt) |
| 2492 | goto err; |
| 2493 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2494 | num_bde = lpfc_bg_setup_bpl(phba, scsi_cmnd, bpl, |
| 2495 | datasegcnt); |
Adam Buchbinder | c9404c9 | 2009-12-18 15:40:42 -0500 | [diff] [blame] | 2496 | /* we should have 2 or more entries in buffer list */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2497 | if (num_bde < 2) |
| 2498 | goto err; |
| 2499 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2500 | |
| 2501 | case LPFC_PG_TYPE_DIF_BUF: |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2502 | /* |
| 2503 | * This type indicates that protection buffers are |
| 2504 | * passed to the driver, so that needs to be prepared |
| 2505 | * for DMA |
| 2506 | */ |
| 2507 | protsegcnt = dma_map_sg(&phba->pcidev->dev, |
| 2508 | scsi_prot_sglist(scsi_cmnd), |
| 2509 | scsi_prot_sg_count(scsi_cmnd), datadir); |
| 2510 | if (unlikely(!protsegcnt)) { |
| 2511 | scsi_dma_unmap(scsi_cmnd); |
| 2512 | return 1; |
| 2513 | } |
| 2514 | |
| 2515 | lpfc_cmd->prot_seg_cnt = protsegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2516 | |
| 2517 | /* |
| 2518 | * There is a minimun of 4 BPLs used for every |
| 2519 | * protection data segment. |
| 2520 | */ |
| 2521 | if ((lpfc_cmd->prot_seg_cnt * 4) > |
| 2522 | (phba->cfg_total_seg_cnt - 2)) |
| 2523 | goto err; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2524 | |
| 2525 | num_bde = lpfc_bg_setup_bpl_prot(phba, scsi_cmnd, bpl, |
| 2526 | datasegcnt, protsegcnt); |
Adam Buchbinder | c9404c9 | 2009-12-18 15:40:42 -0500 | [diff] [blame] | 2527 | /* we should have 3 or more entries in buffer list */ |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2528 | if ((num_bde < 3) || |
| 2529 | (num_bde > phba->cfg_total_seg_cnt)) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2530 | goto err; |
| 2531 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2532 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2533 | case LPFC_PG_TYPE_INVALID: |
| 2534 | default: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2535 | scsi_dma_unmap(scsi_cmnd); |
| 2536 | lpfc_cmd->seg_cnt = 0; |
| 2537 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2538 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2539 | "9022 Unexpected protection group %i\n", |
| 2540 | prot_group_type); |
| 2541 | return 1; |
| 2542 | } |
| 2543 | } |
| 2544 | |
| 2545 | /* |
| 2546 | * Finish initializing those IOCB fields that are dependent on the |
| 2547 | * scsi_cmnd request_buffer. Note that the bdeSize is explicitly |
| 2548 | * reinitialized since all iocb memory resources are used many times |
| 2549 | * for transmit, receive, and continuation bpl's. |
| 2550 | */ |
| 2551 | iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| 2552 | iocb_cmd->un.fcpi64.bdl.bdeSize += (num_bde * sizeof(struct ulp_bde64)); |
| 2553 | iocb_cmd->ulpBdeCount = 1; |
| 2554 | iocb_cmd->ulpLe = 1; |
| 2555 | |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2556 | fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2557 | fcp_cmnd->fcpDl = be32_to_cpu(fcpdl); |
| 2558 | |
| 2559 | /* |
| 2560 | * Due to difference in data length between DIF/non-DIF paths, |
| 2561 | * we need to set word 4 of IOCB here |
| 2562 | */ |
| 2563 | iocb_cmd->un.fcpi.fcpi_parm = fcpdl; |
| 2564 | |
James Smart | 7c4042a | 2018-11-29 16:09:40 -0800 | [diff] [blame] | 2565 | /* |
| 2566 | * For First burst, we may need to adjust the initial transfer |
| 2567 | * length for DIF |
| 2568 | */ |
| 2569 | if (iocb_cmd->un.fcpi.fcpi_XRdy && |
| 2570 | (fcpdl < vport->cfg_first_burst_size)) |
| 2571 | iocb_cmd->un.fcpi.fcpi_XRdy = fcpdl; |
| 2572 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2573 | return 0; |
| 2574 | err: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2575 | if (lpfc_cmd->seg_cnt) |
| 2576 | scsi_dma_unmap(scsi_cmnd); |
| 2577 | if (lpfc_cmd->prot_seg_cnt) |
| 2578 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd), |
| 2579 | scsi_prot_sg_count(scsi_cmnd), |
| 2580 | scsi_cmnd->sc_data_direction); |
| 2581 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2582 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2583 | "9023 Cannot setup S/G List for HBA" |
| 2584 | "IO segs %d/%d BPL %d SCSI %d: %d %d\n", |
| 2585 | lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt, |
| 2586 | phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2587 | prot_group_type, num_bde); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2588 | |
| 2589 | lpfc_cmd->seg_cnt = 0; |
| 2590 | lpfc_cmd->prot_seg_cnt = 0; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2591 | return 1; |
| 2592 | } |
| 2593 | |
| 2594 | /* |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2595 | * This function calcuates the T10 DIF guard tag |
| 2596 | * on the specified data using a CRC algorithmn |
| 2597 | * using crc_t10dif. |
| 2598 | */ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 2599 | static uint16_t |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2600 | lpfc_bg_crc(uint8_t *data, int count) |
| 2601 | { |
| 2602 | uint16_t crc = 0; |
| 2603 | uint16_t x; |
| 2604 | |
| 2605 | crc = crc_t10dif(data, count); |
| 2606 | x = cpu_to_be16(crc); |
| 2607 | return x; |
| 2608 | } |
| 2609 | |
| 2610 | /* |
| 2611 | * This function calcuates the T10 DIF guard tag |
| 2612 | * on the specified data using a CSUM algorithmn |
| 2613 | * using ip_compute_csum. |
| 2614 | */ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 2615 | static uint16_t |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2616 | lpfc_bg_csum(uint8_t *data, int count) |
| 2617 | { |
| 2618 | uint16_t ret; |
| 2619 | |
| 2620 | ret = ip_compute_csum(data, count); |
| 2621 | return ret; |
| 2622 | } |
| 2623 | |
| 2624 | /* |
| 2625 | * This function examines the protection data to try to determine |
| 2626 | * what type of T10-DIF error occurred. |
| 2627 | */ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 2628 | static void |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2629 | lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 2630 | { |
| 2631 | struct scatterlist *sgpe; /* s/g prot entry */ |
| 2632 | struct scatterlist *sgde; /* s/g data entry */ |
| 2633 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 2634 | struct scsi_dif_tuple *src = NULL; |
| 2635 | uint8_t *data_src = NULL; |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 2636 | uint16_t guard_tag; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2637 | uint16_t start_app_tag, app_tag; |
| 2638 | uint32_t start_ref_tag, ref_tag; |
| 2639 | int prot, protsegcnt; |
| 2640 | int err_type, len, data_len; |
| 2641 | int chk_ref, chk_app, chk_guard; |
| 2642 | uint16_t sum; |
| 2643 | unsigned blksize; |
| 2644 | |
| 2645 | err_type = BGS_GUARD_ERR_MASK; |
| 2646 | sum = 0; |
| 2647 | guard_tag = 0; |
| 2648 | |
| 2649 | /* First check to see if there is protection data to examine */ |
| 2650 | prot = scsi_get_prot_op(cmd); |
| 2651 | if ((prot == SCSI_PROT_READ_STRIP) || |
| 2652 | (prot == SCSI_PROT_WRITE_INSERT) || |
| 2653 | (prot == SCSI_PROT_NORMAL)) |
| 2654 | goto out; |
| 2655 | |
| 2656 | /* Currently the driver just supports ref_tag and guard_tag checking */ |
| 2657 | chk_ref = 1; |
| 2658 | chk_app = 0; |
| 2659 | chk_guard = 0; |
| 2660 | |
| 2661 | /* Setup a ptr to the protection data provided by the SCSI host */ |
| 2662 | sgpe = scsi_prot_sglist(cmd); |
| 2663 | protsegcnt = lpfc_cmd->prot_seg_cnt; |
| 2664 | |
| 2665 | if (sgpe && protsegcnt) { |
| 2666 | |
| 2667 | /* |
| 2668 | * We will only try to verify guard tag if the segment |
| 2669 | * data length is a multiple of the blksize. |
| 2670 | */ |
| 2671 | sgde = scsi_sglist(cmd); |
| 2672 | blksize = lpfc_cmd_blksize(cmd); |
| 2673 | data_src = (uint8_t *)sg_virt(sgde); |
| 2674 | data_len = sgde->length; |
| 2675 | if ((data_len & (blksize - 1)) == 0) |
| 2676 | chk_guard = 1; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2677 | |
James Smart | e85d8f9 | 2013-05-31 17:04:10 -0400 | [diff] [blame] | 2678 | src = (struct scsi_dif_tuple *)sg_virt(sgpe); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2679 | start_ref_tag = (uint32_t)scsi_get_lba(cmd); /* Truncate LBA */ |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2680 | start_app_tag = src->app_tag; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2681 | len = sgpe->length; |
| 2682 | while (src && protsegcnt) { |
| 2683 | while (len) { |
| 2684 | |
| 2685 | /* |
| 2686 | * First check to see if a protection data |
| 2687 | * check is valid |
| 2688 | */ |
Dmitry Monakhov | 128b6f9 | 2017-06-29 11:31:12 -0700 | [diff] [blame] | 2689 | if ((src->ref_tag == T10_PI_REF_ESCAPE) || |
| 2690 | (src->app_tag == T10_PI_APP_ESCAPE)) { |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2691 | start_ref_tag++; |
| 2692 | goto skipit; |
| 2693 | } |
| 2694 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2695 | /* First Guard Tag checking */ |
| 2696 | if (chk_guard) { |
| 2697 | guard_tag = src->guard_tag; |
| 2698 | if (lpfc_cmd_guard_csum(cmd)) |
| 2699 | sum = lpfc_bg_csum(data_src, |
| 2700 | blksize); |
| 2701 | else |
| 2702 | sum = lpfc_bg_crc(data_src, |
| 2703 | blksize); |
| 2704 | if ((guard_tag != sum)) { |
| 2705 | err_type = BGS_GUARD_ERR_MASK; |
| 2706 | goto out; |
| 2707 | } |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2708 | } |
| 2709 | |
| 2710 | /* Reference Tag checking */ |
| 2711 | ref_tag = be32_to_cpu(src->ref_tag); |
| 2712 | if (chk_ref && (ref_tag != start_ref_tag)) { |
| 2713 | err_type = BGS_REFTAG_ERR_MASK; |
| 2714 | goto out; |
| 2715 | } |
| 2716 | start_ref_tag++; |
| 2717 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2718 | /* App Tag checking */ |
| 2719 | app_tag = src->app_tag; |
| 2720 | if (chk_app && (app_tag != start_app_tag)) { |
| 2721 | err_type = BGS_APPTAG_ERR_MASK; |
| 2722 | goto out; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2723 | } |
| 2724 | skipit: |
| 2725 | len -= sizeof(struct scsi_dif_tuple); |
| 2726 | if (len < 0) |
| 2727 | len = 0; |
| 2728 | src++; |
| 2729 | |
| 2730 | data_src += blksize; |
| 2731 | data_len -= blksize; |
| 2732 | |
| 2733 | /* |
| 2734 | * Are we at the end of the Data segment? |
| 2735 | * The data segment is only used for Guard |
| 2736 | * tag checking. |
| 2737 | */ |
| 2738 | if (chk_guard && (data_len == 0)) { |
| 2739 | chk_guard = 0; |
| 2740 | sgde = sg_next(sgde); |
| 2741 | if (!sgde) |
| 2742 | goto out; |
| 2743 | |
| 2744 | data_src = (uint8_t *)sg_virt(sgde); |
| 2745 | data_len = sgde->length; |
| 2746 | if ((data_len & (blksize - 1)) == 0) |
| 2747 | chk_guard = 1; |
| 2748 | } |
| 2749 | } |
| 2750 | |
| 2751 | /* Goto the next Protection data segment */ |
| 2752 | sgpe = sg_next(sgpe); |
| 2753 | if (sgpe) { |
| 2754 | src = (struct scsi_dif_tuple *)sg_virt(sgpe); |
| 2755 | len = sgpe->length; |
| 2756 | } else { |
| 2757 | src = NULL; |
| 2758 | } |
| 2759 | protsegcnt--; |
| 2760 | } |
| 2761 | } |
| 2762 | out: |
| 2763 | if (err_type == BGS_GUARD_ERR_MASK) { |
| 2764 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 2765 | 0x10, 0x1); |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 2766 | cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 | |
| 2767 | SAM_STAT_CHECK_CONDITION; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2768 | phba->bg_guard_err_cnt++; |
| 2769 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 2770 | "9069 BLKGRD: LBA %lx grd_tag error %x != %x\n", |
| 2771 | (unsigned long)scsi_get_lba(cmd), |
| 2772 | sum, guard_tag); |
| 2773 | |
| 2774 | } else if (err_type == BGS_REFTAG_ERR_MASK) { |
| 2775 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 2776 | 0x10, 0x3); |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 2777 | cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 | |
| 2778 | SAM_STAT_CHECK_CONDITION; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2779 | |
| 2780 | phba->bg_reftag_err_cnt++; |
| 2781 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 2782 | "9066 BLKGRD: LBA %lx ref_tag error %x != %x\n", |
| 2783 | (unsigned long)scsi_get_lba(cmd), |
| 2784 | ref_tag, start_ref_tag); |
| 2785 | |
| 2786 | } else if (err_type == BGS_APPTAG_ERR_MASK) { |
| 2787 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 2788 | 0x10, 0x2); |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 2789 | cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 | |
| 2790 | SAM_STAT_CHECK_CONDITION; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2791 | |
| 2792 | phba->bg_apptag_err_cnt++; |
| 2793 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 2794 | "9041 BLKGRD: LBA %lx app_tag error %x != %x\n", |
| 2795 | (unsigned long)scsi_get_lba(cmd), |
| 2796 | app_tag, start_app_tag); |
| 2797 | } |
| 2798 | } |
| 2799 | |
| 2800 | |
| 2801 | /* |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2802 | * This function checks for BlockGuard errors detected by |
| 2803 | * the HBA. In case of errors, the ASC/ASCQ fields in the |
| 2804 | * sense buffer will be set accordingly, paired with |
| 2805 | * ILLEGAL_REQUEST to signal to the kernel that the HBA |
| 2806 | * detected corruption. |
| 2807 | * |
| 2808 | * Returns: |
| 2809 | * 0 - No error found |
| 2810 | * 1 - BlockGuard error found |
| 2811 | * -1 - Internal error (bad profile, ...etc) |
| 2812 | */ |
| 2813 | static int |
| 2814 | lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd, |
| 2815 | struct lpfc_iocbq *pIocbOut) |
| 2816 | { |
| 2817 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 2818 | struct sli3_bg_fields *bgf = &pIocbOut->iocb.unsli3.sli3_bg; |
| 2819 | int ret = 0; |
| 2820 | uint32_t bghm = bgf->bghm; |
| 2821 | uint32_t bgstat = bgf->bgstat; |
| 2822 | uint64_t failing_sector = 0; |
| 2823 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2824 | spin_lock(&_dump_buf_lock); |
| 2825 | if (!_dump_buf_done) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2826 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9070 BLKGRD: Saving" |
| 2827 | " Data for %u blocks to debugfs\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2828 | (cmd->cmnd[7] << 8 | cmd->cmnd[8])); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2829 | lpfc_debug_save_data(phba, cmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2830 | |
| 2831 | /* If we have a prot sgl, save the DIF buffer */ |
| 2832 | if (lpfc_prot_group_type(phba, cmd) == |
| 2833 | LPFC_PG_TYPE_DIF_BUF) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2834 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9071 BLKGRD: " |
| 2835 | "Saving DIF for %u blocks to debugfs\n", |
| 2836 | (cmd->cmnd[7] << 8 | cmd->cmnd[8])); |
| 2837 | lpfc_debug_save_dif(phba, cmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2838 | } |
| 2839 | |
| 2840 | _dump_buf_done = 1; |
| 2841 | } |
| 2842 | spin_unlock(&_dump_buf_lock); |
| 2843 | |
| 2844 | if (lpfc_bgs_get_invalid_prof(bgstat)) { |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 2845 | cmd->result = DID_ERROR << 16; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2846 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 2847 | "9072 BLKGRD: Invalid BG Profile in cmd" |
| 2848 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 2849 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 2850 | (unsigned long long)scsi_get_lba(cmd), |
| 2851 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2852 | ret = (-1); |
| 2853 | goto out; |
| 2854 | } |
| 2855 | |
| 2856 | if (lpfc_bgs_get_uninit_dif_block(bgstat)) { |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 2857 | cmd->result = DID_ERROR << 16; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2858 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 2859 | "9073 BLKGRD: Invalid BG PDIF Block in cmd" |
| 2860 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 2861 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 2862 | (unsigned long long)scsi_get_lba(cmd), |
| 2863 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2864 | ret = (-1); |
| 2865 | goto out; |
| 2866 | } |
| 2867 | |
| 2868 | if (lpfc_bgs_get_guard_err(bgstat)) { |
| 2869 | ret = 1; |
| 2870 | |
| 2871 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 2872 | 0x10, 0x1); |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 2873 | cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 | |
| 2874 | SAM_STAT_CHECK_CONDITION; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2875 | phba->bg_guard_err_cnt++; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2876 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 2877 | "9055 BLKGRD: Guard Tag error in cmd" |
| 2878 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 2879 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 2880 | (unsigned long long)scsi_get_lba(cmd), |
| 2881 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2882 | } |
| 2883 | |
| 2884 | if (lpfc_bgs_get_reftag_err(bgstat)) { |
| 2885 | ret = 1; |
| 2886 | |
| 2887 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 2888 | 0x10, 0x3); |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 2889 | cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 | |
| 2890 | SAM_STAT_CHECK_CONDITION; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2891 | |
| 2892 | phba->bg_reftag_err_cnt++; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2893 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 2894 | "9056 BLKGRD: Ref Tag error in cmd" |
| 2895 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 2896 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 2897 | (unsigned long long)scsi_get_lba(cmd), |
| 2898 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2899 | } |
| 2900 | |
| 2901 | if (lpfc_bgs_get_apptag_err(bgstat)) { |
| 2902 | ret = 1; |
| 2903 | |
| 2904 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 2905 | 0x10, 0x2); |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 2906 | cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 | |
| 2907 | SAM_STAT_CHECK_CONDITION; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2908 | |
| 2909 | phba->bg_apptag_err_cnt++; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2910 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 2911 | "9061 BLKGRD: App Tag error in cmd" |
| 2912 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 2913 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 2914 | (unsigned long long)scsi_get_lba(cmd), |
| 2915 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2916 | } |
| 2917 | |
| 2918 | if (lpfc_bgs_get_hi_water_mark_present(bgstat)) { |
| 2919 | /* |
| 2920 | * setup sense data descriptor 0 per SPC-4 as an information |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2921 | * field, and put the failing LBA in it. |
| 2922 | * This code assumes there was also a guard/app/ref tag error |
| 2923 | * indication. |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2924 | */ |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2925 | cmd->sense_buffer[7] = 0xc; /* Additional sense length */ |
| 2926 | cmd->sense_buffer[8] = 0; /* Information descriptor type */ |
| 2927 | cmd->sense_buffer[9] = 0xa; /* Additional descriptor length */ |
| 2928 | cmd->sense_buffer[10] = 0x80; /* Validity bit */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2929 | |
| 2930 | /* bghm is a "on the wire" FC frame based count */ |
| 2931 | switch (scsi_get_prot_op(cmd)) { |
| 2932 | case SCSI_PROT_READ_INSERT: |
| 2933 | case SCSI_PROT_WRITE_STRIP: |
| 2934 | bghm /= cmd->device->sector_size; |
| 2935 | break; |
| 2936 | case SCSI_PROT_READ_STRIP: |
| 2937 | case SCSI_PROT_WRITE_INSERT: |
| 2938 | case SCSI_PROT_READ_PASS: |
| 2939 | case SCSI_PROT_WRITE_PASS: |
| 2940 | bghm /= (cmd->device->sector_size + |
| 2941 | sizeof(struct scsi_dif_tuple)); |
| 2942 | break; |
| 2943 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2944 | |
| 2945 | failing_sector = scsi_get_lba(cmd); |
| 2946 | failing_sector += bghm; |
| 2947 | |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2948 | /* Descriptor Information */ |
| 2949 | put_unaligned_be64(failing_sector, &cmd->sense_buffer[12]); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2950 | } |
| 2951 | |
| 2952 | if (!ret) { |
| 2953 | /* No error was reported - problem in FW? */ |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2954 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 2955 | "9057 BLKGRD: Unknown error in cmd" |
| 2956 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 2957 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 2958 | (unsigned long long)scsi_get_lba(cmd), |
| 2959 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2960 | |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2961 | /* Calcuate what type of error it was */ |
| 2962 | lpfc_calc_bg_err(phba, lpfc_cmd); |
| 2963 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2964 | out: |
| 2965 | return ret; |
| 2966 | } |
| 2967 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2968 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2969 | * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec |
| 2970 | * @phba: The Hba for which this call is being executed. |
| 2971 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 2972 | * |
| 2973 | * This routine does the pci dma mapping for scatter-gather list of scsi cmnd |
| 2974 | * field of @lpfc_cmd for device with SLI-4 interface spec. |
| 2975 | * |
| 2976 | * Return codes: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2977 | * 1 - Error |
| 2978 | * 0 - Success |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2979 | **/ |
| 2980 | static int |
| 2981 | lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 2982 | { |
| 2983 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 2984 | struct scatterlist *sgel = NULL; |
| 2985 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 2986 | struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 2987 | struct sli4_sge *first_data_sgl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2988 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 2989 | dma_addr_t physaddr; |
| 2990 | uint32_t num_bde = 0; |
| 2991 | uint32_t dma_len; |
| 2992 | uint32_t dma_offset = 0; |
| 2993 | int nseg; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 2994 | struct ulp_bde64 *bde; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2995 | |
| 2996 | /* |
| 2997 | * There are three possibilities here - use scatter-gather segment, use |
| 2998 | * the single mapping, or neither. Start the lpfc command prep by |
| 2999 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 3000 | * data bde entry. |
| 3001 | */ |
| 3002 | if (scsi_sg_count(scsi_cmnd)) { |
| 3003 | /* |
| 3004 | * The driver stores the segment count returned from pci_map_sg |
| 3005 | * because this a count of dma-mappings used to map the use_sg |
| 3006 | * pages. They are not guaranteed to be the same for those |
| 3007 | * architectures that implement an IOMMU. |
| 3008 | */ |
| 3009 | |
| 3010 | nseg = scsi_dma_map(scsi_cmnd); |
James Smart | 5116fbf | 2015-05-22 10:42:39 -0400 | [diff] [blame] | 3011 | if (unlikely(nseg <= 0)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3012 | return 1; |
| 3013 | sgl += 1; |
| 3014 | /* clear the last flag in the fcp_rsp map entry */ |
| 3015 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 3016 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 3017 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 3018 | sgl += 1; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3019 | first_data_sgl = sgl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3020 | lpfc_cmd->seg_cnt = nseg; |
| 3021 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3022 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9074 BLKGRD:" |
| 3023 | " %s: Too many sg segments from " |
| 3024 | "dma_map_sg. Config %d, seg_cnt %d\n", |
| 3025 | __func__, phba->cfg_sg_seg_cnt, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3026 | lpfc_cmd->seg_cnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3027 | lpfc_cmd->seg_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3028 | scsi_dma_unmap(scsi_cmnd); |
| 3029 | return 1; |
| 3030 | } |
| 3031 | |
| 3032 | /* |
| 3033 | * The driver established a maximum scatter-gather segment count |
| 3034 | * during probe that limits the number of sg elements in any |
| 3035 | * single scsi command. Just run through the seg_cnt and format |
| 3036 | * the sge's. |
| 3037 | * When using SLI-3 the driver will try to fit all the BDEs into |
| 3038 | * the IOCB. If it can't then the BDEs get added to a BPL as it |
| 3039 | * does for SLI-2 mode. |
| 3040 | */ |
| 3041 | scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) { |
| 3042 | physaddr = sg_dma_address(sgel); |
| 3043 | dma_len = sg_dma_len(sgel); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3044 | sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr)); |
| 3045 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr)); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 3046 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3047 | if ((num_bde + 1) == nseg) |
| 3048 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 3049 | else |
| 3050 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 3051 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 3052 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3053 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 3054 | sgl->sge_len = cpu_to_le32(dma_len); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3055 | dma_offset += dma_len; |
| 3056 | sgl++; |
| 3057 | } |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 3058 | /* |
| 3059 | * Setup the first Payload BDE. For FCoE we just key off |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 3060 | * Performance Hints, for FC we use lpfc_enable_pbde. |
| 3061 | * We populate words 13-15 of IOCB/WQE. |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 3062 | */ |
| 3063 | if ((phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) || |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 3064 | phba->cfg_enable_pbde) { |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3065 | bde = (struct ulp_bde64 *) |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 3066 | &(iocb_cmd->unsli3.sli3Words[5]); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3067 | bde->addrLow = first_data_sgl->addr_lo; |
| 3068 | bde->addrHigh = first_data_sgl->addr_hi; |
| 3069 | bde->tus.f.bdeSize = |
| 3070 | le32_to_cpu(first_data_sgl->sge_len); |
| 3071 | bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 3072 | bde->tus.w = cpu_to_le32(bde->tus.w); |
| 3073 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3074 | } else { |
| 3075 | sgl += 1; |
| 3076 | /* clear the last flag in the fcp_rsp map entry */ |
| 3077 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 3078 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 3079 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 3080 | |
| 3081 | if ((phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) || |
| 3082 | phba->cfg_enable_pbde) { |
| 3083 | bde = (struct ulp_bde64 *) |
| 3084 | &(iocb_cmd->unsli3.sli3Words[5]); |
| 3085 | memset(bde, 0, (sizeof(uint32_t) * 3)); |
| 3086 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3087 | } |
| 3088 | |
| 3089 | /* |
| 3090 | * Finish initializing those IOCB fields that are dependent on the |
| 3091 | * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is |
| 3092 | * explicitly reinitialized. |
| 3093 | * all iocb memory resources are reused. |
| 3094 | */ |
| 3095 | fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); |
| 3096 | |
| 3097 | /* |
| 3098 | * Due to difference in data length between DIF/non-DIF paths, |
| 3099 | * we need to set word 4 of IOCB here |
| 3100 | */ |
| 3101 | iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 3102 | |
| 3103 | /* |
| 3104 | * If the OAS driver feature is enabled and the lun is enabled for |
| 3105 | * OAS, set the oas iocb related flags. |
| 3106 | */ |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 3107 | if ((phba->cfg_fof) && ((struct lpfc_device_data *) |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 3108 | scsi_cmnd->device->hostdata)->oas_enabled) { |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 3109 | lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 3110 | lpfc_cmd->cur_iocbq.priority = ((struct lpfc_device_data *) |
| 3111 | scsi_cmnd->device->hostdata)->priority; |
| 3112 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3113 | return 0; |
| 3114 | } |
| 3115 | |
| 3116 | /** |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3117 | * lpfc_bg_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec |
| 3118 | * @phba: The Hba for which this call is being executed. |
| 3119 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3120 | * |
| 3121 | * This is the protection/DIF aware version of |
| 3122 | * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the |
| 3123 | * two functions eventually, but for now, it's here |
| 3124 | **/ |
| 3125 | static int |
| 3126 | lpfc_bg_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, |
| 3127 | struct lpfc_scsi_buf *lpfc_cmd) |
| 3128 | { |
| 3129 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 3130 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3131 | struct sli4_sge *sgl = (struct sli4_sge *)(lpfc_cmd->dma_sgl); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3132 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3133 | uint32_t num_sge = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3134 | int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction; |
| 3135 | int prot_group_type = 0; |
| 3136 | int fcpdl; |
James Smart | 7c4042a | 2018-11-29 16:09:40 -0800 | [diff] [blame] | 3137 | struct lpfc_vport *vport = phba->pport; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3138 | |
| 3139 | /* |
| 3140 | * Start the lpfc command prep by bumping the sgl beyond fcp_cmnd |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3141 | * fcp_rsp regions to the first data sge entry |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3142 | */ |
| 3143 | if (scsi_sg_count(scsi_cmnd)) { |
| 3144 | /* |
| 3145 | * The driver stores the segment count returned from pci_map_sg |
| 3146 | * because this a count of dma-mappings used to map the use_sg |
| 3147 | * pages. They are not guaranteed to be the same for those |
| 3148 | * architectures that implement an IOMMU. |
| 3149 | */ |
| 3150 | datasegcnt = dma_map_sg(&phba->pcidev->dev, |
| 3151 | scsi_sglist(scsi_cmnd), |
| 3152 | scsi_sg_count(scsi_cmnd), datadir); |
| 3153 | if (unlikely(!datasegcnt)) |
| 3154 | return 1; |
| 3155 | |
| 3156 | sgl += 1; |
| 3157 | /* clear the last flag in the fcp_rsp map entry */ |
| 3158 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 3159 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 3160 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 3161 | |
| 3162 | sgl += 1; |
| 3163 | lpfc_cmd->seg_cnt = datasegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3164 | |
| 3165 | /* First check if data segment count from SCSI Layer is good */ |
| 3166 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) |
| 3167 | goto err; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3168 | |
| 3169 | prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd); |
| 3170 | |
| 3171 | switch (prot_group_type) { |
| 3172 | case LPFC_PG_TYPE_NO_DIF: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3173 | /* Here we need to add a DISEED to the count */ |
| 3174 | if ((lpfc_cmd->seg_cnt + 1) > phba->cfg_total_seg_cnt) |
| 3175 | goto err; |
| 3176 | |
| 3177 | num_sge = lpfc_bg_setup_sgl(phba, scsi_cmnd, sgl, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3178 | datasegcnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3179 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3180 | /* we should have 2 or more entries in buffer list */ |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3181 | if (num_sge < 2) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3182 | goto err; |
| 3183 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3184 | |
| 3185 | case LPFC_PG_TYPE_DIF_BUF: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3186 | /* |
| 3187 | * This type indicates that protection buffers are |
| 3188 | * passed to the driver, so that needs to be prepared |
| 3189 | * for DMA |
| 3190 | */ |
| 3191 | protsegcnt = dma_map_sg(&phba->pcidev->dev, |
| 3192 | scsi_prot_sglist(scsi_cmnd), |
| 3193 | scsi_prot_sg_count(scsi_cmnd), datadir); |
| 3194 | if (unlikely(!protsegcnt)) { |
| 3195 | scsi_dma_unmap(scsi_cmnd); |
| 3196 | return 1; |
| 3197 | } |
| 3198 | |
| 3199 | lpfc_cmd->prot_seg_cnt = protsegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3200 | /* |
| 3201 | * There is a minimun of 3 SGEs used for every |
| 3202 | * protection data segment. |
| 3203 | */ |
| 3204 | if ((lpfc_cmd->prot_seg_cnt * 3) > |
| 3205 | (phba->cfg_total_seg_cnt - 2)) |
| 3206 | goto err; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3207 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3208 | num_sge = lpfc_bg_setup_sgl_prot(phba, scsi_cmnd, sgl, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3209 | datasegcnt, protsegcnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3210 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3211 | /* we should have 3 or more entries in buffer list */ |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3212 | if ((num_sge < 3) || |
| 3213 | (num_sge > phba->cfg_total_seg_cnt)) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3214 | goto err; |
| 3215 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3216 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3217 | case LPFC_PG_TYPE_INVALID: |
| 3218 | default: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3219 | scsi_dma_unmap(scsi_cmnd); |
| 3220 | lpfc_cmd->seg_cnt = 0; |
| 3221 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3222 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 3223 | "9083 Unexpected protection group %i\n", |
| 3224 | prot_group_type); |
| 3225 | return 1; |
| 3226 | } |
| 3227 | } |
| 3228 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 3229 | switch (scsi_get_prot_op(scsi_cmnd)) { |
| 3230 | case SCSI_PROT_WRITE_STRIP: |
| 3231 | case SCSI_PROT_READ_STRIP: |
| 3232 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_STRIP; |
| 3233 | break; |
| 3234 | case SCSI_PROT_WRITE_INSERT: |
| 3235 | case SCSI_PROT_READ_INSERT: |
| 3236 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_INSERT; |
| 3237 | break; |
| 3238 | case SCSI_PROT_WRITE_PASS: |
| 3239 | case SCSI_PROT_READ_PASS: |
| 3240 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_PASS; |
| 3241 | break; |
| 3242 | } |
| 3243 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3244 | fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3245 | fcp_cmnd->fcpDl = be32_to_cpu(fcpdl); |
| 3246 | |
| 3247 | /* |
| 3248 | * Due to difference in data length between DIF/non-DIF paths, |
| 3249 | * we need to set word 4 of IOCB here |
| 3250 | */ |
| 3251 | iocb_cmd->un.fcpi.fcpi_parm = fcpdl; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3252 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 3253 | /* |
James Smart | 7c4042a | 2018-11-29 16:09:40 -0800 | [diff] [blame] | 3254 | * For First burst, we may need to adjust the initial transfer |
| 3255 | * length for DIF |
| 3256 | */ |
| 3257 | if (iocb_cmd->un.fcpi.fcpi_XRdy && |
| 3258 | (fcpdl < vport->cfg_first_burst_size)) |
| 3259 | iocb_cmd->un.fcpi.fcpi_XRdy = fcpdl; |
| 3260 | |
| 3261 | /* |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 3262 | * If the OAS driver feature is enabled and the lun is enabled for |
| 3263 | * OAS, set the oas iocb related flags. |
| 3264 | */ |
| 3265 | if ((phba->cfg_fof) && ((struct lpfc_device_data *) |
| 3266 | scsi_cmnd->device->hostdata)->oas_enabled) |
| 3267 | lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF); |
| 3268 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3269 | return 0; |
| 3270 | err: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3271 | if (lpfc_cmd->seg_cnt) |
| 3272 | scsi_dma_unmap(scsi_cmnd); |
| 3273 | if (lpfc_cmd->prot_seg_cnt) |
| 3274 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd), |
| 3275 | scsi_prot_sg_count(scsi_cmnd), |
| 3276 | scsi_cmnd->sc_data_direction); |
| 3277 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3278 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3279 | "9084 Cannot setup S/G List for HBA" |
| 3280 | "IO segs %d/%d SGL %d SCSI %d: %d %d\n", |
| 3281 | lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt, |
| 3282 | phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt, |
| 3283 | prot_group_type, num_sge); |
| 3284 | |
| 3285 | lpfc_cmd->seg_cnt = 0; |
| 3286 | lpfc_cmd->prot_seg_cnt = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3287 | return 1; |
| 3288 | } |
| 3289 | |
| 3290 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3291 | * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer |
| 3292 | * @phba: The Hba for which this call is being executed. |
| 3293 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3294 | * |
| 3295 | * This routine wraps the actual DMA mapping function pointer from the |
| 3296 | * lpfc_hba struct. |
| 3297 | * |
| 3298 | * Return codes: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 3299 | * 1 - Error |
| 3300 | * 0 - Success |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3301 | **/ |
| 3302 | static inline int |
| 3303 | lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 3304 | { |
| 3305 | return phba->lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 3306 | } |
| 3307 | |
| 3308 | /** |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3309 | * lpfc_bg_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer |
| 3310 | * using BlockGuard. |
| 3311 | * @phba: The Hba for which this call is being executed. |
| 3312 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3313 | * |
| 3314 | * This routine wraps the actual DMA mapping function pointer from the |
| 3315 | * lpfc_hba struct. |
| 3316 | * |
| 3317 | * Return codes: |
| 3318 | * 1 - Error |
| 3319 | * 0 - Success |
| 3320 | **/ |
| 3321 | static inline int |
| 3322 | lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 3323 | { |
| 3324 | return phba->lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 3325 | } |
| 3326 | |
| 3327 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3328 | * 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] | 3329 | * @phba: Pointer to hba context object. |
| 3330 | * @vport: Pointer to vport object. |
| 3331 | * @lpfc_cmd: Pointer to lpfc scsi command which reported the error. |
| 3332 | * @rsp_iocb: Pointer to response iocb object which reported error. |
| 3333 | * |
| 3334 | * This function posts an event when there is a SCSI command reporting |
| 3335 | * error from the scsi device. |
| 3336 | **/ |
| 3337 | static void |
| 3338 | lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 3339 | struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_iocbq *rsp_iocb) { |
| 3340 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 3341 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
| 3342 | uint32_t resp_info = fcprsp->rspStatus2; |
| 3343 | uint32_t scsi_status = fcprsp->rspStatus3; |
| 3344 | uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; |
| 3345 | struct lpfc_fast_path_event *fast_path_evt = NULL; |
| 3346 | struct lpfc_nodelist *pnode = lpfc_cmd->rdata->pnode; |
| 3347 | unsigned long flags; |
| 3348 | |
James Smart | 5989b8d | 2010-10-22 11:06:56 -0400 | [diff] [blame] | 3349 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 3350 | return; |
| 3351 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3352 | /* If there is queuefull or busy condition send a scsi event */ |
| 3353 | if ((cmnd->result == SAM_STAT_TASK_SET_FULL) || |
| 3354 | (cmnd->result == SAM_STAT_BUSY)) { |
| 3355 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3356 | if (!fast_path_evt) |
| 3357 | return; |
| 3358 | fast_path_evt->un.scsi_evt.event_type = |
| 3359 | FC_REG_SCSI_EVENT; |
| 3360 | fast_path_evt->un.scsi_evt.subcategory = |
| 3361 | (cmnd->result == SAM_STAT_TASK_SET_FULL) ? |
| 3362 | LPFC_EVENT_QFULL : LPFC_EVENT_DEVBSY; |
| 3363 | fast_path_evt->un.scsi_evt.lun = cmnd->device->lun; |
| 3364 | memcpy(&fast_path_evt->un.scsi_evt.wwpn, |
| 3365 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3366 | memcpy(&fast_path_evt->un.scsi_evt.wwnn, |
| 3367 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3368 | } else if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen && |
| 3369 | ((cmnd->cmnd[0] == READ_10) || (cmnd->cmnd[0] == WRITE_10))) { |
| 3370 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3371 | if (!fast_path_evt) |
| 3372 | return; |
| 3373 | fast_path_evt->un.check_cond_evt.scsi_event.event_type = |
| 3374 | FC_REG_SCSI_EVENT; |
| 3375 | fast_path_evt->un.check_cond_evt.scsi_event.subcategory = |
| 3376 | LPFC_EVENT_CHECK_COND; |
| 3377 | fast_path_evt->un.check_cond_evt.scsi_event.lun = |
| 3378 | cmnd->device->lun; |
| 3379 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwpn, |
| 3380 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3381 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwnn, |
| 3382 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3383 | fast_path_evt->un.check_cond_evt.sense_key = |
| 3384 | cmnd->sense_buffer[2] & 0xf; |
| 3385 | fast_path_evt->un.check_cond_evt.asc = cmnd->sense_buffer[12]; |
| 3386 | fast_path_evt->un.check_cond_evt.ascq = cmnd->sense_buffer[13]; |
| 3387 | } else if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) && |
| 3388 | fcpi_parm && |
| 3389 | ((be32_to_cpu(fcprsp->rspResId) != fcpi_parm) || |
| 3390 | ((scsi_status == SAM_STAT_GOOD) && |
| 3391 | !(resp_info & (RESID_UNDER | RESID_OVER))))) { |
| 3392 | /* |
| 3393 | * If status is good or resid does not match with fcp_param and |
| 3394 | * there is valid fcpi_parm, then there is a read_check error |
| 3395 | */ |
| 3396 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3397 | if (!fast_path_evt) |
| 3398 | return; |
| 3399 | fast_path_evt->un.read_check_error.header.event_type = |
| 3400 | FC_REG_FABRIC_EVENT; |
| 3401 | fast_path_evt->un.read_check_error.header.subcategory = |
| 3402 | LPFC_EVENT_FCPRDCHKERR; |
| 3403 | memcpy(&fast_path_evt->un.read_check_error.header.wwpn, |
| 3404 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3405 | memcpy(&fast_path_evt->un.read_check_error.header.wwnn, |
| 3406 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3407 | fast_path_evt->un.read_check_error.lun = cmnd->device->lun; |
| 3408 | fast_path_evt->un.read_check_error.opcode = cmnd->cmnd[0]; |
| 3409 | fast_path_evt->un.read_check_error.fcpiparam = |
| 3410 | fcpi_parm; |
| 3411 | } else |
| 3412 | return; |
| 3413 | |
| 3414 | fast_path_evt->vport = vport; |
| 3415 | spin_lock_irqsave(&phba->hbalock, flags); |
| 3416 | list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list); |
| 3417 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 3418 | lpfc_worker_wake_up(phba); |
| 3419 | return; |
| 3420 | } |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3421 | |
| 3422 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3423 | * 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] | 3424 | * @phba: The HBA for which this call is being executed. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3425 | * @psb: The scsi buffer which is going to be un-mapped. |
| 3426 | * |
| 3427 | * 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] | 3428 | * field of @lpfc_cmd for device with SLI-3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3429 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3430 | static void |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3431 | lpfc_scsi_unprep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 3432 | { |
| 3433 | /* |
| 3434 | * There are only two special cases to consider. (1) the scsi command |
| 3435 | * requested scatter-gather usage or (2) the scsi command allocated |
| 3436 | * a request buffer, but did not request use_sg. There is a third |
| 3437 | * case, but it does not require resource deallocation. |
| 3438 | */ |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3439 | if (psb->seg_cnt > 0) |
| 3440 | scsi_dma_unmap(psb->pCmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3441 | if (psb->prot_seg_cnt > 0) |
| 3442 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(psb->pCmd), |
| 3443 | scsi_prot_sg_count(psb->pCmd), |
| 3444 | psb->pCmd->sc_data_direction); |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 3445 | } |
| 3446 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3447 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3448 | * lpfc_handler_fcp_err - FCP response handler |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3449 | * @vport: The virtual port for which this call is being executed. |
| 3450 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. |
| 3451 | * @rsp_iocb: The response IOCB which contains FCP error. |
| 3452 | * |
| 3453 | * This routine is called to process response IOCB with status field |
| 3454 | * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command |
| 3455 | * based upon SCSI and FCP error. |
| 3456 | **/ |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 3457 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3458 | lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd, |
| 3459 | struct lpfc_iocbq *rsp_iocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3460 | { |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3461 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3462 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 3463 | struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd; |
| 3464 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3465 | uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3466 | uint32_t resp_info = fcprsp->rspStatus2; |
| 3467 | uint32_t scsi_status = fcprsp->rspStatus3; |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3468 | uint32_t *lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3469 | uint32_t host_status = DID_OK; |
| 3470 | uint32_t rsplen = 0; |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3471 | uint32_t fcpDl; |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3472 | uint32_t logit = LOG_FCP | LOG_FCP_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3473 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3474 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3475 | /* |
| 3476 | * If this is a task management command, there is no |
| 3477 | * scsi packet associated with this lpfc_cmd. The driver |
| 3478 | * consumes it. |
| 3479 | */ |
| 3480 | if (fcpcmd->fcpCntl2) { |
| 3481 | scsi_status = 0; |
| 3482 | goto out; |
| 3483 | } |
| 3484 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3485 | if (resp_info & RSP_LEN_VALID) { |
| 3486 | rsplen = be32_to_cpu(fcprsp->rspRspLen); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3487 | if (rsplen != 0 && rsplen != 4 && rsplen != 8) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3488 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 3489 | "2719 Invalid response length: " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 3490 | "tgt x%x lun x%llx cmnd x%x rsplen x%x\n", |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3491 | cmnd->device->id, |
| 3492 | cmnd->device->lun, cmnd->cmnd[0], |
| 3493 | rsplen); |
| 3494 | host_status = DID_ERROR; |
| 3495 | goto out; |
| 3496 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3497 | if (fcprsp->rspInfo3 != RSP_NO_FAILURE) { |
| 3498 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 3499 | "2757 Protocol failure detected during " |
| 3500 | "processing of FCP I/O op: " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 3501 | "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] | 3502 | cmnd->device->id, |
| 3503 | cmnd->device->lun, cmnd->cmnd[0], |
| 3504 | fcprsp->rspInfo3); |
| 3505 | host_status = DID_ERROR; |
| 3506 | goto out; |
| 3507 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3508 | } |
| 3509 | |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3510 | if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) { |
| 3511 | uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen); |
| 3512 | if (snslen > SCSI_SENSE_BUFFERSIZE) |
| 3513 | snslen = SCSI_SENSE_BUFFERSIZE; |
| 3514 | |
| 3515 | if (resp_info & RSP_LEN_VALID) |
| 3516 | rsplen = be32_to_cpu(fcprsp->rspRspLen); |
| 3517 | memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen); |
| 3518 | } |
| 3519 | lp = (uint32_t *)cmnd->sense_buffer; |
| 3520 | |
James Smart | aa1c7ee | 2012-08-14 14:26:06 -0400 | [diff] [blame] | 3521 | /* special handling for under run conditions */ |
| 3522 | if (!scsi_status && (resp_info & RESID_UNDER)) { |
| 3523 | /* don't log under runs if fcp set... */ |
| 3524 | if (vport->cfg_log_verbose & LOG_FCP) |
| 3525 | logit = LOG_FCP_ERROR; |
| 3526 | /* unless operator says so */ |
| 3527 | if (vport->cfg_log_verbose & LOG_FCP_UNDER) |
| 3528 | logit = LOG_FCP_UNDER; |
| 3529 | } |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3530 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3531 | lpfc_printf_vlog(vport, KERN_WARNING, logit, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3532 | "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] | 3533 | "Data: x%x x%x x%x x%x x%x\n", |
| 3534 | cmnd->cmnd[0], scsi_status, |
| 3535 | be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info, |
| 3536 | be32_to_cpu(fcprsp->rspResId), |
| 3537 | be32_to_cpu(fcprsp->rspSnsLen), |
| 3538 | be32_to_cpu(fcprsp->rspRspLen), |
| 3539 | fcprsp->rspInfo3); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3540 | |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3541 | scsi_set_resid(cmnd, 0); |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3542 | fcpDl = be32_to_cpu(fcpcmd->fcpDl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3543 | if (resp_info & RESID_UNDER) { |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3544 | scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3545 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3546 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_UNDER, |
James Smart | 45634a86 | 2018-01-30 15:59:00 -0800 | [diff] [blame] | 3547 | "9025 FCP Underrun, expected %d, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3548 | "residual %d Data: x%x x%x x%x\n", |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3549 | fcpDl, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3550 | scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0], |
| 3551 | cmnd->underflow); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3552 | |
| 3553 | /* |
James Smart | 45634a86 | 2018-01-30 15:59:00 -0800 | [diff] [blame] | 3554 | * If there is an under run, check if under run reported by |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3555 | * storage array is same as the under run reported by HBA. |
| 3556 | * If this is not same, there is a dropped frame. |
| 3557 | */ |
James Smart | 45634a86 | 2018-01-30 15:59:00 -0800 | [diff] [blame] | 3558 | if (fcpi_parm && (scsi_get_resid(cmnd) != fcpi_parm)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3559 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 3560 | LOG_FCP | LOG_FCP_ERROR, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3561 | "9026 FCP Read Check Error " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3562 | "and Underrun Data: x%x x%x x%x x%x\n", |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3563 | fcpDl, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3564 | scsi_get_resid(cmnd), fcpi_parm, |
| 3565 | cmnd->cmnd[0]); |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3566 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3567 | host_status = DID_ERROR; |
| 3568 | } |
| 3569 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3570 | * The cmnd->underflow is the minimum number of bytes that must |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3571 | * be transferred for this command. Provided a sense condition |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3572 | * is not present, make sure the actual amount transferred is at |
| 3573 | * least the underflow value or fail. |
| 3574 | */ |
| 3575 | if (!(resp_info & SNS_LEN_VALID) && |
| 3576 | (scsi_status == SAM_STAT_GOOD) && |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3577 | (scsi_bufflen(cmnd) - scsi_get_resid(cmnd) |
| 3578 | < cmnd->underflow)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3579 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3580 | "9027 FCP command x%x residual " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3581 | "underrun converted to error " |
| 3582 | "Data: x%x x%x x%x\n", |
James Smart | 66dbfbe | 2007-08-05 06:08:38 -0400 | [diff] [blame] | 3583 | cmnd->cmnd[0], scsi_bufflen(cmnd), |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3584 | scsi_get_resid(cmnd), cmnd->underflow); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3585 | host_status = DID_ERROR; |
| 3586 | } |
| 3587 | } else if (resp_info & RESID_OVER) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3588 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3589 | "9028 FCP command x%x residual overrun error. " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 3590 | "Data: x%x x%x\n", cmnd->cmnd[0], |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3591 | scsi_bufflen(cmnd), scsi_get_resid(cmnd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3592 | host_status = DID_ERROR; |
| 3593 | |
| 3594 | /* |
| 3595 | * Check SLI validation that all the transfer was actually done |
James Smart | 26373d2 | 2013-09-06 12:19:17 -0400 | [diff] [blame] | 3596 | * (fcpi_parm should be zero). Apply check only to reads. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3597 | */ |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3598 | } else if (fcpi_parm) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3599 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR, |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3600 | "9029 FCP %s Check Error xri x%x Data: " |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 3601 | "x%x x%x x%x x%x x%x\n", |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3602 | ((cmnd->sc_data_direction == DMA_FROM_DEVICE) ? |
| 3603 | "Read" : "Write"), |
| 3604 | ((phba->sli_rev == LPFC_SLI_REV4) ? |
| 3605 | lpfc_cmd->cur_iocbq.sli4_xritag : |
| 3606 | rsp_iocb->iocb.ulpContext), |
| 3607 | fcpDl, be32_to_cpu(fcprsp->rspResId), |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 3608 | fcpi_parm, cmnd->cmnd[0], scsi_status); |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3609 | |
| 3610 | /* There is some issue with the LPe12000 that causes it |
| 3611 | * to miscalculate the fcpi_parm and falsely trip this |
| 3612 | * recovery logic. Detect this case and don't error when true. |
| 3613 | */ |
| 3614 | if (fcpi_parm > fcpDl) |
| 3615 | goto out; |
| 3616 | |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 3617 | switch (scsi_status) { |
| 3618 | case SAM_STAT_GOOD: |
| 3619 | case SAM_STAT_CHECK_CONDITION: |
| 3620 | /* Fabric dropped a data frame. Fail any successful |
| 3621 | * command in which we detected dropped frames. |
| 3622 | * A status of good or some check conditions could |
| 3623 | * be considered a successful command. |
| 3624 | */ |
| 3625 | host_status = DID_ERROR; |
| 3626 | break; |
| 3627 | } |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3628 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3629 | } |
| 3630 | |
| 3631 | out: |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 3632 | cmnd->result = host_status << 16 | scsi_status; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3633 | lpfc_send_scsi_error_event(vport->phba, vport, lpfc_cmd, rsp_iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3634 | } |
| 3635 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3636 | /** |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 3637 | * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution |
| 3638 | * @phba: Pointer to HBA context object. |
| 3639 | * |
| 3640 | * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index |
| 3641 | * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock |
| 3642 | * held. |
| 3643 | * If scsi-mq is enabled, get the default block layer mapping of software queues |
| 3644 | * to hardware queues. This information is saved in request tag. |
| 3645 | * |
| 3646 | * Return: index into SLI4 fast-path FCP queue index. |
| 3647 | **/ |
| 3648 | int lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba, |
| 3649 | struct lpfc_scsi_buf *lpfc_cmd) |
| 3650 | { |
| 3651 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 3652 | struct lpfc_vector_map_info *cpup; |
| 3653 | int chann, cpu; |
| 3654 | uint32_t tag; |
| 3655 | uint16_t hwq; |
| 3656 | |
Jens Axboe | f664a3c | 2018-11-01 16:36:27 -0600 | [diff] [blame] | 3657 | if (cmnd) { |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 3658 | tag = blk_mq_unique_tag(cmnd->request); |
| 3659 | hwq = blk_mq_unique_tag_to_hwq(tag); |
| 3660 | |
| 3661 | return hwq; |
| 3662 | } |
| 3663 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame^] | 3664 | if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_CPU && |
| 3665 | phba->cfg_hdw_queue > 1) { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3666 | cpu = lpfc_cmd->cpu; |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 3667 | if (cpu < phba->sli4_hba.num_present_cpu) { |
| 3668 | cpup = phba->sli4_hba.cpu_map; |
| 3669 | cpup += cpu; |
| 3670 | return cpup->channel_id; |
| 3671 | } |
| 3672 | } |
| 3673 | chann = atomic_add_return(1, &phba->fcp_qidx); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame^] | 3674 | chann = chann % phba->cfg_hdw_queue; |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 3675 | return chann; |
| 3676 | } |
| 3677 | |
| 3678 | |
| 3679 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3680 | * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3681 | * @phba: The Hba for which this call is being executed. |
| 3682 | * @pIocbIn: The command IOCBQ for the scsi cmnd. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3683 | * @pIocbOut: The response IOCBQ for the scsi cmnd. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3684 | * |
| 3685 | * This routine assigns scsi command result by looking into response IOCB |
| 3686 | * status field appropriately. This routine handles QUEUE FULL condition as |
| 3687 | * well by ramping down device queue depth. |
| 3688 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3689 | static void |
| 3690 | lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn, |
| 3691 | struct lpfc_iocbq *pIocbOut) |
| 3692 | { |
| 3693 | struct lpfc_scsi_buf *lpfc_cmd = |
| 3694 | (struct lpfc_scsi_buf *) pIocbIn->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3695 | struct lpfc_vport *vport = pIocbIn->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3696 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| 3697 | struct lpfc_nodelist *pnode = rdata->pnode; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3698 | struct scsi_cmnd *cmd; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 3699 | unsigned long flags; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3700 | struct lpfc_fast_path_event *fast_path_evt; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3701 | struct Scsi_Host *shost; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3702 | uint32_t logit = LOG_FCP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3703 | |
James Smart | 2cee780 | 2017-06-01 21:07:02 -0700 | [diff] [blame] | 3704 | atomic_inc(&phba->fc4ScsiIoCmpls); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3705 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3706 | /* Sanity check on return of outstanding command */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3707 | cmd = lpfc_cmd->pCmd; |
James Smart | c90261d | 2015-12-16 18:11:57 -0500 | [diff] [blame] | 3708 | if (!cmd) |
| 3709 | return; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3710 | shost = cmd->device->host; |
| 3711 | |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3712 | lpfc_cmd->result = (pIocbOut->iocb.un.ulpWord[4] & IOERR_PARAM_MASK); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3713 | lpfc_cmd->status = pIocbOut->iocb.ulpStatus; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3714 | /* pick up SLI4 exhange busy status from HBA */ |
| 3715 | lpfc_cmd->exch_busy = pIocbOut->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 3716 | |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 3717 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 3718 | if (lpfc_cmd->prot_data_type) { |
| 3719 | struct scsi_dif_tuple *src = NULL; |
| 3720 | |
| 3721 | src = (struct scsi_dif_tuple *)lpfc_cmd->prot_data_segment; |
| 3722 | /* |
| 3723 | * Used to restore any changes to protection |
| 3724 | * data for error injection. |
| 3725 | */ |
| 3726 | switch (lpfc_cmd->prot_data_type) { |
| 3727 | case LPFC_INJERR_REFTAG: |
| 3728 | src->ref_tag = |
| 3729 | lpfc_cmd->prot_data; |
| 3730 | break; |
| 3731 | case LPFC_INJERR_APPTAG: |
| 3732 | src->app_tag = |
| 3733 | (uint16_t)lpfc_cmd->prot_data; |
| 3734 | break; |
| 3735 | case LPFC_INJERR_GUARD: |
| 3736 | src->guard_tag = |
| 3737 | (uint16_t)lpfc_cmd->prot_data; |
| 3738 | break; |
| 3739 | default: |
| 3740 | break; |
| 3741 | } |
| 3742 | |
| 3743 | lpfc_cmd->prot_data = 0; |
| 3744 | lpfc_cmd->prot_data_type = 0; |
| 3745 | lpfc_cmd->prot_data_segment = NULL; |
| 3746 | } |
| 3747 | #endif |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 3748 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3749 | if (lpfc_cmd->status) { |
| 3750 | if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT && |
| 3751 | (lpfc_cmd->result & IOERR_DRVR_MASK)) |
| 3752 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; |
| 3753 | else if (lpfc_cmd->status >= IOSTAT_CNT) |
| 3754 | lpfc_cmd->status = IOSTAT_DEFAULT; |
James Smart | aa1c7ee | 2012-08-14 14:26:06 -0400 | [diff] [blame] | 3755 | if (lpfc_cmd->status == IOSTAT_FCP_RSP_ERROR && |
| 3756 | !lpfc_cmd->fcp_rsp->rspStatus3 && |
| 3757 | (lpfc_cmd->fcp_rsp->rspStatus2 & RESID_UNDER) && |
| 3758 | !(vport->cfg_log_verbose & LOG_FCP_UNDER)) |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3759 | logit = 0; |
| 3760 | else |
| 3761 | logit = LOG_FCP | LOG_FCP_UNDER; |
| 3762 | lpfc_printf_vlog(vport, KERN_WARNING, logit, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 3763 | "9030 FCP cmd x%x failed <%d/%lld> " |
James Smart | 5a0d80f | 2012-05-09 21:18:20 -0400 | [diff] [blame] | 3764 | "status: x%x result: x%x " |
| 3765 | "sid: x%x did: x%x oxid: x%x " |
| 3766 | "Data: x%x x%x\n", |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3767 | cmd->cmnd[0], |
| 3768 | cmd->device ? cmd->device->id : 0xffff, |
| 3769 | cmd->device ? cmd->device->lun : 0xffff, |
| 3770 | lpfc_cmd->status, lpfc_cmd->result, |
James Smart | 3bf41ba | 2013-05-31 17:03:18 -0400 | [diff] [blame] | 3771 | vport->fc_myDID, |
| 3772 | (pnode) ? pnode->nlp_DID : 0, |
James Smart | 5a0d80f | 2012-05-09 21:18:20 -0400 | [diff] [blame] | 3773 | phba->sli_rev == LPFC_SLI_REV4 ? |
| 3774 | lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3775 | pIocbOut->iocb.ulpContext, |
| 3776 | lpfc_cmd->cur_iocbq.iocb.ulpIoTag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3777 | |
| 3778 | switch (lpfc_cmd->status) { |
| 3779 | case IOSTAT_FCP_RSP_ERROR: |
| 3780 | /* Call FCP RSP handler to determine result */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3781 | lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3782 | break; |
| 3783 | case IOSTAT_NPORT_BSY: |
| 3784 | case IOSTAT_FABRIC_BSY: |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 3785 | cmd->result = DID_TRANSPORT_DISRUPTED << 16; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3786 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3787 | if (!fast_path_evt) |
| 3788 | break; |
| 3789 | fast_path_evt->un.fabric_evt.event_type = |
| 3790 | FC_REG_FABRIC_EVENT; |
| 3791 | fast_path_evt->un.fabric_evt.subcategory = |
| 3792 | (lpfc_cmd->status == IOSTAT_NPORT_BSY) ? |
| 3793 | LPFC_EVENT_PORT_BUSY : LPFC_EVENT_FABRIC_BUSY; |
| 3794 | if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
| 3795 | memcpy(&fast_path_evt->un.fabric_evt.wwpn, |
| 3796 | &pnode->nlp_portname, |
| 3797 | sizeof(struct lpfc_name)); |
| 3798 | memcpy(&fast_path_evt->un.fabric_evt.wwnn, |
| 3799 | &pnode->nlp_nodename, |
| 3800 | sizeof(struct lpfc_name)); |
| 3801 | } |
| 3802 | fast_path_evt->vport = vport; |
| 3803 | fast_path_evt->work_evt.evt = |
| 3804 | LPFC_EVT_FASTPATH_MGMT_EVT; |
| 3805 | spin_lock_irqsave(&phba->hbalock, flags); |
| 3806 | list_add_tail(&fast_path_evt->work_evt.evt_listp, |
| 3807 | &phba->work_list); |
| 3808 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 3809 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3810 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3811 | case IOSTAT_LOCAL_REJECT: |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3812 | case IOSTAT_REMOTE_STOP: |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 3813 | if (lpfc_cmd->result == IOERR_ELXSEC_KEY_UNWRAP_ERROR || |
| 3814 | lpfc_cmd->result == |
| 3815 | IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR || |
| 3816 | lpfc_cmd->result == IOERR_ELXSEC_CRYPTO_ERROR || |
| 3817 | lpfc_cmd->result == |
| 3818 | IOERR_ELXSEC_CRYPTO_COMPARE_ERROR) { |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 3819 | cmd->result = DID_NO_CONNECT << 16; |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 3820 | break; |
| 3821 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3822 | if (lpfc_cmd->result == IOERR_INVALID_RPI || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3823 | lpfc_cmd->result == IOERR_NO_RESOURCES || |
James Smart | b92938b | 2010-06-07 15:24:12 -0400 | [diff] [blame] | 3824 | lpfc_cmd->result == IOERR_ABORT_REQUESTED || |
| 3825 | lpfc_cmd->result == IOERR_SLER_CMD_RCV_FAILURE) { |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 3826 | cmd->result = DID_REQUEUE << 16; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3827 | break; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3828 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3829 | if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED || |
| 3830 | lpfc_cmd->result == IOERR_TX_DMA_FAILED) && |
| 3831 | pIocbOut->iocb.unsli3.sli3_bg.bgstat) { |
| 3832 | if (scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) { |
| 3833 | /* |
| 3834 | * This is a response for a BG enabled |
| 3835 | * cmd. Parse BG error |
| 3836 | */ |
| 3837 | lpfc_parse_bg_err(phba, lpfc_cmd, |
| 3838 | pIocbOut); |
| 3839 | break; |
| 3840 | } else { |
| 3841 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 3842 | LOG_BG, |
| 3843 | "9031 non-zero BGSTAT " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3844 | "on unprotected cmd\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3845 | } |
| 3846 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3847 | if ((lpfc_cmd->status == IOSTAT_REMOTE_STOP) |
| 3848 | && (phba->sli_rev == LPFC_SLI_REV4) |
| 3849 | && (pnode && NLP_CHK_NODE_ACT(pnode))) { |
| 3850 | /* This IO was aborted by the target, we don't |
| 3851 | * know the rxid and because we did not send the |
| 3852 | * ABTS we cannot generate and RRQ. |
| 3853 | */ |
| 3854 | lpfc_set_rrq_active(phba, pnode, |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 3855 | lpfc_cmd->cur_iocbq.sli4_lxritag, |
| 3856 | 0, 0); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3857 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3858 | /* else: fall through */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3859 | default: |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 3860 | cmd->result = DID_ERROR << 16; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3861 | break; |
| 3862 | } |
| 3863 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3864 | if (!pnode || !NLP_CHK_NODE_ACT(pnode) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3865 | || (pnode->nlp_state != NLP_STE_MAPPED_NODE)) |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 3866 | cmd->result = DID_TRANSPORT_DISRUPTED << 16 | |
| 3867 | SAM_STAT_BUSY; |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 3868 | } else |
Johannes Thumshirn | c6668ca | 2018-07-05 13:01:39 +0200 | [diff] [blame] | 3869 | cmd->result = DID_OK << 16; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3870 | |
| 3871 | if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) { |
| 3872 | uint32_t *lp = (uint32_t *)cmd->sense_buffer; |
| 3873 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3874 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 3875 | "0710 Iodone <%d/%llu> cmd %p, error " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3876 | "x%x SNS x%x x%x Data: x%x x%x\n", |
| 3877 | cmd->device->id, cmd->device->lun, cmd, |
| 3878 | cmd->result, *lp, *(lp + 3), cmd->retries, |
| 3879 | scsi_get_resid(cmd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3880 | } |
| 3881 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3882 | lpfc_update_stats(phba, lpfc_cmd); |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 3883 | if (vport->cfg_max_scsicmpl_time && |
| 3884 | time_after(jiffies, lpfc_cmd->start_time + |
| 3885 | msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3886 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3887 | if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
| 3888 | if (pnode->cmd_qdepth > |
| 3889 | atomic_read(&pnode->cmd_pending) && |
| 3890 | (atomic_read(&pnode->cmd_pending) > |
| 3891 | LPFC_MIN_TGT_QDEPTH) && |
| 3892 | ((cmd->cmnd[0] == READ_10) || |
| 3893 | (cmd->cmnd[0] == WRITE_10))) |
| 3894 | pnode->cmd_qdepth = |
| 3895 | atomic_read(&pnode->cmd_pending); |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 3896 | |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3897 | pnode->last_change_time = jiffies; |
| 3898 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3899 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 3900 | } |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3901 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3902 | |
James Smart | ca7fb76 | 2018-09-10 10:30:44 -0700 | [diff] [blame] | 3903 | /* If pCmd was set to NULL from abort path, do not call scsi_done */ |
| 3904 | if (xchg(&lpfc_cmd->pCmd, NULL) == NULL) { |
| 3905 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
James Smart | 2c4c914 | 2018-11-29 16:09:31 -0800 | [diff] [blame] | 3906 | "5688 FCP cmd already NULL, sid: 0x%06x, " |
James Smart | ca7fb76 | 2018-09-10 10:30:44 -0700 | [diff] [blame] | 3907 | "did: 0x%06x, oxid: 0x%04x\n", |
| 3908 | vport->fc_myDID, |
| 3909 | (pnode) ? pnode->nlp_DID : 0, |
| 3910 | phba->sli_rev == LPFC_SLI_REV4 ? |
| 3911 | lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff); |
| 3912 | return; |
| 3913 | } |
James Smart | 92e3af6 | 2012-08-14 14:26:28 -0400 | [diff] [blame] | 3914 | |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3915 | /* The sdev is not guaranteed to be valid post scsi_done upcall. */ |
| 3916 | cmd->scsi_done(cmd); |
| 3917 | |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 3918 | /* |
| 3919 | * If there is a thread waiting for command completion |
| 3920 | * wake up the thread. |
| 3921 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3922 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 3923 | if (lpfc_cmd->waitq) |
| 3924 | wake_up(lpfc_cmd->waitq); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3925 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 3926 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 3927 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3928 | } |
| 3929 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3930 | /** |
Alexey Kardashevskiy | 8b2564e | 2015-04-28 18:26:22 +1000 | [diff] [blame] | 3931 | * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB |
| 3932 | * @data: A pointer to the immediate command data portion of the IOCB. |
| 3933 | * @fcp_cmnd: The FCP Command that is provided by the SCSI layer. |
| 3934 | * |
| 3935 | * The routine copies the entire FCP command from @fcp_cmnd to @data while |
| 3936 | * byte swapping the data to big endian format for transmission on the wire. |
| 3937 | **/ |
| 3938 | static void |
| 3939 | lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd) |
| 3940 | { |
| 3941 | int i, j; |
| 3942 | for (i = 0, j = 0; i < sizeof(struct fcp_cmnd); |
| 3943 | i += sizeof(uint32_t), j++) { |
| 3944 | ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]); |
| 3945 | } |
| 3946 | } |
| 3947 | |
| 3948 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3949 | * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3950 | * @vport: The virtual port for which this call is being executed. |
| 3951 | * @lpfc_cmd: The scsi command which needs to send. |
| 3952 | * @pnode: Pointer to lpfc_nodelist. |
| 3953 | * |
| 3954 | * This routine initializes fcp_cmnd and iocb data structure from scsi command |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3955 | * to transfer for device with SLI3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3956 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3957 | static void |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3958 | lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3959 | struct lpfc_nodelist *pnode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3960 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3961 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3962 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 3963 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 3964 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 3965 | struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq); |
| 3966 | int datadir = scsi_cmnd->sc_data_direction; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 3967 | uint8_t *ptr; |
| 3968 | bool sli4; |
James Smart | 98bbf5f | 2013-09-06 12:18:45 -0400 | [diff] [blame] | 3969 | uint32_t fcpdl; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3970 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3971 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 3972 | return; |
| 3973 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3974 | lpfc_cmd->fcp_rsp->rspSnsLen = 0; |
James.Smart@Emulex.Com | 69859dc | 2005-08-10 15:02:37 -0400 | [diff] [blame] | 3975 | /* clear task management bits */ |
| 3976 | lpfc_cmd->fcp_cmnd->fcpCntl2 = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3977 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 3978 | int_to_scsilun(lpfc_cmd->pCmd->device->lun, |
| 3979 | &lpfc_cmd->fcp_cmnd->fcp_lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3980 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 3981 | ptr = &fcp_cmnd->fcpCdb[0]; |
| 3982 | memcpy(ptr, scsi_cmnd->cmnd, scsi_cmnd->cmd_len); |
| 3983 | if (scsi_cmnd->cmd_len < LPFC_FCP_CDB_LEN) { |
| 3984 | ptr += scsi_cmnd->cmd_len; |
| 3985 | memset(ptr, 0, (LPFC_FCP_CDB_LEN - scsi_cmnd->cmd_len)); |
| 3986 | } |
| 3987 | |
Christoph Hellwig | 5066863 | 2014-10-30 14:30:06 +0100 | [diff] [blame] | 3988 | fcp_cmnd->fcpCntl1 = SIMPLE_Q; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3989 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 3990 | sli4 = (phba->sli_rev == LPFC_SLI_REV4); |
James Smart | 6acb348 | 2014-04-04 13:51:25 -0400 | [diff] [blame] | 3991 | piocbq->iocb.un.fcpi.fcpi_XRdy = 0; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 3992 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3993 | /* |
| 3994 | * There are three possibilities here - use scatter-gather segment, use |
| 3995 | * the single mapping, or neither. Start the lpfc command prep by |
| 3996 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 3997 | * data bde entry. |
| 3998 | */ |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3999 | if (scsi_sg_count(scsi_cmnd)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4000 | if (datadir == DMA_TO_DEVICE) { |
| 4001 | iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR; |
James Smart | 182ba75 | 2013-07-15 18:34:05 -0400 | [diff] [blame] | 4002 | iocb_cmd->ulpPU = PARM_READ_CHECK; |
James Smart | 3cb01c5 | 2013-07-15 18:35:04 -0400 | [diff] [blame] | 4003 | if (vport->cfg_first_burst_size && |
| 4004 | (pnode->nlp_flag & NLP_FIRSTBURST)) { |
James Smart | 98bbf5f | 2013-09-06 12:18:45 -0400 | [diff] [blame] | 4005 | fcpdl = scsi_bufflen(scsi_cmnd); |
| 4006 | if (fcpdl < vport->cfg_first_burst_size) |
| 4007 | piocbq->iocb.un.fcpi.fcpi_XRdy = fcpdl; |
| 4008 | else |
| 4009 | piocbq->iocb.un.fcpi.fcpi_XRdy = |
| 4010 | vport->cfg_first_burst_size; |
James Smart | 3cb01c5 | 2013-07-15 18:35:04 -0400 | [diff] [blame] | 4011 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4012 | fcp_cmnd->fcpCntl3 = WRITE_DATA; |
James Smart | 2cee780 | 2017-06-01 21:07:02 -0700 | [diff] [blame] | 4013 | atomic_inc(&phba->fc4ScsiOutputRequests); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4014 | } else { |
| 4015 | iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR; |
| 4016 | iocb_cmd->ulpPU = PARM_READ_CHECK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4017 | fcp_cmnd->fcpCntl3 = READ_DATA; |
James Smart | 2cee780 | 2017-06-01 21:07:02 -0700 | [diff] [blame] | 4018 | atomic_inc(&phba->fc4ScsiInputRequests); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4019 | } |
| 4020 | } else { |
| 4021 | iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR; |
| 4022 | iocb_cmd->un.fcpi.fcpi_parm = 0; |
| 4023 | iocb_cmd->ulpPU = 0; |
| 4024 | fcp_cmnd->fcpCntl3 = 0; |
James Smart | 2cee780 | 2017-06-01 21:07:02 -0700 | [diff] [blame] | 4025 | atomic_inc(&phba->fc4ScsiControlRequests); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4026 | } |
Alexey Kardashevskiy | 8b2564e | 2015-04-28 18:26:22 +1000 | [diff] [blame] | 4027 | if (phba->sli_rev == 3 && |
| 4028 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) |
| 4029 | lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4030 | /* |
| 4031 | * Finish initializing those IOCB fields that are independent |
| 4032 | * of the scsi_cmnd request_buffer |
| 4033 | */ |
| 4034 | piocbq->iocb.ulpContext = pnode->nlp_rpi; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4035 | if (sli4) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4036 | piocbq->iocb.ulpContext = |
| 4037 | phba->sli4_hba.rpi_ids[pnode->nlp_rpi]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4038 | if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE) |
| 4039 | piocbq->iocb.ulpFCP2Rcvy = 1; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4040 | else |
| 4041 | piocbq->iocb.ulpFCP2Rcvy = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4042 | |
| 4043 | piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f); |
| 4044 | piocbq->context1 = lpfc_cmd; |
| 4045 | piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; |
| 4046 | piocbq->iocb.ulpTimeout = lpfc_cmd->timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4047 | piocbq->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4048 | } |
| 4049 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4050 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4051 | * 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] | 4052 | * @vport: The virtual port for which this call is being executed. |
| 4053 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. |
| 4054 | * @lun: Logical unit number. |
| 4055 | * @task_mgmt_cmd: SCSI task management command. |
| 4056 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4057 | * This routine creates FCP information unit corresponding to @task_mgmt_cmd |
| 4058 | * for device with SLI-3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4059 | * |
| 4060 | * Return codes: |
| 4061 | * 0 - Error |
| 4062 | * 1 - Success |
| 4063 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4064 | static int |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4065 | lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4066 | struct lpfc_scsi_buf *lpfc_cmd, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4067 | uint64_t lun, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4068 | uint8_t task_mgmt_cmd) |
| 4069 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4070 | struct lpfc_iocbq *piocbq; |
| 4071 | IOCB_t *piocb; |
| 4072 | struct fcp_cmnd *fcp_cmnd; |
James Smart | 0b18ac4 | 2006-05-01 21:50:40 -0400 | [diff] [blame] | 4073 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4074 | struct lpfc_nodelist *ndlp = rdata->pnode; |
| 4075 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4076 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || |
| 4077 | ndlp->nlp_state != NLP_STE_MAPPED_NODE) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4078 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4079 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4080 | piocbq = &(lpfc_cmd->cur_iocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4081 | piocbq->vport = vport; |
| 4082 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4083 | piocb = &piocbq->iocb; |
| 4084 | |
| 4085 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4086 | /* Clear out any old data in the FCP command area */ |
| 4087 | memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd)); |
| 4088 | int_to_scsilun(lun, &fcp_cmnd->fcp_lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4089 | fcp_cmnd->fcpCntl2 = task_mgmt_cmd; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4090 | if (vport->phba->sli_rev == 3 && |
| 4091 | !(vport->phba->sli3_options & LPFC_SLI3_BG_ENABLED)) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4092 | lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4093 | piocb->ulpCommand = CMD_FCP_ICMND64_CR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4094 | piocb->ulpContext = ndlp->nlp_rpi; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4095 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
| 4096 | piocb->ulpContext = |
| 4097 | vport->phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
| 4098 | } |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 4099 | piocb->ulpFCP2Rcvy = (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) ? 1 : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4100 | piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f); |
James Smart | f9226c2 | 2014-02-20 09:57:28 -0500 | [diff] [blame] | 4101 | piocb->ulpPU = 0; |
| 4102 | piocb->un.fcpi.fcpi_parm = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4103 | |
| 4104 | /* ulpTimeout is only one byte */ |
| 4105 | if (lpfc_cmd->timeout > 0xff) { |
| 4106 | /* |
| 4107 | * Do not timeout the command at the firmware level. |
| 4108 | * The driver will provide the timeout mechanism. |
| 4109 | */ |
| 4110 | piocb->ulpTimeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4111 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4112 | piocb->ulpTimeout = lpfc_cmd->timeout; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4113 | |
| 4114 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 4115 | lpfc_sli4_set_rsp_sgl_last(vport->phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4116 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4117 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4118 | } |
| 4119 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4120 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4121 | * lpfc_scsi_api_table_setup - Set up scsi api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4122 | * @phba: The hba struct for which this call is being executed. |
| 4123 | * @dev_grp: The HBA PCI-Device group number. |
| 4124 | * |
| 4125 | * This routine sets up the SCSI interface API function jump table in @phba |
| 4126 | * struct. |
| 4127 | * Returns: 0 - success, -ENODEV - failure. |
| 4128 | **/ |
| 4129 | int |
| 4130 | lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 4131 | { |
| 4132 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4133 | phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf; |
| 4134 | phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4135 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4136 | switch (dev_grp) { |
| 4137 | case LPFC_PCI_DEV_LP: |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4138 | phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4139 | 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] | 4140 | phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4141 | phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s3; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4142 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4143 | case LPFC_PCI_DEV_OC: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4144 | phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s4; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4145 | 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] | 4146 | phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s4; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4147 | phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s4; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4148 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4149 | default: |
| 4150 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4151 | "1418 Invalid HBA PCI-device group: 0x%x\n", |
| 4152 | dev_grp); |
| 4153 | return -ENODEV; |
| 4154 | break; |
| 4155 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4156 | phba->lpfc_rampdown_queue_depth = lpfc_rampdown_queue_depth; |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 4157 | phba->lpfc_scsi_cmd_iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4158 | return 0; |
| 4159 | } |
| 4160 | |
| 4161 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4162 | * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4163 | * @phba: The Hba for which this call is being executed. |
| 4164 | * @cmdiocbq: Pointer to lpfc_iocbq data structure. |
| 4165 | * @rspiocbq: Pointer to lpfc_iocbq data structure. |
| 4166 | * |
| 4167 | * This routine is IOCB completion routine for device reset and target reset |
| 4168 | * routine. This routine release scsi buffer associated with lpfc_cmd. |
| 4169 | **/ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4170 | static void |
| 4171 | lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba, |
| 4172 | struct lpfc_iocbq *cmdiocbq, |
| 4173 | struct lpfc_iocbq *rspiocbq) |
| 4174 | { |
| 4175 | struct lpfc_scsi_buf *lpfc_cmd = |
| 4176 | (struct lpfc_scsi_buf *) cmdiocbq->context1; |
| 4177 | if (lpfc_cmd) |
| 4178 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 4179 | return; |
| 4180 | } |
| 4181 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4182 | /** |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 4183 | * lpfc_check_pci_resettable - Walks list of devices on pci_dev's bus to check |
| 4184 | * if issuing a pci_bus_reset is possibly unsafe |
| 4185 | * @phba: lpfc_hba pointer. |
| 4186 | * |
| 4187 | * Description: |
| 4188 | * Walks the bus_list to ensure only PCI devices with Emulex |
| 4189 | * vendor id, device ids that support hot reset, and only one occurrence |
| 4190 | * of function 0. |
| 4191 | * |
| 4192 | * Returns: |
| 4193 | * -EBADSLT, detected invalid device |
| 4194 | * 0, successful |
| 4195 | */ |
| 4196 | int |
| 4197 | lpfc_check_pci_resettable(const struct lpfc_hba *phba) |
| 4198 | { |
| 4199 | const struct pci_dev *pdev = phba->pcidev; |
| 4200 | struct pci_dev *ptr = NULL; |
| 4201 | u8 counter = 0; |
| 4202 | |
| 4203 | /* Walk the list of devices on the pci_dev's bus */ |
| 4204 | list_for_each_entry(ptr, &pdev->bus->devices, bus_list) { |
| 4205 | /* Check for Emulex Vendor ID */ |
| 4206 | if (ptr->vendor != PCI_VENDOR_ID_EMULEX) { |
| 4207 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4208 | "8346 Non-Emulex vendor found: " |
| 4209 | "0x%04x\n", ptr->vendor); |
| 4210 | return -EBADSLT; |
| 4211 | } |
| 4212 | |
| 4213 | /* Check for valid Emulex Device ID */ |
| 4214 | switch (ptr->device) { |
| 4215 | case PCI_DEVICE_ID_LANCER_FC: |
| 4216 | case PCI_DEVICE_ID_LANCER_G6_FC: |
| 4217 | case PCI_DEVICE_ID_LANCER_G7_FC: |
| 4218 | break; |
| 4219 | default: |
| 4220 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4221 | "8347 Invalid device found: " |
| 4222 | "0x%04x\n", ptr->device); |
| 4223 | return -EBADSLT; |
| 4224 | } |
| 4225 | |
| 4226 | /* Check for only one function 0 ID to ensure only one HBA on |
| 4227 | * secondary bus |
| 4228 | */ |
| 4229 | if (ptr->devfn == 0) { |
| 4230 | if (++counter > 1) { |
| 4231 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4232 | "8348 More than one device on " |
| 4233 | "secondary bus found\n"); |
| 4234 | return -EBADSLT; |
| 4235 | } |
| 4236 | } |
| 4237 | } |
| 4238 | |
| 4239 | return 0; |
| 4240 | } |
| 4241 | |
| 4242 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4243 | * lpfc_info - Info entry point of scsi_host_template data structure |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4244 | * @host: The scsi host for which this call is being executed. |
| 4245 | * |
| 4246 | * This routine provides module information about hba. |
| 4247 | * |
| 4248 | * Reutrn code: |
| 4249 | * Pointer to char - Success. |
| 4250 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4251 | const char * |
| 4252 | lpfc_info(struct Scsi_Host *host) |
| 4253 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4254 | struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata; |
| 4255 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 4256 | int link_speed = 0; |
| 4257 | static char lpfcinfobuf[384]; |
| 4258 | char tmp[384] = {0}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4259 | |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 4260 | memset(lpfcinfobuf, 0, sizeof(lpfcinfobuf)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4261 | if (phba && phba->pcidev){ |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 4262 | /* Model Description */ |
| 4263 | scnprintf(tmp, sizeof(tmp), phba->ModelDesc); |
| 4264 | if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >= |
| 4265 | sizeof(lpfcinfobuf)) |
| 4266 | goto buffer_done; |
| 4267 | |
| 4268 | /* PCI Info */ |
| 4269 | scnprintf(tmp, sizeof(tmp), |
| 4270 | " on PCI bus %02x device %02x irq %d", |
| 4271 | phba->pcidev->bus->number, phba->pcidev->devfn, |
| 4272 | phba->pcidev->irq); |
| 4273 | if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >= |
| 4274 | sizeof(lpfcinfobuf)) |
| 4275 | goto buffer_done; |
| 4276 | |
| 4277 | /* Port Number */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4278 | if (phba->Port[0]) { |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 4279 | scnprintf(tmp, sizeof(tmp), " port %s", phba->Port); |
| 4280 | if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >= |
| 4281 | sizeof(lpfcinfobuf)) |
| 4282 | goto buffer_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4283 | } |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 4284 | |
| 4285 | /* Link Speed */ |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 4286 | link_speed = lpfc_sli_port_speed_get(phba); |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 4287 | if (link_speed != 0) { |
| 4288 | scnprintf(tmp, sizeof(tmp), |
| 4289 | " Logical Link Speed: %d Mbps", link_speed); |
| 4290 | if (strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)) >= |
| 4291 | sizeof(lpfcinfobuf)) |
| 4292 | goto buffer_done; |
| 4293 | } |
| 4294 | |
| 4295 | /* PCI resettable */ |
| 4296 | if (!lpfc_check_pci_resettable(phba)) { |
| 4297 | scnprintf(tmp, sizeof(tmp), " PCI resettable"); |
| 4298 | strlcat(lpfcinfobuf, tmp, sizeof(lpfcinfobuf)); |
| 4299 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4300 | } |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 4301 | |
| 4302 | buffer_done: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4303 | return lpfcinfobuf; |
| 4304 | } |
| 4305 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4306 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4307 | * lpfc_poll_rearm_time - Routine to modify fcp_poll timer of hba |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4308 | * @phba: The Hba for which this call is being executed. |
| 4309 | * |
| 4310 | * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo. |
| 4311 | * The default value of cfg_poll_tmo is 10 milliseconds. |
| 4312 | **/ |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4313 | static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba) |
| 4314 | { |
| 4315 | unsigned long poll_tmo_expires = |
| 4316 | (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo)); |
| 4317 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4318 | 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] | 4319 | mod_timer(&phba->fcp_poll_timer, |
| 4320 | poll_tmo_expires); |
| 4321 | } |
| 4322 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4323 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4324 | * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4325 | * @phba: The Hba for which this call is being executed. |
| 4326 | * |
| 4327 | * This routine starts the fcp_poll_timer of @phba. |
| 4328 | **/ |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4329 | void lpfc_poll_start_timer(struct lpfc_hba * phba) |
| 4330 | { |
| 4331 | lpfc_poll_rearm_timer(phba); |
| 4332 | } |
| 4333 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4334 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4335 | * lpfc_poll_timeout - Restart polling timer |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4336 | * @ptr: Map to lpfc_hba data structure pointer. |
| 4337 | * |
| 4338 | * This routine restarts fcp_poll timer, when FCP ring polling is enable |
| 4339 | * and FCP Ring interrupt is disable. |
| 4340 | **/ |
| 4341 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4342 | void lpfc_poll_timeout(struct timer_list *t) |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4343 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4344 | 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] | 4345 | |
| 4346 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4347 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4348 | &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4349 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4350 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 4351 | lpfc_poll_rearm_timer(phba); |
| 4352 | } |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4353 | } |
| 4354 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4355 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4356 | * lpfc_queuecommand - scsi_host_template queuecommand entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4357 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 4358 | * @done: Pointer to done routine. |
| 4359 | * |
| 4360 | * Driver registers this routine to scsi midlayer to submit a @cmd to process. |
| 4361 | * This routine prepares an IOCB from scsi command and provides to firmware. |
| 4362 | * The @done callback is invoked after driver finished processing the command. |
| 4363 | * |
| 4364 | * Return value : |
| 4365 | * 0 - Success |
| 4366 | * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily. |
| 4367 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4368 | static int |
James Smart | b9a7c63 | 2012-08-03 12:35:24 -0400 | [diff] [blame] | 4369 | lpfc_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4370 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4371 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4372 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 4373 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 4374 | struct lpfc_nodelist *ndlp; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4375 | struct lpfc_scsi_buf *lpfc_cmd; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4376 | struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device)); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4377 | int err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4378 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 4379 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 4380 | |
| 4381 | /* sanity check on references */ |
| 4382 | if (unlikely(!rdata) || unlikely(!rport)) |
| 4383 | goto out_fail_command; |
| 4384 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4385 | err = fc_remote_port_chkready(rport); |
| 4386 | if (err) { |
| 4387 | cmnd->result = err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4388 | goto out_fail_command; |
| 4389 | } |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 4390 | ndlp = rdata->pnode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4391 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 4392 | if ((scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) && |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4393 | (!(phba->sli3_options & LPFC_SLI3_BG_ENABLED))) { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4394 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4395 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 4396 | "9058 BLKGRD: ERROR: rcvd protected cmd:%02x" |
| 4397 | " op:%02x str=%s without registering for" |
| 4398 | " BlockGuard - Rejecting command\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4399 | cmnd->cmnd[0], scsi_get_prot_op(cmnd), |
| 4400 | dif_op_str[scsi_get_prot_op(cmnd)]); |
| 4401 | goto out_fail_command; |
| 4402 | } |
| 4403 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4404 | /* |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4405 | * Catch race where our node has transitioned, but the |
| 4406 | * transport is still transitioning. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4407 | */ |
James Smart | 6b415f5 | 2012-06-12 13:54:59 -0400 | [diff] [blame] | 4408 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 4409 | goto out_tgt_busy; |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 4410 | if (lpfc_ndlp_check_qdepth(phba, ndlp)) { |
| 4411 | if (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth) { |
| 4412 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_ERROR, |
| 4413 | "3377 Target Queue Full, scsi Id:%d " |
| 4414 | "Qdepth:%d Pending command:%d" |
| 4415 | " WWNN:%02x:%02x:%02x:%02x:" |
| 4416 | "%02x:%02x:%02x:%02x, " |
| 4417 | " WWPN:%02x:%02x:%02x:%02x:" |
| 4418 | "%02x:%02x:%02x:%02x", |
| 4419 | ndlp->nlp_sid, ndlp->cmd_qdepth, |
| 4420 | atomic_read(&ndlp->cmd_pending), |
| 4421 | ndlp->nlp_nodename.u.wwn[0], |
| 4422 | ndlp->nlp_nodename.u.wwn[1], |
| 4423 | ndlp->nlp_nodename.u.wwn[2], |
| 4424 | ndlp->nlp_nodename.u.wwn[3], |
| 4425 | ndlp->nlp_nodename.u.wwn[4], |
| 4426 | ndlp->nlp_nodename.u.wwn[5], |
| 4427 | ndlp->nlp_nodename.u.wwn[6], |
| 4428 | ndlp->nlp_nodename.u.wwn[7], |
| 4429 | ndlp->nlp_portname.u.wwn[0], |
| 4430 | ndlp->nlp_portname.u.wwn[1], |
| 4431 | ndlp->nlp_portname.u.wwn[2], |
| 4432 | ndlp->nlp_portname.u.wwn[3], |
| 4433 | ndlp->nlp_portname.u.wwn[4], |
| 4434 | ndlp->nlp_portname.u.wwn[5], |
| 4435 | ndlp->nlp_portname.u.wwn[6], |
| 4436 | ndlp->nlp_portname.u.wwn[7]); |
| 4437 | goto out_tgt_busy; |
| 4438 | } |
James Smart | 64bf009 | 2018-01-30 15:58:53 -0800 | [diff] [blame] | 4439 | } |
James Smart | f91bc59 | 2018-04-09 14:24:22 -0700 | [diff] [blame] | 4440 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4441 | lpfc_cmd = lpfc_get_scsi_buf(phba, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4442 | if (lpfc_cmd == NULL) { |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4443 | lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4444 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4445 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_ERROR, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4446 | "0707 driver's buffer pool is empty, " |
| 4447 | "IO busied\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4448 | goto out_host_busy; |
| 4449 | } |
| 4450 | |
| 4451 | /* |
| 4452 | * Store the midlayer's command structure for the completion phase |
| 4453 | * and complete the command initialization. |
| 4454 | */ |
| 4455 | lpfc_cmd->pCmd = cmnd; |
| 4456 | lpfc_cmd->rdata = rdata; |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 4457 | lpfc_cmd->ndlp = ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4458 | cmnd->host_scribble = (unsigned char *)lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4459 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4460 | if (scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4461 | if (vport->phba->cfg_enable_bg) { |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 4462 | lpfc_printf_vlog(vport, |
| 4463 | KERN_INFO, LOG_SCSI_CMD, |
James Smart | 2613470 | 2012-08-14 14:25:50 -0400 | [diff] [blame] | 4464 | "9033 BLKGRD: rcvd %s cmd:x%x " |
| 4465 | "sector x%llx cnt %u pt %x\n", |
| 4466 | dif_op_str[scsi_get_prot_op(cmnd)], |
| 4467 | cmnd->cmnd[0], |
| 4468 | (unsigned long long)scsi_get_lba(cmnd), |
| 4469 | blk_rq_sectors(cmnd->request), |
| 4470 | (cmnd->cmnd[1]>>5)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4471 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4472 | err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 4473 | } else { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4474 | if (vport->phba->cfg_enable_bg) { |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 4475 | lpfc_printf_vlog(vport, |
| 4476 | KERN_INFO, LOG_SCSI_CMD, |
James Smart | 2613470 | 2012-08-14 14:25:50 -0400 | [diff] [blame] | 4477 | "9038 BLKGRD: rcvd PROT_NORMAL cmd: " |
| 4478 | "x%x sector x%llx cnt %u pt %x\n", |
| 4479 | cmnd->cmnd[0], |
| 4480 | (unsigned long long)scsi_get_lba(cmnd), |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 4481 | blk_rq_sectors(cmnd->request), |
James Smart | 2613470 | 2012-08-14 14:25:50 -0400 | [diff] [blame] | 4482 | (cmnd->cmnd[1]>>5)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4483 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4484 | err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 4485 | } |
| 4486 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4487 | if (err) |
| 4488 | goto out_host_busy_free_buf; |
| 4489 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4490 | lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4491 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4492 | err = lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4493 | &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4494 | if (err) { |
James Smart | 76f96b6 | 2013-12-17 20:29:01 -0500 | [diff] [blame] | 4495 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4496 | "3376 FCP could not issue IOCB err %x" |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4497 | "FCP cmd x%x <%d/%llu> " |
James Smart | 76f96b6 | 2013-12-17 20:29:01 -0500 | [diff] [blame] | 4498 | "sid: x%x did: x%x oxid: x%x " |
| 4499 | "Data: x%x x%x x%x x%x\n", |
| 4500 | err, cmnd->cmnd[0], |
| 4501 | cmnd->device ? cmnd->device->id : 0xffff, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4502 | cmnd->device ? cmnd->device->lun : (u64) -1, |
James Smart | 76f96b6 | 2013-12-17 20:29:01 -0500 | [diff] [blame] | 4503 | vport->fc_myDID, ndlp->nlp_DID, |
| 4504 | phba->sli_rev == LPFC_SLI_REV4 ? |
| 4505 | lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff, |
| 4506 | lpfc_cmd->cur_iocbq.iocb.ulpContext, |
| 4507 | lpfc_cmd->cur_iocbq.iocb.ulpIoTag, |
| 4508 | lpfc_cmd->cur_iocbq.iocb.ulpTimeout, |
| 4509 | (uint32_t) |
| 4510 | (cmnd->request->timeout / 1000)); |
| 4511 | |
James Smart | 2cee780 | 2017-06-01 21:07:02 -0700 | [diff] [blame] | 4512 | switch (lpfc_cmd->fcp_cmnd->fcpCntl3) { |
| 4513 | case WRITE_DATA: |
| 4514 | atomic_dec(&phba->fc4ScsiOutputRequests); |
| 4515 | break; |
| 4516 | case READ_DATA: |
| 4517 | atomic_dec(&phba->fc4ScsiInputRequests); |
| 4518 | break; |
| 4519 | default: |
| 4520 | atomic_dec(&phba->fc4ScsiControlRequests); |
| 4521 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4522 | goto out_host_busy_free_buf; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4523 | } |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4524 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4525 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4526 | &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4527 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4528 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 4529 | lpfc_poll_rearm_timer(phba); |
| 4530 | } |
| 4531 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4532 | return 0; |
| 4533 | |
| 4534 | out_host_busy_free_buf: |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 4535 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4536 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4537 | out_host_busy: |
| 4538 | return SCSI_MLQUEUE_HOST_BUSY; |
| 4539 | |
Mike Christie | 3496343 | 2011-02-25 14:04:28 -0600 | [diff] [blame] | 4540 | out_tgt_busy: |
| 4541 | return SCSI_MLQUEUE_TARGET_BUSY; |
| 4542 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4543 | out_fail_command: |
James Smart | b9a7c63 | 2012-08-03 12:35:24 -0400 | [diff] [blame] | 4544 | cmnd->scsi_done(cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4545 | return 0; |
| 4546 | } |
| 4547 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 4548 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4549 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4550 | * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4551 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 4552 | * |
| 4553 | * This routine aborts @cmnd pending in base driver. |
| 4554 | * |
| 4555 | * Return code : |
| 4556 | * 0x2003 - Error |
| 4557 | * 0x2002 - Success |
| 4558 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4559 | static int |
James.Smart@Emulex.Com | 63c59c3 | 2005-11-28 11:41:53 -0500 | [diff] [blame] | 4560 | lpfc_abort_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4561 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4562 | struct Scsi_Host *shost = cmnd->device->host; |
| 4563 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4564 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4565 | struct lpfc_iocbq *iocb; |
| 4566 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4567 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4568 | IOCB_t *cmd, *icmd; |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4569 | int ret = SUCCESS, status = 0; |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 4570 | struct lpfc_sli_ring *pring_s4 = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4571 | int ret_val; |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 4572 | unsigned long flags; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4573 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4574 | |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4575 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 4576 | if (status != 0 && status != SUCCESS) |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4577 | return status; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4578 | |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4579 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4580 | /* driver queued commands are in process of being flushed */ |
| 4581 | if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) { |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4582 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4583 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4584 | "3168 SCSI Layer abort requested I/O has been " |
| 4585 | "flushed by LLD.\n"); |
| 4586 | return FAILED; |
| 4587 | } |
| 4588 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4589 | lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble; |
James Smart | 92e3af6 | 2012-08-14 14:26:28 -0400 | [diff] [blame] | 4590 | if (!lpfc_cmd || !lpfc_cmd->pCmd) { |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4591 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 4592 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4593 | "2873 SCSI Layer I/O Abort Request IO CMPL Status " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4594 | "x%x ID %d LUN %llu\n", |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4595 | SUCCESS, cmnd->device->id, cmnd->device->lun); |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 4596 | return SUCCESS; |
| 4597 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4598 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4599 | iocb = &lpfc_cmd->cur_iocbq; |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 4600 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame^] | 4601 | pring_s4 = phba->sli4_hba.hdwq[iocb->hba_wqidx].fcp_wq->pring; |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 4602 | if (!pring_s4) { |
| 4603 | ret = FAILED; |
| 4604 | goto out_unlock; |
| 4605 | } |
| 4606 | spin_lock(&pring_s4->ring_lock); |
| 4607 | } |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4608 | /* the command is in process of being cancelled */ |
| 4609 | if (!(iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ)) { |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 4610 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4611 | spin_unlock(&pring_s4->ring_lock); |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4612 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4613 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4614 | "3169 SCSI Layer abort requested I/O has been " |
| 4615 | "cancelled by LLD.\n"); |
| 4616 | return FAILED; |
| 4617 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4618 | /* |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4619 | * If pCmd field of the corresponding lpfc_scsi_buf structure |
| 4620 | * points to a different SCSI command, then the driver has |
| 4621 | * already completed this command, but the midlayer did not |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4622 | * see the completion before the eh fired. Just return SUCCESS. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4623 | */ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4624 | if (lpfc_cmd->pCmd != cmnd) { |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 4625 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4626 | spin_unlock(&pring_s4->ring_lock); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4627 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4628 | "3170 SCSI Layer abort requested I/O has been " |
| 4629 | "completed by LLD.\n"); |
| 4630 | goto out_unlock; |
| 4631 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4632 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4633 | BUG_ON(iocb->context1 != lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4634 | |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4635 | /* abort issued in recovery is still in progress */ |
| 4636 | if (iocb->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 4637 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4638 | "3389 SCSI Layer I/O Abort Request is pending\n"); |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 4639 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4640 | spin_unlock(&pring_s4->ring_lock); |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4641 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4642 | goto wait_for_cmpl; |
| 4643 | } |
| 4644 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4645 | abtsiocb = __lpfc_sli_get_iocbq(phba); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4646 | if (abtsiocb == NULL) { |
| 4647 | ret = FAILED; |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 4648 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4649 | spin_unlock(&pring_s4->ring_lock); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4650 | goto out_unlock; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4651 | } |
| 4652 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 4653 | /* Indicate the IO is being aborted by the driver. */ |
| 4654 | iocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 4655 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4656 | /* |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4657 | * The scsi command can not be in txq and it is in flight because the |
| 4658 | * pCmd is still pointig at the SCSI command we have to abort. There |
| 4659 | * is no need to search the txcmplq. Just send an abort to the FW. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4660 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4661 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4662 | cmd = &iocb->iocb; |
| 4663 | icmd = &abtsiocb->iocb; |
| 4664 | icmd->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 4665 | icmd->un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4666 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4667 | icmd->un.acxri.abortIoTag = iocb->sli4_xritag; |
| 4668 | else |
| 4669 | icmd->un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4670 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4671 | icmd->ulpLe = 1; |
| 4672 | icmd->ulpClass = cmd->ulpClass; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4673 | |
| 4674 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4675 | abtsiocb->hba_wqidx = iocb->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 4676 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 4677 | if (iocb->iocb_flag & LPFC_IO_FOF) |
| 4678 | abtsiocb->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4679 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4680 | if (lpfc_is_link_up(phba)) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4681 | icmd->ulpCommand = CMD_ABORT_XRI_CN; |
| 4682 | else |
| 4683 | icmd->ulpCommand = CMD_CLOSE_XRI_CN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4684 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4685 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4686 | abtsiocb->vport = vport; |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 4687 | lpfc_cmd->waitq = &waitq; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4688 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4689 | /* Note: both hbalock and ring_lock must be set here */ |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4690 | ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 4691 | abtsiocb, 0); |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 4692 | spin_unlock(&pring_s4->ring_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4693 | } else { |
| 4694 | ret_val = __lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, |
| 4695 | abtsiocb, 0); |
| 4696 | } |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4697 | /* no longer need the lock after this point */ |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4698 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4699 | |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4700 | |
| 4701 | if (ret_val == IOCB_ERROR) { |
James Smart | 8931c73 | 2018-07-31 17:23:20 -0700 | [diff] [blame] | 4702 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4703 | spin_lock_irqsave(&pring_s4->ring_lock, flags); |
| 4704 | else |
| 4705 | spin_lock_irqsave(&phba->hbalock, flags); |
| 4706 | /* Indicate the IO is not being aborted by the driver. */ |
| 4707 | iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 4708 | lpfc_cmd->waitq = NULL; |
| 4709 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4710 | spin_unlock_irqrestore(&pring_s4->ring_lock, flags); |
| 4711 | else |
| 4712 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4713 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| 4714 | ret = FAILED; |
| 4715 | goto out; |
| 4716 | } |
| 4717 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4718 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4719 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4720 | &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4721 | |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4722 | wait_for_cmpl: |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4723 | /* Wait for abort to complete */ |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4724 | wait_event_timeout(waitq, |
| 4725 | (lpfc_cmd->pCmd != cmnd), |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4726 | msecs_to_jiffies(2*vport->cfg_devloss_tmo*1000)); |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4727 | |
| 4728 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4729 | lpfc_cmd->waitq = NULL; |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4730 | spin_unlock_irqrestore(shost->host_lock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4731 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4732 | if (lpfc_cmd->pCmd == cmnd) { |
| 4733 | ret = FAILED; |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4734 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 4735 | "0748 abort handler timed out waiting " |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 4736 | "for aborting I/O (xri:x%x) to complete: " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4737 | "ret %#x, ID %d, LUN %llu\n", |
James Smart | 247ca94 | 2012-08-14 14:26:13 -0400 | [diff] [blame] | 4738 | iocb->sli4_xritag, ret, |
| 4739 | cmnd->device->id, cmnd->device->lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4740 | } |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4741 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4742 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4743 | out_unlock: |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4744 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4745 | out: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4746 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4747 | "0749 SCSI Layer I/O Abort Request Status x%x ID %d " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4748 | "LUN %llu\n", ret, cmnd->device->id, |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 4749 | cmnd->device->lun); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4750 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4751 | } |
| 4752 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4753 | static char * |
| 4754 | lpfc_taskmgmt_name(uint8_t task_mgmt_cmd) |
| 4755 | { |
| 4756 | switch (task_mgmt_cmd) { |
| 4757 | case FCP_ABORT_TASK_SET: |
| 4758 | return "ABORT_TASK_SET"; |
| 4759 | case FCP_CLEAR_TASK_SET: |
| 4760 | return "FCP_CLEAR_TASK_SET"; |
| 4761 | case FCP_BUS_RESET: |
| 4762 | return "FCP_BUS_RESET"; |
| 4763 | case FCP_LUN_RESET: |
| 4764 | return "FCP_LUN_RESET"; |
| 4765 | case FCP_TARGET_RESET: |
| 4766 | return "FCP_TARGET_RESET"; |
| 4767 | case FCP_CLEAR_ACA: |
| 4768 | return "FCP_CLEAR_ACA"; |
| 4769 | case FCP_TERMINATE_TASK: |
| 4770 | return "FCP_TERMINATE_TASK"; |
| 4771 | default: |
| 4772 | return "unknown"; |
| 4773 | } |
| 4774 | } |
| 4775 | |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 4776 | |
| 4777 | /** |
| 4778 | * lpfc_check_fcp_rsp - check the returned fcp_rsp to see if task failed |
| 4779 | * @vport: The virtual port for which this call is being executed. |
| 4780 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. |
| 4781 | * |
| 4782 | * This routine checks the FCP RSP INFO to see if the tsk mgmt command succeded |
| 4783 | * |
| 4784 | * Return code : |
| 4785 | * 0x2003 - Error |
| 4786 | * 0x2002 - Success |
| 4787 | **/ |
| 4788 | static int |
| 4789 | lpfc_check_fcp_rsp(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd) |
| 4790 | { |
| 4791 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
| 4792 | uint32_t rsp_info; |
| 4793 | uint32_t rsp_len; |
| 4794 | uint8_t rsp_info_code; |
| 4795 | int ret = FAILED; |
| 4796 | |
| 4797 | |
| 4798 | if (fcprsp == NULL) |
| 4799 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4800 | "0703 fcp_rsp is missing\n"); |
| 4801 | else { |
| 4802 | rsp_info = fcprsp->rspStatus2; |
| 4803 | rsp_len = be32_to_cpu(fcprsp->rspRspLen); |
| 4804 | rsp_info_code = fcprsp->rspInfo3; |
| 4805 | |
| 4806 | |
| 4807 | lpfc_printf_vlog(vport, KERN_INFO, |
| 4808 | LOG_FCP, |
| 4809 | "0706 fcp_rsp valid 0x%x," |
| 4810 | " rsp len=%d code 0x%x\n", |
| 4811 | rsp_info, |
| 4812 | rsp_len, rsp_info_code); |
| 4813 | |
| 4814 | if ((fcprsp->rspStatus2&RSP_LEN_VALID) && (rsp_len == 8)) { |
| 4815 | switch (rsp_info_code) { |
| 4816 | case RSP_NO_FAILURE: |
| 4817 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4818 | "0715 Task Mgmt No Failure\n"); |
| 4819 | ret = SUCCESS; |
| 4820 | break; |
| 4821 | case RSP_TM_NOT_SUPPORTED: /* TM rejected */ |
| 4822 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4823 | "0716 Task Mgmt Target " |
| 4824 | "reject\n"); |
| 4825 | break; |
| 4826 | case RSP_TM_NOT_COMPLETED: /* TM failed */ |
| 4827 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4828 | "0717 Task Mgmt Target " |
| 4829 | "failed TM\n"); |
| 4830 | break; |
| 4831 | case RSP_TM_INVALID_LU: /* TM to invalid LU! */ |
| 4832 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4833 | "0718 Task Mgmt to invalid " |
| 4834 | "LUN\n"); |
| 4835 | break; |
| 4836 | } |
| 4837 | } |
| 4838 | } |
| 4839 | return ret; |
| 4840 | } |
| 4841 | |
| 4842 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4843 | /** |
| 4844 | * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler |
| 4845 | * @vport: The virtual port for which this call is being executed. |
| 4846 | * @rdata: Pointer to remote port local data |
| 4847 | * @tgt_id: Target ID of remote device. |
| 4848 | * @lun_id: Lun number for the TMF |
| 4849 | * @task_mgmt_cmd: type of TMF to send |
| 4850 | * |
| 4851 | * This routine builds and sends a TMF (SCSI Task Mgmt Function) to |
| 4852 | * a remote port. |
| 4853 | * |
| 4854 | * Return Code: |
| 4855 | * 0x2003 - Error |
| 4856 | * 0x2002 - Success. |
| 4857 | **/ |
| 4858 | static int |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 4859 | lpfc_send_taskmgmt(struct lpfc_vport *vport, struct scsi_cmnd *cmnd, |
| 4860 | unsigned int tgt_id, uint64_t lun_id, |
| 4861 | uint8_t task_mgmt_cmd) |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4862 | { |
| 4863 | struct lpfc_hba *phba = vport->phba; |
| 4864 | struct lpfc_scsi_buf *lpfc_cmd; |
| 4865 | struct lpfc_iocbq *iocbq; |
| 4866 | struct lpfc_iocbq *iocbqrsp; |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 4867 | struct lpfc_rport_data *rdata; |
| 4868 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4869 | int ret; |
| 4870 | int status; |
| 4871 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 4872 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
| 4873 | if (!rdata || !rdata->pnode || !NLP_CHK_NODE_ACT(rdata->pnode)) |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4874 | return FAILED; |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 4875 | pnode = rdata->pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4876 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 4877 | lpfc_cmd = lpfc_get_scsi_buf(phba, pnode); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4878 | if (lpfc_cmd == NULL) |
| 4879 | return FAILED; |
James Smart | 0c41122 | 2013-09-06 12:22:46 -0400 | [diff] [blame] | 4880 | lpfc_cmd->timeout = phba->cfg_task_mgmt_tmo; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4881 | lpfc_cmd->rdata = rdata; |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 4882 | lpfc_cmd->pCmd = cmnd; |
James Smart | 2a5b7d6 | 2018-07-31 17:23:22 -0700 | [diff] [blame] | 4883 | lpfc_cmd->ndlp = pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4884 | |
| 4885 | status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun_id, |
| 4886 | task_mgmt_cmd); |
| 4887 | if (!status) { |
| 4888 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 4889 | return FAILED; |
| 4890 | } |
| 4891 | |
| 4892 | iocbq = &lpfc_cmd->cur_iocbq; |
| 4893 | iocbqrsp = lpfc_sli_get_iocbq(phba); |
| 4894 | if (iocbqrsp == NULL) { |
| 4895 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 4896 | return FAILED; |
| 4897 | } |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 4898 | iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4899 | |
| 4900 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4901 | "0702 Issue %s to TGT %d LUN %llu " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4902 | "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] | 4903 | lpfc_taskmgmt_name(task_mgmt_cmd), tgt_id, lun_id, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4904 | pnode->nlp_rpi, pnode->nlp_flag, iocbq->sli4_xritag, |
| 4905 | iocbq->iocb_flag); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4906 | |
| 4907 | status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING, |
| 4908 | iocbq, iocbqrsp, lpfc_cmd->timeout); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 4909 | if ((status != IOCB_SUCCESS) || |
| 4910 | (iocbqrsp->iocb.ulpStatus != IOSTAT_SUCCESS)) { |
James Smart | ae374a3 | 2015-05-22 10:42:41 -0400 | [diff] [blame] | 4911 | if (status != IOCB_SUCCESS || |
| 4912 | iocbqrsp->iocb.ulpStatus != IOSTAT_FCP_RSP_ERROR) |
| 4913 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 4914 | "0727 TMF %s to TGT %d LUN %llu " |
| 4915 | "failed (%d, %d) iocb_flag x%x\n", |
| 4916 | lpfc_taskmgmt_name(task_mgmt_cmd), |
| 4917 | tgt_id, lun_id, |
| 4918 | iocbqrsp->iocb.ulpStatus, |
| 4919 | iocbqrsp->iocb.un.ulpWord[4], |
| 4920 | iocbq->iocb_flag); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 4921 | /* if ulpStatus != IOCB_SUCCESS, then status == IOCB_SUCCESS */ |
| 4922 | if (status == IOCB_SUCCESS) { |
| 4923 | if (iocbqrsp->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 4924 | /* Something in the FCP_RSP was invalid. |
| 4925 | * Check conditions */ |
| 4926 | ret = lpfc_check_fcp_rsp(vport, lpfc_cmd); |
| 4927 | else |
| 4928 | ret = FAILED; |
| 4929 | } else if (status == IOCB_TIMEDOUT) { |
| 4930 | ret = TIMEOUT_ERROR; |
| 4931 | } else { |
| 4932 | ret = FAILED; |
| 4933 | } |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 4934 | } else |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4935 | ret = SUCCESS; |
| 4936 | |
| 4937 | lpfc_sli_release_iocbq(phba, iocbqrsp); |
| 4938 | |
| 4939 | if (ret != TIMEOUT_ERROR) |
| 4940 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 4941 | |
| 4942 | return ret; |
| 4943 | } |
| 4944 | |
| 4945 | /** |
| 4946 | * lpfc_chk_tgt_mapped - |
| 4947 | * @vport: The virtual port to check on |
| 4948 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 4949 | * |
| 4950 | * This routine delays until the scsi target (aka rport) for the |
| 4951 | * command exists (is present and logged in) or we declare it non-existent. |
| 4952 | * |
| 4953 | * Return code : |
| 4954 | * 0x2003 - Error |
| 4955 | * 0x2002 - Success |
| 4956 | **/ |
| 4957 | static int |
| 4958 | lpfc_chk_tgt_mapped(struct lpfc_vport *vport, struct scsi_cmnd *cmnd) |
| 4959 | { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 4960 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 4961 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4962 | unsigned long later; |
| 4963 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 4964 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 4965 | if (!rdata) { |
| 4966 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4967 | "0797 Tgt Map rport failure: rdata x%p\n", rdata); |
| 4968 | return FAILED; |
| 4969 | } |
| 4970 | pnode = rdata->pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4971 | /* |
| 4972 | * If target is not in a MAPPED state, delay until |
| 4973 | * target is rediscovered or devloss timeout expires. |
| 4974 | */ |
| 4975 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; |
| 4976 | while (time_after(later, jiffies)) { |
| 4977 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 4978 | return FAILED; |
| 4979 | if (pnode->nlp_state == NLP_STE_MAPPED_NODE) |
| 4980 | return SUCCESS; |
| 4981 | schedule_timeout_uninterruptible(msecs_to_jiffies(500)); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 4982 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4983 | if (!rdata) |
| 4984 | return FAILED; |
| 4985 | pnode = rdata->pnode; |
| 4986 | } |
| 4987 | if (!pnode || !NLP_CHK_NODE_ACT(pnode) || |
| 4988 | (pnode->nlp_state != NLP_STE_MAPPED_NODE)) |
| 4989 | return FAILED; |
| 4990 | return SUCCESS; |
| 4991 | } |
| 4992 | |
| 4993 | /** |
| 4994 | * lpfc_reset_flush_io_context - |
| 4995 | * @vport: The virtual port (scsi_host) for the flush context |
| 4996 | * @tgt_id: If aborting by Target contect - specifies the target id |
| 4997 | * @lun_id: If aborting by Lun context - specifies the lun id |
| 4998 | * @context: specifies the context level to flush at. |
| 4999 | * |
| 5000 | * After a reset condition via TMF, we need to flush orphaned i/o |
| 5001 | * contexts from the adapter. This routine aborts any contexts |
| 5002 | * outstanding, then waits for their completions. The wait is |
| 5003 | * bounded by devloss_tmo though. |
| 5004 | * |
| 5005 | * Return code : |
| 5006 | * 0x2003 - Error |
| 5007 | * 0x2002 - Success |
| 5008 | **/ |
| 5009 | static int |
| 5010 | lpfc_reset_flush_io_context(struct lpfc_vport *vport, uint16_t tgt_id, |
| 5011 | uint64_t lun_id, lpfc_ctx_cmd context) |
| 5012 | { |
| 5013 | struct lpfc_hba *phba = vport->phba; |
| 5014 | unsigned long later; |
| 5015 | int cnt; |
| 5016 | |
| 5017 | cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context); |
| 5018 | if (cnt) |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 5019 | lpfc_sli_abort_taskmgmt(vport, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5020 | &phba->sli.sli3_ring[LPFC_FCP_RING], |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 5021 | tgt_id, lun_id, context); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5022 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; |
| 5023 | while (time_after(later, jiffies) && cnt) { |
| 5024 | schedule_timeout_uninterruptible(msecs_to_jiffies(20)); |
| 5025 | cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context); |
| 5026 | } |
| 5027 | if (cnt) { |
| 5028 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5029 | "0724 I/O flush failure for context %s : cnt x%x\n", |
| 5030 | ((context == LPFC_CTX_LUN) ? "LUN" : |
| 5031 | ((context == LPFC_CTX_TGT) ? "TGT" : |
| 5032 | ((context == LPFC_CTX_HOST) ? "HOST" : "Unknown"))), |
| 5033 | cnt); |
| 5034 | return FAILED; |
| 5035 | } |
| 5036 | return SUCCESS; |
| 5037 | } |
| 5038 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5039 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5040 | * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5041 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5042 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5043 | * 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] | 5044 | * command. |
| 5045 | * |
| 5046 | * Return code : |
| 5047 | * 0x2003 - Error |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5048 | * 0x2002 - Success |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5049 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5050 | static int |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5051 | lpfc_device_reset_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5052 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5053 | struct Scsi_Host *shost = cmnd->device->host; |
| 5054 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5055 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5056 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5057 | unsigned tgt_id = cmnd->device->id; |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5058 | uint64_t lun_id = cmnd->device->lun; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5059 | struct lpfc_scsi_event_header scsi_event; |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5060 | int status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5061 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5062 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | ad490b6 | 2015-04-07 15:07:26 -0400 | [diff] [blame] | 5063 | if (!rdata || !rdata->pnode) { |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5064 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
James Smart | ad490b6 | 2015-04-07 15:07:26 -0400 | [diff] [blame] | 5065 | "0798 Device Reset rport failure: rdata x%p\n", |
| 5066 | rdata); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5067 | return FAILED; |
| 5068 | } |
| 5069 | pnode = rdata->pnode; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5070 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 5071 | if (status != 0 && status != SUCCESS) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5072 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5073 | |
| 5074 | status = lpfc_chk_tgt_mapped(vport, cmnd); |
| 5075 | if (status == FAILED) { |
| 5076 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5077 | "0721 Device Reset rport failure: rdata x%p\n", rdata); |
| 5078 | return FAILED; |
| 5079 | } |
| 5080 | |
| 5081 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 5082 | scsi_event.subcategory = LPFC_EVENT_LUNRESET; |
| 5083 | scsi_event.lun = lun_id; |
| 5084 | memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 5085 | memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 5086 | |
| 5087 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5088 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
| 5089 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 5090 | status = lpfc_send_taskmgmt(vport, cmnd, tgt_id, lun_id, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5091 | FCP_LUN_RESET); |
| 5092 | |
| 5093 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5094 | "0713 SCSI layer issued Device Reset (%d, %llu) " |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5095 | "return x%x\n", tgt_id, lun_id, status); |
| 5096 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5097 | /* |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5098 | * We have to clean up i/o as : they may be orphaned by the TMF; |
| 5099 | * or if the TMF failed, they may be in an indeterminate state. |
| 5100 | * So, continue on. |
| 5101 | * We will report success if all the i/o aborts successfully. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5102 | */ |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5103 | if (status == SUCCESS) |
| 5104 | status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5105 | LPFC_CTX_LUN); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5106 | |
| 5107 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5108 | } |
| 5109 | |
| 5110 | /** |
| 5111 | * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point |
| 5112 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5113 | * |
| 5114 | * This routine does a target reset by sending a TARGET_RESET task management |
| 5115 | * command. |
| 5116 | * |
| 5117 | * Return code : |
| 5118 | * 0x2003 - Error |
| 5119 | * 0x2002 - Success |
| 5120 | **/ |
| 5121 | static int |
| 5122 | lpfc_target_reset_handler(struct scsi_cmnd *cmnd) |
| 5123 | { |
| 5124 | struct Scsi_Host *shost = cmnd->device->host; |
| 5125 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5126 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5127 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5128 | unsigned tgt_id = cmnd->device->id; |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5129 | uint64_t lun_id = cmnd->device->lun; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5130 | struct lpfc_scsi_event_header scsi_event; |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5131 | int status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5132 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5133 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5134 | if (!rdata) { |
| 5135 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5136 | "0799 Target Reset rport failure: rdata x%p\n", rdata); |
| 5137 | return FAILED; |
| 5138 | } |
| 5139 | pnode = rdata->pnode; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5140 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 5141 | if (status != 0 && status != SUCCESS) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5142 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5143 | |
| 5144 | status = lpfc_chk_tgt_mapped(vport, cmnd); |
| 5145 | if (status == FAILED) { |
| 5146 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5147 | "0722 Target Reset rport failure: rdata x%p\n", rdata); |
James Smart | 63e480f | 2015-04-07 15:07:20 -0400 | [diff] [blame] | 5148 | if (pnode) { |
| 5149 | spin_lock_irq(shost->host_lock); |
| 5150 | pnode->nlp_flag &= ~NLP_NPR_ADISC; |
| 5151 | pnode->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; |
| 5152 | spin_unlock_irq(shost->host_lock); |
| 5153 | } |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 5154 | lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
| 5155 | LPFC_CTX_TGT); |
| 5156 | return FAST_IO_FAIL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5157 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5158 | |
| 5159 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 5160 | scsi_event.subcategory = LPFC_EVENT_TGTRESET; |
| 5161 | scsi_event.lun = 0; |
| 5162 | memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 5163 | memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 5164 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5165 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5166 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5167 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 5168 | status = lpfc_send_taskmgmt(vport, cmnd, tgt_id, lun_id, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5169 | FCP_TARGET_RESET); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5170 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5171 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5172 | "0723 SCSI layer issued Target Reset (%d, %llu) " |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5173 | "return x%x\n", tgt_id, lun_id, status); |
| 5174 | |
| 5175 | /* |
| 5176 | * We have to clean up i/o as : they may be orphaned by the TMF; |
| 5177 | * or if the TMF failed, they may be in an indeterminate state. |
| 5178 | * So, continue on. |
| 5179 | * We will report success if all the i/o aborts successfully. |
| 5180 | */ |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5181 | if (status == SUCCESS) |
| 5182 | status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 5183 | LPFC_CTX_TGT); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5184 | return status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5185 | } |
| 5186 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5187 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5188 | * 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] | 5189 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5190 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5191 | * This routine does target reset to all targets on @cmnd->device->host. |
| 5192 | * This emulates Parallel SCSI Bus Reset Semantics. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5193 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5194 | * Return code : |
| 5195 | * 0x2003 - Error |
| 5196 | * 0x2002 - Success |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5197 | **/ |
Jeff Garzik | 94d0e7b8 | 2005-05-28 07:55:48 -0400 | [diff] [blame] | 5198 | static int |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5199 | lpfc_bus_reset_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5200 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5201 | struct Scsi_Host *shost = cmnd->device->host; |
| 5202 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5203 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5204 | struct lpfc_scsi_event_header scsi_event; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5205 | int match; |
| 5206 | int ret = SUCCESS, status, i; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5207 | |
| 5208 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 5209 | scsi_event.subcategory = LPFC_EVENT_BUSRESET; |
| 5210 | scsi_event.lun = 0; |
| 5211 | memcpy(scsi_event.wwpn, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 5212 | memcpy(scsi_event.wwnn, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| 5213 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5214 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5215 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5216 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 5217 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 5218 | if (status != 0 && status != SUCCESS) |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 5219 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5220 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5221 | /* |
| 5222 | * Since the driver manages a single bus device, reset all |
| 5223 | * targets known to the driver. Should any target reset |
| 5224 | * fail, this routine returns failure to the midlayer. |
| 5225 | */ |
James Smart | e17da18 | 2006-07-06 15:49:25 -0400 | [diff] [blame] | 5226 | for (i = 0; i < LPFC_MAX_TARGET; i++) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5227 | /* Search for mapped node by target ID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5228 | match = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5229 | spin_lock_irq(shost->host_lock); |
| 5230 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5231 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5232 | continue; |
James Smart | a6571c6 | 2012-10-31 14:44:42 -0400 | [diff] [blame] | 5233 | if (vport->phba->cfg_fcp2_no_tgt_reset && |
| 5234 | (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE)) |
| 5235 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5236 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE && |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 5237 | ndlp->nlp_sid == i && |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5238 | ndlp->rport && |
| 5239 | ndlp->nlp_type & NLP_FCP_TARGET) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5240 | match = 1; |
| 5241 | break; |
| 5242 | } |
| 5243 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5244 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5245 | if (!match) |
| 5246 | continue; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5247 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 5248 | status = lpfc_send_taskmgmt(vport, cmnd, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5249 | i, 0, FCP_TARGET_RESET); |
| 5250 | |
| 5251 | if (status != SUCCESS) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5252 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5253 | "0700 Bus Reset on target %d failed\n", |
| 5254 | i); |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 5255 | ret = FAILED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5256 | } |
| 5257 | } |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 5258 | /* |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5259 | * We have to clean up i/o as : they may be orphaned by the TMFs |
| 5260 | * above; or if any of the TMFs failed, they may be in an |
| 5261 | * indeterminate state. |
| 5262 | * 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] | 5263 | */ |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5264 | |
| 5265 | status = lpfc_reset_flush_io_context(vport, 0, 0, LPFC_CTX_HOST); |
| 5266 | if (status != SUCCESS) |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 5267 | ret = FAILED; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5268 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5269 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5270 | "0714 SCSI layer issued Bus Reset Data: x%x\n", ret); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5271 | return ret; |
| 5272 | } |
| 5273 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5274 | /** |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5275 | * lpfc_host_reset_handler - scsi_host_template eh_host_reset_handler entry pt |
| 5276 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5277 | * |
| 5278 | * This routine does host reset to the adaptor port. It brings the HBA |
| 5279 | * offline, performs a board restart, and then brings the board back online. |
| 5280 | * The lpfc_offline calls lpfc_sli_hba_down which will abort and local |
| 5281 | * reject all outstanding SCSI commands to the host and error returned |
| 5282 | * back to SCSI mid-level. As this will be SCSI mid-level's last resort |
| 5283 | * of error handling, it will only return error if resetting of the adapter |
| 5284 | * is not successful; in all other cases, will return success. |
| 5285 | * |
| 5286 | * Return code : |
| 5287 | * 0x2003 - Error |
| 5288 | * 0x2002 - Success |
| 5289 | **/ |
| 5290 | static int |
| 5291 | lpfc_host_reset_handler(struct scsi_cmnd *cmnd) |
| 5292 | { |
| 5293 | struct Scsi_Host *shost = cmnd->device->host; |
| 5294 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 5295 | struct lpfc_hba *phba = vport->phba; |
| 5296 | int rc, ret = SUCCESS; |
| 5297 | |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 5298 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5299 | "3172 SCSI layer issued Host Reset Data:\n"); |
| 5300 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 5301 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5302 | lpfc_offline(phba); |
| 5303 | rc = lpfc_sli_brdrestart(phba); |
| 5304 | if (rc) |
| 5305 | ret = FAILED; |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 5306 | rc = lpfc_online(phba); |
| 5307 | if (rc) |
| 5308 | ret = FAILED; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5309 | lpfc_unblock_mgmt_io(phba); |
| 5310 | |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 5311 | if (ret == FAILED) { |
| 5312 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5313 | "3323 Failed host reset, bring it offline\n"); |
| 5314 | lpfc_sli4_offline_eratt(phba); |
| 5315 | } |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5316 | return ret; |
| 5317 | } |
| 5318 | |
| 5319 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5320 | * lpfc_slave_alloc - scsi_host_template slave_alloc entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5321 | * @sdev: Pointer to scsi_device. |
| 5322 | * |
| 5323 | * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's |
| 5324 | * globally available list of scsi buffers. This routine also makes sure scsi |
| 5325 | * buffer is not allocated more than HBA limit conveyed to midlayer. This list |
| 5326 | * of scsi buffer exists for the lifetime of the driver. |
| 5327 | * |
| 5328 | * Return codes: |
| 5329 | * non-0 - Error |
| 5330 | * 0 - Success |
| 5331 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5332 | static int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5333 | lpfc_slave_alloc(struct scsi_device *sdev) |
| 5334 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5335 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 5336 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 5337 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5338 | uint32_t total = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5339 | uint32_t num_to_alloc = 0; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5340 | int num_allocated = 0; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5341 | uint32_t sdev_cnt; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5342 | struct lpfc_device_data *device_data; |
| 5343 | unsigned long flags; |
| 5344 | struct lpfc_name target_wwpn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5345 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 5346 | if (!rport || fc_remote_port_chkready(rport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5347 | return -ENXIO; |
| 5348 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5349 | if (phba->cfg_fof) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5350 | |
| 5351 | /* |
| 5352 | * Check to see if the device data structure for the lun |
| 5353 | * exists. If not, create one. |
| 5354 | */ |
| 5355 | |
| 5356 | u64_to_wwn(rport->port_name, target_wwpn.u.wwn); |
| 5357 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5358 | device_data = __lpfc_get_device_data(phba, |
| 5359 | &phba->luns, |
| 5360 | &vport->fc_portname, |
| 5361 | &target_wwpn, |
| 5362 | sdev->lun); |
| 5363 | if (!device_data) { |
| 5364 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5365 | device_data = lpfc_create_device_data(phba, |
| 5366 | &vport->fc_portname, |
| 5367 | &target_wwpn, |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5368 | sdev->lun, |
| 5369 | phba->cfg_XLanePriority, |
| 5370 | true); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5371 | if (!device_data) |
| 5372 | return -ENOMEM; |
| 5373 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5374 | list_add_tail(&device_data->listentry, &phba->luns); |
| 5375 | } |
| 5376 | device_data->rport_data = rport->dd_data; |
| 5377 | device_data->available = true; |
| 5378 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5379 | sdev->hostdata = device_data; |
| 5380 | } else { |
| 5381 | sdev->hostdata = rport->dd_data; |
| 5382 | } |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5383 | sdev_cnt = atomic_inc_return(&phba->sdev_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5384 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 5385 | /* For SLI4, all IO buffers are pre-allocated */ |
| 5386 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 5387 | return 0; |
| 5388 | |
| 5389 | /* This code path is now ONLY for SLI3 adapters */ |
| 5390 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5391 | /* |
| 5392 | * Populate the cmds_per_lun count scsi_bufs into this host's globally |
| 5393 | * 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] | 5394 | * HBA limit conveyed to the midlayer via the host structure. The |
| 5395 | * formula accounts for the lun_queue_depth + error handlers + 1 |
| 5396 | * extra. This list of scsi bufs exists for the lifetime of the driver. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5397 | */ |
| 5398 | total = phba->total_scsi_bufs; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5399 | num_to_alloc = vport->cfg_lun_queue_depth + 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5400 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5401 | /* If allocated buffers are enough do nothing */ |
| 5402 | if ((sdev_cnt * (vport->cfg_lun_queue_depth + 2)) < total) |
| 5403 | return 0; |
| 5404 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5405 | /* Allow some exchanges to be available always to complete discovery */ |
| 5406 | if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5407 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 5408 | "0704 At limitation of %d preallocated " |
| 5409 | "command buffers\n", total); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5410 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5411 | /* Allow some exchanges to be available always to complete discovery */ |
| 5412 | } else if (total + num_to_alloc > |
| 5413 | phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5414 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 5415 | "0705 Allocation request of %d " |
| 5416 | "command buffers will exceed max of %d. " |
| 5417 | "Reducing allocation request to %d.\n", |
| 5418 | num_to_alloc, phba->cfg_hba_queue_depth, |
| 5419 | (phba->cfg_hba_queue_depth - total)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5420 | num_to_alloc = phba->cfg_hba_queue_depth - total; |
| 5421 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 5422 | num_allocated = lpfc_new_scsi_buf_s3(vport, num_to_alloc); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5423 | if (num_to_alloc != num_allocated) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5424 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5425 | "0708 Allocation request of %d " |
| 5426 | "command buffers did not succeed. " |
| 5427 | "Allocated %d buffers.\n", |
| 5428 | num_to_alloc, num_allocated); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5429 | } |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5430 | if (num_allocated > 0) |
| 5431 | phba->total_scsi_bufs += num_allocated; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5432 | return 0; |
| 5433 | } |
| 5434 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5435 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5436 | * lpfc_slave_configure - scsi_host_template slave_configure entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5437 | * @sdev: Pointer to scsi_device. |
| 5438 | * |
| 5439 | * This routine configures following items |
| 5440 | * - Tag command queuing support for @sdev if supported. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5441 | * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set. |
| 5442 | * |
| 5443 | * Return codes: |
| 5444 | * 0 - Success |
| 5445 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5446 | static int |
| 5447 | lpfc_slave_configure(struct scsi_device *sdev) |
| 5448 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5449 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 5450 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5451 | |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 5452 | scsi_change_queue_depth(sdev, vport->cfg_lun_queue_depth); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5453 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5454 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 5455 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5456 | &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5457 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 5458 | lpfc_poll_rearm_timer(phba); |
| 5459 | } |
| 5460 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5461 | return 0; |
| 5462 | } |
| 5463 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5464 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5465 | * lpfc_slave_destroy - slave_destroy entry point of SHT data structure |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5466 | * @sdev: Pointer to scsi_device. |
| 5467 | * |
| 5468 | * This routine sets @sdev hostatdata filed to null. |
| 5469 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5470 | static void |
| 5471 | lpfc_slave_destroy(struct scsi_device *sdev) |
| 5472 | { |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5473 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 5474 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5475 | unsigned long flags; |
| 5476 | struct lpfc_device_data *device_data = sdev->hostdata; |
| 5477 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5478 | atomic_dec(&phba->sdev_cnt); |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5479 | if ((phba->cfg_fof) && (device_data)) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5480 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5481 | device_data->available = false; |
| 5482 | if (!device_data->oas_enabled) |
| 5483 | lpfc_delete_device_data(phba, device_data); |
| 5484 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5485 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5486 | sdev->hostdata = NULL; |
| 5487 | return; |
| 5488 | } |
| 5489 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5490 | /** |
| 5491 | * lpfc_create_device_data - creates and initializes device data structure for OAS |
| 5492 | * @pha: Pointer to host bus adapter structure. |
| 5493 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5494 | * @target_wwpn: Pointer to target's wwpn information |
| 5495 | * @lun: Lun on target |
| 5496 | * @atomic_create: Flag to indicate if memory should be allocated using the |
| 5497 | * GFP_ATOMIC flag or not. |
| 5498 | * |
| 5499 | * This routine creates a device data structure which will contain identifying |
| 5500 | * information for the device (host wwpn, target wwpn, lun), state of OAS, |
| 5501 | * whether or not the corresponding lun is available by the system, |
| 5502 | * and pointer to the rport data. |
| 5503 | * |
| 5504 | * Return codes: |
| 5505 | * NULL - Error |
| 5506 | * Pointer to lpfc_device_data - Success |
| 5507 | **/ |
| 5508 | struct lpfc_device_data* |
| 5509 | lpfc_create_device_data(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn, |
| 5510 | struct lpfc_name *target_wwpn, uint64_t lun, |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5511 | uint32_t pri, bool atomic_create) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5512 | { |
| 5513 | |
| 5514 | struct lpfc_device_data *lun_info; |
| 5515 | int memory_flags; |
| 5516 | |
| 5517 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5518 | !(phba->cfg_fof)) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5519 | return NULL; |
| 5520 | |
| 5521 | /* Attempt to create the device data to contain lun info */ |
| 5522 | |
| 5523 | if (atomic_create) |
| 5524 | memory_flags = GFP_ATOMIC; |
| 5525 | else |
| 5526 | memory_flags = GFP_KERNEL; |
| 5527 | lun_info = mempool_alloc(phba->device_data_mem_pool, memory_flags); |
| 5528 | if (!lun_info) |
| 5529 | return NULL; |
| 5530 | INIT_LIST_HEAD(&lun_info->listentry); |
| 5531 | lun_info->rport_data = NULL; |
| 5532 | memcpy(&lun_info->device_id.vport_wwpn, vport_wwpn, |
| 5533 | sizeof(struct lpfc_name)); |
| 5534 | memcpy(&lun_info->device_id.target_wwpn, target_wwpn, |
| 5535 | sizeof(struct lpfc_name)); |
| 5536 | lun_info->device_id.lun = lun; |
| 5537 | lun_info->oas_enabled = false; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5538 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5539 | lun_info->available = false; |
| 5540 | return lun_info; |
| 5541 | } |
| 5542 | |
| 5543 | /** |
| 5544 | * lpfc_delete_device_data - frees a device data structure for OAS |
| 5545 | * @pha: Pointer to host bus adapter structure. |
| 5546 | * @lun_info: Pointer to device data structure to free. |
| 5547 | * |
| 5548 | * This routine frees the previously allocated device data structure passed. |
| 5549 | * |
| 5550 | **/ |
| 5551 | void |
| 5552 | lpfc_delete_device_data(struct lpfc_hba *phba, |
| 5553 | struct lpfc_device_data *lun_info) |
| 5554 | { |
| 5555 | |
| 5556 | if (unlikely(!phba) || !lun_info || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5557 | !(phba->cfg_fof)) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5558 | return; |
| 5559 | |
| 5560 | if (!list_empty(&lun_info->listentry)) |
| 5561 | list_del(&lun_info->listentry); |
| 5562 | mempool_free(lun_info, phba->device_data_mem_pool); |
| 5563 | return; |
| 5564 | } |
| 5565 | |
| 5566 | /** |
| 5567 | * __lpfc_get_device_data - returns the device data for the specified lun |
| 5568 | * @pha: Pointer to host bus adapter structure. |
| 5569 | * @list: Point to list to search. |
| 5570 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5571 | * @target_wwpn: Pointer to target's wwpn information |
| 5572 | * @lun: Lun on target |
| 5573 | * |
| 5574 | * This routine searches the list passed for the specified lun's device data. |
| 5575 | * This function does not hold locks, it is the responsibility of the caller |
| 5576 | * to ensure the proper lock is held before calling the function. |
| 5577 | * |
| 5578 | * Return codes: |
| 5579 | * NULL - Error |
| 5580 | * Pointer to lpfc_device_data - Success |
| 5581 | **/ |
| 5582 | struct lpfc_device_data* |
| 5583 | __lpfc_get_device_data(struct lpfc_hba *phba, struct list_head *list, |
| 5584 | struct lpfc_name *vport_wwpn, |
| 5585 | struct lpfc_name *target_wwpn, uint64_t lun) |
| 5586 | { |
| 5587 | |
| 5588 | struct lpfc_device_data *lun_info; |
| 5589 | |
| 5590 | if (unlikely(!phba) || !list || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5591 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5592 | return NULL; |
| 5593 | |
| 5594 | /* Check to see if the lun is already enabled for OAS. */ |
| 5595 | |
| 5596 | list_for_each_entry(lun_info, list, listentry) { |
| 5597 | if ((memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn, |
| 5598 | sizeof(struct lpfc_name)) == 0) && |
| 5599 | (memcmp(&lun_info->device_id.target_wwpn, target_wwpn, |
| 5600 | sizeof(struct lpfc_name)) == 0) && |
| 5601 | (lun_info->device_id.lun == lun)) |
| 5602 | return lun_info; |
| 5603 | } |
| 5604 | |
| 5605 | return NULL; |
| 5606 | } |
| 5607 | |
| 5608 | /** |
| 5609 | * lpfc_find_next_oas_lun - searches for the next oas lun |
| 5610 | * @pha: Pointer to host bus adapter structure. |
| 5611 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5612 | * @target_wwpn: Pointer to target's wwpn information |
| 5613 | * @starting_lun: Pointer to the lun to start searching for |
| 5614 | * @found_vport_wwpn: Pointer to the found lun's vport wwpn information |
| 5615 | * @found_target_wwpn: Pointer to the found lun's target wwpn information |
| 5616 | * @found_lun: Pointer to the found lun. |
| 5617 | * @found_lun_status: Pointer to status of the found lun. |
| 5618 | * |
| 5619 | * This routine searches the luns list for the specified lun |
| 5620 | * or the first lun for the vport/target. If the vport wwpn contains |
| 5621 | * a zero value then a specific vport is not specified. In this case |
| 5622 | * any vport which contains the lun will be considered a match. If the |
| 5623 | * target wwpn contains a zero value then a specific target is not specified. |
| 5624 | * In this case any target which contains the lun will be considered a |
| 5625 | * match. If the lun is found, the lun, vport wwpn, target wwpn and lun status |
| 5626 | * are returned. The function will also return the next lun if available. |
| 5627 | * If the next lun is not found, starting_lun parameter will be set to |
| 5628 | * NO_MORE_OAS_LUN. |
| 5629 | * |
| 5630 | * Return codes: |
| 5631 | * non-0 - Error |
| 5632 | * 0 - Success |
| 5633 | **/ |
| 5634 | bool |
| 5635 | lpfc_find_next_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn, |
| 5636 | struct lpfc_name *target_wwpn, uint64_t *starting_lun, |
| 5637 | struct lpfc_name *found_vport_wwpn, |
| 5638 | struct lpfc_name *found_target_wwpn, |
| 5639 | uint64_t *found_lun, |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5640 | uint32_t *found_lun_status, |
| 5641 | uint32_t *found_lun_pri) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5642 | { |
| 5643 | |
| 5644 | unsigned long flags; |
| 5645 | struct lpfc_device_data *lun_info; |
| 5646 | struct lpfc_device_id *device_id; |
| 5647 | uint64_t lun; |
| 5648 | bool found = false; |
| 5649 | |
| 5650 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
| 5651 | !starting_lun || !found_vport_wwpn || |
| 5652 | !found_target_wwpn || !found_lun || !found_lun_status || |
| 5653 | (*starting_lun == NO_MORE_OAS_LUN) || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5654 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5655 | return false; |
| 5656 | |
| 5657 | lun = *starting_lun; |
| 5658 | *found_lun = NO_MORE_OAS_LUN; |
| 5659 | *starting_lun = NO_MORE_OAS_LUN; |
| 5660 | |
| 5661 | /* Search for lun or the lun closet in value */ |
| 5662 | |
| 5663 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5664 | list_for_each_entry(lun_info, &phba->luns, listentry) { |
| 5665 | if (((wwn_to_u64(vport_wwpn->u.wwn) == 0) || |
| 5666 | (memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn, |
| 5667 | sizeof(struct lpfc_name)) == 0)) && |
| 5668 | ((wwn_to_u64(target_wwpn->u.wwn) == 0) || |
| 5669 | (memcmp(&lun_info->device_id.target_wwpn, target_wwpn, |
| 5670 | sizeof(struct lpfc_name)) == 0)) && |
| 5671 | (lun_info->oas_enabled)) { |
| 5672 | device_id = &lun_info->device_id; |
| 5673 | if ((!found) && |
| 5674 | ((lun == FIND_FIRST_OAS_LUN) || |
| 5675 | (device_id->lun == lun))) { |
| 5676 | *found_lun = device_id->lun; |
| 5677 | memcpy(found_vport_wwpn, |
| 5678 | &device_id->vport_wwpn, |
| 5679 | sizeof(struct lpfc_name)); |
| 5680 | memcpy(found_target_wwpn, |
| 5681 | &device_id->target_wwpn, |
| 5682 | sizeof(struct lpfc_name)); |
| 5683 | if (lun_info->available) |
| 5684 | *found_lun_status = |
| 5685 | OAS_LUN_STATUS_EXISTS; |
| 5686 | else |
| 5687 | *found_lun_status = 0; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5688 | *found_lun_pri = lun_info->priority; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5689 | if (phba->cfg_oas_flags & OAS_FIND_ANY_VPORT) |
| 5690 | memset(vport_wwpn, 0x0, |
| 5691 | sizeof(struct lpfc_name)); |
| 5692 | if (phba->cfg_oas_flags & OAS_FIND_ANY_TARGET) |
| 5693 | memset(target_wwpn, 0x0, |
| 5694 | sizeof(struct lpfc_name)); |
| 5695 | found = true; |
| 5696 | } else if (found) { |
| 5697 | *starting_lun = device_id->lun; |
| 5698 | memcpy(vport_wwpn, &device_id->vport_wwpn, |
| 5699 | sizeof(struct lpfc_name)); |
| 5700 | memcpy(target_wwpn, &device_id->target_wwpn, |
| 5701 | sizeof(struct lpfc_name)); |
| 5702 | break; |
| 5703 | } |
| 5704 | } |
| 5705 | } |
| 5706 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5707 | return found; |
| 5708 | } |
| 5709 | |
| 5710 | /** |
| 5711 | * lpfc_enable_oas_lun - enables a lun for OAS operations |
| 5712 | * @pha: Pointer to host bus adapter structure. |
| 5713 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5714 | * @target_wwpn: Pointer to target's wwpn information |
| 5715 | * @lun: Lun |
| 5716 | * |
| 5717 | * This routine enables a lun for oas operations. The routines does so by |
| 5718 | * doing the following : |
| 5719 | * |
| 5720 | * 1) Checks to see if the device data for the lun has been created. |
| 5721 | * 2) If found, sets the OAS enabled flag if not set and returns. |
| 5722 | * 3) Otherwise, creates a device data structure. |
| 5723 | * 4) If successfully created, indicates the device data is for an OAS lun, |
| 5724 | * indicates the lun is not available and add to the list of luns. |
| 5725 | * |
| 5726 | * Return codes: |
| 5727 | * false - Error |
| 5728 | * true - Success |
| 5729 | **/ |
| 5730 | bool |
| 5731 | 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] | 5732 | struct lpfc_name *target_wwpn, uint64_t lun, uint8_t pri) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5733 | { |
| 5734 | |
| 5735 | struct lpfc_device_data *lun_info; |
| 5736 | unsigned long flags; |
| 5737 | |
| 5738 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5739 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5740 | return false; |
| 5741 | |
| 5742 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5743 | |
| 5744 | /* Check to see if the device data for the lun has been created */ |
| 5745 | lun_info = __lpfc_get_device_data(phba, &phba->luns, vport_wwpn, |
| 5746 | target_wwpn, lun); |
| 5747 | if (lun_info) { |
| 5748 | if (!lun_info->oas_enabled) |
| 5749 | lun_info->oas_enabled = true; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5750 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5751 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5752 | return true; |
| 5753 | } |
| 5754 | |
| 5755 | /* Create an lun info structure and add to list of luns */ |
| 5756 | lun_info = lpfc_create_device_data(phba, vport_wwpn, target_wwpn, lun, |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5757 | pri, false); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5758 | if (lun_info) { |
| 5759 | lun_info->oas_enabled = true; |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 5760 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5761 | lun_info->available = false; |
| 5762 | list_add_tail(&lun_info->listentry, &phba->luns); |
| 5763 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5764 | return true; |
| 5765 | } |
| 5766 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5767 | return false; |
| 5768 | } |
| 5769 | |
| 5770 | /** |
| 5771 | * lpfc_disable_oas_lun - disables a lun for OAS operations |
| 5772 | * @pha: Pointer to host bus adapter structure. |
| 5773 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5774 | * @target_wwpn: Pointer to target's wwpn information |
| 5775 | * @lun: Lun |
| 5776 | * |
| 5777 | * This routine disables a lun for oas operations. The routines does so by |
| 5778 | * doing the following : |
| 5779 | * |
| 5780 | * 1) Checks to see if the device data for the lun is created. |
| 5781 | * 2) If present, clears the flag indicating this lun is for OAS. |
| 5782 | * 3) If the lun is not available by the system, the device data is |
| 5783 | * freed. |
| 5784 | * |
| 5785 | * Return codes: |
| 5786 | * false - Error |
| 5787 | * true - Success |
| 5788 | **/ |
| 5789 | bool |
| 5790 | 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] | 5791 | struct lpfc_name *target_wwpn, uint64_t lun, uint8_t pri) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5792 | { |
| 5793 | |
| 5794 | struct lpfc_device_data *lun_info; |
| 5795 | unsigned long flags; |
| 5796 | |
| 5797 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5798 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5799 | return false; |
| 5800 | |
| 5801 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5802 | |
| 5803 | /* Check to see if the lun is available. */ |
| 5804 | lun_info = __lpfc_get_device_data(phba, |
| 5805 | &phba->luns, vport_wwpn, |
| 5806 | target_wwpn, lun); |
| 5807 | if (lun_info) { |
| 5808 | lun_info->oas_enabled = false; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5809 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5810 | if (!lun_info->available) |
| 5811 | lpfc_delete_device_data(phba, lun_info); |
| 5812 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5813 | return true; |
| 5814 | } |
| 5815 | |
| 5816 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5817 | return false; |
| 5818 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5819 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5820 | static int |
| 5821 | lpfc_no_command(struct Scsi_Host *shost, struct scsi_cmnd *cmnd) |
| 5822 | { |
| 5823 | return SCSI_MLQUEUE_HOST_BUSY; |
| 5824 | } |
| 5825 | |
| 5826 | static int |
| 5827 | lpfc_no_handler(struct scsi_cmnd *cmnd) |
| 5828 | { |
| 5829 | return FAILED; |
| 5830 | } |
| 5831 | |
| 5832 | static int |
| 5833 | lpfc_no_slave(struct scsi_device *sdev) |
| 5834 | { |
| 5835 | return -ENODEV; |
| 5836 | } |
| 5837 | |
| 5838 | struct scsi_host_template lpfc_template_nvme = { |
| 5839 | .module = THIS_MODULE, |
| 5840 | .name = LPFC_DRIVER_NAME, |
| 5841 | .proc_name = LPFC_DRIVER_NAME, |
| 5842 | .info = lpfc_info, |
| 5843 | .queuecommand = lpfc_no_command, |
| 5844 | .eh_abort_handler = lpfc_no_handler, |
| 5845 | .eh_device_reset_handler = lpfc_no_handler, |
| 5846 | .eh_target_reset_handler = lpfc_no_handler, |
| 5847 | .eh_bus_reset_handler = lpfc_no_handler, |
| 5848 | .eh_host_reset_handler = lpfc_no_handler, |
| 5849 | .slave_alloc = lpfc_no_slave, |
| 5850 | .slave_configure = lpfc_no_slave, |
| 5851 | .scan_finished = lpfc_scan_finished, |
| 5852 | .this_id = -1, |
| 5853 | .sg_tablesize = 1, |
| 5854 | .cmd_per_lun = 1, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5855 | .shost_attrs = lpfc_hba_attrs, |
| 5856 | .max_sectors = 0xFFFF, |
| 5857 | .vendor_id = LPFC_NL_VENDOR_ID, |
| 5858 | .track_queue_depth = 0, |
| 5859 | }; |
| 5860 | |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 5861 | struct scsi_host_template lpfc_template_no_hr = { |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 5862 | .module = THIS_MODULE, |
| 5863 | .name = LPFC_DRIVER_NAME, |
James Smart | 08dcd4c | 2016-07-06 12:35:59 -0700 | [diff] [blame] | 5864 | .proc_name = LPFC_DRIVER_NAME, |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 5865 | .info = lpfc_info, |
| 5866 | .queuecommand = lpfc_queuecommand, |
James Smart | 856984b | 2017-03-04 09:30:32 -0800 | [diff] [blame] | 5867 | .eh_timed_out = fc_eh_timed_out, |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 5868 | .eh_abort_handler = lpfc_abort_handler, |
| 5869 | .eh_device_reset_handler = lpfc_device_reset_handler, |
| 5870 | .eh_target_reset_handler = lpfc_target_reset_handler, |
| 5871 | .eh_bus_reset_handler = lpfc_bus_reset_handler, |
| 5872 | .slave_alloc = lpfc_slave_alloc, |
| 5873 | .slave_configure = lpfc_slave_configure, |
| 5874 | .slave_destroy = lpfc_slave_destroy, |
| 5875 | .scan_finished = lpfc_scan_finished, |
| 5876 | .this_id = -1, |
| 5877 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
| 5878 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 5879 | .shost_attrs = lpfc_hba_attrs, |
| 5880 | .max_sectors = 0xFFFF, |
| 5881 | .vendor_id = LPFC_NL_VENDOR_ID, |
| 5882 | .change_queue_depth = scsi_change_queue_depth, |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 5883 | .track_queue_depth = 1, |
| 5884 | }; |
| 5885 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5886 | struct scsi_host_template lpfc_template = { |
| 5887 | .module = THIS_MODULE, |
| 5888 | .name = LPFC_DRIVER_NAME, |
James Smart | 08dcd4c | 2016-07-06 12:35:59 -0700 | [diff] [blame] | 5889 | .proc_name = LPFC_DRIVER_NAME, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5890 | .info = lpfc_info, |
| 5891 | .queuecommand = lpfc_queuecommand, |
Christoph Hellwig | b6a05c8 | 2017-01-30 13:18:58 +0100 | [diff] [blame] | 5892 | .eh_timed_out = fc_eh_timed_out, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5893 | .eh_abort_handler = lpfc_abort_handler, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5894 | .eh_device_reset_handler = lpfc_device_reset_handler, |
| 5895 | .eh_target_reset_handler = lpfc_target_reset_handler, |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5896 | .eh_bus_reset_handler = lpfc_bus_reset_handler, |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5897 | .eh_host_reset_handler = lpfc_host_reset_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5898 | .slave_alloc = lpfc_slave_alloc, |
| 5899 | .slave_configure = lpfc_slave_configure, |
| 5900 | .slave_destroy = lpfc_slave_destroy, |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 5901 | .scan_finished = lpfc_scan_finished, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5902 | .this_id = -1, |
James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 5903 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5904 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5905 | .shost_attrs = lpfc_hba_attrs, |
James.Smart@Emulex.Com | 564b296 | 2005-06-25 10:34:17 -0400 | [diff] [blame] | 5906 | .max_sectors = 0xFFFF, |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5907 | .vendor_id = LPFC_NL_VENDOR_ID, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 5908 | .change_queue_depth = scsi_change_queue_depth, |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 5909 | .track_queue_depth = 1, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5910 | }; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5911 | |
| 5912 | struct scsi_host_template lpfc_vport_template = { |
| 5913 | .module = THIS_MODULE, |
| 5914 | .name = LPFC_DRIVER_NAME, |
James Smart | 08dcd4c | 2016-07-06 12:35:59 -0700 | [diff] [blame] | 5915 | .proc_name = LPFC_DRIVER_NAME, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5916 | .info = lpfc_info, |
| 5917 | .queuecommand = lpfc_queuecommand, |
Christoph Hellwig | b6a05c8 | 2017-01-30 13:18:58 +0100 | [diff] [blame] | 5918 | .eh_timed_out = fc_eh_timed_out, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5919 | .eh_abort_handler = lpfc_abort_handler, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5920 | .eh_device_reset_handler = lpfc_device_reset_handler, |
| 5921 | .eh_target_reset_handler = lpfc_target_reset_handler, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5922 | .slave_alloc = lpfc_slave_alloc, |
| 5923 | .slave_configure = lpfc_slave_configure, |
| 5924 | .slave_destroy = lpfc_slave_destroy, |
| 5925 | .scan_finished = lpfc_scan_finished, |
| 5926 | .this_id = -1, |
James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 5927 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5928 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5929 | .shost_attrs = lpfc_vport_attrs, |
| 5930 | .max_sectors = 0xFFFF, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 5931 | .change_queue_depth = scsi_change_queue_depth, |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 5932 | .track_queue_depth = 1, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5933 | }; |