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> |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 29 | #include <linux/crc-t10dif.h> |
| 30 | #include <net/checksum.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 31 | |
| 32 | #include <scsi/scsi.h> |
| 33 | #include <scsi/scsi_device.h> |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 34 | #include <scsi/scsi_eh.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 35 | #include <scsi/scsi_host.h> |
| 36 | #include <scsi/scsi_tcq.h> |
| 37 | #include <scsi/scsi_transport_fc.h> |
| 38 | |
| 39 | #include "lpfc_version.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 40 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 41 | #include "lpfc_hw.h" |
| 42 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 43 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 44 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 45 | #include "lpfc_disc.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 46 | #include "lpfc.h" |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 47 | #include "lpfc_scsi.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 48 | #include "lpfc_logmsg.h" |
| 49 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 50 | #include "lpfc_vport.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 51 | |
| 52 | #define LPFC_RESET_WAIT 2 |
| 53 | #define LPFC_ABORT_WAIT 2 |
| 54 | |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 55 | int _dump_buf_done = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 56 | |
| 57 | static char *dif_op_str[] = { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 58 | "PROT_NORMAL", |
| 59 | "PROT_READ_INSERT", |
| 60 | "PROT_WRITE_STRIP", |
| 61 | "PROT_READ_STRIP", |
| 62 | "PROT_WRITE_INSERT", |
| 63 | "PROT_READ_PASS", |
| 64 | "PROT_WRITE_PASS", |
| 65 | }; |
| 66 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 67 | struct scsi_dif_tuple { |
| 68 | __be16 guard_tag; /* Checksum */ |
| 69 | __be16 app_tag; /* Opaque storage */ |
| 70 | __be32 ref_tag; /* Target LBA or indirect LBA */ |
| 71 | }; |
| 72 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 73 | static struct lpfc_rport_data * |
| 74 | lpfc_rport_data_from_scsi_device(struct scsi_device *sdev) |
| 75 | { |
| 76 | struct lpfc_vport *vport = (struct lpfc_vport *)sdev->host->hostdata; |
| 77 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 78 | if (vport->phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 79 | return ((struct lpfc_device_data *)sdev->hostdata)->rport_data; |
| 80 | else |
| 81 | return (struct lpfc_rport_data *)sdev->hostdata; |
| 82 | } |
| 83 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 84 | static void |
| 85 | 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] | 86 | static void |
| 87 | 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] | 88 | static int |
| 89 | lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 90 | |
| 91 | static void |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 92 | lpfc_debug_save_data(struct lpfc_hba *phba, struct scsi_cmnd *cmnd) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 93 | { |
| 94 | void *src, *dst; |
| 95 | struct scatterlist *sgde = scsi_sglist(cmnd); |
| 96 | |
| 97 | if (!_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 98 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 99 | "9050 BLKGRD: ERROR %s _dump_buf_data is NULL\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 100 | __func__); |
| 101 | return; |
| 102 | } |
| 103 | |
| 104 | |
| 105 | if (!sgde) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 106 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 107 | "9051 BLKGRD: ERROR: data scatterlist is null\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 108 | return; |
| 109 | } |
| 110 | |
| 111 | dst = (void *) _dump_buf_data; |
| 112 | while (sgde) { |
| 113 | src = sg_virt(sgde); |
| 114 | memcpy(dst, src, sgde->length); |
| 115 | dst += sgde->length; |
| 116 | sgde = sg_next(sgde); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | static void |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 121 | lpfc_debug_save_dif(struct lpfc_hba *phba, struct scsi_cmnd *cmnd) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 122 | { |
| 123 | void *src, *dst; |
| 124 | struct scatterlist *sgde = scsi_prot_sglist(cmnd); |
| 125 | |
| 126 | if (!_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 127 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 128 | "9052 BLKGRD: ERROR %s _dump_buf_data is NULL\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 129 | __func__); |
| 130 | return; |
| 131 | } |
| 132 | |
| 133 | if (!sgde) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 134 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 135 | "9053 BLKGRD: ERROR: prot scatterlist is null\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 136 | return; |
| 137 | } |
| 138 | |
| 139 | dst = _dump_buf_dif; |
| 140 | while (sgde) { |
| 141 | src = sg_virt(sgde); |
| 142 | memcpy(dst, src, sgde->length); |
| 143 | dst += sgde->length; |
| 144 | sgde = sg_next(sgde); |
| 145 | } |
| 146 | } |
| 147 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 148 | static inline unsigned |
| 149 | lpfc_cmd_blksize(struct scsi_cmnd *sc) |
| 150 | { |
| 151 | return sc->device->sector_size; |
| 152 | } |
| 153 | |
| 154 | #define LPFC_CHECK_PROTECT_GUARD 1 |
| 155 | #define LPFC_CHECK_PROTECT_REF 2 |
| 156 | static inline unsigned |
| 157 | lpfc_cmd_protect(struct scsi_cmnd *sc, int flag) |
| 158 | { |
| 159 | return 1; |
| 160 | } |
| 161 | |
| 162 | static inline unsigned |
| 163 | lpfc_cmd_guard_csum(struct scsi_cmnd *sc) |
| 164 | { |
| 165 | if (lpfc_prot_group_type(NULL, sc) == LPFC_PG_TYPE_NO_DIF) |
| 166 | return 0; |
| 167 | if (scsi_host_get_guard(sc->device->host) == SHOST_DIX_GUARD_IP) |
| 168 | return 1; |
| 169 | return 0; |
| 170 | } |
| 171 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 172 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 173 | * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge. |
| 174 | * @phba: Pointer to HBA object. |
| 175 | * @lpfc_cmd: lpfc scsi command object pointer. |
| 176 | * |
| 177 | * This function is called from the lpfc_prep_task_mgmt_cmd function to |
| 178 | * set the last bit in the response sge entry. |
| 179 | **/ |
| 180 | static void |
| 181 | lpfc_sli4_set_rsp_sgl_last(struct lpfc_hba *phba, |
| 182 | struct lpfc_scsi_buf *lpfc_cmd) |
| 183 | { |
| 184 | struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 185 | if (sgl) { |
| 186 | sgl += 1; |
| 187 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 188 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 189 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 194 | * lpfc_update_stats - Update statistical data for the command completion |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 195 | * @phba: Pointer to HBA object. |
| 196 | * @lpfc_cmd: lpfc scsi command object pointer. |
| 197 | * |
| 198 | * This function is called when there is a command completion and this |
| 199 | * function updates the statistical data for the command completion. |
| 200 | **/ |
| 201 | static void |
| 202 | lpfc_update_stats(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 203 | { |
| 204 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| 205 | struct lpfc_nodelist *pnode = rdata->pnode; |
| 206 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 207 | unsigned long flags; |
| 208 | struct Scsi_Host *shost = cmd->device->host; |
| 209 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 210 | unsigned long latency; |
| 211 | int i; |
| 212 | |
| 213 | if (cmd->result) |
| 214 | return; |
| 215 | |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 216 | latency = jiffies_to_msecs((long)jiffies - (long)lpfc_cmd->start_time); |
| 217 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 218 | spin_lock_irqsave(shost->host_lock, flags); |
| 219 | if (!vport->stat_data_enabled || |
| 220 | vport->stat_data_blocked || |
James Smart | 5989b8d | 2010-10-22 11:06:56 -0400 | [diff] [blame] | 221 | !pnode || |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 222 | !pnode->lat_data || |
| 223 | (phba->bucket_type == LPFC_NO_BUCKET)) { |
| 224 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 225 | return; |
| 226 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 227 | |
| 228 | if (phba->bucket_type == LPFC_LINEAR_BUCKET) { |
| 229 | i = (latency + phba->bucket_step - 1 - phba->bucket_base)/ |
| 230 | phba->bucket_step; |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 231 | /* check array subscript bounds */ |
| 232 | if (i < 0) |
| 233 | i = 0; |
| 234 | else if (i >= LPFC_MAX_BUCKET_COUNT) |
| 235 | i = LPFC_MAX_BUCKET_COUNT - 1; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 236 | } else { |
| 237 | for (i = 0; i < LPFC_MAX_BUCKET_COUNT-1; i++) |
| 238 | if (latency <= (phba->bucket_base + |
| 239 | ((1<<i)*phba->bucket_step))) |
| 240 | break; |
| 241 | } |
| 242 | |
| 243 | pnode->lat_data[i].cmd_count++; |
| 244 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 245 | } |
| 246 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 247 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 248 | * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 249 | * @phba: The Hba for which this call is being executed. |
| 250 | * |
| 251 | * This routine is called when there is resource error in driver or firmware. |
| 252 | * This routine posts WORKER_RAMP_DOWN_QUEUE event for @phba. This routine |
| 253 | * posts at most 1 event each second. This routine wakes up worker thread of |
| 254 | * @phba to process WORKER_RAM_DOWN_EVENT event. |
| 255 | * |
| 256 | * This routine should be called with no lock held. |
| 257 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 258 | void |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 259 | lpfc_rampdown_queue_depth(struct lpfc_hba *phba) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 260 | { |
| 261 | unsigned long flags; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 262 | uint32_t evt_posted; |
Manuel Schölling | 0d4aec1 | 2014-09-03 12:55:58 -0400 | [diff] [blame] | 263 | unsigned long expires; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 264 | |
| 265 | spin_lock_irqsave(&phba->hbalock, flags); |
| 266 | atomic_inc(&phba->num_rsrc_err); |
| 267 | phba->last_rsrc_error_time = jiffies; |
| 268 | |
Manuel Schölling | 0d4aec1 | 2014-09-03 12:55:58 -0400 | [diff] [blame] | 269 | expires = phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL; |
| 270 | if (time_after(expires, jiffies)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 271 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 272 | return; |
| 273 | } |
| 274 | |
| 275 | phba->last_ramp_down_time = jiffies; |
| 276 | |
| 277 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 278 | |
| 279 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 280 | evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE; |
| 281 | if (!evt_posted) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 282 | phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 283 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
| 284 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 285 | if (!evt_posted) |
| 286 | lpfc_worker_wake_up(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 287 | return; |
| 288 | } |
| 289 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 290 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 291 | * lpfc_ramp_down_queue_handler - WORKER_RAMP_DOWN_QUEUE event handler |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 292 | * @phba: The Hba for which this call is being executed. |
| 293 | * |
| 294 | * This routine is called to process WORKER_RAMP_DOWN_QUEUE event for worker |
| 295 | * thread.This routine reduces queue depth for all scsi device on each vport |
| 296 | * associated with @phba. |
| 297 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 298 | void |
| 299 | lpfc_ramp_down_queue_handler(struct lpfc_hba *phba) |
| 300 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 301 | struct lpfc_vport **vports; |
| 302 | struct Scsi_Host *shost; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 303 | struct scsi_device *sdev; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 304 | unsigned long new_queue_depth; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 305 | unsigned long num_rsrc_err, num_cmd_success; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 306 | int i; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 307 | |
| 308 | num_rsrc_err = atomic_read(&phba->num_rsrc_err); |
| 309 | num_cmd_success = atomic_read(&phba->num_cmd_success); |
| 310 | |
James Smart | 75ad83a | 2012-05-09 21:18:40 -0400 | [diff] [blame] | 311 | /* |
| 312 | * The error and success command counters are global per |
| 313 | * driver instance. If another handler has already |
| 314 | * operated on this error event, just exit. |
| 315 | */ |
| 316 | if (num_rsrc_err == 0) |
| 317 | return; |
| 318 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 319 | vports = lpfc_create_vport_work_array(phba); |
| 320 | if (vports != NULL) |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 321 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 322 | shost = lpfc_shost_from_vport(vports[i]); |
| 323 | shost_for_each_device(sdev, shost) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 324 | new_queue_depth = |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 325 | sdev->queue_depth * num_rsrc_err / |
| 326 | (num_rsrc_err + num_cmd_success); |
| 327 | if (!new_queue_depth) |
| 328 | new_queue_depth = sdev->queue_depth - 1; |
| 329 | else |
| 330 | new_queue_depth = sdev->queue_depth - |
| 331 | new_queue_depth; |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 332 | scsi_change_queue_depth(sdev, new_queue_depth); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 333 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 334 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 335 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 336 | atomic_set(&phba->num_rsrc_err, 0); |
| 337 | atomic_set(&phba->num_cmd_success, 0); |
| 338 | } |
| 339 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 340 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 341 | * lpfc_scsi_dev_block - set all scsi hosts to block state |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 342 | * @phba: Pointer to HBA context object. |
| 343 | * |
| 344 | * This function walks vport list and set each SCSI host to block state |
| 345 | * by invoking fc_remote_port_delete() routine. This function is invoked |
| 346 | * with EEH when device's PCI slot has been permanently disabled. |
| 347 | **/ |
| 348 | void |
| 349 | lpfc_scsi_dev_block(struct lpfc_hba *phba) |
| 350 | { |
| 351 | struct lpfc_vport **vports; |
| 352 | struct Scsi_Host *shost; |
| 353 | struct scsi_device *sdev; |
| 354 | struct fc_rport *rport; |
| 355 | int i; |
| 356 | |
| 357 | vports = lpfc_create_vport_work_array(phba); |
| 358 | if (vports != NULL) |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 359 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 360 | shost = lpfc_shost_from_vport(vports[i]); |
| 361 | shost_for_each_device(sdev, shost) { |
| 362 | rport = starget_to_rport(scsi_target(sdev)); |
| 363 | fc_remote_port_delete(rport); |
| 364 | } |
| 365 | } |
| 366 | lpfc_destroy_vport_work_array(phba, vports); |
| 367 | } |
| 368 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 369 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 370 | * 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] | 371 | * @vport: The virtual port for which this call being executed. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 372 | * @num_to_allocate: The requested number of buffers to allocate. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 373 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 374 | * This routine allocates a scsi buffer for device with SLI-3 interface spec, |
| 375 | * the scsi buffer contains all the necessary information needed to initiate |
| 376 | * a SCSI I/O. The non-DMAable buffer region contains information to build |
| 377 | * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP, |
| 378 | * and the initial BPL. In addition to allocating memory, the FCP CMND and |
| 379 | * 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] | 380 | * |
| 381 | * Return codes: |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 382 | * int - number of scsi buffers that were allocated. |
| 383 | * 0 = failure, less than num_to_alloc is a partial failure. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 384 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 385 | static int |
| 386 | lpfc_new_scsi_buf_s3(struct lpfc_vport *vport, int num_to_alloc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 387 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 388 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 389 | struct lpfc_scsi_buf *psb; |
| 390 | struct ulp_bde64 *bpl; |
| 391 | IOCB_t *iocb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 392 | dma_addr_t pdma_phys_fcp_cmd; |
| 393 | dma_addr_t pdma_phys_fcp_rsp; |
| 394 | dma_addr_t pdma_phys_bpl; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 395 | uint16_t iotag; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 396 | int bcnt, bpl_size; |
| 397 | |
| 398 | bpl_size = phba->cfg_sg_dma_buf_size - |
| 399 | (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); |
| 400 | |
| 401 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 402 | "9067 ALLOC %d scsi_bufs: %d (%d + %d + %d)\n", |
| 403 | num_to_alloc, phba->cfg_sg_dma_buf_size, |
| 404 | (int)sizeof(struct fcp_cmnd), |
| 405 | (int)sizeof(struct fcp_rsp), bpl_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 406 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 407 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
| 408 | psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL); |
| 409 | if (!psb) |
| 410 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 411 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 412 | /* |
| 413 | * Get memory from the pci pool to map the virt space to pci |
| 414 | * bus space for an I/O. The DMA buffer includes space for the |
| 415 | * struct fcp_cmnd, struct fcp_rsp and the number of bde's |
| 416 | * necessary to support the sg_tablesize. |
| 417 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 418 | psb->data = pci_pool_zalloc(phba->lpfc_sg_dma_buf_pool, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 419 | GFP_KERNEL, &psb->dma_handle); |
| 420 | if (!psb->data) { |
| 421 | kfree(psb); |
| 422 | break; |
| 423 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 424 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 425 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 426 | /* Allocate iotag for psb->cur_iocbq. */ |
| 427 | iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq); |
| 428 | if (iotag == 0) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 429 | pci_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 430 | psb->data, psb->dma_handle); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 431 | kfree(psb); |
| 432 | break; |
| 433 | } |
| 434 | psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 435 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 436 | psb->fcp_cmnd = psb->data; |
| 437 | psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd); |
| 438 | psb->fcp_bpl = psb->data + sizeof(struct fcp_cmnd) + |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 439 | sizeof(struct fcp_rsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 440 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 441 | /* Initialize local short-hand pointers. */ |
| 442 | bpl = psb->fcp_bpl; |
| 443 | pdma_phys_fcp_cmd = psb->dma_handle; |
| 444 | pdma_phys_fcp_rsp = psb->dma_handle + sizeof(struct fcp_cmnd); |
| 445 | pdma_phys_bpl = psb->dma_handle + sizeof(struct fcp_cmnd) + |
| 446 | sizeof(struct fcp_rsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 447 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 448 | /* |
| 449 | * The first two bdes are the FCP_CMD and FCP_RSP. The balance |
| 450 | * are sg list bdes. Initialize the first two and leave the |
| 451 | * rest for queuecommand. |
| 452 | */ |
| 453 | bpl[0].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd)); |
| 454 | bpl[0].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd)); |
| 455 | bpl[0].tus.f.bdeSize = sizeof(struct fcp_cmnd); |
| 456 | bpl[0].tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 457 | bpl[0].tus.w = le32_to_cpu(bpl[0].tus.w); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 458 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 459 | /* Setup the physical region for the FCP RSP */ |
| 460 | bpl[1].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp)); |
| 461 | bpl[1].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp)); |
| 462 | bpl[1].tus.f.bdeSize = sizeof(struct fcp_rsp); |
| 463 | bpl[1].tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 464 | bpl[1].tus.w = le32_to_cpu(bpl[1].tus.w); |
| 465 | |
| 466 | /* |
| 467 | * Since the IOCB for the FCP I/O is built into this |
| 468 | * lpfc_scsi_buf, initialize it with all known data now. |
| 469 | */ |
| 470 | iocb = &psb->cur_iocbq.iocb; |
| 471 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; |
| 472 | if ((phba->sli_rev == 3) && |
| 473 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) { |
| 474 | /* fill in immediate fcp command BDE */ |
| 475 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_IMMED; |
| 476 | iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); |
| 477 | iocb->un.fcpi64.bdl.addrLow = offsetof(IOCB_t, |
| 478 | unsli3.fcp_ext.icd); |
| 479 | iocb->un.fcpi64.bdl.addrHigh = 0; |
| 480 | iocb->ulpBdeCount = 0; |
| 481 | iocb->ulpLe = 0; |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 482 | /* fill in response BDE */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 483 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeFlags = |
| 484 | BUFF_TYPE_BDE_64; |
| 485 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeSize = |
| 486 | sizeof(struct fcp_rsp); |
| 487 | iocb->unsli3.fcp_ext.rbde.addrLow = |
| 488 | putPaddrLow(pdma_phys_fcp_rsp); |
| 489 | iocb->unsli3.fcp_ext.rbde.addrHigh = |
| 490 | putPaddrHigh(pdma_phys_fcp_rsp); |
| 491 | } else { |
| 492 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
| 493 | iocb->un.fcpi64.bdl.bdeSize = |
| 494 | (2 * sizeof(struct ulp_bde64)); |
| 495 | iocb->un.fcpi64.bdl.addrLow = |
| 496 | putPaddrLow(pdma_phys_bpl); |
| 497 | iocb->un.fcpi64.bdl.addrHigh = |
| 498 | putPaddrHigh(pdma_phys_bpl); |
| 499 | iocb->ulpBdeCount = 1; |
| 500 | iocb->ulpLe = 1; |
| 501 | } |
| 502 | iocb->ulpClass = CLASS3; |
| 503 | psb->status = IOSTAT_SUCCESS; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 504 | /* Put it back into the SCSI buffer list */ |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 505 | psb->cur_iocbq.context1 = psb; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 506 | lpfc_release_scsi_buf_s3(phba, psb); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 507 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 508 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 509 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 510 | return bcnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 511 | } |
| 512 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 513 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 514 | * lpfc_sli4_vport_delete_fcp_xri_aborted -Remove all ndlp references for vport |
| 515 | * @vport: pointer to lpfc vport data structure. |
| 516 | * |
| 517 | * This routine is invoked by the vport cleanup for deletions and the cleanup |
| 518 | * for an ndlp on removal. |
| 519 | **/ |
| 520 | void |
| 521 | lpfc_sli4_vport_delete_fcp_xri_aborted(struct lpfc_vport *vport) |
| 522 | { |
| 523 | struct lpfc_hba *phba = vport->phba; |
| 524 | struct lpfc_scsi_buf *psb, *next_psb; |
| 525 | unsigned long iflag = 0; |
| 526 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 527 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 528 | return; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 529 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 530 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 531 | list_for_each_entry_safe(psb, next_psb, |
| 532 | &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) { |
| 533 | if (psb->rdata && psb->rdata->pnode |
| 534 | && psb->rdata->pnode->vport == vport) |
| 535 | psb->rdata = NULL; |
| 536 | } |
| 537 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 538 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 539 | } |
| 540 | |
| 541 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 542 | * lpfc_sli4_fcp_xri_aborted - Fast-path process of fcp xri abort |
| 543 | * @phba: pointer to lpfc hba data structure. |
| 544 | * @axri: pointer to the fcp xri abort wcqe structure. |
| 545 | * |
| 546 | * This routine is invoked by the worker thread to process a SLI4 fast-path |
| 547 | * FCP aborted xri. |
| 548 | **/ |
| 549 | void |
| 550 | lpfc_sli4_fcp_xri_aborted(struct lpfc_hba *phba, |
| 551 | struct sli4_wcqe_xri_aborted *axri) |
| 552 | { |
| 553 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 554 | uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 555 | struct lpfc_scsi_buf *psb, *next_psb; |
| 556 | unsigned long iflag = 0; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 557 | struct lpfc_iocbq *iocbq; |
| 558 | int i; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 559 | struct lpfc_nodelist *ndlp; |
| 560 | int rrq_empty = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 561 | struct lpfc_sli_ring *pring = phba->sli4_hba.els_wq->pring; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 562 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 563 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 564 | return; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 565 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 566 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 567 | list_for_each_entry_safe(psb, next_psb, |
| 568 | &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) { |
| 569 | if (psb->cur_iocbq.sli4_xritag == xri) { |
| 570 | list_del(&psb->list); |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 571 | psb->exch_busy = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 572 | psb->status = IOSTAT_SUCCESS; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 573 | spin_unlock( |
| 574 | &phba->sli4_hba.abts_scsi_buf_list_lock); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 575 | if (psb->rdata && psb->rdata->pnode) |
| 576 | ndlp = psb->rdata->pnode; |
| 577 | else |
| 578 | ndlp = NULL; |
| 579 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 580 | rrq_empty = list_empty(&phba->active_rrq_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 581 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 582 | if (ndlp) { |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 583 | lpfc_set_rrq_active(phba, ndlp, |
| 584 | psb->cur_iocbq.sli4_lxritag, rxid, 1); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 585 | lpfc_sli4_abts_err_handler(phba, ndlp, axri); |
| 586 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 587 | lpfc_release_scsi_buf_s4(phba, psb); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 588 | if (rrq_empty) |
| 589 | lpfc_worker_wake_up(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 590 | return; |
| 591 | } |
| 592 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 593 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 594 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 595 | iocbq = phba->sli.iocbq_lookup[i]; |
| 596 | |
| 597 | if (!(iocbq->iocb_flag & LPFC_IO_FCP) || |
| 598 | (iocbq->iocb_flag & LPFC_IO_LIBDFC)) |
| 599 | continue; |
| 600 | if (iocbq->sli4_xritag != xri) |
| 601 | continue; |
| 602 | psb = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
| 603 | psb->exch_busy = 0; |
| 604 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 605 | if (!list_empty(&pring->txq)) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 606 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 607 | return; |
| 608 | |
| 609 | } |
| 610 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | /** |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 614 | * 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] | 615 | * @phba: pointer to lpfc hba data structure. |
| 616 | * @post_sblist: pointer to the scsi buffer list. |
| 617 | * |
| 618 | * This routine walks a list of scsi buffers that was passed in. It attempts |
| 619 | * to construct blocks of scsi buffer sgls which contains contiguous xris and |
| 620 | * uses the non-embedded SGL block post mailbox commands to post to the port. |
| 621 | * For single SCSI buffer sgl with non-contiguous xri, if any, it shall use |
| 622 | * embedded SGL post mailbox command for posting. The @post_sblist passed in |
| 623 | * must be local list, thus no lock is needed when manipulate the list. |
| 624 | * |
| 625 | * Returns: 0 = failure, non-zero number of successfully posted buffers. |
| 626 | **/ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 627 | static int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 628 | lpfc_sli4_post_scsi_sgl_list(struct lpfc_hba *phba, |
| 629 | struct list_head *post_sblist, int sb_count) |
| 630 | { |
| 631 | struct lpfc_scsi_buf *psb, *psb_next; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 632 | int status, sgl_size; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 633 | int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0; |
| 634 | dma_addr_t pdma_phys_bpl1; |
| 635 | int last_xritag = NO_XRI; |
| 636 | LIST_HEAD(prep_sblist); |
| 637 | LIST_HEAD(blck_sblist); |
| 638 | LIST_HEAD(scsi_sblist); |
| 639 | |
| 640 | /* sanity check */ |
| 641 | if (sb_count <= 0) |
| 642 | return -EINVAL; |
| 643 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 644 | sgl_size = phba->cfg_sg_dma_buf_size - |
| 645 | (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); |
| 646 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 647 | list_for_each_entry_safe(psb, psb_next, post_sblist, list) { |
| 648 | list_del_init(&psb->list); |
| 649 | block_cnt++; |
| 650 | if ((last_xritag != NO_XRI) && |
| 651 | (psb->cur_iocbq.sli4_xritag != last_xritag + 1)) { |
| 652 | /* a hole in xri block, form a sgl posting block */ |
| 653 | list_splice_init(&prep_sblist, &blck_sblist); |
| 654 | post_cnt = block_cnt - 1; |
| 655 | /* prepare list for next posting block */ |
| 656 | list_add_tail(&psb->list, &prep_sblist); |
| 657 | block_cnt = 1; |
| 658 | } else { |
| 659 | /* prepare list for next posting block */ |
| 660 | list_add_tail(&psb->list, &prep_sblist); |
| 661 | /* enough sgls for non-embed sgl mbox command */ |
| 662 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 663 | list_splice_init(&prep_sblist, &blck_sblist); |
| 664 | post_cnt = block_cnt; |
| 665 | block_cnt = 0; |
| 666 | } |
| 667 | } |
| 668 | num_posting++; |
| 669 | last_xritag = psb->cur_iocbq.sli4_xritag; |
| 670 | |
| 671 | /* end of repost sgl list condition for SCSI buffers */ |
| 672 | if (num_posting == sb_count) { |
| 673 | if (post_cnt == 0) { |
| 674 | /* last sgl posting block */ |
| 675 | list_splice_init(&prep_sblist, &blck_sblist); |
| 676 | post_cnt = block_cnt; |
| 677 | } else if (block_cnt == 1) { |
| 678 | /* last single sgl with non-contiguous xri */ |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 679 | if (sgl_size > SGL_PAGE_SIZE) |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 680 | pdma_phys_bpl1 = psb->dma_phys_bpl + |
| 681 | SGL_PAGE_SIZE; |
| 682 | else |
| 683 | pdma_phys_bpl1 = 0; |
| 684 | status = lpfc_sli4_post_sgl(phba, |
| 685 | psb->dma_phys_bpl, |
| 686 | pdma_phys_bpl1, |
| 687 | psb->cur_iocbq.sli4_xritag); |
| 688 | if (status) { |
| 689 | /* failure, put on abort scsi list */ |
| 690 | psb->exch_busy = 1; |
| 691 | } else { |
| 692 | /* success, put on SCSI buffer list */ |
| 693 | psb->exch_busy = 0; |
| 694 | psb->status = IOSTAT_SUCCESS; |
| 695 | num_posted++; |
| 696 | } |
| 697 | /* success, put on SCSI buffer sgl list */ |
| 698 | list_add_tail(&psb->list, &scsi_sblist); |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | /* continue until a nembed page worth of sgls */ |
| 703 | if (post_cnt == 0) |
| 704 | continue; |
| 705 | |
| 706 | /* post block of SCSI buffer list sgls */ |
| 707 | status = lpfc_sli4_post_scsi_sgl_block(phba, &blck_sblist, |
| 708 | post_cnt); |
| 709 | |
| 710 | /* don't reset xirtag due to hole in xri block */ |
| 711 | if (block_cnt == 0) |
| 712 | last_xritag = NO_XRI; |
| 713 | |
| 714 | /* reset SCSI buffer post count for next round of posting */ |
| 715 | post_cnt = 0; |
| 716 | |
| 717 | /* put posted SCSI buffer-sgl posted on SCSI buffer sgl list */ |
| 718 | while (!list_empty(&blck_sblist)) { |
| 719 | list_remove_head(&blck_sblist, psb, |
| 720 | struct lpfc_scsi_buf, list); |
| 721 | if (status) { |
| 722 | /* failure, put on abort scsi list */ |
| 723 | psb->exch_busy = 1; |
| 724 | } else { |
| 725 | /* success, put on SCSI buffer list */ |
| 726 | psb->exch_busy = 0; |
| 727 | psb->status = IOSTAT_SUCCESS; |
| 728 | num_posted++; |
| 729 | } |
| 730 | list_add_tail(&psb->list, &scsi_sblist); |
| 731 | } |
| 732 | } |
| 733 | /* Push SCSI buffers with sgl posted to the availble list */ |
| 734 | while (!list_empty(&scsi_sblist)) { |
| 735 | list_remove_head(&scsi_sblist, psb, |
| 736 | struct lpfc_scsi_buf, list); |
| 737 | lpfc_release_scsi_buf_s4(phba, psb); |
| 738 | } |
| 739 | return num_posted; |
| 740 | } |
| 741 | |
| 742 | /** |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 743 | * 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] | 744 | * @phba: pointer to lpfc hba data structure. |
| 745 | * |
| 746 | * 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] | 747 | * 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] | 748 | * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine |
| 749 | * is responsible for moving all scsi buffers on the lpfc_abts_scsi_sgl_list |
| 750 | * to the lpfc_scsi_buf_list. If the repost fails, reject all scsi buffers. |
| 751 | * |
| 752 | * Returns: 0 = success, non-zero failure. |
| 753 | **/ |
| 754 | int |
| 755 | lpfc_sli4_repost_scsi_sgl_list(struct lpfc_hba *phba) |
| 756 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 757 | LIST_HEAD(post_sblist); |
| 758 | int num_posted, rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 759 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 760 | /* get all SCSI buffers need to repost to a local list */ |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 761 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 762 | spin_lock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 763 | list_splice_init(&phba->lpfc_scsi_buf_list_get, &post_sblist); |
| 764 | list_splice(&phba->lpfc_scsi_buf_list_put, &post_sblist); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 765 | spin_unlock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 766 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 767 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 768 | /* post the list of scsi buffer sgls to port if available */ |
| 769 | if (!list_empty(&post_sblist)) { |
| 770 | num_posted = lpfc_sli4_post_scsi_sgl_list(phba, &post_sblist, |
| 771 | phba->sli4_hba.scsi_xri_cnt); |
| 772 | /* failed to post any scsi buffer, return error */ |
| 773 | if (num_posted == 0) |
| 774 | rc = -EIO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 775 | } |
| 776 | return rc; |
| 777 | } |
| 778 | |
| 779 | /** |
| 780 | * lpfc_new_scsi_buf_s4 - Scsi buffer allocator for HBA with SLI4 IF spec |
| 781 | * @vport: The virtual port for which this call being executed. |
| 782 | * @num_to_allocate: The requested number of buffers to allocate. |
| 783 | * |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 784 | * This routine allocates scsi buffers for device with SLI-4 interface spec, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 785 | * the scsi buffer contains all the necessary information needed to initiate |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 786 | * a SCSI I/O. After allocating up to @num_to_allocate SCSI buffers and put |
| 787 | * 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] | 788 | * |
| 789 | * Return codes: |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 790 | * int - number of scsi buffers that were allocated and posted. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 791 | * 0 = failure, less than num_to_alloc is a partial failure. |
| 792 | **/ |
| 793 | static int |
| 794 | lpfc_new_scsi_buf_s4(struct lpfc_vport *vport, int num_to_alloc) |
| 795 | { |
| 796 | struct lpfc_hba *phba = vport->phba; |
| 797 | struct lpfc_scsi_buf *psb; |
| 798 | struct sli4_sge *sgl; |
| 799 | IOCB_t *iocb; |
| 800 | dma_addr_t pdma_phys_fcp_cmd; |
| 801 | dma_addr_t pdma_phys_fcp_rsp; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 802 | dma_addr_t pdma_phys_bpl; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 803 | uint16_t iotag, lxri = 0; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 804 | int bcnt, num_posted, sgl_size; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 805 | LIST_HEAD(prep_sblist); |
| 806 | LIST_HEAD(post_sblist); |
| 807 | LIST_HEAD(scsi_sblist); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 808 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 809 | sgl_size = phba->cfg_sg_dma_buf_size - |
| 810 | (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); |
| 811 | |
| 812 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 813 | "9068 ALLOC %d scsi_bufs: %d (%d + %d + %d)\n", |
| 814 | num_to_alloc, phba->cfg_sg_dma_buf_size, sgl_size, |
| 815 | (int)sizeof(struct fcp_cmnd), |
| 816 | (int)sizeof(struct fcp_rsp)); |
| 817 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 818 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
| 819 | psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL); |
| 820 | if (!psb) |
| 821 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 822 | /* |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 823 | * Get memory from the pci pool to map the virt space to |
| 824 | * pci bus space for an I/O. The DMA buffer includes space |
| 825 | * for the struct fcp_cmnd, struct fcp_rsp and the number |
| 826 | * of bde's necessary to support the sg_tablesize. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 827 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 828 | psb->data = pci_pool_zalloc(phba->lpfc_sg_dma_buf_pool, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 829 | GFP_KERNEL, &psb->dma_handle); |
| 830 | if (!psb->data) { |
| 831 | kfree(psb); |
| 832 | break; |
| 833 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 834 | |
James Smart | 092cb03 | 2013-09-06 12:21:50 -0400 | [diff] [blame] | 835 | /* |
| 836 | * 4K Page alignment is CRITICAL to BlockGuard, double check |
| 837 | * to be sure. |
| 838 | */ |
| 839 | if (phba->cfg_enable_bg && (((unsigned long)(psb->data) & |
| 840 | (unsigned long)(SLI4_PAGE_SIZE - 1)) != 0)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 841 | pci_pool_free(phba->lpfc_sg_dma_buf_pool, |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 842 | psb->data, psb->dma_handle); |
| 843 | kfree(psb); |
| 844 | break; |
| 845 | } |
| 846 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 847 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 848 | lxri = lpfc_sli4_next_xritag(phba); |
| 849 | if (lxri == NO_XRI) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 850 | pci_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 851 | psb->data, psb->dma_handle); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 852 | kfree(psb); |
| 853 | break; |
| 854 | } |
James Smart | f7bc643 | 2013-10-10 12:19:53 -0400 | [diff] [blame] | 855 | |
| 856 | /* Allocate iotag for psb->cur_iocbq. */ |
| 857 | iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq); |
| 858 | if (iotag == 0) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 859 | pci_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 860 | psb->data, psb->dma_handle); |
James Smart | f7bc643 | 2013-10-10 12:19:53 -0400 | [diff] [blame] | 861 | kfree(psb); |
| 862 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 863 | "3368 Failed to allocate IOTAG for" |
James Smart | f7bc643 | 2013-10-10 12:19:53 -0400 | [diff] [blame] | 864 | " XRI:0x%x\n", lxri); |
| 865 | lpfc_sli4_free_xri(phba, lxri); |
| 866 | break; |
| 867 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 868 | psb->cur_iocbq.sli4_lxritag = lxri; |
| 869 | psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 870 | psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 871 | psb->fcp_bpl = psb->data; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 872 | psb->fcp_cmnd = (psb->data + sgl_size); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 873 | psb->fcp_rsp = (struct fcp_rsp *)((uint8_t *)psb->fcp_cmnd + |
| 874 | sizeof(struct fcp_cmnd)); |
| 875 | |
| 876 | /* Initialize local short-hand pointers. */ |
| 877 | sgl = (struct sli4_sge *)psb->fcp_bpl; |
| 878 | pdma_phys_bpl = psb->dma_handle; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 879 | pdma_phys_fcp_cmd = (psb->dma_handle + sgl_size); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 880 | pdma_phys_fcp_rsp = pdma_phys_fcp_cmd + sizeof(struct fcp_cmnd); |
| 881 | |
| 882 | /* |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 883 | * The first two bdes are the FCP_CMD and FCP_RSP. |
| 884 | * The balance are sg list bdes. Initialize the |
| 885 | * first two and leave the rest for queuecommand. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 886 | */ |
| 887 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd)); |
| 888 | sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd)); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 889 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 890 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 891 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 892 | sgl->sge_len = cpu_to_le32(sizeof(struct fcp_cmnd)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 893 | sgl++; |
| 894 | |
| 895 | /* Setup the physical region for the FCP RSP */ |
| 896 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp)); |
| 897 | sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp)); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 898 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 899 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 900 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 901 | sgl->sge_len = cpu_to_le32(sizeof(struct fcp_rsp)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 902 | |
| 903 | /* |
| 904 | * Since the IOCB for the FCP I/O is built into this |
| 905 | * lpfc_scsi_buf, initialize it with all known data now. |
| 906 | */ |
| 907 | iocb = &psb->cur_iocbq.iocb; |
| 908 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; |
| 909 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_64; |
| 910 | /* setting the BLP size to 2 * sizeof BDE may not be correct. |
| 911 | * We are setting the bpl to point to out sgl. An sgl's |
| 912 | * entries are 16 bytes, a bpl entries are 12 bytes. |
| 913 | */ |
| 914 | iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); |
| 915 | iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys_fcp_cmd); |
| 916 | iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys_fcp_cmd); |
| 917 | iocb->ulpBdeCount = 1; |
| 918 | iocb->ulpLe = 1; |
| 919 | iocb->ulpClass = CLASS3; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 920 | psb->cur_iocbq.context1 = psb; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 921 | psb->dma_phys_bpl = pdma_phys_bpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 922 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 923 | /* add the scsi buffer to a post list */ |
| 924 | list_add_tail(&psb->list, &post_sblist); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 925 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 926 | phba->sli4_hba.scsi_xri_cnt++; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 927 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 928 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 929 | lpfc_printf_log(phba, KERN_INFO, LOG_BG | LOG_FCP, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 930 | "3021 Allocate %d out of %d requested new SCSI " |
| 931 | "buffers\n", bcnt, num_to_alloc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 932 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 933 | /* post the list of scsi buffer sgls to port if available */ |
| 934 | if (!list_empty(&post_sblist)) |
| 935 | num_posted = lpfc_sli4_post_scsi_sgl_list(phba, |
| 936 | &post_sblist, bcnt); |
| 937 | else |
| 938 | num_posted = 0; |
| 939 | |
| 940 | return num_posted; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 944 | * lpfc_new_scsi_buf - Wrapper funciton for scsi buffer allocator |
| 945 | * @vport: The virtual port for which this call being executed. |
| 946 | * @num_to_allocate: The requested number of buffers to allocate. |
| 947 | * |
| 948 | * This routine wraps the actual SCSI buffer allocator function pointer from |
| 949 | * the lpfc_hba struct. |
| 950 | * |
| 951 | * Return codes: |
| 952 | * int - number of scsi buffers that were allocated. |
| 953 | * 0 = failure, less than num_to_alloc is a partial failure. |
| 954 | **/ |
| 955 | static inline int |
| 956 | lpfc_new_scsi_buf(struct lpfc_vport *vport, int num_to_alloc) |
| 957 | { |
| 958 | return vport->phba->lpfc_new_scsi_buf(vport, num_to_alloc); |
| 959 | } |
| 960 | |
| 961 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 962 | * 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] | 963 | * @phba: The HBA for which this call is being executed. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 964 | * |
| 965 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list |
| 966 | * and returns to caller. |
| 967 | * |
| 968 | * Return codes: |
| 969 | * NULL - Error |
| 970 | * Pointer to lpfc_scsi_buf - Success |
| 971 | **/ |
Adrian Bunk | 455c53e | 2006-01-06 20:21:28 +0100 | [diff] [blame] | 972 | static struct lpfc_scsi_buf* |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 973 | lpfc_get_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 974 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 975 | struct lpfc_scsi_buf * lpfc_cmd = NULL; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 976 | 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] | 977 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 978 | |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 979 | spin_lock_irqsave(&phba->scsi_buf_list_get_lock, iflag); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 980 | list_remove_head(scsi_buf_list_get, lpfc_cmd, struct lpfc_scsi_buf, |
| 981 | list); |
| 982 | if (!lpfc_cmd) { |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 983 | spin_lock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 984 | list_splice(&phba->lpfc_scsi_buf_list_put, |
| 985 | &phba->lpfc_scsi_buf_list_get); |
| 986 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
| 987 | list_remove_head(scsi_buf_list_get, lpfc_cmd, |
| 988 | struct lpfc_scsi_buf, list); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 989 | spin_unlock(&phba->scsi_buf_list_put_lock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 990 | } |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 991 | spin_unlock_irqrestore(&phba->scsi_buf_list_get_lock, iflag); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 992 | return lpfc_cmd; |
| 993 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 994 | /** |
| 995 | * lpfc_get_scsi_buf_s4 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA |
| 996 | * @phba: The HBA for which this call is being executed. |
| 997 | * |
| 998 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list |
| 999 | * and returns to caller. |
| 1000 | * |
| 1001 | * Return codes: |
| 1002 | * NULL - Error |
| 1003 | * Pointer to lpfc_scsi_buf - Success |
| 1004 | **/ |
| 1005 | static struct lpfc_scsi_buf* |
| 1006 | lpfc_get_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| 1007 | { |
James Smart | 3be30e0 | 2013-05-31 17:05:17 -0400 | [diff] [blame] | 1008 | struct lpfc_scsi_buf *lpfc_cmd, *lpfc_cmd_next; |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 1009 | unsigned long iflag = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1010 | int found = 0; |
| 1011 | |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 1012 | spin_lock_irqsave(&phba->scsi_buf_list_get_lock, iflag); |
James Smart | 3be30e0 | 2013-05-31 17:05:17 -0400 | [diff] [blame] | 1013 | list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next, |
| 1014 | &phba->lpfc_scsi_buf_list_get, list) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1015 | if (lpfc_test_rrq_active(phba, ndlp, |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 1016 | lpfc_cmd->cur_iocbq.sli4_lxritag)) |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1017 | continue; |
| 1018 | list_del(&lpfc_cmd->list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1019 | found = 1; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1020 | break; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1021 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1022 | if (!found) { |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 1023 | spin_lock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1024 | list_splice(&phba->lpfc_scsi_buf_list_put, |
| 1025 | &phba->lpfc_scsi_buf_list_get); |
| 1026 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 1027 | spin_unlock(&phba->scsi_buf_list_put_lock); |
James Smart | 3be30e0 | 2013-05-31 17:05:17 -0400 | [diff] [blame] | 1028 | list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next, |
| 1029 | &phba->lpfc_scsi_buf_list_get, list) { |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1030 | if (lpfc_test_rrq_active( |
| 1031 | phba, ndlp, lpfc_cmd->cur_iocbq.sli4_lxritag)) |
| 1032 | continue; |
| 1033 | list_del(&lpfc_cmd->list); |
| 1034 | found = 1; |
| 1035 | break; |
| 1036 | } |
| 1037 | } |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 1038 | spin_unlock_irqrestore(&phba->scsi_buf_list_get_lock, iflag); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1039 | if (!found) |
| 1040 | return NULL; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1041 | return lpfc_cmd; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1042 | } |
| 1043 | /** |
| 1044 | * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA |
| 1045 | * @phba: The HBA for which this call is being executed. |
| 1046 | * |
| 1047 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list |
| 1048 | * and returns to caller. |
| 1049 | * |
| 1050 | * Return codes: |
| 1051 | * NULL - Error |
| 1052 | * Pointer to lpfc_scsi_buf - Success |
| 1053 | **/ |
| 1054 | static struct lpfc_scsi_buf* |
| 1055 | lpfc_get_scsi_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| 1056 | { |
| 1057 | return phba->lpfc_get_scsi_buf(phba, ndlp); |
| 1058 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1059 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 1060 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1061 | * 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] | 1062 | * @phba: The Hba for which this call is being executed. |
| 1063 | * @psb: The scsi buffer which is being released. |
| 1064 | * |
| 1065 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
| 1066 | * lpfc_scsi_buf_list list. |
| 1067 | **/ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1068 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1069 | 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] | 1070 | { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1071 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1072 | |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1073 | psb->seg_cnt = 0; |
| 1074 | psb->nonsg_phys = 0; |
| 1075 | psb->prot_seg_cnt = 0; |
| 1076 | |
| 1077 | spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1078 | psb->pCmd = NULL; |
James Smart | 6a485eb | 2013-04-17 20:19:00 -0400 | [diff] [blame] | 1079 | psb->cur_iocbq.iocb_flag = LPFC_IO_FCP; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1080 | list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list_put); |
| 1081 | spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1082 | } |
| 1083 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 1084 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1085 | * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list. |
| 1086 | * @phba: The Hba for which this call is being executed. |
| 1087 | * @psb: The scsi buffer which is being released. |
| 1088 | * |
| 1089 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
| 1090 | * lpfc_scsi_buf_list list. For SLI4 XRI's are tied to the scsi buffer |
| 1091 | * and cannot be reused for at least RA_TOV amount of time if it was |
| 1092 | * aborted. |
| 1093 | **/ |
| 1094 | static void |
| 1095 | lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) |
| 1096 | { |
| 1097 | unsigned long iflag = 0; |
| 1098 | |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1099 | psb->seg_cnt = 0; |
| 1100 | psb->nonsg_phys = 0; |
| 1101 | psb->prot_seg_cnt = 0; |
| 1102 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 1103 | if (psb->exch_busy) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1104 | spin_lock_irqsave(&phba->sli4_hba.abts_scsi_buf_list_lock, |
| 1105 | iflag); |
| 1106 | psb->pCmd = NULL; |
| 1107 | list_add_tail(&psb->list, |
| 1108 | &phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 1109 | spin_unlock_irqrestore(&phba->sli4_hba.abts_scsi_buf_list_lock, |
| 1110 | iflag); |
| 1111 | } else { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1112 | psb->pCmd = NULL; |
James Smart | 6a485eb | 2013-04-17 20:19:00 -0400 | [diff] [blame] | 1113 | psb->cur_iocbq.iocb_flag = LPFC_IO_FCP; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1114 | spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag); |
| 1115 | list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list_put); |
| 1116 | spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1117 | } |
| 1118 | } |
| 1119 | |
| 1120 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1121 | * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list. |
| 1122 | * @phba: The Hba for which this call is being executed. |
| 1123 | * @psb: The scsi buffer which is being released. |
| 1124 | * |
| 1125 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
| 1126 | * lpfc_scsi_buf_list list. |
| 1127 | **/ |
| 1128 | static void |
| 1129 | lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) |
| 1130 | { |
| 1131 | |
| 1132 | phba->lpfc_release_scsi_buf(phba, psb); |
| 1133 | } |
| 1134 | |
| 1135 | /** |
| 1136 | * 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] | 1137 | * @phba: The Hba for which this call is being executed. |
| 1138 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 1139 | * |
| 1140 | * 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] | 1141 | * 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] | 1142 | * through sg elements and format the bde. This routine also initializes all |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1143 | * IOCB fields which are dependent on scsi command request buffer. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 1144 | * |
| 1145 | * Return codes: |
| 1146 | * 1 - Error |
| 1147 | * 0 - Success |
| 1148 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1149 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1150 | 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] | 1151 | { |
| 1152 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 1153 | struct scatterlist *sgel = NULL; |
| 1154 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 1155 | struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1156 | struct lpfc_iocbq *iocbq = &lpfc_cmd->cur_iocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1157 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1158 | struct ulp_bde64 *data_bde = iocb_cmd->unsli3.fcp_ext.dbde; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1159 | dma_addr_t physaddr; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1160 | uint32_t num_bde = 0; |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1161 | int nseg, datadir = scsi_cmnd->sc_data_direction; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1162 | |
| 1163 | /* |
| 1164 | * There are three possibilities here - use scatter-gather segment, use |
| 1165 | * the single mapping, or neither. Start the lpfc command prep by |
| 1166 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 1167 | * data bde entry. |
| 1168 | */ |
| 1169 | bpl += 2; |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 1170 | if (scsi_sg_count(scsi_cmnd)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1171 | /* |
| 1172 | * The driver stores the segment count returned from pci_map_sg |
| 1173 | * because this a count of dma-mappings used to map the use_sg |
| 1174 | * pages. They are not guaranteed to be the same for those |
| 1175 | * architectures that implement an IOMMU. |
| 1176 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1177 | |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 1178 | nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd), |
| 1179 | scsi_sg_count(scsi_cmnd), datadir); |
| 1180 | if (unlikely(!nseg)) |
| 1181 | return 1; |
| 1182 | |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1183 | lpfc_cmd->seg_cnt = nseg; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1184 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1185 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1186 | "9064 BLKGRD: %s: Too many sg segments from " |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1187 | "dma_map_sg. Config %d, seg_cnt %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1188 | __func__, phba->cfg_sg_seg_cnt, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1189 | lpfc_cmd->seg_cnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 1190 | lpfc_cmd->seg_cnt = 0; |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1191 | scsi_dma_unmap(scsi_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1192 | return 1; |
| 1193 | } |
| 1194 | |
| 1195 | /* |
| 1196 | * The driver established a maximum scatter-gather segment count |
| 1197 | * during probe that limits the number of sg elements in any |
| 1198 | * single scsi command. Just run through the seg_cnt and format |
| 1199 | * the bde's. |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1200 | * When using SLI-3 the driver will try to fit all the BDEs into |
| 1201 | * the IOCB. If it can't then the BDEs get added to a BPL as it |
| 1202 | * does for SLI-2 mode. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1203 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1204 | scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1205 | physaddr = sg_dma_address(sgel); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1206 | if (phba->sli_rev == 3 && |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1207 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1208 | !(iocbq->iocb_flag & DSS_SECURITY_OP) && |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1209 | nseg <= LPFC_EXT_DATA_BDE_COUNT) { |
| 1210 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1211 | data_bde->tus.f.bdeSize = sg_dma_len(sgel); |
| 1212 | data_bde->addrLow = putPaddrLow(physaddr); |
| 1213 | data_bde->addrHigh = putPaddrHigh(physaddr); |
| 1214 | data_bde++; |
| 1215 | } else { |
| 1216 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1217 | bpl->tus.f.bdeSize = sg_dma_len(sgel); |
| 1218 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 1219 | bpl->addrLow = |
| 1220 | le32_to_cpu(putPaddrLow(physaddr)); |
| 1221 | bpl->addrHigh = |
| 1222 | le32_to_cpu(putPaddrHigh(physaddr)); |
| 1223 | bpl++; |
| 1224 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1225 | } |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 1226 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1227 | |
| 1228 | /* |
| 1229 | * Finish initializing those IOCB fields that are dependent on the |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1230 | * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is |
| 1231 | * explicitly reinitialized and for SLI-3 the extended bde count is |
| 1232 | * explicitly reinitialized since all iocb memory resources are reused. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1233 | */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1234 | if (phba->sli_rev == 3 && |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1235 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
| 1236 | !(iocbq->iocb_flag & DSS_SECURITY_OP)) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1237 | if (num_bde > LPFC_EXT_DATA_BDE_COUNT) { |
| 1238 | /* |
| 1239 | * The extended IOCB format can only fit 3 BDE or a BPL. |
| 1240 | * This I/O has more than 3 BDE so the 1st data bde will |
| 1241 | * be a BPL that is filled in here. |
| 1242 | */ |
| 1243 | physaddr = lpfc_cmd->dma_handle; |
| 1244 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BLP_64; |
| 1245 | data_bde->tus.f.bdeSize = (num_bde * |
| 1246 | sizeof(struct ulp_bde64)); |
| 1247 | physaddr += (sizeof(struct fcp_cmnd) + |
| 1248 | sizeof(struct fcp_rsp) + |
| 1249 | (2 * sizeof(struct ulp_bde64))); |
| 1250 | data_bde->addrHigh = putPaddrHigh(physaddr); |
| 1251 | data_bde->addrLow = putPaddrLow(physaddr); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1252 | /* ebde count includes the response bde and data bpl */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1253 | iocb_cmd->unsli3.fcp_ext.ebde_count = 2; |
| 1254 | } else { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1255 | /* ebde count includes the response bde and data bdes */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1256 | iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); |
| 1257 | } |
| 1258 | } else { |
| 1259 | iocb_cmd->un.fcpi64.bdl.bdeSize = |
| 1260 | ((num_bde + 2) * sizeof(struct ulp_bde64)); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1261 | iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1262 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1263 | fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1264 | |
| 1265 | /* |
| 1266 | * Due to difference in data length between DIF/non-DIF paths, |
| 1267 | * we need to set word 4 of IOCB here |
| 1268 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1269 | iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1270 | return 0; |
| 1271 | } |
| 1272 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1273 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1274 | |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1275 | /* Return BG_ERR_INIT if error injection is detected by Initiator */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1276 | #define BG_ERR_INIT 0x1 |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1277 | /* Return BG_ERR_TGT if error injection is detected by Target */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1278 | #define BG_ERR_TGT 0x2 |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1279 | /* 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] | 1280 | #define BG_ERR_SWAP 0x10 |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1281 | /** |
| 1282 | * Return BG_ERR_CHECK if disabling Guard/Ref/App checking is required for |
| 1283 | * error injection |
| 1284 | **/ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1285 | #define BG_ERR_CHECK 0x20 |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1286 | |
| 1287 | /** |
| 1288 | * lpfc_bg_err_inject - Determine if we should inject an error |
| 1289 | * @phba: The Hba for which this call is being executed. |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1290 | * @sc: The SCSI command to examine |
| 1291 | * @reftag: (out) BlockGuard reference tag for transmitted data |
| 1292 | * @apptag: (out) BlockGuard application tag for transmitted data |
| 1293 | * @new_guard (in) Value to replace CRC with if needed |
| 1294 | * |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1295 | * Returns BG_ERR_* bit mask or 0 if request ignored |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1296 | **/ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1297 | static int |
| 1298 | lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1299 | uint32_t *reftag, uint16_t *apptag, uint32_t new_guard) |
| 1300 | { |
| 1301 | struct scatterlist *sgpe; /* s/g prot entry */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1302 | struct lpfc_scsi_buf *lpfc_cmd = NULL; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1303 | struct scsi_dif_tuple *src = NULL; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1304 | struct lpfc_nodelist *ndlp; |
| 1305 | struct lpfc_rport_data *rdata; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1306 | uint32_t op = scsi_get_prot_op(sc); |
| 1307 | uint32_t blksize; |
| 1308 | uint32_t numblks; |
| 1309 | sector_t lba; |
| 1310 | int rc = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1311 | int blockoff = 0; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1312 | |
| 1313 | if (op == SCSI_PROT_NORMAL) |
| 1314 | return 0; |
| 1315 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1316 | sgpe = scsi_prot_sglist(sc); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1317 | lba = scsi_get_lba(sc); |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1318 | |
| 1319 | /* First check if we need to match the LBA */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1320 | if (phba->lpfc_injerr_lba != LPFC_INJERR_LBA_OFF) { |
| 1321 | blksize = lpfc_cmd_blksize(sc); |
| 1322 | numblks = (scsi_bufflen(sc) + blksize - 1) / blksize; |
| 1323 | |
| 1324 | /* Make sure we have the right LBA if one is specified */ |
| 1325 | if ((phba->lpfc_injerr_lba < lba) || |
| 1326 | (phba->lpfc_injerr_lba >= (lba + numblks))) |
| 1327 | return 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1328 | if (sgpe) { |
| 1329 | blockoff = phba->lpfc_injerr_lba - lba; |
| 1330 | numblks = sg_dma_len(sgpe) / |
| 1331 | sizeof(struct scsi_dif_tuple); |
| 1332 | if (numblks < blockoff) |
| 1333 | blockoff = numblks; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1334 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1335 | } |
| 1336 | |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1337 | /* Next check if we need to match the remote NPortID or WWPN */ |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 1338 | rdata = lpfc_rport_data_from_scsi_device(sc->device); |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1339 | if (rdata && rdata->pnode) { |
| 1340 | ndlp = rdata->pnode; |
| 1341 | |
| 1342 | /* Make sure we have the right NPortID if one is specified */ |
| 1343 | if (phba->lpfc_injerr_nportid && |
| 1344 | (phba->lpfc_injerr_nportid != ndlp->nlp_DID)) |
| 1345 | return 0; |
| 1346 | |
| 1347 | /* |
| 1348 | * Make sure we have the right WWPN if one is specified. |
| 1349 | * wwn[0] should be a non-zero NAA in a good WWPN. |
| 1350 | */ |
| 1351 | if (phba->lpfc_injerr_wwpn.u.wwn[0] && |
| 1352 | (memcmp(&ndlp->nlp_portname, &phba->lpfc_injerr_wwpn, |
| 1353 | sizeof(struct lpfc_name)) != 0)) |
| 1354 | return 0; |
| 1355 | } |
| 1356 | |
| 1357 | /* Setup a ptr to the protection data if the SCSI host provides it */ |
| 1358 | if (sgpe) { |
| 1359 | src = (struct scsi_dif_tuple *)sg_virt(sgpe); |
| 1360 | src += blockoff; |
| 1361 | lpfc_cmd = (struct lpfc_scsi_buf *)sc->host_scribble; |
| 1362 | } |
| 1363 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1364 | /* Should we change the Reference Tag */ |
| 1365 | if (reftag) { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1366 | if (phba->lpfc_injerr_wref_cnt) { |
| 1367 | switch (op) { |
| 1368 | case SCSI_PROT_WRITE_PASS: |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1369 | if (src) { |
| 1370 | /* |
| 1371 | * For WRITE_PASS, force the error |
| 1372 | * to be sent on the wire. It should |
| 1373 | * be detected by the Target. |
| 1374 | * If blockoff != 0 error will be |
| 1375 | * inserted in middle of the IO. |
| 1376 | */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1377 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1378 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1379 | "9076 BLKGRD: Injecting reftag error: " |
| 1380 | "write lba x%lx + x%x oldrefTag x%x\n", |
| 1381 | (unsigned long)lba, blockoff, |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1382 | be32_to_cpu(src->ref_tag)); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1383 | |
| 1384 | /* |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1385 | * Save the old ref_tag so we can |
| 1386 | * restore it on completion. |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1387 | */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1388 | if (lpfc_cmd) { |
| 1389 | lpfc_cmd->prot_data_type = |
| 1390 | LPFC_INJERR_REFTAG; |
| 1391 | lpfc_cmd->prot_data_segment = |
| 1392 | src; |
| 1393 | lpfc_cmd->prot_data = |
| 1394 | src->ref_tag; |
| 1395 | } |
| 1396 | src->ref_tag = cpu_to_be32(0xDEADBEEF); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1397 | phba->lpfc_injerr_wref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1398 | if (phba->lpfc_injerr_wref_cnt == 0) { |
| 1399 | phba->lpfc_injerr_nportid = 0; |
| 1400 | phba->lpfc_injerr_lba = |
| 1401 | LPFC_INJERR_LBA_OFF; |
| 1402 | memset(&phba->lpfc_injerr_wwpn, |
| 1403 | 0, sizeof(struct lpfc_name)); |
| 1404 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1405 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
| 1406 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1407 | break; |
| 1408 | } |
| 1409 | /* Drop thru */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1410 | case SCSI_PROT_WRITE_INSERT: |
| 1411 | /* |
| 1412 | * For WRITE_INSERT, force the error |
| 1413 | * to be sent on the wire. It should be |
| 1414 | * detected by the Target. |
| 1415 | */ |
| 1416 | /* DEADBEEF will be the reftag on the wire */ |
| 1417 | *reftag = 0xDEADBEEF; |
| 1418 | phba->lpfc_injerr_wref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1419 | if (phba->lpfc_injerr_wref_cnt == 0) { |
| 1420 | phba->lpfc_injerr_nportid = 0; |
| 1421 | phba->lpfc_injerr_lba = |
| 1422 | LPFC_INJERR_LBA_OFF; |
| 1423 | memset(&phba->lpfc_injerr_wwpn, |
| 1424 | 0, sizeof(struct lpfc_name)); |
| 1425 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1426 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
| 1427 | |
| 1428 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1429 | "9078 BLKGRD: Injecting reftag error: " |
| 1430 | "write lba x%lx\n", (unsigned long)lba); |
| 1431 | break; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1432 | case SCSI_PROT_WRITE_STRIP: |
| 1433 | /* |
| 1434 | * For WRITE_STRIP and WRITE_PASS, |
| 1435 | * force the error on data |
| 1436 | * being copied from SLI-Host to SLI-Port. |
| 1437 | */ |
| 1438 | *reftag = 0xDEADBEEF; |
| 1439 | phba->lpfc_injerr_wref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1440 | if (phba->lpfc_injerr_wref_cnt == 0) { |
| 1441 | phba->lpfc_injerr_nportid = 0; |
| 1442 | phba->lpfc_injerr_lba = |
| 1443 | LPFC_INJERR_LBA_OFF; |
| 1444 | memset(&phba->lpfc_injerr_wwpn, |
| 1445 | 0, sizeof(struct lpfc_name)); |
| 1446 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1447 | rc = BG_ERR_INIT; |
| 1448 | |
| 1449 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1450 | "9077 BLKGRD: Injecting reftag error: " |
| 1451 | "write lba x%lx\n", (unsigned long)lba); |
| 1452 | break; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1453 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1454 | } |
| 1455 | if (phba->lpfc_injerr_rref_cnt) { |
| 1456 | switch (op) { |
| 1457 | case SCSI_PROT_READ_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1458 | case SCSI_PROT_READ_STRIP: |
| 1459 | case SCSI_PROT_READ_PASS: |
| 1460 | /* |
| 1461 | * For READ_STRIP and READ_PASS, force the |
| 1462 | * error on data being read off the wire. It |
| 1463 | * should force an IO error to the driver. |
| 1464 | */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1465 | *reftag = 0xDEADBEEF; |
| 1466 | phba->lpfc_injerr_rref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1467 | if (phba->lpfc_injerr_rref_cnt == 0) { |
| 1468 | phba->lpfc_injerr_nportid = 0; |
| 1469 | phba->lpfc_injerr_lba = |
| 1470 | LPFC_INJERR_LBA_OFF; |
| 1471 | memset(&phba->lpfc_injerr_wwpn, |
| 1472 | 0, sizeof(struct lpfc_name)); |
| 1473 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1474 | rc = BG_ERR_INIT; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1475 | |
| 1476 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1477 | "9079 BLKGRD: Injecting reftag error: " |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1478 | "read lba x%lx\n", (unsigned long)lba); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1479 | break; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1480 | } |
| 1481 | } |
| 1482 | } |
| 1483 | |
| 1484 | /* Should we change the Application Tag */ |
| 1485 | if (apptag) { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1486 | if (phba->lpfc_injerr_wapp_cnt) { |
| 1487 | switch (op) { |
| 1488 | case SCSI_PROT_WRITE_PASS: |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1489 | if (src) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1490 | /* |
| 1491 | * For WRITE_PASS, force the error |
| 1492 | * to be sent on the wire. It should |
| 1493 | * be detected by the Target. |
| 1494 | * If blockoff != 0 error will be |
| 1495 | * inserted in middle of the IO. |
| 1496 | */ |
| 1497 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1498 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1499 | "9080 BLKGRD: Injecting apptag error: " |
| 1500 | "write lba x%lx + x%x oldappTag x%x\n", |
| 1501 | (unsigned long)lba, blockoff, |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1502 | be16_to_cpu(src->app_tag)); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1503 | |
| 1504 | /* |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1505 | * Save the old app_tag so we can |
| 1506 | * restore it on completion. |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1507 | */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1508 | if (lpfc_cmd) { |
| 1509 | lpfc_cmd->prot_data_type = |
| 1510 | LPFC_INJERR_APPTAG; |
| 1511 | lpfc_cmd->prot_data_segment = |
| 1512 | src; |
| 1513 | lpfc_cmd->prot_data = |
| 1514 | src->app_tag; |
| 1515 | } |
| 1516 | src->app_tag = cpu_to_be16(0xDEAD); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1517 | phba->lpfc_injerr_wapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1518 | if (phba->lpfc_injerr_wapp_cnt == 0) { |
| 1519 | phba->lpfc_injerr_nportid = 0; |
| 1520 | phba->lpfc_injerr_lba = |
| 1521 | LPFC_INJERR_LBA_OFF; |
| 1522 | memset(&phba->lpfc_injerr_wwpn, |
| 1523 | 0, sizeof(struct lpfc_name)); |
| 1524 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1525 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1526 | break; |
| 1527 | } |
| 1528 | /* Drop thru */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1529 | case SCSI_PROT_WRITE_INSERT: |
| 1530 | /* |
| 1531 | * For WRITE_INSERT, force the |
| 1532 | * error to be sent on the wire. It should be |
| 1533 | * detected by the Target. |
| 1534 | */ |
| 1535 | /* DEAD will be the apptag on the wire */ |
| 1536 | *apptag = 0xDEAD; |
| 1537 | phba->lpfc_injerr_wapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1538 | if (phba->lpfc_injerr_wapp_cnt == 0) { |
| 1539 | phba->lpfc_injerr_nportid = 0; |
| 1540 | phba->lpfc_injerr_lba = |
| 1541 | LPFC_INJERR_LBA_OFF; |
| 1542 | memset(&phba->lpfc_injerr_wwpn, |
| 1543 | 0, sizeof(struct lpfc_name)); |
| 1544 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1545 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
| 1546 | |
| 1547 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1548 | "0813 BLKGRD: Injecting apptag error: " |
| 1549 | "write lba x%lx\n", (unsigned long)lba); |
| 1550 | break; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1551 | case SCSI_PROT_WRITE_STRIP: |
| 1552 | /* |
| 1553 | * For WRITE_STRIP and WRITE_PASS, |
| 1554 | * force the error on data |
| 1555 | * being copied from SLI-Host to SLI-Port. |
| 1556 | */ |
| 1557 | *apptag = 0xDEAD; |
| 1558 | phba->lpfc_injerr_wapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1559 | if (phba->lpfc_injerr_wapp_cnt == 0) { |
| 1560 | phba->lpfc_injerr_nportid = 0; |
| 1561 | phba->lpfc_injerr_lba = |
| 1562 | LPFC_INJERR_LBA_OFF; |
| 1563 | memset(&phba->lpfc_injerr_wwpn, |
| 1564 | 0, sizeof(struct lpfc_name)); |
| 1565 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1566 | rc = BG_ERR_INIT; |
| 1567 | |
| 1568 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1569 | "0812 BLKGRD: Injecting apptag error: " |
| 1570 | "write lba x%lx\n", (unsigned long)lba); |
| 1571 | break; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1572 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1573 | } |
| 1574 | if (phba->lpfc_injerr_rapp_cnt) { |
| 1575 | switch (op) { |
| 1576 | case SCSI_PROT_READ_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1577 | case SCSI_PROT_READ_STRIP: |
| 1578 | case SCSI_PROT_READ_PASS: |
| 1579 | /* |
| 1580 | * For READ_STRIP and READ_PASS, force the |
| 1581 | * error on data being read off the wire. It |
| 1582 | * should force an IO error to the driver. |
| 1583 | */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1584 | *apptag = 0xDEAD; |
| 1585 | phba->lpfc_injerr_rapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1586 | if (phba->lpfc_injerr_rapp_cnt == 0) { |
| 1587 | phba->lpfc_injerr_nportid = 0; |
| 1588 | phba->lpfc_injerr_lba = |
| 1589 | LPFC_INJERR_LBA_OFF; |
| 1590 | memset(&phba->lpfc_injerr_wwpn, |
| 1591 | 0, sizeof(struct lpfc_name)); |
| 1592 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1593 | rc = BG_ERR_INIT; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1594 | |
| 1595 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1596 | "0814 BLKGRD: Injecting apptag error: " |
| 1597 | "read lba x%lx\n", (unsigned long)lba); |
| 1598 | break; |
| 1599 | } |
| 1600 | } |
| 1601 | } |
| 1602 | |
| 1603 | |
| 1604 | /* Should we change the Guard Tag */ |
| 1605 | if (new_guard) { |
| 1606 | if (phba->lpfc_injerr_wgrd_cnt) { |
| 1607 | switch (op) { |
| 1608 | case SCSI_PROT_WRITE_PASS: |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1609 | rc = BG_ERR_CHECK; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1610 | /* Drop thru */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1611 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1612 | case SCSI_PROT_WRITE_INSERT: |
| 1613 | /* |
| 1614 | * For WRITE_INSERT, force the |
| 1615 | * error to be sent on the wire. It should be |
| 1616 | * detected by the Target. |
| 1617 | */ |
| 1618 | phba->lpfc_injerr_wgrd_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1619 | if (phba->lpfc_injerr_wgrd_cnt == 0) { |
| 1620 | phba->lpfc_injerr_nportid = 0; |
| 1621 | phba->lpfc_injerr_lba = |
| 1622 | LPFC_INJERR_LBA_OFF; |
| 1623 | memset(&phba->lpfc_injerr_wwpn, |
| 1624 | 0, sizeof(struct lpfc_name)); |
| 1625 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1626 | |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1627 | rc |= BG_ERR_TGT | BG_ERR_SWAP; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1628 | /* Signals the caller to swap CRC->CSUM */ |
| 1629 | |
| 1630 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1631 | "0817 BLKGRD: Injecting guard error: " |
| 1632 | "write lba x%lx\n", (unsigned long)lba); |
| 1633 | break; |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1634 | case SCSI_PROT_WRITE_STRIP: |
| 1635 | /* |
| 1636 | * For WRITE_STRIP and WRITE_PASS, |
| 1637 | * force the error on data |
| 1638 | * being copied from SLI-Host to SLI-Port. |
| 1639 | */ |
| 1640 | phba->lpfc_injerr_wgrd_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1641 | if (phba->lpfc_injerr_wgrd_cnt == 0) { |
| 1642 | phba->lpfc_injerr_nportid = 0; |
| 1643 | phba->lpfc_injerr_lba = |
| 1644 | LPFC_INJERR_LBA_OFF; |
| 1645 | memset(&phba->lpfc_injerr_wwpn, |
| 1646 | 0, sizeof(struct lpfc_name)); |
| 1647 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1648 | |
| 1649 | rc = BG_ERR_INIT | BG_ERR_SWAP; |
| 1650 | /* Signals the caller to swap CRC->CSUM */ |
| 1651 | |
| 1652 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1653 | "0816 BLKGRD: Injecting guard error: " |
| 1654 | "write lba x%lx\n", (unsigned long)lba); |
| 1655 | break; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1656 | } |
| 1657 | } |
| 1658 | if (phba->lpfc_injerr_rgrd_cnt) { |
| 1659 | switch (op) { |
| 1660 | case SCSI_PROT_READ_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1661 | case SCSI_PROT_READ_STRIP: |
| 1662 | case SCSI_PROT_READ_PASS: |
| 1663 | /* |
| 1664 | * For READ_STRIP and READ_PASS, force the |
| 1665 | * error on data being read off the wire. It |
| 1666 | * should force an IO error to the driver. |
| 1667 | */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1668 | phba->lpfc_injerr_rgrd_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1669 | if (phba->lpfc_injerr_rgrd_cnt == 0) { |
| 1670 | phba->lpfc_injerr_nportid = 0; |
| 1671 | phba->lpfc_injerr_lba = |
| 1672 | LPFC_INJERR_LBA_OFF; |
| 1673 | memset(&phba->lpfc_injerr_wwpn, |
| 1674 | 0, sizeof(struct lpfc_name)); |
| 1675 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1676 | |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1677 | rc = BG_ERR_INIT | BG_ERR_SWAP; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1678 | /* Signals the caller to swap CRC->CSUM */ |
| 1679 | |
| 1680 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1681 | "0818 BLKGRD: Injecting guard error: " |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1682 | "read lba x%lx\n", (unsigned long)lba); |
| 1683 | } |
| 1684 | } |
| 1685 | } |
| 1686 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1687 | return rc; |
| 1688 | } |
| 1689 | #endif |
| 1690 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1691 | /** |
| 1692 | * lpfc_sc_to_bg_opcodes - Determine the BlockGuard opcodes to be used with |
| 1693 | * the specified SCSI command. |
| 1694 | * @phba: The Hba for which this call is being executed. |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1695 | * @sc: The SCSI command to examine |
| 1696 | * @txopt: (out) BlockGuard operation for transmitted data |
| 1697 | * @rxopt: (out) BlockGuard operation for received data |
| 1698 | * |
| 1699 | * Returns: zero on success; non-zero if tx and/or rx op cannot be determined |
| 1700 | * |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1701 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1702 | static int |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1703 | lpfc_sc_to_bg_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1704 | uint8_t *txop, uint8_t *rxop) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1705 | { |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1706 | uint8_t ret = 0; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1707 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1708 | if (lpfc_cmd_guard_csum(sc)) { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1709 | switch (scsi_get_prot_op(sc)) { |
| 1710 | case SCSI_PROT_READ_INSERT: |
| 1711 | case SCSI_PROT_WRITE_STRIP: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1712 | *rxop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1713 | *txop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1714 | break; |
| 1715 | |
| 1716 | case SCSI_PROT_READ_STRIP: |
| 1717 | case SCSI_PROT_WRITE_INSERT: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1718 | *rxop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1719 | *txop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1720 | break; |
| 1721 | |
Martin K. Petersen | c6af404 | 2009-09-18 17:32:59 -0400 | [diff] [blame] | 1722 | case SCSI_PROT_READ_PASS: |
| 1723 | case SCSI_PROT_WRITE_PASS: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1724 | *rxop = BG_OP_IN_CRC_OUT_CSUM; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1725 | *txop = BG_OP_IN_CSUM_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1726 | break; |
| 1727 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1728 | case SCSI_PROT_NORMAL: |
| 1729 | default: |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1730 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1731 | "9063 BLKGRD: Bad op/guard:%d/IP combination\n", |
| 1732 | scsi_get_prot_op(sc)); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1733 | ret = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1734 | break; |
| 1735 | |
| 1736 | } |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1737 | } else { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1738 | switch (scsi_get_prot_op(sc)) { |
| 1739 | case SCSI_PROT_READ_STRIP: |
| 1740 | case SCSI_PROT_WRITE_INSERT: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1741 | *rxop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1742 | *txop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1743 | break; |
| 1744 | |
| 1745 | case SCSI_PROT_READ_PASS: |
| 1746 | case SCSI_PROT_WRITE_PASS: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1747 | *rxop = BG_OP_IN_CRC_OUT_CRC; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1748 | *txop = BG_OP_IN_CRC_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1749 | break; |
| 1750 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1751 | case SCSI_PROT_READ_INSERT: |
| 1752 | case SCSI_PROT_WRITE_STRIP: |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1753 | *rxop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1754 | *txop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1755 | break; |
| 1756 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1757 | case SCSI_PROT_NORMAL: |
| 1758 | default: |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1759 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1760 | "9075 BLKGRD: Bad op/guard:%d/CRC combination\n", |
| 1761 | scsi_get_prot_op(sc)); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1762 | ret = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1763 | break; |
| 1764 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1765 | } |
| 1766 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1767 | return ret; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1768 | } |
| 1769 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1770 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 1771 | /** |
| 1772 | * lpfc_bg_err_opcodes - reDetermine the BlockGuard opcodes to be used with |
| 1773 | * the specified SCSI command in order to force a guard tag error. |
| 1774 | * @phba: The Hba for which this call is being executed. |
| 1775 | * @sc: The SCSI command to examine |
| 1776 | * @txopt: (out) BlockGuard operation for transmitted data |
| 1777 | * @rxopt: (out) BlockGuard operation for received data |
| 1778 | * |
| 1779 | * Returns: zero on success; non-zero if tx and/or rx op cannot be determined |
| 1780 | * |
| 1781 | **/ |
| 1782 | static int |
| 1783 | lpfc_bg_err_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1784 | uint8_t *txop, uint8_t *rxop) |
| 1785 | { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1786 | uint8_t ret = 0; |
| 1787 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1788 | if (lpfc_cmd_guard_csum(sc)) { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1789 | switch (scsi_get_prot_op(sc)) { |
| 1790 | case SCSI_PROT_READ_INSERT: |
| 1791 | case SCSI_PROT_WRITE_STRIP: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1792 | *rxop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1793 | *txop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1794 | break; |
| 1795 | |
| 1796 | case SCSI_PROT_READ_STRIP: |
| 1797 | case SCSI_PROT_WRITE_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1798 | *rxop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1799 | *txop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1800 | break; |
| 1801 | |
| 1802 | case SCSI_PROT_READ_PASS: |
| 1803 | case SCSI_PROT_WRITE_PASS: |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1804 | *rxop = BG_OP_IN_CSUM_OUT_CRC; |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1805 | *txop = BG_OP_IN_CRC_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1806 | break; |
| 1807 | |
| 1808 | case SCSI_PROT_NORMAL: |
| 1809 | default: |
| 1810 | break; |
| 1811 | |
| 1812 | } |
| 1813 | } else { |
| 1814 | switch (scsi_get_prot_op(sc)) { |
| 1815 | case SCSI_PROT_READ_STRIP: |
| 1816 | case SCSI_PROT_WRITE_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1817 | *rxop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1818 | *txop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1819 | break; |
| 1820 | |
| 1821 | case SCSI_PROT_READ_PASS: |
| 1822 | case SCSI_PROT_WRITE_PASS: |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1823 | *rxop = BG_OP_IN_CSUM_OUT_CSUM; |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1824 | *txop = BG_OP_IN_CSUM_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1825 | break; |
| 1826 | |
| 1827 | case SCSI_PROT_READ_INSERT: |
| 1828 | case SCSI_PROT_WRITE_STRIP: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1829 | *rxop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1830 | *txop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1831 | break; |
| 1832 | |
| 1833 | case SCSI_PROT_NORMAL: |
| 1834 | default: |
| 1835 | break; |
| 1836 | } |
| 1837 | } |
| 1838 | |
| 1839 | return ret; |
| 1840 | } |
| 1841 | #endif |
| 1842 | |
| 1843 | /** |
| 1844 | * lpfc_bg_setup_bpl - Setup BlockGuard BPL with no protection data |
| 1845 | * @phba: The Hba for which this call is being executed. |
| 1846 | * @sc: pointer to scsi command we're working on |
| 1847 | * @bpl: pointer to buffer list for protection groups |
| 1848 | * @datacnt: number of segments of data that have been dma mapped |
| 1849 | * |
| 1850 | * This function sets up BPL buffer list for protection groups of |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1851 | * type LPFC_PG_TYPE_NO_DIF |
| 1852 | * |
| 1853 | * This is usually used when the HBA is instructed to generate |
| 1854 | * DIFs and insert them into data stream (or strip DIF from |
| 1855 | * incoming data stream) |
| 1856 | * |
| 1857 | * The buffer list consists of just one protection group described |
| 1858 | * below: |
| 1859 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1860 | * start of prot group --> | PDE_5 | |
| 1861 | * +-------------------------+ |
| 1862 | * | PDE_6 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1863 | * +-------------------------+ |
| 1864 | * | Data BDE | |
| 1865 | * +-------------------------+ |
| 1866 | * |more Data BDE's ... (opt)| |
| 1867 | * +-------------------------+ |
| 1868 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1869 | * |
| 1870 | * Note: Data s/g buffers have been dma mapped |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1871 | * |
| 1872 | * Returns the number of BDEs added to the BPL. |
| 1873 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1874 | static int |
| 1875 | lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1876 | struct ulp_bde64 *bpl, int datasegcnt) |
| 1877 | { |
| 1878 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1879 | struct lpfc_pde5 *pde5 = NULL; |
| 1880 | struct lpfc_pde6 *pde6 = NULL; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1881 | dma_addr_t physaddr; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1882 | int i = 0, num_bde = 0, status; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1883 | int datadir = sc->sc_data_direction; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 1884 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1885 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 1886 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1887 | uint32_t checking = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1888 | uint32_t reftag; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1889 | uint8_t txop, rxop; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1890 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1891 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 1892 | if (status) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1893 | goto out; |
| 1894 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1895 | /* extract some info from the scsi command for pde*/ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1896 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1897 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1898 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1899 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1900 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1901 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1902 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1903 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1904 | checking = 0; |
| 1905 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1906 | #endif |
| 1907 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1908 | /* setup PDE5 with what we have */ |
| 1909 | pde5 = (struct lpfc_pde5 *) bpl; |
| 1910 | memset(pde5, 0, sizeof(struct lpfc_pde5)); |
| 1911 | bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1912 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1913 | /* Endianness conversion if necessary for PDE5 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1914 | pde5->word0 = cpu_to_le32(pde5->word0); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1915 | pde5->reftag = cpu_to_le32(reftag); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1916 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1917 | /* advance bpl and increment bde count */ |
| 1918 | num_bde++; |
| 1919 | bpl++; |
| 1920 | pde6 = (struct lpfc_pde6 *) bpl; |
| 1921 | |
| 1922 | /* setup PDE6 with the rest of the info */ |
| 1923 | memset(pde6, 0, sizeof(struct lpfc_pde6)); |
| 1924 | bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR); |
| 1925 | bf_set(pde6_optx, pde6, txop); |
| 1926 | bf_set(pde6_oprx, pde6, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1927 | |
| 1928 | /* |
| 1929 | * We only need to check the data on READs, for WRITEs |
| 1930 | * protection data is automatically generated, not checked. |
| 1931 | */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1932 | if (datadir == DMA_FROM_DEVICE) { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1933 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1934 | bf_set(pde6_ce, pde6, checking); |
| 1935 | else |
| 1936 | bf_set(pde6_ce, pde6, 0); |
| 1937 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1938 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1939 | bf_set(pde6_re, pde6, checking); |
| 1940 | else |
| 1941 | bf_set(pde6_re, pde6, 0); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1942 | } |
| 1943 | bf_set(pde6_ai, pde6, 1); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1944 | bf_set(pde6_ae, pde6, 0); |
| 1945 | bf_set(pde6_apptagval, pde6, 0); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1946 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1947 | /* Endianness conversion if necessary for PDE6 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1948 | pde6->word0 = cpu_to_le32(pde6->word0); |
| 1949 | pde6->word1 = cpu_to_le32(pde6->word1); |
| 1950 | pde6->word2 = cpu_to_le32(pde6->word2); |
| 1951 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1952 | /* advance bpl and increment bde count */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1953 | num_bde++; |
| 1954 | bpl++; |
| 1955 | |
| 1956 | /* assumption: caller has already run dma_map_sg on command data */ |
| 1957 | scsi_for_each_sg(sc, sgde, datasegcnt, i) { |
| 1958 | physaddr = sg_dma_address(sgde); |
| 1959 | bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
| 1960 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 1961 | bpl->tus.f.bdeSize = sg_dma_len(sgde); |
| 1962 | if (datadir == DMA_TO_DEVICE) |
| 1963 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1964 | else |
| 1965 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
| 1966 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 1967 | bpl++; |
| 1968 | num_bde++; |
| 1969 | } |
| 1970 | |
| 1971 | out: |
| 1972 | return num_bde; |
| 1973 | } |
| 1974 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1975 | /** |
| 1976 | * lpfc_bg_setup_bpl_prot - Setup BlockGuard BPL with protection data |
| 1977 | * @phba: The Hba for which this call is being executed. |
| 1978 | * @sc: pointer to scsi command we're working on |
| 1979 | * @bpl: pointer to buffer list for protection groups |
| 1980 | * @datacnt: number of segments of data that have been dma mapped |
| 1981 | * @protcnt: number of segment of protection data that have been dma mapped |
| 1982 | * |
| 1983 | * This function sets up BPL buffer list for protection groups of |
| 1984 | * type LPFC_PG_TYPE_DIF |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1985 | * |
| 1986 | * This is usually used when DIFs are in their own buffers, |
| 1987 | * separate from the data. The HBA can then by instructed |
| 1988 | * to place the DIFs in the outgoing stream. For read operations, |
| 1989 | * The HBA could extract the DIFs and place it in DIF buffers. |
| 1990 | * |
| 1991 | * The buffer list for this type consists of one or more of the |
| 1992 | * protection groups described below: |
| 1993 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1994 | * start of first prot group --> | PDE_5 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1995 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1996 | * | PDE_6 | |
| 1997 | * +-------------------------+ |
| 1998 | * | PDE_7 (Prot BDE) | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1999 | * +-------------------------+ |
| 2000 | * | Data BDE | |
| 2001 | * +-------------------------+ |
| 2002 | * |more Data BDE's ... (opt)| |
| 2003 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2004 | * start of new prot group --> | PDE_5 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2005 | * +-------------------------+ |
| 2006 | * | ... | |
| 2007 | * +-------------------------+ |
| 2008 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2009 | * Note: It is assumed that both data and protection s/g buffers have been |
| 2010 | * mapped for DMA |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2011 | * |
| 2012 | * Returns the number of BDEs added to the BPL. |
| 2013 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2014 | static int |
| 2015 | lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 2016 | struct ulp_bde64 *bpl, int datacnt, int protcnt) |
| 2017 | { |
| 2018 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 2019 | struct scatterlist *sgpe = NULL; /* s/g prot entry */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2020 | struct lpfc_pde5 *pde5 = NULL; |
| 2021 | struct lpfc_pde6 *pde6 = NULL; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2022 | struct lpfc_pde7 *pde7 = NULL; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2023 | dma_addr_t dataphysaddr, protphysaddr; |
| 2024 | unsigned short curr_data = 0, curr_prot = 0; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2025 | unsigned int split_offset; |
| 2026 | unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2027 | unsigned int protgrp_blks, protgrp_bytes; |
| 2028 | unsigned int remainder, subtotal; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2029 | int status; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2030 | int datadir = sc->sc_data_direction; |
| 2031 | unsigned char pgdone = 0, alldone = 0; |
| 2032 | unsigned blksize; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2033 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2034 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2035 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2036 | uint32_t checking = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2037 | uint32_t reftag; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2038 | uint8_t txop, rxop; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2039 | int num_bde = 0; |
| 2040 | |
| 2041 | sgpe = scsi_prot_sglist(sc); |
| 2042 | sgde = scsi_sglist(sc); |
| 2043 | |
| 2044 | if (!sgpe || !sgde) { |
| 2045 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2046 | "9020 Invalid s/g entry: data=0x%p prot=0x%p\n", |
| 2047 | sgpe, sgde); |
| 2048 | return 0; |
| 2049 | } |
| 2050 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2051 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 2052 | if (status) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2053 | goto out; |
| 2054 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2055 | /* extract some info from the scsi command */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2056 | blksize = lpfc_cmd_blksize(sc); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2057 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2058 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 2059 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 2060 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2061 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2062 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2063 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2064 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2065 | checking = 0; |
| 2066 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 2067 | #endif |
| 2068 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2069 | split_offset = 0; |
| 2070 | do { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2071 | /* Check to see if we ran out of space */ |
| 2072 | if (num_bde >= (phba->cfg_total_seg_cnt - 2)) |
| 2073 | return num_bde + 3; |
| 2074 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2075 | /* setup PDE5 with what we have */ |
| 2076 | pde5 = (struct lpfc_pde5 *) bpl; |
| 2077 | memset(pde5, 0, sizeof(struct lpfc_pde5)); |
| 2078 | bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2079 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 2080 | /* Endianness conversion if necessary for PDE5 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 2081 | pde5->word0 = cpu_to_le32(pde5->word0); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2082 | pde5->reftag = cpu_to_le32(reftag); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 2083 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2084 | /* advance bpl and increment bde count */ |
| 2085 | num_bde++; |
| 2086 | bpl++; |
| 2087 | pde6 = (struct lpfc_pde6 *) bpl; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2088 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2089 | /* setup PDE6 with the rest of the info */ |
| 2090 | memset(pde6, 0, sizeof(struct lpfc_pde6)); |
| 2091 | bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR); |
| 2092 | bf_set(pde6_optx, pde6, txop); |
| 2093 | bf_set(pde6_oprx, pde6, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2094 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2095 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2096 | bf_set(pde6_ce, pde6, checking); |
| 2097 | else |
| 2098 | bf_set(pde6_ce, pde6, 0); |
| 2099 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2100 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2101 | bf_set(pde6_re, pde6, checking); |
| 2102 | else |
| 2103 | bf_set(pde6_re, pde6, 0); |
| 2104 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2105 | bf_set(pde6_ai, pde6, 1); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2106 | bf_set(pde6_ae, pde6, 0); |
| 2107 | bf_set(pde6_apptagval, pde6, 0); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2108 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 2109 | /* Endianness conversion if necessary for PDE6 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 2110 | pde6->word0 = cpu_to_le32(pde6->word0); |
| 2111 | pde6->word1 = cpu_to_le32(pde6->word1); |
| 2112 | pde6->word2 = cpu_to_le32(pde6->word2); |
| 2113 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2114 | /* advance bpl and increment bde count */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2115 | num_bde++; |
| 2116 | bpl++; |
| 2117 | |
| 2118 | /* setup the first BDE that points to protection buffer */ |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2119 | protphysaddr = sg_dma_address(sgpe) + protgroup_offset; |
| 2120 | protgroup_len = sg_dma_len(sgpe) - protgroup_offset; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2121 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2122 | /* must be integer multiple of the DIF block length */ |
| 2123 | BUG_ON(protgroup_len % 8); |
| 2124 | |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2125 | pde7 = (struct lpfc_pde7 *) bpl; |
| 2126 | memset(pde7, 0, sizeof(struct lpfc_pde7)); |
| 2127 | bf_set(pde7_type, pde7, LPFC_PDE7_DESCRIPTOR); |
| 2128 | |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2129 | pde7->addrHigh = le32_to_cpu(putPaddrHigh(protphysaddr)); |
| 2130 | pde7->addrLow = le32_to_cpu(putPaddrLow(protphysaddr)); |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2131 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2132 | protgrp_blks = protgroup_len / 8; |
| 2133 | protgrp_bytes = protgrp_blks * blksize; |
| 2134 | |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2135 | /* check if this pde is crossing the 4K boundary; if so split */ |
| 2136 | if ((pde7->addrLow & 0xfff) + protgroup_len > 0x1000) { |
| 2137 | protgroup_remainder = 0x1000 - (pde7->addrLow & 0xfff); |
| 2138 | protgroup_offset += protgroup_remainder; |
| 2139 | protgrp_blks = protgroup_remainder / 8; |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2140 | protgrp_bytes = protgrp_blks * blksize; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2141 | } else { |
| 2142 | protgroup_offset = 0; |
| 2143 | curr_prot++; |
| 2144 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2145 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2146 | num_bde++; |
| 2147 | |
| 2148 | /* setup BDE's for data blocks associated with DIF data */ |
| 2149 | pgdone = 0; |
| 2150 | subtotal = 0; /* total bytes processed for current prot grp */ |
| 2151 | while (!pgdone) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2152 | /* Check to see if we ran out of space */ |
| 2153 | if (num_bde >= phba->cfg_total_seg_cnt) |
| 2154 | return num_bde + 1; |
| 2155 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2156 | if (!sgde) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2157 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2158 | "9065 BLKGRD:%s Invalid data segment\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2159 | __func__); |
| 2160 | return 0; |
| 2161 | } |
| 2162 | bpl++; |
| 2163 | dataphysaddr = sg_dma_address(sgde) + split_offset; |
| 2164 | bpl->addrLow = le32_to_cpu(putPaddrLow(dataphysaddr)); |
| 2165 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(dataphysaddr)); |
| 2166 | |
| 2167 | remainder = sg_dma_len(sgde) - split_offset; |
| 2168 | |
| 2169 | if ((subtotal + remainder) <= protgrp_bytes) { |
| 2170 | /* we can use this whole buffer */ |
| 2171 | bpl->tus.f.bdeSize = remainder; |
| 2172 | split_offset = 0; |
| 2173 | |
| 2174 | if ((subtotal + remainder) == protgrp_bytes) |
| 2175 | pgdone = 1; |
| 2176 | } else { |
| 2177 | /* must split this buffer with next prot grp */ |
| 2178 | bpl->tus.f.bdeSize = protgrp_bytes - subtotal; |
| 2179 | split_offset += bpl->tus.f.bdeSize; |
| 2180 | } |
| 2181 | |
| 2182 | subtotal += bpl->tus.f.bdeSize; |
| 2183 | |
| 2184 | if (datadir == DMA_TO_DEVICE) |
| 2185 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 2186 | else |
| 2187 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
| 2188 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 2189 | |
| 2190 | num_bde++; |
| 2191 | curr_data++; |
| 2192 | |
| 2193 | if (split_offset) |
| 2194 | break; |
| 2195 | |
| 2196 | /* Move to the next s/g segment if possible */ |
| 2197 | sgde = sg_next(sgde); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2198 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2199 | } |
| 2200 | |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2201 | if (protgroup_offset) { |
| 2202 | /* update the reference tag */ |
| 2203 | reftag += protgrp_blks; |
| 2204 | bpl++; |
| 2205 | continue; |
| 2206 | } |
| 2207 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2208 | /* are we done ? */ |
| 2209 | if (curr_prot == protcnt) { |
| 2210 | alldone = 1; |
| 2211 | } else if (curr_prot < protcnt) { |
| 2212 | /* advance to next prot buffer */ |
| 2213 | sgpe = sg_next(sgpe); |
| 2214 | bpl++; |
| 2215 | |
| 2216 | /* update the reference tag */ |
| 2217 | reftag += protgrp_blks; |
| 2218 | } else { |
| 2219 | /* if we're here, we have a bug */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2220 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2221 | "9054 BLKGRD: bug in %s\n", __func__); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2222 | } |
| 2223 | |
| 2224 | } while (!alldone); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2225 | out: |
| 2226 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2227 | return num_bde; |
| 2228 | } |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2229 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2230 | /** |
| 2231 | * lpfc_bg_setup_sgl - Setup BlockGuard SGL with no protection data |
| 2232 | * @phba: The Hba for which this call is being executed. |
| 2233 | * @sc: pointer to scsi command we're working on |
| 2234 | * @sgl: pointer to buffer list for protection groups |
| 2235 | * @datacnt: number of segments of data that have been dma mapped |
| 2236 | * |
| 2237 | * This function sets up SGL buffer list for protection groups of |
| 2238 | * type LPFC_PG_TYPE_NO_DIF |
| 2239 | * |
| 2240 | * This is usually used when the HBA is instructed to generate |
| 2241 | * DIFs and insert them into data stream (or strip DIF from |
| 2242 | * incoming data stream) |
| 2243 | * |
| 2244 | * The buffer list consists of just one protection group described |
| 2245 | * below: |
| 2246 | * +-------------------------+ |
| 2247 | * start of prot group --> | DI_SEED | |
| 2248 | * +-------------------------+ |
| 2249 | * | Data SGE | |
| 2250 | * +-------------------------+ |
| 2251 | * |more Data SGE's ... (opt)| |
| 2252 | * +-------------------------+ |
| 2253 | * |
| 2254 | * |
| 2255 | * Note: Data s/g buffers have been dma mapped |
| 2256 | * |
| 2257 | * Returns the number of SGEs added to the SGL. |
| 2258 | **/ |
| 2259 | static int |
| 2260 | lpfc_bg_setup_sgl(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 2261 | struct sli4_sge *sgl, int datasegcnt) |
| 2262 | { |
| 2263 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 2264 | struct sli4_sge_diseed *diseed = NULL; |
| 2265 | dma_addr_t physaddr; |
| 2266 | int i = 0, num_sge = 0, status; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2267 | uint32_t reftag; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2268 | uint8_t txop, rxop; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2269 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2270 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2271 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2272 | uint32_t checking = 1; |
| 2273 | uint32_t dma_len; |
| 2274 | uint32_t dma_offset = 0; |
| 2275 | |
| 2276 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 2277 | if (status) |
| 2278 | goto out; |
| 2279 | |
| 2280 | /* extract some info from the scsi command for pde*/ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2281 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
| 2282 | |
| 2283 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 2284 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2285 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2286 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2287 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2288 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2289 | checking = 0; |
| 2290 | } |
| 2291 | #endif |
| 2292 | |
| 2293 | /* setup DISEED with what we have */ |
| 2294 | diseed = (struct sli4_sge_diseed *) sgl; |
| 2295 | memset(diseed, 0, sizeof(struct sli4_sge_diseed)); |
| 2296 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED); |
| 2297 | |
| 2298 | /* Endianness conversion if necessary */ |
| 2299 | diseed->ref_tag = cpu_to_le32(reftag); |
| 2300 | diseed->ref_tag_tran = diseed->ref_tag; |
| 2301 | |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2302 | /* |
| 2303 | * We only need to check the data on READs, for WRITEs |
| 2304 | * protection data is automatically generated, not checked. |
| 2305 | */ |
| 2306 | if (sc->sc_data_direction == DMA_FROM_DEVICE) { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2307 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2308 | bf_set(lpfc_sli4_sge_dif_ce, diseed, checking); |
| 2309 | else |
| 2310 | bf_set(lpfc_sli4_sge_dif_ce, diseed, 0); |
| 2311 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2312 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2313 | bf_set(lpfc_sli4_sge_dif_re, diseed, checking); |
| 2314 | else |
| 2315 | bf_set(lpfc_sli4_sge_dif_re, diseed, 0); |
| 2316 | } |
| 2317 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2318 | /* setup DISEED with the rest of the info */ |
| 2319 | bf_set(lpfc_sli4_sge_dif_optx, diseed, txop); |
| 2320 | bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2321 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2322 | bf_set(lpfc_sli4_sge_dif_ai, diseed, 1); |
| 2323 | bf_set(lpfc_sli4_sge_dif_me, diseed, 0); |
| 2324 | |
| 2325 | /* Endianness conversion if necessary for DISEED */ |
| 2326 | diseed->word2 = cpu_to_le32(diseed->word2); |
| 2327 | diseed->word3 = cpu_to_le32(diseed->word3); |
| 2328 | |
| 2329 | /* advance bpl and increment sge count */ |
| 2330 | num_sge++; |
| 2331 | sgl++; |
| 2332 | |
| 2333 | /* assumption: caller has already run dma_map_sg on command data */ |
| 2334 | scsi_for_each_sg(sc, sgde, datasegcnt, i) { |
| 2335 | physaddr = sg_dma_address(sgde); |
| 2336 | dma_len = sg_dma_len(sgde); |
| 2337 | sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr)); |
| 2338 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr)); |
| 2339 | if ((i + 1) == datasegcnt) |
| 2340 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 2341 | else |
| 2342 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 2343 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
| 2344 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); |
| 2345 | |
| 2346 | sgl->sge_len = cpu_to_le32(dma_len); |
| 2347 | dma_offset += dma_len; |
| 2348 | |
| 2349 | sgl++; |
| 2350 | num_sge++; |
| 2351 | } |
| 2352 | |
| 2353 | out: |
| 2354 | return num_sge; |
| 2355 | } |
| 2356 | |
| 2357 | /** |
| 2358 | * lpfc_bg_setup_sgl_prot - Setup BlockGuard SGL with protection data |
| 2359 | * @phba: The Hba for which this call is being executed. |
| 2360 | * @sc: pointer to scsi command we're working on |
| 2361 | * @sgl: pointer to buffer list for protection groups |
| 2362 | * @datacnt: number of segments of data that have been dma mapped |
| 2363 | * @protcnt: number of segment of protection data that have been dma mapped |
| 2364 | * |
| 2365 | * This function sets up SGL buffer list for protection groups of |
| 2366 | * type LPFC_PG_TYPE_DIF |
| 2367 | * |
| 2368 | * This is usually used when DIFs are in their own buffers, |
| 2369 | * separate from the data. The HBA can then by instructed |
| 2370 | * to place the DIFs in the outgoing stream. For read operations, |
| 2371 | * The HBA could extract the DIFs and place it in DIF buffers. |
| 2372 | * |
| 2373 | * The buffer list for this type consists of one or more of the |
| 2374 | * protection groups described below: |
| 2375 | * +-------------------------+ |
| 2376 | * start of first prot group --> | DISEED | |
| 2377 | * +-------------------------+ |
| 2378 | * | DIF (Prot SGE) | |
| 2379 | * +-------------------------+ |
| 2380 | * | Data SGE | |
| 2381 | * +-------------------------+ |
| 2382 | * |more Data SGE's ... (opt)| |
| 2383 | * +-------------------------+ |
| 2384 | * start of new prot group --> | DISEED | |
| 2385 | * +-------------------------+ |
| 2386 | * | ... | |
| 2387 | * +-------------------------+ |
| 2388 | * |
| 2389 | * Note: It is assumed that both data and protection s/g buffers have been |
| 2390 | * mapped for DMA |
| 2391 | * |
| 2392 | * Returns the number of SGEs added to the SGL. |
| 2393 | **/ |
| 2394 | static int |
| 2395 | lpfc_bg_setup_sgl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 2396 | struct sli4_sge *sgl, int datacnt, int protcnt) |
| 2397 | { |
| 2398 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 2399 | struct scatterlist *sgpe = NULL; /* s/g prot entry */ |
| 2400 | struct sli4_sge_diseed *diseed = NULL; |
| 2401 | dma_addr_t dataphysaddr, protphysaddr; |
| 2402 | unsigned short curr_data = 0, curr_prot = 0; |
| 2403 | unsigned int split_offset; |
| 2404 | unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder; |
| 2405 | unsigned int protgrp_blks, protgrp_bytes; |
| 2406 | unsigned int remainder, subtotal; |
| 2407 | int status; |
| 2408 | unsigned char pgdone = 0, alldone = 0; |
| 2409 | unsigned blksize; |
| 2410 | uint32_t reftag; |
| 2411 | uint8_t txop, rxop; |
| 2412 | uint32_t dma_len; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2413 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2414 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2415 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2416 | uint32_t checking = 1; |
| 2417 | uint32_t dma_offset = 0; |
| 2418 | int num_sge = 0; |
| 2419 | |
| 2420 | sgpe = scsi_prot_sglist(sc); |
| 2421 | sgde = scsi_sglist(sc); |
| 2422 | |
| 2423 | if (!sgpe || !sgde) { |
| 2424 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2425 | "9082 Invalid s/g entry: data=0x%p prot=0x%p\n", |
| 2426 | sgpe, sgde); |
| 2427 | return 0; |
| 2428 | } |
| 2429 | |
| 2430 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 2431 | if (status) |
| 2432 | goto out; |
| 2433 | |
| 2434 | /* extract some info from the scsi command */ |
| 2435 | blksize = lpfc_cmd_blksize(sc); |
| 2436 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
| 2437 | |
| 2438 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 2439 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2440 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2441 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2442 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2443 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2444 | checking = 0; |
| 2445 | } |
| 2446 | #endif |
| 2447 | |
| 2448 | split_offset = 0; |
| 2449 | do { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2450 | /* Check to see if we ran out of space */ |
| 2451 | if (num_sge >= (phba->cfg_total_seg_cnt - 2)) |
| 2452 | return num_sge + 3; |
| 2453 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2454 | /* setup DISEED with what we have */ |
| 2455 | diseed = (struct sli4_sge_diseed *) sgl; |
| 2456 | memset(diseed, 0, sizeof(struct sli4_sge_diseed)); |
| 2457 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED); |
| 2458 | |
| 2459 | /* Endianness conversion if necessary */ |
| 2460 | diseed->ref_tag = cpu_to_le32(reftag); |
| 2461 | diseed->ref_tag_tran = diseed->ref_tag; |
| 2462 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2463 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) { |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2464 | bf_set(lpfc_sli4_sge_dif_ce, diseed, checking); |
| 2465 | |
| 2466 | } else { |
| 2467 | bf_set(lpfc_sli4_sge_dif_ce, diseed, 0); |
| 2468 | /* |
| 2469 | * When in this mode, the hardware will replace |
| 2470 | * the guard tag from the host with a |
| 2471 | * newly generated good CRC for the wire. |
| 2472 | * Switch to raw mode here to avoid this |
| 2473 | * behavior. What the host sends gets put on the wire. |
| 2474 | */ |
| 2475 | if (txop == BG_OP_IN_CRC_OUT_CRC) { |
| 2476 | txop = BG_OP_RAW_MODE; |
| 2477 | rxop = BG_OP_RAW_MODE; |
| 2478 | } |
| 2479 | } |
| 2480 | |
| 2481 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2482 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2483 | bf_set(lpfc_sli4_sge_dif_re, diseed, checking); |
| 2484 | else |
| 2485 | bf_set(lpfc_sli4_sge_dif_re, diseed, 0); |
| 2486 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2487 | /* setup DISEED with the rest of the info */ |
| 2488 | bf_set(lpfc_sli4_sge_dif_optx, diseed, txop); |
| 2489 | bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2490 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2491 | bf_set(lpfc_sli4_sge_dif_ai, diseed, 1); |
| 2492 | bf_set(lpfc_sli4_sge_dif_me, diseed, 0); |
| 2493 | |
| 2494 | /* Endianness conversion if necessary for DISEED */ |
| 2495 | diseed->word2 = cpu_to_le32(diseed->word2); |
| 2496 | diseed->word3 = cpu_to_le32(diseed->word3); |
| 2497 | |
| 2498 | /* advance sgl and increment bde count */ |
| 2499 | num_sge++; |
| 2500 | sgl++; |
| 2501 | |
| 2502 | /* setup the first BDE that points to protection buffer */ |
| 2503 | protphysaddr = sg_dma_address(sgpe) + protgroup_offset; |
| 2504 | protgroup_len = sg_dma_len(sgpe) - protgroup_offset; |
| 2505 | |
| 2506 | /* must be integer multiple of the DIF block length */ |
| 2507 | BUG_ON(protgroup_len % 8); |
| 2508 | |
| 2509 | /* Now setup DIF SGE */ |
| 2510 | sgl->word2 = 0; |
| 2511 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DIF); |
| 2512 | sgl->addr_hi = le32_to_cpu(putPaddrHigh(protphysaddr)); |
| 2513 | sgl->addr_lo = le32_to_cpu(putPaddrLow(protphysaddr)); |
| 2514 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 2515 | |
| 2516 | protgrp_blks = protgroup_len / 8; |
| 2517 | protgrp_bytes = protgrp_blks * blksize; |
| 2518 | |
| 2519 | /* check if DIF SGE is crossing the 4K boundary; if so split */ |
| 2520 | if ((sgl->addr_lo & 0xfff) + protgroup_len > 0x1000) { |
| 2521 | protgroup_remainder = 0x1000 - (sgl->addr_lo & 0xfff); |
| 2522 | protgroup_offset += protgroup_remainder; |
| 2523 | protgrp_blks = protgroup_remainder / 8; |
| 2524 | protgrp_bytes = protgrp_blks * blksize; |
| 2525 | } else { |
| 2526 | protgroup_offset = 0; |
| 2527 | curr_prot++; |
| 2528 | } |
| 2529 | |
| 2530 | num_sge++; |
| 2531 | |
| 2532 | /* setup SGE's for data blocks associated with DIF data */ |
| 2533 | pgdone = 0; |
| 2534 | subtotal = 0; /* total bytes processed for current prot grp */ |
| 2535 | while (!pgdone) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2536 | /* Check to see if we ran out of space */ |
| 2537 | if (num_sge >= phba->cfg_total_seg_cnt) |
| 2538 | return num_sge + 1; |
| 2539 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2540 | if (!sgde) { |
| 2541 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2542 | "9086 BLKGRD:%s Invalid data segment\n", |
| 2543 | __func__); |
| 2544 | return 0; |
| 2545 | } |
| 2546 | sgl++; |
| 2547 | dataphysaddr = sg_dma_address(sgde) + split_offset; |
| 2548 | |
| 2549 | remainder = sg_dma_len(sgde) - split_offset; |
| 2550 | |
| 2551 | if ((subtotal + remainder) <= protgrp_bytes) { |
| 2552 | /* we can use this whole buffer */ |
| 2553 | dma_len = remainder; |
| 2554 | split_offset = 0; |
| 2555 | |
| 2556 | if ((subtotal + remainder) == protgrp_bytes) |
| 2557 | pgdone = 1; |
| 2558 | } else { |
| 2559 | /* must split this buffer with next prot grp */ |
| 2560 | dma_len = protgrp_bytes - subtotal; |
| 2561 | split_offset += dma_len; |
| 2562 | } |
| 2563 | |
| 2564 | subtotal += dma_len; |
| 2565 | |
| 2566 | sgl->addr_lo = cpu_to_le32(putPaddrLow(dataphysaddr)); |
| 2567 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(dataphysaddr)); |
| 2568 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 2569 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
| 2570 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); |
| 2571 | |
| 2572 | sgl->sge_len = cpu_to_le32(dma_len); |
| 2573 | dma_offset += dma_len; |
| 2574 | |
| 2575 | num_sge++; |
| 2576 | curr_data++; |
| 2577 | |
| 2578 | if (split_offset) |
| 2579 | break; |
| 2580 | |
| 2581 | /* Move to the next s/g segment if possible */ |
| 2582 | sgde = sg_next(sgde); |
| 2583 | } |
| 2584 | |
| 2585 | if (protgroup_offset) { |
| 2586 | /* update the reference tag */ |
| 2587 | reftag += protgrp_blks; |
| 2588 | sgl++; |
| 2589 | continue; |
| 2590 | } |
| 2591 | |
| 2592 | /* are we done ? */ |
| 2593 | if (curr_prot == protcnt) { |
| 2594 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 2595 | alldone = 1; |
| 2596 | } else if (curr_prot < protcnt) { |
| 2597 | /* advance to next prot buffer */ |
| 2598 | sgpe = sg_next(sgpe); |
| 2599 | sgl++; |
| 2600 | |
| 2601 | /* update the reference tag */ |
| 2602 | reftag += protgrp_blks; |
| 2603 | } else { |
| 2604 | /* if we're here, we have a bug */ |
| 2605 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2606 | "9085 BLKGRD: bug in %s\n", __func__); |
| 2607 | } |
| 2608 | |
| 2609 | } while (!alldone); |
| 2610 | |
| 2611 | out: |
| 2612 | |
| 2613 | return num_sge; |
| 2614 | } |
| 2615 | |
| 2616 | /** |
| 2617 | * lpfc_prot_group_type - Get prtotection group type of SCSI command |
| 2618 | * @phba: The Hba for which this call is being executed. |
| 2619 | * @sc: pointer to scsi command we're working on |
| 2620 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2621 | * Given a SCSI command that supports DIF, determine composition of protection |
| 2622 | * groups involved in setting up buffer lists |
| 2623 | * |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2624 | * Returns: Protection group type (with or without DIF) |
| 2625 | * |
| 2626 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2627 | static int |
| 2628 | lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc) |
| 2629 | { |
| 2630 | int ret = LPFC_PG_TYPE_INVALID; |
| 2631 | unsigned char op = scsi_get_prot_op(sc); |
| 2632 | |
| 2633 | switch (op) { |
| 2634 | case SCSI_PROT_READ_STRIP: |
| 2635 | case SCSI_PROT_WRITE_INSERT: |
| 2636 | ret = LPFC_PG_TYPE_NO_DIF; |
| 2637 | break; |
| 2638 | case SCSI_PROT_READ_INSERT: |
| 2639 | case SCSI_PROT_WRITE_STRIP: |
| 2640 | case SCSI_PROT_READ_PASS: |
| 2641 | case SCSI_PROT_WRITE_PASS: |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2642 | ret = LPFC_PG_TYPE_DIF_BUF; |
| 2643 | break; |
| 2644 | default: |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2645 | if (phba) |
| 2646 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2647 | "9021 Unsupported protection op:%d\n", |
| 2648 | op); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2649 | break; |
| 2650 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2651 | return ret; |
| 2652 | } |
| 2653 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2654 | /** |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2655 | * lpfc_bg_scsi_adjust_dl - Adjust SCSI data length for BlockGuard |
| 2656 | * @phba: The Hba for which this call is being executed. |
| 2657 | * @lpfc_cmd: The scsi buffer which is going to be adjusted. |
| 2658 | * |
| 2659 | * Adjust the data length to account for how much data |
| 2660 | * is actually on the wire. |
| 2661 | * |
| 2662 | * returns the adjusted data length |
| 2663 | **/ |
| 2664 | static int |
| 2665 | lpfc_bg_scsi_adjust_dl(struct lpfc_hba *phba, |
| 2666 | struct lpfc_scsi_buf *lpfc_cmd) |
| 2667 | { |
| 2668 | struct scsi_cmnd *sc = lpfc_cmd->pCmd; |
| 2669 | int fcpdl; |
| 2670 | |
| 2671 | fcpdl = scsi_bufflen(sc); |
| 2672 | |
| 2673 | /* Check if there is protection data on the wire */ |
| 2674 | if (sc->sc_data_direction == DMA_FROM_DEVICE) { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2675 | /* Read check for protection data */ |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2676 | if (scsi_get_prot_op(sc) == SCSI_PROT_READ_INSERT) |
| 2677 | return fcpdl; |
| 2678 | |
| 2679 | } else { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2680 | /* Write check for protection data */ |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2681 | if (scsi_get_prot_op(sc) == SCSI_PROT_WRITE_STRIP) |
| 2682 | return fcpdl; |
| 2683 | } |
| 2684 | |
| 2685 | /* |
| 2686 | * 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] | 2687 | * DIF (trailer) attached to it. Must ajust FCP data length |
| 2688 | * to account for the protection data. |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2689 | */ |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2690 | fcpdl += (fcpdl / lpfc_cmd_blksize(sc)) * 8; |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2691 | |
| 2692 | return fcpdl; |
| 2693 | } |
| 2694 | |
| 2695 | /** |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2696 | * lpfc_bg_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec |
| 2697 | * @phba: The Hba for which this call is being executed. |
| 2698 | * @lpfc_cmd: The scsi buffer which is going to be prep'ed. |
| 2699 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2700 | * This is the protection/DIF aware version of |
| 2701 | * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the |
| 2702 | * two functions eventually, but for now, it's here |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2703 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2704 | static int |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2705 | lpfc_bg_scsi_prep_dma_buf_s3(struct lpfc_hba *phba, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2706 | struct lpfc_scsi_buf *lpfc_cmd) |
| 2707 | { |
| 2708 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 2709 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 2710 | struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl; |
| 2711 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 2712 | uint32_t num_bde = 0; |
| 2713 | int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction; |
| 2714 | int prot_group_type = 0; |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2715 | int fcpdl; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2716 | |
| 2717 | /* |
| 2718 | * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd |
| 2719 | * fcp_rsp regions to the first data bde entry |
| 2720 | */ |
| 2721 | bpl += 2; |
| 2722 | if (scsi_sg_count(scsi_cmnd)) { |
| 2723 | /* |
| 2724 | * The driver stores the segment count returned from pci_map_sg |
| 2725 | * because this a count of dma-mappings used to map the use_sg |
| 2726 | * pages. They are not guaranteed to be the same for those |
| 2727 | * architectures that implement an IOMMU. |
| 2728 | */ |
| 2729 | datasegcnt = dma_map_sg(&phba->pcidev->dev, |
| 2730 | scsi_sglist(scsi_cmnd), |
| 2731 | scsi_sg_count(scsi_cmnd), datadir); |
| 2732 | if (unlikely(!datasegcnt)) |
| 2733 | return 1; |
| 2734 | |
| 2735 | lpfc_cmd->seg_cnt = datasegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2736 | |
| 2737 | /* First check if data segment count from SCSI Layer is good */ |
| 2738 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) |
| 2739 | goto err; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2740 | |
| 2741 | prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd); |
| 2742 | |
| 2743 | switch (prot_group_type) { |
| 2744 | case LPFC_PG_TYPE_NO_DIF: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2745 | |
| 2746 | /* Here we need to add a PDE5 and PDE6 to the count */ |
| 2747 | if ((lpfc_cmd->seg_cnt + 2) > phba->cfg_total_seg_cnt) |
| 2748 | goto err; |
| 2749 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2750 | num_bde = lpfc_bg_setup_bpl(phba, scsi_cmnd, bpl, |
| 2751 | datasegcnt); |
Adam Buchbinder | c9404c9 | 2009-12-18 15:40:42 -0500 | [diff] [blame] | 2752 | /* we should have 2 or more entries in buffer list */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2753 | if (num_bde < 2) |
| 2754 | goto err; |
| 2755 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2756 | |
| 2757 | case LPFC_PG_TYPE_DIF_BUF: |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2758 | /* |
| 2759 | * This type indicates that protection buffers are |
| 2760 | * passed to the driver, so that needs to be prepared |
| 2761 | * for DMA |
| 2762 | */ |
| 2763 | protsegcnt = dma_map_sg(&phba->pcidev->dev, |
| 2764 | scsi_prot_sglist(scsi_cmnd), |
| 2765 | scsi_prot_sg_count(scsi_cmnd), datadir); |
| 2766 | if (unlikely(!protsegcnt)) { |
| 2767 | scsi_dma_unmap(scsi_cmnd); |
| 2768 | return 1; |
| 2769 | } |
| 2770 | |
| 2771 | lpfc_cmd->prot_seg_cnt = protsegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2772 | |
| 2773 | /* |
| 2774 | * There is a minimun of 4 BPLs used for every |
| 2775 | * protection data segment. |
| 2776 | */ |
| 2777 | if ((lpfc_cmd->prot_seg_cnt * 4) > |
| 2778 | (phba->cfg_total_seg_cnt - 2)) |
| 2779 | goto err; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2780 | |
| 2781 | num_bde = lpfc_bg_setup_bpl_prot(phba, scsi_cmnd, bpl, |
| 2782 | datasegcnt, protsegcnt); |
Adam Buchbinder | c9404c9 | 2009-12-18 15:40:42 -0500 | [diff] [blame] | 2783 | /* we should have 3 or more entries in buffer list */ |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2784 | if ((num_bde < 3) || |
| 2785 | (num_bde > phba->cfg_total_seg_cnt)) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2786 | goto err; |
| 2787 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2788 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2789 | case LPFC_PG_TYPE_INVALID: |
| 2790 | default: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2791 | scsi_dma_unmap(scsi_cmnd); |
| 2792 | lpfc_cmd->seg_cnt = 0; |
| 2793 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2794 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2795 | "9022 Unexpected protection group %i\n", |
| 2796 | prot_group_type); |
| 2797 | return 1; |
| 2798 | } |
| 2799 | } |
| 2800 | |
| 2801 | /* |
| 2802 | * Finish initializing those IOCB fields that are dependent on the |
| 2803 | * scsi_cmnd request_buffer. Note that the bdeSize is explicitly |
| 2804 | * reinitialized since all iocb memory resources are used many times |
| 2805 | * for transmit, receive, and continuation bpl's. |
| 2806 | */ |
| 2807 | iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| 2808 | iocb_cmd->un.fcpi64.bdl.bdeSize += (num_bde * sizeof(struct ulp_bde64)); |
| 2809 | iocb_cmd->ulpBdeCount = 1; |
| 2810 | iocb_cmd->ulpLe = 1; |
| 2811 | |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2812 | fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2813 | fcp_cmnd->fcpDl = be32_to_cpu(fcpdl); |
| 2814 | |
| 2815 | /* |
| 2816 | * Due to difference in data length between DIF/non-DIF paths, |
| 2817 | * we need to set word 4 of IOCB here |
| 2818 | */ |
| 2819 | iocb_cmd->un.fcpi.fcpi_parm = fcpdl; |
| 2820 | |
| 2821 | return 0; |
| 2822 | err: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2823 | if (lpfc_cmd->seg_cnt) |
| 2824 | scsi_dma_unmap(scsi_cmnd); |
| 2825 | if (lpfc_cmd->prot_seg_cnt) |
| 2826 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd), |
| 2827 | scsi_prot_sg_count(scsi_cmnd), |
| 2828 | scsi_cmnd->sc_data_direction); |
| 2829 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2830 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2831 | "9023 Cannot setup S/G List for HBA" |
| 2832 | "IO segs %d/%d BPL %d SCSI %d: %d %d\n", |
| 2833 | lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt, |
| 2834 | phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2835 | prot_group_type, num_bde); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2836 | |
| 2837 | lpfc_cmd->seg_cnt = 0; |
| 2838 | lpfc_cmd->prot_seg_cnt = 0; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2839 | return 1; |
| 2840 | } |
| 2841 | |
| 2842 | /* |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2843 | * This function calcuates the T10 DIF guard tag |
| 2844 | * on the specified data using a CRC algorithmn |
| 2845 | * using crc_t10dif. |
| 2846 | */ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 2847 | static uint16_t |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2848 | lpfc_bg_crc(uint8_t *data, int count) |
| 2849 | { |
| 2850 | uint16_t crc = 0; |
| 2851 | uint16_t x; |
| 2852 | |
| 2853 | crc = crc_t10dif(data, count); |
| 2854 | x = cpu_to_be16(crc); |
| 2855 | return x; |
| 2856 | } |
| 2857 | |
| 2858 | /* |
| 2859 | * This function calcuates the T10 DIF guard tag |
| 2860 | * on the specified data using a CSUM algorithmn |
| 2861 | * using ip_compute_csum. |
| 2862 | */ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 2863 | static uint16_t |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2864 | lpfc_bg_csum(uint8_t *data, int count) |
| 2865 | { |
| 2866 | uint16_t ret; |
| 2867 | |
| 2868 | ret = ip_compute_csum(data, count); |
| 2869 | return ret; |
| 2870 | } |
| 2871 | |
| 2872 | /* |
| 2873 | * This function examines the protection data to try to determine |
| 2874 | * what type of T10-DIF error occurred. |
| 2875 | */ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 2876 | static void |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2877 | lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 2878 | { |
| 2879 | struct scatterlist *sgpe; /* s/g prot entry */ |
| 2880 | struct scatterlist *sgde; /* s/g data entry */ |
| 2881 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 2882 | struct scsi_dif_tuple *src = NULL; |
| 2883 | uint8_t *data_src = NULL; |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 2884 | uint16_t guard_tag; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2885 | uint16_t start_app_tag, app_tag; |
| 2886 | uint32_t start_ref_tag, ref_tag; |
| 2887 | int prot, protsegcnt; |
| 2888 | int err_type, len, data_len; |
| 2889 | int chk_ref, chk_app, chk_guard; |
| 2890 | uint16_t sum; |
| 2891 | unsigned blksize; |
| 2892 | |
| 2893 | err_type = BGS_GUARD_ERR_MASK; |
| 2894 | sum = 0; |
| 2895 | guard_tag = 0; |
| 2896 | |
| 2897 | /* First check to see if there is protection data to examine */ |
| 2898 | prot = scsi_get_prot_op(cmd); |
| 2899 | if ((prot == SCSI_PROT_READ_STRIP) || |
| 2900 | (prot == SCSI_PROT_WRITE_INSERT) || |
| 2901 | (prot == SCSI_PROT_NORMAL)) |
| 2902 | goto out; |
| 2903 | |
| 2904 | /* Currently the driver just supports ref_tag and guard_tag checking */ |
| 2905 | chk_ref = 1; |
| 2906 | chk_app = 0; |
| 2907 | chk_guard = 0; |
| 2908 | |
| 2909 | /* Setup a ptr to the protection data provided by the SCSI host */ |
| 2910 | sgpe = scsi_prot_sglist(cmd); |
| 2911 | protsegcnt = lpfc_cmd->prot_seg_cnt; |
| 2912 | |
| 2913 | if (sgpe && protsegcnt) { |
| 2914 | |
| 2915 | /* |
| 2916 | * We will only try to verify guard tag if the segment |
| 2917 | * data length is a multiple of the blksize. |
| 2918 | */ |
| 2919 | sgde = scsi_sglist(cmd); |
| 2920 | blksize = lpfc_cmd_blksize(cmd); |
| 2921 | data_src = (uint8_t *)sg_virt(sgde); |
| 2922 | data_len = sgde->length; |
| 2923 | if ((data_len & (blksize - 1)) == 0) |
| 2924 | chk_guard = 1; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2925 | |
James Smart | e85d8f9 | 2013-05-31 17:04:10 -0400 | [diff] [blame] | 2926 | src = (struct scsi_dif_tuple *)sg_virt(sgpe); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2927 | start_ref_tag = (uint32_t)scsi_get_lba(cmd); /* Truncate LBA */ |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2928 | start_app_tag = src->app_tag; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2929 | len = sgpe->length; |
| 2930 | while (src && protsegcnt) { |
| 2931 | while (len) { |
| 2932 | |
| 2933 | /* |
| 2934 | * First check to see if a protection data |
| 2935 | * check is valid |
| 2936 | */ |
| 2937 | if ((src->ref_tag == 0xffffffff) || |
| 2938 | (src->app_tag == 0xffff)) { |
| 2939 | start_ref_tag++; |
| 2940 | goto skipit; |
| 2941 | } |
| 2942 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2943 | /* First Guard Tag checking */ |
| 2944 | if (chk_guard) { |
| 2945 | guard_tag = src->guard_tag; |
| 2946 | if (lpfc_cmd_guard_csum(cmd)) |
| 2947 | sum = lpfc_bg_csum(data_src, |
| 2948 | blksize); |
| 2949 | else |
| 2950 | sum = lpfc_bg_crc(data_src, |
| 2951 | blksize); |
| 2952 | if ((guard_tag != sum)) { |
| 2953 | err_type = BGS_GUARD_ERR_MASK; |
| 2954 | goto out; |
| 2955 | } |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2956 | } |
| 2957 | |
| 2958 | /* Reference Tag checking */ |
| 2959 | ref_tag = be32_to_cpu(src->ref_tag); |
| 2960 | if (chk_ref && (ref_tag != start_ref_tag)) { |
| 2961 | err_type = BGS_REFTAG_ERR_MASK; |
| 2962 | goto out; |
| 2963 | } |
| 2964 | start_ref_tag++; |
| 2965 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2966 | /* App Tag checking */ |
| 2967 | app_tag = src->app_tag; |
| 2968 | if (chk_app && (app_tag != start_app_tag)) { |
| 2969 | err_type = BGS_APPTAG_ERR_MASK; |
| 2970 | goto out; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2971 | } |
| 2972 | skipit: |
| 2973 | len -= sizeof(struct scsi_dif_tuple); |
| 2974 | if (len < 0) |
| 2975 | len = 0; |
| 2976 | src++; |
| 2977 | |
| 2978 | data_src += blksize; |
| 2979 | data_len -= blksize; |
| 2980 | |
| 2981 | /* |
| 2982 | * Are we at the end of the Data segment? |
| 2983 | * The data segment is only used for Guard |
| 2984 | * tag checking. |
| 2985 | */ |
| 2986 | if (chk_guard && (data_len == 0)) { |
| 2987 | chk_guard = 0; |
| 2988 | sgde = sg_next(sgde); |
| 2989 | if (!sgde) |
| 2990 | goto out; |
| 2991 | |
| 2992 | data_src = (uint8_t *)sg_virt(sgde); |
| 2993 | data_len = sgde->length; |
| 2994 | if ((data_len & (blksize - 1)) == 0) |
| 2995 | chk_guard = 1; |
| 2996 | } |
| 2997 | } |
| 2998 | |
| 2999 | /* Goto the next Protection data segment */ |
| 3000 | sgpe = sg_next(sgpe); |
| 3001 | if (sgpe) { |
| 3002 | src = (struct scsi_dif_tuple *)sg_virt(sgpe); |
| 3003 | len = sgpe->length; |
| 3004 | } else { |
| 3005 | src = NULL; |
| 3006 | } |
| 3007 | protsegcnt--; |
| 3008 | } |
| 3009 | } |
| 3010 | out: |
| 3011 | if (err_type == BGS_GUARD_ERR_MASK) { |
| 3012 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 3013 | 0x10, 0x1); |
| 3014 | cmd->result = DRIVER_SENSE << 24 |
| 3015 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 3016 | phba->bg_guard_err_cnt++; |
| 3017 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3018 | "9069 BLKGRD: LBA %lx grd_tag error %x != %x\n", |
| 3019 | (unsigned long)scsi_get_lba(cmd), |
| 3020 | sum, guard_tag); |
| 3021 | |
| 3022 | } else if (err_type == BGS_REFTAG_ERR_MASK) { |
| 3023 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 3024 | 0x10, 0x3); |
| 3025 | cmd->result = DRIVER_SENSE << 24 |
| 3026 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 3027 | |
| 3028 | phba->bg_reftag_err_cnt++; |
| 3029 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3030 | "9066 BLKGRD: LBA %lx ref_tag error %x != %x\n", |
| 3031 | (unsigned long)scsi_get_lba(cmd), |
| 3032 | ref_tag, start_ref_tag); |
| 3033 | |
| 3034 | } else if (err_type == BGS_APPTAG_ERR_MASK) { |
| 3035 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 3036 | 0x10, 0x2); |
| 3037 | cmd->result = DRIVER_SENSE << 24 |
| 3038 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 3039 | |
| 3040 | phba->bg_apptag_err_cnt++; |
| 3041 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3042 | "9041 BLKGRD: LBA %lx app_tag error %x != %x\n", |
| 3043 | (unsigned long)scsi_get_lba(cmd), |
| 3044 | app_tag, start_app_tag); |
| 3045 | } |
| 3046 | } |
| 3047 | |
| 3048 | |
| 3049 | /* |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3050 | * This function checks for BlockGuard errors detected by |
| 3051 | * the HBA. In case of errors, the ASC/ASCQ fields in the |
| 3052 | * sense buffer will be set accordingly, paired with |
| 3053 | * ILLEGAL_REQUEST to signal to the kernel that the HBA |
| 3054 | * detected corruption. |
| 3055 | * |
| 3056 | * Returns: |
| 3057 | * 0 - No error found |
| 3058 | * 1 - BlockGuard error found |
| 3059 | * -1 - Internal error (bad profile, ...etc) |
| 3060 | */ |
| 3061 | static int |
| 3062 | lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd, |
| 3063 | struct lpfc_iocbq *pIocbOut) |
| 3064 | { |
| 3065 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 3066 | struct sli3_bg_fields *bgf = &pIocbOut->iocb.unsli3.sli3_bg; |
| 3067 | int ret = 0; |
| 3068 | uint32_t bghm = bgf->bghm; |
| 3069 | uint32_t bgstat = bgf->bgstat; |
| 3070 | uint64_t failing_sector = 0; |
| 3071 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3072 | spin_lock(&_dump_buf_lock); |
| 3073 | if (!_dump_buf_done) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3074 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9070 BLKGRD: Saving" |
| 3075 | " Data for %u blocks to debugfs\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3076 | (cmd->cmnd[7] << 8 | cmd->cmnd[8])); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3077 | lpfc_debug_save_data(phba, cmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3078 | |
| 3079 | /* If we have a prot sgl, save the DIF buffer */ |
| 3080 | if (lpfc_prot_group_type(phba, cmd) == |
| 3081 | LPFC_PG_TYPE_DIF_BUF) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3082 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9071 BLKGRD: " |
| 3083 | "Saving DIF for %u blocks to debugfs\n", |
| 3084 | (cmd->cmnd[7] << 8 | cmd->cmnd[8])); |
| 3085 | lpfc_debug_save_dif(phba, cmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3086 | } |
| 3087 | |
| 3088 | _dump_buf_done = 1; |
| 3089 | } |
| 3090 | spin_unlock(&_dump_buf_lock); |
| 3091 | |
| 3092 | if (lpfc_bgs_get_invalid_prof(bgstat)) { |
| 3093 | cmd->result = ScsiResult(DID_ERROR, 0); |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3094 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3095 | "9072 BLKGRD: Invalid BG Profile in cmd" |
| 3096 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3097 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3098 | (unsigned long long)scsi_get_lba(cmd), |
| 3099 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3100 | ret = (-1); |
| 3101 | goto out; |
| 3102 | } |
| 3103 | |
| 3104 | if (lpfc_bgs_get_uninit_dif_block(bgstat)) { |
| 3105 | cmd->result = ScsiResult(DID_ERROR, 0); |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3106 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3107 | "9073 BLKGRD: Invalid BG PDIF Block in cmd" |
| 3108 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3109 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3110 | (unsigned long long)scsi_get_lba(cmd), |
| 3111 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3112 | ret = (-1); |
| 3113 | goto out; |
| 3114 | } |
| 3115 | |
| 3116 | if (lpfc_bgs_get_guard_err(bgstat)) { |
| 3117 | ret = 1; |
| 3118 | |
| 3119 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 3120 | 0x10, 0x1); |
Martin K. Petersen | 1c9fbaf | 2009-01-04 03:14:11 -0500 | [diff] [blame] | 3121 | cmd->result = DRIVER_SENSE << 24 |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3122 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 3123 | phba->bg_guard_err_cnt++; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3124 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3125 | "9055 BLKGRD: Guard Tag error in cmd" |
| 3126 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3127 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3128 | (unsigned long long)scsi_get_lba(cmd), |
| 3129 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3130 | } |
| 3131 | |
| 3132 | if (lpfc_bgs_get_reftag_err(bgstat)) { |
| 3133 | ret = 1; |
| 3134 | |
| 3135 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 3136 | 0x10, 0x3); |
Martin K. Petersen | 1c9fbaf | 2009-01-04 03:14:11 -0500 | [diff] [blame] | 3137 | cmd->result = DRIVER_SENSE << 24 |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3138 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 3139 | |
| 3140 | phba->bg_reftag_err_cnt++; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3141 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3142 | "9056 BLKGRD: Ref Tag error in cmd" |
| 3143 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3144 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3145 | (unsigned long long)scsi_get_lba(cmd), |
| 3146 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3147 | } |
| 3148 | |
| 3149 | if (lpfc_bgs_get_apptag_err(bgstat)) { |
| 3150 | ret = 1; |
| 3151 | |
| 3152 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 3153 | 0x10, 0x2); |
Martin K. Petersen | 1c9fbaf | 2009-01-04 03:14:11 -0500 | [diff] [blame] | 3154 | cmd->result = DRIVER_SENSE << 24 |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3155 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 3156 | |
| 3157 | phba->bg_apptag_err_cnt++; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3158 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3159 | "9061 BLKGRD: App Tag error in cmd" |
| 3160 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3161 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3162 | (unsigned long long)scsi_get_lba(cmd), |
| 3163 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3164 | } |
| 3165 | |
| 3166 | if (lpfc_bgs_get_hi_water_mark_present(bgstat)) { |
| 3167 | /* |
| 3168 | * setup sense data descriptor 0 per SPC-4 as an information |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 3169 | * field, and put the failing LBA in it. |
| 3170 | * This code assumes there was also a guard/app/ref tag error |
| 3171 | * indication. |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3172 | */ |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 3173 | cmd->sense_buffer[7] = 0xc; /* Additional sense length */ |
| 3174 | cmd->sense_buffer[8] = 0; /* Information descriptor type */ |
| 3175 | cmd->sense_buffer[9] = 0xa; /* Additional descriptor length */ |
| 3176 | cmd->sense_buffer[10] = 0x80; /* Validity bit */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3177 | |
| 3178 | /* bghm is a "on the wire" FC frame based count */ |
| 3179 | switch (scsi_get_prot_op(cmd)) { |
| 3180 | case SCSI_PROT_READ_INSERT: |
| 3181 | case SCSI_PROT_WRITE_STRIP: |
| 3182 | bghm /= cmd->device->sector_size; |
| 3183 | break; |
| 3184 | case SCSI_PROT_READ_STRIP: |
| 3185 | case SCSI_PROT_WRITE_INSERT: |
| 3186 | case SCSI_PROT_READ_PASS: |
| 3187 | case SCSI_PROT_WRITE_PASS: |
| 3188 | bghm /= (cmd->device->sector_size + |
| 3189 | sizeof(struct scsi_dif_tuple)); |
| 3190 | break; |
| 3191 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3192 | |
| 3193 | failing_sector = scsi_get_lba(cmd); |
| 3194 | failing_sector += bghm; |
| 3195 | |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 3196 | /* Descriptor Information */ |
| 3197 | put_unaligned_be64(failing_sector, &cmd->sense_buffer[12]); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3198 | } |
| 3199 | |
| 3200 | if (!ret) { |
| 3201 | /* No error was reported - problem in FW? */ |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3202 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3203 | "9057 BLKGRD: Unknown error in cmd" |
| 3204 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3205 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3206 | (unsigned long long)scsi_get_lba(cmd), |
| 3207 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3208 | |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3209 | /* Calcuate what type of error it was */ |
| 3210 | lpfc_calc_bg_err(phba, lpfc_cmd); |
| 3211 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3212 | out: |
| 3213 | return ret; |
| 3214 | } |
| 3215 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3216 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3217 | * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec |
| 3218 | * @phba: The Hba for which this call is being executed. |
| 3219 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3220 | * |
| 3221 | * This routine does the pci dma mapping for scatter-gather list of scsi cmnd |
| 3222 | * field of @lpfc_cmd for device with SLI-4 interface spec. |
| 3223 | * |
| 3224 | * Return codes: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 3225 | * 1 - Error |
| 3226 | * 0 - Success |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3227 | **/ |
| 3228 | static int |
| 3229 | lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 3230 | { |
| 3231 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 3232 | struct scatterlist *sgel = NULL; |
| 3233 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 3234 | struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3235 | struct sli4_sge *first_data_sgl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3236 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 3237 | dma_addr_t physaddr; |
| 3238 | uint32_t num_bde = 0; |
| 3239 | uint32_t dma_len; |
| 3240 | uint32_t dma_offset = 0; |
| 3241 | int nseg; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3242 | struct ulp_bde64 *bde; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3243 | |
| 3244 | /* |
| 3245 | * There are three possibilities here - use scatter-gather segment, use |
| 3246 | * the single mapping, or neither. Start the lpfc command prep by |
| 3247 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 3248 | * data bde entry. |
| 3249 | */ |
| 3250 | if (scsi_sg_count(scsi_cmnd)) { |
| 3251 | /* |
| 3252 | * The driver stores the segment count returned from pci_map_sg |
| 3253 | * because this a count of dma-mappings used to map the use_sg |
| 3254 | * pages. They are not guaranteed to be the same for those |
| 3255 | * architectures that implement an IOMMU. |
| 3256 | */ |
| 3257 | |
| 3258 | nseg = scsi_dma_map(scsi_cmnd); |
James Smart | 5116fbf | 2015-05-22 10:42:39 -0400 | [diff] [blame] | 3259 | if (unlikely(nseg <= 0)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3260 | return 1; |
| 3261 | sgl += 1; |
| 3262 | /* clear the last flag in the fcp_rsp map entry */ |
| 3263 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 3264 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 3265 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 3266 | sgl += 1; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3267 | first_data_sgl = sgl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3268 | lpfc_cmd->seg_cnt = nseg; |
| 3269 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3270 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9074 BLKGRD:" |
| 3271 | " %s: Too many sg segments from " |
| 3272 | "dma_map_sg. Config %d, seg_cnt %d\n", |
| 3273 | __func__, phba->cfg_sg_seg_cnt, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3274 | lpfc_cmd->seg_cnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3275 | lpfc_cmd->seg_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3276 | scsi_dma_unmap(scsi_cmnd); |
| 3277 | return 1; |
| 3278 | } |
| 3279 | |
| 3280 | /* |
| 3281 | * The driver established a maximum scatter-gather segment count |
| 3282 | * during probe that limits the number of sg elements in any |
| 3283 | * single scsi command. Just run through the seg_cnt and format |
| 3284 | * the sge's. |
| 3285 | * When using SLI-3 the driver will try to fit all the BDEs into |
| 3286 | * the IOCB. If it can't then the BDEs get added to a BPL as it |
| 3287 | * does for SLI-2 mode. |
| 3288 | */ |
| 3289 | scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) { |
| 3290 | physaddr = sg_dma_address(sgel); |
| 3291 | dma_len = sg_dma_len(sgel); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3292 | sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr)); |
| 3293 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr)); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 3294 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3295 | if ((num_bde + 1) == nseg) |
| 3296 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 3297 | else |
| 3298 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 3299 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 3300 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3301 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 3302 | sgl->sge_len = cpu_to_le32(dma_len); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3303 | dma_offset += dma_len; |
| 3304 | sgl++; |
| 3305 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3306 | /* setup the performance hint (first data BDE) if enabled */ |
| 3307 | if (phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) { |
| 3308 | bde = (struct ulp_bde64 *) |
| 3309 | &(iocb_cmd->unsli3.sli3Words[5]); |
| 3310 | bde->addrLow = first_data_sgl->addr_lo; |
| 3311 | bde->addrHigh = first_data_sgl->addr_hi; |
| 3312 | bde->tus.f.bdeSize = |
| 3313 | le32_to_cpu(first_data_sgl->sge_len); |
| 3314 | bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 3315 | bde->tus.w = cpu_to_le32(bde->tus.w); |
| 3316 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3317 | } else { |
| 3318 | sgl += 1; |
| 3319 | /* clear the last flag in the fcp_rsp map entry */ |
| 3320 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 3321 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 3322 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 3323 | } |
| 3324 | |
| 3325 | /* |
| 3326 | * Finish initializing those IOCB fields that are dependent on the |
| 3327 | * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is |
| 3328 | * explicitly reinitialized. |
| 3329 | * all iocb memory resources are reused. |
| 3330 | */ |
| 3331 | fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); |
| 3332 | |
| 3333 | /* |
| 3334 | * Due to difference in data length between DIF/non-DIF paths, |
| 3335 | * we need to set word 4 of IOCB here |
| 3336 | */ |
| 3337 | iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 3338 | |
| 3339 | /* |
| 3340 | * If the OAS driver feature is enabled and the lun is enabled for |
| 3341 | * OAS, set the oas iocb related flags. |
| 3342 | */ |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 3343 | if ((phba->cfg_fof) && ((struct lpfc_device_data *) |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 3344 | scsi_cmnd->device->hostdata)->oas_enabled) { |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 3345 | lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 3346 | lpfc_cmd->cur_iocbq.priority = ((struct lpfc_device_data *) |
| 3347 | scsi_cmnd->device->hostdata)->priority; |
| 3348 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3349 | return 0; |
| 3350 | } |
| 3351 | |
| 3352 | /** |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3353 | * lpfc_bg_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec |
| 3354 | * @phba: The Hba for which this call is being executed. |
| 3355 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3356 | * |
| 3357 | * This is the protection/DIF aware version of |
| 3358 | * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the |
| 3359 | * two functions eventually, but for now, it's here |
| 3360 | **/ |
| 3361 | static int |
| 3362 | lpfc_bg_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, |
| 3363 | struct lpfc_scsi_buf *lpfc_cmd) |
| 3364 | { |
| 3365 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 3366 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 3367 | struct sli4_sge *sgl = (struct sli4_sge *)(lpfc_cmd->fcp_bpl); |
| 3368 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3369 | uint32_t num_sge = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3370 | int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction; |
| 3371 | int prot_group_type = 0; |
| 3372 | int fcpdl; |
| 3373 | |
| 3374 | /* |
| 3375 | * Start the lpfc command prep by bumping the sgl beyond fcp_cmnd |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3376 | * fcp_rsp regions to the first data sge entry |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3377 | */ |
| 3378 | if (scsi_sg_count(scsi_cmnd)) { |
| 3379 | /* |
| 3380 | * The driver stores the segment count returned from pci_map_sg |
| 3381 | * because this a count of dma-mappings used to map the use_sg |
| 3382 | * pages. They are not guaranteed to be the same for those |
| 3383 | * architectures that implement an IOMMU. |
| 3384 | */ |
| 3385 | datasegcnt = dma_map_sg(&phba->pcidev->dev, |
| 3386 | scsi_sglist(scsi_cmnd), |
| 3387 | scsi_sg_count(scsi_cmnd), datadir); |
| 3388 | if (unlikely(!datasegcnt)) |
| 3389 | return 1; |
| 3390 | |
| 3391 | sgl += 1; |
| 3392 | /* clear the last flag in the fcp_rsp map entry */ |
| 3393 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 3394 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 3395 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 3396 | |
| 3397 | sgl += 1; |
| 3398 | lpfc_cmd->seg_cnt = datasegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3399 | |
| 3400 | /* First check if data segment count from SCSI Layer is good */ |
| 3401 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) |
| 3402 | goto err; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3403 | |
| 3404 | prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd); |
| 3405 | |
| 3406 | switch (prot_group_type) { |
| 3407 | case LPFC_PG_TYPE_NO_DIF: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3408 | /* Here we need to add a DISEED to the count */ |
| 3409 | if ((lpfc_cmd->seg_cnt + 1) > phba->cfg_total_seg_cnt) |
| 3410 | goto err; |
| 3411 | |
| 3412 | num_sge = lpfc_bg_setup_sgl(phba, scsi_cmnd, sgl, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3413 | datasegcnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3414 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3415 | /* we should have 2 or more entries in buffer list */ |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3416 | if (num_sge < 2) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3417 | goto err; |
| 3418 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3419 | |
| 3420 | case LPFC_PG_TYPE_DIF_BUF: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3421 | /* |
| 3422 | * This type indicates that protection buffers are |
| 3423 | * passed to the driver, so that needs to be prepared |
| 3424 | * for DMA |
| 3425 | */ |
| 3426 | protsegcnt = dma_map_sg(&phba->pcidev->dev, |
| 3427 | scsi_prot_sglist(scsi_cmnd), |
| 3428 | scsi_prot_sg_count(scsi_cmnd), datadir); |
| 3429 | if (unlikely(!protsegcnt)) { |
| 3430 | scsi_dma_unmap(scsi_cmnd); |
| 3431 | return 1; |
| 3432 | } |
| 3433 | |
| 3434 | lpfc_cmd->prot_seg_cnt = protsegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3435 | /* |
| 3436 | * There is a minimun of 3 SGEs used for every |
| 3437 | * protection data segment. |
| 3438 | */ |
| 3439 | if ((lpfc_cmd->prot_seg_cnt * 3) > |
| 3440 | (phba->cfg_total_seg_cnt - 2)) |
| 3441 | goto err; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3442 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3443 | num_sge = lpfc_bg_setup_sgl_prot(phba, scsi_cmnd, sgl, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3444 | datasegcnt, protsegcnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3445 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3446 | /* we should have 3 or more entries in buffer list */ |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3447 | if ((num_sge < 3) || |
| 3448 | (num_sge > phba->cfg_total_seg_cnt)) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3449 | goto err; |
| 3450 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3451 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3452 | case LPFC_PG_TYPE_INVALID: |
| 3453 | default: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3454 | scsi_dma_unmap(scsi_cmnd); |
| 3455 | lpfc_cmd->seg_cnt = 0; |
| 3456 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3457 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 3458 | "9083 Unexpected protection group %i\n", |
| 3459 | prot_group_type); |
| 3460 | return 1; |
| 3461 | } |
| 3462 | } |
| 3463 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 3464 | switch (scsi_get_prot_op(scsi_cmnd)) { |
| 3465 | case SCSI_PROT_WRITE_STRIP: |
| 3466 | case SCSI_PROT_READ_STRIP: |
| 3467 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_STRIP; |
| 3468 | break; |
| 3469 | case SCSI_PROT_WRITE_INSERT: |
| 3470 | case SCSI_PROT_READ_INSERT: |
| 3471 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_INSERT; |
| 3472 | break; |
| 3473 | case SCSI_PROT_WRITE_PASS: |
| 3474 | case SCSI_PROT_READ_PASS: |
| 3475 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_PASS; |
| 3476 | break; |
| 3477 | } |
| 3478 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3479 | fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3480 | fcp_cmnd->fcpDl = be32_to_cpu(fcpdl); |
| 3481 | |
| 3482 | /* |
| 3483 | * Due to difference in data length between DIF/non-DIF paths, |
| 3484 | * we need to set word 4 of IOCB here |
| 3485 | */ |
| 3486 | iocb_cmd->un.fcpi.fcpi_parm = fcpdl; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3487 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 3488 | /* |
| 3489 | * If the OAS driver feature is enabled and the lun is enabled for |
| 3490 | * OAS, set the oas iocb related flags. |
| 3491 | */ |
| 3492 | if ((phba->cfg_fof) && ((struct lpfc_device_data *) |
| 3493 | scsi_cmnd->device->hostdata)->oas_enabled) |
| 3494 | lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF); |
| 3495 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3496 | return 0; |
| 3497 | err: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3498 | if (lpfc_cmd->seg_cnt) |
| 3499 | scsi_dma_unmap(scsi_cmnd); |
| 3500 | if (lpfc_cmd->prot_seg_cnt) |
| 3501 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd), |
| 3502 | scsi_prot_sg_count(scsi_cmnd), |
| 3503 | scsi_cmnd->sc_data_direction); |
| 3504 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3505 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3506 | "9084 Cannot setup S/G List for HBA" |
| 3507 | "IO segs %d/%d SGL %d SCSI %d: %d %d\n", |
| 3508 | lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt, |
| 3509 | phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt, |
| 3510 | prot_group_type, num_sge); |
| 3511 | |
| 3512 | lpfc_cmd->seg_cnt = 0; |
| 3513 | lpfc_cmd->prot_seg_cnt = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3514 | return 1; |
| 3515 | } |
| 3516 | |
| 3517 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3518 | * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer |
| 3519 | * @phba: The Hba for which this call is being executed. |
| 3520 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3521 | * |
| 3522 | * This routine wraps the actual DMA mapping function pointer from the |
| 3523 | * lpfc_hba struct. |
| 3524 | * |
| 3525 | * Return codes: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 3526 | * 1 - Error |
| 3527 | * 0 - Success |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3528 | **/ |
| 3529 | static inline int |
| 3530 | lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 3531 | { |
| 3532 | return phba->lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 3533 | } |
| 3534 | |
| 3535 | /** |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3536 | * lpfc_bg_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer |
| 3537 | * using BlockGuard. |
| 3538 | * @phba: The Hba for which this call is being executed. |
| 3539 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3540 | * |
| 3541 | * This routine wraps the actual DMA mapping function pointer from the |
| 3542 | * lpfc_hba struct. |
| 3543 | * |
| 3544 | * Return codes: |
| 3545 | * 1 - Error |
| 3546 | * 0 - Success |
| 3547 | **/ |
| 3548 | static inline int |
| 3549 | lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 3550 | { |
| 3551 | return phba->lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 3552 | } |
| 3553 | |
| 3554 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3555 | * 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] | 3556 | * @phba: Pointer to hba context object. |
| 3557 | * @vport: Pointer to vport object. |
| 3558 | * @lpfc_cmd: Pointer to lpfc scsi command which reported the error. |
| 3559 | * @rsp_iocb: Pointer to response iocb object which reported error. |
| 3560 | * |
| 3561 | * This function posts an event when there is a SCSI command reporting |
| 3562 | * error from the scsi device. |
| 3563 | **/ |
| 3564 | static void |
| 3565 | lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 3566 | struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_iocbq *rsp_iocb) { |
| 3567 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 3568 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
| 3569 | uint32_t resp_info = fcprsp->rspStatus2; |
| 3570 | uint32_t scsi_status = fcprsp->rspStatus3; |
| 3571 | uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; |
| 3572 | struct lpfc_fast_path_event *fast_path_evt = NULL; |
| 3573 | struct lpfc_nodelist *pnode = lpfc_cmd->rdata->pnode; |
| 3574 | unsigned long flags; |
| 3575 | |
James Smart | 5989b8d | 2010-10-22 11:06:56 -0400 | [diff] [blame] | 3576 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 3577 | return; |
| 3578 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3579 | /* If there is queuefull or busy condition send a scsi event */ |
| 3580 | if ((cmnd->result == SAM_STAT_TASK_SET_FULL) || |
| 3581 | (cmnd->result == SAM_STAT_BUSY)) { |
| 3582 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3583 | if (!fast_path_evt) |
| 3584 | return; |
| 3585 | fast_path_evt->un.scsi_evt.event_type = |
| 3586 | FC_REG_SCSI_EVENT; |
| 3587 | fast_path_evt->un.scsi_evt.subcategory = |
| 3588 | (cmnd->result == SAM_STAT_TASK_SET_FULL) ? |
| 3589 | LPFC_EVENT_QFULL : LPFC_EVENT_DEVBSY; |
| 3590 | fast_path_evt->un.scsi_evt.lun = cmnd->device->lun; |
| 3591 | memcpy(&fast_path_evt->un.scsi_evt.wwpn, |
| 3592 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3593 | memcpy(&fast_path_evt->un.scsi_evt.wwnn, |
| 3594 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3595 | } else if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen && |
| 3596 | ((cmnd->cmnd[0] == READ_10) || (cmnd->cmnd[0] == WRITE_10))) { |
| 3597 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3598 | if (!fast_path_evt) |
| 3599 | return; |
| 3600 | fast_path_evt->un.check_cond_evt.scsi_event.event_type = |
| 3601 | FC_REG_SCSI_EVENT; |
| 3602 | fast_path_evt->un.check_cond_evt.scsi_event.subcategory = |
| 3603 | LPFC_EVENT_CHECK_COND; |
| 3604 | fast_path_evt->un.check_cond_evt.scsi_event.lun = |
| 3605 | cmnd->device->lun; |
| 3606 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwpn, |
| 3607 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3608 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwnn, |
| 3609 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3610 | fast_path_evt->un.check_cond_evt.sense_key = |
| 3611 | cmnd->sense_buffer[2] & 0xf; |
| 3612 | fast_path_evt->un.check_cond_evt.asc = cmnd->sense_buffer[12]; |
| 3613 | fast_path_evt->un.check_cond_evt.ascq = cmnd->sense_buffer[13]; |
| 3614 | } else if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) && |
| 3615 | fcpi_parm && |
| 3616 | ((be32_to_cpu(fcprsp->rspResId) != fcpi_parm) || |
| 3617 | ((scsi_status == SAM_STAT_GOOD) && |
| 3618 | !(resp_info & (RESID_UNDER | RESID_OVER))))) { |
| 3619 | /* |
| 3620 | * If status is good or resid does not match with fcp_param and |
| 3621 | * there is valid fcpi_parm, then there is a read_check error |
| 3622 | */ |
| 3623 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3624 | if (!fast_path_evt) |
| 3625 | return; |
| 3626 | fast_path_evt->un.read_check_error.header.event_type = |
| 3627 | FC_REG_FABRIC_EVENT; |
| 3628 | fast_path_evt->un.read_check_error.header.subcategory = |
| 3629 | LPFC_EVENT_FCPRDCHKERR; |
| 3630 | memcpy(&fast_path_evt->un.read_check_error.header.wwpn, |
| 3631 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3632 | memcpy(&fast_path_evt->un.read_check_error.header.wwnn, |
| 3633 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3634 | fast_path_evt->un.read_check_error.lun = cmnd->device->lun; |
| 3635 | fast_path_evt->un.read_check_error.opcode = cmnd->cmnd[0]; |
| 3636 | fast_path_evt->un.read_check_error.fcpiparam = |
| 3637 | fcpi_parm; |
| 3638 | } else |
| 3639 | return; |
| 3640 | |
| 3641 | fast_path_evt->vport = vport; |
| 3642 | spin_lock_irqsave(&phba->hbalock, flags); |
| 3643 | list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list); |
| 3644 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 3645 | lpfc_worker_wake_up(phba); |
| 3646 | return; |
| 3647 | } |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3648 | |
| 3649 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3650 | * 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] | 3651 | * @phba: The HBA for which this call is being executed. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3652 | * @psb: The scsi buffer which is going to be un-mapped. |
| 3653 | * |
| 3654 | * 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] | 3655 | * field of @lpfc_cmd for device with SLI-3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3656 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3657 | static void |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3658 | 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] | 3659 | { |
| 3660 | /* |
| 3661 | * There are only two special cases to consider. (1) the scsi command |
| 3662 | * requested scatter-gather usage or (2) the scsi command allocated |
| 3663 | * a request buffer, but did not request use_sg. There is a third |
| 3664 | * case, but it does not require resource deallocation. |
| 3665 | */ |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3666 | if (psb->seg_cnt > 0) |
| 3667 | scsi_dma_unmap(psb->pCmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3668 | if (psb->prot_seg_cnt > 0) |
| 3669 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(psb->pCmd), |
| 3670 | scsi_prot_sg_count(psb->pCmd), |
| 3671 | psb->pCmd->sc_data_direction); |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 3672 | } |
| 3673 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3674 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3675 | * lpfc_handler_fcp_err - FCP response handler |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3676 | * @vport: The virtual port for which this call is being executed. |
| 3677 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. |
| 3678 | * @rsp_iocb: The response IOCB which contains FCP error. |
| 3679 | * |
| 3680 | * This routine is called to process response IOCB with status field |
| 3681 | * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command |
| 3682 | * based upon SCSI and FCP error. |
| 3683 | **/ |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 3684 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3685 | lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd, |
| 3686 | struct lpfc_iocbq *rsp_iocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3687 | { |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3688 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3689 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 3690 | struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd; |
| 3691 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3692 | uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3693 | uint32_t resp_info = fcprsp->rspStatus2; |
| 3694 | uint32_t scsi_status = fcprsp->rspStatus3; |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3695 | uint32_t *lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3696 | uint32_t host_status = DID_OK; |
| 3697 | uint32_t rsplen = 0; |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3698 | uint32_t fcpDl; |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3699 | uint32_t logit = LOG_FCP | LOG_FCP_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3700 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3701 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3702 | /* |
| 3703 | * If this is a task management command, there is no |
| 3704 | * scsi packet associated with this lpfc_cmd. The driver |
| 3705 | * consumes it. |
| 3706 | */ |
| 3707 | if (fcpcmd->fcpCntl2) { |
| 3708 | scsi_status = 0; |
| 3709 | goto out; |
| 3710 | } |
| 3711 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3712 | if (resp_info & RSP_LEN_VALID) { |
| 3713 | rsplen = be32_to_cpu(fcprsp->rspRspLen); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3714 | if (rsplen != 0 && rsplen != 4 && rsplen != 8) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3715 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 3716 | "2719 Invalid response length: " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 3717 | "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] | 3718 | cmnd->device->id, |
| 3719 | cmnd->device->lun, cmnd->cmnd[0], |
| 3720 | rsplen); |
| 3721 | host_status = DID_ERROR; |
| 3722 | goto out; |
| 3723 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3724 | if (fcprsp->rspInfo3 != RSP_NO_FAILURE) { |
| 3725 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 3726 | "2757 Protocol failure detected during " |
| 3727 | "processing of FCP I/O op: " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 3728 | "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] | 3729 | cmnd->device->id, |
| 3730 | cmnd->device->lun, cmnd->cmnd[0], |
| 3731 | fcprsp->rspInfo3); |
| 3732 | host_status = DID_ERROR; |
| 3733 | goto out; |
| 3734 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3735 | } |
| 3736 | |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3737 | if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) { |
| 3738 | uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen); |
| 3739 | if (snslen > SCSI_SENSE_BUFFERSIZE) |
| 3740 | snslen = SCSI_SENSE_BUFFERSIZE; |
| 3741 | |
| 3742 | if (resp_info & RSP_LEN_VALID) |
| 3743 | rsplen = be32_to_cpu(fcprsp->rspRspLen); |
| 3744 | memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen); |
| 3745 | } |
| 3746 | lp = (uint32_t *)cmnd->sense_buffer; |
| 3747 | |
James Smart | aa1c7ee | 2012-08-14 14:26:06 -0400 | [diff] [blame] | 3748 | /* special handling for under run conditions */ |
| 3749 | if (!scsi_status && (resp_info & RESID_UNDER)) { |
| 3750 | /* don't log under runs if fcp set... */ |
| 3751 | if (vport->cfg_log_verbose & LOG_FCP) |
| 3752 | logit = LOG_FCP_ERROR; |
| 3753 | /* unless operator says so */ |
| 3754 | if (vport->cfg_log_verbose & LOG_FCP_UNDER) |
| 3755 | logit = LOG_FCP_UNDER; |
| 3756 | } |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3757 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3758 | lpfc_printf_vlog(vport, KERN_WARNING, logit, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3759 | "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] | 3760 | "Data: x%x x%x x%x x%x x%x\n", |
| 3761 | cmnd->cmnd[0], scsi_status, |
| 3762 | be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info, |
| 3763 | be32_to_cpu(fcprsp->rspResId), |
| 3764 | be32_to_cpu(fcprsp->rspSnsLen), |
| 3765 | be32_to_cpu(fcprsp->rspRspLen), |
| 3766 | fcprsp->rspInfo3); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3767 | |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3768 | scsi_set_resid(cmnd, 0); |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3769 | fcpDl = be32_to_cpu(fcpcmd->fcpDl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3770 | if (resp_info & RESID_UNDER) { |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3771 | scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3772 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3773 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_UNDER, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3774 | "9025 FCP Read Underrun, expected %d, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3775 | "residual %d Data: x%x x%x x%x\n", |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3776 | fcpDl, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3777 | scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0], |
| 3778 | cmnd->underflow); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3779 | |
| 3780 | /* |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3781 | * If there is an under run check if under run reported by |
| 3782 | * storage array is same as the under run reported by HBA. |
| 3783 | * If this is not same, there is a dropped frame. |
| 3784 | */ |
| 3785 | if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) && |
| 3786 | fcpi_parm && |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3787 | (scsi_get_resid(cmnd) != fcpi_parm)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3788 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 3789 | LOG_FCP | LOG_FCP_ERROR, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3790 | "9026 FCP Read Check Error " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3791 | "and Underrun Data: x%x x%x x%x x%x\n", |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3792 | fcpDl, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3793 | scsi_get_resid(cmnd), fcpi_parm, |
| 3794 | cmnd->cmnd[0]); |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3795 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3796 | host_status = DID_ERROR; |
| 3797 | } |
| 3798 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3799 | * The cmnd->underflow is the minimum number of bytes that must |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3800 | * be transferred for this command. Provided a sense condition |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3801 | * is not present, make sure the actual amount transferred is at |
| 3802 | * least the underflow value or fail. |
| 3803 | */ |
| 3804 | if (!(resp_info & SNS_LEN_VALID) && |
| 3805 | (scsi_status == SAM_STAT_GOOD) && |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3806 | (scsi_bufflen(cmnd) - scsi_get_resid(cmnd) |
| 3807 | < cmnd->underflow)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3808 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3809 | "9027 FCP command x%x residual " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3810 | "underrun converted to error " |
| 3811 | "Data: x%x x%x x%x\n", |
James Smart | 66dbfbe | 2007-08-05 06:08:38 -0400 | [diff] [blame] | 3812 | cmnd->cmnd[0], scsi_bufflen(cmnd), |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3813 | scsi_get_resid(cmnd), cmnd->underflow); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3814 | host_status = DID_ERROR; |
| 3815 | } |
| 3816 | } else if (resp_info & RESID_OVER) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3817 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3818 | "9028 FCP command x%x residual overrun error. " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 3819 | "Data: x%x x%x\n", cmnd->cmnd[0], |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3820 | scsi_bufflen(cmnd), scsi_get_resid(cmnd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3821 | host_status = DID_ERROR; |
| 3822 | |
| 3823 | /* |
| 3824 | * Check SLI validation that all the transfer was actually done |
James Smart | 26373d2 | 2013-09-06 12:19:17 -0400 | [diff] [blame] | 3825 | * (fcpi_parm should be zero). Apply check only to reads. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3826 | */ |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3827 | } else if (fcpi_parm) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3828 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR, |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3829 | "9029 FCP %s Check Error xri x%x Data: " |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 3830 | "x%x x%x x%x x%x x%x\n", |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3831 | ((cmnd->sc_data_direction == DMA_FROM_DEVICE) ? |
| 3832 | "Read" : "Write"), |
| 3833 | ((phba->sli_rev == LPFC_SLI_REV4) ? |
| 3834 | lpfc_cmd->cur_iocbq.sli4_xritag : |
| 3835 | rsp_iocb->iocb.ulpContext), |
| 3836 | fcpDl, be32_to_cpu(fcprsp->rspResId), |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 3837 | fcpi_parm, cmnd->cmnd[0], scsi_status); |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3838 | |
| 3839 | /* There is some issue with the LPe12000 that causes it |
| 3840 | * to miscalculate the fcpi_parm and falsely trip this |
| 3841 | * recovery logic. Detect this case and don't error when true. |
| 3842 | */ |
| 3843 | if (fcpi_parm > fcpDl) |
| 3844 | goto out; |
| 3845 | |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 3846 | switch (scsi_status) { |
| 3847 | case SAM_STAT_GOOD: |
| 3848 | case SAM_STAT_CHECK_CONDITION: |
| 3849 | /* Fabric dropped a data frame. Fail any successful |
| 3850 | * command in which we detected dropped frames. |
| 3851 | * A status of good or some check conditions could |
| 3852 | * be considered a successful command. |
| 3853 | */ |
| 3854 | host_status = DID_ERROR; |
| 3855 | break; |
| 3856 | } |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3857 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3858 | } |
| 3859 | |
| 3860 | out: |
| 3861 | cmnd->result = ScsiResult(host_status, scsi_status); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3862 | lpfc_send_scsi_error_event(vport->phba, vport, lpfc_cmd, rsp_iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3863 | } |
| 3864 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3865 | /** |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 3866 | * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution |
| 3867 | * @phba: Pointer to HBA context object. |
| 3868 | * |
| 3869 | * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index |
| 3870 | * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock |
| 3871 | * held. |
| 3872 | * If scsi-mq is enabled, get the default block layer mapping of software queues |
| 3873 | * to hardware queues. This information is saved in request tag. |
| 3874 | * |
| 3875 | * Return: index into SLI4 fast-path FCP queue index. |
| 3876 | **/ |
| 3877 | int lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba, |
| 3878 | struct lpfc_scsi_buf *lpfc_cmd) |
| 3879 | { |
| 3880 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 3881 | struct lpfc_vector_map_info *cpup; |
| 3882 | int chann, cpu; |
| 3883 | uint32_t tag; |
| 3884 | uint16_t hwq; |
| 3885 | |
Mauricio Faria de Oliveira | 05a0587 | 2016-06-07 20:13:08 -0300 | [diff] [blame] | 3886 | if (cmnd && shost_use_blk_mq(cmnd->device->host)) { |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 3887 | tag = blk_mq_unique_tag(cmnd->request); |
| 3888 | hwq = blk_mq_unique_tag_to_hwq(tag); |
| 3889 | |
| 3890 | return hwq; |
| 3891 | } |
| 3892 | |
| 3893 | if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_CPU |
| 3894 | && phba->cfg_fcp_io_channel > 1) { |
| 3895 | cpu = smp_processor_id(); |
| 3896 | if (cpu < phba->sli4_hba.num_present_cpu) { |
| 3897 | cpup = phba->sli4_hba.cpu_map; |
| 3898 | cpup += cpu; |
| 3899 | return cpup->channel_id; |
| 3900 | } |
| 3901 | } |
| 3902 | chann = atomic_add_return(1, &phba->fcp_qidx); |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 3903 | chann = chann % phba->cfg_fcp_io_channel; |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 3904 | return chann; |
| 3905 | } |
| 3906 | |
| 3907 | |
| 3908 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3909 | * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3910 | * @phba: The Hba for which this call is being executed. |
| 3911 | * @pIocbIn: The command IOCBQ for the scsi cmnd. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3912 | * @pIocbOut: The response IOCBQ for the scsi cmnd. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3913 | * |
| 3914 | * This routine assigns scsi command result by looking into response IOCB |
| 3915 | * status field appropriately. This routine handles QUEUE FULL condition as |
| 3916 | * well by ramping down device queue depth. |
| 3917 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3918 | static void |
| 3919 | lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn, |
| 3920 | struct lpfc_iocbq *pIocbOut) |
| 3921 | { |
| 3922 | struct lpfc_scsi_buf *lpfc_cmd = |
| 3923 | (struct lpfc_scsi_buf *) pIocbIn->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3924 | struct lpfc_vport *vport = pIocbIn->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3925 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| 3926 | struct lpfc_nodelist *pnode = rdata->pnode; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3927 | struct scsi_cmnd *cmd; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 3928 | int depth; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 3929 | unsigned long flags; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3930 | struct lpfc_fast_path_event *fast_path_evt; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3931 | struct Scsi_Host *shost; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3932 | uint32_t logit = LOG_FCP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3933 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3934 | phba->fc4ScsiIoCmpls++; |
| 3935 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3936 | /* Sanity check on return of outstanding command */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3937 | cmd = lpfc_cmd->pCmd; |
James Smart | c90261d | 2015-12-16 18:11:57 -0500 | [diff] [blame] | 3938 | if (!cmd) |
| 3939 | return; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3940 | shost = cmd->device->host; |
| 3941 | |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3942 | lpfc_cmd->result = (pIocbOut->iocb.un.ulpWord[4] & IOERR_PARAM_MASK); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3943 | lpfc_cmd->status = pIocbOut->iocb.ulpStatus; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3944 | /* pick up SLI4 exhange busy status from HBA */ |
| 3945 | lpfc_cmd->exch_busy = pIocbOut->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 3946 | |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 3947 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 3948 | if (lpfc_cmd->prot_data_type) { |
| 3949 | struct scsi_dif_tuple *src = NULL; |
| 3950 | |
| 3951 | src = (struct scsi_dif_tuple *)lpfc_cmd->prot_data_segment; |
| 3952 | /* |
| 3953 | * Used to restore any changes to protection |
| 3954 | * data for error injection. |
| 3955 | */ |
| 3956 | switch (lpfc_cmd->prot_data_type) { |
| 3957 | case LPFC_INJERR_REFTAG: |
| 3958 | src->ref_tag = |
| 3959 | lpfc_cmd->prot_data; |
| 3960 | break; |
| 3961 | case LPFC_INJERR_APPTAG: |
| 3962 | src->app_tag = |
| 3963 | (uint16_t)lpfc_cmd->prot_data; |
| 3964 | break; |
| 3965 | case LPFC_INJERR_GUARD: |
| 3966 | src->guard_tag = |
| 3967 | (uint16_t)lpfc_cmd->prot_data; |
| 3968 | break; |
| 3969 | default: |
| 3970 | break; |
| 3971 | } |
| 3972 | |
| 3973 | lpfc_cmd->prot_data = 0; |
| 3974 | lpfc_cmd->prot_data_type = 0; |
| 3975 | lpfc_cmd->prot_data_segment = NULL; |
| 3976 | } |
| 3977 | #endif |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 3978 | |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3979 | if (pnode && NLP_CHK_NODE_ACT(pnode)) |
| 3980 | atomic_dec(&pnode->cmd_pending); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3981 | |
| 3982 | if (lpfc_cmd->status) { |
| 3983 | if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT && |
| 3984 | (lpfc_cmd->result & IOERR_DRVR_MASK)) |
| 3985 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; |
| 3986 | else if (lpfc_cmd->status >= IOSTAT_CNT) |
| 3987 | lpfc_cmd->status = IOSTAT_DEFAULT; |
James Smart | aa1c7ee | 2012-08-14 14:26:06 -0400 | [diff] [blame] | 3988 | if (lpfc_cmd->status == IOSTAT_FCP_RSP_ERROR && |
| 3989 | !lpfc_cmd->fcp_rsp->rspStatus3 && |
| 3990 | (lpfc_cmd->fcp_rsp->rspStatus2 & RESID_UNDER) && |
| 3991 | !(vport->cfg_log_verbose & LOG_FCP_UNDER)) |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3992 | logit = 0; |
| 3993 | else |
| 3994 | logit = LOG_FCP | LOG_FCP_UNDER; |
| 3995 | lpfc_printf_vlog(vport, KERN_WARNING, logit, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 3996 | "9030 FCP cmd x%x failed <%d/%lld> " |
James Smart | 5a0d80f | 2012-05-09 21:18:20 -0400 | [diff] [blame] | 3997 | "status: x%x result: x%x " |
| 3998 | "sid: x%x did: x%x oxid: x%x " |
| 3999 | "Data: x%x x%x\n", |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 4000 | cmd->cmnd[0], |
| 4001 | cmd->device ? cmd->device->id : 0xffff, |
| 4002 | cmd->device ? cmd->device->lun : 0xffff, |
| 4003 | lpfc_cmd->status, lpfc_cmd->result, |
James Smart | 3bf41ba | 2013-05-31 17:03:18 -0400 | [diff] [blame] | 4004 | vport->fc_myDID, |
| 4005 | (pnode) ? pnode->nlp_DID : 0, |
James Smart | 5a0d80f | 2012-05-09 21:18:20 -0400 | [diff] [blame] | 4006 | phba->sli_rev == LPFC_SLI_REV4 ? |
| 4007 | lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 4008 | pIocbOut->iocb.ulpContext, |
| 4009 | lpfc_cmd->cur_iocbq.iocb.ulpIoTag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4010 | |
| 4011 | switch (lpfc_cmd->status) { |
| 4012 | case IOSTAT_FCP_RSP_ERROR: |
| 4013 | /* Call FCP RSP handler to determine result */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4014 | lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4015 | break; |
| 4016 | case IOSTAT_NPORT_BSY: |
| 4017 | case IOSTAT_FABRIC_BSY: |
James Smart | 0f1f53a | 2008-08-24 21:50:18 -0400 | [diff] [blame] | 4018 | cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 0); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4019 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 4020 | if (!fast_path_evt) |
| 4021 | break; |
| 4022 | fast_path_evt->un.fabric_evt.event_type = |
| 4023 | FC_REG_FABRIC_EVENT; |
| 4024 | fast_path_evt->un.fabric_evt.subcategory = |
| 4025 | (lpfc_cmd->status == IOSTAT_NPORT_BSY) ? |
| 4026 | LPFC_EVENT_PORT_BUSY : LPFC_EVENT_FABRIC_BUSY; |
| 4027 | if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
| 4028 | memcpy(&fast_path_evt->un.fabric_evt.wwpn, |
| 4029 | &pnode->nlp_portname, |
| 4030 | sizeof(struct lpfc_name)); |
| 4031 | memcpy(&fast_path_evt->un.fabric_evt.wwnn, |
| 4032 | &pnode->nlp_nodename, |
| 4033 | sizeof(struct lpfc_name)); |
| 4034 | } |
| 4035 | fast_path_evt->vport = vport; |
| 4036 | fast_path_evt->work_evt.evt = |
| 4037 | LPFC_EVT_FASTPATH_MGMT_EVT; |
| 4038 | spin_lock_irqsave(&phba->hbalock, flags); |
| 4039 | list_add_tail(&fast_path_evt->work_evt.evt_listp, |
| 4040 | &phba->work_list); |
| 4041 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4042 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4043 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4044 | case IOSTAT_LOCAL_REJECT: |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4045 | case IOSTAT_REMOTE_STOP: |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 4046 | if (lpfc_cmd->result == IOERR_ELXSEC_KEY_UNWRAP_ERROR || |
| 4047 | lpfc_cmd->result == |
| 4048 | IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR || |
| 4049 | lpfc_cmd->result == IOERR_ELXSEC_CRYPTO_ERROR || |
| 4050 | lpfc_cmd->result == |
| 4051 | IOERR_ELXSEC_CRYPTO_COMPARE_ERROR) { |
| 4052 | cmd->result = ScsiResult(DID_NO_CONNECT, 0); |
| 4053 | break; |
| 4054 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4055 | if (lpfc_cmd->result == IOERR_INVALID_RPI || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4056 | lpfc_cmd->result == IOERR_NO_RESOURCES || |
James Smart | b92938b | 2010-06-07 15:24:12 -0400 | [diff] [blame] | 4057 | lpfc_cmd->result == IOERR_ABORT_REQUESTED || |
| 4058 | lpfc_cmd->result == IOERR_SLER_CMD_RCV_FAILURE) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4059 | cmd->result = ScsiResult(DID_REQUEUE, 0); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4060 | break; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4061 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4062 | if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED || |
| 4063 | lpfc_cmd->result == IOERR_TX_DMA_FAILED) && |
| 4064 | pIocbOut->iocb.unsli3.sli3_bg.bgstat) { |
| 4065 | if (scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) { |
| 4066 | /* |
| 4067 | * This is a response for a BG enabled |
| 4068 | * cmd. Parse BG error |
| 4069 | */ |
| 4070 | lpfc_parse_bg_err(phba, lpfc_cmd, |
| 4071 | pIocbOut); |
| 4072 | break; |
| 4073 | } else { |
| 4074 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 4075 | LOG_BG, |
| 4076 | "9031 non-zero BGSTAT " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4077 | "on unprotected cmd\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4078 | } |
| 4079 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4080 | if ((lpfc_cmd->status == IOSTAT_REMOTE_STOP) |
| 4081 | && (phba->sli_rev == LPFC_SLI_REV4) |
| 4082 | && (pnode && NLP_CHK_NODE_ACT(pnode))) { |
| 4083 | /* This IO was aborted by the target, we don't |
| 4084 | * know the rxid and because we did not send the |
| 4085 | * ABTS we cannot generate and RRQ. |
| 4086 | */ |
| 4087 | lpfc_set_rrq_active(phba, pnode, |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 4088 | lpfc_cmd->cur_iocbq.sli4_lxritag, |
| 4089 | 0, 0); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4090 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4091 | /* else: fall through */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4092 | default: |
| 4093 | cmd->result = ScsiResult(DID_ERROR, 0); |
| 4094 | break; |
| 4095 | } |
| 4096 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4097 | if (!pnode || !NLP_CHK_NODE_ACT(pnode) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4098 | || (pnode->nlp_state != NLP_STE_MAPPED_NODE)) |
James Smart | 0f1f53a | 2008-08-24 21:50:18 -0400 | [diff] [blame] | 4099 | cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, |
| 4100 | SAM_STAT_BUSY); |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 4101 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4102 | cmd->result = ScsiResult(DID_OK, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4103 | |
| 4104 | if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) { |
| 4105 | uint32_t *lp = (uint32_t *)cmd->sense_buffer; |
| 4106 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4107 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4108 | "0710 Iodone <%d/%llu> cmd %p, error " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4109 | "x%x SNS x%x x%x Data: x%x x%x\n", |
| 4110 | cmd->device->id, cmd->device->lun, cmd, |
| 4111 | cmd->result, *lp, *(lp + 3), cmd->retries, |
| 4112 | scsi_get_resid(cmd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4113 | } |
| 4114 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4115 | lpfc_update_stats(phba, lpfc_cmd); |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4116 | if (vport->cfg_max_scsicmpl_time && |
| 4117 | time_after(jiffies, lpfc_cmd->start_time + |
| 4118 | msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4119 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4120 | if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
| 4121 | if (pnode->cmd_qdepth > |
| 4122 | atomic_read(&pnode->cmd_pending) && |
| 4123 | (atomic_read(&pnode->cmd_pending) > |
| 4124 | LPFC_MIN_TGT_QDEPTH) && |
| 4125 | ((cmd->cmnd[0] == READ_10) || |
| 4126 | (cmd->cmnd[0] == WRITE_10))) |
| 4127 | pnode->cmd_qdepth = |
| 4128 | atomic_read(&pnode->cmd_pending); |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4129 | |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4130 | pnode->last_change_time = jiffies; |
| 4131 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4132 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4133 | } else if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 4134 | if ((pnode->cmd_qdepth < vport->cfg_tgt_queue_depth) && |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4135 | time_after(jiffies, pnode->last_change_time + |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4136 | msecs_to_jiffies(LPFC_TGTQ_INTERVAL))) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4137 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 4138 | depth = pnode->cmd_qdepth * LPFC_TGTQ_RAMPUP_PCENT |
| 4139 | / 100; |
| 4140 | depth = depth ? depth : 1; |
| 4141 | pnode->cmd_qdepth += depth; |
| 4142 | if (pnode->cmd_qdepth > vport->cfg_tgt_queue_depth) |
| 4143 | pnode->cmd_qdepth = vport->cfg_tgt_queue_depth; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4144 | pnode->last_change_time = jiffies; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4145 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4146 | } |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4147 | } |
| 4148 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4149 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4150 | |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4151 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92e3af6 | 2012-08-14 14:26:28 -0400 | [diff] [blame] | 4152 | lpfc_cmd->pCmd = NULL; |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4153 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92e3af6 | 2012-08-14 14:26:28 -0400 | [diff] [blame] | 4154 | |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 4155 | /* The sdev is not guaranteed to be valid post scsi_done upcall. */ |
| 4156 | cmd->scsi_done(cmd); |
| 4157 | |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4158 | /* |
| 4159 | * If there is a thread waiting for command completion |
| 4160 | * wake up the thread. |
| 4161 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4162 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4163 | if (lpfc_cmd->waitq) |
| 4164 | wake_up(lpfc_cmd->waitq); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4165 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4166 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4167 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4168 | } |
| 4169 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4170 | /** |
Alexey Kardashevskiy | 8b2564e | 2015-04-28 18:26:22 +1000 | [diff] [blame] | 4171 | * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB |
| 4172 | * @data: A pointer to the immediate command data portion of the IOCB. |
| 4173 | * @fcp_cmnd: The FCP Command that is provided by the SCSI layer. |
| 4174 | * |
| 4175 | * The routine copies the entire FCP command from @fcp_cmnd to @data while |
| 4176 | * byte swapping the data to big endian format for transmission on the wire. |
| 4177 | **/ |
| 4178 | static void |
| 4179 | lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd) |
| 4180 | { |
| 4181 | int i, j; |
| 4182 | for (i = 0, j = 0; i < sizeof(struct fcp_cmnd); |
| 4183 | i += sizeof(uint32_t), j++) { |
| 4184 | ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]); |
| 4185 | } |
| 4186 | } |
| 4187 | |
| 4188 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4189 | * 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] | 4190 | * @vport: The virtual port for which this call is being executed. |
| 4191 | * @lpfc_cmd: The scsi command which needs to send. |
| 4192 | * @pnode: Pointer to lpfc_nodelist. |
| 4193 | * |
| 4194 | * This routine initializes fcp_cmnd and iocb data structure from scsi command |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4195 | * to transfer for device with SLI3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4196 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4197 | static void |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4198 | 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] | 4199 | struct lpfc_nodelist *pnode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4200 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4201 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4202 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 4203 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 4204 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 4205 | struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq); |
| 4206 | int datadir = scsi_cmnd->sc_data_direction; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4207 | uint8_t *ptr; |
| 4208 | bool sli4; |
James Smart | 98bbf5f | 2013-09-06 12:18:45 -0400 | [diff] [blame] | 4209 | uint32_t fcpdl; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4210 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4211 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 4212 | return; |
| 4213 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4214 | lpfc_cmd->fcp_rsp->rspSnsLen = 0; |
James.Smart@Emulex.Com | 69859dc | 2005-08-10 15:02:37 -0400 | [diff] [blame] | 4215 | /* clear task management bits */ |
| 4216 | lpfc_cmd->fcp_cmnd->fcpCntl2 = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4217 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 4218 | int_to_scsilun(lpfc_cmd->pCmd->device->lun, |
| 4219 | &lpfc_cmd->fcp_cmnd->fcp_lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4220 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4221 | ptr = &fcp_cmnd->fcpCdb[0]; |
| 4222 | memcpy(ptr, scsi_cmnd->cmnd, scsi_cmnd->cmd_len); |
| 4223 | if (scsi_cmnd->cmd_len < LPFC_FCP_CDB_LEN) { |
| 4224 | ptr += scsi_cmnd->cmd_len; |
| 4225 | memset(ptr, 0, (LPFC_FCP_CDB_LEN - scsi_cmnd->cmd_len)); |
| 4226 | } |
| 4227 | |
Christoph Hellwig | 5066863 | 2014-10-30 14:30:06 +0100 | [diff] [blame] | 4228 | fcp_cmnd->fcpCntl1 = SIMPLE_Q; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4229 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4230 | sli4 = (phba->sli_rev == LPFC_SLI_REV4); |
James Smart | 6acb348 | 2014-04-04 13:51:25 -0400 | [diff] [blame] | 4231 | piocbq->iocb.un.fcpi.fcpi_XRdy = 0; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4232 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4233 | /* |
| 4234 | * There are three possibilities here - use scatter-gather segment, use |
| 4235 | * the single mapping, or neither. Start the lpfc command prep by |
| 4236 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 4237 | * data bde entry. |
| 4238 | */ |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4239 | if (scsi_sg_count(scsi_cmnd)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4240 | if (datadir == DMA_TO_DEVICE) { |
| 4241 | iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR; |
James Smart | 182ba75 | 2013-07-15 18:34:05 -0400 | [diff] [blame] | 4242 | iocb_cmd->ulpPU = PARM_READ_CHECK; |
James Smart | 3cb01c5 | 2013-07-15 18:35:04 -0400 | [diff] [blame] | 4243 | if (vport->cfg_first_burst_size && |
| 4244 | (pnode->nlp_flag & NLP_FIRSTBURST)) { |
James Smart | 98bbf5f | 2013-09-06 12:18:45 -0400 | [diff] [blame] | 4245 | fcpdl = scsi_bufflen(scsi_cmnd); |
| 4246 | if (fcpdl < vport->cfg_first_burst_size) |
| 4247 | piocbq->iocb.un.fcpi.fcpi_XRdy = fcpdl; |
| 4248 | else |
| 4249 | piocbq->iocb.un.fcpi.fcpi_XRdy = |
| 4250 | vport->cfg_first_burst_size; |
James Smart | 3cb01c5 | 2013-07-15 18:35:04 -0400 | [diff] [blame] | 4251 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4252 | fcp_cmnd->fcpCntl3 = WRITE_DATA; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4253 | phba->fc4ScsiOutputRequests++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4254 | } else { |
| 4255 | iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR; |
| 4256 | iocb_cmd->ulpPU = PARM_READ_CHECK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4257 | fcp_cmnd->fcpCntl3 = READ_DATA; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4258 | phba->fc4ScsiInputRequests++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4259 | } |
| 4260 | } else { |
| 4261 | iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR; |
| 4262 | iocb_cmd->un.fcpi.fcpi_parm = 0; |
| 4263 | iocb_cmd->ulpPU = 0; |
| 4264 | fcp_cmnd->fcpCntl3 = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4265 | phba->fc4ScsiControlRequests++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4266 | } |
Alexey Kardashevskiy | 8b2564e | 2015-04-28 18:26:22 +1000 | [diff] [blame] | 4267 | if (phba->sli_rev == 3 && |
| 4268 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) |
| 4269 | lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4270 | /* |
| 4271 | * Finish initializing those IOCB fields that are independent |
| 4272 | * of the scsi_cmnd request_buffer |
| 4273 | */ |
| 4274 | piocbq->iocb.ulpContext = pnode->nlp_rpi; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4275 | if (sli4) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4276 | piocbq->iocb.ulpContext = |
| 4277 | phba->sli4_hba.rpi_ids[pnode->nlp_rpi]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4278 | if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE) |
| 4279 | piocbq->iocb.ulpFCP2Rcvy = 1; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4280 | else |
| 4281 | piocbq->iocb.ulpFCP2Rcvy = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4282 | |
| 4283 | piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f); |
| 4284 | piocbq->context1 = lpfc_cmd; |
| 4285 | piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; |
| 4286 | piocbq->iocb.ulpTimeout = lpfc_cmd->timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4287 | piocbq->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4288 | } |
| 4289 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4290 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4291 | * 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] | 4292 | * @vport: The virtual port for which this call is being executed. |
| 4293 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. |
| 4294 | * @lun: Logical unit number. |
| 4295 | * @task_mgmt_cmd: SCSI task management command. |
| 4296 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4297 | * This routine creates FCP information unit corresponding to @task_mgmt_cmd |
| 4298 | * for device with SLI-3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4299 | * |
| 4300 | * Return codes: |
| 4301 | * 0 - Error |
| 4302 | * 1 - Success |
| 4303 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4304 | static int |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4305 | lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4306 | struct lpfc_scsi_buf *lpfc_cmd, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4307 | uint64_t lun, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4308 | uint8_t task_mgmt_cmd) |
| 4309 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4310 | struct lpfc_iocbq *piocbq; |
| 4311 | IOCB_t *piocb; |
| 4312 | struct fcp_cmnd *fcp_cmnd; |
James Smart | 0b18ac4 | 2006-05-01 21:50:40 -0400 | [diff] [blame] | 4313 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4314 | struct lpfc_nodelist *ndlp = rdata->pnode; |
| 4315 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4316 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || |
| 4317 | ndlp->nlp_state != NLP_STE_MAPPED_NODE) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4318 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4319 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4320 | piocbq = &(lpfc_cmd->cur_iocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4321 | piocbq->vport = vport; |
| 4322 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4323 | piocb = &piocbq->iocb; |
| 4324 | |
| 4325 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4326 | /* Clear out any old data in the FCP command area */ |
| 4327 | memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd)); |
| 4328 | int_to_scsilun(lun, &fcp_cmnd->fcp_lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4329 | fcp_cmnd->fcpCntl2 = task_mgmt_cmd; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4330 | if (vport->phba->sli_rev == 3 && |
| 4331 | !(vport->phba->sli3_options & LPFC_SLI3_BG_ENABLED)) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4332 | lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4333 | piocb->ulpCommand = CMD_FCP_ICMND64_CR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4334 | piocb->ulpContext = ndlp->nlp_rpi; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4335 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
| 4336 | piocb->ulpContext = |
| 4337 | vport->phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
| 4338 | } |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 4339 | piocb->ulpFCP2Rcvy = (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) ? 1 : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4340 | piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f); |
James Smart | f9226c2 | 2014-02-20 09:57:28 -0500 | [diff] [blame] | 4341 | piocb->ulpPU = 0; |
| 4342 | piocb->un.fcpi.fcpi_parm = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4343 | |
| 4344 | /* ulpTimeout is only one byte */ |
| 4345 | if (lpfc_cmd->timeout > 0xff) { |
| 4346 | /* |
| 4347 | * Do not timeout the command at the firmware level. |
| 4348 | * The driver will provide the timeout mechanism. |
| 4349 | */ |
| 4350 | piocb->ulpTimeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4351 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4352 | piocb->ulpTimeout = lpfc_cmd->timeout; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4353 | |
| 4354 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 4355 | lpfc_sli4_set_rsp_sgl_last(vport->phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4356 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4357 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4358 | } |
| 4359 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4360 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4361 | * lpfc_scsi_api_table_setup - Set up scsi api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4362 | * @phba: The hba struct for which this call is being executed. |
| 4363 | * @dev_grp: The HBA PCI-Device group number. |
| 4364 | * |
| 4365 | * This routine sets up the SCSI interface API function jump table in @phba |
| 4366 | * struct. |
| 4367 | * Returns: 0 - success, -ENODEV - failure. |
| 4368 | **/ |
| 4369 | int |
| 4370 | lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 4371 | { |
| 4372 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4373 | phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf; |
| 4374 | phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4375 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4376 | switch (dev_grp) { |
| 4377 | case LPFC_PCI_DEV_LP: |
| 4378 | phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s3; |
| 4379 | phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4380 | 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] | 4381 | phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4382 | phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s3; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4383 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4384 | case LPFC_PCI_DEV_OC: |
| 4385 | phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s4; |
| 4386 | phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s4; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4387 | 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] | 4388 | phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s4; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4389 | phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s4; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4390 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4391 | default: |
| 4392 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4393 | "1418 Invalid HBA PCI-device group: 0x%x\n", |
| 4394 | dev_grp); |
| 4395 | return -ENODEV; |
| 4396 | break; |
| 4397 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4398 | phba->lpfc_rampdown_queue_depth = lpfc_rampdown_queue_depth; |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 4399 | phba->lpfc_scsi_cmd_iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4400 | return 0; |
| 4401 | } |
| 4402 | |
| 4403 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4404 | * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4405 | * @phba: The Hba for which this call is being executed. |
| 4406 | * @cmdiocbq: Pointer to lpfc_iocbq data structure. |
| 4407 | * @rspiocbq: Pointer to lpfc_iocbq data structure. |
| 4408 | * |
| 4409 | * This routine is IOCB completion routine for device reset and target reset |
| 4410 | * routine. This routine release scsi buffer associated with lpfc_cmd. |
| 4411 | **/ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4412 | static void |
| 4413 | lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba, |
| 4414 | struct lpfc_iocbq *cmdiocbq, |
| 4415 | struct lpfc_iocbq *rspiocbq) |
| 4416 | { |
| 4417 | struct lpfc_scsi_buf *lpfc_cmd = |
| 4418 | (struct lpfc_scsi_buf *) cmdiocbq->context1; |
| 4419 | if (lpfc_cmd) |
| 4420 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 4421 | return; |
| 4422 | } |
| 4423 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4424 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4425 | * lpfc_info - Info entry point of scsi_host_template data structure |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4426 | * @host: The scsi host for which this call is being executed. |
| 4427 | * |
| 4428 | * This routine provides module information about hba. |
| 4429 | * |
| 4430 | * Reutrn code: |
| 4431 | * Pointer to char - Success. |
| 4432 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4433 | const char * |
| 4434 | lpfc_info(struct Scsi_Host *host) |
| 4435 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4436 | struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata; |
| 4437 | struct lpfc_hba *phba = vport->phba; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4438 | int len, link_speed = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4439 | static char lpfcinfobuf[384]; |
| 4440 | |
| 4441 | memset(lpfcinfobuf,0,384); |
| 4442 | if (phba && phba->pcidev){ |
| 4443 | strncpy(lpfcinfobuf, phba->ModelDesc, 256); |
| 4444 | len = strlen(lpfcinfobuf); |
| 4445 | snprintf(lpfcinfobuf + len, |
| 4446 | 384-len, |
| 4447 | " on PCI bus %02x device %02x irq %d", |
| 4448 | phba->pcidev->bus->number, |
| 4449 | phba->pcidev->devfn, |
| 4450 | phba->pcidev->irq); |
| 4451 | len = strlen(lpfcinfobuf); |
| 4452 | if (phba->Port[0]) { |
| 4453 | snprintf(lpfcinfobuf + len, |
| 4454 | 384-len, |
| 4455 | " port %s", |
| 4456 | phba->Port); |
| 4457 | } |
James Smart | 65467b6 | 2010-01-26 23:08:29 -0500 | [diff] [blame] | 4458 | len = strlen(lpfcinfobuf); |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 4459 | link_speed = lpfc_sli_port_speed_get(phba); |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4460 | if (link_speed != 0) |
| 4461 | snprintf(lpfcinfobuf + len, 384-len, |
| 4462 | " Logical Link Speed: %d Mbps", link_speed); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4463 | } |
| 4464 | return lpfcinfobuf; |
| 4465 | } |
| 4466 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4467 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4468 | * lpfc_poll_rearm_time - Routine to modify fcp_poll timer of hba |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4469 | * @phba: The Hba for which this call is being executed. |
| 4470 | * |
| 4471 | * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo. |
| 4472 | * The default value of cfg_poll_tmo is 10 milliseconds. |
| 4473 | **/ |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4474 | static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba) |
| 4475 | { |
| 4476 | unsigned long poll_tmo_expires = |
| 4477 | (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo)); |
| 4478 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4479 | 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] | 4480 | mod_timer(&phba->fcp_poll_timer, |
| 4481 | poll_tmo_expires); |
| 4482 | } |
| 4483 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4484 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4485 | * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4486 | * @phba: The Hba for which this call is being executed. |
| 4487 | * |
| 4488 | * This routine starts the fcp_poll_timer of @phba. |
| 4489 | **/ |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4490 | void lpfc_poll_start_timer(struct lpfc_hba * phba) |
| 4491 | { |
| 4492 | lpfc_poll_rearm_timer(phba); |
| 4493 | } |
| 4494 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4495 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4496 | * lpfc_poll_timeout - Restart polling timer |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4497 | * @ptr: Map to lpfc_hba data structure pointer. |
| 4498 | * |
| 4499 | * This routine restarts fcp_poll timer, when FCP ring polling is enable |
| 4500 | * and FCP Ring interrupt is disable. |
| 4501 | **/ |
| 4502 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4503 | void lpfc_poll_timeout(unsigned long ptr) |
| 4504 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4505 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4506 | |
| 4507 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4508 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4509 | &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4510 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4511 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 4512 | lpfc_poll_rearm_timer(phba); |
| 4513 | } |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4514 | } |
| 4515 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4516 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4517 | * lpfc_queuecommand - scsi_host_template queuecommand entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4518 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 4519 | * @done: Pointer to done routine. |
| 4520 | * |
| 4521 | * Driver registers this routine to scsi midlayer to submit a @cmd to process. |
| 4522 | * This routine prepares an IOCB from scsi command and provides to firmware. |
| 4523 | * The @done callback is invoked after driver finished processing the command. |
| 4524 | * |
| 4525 | * Return value : |
| 4526 | * 0 - Success |
| 4527 | * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily. |
| 4528 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4529 | static int |
James Smart | b9a7c63 | 2012-08-03 12:35:24 -0400 | [diff] [blame] | 4530 | lpfc_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4531 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4532 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4533 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 4534 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 4535 | struct lpfc_nodelist *ndlp; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4536 | struct lpfc_scsi_buf *lpfc_cmd; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4537 | 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] | 4538 | int err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4539 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 4540 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4541 | err = fc_remote_port_chkready(rport); |
| 4542 | if (err) { |
| 4543 | cmnd->result = err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4544 | goto out_fail_command; |
| 4545 | } |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 4546 | ndlp = rdata->pnode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4547 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 4548 | if ((scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) && |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4549 | (!(phba->sli3_options & LPFC_SLI3_BG_ENABLED))) { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4550 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4551 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 4552 | "9058 BLKGRD: ERROR: rcvd protected cmd:%02x" |
| 4553 | " op:%02x str=%s without registering for" |
| 4554 | " BlockGuard - Rejecting command\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4555 | cmnd->cmnd[0], scsi_get_prot_op(cmnd), |
| 4556 | dif_op_str[scsi_get_prot_op(cmnd)]); |
| 4557 | goto out_fail_command; |
| 4558 | } |
| 4559 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4560 | /* |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4561 | * Catch race where our node has transitioned, but the |
| 4562 | * transport is still transitioning. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4563 | */ |
James Smart | 6b415f5 | 2012-06-12 13:54:59 -0400 | [diff] [blame] | 4564 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 4565 | goto out_tgt_busy; |
James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 4566 | if (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth) |
Mike Christie | 3496343 | 2011-02-25 14:04:28 -0600 | [diff] [blame] | 4567 | goto out_tgt_busy; |
Mike Christie | a93ce02 | 2008-08-17 15:24:41 -0500 | [diff] [blame] | 4568 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4569 | lpfc_cmd = lpfc_get_scsi_buf(phba, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4570 | if (lpfc_cmd == NULL) { |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4571 | lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4572 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4573 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_ERROR, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4574 | "0707 driver's buffer pool is empty, " |
| 4575 | "IO busied\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4576 | goto out_host_busy; |
| 4577 | } |
| 4578 | |
| 4579 | /* |
| 4580 | * Store the midlayer's command structure for the completion phase |
| 4581 | * and complete the command initialization. |
| 4582 | */ |
| 4583 | lpfc_cmd->pCmd = cmnd; |
| 4584 | lpfc_cmd->rdata = rdata; |
| 4585 | lpfc_cmd->timeout = 0; |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4586 | lpfc_cmd->start_time = jiffies; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4587 | cmnd->host_scribble = (unsigned char *)lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4588 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4589 | if (scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4590 | if (vport->phba->cfg_enable_bg) { |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 4591 | lpfc_printf_vlog(vport, |
| 4592 | KERN_INFO, LOG_SCSI_CMD, |
James Smart | 2613470 | 2012-08-14 14:25:50 -0400 | [diff] [blame] | 4593 | "9033 BLKGRD: rcvd %s cmd:x%x " |
| 4594 | "sector x%llx cnt %u pt %x\n", |
| 4595 | dif_op_str[scsi_get_prot_op(cmnd)], |
| 4596 | cmnd->cmnd[0], |
| 4597 | (unsigned long long)scsi_get_lba(cmnd), |
| 4598 | blk_rq_sectors(cmnd->request), |
| 4599 | (cmnd->cmnd[1]>>5)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4600 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4601 | err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 4602 | } else { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4603 | if (vport->phba->cfg_enable_bg) { |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 4604 | lpfc_printf_vlog(vport, |
| 4605 | KERN_INFO, LOG_SCSI_CMD, |
James Smart | 2613470 | 2012-08-14 14:25:50 -0400 | [diff] [blame] | 4606 | "9038 BLKGRD: rcvd PROT_NORMAL cmd: " |
| 4607 | "x%x sector x%llx cnt %u pt %x\n", |
| 4608 | cmnd->cmnd[0], |
| 4609 | (unsigned long long)scsi_get_lba(cmnd), |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 4610 | blk_rq_sectors(cmnd->request), |
James Smart | 2613470 | 2012-08-14 14:25:50 -0400 | [diff] [blame] | 4611 | (cmnd->cmnd[1]>>5)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4612 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4613 | err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 4614 | } |
| 4615 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4616 | if (err) |
| 4617 | goto out_host_busy_free_buf; |
| 4618 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4619 | lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4620 | |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4621 | atomic_inc(&ndlp->cmd_pending); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4622 | err = lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4623 | &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4624 | if (err) { |
| 4625 | atomic_dec(&ndlp->cmd_pending); |
James Smart | 76f96b6 | 2013-12-17 20:29:01 -0500 | [diff] [blame] | 4626 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4627 | "3376 FCP could not issue IOCB err %x" |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4628 | "FCP cmd x%x <%d/%llu> " |
James Smart | 76f96b6 | 2013-12-17 20:29:01 -0500 | [diff] [blame] | 4629 | "sid: x%x did: x%x oxid: x%x " |
| 4630 | "Data: x%x x%x x%x x%x\n", |
| 4631 | err, cmnd->cmnd[0], |
| 4632 | cmnd->device ? cmnd->device->id : 0xffff, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4633 | cmnd->device ? cmnd->device->lun : (u64) -1, |
James Smart | 76f96b6 | 2013-12-17 20:29:01 -0500 | [diff] [blame] | 4634 | vport->fc_myDID, ndlp->nlp_DID, |
| 4635 | phba->sli_rev == LPFC_SLI_REV4 ? |
| 4636 | lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff, |
| 4637 | lpfc_cmd->cur_iocbq.iocb.ulpContext, |
| 4638 | lpfc_cmd->cur_iocbq.iocb.ulpIoTag, |
| 4639 | lpfc_cmd->cur_iocbq.iocb.ulpTimeout, |
| 4640 | (uint32_t) |
| 4641 | (cmnd->request->timeout / 1000)); |
| 4642 | |
| 4643 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4644 | goto out_host_busy_free_buf; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4645 | } |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4646 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4647 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4648 | &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4649 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4650 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 4651 | lpfc_poll_rearm_timer(phba); |
| 4652 | } |
| 4653 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4654 | return 0; |
| 4655 | |
| 4656 | out_host_busy_free_buf: |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 4657 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4658 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4659 | out_host_busy: |
| 4660 | return SCSI_MLQUEUE_HOST_BUSY; |
| 4661 | |
Mike Christie | 3496343 | 2011-02-25 14:04:28 -0600 | [diff] [blame] | 4662 | out_tgt_busy: |
| 4663 | return SCSI_MLQUEUE_TARGET_BUSY; |
| 4664 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4665 | out_fail_command: |
James Smart | b9a7c63 | 2012-08-03 12:35:24 -0400 | [diff] [blame] | 4666 | cmnd->scsi_done(cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4667 | return 0; |
| 4668 | } |
| 4669 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 4670 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4671 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4672 | * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4673 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 4674 | * |
| 4675 | * This routine aborts @cmnd pending in base driver. |
| 4676 | * |
| 4677 | * Return code : |
| 4678 | * 0x2003 - Error |
| 4679 | * 0x2002 - Success |
| 4680 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4681 | static int |
James.Smart@Emulex.Com | 63c59c3 | 2005-11-28 11:41:53 -0500 | [diff] [blame] | 4682 | lpfc_abort_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4683 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4684 | struct Scsi_Host *shost = cmnd->device->host; |
| 4685 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4686 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4687 | struct lpfc_iocbq *iocb; |
| 4688 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4689 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4690 | IOCB_t *cmd, *icmd; |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4691 | int ret = SUCCESS, status = 0; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4692 | struct lpfc_sli_ring *pring_s4; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4693 | int ret_val; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4694 | unsigned long flags, iflags; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4695 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4696 | |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4697 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 4698 | if (status != 0 && status != SUCCESS) |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4699 | return status; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4700 | |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4701 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4702 | /* driver queued commands are in process of being flushed */ |
| 4703 | if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) { |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4704 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4705 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4706 | "3168 SCSI Layer abort requested I/O has been " |
| 4707 | "flushed by LLD.\n"); |
| 4708 | return FAILED; |
| 4709 | } |
| 4710 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4711 | lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble; |
James Smart | 92e3af6 | 2012-08-14 14:26:28 -0400 | [diff] [blame] | 4712 | if (!lpfc_cmd || !lpfc_cmd->pCmd) { |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4713 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 4714 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4715 | "2873 SCSI Layer I/O Abort Request IO CMPL Status " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4716 | "x%x ID %d LUN %llu\n", |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4717 | SUCCESS, cmnd->device->id, cmnd->device->lun); |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 4718 | return SUCCESS; |
| 4719 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4720 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4721 | iocb = &lpfc_cmd->cur_iocbq; |
| 4722 | /* the command is in process of being cancelled */ |
| 4723 | if (!(iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ)) { |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4724 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4725 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4726 | "3169 SCSI Layer abort requested I/O has been " |
| 4727 | "cancelled by LLD.\n"); |
| 4728 | return FAILED; |
| 4729 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4730 | /* |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4731 | * If pCmd field of the corresponding lpfc_scsi_buf structure |
| 4732 | * points to a different SCSI command, then the driver has |
| 4733 | * already completed this command, but the midlayer did not |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4734 | * see the completion before the eh fired. Just return SUCCESS. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4735 | */ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4736 | if (lpfc_cmd->pCmd != cmnd) { |
| 4737 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4738 | "3170 SCSI Layer abort requested I/O has been " |
| 4739 | "completed by LLD.\n"); |
| 4740 | goto out_unlock; |
| 4741 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4742 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4743 | BUG_ON(iocb->context1 != lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4744 | |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4745 | /* abort issued in recovery is still in progress */ |
| 4746 | if (iocb->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 4747 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4748 | "3389 SCSI Layer I/O Abort Request is pending\n"); |
| 4749 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4750 | goto wait_for_cmpl; |
| 4751 | } |
| 4752 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4753 | abtsiocb = __lpfc_sli_get_iocbq(phba); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4754 | if (abtsiocb == NULL) { |
| 4755 | ret = FAILED; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4756 | goto out_unlock; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4757 | } |
| 4758 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 4759 | /* Indicate the IO is being aborted by the driver. */ |
| 4760 | iocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 4761 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4762 | /* |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4763 | * The scsi command can not be in txq and it is in flight because the |
| 4764 | * pCmd is still pointig at the SCSI command we have to abort. There |
| 4765 | * is no need to search the txcmplq. Just send an abort to the FW. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4766 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4767 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4768 | cmd = &iocb->iocb; |
| 4769 | icmd = &abtsiocb->iocb; |
| 4770 | icmd->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 4771 | icmd->un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4772 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4773 | icmd->un.acxri.abortIoTag = iocb->sli4_xritag; |
| 4774 | else |
| 4775 | icmd->un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4776 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4777 | icmd->ulpLe = 1; |
| 4778 | icmd->ulpClass = cmd->ulpClass; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4779 | |
| 4780 | /* 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] | 4781 | abtsiocb->hba_wqidx = iocb->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 4782 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 4783 | if (iocb->iocb_flag & LPFC_IO_FOF) |
| 4784 | abtsiocb->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4785 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4786 | if (lpfc_is_link_up(phba)) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4787 | icmd->ulpCommand = CMD_ABORT_XRI_CN; |
| 4788 | else |
| 4789 | icmd->ulpCommand = CMD_CLOSE_XRI_CN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4790 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4791 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4792 | abtsiocb->vport = vport; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4793 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4794 | pring_s4 = lpfc_sli4_calc_ring(phba, iocb); |
| 4795 | if (pring_s4 == NULL) { |
| 4796 | ret = FAILED; |
| 4797 | goto out_unlock; |
| 4798 | } |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4799 | /* Note: both hbalock and ring_lock must be set here */ |
| 4800 | spin_lock_irqsave(&pring_s4->ring_lock, iflags); |
| 4801 | ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 4802 | abtsiocb, 0); |
| 4803 | spin_unlock_irqrestore(&pring_s4->ring_lock, iflags); |
| 4804 | } else { |
| 4805 | ret_val = __lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, |
| 4806 | abtsiocb, 0); |
| 4807 | } |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4808 | /* no longer need the lock after this point */ |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4809 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4810 | |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4811 | |
| 4812 | if (ret_val == IOCB_ERROR) { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4813 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| 4814 | ret = FAILED; |
| 4815 | goto out; |
| 4816 | } |
| 4817 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4818 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4819 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4820 | &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4821 | |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4822 | wait_for_cmpl: |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4823 | lpfc_cmd->waitq = &waitq; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4824 | /* Wait for abort to complete */ |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4825 | wait_event_timeout(waitq, |
| 4826 | (lpfc_cmd->pCmd != cmnd), |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4827 | msecs_to_jiffies(2*vport->cfg_devloss_tmo*1000)); |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4828 | |
| 4829 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4830 | lpfc_cmd->waitq = NULL; |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4831 | spin_unlock_irqrestore(shost->host_lock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4832 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4833 | if (lpfc_cmd->pCmd == cmnd) { |
| 4834 | ret = FAILED; |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4835 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 4836 | "0748 abort handler timed out waiting " |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 4837 | "for aborting I/O (xri:x%x) to complete: " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4838 | "ret %#x, ID %d, LUN %llu\n", |
James Smart | 247ca94 | 2012-08-14 14:26:13 -0400 | [diff] [blame] | 4839 | iocb->sli4_xritag, ret, |
| 4840 | cmnd->device->id, cmnd->device->lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4841 | } |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4842 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4843 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4844 | out_unlock: |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4845 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4846 | out: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4847 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4848 | "0749 SCSI Layer I/O Abort Request Status x%x ID %d " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4849 | "LUN %llu\n", ret, cmnd->device->id, |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 4850 | cmnd->device->lun); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4851 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4852 | } |
| 4853 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4854 | static char * |
| 4855 | lpfc_taskmgmt_name(uint8_t task_mgmt_cmd) |
| 4856 | { |
| 4857 | switch (task_mgmt_cmd) { |
| 4858 | case FCP_ABORT_TASK_SET: |
| 4859 | return "ABORT_TASK_SET"; |
| 4860 | case FCP_CLEAR_TASK_SET: |
| 4861 | return "FCP_CLEAR_TASK_SET"; |
| 4862 | case FCP_BUS_RESET: |
| 4863 | return "FCP_BUS_RESET"; |
| 4864 | case FCP_LUN_RESET: |
| 4865 | return "FCP_LUN_RESET"; |
| 4866 | case FCP_TARGET_RESET: |
| 4867 | return "FCP_TARGET_RESET"; |
| 4868 | case FCP_CLEAR_ACA: |
| 4869 | return "FCP_CLEAR_ACA"; |
| 4870 | case FCP_TERMINATE_TASK: |
| 4871 | return "FCP_TERMINATE_TASK"; |
| 4872 | default: |
| 4873 | return "unknown"; |
| 4874 | } |
| 4875 | } |
| 4876 | |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 4877 | |
| 4878 | /** |
| 4879 | * lpfc_check_fcp_rsp - check the returned fcp_rsp to see if task failed |
| 4880 | * @vport: The virtual port for which this call is being executed. |
| 4881 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. |
| 4882 | * |
| 4883 | * This routine checks the FCP RSP INFO to see if the tsk mgmt command succeded |
| 4884 | * |
| 4885 | * Return code : |
| 4886 | * 0x2003 - Error |
| 4887 | * 0x2002 - Success |
| 4888 | **/ |
| 4889 | static int |
| 4890 | lpfc_check_fcp_rsp(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd) |
| 4891 | { |
| 4892 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
| 4893 | uint32_t rsp_info; |
| 4894 | uint32_t rsp_len; |
| 4895 | uint8_t rsp_info_code; |
| 4896 | int ret = FAILED; |
| 4897 | |
| 4898 | |
| 4899 | if (fcprsp == NULL) |
| 4900 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4901 | "0703 fcp_rsp is missing\n"); |
| 4902 | else { |
| 4903 | rsp_info = fcprsp->rspStatus2; |
| 4904 | rsp_len = be32_to_cpu(fcprsp->rspRspLen); |
| 4905 | rsp_info_code = fcprsp->rspInfo3; |
| 4906 | |
| 4907 | |
| 4908 | lpfc_printf_vlog(vport, KERN_INFO, |
| 4909 | LOG_FCP, |
| 4910 | "0706 fcp_rsp valid 0x%x," |
| 4911 | " rsp len=%d code 0x%x\n", |
| 4912 | rsp_info, |
| 4913 | rsp_len, rsp_info_code); |
| 4914 | |
| 4915 | if ((fcprsp->rspStatus2&RSP_LEN_VALID) && (rsp_len == 8)) { |
| 4916 | switch (rsp_info_code) { |
| 4917 | case RSP_NO_FAILURE: |
| 4918 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4919 | "0715 Task Mgmt No Failure\n"); |
| 4920 | ret = SUCCESS; |
| 4921 | break; |
| 4922 | case RSP_TM_NOT_SUPPORTED: /* TM rejected */ |
| 4923 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4924 | "0716 Task Mgmt Target " |
| 4925 | "reject\n"); |
| 4926 | break; |
| 4927 | case RSP_TM_NOT_COMPLETED: /* TM failed */ |
| 4928 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4929 | "0717 Task Mgmt Target " |
| 4930 | "failed TM\n"); |
| 4931 | break; |
| 4932 | case RSP_TM_INVALID_LU: /* TM to invalid LU! */ |
| 4933 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4934 | "0718 Task Mgmt to invalid " |
| 4935 | "LUN\n"); |
| 4936 | break; |
| 4937 | } |
| 4938 | } |
| 4939 | } |
| 4940 | return ret; |
| 4941 | } |
| 4942 | |
| 4943 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4944 | /** |
| 4945 | * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler |
| 4946 | * @vport: The virtual port for which this call is being executed. |
| 4947 | * @rdata: Pointer to remote port local data |
| 4948 | * @tgt_id: Target ID of remote device. |
| 4949 | * @lun_id: Lun number for the TMF |
| 4950 | * @task_mgmt_cmd: type of TMF to send |
| 4951 | * |
| 4952 | * This routine builds and sends a TMF (SCSI Task Mgmt Function) to |
| 4953 | * a remote port. |
| 4954 | * |
| 4955 | * Return Code: |
| 4956 | * 0x2003 - Error |
| 4957 | * 0x2002 - Success. |
| 4958 | **/ |
| 4959 | static int |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 4960 | lpfc_send_taskmgmt(struct lpfc_vport *vport, struct scsi_cmnd *cmnd, |
| 4961 | unsigned int tgt_id, uint64_t lun_id, |
| 4962 | uint8_t task_mgmt_cmd) |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4963 | { |
| 4964 | struct lpfc_hba *phba = vport->phba; |
| 4965 | struct lpfc_scsi_buf *lpfc_cmd; |
| 4966 | struct lpfc_iocbq *iocbq; |
| 4967 | struct lpfc_iocbq *iocbqrsp; |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 4968 | struct lpfc_rport_data *rdata; |
| 4969 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4970 | int ret; |
| 4971 | int status; |
| 4972 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 4973 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
| 4974 | if (!rdata || !rdata->pnode || !NLP_CHK_NODE_ACT(rdata->pnode)) |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4975 | return FAILED; |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 4976 | pnode = rdata->pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4977 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 4978 | lpfc_cmd = lpfc_get_scsi_buf(phba, pnode); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4979 | if (lpfc_cmd == NULL) |
| 4980 | return FAILED; |
James Smart | 0c41122 | 2013-09-06 12:22:46 -0400 | [diff] [blame] | 4981 | lpfc_cmd->timeout = phba->cfg_task_mgmt_tmo; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4982 | lpfc_cmd->rdata = rdata; |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 4983 | lpfc_cmd->pCmd = cmnd; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4984 | |
| 4985 | status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun_id, |
| 4986 | task_mgmt_cmd); |
| 4987 | if (!status) { |
| 4988 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 4989 | return FAILED; |
| 4990 | } |
| 4991 | |
| 4992 | iocbq = &lpfc_cmd->cur_iocbq; |
| 4993 | iocbqrsp = lpfc_sli_get_iocbq(phba); |
| 4994 | if (iocbqrsp == NULL) { |
| 4995 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 4996 | return FAILED; |
| 4997 | } |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 4998 | iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4999 | |
| 5000 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5001 | "0702 Issue %s to TGT %d LUN %llu " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5002 | "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] | 5003 | lpfc_taskmgmt_name(task_mgmt_cmd), tgt_id, lun_id, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5004 | pnode->nlp_rpi, pnode->nlp_flag, iocbq->sli4_xritag, |
| 5005 | iocbq->iocb_flag); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5006 | |
| 5007 | status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING, |
| 5008 | iocbq, iocbqrsp, lpfc_cmd->timeout); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5009 | if ((status != IOCB_SUCCESS) || |
| 5010 | (iocbqrsp->iocb.ulpStatus != IOSTAT_SUCCESS)) { |
James Smart | ae374a3 | 2015-05-22 10:42:41 -0400 | [diff] [blame] | 5011 | if (status != IOCB_SUCCESS || |
| 5012 | iocbqrsp->iocb.ulpStatus != IOSTAT_FCP_RSP_ERROR) |
| 5013 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5014 | "0727 TMF %s to TGT %d LUN %llu " |
| 5015 | "failed (%d, %d) iocb_flag x%x\n", |
| 5016 | lpfc_taskmgmt_name(task_mgmt_cmd), |
| 5017 | tgt_id, lun_id, |
| 5018 | iocbqrsp->iocb.ulpStatus, |
| 5019 | iocbqrsp->iocb.un.ulpWord[4], |
| 5020 | iocbq->iocb_flag); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5021 | /* if ulpStatus != IOCB_SUCCESS, then status == IOCB_SUCCESS */ |
| 5022 | if (status == IOCB_SUCCESS) { |
| 5023 | if (iocbqrsp->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 5024 | /* Something in the FCP_RSP was invalid. |
| 5025 | * Check conditions */ |
| 5026 | ret = lpfc_check_fcp_rsp(vport, lpfc_cmd); |
| 5027 | else |
| 5028 | ret = FAILED; |
| 5029 | } else if (status == IOCB_TIMEDOUT) { |
| 5030 | ret = TIMEOUT_ERROR; |
| 5031 | } else { |
| 5032 | ret = FAILED; |
| 5033 | } |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5034 | } else |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5035 | ret = SUCCESS; |
| 5036 | |
| 5037 | lpfc_sli_release_iocbq(phba, iocbqrsp); |
| 5038 | |
| 5039 | if (ret != TIMEOUT_ERROR) |
| 5040 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 5041 | |
| 5042 | return ret; |
| 5043 | } |
| 5044 | |
| 5045 | /** |
| 5046 | * lpfc_chk_tgt_mapped - |
| 5047 | * @vport: The virtual port to check on |
| 5048 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5049 | * |
| 5050 | * This routine delays until the scsi target (aka rport) for the |
| 5051 | * command exists (is present and logged in) or we declare it non-existent. |
| 5052 | * |
| 5053 | * Return code : |
| 5054 | * 0x2003 - Error |
| 5055 | * 0x2002 - Success |
| 5056 | **/ |
| 5057 | static int |
| 5058 | lpfc_chk_tgt_mapped(struct lpfc_vport *vport, struct scsi_cmnd *cmnd) |
| 5059 | { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5060 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5061 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5062 | unsigned long later; |
| 5063 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5064 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5065 | if (!rdata) { |
| 5066 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 5067 | "0797 Tgt Map rport failure: rdata x%p\n", rdata); |
| 5068 | return FAILED; |
| 5069 | } |
| 5070 | pnode = rdata->pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5071 | /* |
| 5072 | * If target is not in a MAPPED state, delay until |
| 5073 | * target is rediscovered or devloss timeout expires. |
| 5074 | */ |
| 5075 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; |
| 5076 | while (time_after(later, jiffies)) { |
| 5077 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 5078 | return FAILED; |
| 5079 | if (pnode->nlp_state == NLP_STE_MAPPED_NODE) |
| 5080 | return SUCCESS; |
| 5081 | schedule_timeout_uninterruptible(msecs_to_jiffies(500)); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5082 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5083 | if (!rdata) |
| 5084 | return FAILED; |
| 5085 | pnode = rdata->pnode; |
| 5086 | } |
| 5087 | if (!pnode || !NLP_CHK_NODE_ACT(pnode) || |
| 5088 | (pnode->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5089 | return FAILED; |
| 5090 | return SUCCESS; |
| 5091 | } |
| 5092 | |
| 5093 | /** |
| 5094 | * lpfc_reset_flush_io_context - |
| 5095 | * @vport: The virtual port (scsi_host) for the flush context |
| 5096 | * @tgt_id: If aborting by Target contect - specifies the target id |
| 5097 | * @lun_id: If aborting by Lun context - specifies the lun id |
| 5098 | * @context: specifies the context level to flush at. |
| 5099 | * |
| 5100 | * After a reset condition via TMF, we need to flush orphaned i/o |
| 5101 | * contexts from the adapter. This routine aborts any contexts |
| 5102 | * outstanding, then waits for their completions. The wait is |
| 5103 | * bounded by devloss_tmo though. |
| 5104 | * |
| 5105 | * Return code : |
| 5106 | * 0x2003 - Error |
| 5107 | * 0x2002 - Success |
| 5108 | **/ |
| 5109 | static int |
| 5110 | lpfc_reset_flush_io_context(struct lpfc_vport *vport, uint16_t tgt_id, |
| 5111 | uint64_t lun_id, lpfc_ctx_cmd context) |
| 5112 | { |
| 5113 | struct lpfc_hba *phba = vport->phba; |
| 5114 | unsigned long later; |
| 5115 | int cnt; |
| 5116 | |
| 5117 | cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context); |
| 5118 | if (cnt) |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 5119 | lpfc_sli_abort_taskmgmt(vport, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5120 | &phba->sli.sli3_ring[LPFC_FCP_RING], |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 5121 | tgt_id, lun_id, context); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5122 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; |
| 5123 | while (time_after(later, jiffies) && cnt) { |
| 5124 | schedule_timeout_uninterruptible(msecs_to_jiffies(20)); |
| 5125 | cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context); |
| 5126 | } |
| 5127 | if (cnt) { |
| 5128 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5129 | "0724 I/O flush failure for context %s : cnt x%x\n", |
| 5130 | ((context == LPFC_CTX_LUN) ? "LUN" : |
| 5131 | ((context == LPFC_CTX_TGT) ? "TGT" : |
| 5132 | ((context == LPFC_CTX_HOST) ? "HOST" : "Unknown"))), |
| 5133 | cnt); |
| 5134 | return FAILED; |
| 5135 | } |
| 5136 | return SUCCESS; |
| 5137 | } |
| 5138 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5139 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5140 | * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5141 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5142 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5143 | * 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] | 5144 | * command. |
| 5145 | * |
| 5146 | * Return code : |
| 5147 | * 0x2003 - Error |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5148 | * 0x2002 - Success |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5149 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5150 | static int |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5151 | lpfc_device_reset_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5152 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5153 | struct Scsi_Host *shost = cmnd->device->host; |
| 5154 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5155 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5156 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5157 | unsigned tgt_id = cmnd->device->id; |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5158 | uint64_t lun_id = cmnd->device->lun; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5159 | struct lpfc_scsi_event_header scsi_event; |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5160 | int status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5161 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5162 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | ad490b6 | 2015-04-07 15:07:26 -0400 | [diff] [blame] | 5163 | if (!rdata || !rdata->pnode) { |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5164 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
James Smart | ad490b6 | 2015-04-07 15:07:26 -0400 | [diff] [blame] | 5165 | "0798 Device Reset rport failure: rdata x%p\n", |
| 5166 | rdata); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5167 | return FAILED; |
| 5168 | } |
| 5169 | pnode = rdata->pnode; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5170 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 5171 | if (status != 0 && status != SUCCESS) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5172 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5173 | |
| 5174 | status = lpfc_chk_tgt_mapped(vport, cmnd); |
| 5175 | if (status == FAILED) { |
| 5176 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5177 | "0721 Device Reset rport failure: rdata x%p\n", rdata); |
| 5178 | return FAILED; |
| 5179 | } |
| 5180 | |
| 5181 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 5182 | scsi_event.subcategory = LPFC_EVENT_LUNRESET; |
| 5183 | scsi_event.lun = lun_id; |
| 5184 | memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 5185 | memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 5186 | |
| 5187 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5188 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
| 5189 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 5190 | status = lpfc_send_taskmgmt(vport, cmnd, tgt_id, lun_id, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5191 | FCP_LUN_RESET); |
| 5192 | |
| 5193 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5194 | "0713 SCSI layer issued Device Reset (%d, %llu) " |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5195 | "return x%x\n", tgt_id, lun_id, status); |
| 5196 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5197 | /* |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5198 | * We have to clean up i/o as : they may be orphaned by the TMF; |
| 5199 | * or if the TMF failed, they may be in an indeterminate state. |
| 5200 | * So, continue on. |
| 5201 | * We will report success if all the i/o aborts successfully. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5202 | */ |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5203 | if (status == SUCCESS) |
| 5204 | status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5205 | LPFC_CTX_LUN); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5206 | |
| 5207 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5208 | } |
| 5209 | |
| 5210 | /** |
| 5211 | * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point |
| 5212 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5213 | * |
| 5214 | * This routine does a target reset by sending a TARGET_RESET task management |
| 5215 | * command. |
| 5216 | * |
| 5217 | * Return code : |
| 5218 | * 0x2003 - Error |
| 5219 | * 0x2002 - Success |
| 5220 | **/ |
| 5221 | static int |
| 5222 | lpfc_target_reset_handler(struct scsi_cmnd *cmnd) |
| 5223 | { |
| 5224 | struct Scsi_Host *shost = cmnd->device->host; |
| 5225 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5226 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5227 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5228 | unsigned tgt_id = cmnd->device->id; |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5229 | uint64_t lun_id = cmnd->device->lun; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5230 | struct lpfc_scsi_event_header scsi_event; |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5231 | int status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5232 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5233 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5234 | if (!rdata) { |
| 5235 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5236 | "0799 Target Reset rport failure: rdata x%p\n", rdata); |
| 5237 | return FAILED; |
| 5238 | } |
| 5239 | pnode = rdata->pnode; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5240 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 5241 | if (status != 0 && status != SUCCESS) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5242 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5243 | |
| 5244 | status = lpfc_chk_tgt_mapped(vport, cmnd); |
| 5245 | if (status == FAILED) { |
| 5246 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5247 | "0722 Target Reset rport failure: rdata x%p\n", rdata); |
James Smart | 63e480f | 2015-04-07 15:07:20 -0400 | [diff] [blame] | 5248 | if (pnode) { |
| 5249 | spin_lock_irq(shost->host_lock); |
| 5250 | pnode->nlp_flag &= ~NLP_NPR_ADISC; |
| 5251 | pnode->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; |
| 5252 | spin_unlock_irq(shost->host_lock); |
| 5253 | } |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 5254 | lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
| 5255 | LPFC_CTX_TGT); |
| 5256 | return FAST_IO_FAIL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5257 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5258 | |
| 5259 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 5260 | scsi_event.subcategory = LPFC_EVENT_TGTRESET; |
| 5261 | scsi_event.lun = 0; |
| 5262 | memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 5263 | memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 5264 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5265 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5266 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5267 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 5268 | status = lpfc_send_taskmgmt(vport, cmnd, tgt_id, lun_id, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5269 | FCP_TARGET_RESET); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5270 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5271 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5272 | "0723 SCSI layer issued Target Reset (%d, %llu) " |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5273 | "return x%x\n", tgt_id, lun_id, status); |
| 5274 | |
| 5275 | /* |
| 5276 | * We have to clean up i/o as : they may be orphaned by the TMF; |
| 5277 | * or if the TMF failed, they may be in an indeterminate state. |
| 5278 | * So, continue on. |
| 5279 | * We will report success if all the i/o aborts successfully. |
| 5280 | */ |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5281 | if (status == SUCCESS) |
| 5282 | status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 5283 | LPFC_CTX_TGT); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5284 | return status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5285 | } |
| 5286 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5287 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5288 | * 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] | 5289 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5290 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5291 | * This routine does target reset to all targets on @cmnd->device->host. |
| 5292 | * This emulates Parallel SCSI Bus Reset Semantics. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5293 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5294 | * Return code : |
| 5295 | * 0x2003 - Error |
| 5296 | * 0x2002 - Success |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5297 | **/ |
Jeff Garzik | 94d0e7b8 | 2005-05-28 07:55:48 -0400 | [diff] [blame] | 5298 | static int |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5299 | lpfc_bus_reset_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5300 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5301 | struct Scsi_Host *shost = cmnd->device->host; |
| 5302 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5303 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5304 | struct lpfc_scsi_event_header scsi_event; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5305 | int match; |
| 5306 | int ret = SUCCESS, status, i; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5307 | |
| 5308 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 5309 | scsi_event.subcategory = LPFC_EVENT_BUSRESET; |
| 5310 | scsi_event.lun = 0; |
| 5311 | memcpy(scsi_event.wwpn, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 5312 | memcpy(scsi_event.wwnn, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| 5313 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5314 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5315 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5316 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 5317 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 5318 | if (status != 0 && status != SUCCESS) |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 5319 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5320 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5321 | /* |
| 5322 | * Since the driver manages a single bus device, reset all |
| 5323 | * targets known to the driver. Should any target reset |
| 5324 | * fail, this routine returns failure to the midlayer. |
| 5325 | */ |
James Smart | e17da18 | 2006-07-06 15:49:25 -0400 | [diff] [blame] | 5326 | for (i = 0; i < LPFC_MAX_TARGET; i++) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5327 | /* Search for mapped node by target ID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5328 | match = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5329 | spin_lock_irq(shost->host_lock); |
| 5330 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5331 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5332 | continue; |
James Smart | a6571c6 | 2012-10-31 14:44:42 -0400 | [diff] [blame] | 5333 | if (vport->phba->cfg_fcp2_no_tgt_reset && |
| 5334 | (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE)) |
| 5335 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5336 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE && |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 5337 | ndlp->nlp_sid == i && |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 5338 | ndlp->rport && |
| 5339 | ndlp->nlp_type & NLP_FCP_TARGET) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5340 | match = 1; |
| 5341 | break; |
| 5342 | } |
| 5343 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5344 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5345 | if (!match) |
| 5346 | continue; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5347 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 5348 | status = lpfc_send_taskmgmt(vport, cmnd, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5349 | i, 0, FCP_TARGET_RESET); |
| 5350 | |
| 5351 | if (status != SUCCESS) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5352 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5353 | "0700 Bus Reset on target %d failed\n", |
| 5354 | i); |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 5355 | ret = FAILED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5356 | } |
| 5357 | } |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 5358 | /* |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5359 | * We have to clean up i/o as : they may be orphaned by the TMFs |
| 5360 | * above; or if any of the TMFs failed, they may be in an |
| 5361 | * indeterminate state. |
| 5362 | * 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] | 5363 | */ |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5364 | |
| 5365 | status = lpfc_reset_flush_io_context(vport, 0, 0, LPFC_CTX_HOST); |
| 5366 | if (status != SUCCESS) |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 5367 | ret = FAILED; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5368 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5369 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5370 | "0714 SCSI layer issued Bus Reset Data: x%x\n", ret); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5371 | return ret; |
| 5372 | } |
| 5373 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5374 | /** |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5375 | * lpfc_host_reset_handler - scsi_host_template eh_host_reset_handler entry pt |
| 5376 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5377 | * |
| 5378 | * This routine does host reset to the adaptor port. It brings the HBA |
| 5379 | * offline, performs a board restart, and then brings the board back online. |
| 5380 | * The lpfc_offline calls lpfc_sli_hba_down which will abort and local |
| 5381 | * reject all outstanding SCSI commands to the host and error returned |
| 5382 | * back to SCSI mid-level. As this will be SCSI mid-level's last resort |
| 5383 | * of error handling, it will only return error if resetting of the adapter |
| 5384 | * is not successful; in all other cases, will return success. |
| 5385 | * |
| 5386 | * Return code : |
| 5387 | * 0x2003 - Error |
| 5388 | * 0x2002 - Success |
| 5389 | **/ |
| 5390 | static int |
| 5391 | lpfc_host_reset_handler(struct scsi_cmnd *cmnd) |
| 5392 | { |
| 5393 | struct Scsi_Host *shost = cmnd->device->host; |
| 5394 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 5395 | struct lpfc_hba *phba = vport->phba; |
| 5396 | int rc, ret = SUCCESS; |
| 5397 | |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 5398 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5399 | "3172 SCSI layer issued Host Reset Data:\n"); |
| 5400 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 5401 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5402 | lpfc_offline(phba); |
| 5403 | rc = lpfc_sli_brdrestart(phba); |
| 5404 | if (rc) |
| 5405 | ret = FAILED; |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 5406 | rc = lpfc_online(phba); |
| 5407 | if (rc) |
| 5408 | ret = FAILED; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5409 | lpfc_unblock_mgmt_io(phba); |
| 5410 | |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 5411 | if (ret == FAILED) { |
| 5412 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5413 | "3323 Failed host reset, bring it offline\n"); |
| 5414 | lpfc_sli4_offline_eratt(phba); |
| 5415 | } |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5416 | return ret; |
| 5417 | } |
| 5418 | |
| 5419 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5420 | * lpfc_slave_alloc - scsi_host_template slave_alloc entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5421 | * @sdev: Pointer to scsi_device. |
| 5422 | * |
| 5423 | * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's |
| 5424 | * globally available list of scsi buffers. This routine also makes sure scsi |
| 5425 | * buffer is not allocated more than HBA limit conveyed to midlayer. This list |
| 5426 | * of scsi buffer exists for the lifetime of the driver. |
| 5427 | * |
| 5428 | * Return codes: |
| 5429 | * non-0 - Error |
| 5430 | * 0 - Success |
| 5431 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5432 | static int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5433 | lpfc_slave_alloc(struct scsi_device *sdev) |
| 5434 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5435 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 5436 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 5437 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5438 | uint32_t total = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5439 | uint32_t num_to_alloc = 0; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5440 | int num_allocated = 0; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5441 | uint32_t sdev_cnt; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5442 | struct lpfc_device_data *device_data; |
| 5443 | unsigned long flags; |
| 5444 | struct lpfc_name target_wwpn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5445 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 5446 | if (!rport || fc_remote_port_chkready(rport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5447 | return -ENXIO; |
| 5448 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5449 | if (phba->cfg_fof) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5450 | |
| 5451 | /* |
| 5452 | * Check to see if the device data structure for the lun |
| 5453 | * exists. If not, create one. |
| 5454 | */ |
| 5455 | |
| 5456 | u64_to_wwn(rport->port_name, target_wwpn.u.wwn); |
| 5457 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5458 | device_data = __lpfc_get_device_data(phba, |
| 5459 | &phba->luns, |
| 5460 | &vport->fc_portname, |
| 5461 | &target_wwpn, |
| 5462 | sdev->lun); |
| 5463 | if (!device_data) { |
| 5464 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5465 | device_data = lpfc_create_device_data(phba, |
| 5466 | &vport->fc_portname, |
| 5467 | &target_wwpn, |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5468 | sdev->lun, |
| 5469 | phba->cfg_XLanePriority, |
| 5470 | true); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5471 | if (!device_data) |
| 5472 | return -ENOMEM; |
| 5473 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5474 | list_add_tail(&device_data->listentry, &phba->luns); |
| 5475 | } |
| 5476 | device_data->rport_data = rport->dd_data; |
| 5477 | device_data->available = true; |
| 5478 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5479 | sdev->hostdata = device_data; |
| 5480 | } else { |
| 5481 | sdev->hostdata = rport->dd_data; |
| 5482 | } |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5483 | sdev_cnt = atomic_inc_return(&phba->sdev_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5484 | |
| 5485 | /* |
| 5486 | * Populate the cmds_per_lun count scsi_bufs into this host's globally |
| 5487 | * 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] | 5488 | * HBA limit conveyed to the midlayer via the host structure. The |
| 5489 | * formula accounts for the lun_queue_depth + error handlers + 1 |
| 5490 | * extra. This list of scsi bufs exists for the lifetime of the driver. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5491 | */ |
| 5492 | total = phba->total_scsi_bufs; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5493 | num_to_alloc = vport->cfg_lun_queue_depth + 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5494 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5495 | /* If allocated buffers are enough do nothing */ |
| 5496 | if ((sdev_cnt * (vport->cfg_lun_queue_depth + 2)) < total) |
| 5497 | return 0; |
| 5498 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5499 | /* Allow some exchanges to be available always to complete discovery */ |
| 5500 | if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5501 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 5502 | "0704 At limitation of %d preallocated " |
| 5503 | "command buffers\n", total); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5504 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5505 | /* Allow some exchanges to be available always to complete discovery */ |
| 5506 | } else if (total + num_to_alloc > |
| 5507 | phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5508 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 5509 | "0705 Allocation request of %d " |
| 5510 | "command buffers will exceed max of %d. " |
| 5511 | "Reducing allocation request to %d.\n", |
| 5512 | num_to_alloc, phba->cfg_hba_queue_depth, |
| 5513 | (phba->cfg_hba_queue_depth - total)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5514 | num_to_alloc = phba->cfg_hba_queue_depth - total; |
| 5515 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5516 | num_allocated = lpfc_new_scsi_buf(vport, num_to_alloc); |
| 5517 | if (num_to_alloc != num_allocated) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5518 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5519 | "0708 Allocation request of %d " |
| 5520 | "command buffers did not succeed. " |
| 5521 | "Allocated %d buffers.\n", |
| 5522 | num_to_alloc, num_allocated); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5523 | } |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5524 | if (num_allocated > 0) |
| 5525 | phba->total_scsi_bufs += num_allocated; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5526 | return 0; |
| 5527 | } |
| 5528 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5529 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5530 | * lpfc_slave_configure - scsi_host_template slave_configure entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5531 | * @sdev: Pointer to scsi_device. |
| 5532 | * |
| 5533 | * This routine configures following items |
| 5534 | * - Tag command queuing support for @sdev if supported. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5535 | * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set. |
| 5536 | * |
| 5537 | * Return codes: |
| 5538 | * 0 - Success |
| 5539 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5540 | static int |
| 5541 | lpfc_slave_configure(struct scsi_device *sdev) |
| 5542 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5543 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 5544 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5545 | |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 5546 | scsi_change_queue_depth(sdev, vport->cfg_lun_queue_depth); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5547 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5548 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 5549 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5550 | &phba->sli.sli3_ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5551 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 5552 | lpfc_poll_rearm_timer(phba); |
| 5553 | } |
| 5554 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5555 | return 0; |
| 5556 | } |
| 5557 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5558 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5559 | * lpfc_slave_destroy - slave_destroy entry point of SHT data structure |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5560 | * @sdev: Pointer to scsi_device. |
| 5561 | * |
| 5562 | * This routine sets @sdev hostatdata filed to null. |
| 5563 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5564 | static void |
| 5565 | lpfc_slave_destroy(struct scsi_device *sdev) |
| 5566 | { |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5567 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 5568 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5569 | unsigned long flags; |
| 5570 | struct lpfc_device_data *device_data = sdev->hostdata; |
| 5571 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5572 | atomic_dec(&phba->sdev_cnt); |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5573 | if ((phba->cfg_fof) && (device_data)) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5574 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5575 | device_data->available = false; |
| 5576 | if (!device_data->oas_enabled) |
| 5577 | lpfc_delete_device_data(phba, device_data); |
| 5578 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5579 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5580 | sdev->hostdata = NULL; |
| 5581 | return; |
| 5582 | } |
| 5583 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5584 | /** |
| 5585 | * lpfc_create_device_data - creates and initializes device data structure for OAS |
| 5586 | * @pha: Pointer to host bus adapter structure. |
| 5587 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5588 | * @target_wwpn: Pointer to target's wwpn information |
| 5589 | * @lun: Lun on target |
| 5590 | * @atomic_create: Flag to indicate if memory should be allocated using the |
| 5591 | * GFP_ATOMIC flag or not. |
| 5592 | * |
| 5593 | * This routine creates a device data structure which will contain identifying |
| 5594 | * information for the device (host wwpn, target wwpn, lun), state of OAS, |
| 5595 | * whether or not the corresponding lun is available by the system, |
| 5596 | * and pointer to the rport data. |
| 5597 | * |
| 5598 | * Return codes: |
| 5599 | * NULL - Error |
| 5600 | * Pointer to lpfc_device_data - Success |
| 5601 | **/ |
| 5602 | struct lpfc_device_data* |
| 5603 | lpfc_create_device_data(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn, |
| 5604 | struct lpfc_name *target_wwpn, uint64_t lun, |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5605 | uint32_t pri, bool atomic_create) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5606 | { |
| 5607 | |
| 5608 | struct lpfc_device_data *lun_info; |
| 5609 | int memory_flags; |
| 5610 | |
| 5611 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5612 | !(phba->cfg_fof)) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5613 | return NULL; |
| 5614 | |
| 5615 | /* Attempt to create the device data to contain lun info */ |
| 5616 | |
| 5617 | if (atomic_create) |
| 5618 | memory_flags = GFP_ATOMIC; |
| 5619 | else |
| 5620 | memory_flags = GFP_KERNEL; |
| 5621 | lun_info = mempool_alloc(phba->device_data_mem_pool, memory_flags); |
| 5622 | if (!lun_info) |
| 5623 | return NULL; |
| 5624 | INIT_LIST_HEAD(&lun_info->listentry); |
| 5625 | lun_info->rport_data = NULL; |
| 5626 | memcpy(&lun_info->device_id.vport_wwpn, vport_wwpn, |
| 5627 | sizeof(struct lpfc_name)); |
| 5628 | memcpy(&lun_info->device_id.target_wwpn, target_wwpn, |
| 5629 | sizeof(struct lpfc_name)); |
| 5630 | lun_info->device_id.lun = lun; |
| 5631 | lun_info->oas_enabled = false; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5632 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5633 | lun_info->available = false; |
| 5634 | return lun_info; |
| 5635 | } |
| 5636 | |
| 5637 | /** |
| 5638 | * lpfc_delete_device_data - frees a device data structure for OAS |
| 5639 | * @pha: Pointer to host bus adapter structure. |
| 5640 | * @lun_info: Pointer to device data structure to free. |
| 5641 | * |
| 5642 | * This routine frees the previously allocated device data structure passed. |
| 5643 | * |
| 5644 | **/ |
| 5645 | void |
| 5646 | lpfc_delete_device_data(struct lpfc_hba *phba, |
| 5647 | struct lpfc_device_data *lun_info) |
| 5648 | { |
| 5649 | |
| 5650 | if (unlikely(!phba) || !lun_info || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5651 | !(phba->cfg_fof)) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5652 | return; |
| 5653 | |
| 5654 | if (!list_empty(&lun_info->listentry)) |
| 5655 | list_del(&lun_info->listentry); |
| 5656 | mempool_free(lun_info, phba->device_data_mem_pool); |
| 5657 | return; |
| 5658 | } |
| 5659 | |
| 5660 | /** |
| 5661 | * __lpfc_get_device_data - returns the device data for the specified lun |
| 5662 | * @pha: Pointer to host bus adapter structure. |
| 5663 | * @list: Point to list to search. |
| 5664 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5665 | * @target_wwpn: Pointer to target's wwpn information |
| 5666 | * @lun: Lun on target |
| 5667 | * |
| 5668 | * This routine searches the list passed for the specified lun's device data. |
| 5669 | * This function does not hold locks, it is the responsibility of the caller |
| 5670 | * to ensure the proper lock is held before calling the function. |
| 5671 | * |
| 5672 | * Return codes: |
| 5673 | * NULL - Error |
| 5674 | * Pointer to lpfc_device_data - Success |
| 5675 | **/ |
| 5676 | struct lpfc_device_data* |
| 5677 | __lpfc_get_device_data(struct lpfc_hba *phba, struct list_head *list, |
| 5678 | struct lpfc_name *vport_wwpn, |
| 5679 | struct lpfc_name *target_wwpn, uint64_t lun) |
| 5680 | { |
| 5681 | |
| 5682 | struct lpfc_device_data *lun_info; |
| 5683 | |
| 5684 | if (unlikely(!phba) || !list || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5685 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5686 | return NULL; |
| 5687 | |
| 5688 | /* Check to see if the lun is already enabled for OAS. */ |
| 5689 | |
| 5690 | list_for_each_entry(lun_info, list, listentry) { |
| 5691 | if ((memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn, |
| 5692 | sizeof(struct lpfc_name)) == 0) && |
| 5693 | (memcmp(&lun_info->device_id.target_wwpn, target_wwpn, |
| 5694 | sizeof(struct lpfc_name)) == 0) && |
| 5695 | (lun_info->device_id.lun == lun)) |
| 5696 | return lun_info; |
| 5697 | } |
| 5698 | |
| 5699 | return NULL; |
| 5700 | } |
| 5701 | |
| 5702 | /** |
| 5703 | * lpfc_find_next_oas_lun - searches for the next oas lun |
| 5704 | * @pha: Pointer to host bus adapter structure. |
| 5705 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5706 | * @target_wwpn: Pointer to target's wwpn information |
| 5707 | * @starting_lun: Pointer to the lun to start searching for |
| 5708 | * @found_vport_wwpn: Pointer to the found lun's vport wwpn information |
| 5709 | * @found_target_wwpn: Pointer to the found lun's target wwpn information |
| 5710 | * @found_lun: Pointer to the found lun. |
| 5711 | * @found_lun_status: Pointer to status of the found lun. |
| 5712 | * |
| 5713 | * This routine searches the luns list for the specified lun |
| 5714 | * or the first lun for the vport/target. If the vport wwpn contains |
| 5715 | * a zero value then a specific vport is not specified. In this case |
| 5716 | * any vport which contains the lun will be considered a match. If the |
| 5717 | * target wwpn contains a zero value then a specific target is not specified. |
| 5718 | * In this case any target which contains the lun will be considered a |
| 5719 | * match. If the lun is found, the lun, vport wwpn, target wwpn and lun status |
| 5720 | * are returned. The function will also return the next lun if available. |
| 5721 | * If the next lun is not found, starting_lun parameter will be set to |
| 5722 | * NO_MORE_OAS_LUN. |
| 5723 | * |
| 5724 | * Return codes: |
| 5725 | * non-0 - Error |
| 5726 | * 0 - Success |
| 5727 | **/ |
| 5728 | bool |
| 5729 | lpfc_find_next_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn, |
| 5730 | struct lpfc_name *target_wwpn, uint64_t *starting_lun, |
| 5731 | struct lpfc_name *found_vport_wwpn, |
| 5732 | struct lpfc_name *found_target_wwpn, |
| 5733 | uint64_t *found_lun, |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5734 | uint32_t *found_lun_status, |
| 5735 | uint32_t *found_lun_pri) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5736 | { |
| 5737 | |
| 5738 | unsigned long flags; |
| 5739 | struct lpfc_device_data *lun_info; |
| 5740 | struct lpfc_device_id *device_id; |
| 5741 | uint64_t lun; |
| 5742 | bool found = false; |
| 5743 | |
| 5744 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
| 5745 | !starting_lun || !found_vport_wwpn || |
| 5746 | !found_target_wwpn || !found_lun || !found_lun_status || |
| 5747 | (*starting_lun == NO_MORE_OAS_LUN) || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5748 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5749 | return false; |
| 5750 | |
| 5751 | lun = *starting_lun; |
| 5752 | *found_lun = NO_MORE_OAS_LUN; |
| 5753 | *starting_lun = NO_MORE_OAS_LUN; |
| 5754 | |
| 5755 | /* Search for lun or the lun closet in value */ |
| 5756 | |
| 5757 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5758 | list_for_each_entry(lun_info, &phba->luns, listentry) { |
| 5759 | if (((wwn_to_u64(vport_wwpn->u.wwn) == 0) || |
| 5760 | (memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn, |
| 5761 | sizeof(struct lpfc_name)) == 0)) && |
| 5762 | ((wwn_to_u64(target_wwpn->u.wwn) == 0) || |
| 5763 | (memcmp(&lun_info->device_id.target_wwpn, target_wwpn, |
| 5764 | sizeof(struct lpfc_name)) == 0)) && |
| 5765 | (lun_info->oas_enabled)) { |
| 5766 | device_id = &lun_info->device_id; |
| 5767 | if ((!found) && |
| 5768 | ((lun == FIND_FIRST_OAS_LUN) || |
| 5769 | (device_id->lun == lun))) { |
| 5770 | *found_lun = device_id->lun; |
| 5771 | memcpy(found_vport_wwpn, |
| 5772 | &device_id->vport_wwpn, |
| 5773 | sizeof(struct lpfc_name)); |
| 5774 | memcpy(found_target_wwpn, |
| 5775 | &device_id->target_wwpn, |
| 5776 | sizeof(struct lpfc_name)); |
| 5777 | if (lun_info->available) |
| 5778 | *found_lun_status = |
| 5779 | OAS_LUN_STATUS_EXISTS; |
| 5780 | else |
| 5781 | *found_lun_status = 0; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5782 | *found_lun_pri = lun_info->priority; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5783 | if (phba->cfg_oas_flags & OAS_FIND_ANY_VPORT) |
| 5784 | memset(vport_wwpn, 0x0, |
| 5785 | sizeof(struct lpfc_name)); |
| 5786 | if (phba->cfg_oas_flags & OAS_FIND_ANY_TARGET) |
| 5787 | memset(target_wwpn, 0x0, |
| 5788 | sizeof(struct lpfc_name)); |
| 5789 | found = true; |
| 5790 | } else if (found) { |
| 5791 | *starting_lun = device_id->lun; |
| 5792 | memcpy(vport_wwpn, &device_id->vport_wwpn, |
| 5793 | sizeof(struct lpfc_name)); |
| 5794 | memcpy(target_wwpn, &device_id->target_wwpn, |
| 5795 | sizeof(struct lpfc_name)); |
| 5796 | break; |
| 5797 | } |
| 5798 | } |
| 5799 | } |
| 5800 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5801 | return found; |
| 5802 | } |
| 5803 | |
| 5804 | /** |
| 5805 | * lpfc_enable_oas_lun - enables a lun for OAS operations |
| 5806 | * @pha: Pointer to host bus adapter structure. |
| 5807 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5808 | * @target_wwpn: Pointer to target's wwpn information |
| 5809 | * @lun: Lun |
| 5810 | * |
| 5811 | * This routine enables a lun for oas operations. The routines does so by |
| 5812 | * doing the following : |
| 5813 | * |
| 5814 | * 1) Checks to see if the device data for the lun has been created. |
| 5815 | * 2) If found, sets the OAS enabled flag if not set and returns. |
| 5816 | * 3) Otherwise, creates a device data structure. |
| 5817 | * 4) If successfully created, indicates the device data is for an OAS lun, |
| 5818 | * indicates the lun is not available and add to the list of luns. |
| 5819 | * |
| 5820 | * Return codes: |
| 5821 | * false - Error |
| 5822 | * true - Success |
| 5823 | **/ |
| 5824 | bool |
| 5825 | 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] | 5826 | struct lpfc_name *target_wwpn, uint64_t lun, uint8_t pri) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5827 | { |
| 5828 | |
| 5829 | struct lpfc_device_data *lun_info; |
| 5830 | unsigned long flags; |
| 5831 | |
| 5832 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5833 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5834 | return false; |
| 5835 | |
| 5836 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5837 | |
| 5838 | /* Check to see if the device data for the lun has been created */ |
| 5839 | lun_info = __lpfc_get_device_data(phba, &phba->luns, vport_wwpn, |
| 5840 | target_wwpn, lun); |
| 5841 | if (lun_info) { |
| 5842 | if (!lun_info->oas_enabled) |
| 5843 | lun_info->oas_enabled = true; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5844 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5845 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5846 | return true; |
| 5847 | } |
| 5848 | |
| 5849 | /* Create an lun info structure and add to list of luns */ |
| 5850 | lun_info = lpfc_create_device_data(phba, vport_wwpn, target_wwpn, lun, |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5851 | pri, false); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5852 | if (lun_info) { |
| 5853 | lun_info->oas_enabled = true; |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 5854 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5855 | lun_info->available = false; |
| 5856 | list_add_tail(&lun_info->listentry, &phba->luns); |
| 5857 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5858 | return true; |
| 5859 | } |
| 5860 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5861 | return false; |
| 5862 | } |
| 5863 | |
| 5864 | /** |
| 5865 | * lpfc_disable_oas_lun - disables a lun for OAS operations |
| 5866 | * @pha: Pointer to host bus adapter structure. |
| 5867 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5868 | * @target_wwpn: Pointer to target's wwpn information |
| 5869 | * @lun: Lun |
| 5870 | * |
| 5871 | * This routine disables a lun for oas operations. The routines does so by |
| 5872 | * doing the following : |
| 5873 | * |
| 5874 | * 1) Checks to see if the device data for the lun is created. |
| 5875 | * 2) If present, clears the flag indicating this lun is for OAS. |
| 5876 | * 3) If the lun is not available by the system, the device data is |
| 5877 | * freed. |
| 5878 | * |
| 5879 | * Return codes: |
| 5880 | * false - Error |
| 5881 | * true - Success |
| 5882 | **/ |
| 5883 | bool |
| 5884 | 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] | 5885 | struct lpfc_name *target_wwpn, uint64_t lun, uint8_t pri) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5886 | { |
| 5887 | |
| 5888 | struct lpfc_device_data *lun_info; |
| 5889 | unsigned long flags; |
| 5890 | |
| 5891 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5892 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5893 | return false; |
| 5894 | |
| 5895 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5896 | |
| 5897 | /* Check to see if the lun is available. */ |
| 5898 | lun_info = __lpfc_get_device_data(phba, |
| 5899 | &phba->luns, vport_wwpn, |
| 5900 | target_wwpn, lun); |
| 5901 | if (lun_info) { |
| 5902 | lun_info->oas_enabled = false; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame] | 5903 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5904 | if (!lun_info->available) |
| 5905 | lpfc_delete_device_data(phba, lun_info); |
| 5906 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5907 | return true; |
| 5908 | } |
| 5909 | |
| 5910 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5911 | return false; |
| 5912 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5913 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5914 | static int |
| 5915 | lpfc_no_command(struct Scsi_Host *shost, struct scsi_cmnd *cmnd) |
| 5916 | { |
| 5917 | return SCSI_MLQUEUE_HOST_BUSY; |
| 5918 | } |
| 5919 | |
| 5920 | static int |
| 5921 | lpfc_no_handler(struct scsi_cmnd *cmnd) |
| 5922 | { |
| 5923 | return FAILED; |
| 5924 | } |
| 5925 | |
| 5926 | static int |
| 5927 | lpfc_no_slave(struct scsi_device *sdev) |
| 5928 | { |
| 5929 | return -ENODEV; |
| 5930 | } |
| 5931 | |
| 5932 | struct scsi_host_template lpfc_template_nvme = { |
| 5933 | .module = THIS_MODULE, |
| 5934 | .name = LPFC_DRIVER_NAME, |
| 5935 | .proc_name = LPFC_DRIVER_NAME, |
| 5936 | .info = lpfc_info, |
| 5937 | .queuecommand = lpfc_no_command, |
| 5938 | .eh_abort_handler = lpfc_no_handler, |
| 5939 | .eh_device_reset_handler = lpfc_no_handler, |
| 5940 | .eh_target_reset_handler = lpfc_no_handler, |
| 5941 | .eh_bus_reset_handler = lpfc_no_handler, |
| 5942 | .eh_host_reset_handler = lpfc_no_handler, |
| 5943 | .slave_alloc = lpfc_no_slave, |
| 5944 | .slave_configure = lpfc_no_slave, |
| 5945 | .scan_finished = lpfc_scan_finished, |
| 5946 | .this_id = -1, |
| 5947 | .sg_tablesize = 1, |
| 5948 | .cmd_per_lun = 1, |
| 5949 | .use_clustering = ENABLE_CLUSTERING, |
| 5950 | .shost_attrs = lpfc_hba_attrs, |
| 5951 | .max_sectors = 0xFFFF, |
| 5952 | .vendor_id = LPFC_NL_VENDOR_ID, |
| 5953 | .track_queue_depth = 0, |
| 5954 | }; |
| 5955 | |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 5956 | struct scsi_host_template lpfc_template_no_hr = { |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 5957 | .module = THIS_MODULE, |
| 5958 | .name = LPFC_DRIVER_NAME, |
James Smart | 08dcd4c | 2016-07-06 12:35:59 -0700 | [diff] [blame] | 5959 | .proc_name = LPFC_DRIVER_NAME, |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 5960 | .info = lpfc_info, |
| 5961 | .queuecommand = lpfc_queuecommand, |
James Smart | 856984b | 2017-03-04 09:30:32 -0800 | [diff] [blame^] | 5962 | .eh_timed_out = fc_eh_timed_out, |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 5963 | .eh_abort_handler = lpfc_abort_handler, |
| 5964 | .eh_device_reset_handler = lpfc_device_reset_handler, |
| 5965 | .eh_target_reset_handler = lpfc_target_reset_handler, |
| 5966 | .eh_bus_reset_handler = lpfc_bus_reset_handler, |
| 5967 | .slave_alloc = lpfc_slave_alloc, |
| 5968 | .slave_configure = lpfc_slave_configure, |
| 5969 | .slave_destroy = lpfc_slave_destroy, |
| 5970 | .scan_finished = lpfc_scan_finished, |
| 5971 | .this_id = -1, |
| 5972 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
| 5973 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
| 5974 | .use_clustering = ENABLE_CLUSTERING, |
| 5975 | .shost_attrs = lpfc_hba_attrs, |
| 5976 | .max_sectors = 0xFFFF, |
| 5977 | .vendor_id = LPFC_NL_VENDOR_ID, |
| 5978 | .change_queue_depth = scsi_change_queue_depth, |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 5979 | .track_queue_depth = 1, |
| 5980 | }; |
| 5981 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5982 | struct scsi_host_template lpfc_template = { |
| 5983 | .module = THIS_MODULE, |
| 5984 | .name = LPFC_DRIVER_NAME, |
James Smart | 08dcd4c | 2016-07-06 12:35:59 -0700 | [diff] [blame] | 5985 | .proc_name = LPFC_DRIVER_NAME, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5986 | .info = lpfc_info, |
| 5987 | .queuecommand = lpfc_queuecommand, |
Christoph Hellwig | b6a05c8 | 2017-01-30 13:18:58 +0100 | [diff] [blame] | 5988 | .eh_timed_out = fc_eh_timed_out, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5989 | .eh_abort_handler = lpfc_abort_handler, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5990 | .eh_device_reset_handler = lpfc_device_reset_handler, |
| 5991 | .eh_target_reset_handler = lpfc_target_reset_handler, |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5992 | .eh_bus_reset_handler = lpfc_bus_reset_handler, |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5993 | .eh_host_reset_handler = lpfc_host_reset_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5994 | .slave_alloc = lpfc_slave_alloc, |
| 5995 | .slave_configure = lpfc_slave_configure, |
| 5996 | .slave_destroy = lpfc_slave_destroy, |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 5997 | .scan_finished = lpfc_scan_finished, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5998 | .this_id = -1, |
James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 5999 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6000 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
| 6001 | .use_clustering = ENABLE_CLUSTERING, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6002 | .shost_attrs = lpfc_hba_attrs, |
James.Smart@Emulex.Com | 564b296 | 2005-06-25 10:34:17 -0400 | [diff] [blame] | 6003 | .max_sectors = 0xFFFF, |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 6004 | .vendor_id = LPFC_NL_VENDOR_ID, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 6005 | .change_queue_depth = scsi_change_queue_depth, |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 6006 | .track_queue_depth = 1, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6007 | }; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6008 | |
| 6009 | struct scsi_host_template lpfc_vport_template = { |
| 6010 | .module = THIS_MODULE, |
| 6011 | .name = LPFC_DRIVER_NAME, |
James Smart | 08dcd4c | 2016-07-06 12:35:59 -0700 | [diff] [blame] | 6012 | .proc_name = LPFC_DRIVER_NAME, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6013 | .info = lpfc_info, |
| 6014 | .queuecommand = lpfc_queuecommand, |
Christoph Hellwig | b6a05c8 | 2017-01-30 13:18:58 +0100 | [diff] [blame] | 6015 | .eh_timed_out = fc_eh_timed_out, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6016 | .eh_abort_handler = lpfc_abort_handler, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 6017 | .eh_device_reset_handler = lpfc_device_reset_handler, |
| 6018 | .eh_target_reset_handler = lpfc_target_reset_handler, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6019 | .slave_alloc = lpfc_slave_alloc, |
| 6020 | .slave_configure = lpfc_slave_configure, |
| 6021 | .slave_destroy = lpfc_slave_destroy, |
| 6022 | .scan_finished = lpfc_scan_finished, |
| 6023 | .this_id = -1, |
James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 6024 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6025 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
| 6026 | .use_clustering = ENABLE_CLUSTERING, |
| 6027 | .shost_attrs = lpfc_vport_attrs, |
| 6028 | .max_sectors = 0xFFFF, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 6029 | .change_queue_depth = scsi_change_queue_depth, |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 6030 | .track_queue_depth = 1, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6031 | }; |