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 | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 5 | * “Broadcom” refers to Broadcom Limited 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 | { |
| 185 | struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 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 | { |
| 205 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| 206 | struct lpfc_nodelist *pnode = rdata->pnode; |
| 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 | |
| 214 | if (cmd->result) |
| 215 | return; |
| 216 | |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 217 | latency = jiffies_to_msecs((long)jiffies - (long)lpfc_cmd->start_time); |
| 218 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 219 | spin_lock_irqsave(shost->host_lock, flags); |
| 220 | if (!vport->stat_data_enabled || |
| 221 | vport->stat_data_blocked || |
James Smart | 5989b8d | 2010-10-22 11:06:56 -0400 | [diff] [blame] | 222 | !pnode || |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 223 | !pnode->lat_data || |
| 224 | (phba->bucket_type == LPFC_NO_BUCKET)) { |
| 225 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 226 | return; |
| 227 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 228 | |
| 229 | if (phba->bucket_type == LPFC_LINEAR_BUCKET) { |
| 230 | i = (latency + phba->bucket_step - 1 - phba->bucket_base)/ |
| 231 | phba->bucket_step; |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 232 | /* check array subscript bounds */ |
| 233 | if (i < 0) |
| 234 | i = 0; |
| 235 | else if (i >= LPFC_MAX_BUCKET_COUNT) |
| 236 | i = LPFC_MAX_BUCKET_COUNT - 1; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 237 | } else { |
| 238 | for (i = 0; i < LPFC_MAX_BUCKET_COUNT-1; i++) |
| 239 | if (latency <= (phba->bucket_base + |
| 240 | ((1<<i)*phba->bucket_step))) |
| 241 | break; |
| 242 | } |
| 243 | |
| 244 | pnode->lat_data[i].cmd_count++; |
| 245 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 246 | } |
| 247 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 248 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 249 | * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 250 | * @phba: The Hba for which this call is being executed. |
| 251 | * |
| 252 | * This routine is called when there is resource error in driver or firmware. |
| 253 | * This routine posts WORKER_RAMP_DOWN_QUEUE event for @phba. This routine |
| 254 | * posts at most 1 event each second. This routine wakes up worker thread of |
| 255 | * @phba to process WORKER_RAM_DOWN_EVENT event. |
| 256 | * |
| 257 | * This routine should be called with no lock held. |
| 258 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 259 | void |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 260 | lpfc_rampdown_queue_depth(struct lpfc_hba *phba) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 261 | { |
| 262 | unsigned long flags; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 263 | uint32_t evt_posted; |
Manuel Schölling | 0d4aec1 | 2014-09-03 12:55:58 -0400 | [diff] [blame] | 264 | unsigned long expires; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 265 | |
| 266 | spin_lock_irqsave(&phba->hbalock, flags); |
| 267 | atomic_inc(&phba->num_rsrc_err); |
| 268 | phba->last_rsrc_error_time = jiffies; |
| 269 | |
Manuel Schölling | 0d4aec1 | 2014-09-03 12:55:58 -0400 | [diff] [blame] | 270 | expires = phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL; |
| 271 | if (time_after(expires, jiffies)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 272 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 273 | return; |
| 274 | } |
| 275 | |
| 276 | phba->last_ramp_down_time = jiffies; |
| 277 | |
| 278 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 279 | |
| 280 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 281 | evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE; |
| 282 | if (!evt_posted) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 283 | phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 284 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
| 285 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 286 | if (!evt_posted) |
| 287 | lpfc_worker_wake_up(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 288 | return; |
| 289 | } |
| 290 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 291 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 292 | * lpfc_ramp_down_queue_handler - WORKER_RAMP_DOWN_QUEUE event handler |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 293 | * @phba: The Hba for which this call is being executed. |
| 294 | * |
| 295 | * This routine is called to process WORKER_RAMP_DOWN_QUEUE event for worker |
| 296 | * thread.This routine reduces queue depth for all scsi device on each vport |
| 297 | * associated with @phba. |
| 298 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 299 | void |
| 300 | lpfc_ramp_down_queue_handler(struct lpfc_hba *phba) |
| 301 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 302 | struct lpfc_vport **vports; |
| 303 | struct Scsi_Host *shost; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 304 | struct scsi_device *sdev; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 305 | unsigned long new_queue_depth; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 306 | unsigned long num_rsrc_err, num_cmd_success; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 307 | int i; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 308 | |
| 309 | num_rsrc_err = atomic_read(&phba->num_rsrc_err); |
| 310 | num_cmd_success = atomic_read(&phba->num_cmd_success); |
| 311 | |
James Smart | 75ad83a | 2012-05-09 21:18:40 -0400 | [diff] [blame] | 312 | /* |
| 313 | * The error and success command counters are global per |
| 314 | * driver instance. If another handler has already |
| 315 | * operated on this error event, just exit. |
| 316 | */ |
| 317 | if (num_rsrc_err == 0) |
| 318 | return; |
| 319 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 320 | vports = lpfc_create_vport_work_array(phba); |
| 321 | if (vports != NULL) |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 322 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 323 | shost = lpfc_shost_from_vport(vports[i]); |
| 324 | shost_for_each_device(sdev, shost) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 325 | new_queue_depth = |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 326 | sdev->queue_depth * num_rsrc_err / |
| 327 | (num_rsrc_err + num_cmd_success); |
| 328 | if (!new_queue_depth) |
| 329 | new_queue_depth = sdev->queue_depth - 1; |
| 330 | else |
| 331 | new_queue_depth = sdev->queue_depth - |
| 332 | new_queue_depth; |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 333 | scsi_change_queue_depth(sdev, new_queue_depth); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 334 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 335 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 336 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 337 | atomic_set(&phba->num_rsrc_err, 0); |
| 338 | atomic_set(&phba->num_cmd_success, 0); |
| 339 | } |
| 340 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 341 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 342 | * lpfc_scsi_dev_block - set all scsi hosts to block state |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 343 | * @phba: Pointer to HBA context object. |
| 344 | * |
| 345 | * This function walks vport list and set each SCSI host to block state |
| 346 | * by invoking fc_remote_port_delete() routine. This function is invoked |
| 347 | * with EEH when device's PCI slot has been permanently disabled. |
| 348 | **/ |
| 349 | void |
| 350 | lpfc_scsi_dev_block(struct lpfc_hba *phba) |
| 351 | { |
| 352 | struct lpfc_vport **vports; |
| 353 | struct Scsi_Host *shost; |
| 354 | struct scsi_device *sdev; |
| 355 | struct fc_rport *rport; |
| 356 | int i; |
| 357 | |
| 358 | vports = lpfc_create_vport_work_array(phba); |
| 359 | if (vports != NULL) |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 360 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 361 | shost = lpfc_shost_from_vport(vports[i]); |
| 362 | shost_for_each_device(sdev, shost) { |
| 363 | rport = starget_to_rport(scsi_target(sdev)); |
| 364 | fc_remote_port_delete(rport); |
| 365 | } |
| 366 | } |
| 367 | lpfc_destroy_vport_work_array(phba, vports); |
| 368 | } |
| 369 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 370 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 371 | * 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] | 372 | * @vport: The virtual port for which this call being executed. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 373 | * @num_to_allocate: The requested number of buffers to allocate. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 374 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 375 | * This routine allocates a scsi buffer for device with SLI-3 interface spec, |
| 376 | * the scsi buffer contains all the necessary information needed to initiate |
| 377 | * a SCSI I/O. The non-DMAable buffer region contains information to build |
| 378 | * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP, |
| 379 | * and the initial BPL. In addition to allocating memory, the FCP CMND and |
| 380 | * 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] | 381 | * |
| 382 | * Return codes: |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 383 | * int - number of scsi buffers that were allocated. |
| 384 | * 0 = failure, less than num_to_alloc is a partial failure. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 385 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 386 | static int |
| 387 | lpfc_new_scsi_buf_s3(struct lpfc_vport *vport, int num_to_alloc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 388 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 389 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 390 | struct lpfc_scsi_buf *psb; |
| 391 | struct ulp_bde64 *bpl; |
| 392 | IOCB_t *iocb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 393 | dma_addr_t pdma_phys_fcp_cmd; |
| 394 | dma_addr_t pdma_phys_fcp_rsp; |
| 395 | dma_addr_t pdma_phys_bpl; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 396 | uint16_t iotag; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 397 | int bcnt, bpl_size; |
| 398 | |
| 399 | bpl_size = phba->cfg_sg_dma_buf_size - |
| 400 | (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); |
| 401 | |
| 402 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 403 | "9067 ALLOC %d scsi_bufs: %d (%d + %d + %d)\n", |
| 404 | num_to_alloc, phba->cfg_sg_dma_buf_size, |
| 405 | (int)sizeof(struct fcp_cmnd), |
| 406 | (int)sizeof(struct fcp_rsp), bpl_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 407 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 408 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
| 409 | psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL); |
| 410 | if (!psb) |
| 411 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 412 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 413 | /* |
| 414 | * Get memory from the pci pool to map the virt space to pci |
| 415 | * bus space for an I/O. The DMA buffer includes space for the |
| 416 | * struct fcp_cmnd, struct fcp_rsp and the number of bde's |
| 417 | * necessary to support the sg_tablesize. |
| 418 | */ |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 419 | psb->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 420 | GFP_KERNEL, &psb->dma_handle); |
| 421 | if (!psb->data) { |
| 422 | kfree(psb); |
| 423 | break; |
| 424 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 425 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 426 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 427 | /* Allocate iotag for psb->cur_iocbq. */ |
| 428 | iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq); |
| 429 | if (iotag == 0) { |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 430 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 431 | psb->data, psb->dma_handle); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 432 | kfree(psb); |
| 433 | break; |
| 434 | } |
| 435 | psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 436 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 437 | psb->fcp_cmnd = psb->data; |
| 438 | psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd); |
| 439 | psb->fcp_bpl = psb->data + sizeof(struct fcp_cmnd) + |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 440 | sizeof(struct fcp_rsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 441 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 442 | /* Initialize local short-hand pointers. */ |
| 443 | bpl = psb->fcp_bpl; |
| 444 | pdma_phys_fcp_cmd = psb->dma_handle; |
| 445 | pdma_phys_fcp_rsp = psb->dma_handle + sizeof(struct fcp_cmnd); |
| 446 | pdma_phys_bpl = psb->dma_handle + sizeof(struct fcp_cmnd) + |
| 447 | sizeof(struct fcp_rsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 448 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 449 | /* |
| 450 | * The first two bdes are the FCP_CMD and FCP_RSP. The balance |
| 451 | * are sg list bdes. Initialize the first two and leave the |
| 452 | * rest for queuecommand. |
| 453 | */ |
| 454 | bpl[0].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd)); |
| 455 | bpl[0].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd)); |
| 456 | bpl[0].tus.f.bdeSize = sizeof(struct fcp_cmnd); |
| 457 | bpl[0].tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 458 | bpl[0].tus.w = le32_to_cpu(bpl[0].tus.w); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 459 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 460 | /* Setup the physical region for the FCP RSP */ |
| 461 | bpl[1].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp)); |
| 462 | bpl[1].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp)); |
| 463 | bpl[1].tus.f.bdeSize = sizeof(struct fcp_rsp); |
| 464 | bpl[1].tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 465 | bpl[1].tus.w = le32_to_cpu(bpl[1].tus.w); |
| 466 | |
| 467 | /* |
| 468 | * Since the IOCB for the FCP I/O is built into this |
| 469 | * lpfc_scsi_buf, initialize it with all known data now. |
| 470 | */ |
| 471 | iocb = &psb->cur_iocbq.iocb; |
| 472 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; |
| 473 | if ((phba->sli_rev == 3) && |
| 474 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) { |
| 475 | /* fill in immediate fcp command BDE */ |
| 476 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_IMMED; |
| 477 | iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); |
| 478 | iocb->un.fcpi64.bdl.addrLow = offsetof(IOCB_t, |
| 479 | unsli3.fcp_ext.icd); |
| 480 | iocb->un.fcpi64.bdl.addrHigh = 0; |
| 481 | iocb->ulpBdeCount = 0; |
| 482 | iocb->ulpLe = 0; |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 483 | /* fill in response BDE */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 484 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeFlags = |
| 485 | BUFF_TYPE_BDE_64; |
| 486 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeSize = |
| 487 | sizeof(struct fcp_rsp); |
| 488 | iocb->unsli3.fcp_ext.rbde.addrLow = |
| 489 | putPaddrLow(pdma_phys_fcp_rsp); |
| 490 | iocb->unsli3.fcp_ext.rbde.addrHigh = |
| 491 | putPaddrHigh(pdma_phys_fcp_rsp); |
| 492 | } else { |
| 493 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
| 494 | iocb->un.fcpi64.bdl.bdeSize = |
| 495 | (2 * sizeof(struct ulp_bde64)); |
| 496 | iocb->un.fcpi64.bdl.addrLow = |
| 497 | putPaddrLow(pdma_phys_bpl); |
| 498 | iocb->un.fcpi64.bdl.addrHigh = |
| 499 | putPaddrHigh(pdma_phys_bpl); |
| 500 | iocb->ulpBdeCount = 1; |
| 501 | iocb->ulpLe = 1; |
| 502 | } |
| 503 | iocb->ulpClass = CLASS3; |
| 504 | psb->status = IOSTAT_SUCCESS; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 505 | /* Put it back into the SCSI buffer list */ |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 506 | psb->cur_iocbq.context1 = psb; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 507 | lpfc_release_scsi_buf_s3(phba, psb); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 508 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 509 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 510 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 511 | return bcnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 512 | } |
| 513 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 514 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 515 | * lpfc_sli4_vport_delete_fcp_xri_aborted -Remove all ndlp references for vport |
| 516 | * @vport: pointer to lpfc vport data structure. |
| 517 | * |
| 518 | * This routine is invoked by the vport cleanup for deletions and the cleanup |
| 519 | * for an ndlp on removal. |
| 520 | **/ |
| 521 | void |
| 522 | lpfc_sli4_vport_delete_fcp_xri_aborted(struct lpfc_vport *vport) |
| 523 | { |
| 524 | struct lpfc_hba *phba = vport->phba; |
| 525 | struct lpfc_scsi_buf *psb, *next_psb; |
| 526 | unsigned long iflag = 0; |
| 527 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 528 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 529 | return; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 530 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 531 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 532 | list_for_each_entry_safe(psb, next_psb, |
| 533 | &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) { |
| 534 | if (psb->rdata && psb->rdata->pnode |
| 535 | && psb->rdata->pnode->vport == vport) |
| 536 | psb->rdata = NULL; |
| 537 | } |
| 538 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 539 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 540 | } |
| 541 | |
| 542 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 543 | * lpfc_sli4_fcp_xri_aborted - Fast-path process of fcp xri abort |
| 544 | * @phba: pointer to lpfc hba data structure. |
| 545 | * @axri: pointer to the fcp xri abort wcqe structure. |
| 546 | * |
| 547 | * This routine is invoked by the worker thread to process a SLI4 fast-path |
| 548 | * FCP aborted xri. |
| 549 | **/ |
| 550 | void |
| 551 | lpfc_sli4_fcp_xri_aborted(struct lpfc_hba *phba, |
| 552 | struct sli4_wcqe_xri_aborted *axri) |
| 553 | { |
| 554 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 555 | uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 556 | struct lpfc_scsi_buf *psb, *next_psb; |
| 557 | unsigned long iflag = 0; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 558 | struct lpfc_iocbq *iocbq; |
| 559 | int i; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 560 | struct lpfc_nodelist *ndlp; |
| 561 | int rrq_empty = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 562 | struct lpfc_sli_ring *pring = phba->sli4_hba.els_wq->pring; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 563 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 564 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 565 | return; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 566 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 567 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 568 | list_for_each_entry_safe(psb, next_psb, |
| 569 | &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) { |
| 570 | if (psb->cur_iocbq.sli4_xritag == xri) { |
| 571 | list_del(&psb->list); |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 572 | psb->exch_busy = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 573 | psb->status = IOSTAT_SUCCESS; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 574 | spin_unlock( |
| 575 | &phba->sli4_hba.abts_scsi_buf_list_lock); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 576 | if (psb->rdata && psb->rdata->pnode) |
| 577 | ndlp = psb->rdata->pnode; |
| 578 | else |
| 579 | ndlp = NULL; |
| 580 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 581 | rrq_empty = list_empty(&phba->active_rrq_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 582 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 583 | if (ndlp) { |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 584 | lpfc_set_rrq_active(phba, ndlp, |
| 585 | psb->cur_iocbq.sli4_lxritag, rxid, 1); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 586 | lpfc_sli4_abts_err_handler(phba, ndlp, axri); |
| 587 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 588 | lpfc_release_scsi_buf_s4(phba, psb); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 589 | if (rrq_empty) |
| 590 | lpfc_worker_wake_up(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 591 | return; |
| 592 | } |
| 593 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 594 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 595 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 596 | iocbq = phba->sli.iocbq_lookup[i]; |
| 597 | |
| 598 | if (!(iocbq->iocb_flag & LPFC_IO_FCP) || |
| 599 | (iocbq->iocb_flag & LPFC_IO_LIBDFC)) |
| 600 | continue; |
| 601 | if (iocbq->sli4_xritag != xri) |
| 602 | continue; |
| 603 | psb = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
| 604 | psb->exch_busy = 0; |
| 605 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 606 | if (!list_empty(&pring->txq)) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 607 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 608 | return; |
| 609 | |
| 610 | } |
| 611 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | /** |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 615 | * lpfc_sli4_post_scsi_sgl_list - Post blocks of scsi buffer sgls from a list |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 616 | * @phba: pointer to lpfc hba data structure. |
| 617 | * @post_sblist: pointer to the scsi buffer list. |
| 618 | * |
| 619 | * This routine walks a list of scsi buffers that was passed in. It attempts |
| 620 | * to construct blocks of scsi buffer sgls which contains contiguous xris and |
| 621 | * uses the non-embedded SGL block post mailbox commands to post to the port. |
| 622 | * For single SCSI buffer sgl with non-contiguous xri, if any, it shall use |
| 623 | * embedded SGL post mailbox command for posting. The @post_sblist passed in |
| 624 | * must be local list, thus no lock is needed when manipulate the list. |
| 625 | * |
| 626 | * Returns: 0 = failure, non-zero number of successfully posted buffers. |
| 627 | **/ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 628 | static int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 629 | lpfc_sli4_post_scsi_sgl_list(struct lpfc_hba *phba, |
| 630 | struct list_head *post_sblist, int sb_count) |
| 631 | { |
| 632 | struct lpfc_scsi_buf *psb, *psb_next; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 633 | int status, sgl_size; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 634 | int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0; |
| 635 | dma_addr_t pdma_phys_bpl1; |
| 636 | int last_xritag = NO_XRI; |
| 637 | LIST_HEAD(prep_sblist); |
| 638 | LIST_HEAD(blck_sblist); |
| 639 | LIST_HEAD(scsi_sblist); |
| 640 | |
| 641 | /* sanity check */ |
| 642 | if (sb_count <= 0) |
| 643 | return -EINVAL; |
| 644 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 645 | sgl_size = phba->cfg_sg_dma_buf_size - |
| 646 | (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); |
| 647 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 648 | list_for_each_entry_safe(psb, psb_next, post_sblist, list) { |
| 649 | list_del_init(&psb->list); |
| 650 | block_cnt++; |
| 651 | if ((last_xritag != NO_XRI) && |
| 652 | (psb->cur_iocbq.sli4_xritag != last_xritag + 1)) { |
| 653 | /* a hole in xri block, form a sgl posting block */ |
| 654 | list_splice_init(&prep_sblist, &blck_sblist); |
| 655 | post_cnt = block_cnt - 1; |
| 656 | /* prepare list for next posting block */ |
| 657 | list_add_tail(&psb->list, &prep_sblist); |
| 658 | block_cnt = 1; |
| 659 | } else { |
| 660 | /* prepare list for next posting block */ |
| 661 | list_add_tail(&psb->list, &prep_sblist); |
| 662 | /* enough sgls for non-embed sgl mbox command */ |
| 663 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 664 | list_splice_init(&prep_sblist, &blck_sblist); |
| 665 | post_cnt = block_cnt; |
| 666 | block_cnt = 0; |
| 667 | } |
| 668 | } |
| 669 | num_posting++; |
| 670 | last_xritag = psb->cur_iocbq.sli4_xritag; |
| 671 | |
| 672 | /* end of repost sgl list condition for SCSI buffers */ |
| 673 | if (num_posting == sb_count) { |
| 674 | if (post_cnt == 0) { |
| 675 | /* last sgl posting block */ |
| 676 | list_splice_init(&prep_sblist, &blck_sblist); |
| 677 | post_cnt = block_cnt; |
| 678 | } else if (block_cnt == 1) { |
| 679 | /* last single sgl with non-contiguous xri */ |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 680 | if (sgl_size > SGL_PAGE_SIZE) |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 681 | pdma_phys_bpl1 = psb->dma_phys_bpl + |
| 682 | SGL_PAGE_SIZE; |
| 683 | else |
| 684 | pdma_phys_bpl1 = 0; |
| 685 | status = lpfc_sli4_post_sgl(phba, |
| 686 | psb->dma_phys_bpl, |
| 687 | pdma_phys_bpl1, |
| 688 | psb->cur_iocbq.sli4_xritag); |
| 689 | if (status) { |
| 690 | /* failure, put on abort scsi list */ |
| 691 | psb->exch_busy = 1; |
| 692 | } else { |
| 693 | /* success, put on SCSI buffer list */ |
| 694 | psb->exch_busy = 0; |
| 695 | psb->status = IOSTAT_SUCCESS; |
| 696 | num_posted++; |
| 697 | } |
| 698 | /* success, put on SCSI buffer sgl list */ |
| 699 | list_add_tail(&psb->list, &scsi_sblist); |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | /* continue until a nembed page worth of sgls */ |
| 704 | if (post_cnt == 0) |
| 705 | continue; |
| 706 | |
| 707 | /* post block of SCSI buffer list sgls */ |
| 708 | status = lpfc_sli4_post_scsi_sgl_block(phba, &blck_sblist, |
| 709 | post_cnt); |
| 710 | |
| 711 | /* don't reset xirtag due to hole in xri block */ |
| 712 | if (block_cnt == 0) |
| 713 | last_xritag = NO_XRI; |
| 714 | |
| 715 | /* reset SCSI buffer post count for next round of posting */ |
| 716 | post_cnt = 0; |
| 717 | |
| 718 | /* put posted SCSI buffer-sgl posted on SCSI buffer sgl list */ |
| 719 | while (!list_empty(&blck_sblist)) { |
| 720 | list_remove_head(&blck_sblist, psb, |
| 721 | struct lpfc_scsi_buf, list); |
| 722 | if (status) { |
| 723 | /* failure, put on abort scsi list */ |
| 724 | psb->exch_busy = 1; |
| 725 | } else { |
| 726 | /* success, put on SCSI buffer list */ |
| 727 | psb->exch_busy = 0; |
| 728 | psb->status = IOSTAT_SUCCESS; |
| 729 | num_posted++; |
| 730 | } |
| 731 | list_add_tail(&psb->list, &scsi_sblist); |
| 732 | } |
| 733 | } |
| 734 | /* Push SCSI buffers with sgl posted to the availble list */ |
| 735 | while (!list_empty(&scsi_sblist)) { |
| 736 | list_remove_head(&scsi_sblist, psb, |
| 737 | struct lpfc_scsi_buf, list); |
| 738 | lpfc_release_scsi_buf_s4(phba, psb); |
| 739 | } |
| 740 | return num_posted; |
| 741 | } |
| 742 | |
| 743 | /** |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 744 | * lpfc_sli4_repost_scsi_sgl_list - Repost all the allocated scsi buffer sgls |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 745 | * @phba: pointer to lpfc hba data structure. |
| 746 | * |
| 747 | * This routine walks the list of scsi buffers that have been allocated and |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 748 | * repost them to the port by using SGL block post. This is needed after a |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 749 | * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine |
| 750 | * is responsible for moving all scsi buffers on the lpfc_abts_scsi_sgl_list |
| 751 | * to the lpfc_scsi_buf_list. If the repost fails, reject all scsi buffers. |
| 752 | * |
| 753 | * Returns: 0 = success, non-zero failure. |
| 754 | **/ |
| 755 | int |
| 756 | lpfc_sli4_repost_scsi_sgl_list(struct lpfc_hba *phba) |
| 757 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 758 | LIST_HEAD(post_sblist); |
| 759 | int num_posted, rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 760 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 761 | /* get all SCSI buffers need to repost to a local list */ |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 762 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 763 | spin_lock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 764 | list_splice_init(&phba->lpfc_scsi_buf_list_get, &post_sblist); |
| 765 | list_splice(&phba->lpfc_scsi_buf_list_put, &post_sblist); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 766 | spin_unlock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 767 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 768 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 769 | /* post the list of scsi buffer sgls to port if available */ |
| 770 | if (!list_empty(&post_sblist)) { |
| 771 | num_posted = lpfc_sli4_post_scsi_sgl_list(phba, &post_sblist, |
| 772 | phba->sli4_hba.scsi_xri_cnt); |
| 773 | /* failed to post any scsi buffer, return error */ |
| 774 | if (num_posted == 0) |
| 775 | rc = -EIO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 776 | } |
| 777 | return rc; |
| 778 | } |
| 779 | |
| 780 | /** |
| 781 | * lpfc_new_scsi_buf_s4 - Scsi buffer allocator for HBA with SLI4 IF spec |
| 782 | * @vport: The virtual port for which this call being executed. |
| 783 | * @num_to_allocate: The requested number of buffers to allocate. |
| 784 | * |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 785 | * This routine allocates scsi buffers for device with SLI-4 interface spec, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 786 | * the scsi buffer contains all the necessary information needed to initiate |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 787 | * a SCSI I/O. After allocating up to @num_to_allocate SCSI buffers and put |
| 788 | * them on a list, it post them to the port by using SGL block post. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 789 | * |
| 790 | * Return codes: |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 791 | * int - number of scsi buffers that were allocated and posted. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 792 | * 0 = failure, less than num_to_alloc is a partial failure. |
| 793 | **/ |
| 794 | static int |
| 795 | lpfc_new_scsi_buf_s4(struct lpfc_vport *vport, int num_to_alloc) |
| 796 | { |
| 797 | struct lpfc_hba *phba = vport->phba; |
| 798 | struct lpfc_scsi_buf *psb; |
| 799 | struct sli4_sge *sgl; |
| 800 | IOCB_t *iocb; |
| 801 | dma_addr_t pdma_phys_fcp_cmd; |
| 802 | dma_addr_t pdma_phys_fcp_rsp; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 803 | dma_addr_t pdma_phys_bpl; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 804 | uint16_t iotag, lxri = 0; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 805 | int bcnt, num_posted, sgl_size; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 806 | LIST_HEAD(prep_sblist); |
| 807 | LIST_HEAD(post_sblist); |
| 808 | LIST_HEAD(scsi_sblist); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 809 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 810 | sgl_size = phba->cfg_sg_dma_buf_size - |
| 811 | (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); |
| 812 | |
| 813 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 814 | "9068 ALLOC %d scsi_bufs: %d (%d + %d + %d)\n", |
| 815 | num_to_alloc, phba->cfg_sg_dma_buf_size, sgl_size, |
| 816 | (int)sizeof(struct fcp_cmnd), |
| 817 | (int)sizeof(struct fcp_rsp)); |
| 818 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 819 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
| 820 | psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL); |
| 821 | if (!psb) |
| 822 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 823 | /* |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 824 | * Get memory from the pci pool to map the virt space to |
| 825 | * pci bus space for an I/O. The DMA buffer includes space |
| 826 | * for the struct fcp_cmnd, struct fcp_rsp and the number |
| 827 | * of bde's necessary to support the sg_tablesize. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 828 | */ |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 829 | psb->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 830 | GFP_KERNEL, &psb->dma_handle); |
| 831 | if (!psb->data) { |
| 832 | kfree(psb); |
| 833 | break; |
| 834 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 835 | |
James Smart | 092cb03 | 2013-09-06 12:21:50 -0400 | [diff] [blame] | 836 | /* |
| 837 | * 4K Page alignment is CRITICAL to BlockGuard, double check |
| 838 | * to be sure. |
| 839 | */ |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 840 | if ((phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
| 841 | (((unsigned long)(psb->data) & |
James Smart | 092cb03 | 2013-09-06 12:21:50 -0400 | [diff] [blame] | 842 | (unsigned long)(SLI4_PAGE_SIZE - 1)) != 0)) { |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 843 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 844 | "3369 Memory alignment error " |
| 845 | "addr=%lx\n", |
| 846 | (unsigned long)psb->data); |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 847 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 848 | psb->data, psb->dma_handle); |
| 849 | kfree(psb); |
| 850 | break; |
| 851 | } |
| 852 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 853 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 854 | lxri = lpfc_sli4_next_xritag(phba); |
| 855 | if (lxri == NO_XRI) { |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 856 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 857 | psb->data, psb->dma_handle); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 858 | kfree(psb); |
| 859 | break; |
| 860 | } |
James Smart | f7bc643 | 2013-10-10 12:19:53 -0400 | [diff] [blame] | 861 | |
| 862 | /* Allocate iotag for psb->cur_iocbq. */ |
| 863 | iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq); |
| 864 | if (iotag == 0) { |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 865 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 866 | psb->data, psb->dma_handle); |
James Smart | f7bc643 | 2013-10-10 12:19:53 -0400 | [diff] [blame] | 867 | kfree(psb); |
| 868 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 869 | "3368 Failed to allocate IOTAG for" |
James Smart | f7bc643 | 2013-10-10 12:19:53 -0400 | [diff] [blame] | 870 | " XRI:0x%x\n", lxri); |
| 871 | lpfc_sli4_free_xri(phba, lxri); |
| 872 | break; |
| 873 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 874 | psb->cur_iocbq.sli4_lxritag = lxri; |
| 875 | psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 876 | psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 877 | psb->fcp_bpl = psb->data; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 878 | psb->fcp_cmnd = (psb->data + sgl_size); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 879 | psb->fcp_rsp = (struct fcp_rsp *)((uint8_t *)psb->fcp_cmnd + |
| 880 | sizeof(struct fcp_cmnd)); |
| 881 | |
| 882 | /* Initialize local short-hand pointers. */ |
| 883 | sgl = (struct sli4_sge *)psb->fcp_bpl; |
| 884 | pdma_phys_bpl = psb->dma_handle; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 885 | pdma_phys_fcp_cmd = (psb->dma_handle + sgl_size); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 886 | pdma_phys_fcp_rsp = pdma_phys_fcp_cmd + sizeof(struct fcp_cmnd); |
| 887 | |
| 888 | /* |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 889 | * The first two bdes are the FCP_CMD and FCP_RSP. |
| 890 | * The balance are sg list bdes. Initialize the |
| 891 | * first two and leave the rest for queuecommand. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 892 | */ |
| 893 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd)); |
| 894 | sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd)); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 895 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 896 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 897 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 898 | sgl->sge_len = cpu_to_le32(sizeof(struct fcp_cmnd)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 899 | sgl++; |
| 900 | |
| 901 | /* Setup the physical region for the FCP RSP */ |
| 902 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp)); |
| 903 | sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp)); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 904 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 905 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 906 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 907 | sgl->sge_len = cpu_to_le32(sizeof(struct fcp_rsp)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 908 | |
| 909 | /* |
| 910 | * Since the IOCB for the FCP I/O is built into this |
| 911 | * lpfc_scsi_buf, initialize it with all known data now. |
| 912 | */ |
| 913 | iocb = &psb->cur_iocbq.iocb; |
| 914 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; |
| 915 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_64; |
| 916 | /* setting the BLP size to 2 * sizeof BDE may not be correct. |
| 917 | * We are setting the bpl to point to out sgl. An sgl's |
| 918 | * entries are 16 bytes, a bpl entries are 12 bytes. |
| 919 | */ |
| 920 | iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); |
| 921 | iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys_fcp_cmd); |
| 922 | iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys_fcp_cmd); |
| 923 | iocb->ulpBdeCount = 1; |
| 924 | iocb->ulpLe = 1; |
| 925 | iocb->ulpClass = CLASS3; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 926 | psb->cur_iocbq.context1 = psb; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 927 | psb->dma_phys_bpl = pdma_phys_bpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 928 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 929 | /* add the scsi buffer to a post list */ |
| 930 | list_add_tail(&psb->list, &post_sblist); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 931 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 932 | phba->sli4_hba.scsi_xri_cnt++; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 933 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 934 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 935 | lpfc_printf_log(phba, KERN_INFO, LOG_BG | LOG_FCP, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 936 | "3021 Allocate %d out of %d requested new SCSI " |
| 937 | "buffers\n", bcnt, num_to_alloc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 938 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 939 | /* post the list of scsi buffer sgls to port if available */ |
| 940 | if (!list_empty(&post_sblist)) |
| 941 | num_posted = lpfc_sli4_post_scsi_sgl_list(phba, |
| 942 | &post_sblist, bcnt); |
| 943 | else |
| 944 | num_posted = 0; |
| 945 | |
| 946 | return num_posted; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 950 | * lpfc_new_scsi_buf - Wrapper funciton for scsi buffer allocator |
| 951 | * @vport: The virtual port for which this call being executed. |
| 952 | * @num_to_allocate: The requested number of buffers to allocate. |
| 953 | * |
| 954 | * This routine wraps the actual SCSI buffer allocator function pointer from |
| 955 | * the lpfc_hba struct. |
| 956 | * |
| 957 | * Return codes: |
| 958 | * int - number of scsi buffers that were allocated. |
| 959 | * 0 = failure, less than num_to_alloc is a partial failure. |
| 960 | **/ |
| 961 | static inline int |
| 962 | lpfc_new_scsi_buf(struct lpfc_vport *vport, int num_to_alloc) |
| 963 | { |
| 964 | return vport->phba->lpfc_new_scsi_buf(vport, num_to_alloc); |
| 965 | } |
| 966 | |
| 967 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 968 | * 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] | 969 | * @phba: The HBA for which this call is being executed. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 970 | * |
| 971 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list |
| 972 | * and returns to caller. |
| 973 | * |
| 974 | * Return codes: |
| 975 | * NULL - Error |
| 976 | * Pointer to lpfc_scsi_buf - Success |
| 977 | **/ |
Adrian Bunk | 455c53e | 2006-01-06 20:21:28 +0100 | [diff] [blame] | 978 | static struct lpfc_scsi_buf* |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 979 | lpfc_get_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 980 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 981 | struct lpfc_scsi_buf * lpfc_cmd = NULL; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 982 | 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] | 983 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 984 | |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 985 | spin_lock_irqsave(&phba->scsi_buf_list_get_lock, iflag); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 986 | list_remove_head(scsi_buf_list_get, lpfc_cmd, struct lpfc_scsi_buf, |
| 987 | list); |
| 988 | if (!lpfc_cmd) { |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 989 | spin_lock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 990 | list_splice(&phba->lpfc_scsi_buf_list_put, |
| 991 | &phba->lpfc_scsi_buf_list_get); |
| 992 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
| 993 | list_remove_head(scsi_buf_list_get, lpfc_cmd, |
| 994 | struct lpfc_scsi_buf, list); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 995 | spin_unlock(&phba->scsi_buf_list_put_lock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 996 | } |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 997 | spin_unlock_irqrestore(&phba->scsi_buf_list_get_lock, iflag); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 998 | return lpfc_cmd; |
| 999 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1000 | /** |
| 1001 | * lpfc_get_scsi_buf_s4 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA |
| 1002 | * @phba: The HBA for which this call is being executed. |
| 1003 | * |
| 1004 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list |
| 1005 | * and returns to caller. |
| 1006 | * |
| 1007 | * Return codes: |
| 1008 | * NULL - Error |
| 1009 | * Pointer to lpfc_scsi_buf - Success |
| 1010 | **/ |
| 1011 | static struct lpfc_scsi_buf* |
| 1012 | lpfc_get_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| 1013 | { |
James Smart | 3be30e0 | 2013-05-31 17:05:17 -0400 | [diff] [blame] | 1014 | struct lpfc_scsi_buf *lpfc_cmd, *lpfc_cmd_next; |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 1015 | unsigned long iflag = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1016 | int found = 0; |
| 1017 | |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 1018 | spin_lock_irqsave(&phba->scsi_buf_list_get_lock, iflag); |
James Smart | 3be30e0 | 2013-05-31 17:05:17 -0400 | [diff] [blame] | 1019 | list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next, |
| 1020 | &phba->lpfc_scsi_buf_list_get, list) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1021 | if (lpfc_test_rrq_active(phba, ndlp, |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 1022 | lpfc_cmd->cur_iocbq.sli4_lxritag)) |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1023 | continue; |
| 1024 | list_del(&lpfc_cmd->list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1025 | found = 1; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1026 | break; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1027 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1028 | if (!found) { |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 1029 | spin_lock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1030 | list_splice(&phba->lpfc_scsi_buf_list_put, |
| 1031 | &phba->lpfc_scsi_buf_list_get); |
| 1032 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 1033 | spin_unlock(&phba->scsi_buf_list_put_lock); |
James Smart | 3be30e0 | 2013-05-31 17:05:17 -0400 | [diff] [blame] | 1034 | list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next, |
| 1035 | &phba->lpfc_scsi_buf_list_get, list) { |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1036 | if (lpfc_test_rrq_active( |
| 1037 | phba, ndlp, lpfc_cmd->cur_iocbq.sli4_lxritag)) |
| 1038 | continue; |
| 1039 | list_del(&lpfc_cmd->list); |
| 1040 | found = 1; |
| 1041 | break; |
| 1042 | } |
| 1043 | } |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 1044 | spin_unlock_irqrestore(&phba->scsi_buf_list_get_lock, iflag); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1045 | if (!found) |
| 1046 | return NULL; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1047 | return lpfc_cmd; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1048 | } |
| 1049 | /** |
| 1050 | * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA |
| 1051 | * @phba: The HBA for which this call is being executed. |
| 1052 | * |
| 1053 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list |
| 1054 | * and returns to caller. |
| 1055 | * |
| 1056 | * Return codes: |
| 1057 | * NULL - Error |
| 1058 | * Pointer to lpfc_scsi_buf - Success |
| 1059 | **/ |
| 1060 | static struct lpfc_scsi_buf* |
| 1061 | lpfc_get_scsi_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| 1062 | { |
| 1063 | return phba->lpfc_get_scsi_buf(phba, ndlp); |
| 1064 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1065 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 1066 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1067 | * 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] | 1068 | * @phba: The Hba for which this call is being executed. |
| 1069 | * @psb: The scsi buffer which is being released. |
| 1070 | * |
| 1071 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
| 1072 | * lpfc_scsi_buf_list list. |
| 1073 | **/ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1074 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1075 | 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] | 1076 | { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1077 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1078 | |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1079 | psb->seg_cnt = 0; |
| 1080 | psb->nonsg_phys = 0; |
| 1081 | psb->prot_seg_cnt = 0; |
| 1082 | |
| 1083 | spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1084 | psb->pCmd = NULL; |
James Smart | 6a485eb | 2013-04-17 20:19:00 -0400 | [diff] [blame] | 1085 | psb->cur_iocbq.iocb_flag = LPFC_IO_FCP; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1086 | list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list_put); |
| 1087 | spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1088 | } |
| 1089 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 1090 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1091 | * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list. |
| 1092 | * @phba: The Hba for which this call is being executed. |
| 1093 | * @psb: The scsi buffer which is being released. |
| 1094 | * |
| 1095 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
| 1096 | * lpfc_scsi_buf_list list. For SLI4 XRI's are tied to the scsi buffer |
| 1097 | * and cannot be reused for at least RA_TOV amount of time if it was |
| 1098 | * aborted. |
| 1099 | **/ |
| 1100 | static void |
| 1101 | lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) |
| 1102 | { |
| 1103 | unsigned long iflag = 0; |
| 1104 | |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1105 | psb->seg_cnt = 0; |
| 1106 | psb->nonsg_phys = 0; |
| 1107 | psb->prot_seg_cnt = 0; |
| 1108 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 1109 | if (psb->exch_busy) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1110 | spin_lock_irqsave(&phba->sli4_hba.abts_scsi_buf_list_lock, |
| 1111 | iflag); |
| 1112 | psb->pCmd = NULL; |
| 1113 | list_add_tail(&psb->list, |
| 1114 | &phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 1115 | spin_unlock_irqrestore(&phba->sli4_hba.abts_scsi_buf_list_lock, |
| 1116 | iflag); |
| 1117 | } else { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1118 | psb->pCmd = NULL; |
James Smart | 6a485eb | 2013-04-17 20:19:00 -0400 | [diff] [blame] | 1119 | psb->cur_iocbq.iocb_flag = LPFC_IO_FCP; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1120 | spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag); |
| 1121 | list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list_put); |
| 1122 | spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1127 | * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list. |
| 1128 | * @phba: The Hba for which this call is being executed. |
| 1129 | * @psb: The scsi buffer which is being released. |
| 1130 | * |
| 1131 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
| 1132 | * lpfc_scsi_buf_list list. |
| 1133 | **/ |
| 1134 | static void |
| 1135 | lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) |
| 1136 | { |
| 1137 | |
| 1138 | phba->lpfc_release_scsi_buf(phba, psb); |
| 1139 | } |
| 1140 | |
| 1141 | /** |
| 1142 | * 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] | 1143 | * @phba: The Hba for which this call is being executed. |
| 1144 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 1145 | * |
| 1146 | * 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] | 1147 | * 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] | 1148 | * through sg elements and format the bde. This routine also initializes all |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1149 | * IOCB fields which are dependent on scsi command request buffer. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 1150 | * |
| 1151 | * Return codes: |
| 1152 | * 1 - Error |
| 1153 | * 0 - Success |
| 1154 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1155 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1156 | 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] | 1157 | { |
| 1158 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 1159 | struct scatterlist *sgel = NULL; |
| 1160 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 1161 | struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1162 | struct lpfc_iocbq *iocbq = &lpfc_cmd->cur_iocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1163 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1164 | struct ulp_bde64 *data_bde = iocb_cmd->unsli3.fcp_ext.dbde; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1165 | dma_addr_t physaddr; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1166 | uint32_t num_bde = 0; |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1167 | int nseg, datadir = scsi_cmnd->sc_data_direction; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1168 | |
| 1169 | /* |
| 1170 | * There are three possibilities here - use scatter-gather segment, use |
| 1171 | * the single mapping, or neither. Start the lpfc command prep by |
| 1172 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 1173 | * data bde entry. |
| 1174 | */ |
| 1175 | bpl += 2; |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 1176 | if (scsi_sg_count(scsi_cmnd)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1177 | /* |
| 1178 | * The driver stores the segment count returned from pci_map_sg |
| 1179 | * because this a count of dma-mappings used to map the use_sg |
| 1180 | * pages. They are not guaranteed to be the same for those |
| 1181 | * architectures that implement an IOMMU. |
| 1182 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1183 | |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 1184 | nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd), |
| 1185 | scsi_sg_count(scsi_cmnd), datadir); |
| 1186 | if (unlikely(!nseg)) |
| 1187 | return 1; |
| 1188 | |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1189 | lpfc_cmd->seg_cnt = nseg; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1190 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1191 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1192 | "9064 BLKGRD: %s: Too many sg segments from " |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1193 | "dma_map_sg. Config %d, seg_cnt %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1194 | __func__, phba->cfg_sg_seg_cnt, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1195 | lpfc_cmd->seg_cnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 1196 | lpfc_cmd->seg_cnt = 0; |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1197 | scsi_dma_unmap(scsi_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1198 | return 1; |
| 1199 | } |
| 1200 | |
| 1201 | /* |
| 1202 | * The driver established a maximum scatter-gather segment count |
| 1203 | * during probe that limits the number of sg elements in any |
| 1204 | * single scsi command. Just run through the seg_cnt and format |
| 1205 | * the bde's. |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1206 | * When using SLI-3 the driver will try to fit all the BDEs into |
| 1207 | * the IOCB. If it can't then the BDEs get added to a BPL as it |
| 1208 | * does for SLI-2 mode. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1209 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1210 | scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1211 | physaddr = sg_dma_address(sgel); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1212 | if (phba->sli_rev == 3 && |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1213 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1214 | !(iocbq->iocb_flag & DSS_SECURITY_OP) && |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1215 | nseg <= LPFC_EXT_DATA_BDE_COUNT) { |
| 1216 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1217 | data_bde->tus.f.bdeSize = sg_dma_len(sgel); |
| 1218 | data_bde->addrLow = putPaddrLow(physaddr); |
| 1219 | data_bde->addrHigh = putPaddrHigh(physaddr); |
| 1220 | data_bde++; |
| 1221 | } else { |
| 1222 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1223 | bpl->tus.f.bdeSize = sg_dma_len(sgel); |
| 1224 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 1225 | bpl->addrLow = |
| 1226 | le32_to_cpu(putPaddrLow(physaddr)); |
| 1227 | bpl->addrHigh = |
| 1228 | le32_to_cpu(putPaddrHigh(physaddr)); |
| 1229 | bpl++; |
| 1230 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1231 | } |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 1232 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1233 | |
| 1234 | /* |
| 1235 | * Finish initializing those IOCB fields that are dependent on the |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1236 | * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is |
| 1237 | * explicitly reinitialized and for SLI-3 the extended bde count is |
| 1238 | * explicitly reinitialized since all iocb memory resources are reused. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1239 | */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1240 | if (phba->sli_rev == 3 && |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1241 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
| 1242 | !(iocbq->iocb_flag & DSS_SECURITY_OP)) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1243 | if (num_bde > LPFC_EXT_DATA_BDE_COUNT) { |
| 1244 | /* |
| 1245 | * The extended IOCB format can only fit 3 BDE or a BPL. |
| 1246 | * This I/O has more than 3 BDE so the 1st data bde will |
| 1247 | * be a BPL that is filled in here. |
| 1248 | */ |
| 1249 | physaddr = lpfc_cmd->dma_handle; |
| 1250 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BLP_64; |
| 1251 | data_bde->tus.f.bdeSize = (num_bde * |
| 1252 | sizeof(struct ulp_bde64)); |
| 1253 | physaddr += (sizeof(struct fcp_cmnd) + |
| 1254 | sizeof(struct fcp_rsp) + |
| 1255 | (2 * sizeof(struct ulp_bde64))); |
| 1256 | data_bde->addrHigh = putPaddrHigh(physaddr); |
| 1257 | data_bde->addrLow = putPaddrLow(physaddr); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1258 | /* ebde count includes the response bde and data bpl */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1259 | iocb_cmd->unsli3.fcp_ext.ebde_count = 2; |
| 1260 | } else { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1261 | /* ebde count includes the response bde and data bdes */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1262 | iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); |
| 1263 | } |
| 1264 | } else { |
| 1265 | iocb_cmd->un.fcpi64.bdl.bdeSize = |
| 1266 | ((num_bde + 2) * sizeof(struct ulp_bde64)); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1267 | iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1268 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1269 | fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1270 | |
| 1271 | /* |
| 1272 | * Due to difference in data length between DIF/non-DIF paths, |
| 1273 | * we need to set word 4 of IOCB here |
| 1274 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1275 | iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1276 | return 0; |
| 1277 | } |
| 1278 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1279 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1280 | |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1281 | /* Return BG_ERR_INIT if error injection is detected by Initiator */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1282 | #define BG_ERR_INIT 0x1 |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1283 | /* Return BG_ERR_TGT if error injection is detected by Target */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1284 | #define BG_ERR_TGT 0x2 |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1285 | /* 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] | 1286 | #define BG_ERR_SWAP 0x10 |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1287 | /** |
| 1288 | * Return BG_ERR_CHECK if disabling Guard/Ref/App checking is required for |
| 1289 | * error injection |
| 1290 | **/ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1291 | #define BG_ERR_CHECK 0x20 |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1292 | |
| 1293 | /** |
| 1294 | * lpfc_bg_err_inject - Determine if we should inject an error |
| 1295 | * @phba: The Hba for which this call is being executed. |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1296 | * @sc: The SCSI command to examine |
| 1297 | * @reftag: (out) BlockGuard reference tag for transmitted data |
| 1298 | * @apptag: (out) BlockGuard application tag for transmitted data |
| 1299 | * @new_guard (in) Value to replace CRC with if needed |
| 1300 | * |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1301 | * Returns BG_ERR_* bit mask or 0 if request ignored |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1302 | **/ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1303 | static int |
| 1304 | lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1305 | uint32_t *reftag, uint16_t *apptag, uint32_t new_guard) |
| 1306 | { |
| 1307 | struct scatterlist *sgpe; /* s/g prot entry */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1308 | struct lpfc_scsi_buf *lpfc_cmd = NULL; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1309 | struct scsi_dif_tuple *src = NULL; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1310 | struct lpfc_nodelist *ndlp; |
| 1311 | struct lpfc_rport_data *rdata; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1312 | uint32_t op = scsi_get_prot_op(sc); |
| 1313 | uint32_t blksize; |
| 1314 | uint32_t numblks; |
| 1315 | sector_t lba; |
| 1316 | int rc = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1317 | int blockoff = 0; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1318 | |
| 1319 | if (op == SCSI_PROT_NORMAL) |
| 1320 | return 0; |
| 1321 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1322 | sgpe = scsi_prot_sglist(sc); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1323 | lba = scsi_get_lba(sc); |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1324 | |
| 1325 | /* First check if we need to match the LBA */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1326 | if (phba->lpfc_injerr_lba != LPFC_INJERR_LBA_OFF) { |
| 1327 | blksize = lpfc_cmd_blksize(sc); |
| 1328 | numblks = (scsi_bufflen(sc) + blksize - 1) / blksize; |
| 1329 | |
| 1330 | /* Make sure we have the right LBA if one is specified */ |
| 1331 | if ((phba->lpfc_injerr_lba < lba) || |
| 1332 | (phba->lpfc_injerr_lba >= (lba + numblks))) |
| 1333 | return 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1334 | if (sgpe) { |
| 1335 | blockoff = phba->lpfc_injerr_lba - lba; |
| 1336 | numblks = sg_dma_len(sgpe) / |
| 1337 | sizeof(struct scsi_dif_tuple); |
| 1338 | if (numblks < blockoff) |
| 1339 | blockoff = numblks; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1340 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1341 | } |
| 1342 | |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1343 | /* Next check if we need to match the remote NPortID or WWPN */ |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 1344 | rdata = lpfc_rport_data_from_scsi_device(sc->device); |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1345 | if (rdata && rdata->pnode) { |
| 1346 | ndlp = rdata->pnode; |
| 1347 | |
| 1348 | /* Make sure we have the right NPortID if one is specified */ |
| 1349 | if (phba->lpfc_injerr_nportid && |
| 1350 | (phba->lpfc_injerr_nportid != ndlp->nlp_DID)) |
| 1351 | return 0; |
| 1352 | |
| 1353 | /* |
| 1354 | * Make sure we have the right WWPN if one is specified. |
| 1355 | * wwn[0] should be a non-zero NAA in a good WWPN. |
| 1356 | */ |
| 1357 | if (phba->lpfc_injerr_wwpn.u.wwn[0] && |
| 1358 | (memcmp(&ndlp->nlp_portname, &phba->lpfc_injerr_wwpn, |
| 1359 | sizeof(struct lpfc_name)) != 0)) |
| 1360 | return 0; |
| 1361 | } |
| 1362 | |
| 1363 | /* Setup a ptr to the protection data if the SCSI host provides it */ |
| 1364 | if (sgpe) { |
| 1365 | src = (struct scsi_dif_tuple *)sg_virt(sgpe); |
| 1366 | src += blockoff; |
| 1367 | lpfc_cmd = (struct lpfc_scsi_buf *)sc->host_scribble; |
| 1368 | } |
| 1369 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1370 | /* Should we change the Reference Tag */ |
| 1371 | if (reftag) { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1372 | if (phba->lpfc_injerr_wref_cnt) { |
| 1373 | switch (op) { |
| 1374 | case SCSI_PROT_WRITE_PASS: |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1375 | if (src) { |
| 1376 | /* |
| 1377 | * For WRITE_PASS, force the error |
| 1378 | * to be sent on the wire. It should |
| 1379 | * be detected by the Target. |
| 1380 | * If blockoff != 0 error will be |
| 1381 | * inserted in middle of the IO. |
| 1382 | */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1383 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1384 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1385 | "9076 BLKGRD: Injecting reftag error: " |
| 1386 | "write lba x%lx + x%x oldrefTag x%x\n", |
| 1387 | (unsigned long)lba, blockoff, |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1388 | be32_to_cpu(src->ref_tag)); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1389 | |
| 1390 | /* |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1391 | * Save the old ref_tag so we can |
| 1392 | * restore it on completion. |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1393 | */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1394 | if (lpfc_cmd) { |
| 1395 | lpfc_cmd->prot_data_type = |
| 1396 | LPFC_INJERR_REFTAG; |
| 1397 | lpfc_cmd->prot_data_segment = |
| 1398 | src; |
| 1399 | lpfc_cmd->prot_data = |
| 1400 | src->ref_tag; |
| 1401 | } |
| 1402 | src->ref_tag = cpu_to_be32(0xDEADBEEF); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1403 | phba->lpfc_injerr_wref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1404 | if (phba->lpfc_injerr_wref_cnt == 0) { |
| 1405 | phba->lpfc_injerr_nportid = 0; |
| 1406 | phba->lpfc_injerr_lba = |
| 1407 | LPFC_INJERR_LBA_OFF; |
| 1408 | memset(&phba->lpfc_injerr_wwpn, |
| 1409 | 0, sizeof(struct lpfc_name)); |
| 1410 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1411 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
| 1412 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1413 | break; |
| 1414 | } |
| 1415 | /* Drop thru */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1416 | case SCSI_PROT_WRITE_INSERT: |
| 1417 | /* |
| 1418 | * For WRITE_INSERT, force the error |
| 1419 | * to be sent on the wire. It should be |
| 1420 | * detected by the Target. |
| 1421 | */ |
| 1422 | /* DEADBEEF will be the reftag on the wire */ |
| 1423 | *reftag = 0xDEADBEEF; |
| 1424 | phba->lpfc_injerr_wref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1425 | if (phba->lpfc_injerr_wref_cnt == 0) { |
| 1426 | phba->lpfc_injerr_nportid = 0; |
| 1427 | phba->lpfc_injerr_lba = |
| 1428 | LPFC_INJERR_LBA_OFF; |
| 1429 | memset(&phba->lpfc_injerr_wwpn, |
| 1430 | 0, sizeof(struct lpfc_name)); |
| 1431 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1432 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
| 1433 | |
| 1434 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1435 | "9078 BLKGRD: Injecting reftag error: " |
| 1436 | "write lba x%lx\n", (unsigned long)lba); |
| 1437 | break; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1438 | case SCSI_PROT_WRITE_STRIP: |
| 1439 | /* |
| 1440 | * For WRITE_STRIP and WRITE_PASS, |
| 1441 | * force the error on data |
| 1442 | * being copied from SLI-Host to SLI-Port. |
| 1443 | */ |
| 1444 | *reftag = 0xDEADBEEF; |
| 1445 | phba->lpfc_injerr_wref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1446 | if (phba->lpfc_injerr_wref_cnt == 0) { |
| 1447 | phba->lpfc_injerr_nportid = 0; |
| 1448 | phba->lpfc_injerr_lba = |
| 1449 | LPFC_INJERR_LBA_OFF; |
| 1450 | memset(&phba->lpfc_injerr_wwpn, |
| 1451 | 0, sizeof(struct lpfc_name)); |
| 1452 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1453 | rc = BG_ERR_INIT; |
| 1454 | |
| 1455 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1456 | "9077 BLKGRD: Injecting reftag error: " |
| 1457 | "write lba x%lx\n", (unsigned long)lba); |
| 1458 | break; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1459 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1460 | } |
| 1461 | if (phba->lpfc_injerr_rref_cnt) { |
| 1462 | switch (op) { |
| 1463 | case SCSI_PROT_READ_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1464 | case SCSI_PROT_READ_STRIP: |
| 1465 | case SCSI_PROT_READ_PASS: |
| 1466 | /* |
| 1467 | * For READ_STRIP and READ_PASS, force the |
| 1468 | * error on data being read off the wire. It |
| 1469 | * should force an IO error to the driver. |
| 1470 | */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1471 | *reftag = 0xDEADBEEF; |
| 1472 | phba->lpfc_injerr_rref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1473 | if (phba->lpfc_injerr_rref_cnt == 0) { |
| 1474 | phba->lpfc_injerr_nportid = 0; |
| 1475 | phba->lpfc_injerr_lba = |
| 1476 | LPFC_INJERR_LBA_OFF; |
| 1477 | memset(&phba->lpfc_injerr_wwpn, |
| 1478 | 0, sizeof(struct lpfc_name)); |
| 1479 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1480 | rc = BG_ERR_INIT; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1481 | |
| 1482 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1483 | "9079 BLKGRD: Injecting reftag error: " |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1484 | "read lba x%lx\n", (unsigned long)lba); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1485 | break; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1486 | } |
| 1487 | } |
| 1488 | } |
| 1489 | |
| 1490 | /* Should we change the Application Tag */ |
| 1491 | if (apptag) { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1492 | if (phba->lpfc_injerr_wapp_cnt) { |
| 1493 | switch (op) { |
| 1494 | case SCSI_PROT_WRITE_PASS: |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1495 | if (src) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1496 | /* |
| 1497 | * For WRITE_PASS, force the error |
| 1498 | * to be sent on the wire. It should |
| 1499 | * be detected by the Target. |
| 1500 | * If blockoff != 0 error will be |
| 1501 | * inserted in middle of the IO. |
| 1502 | */ |
| 1503 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1504 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1505 | "9080 BLKGRD: Injecting apptag error: " |
| 1506 | "write lba x%lx + x%x oldappTag x%x\n", |
| 1507 | (unsigned long)lba, blockoff, |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1508 | be16_to_cpu(src->app_tag)); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1509 | |
| 1510 | /* |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1511 | * Save the old app_tag so we can |
| 1512 | * restore it on completion. |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1513 | */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1514 | if (lpfc_cmd) { |
| 1515 | lpfc_cmd->prot_data_type = |
| 1516 | LPFC_INJERR_APPTAG; |
| 1517 | lpfc_cmd->prot_data_segment = |
| 1518 | src; |
| 1519 | lpfc_cmd->prot_data = |
| 1520 | src->app_tag; |
| 1521 | } |
| 1522 | src->app_tag = cpu_to_be16(0xDEAD); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1523 | phba->lpfc_injerr_wapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1524 | if (phba->lpfc_injerr_wapp_cnt == 0) { |
| 1525 | phba->lpfc_injerr_nportid = 0; |
| 1526 | phba->lpfc_injerr_lba = |
| 1527 | LPFC_INJERR_LBA_OFF; |
| 1528 | memset(&phba->lpfc_injerr_wwpn, |
| 1529 | 0, sizeof(struct lpfc_name)); |
| 1530 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1531 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1532 | break; |
| 1533 | } |
| 1534 | /* Drop thru */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1535 | case SCSI_PROT_WRITE_INSERT: |
| 1536 | /* |
| 1537 | * For WRITE_INSERT, force the |
| 1538 | * error to be sent on the wire. It should be |
| 1539 | * detected by the Target. |
| 1540 | */ |
| 1541 | /* DEAD will be the apptag on the wire */ |
| 1542 | *apptag = 0xDEAD; |
| 1543 | phba->lpfc_injerr_wapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1544 | if (phba->lpfc_injerr_wapp_cnt == 0) { |
| 1545 | phba->lpfc_injerr_nportid = 0; |
| 1546 | phba->lpfc_injerr_lba = |
| 1547 | LPFC_INJERR_LBA_OFF; |
| 1548 | memset(&phba->lpfc_injerr_wwpn, |
| 1549 | 0, sizeof(struct lpfc_name)); |
| 1550 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1551 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
| 1552 | |
| 1553 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1554 | "0813 BLKGRD: Injecting apptag error: " |
| 1555 | "write lba x%lx\n", (unsigned long)lba); |
| 1556 | break; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1557 | case SCSI_PROT_WRITE_STRIP: |
| 1558 | /* |
| 1559 | * For WRITE_STRIP and WRITE_PASS, |
| 1560 | * force the error on data |
| 1561 | * being copied from SLI-Host to SLI-Port. |
| 1562 | */ |
| 1563 | *apptag = 0xDEAD; |
| 1564 | phba->lpfc_injerr_wapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1565 | if (phba->lpfc_injerr_wapp_cnt == 0) { |
| 1566 | phba->lpfc_injerr_nportid = 0; |
| 1567 | phba->lpfc_injerr_lba = |
| 1568 | LPFC_INJERR_LBA_OFF; |
| 1569 | memset(&phba->lpfc_injerr_wwpn, |
| 1570 | 0, sizeof(struct lpfc_name)); |
| 1571 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1572 | rc = BG_ERR_INIT; |
| 1573 | |
| 1574 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1575 | "0812 BLKGRD: Injecting apptag error: " |
| 1576 | "write lba x%lx\n", (unsigned long)lba); |
| 1577 | break; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1578 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1579 | } |
| 1580 | if (phba->lpfc_injerr_rapp_cnt) { |
| 1581 | switch (op) { |
| 1582 | case SCSI_PROT_READ_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1583 | case SCSI_PROT_READ_STRIP: |
| 1584 | case SCSI_PROT_READ_PASS: |
| 1585 | /* |
| 1586 | * For READ_STRIP and READ_PASS, force the |
| 1587 | * error on data being read off the wire. It |
| 1588 | * should force an IO error to the driver. |
| 1589 | */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1590 | *apptag = 0xDEAD; |
| 1591 | phba->lpfc_injerr_rapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1592 | if (phba->lpfc_injerr_rapp_cnt == 0) { |
| 1593 | phba->lpfc_injerr_nportid = 0; |
| 1594 | phba->lpfc_injerr_lba = |
| 1595 | LPFC_INJERR_LBA_OFF; |
| 1596 | memset(&phba->lpfc_injerr_wwpn, |
| 1597 | 0, sizeof(struct lpfc_name)); |
| 1598 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1599 | rc = BG_ERR_INIT; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1600 | |
| 1601 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1602 | "0814 BLKGRD: Injecting apptag error: " |
| 1603 | "read lba x%lx\n", (unsigned long)lba); |
| 1604 | break; |
| 1605 | } |
| 1606 | } |
| 1607 | } |
| 1608 | |
| 1609 | |
| 1610 | /* Should we change the Guard Tag */ |
| 1611 | if (new_guard) { |
| 1612 | if (phba->lpfc_injerr_wgrd_cnt) { |
| 1613 | switch (op) { |
| 1614 | case SCSI_PROT_WRITE_PASS: |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1615 | rc = BG_ERR_CHECK; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1616 | /* Drop thru */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1617 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1618 | case SCSI_PROT_WRITE_INSERT: |
| 1619 | /* |
| 1620 | * For WRITE_INSERT, force the |
| 1621 | * error to be sent on the wire. It should be |
| 1622 | * detected by the Target. |
| 1623 | */ |
| 1624 | phba->lpfc_injerr_wgrd_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1625 | if (phba->lpfc_injerr_wgrd_cnt == 0) { |
| 1626 | phba->lpfc_injerr_nportid = 0; |
| 1627 | phba->lpfc_injerr_lba = |
| 1628 | LPFC_INJERR_LBA_OFF; |
| 1629 | memset(&phba->lpfc_injerr_wwpn, |
| 1630 | 0, sizeof(struct lpfc_name)); |
| 1631 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1632 | |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1633 | rc |= BG_ERR_TGT | BG_ERR_SWAP; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1634 | /* Signals the caller to swap CRC->CSUM */ |
| 1635 | |
| 1636 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1637 | "0817 BLKGRD: Injecting guard error: " |
| 1638 | "write lba x%lx\n", (unsigned long)lba); |
| 1639 | break; |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1640 | case SCSI_PROT_WRITE_STRIP: |
| 1641 | /* |
| 1642 | * For WRITE_STRIP and WRITE_PASS, |
| 1643 | * force the error on data |
| 1644 | * being copied from SLI-Host to SLI-Port. |
| 1645 | */ |
| 1646 | phba->lpfc_injerr_wgrd_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1647 | if (phba->lpfc_injerr_wgrd_cnt == 0) { |
| 1648 | phba->lpfc_injerr_nportid = 0; |
| 1649 | phba->lpfc_injerr_lba = |
| 1650 | LPFC_INJERR_LBA_OFF; |
| 1651 | memset(&phba->lpfc_injerr_wwpn, |
| 1652 | 0, sizeof(struct lpfc_name)); |
| 1653 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1654 | |
| 1655 | rc = BG_ERR_INIT | BG_ERR_SWAP; |
| 1656 | /* Signals the caller to swap CRC->CSUM */ |
| 1657 | |
| 1658 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1659 | "0816 BLKGRD: Injecting guard error: " |
| 1660 | "write lba x%lx\n", (unsigned long)lba); |
| 1661 | break; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1662 | } |
| 1663 | } |
| 1664 | if (phba->lpfc_injerr_rgrd_cnt) { |
| 1665 | switch (op) { |
| 1666 | case SCSI_PROT_READ_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1667 | case SCSI_PROT_READ_STRIP: |
| 1668 | case SCSI_PROT_READ_PASS: |
| 1669 | /* |
| 1670 | * For READ_STRIP and READ_PASS, force the |
| 1671 | * error on data being read off the wire. It |
| 1672 | * should force an IO error to the driver. |
| 1673 | */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1674 | phba->lpfc_injerr_rgrd_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1675 | if (phba->lpfc_injerr_rgrd_cnt == 0) { |
| 1676 | phba->lpfc_injerr_nportid = 0; |
| 1677 | phba->lpfc_injerr_lba = |
| 1678 | LPFC_INJERR_LBA_OFF; |
| 1679 | memset(&phba->lpfc_injerr_wwpn, |
| 1680 | 0, sizeof(struct lpfc_name)); |
| 1681 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1682 | |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1683 | rc = BG_ERR_INIT | BG_ERR_SWAP; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1684 | /* Signals the caller to swap CRC->CSUM */ |
| 1685 | |
| 1686 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1687 | "0818 BLKGRD: Injecting guard error: " |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1688 | "read lba x%lx\n", (unsigned long)lba); |
| 1689 | } |
| 1690 | } |
| 1691 | } |
| 1692 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1693 | return rc; |
| 1694 | } |
| 1695 | #endif |
| 1696 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1697 | /** |
| 1698 | * lpfc_sc_to_bg_opcodes - Determine the BlockGuard opcodes to be used with |
| 1699 | * the specified SCSI command. |
| 1700 | * @phba: The Hba for which this call is being executed. |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1701 | * @sc: The SCSI command to examine |
| 1702 | * @txopt: (out) BlockGuard operation for transmitted data |
| 1703 | * @rxopt: (out) BlockGuard operation for received data |
| 1704 | * |
| 1705 | * Returns: zero on success; non-zero if tx and/or rx op cannot be determined |
| 1706 | * |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1707 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1708 | static int |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1709 | lpfc_sc_to_bg_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1710 | uint8_t *txop, uint8_t *rxop) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1711 | { |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1712 | uint8_t ret = 0; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1713 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1714 | if (lpfc_cmd_guard_csum(sc)) { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1715 | switch (scsi_get_prot_op(sc)) { |
| 1716 | case SCSI_PROT_READ_INSERT: |
| 1717 | case SCSI_PROT_WRITE_STRIP: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1718 | *rxop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1719 | *txop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1720 | break; |
| 1721 | |
| 1722 | case SCSI_PROT_READ_STRIP: |
| 1723 | case SCSI_PROT_WRITE_INSERT: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1724 | *rxop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1725 | *txop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1726 | break; |
| 1727 | |
Martin K. Petersen | c6af404 | 2009-09-18 17:32:59 -0400 | [diff] [blame] | 1728 | case SCSI_PROT_READ_PASS: |
| 1729 | case SCSI_PROT_WRITE_PASS: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1730 | *rxop = BG_OP_IN_CRC_OUT_CSUM; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1731 | *txop = BG_OP_IN_CSUM_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1732 | break; |
| 1733 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1734 | case SCSI_PROT_NORMAL: |
| 1735 | default: |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1736 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1737 | "9063 BLKGRD: Bad op/guard:%d/IP combination\n", |
| 1738 | scsi_get_prot_op(sc)); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1739 | ret = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1740 | break; |
| 1741 | |
| 1742 | } |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1743 | } else { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1744 | switch (scsi_get_prot_op(sc)) { |
| 1745 | case SCSI_PROT_READ_STRIP: |
| 1746 | case SCSI_PROT_WRITE_INSERT: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1747 | *rxop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1748 | *txop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1749 | break; |
| 1750 | |
| 1751 | case SCSI_PROT_READ_PASS: |
| 1752 | case SCSI_PROT_WRITE_PASS: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1753 | *rxop = BG_OP_IN_CRC_OUT_CRC; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1754 | *txop = BG_OP_IN_CRC_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1755 | break; |
| 1756 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1757 | case SCSI_PROT_READ_INSERT: |
| 1758 | case SCSI_PROT_WRITE_STRIP: |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1759 | *rxop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1760 | *txop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1761 | break; |
| 1762 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1763 | case SCSI_PROT_NORMAL: |
| 1764 | default: |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1765 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1766 | "9075 BLKGRD: Bad op/guard:%d/CRC combination\n", |
| 1767 | scsi_get_prot_op(sc)); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1768 | ret = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1769 | break; |
| 1770 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1771 | } |
| 1772 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1773 | return ret; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1774 | } |
| 1775 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1776 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 1777 | /** |
| 1778 | * lpfc_bg_err_opcodes - reDetermine the BlockGuard opcodes to be used with |
| 1779 | * the specified SCSI command in order to force a guard tag error. |
| 1780 | * @phba: The Hba for which this call is being executed. |
| 1781 | * @sc: The SCSI command to examine |
| 1782 | * @txopt: (out) BlockGuard operation for transmitted data |
| 1783 | * @rxopt: (out) BlockGuard operation for received data |
| 1784 | * |
| 1785 | * Returns: zero on success; non-zero if tx and/or rx op cannot be determined |
| 1786 | * |
| 1787 | **/ |
| 1788 | static int |
| 1789 | lpfc_bg_err_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1790 | uint8_t *txop, uint8_t *rxop) |
| 1791 | { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1792 | uint8_t ret = 0; |
| 1793 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1794 | if (lpfc_cmd_guard_csum(sc)) { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1795 | switch (scsi_get_prot_op(sc)) { |
| 1796 | case SCSI_PROT_READ_INSERT: |
| 1797 | case SCSI_PROT_WRITE_STRIP: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1798 | *rxop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1799 | *txop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1800 | break; |
| 1801 | |
| 1802 | case SCSI_PROT_READ_STRIP: |
| 1803 | case SCSI_PROT_WRITE_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1804 | *rxop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1805 | *txop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1806 | break; |
| 1807 | |
| 1808 | case SCSI_PROT_READ_PASS: |
| 1809 | case SCSI_PROT_WRITE_PASS: |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1810 | *rxop = BG_OP_IN_CSUM_OUT_CRC; |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1811 | *txop = BG_OP_IN_CRC_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1812 | break; |
| 1813 | |
| 1814 | case SCSI_PROT_NORMAL: |
| 1815 | default: |
| 1816 | break; |
| 1817 | |
| 1818 | } |
| 1819 | } else { |
| 1820 | switch (scsi_get_prot_op(sc)) { |
| 1821 | case SCSI_PROT_READ_STRIP: |
| 1822 | case SCSI_PROT_WRITE_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1823 | *rxop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1824 | *txop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1825 | break; |
| 1826 | |
| 1827 | case SCSI_PROT_READ_PASS: |
| 1828 | case SCSI_PROT_WRITE_PASS: |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1829 | *rxop = BG_OP_IN_CSUM_OUT_CSUM; |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1830 | *txop = BG_OP_IN_CSUM_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1831 | break; |
| 1832 | |
| 1833 | case SCSI_PROT_READ_INSERT: |
| 1834 | case SCSI_PROT_WRITE_STRIP: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1835 | *rxop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1836 | *txop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1837 | break; |
| 1838 | |
| 1839 | case SCSI_PROT_NORMAL: |
| 1840 | default: |
| 1841 | break; |
| 1842 | } |
| 1843 | } |
| 1844 | |
| 1845 | return ret; |
| 1846 | } |
| 1847 | #endif |
| 1848 | |
| 1849 | /** |
| 1850 | * lpfc_bg_setup_bpl - Setup BlockGuard BPL with no protection data |
| 1851 | * @phba: The Hba for which this call is being executed. |
| 1852 | * @sc: pointer to scsi command we're working on |
| 1853 | * @bpl: pointer to buffer list for protection groups |
| 1854 | * @datacnt: number of segments of data that have been dma mapped |
| 1855 | * |
| 1856 | * This function sets up BPL buffer list for protection groups of |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1857 | * type LPFC_PG_TYPE_NO_DIF |
| 1858 | * |
| 1859 | * This is usually used when the HBA is instructed to generate |
| 1860 | * DIFs and insert them into data stream (or strip DIF from |
| 1861 | * incoming data stream) |
| 1862 | * |
| 1863 | * The buffer list consists of just one protection group described |
| 1864 | * below: |
| 1865 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1866 | * start of prot group --> | PDE_5 | |
| 1867 | * +-------------------------+ |
| 1868 | * | PDE_6 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1869 | * +-------------------------+ |
| 1870 | * | Data BDE | |
| 1871 | * +-------------------------+ |
| 1872 | * |more Data BDE's ... (opt)| |
| 1873 | * +-------------------------+ |
| 1874 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1875 | * |
| 1876 | * Note: Data s/g buffers have been dma mapped |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1877 | * |
| 1878 | * Returns the number of BDEs added to the BPL. |
| 1879 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1880 | static int |
| 1881 | lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1882 | struct ulp_bde64 *bpl, int datasegcnt) |
| 1883 | { |
| 1884 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1885 | struct lpfc_pde5 *pde5 = NULL; |
| 1886 | struct lpfc_pde6 *pde6 = NULL; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1887 | dma_addr_t physaddr; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1888 | int i = 0, num_bde = 0, status; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1889 | int datadir = sc->sc_data_direction; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 1890 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1891 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 1892 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1893 | uint32_t checking = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1894 | uint32_t reftag; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1895 | uint8_t txop, rxop; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1896 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1897 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 1898 | if (status) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1899 | goto out; |
| 1900 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1901 | /* extract some info from the scsi command for pde*/ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1902 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1903 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1904 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1905 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1906 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1907 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1908 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1909 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1910 | checking = 0; |
| 1911 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1912 | #endif |
| 1913 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1914 | /* setup PDE5 with what we have */ |
| 1915 | pde5 = (struct lpfc_pde5 *) bpl; |
| 1916 | memset(pde5, 0, sizeof(struct lpfc_pde5)); |
| 1917 | bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1918 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1919 | /* Endianness conversion if necessary for PDE5 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1920 | pde5->word0 = cpu_to_le32(pde5->word0); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1921 | pde5->reftag = cpu_to_le32(reftag); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1922 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1923 | /* advance bpl and increment bde count */ |
| 1924 | num_bde++; |
| 1925 | bpl++; |
| 1926 | pde6 = (struct lpfc_pde6 *) bpl; |
| 1927 | |
| 1928 | /* setup PDE6 with the rest of the info */ |
| 1929 | memset(pde6, 0, sizeof(struct lpfc_pde6)); |
| 1930 | bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR); |
| 1931 | bf_set(pde6_optx, pde6, txop); |
| 1932 | bf_set(pde6_oprx, pde6, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1933 | |
| 1934 | /* |
| 1935 | * We only need to check the data on READs, for WRITEs |
| 1936 | * protection data is automatically generated, not checked. |
| 1937 | */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1938 | if (datadir == DMA_FROM_DEVICE) { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1939 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1940 | bf_set(pde6_ce, pde6, checking); |
| 1941 | else |
| 1942 | bf_set(pde6_ce, pde6, 0); |
| 1943 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1944 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1945 | bf_set(pde6_re, pde6, checking); |
| 1946 | else |
| 1947 | bf_set(pde6_re, pde6, 0); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1948 | } |
| 1949 | bf_set(pde6_ai, pde6, 1); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1950 | bf_set(pde6_ae, pde6, 0); |
| 1951 | bf_set(pde6_apptagval, pde6, 0); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1952 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1953 | /* Endianness conversion if necessary for PDE6 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1954 | pde6->word0 = cpu_to_le32(pde6->word0); |
| 1955 | pde6->word1 = cpu_to_le32(pde6->word1); |
| 1956 | pde6->word2 = cpu_to_le32(pde6->word2); |
| 1957 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1958 | /* advance bpl and increment bde count */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1959 | num_bde++; |
| 1960 | bpl++; |
| 1961 | |
| 1962 | /* assumption: caller has already run dma_map_sg on command data */ |
| 1963 | scsi_for_each_sg(sc, sgde, datasegcnt, i) { |
| 1964 | physaddr = sg_dma_address(sgde); |
| 1965 | bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
| 1966 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 1967 | bpl->tus.f.bdeSize = sg_dma_len(sgde); |
| 1968 | if (datadir == DMA_TO_DEVICE) |
| 1969 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1970 | else |
| 1971 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
| 1972 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 1973 | bpl++; |
| 1974 | num_bde++; |
| 1975 | } |
| 1976 | |
| 1977 | out: |
| 1978 | return num_bde; |
| 1979 | } |
| 1980 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1981 | /** |
| 1982 | * lpfc_bg_setup_bpl_prot - Setup BlockGuard BPL with protection data |
| 1983 | * @phba: The Hba for which this call is being executed. |
| 1984 | * @sc: pointer to scsi command we're working on |
| 1985 | * @bpl: pointer to buffer list for protection groups |
| 1986 | * @datacnt: number of segments of data that have been dma mapped |
| 1987 | * @protcnt: number of segment of protection data that have been dma mapped |
| 1988 | * |
| 1989 | * This function sets up BPL buffer list for protection groups of |
| 1990 | * type LPFC_PG_TYPE_DIF |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1991 | * |
| 1992 | * This is usually used when DIFs are in their own buffers, |
| 1993 | * separate from the data. The HBA can then by instructed |
| 1994 | * to place the DIFs in the outgoing stream. For read operations, |
| 1995 | * The HBA could extract the DIFs and place it in DIF buffers. |
| 1996 | * |
| 1997 | * The buffer list for this type consists of one or more of the |
| 1998 | * protection groups described below: |
| 1999 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2000 | * start of first prot group --> | PDE_5 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2001 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2002 | * | PDE_6 | |
| 2003 | * +-------------------------+ |
| 2004 | * | PDE_7 (Prot BDE) | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2005 | * +-------------------------+ |
| 2006 | * | Data BDE | |
| 2007 | * +-------------------------+ |
| 2008 | * |more Data BDE's ... (opt)| |
| 2009 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2010 | * start of new prot group --> | PDE_5 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2011 | * +-------------------------+ |
| 2012 | * | ... | |
| 2013 | * +-------------------------+ |
| 2014 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2015 | * Note: It is assumed that both data and protection s/g buffers have been |
| 2016 | * mapped for DMA |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2017 | * |
| 2018 | * Returns the number of BDEs added to the BPL. |
| 2019 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2020 | static int |
| 2021 | lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 2022 | struct ulp_bde64 *bpl, int datacnt, int protcnt) |
| 2023 | { |
| 2024 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 2025 | struct scatterlist *sgpe = NULL; /* s/g prot entry */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2026 | struct lpfc_pde5 *pde5 = NULL; |
| 2027 | struct lpfc_pde6 *pde6 = NULL; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2028 | struct lpfc_pde7 *pde7 = NULL; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2029 | dma_addr_t dataphysaddr, protphysaddr; |
| 2030 | unsigned short curr_data = 0, curr_prot = 0; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2031 | unsigned int split_offset; |
| 2032 | unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2033 | unsigned int protgrp_blks, protgrp_bytes; |
| 2034 | unsigned int remainder, subtotal; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2035 | int status; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2036 | int datadir = sc->sc_data_direction; |
| 2037 | unsigned char pgdone = 0, alldone = 0; |
| 2038 | unsigned blksize; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2039 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2040 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2041 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2042 | uint32_t checking = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2043 | uint32_t reftag; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2044 | uint8_t txop, rxop; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2045 | int num_bde = 0; |
| 2046 | |
| 2047 | sgpe = scsi_prot_sglist(sc); |
| 2048 | sgde = scsi_sglist(sc); |
| 2049 | |
| 2050 | if (!sgpe || !sgde) { |
| 2051 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2052 | "9020 Invalid s/g entry: data=0x%p prot=0x%p\n", |
| 2053 | sgpe, sgde); |
| 2054 | return 0; |
| 2055 | } |
| 2056 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2057 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 2058 | if (status) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2059 | goto out; |
| 2060 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2061 | /* extract some info from the scsi command */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2062 | blksize = lpfc_cmd_blksize(sc); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2063 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2064 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 2065 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 2066 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2067 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2068 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2069 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2070 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2071 | checking = 0; |
| 2072 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 2073 | #endif |
| 2074 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2075 | split_offset = 0; |
| 2076 | do { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2077 | /* Check to see if we ran out of space */ |
| 2078 | if (num_bde >= (phba->cfg_total_seg_cnt - 2)) |
| 2079 | return num_bde + 3; |
| 2080 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2081 | /* setup PDE5 with what we have */ |
| 2082 | pde5 = (struct lpfc_pde5 *) bpl; |
| 2083 | memset(pde5, 0, sizeof(struct lpfc_pde5)); |
| 2084 | bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2085 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 2086 | /* Endianness conversion if necessary for PDE5 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 2087 | pde5->word0 = cpu_to_le32(pde5->word0); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2088 | pde5->reftag = cpu_to_le32(reftag); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 2089 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2090 | /* advance bpl and increment bde count */ |
| 2091 | num_bde++; |
| 2092 | bpl++; |
| 2093 | pde6 = (struct lpfc_pde6 *) bpl; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2094 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2095 | /* setup PDE6 with the rest of the info */ |
| 2096 | memset(pde6, 0, sizeof(struct lpfc_pde6)); |
| 2097 | bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR); |
| 2098 | bf_set(pde6_optx, pde6, txop); |
| 2099 | bf_set(pde6_oprx, pde6, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2100 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2101 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2102 | bf_set(pde6_ce, pde6, checking); |
| 2103 | else |
| 2104 | bf_set(pde6_ce, pde6, 0); |
| 2105 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2106 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2107 | bf_set(pde6_re, pde6, checking); |
| 2108 | else |
| 2109 | bf_set(pde6_re, pde6, 0); |
| 2110 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2111 | bf_set(pde6_ai, pde6, 1); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2112 | bf_set(pde6_ae, pde6, 0); |
| 2113 | bf_set(pde6_apptagval, pde6, 0); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2114 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 2115 | /* Endianness conversion if necessary for PDE6 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 2116 | pde6->word0 = cpu_to_le32(pde6->word0); |
| 2117 | pde6->word1 = cpu_to_le32(pde6->word1); |
| 2118 | pde6->word2 = cpu_to_le32(pde6->word2); |
| 2119 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2120 | /* advance bpl and increment bde count */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2121 | num_bde++; |
| 2122 | bpl++; |
| 2123 | |
| 2124 | /* setup the first BDE that points to protection buffer */ |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2125 | protphysaddr = sg_dma_address(sgpe) + protgroup_offset; |
| 2126 | protgroup_len = sg_dma_len(sgpe) - protgroup_offset; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2127 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2128 | /* must be integer multiple of the DIF block length */ |
| 2129 | BUG_ON(protgroup_len % 8); |
| 2130 | |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2131 | pde7 = (struct lpfc_pde7 *) bpl; |
| 2132 | memset(pde7, 0, sizeof(struct lpfc_pde7)); |
| 2133 | bf_set(pde7_type, pde7, LPFC_PDE7_DESCRIPTOR); |
| 2134 | |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2135 | pde7->addrHigh = le32_to_cpu(putPaddrHigh(protphysaddr)); |
| 2136 | pde7->addrLow = le32_to_cpu(putPaddrLow(protphysaddr)); |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2137 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2138 | protgrp_blks = protgroup_len / 8; |
| 2139 | protgrp_bytes = protgrp_blks * blksize; |
| 2140 | |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2141 | /* check if this pde is crossing the 4K boundary; if so split */ |
| 2142 | if ((pde7->addrLow & 0xfff) + protgroup_len > 0x1000) { |
| 2143 | protgroup_remainder = 0x1000 - (pde7->addrLow & 0xfff); |
| 2144 | protgroup_offset += protgroup_remainder; |
| 2145 | protgrp_blks = protgroup_remainder / 8; |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2146 | protgrp_bytes = protgrp_blks * blksize; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2147 | } else { |
| 2148 | protgroup_offset = 0; |
| 2149 | curr_prot++; |
| 2150 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2151 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2152 | num_bde++; |
| 2153 | |
| 2154 | /* setup BDE's for data blocks associated with DIF data */ |
| 2155 | pgdone = 0; |
| 2156 | subtotal = 0; /* total bytes processed for current prot grp */ |
| 2157 | while (!pgdone) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2158 | /* Check to see if we ran out of space */ |
| 2159 | if (num_bde >= phba->cfg_total_seg_cnt) |
| 2160 | return num_bde + 1; |
| 2161 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2162 | if (!sgde) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2163 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2164 | "9065 BLKGRD:%s Invalid data segment\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2165 | __func__); |
| 2166 | return 0; |
| 2167 | } |
| 2168 | bpl++; |
| 2169 | dataphysaddr = sg_dma_address(sgde) + split_offset; |
| 2170 | bpl->addrLow = le32_to_cpu(putPaddrLow(dataphysaddr)); |
| 2171 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(dataphysaddr)); |
| 2172 | |
| 2173 | remainder = sg_dma_len(sgde) - split_offset; |
| 2174 | |
| 2175 | if ((subtotal + remainder) <= protgrp_bytes) { |
| 2176 | /* we can use this whole buffer */ |
| 2177 | bpl->tus.f.bdeSize = remainder; |
| 2178 | split_offset = 0; |
| 2179 | |
| 2180 | if ((subtotal + remainder) == protgrp_bytes) |
| 2181 | pgdone = 1; |
| 2182 | } else { |
| 2183 | /* must split this buffer with next prot grp */ |
| 2184 | bpl->tus.f.bdeSize = protgrp_bytes - subtotal; |
| 2185 | split_offset += bpl->tus.f.bdeSize; |
| 2186 | } |
| 2187 | |
| 2188 | subtotal += bpl->tus.f.bdeSize; |
| 2189 | |
| 2190 | if (datadir == DMA_TO_DEVICE) |
| 2191 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 2192 | else |
| 2193 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
| 2194 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 2195 | |
| 2196 | num_bde++; |
| 2197 | curr_data++; |
| 2198 | |
| 2199 | if (split_offset) |
| 2200 | break; |
| 2201 | |
| 2202 | /* Move to the next s/g segment if possible */ |
| 2203 | sgde = sg_next(sgde); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2204 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2205 | } |
| 2206 | |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2207 | if (protgroup_offset) { |
| 2208 | /* update the reference tag */ |
| 2209 | reftag += protgrp_blks; |
| 2210 | bpl++; |
| 2211 | continue; |
| 2212 | } |
| 2213 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2214 | /* are we done ? */ |
| 2215 | if (curr_prot == protcnt) { |
| 2216 | alldone = 1; |
| 2217 | } else if (curr_prot < protcnt) { |
| 2218 | /* advance to next prot buffer */ |
| 2219 | sgpe = sg_next(sgpe); |
| 2220 | bpl++; |
| 2221 | |
| 2222 | /* update the reference tag */ |
| 2223 | reftag += protgrp_blks; |
| 2224 | } else { |
| 2225 | /* if we're here, we have a bug */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2226 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2227 | "9054 BLKGRD: bug in %s\n", __func__); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2228 | } |
| 2229 | |
| 2230 | } while (!alldone); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2231 | out: |
| 2232 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2233 | return num_bde; |
| 2234 | } |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2235 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2236 | /** |
| 2237 | * lpfc_bg_setup_sgl - Setup BlockGuard SGL with no protection data |
| 2238 | * @phba: The Hba for which this call is being executed. |
| 2239 | * @sc: pointer to scsi command we're working on |
| 2240 | * @sgl: pointer to buffer list for protection groups |
| 2241 | * @datacnt: number of segments of data that have been dma mapped |
| 2242 | * |
| 2243 | * This function sets up SGL buffer list for protection groups of |
| 2244 | * type LPFC_PG_TYPE_NO_DIF |
| 2245 | * |
| 2246 | * This is usually used when the HBA is instructed to generate |
| 2247 | * DIFs and insert them into data stream (or strip DIF from |
| 2248 | * incoming data stream) |
| 2249 | * |
| 2250 | * The buffer list consists of just one protection group described |
| 2251 | * below: |
| 2252 | * +-------------------------+ |
| 2253 | * start of prot group --> | DI_SEED | |
| 2254 | * +-------------------------+ |
| 2255 | * | Data SGE | |
| 2256 | * +-------------------------+ |
| 2257 | * |more Data SGE's ... (opt)| |
| 2258 | * +-------------------------+ |
| 2259 | * |
| 2260 | * |
| 2261 | * Note: Data s/g buffers have been dma mapped |
| 2262 | * |
| 2263 | * Returns the number of SGEs added to the SGL. |
| 2264 | **/ |
| 2265 | static int |
| 2266 | lpfc_bg_setup_sgl(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 2267 | struct sli4_sge *sgl, int datasegcnt) |
| 2268 | { |
| 2269 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 2270 | struct sli4_sge_diseed *diseed = NULL; |
| 2271 | dma_addr_t physaddr; |
| 2272 | int i = 0, num_sge = 0, status; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2273 | uint32_t reftag; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2274 | uint8_t txop, rxop; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2275 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2276 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2277 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2278 | uint32_t checking = 1; |
| 2279 | uint32_t dma_len; |
| 2280 | uint32_t dma_offset = 0; |
| 2281 | |
| 2282 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 2283 | if (status) |
| 2284 | goto out; |
| 2285 | |
| 2286 | /* extract some info from the scsi command for pde*/ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2287 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
| 2288 | |
| 2289 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 2290 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2291 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2292 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2293 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2294 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2295 | checking = 0; |
| 2296 | } |
| 2297 | #endif |
| 2298 | |
| 2299 | /* setup DISEED with what we have */ |
| 2300 | diseed = (struct sli4_sge_diseed *) sgl; |
| 2301 | memset(diseed, 0, sizeof(struct sli4_sge_diseed)); |
| 2302 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED); |
| 2303 | |
| 2304 | /* Endianness conversion if necessary */ |
| 2305 | diseed->ref_tag = cpu_to_le32(reftag); |
| 2306 | diseed->ref_tag_tran = diseed->ref_tag; |
| 2307 | |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2308 | /* |
| 2309 | * We only need to check the data on READs, for WRITEs |
| 2310 | * protection data is automatically generated, not checked. |
| 2311 | */ |
| 2312 | if (sc->sc_data_direction == DMA_FROM_DEVICE) { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2313 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2314 | bf_set(lpfc_sli4_sge_dif_ce, diseed, checking); |
| 2315 | else |
| 2316 | bf_set(lpfc_sli4_sge_dif_ce, diseed, 0); |
| 2317 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2318 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2319 | bf_set(lpfc_sli4_sge_dif_re, diseed, checking); |
| 2320 | else |
| 2321 | bf_set(lpfc_sli4_sge_dif_re, diseed, 0); |
| 2322 | } |
| 2323 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2324 | /* setup DISEED with the rest of the info */ |
| 2325 | bf_set(lpfc_sli4_sge_dif_optx, diseed, txop); |
| 2326 | bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2327 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2328 | bf_set(lpfc_sli4_sge_dif_ai, diseed, 1); |
| 2329 | bf_set(lpfc_sli4_sge_dif_me, diseed, 0); |
| 2330 | |
| 2331 | /* Endianness conversion if necessary for DISEED */ |
| 2332 | diseed->word2 = cpu_to_le32(diseed->word2); |
| 2333 | diseed->word3 = cpu_to_le32(diseed->word3); |
| 2334 | |
| 2335 | /* advance bpl and increment sge count */ |
| 2336 | num_sge++; |
| 2337 | sgl++; |
| 2338 | |
| 2339 | /* assumption: caller has already run dma_map_sg on command data */ |
| 2340 | scsi_for_each_sg(sc, sgde, datasegcnt, i) { |
| 2341 | physaddr = sg_dma_address(sgde); |
| 2342 | dma_len = sg_dma_len(sgde); |
| 2343 | sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr)); |
| 2344 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr)); |
| 2345 | if ((i + 1) == datasegcnt) |
| 2346 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 2347 | else |
| 2348 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 2349 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
| 2350 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); |
| 2351 | |
| 2352 | sgl->sge_len = cpu_to_le32(dma_len); |
| 2353 | dma_offset += dma_len; |
| 2354 | |
| 2355 | sgl++; |
| 2356 | num_sge++; |
| 2357 | } |
| 2358 | |
| 2359 | out: |
| 2360 | return num_sge; |
| 2361 | } |
| 2362 | |
| 2363 | /** |
| 2364 | * lpfc_bg_setup_sgl_prot - Setup BlockGuard SGL with protection data |
| 2365 | * @phba: The Hba for which this call is being executed. |
| 2366 | * @sc: pointer to scsi command we're working on |
| 2367 | * @sgl: pointer to buffer list for protection groups |
| 2368 | * @datacnt: number of segments of data that have been dma mapped |
| 2369 | * @protcnt: number of segment of protection data that have been dma mapped |
| 2370 | * |
| 2371 | * This function sets up SGL buffer list for protection groups of |
| 2372 | * type LPFC_PG_TYPE_DIF |
| 2373 | * |
| 2374 | * This is usually used when DIFs are in their own buffers, |
| 2375 | * separate from the data. The HBA can then by instructed |
| 2376 | * to place the DIFs in the outgoing stream. For read operations, |
| 2377 | * The HBA could extract the DIFs and place it in DIF buffers. |
| 2378 | * |
| 2379 | * The buffer list for this type consists of one or more of the |
| 2380 | * protection groups described below: |
| 2381 | * +-------------------------+ |
| 2382 | * start of first prot group --> | DISEED | |
| 2383 | * +-------------------------+ |
| 2384 | * | DIF (Prot SGE) | |
| 2385 | * +-------------------------+ |
| 2386 | * | Data SGE | |
| 2387 | * +-------------------------+ |
| 2388 | * |more Data SGE's ... (opt)| |
| 2389 | * +-------------------------+ |
| 2390 | * start of new prot group --> | DISEED | |
| 2391 | * +-------------------------+ |
| 2392 | * | ... | |
| 2393 | * +-------------------------+ |
| 2394 | * |
| 2395 | * Note: It is assumed that both data and protection s/g buffers have been |
| 2396 | * mapped for DMA |
| 2397 | * |
| 2398 | * Returns the number of SGEs added to the SGL. |
| 2399 | **/ |
| 2400 | static int |
| 2401 | lpfc_bg_setup_sgl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 2402 | struct sli4_sge *sgl, int datacnt, int protcnt) |
| 2403 | { |
| 2404 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 2405 | struct scatterlist *sgpe = NULL; /* s/g prot entry */ |
| 2406 | struct sli4_sge_diseed *diseed = NULL; |
| 2407 | dma_addr_t dataphysaddr, protphysaddr; |
| 2408 | unsigned short curr_data = 0, curr_prot = 0; |
| 2409 | unsigned int split_offset; |
| 2410 | unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder; |
| 2411 | unsigned int protgrp_blks, protgrp_bytes; |
| 2412 | unsigned int remainder, subtotal; |
| 2413 | int status; |
| 2414 | unsigned char pgdone = 0, alldone = 0; |
| 2415 | unsigned blksize; |
| 2416 | uint32_t reftag; |
| 2417 | uint8_t txop, rxop; |
| 2418 | uint32_t dma_len; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2419 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2420 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2421 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2422 | uint32_t checking = 1; |
| 2423 | uint32_t dma_offset = 0; |
| 2424 | int num_sge = 0; |
| 2425 | |
| 2426 | sgpe = scsi_prot_sglist(sc); |
| 2427 | sgde = scsi_sglist(sc); |
| 2428 | |
| 2429 | if (!sgpe || !sgde) { |
| 2430 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2431 | "9082 Invalid s/g entry: data=0x%p prot=0x%p\n", |
| 2432 | sgpe, sgde); |
| 2433 | return 0; |
| 2434 | } |
| 2435 | |
| 2436 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 2437 | if (status) |
| 2438 | goto out; |
| 2439 | |
| 2440 | /* extract some info from the scsi command */ |
| 2441 | blksize = lpfc_cmd_blksize(sc); |
| 2442 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
| 2443 | |
| 2444 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 2445 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2446 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2447 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2448 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2449 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2450 | checking = 0; |
| 2451 | } |
| 2452 | #endif |
| 2453 | |
| 2454 | split_offset = 0; |
| 2455 | do { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2456 | /* Check to see if we ran out of space */ |
| 2457 | if (num_sge >= (phba->cfg_total_seg_cnt - 2)) |
| 2458 | return num_sge + 3; |
| 2459 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2460 | /* setup DISEED with what we have */ |
| 2461 | diseed = (struct sli4_sge_diseed *) sgl; |
| 2462 | memset(diseed, 0, sizeof(struct sli4_sge_diseed)); |
| 2463 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED); |
| 2464 | |
| 2465 | /* Endianness conversion if necessary */ |
| 2466 | diseed->ref_tag = cpu_to_le32(reftag); |
| 2467 | diseed->ref_tag_tran = diseed->ref_tag; |
| 2468 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2469 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) { |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2470 | bf_set(lpfc_sli4_sge_dif_ce, diseed, checking); |
| 2471 | |
| 2472 | } else { |
| 2473 | bf_set(lpfc_sli4_sge_dif_ce, diseed, 0); |
| 2474 | /* |
| 2475 | * When in this mode, the hardware will replace |
| 2476 | * the guard tag from the host with a |
| 2477 | * newly generated good CRC for the wire. |
| 2478 | * Switch to raw mode here to avoid this |
| 2479 | * behavior. What the host sends gets put on the wire. |
| 2480 | */ |
| 2481 | if (txop == BG_OP_IN_CRC_OUT_CRC) { |
| 2482 | txop = BG_OP_RAW_MODE; |
| 2483 | rxop = BG_OP_RAW_MODE; |
| 2484 | } |
| 2485 | } |
| 2486 | |
| 2487 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2488 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2489 | bf_set(lpfc_sli4_sge_dif_re, diseed, checking); |
| 2490 | else |
| 2491 | bf_set(lpfc_sli4_sge_dif_re, diseed, 0); |
| 2492 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2493 | /* setup DISEED with the rest of the info */ |
| 2494 | bf_set(lpfc_sli4_sge_dif_optx, diseed, txop); |
| 2495 | bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2496 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2497 | bf_set(lpfc_sli4_sge_dif_ai, diseed, 1); |
| 2498 | bf_set(lpfc_sli4_sge_dif_me, diseed, 0); |
| 2499 | |
| 2500 | /* Endianness conversion if necessary for DISEED */ |
| 2501 | diseed->word2 = cpu_to_le32(diseed->word2); |
| 2502 | diseed->word3 = cpu_to_le32(diseed->word3); |
| 2503 | |
| 2504 | /* advance sgl and increment bde count */ |
| 2505 | num_sge++; |
| 2506 | sgl++; |
| 2507 | |
| 2508 | /* setup the first BDE that points to protection buffer */ |
| 2509 | protphysaddr = sg_dma_address(sgpe) + protgroup_offset; |
| 2510 | protgroup_len = sg_dma_len(sgpe) - protgroup_offset; |
| 2511 | |
| 2512 | /* must be integer multiple of the DIF block length */ |
| 2513 | BUG_ON(protgroup_len % 8); |
| 2514 | |
| 2515 | /* Now setup DIF SGE */ |
| 2516 | sgl->word2 = 0; |
| 2517 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DIF); |
| 2518 | sgl->addr_hi = le32_to_cpu(putPaddrHigh(protphysaddr)); |
| 2519 | sgl->addr_lo = le32_to_cpu(putPaddrLow(protphysaddr)); |
| 2520 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 2521 | |
| 2522 | protgrp_blks = protgroup_len / 8; |
| 2523 | protgrp_bytes = protgrp_blks * blksize; |
| 2524 | |
| 2525 | /* check if DIF SGE is crossing the 4K boundary; if so split */ |
| 2526 | if ((sgl->addr_lo & 0xfff) + protgroup_len > 0x1000) { |
| 2527 | protgroup_remainder = 0x1000 - (sgl->addr_lo & 0xfff); |
| 2528 | protgroup_offset += protgroup_remainder; |
| 2529 | protgrp_blks = protgroup_remainder / 8; |
| 2530 | protgrp_bytes = protgrp_blks * blksize; |
| 2531 | } else { |
| 2532 | protgroup_offset = 0; |
| 2533 | curr_prot++; |
| 2534 | } |
| 2535 | |
| 2536 | num_sge++; |
| 2537 | |
| 2538 | /* setup SGE's for data blocks associated with DIF data */ |
| 2539 | pgdone = 0; |
| 2540 | subtotal = 0; /* total bytes processed for current prot grp */ |
| 2541 | while (!pgdone) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2542 | /* Check to see if we ran out of space */ |
| 2543 | if (num_sge >= phba->cfg_total_seg_cnt) |
| 2544 | return num_sge + 1; |
| 2545 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2546 | if (!sgde) { |
| 2547 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2548 | "9086 BLKGRD:%s Invalid data segment\n", |
| 2549 | __func__); |
| 2550 | return 0; |
| 2551 | } |
| 2552 | sgl++; |
| 2553 | dataphysaddr = sg_dma_address(sgde) + split_offset; |
| 2554 | |
| 2555 | remainder = sg_dma_len(sgde) - split_offset; |
| 2556 | |
| 2557 | if ((subtotal + remainder) <= protgrp_bytes) { |
| 2558 | /* we can use this whole buffer */ |
| 2559 | dma_len = remainder; |
| 2560 | split_offset = 0; |
| 2561 | |
| 2562 | if ((subtotal + remainder) == protgrp_bytes) |
| 2563 | pgdone = 1; |
| 2564 | } else { |
| 2565 | /* must split this buffer with next prot grp */ |
| 2566 | dma_len = protgrp_bytes - subtotal; |
| 2567 | split_offset += dma_len; |
| 2568 | } |
| 2569 | |
| 2570 | subtotal += dma_len; |
| 2571 | |
| 2572 | sgl->addr_lo = cpu_to_le32(putPaddrLow(dataphysaddr)); |
| 2573 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(dataphysaddr)); |
| 2574 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 2575 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
| 2576 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); |
| 2577 | |
| 2578 | sgl->sge_len = cpu_to_le32(dma_len); |
| 2579 | dma_offset += dma_len; |
| 2580 | |
| 2581 | num_sge++; |
| 2582 | curr_data++; |
| 2583 | |
| 2584 | if (split_offset) |
| 2585 | break; |
| 2586 | |
| 2587 | /* Move to the next s/g segment if possible */ |
| 2588 | sgde = sg_next(sgde); |
| 2589 | } |
| 2590 | |
| 2591 | if (protgroup_offset) { |
| 2592 | /* update the reference tag */ |
| 2593 | reftag += protgrp_blks; |
| 2594 | sgl++; |
| 2595 | continue; |
| 2596 | } |
| 2597 | |
| 2598 | /* are we done ? */ |
| 2599 | if (curr_prot == protcnt) { |
| 2600 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 2601 | alldone = 1; |
| 2602 | } else if (curr_prot < protcnt) { |
| 2603 | /* advance to next prot buffer */ |
| 2604 | sgpe = sg_next(sgpe); |
| 2605 | sgl++; |
| 2606 | |
| 2607 | /* update the reference tag */ |
| 2608 | reftag += protgrp_blks; |
| 2609 | } else { |
| 2610 | /* if we're here, we have a bug */ |
| 2611 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2612 | "9085 BLKGRD: bug in %s\n", __func__); |
| 2613 | } |
| 2614 | |
| 2615 | } while (!alldone); |
| 2616 | |
| 2617 | out: |
| 2618 | |
| 2619 | return num_sge; |
| 2620 | } |
| 2621 | |
| 2622 | /** |
| 2623 | * lpfc_prot_group_type - Get prtotection group type of SCSI command |
| 2624 | * @phba: The Hba for which this call is being executed. |
| 2625 | * @sc: pointer to scsi command we're working on |
| 2626 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2627 | * Given a SCSI command that supports DIF, determine composition of protection |
| 2628 | * groups involved in setting up buffer lists |
| 2629 | * |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2630 | * Returns: Protection group type (with or without DIF) |
| 2631 | * |
| 2632 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2633 | static int |
| 2634 | lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc) |
| 2635 | { |
| 2636 | int ret = LPFC_PG_TYPE_INVALID; |
| 2637 | unsigned char op = scsi_get_prot_op(sc); |
| 2638 | |
| 2639 | switch (op) { |
| 2640 | case SCSI_PROT_READ_STRIP: |
| 2641 | case SCSI_PROT_WRITE_INSERT: |
| 2642 | ret = LPFC_PG_TYPE_NO_DIF; |
| 2643 | break; |
| 2644 | case SCSI_PROT_READ_INSERT: |
| 2645 | case SCSI_PROT_WRITE_STRIP: |
| 2646 | case SCSI_PROT_READ_PASS: |
| 2647 | case SCSI_PROT_WRITE_PASS: |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2648 | ret = LPFC_PG_TYPE_DIF_BUF; |
| 2649 | break; |
| 2650 | default: |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2651 | if (phba) |
| 2652 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2653 | "9021 Unsupported protection op:%d\n", |
| 2654 | op); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2655 | break; |
| 2656 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2657 | return ret; |
| 2658 | } |
| 2659 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2660 | /** |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2661 | * lpfc_bg_scsi_adjust_dl - Adjust SCSI data length for BlockGuard |
| 2662 | * @phba: The Hba for which this call is being executed. |
| 2663 | * @lpfc_cmd: The scsi buffer which is going to be adjusted. |
| 2664 | * |
| 2665 | * Adjust the data length to account for how much data |
| 2666 | * is actually on the wire. |
| 2667 | * |
| 2668 | * returns the adjusted data length |
| 2669 | **/ |
| 2670 | static int |
| 2671 | lpfc_bg_scsi_adjust_dl(struct lpfc_hba *phba, |
| 2672 | struct lpfc_scsi_buf *lpfc_cmd) |
| 2673 | { |
| 2674 | struct scsi_cmnd *sc = lpfc_cmd->pCmd; |
| 2675 | int fcpdl; |
| 2676 | |
| 2677 | fcpdl = scsi_bufflen(sc); |
| 2678 | |
| 2679 | /* Check if there is protection data on the wire */ |
| 2680 | if (sc->sc_data_direction == DMA_FROM_DEVICE) { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2681 | /* Read check for protection data */ |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2682 | if (scsi_get_prot_op(sc) == SCSI_PROT_READ_INSERT) |
| 2683 | return fcpdl; |
| 2684 | |
| 2685 | } else { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2686 | /* Write check for protection data */ |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2687 | if (scsi_get_prot_op(sc) == SCSI_PROT_WRITE_STRIP) |
| 2688 | return fcpdl; |
| 2689 | } |
| 2690 | |
| 2691 | /* |
| 2692 | * 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] | 2693 | * DIF (trailer) attached to it. Must ajust FCP data length |
| 2694 | * to account for the protection data. |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2695 | */ |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2696 | fcpdl += (fcpdl / lpfc_cmd_blksize(sc)) * 8; |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2697 | |
| 2698 | return fcpdl; |
| 2699 | } |
| 2700 | |
| 2701 | /** |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2702 | * lpfc_bg_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec |
| 2703 | * @phba: The Hba for which this call is being executed. |
| 2704 | * @lpfc_cmd: The scsi buffer which is going to be prep'ed. |
| 2705 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2706 | * This is the protection/DIF aware version of |
| 2707 | * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the |
| 2708 | * two functions eventually, but for now, it's here |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2709 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2710 | static int |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2711 | lpfc_bg_scsi_prep_dma_buf_s3(struct lpfc_hba *phba, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2712 | struct lpfc_scsi_buf *lpfc_cmd) |
| 2713 | { |
| 2714 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 2715 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 2716 | struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl; |
| 2717 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 2718 | uint32_t num_bde = 0; |
| 2719 | int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction; |
| 2720 | int prot_group_type = 0; |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2721 | int fcpdl; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2722 | |
| 2723 | /* |
| 2724 | * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd |
| 2725 | * fcp_rsp regions to the first data bde entry |
| 2726 | */ |
| 2727 | bpl += 2; |
| 2728 | if (scsi_sg_count(scsi_cmnd)) { |
| 2729 | /* |
| 2730 | * The driver stores the segment count returned from pci_map_sg |
| 2731 | * because this a count of dma-mappings used to map the use_sg |
| 2732 | * pages. They are not guaranteed to be the same for those |
| 2733 | * architectures that implement an IOMMU. |
| 2734 | */ |
| 2735 | datasegcnt = dma_map_sg(&phba->pcidev->dev, |
| 2736 | scsi_sglist(scsi_cmnd), |
| 2737 | scsi_sg_count(scsi_cmnd), datadir); |
| 2738 | if (unlikely(!datasegcnt)) |
| 2739 | return 1; |
| 2740 | |
| 2741 | lpfc_cmd->seg_cnt = datasegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2742 | |
| 2743 | /* First check if data segment count from SCSI Layer is good */ |
| 2744 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) |
| 2745 | goto err; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2746 | |
| 2747 | prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd); |
| 2748 | |
| 2749 | switch (prot_group_type) { |
| 2750 | case LPFC_PG_TYPE_NO_DIF: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2751 | |
| 2752 | /* Here we need to add a PDE5 and PDE6 to the count */ |
| 2753 | if ((lpfc_cmd->seg_cnt + 2) > phba->cfg_total_seg_cnt) |
| 2754 | goto err; |
| 2755 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2756 | num_bde = lpfc_bg_setup_bpl(phba, scsi_cmnd, bpl, |
| 2757 | datasegcnt); |
Adam Buchbinder | c9404c9 | 2009-12-18 15:40:42 -0500 | [diff] [blame] | 2758 | /* we should have 2 or more entries in buffer list */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2759 | if (num_bde < 2) |
| 2760 | goto err; |
| 2761 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2762 | |
| 2763 | case LPFC_PG_TYPE_DIF_BUF: |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2764 | /* |
| 2765 | * This type indicates that protection buffers are |
| 2766 | * passed to the driver, so that needs to be prepared |
| 2767 | * for DMA |
| 2768 | */ |
| 2769 | protsegcnt = dma_map_sg(&phba->pcidev->dev, |
| 2770 | scsi_prot_sglist(scsi_cmnd), |
| 2771 | scsi_prot_sg_count(scsi_cmnd), datadir); |
| 2772 | if (unlikely(!protsegcnt)) { |
| 2773 | scsi_dma_unmap(scsi_cmnd); |
| 2774 | return 1; |
| 2775 | } |
| 2776 | |
| 2777 | lpfc_cmd->prot_seg_cnt = protsegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2778 | |
| 2779 | /* |
| 2780 | * There is a minimun of 4 BPLs used for every |
| 2781 | * protection data segment. |
| 2782 | */ |
| 2783 | if ((lpfc_cmd->prot_seg_cnt * 4) > |
| 2784 | (phba->cfg_total_seg_cnt - 2)) |
| 2785 | goto err; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2786 | |
| 2787 | num_bde = lpfc_bg_setup_bpl_prot(phba, scsi_cmnd, bpl, |
| 2788 | datasegcnt, protsegcnt); |
Adam Buchbinder | c9404c9 | 2009-12-18 15:40:42 -0500 | [diff] [blame] | 2789 | /* we should have 3 or more entries in buffer list */ |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2790 | if ((num_bde < 3) || |
| 2791 | (num_bde > phba->cfg_total_seg_cnt)) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2792 | goto err; |
| 2793 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2794 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2795 | case LPFC_PG_TYPE_INVALID: |
| 2796 | default: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2797 | scsi_dma_unmap(scsi_cmnd); |
| 2798 | lpfc_cmd->seg_cnt = 0; |
| 2799 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2800 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2801 | "9022 Unexpected protection group %i\n", |
| 2802 | prot_group_type); |
| 2803 | return 1; |
| 2804 | } |
| 2805 | } |
| 2806 | |
| 2807 | /* |
| 2808 | * Finish initializing those IOCB fields that are dependent on the |
| 2809 | * scsi_cmnd request_buffer. Note that the bdeSize is explicitly |
| 2810 | * reinitialized since all iocb memory resources are used many times |
| 2811 | * for transmit, receive, and continuation bpl's. |
| 2812 | */ |
| 2813 | iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| 2814 | iocb_cmd->un.fcpi64.bdl.bdeSize += (num_bde * sizeof(struct ulp_bde64)); |
| 2815 | iocb_cmd->ulpBdeCount = 1; |
| 2816 | iocb_cmd->ulpLe = 1; |
| 2817 | |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2818 | fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2819 | fcp_cmnd->fcpDl = be32_to_cpu(fcpdl); |
| 2820 | |
| 2821 | /* |
| 2822 | * Due to difference in data length between DIF/non-DIF paths, |
| 2823 | * we need to set word 4 of IOCB here |
| 2824 | */ |
| 2825 | iocb_cmd->un.fcpi.fcpi_parm = fcpdl; |
| 2826 | |
| 2827 | return 0; |
| 2828 | err: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2829 | if (lpfc_cmd->seg_cnt) |
| 2830 | scsi_dma_unmap(scsi_cmnd); |
| 2831 | if (lpfc_cmd->prot_seg_cnt) |
| 2832 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd), |
| 2833 | scsi_prot_sg_count(scsi_cmnd), |
| 2834 | scsi_cmnd->sc_data_direction); |
| 2835 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2836 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2837 | "9023 Cannot setup S/G List for HBA" |
| 2838 | "IO segs %d/%d BPL %d SCSI %d: %d %d\n", |
| 2839 | lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt, |
| 2840 | phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2841 | prot_group_type, num_bde); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2842 | |
| 2843 | lpfc_cmd->seg_cnt = 0; |
| 2844 | lpfc_cmd->prot_seg_cnt = 0; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2845 | return 1; |
| 2846 | } |
| 2847 | |
| 2848 | /* |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2849 | * This function calcuates the T10 DIF guard tag |
| 2850 | * on the specified data using a CRC algorithmn |
| 2851 | * using crc_t10dif. |
| 2852 | */ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 2853 | static uint16_t |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2854 | lpfc_bg_crc(uint8_t *data, int count) |
| 2855 | { |
| 2856 | uint16_t crc = 0; |
| 2857 | uint16_t x; |
| 2858 | |
| 2859 | crc = crc_t10dif(data, count); |
| 2860 | x = cpu_to_be16(crc); |
| 2861 | return x; |
| 2862 | } |
| 2863 | |
| 2864 | /* |
| 2865 | * This function calcuates the T10 DIF guard tag |
| 2866 | * on the specified data using a CSUM algorithmn |
| 2867 | * using ip_compute_csum. |
| 2868 | */ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 2869 | static uint16_t |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2870 | lpfc_bg_csum(uint8_t *data, int count) |
| 2871 | { |
| 2872 | uint16_t ret; |
| 2873 | |
| 2874 | ret = ip_compute_csum(data, count); |
| 2875 | return ret; |
| 2876 | } |
| 2877 | |
| 2878 | /* |
| 2879 | * This function examines the protection data to try to determine |
| 2880 | * what type of T10-DIF error occurred. |
| 2881 | */ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 2882 | static void |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2883 | lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 2884 | { |
| 2885 | struct scatterlist *sgpe; /* s/g prot entry */ |
| 2886 | struct scatterlist *sgde; /* s/g data entry */ |
| 2887 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 2888 | struct scsi_dif_tuple *src = NULL; |
| 2889 | uint8_t *data_src = NULL; |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 2890 | uint16_t guard_tag; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2891 | uint16_t start_app_tag, app_tag; |
| 2892 | uint32_t start_ref_tag, ref_tag; |
| 2893 | int prot, protsegcnt; |
| 2894 | int err_type, len, data_len; |
| 2895 | int chk_ref, chk_app, chk_guard; |
| 2896 | uint16_t sum; |
| 2897 | unsigned blksize; |
| 2898 | |
| 2899 | err_type = BGS_GUARD_ERR_MASK; |
| 2900 | sum = 0; |
| 2901 | guard_tag = 0; |
| 2902 | |
| 2903 | /* First check to see if there is protection data to examine */ |
| 2904 | prot = scsi_get_prot_op(cmd); |
| 2905 | if ((prot == SCSI_PROT_READ_STRIP) || |
| 2906 | (prot == SCSI_PROT_WRITE_INSERT) || |
| 2907 | (prot == SCSI_PROT_NORMAL)) |
| 2908 | goto out; |
| 2909 | |
| 2910 | /* Currently the driver just supports ref_tag and guard_tag checking */ |
| 2911 | chk_ref = 1; |
| 2912 | chk_app = 0; |
| 2913 | chk_guard = 0; |
| 2914 | |
| 2915 | /* Setup a ptr to the protection data provided by the SCSI host */ |
| 2916 | sgpe = scsi_prot_sglist(cmd); |
| 2917 | protsegcnt = lpfc_cmd->prot_seg_cnt; |
| 2918 | |
| 2919 | if (sgpe && protsegcnt) { |
| 2920 | |
| 2921 | /* |
| 2922 | * We will only try to verify guard tag if the segment |
| 2923 | * data length is a multiple of the blksize. |
| 2924 | */ |
| 2925 | sgde = scsi_sglist(cmd); |
| 2926 | blksize = lpfc_cmd_blksize(cmd); |
| 2927 | data_src = (uint8_t *)sg_virt(sgde); |
| 2928 | data_len = sgde->length; |
| 2929 | if ((data_len & (blksize - 1)) == 0) |
| 2930 | chk_guard = 1; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2931 | |
James Smart | e85d8f9 | 2013-05-31 17:04:10 -0400 | [diff] [blame] | 2932 | src = (struct scsi_dif_tuple *)sg_virt(sgpe); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2933 | start_ref_tag = (uint32_t)scsi_get_lba(cmd); /* Truncate LBA */ |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2934 | start_app_tag = src->app_tag; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2935 | len = sgpe->length; |
| 2936 | while (src && protsegcnt) { |
| 2937 | while (len) { |
| 2938 | |
| 2939 | /* |
| 2940 | * First check to see if a protection data |
| 2941 | * check is valid |
| 2942 | */ |
Dmitry Monakhov | 128b6f9 | 2017-06-29 11:31:12 -0700 | [diff] [blame] | 2943 | if ((src->ref_tag == T10_PI_REF_ESCAPE) || |
| 2944 | (src->app_tag == T10_PI_APP_ESCAPE)) { |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2945 | start_ref_tag++; |
| 2946 | goto skipit; |
| 2947 | } |
| 2948 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2949 | /* First Guard Tag checking */ |
| 2950 | if (chk_guard) { |
| 2951 | guard_tag = src->guard_tag; |
| 2952 | if (lpfc_cmd_guard_csum(cmd)) |
| 2953 | sum = lpfc_bg_csum(data_src, |
| 2954 | blksize); |
| 2955 | else |
| 2956 | sum = lpfc_bg_crc(data_src, |
| 2957 | blksize); |
| 2958 | if ((guard_tag != sum)) { |
| 2959 | err_type = BGS_GUARD_ERR_MASK; |
| 2960 | goto out; |
| 2961 | } |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2962 | } |
| 2963 | |
| 2964 | /* Reference Tag checking */ |
| 2965 | ref_tag = be32_to_cpu(src->ref_tag); |
| 2966 | if (chk_ref && (ref_tag != start_ref_tag)) { |
| 2967 | err_type = BGS_REFTAG_ERR_MASK; |
| 2968 | goto out; |
| 2969 | } |
| 2970 | start_ref_tag++; |
| 2971 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2972 | /* App Tag checking */ |
| 2973 | app_tag = src->app_tag; |
| 2974 | if (chk_app && (app_tag != start_app_tag)) { |
| 2975 | err_type = BGS_APPTAG_ERR_MASK; |
| 2976 | goto out; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2977 | } |
| 2978 | skipit: |
| 2979 | len -= sizeof(struct scsi_dif_tuple); |
| 2980 | if (len < 0) |
| 2981 | len = 0; |
| 2982 | src++; |
| 2983 | |
| 2984 | data_src += blksize; |
| 2985 | data_len -= blksize; |
| 2986 | |
| 2987 | /* |
| 2988 | * Are we at the end of the Data segment? |
| 2989 | * The data segment is only used for Guard |
| 2990 | * tag checking. |
| 2991 | */ |
| 2992 | if (chk_guard && (data_len == 0)) { |
| 2993 | chk_guard = 0; |
| 2994 | sgde = sg_next(sgde); |
| 2995 | if (!sgde) |
| 2996 | goto out; |
| 2997 | |
| 2998 | data_src = (uint8_t *)sg_virt(sgde); |
| 2999 | data_len = sgde->length; |
| 3000 | if ((data_len & (blksize - 1)) == 0) |
| 3001 | chk_guard = 1; |
| 3002 | } |
| 3003 | } |
| 3004 | |
| 3005 | /* Goto the next Protection data segment */ |
| 3006 | sgpe = sg_next(sgpe); |
| 3007 | if (sgpe) { |
| 3008 | src = (struct scsi_dif_tuple *)sg_virt(sgpe); |
| 3009 | len = sgpe->length; |
| 3010 | } else { |
| 3011 | src = NULL; |
| 3012 | } |
| 3013 | protsegcnt--; |
| 3014 | } |
| 3015 | } |
| 3016 | out: |
| 3017 | if (err_type == BGS_GUARD_ERR_MASK) { |
| 3018 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 3019 | 0x10, 0x1); |
| 3020 | cmd->result = DRIVER_SENSE << 24 |
| 3021 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 3022 | phba->bg_guard_err_cnt++; |
| 3023 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3024 | "9069 BLKGRD: LBA %lx grd_tag error %x != %x\n", |
| 3025 | (unsigned long)scsi_get_lba(cmd), |
| 3026 | sum, guard_tag); |
| 3027 | |
| 3028 | } else if (err_type == BGS_REFTAG_ERR_MASK) { |
| 3029 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 3030 | 0x10, 0x3); |
| 3031 | cmd->result = DRIVER_SENSE << 24 |
| 3032 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 3033 | |
| 3034 | phba->bg_reftag_err_cnt++; |
| 3035 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3036 | "9066 BLKGRD: LBA %lx ref_tag error %x != %x\n", |
| 3037 | (unsigned long)scsi_get_lba(cmd), |
| 3038 | ref_tag, start_ref_tag); |
| 3039 | |
| 3040 | } else if (err_type == BGS_APPTAG_ERR_MASK) { |
| 3041 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 3042 | 0x10, 0x2); |
| 3043 | cmd->result = DRIVER_SENSE << 24 |
| 3044 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 3045 | |
| 3046 | phba->bg_apptag_err_cnt++; |
| 3047 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3048 | "9041 BLKGRD: LBA %lx app_tag error %x != %x\n", |
| 3049 | (unsigned long)scsi_get_lba(cmd), |
| 3050 | app_tag, start_app_tag); |
| 3051 | } |
| 3052 | } |
| 3053 | |
| 3054 | |
| 3055 | /* |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3056 | * This function checks for BlockGuard errors detected by |
| 3057 | * the HBA. In case of errors, the ASC/ASCQ fields in the |
| 3058 | * sense buffer will be set accordingly, paired with |
| 3059 | * ILLEGAL_REQUEST to signal to the kernel that the HBA |
| 3060 | * detected corruption. |
| 3061 | * |
| 3062 | * Returns: |
| 3063 | * 0 - No error found |
| 3064 | * 1 - BlockGuard error found |
| 3065 | * -1 - Internal error (bad profile, ...etc) |
| 3066 | */ |
| 3067 | static int |
| 3068 | lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd, |
| 3069 | struct lpfc_iocbq *pIocbOut) |
| 3070 | { |
| 3071 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 3072 | struct sli3_bg_fields *bgf = &pIocbOut->iocb.unsli3.sli3_bg; |
| 3073 | int ret = 0; |
| 3074 | uint32_t bghm = bgf->bghm; |
| 3075 | uint32_t bgstat = bgf->bgstat; |
| 3076 | uint64_t failing_sector = 0; |
| 3077 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3078 | spin_lock(&_dump_buf_lock); |
| 3079 | if (!_dump_buf_done) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3080 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9070 BLKGRD: Saving" |
| 3081 | " Data for %u blocks to debugfs\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3082 | (cmd->cmnd[7] << 8 | cmd->cmnd[8])); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3083 | lpfc_debug_save_data(phba, cmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3084 | |
| 3085 | /* If we have a prot sgl, save the DIF buffer */ |
| 3086 | if (lpfc_prot_group_type(phba, cmd) == |
| 3087 | LPFC_PG_TYPE_DIF_BUF) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3088 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9071 BLKGRD: " |
| 3089 | "Saving DIF for %u blocks to debugfs\n", |
| 3090 | (cmd->cmnd[7] << 8 | cmd->cmnd[8])); |
| 3091 | lpfc_debug_save_dif(phba, cmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3092 | } |
| 3093 | |
| 3094 | _dump_buf_done = 1; |
| 3095 | } |
| 3096 | spin_unlock(&_dump_buf_lock); |
| 3097 | |
| 3098 | if (lpfc_bgs_get_invalid_prof(bgstat)) { |
| 3099 | cmd->result = ScsiResult(DID_ERROR, 0); |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3100 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3101 | "9072 BLKGRD: Invalid BG Profile in cmd" |
| 3102 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3103 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3104 | (unsigned long long)scsi_get_lba(cmd), |
| 3105 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3106 | ret = (-1); |
| 3107 | goto out; |
| 3108 | } |
| 3109 | |
| 3110 | if (lpfc_bgs_get_uninit_dif_block(bgstat)) { |
| 3111 | cmd->result = ScsiResult(DID_ERROR, 0); |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3112 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3113 | "9073 BLKGRD: Invalid BG PDIF Block in cmd" |
| 3114 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3115 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3116 | (unsigned long long)scsi_get_lba(cmd), |
| 3117 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3118 | ret = (-1); |
| 3119 | goto out; |
| 3120 | } |
| 3121 | |
| 3122 | if (lpfc_bgs_get_guard_err(bgstat)) { |
| 3123 | ret = 1; |
| 3124 | |
| 3125 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 3126 | 0x10, 0x1); |
Martin K. Petersen | 1c9fbaf | 2009-01-04 03:14:11 -0500 | [diff] [blame] | 3127 | cmd->result = DRIVER_SENSE << 24 |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3128 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 3129 | phba->bg_guard_err_cnt++; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3130 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3131 | "9055 BLKGRD: Guard Tag error in cmd" |
| 3132 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3133 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3134 | (unsigned long long)scsi_get_lba(cmd), |
| 3135 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3136 | } |
| 3137 | |
| 3138 | if (lpfc_bgs_get_reftag_err(bgstat)) { |
| 3139 | ret = 1; |
| 3140 | |
| 3141 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 3142 | 0x10, 0x3); |
Martin K. Petersen | 1c9fbaf | 2009-01-04 03:14:11 -0500 | [diff] [blame] | 3143 | cmd->result = DRIVER_SENSE << 24 |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3144 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 3145 | |
| 3146 | phba->bg_reftag_err_cnt++; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3147 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3148 | "9056 BLKGRD: Ref Tag error in cmd" |
| 3149 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3150 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3151 | (unsigned long long)scsi_get_lba(cmd), |
| 3152 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3153 | } |
| 3154 | |
| 3155 | if (lpfc_bgs_get_apptag_err(bgstat)) { |
| 3156 | ret = 1; |
| 3157 | |
| 3158 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 3159 | 0x10, 0x2); |
Martin K. Petersen | 1c9fbaf | 2009-01-04 03:14:11 -0500 | [diff] [blame] | 3160 | cmd->result = DRIVER_SENSE << 24 |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3161 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 3162 | |
| 3163 | phba->bg_apptag_err_cnt++; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3164 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3165 | "9061 BLKGRD: App Tag error in cmd" |
| 3166 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3167 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3168 | (unsigned long long)scsi_get_lba(cmd), |
| 3169 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3170 | } |
| 3171 | |
| 3172 | if (lpfc_bgs_get_hi_water_mark_present(bgstat)) { |
| 3173 | /* |
| 3174 | * setup sense data descriptor 0 per SPC-4 as an information |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 3175 | * field, and put the failing LBA in it. |
| 3176 | * This code assumes there was also a guard/app/ref tag error |
| 3177 | * indication. |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3178 | */ |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 3179 | cmd->sense_buffer[7] = 0xc; /* Additional sense length */ |
| 3180 | cmd->sense_buffer[8] = 0; /* Information descriptor type */ |
| 3181 | cmd->sense_buffer[9] = 0xa; /* Additional descriptor length */ |
| 3182 | cmd->sense_buffer[10] = 0x80; /* Validity bit */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3183 | |
| 3184 | /* bghm is a "on the wire" FC frame based count */ |
| 3185 | switch (scsi_get_prot_op(cmd)) { |
| 3186 | case SCSI_PROT_READ_INSERT: |
| 3187 | case SCSI_PROT_WRITE_STRIP: |
| 3188 | bghm /= cmd->device->sector_size; |
| 3189 | break; |
| 3190 | case SCSI_PROT_READ_STRIP: |
| 3191 | case SCSI_PROT_WRITE_INSERT: |
| 3192 | case SCSI_PROT_READ_PASS: |
| 3193 | case SCSI_PROT_WRITE_PASS: |
| 3194 | bghm /= (cmd->device->sector_size + |
| 3195 | sizeof(struct scsi_dif_tuple)); |
| 3196 | break; |
| 3197 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3198 | |
| 3199 | failing_sector = scsi_get_lba(cmd); |
| 3200 | failing_sector += bghm; |
| 3201 | |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 3202 | /* Descriptor Information */ |
| 3203 | put_unaligned_be64(failing_sector, &cmd->sense_buffer[12]); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3204 | } |
| 3205 | |
| 3206 | if (!ret) { |
| 3207 | /* No error was reported - problem in FW? */ |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3208 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3209 | "9057 BLKGRD: Unknown error in cmd" |
| 3210 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3211 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3212 | (unsigned long long)scsi_get_lba(cmd), |
| 3213 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3214 | |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3215 | /* Calcuate what type of error it was */ |
| 3216 | lpfc_calc_bg_err(phba, lpfc_cmd); |
| 3217 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3218 | out: |
| 3219 | return ret; |
| 3220 | } |
| 3221 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3222 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3223 | * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec |
| 3224 | * @phba: The Hba for which this call is being executed. |
| 3225 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3226 | * |
| 3227 | * This routine does the pci dma mapping for scatter-gather list of scsi cmnd |
| 3228 | * field of @lpfc_cmd for device with SLI-4 interface spec. |
| 3229 | * |
| 3230 | * Return codes: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 3231 | * 1 - Error |
| 3232 | * 0 - Success |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3233 | **/ |
| 3234 | static int |
| 3235 | lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 3236 | { |
| 3237 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 3238 | struct scatterlist *sgel = NULL; |
| 3239 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 3240 | struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3241 | struct sli4_sge *first_data_sgl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3242 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 3243 | dma_addr_t physaddr; |
| 3244 | uint32_t num_bde = 0; |
| 3245 | uint32_t dma_len; |
| 3246 | uint32_t dma_offset = 0; |
| 3247 | int nseg; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3248 | struct ulp_bde64 *bde; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3249 | |
| 3250 | /* |
| 3251 | * There are three possibilities here - use scatter-gather segment, use |
| 3252 | * the single mapping, or neither. Start the lpfc command prep by |
| 3253 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 3254 | * data bde entry. |
| 3255 | */ |
| 3256 | if (scsi_sg_count(scsi_cmnd)) { |
| 3257 | /* |
| 3258 | * The driver stores the segment count returned from pci_map_sg |
| 3259 | * because this a count of dma-mappings used to map the use_sg |
| 3260 | * pages. They are not guaranteed to be the same for those |
| 3261 | * architectures that implement an IOMMU. |
| 3262 | */ |
| 3263 | |
| 3264 | nseg = scsi_dma_map(scsi_cmnd); |
James Smart | 5116fbf | 2015-05-22 10:42:39 -0400 | [diff] [blame] | 3265 | if (unlikely(nseg <= 0)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3266 | return 1; |
| 3267 | sgl += 1; |
| 3268 | /* clear the last flag in the fcp_rsp map entry */ |
| 3269 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 3270 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 3271 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 3272 | sgl += 1; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3273 | first_data_sgl = sgl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3274 | lpfc_cmd->seg_cnt = nseg; |
| 3275 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3276 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9074 BLKGRD:" |
| 3277 | " %s: Too many sg segments from " |
| 3278 | "dma_map_sg. Config %d, seg_cnt %d\n", |
| 3279 | __func__, phba->cfg_sg_seg_cnt, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3280 | lpfc_cmd->seg_cnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3281 | lpfc_cmd->seg_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3282 | scsi_dma_unmap(scsi_cmnd); |
| 3283 | return 1; |
| 3284 | } |
| 3285 | |
| 3286 | /* |
| 3287 | * The driver established a maximum scatter-gather segment count |
| 3288 | * during probe that limits the number of sg elements in any |
| 3289 | * single scsi command. Just run through the seg_cnt and format |
| 3290 | * the sge's. |
| 3291 | * When using SLI-3 the driver will try to fit all the BDEs into |
| 3292 | * the IOCB. If it can't then the BDEs get added to a BPL as it |
| 3293 | * does for SLI-2 mode. |
| 3294 | */ |
| 3295 | scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) { |
| 3296 | physaddr = sg_dma_address(sgel); |
| 3297 | dma_len = sg_dma_len(sgel); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3298 | sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr)); |
| 3299 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr)); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 3300 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3301 | if ((num_bde + 1) == nseg) |
| 3302 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 3303 | else |
| 3304 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 3305 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 3306 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3307 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 3308 | sgl->sge_len = cpu_to_le32(dma_len); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3309 | dma_offset += dma_len; |
| 3310 | sgl++; |
| 3311 | } |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 3312 | /* |
| 3313 | * Setup the first Payload BDE. For FCoE we just key off |
| 3314 | * Performance Hints, for FC we utilize fcp_embed_pbde. |
| 3315 | */ |
| 3316 | if ((phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) || |
| 3317 | phba->fcp_embed_pbde) { |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3318 | bde = (struct ulp_bde64 *) |
| 3319 | &(iocb_cmd->unsli3.sli3Words[5]); |
| 3320 | bde->addrLow = first_data_sgl->addr_lo; |
| 3321 | bde->addrHigh = first_data_sgl->addr_hi; |
| 3322 | bde->tus.f.bdeSize = |
| 3323 | le32_to_cpu(first_data_sgl->sge_len); |
| 3324 | bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 3325 | bde->tus.w = cpu_to_le32(bde->tus.w); |
| 3326 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3327 | } else { |
| 3328 | sgl += 1; |
| 3329 | /* clear the last flag in the fcp_rsp map entry */ |
| 3330 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 3331 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 3332 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 3333 | } |
| 3334 | |
| 3335 | /* |
| 3336 | * Finish initializing those IOCB fields that are dependent on the |
| 3337 | * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is |
| 3338 | * explicitly reinitialized. |
| 3339 | * all iocb memory resources are reused. |
| 3340 | */ |
| 3341 | fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); |
| 3342 | |
| 3343 | /* |
| 3344 | * Due to difference in data length between DIF/non-DIF paths, |
| 3345 | * we need to set word 4 of IOCB here |
| 3346 | */ |
| 3347 | iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 3348 | |
| 3349 | /* |
| 3350 | * If the OAS driver feature is enabled and the lun is enabled for |
| 3351 | * OAS, set the oas iocb related flags. |
| 3352 | */ |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 3353 | if ((phba->cfg_fof) && ((struct lpfc_device_data *) |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 3354 | scsi_cmnd->device->hostdata)->oas_enabled) { |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 3355 | lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 3356 | lpfc_cmd->cur_iocbq.priority = ((struct lpfc_device_data *) |
| 3357 | scsi_cmnd->device->hostdata)->priority; |
| 3358 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3359 | return 0; |
| 3360 | } |
| 3361 | |
| 3362 | /** |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3363 | * lpfc_bg_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec |
| 3364 | * @phba: The Hba for which this call is being executed. |
| 3365 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3366 | * |
| 3367 | * This is the protection/DIF aware version of |
| 3368 | * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the |
| 3369 | * two functions eventually, but for now, it's here |
| 3370 | **/ |
| 3371 | static int |
| 3372 | lpfc_bg_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, |
| 3373 | struct lpfc_scsi_buf *lpfc_cmd) |
| 3374 | { |
| 3375 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 3376 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 3377 | struct sli4_sge *sgl = (struct sli4_sge *)(lpfc_cmd->fcp_bpl); |
| 3378 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3379 | uint32_t num_sge = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3380 | int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction; |
| 3381 | int prot_group_type = 0; |
| 3382 | int fcpdl; |
| 3383 | |
| 3384 | /* |
| 3385 | * Start the lpfc command prep by bumping the sgl beyond fcp_cmnd |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3386 | * fcp_rsp regions to the first data sge entry |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3387 | */ |
| 3388 | if (scsi_sg_count(scsi_cmnd)) { |
| 3389 | /* |
| 3390 | * The driver stores the segment count returned from pci_map_sg |
| 3391 | * because this a count of dma-mappings used to map the use_sg |
| 3392 | * pages. They are not guaranteed to be the same for those |
| 3393 | * architectures that implement an IOMMU. |
| 3394 | */ |
| 3395 | datasegcnt = dma_map_sg(&phba->pcidev->dev, |
| 3396 | scsi_sglist(scsi_cmnd), |
| 3397 | scsi_sg_count(scsi_cmnd), datadir); |
| 3398 | if (unlikely(!datasegcnt)) |
| 3399 | return 1; |
| 3400 | |
| 3401 | sgl += 1; |
| 3402 | /* clear the last flag in the fcp_rsp map entry */ |
| 3403 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 3404 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 3405 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 3406 | |
| 3407 | sgl += 1; |
| 3408 | lpfc_cmd->seg_cnt = datasegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3409 | |
| 3410 | /* First check if data segment count from SCSI Layer is good */ |
| 3411 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) |
| 3412 | goto err; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3413 | |
| 3414 | prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd); |
| 3415 | |
| 3416 | switch (prot_group_type) { |
| 3417 | case LPFC_PG_TYPE_NO_DIF: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3418 | /* Here we need to add a DISEED to the count */ |
| 3419 | if ((lpfc_cmd->seg_cnt + 1) > phba->cfg_total_seg_cnt) |
| 3420 | goto err; |
| 3421 | |
| 3422 | num_sge = lpfc_bg_setup_sgl(phba, scsi_cmnd, sgl, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3423 | datasegcnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3424 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3425 | /* we should have 2 or more entries in buffer list */ |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3426 | if (num_sge < 2) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3427 | goto err; |
| 3428 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3429 | |
| 3430 | case LPFC_PG_TYPE_DIF_BUF: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3431 | /* |
| 3432 | * This type indicates that protection buffers are |
| 3433 | * passed to the driver, so that needs to be prepared |
| 3434 | * for DMA |
| 3435 | */ |
| 3436 | protsegcnt = dma_map_sg(&phba->pcidev->dev, |
| 3437 | scsi_prot_sglist(scsi_cmnd), |
| 3438 | scsi_prot_sg_count(scsi_cmnd), datadir); |
| 3439 | if (unlikely(!protsegcnt)) { |
| 3440 | scsi_dma_unmap(scsi_cmnd); |
| 3441 | return 1; |
| 3442 | } |
| 3443 | |
| 3444 | lpfc_cmd->prot_seg_cnt = protsegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3445 | /* |
| 3446 | * There is a minimun of 3 SGEs used for every |
| 3447 | * protection data segment. |
| 3448 | */ |
| 3449 | if ((lpfc_cmd->prot_seg_cnt * 3) > |
| 3450 | (phba->cfg_total_seg_cnt - 2)) |
| 3451 | goto err; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3452 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3453 | num_sge = lpfc_bg_setup_sgl_prot(phba, scsi_cmnd, sgl, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3454 | datasegcnt, protsegcnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3455 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3456 | /* we should have 3 or more entries in buffer list */ |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3457 | if ((num_sge < 3) || |
| 3458 | (num_sge > phba->cfg_total_seg_cnt)) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3459 | goto err; |
| 3460 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3461 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3462 | case LPFC_PG_TYPE_INVALID: |
| 3463 | default: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3464 | scsi_dma_unmap(scsi_cmnd); |
| 3465 | lpfc_cmd->seg_cnt = 0; |
| 3466 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3467 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 3468 | "9083 Unexpected protection group %i\n", |
| 3469 | prot_group_type); |
| 3470 | return 1; |
| 3471 | } |
| 3472 | } |
| 3473 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 3474 | switch (scsi_get_prot_op(scsi_cmnd)) { |
| 3475 | case SCSI_PROT_WRITE_STRIP: |
| 3476 | case SCSI_PROT_READ_STRIP: |
| 3477 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_STRIP; |
| 3478 | break; |
| 3479 | case SCSI_PROT_WRITE_INSERT: |
| 3480 | case SCSI_PROT_READ_INSERT: |
| 3481 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_INSERT; |
| 3482 | break; |
| 3483 | case SCSI_PROT_WRITE_PASS: |
| 3484 | case SCSI_PROT_READ_PASS: |
| 3485 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_PASS; |
| 3486 | break; |
| 3487 | } |
| 3488 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3489 | fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3490 | fcp_cmnd->fcpDl = be32_to_cpu(fcpdl); |
| 3491 | |
| 3492 | /* |
| 3493 | * Due to difference in data length between DIF/non-DIF paths, |
| 3494 | * we need to set word 4 of IOCB here |
| 3495 | */ |
| 3496 | iocb_cmd->un.fcpi.fcpi_parm = fcpdl; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3497 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 3498 | /* |
| 3499 | * If the OAS driver feature is enabled and the lun is enabled for |
| 3500 | * OAS, set the oas iocb related flags. |
| 3501 | */ |
| 3502 | if ((phba->cfg_fof) && ((struct lpfc_device_data *) |
| 3503 | scsi_cmnd->device->hostdata)->oas_enabled) |
| 3504 | lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF); |
| 3505 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3506 | return 0; |
| 3507 | err: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3508 | if (lpfc_cmd->seg_cnt) |
| 3509 | scsi_dma_unmap(scsi_cmnd); |
| 3510 | if (lpfc_cmd->prot_seg_cnt) |
| 3511 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd), |
| 3512 | scsi_prot_sg_count(scsi_cmnd), |
| 3513 | scsi_cmnd->sc_data_direction); |
| 3514 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3515 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3516 | "9084 Cannot setup S/G List for HBA" |
| 3517 | "IO segs %d/%d SGL %d SCSI %d: %d %d\n", |
| 3518 | lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt, |
| 3519 | phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt, |
| 3520 | prot_group_type, num_sge); |
| 3521 | |
| 3522 | lpfc_cmd->seg_cnt = 0; |
| 3523 | lpfc_cmd->prot_seg_cnt = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3524 | return 1; |
| 3525 | } |
| 3526 | |
| 3527 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3528 | * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer |
| 3529 | * @phba: The Hba for which this call is being executed. |
| 3530 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3531 | * |
| 3532 | * This routine wraps the actual DMA mapping function pointer from the |
| 3533 | * lpfc_hba struct. |
| 3534 | * |
| 3535 | * Return codes: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 3536 | * 1 - Error |
| 3537 | * 0 - Success |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3538 | **/ |
| 3539 | static inline int |
| 3540 | lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 3541 | { |
| 3542 | return phba->lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 3543 | } |
| 3544 | |
| 3545 | /** |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3546 | * lpfc_bg_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer |
| 3547 | * using BlockGuard. |
| 3548 | * @phba: The Hba for which this call is being executed. |
| 3549 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3550 | * |
| 3551 | * This routine wraps the actual DMA mapping function pointer from the |
| 3552 | * lpfc_hba struct. |
| 3553 | * |
| 3554 | * Return codes: |
| 3555 | * 1 - Error |
| 3556 | * 0 - Success |
| 3557 | **/ |
| 3558 | static inline int |
| 3559 | lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 3560 | { |
| 3561 | return phba->lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 3562 | } |
| 3563 | |
| 3564 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3565 | * 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] | 3566 | * @phba: Pointer to hba context object. |
| 3567 | * @vport: Pointer to vport object. |
| 3568 | * @lpfc_cmd: Pointer to lpfc scsi command which reported the error. |
| 3569 | * @rsp_iocb: Pointer to response iocb object which reported error. |
| 3570 | * |
| 3571 | * This function posts an event when there is a SCSI command reporting |
| 3572 | * error from the scsi device. |
| 3573 | **/ |
| 3574 | static void |
| 3575 | lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 3576 | struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_iocbq *rsp_iocb) { |
| 3577 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 3578 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
| 3579 | uint32_t resp_info = fcprsp->rspStatus2; |
| 3580 | uint32_t scsi_status = fcprsp->rspStatus3; |
| 3581 | uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; |
| 3582 | struct lpfc_fast_path_event *fast_path_evt = NULL; |
| 3583 | struct lpfc_nodelist *pnode = lpfc_cmd->rdata->pnode; |
| 3584 | unsigned long flags; |
| 3585 | |
James Smart | 5989b8d | 2010-10-22 11:06:56 -0400 | [diff] [blame] | 3586 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 3587 | return; |
| 3588 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3589 | /* If there is queuefull or busy condition send a scsi event */ |
| 3590 | if ((cmnd->result == SAM_STAT_TASK_SET_FULL) || |
| 3591 | (cmnd->result == SAM_STAT_BUSY)) { |
| 3592 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3593 | if (!fast_path_evt) |
| 3594 | return; |
| 3595 | fast_path_evt->un.scsi_evt.event_type = |
| 3596 | FC_REG_SCSI_EVENT; |
| 3597 | fast_path_evt->un.scsi_evt.subcategory = |
| 3598 | (cmnd->result == SAM_STAT_TASK_SET_FULL) ? |
| 3599 | LPFC_EVENT_QFULL : LPFC_EVENT_DEVBSY; |
| 3600 | fast_path_evt->un.scsi_evt.lun = cmnd->device->lun; |
| 3601 | memcpy(&fast_path_evt->un.scsi_evt.wwpn, |
| 3602 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3603 | memcpy(&fast_path_evt->un.scsi_evt.wwnn, |
| 3604 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3605 | } else if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen && |
| 3606 | ((cmnd->cmnd[0] == READ_10) || (cmnd->cmnd[0] == WRITE_10))) { |
| 3607 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3608 | if (!fast_path_evt) |
| 3609 | return; |
| 3610 | fast_path_evt->un.check_cond_evt.scsi_event.event_type = |
| 3611 | FC_REG_SCSI_EVENT; |
| 3612 | fast_path_evt->un.check_cond_evt.scsi_event.subcategory = |
| 3613 | LPFC_EVENT_CHECK_COND; |
| 3614 | fast_path_evt->un.check_cond_evt.scsi_event.lun = |
| 3615 | cmnd->device->lun; |
| 3616 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwpn, |
| 3617 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3618 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwnn, |
| 3619 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3620 | fast_path_evt->un.check_cond_evt.sense_key = |
| 3621 | cmnd->sense_buffer[2] & 0xf; |
| 3622 | fast_path_evt->un.check_cond_evt.asc = cmnd->sense_buffer[12]; |
| 3623 | fast_path_evt->un.check_cond_evt.ascq = cmnd->sense_buffer[13]; |
| 3624 | } else if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) && |
| 3625 | fcpi_parm && |
| 3626 | ((be32_to_cpu(fcprsp->rspResId) != fcpi_parm) || |
| 3627 | ((scsi_status == SAM_STAT_GOOD) && |
| 3628 | !(resp_info & (RESID_UNDER | RESID_OVER))))) { |
| 3629 | /* |
| 3630 | * If status is good or resid does not match with fcp_param and |
| 3631 | * there is valid fcpi_parm, then there is a read_check error |
| 3632 | */ |
| 3633 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3634 | if (!fast_path_evt) |
| 3635 | return; |
| 3636 | fast_path_evt->un.read_check_error.header.event_type = |
| 3637 | FC_REG_FABRIC_EVENT; |
| 3638 | fast_path_evt->un.read_check_error.header.subcategory = |
| 3639 | LPFC_EVENT_FCPRDCHKERR; |
| 3640 | memcpy(&fast_path_evt->un.read_check_error.header.wwpn, |
| 3641 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3642 | memcpy(&fast_path_evt->un.read_check_error.header.wwnn, |
| 3643 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3644 | fast_path_evt->un.read_check_error.lun = cmnd->device->lun; |
| 3645 | fast_path_evt->un.read_check_error.opcode = cmnd->cmnd[0]; |
| 3646 | fast_path_evt->un.read_check_error.fcpiparam = |
| 3647 | fcpi_parm; |
| 3648 | } else |
| 3649 | return; |
| 3650 | |
| 3651 | fast_path_evt->vport = vport; |
| 3652 | spin_lock_irqsave(&phba->hbalock, flags); |
| 3653 | list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list); |
| 3654 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 3655 | lpfc_worker_wake_up(phba); |
| 3656 | return; |
| 3657 | } |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3658 | |
| 3659 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3660 | * 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] | 3661 | * @phba: The HBA for which this call is being executed. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3662 | * @psb: The scsi buffer which is going to be un-mapped. |
| 3663 | * |
| 3664 | * 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] | 3665 | * field of @lpfc_cmd for device with SLI-3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3666 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3667 | static void |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3668 | 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] | 3669 | { |
| 3670 | /* |
| 3671 | * There are only two special cases to consider. (1) the scsi command |
| 3672 | * requested scatter-gather usage or (2) the scsi command allocated |
| 3673 | * a request buffer, but did not request use_sg. There is a third |
| 3674 | * case, but it does not require resource deallocation. |
| 3675 | */ |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3676 | if (psb->seg_cnt > 0) |
| 3677 | scsi_dma_unmap(psb->pCmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3678 | if (psb->prot_seg_cnt > 0) |
| 3679 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(psb->pCmd), |
| 3680 | scsi_prot_sg_count(psb->pCmd), |
| 3681 | psb->pCmd->sc_data_direction); |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 3682 | } |
| 3683 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3684 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3685 | * lpfc_handler_fcp_err - FCP response handler |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3686 | * @vport: The virtual port for which this call is being executed. |
| 3687 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. |
| 3688 | * @rsp_iocb: The response IOCB which contains FCP error. |
| 3689 | * |
| 3690 | * This routine is called to process response IOCB with status field |
| 3691 | * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command |
| 3692 | * based upon SCSI and FCP error. |
| 3693 | **/ |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 3694 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3695 | lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd, |
| 3696 | struct lpfc_iocbq *rsp_iocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3697 | { |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3698 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3699 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 3700 | struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd; |
| 3701 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3702 | uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3703 | uint32_t resp_info = fcprsp->rspStatus2; |
| 3704 | uint32_t scsi_status = fcprsp->rspStatus3; |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3705 | uint32_t *lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3706 | uint32_t host_status = DID_OK; |
| 3707 | uint32_t rsplen = 0; |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3708 | uint32_t fcpDl; |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3709 | uint32_t logit = LOG_FCP | LOG_FCP_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3710 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3711 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3712 | /* |
| 3713 | * If this is a task management command, there is no |
| 3714 | * scsi packet associated with this lpfc_cmd. The driver |
| 3715 | * consumes it. |
| 3716 | */ |
| 3717 | if (fcpcmd->fcpCntl2) { |
| 3718 | scsi_status = 0; |
| 3719 | goto out; |
| 3720 | } |
| 3721 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3722 | if (resp_info & RSP_LEN_VALID) { |
| 3723 | rsplen = be32_to_cpu(fcprsp->rspRspLen); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3724 | if (rsplen != 0 && rsplen != 4 && rsplen != 8) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3725 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 3726 | "2719 Invalid response length: " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 3727 | "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] | 3728 | cmnd->device->id, |
| 3729 | cmnd->device->lun, cmnd->cmnd[0], |
| 3730 | rsplen); |
| 3731 | host_status = DID_ERROR; |
| 3732 | goto out; |
| 3733 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3734 | if (fcprsp->rspInfo3 != RSP_NO_FAILURE) { |
| 3735 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 3736 | "2757 Protocol failure detected during " |
| 3737 | "processing of FCP I/O op: " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 3738 | "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] | 3739 | cmnd->device->id, |
| 3740 | cmnd->device->lun, cmnd->cmnd[0], |
| 3741 | fcprsp->rspInfo3); |
| 3742 | host_status = DID_ERROR; |
| 3743 | goto out; |
| 3744 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3745 | } |
| 3746 | |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3747 | if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) { |
| 3748 | uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen); |
| 3749 | if (snslen > SCSI_SENSE_BUFFERSIZE) |
| 3750 | snslen = SCSI_SENSE_BUFFERSIZE; |
| 3751 | |
| 3752 | if (resp_info & RSP_LEN_VALID) |
| 3753 | rsplen = be32_to_cpu(fcprsp->rspRspLen); |
| 3754 | memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen); |
| 3755 | } |
| 3756 | lp = (uint32_t *)cmnd->sense_buffer; |
| 3757 | |
James Smart | aa1c7ee | 2012-08-14 14:26:06 -0400 | [diff] [blame] | 3758 | /* special handling for under run conditions */ |
| 3759 | if (!scsi_status && (resp_info & RESID_UNDER)) { |
| 3760 | /* don't log under runs if fcp set... */ |
| 3761 | if (vport->cfg_log_verbose & LOG_FCP) |
| 3762 | logit = LOG_FCP_ERROR; |
| 3763 | /* unless operator says so */ |
| 3764 | if (vport->cfg_log_verbose & LOG_FCP_UNDER) |
| 3765 | logit = LOG_FCP_UNDER; |
| 3766 | } |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3767 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3768 | lpfc_printf_vlog(vport, KERN_WARNING, logit, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3769 | "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] | 3770 | "Data: x%x x%x x%x x%x x%x\n", |
| 3771 | cmnd->cmnd[0], scsi_status, |
| 3772 | be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info, |
| 3773 | be32_to_cpu(fcprsp->rspResId), |
| 3774 | be32_to_cpu(fcprsp->rspSnsLen), |
| 3775 | be32_to_cpu(fcprsp->rspRspLen), |
| 3776 | fcprsp->rspInfo3); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3777 | |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3778 | scsi_set_resid(cmnd, 0); |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3779 | fcpDl = be32_to_cpu(fcpcmd->fcpDl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3780 | if (resp_info & RESID_UNDER) { |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3781 | scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3782 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3783 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_UNDER, |
James Smart | 45634a86 | 2018-01-30 15:59:00 -0800 | [diff] [blame] | 3784 | "9025 FCP Underrun, expected %d, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3785 | "residual %d Data: x%x x%x x%x\n", |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3786 | fcpDl, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3787 | scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0], |
| 3788 | cmnd->underflow); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3789 | |
| 3790 | /* |
James Smart | 45634a86 | 2018-01-30 15:59:00 -0800 | [diff] [blame] | 3791 | * If there is an under run, check if under run reported by |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3792 | * storage array is same as the under run reported by HBA. |
| 3793 | * If this is not same, there is a dropped frame. |
| 3794 | */ |
James Smart | 45634a86 | 2018-01-30 15:59:00 -0800 | [diff] [blame] | 3795 | if (fcpi_parm && (scsi_get_resid(cmnd) != fcpi_parm)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3796 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 3797 | LOG_FCP | LOG_FCP_ERROR, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3798 | "9026 FCP Read Check Error " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3799 | "and Underrun Data: x%x x%x x%x x%x\n", |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3800 | fcpDl, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3801 | scsi_get_resid(cmnd), fcpi_parm, |
| 3802 | cmnd->cmnd[0]); |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3803 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3804 | host_status = DID_ERROR; |
| 3805 | } |
| 3806 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3807 | * The cmnd->underflow is the minimum number of bytes that must |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3808 | * be transferred for this command. Provided a sense condition |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3809 | * is not present, make sure the actual amount transferred is at |
| 3810 | * least the underflow value or fail. |
| 3811 | */ |
| 3812 | if (!(resp_info & SNS_LEN_VALID) && |
| 3813 | (scsi_status == SAM_STAT_GOOD) && |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3814 | (scsi_bufflen(cmnd) - scsi_get_resid(cmnd) |
| 3815 | < cmnd->underflow)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3816 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3817 | "9027 FCP command x%x residual " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3818 | "underrun converted to error " |
| 3819 | "Data: x%x x%x x%x\n", |
James Smart | 66dbfbe | 2007-08-05 06:08:38 -0400 | [diff] [blame] | 3820 | cmnd->cmnd[0], scsi_bufflen(cmnd), |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3821 | scsi_get_resid(cmnd), cmnd->underflow); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3822 | host_status = DID_ERROR; |
| 3823 | } |
| 3824 | } else if (resp_info & RESID_OVER) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3825 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3826 | "9028 FCP command x%x residual overrun error. " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 3827 | "Data: x%x x%x\n", cmnd->cmnd[0], |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3828 | scsi_bufflen(cmnd), scsi_get_resid(cmnd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3829 | host_status = DID_ERROR; |
| 3830 | |
| 3831 | /* |
| 3832 | * Check SLI validation that all the transfer was actually done |
James Smart | 26373d2 | 2013-09-06 12:19:17 -0400 | [diff] [blame] | 3833 | * (fcpi_parm should be zero). Apply check only to reads. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3834 | */ |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3835 | } else if (fcpi_parm) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3836 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR, |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3837 | "9029 FCP %s Check Error xri x%x Data: " |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 3838 | "x%x x%x x%x x%x x%x\n", |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3839 | ((cmnd->sc_data_direction == DMA_FROM_DEVICE) ? |
| 3840 | "Read" : "Write"), |
| 3841 | ((phba->sli_rev == LPFC_SLI_REV4) ? |
| 3842 | lpfc_cmd->cur_iocbq.sli4_xritag : |
| 3843 | rsp_iocb->iocb.ulpContext), |
| 3844 | fcpDl, be32_to_cpu(fcprsp->rspResId), |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 3845 | fcpi_parm, cmnd->cmnd[0], scsi_status); |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3846 | |
| 3847 | /* There is some issue with the LPe12000 that causes it |
| 3848 | * to miscalculate the fcpi_parm and falsely trip this |
| 3849 | * recovery logic. Detect this case and don't error when true. |
| 3850 | */ |
| 3851 | if (fcpi_parm > fcpDl) |
| 3852 | goto out; |
| 3853 | |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 3854 | switch (scsi_status) { |
| 3855 | case SAM_STAT_GOOD: |
| 3856 | case SAM_STAT_CHECK_CONDITION: |
| 3857 | /* Fabric dropped a data frame. Fail any successful |
| 3858 | * command in which we detected dropped frames. |
| 3859 | * A status of good or some check conditions could |
| 3860 | * be considered a successful command. |
| 3861 | */ |
| 3862 | host_status = DID_ERROR; |
| 3863 | break; |
| 3864 | } |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3865 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3866 | } |
| 3867 | |
| 3868 | out: |
| 3869 | cmnd->result = ScsiResult(host_status, scsi_status); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3870 | lpfc_send_scsi_error_event(vport->phba, vport, lpfc_cmd, rsp_iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3871 | } |
| 3872 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3873 | /** |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 3874 | * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution |
| 3875 | * @phba: Pointer to HBA context object. |
| 3876 | * |
| 3877 | * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index |
| 3878 | * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock |
| 3879 | * held. |
| 3880 | * If scsi-mq is enabled, get the default block layer mapping of software queues |
| 3881 | * to hardware queues. This information is saved in request tag. |
| 3882 | * |
| 3883 | * Return: index into SLI4 fast-path FCP queue index. |
| 3884 | **/ |
| 3885 | int lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba, |
| 3886 | struct lpfc_scsi_buf *lpfc_cmd) |
| 3887 | { |
| 3888 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 3889 | struct lpfc_vector_map_info *cpup; |
| 3890 | int chann, cpu; |
| 3891 | uint32_t tag; |
| 3892 | uint16_t hwq; |
| 3893 | |
Mauricio Faria de Oliveira | 05a0587 | 2016-06-07 20:13:08 -0300 | [diff] [blame] | 3894 | if (cmnd && shost_use_blk_mq(cmnd->device->host)) { |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 3895 | tag = blk_mq_unique_tag(cmnd->request); |
| 3896 | hwq = blk_mq_unique_tag_to_hwq(tag); |
| 3897 | |
| 3898 | return hwq; |
| 3899 | } |
| 3900 | |
| 3901 | if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_CPU |
| 3902 | && phba->cfg_fcp_io_channel > 1) { |
| 3903 | cpu = smp_processor_id(); |
| 3904 | if (cpu < phba->sli4_hba.num_present_cpu) { |
| 3905 | cpup = phba->sli4_hba.cpu_map; |
| 3906 | cpup += cpu; |
| 3907 | return cpup->channel_id; |
| 3908 | } |
| 3909 | } |
| 3910 | chann = atomic_add_return(1, &phba->fcp_qidx); |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 3911 | chann = chann % phba->cfg_fcp_io_channel; |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 3912 | return chann; |
| 3913 | } |
| 3914 | |
| 3915 | |
| 3916 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3917 | * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3918 | * @phba: The Hba for which this call is being executed. |
| 3919 | * @pIocbIn: The command IOCBQ for the scsi cmnd. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3920 | * @pIocbOut: The response IOCBQ for the scsi cmnd. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3921 | * |
| 3922 | * This routine assigns scsi command result by looking into response IOCB |
| 3923 | * status field appropriately. This routine handles QUEUE FULL condition as |
| 3924 | * well by ramping down device queue depth. |
| 3925 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3926 | static void |
| 3927 | lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn, |
| 3928 | struct lpfc_iocbq *pIocbOut) |
| 3929 | { |
| 3930 | struct lpfc_scsi_buf *lpfc_cmd = |
| 3931 | (struct lpfc_scsi_buf *) pIocbIn->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3932 | struct lpfc_vport *vport = pIocbIn->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3933 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| 3934 | struct lpfc_nodelist *pnode = rdata->pnode; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3935 | struct scsi_cmnd *cmd; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 3936 | unsigned long flags; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3937 | struct lpfc_fast_path_event *fast_path_evt; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3938 | struct Scsi_Host *shost; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3939 | uint32_t logit = LOG_FCP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3940 | |
James Smart | 2cee780 | 2017-06-01 21:07:02 -0700 | [diff] [blame] | 3941 | atomic_inc(&phba->fc4ScsiIoCmpls); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3942 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3943 | /* Sanity check on return of outstanding command */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3944 | cmd = lpfc_cmd->pCmd; |
James Smart | c90261d | 2015-12-16 18:11:57 -0500 | [diff] [blame] | 3945 | if (!cmd) |
| 3946 | return; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3947 | shost = cmd->device->host; |
| 3948 | |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3949 | lpfc_cmd->result = (pIocbOut->iocb.un.ulpWord[4] & IOERR_PARAM_MASK); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3950 | lpfc_cmd->status = pIocbOut->iocb.ulpStatus; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3951 | /* pick up SLI4 exhange busy status from HBA */ |
| 3952 | lpfc_cmd->exch_busy = pIocbOut->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 3953 | |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 3954 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 3955 | if (lpfc_cmd->prot_data_type) { |
| 3956 | struct scsi_dif_tuple *src = NULL; |
| 3957 | |
| 3958 | src = (struct scsi_dif_tuple *)lpfc_cmd->prot_data_segment; |
| 3959 | /* |
| 3960 | * Used to restore any changes to protection |
| 3961 | * data for error injection. |
| 3962 | */ |
| 3963 | switch (lpfc_cmd->prot_data_type) { |
| 3964 | case LPFC_INJERR_REFTAG: |
| 3965 | src->ref_tag = |
| 3966 | lpfc_cmd->prot_data; |
| 3967 | break; |
| 3968 | case LPFC_INJERR_APPTAG: |
| 3969 | src->app_tag = |
| 3970 | (uint16_t)lpfc_cmd->prot_data; |
| 3971 | break; |
| 3972 | case LPFC_INJERR_GUARD: |
| 3973 | src->guard_tag = |
| 3974 | (uint16_t)lpfc_cmd->prot_data; |
| 3975 | break; |
| 3976 | default: |
| 3977 | break; |
| 3978 | } |
| 3979 | |
| 3980 | lpfc_cmd->prot_data = 0; |
| 3981 | lpfc_cmd->prot_data_type = 0; |
| 3982 | lpfc_cmd->prot_data_segment = NULL; |
| 3983 | } |
| 3984 | #endif |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 3985 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3986 | if (lpfc_cmd->status) { |
| 3987 | if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT && |
| 3988 | (lpfc_cmd->result & IOERR_DRVR_MASK)) |
| 3989 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; |
| 3990 | else if (lpfc_cmd->status >= IOSTAT_CNT) |
| 3991 | lpfc_cmd->status = IOSTAT_DEFAULT; |
James Smart | aa1c7ee | 2012-08-14 14:26:06 -0400 | [diff] [blame] | 3992 | if (lpfc_cmd->status == IOSTAT_FCP_RSP_ERROR && |
| 3993 | !lpfc_cmd->fcp_rsp->rspStatus3 && |
| 3994 | (lpfc_cmd->fcp_rsp->rspStatus2 & RESID_UNDER) && |
| 3995 | !(vport->cfg_log_verbose & LOG_FCP_UNDER)) |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3996 | logit = 0; |
| 3997 | else |
| 3998 | logit = LOG_FCP | LOG_FCP_UNDER; |
| 3999 | lpfc_printf_vlog(vport, KERN_WARNING, logit, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4000 | "9030 FCP cmd x%x failed <%d/%lld> " |
James Smart | 5a0d80f | 2012-05-09 21:18:20 -0400 | [diff] [blame] | 4001 | "status: x%x result: x%x " |
| 4002 | "sid: x%x did: x%x oxid: x%x " |
| 4003 | "Data: x%x x%x\n", |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 4004 | cmd->cmnd[0], |
| 4005 | cmd->device ? cmd->device->id : 0xffff, |
| 4006 | cmd->device ? cmd->device->lun : 0xffff, |
| 4007 | lpfc_cmd->status, lpfc_cmd->result, |
James Smart | 3bf41ba | 2013-05-31 17:03:18 -0400 | [diff] [blame] | 4008 | vport->fc_myDID, |
| 4009 | (pnode) ? pnode->nlp_DID : 0, |
James Smart | 5a0d80f | 2012-05-09 21:18:20 -0400 | [diff] [blame] | 4010 | phba->sli_rev == LPFC_SLI_REV4 ? |
| 4011 | lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 4012 | pIocbOut->iocb.ulpContext, |
| 4013 | lpfc_cmd->cur_iocbq.iocb.ulpIoTag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4014 | |
| 4015 | switch (lpfc_cmd->status) { |
| 4016 | case IOSTAT_FCP_RSP_ERROR: |
| 4017 | /* Call FCP RSP handler to determine result */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4018 | lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4019 | break; |
| 4020 | case IOSTAT_NPORT_BSY: |
| 4021 | case IOSTAT_FABRIC_BSY: |
James Smart | 0f1f53a | 2008-08-24 21:50:18 -0400 | [diff] [blame] | 4022 | cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 0); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4023 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 4024 | if (!fast_path_evt) |
| 4025 | break; |
| 4026 | fast_path_evt->un.fabric_evt.event_type = |
| 4027 | FC_REG_FABRIC_EVENT; |
| 4028 | fast_path_evt->un.fabric_evt.subcategory = |
| 4029 | (lpfc_cmd->status == IOSTAT_NPORT_BSY) ? |
| 4030 | LPFC_EVENT_PORT_BUSY : LPFC_EVENT_FABRIC_BUSY; |
| 4031 | if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
| 4032 | memcpy(&fast_path_evt->un.fabric_evt.wwpn, |
| 4033 | &pnode->nlp_portname, |
| 4034 | sizeof(struct lpfc_name)); |
| 4035 | memcpy(&fast_path_evt->un.fabric_evt.wwnn, |
| 4036 | &pnode->nlp_nodename, |
| 4037 | sizeof(struct lpfc_name)); |
| 4038 | } |
| 4039 | fast_path_evt->vport = vport; |
| 4040 | fast_path_evt->work_evt.evt = |
| 4041 | LPFC_EVT_FASTPATH_MGMT_EVT; |
| 4042 | spin_lock_irqsave(&phba->hbalock, flags); |
| 4043 | list_add_tail(&fast_path_evt->work_evt.evt_listp, |
| 4044 | &phba->work_list); |
| 4045 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4046 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4047 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4048 | case IOSTAT_LOCAL_REJECT: |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4049 | case IOSTAT_REMOTE_STOP: |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 4050 | if (lpfc_cmd->result == IOERR_ELXSEC_KEY_UNWRAP_ERROR || |
| 4051 | lpfc_cmd->result == |
| 4052 | IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR || |
| 4053 | lpfc_cmd->result == IOERR_ELXSEC_CRYPTO_ERROR || |
| 4054 | lpfc_cmd->result == |
| 4055 | IOERR_ELXSEC_CRYPTO_COMPARE_ERROR) { |
| 4056 | cmd->result = ScsiResult(DID_NO_CONNECT, 0); |
| 4057 | break; |
| 4058 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4059 | if (lpfc_cmd->result == IOERR_INVALID_RPI || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4060 | lpfc_cmd->result == IOERR_NO_RESOURCES || |
James Smart | b92938b | 2010-06-07 15:24:12 -0400 | [diff] [blame] | 4061 | lpfc_cmd->result == IOERR_ABORT_REQUESTED || |
| 4062 | lpfc_cmd->result == IOERR_SLER_CMD_RCV_FAILURE) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4063 | cmd->result = ScsiResult(DID_REQUEUE, 0); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4064 | break; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4065 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4066 | if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED || |
| 4067 | lpfc_cmd->result == IOERR_TX_DMA_FAILED) && |
| 4068 | pIocbOut->iocb.unsli3.sli3_bg.bgstat) { |
| 4069 | if (scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) { |
| 4070 | /* |
| 4071 | * This is a response for a BG enabled |
| 4072 | * cmd. Parse BG error |
| 4073 | */ |
| 4074 | lpfc_parse_bg_err(phba, lpfc_cmd, |
| 4075 | pIocbOut); |
| 4076 | break; |
| 4077 | } else { |
| 4078 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 4079 | LOG_BG, |
| 4080 | "9031 non-zero BGSTAT " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4081 | "on unprotected cmd\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4082 | } |
| 4083 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4084 | if ((lpfc_cmd->status == IOSTAT_REMOTE_STOP) |
| 4085 | && (phba->sli_rev == LPFC_SLI_REV4) |
| 4086 | && (pnode && NLP_CHK_NODE_ACT(pnode))) { |
| 4087 | /* This IO was aborted by the target, we don't |
| 4088 | * know the rxid and because we did not send the |
| 4089 | * ABTS we cannot generate and RRQ. |
| 4090 | */ |
| 4091 | lpfc_set_rrq_active(phba, pnode, |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 4092 | lpfc_cmd->cur_iocbq.sli4_lxritag, |
| 4093 | 0, 0); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4094 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4095 | /* else: fall through */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4096 | default: |
| 4097 | cmd->result = ScsiResult(DID_ERROR, 0); |
| 4098 | break; |
| 4099 | } |
| 4100 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4101 | if (!pnode || !NLP_CHK_NODE_ACT(pnode) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4102 | || (pnode->nlp_state != NLP_STE_MAPPED_NODE)) |
James Smart | 0f1f53a | 2008-08-24 21:50:18 -0400 | [diff] [blame] | 4103 | cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, |
| 4104 | SAM_STAT_BUSY); |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 4105 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4106 | cmd->result = ScsiResult(DID_OK, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4107 | |
| 4108 | if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) { |
| 4109 | uint32_t *lp = (uint32_t *)cmd->sense_buffer; |
| 4110 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4111 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4112 | "0710 Iodone <%d/%llu> cmd %p, error " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4113 | "x%x SNS x%x x%x Data: x%x x%x\n", |
| 4114 | cmd->device->id, cmd->device->lun, cmd, |
| 4115 | cmd->result, *lp, *(lp + 3), cmd->retries, |
| 4116 | scsi_get_resid(cmd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4117 | } |
| 4118 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4119 | lpfc_update_stats(phba, lpfc_cmd); |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4120 | if (vport->cfg_max_scsicmpl_time && |
| 4121 | time_after(jiffies, lpfc_cmd->start_time + |
| 4122 | msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4123 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4124 | if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
James Smart | f91bc59 | 2018-04-09 14:24:22 -0700 | [diff] [blame^] | 4125 | atomic_dec(&pnode->cmd_pending); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4126 | if (pnode->cmd_qdepth > |
| 4127 | atomic_read(&pnode->cmd_pending) && |
| 4128 | (atomic_read(&pnode->cmd_pending) > |
| 4129 | LPFC_MIN_TGT_QDEPTH) && |
| 4130 | ((cmd->cmnd[0] == READ_10) || |
| 4131 | (cmd->cmnd[0] == WRITE_10))) |
| 4132 | pnode->cmd_qdepth = |
| 4133 | atomic_read(&pnode->cmd_pending); |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4134 | |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4135 | pnode->last_change_time = jiffies; |
| 4136 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4137 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4138 | } else if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
James Smart | f91bc59 | 2018-04-09 14:24:22 -0700 | [diff] [blame^] | 4139 | atomic_dec(&pnode->cmd_pending); |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4140 | } |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4141 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4142 | |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4143 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92e3af6 | 2012-08-14 14:26:28 -0400 | [diff] [blame] | 4144 | lpfc_cmd->pCmd = NULL; |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4145 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92e3af6 | 2012-08-14 14:26:28 -0400 | [diff] [blame] | 4146 | |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 4147 | /* The sdev is not guaranteed to be valid post scsi_done upcall. */ |
| 4148 | cmd->scsi_done(cmd); |
| 4149 | |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4150 | /* |
| 4151 | * If there is a thread waiting for command completion |
| 4152 | * wake up the thread. |
| 4153 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4154 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4155 | if (lpfc_cmd->waitq) |
| 4156 | wake_up(lpfc_cmd->waitq); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4157 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4158 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4159 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4160 | } |
| 4161 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4162 | /** |
Alexey Kardashevskiy | 8b2564e | 2015-04-28 18:26:22 +1000 | [diff] [blame] | 4163 | * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB |
| 4164 | * @data: A pointer to the immediate command data portion of the IOCB. |
| 4165 | * @fcp_cmnd: The FCP Command that is provided by the SCSI layer. |
| 4166 | * |
| 4167 | * The routine copies the entire FCP command from @fcp_cmnd to @data while |
| 4168 | * byte swapping the data to big endian format for transmission on the wire. |
| 4169 | **/ |
| 4170 | static void |
| 4171 | lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd) |
| 4172 | { |
| 4173 | int i, j; |
| 4174 | for (i = 0, j = 0; i < sizeof(struct fcp_cmnd); |
| 4175 | i += sizeof(uint32_t), j++) { |
| 4176 | ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]); |
| 4177 | } |
| 4178 | } |
| 4179 | |
| 4180 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4181 | * 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] | 4182 | * @vport: The virtual port for which this call is being executed. |
| 4183 | * @lpfc_cmd: The scsi command which needs to send. |
| 4184 | * @pnode: Pointer to lpfc_nodelist. |
| 4185 | * |
| 4186 | * This routine initializes fcp_cmnd and iocb data structure from scsi command |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4187 | * to transfer for device with SLI3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4188 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4189 | static void |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4190 | 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] | 4191 | struct lpfc_nodelist *pnode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4192 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4193 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4194 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 4195 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 4196 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 4197 | struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq); |
| 4198 | int datadir = scsi_cmnd->sc_data_direction; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4199 | uint8_t *ptr; |
| 4200 | bool sli4; |
James Smart | 98bbf5f | 2013-09-06 12:18:45 -0400 | [diff] [blame] | 4201 | uint32_t fcpdl; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4202 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4203 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 4204 | return; |
| 4205 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4206 | lpfc_cmd->fcp_rsp->rspSnsLen = 0; |
James.Smart@Emulex.Com | 69859dc | 2005-08-10 15:02:37 -0400 | [diff] [blame] | 4207 | /* clear task management bits */ |
| 4208 | lpfc_cmd->fcp_cmnd->fcpCntl2 = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4209 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 4210 | int_to_scsilun(lpfc_cmd->pCmd->device->lun, |
| 4211 | &lpfc_cmd->fcp_cmnd->fcp_lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4212 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4213 | ptr = &fcp_cmnd->fcpCdb[0]; |
| 4214 | memcpy(ptr, scsi_cmnd->cmnd, scsi_cmnd->cmd_len); |
| 4215 | if (scsi_cmnd->cmd_len < LPFC_FCP_CDB_LEN) { |
| 4216 | ptr += scsi_cmnd->cmd_len; |
| 4217 | memset(ptr, 0, (LPFC_FCP_CDB_LEN - scsi_cmnd->cmd_len)); |
| 4218 | } |
| 4219 | |
Christoph Hellwig | 5066863 | 2014-10-30 14:30:06 +0100 | [diff] [blame] | 4220 | fcp_cmnd->fcpCntl1 = SIMPLE_Q; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4221 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4222 | sli4 = (phba->sli_rev == LPFC_SLI_REV4); |
James Smart | 6acb348 | 2014-04-04 13:51:25 -0400 | [diff] [blame] | 4223 | piocbq->iocb.un.fcpi.fcpi_XRdy = 0; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4224 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4225 | /* |
| 4226 | * There are three possibilities here - use scatter-gather segment, use |
| 4227 | * the single mapping, or neither. Start the lpfc command prep by |
| 4228 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 4229 | * data bde entry. |
| 4230 | */ |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4231 | if (scsi_sg_count(scsi_cmnd)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4232 | if (datadir == DMA_TO_DEVICE) { |
| 4233 | iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR; |
James Smart | 182ba75 | 2013-07-15 18:34:05 -0400 | [diff] [blame] | 4234 | iocb_cmd->ulpPU = PARM_READ_CHECK; |
James Smart | 3cb01c5 | 2013-07-15 18:35:04 -0400 | [diff] [blame] | 4235 | if (vport->cfg_first_burst_size && |
| 4236 | (pnode->nlp_flag & NLP_FIRSTBURST)) { |
James Smart | 98bbf5f | 2013-09-06 12:18:45 -0400 | [diff] [blame] | 4237 | fcpdl = scsi_bufflen(scsi_cmnd); |
| 4238 | if (fcpdl < vport->cfg_first_burst_size) |
| 4239 | piocbq->iocb.un.fcpi.fcpi_XRdy = fcpdl; |
| 4240 | else |
| 4241 | piocbq->iocb.un.fcpi.fcpi_XRdy = |
| 4242 | vport->cfg_first_burst_size; |
James Smart | 3cb01c5 | 2013-07-15 18:35:04 -0400 | [diff] [blame] | 4243 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4244 | fcp_cmnd->fcpCntl3 = WRITE_DATA; |
James Smart | 2cee780 | 2017-06-01 21:07:02 -0700 | [diff] [blame] | 4245 | atomic_inc(&phba->fc4ScsiOutputRequests); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4246 | } else { |
| 4247 | iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR; |
| 4248 | iocb_cmd->ulpPU = PARM_READ_CHECK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4249 | fcp_cmnd->fcpCntl3 = READ_DATA; |
James Smart | 2cee780 | 2017-06-01 21:07:02 -0700 | [diff] [blame] | 4250 | atomic_inc(&phba->fc4ScsiInputRequests); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4251 | } |
| 4252 | } else { |
| 4253 | iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR; |
| 4254 | iocb_cmd->un.fcpi.fcpi_parm = 0; |
| 4255 | iocb_cmd->ulpPU = 0; |
| 4256 | fcp_cmnd->fcpCntl3 = 0; |
James Smart | 2cee780 | 2017-06-01 21:07:02 -0700 | [diff] [blame] | 4257 | atomic_inc(&phba->fc4ScsiControlRequests); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4258 | } |
Alexey Kardashevskiy | 8b2564e | 2015-04-28 18:26:22 +1000 | [diff] [blame] | 4259 | if (phba->sli_rev == 3 && |
| 4260 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) |
| 4261 | lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4262 | /* |
| 4263 | * Finish initializing those IOCB fields that are independent |
| 4264 | * of the scsi_cmnd request_buffer |
| 4265 | */ |
| 4266 | piocbq->iocb.ulpContext = pnode->nlp_rpi; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4267 | if (sli4) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4268 | piocbq->iocb.ulpContext = |
| 4269 | phba->sli4_hba.rpi_ids[pnode->nlp_rpi]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4270 | if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE) |
| 4271 | piocbq->iocb.ulpFCP2Rcvy = 1; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4272 | else |
| 4273 | piocbq->iocb.ulpFCP2Rcvy = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4274 | |
| 4275 | piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f); |
| 4276 | piocbq->context1 = lpfc_cmd; |
| 4277 | piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; |
| 4278 | piocbq->iocb.ulpTimeout = lpfc_cmd->timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4279 | piocbq->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4280 | } |
| 4281 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4282 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4283 | * 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] | 4284 | * @vport: The virtual port for which this call is being executed. |
| 4285 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. |
| 4286 | * @lun: Logical unit number. |
| 4287 | * @task_mgmt_cmd: SCSI task management command. |
| 4288 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4289 | * This routine creates FCP information unit corresponding to @task_mgmt_cmd |
| 4290 | * for device with SLI-3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4291 | * |
| 4292 | * Return codes: |
| 4293 | * 0 - Error |
| 4294 | * 1 - Success |
| 4295 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4296 | static int |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4297 | lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4298 | struct lpfc_scsi_buf *lpfc_cmd, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4299 | uint64_t lun, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4300 | uint8_t task_mgmt_cmd) |
| 4301 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4302 | struct lpfc_iocbq *piocbq; |
| 4303 | IOCB_t *piocb; |
| 4304 | struct fcp_cmnd *fcp_cmnd; |
James Smart | 0b18ac4 | 2006-05-01 21:50:40 -0400 | [diff] [blame] | 4305 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4306 | struct lpfc_nodelist *ndlp = rdata->pnode; |
| 4307 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4308 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || |
| 4309 | ndlp->nlp_state != NLP_STE_MAPPED_NODE) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4310 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4311 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4312 | piocbq = &(lpfc_cmd->cur_iocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4313 | piocbq->vport = vport; |
| 4314 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4315 | piocb = &piocbq->iocb; |
| 4316 | |
| 4317 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4318 | /* Clear out any old data in the FCP command area */ |
| 4319 | memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd)); |
| 4320 | int_to_scsilun(lun, &fcp_cmnd->fcp_lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4321 | fcp_cmnd->fcpCntl2 = task_mgmt_cmd; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4322 | if (vport->phba->sli_rev == 3 && |
| 4323 | !(vport->phba->sli3_options & LPFC_SLI3_BG_ENABLED)) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4324 | lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4325 | piocb->ulpCommand = CMD_FCP_ICMND64_CR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4326 | piocb->ulpContext = ndlp->nlp_rpi; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4327 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
| 4328 | piocb->ulpContext = |
| 4329 | vport->phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
| 4330 | } |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 4331 | piocb->ulpFCP2Rcvy = (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) ? 1 : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4332 | piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f); |
James Smart | f9226c2 | 2014-02-20 09:57:28 -0500 | [diff] [blame] | 4333 | piocb->ulpPU = 0; |
| 4334 | piocb->un.fcpi.fcpi_parm = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4335 | |
| 4336 | /* ulpTimeout is only one byte */ |
| 4337 | if (lpfc_cmd->timeout > 0xff) { |
| 4338 | /* |
| 4339 | * Do not timeout the command at the firmware level. |
| 4340 | * The driver will provide the timeout mechanism. |
| 4341 | */ |
| 4342 | piocb->ulpTimeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4343 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4344 | piocb->ulpTimeout = lpfc_cmd->timeout; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4345 | |
| 4346 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 4347 | lpfc_sli4_set_rsp_sgl_last(vport->phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4348 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4349 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4350 | } |
| 4351 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4352 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4353 | * lpfc_scsi_api_table_setup - Set up scsi api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4354 | * @phba: The hba struct for which this call is being executed. |
| 4355 | * @dev_grp: The HBA PCI-Device group number. |
| 4356 | * |
| 4357 | * This routine sets up the SCSI interface API function jump table in @phba |
| 4358 | * struct. |
| 4359 | * Returns: 0 - success, -ENODEV - failure. |
| 4360 | **/ |
| 4361 | int |
| 4362 | lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 4363 | { |
| 4364 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4365 | phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf; |
| 4366 | phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4367 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4368 | switch (dev_grp) { |
| 4369 | case LPFC_PCI_DEV_LP: |
| 4370 | phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s3; |
| 4371 | phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4372 | 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] | 4373 | phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4374 | phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s3; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4375 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4376 | case LPFC_PCI_DEV_OC: |
| 4377 | phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s4; |
| 4378 | phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s4; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4379 | 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] | 4380 | phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s4; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4381 | phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s4; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4382 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4383 | default: |
| 4384 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4385 | "1418 Invalid HBA PCI-device group: 0x%x\n", |
| 4386 | dev_grp); |
| 4387 | return -ENODEV; |
| 4388 | break; |
| 4389 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4390 | phba->lpfc_rampdown_queue_depth = lpfc_rampdown_queue_depth; |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 4391 | phba->lpfc_scsi_cmd_iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4392 | return 0; |
| 4393 | } |
| 4394 | |
| 4395 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4396 | * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4397 | * @phba: The Hba for which this call is being executed. |
| 4398 | * @cmdiocbq: Pointer to lpfc_iocbq data structure. |
| 4399 | * @rspiocbq: Pointer to lpfc_iocbq data structure. |
| 4400 | * |
| 4401 | * This routine is IOCB completion routine for device reset and target reset |
| 4402 | * routine. This routine release scsi buffer associated with lpfc_cmd. |
| 4403 | **/ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4404 | static void |
| 4405 | lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba, |
| 4406 | struct lpfc_iocbq *cmdiocbq, |
| 4407 | struct lpfc_iocbq *rspiocbq) |
| 4408 | { |
| 4409 | struct lpfc_scsi_buf *lpfc_cmd = |
| 4410 | (struct lpfc_scsi_buf *) cmdiocbq->context1; |
| 4411 | if (lpfc_cmd) |
| 4412 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 4413 | return; |
| 4414 | } |
| 4415 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4416 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4417 | * lpfc_info - Info entry point of scsi_host_template data structure |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4418 | * @host: The scsi host for which this call is being executed. |
| 4419 | * |
| 4420 | * This routine provides module information about hba. |
| 4421 | * |
| 4422 | * Reutrn code: |
| 4423 | * Pointer to char - Success. |
| 4424 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4425 | const char * |
| 4426 | lpfc_info(struct Scsi_Host *host) |
| 4427 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4428 | struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata; |
| 4429 | struct lpfc_hba *phba = vport->phba; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4430 | int len, link_speed = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4431 | static char lpfcinfobuf[384]; |
| 4432 | |
| 4433 | memset(lpfcinfobuf,0,384); |
| 4434 | if (phba && phba->pcidev){ |
| 4435 | strncpy(lpfcinfobuf, phba->ModelDesc, 256); |
| 4436 | len = strlen(lpfcinfobuf); |
| 4437 | snprintf(lpfcinfobuf + len, |
| 4438 | 384-len, |
| 4439 | " on PCI bus %02x device %02x irq %d", |
| 4440 | phba->pcidev->bus->number, |
| 4441 | phba->pcidev->devfn, |
| 4442 | phba->pcidev->irq); |
| 4443 | len = strlen(lpfcinfobuf); |
| 4444 | if (phba->Port[0]) { |
| 4445 | snprintf(lpfcinfobuf + len, |
| 4446 | 384-len, |
| 4447 | " port %s", |
| 4448 | phba->Port); |
| 4449 | } |
James Smart | 65467b6 | 2010-01-26 23:08:29 -0500 | [diff] [blame] | 4450 | len = strlen(lpfcinfobuf); |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 4451 | link_speed = lpfc_sli_port_speed_get(phba); |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4452 | if (link_speed != 0) |
| 4453 | snprintf(lpfcinfobuf + len, 384-len, |
| 4454 | " Logical Link Speed: %d Mbps", link_speed); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4455 | } |
| 4456 | return lpfcinfobuf; |
| 4457 | } |
| 4458 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4459 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4460 | * lpfc_poll_rearm_time - Routine to modify fcp_poll timer of hba |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4461 | * @phba: The Hba for which this call is being executed. |
| 4462 | * |
| 4463 | * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo. |
| 4464 | * The default value of cfg_poll_tmo is 10 milliseconds. |
| 4465 | **/ |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4466 | static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba) |
| 4467 | { |
| 4468 | unsigned long poll_tmo_expires = |
| 4469 | (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo)); |
| 4470 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4471 | 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] | 4472 | mod_timer(&phba->fcp_poll_timer, |
| 4473 | poll_tmo_expires); |
| 4474 | } |
| 4475 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4476 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4477 | * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4478 | * @phba: The Hba for which this call is being executed. |
| 4479 | * |
| 4480 | * This routine starts the fcp_poll_timer of @phba. |
| 4481 | **/ |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4482 | void lpfc_poll_start_timer(struct lpfc_hba * phba) |
| 4483 | { |
| 4484 | lpfc_poll_rearm_timer(phba); |
| 4485 | } |
| 4486 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4487 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4488 | * lpfc_poll_timeout - Restart polling timer |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4489 | * @ptr: Map to lpfc_hba data structure pointer. |
| 4490 | * |
| 4491 | * This routine restarts fcp_poll timer, when FCP ring polling is enable |
| 4492 | * and FCP Ring interrupt is disable. |
| 4493 | **/ |
| 4494 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4495 | void lpfc_poll_timeout(struct timer_list *t) |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4496 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4497 | 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] | 4498 | |
| 4499 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4500 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4501 | &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4502 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4503 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 4504 | lpfc_poll_rearm_timer(phba); |
| 4505 | } |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4506 | } |
| 4507 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4508 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4509 | * lpfc_queuecommand - scsi_host_template queuecommand entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4510 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 4511 | * @done: Pointer to done routine. |
| 4512 | * |
| 4513 | * Driver registers this routine to scsi midlayer to submit a @cmd to process. |
| 4514 | * This routine prepares an IOCB from scsi command and provides to firmware. |
| 4515 | * The @done callback is invoked after driver finished processing the command. |
| 4516 | * |
| 4517 | * Return value : |
| 4518 | * 0 - Success |
| 4519 | * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily. |
| 4520 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4521 | static int |
James Smart | b9a7c63 | 2012-08-03 12:35:24 -0400 | [diff] [blame] | 4522 | lpfc_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4523 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4524 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4525 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 4526 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 4527 | struct lpfc_nodelist *ndlp; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4528 | struct lpfc_scsi_buf *lpfc_cmd; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4529 | 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] | 4530 | int err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4531 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 4532 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4533 | err = fc_remote_port_chkready(rport); |
| 4534 | if (err) { |
| 4535 | cmnd->result = err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4536 | goto out_fail_command; |
| 4537 | } |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 4538 | ndlp = rdata->pnode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4539 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 4540 | if ((scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) && |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4541 | (!(phba->sli3_options & LPFC_SLI3_BG_ENABLED))) { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4542 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4543 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 4544 | "9058 BLKGRD: ERROR: rcvd protected cmd:%02x" |
| 4545 | " op:%02x str=%s without registering for" |
| 4546 | " BlockGuard - Rejecting command\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4547 | cmnd->cmnd[0], scsi_get_prot_op(cmnd), |
| 4548 | dif_op_str[scsi_get_prot_op(cmnd)]); |
| 4549 | goto out_fail_command; |
| 4550 | } |
| 4551 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4552 | /* |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4553 | * Catch race where our node has transitioned, but the |
| 4554 | * transport is still transitioning. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4555 | */ |
James Smart | 6b415f5 | 2012-06-12 13:54:59 -0400 | [diff] [blame] | 4556 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 4557 | goto out_tgt_busy; |
James Smart | 64bf009 | 2018-01-30 15:58:53 -0800 | [diff] [blame] | 4558 | if (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth) { |
| 4559 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_ERROR, |
| 4560 | "3377 Target Queue Full, scsi Id:%d Qdepth:%d" |
| 4561 | " Pending command:%d" |
| 4562 | " WWNN:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x, " |
| 4563 | " WWPN:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", |
| 4564 | ndlp->nlp_sid, ndlp->cmd_qdepth, |
| 4565 | atomic_read(&ndlp->cmd_pending), |
| 4566 | ndlp->nlp_nodename.u.wwn[0], |
| 4567 | ndlp->nlp_nodename.u.wwn[1], |
| 4568 | ndlp->nlp_nodename.u.wwn[2], |
| 4569 | ndlp->nlp_nodename.u.wwn[3], |
| 4570 | ndlp->nlp_nodename.u.wwn[4], |
| 4571 | ndlp->nlp_nodename.u.wwn[5], |
| 4572 | ndlp->nlp_nodename.u.wwn[6], |
| 4573 | ndlp->nlp_nodename.u.wwn[7], |
| 4574 | ndlp->nlp_portname.u.wwn[0], |
| 4575 | ndlp->nlp_portname.u.wwn[1], |
| 4576 | ndlp->nlp_portname.u.wwn[2], |
| 4577 | ndlp->nlp_portname.u.wwn[3], |
| 4578 | ndlp->nlp_portname.u.wwn[4], |
| 4579 | ndlp->nlp_portname.u.wwn[5], |
| 4580 | ndlp->nlp_portname.u.wwn[6], |
| 4581 | ndlp->nlp_portname.u.wwn[7]); |
Mike Christie | 3496343 | 2011-02-25 14:04:28 -0600 | [diff] [blame] | 4582 | goto out_tgt_busy; |
James Smart | 64bf009 | 2018-01-30 15:58:53 -0800 | [diff] [blame] | 4583 | } |
James Smart | f91bc59 | 2018-04-09 14:24:22 -0700 | [diff] [blame^] | 4584 | atomic_inc(&ndlp->cmd_pending); |
| 4585 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4586 | lpfc_cmd = lpfc_get_scsi_buf(phba, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4587 | if (lpfc_cmd == NULL) { |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4588 | lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4589 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4590 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_ERROR, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4591 | "0707 driver's buffer pool is empty, " |
| 4592 | "IO busied\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4593 | goto out_host_busy; |
| 4594 | } |
| 4595 | |
| 4596 | /* |
| 4597 | * Store the midlayer's command structure for the completion phase |
| 4598 | * and complete the command initialization. |
| 4599 | */ |
| 4600 | lpfc_cmd->pCmd = cmnd; |
| 4601 | lpfc_cmd->rdata = rdata; |
| 4602 | lpfc_cmd->timeout = 0; |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4603 | lpfc_cmd->start_time = jiffies; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4604 | cmnd->host_scribble = (unsigned char *)lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4605 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4606 | if (scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4607 | if (vport->phba->cfg_enable_bg) { |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 4608 | lpfc_printf_vlog(vport, |
| 4609 | KERN_INFO, LOG_SCSI_CMD, |
James Smart | 2613470 | 2012-08-14 14:25:50 -0400 | [diff] [blame] | 4610 | "9033 BLKGRD: rcvd %s cmd:x%x " |
| 4611 | "sector x%llx cnt %u pt %x\n", |
| 4612 | dif_op_str[scsi_get_prot_op(cmnd)], |
| 4613 | cmnd->cmnd[0], |
| 4614 | (unsigned long long)scsi_get_lba(cmnd), |
| 4615 | blk_rq_sectors(cmnd->request), |
| 4616 | (cmnd->cmnd[1]>>5)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4617 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4618 | err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 4619 | } else { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4620 | if (vport->phba->cfg_enable_bg) { |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 4621 | lpfc_printf_vlog(vport, |
| 4622 | KERN_INFO, LOG_SCSI_CMD, |
James Smart | 2613470 | 2012-08-14 14:25:50 -0400 | [diff] [blame] | 4623 | "9038 BLKGRD: rcvd PROT_NORMAL cmd: " |
| 4624 | "x%x sector x%llx cnt %u pt %x\n", |
| 4625 | cmnd->cmnd[0], |
| 4626 | (unsigned long long)scsi_get_lba(cmnd), |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 4627 | blk_rq_sectors(cmnd->request), |
James Smart | 2613470 | 2012-08-14 14:25:50 -0400 | [diff] [blame] | 4628 | (cmnd->cmnd[1]>>5)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4629 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4630 | err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 4631 | } |
| 4632 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4633 | if (err) |
| 4634 | goto out_host_busy_free_buf; |
| 4635 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4636 | lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4637 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4638 | err = lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4639 | &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4640 | if (err) { |
James Smart | 76f96b6 | 2013-12-17 20:29:01 -0500 | [diff] [blame] | 4641 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4642 | "3376 FCP could not issue IOCB err %x" |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4643 | "FCP cmd x%x <%d/%llu> " |
James Smart | 76f96b6 | 2013-12-17 20:29:01 -0500 | [diff] [blame] | 4644 | "sid: x%x did: x%x oxid: x%x " |
| 4645 | "Data: x%x x%x x%x x%x\n", |
| 4646 | err, cmnd->cmnd[0], |
| 4647 | cmnd->device ? cmnd->device->id : 0xffff, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4648 | cmnd->device ? cmnd->device->lun : (u64) -1, |
James Smart | 76f96b6 | 2013-12-17 20:29:01 -0500 | [diff] [blame] | 4649 | vport->fc_myDID, ndlp->nlp_DID, |
| 4650 | phba->sli_rev == LPFC_SLI_REV4 ? |
| 4651 | lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff, |
| 4652 | lpfc_cmd->cur_iocbq.iocb.ulpContext, |
| 4653 | lpfc_cmd->cur_iocbq.iocb.ulpIoTag, |
| 4654 | lpfc_cmd->cur_iocbq.iocb.ulpTimeout, |
| 4655 | (uint32_t) |
| 4656 | (cmnd->request->timeout / 1000)); |
| 4657 | |
James Smart | 2cee780 | 2017-06-01 21:07:02 -0700 | [diff] [blame] | 4658 | switch (lpfc_cmd->fcp_cmnd->fcpCntl3) { |
| 4659 | case WRITE_DATA: |
| 4660 | atomic_dec(&phba->fc4ScsiOutputRequests); |
| 4661 | break; |
| 4662 | case READ_DATA: |
| 4663 | atomic_dec(&phba->fc4ScsiInputRequests); |
| 4664 | break; |
| 4665 | default: |
| 4666 | atomic_dec(&phba->fc4ScsiControlRequests); |
| 4667 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4668 | goto out_host_busy_free_buf; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4669 | } |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4670 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4671 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4672 | &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4673 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4674 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 4675 | lpfc_poll_rearm_timer(phba); |
| 4676 | } |
| 4677 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4678 | return 0; |
| 4679 | |
| 4680 | out_host_busy_free_buf: |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 4681 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4682 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4683 | out_host_busy: |
James Smart | f91bc59 | 2018-04-09 14:24:22 -0700 | [diff] [blame^] | 4684 | atomic_dec(&ndlp->cmd_pending); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4685 | return SCSI_MLQUEUE_HOST_BUSY; |
| 4686 | |
Mike Christie | 3496343 | 2011-02-25 14:04:28 -0600 | [diff] [blame] | 4687 | out_tgt_busy: |
| 4688 | return SCSI_MLQUEUE_TARGET_BUSY; |
| 4689 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4690 | out_fail_command: |
James Smart | b9a7c63 | 2012-08-03 12:35:24 -0400 | [diff] [blame] | 4691 | cmnd->scsi_done(cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4692 | return 0; |
| 4693 | } |
| 4694 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 4695 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4696 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4697 | * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4698 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 4699 | * |
| 4700 | * This routine aborts @cmnd pending in base driver. |
| 4701 | * |
| 4702 | * Return code : |
| 4703 | * 0x2003 - Error |
| 4704 | * 0x2002 - Success |
| 4705 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4706 | static int |
James.Smart@Emulex.Com | 63c59c3 | 2005-11-28 11:41:53 -0500 | [diff] [blame] | 4707 | lpfc_abort_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4708 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4709 | struct Scsi_Host *shost = cmnd->device->host; |
| 4710 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4711 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4712 | struct lpfc_iocbq *iocb; |
| 4713 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4714 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4715 | IOCB_t *cmd, *icmd; |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4716 | int ret = SUCCESS, status = 0; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4717 | struct lpfc_sli_ring *pring_s4; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4718 | int ret_val; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4719 | unsigned long flags, iflags; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4720 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4721 | |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4722 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 4723 | if (status != 0 && status != SUCCESS) |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4724 | return status; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4725 | |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4726 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4727 | /* driver queued commands are in process of being flushed */ |
| 4728 | if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) { |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4729 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4730 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4731 | "3168 SCSI Layer abort requested I/O has been " |
| 4732 | "flushed by LLD.\n"); |
| 4733 | return FAILED; |
| 4734 | } |
| 4735 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4736 | lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble; |
James Smart | 92e3af6 | 2012-08-14 14:26:28 -0400 | [diff] [blame] | 4737 | if (!lpfc_cmd || !lpfc_cmd->pCmd) { |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4738 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 4739 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4740 | "2873 SCSI Layer I/O Abort Request IO CMPL Status " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4741 | "x%x ID %d LUN %llu\n", |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4742 | SUCCESS, cmnd->device->id, cmnd->device->lun); |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 4743 | return SUCCESS; |
| 4744 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4745 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4746 | iocb = &lpfc_cmd->cur_iocbq; |
| 4747 | /* the command is in process of being cancelled */ |
| 4748 | if (!(iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ)) { |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4749 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4750 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4751 | "3169 SCSI Layer abort requested I/O has been " |
| 4752 | "cancelled by LLD.\n"); |
| 4753 | return FAILED; |
| 4754 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4755 | /* |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4756 | * If pCmd field of the corresponding lpfc_scsi_buf structure |
| 4757 | * points to a different SCSI command, then the driver has |
| 4758 | * already completed this command, but the midlayer did not |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4759 | * see the completion before the eh fired. Just return SUCCESS. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4760 | */ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4761 | if (lpfc_cmd->pCmd != cmnd) { |
| 4762 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4763 | "3170 SCSI Layer abort requested I/O has been " |
| 4764 | "completed by LLD.\n"); |
| 4765 | goto out_unlock; |
| 4766 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4767 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4768 | BUG_ON(iocb->context1 != lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4769 | |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4770 | /* abort issued in recovery is still in progress */ |
| 4771 | if (iocb->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 4772 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4773 | "3389 SCSI Layer I/O Abort Request is pending\n"); |
| 4774 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4775 | goto wait_for_cmpl; |
| 4776 | } |
| 4777 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4778 | abtsiocb = __lpfc_sli_get_iocbq(phba); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4779 | if (abtsiocb == NULL) { |
| 4780 | ret = FAILED; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4781 | goto out_unlock; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4782 | } |
| 4783 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 4784 | /* Indicate the IO is being aborted by the driver. */ |
| 4785 | iocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 4786 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4787 | /* |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4788 | * The scsi command can not be in txq and it is in flight because the |
| 4789 | * pCmd is still pointig at the SCSI command we have to abort. There |
| 4790 | * is no need to search the txcmplq. Just send an abort to the FW. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4791 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4792 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4793 | cmd = &iocb->iocb; |
| 4794 | icmd = &abtsiocb->iocb; |
| 4795 | icmd->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 4796 | icmd->un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4797 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4798 | icmd->un.acxri.abortIoTag = iocb->sli4_xritag; |
| 4799 | else |
| 4800 | icmd->un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4801 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4802 | icmd->ulpLe = 1; |
| 4803 | icmd->ulpClass = cmd->ulpClass; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4804 | |
| 4805 | /* 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] | 4806 | abtsiocb->hba_wqidx = iocb->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 4807 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 4808 | if (iocb->iocb_flag & LPFC_IO_FOF) |
| 4809 | abtsiocb->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4810 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4811 | if (lpfc_is_link_up(phba)) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4812 | icmd->ulpCommand = CMD_ABORT_XRI_CN; |
| 4813 | else |
| 4814 | icmd->ulpCommand = CMD_CLOSE_XRI_CN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4815 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4816 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4817 | abtsiocb->vport = vport; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4818 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4819 | pring_s4 = lpfc_sli4_calc_ring(phba, iocb); |
| 4820 | if (pring_s4 == NULL) { |
| 4821 | ret = FAILED; |
| 4822 | goto out_unlock; |
| 4823 | } |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4824 | /* Note: both hbalock and ring_lock must be set here */ |
| 4825 | spin_lock_irqsave(&pring_s4->ring_lock, iflags); |
| 4826 | ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 4827 | abtsiocb, 0); |
| 4828 | spin_unlock_irqrestore(&pring_s4->ring_lock, iflags); |
| 4829 | } else { |
| 4830 | ret_val = __lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, |
| 4831 | abtsiocb, 0); |
| 4832 | } |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4833 | /* no longer need the lock after this point */ |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4834 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4835 | |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4836 | |
| 4837 | if (ret_val == IOCB_ERROR) { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4838 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| 4839 | ret = FAILED; |
| 4840 | goto out; |
| 4841 | } |
| 4842 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4843 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4844 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4845 | &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4846 | |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4847 | wait_for_cmpl: |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4848 | lpfc_cmd->waitq = &waitq; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4849 | /* Wait for abort to complete */ |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4850 | wait_event_timeout(waitq, |
| 4851 | (lpfc_cmd->pCmd != cmnd), |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4852 | msecs_to_jiffies(2*vport->cfg_devloss_tmo*1000)); |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4853 | |
| 4854 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4855 | lpfc_cmd->waitq = NULL; |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4856 | spin_unlock_irqrestore(shost->host_lock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4857 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4858 | if (lpfc_cmd->pCmd == cmnd) { |
| 4859 | ret = FAILED; |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4860 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 4861 | "0748 abort handler timed out waiting " |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 4862 | "for aborting I/O (xri:x%x) to complete: " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4863 | "ret %#x, ID %d, LUN %llu\n", |
James Smart | 247ca94 | 2012-08-14 14:26:13 -0400 | [diff] [blame] | 4864 | iocb->sli4_xritag, ret, |
| 4865 | cmnd->device->id, cmnd->device->lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4866 | } |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4867 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4868 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4869 | out_unlock: |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4870 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4871 | out: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4872 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4873 | "0749 SCSI Layer I/O Abort Request Status x%x ID %d " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4874 | "LUN %llu\n", ret, cmnd->device->id, |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 4875 | cmnd->device->lun); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4876 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4877 | } |
| 4878 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4879 | static char * |
| 4880 | lpfc_taskmgmt_name(uint8_t task_mgmt_cmd) |
| 4881 | { |
| 4882 | switch (task_mgmt_cmd) { |
| 4883 | case FCP_ABORT_TASK_SET: |
| 4884 | return "ABORT_TASK_SET"; |
| 4885 | case FCP_CLEAR_TASK_SET: |
| 4886 | return "FCP_CLEAR_TASK_SET"; |
| 4887 | case FCP_BUS_RESET: |
| 4888 | return "FCP_BUS_RESET"; |
| 4889 | case FCP_LUN_RESET: |
| 4890 | return "FCP_LUN_RESET"; |
| 4891 | case FCP_TARGET_RESET: |
| 4892 | return "FCP_TARGET_RESET"; |
| 4893 | case FCP_CLEAR_ACA: |
| 4894 | return "FCP_CLEAR_ACA"; |
| 4895 | case FCP_TERMINATE_TASK: |
| 4896 | return "FCP_TERMINATE_TASK"; |
| 4897 | default: |
| 4898 | return "unknown"; |
| 4899 | } |
| 4900 | } |
| 4901 | |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 4902 | |
| 4903 | /** |
| 4904 | * lpfc_check_fcp_rsp - check the returned fcp_rsp to see if task failed |
| 4905 | * @vport: The virtual port for which this call is being executed. |
| 4906 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. |
| 4907 | * |
| 4908 | * This routine checks the FCP RSP INFO to see if the tsk mgmt command succeded |
| 4909 | * |
| 4910 | * Return code : |
| 4911 | * 0x2003 - Error |
| 4912 | * 0x2002 - Success |
| 4913 | **/ |
| 4914 | static int |
| 4915 | lpfc_check_fcp_rsp(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd) |
| 4916 | { |
| 4917 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
| 4918 | uint32_t rsp_info; |
| 4919 | uint32_t rsp_len; |
| 4920 | uint8_t rsp_info_code; |
| 4921 | int ret = FAILED; |
| 4922 | |
| 4923 | |
| 4924 | if (fcprsp == NULL) |
| 4925 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4926 | "0703 fcp_rsp is missing\n"); |
| 4927 | else { |
| 4928 | rsp_info = fcprsp->rspStatus2; |
| 4929 | rsp_len = be32_to_cpu(fcprsp->rspRspLen); |
| 4930 | rsp_info_code = fcprsp->rspInfo3; |
| 4931 | |
| 4932 | |
| 4933 | lpfc_printf_vlog(vport, KERN_INFO, |
| 4934 | LOG_FCP, |
| 4935 | "0706 fcp_rsp valid 0x%x," |
| 4936 | " rsp len=%d code 0x%x\n", |
| 4937 | rsp_info, |
| 4938 | rsp_len, rsp_info_code); |
| 4939 | |
| 4940 | if ((fcprsp->rspStatus2&RSP_LEN_VALID) && (rsp_len == 8)) { |
| 4941 | switch (rsp_info_code) { |
| 4942 | case RSP_NO_FAILURE: |
| 4943 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4944 | "0715 Task Mgmt No Failure\n"); |
| 4945 | ret = SUCCESS; |
| 4946 | break; |
| 4947 | case RSP_TM_NOT_SUPPORTED: /* TM rejected */ |
| 4948 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4949 | "0716 Task Mgmt Target " |
| 4950 | "reject\n"); |
| 4951 | break; |
| 4952 | case RSP_TM_NOT_COMPLETED: /* TM failed */ |
| 4953 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4954 | "0717 Task Mgmt Target " |
| 4955 | "failed TM\n"); |
| 4956 | break; |
| 4957 | case RSP_TM_INVALID_LU: /* TM to invalid LU! */ |
| 4958 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4959 | "0718 Task Mgmt to invalid " |
| 4960 | "LUN\n"); |
| 4961 | break; |
| 4962 | } |
| 4963 | } |
| 4964 | } |
| 4965 | return ret; |
| 4966 | } |
| 4967 | |
| 4968 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4969 | /** |
| 4970 | * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler |
| 4971 | * @vport: The virtual port for which this call is being executed. |
| 4972 | * @rdata: Pointer to remote port local data |
| 4973 | * @tgt_id: Target ID of remote device. |
| 4974 | * @lun_id: Lun number for the TMF |
| 4975 | * @task_mgmt_cmd: type of TMF to send |
| 4976 | * |
| 4977 | * This routine builds and sends a TMF (SCSI Task Mgmt Function) to |
| 4978 | * a remote port. |
| 4979 | * |
| 4980 | * Return Code: |
| 4981 | * 0x2003 - Error |
| 4982 | * 0x2002 - Success. |
| 4983 | **/ |
| 4984 | static int |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 4985 | lpfc_send_taskmgmt(struct lpfc_vport *vport, struct scsi_cmnd *cmnd, |
| 4986 | unsigned int tgt_id, uint64_t lun_id, |
| 4987 | uint8_t task_mgmt_cmd) |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4988 | { |
| 4989 | struct lpfc_hba *phba = vport->phba; |
| 4990 | struct lpfc_scsi_buf *lpfc_cmd; |
| 4991 | struct lpfc_iocbq *iocbq; |
| 4992 | struct lpfc_iocbq *iocbqrsp; |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 4993 | struct lpfc_rport_data *rdata; |
| 4994 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4995 | int ret; |
| 4996 | int status; |
| 4997 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 4998 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
| 4999 | if (!rdata || !rdata->pnode || !NLP_CHK_NODE_ACT(rdata->pnode)) |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5000 | return FAILED; |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 5001 | pnode = rdata->pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5002 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 5003 | lpfc_cmd = lpfc_get_scsi_buf(phba, pnode); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5004 | if (lpfc_cmd == NULL) |
| 5005 | return FAILED; |
James Smart | 0c41122 | 2013-09-06 12:22:46 -0400 | [diff] [blame] | 5006 | lpfc_cmd->timeout = phba->cfg_task_mgmt_tmo; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5007 | lpfc_cmd->rdata = rdata; |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 5008 | lpfc_cmd->pCmd = cmnd; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5009 | |
| 5010 | status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun_id, |
| 5011 | task_mgmt_cmd); |
| 5012 | if (!status) { |
| 5013 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 5014 | return FAILED; |
| 5015 | } |
| 5016 | |
| 5017 | iocbq = &lpfc_cmd->cur_iocbq; |
| 5018 | iocbqrsp = lpfc_sli_get_iocbq(phba); |
| 5019 | if (iocbqrsp == NULL) { |
| 5020 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 5021 | return FAILED; |
| 5022 | } |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 5023 | iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5024 | |
| 5025 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5026 | "0702 Issue %s to TGT %d LUN %llu " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5027 | "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] | 5028 | lpfc_taskmgmt_name(task_mgmt_cmd), tgt_id, lun_id, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5029 | pnode->nlp_rpi, pnode->nlp_flag, iocbq->sli4_xritag, |
| 5030 | iocbq->iocb_flag); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5031 | |
| 5032 | status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING, |
| 5033 | iocbq, iocbqrsp, lpfc_cmd->timeout); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5034 | if ((status != IOCB_SUCCESS) || |
| 5035 | (iocbqrsp->iocb.ulpStatus != IOSTAT_SUCCESS)) { |
James Smart | ae374a3 | 2015-05-22 10:42:41 -0400 | [diff] [blame] | 5036 | if (status != IOCB_SUCCESS || |
| 5037 | iocbqrsp->iocb.ulpStatus != IOSTAT_FCP_RSP_ERROR) |
| 5038 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5039 | "0727 TMF %s to TGT %d LUN %llu " |
| 5040 | "failed (%d, %d) iocb_flag x%x\n", |
| 5041 | lpfc_taskmgmt_name(task_mgmt_cmd), |
| 5042 | tgt_id, lun_id, |
| 5043 | iocbqrsp->iocb.ulpStatus, |
| 5044 | iocbqrsp->iocb.un.ulpWord[4], |
| 5045 | iocbq->iocb_flag); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5046 | /* if ulpStatus != IOCB_SUCCESS, then status == IOCB_SUCCESS */ |
| 5047 | if (status == IOCB_SUCCESS) { |
| 5048 | if (iocbqrsp->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 5049 | /* Something in the FCP_RSP was invalid. |
| 5050 | * Check conditions */ |
| 5051 | ret = lpfc_check_fcp_rsp(vport, lpfc_cmd); |
| 5052 | else |
| 5053 | ret = FAILED; |
| 5054 | } else if (status == IOCB_TIMEDOUT) { |
| 5055 | ret = TIMEOUT_ERROR; |
| 5056 | } else { |
| 5057 | ret = FAILED; |
| 5058 | } |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5059 | } else |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5060 | ret = SUCCESS; |
| 5061 | |
| 5062 | lpfc_sli_release_iocbq(phba, iocbqrsp); |
| 5063 | |
| 5064 | if (ret != TIMEOUT_ERROR) |
| 5065 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 5066 | |
| 5067 | return ret; |
| 5068 | } |
| 5069 | |
| 5070 | /** |
| 5071 | * lpfc_chk_tgt_mapped - |
| 5072 | * @vport: The virtual port to check on |
| 5073 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5074 | * |
| 5075 | * This routine delays until the scsi target (aka rport) for the |
| 5076 | * command exists (is present and logged in) or we declare it non-existent. |
| 5077 | * |
| 5078 | * Return code : |
| 5079 | * 0x2003 - Error |
| 5080 | * 0x2002 - Success |
| 5081 | **/ |
| 5082 | static int |
| 5083 | lpfc_chk_tgt_mapped(struct lpfc_vport *vport, struct scsi_cmnd *cmnd) |
| 5084 | { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5085 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5086 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5087 | unsigned long later; |
| 5088 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5089 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5090 | if (!rdata) { |
| 5091 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 5092 | "0797 Tgt Map rport failure: rdata x%p\n", rdata); |
| 5093 | return FAILED; |
| 5094 | } |
| 5095 | pnode = rdata->pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5096 | /* |
| 5097 | * If target is not in a MAPPED state, delay until |
| 5098 | * target is rediscovered or devloss timeout expires. |
| 5099 | */ |
| 5100 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; |
| 5101 | while (time_after(later, jiffies)) { |
| 5102 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 5103 | return FAILED; |
| 5104 | if (pnode->nlp_state == NLP_STE_MAPPED_NODE) |
| 5105 | return SUCCESS; |
| 5106 | schedule_timeout_uninterruptible(msecs_to_jiffies(500)); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5107 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5108 | if (!rdata) |
| 5109 | return FAILED; |
| 5110 | pnode = rdata->pnode; |
| 5111 | } |
| 5112 | if (!pnode || !NLP_CHK_NODE_ACT(pnode) || |
| 5113 | (pnode->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5114 | return FAILED; |
| 5115 | return SUCCESS; |
| 5116 | } |
| 5117 | |
| 5118 | /** |
| 5119 | * lpfc_reset_flush_io_context - |
| 5120 | * @vport: The virtual port (scsi_host) for the flush context |
| 5121 | * @tgt_id: If aborting by Target contect - specifies the target id |
| 5122 | * @lun_id: If aborting by Lun context - specifies the lun id |
| 5123 | * @context: specifies the context level to flush at. |
| 5124 | * |
| 5125 | * After a reset condition via TMF, we need to flush orphaned i/o |
| 5126 | * contexts from the adapter. This routine aborts any contexts |
| 5127 | * outstanding, then waits for their completions. The wait is |
| 5128 | * bounded by devloss_tmo though. |
| 5129 | * |
| 5130 | * Return code : |
| 5131 | * 0x2003 - Error |
| 5132 | * 0x2002 - Success |
| 5133 | **/ |
| 5134 | static int |
| 5135 | lpfc_reset_flush_io_context(struct lpfc_vport *vport, uint16_t tgt_id, |
| 5136 | uint64_t lun_id, lpfc_ctx_cmd context) |
| 5137 | { |
| 5138 | struct lpfc_hba *phba = vport->phba; |
| 5139 | unsigned long later; |
| 5140 | int cnt; |
| 5141 | |
| 5142 | cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context); |
| 5143 | if (cnt) |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 5144 | lpfc_sli_abort_taskmgmt(vport, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5145 | &phba->sli.sli3_ring[LPFC_FCP_RING], |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 5146 | tgt_id, lun_id, context); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5147 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; |
| 5148 | while (time_after(later, jiffies) && cnt) { |
| 5149 | schedule_timeout_uninterruptible(msecs_to_jiffies(20)); |
| 5150 | cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context); |
| 5151 | } |
| 5152 | if (cnt) { |
| 5153 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5154 | "0724 I/O flush failure for context %s : cnt x%x\n", |
| 5155 | ((context == LPFC_CTX_LUN) ? "LUN" : |
| 5156 | ((context == LPFC_CTX_TGT) ? "TGT" : |
| 5157 | ((context == LPFC_CTX_HOST) ? "HOST" : "Unknown"))), |
| 5158 | cnt); |
| 5159 | return FAILED; |
| 5160 | } |
| 5161 | return SUCCESS; |
| 5162 | } |
| 5163 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5164 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5165 | * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5166 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5167 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5168 | * 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] | 5169 | * command. |
| 5170 | * |
| 5171 | * Return code : |
| 5172 | * 0x2003 - Error |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5173 | * 0x2002 - Success |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5174 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5175 | static int |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5176 | lpfc_device_reset_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5177 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5178 | struct Scsi_Host *shost = cmnd->device->host; |
| 5179 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5180 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5181 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5182 | unsigned tgt_id = cmnd->device->id; |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5183 | uint64_t lun_id = cmnd->device->lun; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5184 | struct lpfc_scsi_event_header scsi_event; |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5185 | int status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5186 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5187 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | ad490b6 | 2015-04-07 15:07:26 -0400 | [diff] [blame] | 5188 | if (!rdata || !rdata->pnode) { |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5189 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
James Smart | ad490b6 | 2015-04-07 15:07:26 -0400 | [diff] [blame] | 5190 | "0798 Device Reset rport failure: rdata x%p\n", |
| 5191 | rdata); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5192 | return FAILED; |
| 5193 | } |
| 5194 | pnode = rdata->pnode; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5195 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 5196 | if (status != 0 && status != SUCCESS) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5197 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5198 | |
| 5199 | status = lpfc_chk_tgt_mapped(vport, cmnd); |
| 5200 | if (status == FAILED) { |
| 5201 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5202 | "0721 Device Reset rport failure: rdata x%p\n", rdata); |
| 5203 | return FAILED; |
| 5204 | } |
| 5205 | |
| 5206 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 5207 | scsi_event.subcategory = LPFC_EVENT_LUNRESET; |
| 5208 | scsi_event.lun = lun_id; |
| 5209 | memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 5210 | memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 5211 | |
| 5212 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5213 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
| 5214 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 5215 | status = lpfc_send_taskmgmt(vport, cmnd, tgt_id, lun_id, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5216 | FCP_LUN_RESET); |
| 5217 | |
| 5218 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5219 | "0713 SCSI layer issued Device Reset (%d, %llu) " |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5220 | "return x%x\n", tgt_id, lun_id, status); |
| 5221 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5222 | /* |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5223 | * We have to clean up i/o as : they may be orphaned by the TMF; |
| 5224 | * or if the TMF failed, they may be in an indeterminate state. |
| 5225 | * So, continue on. |
| 5226 | * We will report success if all the i/o aborts successfully. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5227 | */ |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5228 | if (status == SUCCESS) |
| 5229 | status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5230 | LPFC_CTX_LUN); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5231 | |
| 5232 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5233 | } |
| 5234 | |
| 5235 | /** |
| 5236 | * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point |
| 5237 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5238 | * |
| 5239 | * This routine does a target reset by sending a TARGET_RESET task management |
| 5240 | * command. |
| 5241 | * |
| 5242 | * Return code : |
| 5243 | * 0x2003 - Error |
| 5244 | * 0x2002 - Success |
| 5245 | **/ |
| 5246 | static int |
| 5247 | lpfc_target_reset_handler(struct scsi_cmnd *cmnd) |
| 5248 | { |
| 5249 | struct Scsi_Host *shost = cmnd->device->host; |
| 5250 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5251 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5252 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5253 | unsigned tgt_id = cmnd->device->id; |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5254 | uint64_t lun_id = cmnd->device->lun; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5255 | struct lpfc_scsi_event_header scsi_event; |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5256 | int status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5257 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5258 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5259 | if (!rdata) { |
| 5260 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5261 | "0799 Target Reset rport failure: rdata x%p\n", rdata); |
| 5262 | return FAILED; |
| 5263 | } |
| 5264 | pnode = rdata->pnode; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5265 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 5266 | if (status != 0 && status != SUCCESS) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5267 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5268 | |
| 5269 | status = lpfc_chk_tgt_mapped(vport, cmnd); |
| 5270 | if (status == FAILED) { |
| 5271 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5272 | "0722 Target Reset rport failure: rdata x%p\n", rdata); |
James Smart | 63e480f | 2015-04-07 15:07:20 -0400 | [diff] [blame] | 5273 | if (pnode) { |
| 5274 | spin_lock_irq(shost->host_lock); |
| 5275 | pnode->nlp_flag &= ~NLP_NPR_ADISC; |
| 5276 | pnode->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; |
| 5277 | spin_unlock_irq(shost->host_lock); |
| 5278 | } |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 5279 | lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
| 5280 | LPFC_CTX_TGT); |
| 5281 | return FAST_IO_FAIL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5282 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5283 | |
| 5284 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 5285 | scsi_event.subcategory = LPFC_EVENT_TGTRESET; |
| 5286 | scsi_event.lun = 0; |
| 5287 | memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 5288 | memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 5289 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5290 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5291 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5292 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 5293 | status = lpfc_send_taskmgmt(vport, cmnd, tgt_id, lun_id, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5294 | FCP_TARGET_RESET); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5295 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5296 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5297 | "0723 SCSI layer issued Target Reset (%d, %llu) " |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5298 | "return x%x\n", tgt_id, lun_id, status); |
| 5299 | |
| 5300 | /* |
| 5301 | * We have to clean up i/o as : they may be orphaned by the TMF; |
| 5302 | * or if the TMF failed, they may be in an indeterminate state. |
| 5303 | * So, continue on. |
| 5304 | * We will report success if all the i/o aborts successfully. |
| 5305 | */ |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5306 | if (status == SUCCESS) |
| 5307 | status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 5308 | LPFC_CTX_TGT); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5309 | return status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5310 | } |
| 5311 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5312 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5313 | * 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] | 5314 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5315 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5316 | * This routine does target reset to all targets on @cmnd->device->host. |
| 5317 | * This emulates Parallel SCSI Bus Reset Semantics. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5318 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5319 | * Return code : |
| 5320 | * 0x2003 - Error |
| 5321 | * 0x2002 - Success |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5322 | **/ |
Jeff Garzik | 94d0e7b8 | 2005-05-28 07:55:48 -0400 | [diff] [blame] | 5323 | static int |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5324 | lpfc_bus_reset_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5325 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5326 | struct Scsi_Host *shost = cmnd->device->host; |
| 5327 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5328 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5329 | struct lpfc_scsi_event_header scsi_event; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5330 | int match; |
| 5331 | int ret = SUCCESS, status, i; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5332 | |
| 5333 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 5334 | scsi_event.subcategory = LPFC_EVENT_BUSRESET; |
| 5335 | scsi_event.lun = 0; |
| 5336 | memcpy(scsi_event.wwpn, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 5337 | memcpy(scsi_event.wwnn, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| 5338 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5339 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5340 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5341 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 5342 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 5343 | if (status != 0 && status != SUCCESS) |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 5344 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5345 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5346 | /* |
| 5347 | * Since the driver manages a single bus device, reset all |
| 5348 | * targets known to the driver. Should any target reset |
| 5349 | * fail, this routine returns failure to the midlayer. |
| 5350 | */ |
James Smart | e17da18 | 2006-07-06 15:49:25 -0400 | [diff] [blame] | 5351 | for (i = 0; i < LPFC_MAX_TARGET; i++) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5352 | /* Search for mapped node by target ID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5353 | match = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5354 | spin_lock_irq(shost->host_lock); |
| 5355 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5356 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5357 | continue; |
James Smart | a6571c6 | 2012-10-31 14:44:42 -0400 | [diff] [blame] | 5358 | if (vport->phba->cfg_fcp2_no_tgt_reset && |
| 5359 | (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE)) |
| 5360 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5361 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE && |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 5362 | ndlp->nlp_sid == i && |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5363 | ndlp->rport && |
| 5364 | ndlp->nlp_type & NLP_FCP_TARGET) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5365 | match = 1; |
| 5366 | break; |
| 5367 | } |
| 5368 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5369 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5370 | if (!match) |
| 5371 | continue; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5372 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 5373 | status = lpfc_send_taskmgmt(vport, cmnd, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5374 | i, 0, FCP_TARGET_RESET); |
| 5375 | |
| 5376 | if (status != SUCCESS) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5377 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5378 | "0700 Bus Reset on target %d failed\n", |
| 5379 | i); |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 5380 | ret = FAILED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5381 | } |
| 5382 | } |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 5383 | /* |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5384 | * We have to clean up i/o as : they may be orphaned by the TMFs |
| 5385 | * above; or if any of the TMFs failed, they may be in an |
| 5386 | * indeterminate state. |
| 5387 | * 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] | 5388 | */ |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5389 | |
| 5390 | status = lpfc_reset_flush_io_context(vport, 0, 0, LPFC_CTX_HOST); |
| 5391 | if (status != SUCCESS) |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 5392 | ret = FAILED; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5393 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5394 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5395 | "0714 SCSI layer issued Bus Reset Data: x%x\n", ret); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5396 | return ret; |
| 5397 | } |
| 5398 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5399 | /** |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5400 | * lpfc_host_reset_handler - scsi_host_template eh_host_reset_handler entry pt |
| 5401 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5402 | * |
| 5403 | * This routine does host reset to the adaptor port. It brings the HBA |
| 5404 | * offline, performs a board restart, and then brings the board back online. |
| 5405 | * The lpfc_offline calls lpfc_sli_hba_down which will abort and local |
| 5406 | * reject all outstanding SCSI commands to the host and error returned |
| 5407 | * back to SCSI mid-level. As this will be SCSI mid-level's last resort |
| 5408 | * of error handling, it will only return error if resetting of the adapter |
| 5409 | * is not successful; in all other cases, will return success. |
| 5410 | * |
| 5411 | * Return code : |
| 5412 | * 0x2003 - Error |
| 5413 | * 0x2002 - Success |
| 5414 | **/ |
| 5415 | static int |
| 5416 | lpfc_host_reset_handler(struct scsi_cmnd *cmnd) |
| 5417 | { |
| 5418 | struct Scsi_Host *shost = cmnd->device->host; |
| 5419 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 5420 | struct lpfc_hba *phba = vport->phba; |
| 5421 | int rc, ret = SUCCESS; |
| 5422 | |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 5423 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5424 | "3172 SCSI layer issued Host Reset Data:\n"); |
| 5425 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 5426 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5427 | lpfc_offline(phba); |
| 5428 | rc = lpfc_sli_brdrestart(phba); |
| 5429 | if (rc) |
| 5430 | ret = FAILED; |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 5431 | rc = lpfc_online(phba); |
| 5432 | if (rc) |
| 5433 | ret = FAILED; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5434 | lpfc_unblock_mgmt_io(phba); |
| 5435 | |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 5436 | if (ret == FAILED) { |
| 5437 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5438 | "3323 Failed host reset, bring it offline\n"); |
| 5439 | lpfc_sli4_offline_eratt(phba); |
| 5440 | } |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5441 | return ret; |
| 5442 | } |
| 5443 | |
| 5444 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5445 | * lpfc_slave_alloc - scsi_host_template slave_alloc entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5446 | * @sdev: Pointer to scsi_device. |
| 5447 | * |
| 5448 | * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's |
| 5449 | * globally available list of scsi buffers. This routine also makes sure scsi |
| 5450 | * buffer is not allocated more than HBA limit conveyed to midlayer. This list |
| 5451 | * of scsi buffer exists for the lifetime of the driver. |
| 5452 | * |
| 5453 | * Return codes: |
| 5454 | * non-0 - Error |
| 5455 | * 0 - Success |
| 5456 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5457 | static int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5458 | lpfc_slave_alloc(struct scsi_device *sdev) |
| 5459 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5460 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 5461 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 5462 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5463 | uint32_t total = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5464 | uint32_t num_to_alloc = 0; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5465 | int num_allocated = 0; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5466 | uint32_t sdev_cnt; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5467 | struct lpfc_device_data *device_data; |
| 5468 | unsigned long flags; |
| 5469 | struct lpfc_name target_wwpn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5470 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 5471 | if (!rport || fc_remote_port_chkready(rport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5472 | return -ENXIO; |
| 5473 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5474 | if (phba->cfg_fof) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5475 | |
| 5476 | /* |
| 5477 | * Check to see if the device data structure for the lun |
| 5478 | * exists. If not, create one. |
| 5479 | */ |
| 5480 | |
| 5481 | u64_to_wwn(rport->port_name, target_wwpn.u.wwn); |
| 5482 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5483 | device_data = __lpfc_get_device_data(phba, |
| 5484 | &phba->luns, |
| 5485 | &vport->fc_portname, |
| 5486 | &target_wwpn, |
| 5487 | sdev->lun); |
| 5488 | if (!device_data) { |
| 5489 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5490 | device_data = lpfc_create_device_data(phba, |
| 5491 | &vport->fc_portname, |
| 5492 | &target_wwpn, |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5493 | sdev->lun, |
| 5494 | phba->cfg_XLanePriority, |
| 5495 | true); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5496 | if (!device_data) |
| 5497 | return -ENOMEM; |
| 5498 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5499 | list_add_tail(&device_data->listentry, &phba->luns); |
| 5500 | } |
| 5501 | device_data->rport_data = rport->dd_data; |
| 5502 | device_data->available = true; |
| 5503 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5504 | sdev->hostdata = device_data; |
| 5505 | } else { |
| 5506 | sdev->hostdata = rport->dd_data; |
| 5507 | } |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5508 | sdev_cnt = atomic_inc_return(&phba->sdev_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5509 | |
| 5510 | /* |
| 5511 | * Populate the cmds_per_lun count scsi_bufs into this host's globally |
| 5512 | * 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] | 5513 | * HBA limit conveyed to the midlayer via the host structure. The |
| 5514 | * formula accounts for the lun_queue_depth + error handlers + 1 |
| 5515 | * extra. This list of scsi bufs exists for the lifetime of the driver. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5516 | */ |
| 5517 | total = phba->total_scsi_bufs; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5518 | num_to_alloc = vport->cfg_lun_queue_depth + 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5519 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5520 | /* If allocated buffers are enough do nothing */ |
| 5521 | if ((sdev_cnt * (vport->cfg_lun_queue_depth + 2)) < total) |
| 5522 | return 0; |
| 5523 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5524 | /* Allow some exchanges to be available always to complete discovery */ |
| 5525 | if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5526 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 5527 | "0704 At limitation of %d preallocated " |
| 5528 | "command buffers\n", total); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5529 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5530 | /* Allow some exchanges to be available always to complete discovery */ |
| 5531 | } else if (total + num_to_alloc > |
| 5532 | phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5533 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 5534 | "0705 Allocation request of %d " |
| 5535 | "command buffers will exceed max of %d. " |
| 5536 | "Reducing allocation request to %d.\n", |
| 5537 | num_to_alloc, phba->cfg_hba_queue_depth, |
| 5538 | (phba->cfg_hba_queue_depth - total)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5539 | num_to_alloc = phba->cfg_hba_queue_depth - total; |
| 5540 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5541 | num_allocated = lpfc_new_scsi_buf(vport, num_to_alloc); |
| 5542 | if (num_to_alloc != num_allocated) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5543 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5544 | "0708 Allocation request of %d " |
| 5545 | "command buffers did not succeed. " |
| 5546 | "Allocated %d buffers.\n", |
| 5547 | num_to_alloc, num_allocated); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5548 | } |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5549 | if (num_allocated > 0) |
| 5550 | phba->total_scsi_bufs += num_allocated; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5551 | return 0; |
| 5552 | } |
| 5553 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5554 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5555 | * lpfc_slave_configure - scsi_host_template slave_configure entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5556 | * @sdev: Pointer to scsi_device. |
| 5557 | * |
| 5558 | * This routine configures following items |
| 5559 | * - Tag command queuing support for @sdev if supported. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5560 | * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set. |
| 5561 | * |
| 5562 | * Return codes: |
| 5563 | * 0 - Success |
| 5564 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5565 | static int |
| 5566 | lpfc_slave_configure(struct scsi_device *sdev) |
| 5567 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5568 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 5569 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5570 | |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 5571 | scsi_change_queue_depth(sdev, vport->cfg_lun_queue_depth); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5572 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5573 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 5574 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5575 | &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5576 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 5577 | lpfc_poll_rearm_timer(phba); |
| 5578 | } |
| 5579 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5580 | return 0; |
| 5581 | } |
| 5582 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5583 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5584 | * lpfc_slave_destroy - slave_destroy entry point of SHT data structure |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5585 | * @sdev: Pointer to scsi_device. |
| 5586 | * |
| 5587 | * This routine sets @sdev hostatdata filed to null. |
| 5588 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5589 | static void |
| 5590 | lpfc_slave_destroy(struct scsi_device *sdev) |
| 5591 | { |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5592 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 5593 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5594 | unsigned long flags; |
| 5595 | struct lpfc_device_data *device_data = sdev->hostdata; |
| 5596 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5597 | atomic_dec(&phba->sdev_cnt); |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5598 | if ((phba->cfg_fof) && (device_data)) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5599 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5600 | device_data->available = false; |
| 5601 | if (!device_data->oas_enabled) |
| 5602 | lpfc_delete_device_data(phba, device_data); |
| 5603 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5604 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5605 | sdev->hostdata = NULL; |
| 5606 | return; |
| 5607 | } |
| 5608 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5609 | /** |
| 5610 | * lpfc_create_device_data - creates and initializes device data structure for OAS |
| 5611 | * @pha: Pointer to host bus adapter structure. |
| 5612 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5613 | * @target_wwpn: Pointer to target's wwpn information |
| 5614 | * @lun: Lun on target |
| 5615 | * @atomic_create: Flag to indicate if memory should be allocated using the |
| 5616 | * GFP_ATOMIC flag or not. |
| 5617 | * |
| 5618 | * This routine creates a device data structure which will contain identifying |
| 5619 | * information for the device (host wwpn, target wwpn, lun), state of OAS, |
| 5620 | * whether or not the corresponding lun is available by the system, |
| 5621 | * and pointer to the rport data. |
| 5622 | * |
| 5623 | * Return codes: |
| 5624 | * NULL - Error |
| 5625 | * Pointer to lpfc_device_data - Success |
| 5626 | **/ |
| 5627 | struct lpfc_device_data* |
| 5628 | lpfc_create_device_data(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn, |
| 5629 | struct lpfc_name *target_wwpn, uint64_t lun, |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5630 | uint32_t pri, bool atomic_create) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5631 | { |
| 5632 | |
| 5633 | struct lpfc_device_data *lun_info; |
| 5634 | int memory_flags; |
| 5635 | |
| 5636 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5637 | !(phba->cfg_fof)) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5638 | return NULL; |
| 5639 | |
| 5640 | /* Attempt to create the device data to contain lun info */ |
| 5641 | |
| 5642 | if (atomic_create) |
| 5643 | memory_flags = GFP_ATOMIC; |
| 5644 | else |
| 5645 | memory_flags = GFP_KERNEL; |
| 5646 | lun_info = mempool_alloc(phba->device_data_mem_pool, memory_flags); |
| 5647 | if (!lun_info) |
| 5648 | return NULL; |
| 5649 | INIT_LIST_HEAD(&lun_info->listentry); |
| 5650 | lun_info->rport_data = NULL; |
| 5651 | memcpy(&lun_info->device_id.vport_wwpn, vport_wwpn, |
| 5652 | sizeof(struct lpfc_name)); |
| 5653 | memcpy(&lun_info->device_id.target_wwpn, target_wwpn, |
| 5654 | sizeof(struct lpfc_name)); |
| 5655 | lun_info->device_id.lun = lun; |
| 5656 | lun_info->oas_enabled = false; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5657 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5658 | lun_info->available = false; |
| 5659 | return lun_info; |
| 5660 | } |
| 5661 | |
| 5662 | /** |
| 5663 | * lpfc_delete_device_data - frees a device data structure for OAS |
| 5664 | * @pha: Pointer to host bus adapter structure. |
| 5665 | * @lun_info: Pointer to device data structure to free. |
| 5666 | * |
| 5667 | * This routine frees the previously allocated device data structure passed. |
| 5668 | * |
| 5669 | **/ |
| 5670 | void |
| 5671 | lpfc_delete_device_data(struct lpfc_hba *phba, |
| 5672 | struct lpfc_device_data *lun_info) |
| 5673 | { |
| 5674 | |
| 5675 | if (unlikely(!phba) || !lun_info || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5676 | !(phba->cfg_fof)) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5677 | return; |
| 5678 | |
| 5679 | if (!list_empty(&lun_info->listentry)) |
| 5680 | list_del(&lun_info->listentry); |
| 5681 | mempool_free(lun_info, phba->device_data_mem_pool); |
| 5682 | return; |
| 5683 | } |
| 5684 | |
| 5685 | /** |
| 5686 | * __lpfc_get_device_data - returns the device data for the specified lun |
| 5687 | * @pha: Pointer to host bus adapter structure. |
| 5688 | * @list: Point to list to search. |
| 5689 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5690 | * @target_wwpn: Pointer to target's wwpn information |
| 5691 | * @lun: Lun on target |
| 5692 | * |
| 5693 | * This routine searches the list passed for the specified lun's device data. |
| 5694 | * This function does not hold locks, it is the responsibility of the caller |
| 5695 | * to ensure the proper lock is held before calling the function. |
| 5696 | * |
| 5697 | * Return codes: |
| 5698 | * NULL - Error |
| 5699 | * Pointer to lpfc_device_data - Success |
| 5700 | **/ |
| 5701 | struct lpfc_device_data* |
| 5702 | __lpfc_get_device_data(struct lpfc_hba *phba, struct list_head *list, |
| 5703 | struct lpfc_name *vport_wwpn, |
| 5704 | struct lpfc_name *target_wwpn, uint64_t lun) |
| 5705 | { |
| 5706 | |
| 5707 | struct lpfc_device_data *lun_info; |
| 5708 | |
| 5709 | if (unlikely(!phba) || !list || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5710 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5711 | return NULL; |
| 5712 | |
| 5713 | /* Check to see if the lun is already enabled for OAS. */ |
| 5714 | |
| 5715 | list_for_each_entry(lun_info, list, listentry) { |
| 5716 | if ((memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn, |
| 5717 | sizeof(struct lpfc_name)) == 0) && |
| 5718 | (memcmp(&lun_info->device_id.target_wwpn, target_wwpn, |
| 5719 | sizeof(struct lpfc_name)) == 0) && |
| 5720 | (lun_info->device_id.lun == lun)) |
| 5721 | return lun_info; |
| 5722 | } |
| 5723 | |
| 5724 | return NULL; |
| 5725 | } |
| 5726 | |
| 5727 | /** |
| 5728 | * lpfc_find_next_oas_lun - searches for the next oas lun |
| 5729 | * @pha: Pointer to host bus adapter structure. |
| 5730 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5731 | * @target_wwpn: Pointer to target's wwpn information |
| 5732 | * @starting_lun: Pointer to the lun to start searching for |
| 5733 | * @found_vport_wwpn: Pointer to the found lun's vport wwpn information |
| 5734 | * @found_target_wwpn: Pointer to the found lun's target wwpn information |
| 5735 | * @found_lun: Pointer to the found lun. |
| 5736 | * @found_lun_status: Pointer to status of the found lun. |
| 5737 | * |
| 5738 | * This routine searches the luns list for the specified lun |
| 5739 | * or the first lun for the vport/target. If the vport wwpn contains |
| 5740 | * a zero value then a specific vport is not specified. In this case |
| 5741 | * any vport which contains the lun will be considered a match. If the |
| 5742 | * target wwpn contains a zero value then a specific target is not specified. |
| 5743 | * In this case any target which contains the lun will be considered a |
| 5744 | * match. If the lun is found, the lun, vport wwpn, target wwpn and lun status |
| 5745 | * are returned. The function will also return the next lun if available. |
| 5746 | * If the next lun is not found, starting_lun parameter will be set to |
| 5747 | * NO_MORE_OAS_LUN. |
| 5748 | * |
| 5749 | * Return codes: |
| 5750 | * non-0 - Error |
| 5751 | * 0 - Success |
| 5752 | **/ |
| 5753 | bool |
| 5754 | lpfc_find_next_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn, |
| 5755 | struct lpfc_name *target_wwpn, uint64_t *starting_lun, |
| 5756 | struct lpfc_name *found_vport_wwpn, |
| 5757 | struct lpfc_name *found_target_wwpn, |
| 5758 | uint64_t *found_lun, |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5759 | uint32_t *found_lun_status, |
| 5760 | uint32_t *found_lun_pri) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5761 | { |
| 5762 | |
| 5763 | unsigned long flags; |
| 5764 | struct lpfc_device_data *lun_info; |
| 5765 | struct lpfc_device_id *device_id; |
| 5766 | uint64_t lun; |
| 5767 | bool found = false; |
| 5768 | |
| 5769 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
| 5770 | !starting_lun || !found_vport_wwpn || |
| 5771 | !found_target_wwpn || !found_lun || !found_lun_status || |
| 5772 | (*starting_lun == NO_MORE_OAS_LUN) || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5773 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5774 | return false; |
| 5775 | |
| 5776 | lun = *starting_lun; |
| 5777 | *found_lun = NO_MORE_OAS_LUN; |
| 5778 | *starting_lun = NO_MORE_OAS_LUN; |
| 5779 | |
| 5780 | /* Search for lun or the lun closet in value */ |
| 5781 | |
| 5782 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5783 | list_for_each_entry(lun_info, &phba->luns, listentry) { |
| 5784 | if (((wwn_to_u64(vport_wwpn->u.wwn) == 0) || |
| 5785 | (memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn, |
| 5786 | sizeof(struct lpfc_name)) == 0)) && |
| 5787 | ((wwn_to_u64(target_wwpn->u.wwn) == 0) || |
| 5788 | (memcmp(&lun_info->device_id.target_wwpn, target_wwpn, |
| 5789 | sizeof(struct lpfc_name)) == 0)) && |
| 5790 | (lun_info->oas_enabled)) { |
| 5791 | device_id = &lun_info->device_id; |
| 5792 | if ((!found) && |
| 5793 | ((lun == FIND_FIRST_OAS_LUN) || |
| 5794 | (device_id->lun == lun))) { |
| 5795 | *found_lun = device_id->lun; |
| 5796 | memcpy(found_vport_wwpn, |
| 5797 | &device_id->vport_wwpn, |
| 5798 | sizeof(struct lpfc_name)); |
| 5799 | memcpy(found_target_wwpn, |
| 5800 | &device_id->target_wwpn, |
| 5801 | sizeof(struct lpfc_name)); |
| 5802 | if (lun_info->available) |
| 5803 | *found_lun_status = |
| 5804 | OAS_LUN_STATUS_EXISTS; |
| 5805 | else |
| 5806 | *found_lun_status = 0; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5807 | *found_lun_pri = lun_info->priority; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5808 | if (phba->cfg_oas_flags & OAS_FIND_ANY_VPORT) |
| 5809 | memset(vport_wwpn, 0x0, |
| 5810 | sizeof(struct lpfc_name)); |
| 5811 | if (phba->cfg_oas_flags & OAS_FIND_ANY_TARGET) |
| 5812 | memset(target_wwpn, 0x0, |
| 5813 | sizeof(struct lpfc_name)); |
| 5814 | found = true; |
| 5815 | } else if (found) { |
| 5816 | *starting_lun = device_id->lun; |
| 5817 | memcpy(vport_wwpn, &device_id->vport_wwpn, |
| 5818 | sizeof(struct lpfc_name)); |
| 5819 | memcpy(target_wwpn, &device_id->target_wwpn, |
| 5820 | sizeof(struct lpfc_name)); |
| 5821 | break; |
| 5822 | } |
| 5823 | } |
| 5824 | } |
| 5825 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5826 | return found; |
| 5827 | } |
| 5828 | |
| 5829 | /** |
| 5830 | * lpfc_enable_oas_lun - enables a lun for OAS operations |
| 5831 | * @pha: Pointer to host bus adapter structure. |
| 5832 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5833 | * @target_wwpn: Pointer to target's wwpn information |
| 5834 | * @lun: Lun |
| 5835 | * |
| 5836 | * This routine enables a lun for oas operations. The routines does so by |
| 5837 | * doing the following : |
| 5838 | * |
| 5839 | * 1) Checks to see if the device data for the lun has been created. |
| 5840 | * 2) If found, sets the OAS enabled flag if not set and returns. |
| 5841 | * 3) Otherwise, creates a device data structure. |
| 5842 | * 4) If successfully created, indicates the device data is for an OAS lun, |
| 5843 | * indicates the lun is not available and add to the list of luns. |
| 5844 | * |
| 5845 | * Return codes: |
| 5846 | * false - Error |
| 5847 | * true - Success |
| 5848 | **/ |
| 5849 | bool |
| 5850 | 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] | 5851 | struct lpfc_name *target_wwpn, uint64_t lun, uint8_t pri) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5852 | { |
| 5853 | |
| 5854 | struct lpfc_device_data *lun_info; |
| 5855 | unsigned long flags; |
| 5856 | |
| 5857 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5858 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5859 | return false; |
| 5860 | |
| 5861 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5862 | |
| 5863 | /* Check to see if the device data for the lun has been created */ |
| 5864 | lun_info = __lpfc_get_device_data(phba, &phba->luns, vport_wwpn, |
| 5865 | target_wwpn, lun); |
| 5866 | if (lun_info) { |
| 5867 | if (!lun_info->oas_enabled) |
| 5868 | lun_info->oas_enabled = true; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5869 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5870 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5871 | return true; |
| 5872 | } |
| 5873 | |
| 5874 | /* Create an lun info structure and add to list of luns */ |
| 5875 | lun_info = lpfc_create_device_data(phba, vport_wwpn, target_wwpn, lun, |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5876 | pri, false); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5877 | if (lun_info) { |
| 5878 | lun_info->oas_enabled = true; |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 5879 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5880 | lun_info->available = false; |
| 5881 | list_add_tail(&lun_info->listentry, &phba->luns); |
| 5882 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5883 | return true; |
| 5884 | } |
| 5885 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5886 | return false; |
| 5887 | } |
| 5888 | |
| 5889 | /** |
| 5890 | * lpfc_disable_oas_lun - disables a lun for OAS operations |
| 5891 | * @pha: Pointer to host bus adapter structure. |
| 5892 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5893 | * @target_wwpn: Pointer to target's wwpn information |
| 5894 | * @lun: Lun |
| 5895 | * |
| 5896 | * This routine disables a lun for oas operations. The routines does so by |
| 5897 | * doing the following : |
| 5898 | * |
| 5899 | * 1) Checks to see if the device data for the lun is created. |
| 5900 | * 2) If present, clears the flag indicating this lun is for OAS. |
| 5901 | * 3) If the lun is not available by the system, the device data is |
| 5902 | * freed. |
| 5903 | * |
| 5904 | * Return codes: |
| 5905 | * false - Error |
| 5906 | * true - Success |
| 5907 | **/ |
| 5908 | bool |
| 5909 | 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] | 5910 | struct lpfc_name *target_wwpn, uint64_t lun, uint8_t pri) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5911 | { |
| 5912 | |
| 5913 | struct lpfc_device_data *lun_info; |
| 5914 | unsigned long flags; |
| 5915 | |
| 5916 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5917 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5918 | return false; |
| 5919 | |
| 5920 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5921 | |
| 5922 | /* Check to see if the lun is available. */ |
| 5923 | lun_info = __lpfc_get_device_data(phba, |
| 5924 | &phba->luns, vport_wwpn, |
| 5925 | target_wwpn, lun); |
| 5926 | if (lun_info) { |
| 5927 | lun_info->oas_enabled = false; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5928 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5929 | if (!lun_info->available) |
| 5930 | lpfc_delete_device_data(phba, lun_info); |
| 5931 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5932 | return true; |
| 5933 | } |
| 5934 | |
| 5935 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5936 | return false; |
| 5937 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5938 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5939 | static int |
| 5940 | lpfc_no_command(struct Scsi_Host *shost, struct scsi_cmnd *cmnd) |
| 5941 | { |
| 5942 | return SCSI_MLQUEUE_HOST_BUSY; |
| 5943 | } |
| 5944 | |
| 5945 | static int |
| 5946 | lpfc_no_handler(struct scsi_cmnd *cmnd) |
| 5947 | { |
| 5948 | return FAILED; |
| 5949 | } |
| 5950 | |
| 5951 | static int |
| 5952 | lpfc_no_slave(struct scsi_device *sdev) |
| 5953 | { |
| 5954 | return -ENODEV; |
| 5955 | } |
| 5956 | |
| 5957 | struct scsi_host_template lpfc_template_nvme = { |
| 5958 | .module = THIS_MODULE, |
| 5959 | .name = LPFC_DRIVER_NAME, |
| 5960 | .proc_name = LPFC_DRIVER_NAME, |
| 5961 | .info = lpfc_info, |
| 5962 | .queuecommand = lpfc_no_command, |
| 5963 | .eh_abort_handler = lpfc_no_handler, |
| 5964 | .eh_device_reset_handler = lpfc_no_handler, |
| 5965 | .eh_target_reset_handler = lpfc_no_handler, |
| 5966 | .eh_bus_reset_handler = lpfc_no_handler, |
| 5967 | .eh_host_reset_handler = lpfc_no_handler, |
| 5968 | .slave_alloc = lpfc_no_slave, |
| 5969 | .slave_configure = lpfc_no_slave, |
| 5970 | .scan_finished = lpfc_scan_finished, |
| 5971 | .this_id = -1, |
| 5972 | .sg_tablesize = 1, |
| 5973 | .cmd_per_lun = 1, |
| 5974 | .use_clustering = ENABLE_CLUSTERING, |
| 5975 | .shost_attrs = lpfc_hba_attrs, |
| 5976 | .max_sectors = 0xFFFF, |
| 5977 | .vendor_id = LPFC_NL_VENDOR_ID, |
| 5978 | .track_queue_depth = 0, |
| 5979 | }; |
| 5980 | |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 5981 | struct scsi_host_template lpfc_template_no_hr = { |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 5982 | .module = THIS_MODULE, |
| 5983 | .name = LPFC_DRIVER_NAME, |
James Smart | 08dcd4c | 2016-07-06 12:35:59 -0700 | [diff] [blame] | 5984 | .proc_name = LPFC_DRIVER_NAME, |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 5985 | .info = lpfc_info, |
| 5986 | .queuecommand = lpfc_queuecommand, |
James Smart | 856984b | 2017-03-04 09:30:32 -0800 | [diff] [blame] | 5987 | .eh_timed_out = fc_eh_timed_out, |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 5988 | .eh_abort_handler = lpfc_abort_handler, |
| 5989 | .eh_device_reset_handler = lpfc_device_reset_handler, |
| 5990 | .eh_target_reset_handler = lpfc_target_reset_handler, |
| 5991 | .eh_bus_reset_handler = lpfc_bus_reset_handler, |
| 5992 | .slave_alloc = lpfc_slave_alloc, |
| 5993 | .slave_configure = lpfc_slave_configure, |
| 5994 | .slave_destroy = lpfc_slave_destroy, |
| 5995 | .scan_finished = lpfc_scan_finished, |
| 5996 | .this_id = -1, |
| 5997 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
| 5998 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
| 5999 | .use_clustering = ENABLE_CLUSTERING, |
| 6000 | .shost_attrs = lpfc_hba_attrs, |
| 6001 | .max_sectors = 0xFFFF, |
| 6002 | .vendor_id = LPFC_NL_VENDOR_ID, |
| 6003 | .change_queue_depth = scsi_change_queue_depth, |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 6004 | .track_queue_depth = 1, |
| 6005 | }; |
| 6006 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6007 | struct scsi_host_template lpfc_template = { |
| 6008 | .module = THIS_MODULE, |
| 6009 | .name = LPFC_DRIVER_NAME, |
James Smart | 08dcd4c | 2016-07-06 12:35:59 -0700 | [diff] [blame] | 6010 | .proc_name = LPFC_DRIVER_NAME, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6011 | .info = lpfc_info, |
| 6012 | .queuecommand = lpfc_queuecommand, |
Christoph Hellwig | b6a05c8 | 2017-01-30 13:18:58 +0100 | [diff] [blame] | 6013 | .eh_timed_out = fc_eh_timed_out, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6014 | .eh_abort_handler = lpfc_abort_handler, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6015 | .eh_device_reset_handler = lpfc_device_reset_handler, |
| 6016 | .eh_target_reset_handler = lpfc_target_reset_handler, |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 6017 | .eh_bus_reset_handler = lpfc_bus_reset_handler, |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 6018 | .eh_host_reset_handler = lpfc_host_reset_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6019 | .slave_alloc = lpfc_slave_alloc, |
| 6020 | .slave_configure = lpfc_slave_configure, |
| 6021 | .slave_destroy = lpfc_slave_destroy, |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 6022 | .scan_finished = lpfc_scan_finished, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6023 | .this_id = -1, |
James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 6024 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6025 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
| 6026 | .use_clustering = ENABLE_CLUSTERING, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6027 | .shost_attrs = lpfc_hba_attrs, |
James.Smart@Emulex.Com | 564b296 | 2005-06-25 10:34:17 -0400 | [diff] [blame] | 6028 | .max_sectors = 0xFFFF, |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 6029 | .vendor_id = LPFC_NL_VENDOR_ID, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 6030 | .change_queue_depth = scsi_change_queue_depth, |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 6031 | .track_queue_depth = 1, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6032 | }; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6033 | |
| 6034 | struct scsi_host_template lpfc_vport_template = { |
| 6035 | .module = THIS_MODULE, |
| 6036 | .name = LPFC_DRIVER_NAME, |
James Smart | 08dcd4c | 2016-07-06 12:35:59 -0700 | [diff] [blame] | 6037 | .proc_name = LPFC_DRIVER_NAME, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6038 | .info = lpfc_info, |
| 6039 | .queuecommand = lpfc_queuecommand, |
Christoph Hellwig | b6a05c8 | 2017-01-30 13:18:58 +0100 | [diff] [blame] | 6040 | .eh_timed_out = fc_eh_timed_out, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6041 | .eh_abort_handler = lpfc_abort_handler, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6042 | .eh_device_reset_handler = lpfc_device_reset_handler, |
| 6043 | .eh_target_reset_handler = lpfc_target_reset_handler, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6044 | .slave_alloc = lpfc_slave_alloc, |
| 6045 | .slave_configure = lpfc_slave_configure, |
| 6046 | .slave_destroy = lpfc_slave_destroy, |
| 6047 | .scan_finished = lpfc_scan_finished, |
| 6048 | .this_id = -1, |
James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 6049 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6050 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
| 6051 | .use_clustering = ENABLE_CLUSTERING, |
| 6052 | .shost_attrs = lpfc_vport_attrs, |
| 6053 | .max_sectors = 0xFFFF, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 6054 | .change_queue_depth = scsi_change_queue_depth, |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 6055 | .track_queue_depth = 1, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6056 | }; |