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