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 | 51f4ca3 | 2016-07-06 12:36:13 -0700 | [diff] [blame] | 4 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 5 | * EMULEX and SLI are trademarks of Emulex. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6 | * www.emulex.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8 | * * |
| 9 | * 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] | 10 | * modify it under the terms of version 2 of the GNU General * |
| 11 | * Public License as published by the Free Software Foundation. * |
| 12 | * This program is distributed in the hope that it will be useful. * |
| 13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 18 | * more details, a copy of which can be found in the file COPYING * |
| 19 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 20 | *******************************************************************/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 21 | #include <linux/pci.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/slab.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 23 | #include <linux/interrupt.h> |
Paul Gortmaker | 0970366 | 2011-05-27 09:37:25 -0400 | [diff] [blame] | 24 | #include <linux/export.h> |
James Smart | a90f568 | 2006-08-17 11:58:04 -0400 | [diff] [blame] | 25 | #include <linux/delay.h> |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 26 | #include <asm/unaligned.h> |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 27 | #include <linux/crc-t10dif.h> |
| 28 | #include <net/checksum.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 29 | |
| 30 | #include <scsi/scsi.h> |
| 31 | #include <scsi/scsi_device.h> |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 32 | #include <scsi/scsi_eh.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 33 | #include <scsi/scsi_host.h> |
| 34 | #include <scsi/scsi_tcq.h> |
| 35 | #include <scsi/scsi_transport_fc.h> |
| 36 | |
| 37 | #include "lpfc_version.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 38 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 39 | #include "lpfc_hw.h" |
| 40 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 41 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 42 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 43 | #include "lpfc_disc.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 44 | #include "lpfc.h" |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 45 | #include "lpfc_scsi.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 46 | #include "lpfc_logmsg.h" |
| 47 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 48 | #include "lpfc_vport.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 49 | |
| 50 | #define LPFC_RESET_WAIT 2 |
| 51 | #define LPFC_ABORT_WAIT 2 |
| 52 | |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 53 | int _dump_buf_done = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 54 | |
| 55 | static char *dif_op_str[] = { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 56 | "PROT_NORMAL", |
| 57 | "PROT_READ_INSERT", |
| 58 | "PROT_WRITE_STRIP", |
| 59 | "PROT_READ_STRIP", |
| 60 | "PROT_WRITE_INSERT", |
| 61 | "PROT_READ_PASS", |
| 62 | "PROT_WRITE_PASS", |
| 63 | }; |
| 64 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 65 | struct scsi_dif_tuple { |
| 66 | __be16 guard_tag; /* Checksum */ |
| 67 | __be16 app_tag; /* Opaque storage */ |
| 68 | __be32 ref_tag; /* Target LBA or indirect LBA */ |
| 69 | }; |
| 70 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 71 | static struct lpfc_rport_data * |
| 72 | lpfc_rport_data_from_scsi_device(struct scsi_device *sdev) |
| 73 | { |
| 74 | struct lpfc_vport *vport = (struct lpfc_vport *)sdev->host->hostdata; |
| 75 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 76 | if (vport->phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 77 | return ((struct lpfc_device_data *)sdev->hostdata)->rport_data; |
| 78 | else |
| 79 | return (struct lpfc_rport_data *)sdev->hostdata; |
| 80 | } |
| 81 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 82 | static void |
| 83 | 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] | 84 | static void |
| 85 | 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] | 86 | static int |
| 87 | lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 88 | |
| 89 | static void |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 90 | lpfc_debug_save_data(struct lpfc_hba *phba, struct scsi_cmnd *cmnd) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 91 | { |
| 92 | void *src, *dst; |
| 93 | struct scatterlist *sgde = scsi_sglist(cmnd); |
| 94 | |
| 95 | if (!_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 96 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 97 | "9050 BLKGRD: ERROR %s _dump_buf_data is NULL\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 98 | __func__); |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | |
| 103 | if (!sgde) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 104 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 105 | "9051 BLKGRD: ERROR: data scatterlist is null\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 106 | return; |
| 107 | } |
| 108 | |
| 109 | dst = (void *) _dump_buf_data; |
| 110 | while (sgde) { |
| 111 | src = sg_virt(sgde); |
| 112 | memcpy(dst, src, sgde->length); |
| 113 | dst += sgde->length; |
| 114 | sgde = sg_next(sgde); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | static void |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 119 | lpfc_debug_save_dif(struct lpfc_hba *phba, struct scsi_cmnd *cmnd) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 120 | { |
| 121 | void *src, *dst; |
| 122 | struct scatterlist *sgde = scsi_prot_sglist(cmnd); |
| 123 | |
| 124 | if (!_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 125 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 126 | "9052 BLKGRD: ERROR %s _dump_buf_data is NULL\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 127 | __func__); |
| 128 | return; |
| 129 | } |
| 130 | |
| 131 | if (!sgde) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 132 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 133 | "9053 BLKGRD: ERROR: prot scatterlist is null\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 134 | return; |
| 135 | } |
| 136 | |
| 137 | dst = _dump_buf_dif; |
| 138 | while (sgde) { |
| 139 | src = sg_virt(sgde); |
| 140 | memcpy(dst, src, sgde->length); |
| 141 | dst += sgde->length; |
| 142 | sgde = sg_next(sgde); |
| 143 | } |
| 144 | } |
| 145 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 146 | static inline unsigned |
| 147 | lpfc_cmd_blksize(struct scsi_cmnd *sc) |
| 148 | { |
| 149 | return sc->device->sector_size; |
| 150 | } |
| 151 | |
| 152 | #define LPFC_CHECK_PROTECT_GUARD 1 |
| 153 | #define LPFC_CHECK_PROTECT_REF 2 |
| 154 | static inline unsigned |
| 155 | lpfc_cmd_protect(struct scsi_cmnd *sc, int flag) |
| 156 | { |
| 157 | return 1; |
| 158 | } |
| 159 | |
| 160 | static inline unsigned |
| 161 | lpfc_cmd_guard_csum(struct scsi_cmnd *sc) |
| 162 | { |
| 163 | if (lpfc_prot_group_type(NULL, sc) == LPFC_PG_TYPE_NO_DIF) |
| 164 | return 0; |
| 165 | if (scsi_host_get_guard(sc->device->host) == SHOST_DIX_GUARD_IP) |
| 166 | return 1; |
| 167 | return 0; |
| 168 | } |
| 169 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 170 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 171 | * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge. |
| 172 | * @phba: Pointer to HBA object. |
| 173 | * @lpfc_cmd: lpfc scsi command object pointer. |
| 174 | * |
| 175 | * This function is called from the lpfc_prep_task_mgmt_cmd function to |
| 176 | * set the last bit in the response sge entry. |
| 177 | **/ |
| 178 | static void |
| 179 | lpfc_sli4_set_rsp_sgl_last(struct lpfc_hba *phba, |
| 180 | struct lpfc_scsi_buf *lpfc_cmd) |
| 181 | { |
| 182 | struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 183 | if (sgl) { |
| 184 | sgl += 1; |
| 185 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 186 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 187 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 192 | * lpfc_update_stats - Update statistical data for the command completion |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 193 | * @phba: Pointer to HBA object. |
| 194 | * @lpfc_cmd: lpfc scsi command object pointer. |
| 195 | * |
| 196 | * This function is called when there is a command completion and this |
| 197 | * function updates the statistical data for the command completion. |
| 198 | **/ |
| 199 | static void |
| 200 | lpfc_update_stats(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 201 | { |
| 202 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| 203 | struct lpfc_nodelist *pnode = rdata->pnode; |
| 204 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 205 | unsigned long flags; |
| 206 | struct Scsi_Host *shost = cmd->device->host; |
| 207 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 208 | unsigned long latency; |
| 209 | int i; |
| 210 | |
| 211 | if (cmd->result) |
| 212 | return; |
| 213 | |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 214 | latency = jiffies_to_msecs((long)jiffies - (long)lpfc_cmd->start_time); |
| 215 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 216 | spin_lock_irqsave(shost->host_lock, flags); |
| 217 | if (!vport->stat_data_enabled || |
| 218 | vport->stat_data_blocked || |
James Smart | 5989b8d | 2010-10-22 11:06:56 -0400 | [diff] [blame] | 219 | !pnode || |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 220 | !pnode->lat_data || |
| 221 | (phba->bucket_type == LPFC_NO_BUCKET)) { |
| 222 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 223 | return; |
| 224 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 225 | |
| 226 | if (phba->bucket_type == LPFC_LINEAR_BUCKET) { |
| 227 | i = (latency + phba->bucket_step - 1 - phba->bucket_base)/ |
| 228 | phba->bucket_step; |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 229 | /* check array subscript bounds */ |
| 230 | if (i < 0) |
| 231 | i = 0; |
| 232 | else if (i >= LPFC_MAX_BUCKET_COUNT) |
| 233 | i = LPFC_MAX_BUCKET_COUNT - 1; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 234 | } else { |
| 235 | for (i = 0; i < LPFC_MAX_BUCKET_COUNT-1; i++) |
| 236 | if (latency <= (phba->bucket_base + |
| 237 | ((1<<i)*phba->bucket_step))) |
| 238 | break; |
| 239 | } |
| 240 | |
| 241 | pnode->lat_data[i].cmd_count++; |
| 242 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 243 | } |
| 244 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 245 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 246 | * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 247 | * @phba: The Hba for which this call is being executed. |
| 248 | * |
| 249 | * This routine is called when there is resource error in driver or firmware. |
| 250 | * This routine posts WORKER_RAMP_DOWN_QUEUE event for @phba. This routine |
| 251 | * posts at most 1 event each second. This routine wakes up worker thread of |
| 252 | * @phba to process WORKER_RAM_DOWN_EVENT event. |
| 253 | * |
| 254 | * This routine should be called with no lock held. |
| 255 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 256 | void |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 257 | lpfc_rampdown_queue_depth(struct lpfc_hba *phba) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 258 | { |
| 259 | unsigned long flags; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 260 | uint32_t evt_posted; |
Manuel Schölling | 0d4aec1 | 2014-09-03 12:55:58 -0400 | [diff] [blame] | 261 | unsigned long expires; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 262 | |
| 263 | spin_lock_irqsave(&phba->hbalock, flags); |
| 264 | atomic_inc(&phba->num_rsrc_err); |
| 265 | phba->last_rsrc_error_time = jiffies; |
| 266 | |
Manuel Schölling | 0d4aec1 | 2014-09-03 12:55:58 -0400 | [diff] [blame] | 267 | expires = phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL; |
| 268 | if (time_after(expires, jiffies)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 269 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 270 | return; |
| 271 | } |
| 272 | |
| 273 | phba->last_ramp_down_time = jiffies; |
| 274 | |
| 275 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 276 | |
| 277 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 278 | evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE; |
| 279 | if (!evt_posted) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 280 | phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 281 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
| 282 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 283 | if (!evt_posted) |
| 284 | lpfc_worker_wake_up(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 285 | return; |
| 286 | } |
| 287 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 288 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 289 | * lpfc_ramp_down_queue_handler - WORKER_RAMP_DOWN_QUEUE event handler |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 290 | * @phba: The Hba for which this call is being executed. |
| 291 | * |
| 292 | * This routine is called to process WORKER_RAMP_DOWN_QUEUE event for worker |
| 293 | * thread.This routine reduces queue depth for all scsi device on each vport |
| 294 | * associated with @phba. |
| 295 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 296 | void |
| 297 | lpfc_ramp_down_queue_handler(struct lpfc_hba *phba) |
| 298 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 299 | struct lpfc_vport **vports; |
| 300 | struct Scsi_Host *shost; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 301 | struct scsi_device *sdev; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 302 | unsigned long new_queue_depth; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 303 | unsigned long num_rsrc_err, num_cmd_success; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 304 | int i; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 305 | |
| 306 | num_rsrc_err = atomic_read(&phba->num_rsrc_err); |
| 307 | num_cmd_success = atomic_read(&phba->num_cmd_success); |
| 308 | |
James Smart | 75ad83a | 2012-05-09 21:18:40 -0400 | [diff] [blame] | 309 | /* |
| 310 | * The error and success command counters are global per |
| 311 | * driver instance. If another handler has already |
| 312 | * operated on this error event, just exit. |
| 313 | */ |
| 314 | if (num_rsrc_err == 0) |
| 315 | return; |
| 316 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 317 | vports = lpfc_create_vport_work_array(phba); |
| 318 | if (vports != NULL) |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 319 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 320 | shost = lpfc_shost_from_vport(vports[i]); |
| 321 | shost_for_each_device(sdev, shost) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 322 | new_queue_depth = |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 323 | sdev->queue_depth * num_rsrc_err / |
| 324 | (num_rsrc_err + num_cmd_success); |
| 325 | if (!new_queue_depth) |
| 326 | new_queue_depth = sdev->queue_depth - 1; |
| 327 | else |
| 328 | new_queue_depth = sdev->queue_depth - |
| 329 | new_queue_depth; |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 330 | scsi_change_queue_depth(sdev, new_queue_depth); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 331 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 332 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 333 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 334 | atomic_set(&phba->num_rsrc_err, 0); |
| 335 | atomic_set(&phba->num_cmd_success, 0); |
| 336 | } |
| 337 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 338 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 339 | * lpfc_scsi_dev_block - set all scsi hosts to block state |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 340 | * @phba: Pointer to HBA context object. |
| 341 | * |
| 342 | * This function walks vport list and set each SCSI host to block state |
| 343 | * by invoking fc_remote_port_delete() routine. This function is invoked |
| 344 | * with EEH when device's PCI slot has been permanently disabled. |
| 345 | **/ |
| 346 | void |
| 347 | lpfc_scsi_dev_block(struct lpfc_hba *phba) |
| 348 | { |
| 349 | struct lpfc_vport **vports; |
| 350 | struct Scsi_Host *shost; |
| 351 | struct scsi_device *sdev; |
| 352 | struct fc_rport *rport; |
| 353 | int i; |
| 354 | |
| 355 | vports = lpfc_create_vport_work_array(phba); |
| 356 | if (vports != NULL) |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 357 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 358 | shost = lpfc_shost_from_vport(vports[i]); |
| 359 | shost_for_each_device(sdev, shost) { |
| 360 | rport = starget_to_rport(scsi_target(sdev)); |
| 361 | fc_remote_port_delete(rport); |
| 362 | } |
| 363 | } |
| 364 | lpfc_destroy_vport_work_array(phba, vports); |
| 365 | } |
| 366 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 367 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 368 | * 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] | 369 | * @vport: The virtual port for which this call being executed. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 370 | * @num_to_allocate: The requested number of buffers to allocate. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 371 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 372 | * This routine allocates a scsi buffer for device with SLI-3 interface spec, |
| 373 | * the scsi buffer contains all the necessary information needed to initiate |
| 374 | * a SCSI I/O. The non-DMAable buffer region contains information to build |
| 375 | * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP, |
| 376 | * and the initial BPL. In addition to allocating memory, the FCP CMND and |
| 377 | * 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] | 378 | * |
| 379 | * Return codes: |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 380 | * int - number of scsi buffers that were allocated. |
| 381 | * 0 = failure, less than num_to_alloc is a partial failure. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 382 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 383 | static int |
| 384 | lpfc_new_scsi_buf_s3(struct lpfc_vport *vport, int num_to_alloc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 385 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 386 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 387 | struct lpfc_scsi_buf *psb; |
| 388 | struct ulp_bde64 *bpl; |
| 389 | IOCB_t *iocb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 390 | dma_addr_t pdma_phys_fcp_cmd; |
| 391 | dma_addr_t pdma_phys_fcp_rsp; |
| 392 | dma_addr_t pdma_phys_bpl; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 393 | uint16_t iotag; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 394 | int bcnt, bpl_size; |
| 395 | |
| 396 | bpl_size = phba->cfg_sg_dma_buf_size - |
| 397 | (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); |
| 398 | |
| 399 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 400 | "9067 ALLOC %d scsi_bufs: %d (%d + %d + %d)\n", |
| 401 | num_to_alloc, phba->cfg_sg_dma_buf_size, |
| 402 | (int)sizeof(struct fcp_cmnd), |
| 403 | (int)sizeof(struct fcp_rsp), bpl_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 404 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 405 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
| 406 | psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL); |
| 407 | if (!psb) |
| 408 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 409 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 410 | /* |
| 411 | * Get memory from the pci pool to map the virt space to pci |
| 412 | * bus space for an I/O. The DMA buffer includes space for the |
| 413 | * struct fcp_cmnd, struct fcp_rsp and the number of bde's |
| 414 | * necessary to support the sg_tablesize. |
| 415 | */ |
Souptick Joarder | b4b22a0 | 2016-11-28 15:22:37 +0530 | [diff] [blame] | 416 | psb->data = pci_pool_zalloc(phba->lpfc_scsi_dma_buf_pool, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 417 | GFP_KERNEL, &psb->dma_handle); |
| 418 | if (!psb->data) { |
| 419 | kfree(psb); |
| 420 | break; |
| 421 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 422 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 423 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 424 | /* Allocate iotag for psb->cur_iocbq. */ |
| 425 | iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq); |
| 426 | if (iotag == 0) { |
| 427 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, |
| 428 | psb->data, psb->dma_handle); |
| 429 | kfree(psb); |
| 430 | break; |
| 431 | } |
| 432 | psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 433 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 434 | psb->fcp_cmnd = psb->data; |
| 435 | psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd); |
| 436 | psb->fcp_bpl = psb->data + sizeof(struct fcp_cmnd) + |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 437 | sizeof(struct fcp_rsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 438 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 439 | /* Initialize local short-hand pointers. */ |
| 440 | bpl = psb->fcp_bpl; |
| 441 | pdma_phys_fcp_cmd = psb->dma_handle; |
| 442 | pdma_phys_fcp_rsp = psb->dma_handle + sizeof(struct fcp_cmnd); |
| 443 | pdma_phys_bpl = psb->dma_handle + sizeof(struct fcp_cmnd) + |
| 444 | sizeof(struct fcp_rsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 445 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 446 | /* |
| 447 | * The first two bdes are the FCP_CMD and FCP_RSP. The balance |
| 448 | * are sg list bdes. Initialize the first two and leave the |
| 449 | * rest for queuecommand. |
| 450 | */ |
| 451 | bpl[0].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd)); |
| 452 | bpl[0].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd)); |
| 453 | bpl[0].tus.f.bdeSize = sizeof(struct fcp_cmnd); |
| 454 | bpl[0].tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 455 | bpl[0].tus.w = le32_to_cpu(bpl[0].tus.w); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 456 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 457 | /* Setup the physical region for the FCP RSP */ |
| 458 | bpl[1].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp)); |
| 459 | bpl[1].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp)); |
| 460 | bpl[1].tus.f.bdeSize = sizeof(struct fcp_rsp); |
| 461 | bpl[1].tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 462 | bpl[1].tus.w = le32_to_cpu(bpl[1].tus.w); |
| 463 | |
| 464 | /* |
| 465 | * Since the IOCB for the FCP I/O is built into this |
| 466 | * lpfc_scsi_buf, initialize it with all known data now. |
| 467 | */ |
| 468 | iocb = &psb->cur_iocbq.iocb; |
| 469 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; |
| 470 | if ((phba->sli_rev == 3) && |
| 471 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) { |
| 472 | /* fill in immediate fcp command BDE */ |
| 473 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_IMMED; |
| 474 | iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); |
| 475 | iocb->un.fcpi64.bdl.addrLow = offsetof(IOCB_t, |
| 476 | unsli3.fcp_ext.icd); |
| 477 | iocb->un.fcpi64.bdl.addrHigh = 0; |
| 478 | iocb->ulpBdeCount = 0; |
| 479 | iocb->ulpLe = 0; |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 480 | /* fill in response BDE */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 481 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeFlags = |
| 482 | BUFF_TYPE_BDE_64; |
| 483 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeSize = |
| 484 | sizeof(struct fcp_rsp); |
| 485 | iocb->unsli3.fcp_ext.rbde.addrLow = |
| 486 | putPaddrLow(pdma_phys_fcp_rsp); |
| 487 | iocb->unsli3.fcp_ext.rbde.addrHigh = |
| 488 | putPaddrHigh(pdma_phys_fcp_rsp); |
| 489 | } else { |
| 490 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
| 491 | iocb->un.fcpi64.bdl.bdeSize = |
| 492 | (2 * sizeof(struct ulp_bde64)); |
| 493 | iocb->un.fcpi64.bdl.addrLow = |
| 494 | putPaddrLow(pdma_phys_bpl); |
| 495 | iocb->un.fcpi64.bdl.addrHigh = |
| 496 | putPaddrHigh(pdma_phys_bpl); |
| 497 | iocb->ulpBdeCount = 1; |
| 498 | iocb->ulpLe = 1; |
| 499 | } |
| 500 | iocb->ulpClass = CLASS3; |
| 501 | psb->status = IOSTAT_SUCCESS; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 502 | /* Put it back into the SCSI buffer list */ |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 503 | psb->cur_iocbq.context1 = psb; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 504 | lpfc_release_scsi_buf_s3(phba, psb); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 505 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 506 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 507 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 508 | return bcnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 509 | } |
| 510 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 511 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 512 | * lpfc_sli4_vport_delete_fcp_xri_aborted -Remove all ndlp references for vport |
| 513 | * @vport: pointer to lpfc vport data structure. |
| 514 | * |
| 515 | * This routine is invoked by the vport cleanup for deletions and the cleanup |
| 516 | * for an ndlp on removal. |
| 517 | **/ |
| 518 | void |
| 519 | lpfc_sli4_vport_delete_fcp_xri_aborted(struct lpfc_vport *vport) |
| 520 | { |
| 521 | struct lpfc_hba *phba = vport->phba; |
| 522 | struct lpfc_scsi_buf *psb, *next_psb; |
| 523 | unsigned long iflag = 0; |
| 524 | |
| 525 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 526 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 527 | list_for_each_entry_safe(psb, next_psb, |
| 528 | &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) { |
| 529 | if (psb->rdata && psb->rdata->pnode |
| 530 | && psb->rdata->pnode->vport == vport) |
| 531 | psb->rdata = NULL; |
| 532 | } |
| 533 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 534 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 535 | } |
| 536 | |
| 537 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 538 | * lpfc_sli4_fcp_xri_aborted - Fast-path process of fcp xri abort |
| 539 | * @phba: pointer to lpfc hba data structure. |
| 540 | * @axri: pointer to the fcp xri abort wcqe structure. |
| 541 | * |
| 542 | * This routine is invoked by the worker thread to process a SLI4 fast-path |
| 543 | * FCP aborted xri. |
| 544 | **/ |
| 545 | void |
| 546 | lpfc_sli4_fcp_xri_aborted(struct lpfc_hba *phba, |
| 547 | struct sli4_wcqe_xri_aborted *axri) |
| 548 | { |
| 549 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 550 | uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 551 | struct lpfc_scsi_buf *psb, *next_psb; |
| 552 | unsigned long iflag = 0; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 553 | struct lpfc_iocbq *iocbq; |
| 554 | int i; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 555 | struct lpfc_nodelist *ndlp; |
| 556 | int rrq_empty = 0; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 557 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 558 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 559 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 560 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 561 | list_for_each_entry_safe(psb, next_psb, |
| 562 | &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) { |
| 563 | if (psb->cur_iocbq.sli4_xritag == xri) { |
| 564 | list_del(&psb->list); |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 565 | psb->exch_busy = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 566 | psb->status = IOSTAT_SUCCESS; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 567 | spin_unlock( |
| 568 | &phba->sli4_hba.abts_scsi_buf_list_lock); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 569 | if (psb->rdata && psb->rdata->pnode) |
| 570 | ndlp = psb->rdata->pnode; |
| 571 | else |
| 572 | ndlp = NULL; |
| 573 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 574 | rrq_empty = list_empty(&phba->active_rrq_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 575 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 576 | if (ndlp) { |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 577 | lpfc_set_rrq_active(phba, ndlp, |
| 578 | psb->cur_iocbq.sli4_lxritag, rxid, 1); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 579 | lpfc_sli4_abts_err_handler(phba, ndlp, axri); |
| 580 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 581 | lpfc_release_scsi_buf_s4(phba, psb); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 582 | if (rrq_empty) |
| 583 | lpfc_worker_wake_up(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 584 | return; |
| 585 | } |
| 586 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 587 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 588 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 589 | iocbq = phba->sli.iocbq_lookup[i]; |
| 590 | |
| 591 | if (!(iocbq->iocb_flag & LPFC_IO_FCP) || |
| 592 | (iocbq->iocb_flag & LPFC_IO_LIBDFC)) |
| 593 | continue; |
| 594 | if (iocbq->sli4_xritag != xri) |
| 595 | continue; |
| 596 | psb = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
| 597 | psb->exch_busy = 0; |
| 598 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 599 | if (!list_empty(&pring->txq)) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 600 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 601 | return; |
| 602 | |
| 603 | } |
| 604 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | /** |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 608 | * 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] | 609 | * @phba: pointer to lpfc hba data structure. |
| 610 | * @post_sblist: pointer to the scsi buffer list. |
| 611 | * |
| 612 | * This routine walks a list of scsi buffers that was passed in. It attempts |
| 613 | * to construct blocks of scsi buffer sgls which contains contiguous xris and |
| 614 | * uses the non-embedded SGL block post mailbox commands to post to the port. |
| 615 | * For single SCSI buffer sgl with non-contiguous xri, if any, it shall use |
| 616 | * embedded SGL post mailbox command for posting. The @post_sblist passed in |
| 617 | * must be local list, thus no lock is needed when manipulate the list. |
| 618 | * |
| 619 | * Returns: 0 = failure, non-zero number of successfully posted buffers. |
| 620 | **/ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 621 | static int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 622 | lpfc_sli4_post_scsi_sgl_list(struct lpfc_hba *phba, |
| 623 | struct list_head *post_sblist, int sb_count) |
| 624 | { |
| 625 | struct lpfc_scsi_buf *psb, *psb_next; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 626 | int status, sgl_size; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 627 | int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0; |
| 628 | dma_addr_t pdma_phys_bpl1; |
| 629 | int last_xritag = NO_XRI; |
| 630 | LIST_HEAD(prep_sblist); |
| 631 | LIST_HEAD(blck_sblist); |
| 632 | LIST_HEAD(scsi_sblist); |
| 633 | |
| 634 | /* sanity check */ |
| 635 | if (sb_count <= 0) |
| 636 | return -EINVAL; |
| 637 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 638 | sgl_size = phba->cfg_sg_dma_buf_size - |
| 639 | (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); |
| 640 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 641 | list_for_each_entry_safe(psb, psb_next, post_sblist, list) { |
| 642 | list_del_init(&psb->list); |
| 643 | block_cnt++; |
| 644 | if ((last_xritag != NO_XRI) && |
| 645 | (psb->cur_iocbq.sli4_xritag != last_xritag + 1)) { |
| 646 | /* a hole in xri block, form a sgl posting block */ |
| 647 | list_splice_init(&prep_sblist, &blck_sblist); |
| 648 | post_cnt = block_cnt - 1; |
| 649 | /* prepare list for next posting block */ |
| 650 | list_add_tail(&psb->list, &prep_sblist); |
| 651 | block_cnt = 1; |
| 652 | } else { |
| 653 | /* prepare list for next posting block */ |
| 654 | list_add_tail(&psb->list, &prep_sblist); |
| 655 | /* enough sgls for non-embed sgl mbox command */ |
| 656 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 657 | list_splice_init(&prep_sblist, &blck_sblist); |
| 658 | post_cnt = block_cnt; |
| 659 | block_cnt = 0; |
| 660 | } |
| 661 | } |
| 662 | num_posting++; |
| 663 | last_xritag = psb->cur_iocbq.sli4_xritag; |
| 664 | |
| 665 | /* end of repost sgl list condition for SCSI buffers */ |
| 666 | if (num_posting == sb_count) { |
| 667 | if (post_cnt == 0) { |
| 668 | /* last sgl posting block */ |
| 669 | list_splice_init(&prep_sblist, &blck_sblist); |
| 670 | post_cnt = block_cnt; |
| 671 | } else if (block_cnt == 1) { |
| 672 | /* last single sgl with non-contiguous xri */ |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 673 | if (sgl_size > SGL_PAGE_SIZE) |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 674 | pdma_phys_bpl1 = psb->dma_phys_bpl + |
| 675 | SGL_PAGE_SIZE; |
| 676 | else |
| 677 | pdma_phys_bpl1 = 0; |
| 678 | status = lpfc_sli4_post_sgl(phba, |
| 679 | psb->dma_phys_bpl, |
| 680 | pdma_phys_bpl1, |
| 681 | psb->cur_iocbq.sli4_xritag); |
| 682 | if (status) { |
| 683 | /* failure, put on abort scsi list */ |
| 684 | psb->exch_busy = 1; |
| 685 | } else { |
| 686 | /* success, put on SCSI buffer list */ |
| 687 | psb->exch_busy = 0; |
| 688 | psb->status = IOSTAT_SUCCESS; |
| 689 | num_posted++; |
| 690 | } |
| 691 | /* success, put on SCSI buffer sgl list */ |
| 692 | list_add_tail(&psb->list, &scsi_sblist); |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | /* continue until a nembed page worth of sgls */ |
| 697 | if (post_cnt == 0) |
| 698 | continue; |
| 699 | |
| 700 | /* post block of SCSI buffer list sgls */ |
| 701 | status = lpfc_sli4_post_scsi_sgl_block(phba, &blck_sblist, |
| 702 | post_cnt); |
| 703 | |
| 704 | /* don't reset xirtag due to hole in xri block */ |
| 705 | if (block_cnt == 0) |
| 706 | last_xritag = NO_XRI; |
| 707 | |
| 708 | /* reset SCSI buffer post count for next round of posting */ |
| 709 | post_cnt = 0; |
| 710 | |
| 711 | /* put posted SCSI buffer-sgl posted on SCSI buffer sgl list */ |
| 712 | while (!list_empty(&blck_sblist)) { |
| 713 | list_remove_head(&blck_sblist, psb, |
| 714 | struct lpfc_scsi_buf, list); |
| 715 | if (status) { |
| 716 | /* failure, put on abort scsi list */ |
| 717 | psb->exch_busy = 1; |
| 718 | } else { |
| 719 | /* success, put on SCSI buffer list */ |
| 720 | psb->exch_busy = 0; |
| 721 | psb->status = IOSTAT_SUCCESS; |
| 722 | num_posted++; |
| 723 | } |
| 724 | list_add_tail(&psb->list, &scsi_sblist); |
| 725 | } |
| 726 | } |
| 727 | /* Push SCSI buffers with sgl posted to the availble list */ |
| 728 | while (!list_empty(&scsi_sblist)) { |
| 729 | list_remove_head(&scsi_sblist, psb, |
| 730 | struct lpfc_scsi_buf, list); |
| 731 | lpfc_release_scsi_buf_s4(phba, psb); |
| 732 | } |
| 733 | return num_posted; |
| 734 | } |
| 735 | |
| 736 | /** |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 737 | * 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] | 738 | * @phba: pointer to lpfc hba data structure. |
| 739 | * |
| 740 | * 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] | 741 | * 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] | 742 | * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine |
| 743 | * is responsible for moving all scsi buffers on the lpfc_abts_scsi_sgl_list |
| 744 | * to the lpfc_scsi_buf_list. If the repost fails, reject all scsi buffers. |
| 745 | * |
| 746 | * Returns: 0 = success, non-zero failure. |
| 747 | **/ |
| 748 | int |
| 749 | lpfc_sli4_repost_scsi_sgl_list(struct lpfc_hba *phba) |
| 750 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 751 | LIST_HEAD(post_sblist); |
| 752 | int num_posted, rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 753 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 754 | /* get all SCSI buffers need to repost to a local list */ |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 755 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 756 | spin_lock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 757 | list_splice_init(&phba->lpfc_scsi_buf_list_get, &post_sblist); |
| 758 | list_splice(&phba->lpfc_scsi_buf_list_put, &post_sblist); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 759 | spin_unlock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 760 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 761 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 762 | /* post the list of scsi buffer sgls to port if available */ |
| 763 | if (!list_empty(&post_sblist)) { |
| 764 | num_posted = lpfc_sli4_post_scsi_sgl_list(phba, &post_sblist, |
| 765 | phba->sli4_hba.scsi_xri_cnt); |
| 766 | /* failed to post any scsi buffer, return error */ |
| 767 | if (num_posted == 0) |
| 768 | rc = -EIO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 769 | } |
| 770 | return rc; |
| 771 | } |
| 772 | |
| 773 | /** |
| 774 | * lpfc_new_scsi_buf_s4 - Scsi buffer allocator for HBA with SLI4 IF spec |
| 775 | * @vport: The virtual port for which this call being executed. |
| 776 | * @num_to_allocate: The requested number of buffers to allocate. |
| 777 | * |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 778 | * This routine allocates scsi buffers for device with SLI-4 interface spec, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 779 | * the scsi buffer contains all the necessary information needed to initiate |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 780 | * a SCSI I/O. After allocating up to @num_to_allocate SCSI buffers and put |
| 781 | * 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] | 782 | * |
| 783 | * Return codes: |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 784 | * int - number of scsi buffers that were allocated and posted. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 785 | * 0 = failure, less than num_to_alloc is a partial failure. |
| 786 | **/ |
| 787 | static int |
| 788 | lpfc_new_scsi_buf_s4(struct lpfc_vport *vport, int num_to_alloc) |
| 789 | { |
| 790 | struct lpfc_hba *phba = vport->phba; |
| 791 | struct lpfc_scsi_buf *psb; |
| 792 | struct sli4_sge *sgl; |
| 793 | IOCB_t *iocb; |
| 794 | dma_addr_t pdma_phys_fcp_cmd; |
| 795 | dma_addr_t pdma_phys_fcp_rsp; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 796 | dma_addr_t pdma_phys_bpl; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 797 | uint16_t iotag, lxri = 0; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 798 | int bcnt, num_posted, sgl_size; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 799 | LIST_HEAD(prep_sblist); |
| 800 | LIST_HEAD(post_sblist); |
| 801 | LIST_HEAD(scsi_sblist); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 802 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 803 | sgl_size = phba->cfg_sg_dma_buf_size - |
| 804 | (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); |
| 805 | |
| 806 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 807 | "9068 ALLOC %d scsi_bufs: %d (%d + %d + %d)\n", |
| 808 | num_to_alloc, phba->cfg_sg_dma_buf_size, sgl_size, |
| 809 | (int)sizeof(struct fcp_cmnd), |
| 810 | (int)sizeof(struct fcp_rsp)); |
| 811 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 812 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
| 813 | psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL); |
| 814 | if (!psb) |
| 815 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 816 | /* |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 817 | * Get memory from the pci pool to map the virt space to |
| 818 | * pci bus space for an I/O. The DMA buffer includes space |
| 819 | * for the struct fcp_cmnd, struct fcp_rsp and the number |
| 820 | * of bde's necessary to support the sg_tablesize. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 821 | */ |
Souptick Joarder | b4b22a0 | 2016-11-28 15:22:37 +0530 | [diff] [blame] | 822 | psb->data = pci_pool_zalloc(phba->lpfc_scsi_dma_buf_pool, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 823 | GFP_KERNEL, &psb->dma_handle); |
| 824 | if (!psb->data) { |
| 825 | kfree(psb); |
| 826 | break; |
| 827 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 828 | |
James Smart | 092cb03 | 2013-09-06 12:21:50 -0400 | [diff] [blame] | 829 | /* |
| 830 | * 4K Page alignment is CRITICAL to BlockGuard, double check |
| 831 | * to be sure. |
| 832 | */ |
| 833 | if (phba->cfg_enable_bg && (((unsigned long)(psb->data) & |
| 834 | (unsigned long)(SLI4_PAGE_SIZE - 1)) != 0)) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 835 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, |
| 836 | psb->data, psb->dma_handle); |
| 837 | kfree(psb); |
| 838 | break; |
| 839 | } |
| 840 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 841 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 842 | lxri = lpfc_sli4_next_xritag(phba); |
| 843 | if (lxri == NO_XRI) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 844 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, |
| 845 | psb->data, psb->dma_handle); |
| 846 | kfree(psb); |
| 847 | break; |
| 848 | } |
James Smart | f7bc643 | 2013-10-10 12:19:53 -0400 | [diff] [blame] | 849 | |
| 850 | /* Allocate iotag for psb->cur_iocbq. */ |
| 851 | iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq); |
| 852 | if (iotag == 0) { |
| 853 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, |
| 854 | psb->data, psb->dma_handle); |
| 855 | kfree(psb); |
| 856 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 857 | "3368 Failed to allocate IOTAG for" |
James Smart | f7bc643 | 2013-10-10 12:19:53 -0400 | [diff] [blame] | 858 | " XRI:0x%x\n", lxri); |
| 859 | lpfc_sli4_free_xri(phba, lxri); |
| 860 | break; |
| 861 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 862 | psb->cur_iocbq.sli4_lxritag = lxri; |
| 863 | psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 864 | psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 865 | psb->fcp_bpl = psb->data; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 866 | psb->fcp_cmnd = (psb->data + sgl_size); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 867 | psb->fcp_rsp = (struct fcp_rsp *)((uint8_t *)psb->fcp_cmnd + |
| 868 | sizeof(struct fcp_cmnd)); |
| 869 | |
| 870 | /* Initialize local short-hand pointers. */ |
| 871 | sgl = (struct sli4_sge *)psb->fcp_bpl; |
| 872 | pdma_phys_bpl = psb->dma_handle; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 873 | pdma_phys_fcp_cmd = (psb->dma_handle + sgl_size); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 874 | pdma_phys_fcp_rsp = pdma_phys_fcp_cmd + sizeof(struct fcp_cmnd); |
| 875 | |
| 876 | /* |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 877 | * The first two bdes are the FCP_CMD and FCP_RSP. |
| 878 | * The balance are sg list bdes. Initialize the |
| 879 | * first two and leave the rest for queuecommand. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 880 | */ |
| 881 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd)); |
| 882 | sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd)); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 883 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 884 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 885 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 886 | sgl->sge_len = cpu_to_le32(sizeof(struct fcp_cmnd)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 887 | sgl++; |
| 888 | |
| 889 | /* Setup the physical region for the FCP RSP */ |
| 890 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp)); |
| 891 | sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp)); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 892 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 893 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 894 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 895 | sgl->sge_len = cpu_to_le32(sizeof(struct fcp_rsp)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 896 | |
| 897 | /* |
| 898 | * Since the IOCB for the FCP I/O is built into this |
| 899 | * lpfc_scsi_buf, initialize it with all known data now. |
| 900 | */ |
| 901 | iocb = &psb->cur_iocbq.iocb; |
| 902 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; |
| 903 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_64; |
| 904 | /* setting the BLP size to 2 * sizeof BDE may not be correct. |
| 905 | * We are setting the bpl to point to out sgl. An sgl's |
| 906 | * entries are 16 bytes, a bpl entries are 12 bytes. |
| 907 | */ |
| 908 | iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); |
| 909 | iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys_fcp_cmd); |
| 910 | iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys_fcp_cmd); |
| 911 | iocb->ulpBdeCount = 1; |
| 912 | iocb->ulpLe = 1; |
| 913 | iocb->ulpClass = CLASS3; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 914 | psb->cur_iocbq.context1 = psb; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 915 | psb->dma_phys_bpl = pdma_phys_bpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 916 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 917 | /* add the scsi buffer to a post list */ |
| 918 | list_add_tail(&psb->list, &post_sblist); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 919 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 920 | phba->sli4_hba.scsi_xri_cnt++; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 921 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 922 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 923 | lpfc_printf_log(phba, KERN_INFO, LOG_BG, |
| 924 | "3021 Allocate %d out of %d requested new SCSI " |
| 925 | "buffers\n", bcnt, num_to_alloc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 926 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 927 | /* post the list of scsi buffer sgls to port if available */ |
| 928 | if (!list_empty(&post_sblist)) |
| 929 | num_posted = lpfc_sli4_post_scsi_sgl_list(phba, |
| 930 | &post_sblist, bcnt); |
| 931 | else |
| 932 | num_posted = 0; |
| 933 | |
| 934 | return num_posted; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 938 | * lpfc_new_scsi_buf - Wrapper funciton for scsi buffer allocator |
| 939 | * @vport: The virtual port for which this call being executed. |
| 940 | * @num_to_allocate: The requested number of buffers to allocate. |
| 941 | * |
| 942 | * This routine wraps the actual SCSI buffer allocator function pointer from |
| 943 | * the lpfc_hba struct. |
| 944 | * |
| 945 | * Return codes: |
| 946 | * int - number of scsi buffers that were allocated. |
| 947 | * 0 = failure, less than num_to_alloc is a partial failure. |
| 948 | **/ |
| 949 | static inline int |
| 950 | lpfc_new_scsi_buf(struct lpfc_vport *vport, int num_to_alloc) |
| 951 | { |
| 952 | return vport->phba->lpfc_new_scsi_buf(vport, num_to_alloc); |
| 953 | } |
| 954 | |
| 955 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 956 | * 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] | 957 | * @phba: The HBA for which this call is being executed. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 958 | * |
| 959 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list |
| 960 | * and returns to caller. |
| 961 | * |
| 962 | * Return codes: |
| 963 | * NULL - Error |
| 964 | * Pointer to lpfc_scsi_buf - Success |
| 965 | **/ |
Adrian Bunk | 455c53e | 2006-01-06 20:21:28 +0100 | [diff] [blame] | 966 | static struct lpfc_scsi_buf* |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 967 | lpfc_get_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 968 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 969 | struct lpfc_scsi_buf * lpfc_cmd = NULL; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 970 | 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] | 971 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 972 | |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 973 | spin_lock_irqsave(&phba->scsi_buf_list_get_lock, iflag); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 974 | list_remove_head(scsi_buf_list_get, lpfc_cmd, struct lpfc_scsi_buf, |
| 975 | list); |
| 976 | if (!lpfc_cmd) { |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 977 | spin_lock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 978 | list_splice(&phba->lpfc_scsi_buf_list_put, |
| 979 | &phba->lpfc_scsi_buf_list_get); |
| 980 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
| 981 | list_remove_head(scsi_buf_list_get, lpfc_cmd, |
| 982 | struct lpfc_scsi_buf, list); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 983 | spin_unlock(&phba->scsi_buf_list_put_lock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 984 | } |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 985 | spin_unlock_irqrestore(&phba->scsi_buf_list_get_lock, iflag); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 986 | return lpfc_cmd; |
| 987 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 988 | /** |
| 989 | * lpfc_get_scsi_buf_s4 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA |
| 990 | * @phba: The HBA for which this call is being executed. |
| 991 | * |
| 992 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list |
| 993 | * and returns to caller. |
| 994 | * |
| 995 | * Return codes: |
| 996 | * NULL - Error |
| 997 | * Pointer to lpfc_scsi_buf - Success |
| 998 | **/ |
| 999 | static struct lpfc_scsi_buf* |
| 1000 | lpfc_get_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| 1001 | { |
James Smart | 3be30e0 | 2013-05-31 17:05:17 -0400 | [diff] [blame] | 1002 | struct lpfc_scsi_buf *lpfc_cmd, *lpfc_cmd_next; |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 1003 | unsigned long iflag = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1004 | int found = 0; |
| 1005 | |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 1006 | spin_lock_irqsave(&phba->scsi_buf_list_get_lock, iflag); |
James Smart | 3be30e0 | 2013-05-31 17:05:17 -0400 | [diff] [blame] | 1007 | list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next, |
| 1008 | &phba->lpfc_scsi_buf_list_get, list) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1009 | if (lpfc_test_rrq_active(phba, ndlp, |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 1010 | lpfc_cmd->cur_iocbq.sli4_lxritag)) |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1011 | continue; |
| 1012 | list_del(&lpfc_cmd->list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1013 | found = 1; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1014 | break; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1015 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1016 | if (!found) { |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 1017 | spin_lock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1018 | list_splice(&phba->lpfc_scsi_buf_list_put, |
| 1019 | &phba->lpfc_scsi_buf_list_get); |
| 1020 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 1021 | spin_unlock(&phba->scsi_buf_list_put_lock); |
James Smart | 3be30e0 | 2013-05-31 17:05:17 -0400 | [diff] [blame] | 1022 | list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next, |
| 1023 | &phba->lpfc_scsi_buf_list_get, list) { |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1024 | if (lpfc_test_rrq_active( |
| 1025 | phba, ndlp, lpfc_cmd->cur_iocbq.sli4_lxritag)) |
| 1026 | continue; |
| 1027 | list_del(&lpfc_cmd->list); |
| 1028 | found = 1; |
| 1029 | break; |
| 1030 | } |
| 1031 | } |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 1032 | spin_unlock_irqrestore(&phba->scsi_buf_list_get_lock, iflag); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1033 | if (!found) |
| 1034 | return NULL; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1035 | return lpfc_cmd; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1036 | } |
| 1037 | /** |
| 1038 | * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA |
| 1039 | * @phba: The HBA for which this call is being executed. |
| 1040 | * |
| 1041 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list |
| 1042 | * and returns to caller. |
| 1043 | * |
| 1044 | * Return codes: |
| 1045 | * NULL - Error |
| 1046 | * Pointer to lpfc_scsi_buf - Success |
| 1047 | **/ |
| 1048 | static struct lpfc_scsi_buf* |
| 1049 | lpfc_get_scsi_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
| 1050 | { |
| 1051 | return phba->lpfc_get_scsi_buf(phba, ndlp); |
| 1052 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1053 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 1054 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1055 | * 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] | 1056 | * @phba: The Hba for which this call is being executed. |
| 1057 | * @psb: The scsi buffer which is being released. |
| 1058 | * |
| 1059 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
| 1060 | * lpfc_scsi_buf_list list. |
| 1061 | **/ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1062 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1063 | 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] | 1064 | { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1065 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1066 | |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1067 | psb->seg_cnt = 0; |
| 1068 | psb->nonsg_phys = 0; |
| 1069 | psb->prot_seg_cnt = 0; |
| 1070 | |
| 1071 | spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1072 | psb->pCmd = NULL; |
James Smart | 6a485eb | 2013-04-17 20:19:00 -0400 | [diff] [blame] | 1073 | psb->cur_iocbq.iocb_flag = LPFC_IO_FCP; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1074 | list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list_put); |
| 1075 | spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1076 | } |
| 1077 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 1078 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1079 | * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list. |
| 1080 | * @phba: The Hba for which this call is being executed. |
| 1081 | * @psb: The scsi buffer which is being released. |
| 1082 | * |
| 1083 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
| 1084 | * lpfc_scsi_buf_list list. For SLI4 XRI's are tied to the scsi buffer |
| 1085 | * and cannot be reused for at least RA_TOV amount of time if it was |
| 1086 | * aborted. |
| 1087 | **/ |
| 1088 | static void |
| 1089 | lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) |
| 1090 | { |
| 1091 | unsigned long iflag = 0; |
| 1092 | |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1093 | psb->seg_cnt = 0; |
| 1094 | psb->nonsg_phys = 0; |
| 1095 | psb->prot_seg_cnt = 0; |
| 1096 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 1097 | if (psb->exch_busy) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1098 | spin_lock_irqsave(&phba->sli4_hba.abts_scsi_buf_list_lock, |
| 1099 | iflag); |
| 1100 | psb->pCmd = NULL; |
| 1101 | list_add_tail(&psb->list, |
| 1102 | &phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 1103 | spin_unlock_irqrestore(&phba->sli4_hba.abts_scsi_buf_list_lock, |
| 1104 | iflag); |
| 1105 | } else { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1106 | psb->pCmd = NULL; |
James Smart | 6a485eb | 2013-04-17 20:19:00 -0400 | [diff] [blame] | 1107 | psb->cur_iocbq.iocb_flag = LPFC_IO_FCP; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1108 | spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag); |
| 1109 | list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list_put); |
| 1110 | spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1111 | } |
| 1112 | } |
| 1113 | |
| 1114 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1115 | * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list. |
| 1116 | * @phba: The Hba for which this call is being executed. |
| 1117 | * @psb: The scsi buffer which is being released. |
| 1118 | * |
| 1119 | * This routine releases @psb scsi buffer by adding it to tail of @phba |
| 1120 | * lpfc_scsi_buf_list list. |
| 1121 | **/ |
| 1122 | static void |
| 1123 | lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) |
| 1124 | { |
| 1125 | |
| 1126 | phba->lpfc_release_scsi_buf(phba, psb); |
| 1127 | } |
| 1128 | |
| 1129 | /** |
| 1130 | * 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] | 1131 | * @phba: The Hba for which this call is being executed. |
| 1132 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 1133 | * |
| 1134 | * 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] | 1135 | * 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] | 1136 | * through sg elements and format the bde. This routine also initializes all |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1137 | * IOCB fields which are dependent on scsi command request buffer. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 1138 | * |
| 1139 | * Return codes: |
| 1140 | * 1 - Error |
| 1141 | * 0 - Success |
| 1142 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1143 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1144 | 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] | 1145 | { |
| 1146 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 1147 | struct scatterlist *sgel = NULL; |
| 1148 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 1149 | struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1150 | struct lpfc_iocbq *iocbq = &lpfc_cmd->cur_iocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1151 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1152 | struct ulp_bde64 *data_bde = iocb_cmd->unsli3.fcp_ext.dbde; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1153 | dma_addr_t physaddr; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1154 | uint32_t num_bde = 0; |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1155 | int nseg, datadir = scsi_cmnd->sc_data_direction; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1156 | |
| 1157 | /* |
| 1158 | * There are three possibilities here - use scatter-gather segment, use |
| 1159 | * the single mapping, or neither. Start the lpfc command prep by |
| 1160 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 1161 | * data bde entry. |
| 1162 | */ |
| 1163 | bpl += 2; |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 1164 | if (scsi_sg_count(scsi_cmnd)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1165 | /* |
| 1166 | * The driver stores the segment count returned from pci_map_sg |
| 1167 | * because this a count of dma-mappings used to map the use_sg |
| 1168 | * pages. They are not guaranteed to be the same for those |
| 1169 | * architectures that implement an IOMMU. |
| 1170 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1171 | |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 1172 | nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd), |
| 1173 | scsi_sg_count(scsi_cmnd), datadir); |
| 1174 | if (unlikely(!nseg)) |
| 1175 | return 1; |
| 1176 | |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1177 | lpfc_cmd->seg_cnt = nseg; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1178 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1179 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1180 | "9064 BLKGRD: %s: Too many sg segments from " |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1181 | "dma_map_sg. Config %d, seg_cnt %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1182 | __func__, phba->cfg_sg_seg_cnt, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1183 | lpfc_cmd->seg_cnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 1184 | lpfc_cmd->seg_cnt = 0; |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1185 | scsi_dma_unmap(scsi_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1186 | return 1; |
| 1187 | } |
| 1188 | |
| 1189 | /* |
| 1190 | * The driver established a maximum scatter-gather segment count |
| 1191 | * during probe that limits the number of sg elements in any |
| 1192 | * single scsi command. Just run through the seg_cnt and format |
| 1193 | * the bde's. |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1194 | * When using SLI-3 the driver will try to fit all the BDEs into |
| 1195 | * the IOCB. If it can't then the BDEs get added to a BPL as it |
| 1196 | * does for SLI-2 mode. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1197 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1198 | scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1199 | physaddr = sg_dma_address(sgel); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1200 | if (phba->sli_rev == 3 && |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1201 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1202 | !(iocbq->iocb_flag & DSS_SECURITY_OP) && |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1203 | nseg <= LPFC_EXT_DATA_BDE_COUNT) { |
| 1204 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1205 | data_bde->tus.f.bdeSize = sg_dma_len(sgel); |
| 1206 | data_bde->addrLow = putPaddrLow(physaddr); |
| 1207 | data_bde->addrHigh = putPaddrHigh(physaddr); |
| 1208 | data_bde++; |
| 1209 | } else { |
| 1210 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1211 | bpl->tus.f.bdeSize = sg_dma_len(sgel); |
| 1212 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 1213 | bpl->addrLow = |
| 1214 | le32_to_cpu(putPaddrLow(physaddr)); |
| 1215 | bpl->addrHigh = |
| 1216 | le32_to_cpu(putPaddrHigh(physaddr)); |
| 1217 | bpl++; |
| 1218 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1219 | } |
FUJITA Tomonori | c59fd9e | 2007-07-04 06:03:11 -0700 | [diff] [blame] | 1220 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1221 | |
| 1222 | /* |
| 1223 | * Finish initializing those IOCB fields that are dependent on the |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1224 | * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is |
| 1225 | * explicitly reinitialized and for SLI-3 the extended bde count is |
| 1226 | * explicitly reinitialized since all iocb memory resources are reused. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1227 | */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1228 | if (phba->sli_rev == 3 && |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1229 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
| 1230 | !(iocbq->iocb_flag & DSS_SECURITY_OP)) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1231 | if (num_bde > LPFC_EXT_DATA_BDE_COUNT) { |
| 1232 | /* |
| 1233 | * The extended IOCB format can only fit 3 BDE or a BPL. |
| 1234 | * This I/O has more than 3 BDE so the 1st data bde will |
| 1235 | * be a BPL that is filled in here. |
| 1236 | */ |
| 1237 | physaddr = lpfc_cmd->dma_handle; |
| 1238 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BLP_64; |
| 1239 | data_bde->tus.f.bdeSize = (num_bde * |
| 1240 | sizeof(struct ulp_bde64)); |
| 1241 | physaddr += (sizeof(struct fcp_cmnd) + |
| 1242 | sizeof(struct fcp_rsp) + |
| 1243 | (2 * sizeof(struct ulp_bde64))); |
| 1244 | data_bde->addrHigh = putPaddrHigh(physaddr); |
| 1245 | data_bde->addrLow = putPaddrLow(physaddr); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1246 | /* ebde count includes the response bde and data bpl */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1247 | iocb_cmd->unsli3.fcp_ext.ebde_count = 2; |
| 1248 | } else { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1249 | /* ebde count includes the response bde and data bdes */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1250 | iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); |
| 1251 | } |
| 1252 | } else { |
| 1253 | iocb_cmd->un.fcpi64.bdl.bdeSize = |
| 1254 | ((num_bde + 2) * sizeof(struct ulp_bde64)); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1255 | iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1256 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1257 | fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1258 | |
| 1259 | /* |
| 1260 | * Due to difference in data length between DIF/non-DIF paths, |
| 1261 | * we need to set word 4 of IOCB here |
| 1262 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1263 | iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1264 | return 0; |
| 1265 | } |
| 1266 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1267 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1268 | |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1269 | /* Return BG_ERR_INIT if error injection is detected by Initiator */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1270 | #define BG_ERR_INIT 0x1 |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1271 | /* Return BG_ERR_TGT if error injection is detected by Target */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1272 | #define BG_ERR_TGT 0x2 |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1273 | /* 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] | 1274 | #define BG_ERR_SWAP 0x10 |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 1275 | /** |
| 1276 | * Return BG_ERR_CHECK if disabling Guard/Ref/App checking is required for |
| 1277 | * error injection |
| 1278 | **/ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1279 | #define BG_ERR_CHECK 0x20 |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1280 | |
| 1281 | /** |
| 1282 | * lpfc_bg_err_inject - Determine if we should inject an error |
| 1283 | * @phba: The Hba for which this call is being executed. |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1284 | * @sc: The SCSI command to examine |
| 1285 | * @reftag: (out) BlockGuard reference tag for transmitted data |
| 1286 | * @apptag: (out) BlockGuard application tag for transmitted data |
| 1287 | * @new_guard (in) Value to replace CRC with if needed |
| 1288 | * |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1289 | * Returns BG_ERR_* bit mask or 0 if request ignored |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1290 | **/ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1291 | static int |
| 1292 | lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1293 | uint32_t *reftag, uint16_t *apptag, uint32_t new_guard) |
| 1294 | { |
| 1295 | struct scatterlist *sgpe; /* s/g prot entry */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1296 | struct lpfc_scsi_buf *lpfc_cmd = NULL; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1297 | struct scsi_dif_tuple *src = NULL; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1298 | struct lpfc_nodelist *ndlp; |
| 1299 | struct lpfc_rport_data *rdata; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1300 | uint32_t op = scsi_get_prot_op(sc); |
| 1301 | uint32_t blksize; |
| 1302 | uint32_t numblks; |
| 1303 | sector_t lba; |
| 1304 | int rc = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1305 | int blockoff = 0; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1306 | |
| 1307 | if (op == SCSI_PROT_NORMAL) |
| 1308 | return 0; |
| 1309 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1310 | sgpe = scsi_prot_sglist(sc); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1311 | lba = scsi_get_lba(sc); |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1312 | |
| 1313 | /* First check if we need to match the LBA */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1314 | if (phba->lpfc_injerr_lba != LPFC_INJERR_LBA_OFF) { |
| 1315 | blksize = lpfc_cmd_blksize(sc); |
| 1316 | numblks = (scsi_bufflen(sc) + blksize - 1) / blksize; |
| 1317 | |
| 1318 | /* Make sure we have the right LBA if one is specified */ |
| 1319 | if ((phba->lpfc_injerr_lba < lba) || |
| 1320 | (phba->lpfc_injerr_lba >= (lba + numblks))) |
| 1321 | return 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1322 | if (sgpe) { |
| 1323 | blockoff = phba->lpfc_injerr_lba - lba; |
| 1324 | numblks = sg_dma_len(sgpe) / |
| 1325 | sizeof(struct scsi_dif_tuple); |
| 1326 | if (numblks < blockoff) |
| 1327 | blockoff = numblks; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1328 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1329 | } |
| 1330 | |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1331 | /* Next check if we need to match the remote NPortID or WWPN */ |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 1332 | rdata = lpfc_rport_data_from_scsi_device(sc->device); |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1333 | if (rdata && rdata->pnode) { |
| 1334 | ndlp = rdata->pnode; |
| 1335 | |
| 1336 | /* Make sure we have the right NPortID if one is specified */ |
| 1337 | if (phba->lpfc_injerr_nportid && |
| 1338 | (phba->lpfc_injerr_nportid != ndlp->nlp_DID)) |
| 1339 | return 0; |
| 1340 | |
| 1341 | /* |
| 1342 | * Make sure we have the right WWPN if one is specified. |
| 1343 | * wwn[0] should be a non-zero NAA in a good WWPN. |
| 1344 | */ |
| 1345 | if (phba->lpfc_injerr_wwpn.u.wwn[0] && |
| 1346 | (memcmp(&ndlp->nlp_portname, &phba->lpfc_injerr_wwpn, |
| 1347 | sizeof(struct lpfc_name)) != 0)) |
| 1348 | return 0; |
| 1349 | } |
| 1350 | |
| 1351 | /* Setup a ptr to the protection data if the SCSI host provides it */ |
| 1352 | if (sgpe) { |
| 1353 | src = (struct scsi_dif_tuple *)sg_virt(sgpe); |
| 1354 | src += blockoff; |
| 1355 | lpfc_cmd = (struct lpfc_scsi_buf *)sc->host_scribble; |
| 1356 | } |
| 1357 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1358 | /* Should we change the Reference Tag */ |
| 1359 | if (reftag) { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1360 | if (phba->lpfc_injerr_wref_cnt) { |
| 1361 | switch (op) { |
| 1362 | case SCSI_PROT_WRITE_PASS: |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1363 | if (src) { |
| 1364 | /* |
| 1365 | * For WRITE_PASS, force the error |
| 1366 | * to be sent on the wire. It should |
| 1367 | * be detected by the Target. |
| 1368 | * If blockoff != 0 error will be |
| 1369 | * inserted in middle of the IO. |
| 1370 | */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1371 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1372 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1373 | "9076 BLKGRD: Injecting reftag error: " |
| 1374 | "write lba x%lx + x%x oldrefTag x%x\n", |
| 1375 | (unsigned long)lba, blockoff, |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1376 | be32_to_cpu(src->ref_tag)); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1377 | |
| 1378 | /* |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1379 | * Save the old ref_tag so we can |
| 1380 | * restore it on completion. |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1381 | */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1382 | if (lpfc_cmd) { |
| 1383 | lpfc_cmd->prot_data_type = |
| 1384 | LPFC_INJERR_REFTAG; |
| 1385 | lpfc_cmd->prot_data_segment = |
| 1386 | src; |
| 1387 | lpfc_cmd->prot_data = |
| 1388 | src->ref_tag; |
| 1389 | } |
| 1390 | src->ref_tag = cpu_to_be32(0xDEADBEEF); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1391 | phba->lpfc_injerr_wref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1392 | if (phba->lpfc_injerr_wref_cnt == 0) { |
| 1393 | phba->lpfc_injerr_nportid = 0; |
| 1394 | phba->lpfc_injerr_lba = |
| 1395 | LPFC_INJERR_LBA_OFF; |
| 1396 | memset(&phba->lpfc_injerr_wwpn, |
| 1397 | 0, sizeof(struct lpfc_name)); |
| 1398 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1399 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
| 1400 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1401 | break; |
| 1402 | } |
| 1403 | /* Drop thru */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1404 | case SCSI_PROT_WRITE_INSERT: |
| 1405 | /* |
| 1406 | * For WRITE_INSERT, force the error |
| 1407 | * to be sent on the wire. It should be |
| 1408 | * detected by the Target. |
| 1409 | */ |
| 1410 | /* DEADBEEF will be the reftag on the wire */ |
| 1411 | *reftag = 0xDEADBEEF; |
| 1412 | phba->lpfc_injerr_wref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1413 | if (phba->lpfc_injerr_wref_cnt == 0) { |
| 1414 | phba->lpfc_injerr_nportid = 0; |
| 1415 | phba->lpfc_injerr_lba = |
| 1416 | LPFC_INJERR_LBA_OFF; |
| 1417 | memset(&phba->lpfc_injerr_wwpn, |
| 1418 | 0, sizeof(struct lpfc_name)); |
| 1419 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1420 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
| 1421 | |
| 1422 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1423 | "9078 BLKGRD: Injecting reftag error: " |
| 1424 | "write lba x%lx\n", (unsigned long)lba); |
| 1425 | break; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1426 | case SCSI_PROT_WRITE_STRIP: |
| 1427 | /* |
| 1428 | * For WRITE_STRIP and WRITE_PASS, |
| 1429 | * force the error on data |
| 1430 | * being copied from SLI-Host to SLI-Port. |
| 1431 | */ |
| 1432 | *reftag = 0xDEADBEEF; |
| 1433 | phba->lpfc_injerr_wref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1434 | if (phba->lpfc_injerr_wref_cnt == 0) { |
| 1435 | phba->lpfc_injerr_nportid = 0; |
| 1436 | phba->lpfc_injerr_lba = |
| 1437 | LPFC_INJERR_LBA_OFF; |
| 1438 | memset(&phba->lpfc_injerr_wwpn, |
| 1439 | 0, sizeof(struct lpfc_name)); |
| 1440 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1441 | rc = BG_ERR_INIT; |
| 1442 | |
| 1443 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1444 | "9077 BLKGRD: Injecting reftag error: " |
| 1445 | "write lba x%lx\n", (unsigned long)lba); |
| 1446 | break; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1447 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1448 | } |
| 1449 | if (phba->lpfc_injerr_rref_cnt) { |
| 1450 | switch (op) { |
| 1451 | case SCSI_PROT_READ_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1452 | case SCSI_PROT_READ_STRIP: |
| 1453 | case SCSI_PROT_READ_PASS: |
| 1454 | /* |
| 1455 | * For READ_STRIP and READ_PASS, force the |
| 1456 | * error on data being read off the wire. It |
| 1457 | * should force an IO error to the driver. |
| 1458 | */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1459 | *reftag = 0xDEADBEEF; |
| 1460 | phba->lpfc_injerr_rref_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1461 | if (phba->lpfc_injerr_rref_cnt == 0) { |
| 1462 | phba->lpfc_injerr_nportid = 0; |
| 1463 | phba->lpfc_injerr_lba = |
| 1464 | LPFC_INJERR_LBA_OFF; |
| 1465 | memset(&phba->lpfc_injerr_wwpn, |
| 1466 | 0, sizeof(struct lpfc_name)); |
| 1467 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1468 | rc = BG_ERR_INIT; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1469 | |
| 1470 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1471 | "9079 BLKGRD: Injecting reftag error: " |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1472 | "read lba x%lx\n", (unsigned long)lba); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1473 | break; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1474 | } |
| 1475 | } |
| 1476 | } |
| 1477 | |
| 1478 | /* Should we change the Application Tag */ |
| 1479 | if (apptag) { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1480 | if (phba->lpfc_injerr_wapp_cnt) { |
| 1481 | switch (op) { |
| 1482 | case SCSI_PROT_WRITE_PASS: |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1483 | if (src) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1484 | /* |
| 1485 | * For WRITE_PASS, force the error |
| 1486 | * to be sent on the wire. It should |
| 1487 | * be detected by the Target. |
| 1488 | * If blockoff != 0 error will be |
| 1489 | * inserted in middle of the IO. |
| 1490 | */ |
| 1491 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1492 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1493 | "9080 BLKGRD: Injecting apptag error: " |
| 1494 | "write lba x%lx + x%x oldappTag x%x\n", |
| 1495 | (unsigned long)lba, blockoff, |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1496 | be16_to_cpu(src->app_tag)); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1497 | |
| 1498 | /* |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1499 | * Save the old app_tag so we can |
| 1500 | * restore it on completion. |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1501 | */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1502 | if (lpfc_cmd) { |
| 1503 | lpfc_cmd->prot_data_type = |
| 1504 | LPFC_INJERR_APPTAG; |
| 1505 | lpfc_cmd->prot_data_segment = |
| 1506 | src; |
| 1507 | lpfc_cmd->prot_data = |
| 1508 | src->app_tag; |
| 1509 | } |
| 1510 | src->app_tag = cpu_to_be16(0xDEAD); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1511 | phba->lpfc_injerr_wapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1512 | if (phba->lpfc_injerr_wapp_cnt == 0) { |
| 1513 | phba->lpfc_injerr_nportid = 0; |
| 1514 | phba->lpfc_injerr_lba = |
| 1515 | LPFC_INJERR_LBA_OFF; |
| 1516 | memset(&phba->lpfc_injerr_wwpn, |
| 1517 | 0, sizeof(struct lpfc_name)); |
| 1518 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1519 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1520 | break; |
| 1521 | } |
| 1522 | /* Drop thru */ |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1523 | case SCSI_PROT_WRITE_INSERT: |
| 1524 | /* |
| 1525 | * For WRITE_INSERT, force the |
| 1526 | * error to be sent on the wire. It should be |
| 1527 | * detected by the Target. |
| 1528 | */ |
| 1529 | /* DEAD will be the apptag on the wire */ |
| 1530 | *apptag = 0xDEAD; |
| 1531 | phba->lpfc_injerr_wapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1532 | if (phba->lpfc_injerr_wapp_cnt == 0) { |
| 1533 | phba->lpfc_injerr_nportid = 0; |
| 1534 | phba->lpfc_injerr_lba = |
| 1535 | LPFC_INJERR_LBA_OFF; |
| 1536 | memset(&phba->lpfc_injerr_wwpn, |
| 1537 | 0, sizeof(struct lpfc_name)); |
| 1538 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1539 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
| 1540 | |
| 1541 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1542 | "0813 BLKGRD: Injecting apptag error: " |
| 1543 | "write lba x%lx\n", (unsigned long)lba); |
| 1544 | break; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1545 | case SCSI_PROT_WRITE_STRIP: |
| 1546 | /* |
| 1547 | * For WRITE_STRIP and WRITE_PASS, |
| 1548 | * force the error on data |
| 1549 | * being copied from SLI-Host to SLI-Port. |
| 1550 | */ |
| 1551 | *apptag = 0xDEAD; |
| 1552 | phba->lpfc_injerr_wapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1553 | if (phba->lpfc_injerr_wapp_cnt == 0) { |
| 1554 | phba->lpfc_injerr_nportid = 0; |
| 1555 | phba->lpfc_injerr_lba = |
| 1556 | LPFC_INJERR_LBA_OFF; |
| 1557 | memset(&phba->lpfc_injerr_wwpn, |
| 1558 | 0, sizeof(struct lpfc_name)); |
| 1559 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1560 | rc = BG_ERR_INIT; |
| 1561 | |
| 1562 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1563 | "0812 BLKGRD: Injecting apptag error: " |
| 1564 | "write lba x%lx\n", (unsigned long)lba); |
| 1565 | break; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1566 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1567 | } |
| 1568 | if (phba->lpfc_injerr_rapp_cnt) { |
| 1569 | switch (op) { |
| 1570 | case SCSI_PROT_READ_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1571 | case SCSI_PROT_READ_STRIP: |
| 1572 | case SCSI_PROT_READ_PASS: |
| 1573 | /* |
| 1574 | * For READ_STRIP and READ_PASS, force the |
| 1575 | * error on data being read off the wire. It |
| 1576 | * should force an IO error to the driver. |
| 1577 | */ |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1578 | *apptag = 0xDEAD; |
| 1579 | phba->lpfc_injerr_rapp_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1580 | if (phba->lpfc_injerr_rapp_cnt == 0) { |
| 1581 | phba->lpfc_injerr_nportid = 0; |
| 1582 | phba->lpfc_injerr_lba = |
| 1583 | LPFC_INJERR_LBA_OFF; |
| 1584 | memset(&phba->lpfc_injerr_wwpn, |
| 1585 | 0, sizeof(struct lpfc_name)); |
| 1586 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1587 | rc = BG_ERR_INIT; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1588 | |
| 1589 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1590 | "0814 BLKGRD: Injecting apptag error: " |
| 1591 | "read lba x%lx\n", (unsigned long)lba); |
| 1592 | break; |
| 1593 | } |
| 1594 | } |
| 1595 | } |
| 1596 | |
| 1597 | |
| 1598 | /* Should we change the Guard Tag */ |
| 1599 | if (new_guard) { |
| 1600 | if (phba->lpfc_injerr_wgrd_cnt) { |
| 1601 | switch (op) { |
| 1602 | case SCSI_PROT_WRITE_PASS: |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1603 | rc = BG_ERR_CHECK; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1604 | /* Drop thru */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1605 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1606 | case SCSI_PROT_WRITE_INSERT: |
| 1607 | /* |
| 1608 | * For WRITE_INSERT, force the |
| 1609 | * error to be sent on the wire. It should be |
| 1610 | * detected by the Target. |
| 1611 | */ |
| 1612 | phba->lpfc_injerr_wgrd_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1613 | if (phba->lpfc_injerr_wgrd_cnt == 0) { |
| 1614 | phba->lpfc_injerr_nportid = 0; |
| 1615 | phba->lpfc_injerr_lba = |
| 1616 | LPFC_INJERR_LBA_OFF; |
| 1617 | memset(&phba->lpfc_injerr_wwpn, |
| 1618 | 0, sizeof(struct lpfc_name)); |
| 1619 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1620 | |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1621 | rc |= BG_ERR_TGT | BG_ERR_SWAP; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1622 | /* Signals the caller to swap CRC->CSUM */ |
| 1623 | |
| 1624 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1625 | "0817 BLKGRD: Injecting guard error: " |
| 1626 | "write lba x%lx\n", (unsigned long)lba); |
| 1627 | break; |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1628 | case SCSI_PROT_WRITE_STRIP: |
| 1629 | /* |
| 1630 | * For WRITE_STRIP and WRITE_PASS, |
| 1631 | * force the error on data |
| 1632 | * being copied from SLI-Host to SLI-Port. |
| 1633 | */ |
| 1634 | phba->lpfc_injerr_wgrd_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1635 | if (phba->lpfc_injerr_wgrd_cnt == 0) { |
| 1636 | phba->lpfc_injerr_nportid = 0; |
| 1637 | phba->lpfc_injerr_lba = |
| 1638 | LPFC_INJERR_LBA_OFF; |
| 1639 | memset(&phba->lpfc_injerr_wwpn, |
| 1640 | 0, sizeof(struct lpfc_name)); |
| 1641 | } |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1642 | |
| 1643 | rc = BG_ERR_INIT | BG_ERR_SWAP; |
| 1644 | /* Signals the caller to swap CRC->CSUM */ |
| 1645 | |
| 1646 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1647 | "0816 BLKGRD: Injecting guard error: " |
| 1648 | "write lba x%lx\n", (unsigned long)lba); |
| 1649 | break; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1650 | } |
| 1651 | } |
| 1652 | if (phba->lpfc_injerr_rgrd_cnt) { |
| 1653 | switch (op) { |
| 1654 | case SCSI_PROT_READ_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1655 | case SCSI_PROT_READ_STRIP: |
| 1656 | case SCSI_PROT_READ_PASS: |
| 1657 | /* |
| 1658 | * For READ_STRIP and READ_PASS, force the |
| 1659 | * error on data being read off the wire. It |
| 1660 | * should force an IO error to the driver. |
| 1661 | */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1662 | phba->lpfc_injerr_rgrd_cnt--; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1663 | if (phba->lpfc_injerr_rgrd_cnt == 0) { |
| 1664 | phba->lpfc_injerr_nportid = 0; |
| 1665 | phba->lpfc_injerr_lba = |
| 1666 | LPFC_INJERR_LBA_OFF; |
| 1667 | memset(&phba->lpfc_injerr_wwpn, |
| 1668 | 0, sizeof(struct lpfc_name)); |
| 1669 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1670 | |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1671 | rc = BG_ERR_INIT | BG_ERR_SWAP; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1672 | /* Signals the caller to swap CRC->CSUM */ |
| 1673 | |
| 1674 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 1675 | "0818 BLKGRD: Injecting guard error: " |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1676 | "read lba x%lx\n", (unsigned long)lba); |
| 1677 | } |
| 1678 | } |
| 1679 | } |
| 1680 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1681 | return rc; |
| 1682 | } |
| 1683 | #endif |
| 1684 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1685 | /** |
| 1686 | * lpfc_sc_to_bg_opcodes - Determine the BlockGuard opcodes to be used with |
| 1687 | * the specified SCSI command. |
| 1688 | * @phba: The Hba for which this call is being executed. |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1689 | * @sc: The SCSI command to examine |
| 1690 | * @txopt: (out) BlockGuard operation for transmitted data |
| 1691 | * @rxopt: (out) BlockGuard operation for received data |
| 1692 | * |
| 1693 | * Returns: zero on success; non-zero if tx and/or rx op cannot be determined |
| 1694 | * |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1695 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1696 | static int |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1697 | lpfc_sc_to_bg_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1698 | uint8_t *txop, uint8_t *rxop) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1699 | { |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1700 | uint8_t ret = 0; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1701 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1702 | if (lpfc_cmd_guard_csum(sc)) { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1703 | switch (scsi_get_prot_op(sc)) { |
| 1704 | case SCSI_PROT_READ_INSERT: |
| 1705 | case SCSI_PROT_WRITE_STRIP: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1706 | *rxop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1707 | *txop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1708 | break; |
| 1709 | |
| 1710 | case SCSI_PROT_READ_STRIP: |
| 1711 | case SCSI_PROT_WRITE_INSERT: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1712 | *rxop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1713 | *txop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1714 | break; |
| 1715 | |
Martin K. Petersen | c6af404 | 2009-09-18 17:32:59 -0400 | [diff] [blame] | 1716 | case SCSI_PROT_READ_PASS: |
| 1717 | case SCSI_PROT_WRITE_PASS: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1718 | *rxop = BG_OP_IN_CRC_OUT_CSUM; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1719 | *txop = BG_OP_IN_CSUM_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1720 | break; |
| 1721 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1722 | case SCSI_PROT_NORMAL: |
| 1723 | default: |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1724 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1725 | "9063 BLKGRD: Bad op/guard:%d/IP combination\n", |
| 1726 | scsi_get_prot_op(sc)); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1727 | ret = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1728 | break; |
| 1729 | |
| 1730 | } |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1731 | } else { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1732 | switch (scsi_get_prot_op(sc)) { |
| 1733 | case SCSI_PROT_READ_STRIP: |
| 1734 | case SCSI_PROT_WRITE_INSERT: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1735 | *rxop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1736 | *txop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1737 | break; |
| 1738 | |
| 1739 | case SCSI_PROT_READ_PASS: |
| 1740 | case SCSI_PROT_WRITE_PASS: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1741 | *rxop = BG_OP_IN_CRC_OUT_CRC; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1742 | *txop = BG_OP_IN_CRC_OUT_CRC; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1743 | break; |
| 1744 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1745 | case SCSI_PROT_READ_INSERT: |
| 1746 | case SCSI_PROT_WRITE_STRIP: |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1747 | *rxop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1748 | *txop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1749 | break; |
| 1750 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1751 | case SCSI_PROT_NORMAL: |
| 1752 | default: |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1753 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1754 | "9075 BLKGRD: Bad op/guard:%d/CRC combination\n", |
| 1755 | scsi_get_prot_op(sc)); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1756 | ret = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1757 | break; |
| 1758 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1759 | } |
| 1760 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1761 | return ret; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1762 | } |
| 1763 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1764 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 1765 | /** |
| 1766 | * lpfc_bg_err_opcodes - reDetermine the BlockGuard opcodes to be used with |
| 1767 | * the specified SCSI command in order to force a guard tag error. |
| 1768 | * @phba: The Hba for which this call is being executed. |
| 1769 | * @sc: The SCSI command to examine |
| 1770 | * @txopt: (out) BlockGuard operation for transmitted data |
| 1771 | * @rxopt: (out) BlockGuard operation for received data |
| 1772 | * |
| 1773 | * Returns: zero on success; non-zero if tx and/or rx op cannot be determined |
| 1774 | * |
| 1775 | **/ |
| 1776 | static int |
| 1777 | lpfc_bg_err_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1778 | uint8_t *txop, uint8_t *rxop) |
| 1779 | { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1780 | uint8_t ret = 0; |
| 1781 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1782 | if (lpfc_cmd_guard_csum(sc)) { |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1783 | switch (scsi_get_prot_op(sc)) { |
| 1784 | case SCSI_PROT_READ_INSERT: |
| 1785 | case SCSI_PROT_WRITE_STRIP: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1786 | *rxop = BG_OP_IN_NODIF_OUT_CRC; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1787 | *txop = BG_OP_IN_CRC_OUT_NODIF; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1788 | break; |
| 1789 | |
| 1790 | case SCSI_PROT_READ_STRIP: |
| 1791 | case SCSI_PROT_WRITE_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1792 | *rxop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1793 | *txop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1794 | break; |
| 1795 | |
| 1796 | case SCSI_PROT_READ_PASS: |
| 1797 | case SCSI_PROT_WRITE_PASS: |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1798 | *rxop = BG_OP_IN_CSUM_OUT_CRC; |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1799 | *txop = BG_OP_IN_CRC_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1800 | break; |
| 1801 | |
| 1802 | case SCSI_PROT_NORMAL: |
| 1803 | default: |
| 1804 | break; |
| 1805 | |
| 1806 | } |
| 1807 | } else { |
| 1808 | switch (scsi_get_prot_op(sc)) { |
| 1809 | case SCSI_PROT_READ_STRIP: |
| 1810 | case SCSI_PROT_WRITE_INSERT: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1811 | *rxop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1812 | *txop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1813 | break; |
| 1814 | |
| 1815 | case SCSI_PROT_READ_PASS: |
| 1816 | case SCSI_PROT_WRITE_PASS: |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1817 | *rxop = BG_OP_IN_CSUM_OUT_CSUM; |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1818 | *txop = BG_OP_IN_CSUM_OUT_CSUM; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1819 | break; |
| 1820 | |
| 1821 | case SCSI_PROT_READ_INSERT: |
| 1822 | case SCSI_PROT_WRITE_STRIP: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1823 | *rxop = BG_OP_IN_NODIF_OUT_CSUM; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1824 | *txop = BG_OP_IN_CSUM_OUT_NODIF; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1825 | break; |
| 1826 | |
| 1827 | case SCSI_PROT_NORMAL: |
| 1828 | default: |
| 1829 | break; |
| 1830 | } |
| 1831 | } |
| 1832 | |
| 1833 | return ret; |
| 1834 | } |
| 1835 | #endif |
| 1836 | |
| 1837 | /** |
| 1838 | * lpfc_bg_setup_bpl - Setup BlockGuard BPL with no protection data |
| 1839 | * @phba: The Hba for which this call is being executed. |
| 1840 | * @sc: pointer to scsi command we're working on |
| 1841 | * @bpl: pointer to buffer list for protection groups |
| 1842 | * @datacnt: number of segments of data that have been dma mapped |
| 1843 | * |
| 1844 | * This function sets up BPL buffer list for protection groups of |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1845 | * type LPFC_PG_TYPE_NO_DIF |
| 1846 | * |
| 1847 | * This is usually used when the HBA is instructed to generate |
| 1848 | * DIFs and insert them into data stream (or strip DIF from |
| 1849 | * incoming data stream) |
| 1850 | * |
| 1851 | * The buffer list consists of just one protection group described |
| 1852 | * below: |
| 1853 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1854 | * start of prot group --> | PDE_5 | |
| 1855 | * +-------------------------+ |
| 1856 | * | PDE_6 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1857 | * +-------------------------+ |
| 1858 | * | Data BDE | |
| 1859 | * +-------------------------+ |
| 1860 | * |more Data BDE's ... (opt)| |
| 1861 | * +-------------------------+ |
| 1862 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1863 | * |
| 1864 | * Note: Data s/g buffers have been dma mapped |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1865 | * |
| 1866 | * Returns the number of BDEs added to the BPL. |
| 1867 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1868 | static int |
| 1869 | lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 1870 | struct ulp_bde64 *bpl, int datasegcnt) |
| 1871 | { |
| 1872 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1873 | struct lpfc_pde5 *pde5 = NULL; |
| 1874 | struct lpfc_pde6 *pde6 = NULL; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1875 | dma_addr_t physaddr; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1876 | int i = 0, num_bde = 0, status; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1877 | int datadir = sc->sc_data_direction; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 1878 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1879 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 1880 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1881 | uint32_t checking = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1882 | uint32_t reftag; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1883 | uint8_t txop, rxop; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1884 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1885 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 1886 | if (status) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1887 | goto out; |
| 1888 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1889 | /* extract some info from the scsi command for pde*/ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1890 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1891 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1892 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1893 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1894 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1895 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1896 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1897 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1898 | checking = 0; |
| 1899 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1900 | #endif |
| 1901 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1902 | /* setup PDE5 with what we have */ |
| 1903 | pde5 = (struct lpfc_pde5 *) bpl; |
| 1904 | memset(pde5, 0, sizeof(struct lpfc_pde5)); |
| 1905 | bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1906 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1907 | /* Endianness conversion if necessary for PDE5 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1908 | pde5->word0 = cpu_to_le32(pde5->word0); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1909 | pde5->reftag = cpu_to_le32(reftag); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1910 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1911 | /* advance bpl and increment bde count */ |
| 1912 | num_bde++; |
| 1913 | bpl++; |
| 1914 | pde6 = (struct lpfc_pde6 *) bpl; |
| 1915 | |
| 1916 | /* setup PDE6 with the rest of the info */ |
| 1917 | memset(pde6, 0, sizeof(struct lpfc_pde6)); |
| 1918 | bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR); |
| 1919 | bf_set(pde6_optx, pde6, txop); |
| 1920 | bf_set(pde6_oprx, pde6, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1921 | |
| 1922 | /* |
| 1923 | * We only need to check the data on READs, for WRITEs |
| 1924 | * protection data is automatically generated, not checked. |
| 1925 | */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1926 | if (datadir == DMA_FROM_DEVICE) { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1927 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1928 | bf_set(pde6_ce, pde6, checking); |
| 1929 | else |
| 1930 | bf_set(pde6_ce, pde6, 0); |
| 1931 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 1932 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 1933 | bf_set(pde6_re, pde6, checking); |
| 1934 | else |
| 1935 | bf_set(pde6_re, pde6, 0); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1936 | } |
| 1937 | bf_set(pde6_ai, pde6, 1); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 1938 | bf_set(pde6_ae, pde6, 0); |
| 1939 | bf_set(pde6_apptagval, pde6, 0); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1940 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1941 | /* Endianness conversion if necessary for PDE6 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1942 | pde6->word0 = cpu_to_le32(pde6->word0); |
| 1943 | pde6->word1 = cpu_to_le32(pde6->word1); |
| 1944 | pde6->word2 = cpu_to_le32(pde6->word2); |
| 1945 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1946 | /* advance bpl and increment bde count */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1947 | num_bde++; |
| 1948 | bpl++; |
| 1949 | |
| 1950 | /* assumption: caller has already run dma_map_sg on command data */ |
| 1951 | scsi_for_each_sg(sc, sgde, datasegcnt, i) { |
| 1952 | physaddr = sg_dma_address(sgde); |
| 1953 | bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
| 1954 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 1955 | bpl->tus.f.bdeSize = sg_dma_len(sgde); |
| 1956 | if (datadir == DMA_TO_DEVICE) |
| 1957 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1958 | else |
| 1959 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
| 1960 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 1961 | bpl++; |
| 1962 | num_bde++; |
| 1963 | } |
| 1964 | |
| 1965 | out: |
| 1966 | return num_bde; |
| 1967 | } |
| 1968 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1969 | /** |
| 1970 | * lpfc_bg_setup_bpl_prot - Setup BlockGuard BPL with protection data |
| 1971 | * @phba: The Hba for which this call is being executed. |
| 1972 | * @sc: pointer to scsi command we're working on |
| 1973 | * @bpl: pointer to buffer list for protection groups |
| 1974 | * @datacnt: number of segments of data that have been dma mapped |
| 1975 | * @protcnt: number of segment of protection data that have been dma mapped |
| 1976 | * |
| 1977 | * This function sets up BPL buffer list for protection groups of |
| 1978 | * type LPFC_PG_TYPE_DIF |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1979 | * |
| 1980 | * This is usually used when DIFs are in their own buffers, |
| 1981 | * separate from the data. The HBA can then by instructed |
| 1982 | * to place the DIFs in the outgoing stream. For read operations, |
| 1983 | * The HBA could extract the DIFs and place it in DIF buffers. |
| 1984 | * |
| 1985 | * The buffer list for this type consists of one or more of the |
| 1986 | * protection groups described below: |
| 1987 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1988 | * start of first prot group --> | PDE_5 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1989 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1990 | * | PDE_6 | |
| 1991 | * +-------------------------+ |
| 1992 | * | PDE_7 (Prot BDE) | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1993 | * +-------------------------+ |
| 1994 | * | Data BDE | |
| 1995 | * +-------------------------+ |
| 1996 | * |more Data BDE's ... (opt)| |
| 1997 | * +-------------------------+ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 1998 | * start of new prot group --> | PDE_5 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1999 | * +-------------------------+ |
| 2000 | * | ... | |
| 2001 | * +-------------------------+ |
| 2002 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2003 | * Note: It is assumed that both data and protection s/g buffers have been |
| 2004 | * mapped for DMA |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2005 | * |
| 2006 | * Returns the number of BDEs added to the BPL. |
| 2007 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2008 | static int |
| 2009 | lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 2010 | struct ulp_bde64 *bpl, int datacnt, int protcnt) |
| 2011 | { |
| 2012 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 2013 | struct scatterlist *sgpe = NULL; /* s/g prot entry */ |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2014 | struct lpfc_pde5 *pde5 = NULL; |
| 2015 | struct lpfc_pde6 *pde6 = NULL; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2016 | struct lpfc_pde7 *pde7 = NULL; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2017 | dma_addr_t dataphysaddr, protphysaddr; |
| 2018 | unsigned short curr_data = 0, curr_prot = 0; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2019 | unsigned int split_offset; |
| 2020 | unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2021 | unsigned int protgrp_blks, protgrp_bytes; |
| 2022 | unsigned int remainder, subtotal; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2023 | int status; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2024 | int datadir = sc->sc_data_direction; |
| 2025 | unsigned char pgdone = 0, alldone = 0; |
| 2026 | unsigned blksize; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2027 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2028 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2029 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2030 | uint32_t checking = 1; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2031 | uint32_t reftag; |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2032 | uint8_t txop, rxop; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2033 | int num_bde = 0; |
| 2034 | |
| 2035 | sgpe = scsi_prot_sglist(sc); |
| 2036 | sgde = scsi_sglist(sc); |
| 2037 | |
| 2038 | if (!sgpe || !sgde) { |
| 2039 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2040 | "9020 Invalid s/g entry: data=0x%p prot=0x%p\n", |
| 2041 | sgpe, sgde); |
| 2042 | return 0; |
| 2043 | } |
| 2044 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2045 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 2046 | if (status) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2047 | goto out; |
| 2048 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2049 | /* extract some info from the scsi command */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2050 | blksize = lpfc_cmd_blksize(sc); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2051 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2052 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 2053 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 2054 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2055 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2056 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2057 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2058 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2059 | checking = 0; |
| 2060 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 2061 | #endif |
| 2062 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2063 | split_offset = 0; |
| 2064 | do { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2065 | /* Check to see if we ran out of space */ |
| 2066 | if (num_bde >= (phba->cfg_total_seg_cnt - 2)) |
| 2067 | return num_bde + 3; |
| 2068 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2069 | /* setup PDE5 with what we have */ |
| 2070 | pde5 = (struct lpfc_pde5 *) bpl; |
| 2071 | memset(pde5, 0, sizeof(struct lpfc_pde5)); |
| 2072 | bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2073 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 2074 | /* Endianness conversion if necessary for PDE5 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 2075 | pde5->word0 = cpu_to_le32(pde5->word0); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2076 | pde5->reftag = cpu_to_le32(reftag); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 2077 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2078 | /* advance bpl and increment bde count */ |
| 2079 | num_bde++; |
| 2080 | bpl++; |
| 2081 | pde6 = (struct lpfc_pde6 *) bpl; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2082 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2083 | /* setup PDE6 with the rest of the info */ |
| 2084 | memset(pde6, 0, sizeof(struct lpfc_pde6)); |
| 2085 | bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR); |
| 2086 | bf_set(pde6_optx, pde6, txop); |
| 2087 | bf_set(pde6_oprx, pde6, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2088 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2089 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2090 | bf_set(pde6_ce, pde6, checking); |
| 2091 | else |
| 2092 | bf_set(pde6_ce, pde6, 0); |
| 2093 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2094 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2095 | bf_set(pde6_re, pde6, checking); |
| 2096 | else |
| 2097 | bf_set(pde6_re, pde6, 0); |
| 2098 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2099 | bf_set(pde6_ai, pde6, 1); |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2100 | bf_set(pde6_ae, pde6, 0); |
| 2101 | bf_set(pde6_apptagval, pde6, 0); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2102 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 2103 | /* Endianness conversion if necessary for PDE6 */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 2104 | pde6->word0 = cpu_to_le32(pde6->word0); |
| 2105 | pde6->word1 = cpu_to_le32(pde6->word1); |
| 2106 | pde6->word2 = cpu_to_le32(pde6->word2); |
| 2107 | |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2108 | /* advance bpl and increment bde count */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2109 | num_bde++; |
| 2110 | bpl++; |
| 2111 | |
| 2112 | /* setup the first BDE that points to protection buffer */ |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2113 | protphysaddr = sg_dma_address(sgpe) + protgroup_offset; |
| 2114 | protgroup_len = sg_dma_len(sgpe) - protgroup_offset; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2115 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2116 | /* must be integer multiple of the DIF block length */ |
| 2117 | BUG_ON(protgroup_len % 8); |
| 2118 | |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2119 | pde7 = (struct lpfc_pde7 *) bpl; |
| 2120 | memset(pde7, 0, sizeof(struct lpfc_pde7)); |
| 2121 | bf_set(pde7_type, pde7, LPFC_PDE7_DESCRIPTOR); |
| 2122 | |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2123 | pde7->addrHigh = le32_to_cpu(putPaddrHigh(protphysaddr)); |
| 2124 | pde7->addrLow = le32_to_cpu(putPaddrLow(protphysaddr)); |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2125 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2126 | protgrp_blks = protgroup_len / 8; |
| 2127 | protgrp_bytes = protgrp_blks * blksize; |
| 2128 | |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2129 | /* check if this pde is crossing the 4K boundary; if so split */ |
| 2130 | if ((pde7->addrLow & 0xfff) + protgroup_len > 0x1000) { |
| 2131 | protgroup_remainder = 0x1000 - (pde7->addrLow & 0xfff); |
| 2132 | protgroup_offset += protgroup_remainder; |
| 2133 | protgrp_blks = protgroup_remainder / 8; |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 2134 | protgrp_bytes = protgrp_blks * blksize; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2135 | } else { |
| 2136 | protgroup_offset = 0; |
| 2137 | curr_prot++; |
| 2138 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2139 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2140 | num_bde++; |
| 2141 | |
| 2142 | /* setup BDE's for data blocks associated with DIF data */ |
| 2143 | pgdone = 0; |
| 2144 | subtotal = 0; /* total bytes processed for current prot grp */ |
| 2145 | while (!pgdone) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2146 | /* Check to see if we ran out of space */ |
| 2147 | if (num_bde >= phba->cfg_total_seg_cnt) |
| 2148 | return num_bde + 1; |
| 2149 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2150 | if (!sgde) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2151 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2152 | "9065 BLKGRD:%s Invalid data segment\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2153 | __func__); |
| 2154 | return 0; |
| 2155 | } |
| 2156 | bpl++; |
| 2157 | dataphysaddr = sg_dma_address(sgde) + split_offset; |
| 2158 | bpl->addrLow = le32_to_cpu(putPaddrLow(dataphysaddr)); |
| 2159 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(dataphysaddr)); |
| 2160 | |
| 2161 | remainder = sg_dma_len(sgde) - split_offset; |
| 2162 | |
| 2163 | if ((subtotal + remainder) <= protgrp_bytes) { |
| 2164 | /* we can use this whole buffer */ |
| 2165 | bpl->tus.f.bdeSize = remainder; |
| 2166 | split_offset = 0; |
| 2167 | |
| 2168 | if ((subtotal + remainder) == protgrp_bytes) |
| 2169 | pgdone = 1; |
| 2170 | } else { |
| 2171 | /* must split this buffer with next prot grp */ |
| 2172 | bpl->tus.f.bdeSize = protgrp_bytes - subtotal; |
| 2173 | split_offset += bpl->tus.f.bdeSize; |
| 2174 | } |
| 2175 | |
| 2176 | subtotal += bpl->tus.f.bdeSize; |
| 2177 | |
| 2178 | if (datadir == DMA_TO_DEVICE) |
| 2179 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 2180 | else |
| 2181 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
| 2182 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 2183 | |
| 2184 | num_bde++; |
| 2185 | curr_data++; |
| 2186 | |
| 2187 | if (split_offset) |
| 2188 | break; |
| 2189 | |
| 2190 | /* Move to the next s/g segment if possible */ |
| 2191 | sgde = sg_next(sgde); |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 2192 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2193 | } |
| 2194 | |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2195 | if (protgroup_offset) { |
| 2196 | /* update the reference tag */ |
| 2197 | reftag += protgrp_blks; |
| 2198 | bpl++; |
| 2199 | continue; |
| 2200 | } |
| 2201 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2202 | /* are we done ? */ |
| 2203 | if (curr_prot == protcnt) { |
| 2204 | alldone = 1; |
| 2205 | } else if (curr_prot < protcnt) { |
| 2206 | /* advance to next prot buffer */ |
| 2207 | sgpe = sg_next(sgpe); |
| 2208 | bpl++; |
| 2209 | |
| 2210 | /* update the reference tag */ |
| 2211 | reftag += protgrp_blks; |
| 2212 | } else { |
| 2213 | /* if we're here, we have a bug */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2214 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2215 | "9054 BLKGRD: bug in %s\n", __func__); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2216 | } |
| 2217 | |
| 2218 | } while (!alldone); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2219 | out: |
| 2220 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2221 | return num_bde; |
| 2222 | } |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 2223 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2224 | /** |
| 2225 | * lpfc_bg_setup_sgl - Setup BlockGuard SGL with no protection data |
| 2226 | * @phba: The Hba for which this call is being executed. |
| 2227 | * @sc: pointer to scsi command we're working on |
| 2228 | * @sgl: pointer to buffer list for protection groups |
| 2229 | * @datacnt: number of segments of data that have been dma mapped |
| 2230 | * |
| 2231 | * This function sets up SGL buffer list for protection groups of |
| 2232 | * type LPFC_PG_TYPE_NO_DIF |
| 2233 | * |
| 2234 | * This is usually used when the HBA is instructed to generate |
| 2235 | * DIFs and insert them into data stream (or strip DIF from |
| 2236 | * incoming data stream) |
| 2237 | * |
| 2238 | * The buffer list consists of just one protection group described |
| 2239 | * below: |
| 2240 | * +-------------------------+ |
| 2241 | * start of prot group --> | DI_SEED | |
| 2242 | * +-------------------------+ |
| 2243 | * | Data SGE | |
| 2244 | * +-------------------------+ |
| 2245 | * |more Data SGE's ... (opt)| |
| 2246 | * +-------------------------+ |
| 2247 | * |
| 2248 | * |
| 2249 | * Note: Data s/g buffers have been dma mapped |
| 2250 | * |
| 2251 | * Returns the number of SGEs added to the SGL. |
| 2252 | **/ |
| 2253 | static int |
| 2254 | lpfc_bg_setup_sgl(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 2255 | struct sli4_sge *sgl, int datasegcnt) |
| 2256 | { |
| 2257 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 2258 | struct sli4_sge_diseed *diseed = NULL; |
| 2259 | dma_addr_t physaddr; |
| 2260 | int i = 0, num_sge = 0, status; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2261 | uint32_t reftag; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2262 | uint8_t txop, rxop; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2263 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2264 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2265 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2266 | uint32_t checking = 1; |
| 2267 | uint32_t dma_len; |
| 2268 | uint32_t dma_offset = 0; |
| 2269 | |
| 2270 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 2271 | if (status) |
| 2272 | goto out; |
| 2273 | |
| 2274 | /* extract some info from the scsi command for pde*/ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2275 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
| 2276 | |
| 2277 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 2278 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2279 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2280 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2281 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2282 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2283 | checking = 0; |
| 2284 | } |
| 2285 | #endif |
| 2286 | |
| 2287 | /* setup DISEED with what we have */ |
| 2288 | diseed = (struct sli4_sge_diseed *) sgl; |
| 2289 | memset(diseed, 0, sizeof(struct sli4_sge_diseed)); |
| 2290 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED); |
| 2291 | |
| 2292 | /* Endianness conversion if necessary */ |
| 2293 | diseed->ref_tag = cpu_to_le32(reftag); |
| 2294 | diseed->ref_tag_tran = diseed->ref_tag; |
| 2295 | |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2296 | /* |
| 2297 | * We only need to check the data on READs, for WRITEs |
| 2298 | * protection data is automatically generated, not checked. |
| 2299 | */ |
| 2300 | if (sc->sc_data_direction == DMA_FROM_DEVICE) { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2301 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2302 | bf_set(lpfc_sli4_sge_dif_ce, diseed, checking); |
| 2303 | else |
| 2304 | bf_set(lpfc_sli4_sge_dif_ce, diseed, 0); |
| 2305 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2306 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2307 | bf_set(lpfc_sli4_sge_dif_re, diseed, checking); |
| 2308 | else |
| 2309 | bf_set(lpfc_sli4_sge_dif_re, diseed, 0); |
| 2310 | } |
| 2311 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2312 | /* setup DISEED with the rest of the info */ |
| 2313 | bf_set(lpfc_sli4_sge_dif_optx, diseed, txop); |
| 2314 | bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2315 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2316 | bf_set(lpfc_sli4_sge_dif_ai, diseed, 1); |
| 2317 | bf_set(lpfc_sli4_sge_dif_me, diseed, 0); |
| 2318 | |
| 2319 | /* Endianness conversion if necessary for DISEED */ |
| 2320 | diseed->word2 = cpu_to_le32(diseed->word2); |
| 2321 | diseed->word3 = cpu_to_le32(diseed->word3); |
| 2322 | |
| 2323 | /* advance bpl and increment sge count */ |
| 2324 | num_sge++; |
| 2325 | sgl++; |
| 2326 | |
| 2327 | /* assumption: caller has already run dma_map_sg on command data */ |
| 2328 | scsi_for_each_sg(sc, sgde, datasegcnt, i) { |
| 2329 | physaddr = sg_dma_address(sgde); |
| 2330 | dma_len = sg_dma_len(sgde); |
| 2331 | sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr)); |
| 2332 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr)); |
| 2333 | if ((i + 1) == datasegcnt) |
| 2334 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 2335 | else |
| 2336 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 2337 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
| 2338 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); |
| 2339 | |
| 2340 | sgl->sge_len = cpu_to_le32(dma_len); |
| 2341 | dma_offset += dma_len; |
| 2342 | |
| 2343 | sgl++; |
| 2344 | num_sge++; |
| 2345 | } |
| 2346 | |
| 2347 | out: |
| 2348 | return num_sge; |
| 2349 | } |
| 2350 | |
| 2351 | /** |
| 2352 | * lpfc_bg_setup_sgl_prot - Setup BlockGuard SGL with protection data |
| 2353 | * @phba: The Hba for which this call is being executed. |
| 2354 | * @sc: pointer to scsi command we're working on |
| 2355 | * @sgl: pointer to buffer list for protection groups |
| 2356 | * @datacnt: number of segments of data that have been dma mapped |
| 2357 | * @protcnt: number of segment of protection data that have been dma mapped |
| 2358 | * |
| 2359 | * This function sets up SGL buffer list for protection groups of |
| 2360 | * type LPFC_PG_TYPE_DIF |
| 2361 | * |
| 2362 | * This is usually used when DIFs are in their own buffers, |
| 2363 | * separate from the data. The HBA can then by instructed |
| 2364 | * to place the DIFs in the outgoing stream. For read operations, |
| 2365 | * The HBA could extract the DIFs and place it in DIF buffers. |
| 2366 | * |
| 2367 | * The buffer list for this type consists of one or more of the |
| 2368 | * protection groups described below: |
| 2369 | * +-------------------------+ |
| 2370 | * start of first prot group --> | DISEED | |
| 2371 | * +-------------------------+ |
| 2372 | * | DIF (Prot SGE) | |
| 2373 | * +-------------------------+ |
| 2374 | * | Data SGE | |
| 2375 | * +-------------------------+ |
| 2376 | * |more Data SGE's ... (opt)| |
| 2377 | * +-------------------------+ |
| 2378 | * start of new prot group --> | DISEED | |
| 2379 | * +-------------------------+ |
| 2380 | * | ... | |
| 2381 | * +-------------------------+ |
| 2382 | * |
| 2383 | * Note: It is assumed that both data and protection s/g buffers have been |
| 2384 | * mapped for DMA |
| 2385 | * |
| 2386 | * Returns the number of SGEs added to the SGL. |
| 2387 | **/ |
| 2388 | static int |
| 2389 | lpfc_bg_setup_sgl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
| 2390 | struct sli4_sge *sgl, int datacnt, int protcnt) |
| 2391 | { |
| 2392 | struct scatterlist *sgde = NULL; /* s/g data entry */ |
| 2393 | struct scatterlist *sgpe = NULL; /* s/g prot entry */ |
| 2394 | struct sli4_sge_diseed *diseed = NULL; |
| 2395 | dma_addr_t dataphysaddr, protphysaddr; |
| 2396 | unsigned short curr_data = 0, curr_prot = 0; |
| 2397 | unsigned int split_offset; |
| 2398 | unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder; |
| 2399 | unsigned int protgrp_blks, protgrp_bytes; |
| 2400 | unsigned int remainder, subtotal; |
| 2401 | int status; |
| 2402 | unsigned char pgdone = 0, alldone = 0; |
| 2403 | unsigned blksize; |
| 2404 | uint32_t reftag; |
| 2405 | uint8_t txop, rxop; |
| 2406 | uint32_t dma_len; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2407 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2408 | uint32_t rc; |
James Smart | 0829a19 | 2012-05-09 21:18:12 -0400 | [diff] [blame] | 2409 | #endif |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2410 | uint32_t checking = 1; |
| 2411 | uint32_t dma_offset = 0; |
| 2412 | int num_sge = 0; |
| 2413 | |
| 2414 | sgpe = scsi_prot_sglist(sc); |
| 2415 | sgde = scsi_sglist(sc); |
| 2416 | |
| 2417 | if (!sgpe || !sgde) { |
| 2418 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2419 | "9082 Invalid s/g entry: data=0x%p prot=0x%p\n", |
| 2420 | sgpe, sgde); |
| 2421 | return 0; |
| 2422 | } |
| 2423 | |
| 2424 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
| 2425 | if (status) |
| 2426 | goto out; |
| 2427 | |
| 2428 | /* extract some info from the scsi command */ |
| 2429 | blksize = lpfc_cmd_blksize(sc); |
| 2430 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
| 2431 | |
| 2432 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 2433 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2434 | if (rc) { |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2435 | if (rc & BG_ERR_SWAP) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2436 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 2437 | if (rc & BG_ERR_CHECK) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2438 | checking = 0; |
| 2439 | } |
| 2440 | #endif |
| 2441 | |
| 2442 | split_offset = 0; |
| 2443 | do { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2444 | /* Check to see if we ran out of space */ |
| 2445 | if (num_sge >= (phba->cfg_total_seg_cnt - 2)) |
| 2446 | return num_sge + 3; |
| 2447 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2448 | /* setup DISEED with what we have */ |
| 2449 | diseed = (struct sli4_sge_diseed *) sgl; |
| 2450 | memset(diseed, 0, sizeof(struct sli4_sge_diseed)); |
| 2451 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED); |
| 2452 | |
| 2453 | /* Endianness conversion if necessary */ |
| 2454 | diseed->ref_tag = cpu_to_le32(reftag); |
| 2455 | diseed->ref_tag_tran = diseed->ref_tag; |
| 2456 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2457 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) { |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2458 | bf_set(lpfc_sli4_sge_dif_ce, diseed, checking); |
| 2459 | |
| 2460 | } else { |
| 2461 | bf_set(lpfc_sli4_sge_dif_ce, diseed, 0); |
| 2462 | /* |
| 2463 | * When in this mode, the hardware will replace |
| 2464 | * the guard tag from the host with a |
| 2465 | * newly generated good CRC for the wire. |
| 2466 | * Switch to raw mode here to avoid this |
| 2467 | * behavior. What the host sends gets put on the wire. |
| 2468 | */ |
| 2469 | if (txop == BG_OP_IN_CRC_OUT_CRC) { |
| 2470 | txop = BG_OP_RAW_MODE; |
| 2471 | rxop = BG_OP_RAW_MODE; |
| 2472 | } |
| 2473 | } |
| 2474 | |
| 2475 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2476 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2477 | bf_set(lpfc_sli4_sge_dif_re, diseed, checking); |
| 2478 | else |
| 2479 | bf_set(lpfc_sli4_sge_dif_re, diseed, 0); |
| 2480 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2481 | /* setup DISEED with the rest of the info */ |
| 2482 | bf_set(lpfc_sli4_sge_dif_optx, diseed, txop); |
| 2483 | bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2484 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2485 | bf_set(lpfc_sli4_sge_dif_ai, diseed, 1); |
| 2486 | bf_set(lpfc_sli4_sge_dif_me, diseed, 0); |
| 2487 | |
| 2488 | /* Endianness conversion if necessary for DISEED */ |
| 2489 | diseed->word2 = cpu_to_le32(diseed->word2); |
| 2490 | diseed->word3 = cpu_to_le32(diseed->word3); |
| 2491 | |
| 2492 | /* advance sgl and increment bde count */ |
| 2493 | num_sge++; |
| 2494 | sgl++; |
| 2495 | |
| 2496 | /* setup the first BDE that points to protection buffer */ |
| 2497 | protphysaddr = sg_dma_address(sgpe) + protgroup_offset; |
| 2498 | protgroup_len = sg_dma_len(sgpe) - protgroup_offset; |
| 2499 | |
| 2500 | /* must be integer multiple of the DIF block length */ |
| 2501 | BUG_ON(protgroup_len % 8); |
| 2502 | |
| 2503 | /* Now setup DIF SGE */ |
| 2504 | sgl->word2 = 0; |
| 2505 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DIF); |
| 2506 | sgl->addr_hi = le32_to_cpu(putPaddrHigh(protphysaddr)); |
| 2507 | sgl->addr_lo = le32_to_cpu(putPaddrLow(protphysaddr)); |
| 2508 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 2509 | |
| 2510 | protgrp_blks = protgroup_len / 8; |
| 2511 | protgrp_bytes = protgrp_blks * blksize; |
| 2512 | |
| 2513 | /* check if DIF SGE is crossing the 4K boundary; if so split */ |
| 2514 | if ((sgl->addr_lo & 0xfff) + protgroup_len > 0x1000) { |
| 2515 | protgroup_remainder = 0x1000 - (sgl->addr_lo & 0xfff); |
| 2516 | protgroup_offset += protgroup_remainder; |
| 2517 | protgrp_blks = protgroup_remainder / 8; |
| 2518 | protgrp_bytes = protgrp_blks * blksize; |
| 2519 | } else { |
| 2520 | protgroup_offset = 0; |
| 2521 | curr_prot++; |
| 2522 | } |
| 2523 | |
| 2524 | num_sge++; |
| 2525 | |
| 2526 | /* setup SGE's for data blocks associated with DIF data */ |
| 2527 | pgdone = 0; |
| 2528 | subtotal = 0; /* total bytes processed for current prot grp */ |
| 2529 | while (!pgdone) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2530 | /* Check to see if we ran out of space */ |
| 2531 | if (num_sge >= phba->cfg_total_seg_cnt) |
| 2532 | return num_sge + 1; |
| 2533 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2534 | if (!sgde) { |
| 2535 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2536 | "9086 BLKGRD:%s Invalid data segment\n", |
| 2537 | __func__); |
| 2538 | return 0; |
| 2539 | } |
| 2540 | sgl++; |
| 2541 | dataphysaddr = sg_dma_address(sgde) + split_offset; |
| 2542 | |
| 2543 | remainder = sg_dma_len(sgde) - split_offset; |
| 2544 | |
| 2545 | if ((subtotal + remainder) <= protgrp_bytes) { |
| 2546 | /* we can use this whole buffer */ |
| 2547 | dma_len = remainder; |
| 2548 | split_offset = 0; |
| 2549 | |
| 2550 | if ((subtotal + remainder) == protgrp_bytes) |
| 2551 | pgdone = 1; |
| 2552 | } else { |
| 2553 | /* must split this buffer with next prot grp */ |
| 2554 | dma_len = protgrp_bytes - subtotal; |
| 2555 | split_offset += dma_len; |
| 2556 | } |
| 2557 | |
| 2558 | subtotal += dma_len; |
| 2559 | |
| 2560 | sgl->addr_lo = cpu_to_le32(putPaddrLow(dataphysaddr)); |
| 2561 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(dataphysaddr)); |
| 2562 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 2563 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
| 2564 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); |
| 2565 | |
| 2566 | sgl->sge_len = cpu_to_le32(dma_len); |
| 2567 | dma_offset += dma_len; |
| 2568 | |
| 2569 | num_sge++; |
| 2570 | curr_data++; |
| 2571 | |
| 2572 | if (split_offset) |
| 2573 | break; |
| 2574 | |
| 2575 | /* Move to the next s/g segment if possible */ |
| 2576 | sgde = sg_next(sgde); |
| 2577 | } |
| 2578 | |
| 2579 | if (protgroup_offset) { |
| 2580 | /* update the reference tag */ |
| 2581 | reftag += protgrp_blks; |
| 2582 | sgl++; |
| 2583 | continue; |
| 2584 | } |
| 2585 | |
| 2586 | /* are we done ? */ |
| 2587 | if (curr_prot == protcnt) { |
| 2588 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 2589 | alldone = 1; |
| 2590 | } else if (curr_prot < protcnt) { |
| 2591 | /* advance to next prot buffer */ |
| 2592 | sgpe = sg_next(sgpe); |
| 2593 | sgl++; |
| 2594 | |
| 2595 | /* update the reference tag */ |
| 2596 | reftag += protgrp_blks; |
| 2597 | } else { |
| 2598 | /* if we're here, we have a bug */ |
| 2599 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 2600 | "9085 BLKGRD: bug in %s\n", __func__); |
| 2601 | } |
| 2602 | |
| 2603 | } while (!alldone); |
| 2604 | |
| 2605 | out: |
| 2606 | |
| 2607 | return num_sge; |
| 2608 | } |
| 2609 | |
| 2610 | /** |
| 2611 | * lpfc_prot_group_type - Get prtotection group type of SCSI command |
| 2612 | * @phba: The Hba for which this call is being executed. |
| 2613 | * @sc: pointer to scsi command we're working on |
| 2614 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2615 | * Given a SCSI command that supports DIF, determine composition of protection |
| 2616 | * groups involved in setting up buffer lists |
| 2617 | * |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2618 | * Returns: Protection group type (with or without DIF) |
| 2619 | * |
| 2620 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2621 | static int |
| 2622 | lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc) |
| 2623 | { |
| 2624 | int ret = LPFC_PG_TYPE_INVALID; |
| 2625 | unsigned char op = scsi_get_prot_op(sc); |
| 2626 | |
| 2627 | switch (op) { |
| 2628 | case SCSI_PROT_READ_STRIP: |
| 2629 | case SCSI_PROT_WRITE_INSERT: |
| 2630 | ret = LPFC_PG_TYPE_NO_DIF; |
| 2631 | break; |
| 2632 | case SCSI_PROT_READ_INSERT: |
| 2633 | case SCSI_PROT_WRITE_STRIP: |
| 2634 | case SCSI_PROT_READ_PASS: |
| 2635 | case SCSI_PROT_WRITE_PASS: |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2636 | ret = LPFC_PG_TYPE_DIF_BUF; |
| 2637 | break; |
| 2638 | default: |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2639 | if (phba) |
| 2640 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2641 | "9021 Unsupported protection op:%d\n", |
| 2642 | op); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2643 | break; |
| 2644 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2645 | return ret; |
| 2646 | } |
| 2647 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2648 | /** |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2649 | * lpfc_bg_scsi_adjust_dl - Adjust SCSI data length for BlockGuard |
| 2650 | * @phba: The Hba for which this call is being executed. |
| 2651 | * @lpfc_cmd: The scsi buffer which is going to be adjusted. |
| 2652 | * |
| 2653 | * Adjust the data length to account for how much data |
| 2654 | * is actually on the wire. |
| 2655 | * |
| 2656 | * returns the adjusted data length |
| 2657 | **/ |
| 2658 | static int |
| 2659 | lpfc_bg_scsi_adjust_dl(struct lpfc_hba *phba, |
| 2660 | struct lpfc_scsi_buf *lpfc_cmd) |
| 2661 | { |
| 2662 | struct scsi_cmnd *sc = lpfc_cmd->pCmd; |
| 2663 | int fcpdl; |
| 2664 | |
| 2665 | fcpdl = scsi_bufflen(sc); |
| 2666 | |
| 2667 | /* Check if there is protection data on the wire */ |
| 2668 | if (sc->sc_data_direction == DMA_FROM_DEVICE) { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2669 | /* Read check for protection data */ |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2670 | if (scsi_get_prot_op(sc) == SCSI_PROT_READ_INSERT) |
| 2671 | return fcpdl; |
| 2672 | |
| 2673 | } else { |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2674 | /* Write check for protection data */ |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2675 | if (scsi_get_prot_op(sc) == SCSI_PROT_WRITE_STRIP) |
| 2676 | return fcpdl; |
| 2677 | } |
| 2678 | |
| 2679 | /* |
| 2680 | * 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] | 2681 | * DIF (trailer) attached to it. Must ajust FCP data length |
| 2682 | * to account for the protection data. |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2683 | */ |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2684 | fcpdl += (fcpdl / lpfc_cmd_blksize(sc)) * 8; |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2685 | |
| 2686 | return fcpdl; |
| 2687 | } |
| 2688 | |
| 2689 | /** |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2690 | * lpfc_bg_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec |
| 2691 | * @phba: The Hba for which this call is being executed. |
| 2692 | * @lpfc_cmd: The scsi buffer which is going to be prep'ed. |
| 2693 | * |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2694 | * This is the protection/DIF aware version of |
| 2695 | * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the |
| 2696 | * two functions eventually, but for now, it's here |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2697 | **/ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2698 | static int |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 2699 | lpfc_bg_scsi_prep_dma_buf_s3(struct lpfc_hba *phba, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2700 | struct lpfc_scsi_buf *lpfc_cmd) |
| 2701 | { |
| 2702 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 2703 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 2704 | struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl; |
| 2705 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 2706 | uint32_t num_bde = 0; |
| 2707 | int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction; |
| 2708 | int prot_group_type = 0; |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2709 | int fcpdl; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2710 | |
| 2711 | /* |
| 2712 | * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd |
| 2713 | * fcp_rsp regions to the first data bde entry |
| 2714 | */ |
| 2715 | bpl += 2; |
| 2716 | if (scsi_sg_count(scsi_cmnd)) { |
| 2717 | /* |
| 2718 | * The driver stores the segment count returned from pci_map_sg |
| 2719 | * because this a count of dma-mappings used to map the use_sg |
| 2720 | * pages. They are not guaranteed to be the same for those |
| 2721 | * architectures that implement an IOMMU. |
| 2722 | */ |
| 2723 | datasegcnt = dma_map_sg(&phba->pcidev->dev, |
| 2724 | scsi_sglist(scsi_cmnd), |
| 2725 | scsi_sg_count(scsi_cmnd), datadir); |
| 2726 | if (unlikely(!datasegcnt)) |
| 2727 | return 1; |
| 2728 | |
| 2729 | lpfc_cmd->seg_cnt = datasegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2730 | |
| 2731 | /* First check if data segment count from SCSI Layer is good */ |
| 2732 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) |
| 2733 | goto err; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2734 | |
| 2735 | prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd); |
| 2736 | |
| 2737 | switch (prot_group_type) { |
| 2738 | case LPFC_PG_TYPE_NO_DIF: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2739 | |
| 2740 | /* Here we need to add a PDE5 and PDE6 to the count */ |
| 2741 | if ((lpfc_cmd->seg_cnt + 2) > phba->cfg_total_seg_cnt) |
| 2742 | goto err; |
| 2743 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2744 | num_bde = lpfc_bg_setup_bpl(phba, scsi_cmnd, bpl, |
| 2745 | datasegcnt); |
Adam Buchbinder | c9404c9 | 2009-12-18 15:40:42 -0500 | [diff] [blame] | 2746 | /* we should have 2 or more entries in buffer list */ |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2747 | if (num_bde < 2) |
| 2748 | goto err; |
| 2749 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2750 | |
| 2751 | case LPFC_PG_TYPE_DIF_BUF: |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2752 | /* |
| 2753 | * This type indicates that protection buffers are |
| 2754 | * passed to the driver, so that needs to be prepared |
| 2755 | * for DMA |
| 2756 | */ |
| 2757 | protsegcnt = dma_map_sg(&phba->pcidev->dev, |
| 2758 | scsi_prot_sglist(scsi_cmnd), |
| 2759 | scsi_prot_sg_count(scsi_cmnd), datadir); |
| 2760 | if (unlikely(!protsegcnt)) { |
| 2761 | scsi_dma_unmap(scsi_cmnd); |
| 2762 | return 1; |
| 2763 | } |
| 2764 | |
| 2765 | lpfc_cmd->prot_seg_cnt = protsegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2766 | |
| 2767 | /* |
| 2768 | * There is a minimun of 4 BPLs used for every |
| 2769 | * protection data segment. |
| 2770 | */ |
| 2771 | if ((lpfc_cmd->prot_seg_cnt * 4) > |
| 2772 | (phba->cfg_total_seg_cnt - 2)) |
| 2773 | goto err; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2774 | |
| 2775 | num_bde = lpfc_bg_setup_bpl_prot(phba, scsi_cmnd, bpl, |
| 2776 | datasegcnt, protsegcnt); |
Adam Buchbinder | c9404c9 | 2009-12-18 15:40:42 -0500 | [diff] [blame] | 2777 | /* we should have 3 or more entries in buffer list */ |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2778 | if ((num_bde < 3) || |
| 2779 | (num_bde > phba->cfg_total_seg_cnt)) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2780 | goto err; |
| 2781 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2782 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2783 | case LPFC_PG_TYPE_INVALID: |
| 2784 | default: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2785 | scsi_dma_unmap(scsi_cmnd); |
| 2786 | lpfc_cmd->seg_cnt = 0; |
| 2787 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2788 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 2789 | "9022 Unexpected protection group %i\n", |
| 2790 | prot_group_type); |
| 2791 | return 1; |
| 2792 | } |
| 2793 | } |
| 2794 | |
| 2795 | /* |
| 2796 | * Finish initializing those IOCB fields that are dependent on the |
| 2797 | * scsi_cmnd request_buffer. Note that the bdeSize is explicitly |
| 2798 | * reinitialized since all iocb memory resources are used many times |
| 2799 | * for transmit, receive, and continuation bpl's. |
| 2800 | */ |
| 2801 | iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| 2802 | iocb_cmd->un.fcpi64.bdl.bdeSize += (num_bde * sizeof(struct ulp_bde64)); |
| 2803 | iocb_cmd->ulpBdeCount = 1; |
| 2804 | iocb_cmd->ulpLe = 1; |
| 2805 | |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2806 | fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2807 | fcp_cmnd->fcpDl = be32_to_cpu(fcpdl); |
| 2808 | |
| 2809 | /* |
| 2810 | * Due to difference in data length between DIF/non-DIF paths, |
| 2811 | * we need to set word 4 of IOCB here |
| 2812 | */ |
| 2813 | iocb_cmd->un.fcpi.fcpi_parm = fcpdl; |
| 2814 | |
| 2815 | return 0; |
| 2816 | err: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2817 | if (lpfc_cmd->seg_cnt) |
| 2818 | scsi_dma_unmap(scsi_cmnd); |
| 2819 | if (lpfc_cmd->prot_seg_cnt) |
| 2820 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd), |
| 2821 | scsi_prot_sg_count(scsi_cmnd), |
| 2822 | scsi_cmnd->sc_data_direction); |
| 2823 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2824 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2825 | "9023 Cannot setup S/G List for HBA" |
| 2826 | "IO segs %d/%d BPL %d SCSI %d: %d %d\n", |
| 2827 | lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt, |
| 2828 | phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2829 | prot_group_type, num_bde); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 2830 | |
| 2831 | lpfc_cmd->seg_cnt = 0; |
| 2832 | lpfc_cmd->prot_seg_cnt = 0; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 2833 | return 1; |
| 2834 | } |
| 2835 | |
| 2836 | /* |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2837 | * This function calcuates the T10 DIF guard tag |
| 2838 | * on the specified data using a CRC algorithmn |
| 2839 | * using crc_t10dif. |
| 2840 | */ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 2841 | static uint16_t |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2842 | lpfc_bg_crc(uint8_t *data, int count) |
| 2843 | { |
| 2844 | uint16_t crc = 0; |
| 2845 | uint16_t x; |
| 2846 | |
| 2847 | crc = crc_t10dif(data, count); |
| 2848 | x = cpu_to_be16(crc); |
| 2849 | return x; |
| 2850 | } |
| 2851 | |
| 2852 | /* |
| 2853 | * This function calcuates the T10 DIF guard tag |
| 2854 | * on the specified data using a CSUM algorithmn |
| 2855 | * using ip_compute_csum. |
| 2856 | */ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 2857 | static uint16_t |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2858 | lpfc_bg_csum(uint8_t *data, int count) |
| 2859 | { |
| 2860 | uint16_t ret; |
| 2861 | |
| 2862 | ret = ip_compute_csum(data, count); |
| 2863 | return ret; |
| 2864 | } |
| 2865 | |
| 2866 | /* |
| 2867 | * This function examines the protection data to try to determine |
| 2868 | * what type of T10-DIF error occurred. |
| 2869 | */ |
Rashika Kheria | 7bfe781 | 2014-09-03 12:55:36 -0400 | [diff] [blame] | 2870 | static void |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2871 | lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 2872 | { |
| 2873 | struct scatterlist *sgpe; /* s/g prot entry */ |
| 2874 | struct scatterlist *sgde; /* s/g data entry */ |
| 2875 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 2876 | struct scsi_dif_tuple *src = NULL; |
| 2877 | uint8_t *data_src = NULL; |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 2878 | uint16_t guard_tag; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2879 | uint16_t start_app_tag, app_tag; |
| 2880 | uint32_t start_ref_tag, ref_tag; |
| 2881 | int prot, protsegcnt; |
| 2882 | int err_type, len, data_len; |
| 2883 | int chk_ref, chk_app, chk_guard; |
| 2884 | uint16_t sum; |
| 2885 | unsigned blksize; |
| 2886 | |
| 2887 | err_type = BGS_GUARD_ERR_MASK; |
| 2888 | sum = 0; |
| 2889 | guard_tag = 0; |
| 2890 | |
| 2891 | /* First check to see if there is protection data to examine */ |
| 2892 | prot = scsi_get_prot_op(cmd); |
| 2893 | if ((prot == SCSI_PROT_READ_STRIP) || |
| 2894 | (prot == SCSI_PROT_WRITE_INSERT) || |
| 2895 | (prot == SCSI_PROT_NORMAL)) |
| 2896 | goto out; |
| 2897 | |
| 2898 | /* Currently the driver just supports ref_tag and guard_tag checking */ |
| 2899 | chk_ref = 1; |
| 2900 | chk_app = 0; |
| 2901 | chk_guard = 0; |
| 2902 | |
| 2903 | /* Setup a ptr to the protection data provided by the SCSI host */ |
| 2904 | sgpe = scsi_prot_sglist(cmd); |
| 2905 | protsegcnt = lpfc_cmd->prot_seg_cnt; |
| 2906 | |
| 2907 | if (sgpe && protsegcnt) { |
| 2908 | |
| 2909 | /* |
| 2910 | * We will only try to verify guard tag if the segment |
| 2911 | * data length is a multiple of the blksize. |
| 2912 | */ |
| 2913 | sgde = scsi_sglist(cmd); |
| 2914 | blksize = lpfc_cmd_blksize(cmd); |
| 2915 | data_src = (uint8_t *)sg_virt(sgde); |
| 2916 | data_len = sgde->length; |
| 2917 | if ((data_len & (blksize - 1)) == 0) |
| 2918 | chk_guard = 1; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2919 | |
James Smart | e85d8f9 | 2013-05-31 17:04:10 -0400 | [diff] [blame] | 2920 | src = (struct scsi_dif_tuple *)sg_virt(sgpe); |
James Smart | a6887e2 | 2013-04-17 20:18:07 -0400 | [diff] [blame] | 2921 | start_ref_tag = (uint32_t)scsi_get_lba(cmd); /* Truncate LBA */ |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2922 | start_app_tag = src->app_tag; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2923 | len = sgpe->length; |
| 2924 | while (src && protsegcnt) { |
| 2925 | while (len) { |
| 2926 | |
| 2927 | /* |
| 2928 | * First check to see if a protection data |
| 2929 | * check is valid |
| 2930 | */ |
| 2931 | if ((src->ref_tag == 0xffffffff) || |
| 2932 | (src->app_tag == 0xffff)) { |
| 2933 | start_ref_tag++; |
| 2934 | goto skipit; |
| 2935 | } |
| 2936 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2937 | /* First Guard Tag checking */ |
| 2938 | if (chk_guard) { |
| 2939 | guard_tag = src->guard_tag; |
| 2940 | if (lpfc_cmd_guard_csum(cmd)) |
| 2941 | sum = lpfc_bg_csum(data_src, |
| 2942 | blksize); |
| 2943 | else |
| 2944 | sum = lpfc_bg_crc(data_src, |
| 2945 | blksize); |
| 2946 | if ((guard_tag != sum)) { |
| 2947 | err_type = BGS_GUARD_ERR_MASK; |
| 2948 | goto out; |
| 2949 | } |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2950 | } |
| 2951 | |
| 2952 | /* Reference Tag checking */ |
| 2953 | ref_tag = be32_to_cpu(src->ref_tag); |
| 2954 | if (chk_ref && (ref_tag != start_ref_tag)) { |
| 2955 | err_type = BGS_REFTAG_ERR_MASK; |
| 2956 | goto out; |
| 2957 | } |
| 2958 | start_ref_tag++; |
| 2959 | |
James Smart | 9c6aa9d | 2013-05-31 17:03:39 -0400 | [diff] [blame] | 2960 | /* App Tag checking */ |
| 2961 | app_tag = src->app_tag; |
| 2962 | if (chk_app && (app_tag != start_app_tag)) { |
| 2963 | err_type = BGS_APPTAG_ERR_MASK; |
| 2964 | goto out; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 2965 | } |
| 2966 | skipit: |
| 2967 | len -= sizeof(struct scsi_dif_tuple); |
| 2968 | if (len < 0) |
| 2969 | len = 0; |
| 2970 | src++; |
| 2971 | |
| 2972 | data_src += blksize; |
| 2973 | data_len -= blksize; |
| 2974 | |
| 2975 | /* |
| 2976 | * Are we at the end of the Data segment? |
| 2977 | * The data segment is only used for Guard |
| 2978 | * tag checking. |
| 2979 | */ |
| 2980 | if (chk_guard && (data_len == 0)) { |
| 2981 | chk_guard = 0; |
| 2982 | sgde = sg_next(sgde); |
| 2983 | if (!sgde) |
| 2984 | goto out; |
| 2985 | |
| 2986 | data_src = (uint8_t *)sg_virt(sgde); |
| 2987 | data_len = sgde->length; |
| 2988 | if ((data_len & (blksize - 1)) == 0) |
| 2989 | chk_guard = 1; |
| 2990 | } |
| 2991 | } |
| 2992 | |
| 2993 | /* Goto the next Protection data segment */ |
| 2994 | sgpe = sg_next(sgpe); |
| 2995 | if (sgpe) { |
| 2996 | src = (struct scsi_dif_tuple *)sg_virt(sgpe); |
| 2997 | len = sgpe->length; |
| 2998 | } else { |
| 2999 | src = NULL; |
| 3000 | } |
| 3001 | protsegcnt--; |
| 3002 | } |
| 3003 | } |
| 3004 | out: |
| 3005 | if (err_type == BGS_GUARD_ERR_MASK) { |
| 3006 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 3007 | 0x10, 0x1); |
| 3008 | cmd->result = DRIVER_SENSE << 24 |
| 3009 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 3010 | phba->bg_guard_err_cnt++; |
| 3011 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3012 | "9069 BLKGRD: LBA %lx grd_tag error %x != %x\n", |
| 3013 | (unsigned long)scsi_get_lba(cmd), |
| 3014 | sum, guard_tag); |
| 3015 | |
| 3016 | } else if (err_type == BGS_REFTAG_ERR_MASK) { |
| 3017 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 3018 | 0x10, 0x3); |
| 3019 | cmd->result = DRIVER_SENSE << 24 |
| 3020 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 3021 | |
| 3022 | phba->bg_reftag_err_cnt++; |
| 3023 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3024 | "9066 BLKGRD: LBA %lx ref_tag error %x != %x\n", |
| 3025 | (unsigned long)scsi_get_lba(cmd), |
| 3026 | ref_tag, start_ref_tag); |
| 3027 | |
| 3028 | } else if (err_type == BGS_APPTAG_ERR_MASK) { |
| 3029 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 3030 | 0x10, 0x2); |
| 3031 | cmd->result = DRIVER_SENSE << 24 |
| 3032 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 3033 | |
| 3034 | phba->bg_apptag_err_cnt++; |
| 3035 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3036 | "9041 BLKGRD: LBA %lx app_tag error %x != %x\n", |
| 3037 | (unsigned long)scsi_get_lba(cmd), |
| 3038 | app_tag, start_app_tag); |
| 3039 | } |
| 3040 | } |
| 3041 | |
| 3042 | |
| 3043 | /* |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3044 | * This function checks for BlockGuard errors detected by |
| 3045 | * the HBA. In case of errors, the ASC/ASCQ fields in the |
| 3046 | * sense buffer will be set accordingly, paired with |
| 3047 | * ILLEGAL_REQUEST to signal to the kernel that the HBA |
| 3048 | * detected corruption. |
| 3049 | * |
| 3050 | * Returns: |
| 3051 | * 0 - No error found |
| 3052 | * 1 - BlockGuard error found |
| 3053 | * -1 - Internal error (bad profile, ...etc) |
| 3054 | */ |
| 3055 | static int |
| 3056 | lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd, |
| 3057 | struct lpfc_iocbq *pIocbOut) |
| 3058 | { |
| 3059 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; |
| 3060 | struct sli3_bg_fields *bgf = &pIocbOut->iocb.unsli3.sli3_bg; |
| 3061 | int ret = 0; |
| 3062 | uint32_t bghm = bgf->bghm; |
| 3063 | uint32_t bgstat = bgf->bgstat; |
| 3064 | uint64_t failing_sector = 0; |
| 3065 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3066 | spin_lock(&_dump_buf_lock); |
| 3067 | if (!_dump_buf_done) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3068 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9070 BLKGRD: Saving" |
| 3069 | " Data for %u blocks to debugfs\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3070 | (cmd->cmnd[7] << 8 | cmd->cmnd[8])); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3071 | lpfc_debug_save_data(phba, cmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3072 | |
| 3073 | /* If we have a prot sgl, save the DIF buffer */ |
| 3074 | if (lpfc_prot_group_type(phba, cmd) == |
| 3075 | LPFC_PG_TYPE_DIF_BUF) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3076 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9071 BLKGRD: " |
| 3077 | "Saving DIF for %u blocks to debugfs\n", |
| 3078 | (cmd->cmnd[7] << 8 | cmd->cmnd[8])); |
| 3079 | lpfc_debug_save_dif(phba, cmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3080 | } |
| 3081 | |
| 3082 | _dump_buf_done = 1; |
| 3083 | } |
| 3084 | spin_unlock(&_dump_buf_lock); |
| 3085 | |
| 3086 | if (lpfc_bgs_get_invalid_prof(bgstat)) { |
| 3087 | cmd->result = ScsiResult(DID_ERROR, 0); |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3088 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3089 | "9072 BLKGRD: Invalid BG Profile in cmd" |
| 3090 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3091 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3092 | (unsigned long long)scsi_get_lba(cmd), |
| 3093 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3094 | ret = (-1); |
| 3095 | goto out; |
| 3096 | } |
| 3097 | |
| 3098 | if (lpfc_bgs_get_uninit_dif_block(bgstat)) { |
| 3099 | cmd->result = ScsiResult(DID_ERROR, 0); |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3100 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3101 | "9073 BLKGRD: Invalid BG PDIF Block in cmd" |
| 3102 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3103 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3104 | (unsigned long long)scsi_get_lba(cmd), |
| 3105 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3106 | ret = (-1); |
| 3107 | goto out; |
| 3108 | } |
| 3109 | |
| 3110 | if (lpfc_bgs_get_guard_err(bgstat)) { |
| 3111 | ret = 1; |
| 3112 | |
| 3113 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 3114 | 0x10, 0x1); |
Martin K. Petersen | 1c9fbaf | 2009-01-04 03:14:11 -0500 | [diff] [blame] | 3115 | cmd->result = DRIVER_SENSE << 24 |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3116 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 3117 | phba->bg_guard_err_cnt++; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3118 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3119 | "9055 BLKGRD: Guard Tag error in cmd" |
| 3120 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3121 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3122 | (unsigned long long)scsi_get_lba(cmd), |
| 3123 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3124 | } |
| 3125 | |
| 3126 | if (lpfc_bgs_get_reftag_err(bgstat)) { |
| 3127 | ret = 1; |
| 3128 | |
| 3129 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 3130 | 0x10, 0x3); |
Martin K. Petersen | 1c9fbaf | 2009-01-04 03:14:11 -0500 | [diff] [blame] | 3131 | cmd->result = DRIVER_SENSE << 24 |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3132 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 3133 | |
| 3134 | phba->bg_reftag_err_cnt++; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3135 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3136 | "9056 BLKGRD: Ref Tag error in cmd" |
| 3137 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3138 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3139 | (unsigned long long)scsi_get_lba(cmd), |
| 3140 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3141 | } |
| 3142 | |
| 3143 | if (lpfc_bgs_get_apptag_err(bgstat)) { |
| 3144 | ret = 1; |
| 3145 | |
| 3146 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
| 3147 | 0x10, 0x2); |
Martin K. Petersen | 1c9fbaf | 2009-01-04 03:14:11 -0500 | [diff] [blame] | 3148 | cmd->result = DRIVER_SENSE << 24 |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3149 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
| 3150 | |
| 3151 | phba->bg_apptag_err_cnt++; |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3152 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3153 | "9061 BLKGRD: App Tag error in cmd" |
| 3154 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3155 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3156 | (unsigned long long)scsi_get_lba(cmd), |
| 3157 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3158 | } |
| 3159 | |
| 3160 | if (lpfc_bgs_get_hi_water_mark_present(bgstat)) { |
| 3161 | /* |
| 3162 | * setup sense data descriptor 0 per SPC-4 as an information |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 3163 | * field, and put the failing LBA in it. |
| 3164 | * This code assumes there was also a guard/app/ref tag error |
| 3165 | * indication. |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3166 | */ |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 3167 | cmd->sense_buffer[7] = 0xc; /* Additional sense length */ |
| 3168 | cmd->sense_buffer[8] = 0; /* Information descriptor type */ |
| 3169 | cmd->sense_buffer[9] = 0xa; /* Additional descriptor length */ |
| 3170 | cmd->sense_buffer[10] = 0x80; /* Validity bit */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3171 | |
| 3172 | /* bghm is a "on the wire" FC frame based count */ |
| 3173 | switch (scsi_get_prot_op(cmd)) { |
| 3174 | case SCSI_PROT_READ_INSERT: |
| 3175 | case SCSI_PROT_WRITE_STRIP: |
| 3176 | bghm /= cmd->device->sector_size; |
| 3177 | break; |
| 3178 | case SCSI_PROT_READ_STRIP: |
| 3179 | case SCSI_PROT_WRITE_INSERT: |
| 3180 | case SCSI_PROT_READ_PASS: |
| 3181 | case SCSI_PROT_WRITE_PASS: |
| 3182 | bghm /= (cmd->device->sector_size + |
| 3183 | sizeof(struct scsi_dif_tuple)); |
| 3184 | break; |
| 3185 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3186 | |
| 3187 | failing_sector = scsi_get_lba(cmd); |
| 3188 | failing_sector += bghm; |
| 3189 | |
James Smart | 7c56b9f | 2011-07-22 18:36:25 -0400 | [diff] [blame] | 3190 | /* Descriptor Information */ |
| 3191 | put_unaligned_be64(failing_sector, &cmd->sense_buffer[12]); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3192 | } |
| 3193 | |
| 3194 | if (!ret) { |
| 3195 | /* No error was reported - problem in FW? */ |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3196 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
| 3197 | "9057 BLKGRD: Unknown error in cmd" |
| 3198 | " 0x%x lba 0x%llx blk cnt 0x%x " |
| 3199 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], |
| 3200 | (unsigned long long)scsi_get_lba(cmd), |
| 3201 | blk_rq_sectors(cmd->request), bgstat, bghm); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3202 | |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 3203 | /* Calcuate what type of error it was */ |
| 3204 | lpfc_calc_bg_err(phba, lpfc_cmd); |
| 3205 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3206 | out: |
| 3207 | return ret; |
| 3208 | } |
| 3209 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3210 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3211 | * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec |
| 3212 | * @phba: The Hba for which this call is being executed. |
| 3213 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3214 | * |
| 3215 | * This routine does the pci dma mapping for scatter-gather list of scsi cmnd |
| 3216 | * field of @lpfc_cmd for device with SLI-4 interface spec. |
| 3217 | * |
| 3218 | * Return codes: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 3219 | * 1 - Error |
| 3220 | * 0 - Success |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3221 | **/ |
| 3222 | static int |
| 3223 | lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 3224 | { |
| 3225 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 3226 | struct scatterlist *sgel = NULL; |
| 3227 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 3228 | struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3229 | struct sli4_sge *first_data_sgl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3230 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 3231 | dma_addr_t physaddr; |
| 3232 | uint32_t num_bde = 0; |
| 3233 | uint32_t dma_len; |
| 3234 | uint32_t dma_offset = 0; |
| 3235 | int nseg; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3236 | struct ulp_bde64 *bde; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3237 | |
| 3238 | /* |
| 3239 | * There are three possibilities here - use scatter-gather segment, use |
| 3240 | * the single mapping, or neither. Start the lpfc command prep by |
| 3241 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 3242 | * data bde entry. |
| 3243 | */ |
| 3244 | if (scsi_sg_count(scsi_cmnd)) { |
| 3245 | /* |
| 3246 | * The driver stores the segment count returned from pci_map_sg |
| 3247 | * because this a count of dma-mappings used to map the use_sg |
| 3248 | * pages. They are not guaranteed to be the same for those |
| 3249 | * architectures that implement an IOMMU. |
| 3250 | */ |
| 3251 | |
| 3252 | nseg = scsi_dma_map(scsi_cmnd); |
James Smart | 5116fbf | 2015-05-22 10:42:39 -0400 | [diff] [blame] | 3253 | if (unlikely(nseg <= 0)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3254 | return 1; |
| 3255 | sgl += 1; |
| 3256 | /* clear the last flag in the fcp_rsp map entry */ |
| 3257 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 3258 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 3259 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 3260 | sgl += 1; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3261 | first_data_sgl = sgl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3262 | lpfc_cmd->seg_cnt = nseg; |
| 3263 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3264 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9074 BLKGRD:" |
| 3265 | " %s: Too many sg segments from " |
| 3266 | "dma_map_sg. Config %d, seg_cnt %d\n", |
| 3267 | __func__, phba->cfg_sg_seg_cnt, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3268 | lpfc_cmd->seg_cnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3269 | lpfc_cmd->seg_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3270 | scsi_dma_unmap(scsi_cmnd); |
| 3271 | return 1; |
| 3272 | } |
| 3273 | |
| 3274 | /* |
| 3275 | * The driver established a maximum scatter-gather segment count |
| 3276 | * during probe that limits the number of sg elements in any |
| 3277 | * single scsi command. Just run through the seg_cnt and format |
| 3278 | * the sge's. |
| 3279 | * When using SLI-3 the driver will try to fit all the BDEs into |
| 3280 | * the IOCB. If it can't then the BDEs get added to a BPL as it |
| 3281 | * does for SLI-2 mode. |
| 3282 | */ |
| 3283 | scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) { |
| 3284 | physaddr = sg_dma_address(sgel); |
| 3285 | dma_len = sg_dma_len(sgel); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3286 | sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr)); |
| 3287 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr)); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 3288 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3289 | if ((num_bde + 1) == nseg) |
| 3290 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 3291 | else |
| 3292 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 3293 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 3294 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3295 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 3296 | sgl->sge_len = cpu_to_le32(dma_len); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3297 | dma_offset += dma_len; |
| 3298 | sgl++; |
| 3299 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 3300 | /* setup the performance hint (first data BDE) if enabled */ |
| 3301 | if (phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) { |
| 3302 | bde = (struct ulp_bde64 *) |
| 3303 | &(iocb_cmd->unsli3.sli3Words[5]); |
| 3304 | bde->addrLow = first_data_sgl->addr_lo; |
| 3305 | bde->addrHigh = first_data_sgl->addr_hi; |
| 3306 | bde->tus.f.bdeSize = |
| 3307 | le32_to_cpu(first_data_sgl->sge_len); |
| 3308 | bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 3309 | bde->tus.w = cpu_to_le32(bde->tus.w); |
| 3310 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3311 | } else { |
| 3312 | sgl += 1; |
| 3313 | /* clear the last flag in the fcp_rsp map entry */ |
| 3314 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 3315 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 3316 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 3317 | } |
| 3318 | |
| 3319 | /* |
| 3320 | * Finish initializing those IOCB fields that are dependent on the |
| 3321 | * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is |
| 3322 | * explicitly reinitialized. |
| 3323 | * all iocb memory resources are reused. |
| 3324 | */ |
| 3325 | fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); |
| 3326 | |
| 3327 | /* |
| 3328 | * Due to difference in data length between DIF/non-DIF paths, |
| 3329 | * we need to set word 4 of IOCB here |
| 3330 | */ |
| 3331 | iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 3332 | |
| 3333 | /* |
| 3334 | * If the OAS driver feature is enabled and the lun is enabled for |
| 3335 | * OAS, set the oas iocb related flags. |
| 3336 | */ |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 3337 | if ((phba->cfg_fof) && ((struct lpfc_device_data *) |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 3338 | scsi_cmnd->device->hostdata)->oas_enabled) { |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 3339 | lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 3340 | lpfc_cmd->cur_iocbq.priority = ((struct lpfc_device_data *) |
| 3341 | scsi_cmnd->device->hostdata)->priority; |
| 3342 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3343 | return 0; |
| 3344 | } |
| 3345 | |
| 3346 | /** |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3347 | * lpfc_bg_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec |
| 3348 | * @phba: The Hba for which this call is being executed. |
| 3349 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3350 | * |
| 3351 | * This is the protection/DIF aware version of |
| 3352 | * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the |
| 3353 | * two functions eventually, but for now, it's here |
| 3354 | **/ |
| 3355 | static int |
| 3356 | lpfc_bg_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, |
| 3357 | struct lpfc_scsi_buf *lpfc_cmd) |
| 3358 | { |
| 3359 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 3360 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 3361 | struct sli4_sge *sgl = (struct sli4_sge *)(lpfc_cmd->fcp_bpl); |
| 3362 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3363 | uint32_t num_sge = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3364 | int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction; |
| 3365 | int prot_group_type = 0; |
| 3366 | int fcpdl; |
| 3367 | |
| 3368 | /* |
| 3369 | * Start the lpfc command prep by bumping the sgl beyond fcp_cmnd |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3370 | * fcp_rsp regions to the first data sge entry |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3371 | */ |
| 3372 | if (scsi_sg_count(scsi_cmnd)) { |
| 3373 | /* |
| 3374 | * The driver stores the segment count returned from pci_map_sg |
| 3375 | * because this a count of dma-mappings used to map the use_sg |
| 3376 | * pages. They are not guaranteed to be the same for those |
| 3377 | * architectures that implement an IOMMU. |
| 3378 | */ |
| 3379 | datasegcnt = dma_map_sg(&phba->pcidev->dev, |
| 3380 | scsi_sglist(scsi_cmnd), |
| 3381 | scsi_sg_count(scsi_cmnd), datadir); |
| 3382 | if (unlikely(!datasegcnt)) |
| 3383 | return 1; |
| 3384 | |
| 3385 | sgl += 1; |
| 3386 | /* clear the last flag in the fcp_rsp map entry */ |
| 3387 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 3388 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 3389 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 3390 | |
| 3391 | sgl += 1; |
| 3392 | lpfc_cmd->seg_cnt = datasegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3393 | |
| 3394 | /* First check if data segment count from SCSI Layer is good */ |
| 3395 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) |
| 3396 | goto err; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3397 | |
| 3398 | prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd); |
| 3399 | |
| 3400 | switch (prot_group_type) { |
| 3401 | case LPFC_PG_TYPE_NO_DIF: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3402 | /* Here we need to add a DISEED to the count */ |
| 3403 | if ((lpfc_cmd->seg_cnt + 1) > phba->cfg_total_seg_cnt) |
| 3404 | goto err; |
| 3405 | |
| 3406 | num_sge = lpfc_bg_setup_sgl(phba, scsi_cmnd, sgl, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3407 | datasegcnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3408 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3409 | /* we should have 2 or more entries in buffer list */ |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3410 | if (num_sge < 2) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3411 | goto err; |
| 3412 | break; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3413 | |
| 3414 | case LPFC_PG_TYPE_DIF_BUF: |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3415 | /* |
| 3416 | * This type indicates that protection buffers are |
| 3417 | * passed to the driver, so that needs to be prepared |
| 3418 | * for DMA |
| 3419 | */ |
| 3420 | protsegcnt = dma_map_sg(&phba->pcidev->dev, |
| 3421 | scsi_prot_sglist(scsi_cmnd), |
| 3422 | scsi_prot_sg_count(scsi_cmnd), datadir); |
| 3423 | if (unlikely(!protsegcnt)) { |
| 3424 | scsi_dma_unmap(scsi_cmnd); |
| 3425 | return 1; |
| 3426 | } |
| 3427 | |
| 3428 | lpfc_cmd->prot_seg_cnt = protsegcnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3429 | /* |
| 3430 | * There is a minimun of 3 SGEs used for every |
| 3431 | * protection data segment. |
| 3432 | */ |
| 3433 | if ((lpfc_cmd->prot_seg_cnt * 3) > |
| 3434 | (phba->cfg_total_seg_cnt - 2)) |
| 3435 | goto err; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3436 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3437 | num_sge = lpfc_bg_setup_sgl_prot(phba, scsi_cmnd, sgl, |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3438 | datasegcnt, protsegcnt); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3439 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3440 | /* we should have 3 or more entries in buffer list */ |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3441 | if ((num_sge < 3) || |
| 3442 | (num_sge > phba->cfg_total_seg_cnt)) |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3443 | goto err; |
| 3444 | break; |
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 | case LPFC_PG_TYPE_INVALID: |
| 3447 | default: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3448 | scsi_dma_unmap(scsi_cmnd); |
| 3449 | lpfc_cmd->seg_cnt = 0; |
| 3450 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3451 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 3452 | "9083 Unexpected protection group %i\n", |
| 3453 | prot_group_type); |
| 3454 | return 1; |
| 3455 | } |
| 3456 | } |
| 3457 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 3458 | switch (scsi_get_prot_op(scsi_cmnd)) { |
| 3459 | case SCSI_PROT_WRITE_STRIP: |
| 3460 | case SCSI_PROT_READ_STRIP: |
| 3461 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_STRIP; |
| 3462 | break; |
| 3463 | case SCSI_PROT_WRITE_INSERT: |
| 3464 | case SCSI_PROT_READ_INSERT: |
| 3465 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_INSERT; |
| 3466 | break; |
| 3467 | case SCSI_PROT_WRITE_PASS: |
| 3468 | case SCSI_PROT_READ_PASS: |
| 3469 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_PASS; |
| 3470 | break; |
| 3471 | } |
| 3472 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3473 | fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3474 | fcp_cmnd->fcpDl = be32_to_cpu(fcpdl); |
| 3475 | |
| 3476 | /* |
| 3477 | * Due to difference in data length between DIF/non-DIF paths, |
| 3478 | * we need to set word 4 of IOCB here |
| 3479 | */ |
| 3480 | iocb_cmd->un.fcpi.fcpi_parm = fcpdl; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3481 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 3482 | /* |
| 3483 | * If the OAS driver feature is enabled and the lun is enabled for |
| 3484 | * OAS, set the oas iocb related flags. |
| 3485 | */ |
| 3486 | if ((phba->cfg_fof) && ((struct lpfc_device_data *) |
| 3487 | scsi_cmnd->device->hostdata)->oas_enabled) |
| 3488 | lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF); |
| 3489 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3490 | return 0; |
| 3491 | err: |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3492 | if (lpfc_cmd->seg_cnt) |
| 3493 | scsi_dma_unmap(scsi_cmnd); |
| 3494 | if (lpfc_cmd->prot_seg_cnt) |
| 3495 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd), |
| 3496 | scsi_prot_sg_count(scsi_cmnd), |
| 3497 | scsi_cmnd->sc_data_direction); |
| 3498 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3499 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 3500 | "9084 Cannot setup S/G List for HBA" |
| 3501 | "IO segs %d/%d SGL %d SCSI %d: %d %d\n", |
| 3502 | lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt, |
| 3503 | phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt, |
| 3504 | prot_group_type, num_sge); |
| 3505 | |
| 3506 | lpfc_cmd->seg_cnt = 0; |
| 3507 | lpfc_cmd->prot_seg_cnt = 0; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3508 | return 1; |
| 3509 | } |
| 3510 | |
| 3511 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3512 | * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer |
| 3513 | * @phba: The Hba for which this call is being executed. |
| 3514 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3515 | * |
| 3516 | * This routine wraps the actual DMA mapping function pointer from the |
| 3517 | * lpfc_hba struct. |
| 3518 | * |
| 3519 | * Return codes: |
James Smart | 6c8eea5 | 2010-04-06 14:49:53 -0400 | [diff] [blame] | 3520 | * 1 - Error |
| 3521 | * 0 - Success |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3522 | **/ |
| 3523 | static inline int |
| 3524 | lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 3525 | { |
| 3526 | return phba->lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 3527 | } |
| 3528 | |
| 3529 | /** |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 3530 | * lpfc_bg_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer |
| 3531 | * using BlockGuard. |
| 3532 | * @phba: The Hba for which this call is being executed. |
| 3533 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
| 3534 | * |
| 3535 | * This routine wraps the actual DMA mapping function pointer from the |
| 3536 | * lpfc_hba struct. |
| 3537 | * |
| 3538 | * Return codes: |
| 3539 | * 1 - Error |
| 3540 | * 0 - Success |
| 3541 | **/ |
| 3542 | static inline int |
| 3543 | lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
| 3544 | { |
| 3545 | return phba->lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 3546 | } |
| 3547 | |
| 3548 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3549 | * 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] | 3550 | * @phba: Pointer to hba context object. |
| 3551 | * @vport: Pointer to vport object. |
| 3552 | * @lpfc_cmd: Pointer to lpfc scsi command which reported the error. |
| 3553 | * @rsp_iocb: Pointer to response iocb object which reported error. |
| 3554 | * |
| 3555 | * This function posts an event when there is a SCSI command reporting |
| 3556 | * error from the scsi device. |
| 3557 | **/ |
| 3558 | static void |
| 3559 | lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 3560 | struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_iocbq *rsp_iocb) { |
| 3561 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 3562 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
| 3563 | uint32_t resp_info = fcprsp->rspStatus2; |
| 3564 | uint32_t scsi_status = fcprsp->rspStatus3; |
| 3565 | uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; |
| 3566 | struct lpfc_fast_path_event *fast_path_evt = NULL; |
| 3567 | struct lpfc_nodelist *pnode = lpfc_cmd->rdata->pnode; |
| 3568 | unsigned long flags; |
| 3569 | |
James Smart | 5989b8d | 2010-10-22 11:06:56 -0400 | [diff] [blame] | 3570 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 3571 | return; |
| 3572 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3573 | /* If there is queuefull or busy condition send a scsi event */ |
| 3574 | if ((cmnd->result == SAM_STAT_TASK_SET_FULL) || |
| 3575 | (cmnd->result == SAM_STAT_BUSY)) { |
| 3576 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3577 | if (!fast_path_evt) |
| 3578 | return; |
| 3579 | fast_path_evt->un.scsi_evt.event_type = |
| 3580 | FC_REG_SCSI_EVENT; |
| 3581 | fast_path_evt->un.scsi_evt.subcategory = |
| 3582 | (cmnd->result == SAM_STAT_TASK_SET_FULL) ? |
| 3583 | LPFC_EVENT_QFULL : LPFC_EVENT_DEVBSY; |
| 3584 | fast_path_evt->un.scsi_evt.lun = cmnd->device->lun; |
| 3585 | memcpy(&fast_path_evt->un.scsi_evt.wwpn, |
| 3586 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3587 | memcpy(&fast_path_evt->un.scsi_evt.wwnn, |
| 3588 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3589 | } else if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen && |
| 3590 | ((cmnd->cmnd[0] == READ_10) || (cmnd->cmnd[0] == WRITE_10))) { |
| 3591 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3592 | if (!fast_path_evt) |
| 3593 | return; |
| 3594 | fast_path_evt->un.check_cond_evt.scsi_event.event_type = |
| 3595 | FC_REG_SCSI_EVENT; |
| 3596 | fast_path_evt->un.check_cond_evt.scsi_event.subcategory = |
| 3597 | LPFC_EVENT_CHECK_COND; |
| 3598 | fast_path_evt->un.check_cond_evt.scsi_event.lun = |
| 3599 | cmnd->device->lun; |
| 3600 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwpn, |
| 3601 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3602 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwnn, |
| 3603 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3604 | fast_path_evt->un.check_cond_evt.sense_key = |
| 3605 | cmnd->sense_buffer[2] & 0xf; |
| 3606 | fast_path_evt->un.check_cond_evt.asc = cmnd->sense_buffer[12]; |
| 3607 | fast_path_evt->un.check_cond_evt.ascq = cmnd->sense_buffer[13]; |
| 3608 | } else if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) && |
| 3609 | fcpi_parm && |
| 3610 | ((be32_to_cpu(fcprsp->rspResId) != fcpi_parm) || |
| 3611 | ((scsi_status == SAM_STAT_GOOD) && |
| 3612 | !(resp_info & (RESID_UNDER | RESID_OVER))))) { |
| 3613 | /* |
| 3614 | * If status is good or resid does not match with fcp_param and |
| 3615 | * there is valid fcpi_parm, then there is a read_check error |
| 3616 | */ |
| 3617 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 3618 | if (!fast_path_evt) |
| 3619 | return; |
| 3620 | fast_path_evt->un.read_check_error.header.event_type = |
| 3621 | FC_REG_FABRIC_EVENT; |
| 3622 | fast_path_evt->un.read_check_error.header.subcategory = |
| 3623 | LPFC_EVENT_FCPRDCHKERR; |
| 3624 | memcpy(&fast_path_evt->un.read_check_error.header.wwpn, |
| 3625 | &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 3626 | memcpy(&fast_path_evt->un.read_check_error.header.wwnn, |
| 3627 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 3628 | fast_path_evt->un.read_check_error.lun = cmnd->device->lun; |
| 3629 | fast_path_evt->un.read_check_error.opcode = cmnd->cmnd[0]; |
| 3630 | fast_path_evt->un.read_check_error.fcpiparam = |
| 3631 | fcpi_parm; |
| 3632 | } else |
| 3633 | return; |
| 3634 | |
| 3635 | fast_path_evt->vport = vport; |
| 3636 | spin_lock_irqsave(&phba->hbalock, flags); |
| 3637 | list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list); |
| 3638 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 3639 | lpfc_worker_wake_up(phba); |
| 3640 | return; |
| 3641 | } |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3642 | |
| 3643 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3644 | * 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] | 3645 | * @phba: The HBA for which this call is being executed. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3646 | * @psb: The scsi buffer which is going to be un-mapped. |
| 3647 | * |
| 3648 | * 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] | 3649 | * field of @lpfc_cmd for device with SLI-3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3650 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3651 | static void |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3652 | 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] | 3653 | { |
| 3654 | /* |
| 3655 | * There are only two special cases to consider. (1) the scsi command |
| 3656 | * requested scatter-gather usage or (2) the scsi command allocated |
| 3657 | * a request buffer, but did not request use_sg. There is a third |
| 3658 | * case, but it does not require resource deallocation. |
| 3659 | */ |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3660 | if (psb->seg_cnt > 0) |
| 3661 | scsi_dma_unmap(psb->pCmd); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3662 | if (psb->prot_seg_cnt > 0) |
| 3663 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(psb->pCmd), |
| 3664 | scsi_prot_sg_count(psb->pCmd), |
| 3665 | psb->pCmd->sc_data_direction); |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 3666 | } |
| 3667 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3668 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3669 | * lpfc_handler_fcp_err - FCP response handler |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3670 | * @vport: The virtual port for which this call is being executed. |
| 3671 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. |
| 3672 | * @rsp_iocb: The response IOCB which contains FCP error. |
| 3673 | * |
| 3674 | * This routine is called to process response IOCB with status field |
| 3675 | * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command |
| 3676 | * based upon SCSI and FCP error. |
| 3677 | **/ |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 3678 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3679 | lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd, |
| 3680 | struct lpfc_iocbq *rsp_iocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3681 | { |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3682 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3683 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 3684 | struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd; |
| 3685 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3686 | uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3687 | uint32_t resp_info = fcprsp->rspStatus2; |
| 3688 | uint32_t scsi_status = fcprsp->rspStatus3; |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3689 | uint32_t *lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3690 | uint32_t host_status = DID_OK; |
| 3691 | uint32_t rsplen = 0; |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3692 | uint32_t fcpDl; |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3693 | uint32_t logit = LOG_FCP | LOG_FCP_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3694 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3695 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3696 | /* |
| 3697 | * If this is a task management command, there is no |
| 3698 | * scsi packet associated with this lpfc_cmd. The driver |
| 3699 | * consumes it. |
| 3700 | */ |
| 3701 | if (fcpcmd->fcpCntl2) { |
| 3702 | scsi_status = 0; |
| 3703 | goto out; |
| 3704 | } |
| 3705 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3706 | if (resp_info & RSP_LEN_VALID) { |
| 3707 | rsplen = be32_to_cpu(fcprsp->rspRspLen); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3708 | if (rsplen != 0 && rsplen != 4 && rsplen != 8) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3709 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 3710 | "2719 Invalid response length: " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 3711 | "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] | 3712 | cmnd->device->id, |
| 3713 | cmnd->device->lun, cmnd->cmnd[0], |
| 3714 | rsplen); |
| 3715 | host_status = DID_ERROR; |
| 3716 | goto out; |
| 3717 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3718 | if (fcprsp->rspInfo3 != RSP_NO_FAILURE) { |
| 3719 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 3720 | "2757 Protocol failure detected during " |
| 3721 | "processing of FCP I/O op: " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 3722 | "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] | 3723 | cmnd->device->id, |
| 3724 | cmnd->device->lun, cmnd->cmnd[0], |
| 3725 | fcprsp->rspInfo3); |
| 3726 | host_status = DID_ERROR; |
| 3727 | goto out; |
| 3728 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3729 | } |
| 3730 | |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3731 | if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) { |
| 3732 | uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen); |
| 3733 | if (snslen > SCSI_SENSE_BUFFERSIZE) |
| 3734 | snslen = SCSI_SENSE_BUFFERSIZE; |
| 3735 | |
| 3736 | if (resp_info & RSP_LEN_VALID) |
| 3737 | rsplen = be32_to_cpu(fcprsp->rspRspLen); |
| 3738 | memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen); |
| 3739 | } |
| 3740 | lp = (uint32_t *)cmnd->sense_buffer; |
| 3741 | |
James Smart | aa1c7ee | 2012-08-14 14:26:06 -0400 | [diff] [blame] | 3742 | /* special handling for under run conditions */ |
| 3743 | if (!scsi_status && (resp_info & RESID_UNDER)) { |
| 3744 | /* don't log under runs if fcp set... */ |
| 3745 | if (vport->cfg_log_verbose & LOG_FCP) |
| 3746 | logit = LOG_FCP_ERROR; |
| 3747 | /* unless operator says so */ |
| 3748 | if (vport->cfg_log_verbose & LOG_FCP_UNDER) |
| 3749 | logit = LOG_FCP_UNDER; |
| 3750 | } |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 3751 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3752 | lpfc_printf_vlog(vport, KERN_WARNING, logit, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3753 | "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] | 3754 | "Data: x%x x%x x%x x%x x%x\n", |
| 3755 | cmnd->cmnd[0], scsi_status, |
| 3756 | be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info, |
| 3757 | be32_to_cpu(fcprsp->rspResId), |
| 3758 | be32_to_cpu(fcprsp->rspSnsLen), |
| 3759 | be32_to_cpu(fcprsp->rspRspLen), |
| 3760 | fcprsp->rspInfo3); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3761 | |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3762 | scsi_set_resid(cmnd, 0); |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3763 | fcpDl = be32_to_cpu(fcpcmd->fcpDl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3764 | if (resp_info & RESID_UNDER) { |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3765 | scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3766 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3767 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_UNDER, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3768 | "9025 FCP Read Underrun, expected %d, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3769 | "residual %d Data: x%x x%x x%x\n", |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3770 | fcpDl, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3771 | scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0], |
| 3772 | cmnd->underflow); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3773 | |
| 3774 | /* |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3775 | * If there is an under run check if under run reported by |
| 3776 | * storage array is same as the under run reported by HBA. |
| 3777 | * If this is not same, there is a dropped frame. |
| 3778 | */ |
| 3779 | if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) && |
| 3780 | fcpi_parm && |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3781 | (scsi_get_resid(cmnd) != fcpi_parm)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3782 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 3783 | LOG_FCP | LOG_FCP_ERROR, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3784 | "9026 FCP Read Check Error " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3785 | "and Underrun Data: x%x x%x x%x x%x\n", |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3786 | fcpDl, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3787 | scsi_get_resid(cmnd), fcpi_parm, |
| 3788 | cmnd->cmnd[0]); |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3789 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3790 | host_status = DID_ERROR; |
| 3791 | } |
| 3792 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3793 | * The cmnd->underflow is the minimum number of bytes that must |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3794 | * be transferred for this command. Provided a sense condition |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3795 | * is not present, make sure the actual amount transferred is at |
| 3796 | * least the underflow value or fail. |
| 3797 | */ |
| 3798 | if (!(resp_info & SNS_LEN_VALID) && |
| 3799 | (scsi_status == SAM_STAT_GOOD) && |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3800 | (scsi_bufflen(cmnd) - scsi_get_resid(cmnd) |
| 3801 | < cmnd->underflow)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3802 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3803 | "9027 FCP command x%x residual " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3804 | "underrun converted to error " |
| 3805 | "Data: x%x x%x x%x\n", |
James Smart | 66dbfbe | 2007-08-05 06:08:38 -0400 | [diff] [blame] | 3806 | cmnd->cmnd[0], scsi_bufflen(cmnd), |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3807 | scsi_get_resid(cmnd), cmnd->underflow); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3808 | host_status = DID_ERROR; |
| 3809 | } |
| 3810 | } else if (resp_info & RESID_OVER) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3811 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3812 | "9028 FCP command x%x residual overrun error. " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 3813 | "Data: x%x x%x\n", cmnd->cmnd[0], |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3814 | scsi_bufflen(cmnd), scsi_get_resid(cmnd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3815 | host_status = DID_ERROR; |
| 3816 | |
| 3817 | /* |
| 3818 | * Check SLI validation that all the transfer was actually done |
James Smart | 26373d2 | 2013-09-06 12:19:17 -0400 | [diff] [blame] | 3819 | * (fcpi_parm should be zero). Apply check only to reads. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3820 | */ |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3821 | } else if (fcpi_parm) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3822 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR, |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3823 | "9029 FCP %s Check Error xri x%x Data: " |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 3824 | "x%x x%x x%x x%x x%x\n", |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3825 | ((cmnd->sc_data_direction == DMA_FROM_DEVICE) ? |
| 3826 | "Read" : "Write"), |
| 3827 | ((phba->sli_rev == LPFC_SLI_REV4) ? |
| 3828 | lpfc_cmd->cur_iocbq.sli4_xritag : |
| 3829 | rsp_iocb->iocb.ulpContext), |
| 3830 | fcpDl, be32_to_cpu(fcprsp->rspResId), |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 3831 | fcpi_parm, cmnd->cmnd[0], scsi_status); |
James Smart | 5afab6b | 2015-12-16 18:12:01 -0500 | [diff] [blame] | 3832 | |
| 3833 | /* There is some issue with the LPe12000 that causes it |
| 3834 | * to miscalculate the fcpi_parm and falsely trip this |
| 3835 | * recovery logic. Detect this case and don't error when true. |
| 3836 | */ |
| 3837 | if (fcpi_parm > fcpDl) |
| 3838 | goto out; |
| 3839 | |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 3840 | switch (scsi_status) { |
| 3841 | case SAM_STAT_GOOD: |
| 3842 | case SAM_STAT_CHECK_CONDITION: |
| 3843 | /* Fabric dropped a data frame. Fail any successful |
| 3844 | * command in which we detected dropped frames. |
| 3845 | * A status of good or some check conditions could |
| 3846 | * be considered a successful command. |
| 3847 | */ |
| 3848 | host_status = DID_ERROR; |
| 3849 | break; |
| 3850 | } |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3851 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3852 | } |
| 3853 | |
| 3854 | out: |
| 3855 | cmnd->result = ScsiResult(host_status, scsi_status); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3856 | lpfc_send_scsi_error_event(vport->phba, vport, lpfc_cmd, rsp_iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3857 | } |
| 3858 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3859 | /** |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 3860 | * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution |
| 3861 | * @phba: Pointer to HBA context object. |
| 3862 | * |
| 3863 | * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index |
| 3864 | * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock |
| 3865 | * held. |
| 3866 | * If scsi-mq is enabled, get the default block layer mapping of software queues |
| 3867 | * to hardware queues. This information is saved in request tag. |
| 3868 | * |
| 3869 | * Return: index into SLI4 fast-path FCP queue index. |
| 3870 | **/ |
| 3871 | int lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba, |
| 3872 | struct lpfc_scsi_buf *lpfc_cmd) |
| 3873 | { |
| 3874 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; |
| 3875 | struct lpfc_vector_map_info *cpup; |
| 3876 | int chann, cpu; |
| 3877 | uint32_t tag; |
| 3878 | uint16_t hwq; |
| 3879 | |
Mauricio Faria de Oliveira | 05a0587 | 2016-06-07 20:13:08 -0300 | [diff] [blame] | 3880 | if (cmnd && shost_use_blk_mq(cmnd->device->host)) { |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 3881 | tag = blk_mq_unique_tag(cmnd->request); |
| 3882 | hwq = blk_mq_unique_tag_to_hwq(tag); |
| 3883 | |
| 3884 | return hwq; |
| 3885 | } |
| 3886 | |
| 3887 | if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_CPU |
| 3888 | && phba->cfg_fcp_io_channel > 1) { |
| 3889 | cpu = smp_processor_id(); |
| 3890 | if (cpu < phba->sli4_hba.num_present_cpu) { |
| 3891 | cpup = phba->sli4_hba.cpu_map; |
| 3892 | cpup += cpu; |
| 3893 | return cpup->channel_id; |
| 3894 | } |
| 3895 | } |
| 3896 | chann = atomic_add_return(1, &phba->fcp_qidx); |
| 3897 | chann = (chann % phba->cfg_fcp_io_channel); |
| 3898 | return chann; |
| 3899 | } |
| 3900 | |
| 3901 | |
| 3902 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3903 | * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3904 | * @phba: The Hba for which this call is being executed. |
| 3905 | * @pIocbIn: The command IOCBQ for the scsi cmnd. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3906 | * @pIocbOut: The response IOCBQ for the scsi cmnd. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 3907 | * |
| 3908 | * This routine assigns scsi command result by looking into response IOCB |
| 3909 | * status field appropriately. This routine handles QUEUE FULL condition as |
| 3910 | * well by ramping down device queue depth. |
| 3911 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3912 | static void |
| 3913 | lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn, |
| 3914 | struct lpfc_iocbq *pIocbOut) |
| 3915 | { |
| 3916 | struct lpfc_scsi_buf *lpfc_cmd = |
| 3917 | (struct lpfc_scsi_buf *) pIocbIn->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3918 | struct lpfc_vport *vport = pIocbIn->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3919 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| 3920 | struct lpfc_nodelist *pnode = rdata->pnode; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3921 | struct scsi_cmnd *cmd; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 3922 | int depth; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 3923 | unsigned long flags; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3924 | struct lpfc_fast_path_event *fast_path_evt; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3925 | struct Scsi_Host *shost; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3926 | uint32_t logit = LOG_FCP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3927 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3928 | /* Sanity check on return of outstanding command */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3929 | cmd = lpfc_cmd->pCmd; |
James Smart | c90261d | 2015-12-16 18:11:57 -0500 | [diff] [blame] | 3930 | if (!cmd) |
| 3931 | return; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 3932 | shost = cmd->device->host; |
| 3933 | |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3934 | lpfc_cmd->result = (pIocbOut->iocb.un.ulpWord[4] & IOERR_PARAM_MASK); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3935 | lpfc_cmd->status = pIocbOut->iocb.ulpStatus; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3936 | /* pick up SLI4 exhange busy status from HBA */ |
| 3937 | lpfc_cmd->exch_busy = pIocbOut->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 3938 | |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 3939 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 3940 | if (lpfc_cmd->prot_data_type) { |
| 3941 | struct scsi_dif_tuple *src = NULL; |
| 3942 | |
| 3943 | src = (struct scsi_dif_tuple *)lpfc_cmd->prot_data_segment; |
| 3944 | /* |
| 3945 | * Used to restore any changes to protection |
| 3946 | * data for error injection. |
| 3947 | */ |
| 3948 | switch (lpfc_cmd->prot_data_type) { |
| 3949 | case LPFC_INJERR_REFTAG: |
| 3950 | src->ref_tag = |
| 3951 | lpfc_cmd->prot_data; |
| 3952 | break; |
| 3953 | case LPFC_INJERR_APPTAG: |
| 3954 | src->app_tag = |
| 3955 | (uint16_t)lpfc_cmd->prot_data; |
| 3956 | break; |
| 3957 | case LPFC_INJERR_GUARD: |
| 3958 | src->guard_tag = |
| 3959 | (uint16_t)lpfc_cmd->prot_data; |
| 3960 | break; |
| 3961 | default: |
| 3962 | break; |
| 3963 | } |
| 3964 | |
| 3965 | lpfc_cmd->prot_data = 0; |
| 3966 | lpfc_cmd->prot_data_type = 0; |
| 3967 | lpfc_cmd->prot_data_segment = NULL; |
| 3968 | } |
| 3969 | #endif |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 3970 | if (pnode && NLP_CHK_NODE_ACT(pnode)) |
| 3971 | atomic_dec(&pnode->cmd_pending); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3972 | |
| 3973 | if (lpfc_cmd->status) { |
| 3974 | if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT && |
| 3975 | (lpfc_cmd->result & IOERR_DRVR_MASK)) |
| 3976 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; |
| 3977 | else if (lpfc_cmd->status >= IOSTAT_CNT) |
| 3978 | lpfc_cmd->status = IOSTAT_DEFAULT; |
James Smart | aa1c7ee | 2012-08-14 14:26:06 -0400 | [diff] [blame] | 3979 | if (lpfc_cmd->status == IOSTAT_FCP_RSP_ERROR && |
| 3980 | !lpfc_cmd->fcp_rsp->rspStatus3 && |
| 3981 | (lpfc_cmd->fcp_rsp->rspStatus2 & RESID_UNDER) && |
| 3982 | !(vport->cfg_log_verbose & LOG_FCP_UNDER)) |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3983 | logit = 0; |
| 3984 | else |
| 3985 | logit = LOG_FCP | LOG_FCP_UNDER; |
| 3986 | lpfc_printf_vlog(vport, KERN_WARNING, logit, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 3987 | "9030 FCP cmd x%x failed <%d/%lld> " |
James Smart | 5a0d80f | 2012-05-09 21:18:20 -0400 | [diff] [blame] | 3988 | "status: x%x result: x%x " |
| 3989 | "sid: x%x did: x%x oxid: x%x " |
| 3990 | "Data: x%x x%x\n", |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3991 | cmd->cmnd[0], |
| 3992 | cmd->device ? cmd->device->id : 0xffff, |
| 3993 | cmd->device ? cmd->device->lun : 0xffff, |
| 3994 | lpfc_cmd->status, lpfc_cmd->result, |
James Smart | 3bf41ba | 2013-05-31 17:03:18 -0400 | [diff] [blame] | 3995 | vport->fc_myDID, |
| 3996 | (pnode) ? pnode->nlp_DID : 0, |
James Smart | 5a0d80f | 2012-05-09 21:18:20 -0400 | [diff] [blame] | 3997 | phba->sli_rev == LPFC_SLI_REV4 ? |
| 3998 | lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3999 | pIocbOut->iocb.ulpContext, |
| 4000 | lpfc_cmd->cur_iocbq.iocb.ulpIoTag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4001 | |
| 4002 | switch (lpfc_cmd->status) { |
| 4003 | case IOSTAT_FCP_RSP_ERROR: |
| 4004 | /* Call FCP RSP handler to determine result */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4005 | lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4006 | break; |
| 4007 | case IOSTAT_NPORT_BSY: |
| 4008 | case IOSTAT_FABRIC_BSY: |
James Smart | 0f1f53a | 2008-08-24 21:50:18 -0400 | [diff] [blame] | 4009 | cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 0); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4010 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
| 4011 | if (!fast_path_evt) |
| 4012 | break; |
| 4013 | fast_path_evt->un.fabric_evt.event_type = |
| 4014 | FC_REG_FABRIC_EVENT; |
| 4015 | fast_path_evt->un.fabric_evt.subcategory = |
| 4016 | (lpfc_cmd->status == IOSTAT_NPORT_BSY) ? |
| 4017 | LPFC_EVENT_PORT_BUSY : LPFC_EVENT_FABRIC_BUSY; |
| 4018 | if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
| 4019 | memcpy(&fast_path_evt->un.fabric_evt.wwpn, |
| 4020 | &pnode->nlp_portname, |
| 4021 | sizeof(struct lpfc_name)); |
| 4022 | memcpy(&fast_path_evt->un.fabric_evt.wwnn, |
| 4023 | &pnode->nlp_nodename, |
| 4024 | sizeof(struct lpfc_name)); |
| 4025 | } |
| 4026 | fast_path_evt->vport = vport; |
| 4027 | fast_path_evt->work_evt.evt = |
| 4028 | LPFC_EVT_FASTPATH_MGMT_EVT; |
| 4029 | spin_lock_irqsave(&phba->hbalock, flags); |
| 4030 | list_add_tail(&fast_path_evt->work_evt.evt_listp, |
| 4031 | &phba->work_list); |
| 4032 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4033 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4034 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4035 | case IOSTAT_LOCAL_REJECT: |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4036 | case IOSTAT_REMOTE_STOP: |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 4037 | if (lpfc_cmd->result == IOERR_ELXSEC_KEY_UNWRAP_ERROR || |
| 4038 | lpfc_cmd->result == |
| 4039 | IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR || |
| 4040 | lpfc_cmd->result == IOERR_ELXSEC_CRYPTO_ERROR || |
| 4041 | lpfc_cmd->result == |
| 4042 | IOERR_ELXSEC_CRYPTO_COMPARE_ERROR) { |
| 4043 | cmd->result = ScsiResult(DID_NO_CONNECT, 0); |
| 4044 | break; |
| 4045 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4046 | if (lpfc_cmd->result == IOERR_INVALID_RPI || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4047 | lpfc_cmd->result == IOERR_NO_RESOURCES || |
James Smart | b92938b | 2010-06-07 15:24:12 -0400 | [diff] [blame] | 4048 | lpfc_cmd->result == IOERR_ABORT_REQUESTED || |
| 4049 | lpfc_cmd->result == IOERR_SLER_CMD_RCV_FAILURE) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4050 | cmd->result = ScsiResult(DID_REQUEUE, 0); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4051 | break; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4052 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4053 | if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED || |
| 4054 | lpfc_cmd->result == IOERR_TX_DMA_FAILED) && |
| 4055 | pIocbOut->iocb.unsli3.sli3_bg.bgstat) { |
| 4056 | if (scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) { |
| 4057 | /* |
| 4058 | * This is a response for a BG enabled |
| 4059 | * cmd. Parse BG error |
| 4060 | */ |
| 4061 | lpfc_parse_bg_err(phba, lpfc_cmd, |
| 4062 | pIocbOut); |
| 4063 | break; |
| 4064 | } else { |
| 4065 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 4066 | LOG_BG, |
| 4067 | "9031 non-zero BGSTAT " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4068 | "on unprotected cmd\n"); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4069 | } |
| 4070 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4071 | if ((lpfc_cmd->status == IOSTAT_REMOTE_STOP) |
| 4072 | && (phba->sli_rev == LPFC_SLI_REV4) |
| 4073 | && (pnode && NLP_CHK_NODE_ACT(pnode))) { |
| 4074 | /* This IO was aborted by the target, we don't |
| 4075 | * know the rxid and because we did not send the |
| 4076 | * ABTS we cannot generate and RRQ. |
| 4077 | */ |
| 4078 | lpfc_set_rrq_active(phba, pnode, |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 4079 | lpfc_cmd->cur_iocbq.sli4_lxritag, |
| 4080 | 0, 0); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4081 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4082 | /* else: fall through */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4083 | default: |
| 4084 | cmd->result = ScsiResult(DID_ERROR, 0); |
| 4085 | break; |
| 4086 | } |
| 4087 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4088 | if (!pnode || !NLP_CHK_NODE_ACT(pnode) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4089 | || (pnode->nlp_state != NLP_STE_MAPPED_NODE)) |
James Smart | 0f1f53a | 2008-08-24 21:50:18 -0400 | [diff] [blame] | 4090 | cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, |
| 4091 | SAM_STAT_BUSY); |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 4092 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4093 | cmd->result = ScsiResult(DID_OK, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4094 | |
| 4095 | if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) { |
| 4096 | uint32_t *lp = (uint32_t *)cmd->sense_buffer; |
| 4097 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4098 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4099 | "0710 Iodone <%d/%llu> cmd %p, error " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4100 | "x%x SNS x%x x%x Data: x%x x%x\n", |
| 4101 | cmd->device->id, cmd->device->lun, cmd, |
| 4102 | cmd->result, *lp, *(lp + 3), cmd->retries, |
| 4103 | scsi_get_resid(cmd)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4104 | } |
| 4105 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4106 | lpfc_update_stats(phba, lpfc_cmd); |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4107 | if (vport->cfg_max_scsicmpl_time && |
| 4108 | time_after(jiffies, lpfc_cmd->start_time + |
| 4109 | msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4110 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4111 | if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
| 4112 | if (pnode->cmd_qdepth > |
| 4113 | atomic_read(&pnode->cmd_pending) && |
| 4114 | (atomic_read(&pnode->cmd_pending) > |
| 4115 | LPFC_MIN_TGT_QDEPTH) && |
| 4116 | ((cmd->cmnd[0] == READ_10) || |
| 4117 | (cmd->cmnd[0] == WRITE_10))) |
| 4118 | pnode->cmd_qdepth = |
| 4119 | atomic_read(&pnode->cmd_pending); |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4120 | |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4121 | pnode->last_change_time = jiffies; |
| 4122 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4123 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4124 | } else if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 4125 | if ((pnode->cmd_qdepth < vport->cfg_tgt_queue_depth) && |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4126 | time_after(jiffies, pnode->last_change_time + |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4127 | msecs_to_jiffies(LPFC_TGTQ_INTERVAL))) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4128 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 4129 | depth = pnode->cmd_qdepth * LPFC_TGTQ_RAMPUP_PCENT |
| 4130 | / 100; |
| 4131 | depth = depth ? depth : 1; |
| 4132 | pnode->cmd_qdepth += depth; |
| 4133 | if (pnode->cmd_qdepth > vport->cfg_tgt_queue_depth) |
| 4134 | pnode->cmd_qdepth = vport->cfg_tgt_queue_depth; |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4135 | pnode->last_change_time = jiffies; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4136 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | 109f6ed | 2008-12-04 22:39:08 -0500 | [diff] [blame] | 4137 | } |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4138 | } |
| 4139 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4140 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4141 | |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4142 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92e3af6 | 2012-08-14 14:26:28 -0400 | [diff] [blame] | 4143 | lpfc_cmd->pCmd = NULL; |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4144 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92e3af6 | 2012-08-14 14:26:28 -0400 | [diff] [blame] | 4145 | |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 4146 | /* The sdev is not guaranteed to be valid post scsi_done upcall. */ |
| 4147 | cmd->scsi_done(cmd); |
| 4148 | |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4149 | /* |
| 4150 | * If there is a thread waiting for command completion |
| 4151 | * wake up the thread. |
| 4152 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4153 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4154 | if (lpfc_cmd->waitq) |
| 4155 | wake_up(lpfc_cmd->waitq); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4156 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4157 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4158 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4159 | } |
| 4160 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4161 | /** |
Alexey Kardashevskiy | 8b2564e | 2015-04-28 18:26:22 +1000 | [diff] [blame] | 4162 | * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB |
| 4163 | * @data: A pointer to the immediate command data portion of the IOCB. |
| 4164 | * @fcp_cmnd: The FCP Command that is provided by the SCSI layer. |
| 4165 | * |
| 4166 | * The routine copies the entire FCP command from @fcp_cmnd to @data while |
| 4167 | * byte swapping the data to big endian format for transmission on the wire. |
| 4168 | **/ |
| 4169 | static void |
| 4170 | lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd) |
| 4171 | { |
| 4172 | int i, j; |
| 4173 | for (i = 0, j = 0; i < sizeof(struct fcp_cmnd); |
| 4174 | i += sizeof(uint32_t), j++) { |
| 4175 | ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]); |
| 4176 | } |
| 4177 | } |
| 4178 | |
| 4179 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4180 | * 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] | 4181 | * @vport: The virtual port for which this call is being executed. |
| 4182 | * @lpfc_cmd: The scsi command which needs to send. |
| 4183 | * @pnode: Pointer to lpfc_nodelist. |
| 4184 | * |
| 4185 | * This routine initializes fcp_cmnd and iocb data structure from scsi command |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4186 | * to transfer for device with SLI3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4187 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4188 | static void |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4189 | 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] | 4190 | struct lpfc_nodelist *pnode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4191 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4192 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4193 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
| 4194 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 4195 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
| 4196 | struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq); |
| 4197 | int datadir = scsi_cmnd->sc_data_direction; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4198 | uint8_t *ptr; |
| 4199 | bool sli4; |
James Smart | 98bbf5f | 2013-09-06 12:18:45 -0400 | [diff] [blame] | 4200 | uint32_t fcpdl; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4201 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4202 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 4203 | return; |
| 4204 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4205 | lpfc_cmd->fcp_rsp->rspSnsLen = 0; |
James.Smart@Emulex.Com | 69859dc | 2005-08-10 15:02:37 -0400 | [diff] [blame] | 4206 | /* clear task management bits */ |
| 4207 | lpfc_cmd->fcp_cmnd->fcpCntl2 = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4208 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 4209 | int_to_scsilun(lpfc_cmd->pCmd->device->lun, |
| 4210 | &lpfc_cmd->fcp_cmnd->fcp_lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4211 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4212 | ptr = &fcp_cmnd->fcpCdb[0]; |
| 4213 | memcpy(ptr, scsi_cmnd->cmnd, scsi_cmnd->cmd_len); |
| 4214 | if (scsi_cmnd->cmd_len < LPFC_FCP_CDB_LEN) { |
| 4215 | ptr += scsi_cmnd->cmd_len; |
| 4216 | memset(ptr, 0, (LPFC_FCP_CDB_LEN - scsi_cmnd->cmd_len)); |
| 4217 | } |
| 4218 | |
Christoph Hellwig | 5066863 | 2014-10-30 14:30:06 +0100 | [diff] [blame] | 4219 | fcp_cmnd->fcpCntl1 = SIMPLE_Q; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4220 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4221 | sli4 = (phba->sli_rev == LPFC_SLI_REV4); |
James Smart | 6acb348 | 2014-04-04 13:51:25 -0400 | [diff] [blame] | 4222 | piocbq->iocb.un.fcpi.fcpi_XRdy = 0; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4223 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4224 | /* |
| 4225 | * There are three possibilities here - use scatter-gather segment, use |
| 4226 | * the single mapping, or neither. Start the lpfc command prep by |
| 4227 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first |
| 4228 | * data bde entry. |
| 4229 | */ |
FUJITA Tomonori | a0b4f78 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4230 | if (scsi_sg_count(scsi_cmnd)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4231 | if (datadir == DMA_TO_DEVICE) { |
| 4232 | iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR; |
James Smart | 182ba75 | 2013-07-15 18:34:05 -0400 | [diff] [blame] | 4233 | iocb_cmd->ulpPU = PARM_READ_CHECK; |
James Smart | 3cb01c5 | 2013-07-15 18:35:04 -0400 | [diff] [blame] | 4234 | if (vport->cfg_first_burst_size && |
| 4235 | (pnode->nlp_flag & NLP_FIRSTBURST)) { |
James Smart | 98bbf5f | 2013-09-06 12:18:45 -0400 | [diff] [blame] | 4236 | fcpdl = scsi_bufflen(scsi_cmnd); |
| 4237 | if (fcpdl < vport->cfg_first_burst_size) |
| 4238 | piocbq->iocb.un.fcpi.fcpi_XRdy = fcpdl; |
| 4239 | else |
| 4240 | piocbq->iocb.un.fcpi.fcpi_XRdy = |
| 4241 | vport->cfg_first_burst_size; |
James Smart | 3cb01c5 | 2013-07-15 18:35:04 -0400 | [diff] [blame] | 4242 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4243 | fcp_cmnd->fcpCntl3 = WRITE_DATA; |
| 4244 | phba->fc4OutputRequests++; |
| 4245 | } else { |
| 4246 | iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR; |
| 4247 | iocb_cmd->ulpPU = PARM_READ_CHECK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4248 | fcp_cmnd->fcpCntl3 = READ_DATA; |
| 4249 | phba->fc4InputRequests++; |
| 4250 | } |
| 4251 | } else { |
| 4252 | iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR; |
| 4253 | iocb_cmd->un.fcpi.fcpi_parm = 0; |
| 4254 | iocb_cmd->ulpPU = 0; |
| 4255 | fcp_cmnd->fcpCntl3 = 0; |
| 4256 | phba->fc4ControlRequests++; |
| 4257 | } |
Alexey Kardashevskiy | 8b2564e | 2015-04-28 18:26:22 +1000 | [diff] [blame] | 4258 | if (phba->sli_rev == 3 && |
| 4259 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) |
| 4260 | lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4261 | /* |
| 4262 | * Finish initializing those IOCB fields that are independent |
| 4263 | * of the scsi_cmnd request_buffer |
| 4264 | */ |
| 4265 | piocbq->iocb.ulpContext = pnode->nlp_rpi; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 4266 | if (sli4) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4267 | piocbq->iocb.ulpContext = |
| 4268 | phba->sli4_hba.rpi_ids[pnode->nlp_rpi]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4269 | if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE) |
| 4270 | piocbq->iocb.ulpFCP2Rcvy = 1; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4271 | else |
| 4272 | piocbq->iocb.ulpFCP2Rcvy = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4273 | |
| 4274 | piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f); |
| 4275 | piocbq->context1 = lpfc_cmd; |
| 4276 | piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; |
| 4277 | piocbq->iocb.ulpTimeout = lpfc_cmd->timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4278 | piocbq->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4279 | } |
| 4280 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4281 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4282 | * 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] | 4283 | * @vport: The virtual port for which this call is being executed. |
| 4284 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. |
| 4285 | * @lun: Logical unit number. |
| 4286 | * @task_mgmt_cmd: SCSI task management command. |
| 4287 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4288 | * This routine creates FCP information unit corresponding to @task_mgmt_cmd |
| 4289 | * for device with SLI-3 interface spec. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4290 | * |
| 4291 | * Return codes: |
| 4292 | * 0 - Error |
| 4293 | * 1 - Success |
| 4294 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4295 | static int |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4296 | lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4297 | struct lpfc_scsi_buf *lpfc_cmd, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4298 | uint64_t lun, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4299 | uint8_t task_mgmt_cmd) |
| 4300 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4301 | struct lpfc_iocbq *piocbq; |
| 4302 | IOCB_t *piocb; |
| 4303 | struct fcp_cmnd *fcp_cmnd; |
James Smart | 0b18ac4 | 2006-05-01 21:50:40 -0400 | [diff] [blame] | 4304 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4305 | struct lpfc_nodelist *ndlp = rdata->pnode; |
| 4306 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4307 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || |
| 4308 | ndlp->nlp_state != NLP_STE_MAPPED_NODE) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4309 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4310 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4311 | piocbq = &(lpfc_cmd->cur_iocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4312 | piocbq->vport = vport; |
| 4313 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4314 | piocb = &piocbq->iocb; |
| 4315 | |
| 4316 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4317 | /* Clear out any old data in the FCP command area */ |
| 4318 | memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd)); |
| 4319 | int_to_scsilun(lun, &fcp_cmnd->fcp_lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4320 | fcp_cmnd->fcpCntl2 = task_mgmt_cmd; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4321 | if (vport->phba->sli_rev == 3 && |
| 4322 | !(vport->phba->sli3_options & LPFC_SLI3_BG_ENABLED)) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4323 | lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4324 | piocb->ulpCommand = CMD_FCP_ICMND64_CR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4325 | piocb->ulpContext = ndlp->nlp_rpi; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4326 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
| 4327 | piocb->ulpContext = |
| 4328 | vport->phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
| 4329 | } |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 4330 | piocb->ulpFCP2Rcvy = (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) ? 1 : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4331 | piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f); |
James Smart | f9226c2 | 2014-02-20 09:57:28 -0500 | [diff] [blame] | 4332 | piocb->ulpPU = 0; |
| 4333 | piocb->un.fcpi.fcpi_parm = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4334 | |
| 4335 | /* ulpTimeout is only one byte */ |
| 4336 | if (lpfc_cmd->timeout > 0xff) { |
| 4337 | /* |
| 4338 | * Do not timeout the command at the firmware level. |
| 4339 | * The driver will provide the timeout mechanism. |
| 4340 | */ |
| 4341 | piocb->ulpTimeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4342 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4343 | piocb->ulpTimeout = lpfc_cmd->timeout; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4344 | |
| 4345 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 4346 | lpfc_sli4_set_rsp_sgl_last(vport->phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4347 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4348 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4349 | } |
| 4350 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4351 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4352 | * lpfc_scsi_api_table_setup - Set up scsi api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4353 | * @phba: The hba struct for which this call is being executed. |
| 4354 | * @dev_grp: The HBA PCI-Device group number. |
| 4355 | * |
| 4356 | * This routine sets up the SCSI interface API function jump table in @phba |
| 4357 | * struct. |
| 4358 | * Returns: 0 - success, -ENODEV - failure. |
| 4359 | **/ |
| 4360 | int |
| 4361 | lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 4362 | { |
| 4363 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4364 | phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf; |
| 4365 | phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 4366 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4367 | switch (dev_grp) { |
| 4368 | case LPFC_PCI_DEV_LP: |
| 4369 | phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s3; |
| 4370 | phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4371 | 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] | 4372 | phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4373 | phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s3; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4374 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4375 | case LPFC_PCI_DEV_OC: |
| 4376 | phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s4; |
| 4377 | phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s4; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4378 | 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] | 4379 | phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s4; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4380 | phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s4; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4381 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4382 | default: |
| 4383 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4384 | "1418 Invalid HBA PCI-device group: 0x%x\n", |
| 4385 | dev_grp); |
| 4386 | return -ENODEV; |
| 4387 | break; |
| 4388 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4389 | phba->lpfc_rampdown_queue_depth = lpfc_rampdown_queue_depth; |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 4390 | phba->lpfc_scsi_cmd_iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4391 | return 0; |
| 4392 | } |
| 4393 | |
| 4394 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4395 | * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4396 | * @phba: The Hba for which this call is being executed. |
| 4397 | * @cmdiocbq: Pointer to lpfc_iocbq data structure. |
| 4398 | * @rspiocbq: Pointer to lpfc_iocbq data structure. |
| 4399 | * |
| 4400 | * This routine is IOCB completion routine for device reset and target reset |
| 4401 | * routine. This routine release scsi buffer associated with lpfc_cmd. |
| 4402 | **/ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4403 | static void |
| 4404 | lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba, |
| 4405 | struct lpfc_iocbq *cmdiocbq, |
| 4406 | struct lpfc_iocbq *rspiocbq) |
| 4407 | { |
| 4408 | struct lpfc_scsi_buf *lpfc_cmd = |
| 4409 | (struct lpfc_scsi_buf *) cmdiocbq->context1; |
| 4410 | if (lpfc_cmd) |
| 4411 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 4412 | return; |
| 4413 | } |
| 4414 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4415 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4416 | * lpfc_info - Info entry point of scsi_host_template data structure |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4417 | * @host: The scsi host for which this call is being executed. |
| 4418 | * |
| 4419 | * This routine provides module information about hba. |
| 4420 | * |
| 4421 | * Reutrn code: |
| 4422 | * Pointer to char - Success. |
| 4423 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4424 | const char * |
| 4425 | lpfc_info(struct Scsi_Host *host) |
| 4426 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4427 | struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata; |
| 4428 | struct lpfc_hba *phba = vport->phba; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4429 | int len, link_speed = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4430 | static char lpfcinfobuf[384]; |
| 4431 | |
| 4432 | memset(lpfcinfobuf,0,384); |
| 4433 | if (phba && phba->pcidev){ |
| 4434 | strncpy(lpfcinfobuf, phba->ModelDesc, 256); |
| 4435 | len = strlen(lpfcinfobuf); |
| 4436 | snprintf(lpfcinfobuf + len, |
| 4437 | 384-len, |
| 4438 | " on PCI bus %02x device %02x irq %d", |
| 4439 | phba->pcidev->bus->number, |
| 4440 | phba->pcidev->devfn, |
| 4441 | phba->pcidev->irq); |
| 4442 | len = strlen(lpfcinfobuf); |
| 4443 | if (phba->Port[0]) { |
| 4444 | snprintf(lpfcinfobuf + len, |
| 4445 | 384-len, |
| 4446 | " port %s", |
| 4447 | phba->Port); |
| 4448 | } |
James Smart | 65467b6 | 2010-01-26 23:08:29 -0500 | [diff] [blame] | 4449 | len = strlen(lpfcinfobuf); |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 4450 | link_speed = lpfc_sli_port_speed_get(phba); |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4451 | if (link_speed != 0) |
| 4452 | snprintf(lpfcinfobuf + len, 384-len, |
| 4453 | " Logical Link Speed: %d Mbps", link_speed); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4454 | } |
| 4455 | return lpfcinfobuf; |
| 4456 | } |
| 4457 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4458 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4459 | * lpfc_poll_rearm_time - Routine to modify fcp_poll timer of hba |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4460 | * @phba: The Hba for which this call is being executed. |
| 4461 | * |
| 4462 | * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo. |
| 4463 | * The default value of cfg_poll_tmo is 10 milliseconds. |
| 4464 | **/ |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4465 | static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba) |
| 4466 | { |
| 4467 | unsigned long poll_tmo_expires = |
| 4468 | (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo)); |
| 4469 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 4470 | if (!list_empty(&phba->sli.ring[LPFC_FCP_RING].txcmplq)) |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4471 | mod_timer(&phba->fcp_poll_timer, |
| 4472 | poll_tmo_expires); |
| 4473 | } |
| 4474 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4475 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4476 | * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4477 | * @phba: The Hba for which this call is being executed. |
| 4478 | * |
| 4479 | * This routine starts the fcp_poll_timer of @phba. |
| 4480 | **/ |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4481 | void lpfc_poll_start_timer(struct lpfc_hba * phba) |
| 4482 | { |
| 4483 | lpfc_poll_rearm_timer(phba); |
| 4484 | } |
| 4485 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4486 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4487 | * lpfc_poll_timeout - Restart polling timer |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4488 | * @ptr: Map to lpfc_hba data structure pointer. |
| 4489 | * |
| 4490 | * This routine restarts fcp_poll timer, when FCP ring polling is enable |
| 4491 | * and FCP Ring interrupt is disable. |
| 4492 | **/ |
| 4493 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4494 | void lpfc_poll_timeout(unsigned long ptr) |
| 4495 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4496 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4497 | |
| 4498 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4499 | lpfc_sli_handle_fast_ring_event(phba, |
| 4500 | &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ); |
| 4501 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4502 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 4503 | lpfc_poll_rearm_timer(phba); |
| 4504 | } |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4505 | } |
| 4506 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4507 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4508 | * lpfc_queuecommand - scsi_host_template queuecommand entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4509 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 4510 | * @done: Pointer to done routine. |
| 4511 | * |
| 4512 | * Driver registers this routine to scsi midlayer to submit a @cmd to process. |
| 4513 | * This routine prepares an IOCB from scsi command and provides to firmware. |
| 4514 | * The @done callback is invoked after driver finished processing the command. |
| 4515 | * |
| 4516 | * Return value : |
| 4517 | * 0 - Success |
| 4518 | * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily. |
| 4519 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4520 | static int |
James Smart | b9a7c63 | 2012-08-03 12:35:24 -0400 | [diff] [blame] | 4521 | lpfc_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4522 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4523 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4524 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 4525 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 4526 | struct lpfc_nodelist *ndlp; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4527 | struct lpfc_scsi_buf *lpfc_cmd; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4528 | 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] | 4529 | int err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4530 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 4531 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4532 | err = fc_remote_port_chkready(rport); |
| 4533 | if (err) { |
| 4534 | cmnd->result = err; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4535 | goto out_fail_command; |
| 4536 | } |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 4537 | ndlp = rdata->pnode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4538 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 4539 | if ((scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) && |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4540 | (!(phba->sli3_options & LPFC_SLI3_BG_ENABLED))) { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4541 | |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4542 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 4543 | "9058 BLKGRD: ERROR: rcvd protected cmd:%02x" |
| 4544 | " op:%02x str=%s without registering for" |
| 4545 | " BlockGuard - Rejecting command\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4546 | cmnd->cmnd[0], scsi_get_prot_op(cmnd), |
| 4547 | dif_op_str[scsi_get_prot_op(cmnd)]); |
| 4548 | goto out_fail_command; |
| 4549 | } |
| 4550 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4551 | /* |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4552 | * Catch race where our node has transitioned, but the |
| 4553 | * transport is still transitioning. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4554 | */ |
James Smart | 6b415f5 | 2012-06-12 13:54:59 -0400 | [diff] [blame] | 4555 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 4556 | goto out_tgt_busy; |
James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 4557 | if (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth) |
Mike Christie | 3496343 | 2011-02-25 14:04:28 -0600 | [diff] [blame] | 4558 | goto out_tgt_busy; |
Mike Christie | a93ce02 | 2008-08-17 15:24:41 -0500 | [diff] [blame] | 4559 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4560 | lpfc_cmd = lpfc_get_scsi_buf(phba, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4561 | if (lpfc_cmd == NULL) { |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4562 | lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4563 | |
James Smart | f911462 | 2015-05-21 13:55:30 -0400 | [diff] [blame] | 4564 | lpfc_printf_vlog(vport, KERN_INFO, LOG_MISC, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4565 | "0707 driver's buffer pool is empty, " |
| 4566 | "IO busied\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4567 | goto out_host_busy; |
| 4568 | } |
| 4569 | |
| 4570 | /* |
| 4571 | * Store the midlayer's command structure for the completion phase |
| 4572 | * and complete the command initialization. |
| 4573 | */ |
| 4574 | lpfc_cmd->pCmd = cmnd; |
| 4575 | lpfc_cmd->rdata = rdata; |
| 4576 | lpfc_cmd->timeout = 0; |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4577 | lpfc_cmd->start_time = jiffies; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4578 | cmnd->host_scribble = (unsigned char *)lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4579 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4580 | if (scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4581 | if (vport->phba->cfg_enable_bg) { |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 4582 | lpfc_printf_vlog(vport, |
| 4583 | KERN_INFO, LOG_SCSI_CMD, |
James Smart | 2613470 | 2012-08-14 14:25:50 -0400 | [diff] [blame] | 4584 | "9033 BLKGRD: rcvd %s cmd:x%x " |
| 4585 | "sector x%llx cnt %u pt %x\n", |
| 4586 | dif_op_str[scsi_get_prot_op(cmnd)], |
| 4587 | cmnd->cmnd[0], |
| 4588 | (unsigned long long)scsi_get_lba(cmnd), |
| 4589 | blk_rq_sectors(cmnd->request), |
| 4590 | (cmnd->cmnd[1]>>5)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4591 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4592 | err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 4593 | } else { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4594 | if (vport->phba->cfg_enable_bg) { |
James Smart | 737d424 | 2013-04-17 20:14:49 -0400 | [diff] [blame] | 4595 | lpfc_printf_vlog(vport, |
| 4596 | KERN_INFO, LOG_SCSI_CMD, |
James Smart | 2613470 | 2012-08-14 14:25:50 -0400 | [diff] [blame] | 4597 | "9038 BLKGRD: rcvd PROT_NORMAL cmd: " |
| 4598 | "x%x sector x%llx cnt %u pt %x\n", |
| 4599 | cmnd->cmnd[0], |
| 4600 | (unsigned long long)scsi_get_lba(cmnd), |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 4601 | blk_rq_sectors(cmnd->request), |
James Smart | 2613470 | 2012-08-14 14:25:50 -0400 | [diff] [blame] | 4602 | (cmnd->cmnd[1]>>5)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 4603 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4604 | err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); |
| 4605 | } |
| 4606 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4607 | if (err) |
| 4608 | goto out_host_busy_free_buf; |
| 4609 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4610 | lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4611 | |
James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4612 | atomic_inc(&ndlp->cmd_pending); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4613 | err = lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4614 | &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4615 | if (err) { |
| 4616 | atomic_dec(&ndlp->cmd_pending); |
James Smart | 76f96b6 | 2013-12-17 20:29:01 -0500 | [diff] [blame] | 4617 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4618 | "3376 FCP could not issue IOCB err %x" |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4619 | "FCP cmd x%x <%d/%llu> " |
James Smart | 76f96b6 | 2013-12-17 20:29:01 -0500 | [diff] [blame] | 4620 | "sid: x%x did: x%x oxid: x%x " |
| 4621 | "Data: x%x x%x x%x x%x\n", |
| 4622 | err, cmnd->cmnd[0], |
| 4623 | cmnd->device ? cmnd->device->id : 0xffff, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4624 | cmnd->device ? cmnd->device->lun : (u64) -1, |
James Smart | 76f96b6 | 2013-12-17 20:29:01 -0500 | [diff] [blame] | 4625 | vport->fc_myDID, ndlp->nlp_DID, |
| 4626 | phba->sli_rev == LPFC_SLI_REV4 ? |
| 4627 | lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff, |
| 4628 | lpfc_cmd->cur_iocbq.iocb.ulpContext, |
| 4629 | lpfc_cmd->cur_iocbq.iocb.ulpIoTag, |
| 4630 | lpfc_cmd->cur_iocbq.iocb.ulpTimeout, |
| 4631 | (uint32_t) |
| 4632 | (cmnd->request->timeout / 1000)); |
| 4633 | |
| 4634 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4635 | goto out_host_busy_free_buf; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4636 | } |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4637 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4638 | lpfc_sli_handle_fast_ring_event(phba, |
| 4639 | &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ); |
| 4640 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4641 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 4642 | lpfc_poll_rearm_timer(phba); |
| 4643 | } |
| 4644 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4645 | return 0; |
| 4646 | |
| 4647 | out_host_busy_free_buf: |
James Smart | bcf4dbf | 2006-07-06 15:50:08 -0400 | [diff] [blame] | 4648 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4649 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4650 | out_host_busy: |
| 4651 | return SCSI_MLQUEUE_HOST_BUSY; |
| 4652 | |
Mike Christie | 3496343 | 2011-02-25 14:04:28 -0600 | [diff] [blame] | 4653 | out_tgt_busy: |
| 4654 | return SCSI_MLQUEUE_TARGET_BUSY; |
| 4655 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4656 | out_fail_command: |
James Smart | b9a7c63 | 2012-08-03 12:35:24 -0400 | [diff] [blame] | 4657 | cmnd->scsi_done(cmnd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4658 | return 0; |
| 4659 | } |
| 4660 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 4661 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4662 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4663 | * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 4664 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 4665 | * |
| 4666 | * This routine aborts @cmnd pending in base driver. |
| 4667 | * |
| 4668 | * Return code : |
| 4669 | * 0x2003 - Error |
| 4670 | * 0x2002 - Success |
| 4671 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4672 | static int |
James.Smart@Emulex.Com | 63c59c3 | 2005-11-28 11:41:53 -0500 | [diff] [blame] | 4673 | lpfc_abort_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4674 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4675 | struct Scsi_Host *shost = cmnd->device->host; |
| 4676 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4677 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4678 | struct lpfc_iocbq *iocb; |
| 4679 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4680 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4681 | IOCB_t *cmd, *icmd; |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4682 | int ret = SUCCESS, status = 0; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4683 | struct lpfc_sli_ring *pring_s4; |
| 4684 | int ring_number, ret_val; |
| 4685 | unsigned long flags, iflags; |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4686 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4687 | |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4688 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 4689 | if (status != 0 && status != SUCCESS) |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4690 | return status; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4691 | |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4692 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4693 | /* driver queued commands are in process of being flushed */ |
| 4694 | if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) { |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4695 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4696 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4697 | "3168 SCSI Layer abort requested I/O has been " |
| 4698 | "flushed by LLD.\n"); |
| 4699 | return FAILED; |
| 4700 | } |
| 4701 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4702 | lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble; |
James Smart | 92e3af6 | 2012-08-14 14:26:28 -0400 | [diff] [blame] | 4703 | if (!lpfc_cmd || !lpfc_cmd->pCmd) { |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4704 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 4705 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4706 | "2873 SCSI Layer I/O Abort Request IO CMPL Status " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4707 | "x%x ID %d LUN %llu\n", |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 4708 | SUCCESS, cmnd->device->id, cmnd->device->lun); |
James Smart | eee8877 | 2010-09-29 11:19:08 -0400 | [diff] [blame] | 4709 | return SUCCESS; |
| 4710 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4711 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4712 | iocb = &lpfc_cmd->cur_iocbq; |
| 4713 | /* the command is in process of being cancelled */ |
| 4714 | if (!(iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ)) { |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4715 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4716 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4717 | "3169 SCSI Layer abort requested I/O has been " |
| 4718 | "cancelled by LLD.\n"); |
| 4719 | return FAILED; |
| 4720 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4721 | /* |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4722 | * If pCmd field of the corresponding lpfc_scsi_buf structure |
| 4723 | * points to a different SCSI command, then the driver has |
| 4724 | * already completed this command, but the midlayer did not |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4725 | * see the completion before the eh fired. Just return SUCCESS. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4726 | */ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4727 | if (lpfc_cmd->pCmd != cmnd) { |
| 4728 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4729 | "3170 SCSI Layer abort requested I/O has been " |
| 4730 | "completed by LLD.\n"); |
| 4731 | goto out_unlock; |
| 4732 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4733 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4734 | BUG_ON(iocb->context1 != lpfc_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4735 | |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4736 | /* abort issued in recovery is still in progress */ |
| 4737 | if (iocb->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 4738 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4739 | "3389 SCSI Layer I/O Abort Request is pending\n"); |
| 4740 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4741 | goto wait_for_cmpl; |
| 4742 | } |
| 4743 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4744 | abtsiocb = __lpfc_sli_get_iocbq(phba); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4745 | if (abtsiocb == NULL) { |
| 4746 | ret = FAILED; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4747 | goto out_unlock; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4748 | } |
| 4749 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 4750 | /* Indicate the IO is being aborted by the driver. */ |
| 4751 | iocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 4752 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4753 | /* |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4754 | * The scsi command can not be in txq and it is in flight because the |
| 4755 | * pCmd is still pointig at the SCSI command we have to abort. There |
| 4756 | * is no need to search the txcmplq. Just send an abort to the FW. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4757 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4758 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4759 | cmd = &iocb->iocb; |
| 4760 | icmd = &abtsiocb->iocb; |
| 4761 | icmd->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 4762 | icmd->un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4763 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4764 | icmd->un.acxri.abortIoTag = iocb->sli4_xritag; |
| 4765 | else |
| 4766 | icmd->un.acxri.abortIoTag = cmd->ulpIoTag; |
| 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 | icmd->ulpLe = 1; |
| 4769 | icmd->ulpClass = cmd->ulpClass; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4770 | |
| 4771 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 4772 | abtsiocb->fcp_wqidx = iocb->fcp_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 4773 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 4774 | if (iocb->iocb_flag & LPFC_IO_FOF) |
| 4775 | abtsiocb->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4776 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4777 | if (lpfc_is_link_up(phba)) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4778 | icmd->ulpCommand = CMD_ABORT_XRI_CN; |
| 4779 | else |
| 4780 | icmd->ulpCommand = CMD_CLOSE_XRI_CN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4781 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4782 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4783 | abtsiocb->vport = vport; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4784 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 4785 | ring_number = MAX_SLI3_CONFIGURED_RINGS + iocb->fcp_wqidx; |
| 4786 | pring_s4 = &phba->sli.ring[ring_number]; |
| 4787 | /* Note: both hbalock and ring_lock must be set here */ |
| 4788 | spin_lock_irqsave(&pring_s4->ring_lock, iflags); |
| 4789 | ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 4790 | abtsiocb, 0); |
| 4791 | spin_unlock_irqrestore(&pring_s4->ring_lock, iflags); |
| 4792 | } else { |
| 4793 | ret_val = __lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, |
| 4794 | abtsiocb, 0); |
| 4795 | } |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4796 | /* no longer need the lock after this point */ |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4797 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4798 | |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 4799 | |
| 4800 | if (ret_val == IOCB_ERROR) { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4801 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| 4802 | ret = FAILED; |
| 4803 | goto out; |
| 4804 | } |
| 4805 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4806 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4807 | lpfc_sli_handle_fast_ring_event(phba, |
| 4808 | &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4809 | |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4810 | wait_for_cmpl: |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4811 | lpfc_cmd->waitq = &waitq; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4812 | /* Wait for abort to complete */ |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4813 | wait_event_timeout(waitq, |
| 4814 | (lpfc_cmd->pCmd != cmnd), |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4815 | msecs_to_jiffies(2*vport->cfg_devloss_tmo*1000)); |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4816 | |
| 4817 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | fa61a54 | 2008-01-11 01:52:42 -0500 | [diff] [blame] | 4818 | lpfc_cmd->waitq = NULL; |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4819 | spin_unlock_irqrestore(shost->host_lock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4820 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4821 | if (lpfc_cmd->pCmd == cmnd) { |
| 4822 | ret = FAILED; |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4823 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 4824 | "0748 abort handler timed out waiting " |
Milan P. Gandhi | 4b160ae | 2016-10-13 15:06:02 -0700 | [diff] [blame] | 4825 | "for aborting I/O (xri:x%x) to complete: " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4826 | "ret %#x, ID %d, LUN %llu\n", |
James Smart | 247ca94 | 2012-08-14 14:26:13 -0400 | [diff] [blame] | 4827 | iocb->sli4_xritag, ret, |
| 4828 | cmnd->device->id, cmnd->device->lun); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4829 | } |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4830 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4831 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4832 | out_unlock: |
James Smart | 876dd7d | 2012-09-29 11:31:28 -0400 | [diff] [blame] | 4833 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4834 | out: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4835 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 4836 | "0749 SCSI Layer I/O Abort Request Status x%x ID %d " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4837 | "LUN %llu\n", ret, cmnd->device->id, |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 4838 | cmnd->device->lun); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4839 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4840 | } |
| 4841 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4842 | static char * |
| 4843 | lpfc_taskmgmt_name(uint8_t task_mgmt_cmd) |
| 4844 | { |
| 4845 | switch (task_mgmt_cmd) { |
| 4846 | case FCP_ABORT_TASK_SET: |
| 4847 | return "ABORT_TASK_SET"; |
| 4848 | case FCP_CLEAR_TASK_SET: |
| 4849 | return "FCP_CLEAR_TASK_SET"; |
| 4850 | case FCP_BUS_RESET: |
| 4851 | return "FCP_BUS_RESET"; |
| 4852 | case FCP_LUN_RESET: |
| 4853 | return "FCP_LUN_RESET"; |
| 4854 | case FCP_TARGET_RESET: |
| 4855 | return "FCP_TARGET_RESET"; |
| 4856 | case FCP_CLEAR_ACA: |
| 4857 | return "FCP_CLEAR_ACA"; |
| 4858 | case FCP_TERMINATE_TASK: |
| 4859 | return "FCP_TERMINATE_TASK"; |
| 4860 | default: |
| 4861 | return "unknown"; |
| 4862 | } |
| 4863 | } |
| 4864 | |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 4865 | |
| 4866 | /** |
| 4867 | * lpfc_check_fcp_rsp - check the returned fcp_rsp to see if task failed |
| 4868 | * @vport: The virtual port for which this call is being executed. |
| 4869 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. |
| 4870 | * |
| 4871 | * This routine checks the FCP RSP INFO to see if the tsk mgmt command succeded |
| 4872 | * |
| 4873 | * Return code : |
| 4874 | * 0x2003 - Error |
| 4875 | * 0x2002 - Success |
| 4876 | **/ |
| 4877 | static int |
| 4878 | lpfc_check_fcp_rsp(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd) |
| 4879 | { |
| 4880 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; |
| 4881 | uint32_t rsp_info; |
| 4882 | uint32_t rsp_len; |
| 4883 | uint8_t rsp_info_code; |
| 4884 | int ret = FAILED; |
| 4885 | |
| 4886 | |
| 4887 | if (fcprsp == NULL) |
| 4888 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4889 | "0703 fcp_rsp is missing\n"); |
| 4890 | else { |
| 4891 | rsp_info = fcprsp->rspStatus2; |
| 4892 | rsp_len = be32_to_cpu(fcprsp->rspRspLen); |
| 4893 | rsp_info_code = fcprsp->rspInfo3; |
| 4894 | |
| 4895 | |
| 4896 | lpfc_printf_vlog(vport, KERN_INFO, |
| 4897 | LOG_FCP, |
| 4898 | "0706 fcp_rsp valid 0x%x," |
| 4899 | " rsp len=%d code 0x%x\n", |
| 4900 | rsp_info, |
| 4901 | rsp_len, rsp_info_code); |
| 4902 | |
| 4903 | if ((fcprsp->rspStatus2&RSP_LEN_VALID) && (rsp_len == 8)) { |
| 4904 | switch (rsp_info_code) { |
| 4905 | case RSP_NO_FAILURE: |
| 4906 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4907 | "0715 Task Mgmt No Failure\n"); |
| 4908 | ret = SUCCESS; |
| 4909 | break; |
| 4910 | case RSP_TM_NOT_SUPPORTED: /* TM rejected */ |
| 4911 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4912 | "0716 Task Mgmt Target " |
| 4913 | "reject\n"); |
| 4914 | break; |
| 4915 | case RSP_TM_NOT_COMPLETED: /* TM failed */ |
| 4916 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4917 | "0717 Task Mgmt Target " |
| 4918 | "failed TM\n"); |
| 4919 | break; |
| 4920 | case RSP_TM_INVALID_LU: /* TM to invalid LU! */ |
| 4921 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 4922 | "0718 Task Mgmt to invalid " |
| 4923 | "LUN\n"); |
| 4924 | break; |
| 4925 | } |
| 4926 | } |
| 4927 | } |
| 4928 | return ret; |
| 4929 | } |
| 4930 | |
| 4931 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4932 | /** |
| 4933 | * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler |
| 4934 | * @vport: The virtual port for which this call is being executed. |
| 4935 | * @rdata: Pointer to remote port local data |
| 4936 | * @tgt_id: Target ID of remote device. |
| 4937 | * @lun_id: Lun number for the TMF |
| 4938 | * @task_mgmt_cmd: type of TMF to send |
| 4939 | * |
| 4940 | * This routine builds and sends a TMF (SCSI Task Mgmt Function) to |
| 4941 | * a remote port. |
| 4942 | * |
| 4943 | * Return Code: |
| 4944 | * 0x2003 - Error |
| 4945 | * 0x2002 - Success. |
| 4946 | **/ |
| 4947 | static int |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 4948 | lpfc_send_taskmgmt(struct lpfc_vport *vport, struct scsi_cmnd *cmnd, |
| 4949 | unsigned int tgt_id, uint64_t lun_id, |
| 4950 | uint8_t task_mgmt_cmd) |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4951 | { |
| 4952 | struct lpfc_hba *phba = vport->phba; |
| 4953 | struct lpfc_scsi_buf *lpfc_cmd; |
| 4954 | struct lpfc_iocbq *iocbq; |
| 4955 | struct lpfc_iocbq *iocbqrsp; |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 4956 | struct lpfc_rport_data *rdata; |
| 4957 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4958 | int ret; |
| 4959 | int status; |
| 4960 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 4961 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
| 4962 | if (!rdata || !rdata->pnode || !NLP_CHK_NODE_ACT(rdata->pnode)) |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4963 | return FAILED; |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 4964 | pnode = rdata->pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4965 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 4966 | lpfc_cmd = lpfc_get_scsi_buf(phba, pnode); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4967 | if (lpfc_cmd == NULL) |
| 4968 | return FAILED; |
James Smart | 0c41122 | 2013-09-06 12:22:46 -0400 | [diff] [blame] | 4969 | lpfc_cmd->timeout = phba->cfg_task_mgmt_tmo; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4970 | lpfc_cmd->rdata = rdata; |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 4971 | lpfc_cmd->pCmd = cmnd; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4972 | |
| 4973 | status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun_id, |
| 4974 | task_mgmt_cmd); |
| 4975 | if (!status) { |
| 4976 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 4977 | return FAILED; |
| 4978 | } |
| 4979 | |
| 4980 | iocbq = &lpfc_cmd->cur_iocbq; |
| 4981 | iocbqrsp = lpfc_sli_get_iocbq(phba); |
| 4982 | if (iocbqrsp == NULL) { |
| 4983 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 4984 | return FAILED; |
| 4985 | } |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 4986 | iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4987 | |
| 4988 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4989 | "0702 Issue %s to TGT %d LUN %llu " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4990 | "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] | 4991 | lpfc_taskmgmt_name(task_mgmt_cmd), tgt_id, lun_id, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4992 | pnode->nlp_rpi, pnode->nlp_flag, iocbq->sli4_xritag, |
| 4993 | iocbq->iocb_flag); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 4994 | |
| 4995 | status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING, |
| 4996 | iocbq, iocbqrsp, lpfc_cmd->timeout); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 4997 | if ((status != IOCB_SUCCESS) || |
| 4998 | (iocbqrsp->iocb.ulpStatus != IOSTAT_SUCCESS)) { |
James Smart | ae374a3 | 2015-05-22 10:42:41 -0400 | [diff] [blame] | 4999 | if (status != IOCB_SUCCESS || |
| 5000 | iocbqrsp->iocb.ulpStatus != IOSTAT_FCP_RSP_ERROR) |
| 5001 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5002 | "0727 TMF %s to TGT %d LUN %llu " |
| 5003 | "failed (%d, %d) iocb_flag x%x\n", |
| 5004 | lpfc_taskmgmt_name(task_mgmt_cmd), |
| 5005 | tgt_id, lun_id, |
| 5006 | iocbqrsp->iocb.ulpStatus, |
| 5007 | iocbqrsp->iocb.un.ulpWord[4], |
| 5008 | iocbq->iocb_flag); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5009 | /* if ulpStatus != IOCB_SUCCESS, then status == IOCB_SUCCESS */ |
| 5010 | if (status == IOCB_SUCCESS) { |
| 5011 | if (iocbqrsp->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 5012 | /* Something in the FCP_RSP was invalid. |
| 5013 | * Check conditions */ |
| 5014 | ret = lpfc_check_fcp_rsp(vport, lpfc_cmd); |
| 5015 | else |
| 5016 | ret = FAILED; |
| 5017 | } else if (status == IOCB_TIMEDOUT) { |
| 5018 | ret = TIMEOUT_ERROR; |
| 5019 | } else { |
| 5020 | ret = FAILED; |
| 5021 | } |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5022 | } else |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5023 | ret = SUCCESS; |
| 5024 | |
| 5025 | lpfc_sli_release_iocbq(phba, iocbqrsp); |
| 5026 | |
| 5027 | if (ret != TIMEOUT_ERROR) |
| 5028 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
| 5029 | |
| 5030 | return ret; |
| 5031 | } |
| 5032 | |
| 5033 | /** |
| 5034 | * lpfc_chk_tgt_mapped - |
| 5035 | * @vport: The virtual port to check on |
| 5036 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5037 | * |
| 5038 | * This routine delays until the scsi target (aka rport) for the |
| 5039 | * command exists (is present and logged in) or we declare it non-existent. |
| 5040 | * |
| 5041 | * Return code : |
| 5042 | * 0x2003 - Error |
| 5043 | * 0x2002 - Success |
| 5044 | **/ |
| 5045 | static int |
| 5046 | lpfc_chk_tgt_mapped(struct lpfc_vport *vport, struct scsi_cmnd *cmnd) |
| 5047 | { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5048 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5049 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5050 | unsigned long later; |
| 5051 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5052 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5053 | if (!rdata) { |
| 5054 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
| 5055 | "0797 Tgt Map rport failure: rdata x%p\n", rdata); |
| 5056 | return FAILED; |
| 5057 | } |
| 5058 | pnode = rdata->pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5059 | /* |
| 5060 | * If target is not in a MAPPED state, delay until |
| 5061 | * target is rediscovered or devloss timeout expires. |
| 5062 | */ |
| 5063 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; |
| 5064 | while (time_after(later, jiffies)) { |
| 5065 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
| 5066 | return FAILED; |
| 5067 | if (pnode->nlp_state == NLP_STE_MAPPED_NODE) |
| 5068 | return SUCCESS; |
| 5069 | schedule_timeout_uninterruptible(msecs_to_jiffies(500)); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5070 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5071 | if (!rdata) |
| 5072 | return FAILED; |
| 5073 | pnode = rdata->pnode; |
| 5074 | } |
| 5075 | if (!pnode || !NLP_CHK_NODE_ACT(pnode) || |
| 5076 | (pnode->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5077 | return FAILED; |
| 5078 | return SUCCESS; |
| 5079 | } |
| 5080 | |
| 5081 | /** |
| 5082 | * lpfc_reset_flush_io_context - |
| 5083 | * @vport: The virtual port (scsi_host) for the flush context |
| 5084 | * @tgt_id: If aborting by Target contect - specifies the target id |
| 5085 | * @lun_id: If aborting by Lun context - specifies the lun id |
| 5086 | * @context: specifies the context level to flush at. |
| 5087 | * |
| 5088 | * After a reset condition via TMF, we need to flush orphaned i/o |
| 5089 | * contexts from the adapter. This routine aborts any contexts |
| 5090 | * outstanding, then waits for their completions. The wait is |
| 5091 | * bounded by devloss_tmo though. |
| 5092 | * |
| 5093 | * Return code : |
| 5094 | * 0x2003 - Error |
| 5095 | * 0x2002 - Success |
| 5096 | **/ |
| 5097 | static int |
| 5098 | lpfc_reset_flush_io_context(struct lpfc_vport *vport, uint16_t tgt_id, |
| 5099 | uint64_t lun_id, lpfc_ctx_cmd context) |
| 5100 | { |
| 5101 | struct lpfc_hba *phba = vport->phba; |
| 5102 | unsigned long later; |
| 5103 | int cnt; |
| 5104 | |
| 5105 | cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context); |
| 5106 | if (cnt) |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 5107 | lpfc_sli_abort_taskmgmt(vport, |
| 5108 | &phba->sli.ring[phba->sli.fcp_ring], |
| 5109 | tgt_id, lun_id, context); |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5110 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; |
| 5111 | while (time_after(later, jiffies) && cnt) { |
| 5112 | schedule_timeout_uninterruptible(msecs_to_jiffies(20)); |
| 5113 | cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context); |
| 5114 | } |
| 5115 | if (cnt) { |
| 5116 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5117 | "0724 I/O flush failure for context %s : cnt x%x\n", |
| 5118 | ((context == LPFC_CTX_LUN) ? "LUN" : |
| 5119 | ((context == LPFC_CTX_TGT) ? "TGT" : |
| 5120 | ((context == LPFC_CTX_HOST) ? "HOST" : "Unknown"))), |
| 5121 | cnt); |
| 5122 | return FAILED; |
| 5123 | } |
| 5124 | return SUCCESS; |
| 5125 | } |
| 5126 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5127 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5128 | * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5129 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5130 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5131 | * 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] | 5132 | * command. |
| 5133 | * |
| 5134 | * Return code : |
| 5135 | * 0x2003 - Error |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5136 | * 0x2002 - Success |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5137 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5138 | static int |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5139 | lpfc_device_reset_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5140 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5141 | struct Scsi_Host *shost = cmnd->device->host; |
| 5142 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5143 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5144 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5145 | unsigned tgt_id = cmnd->device->id; |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5146 | uint64_t lun_id = cmnd->device->lun; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5147 | struct lpfc_scsi_event_header scsi_event; |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5148 | int status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5149 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5150 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | ad490b6 | 2015-04-07 15:07:26 -0400 | [diff] [blame] | 5151 | if (!rdata || !rdata->pnode) { |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5152 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
James Smart | ad490b6 | 2015-04-07 15:07:26 -0400 | [diff] [blame] | 5153 | "0798 Device Reset rport failure: rdata x%p\n", |
| 5154 | rdata); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5155 | return FAILED; |
| 5156 | } |
| 5157 | pnode = rdata->pnode; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5158 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 5159 | if (status != 0 && status != SUCCESS) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5160 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5161 | |
| 5162 | status = lpfc_chk_tgt_mapped(vport, cmnd); |
| 5163 | if (status == FAILED) { |
| 5164 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5165 | "0721 Device Reset rport failure: rdata x%p\n", rdata); |
| 5166 | return FAILED; |
| 5167 | } |
| 5168 | |
| 5169 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 5170 | scsi_event.subcategory = LPFC_EVENT_LUNRESET; |
| 5171 | scsi_event.lun = lun_id; |
| 5172 | memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 5173 | memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 5174 | |
| 5175 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5176 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
| 5177 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 5178 | status = lpfc_send_taskmgmt(vport, cmnd, tgt_id, lun_id, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5179 | FCP_LUN_RESET); |
| 5180 | |
| 5181 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5182 | "0713 SCSI layer issued Device Reset (%d, %llu) " |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5183 | "return x%x\n", tgt_id, lun_id, status); |
| 5184 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5185 | /* |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5186 | * We have to clean up i/o as : they may be orphaned by the TMF; |
| 5187 | * or if the TMF failed, they may be in an indeterminate state. |
| 5188 | * So, continue on. |
| 5189 | * We will report success if all the i/o aborts successfully. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5190 | */ |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5191 | if (status == SUCCESS) |
| 5192 | status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5193 | LPFC_CTX_LUN); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5194 | |
| 5195 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5196 | } |
| 5197 | |
| 5198 | /** |
| 5199 | * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point |
| 5200 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5201 | * |
| 5202 | * This routine does a target reset by sending a TARGET_RESET task management |
| 5203 | * command. |
| 5204 | * |
| 5205 | * Return code : |
| 5206 | * 0x2003 - Error |
| 5207 | * 0x2002 - Success |
| 5208 | **/ |
| 5209 | static int |
| 5210 | lpfc_target_reset_handler(struct scsi_cmnd *cmnd) |
| 5211 | { |
| 5212 | struct Scsi_Host *shost = cmnd->device->host; |
| 5213 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5214 | struct lpfc_rport_data *rdata; |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5215 | struct lpfc_nodelist *pnode; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5216 | unsigned tgt_id = cmnd->device->id; |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5217 | uint64_t lun_id = cmnd->device->lun; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5218 | struct lpfc_scsi_event_header scsi_event; |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5219 | int status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5220 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5221 | rdata = lpfc_rport_data_from_scsi_device(cmnd->device); |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5222 | if (!rdata) { |
| 5223 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5224 | "0799 Target Reset rport failure: rdata x%p\n", rdata); |
| 5225 | return FAILED; |
| 5226 | } |
| 5227 | pnode = rdata->pnode; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5228 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 5229 | if (status != 0 && status != SUCCESS) |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 5230 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5231 | |
| 5232 | status = lpfc_chk_tgt_mapped(vport, cmnd); |
| 5233 | if (status == FAILED) { |
| 5234 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5235 | "0722 Target Reset rport failure: rdata x%p\n", rdata); |
James Smart | 63e480f | 2015-04-07 15:07:20 -0400 | [diff] [blame] | 5236 | if (pnode) { |
| 5237 | spin_lock_irq(shost->host_lock); |
| 5238 | pnode->nlp_flag &= ~NLP_NPR_ADISC; |
| 5239 | pnode->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; |
| 5240 | spin_unlock_irq(shost->host_lock); |
| 5241 | } |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 5242 | lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
| 5243 | LPFC_CTX_TGT); |
| 5244 | return FAST_IO_FAIL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5245 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5246 | |
| 5247 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 5248 | scsi_event.subcategory = LPFC_EVENT_TGTRESET; |
| 5249 | scsi_event.lun = 0; |
| 5250 | memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); |
| 5251 | memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); |
| 5252 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5253 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5254 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5255 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 5256 | status = lpfc_send_taskmgmt(vport, cmnd, tgt_id, lun_id, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5257 | FCP_TARGET_RESET); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5258 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5259 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 5260 | "0723 SCSI layer issued Target Reset (%d, %llu) " |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5261 | "return x%x\n", tgt_id, lun_id, status); |
| 5262 | |
| 5263 | /* |
| 5264 | * We have to clean up i/o as : they may be orphaned by the TMF; |
| 5265 | * or if the TMF failed, they may be in an indeterminate state. |
| 5266 | * So, continue on. |
| 5267 | * We will report success if all the i/o aborts successfully. |
| 5268 | */ |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5269 | if (status == SUCCESS) |
| 5270 | status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
James Smart | 3a70730 | 2012-06-12 13:54:42 -0400 | [diff] [blame] | 5271 | LPFC_CTX_TGT); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 5272 | return status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5273 | } |
| 5274 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5275 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5276 | * 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] | 5277 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5278 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5279 | * This routine does target reset to all targets on @cmnd->device->host. |
| 5280 | * This emulates Parallel SCSI Bus Reset Semantics. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5281 | * |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5282 | * Return code : |
| 5283 | * 0x2003 - Error |
| 5284 | * 0x2002 - Success |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5285 | **/ |
Jeff Garzik | 94d0e7b8 | 2005-05-28 07:55:48 -0400 | [diff] [blame] | 5286 | static int |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5287 | lpfc_bus_reset_handler(struct scsi_cmnd *cmnd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5288 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5289 | struct Scsi_Host *shost = cmnd->device->host; |
| 5290 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5291 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5292 | struct lpfc_scsi_event_header scsi_event; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5293 | int match; |
| 5294 | int ret = SUCCESS, status, i; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5295 | |
| 5296 | scsi_event.event_type = FC_REG_SCSI_EVENT; |
| 5297 | scsi_event.subcategory = LPFC_EVENT_BUSRESET; |
| 5298 | scsi_event.lun = 0; |
| 5299 | memcpy(scsi_event.wwpn, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 5300 | memcpy(scsi_event.wwnn, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| 5301 | |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5302 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5303 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5304 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 5305 | status = fc_block_scsi_eh(cmnd); |
James Smart | 908e18e | 2012-08-03 12:34:54 -0400 | [diff] [blame] | 5306 | if (status != 0 && status != SUCCESS) |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 5307 | return status; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5308 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5309 | /* |
| 5310 | * Since the driver manages a single bus device, reset all |
| 5311 | * targets known to the driver. Should any target reset |
| 5312 | * fail, this routine returns failure to the midlayer. |
| 5313 | */ |
James Smart | e17da18 | 2006-07-06 15:49:25 -0400 | [diff] [blame] | 5314 | for (i = 0; i < LPFC_MAX_TARGET; i++) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5315 | /* Search for mapped node by target ID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5316 | match = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5317 | spin_lock_irq(shost->host_lock); |
| 5318 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5319 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 5320 | continue; |
James Smart | a6571c6 | 2012-10-31 14:44:42 -0400 | [diff] [blame] | 5321 | if (vport->phba->cfg_fcp2_no_tgt_reset && |
| 5322 | (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE)) |
| 5323 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5324 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE && |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 5325 | ndlp->nlp_sid == i && |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 5326 | ndlp->rport) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5327 | match = 1; |
| 5328 | break; |
| 5329 | } |
| 5330 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5331 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5332 | if (!match) |
| 5333 | continue; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5334 | |
James Smart | eed695d | 2016-10-13 15:06:04 -0700 | [diff] [blame] | 5335 | status = lpfc_send_taskmgmt(vport, cmnd, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5336 | i, 0, FCP_TARGET_RESET); |
| 5337 | |
| 5338 | if (status != SUCCESS) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5339 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5340 | "0700 Bus Reset on target %d failed\n", |
| 5341 | i); |
James Smart | 915caaa | 2008-06-14 22:52:38 -0400 | [diff] [blame] | 5342 | ret = FAILED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5343 | } |
| 5344 | } |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 5345 | /* |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5346 | * We have to clean up i/o as : they may be orphaned by the TMFs |
| 5347 | * above; or if any of the TMFs failed, they may be in an |
| 5348 | * indeterminate state. |
| 5349 | * 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] | 5350 | */ |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5351 | |
| 5352 | status = lpfc_reset_flush_io_context(vport, 0, 0, LPFC_CTX_HOST); |
| 5353 | if (status != SUCCESS) |
James.Smart@Emulex.Com | 6175c02 | 2005-11-28 11:42:05 -0500 | [diff] [blame] | 5354 | ret = FAILED; |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5355 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5356 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5357 | "0714 SCSI layer issued Bus Reset Data: x%x\n", ret); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5358 | return ret; |
| 5359 | } |
| 5360 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5361 | /** |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5362 | * lpfc_host_reset_handler - scsi_host_template eh_host_reset_handler entry pt |
| 5363 | * @cmnd: Pointer to scsi_cmnd data structure. |
| 5364 | * |
| 5365 | * This routine does host reset to the adaptor port. It brings the HBA |
| 5366 | * offline, performs a board restart, and then brings the board back online. |
| 5367 | * The lpfc_offline calls lpfc_sli_hba_down which will abort and local |
| 5368 | * reject all outstanding SCSI commands to the host and error returned |
| 5369 | * back to SCSI mid-level. As this will be SCSI mid-level's last resort |
| 5370 | * of error handling, it will only return error if resetting of the adapter |
| 5371 | * is not successful; in all other cases, will return success. |
| 5372 | * |
| 5373 | * Return code : |
| 5374 | * 0x2003 - Error |
| 5375 | * 0x2002 - Success |
| 5376 | **/ |
| 5377 | static int |
| 5378 | lpfc_host_reset_handler(struct scsi_cmnd *cmnd) |
| 5379 | { |
| 5380 | struct Scsi_Host *shost = cmnd->device->host; |
| 5381 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 5382 | struct lpfc_hba *phba = vport->phba; |
| 5383 | int rc, ret = SUCCESS; |
| 5384 | |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 5385 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5386 | "3172 SCSI layer issued Host Reset Data:\n"); |
| 5387 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 5388 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5389 | lpfc_offline(phba); |
| 5390 | rc = lpfc_sli_brdrestart(phba); |
| 5391 | if (rc) |
| 5392 | ret = FAILED; |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 5393 | rc = lpfc_online(phba); |
| 5394 | if (rc) |
| 5395 | ret = FAILED; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5396 | lpfc_unblock_mgmt_io(phba); |
| 5397 | |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 5398 | if (ret == FAILED) { |
| 5399 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5400 | "3323 Failed host reset, bring it offline\n"); |
| 5401 | lpfc_sli4_offline_eratt(phba); |
| 5402 | } |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5403 | return ret; |
| 5404 | } |
| 5405 | |
| 5406 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5407 | * lpfc_slave_alloc - scsi_host_template slave_alloc entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5408 | * @sdev: Pointer to scsi_device. |
| 5409 | * |
| 5410 | * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's |
| 5411 | * globally available list of scsi buffers. This routine also makes sure scsi |
| 5412 | * buffer is not allocated more than HBA limit conveyed to midlayer. This list |
| 5413 | * of scsi buffer exists for the lifetime of the driver. |
| 5414 | * |
| 5415 | * Return codes: |
| 5416 | * non-0 - Error |
| 5417 | * 0 - Success |
| 5418 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5419 | static int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5420 | lpfc_slave_alloc(struct scsi_device *sdev) |
| 5421 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5422 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 5423 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 5424 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5425 | uint32_t total = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5426 | uint32_t num_to_alloc = 0; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5427 | int num_allocated = 0; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5428 | uint32_t sdev_cnt; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5429 | struct lpfc_device_data *device_data; |
| 5430 | unsigned long flags; |
| 5431 | struct lpfc_name target_wwpn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5432 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 5433 | if (!rport || fc_remote_port_chkready(rport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5434 | return -ENXIO; |
| 5435 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5436 | if (phba->cfg_fof) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5437 | |
| 5438 | /* |
| 5439 | * Check to see if the device data structure for the lun |
| 5440 | * exists. If not, create one. |
| 5441 | */ |
| 5442 | |
| 5443 | u64_to_wwn(rport->port_name, target_wwpn.u.wwn); |
| 5444 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5445 | device_data = __lpfc_get_device_data(phba, |
| 5446 | &phba->luns, |
| 5447 | &vport->fc_portname, |
| 5448 | &target_wwpn, |
| 5449 | sdev->lun); |
| 5450 | if (!device_data) { |
| 5451 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5452 | device_data = lpfc_create_device_data(phba, |
| 5453 | &vport->fc_portname, |
| 5454 | &target_wwpn, |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame^] | 5455 | sdev->lun, |
| 5456 | phba->cfg_XLanePriority, |
| 5457 | true); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5458 | if (!device_data) |
| 5459 | return -ENOMEM; |
| 5460 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5461 | list_add_tail(&device_data->listentry, &phba->luns); |
| 5462 | } |
| 5463 | device_data->rport_data = rport->dd_data; |
| 5464 | device_data->available = true; |
| 5465 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5466 | sdev->hostdata = device_data; |
| 5467 | } else { |
| 5468 | sdev->hostdata = rport->dd_data; |
| 5469 | } |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5470 | sdev_cnt = atomic_inc_return(&phba->sdev_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5471 | |
| 5472 | /* |
| 5473 | * Populate the cmds_per_lun count scsi_bufs into this host's globally |
| 5474 | * 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] | 5475 | * HBA limit conveyed to the midlayer via the host structure. The |
| 5476 | * formula accounts for the lun_queue_depth + error handlers + 1 |
| 5477 | * extra. This list of scsi bufs exists for the lifetime of the driver. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5478 | */ |
| 5479 | total = phba->total_scsi_bufs; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5480 | num_to_alloc = vport->cfg_lun_queue_depth + 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5481 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5482 | /* If allocated buffers are enough do nothing */ |
| 5483 | if ((sdev_cnt * (vport->cfg_lun_queue_depth + 2)) < total) |
| 5484 | return 0; |
| 5485 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5486 | /* Allow some exchanges to be available always to complete discovery */ |
| 5487 | if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5488 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 5489 | "0704 At limitation of %d preallocated " |
| 5490 | "command buffers\n", total); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5491 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5492 | /* Allow some exchanges to be available always to complete discovery */ |
| 5493 | } else if (total + num_to_alloc > |
| 5494 | phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5495 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
| 5496 | "0705 Allocation request of %d " |
| 5497 | "command buffers will exceed max of %d. " |
| 5498 | "Reducing allocation request to %d.\n", |
| 5499 | num_to_alloc, phba->cfg_hba_queue_depth, |
| 5500 | (phba->cfg_hba_queue_depth - total)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5501 | num_to_alloc = phba->cfg_hba_queue_depth - total; |
| 5502 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5503 | num_allocated = lpfc_new_scsi_buf(vport, num_to_alloc); |
| 5504 | if (num_to_alloc != num_allocated) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5505 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
| 5506 | "0708 Allocation request of %d " |
| 5507 | "command buffers did not succeed. " |
| 5508 | "Allocated %d buffers.\n", |
| 5509 | num_to_alloc, num_allocated); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5510 | } |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 5511 | if (num_allocated > 0) |
| 5512 | phba->total_scsi_bufs += num_allocated; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5513 | return 0; |
| 5514 | } |
| 5515 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5516 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5517 | * lpfc_slave_configure - scsi_host_template slave_configure entry point |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5518 | * @sdev: Pointer to scsi_device. |
| 5519 | * |
| 5520 | * This routine configures following items |
| 5521 | * - Tag command queuing support for @sdev if supported. |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5522 | * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set. |
| 5523 | * |
| 5524 | * Return codes: |
| 5525 | * 0 - Success |
| 5526 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5527 | static int |
| 5528 | lpfc_slave_configure(struct scsi_device *sdev) |
| 5529 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5530 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 5531 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5532 | |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 5533 | scsi_change_queue_depth(sdev, vport->cfg_lun_queue_depth); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5534 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5535 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 5536 | lpfc_sli_handle_fast_ring_event(phba, |
| 5537 | &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5538 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
| 5539 | lpfc_poll_rearm_timer(phba); |
| 5540 | } |
| 5541 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5542 | return 0; |
| 5543 | } |
| 5544 | |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5545 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5546 | * lpfc_slave_destroy - slave_destroy entry point of SHT data structure |
James Smart | 9bad767 | 2008-12-04 22:39:02 -0500 | [diff] [blame] | 5547 | * @sdev: Pointer to scsi_device. |
| 5548 | * |
| 5549 | * This routine sets @sdev hostatdata filed to null. |
| 5550 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5551 | static void |
| 5552 | lpfc_slave_destroy(struct scsi_device *sdev) |
| 5553 | { |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5554 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
| 5555 | struct lpfc_hba *phba = vport->phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5556 | unsigned long flags; |
| 5557 | struct lpfc_device_data *device_data = sdev->hostdata; |
| 5558 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5559 | atomic_dec(&phba->sdev_cnt); |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5560 | if ((phba->cfg_fof) && (device_data)) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5561 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5562 | device_data->available = false; |
| 5563 | if (!device_data->oas_enabled) |
| 5564 | lpfc_delete_device_data(phba, device_data); |
| 5565 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5566 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5567 | sdev->hostdata = NULL; |
| 5568 | return; |
| 5569 | } |
| 5570 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5571 | /** |
| 5572 | * lpfc_create_device_data - creates and initializes device data structure for OAS |
| 5573 | * @pha: Pointer to host bus adapter structure. |
| 5574 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5575 | * @target_wwpn: Pointer to target's wwpn information |
| 5576 | * @lun: Lun on target |
| 5577 | * @atomic_create: Flag to indicate if memory should be allocated using the |
| 5578 | * GFP_ATOMIC flag or not. |
| 5579 | * |
| 5580 | * This routine creates a device data structure which will contain identifying |
| 5581 | * information for the device (host wwpn, target wwpn, lun), state of OAS, |
| 5582 | * whether or not the corresponding lun is available by the system, |
| 5583 | * and pointer to the rport data. |
| 5584 | * |
| 5585 | * Return codes: |
| 5586 | * NULL - Error |
| 5587 | * Pointer to lpfc_device_data - Success |
| 5588 | **/ |
| 5589 | struct lpfc_device_data* |
| 5590 | lpfc_create_device_data(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn, |
| 5591 | struct lpfc_name *target_wwpn, uint64_t lun, |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame^] | 5592 | uint32_t pri, bool atomic_create) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5593 | { |
| 5594 | |
| 5595 | struct lpfc_device_data *lun_info; |
| 5596 | int memory_flags; |
| 5597 | |
| 5598 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5599 | !(phba->cfg_fof)) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5600 | return NULL; |
| 5601 | |
| 5602 | /* Attempt to create the device data to contain lun info */ |
| 5603 | |
| 5604 | if (atomic_create) |
| 5605 | memory_flags = GFP_ATOMIC; |
| 5606 | else |
| 5607 | memory_flags = GFP_KERNEL; |
| 5608 | lun_info = mempool_alloc(phba->device_data_mem_pool, memory_flags); |
| 5609 | if (!lun_info) |
| 5610 | return NULL; |
| 5611 | INIT_LIST_HEAD(&lun_info->listentry); |
| 5612 | lun_info->rport_data = NULL; |
| 5613 | memcpy(&lun_info->device_id.vport_wwpn, vport_wwpn, |
| 5614 | sizeof(struct lpfc_name)); |
| 5615 | memcpy(&lun_info->device_id.target_wwpn, target_wwpn, |
| 5616 | sizeof(struct lpfc_name)); |
| 5617 | lun_info->device_id.lun = lun; |
| 5618 | lun_info->oas_enabled = false; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame^] | 5619 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5620 | lun_info->available = false; |
| 5621 | return lun_info; |
| 5622 | } |
| 5623 | |
| 5624 | /** |
| 5625 | * lpfc_delete_device_data - frees a device data structure for OAS |
| 5626 | * @pha: Pointer to host bus adapter structure. |
| 5627 | * @lun_info: Pointer to device data structure to free. |
| 5628 | * |
| 5629 | * This routine frees the previously allocated device data structure passed. |
| 5630 | * |
| 5631 | **/ |
| 5632 | void |
| 5633 | lpfc_delete_device_data(struct lpfc_hba *phba, |
| 5634 | struct lpfc_device_data *lun_info) |
| 5635 | { |
| 5636 | |
| 5637 | if (unlikely(!phba) || !lun_info || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5638 | !(phba->cfg_fof)) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5639 | return; |
| 5640 | |
| 5641 | if (!list_empty(&lun_info->listentry)) |
| 5642 | list_del(&lun_info->listentry); |
| 5643 | mempool_free(lun_info, phba->device_data_mem_pool); |
| 5644 | return; |
| 5645 | } |
| 5646 | |
| 5647 | /** |
| 5648 | * __lpfc_get_device_data - returns the device data for the specified lun |
| 5649 | * @pha: Pointer to host bus adapter structure. |
| 5650 | * @list: Point to list to search. |
| 5651 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5652 | * @target_wwpn: Pointer to target's wwpn information |
| 5653 | * @lun: Lun on target |
| 5654 | * |
| 5655 | * This routine searches the list passed for the specified lun's device data. |
| 5656 | * This function does not hold locks, it is the responsibility of the caller |
| 5657 | * to ensure the proper lock is held before calling the function. |
| 5658 | * |
| 5659 | * Return codes: |
| 5660 | * NULL - Error |
| 5661 | * Pointer to lpfc_device_data - Success |
| 5662 | **/ |
| 5663 | struct lpfc_device_data* |
| 5664 | __lpfc_get_device_data(struct lpfc_hba *phba, struct list_head *list, |
| 5665 | struct lpfc_name *vport_wwpn, |
| 5666 | struct lpfc_name *target_wwpn, uint64_t lun) |
| 5667 | { |
| 5668 | |
| 5669 | struct lpfc_device_data *lun_info; |
| 5670 | |
| 5671 | if (unlikely(!phba) || !list || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5672 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5673 | return NULL; |
| 5674 | |
| 5675 | /* Check to see if the lun is already enabled for OAS. */ |
| 5676 | |
| 5677 | list_for_each_entry(lun_info, list, listentry) { |
| 5678 | if ((memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn, |
| 5679 | sizeof(struct lpfc_name)) == 0) && |
| 5680 | (memcmp(&lun_info->device_id.target_wwpn, target_wwpn, |
| 5681 | sizeof(struct lpfc_name)) == 0) && |
| 5682 | (lun_info->device_id.lun == lun)) |
| 5683 | return lun_info; |
| 5684 | } |
| 5685 | |
| 5686 | return NULL; |
| 5687 | } |
| 5688 | |
| 5689 | /** |
| 5690 | * lpfc_find_next_oas_lun - searches for the next oas lun |
| 5691 | * @pha: Pointer to host bus adapter structure. |
| 5692 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5693 | * @target_wwpn: Pointer to target's wwpn information |
| 5694 | * @starting_lun: Pointer to the lun to start searching for |
| 5695 | * @found_vport_wwpn: Pointer to the found lun's vport wwpn information |
| 5696 | * @found_target_wwpn: Pointer to the found lun's target wwpn information |
| 5697 | * @found_lun: Pointer to the found lun. |
| 5698 | * @found_lun_status: Pointer to status of the found lun. |
| 5699 | * |
| 5700 | * This routine searches the luns list for the specified lun |
| 5701 | * or the first lun for the vport/target. If the vport wwpn contains |
| 5702 | * a zero value then a specific vport is not specified. In this case |
| 5703 | * any vport which contains the lun will be considered a match. If the |
| 5704 | * target wwpn contains a zero value then a specific target is not specified. |
| 5705 | * In this case any target which contains the lun will be considered a |
| 5706 | * match. If the lun is found, the lun, vport wwpn, target wwpn and lun status |
| 5707 | * are returned. The function will also return the next lun if available. |
| 5708 | * If the next lun is not found, starting_lun parameter will be set to |
| 5709 | * NO_MORE_OAS_LUN. |
| 5710 | * |
| 5711 | * Return codes: |
| 5712 | * non-0 - Error |
| 5713 | * 0 - Success |
| 5714 | **/ |
| 5715 | bool |
| 5716 | lpfc_find_next_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn, |
| 5717 | struct lpfc_name *target_wwpn, uint64_t *starting_lun, |
| 5718 | struct lpfc_name *found_vport_wwpn, |
| 5719 | struct lpfc_name *found_target_wwpn, |
| 5720 | uint64_t *found_lun, |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame^] | 5721 | uint32_t *found_lun_status, |
| 5722 | uint32_t *found_lun_pri) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5723 | { |
| 5724 | |
| 5725 | unsigned long flags; |
| 5726 | struct lpfc_device_data *lun_info; |
| 5727 | struct lpfc_device_id *device_id; |
| 5728 | uint64_t lun; |
| 5729 | bool found = false; |
| 5730 | |
| 5731 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
| 5732 | !starting_lun || !found_vport_wwpn || |
| 5733 | !found_target_wwpn || !found_lun || !found_lun_status || |
| 5734 | (*starting_lun == NO_MORE_OAS_LUN) || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5735 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5736 | return false; |
| 5737 | |
| 5738 | lun = *starting_lun; |
| 5739 | *found_lun = NO_MORE_OAS_LUN; |
| 5740 | *starting_lun = NO_MORE_OAS_LUN; |
| 5741 | |
| 5742 | /* Search for lun or the lun closet in value */ |
| 5743 | |
| 5744 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5745 | list_for_each_entry(lun_info, &phba->luns, listentry) { |
| 5746 | if (((wwn_to_u64(vport_wwpn->u.wwn) == 0) || |
| 5747 | (memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn, |
| 5748 | sizeof(struct lpfc_name)) == 0)) && |
| 5749 | ((wwn_to_u64(target_wwpn->u.wwn) == 0) || |
| 5750 | (memcmp(&lun_info->device_id.target_wwpn, target_wwpn, |
| 5751 | sizeof(struct lpfc_name)) == 0)) && |
| 5752 | (lun_info->oas_enabled)) { |
| 5753 | device_id = &lun_info->device_id; |
| 5754 | if ((!found) && |
| 5755 | ((lun == FIND_FIRST_OAS_LUN) || |
| 5756 | (device_id->lun == lun))) { |
| 5757 | *found_lun = device_id->lun; |
| 5758 | memcpy(found_vport_wwpn, |
| 5759 | &device_id->vport_wwpn, |
| 5760 | sizeof(struct lpfc_name)); |
| 5761 | memcpy(found_target_wwpn, |
| 5762 | &device_id->target_wwpn, |
| 5763 | sizeof(struct lpfc_name)); |
| 5764 | if (lun_info->available) |
| 5765 | *found_lun_status = |
| 5766 | OAS_LUN_STATUS_EXISTS; |
| 5767 | else |
| 5768 | *found_lun_status = 0; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame^] | 5769 | *found_lun_pri = lun_info->priority; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5770 | if (phba->cfg_oas_flags & OAS_FIND_ANY_VPORT) |
| 5771 | memset(vport_wwpn, 0x0, |
| 5772 | sizeof(struct lpfc_name)); |
| 5773 | if (phba->cfg_oas_flags & OAS_FIND_ANY_TARGET) |
| 5774 | memset(target_wwpn, 0x0, |
| 5775 | sizeof(struct lpfc_name)); |
| 5776 | found = true; |
| 5777 | } else if (found) { |
| 5778 | *starting_lun = device_id->lun; |
| 5779 | memcpy(vport_wwpn, &device_id->vport_wwpn, |
| 5780 | sizeof(struct lpfc_name)); |
| 5781 | memcpy(target_wwpn, &device_id->target_wwpn, |
| 5782 | sizeof(struct lpfc_name)); |
| 5783 | break; |
| 5784 | } |
| 5785 | } |
| 5786 | } |
| 5787 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5788 | return found; |
| 5789 | } |
| 5790 | |
| 5791 | /** |
| 5792 | * lpfc_enable_oas_lun - enables a lun for OAS operations |
| 5793 | * @pha: Pointer to host bus adapter structure. |
| 5794 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5795 | * @target_wwpn: Pointer to target's wwpn information |
| 5796 | * @lun: Lun |
| 5797 | * |
| 5798 | * This routine enables a lun for oas operations. The routines does so by |
| 5799 | * doing the following : |
| 5800 | * |
| 5801 | * 1) Checks to see if the device data for the lun has been created. |
| 5802 | * 2) If found, sets the OAS enabled flag if not set and returns. |
| 5803 | * 3) Otherwise, creates a device data structure. |
| 5804 | * 4) If successfully created, indicates the device data is for an OAS lun, |
| 5805 | * indicates the lun is not available and add to the list of luns. |
| 5806 | * |
| 5807 | * Return codes: |
| 5808 | * false - Error |
| 5809 | * true - Success |
| 5810 | **/ |
| 5811 | bool |
| 5812 | 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] | 5813 | struct lpfc_name *target_wwpn, uint64_t lun, uint8_t pri) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5814 | { |
| 5815 | |
| 5816 | struct lpfc_device_data *lun_info; |
| 5817 | unsigned long flags; |
| 5818 | |
| 5819 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5820 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5821 | return false; |
| 5822 | |
| 5823 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5824 | |
| 5825 | /* Check to see if the device data for the lun has been created */ |
| 5826 | lun_info = __lpfc_get_device_data(phba, &phba->luns, vport_wwpn, |
| 5827 | target_wwpn, lun); |
| 5828 | if (lun_info) { |
| 5829 | if (!lun_info->oas_enabled) |
| 5830 | lun_info->oas_enabled = true; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame^] | 5831 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5832 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5833 | return true; |
| 5834 | } |
| 5835 | |
| 5836 | /* Create an lun info structure and add to list of luns */ |
| 5837 | lun_info = lpfc_create_device_data(phba, vport_wwpn, target_wwpn, lun, |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame^] | 5838 | pri, false); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5839 | if (lun_info) { |
| 5840 | lun_info->oas_enabled = true; |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 5841 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5842 | lun_info->available = false; |
| 5843 | list_add_tail(&lun_info->listentry, &phba->luns); |
| 5844 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5845 | return true; |
| 5846 | } |
| 5847 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5848 | return false; |
| 5849 | } |
| 5850 | |
| 5851 | /** |
| 5852 | * lpfc_disable_oas_lun - disables a lun for OAS operations |
| 5853 | * @pha: Pointer to host bus adapter structure. |
| 5854 | * @vport_wwpn: Pointer to vport's wwpn information |
| 5855 | * @target_wwpn: Pointer to target's wwpn information |
| 5856 | * @lun: Lun |
| 5857 | * |
| 5858 | * This routine disables a lun for oas operations. The routines does so by |
| 5859 | * doing the following : |
| 5860 | * |
| 5861 | * 1) Checks to see if the device data for the lun is created. |
| 5862 | * 2) If present, clears the flag indicating this lun is for OAS. |
| 5863 | * 3) If the lun is not available by the system, the device data is |
| 5864 | * freed. |
| 5865 | * |
| 5866 | * Return codes: |
| 5867 | * false - Error |
| 5868 | * true - Success |
| 5869 | **/ |
| 5870 | bool |
| 5871 | 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^] | 5872 | struct lpfc_name *target_wwpn, uint64_t lun, uint8_t pri) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5873 | { |
| 5874 | |
| 5875 | struct lpfc_device_data *lun_info; |
| 5876 | unsigned long flags; |
| 5877 | |
| 5878 | if (unlikely(!phba) || !vport_wwpn || !target_wwpn || |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5879 | !phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5880 | return false; |
| 5881 | |
| 5882 | spin_lock_irqsave(&phba->devicelock, flags); |
| 5883 | |
| 5884 | /* Check to see if the lun is available. */ |
| 5885 | lun_info = __lpfc_get_device_data(phba, |
| 5886 | &phba->luns, vport_wwpn, |
| 5887 | target_wwpn, lun); |
| 5888 | if (lun_info) { |
| 5889 | lun_info->oas_enabled = false; |
James Smart | b5749fe | 2016-12-19 15:07:26 -0800 | [diff] [blame^] | 5890 | lun_info->priority = pri; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5891 | if (!lun_info->available) |
| 5892 | lpfc_delete_device_data(phba, lun_info); |
| 5893 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5894 | return true; |
| 5895 | } |
| 5896 | |
| 5897 | spin_unlock_irqrestore(&phba->devicelock, flags); |
| 5898 | return false; |
| 5899 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5900 | |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 5901 | struct scsi_host_template lpfc_template_s3 = { |
| 5902 | .module = THIS_MODULE, |
| 5903 | .name = LPFC_DRIVER_NAME, |
James Smart | 08dcd4c | 2016-07-06 12:35:59 -0700 | [diff] [blame] | 5904 | .proc_name = LPFC_DRIVER_NAME, |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 5905 | .info = lpfc_info, |
| 5906 | .queuecommand = lpfc_queuecommand, |
| 5907 | .eh_abort_handler = lpfc_abort_handler, |
| 5908 | .eh_device_reset_handler = lpfc_device_reset_handler, |
| 5909 | .eh_target_reset_handler = lpfc_target_reset_handler, |
| 5910 | .eh_bus_reset_handler = lpfc_bus_reset_handler, |
| 5911 | .slave_alloc = lpfc_slave_alloc, |
| 5912 | .slave_configure = lpfc_slave_configure, |
| 5913 | .slave_destroy = lpfc_slave_destroy, |
| 5914 | .scan_finished = lpfc_scan_finished, |
| 5915 | .this_id = -1, |
| 5916 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
| 5917 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
| 5918 | .use_clustering = ENABLE_CLUSTERING, |
| 5919 | .shost_attrs = lpfc_hba_attrs, |
| 5920 | .max_sectors = 0xFFFF, |
| 5921 | .vendor_id = LPFC_NL_VENDOR_ID, |
| 5922 | .change_queue_depth = scsi_change_queue_depth, |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 5923 | .track_queue_depth = 1, |
| 5924 | }; |
| 5925 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5926 | struct scsi_host_template lpfc_template = { |
| 5927 | .module = THIS_MODULE, |
| 5928 | .name = LPFC_DRIVER_NAME, |
James Smart | 08dcd4c | 2016-07-06 12:35:59 -0700 | [diff] [blame] | 5929 | .proc_name = LPFC_DRIVER_NAME, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5930 | .info = lpfc_info, |
| 5931 | .queuecommand = lpfc_queuecommand, |
| 5932 | .eh_abort_handler = lpfc_abort_handler, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5933 | .eh_device_reset_handler = lpfc_device_reset_handler, |
| 5934 | .eh_target_reset_handler = lpfc_target_reset_handler, |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5935 | .eh_bus_reset_handler = lpfc_bus_reset_handler, |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 5936 | .eh_host_reset_handler = lpfc_host_reset_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5937 | .slave_alloc = lpfc_slave_alloc, |
| 5938 | .slave_configure = lpfc_slave_configure, |
| 5939 | .slave_destroy = lpfc_slave_destroy, |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 5940 | .scan_finished = lpfc_scan_finished, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5941 | .this_id = -1, |
James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 5942 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5943 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
| 5944 | .use_clustering = ENABLE_CLUSTERING, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5945 | .shost_attrs = lpfc_hba_attrs, |
James.Smart@Emulex.Com | 564b296 | 2005-06-25 10:34:17 -0400 | [diff] [blame] | 5946 | .max_sectors = 0xFFFF, |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5947 | .vendor_id = LPFC_NL_VENDOR_ID, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 5948 | .change_queue_depth = scsi_change_queue_depth, |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 5949 | .track_queue_depth = 1, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5950 | }; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5951 | |
| 5952 | struct scsi_host_template lpfc_vport_template = { |
| 5953 | .module = THIS_MODULE, |
| 5954 | .name = LPFC_DRIVER_NAME, |
James Smart | 08dcd4c | 2016-07-06 12:35:59 -0700 | [diff] [blame] | 5955 | .proc_name = LPFC_DRIVER_NAME, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5956 | .info = lpfc_info, |
| 5957 | .queuecommand = lpfc_queuecommand, |
| 5958 | .eh_abort_handler = lpfc_abort_handler, |
James Smart | bbb9d18 | 2009-06-10 17:23:16 -0400 | [diff] [blame] | 5959 | .eh_device_reset_handler = lpfc_device_reset_handler, |
| 5960 | .eh_target_reset_handler = lpfc_target_reset_handler, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5961 | .eh_bus_reset_handler = lpfc_bus_reset_handler, |
| 5962 | .slave_alloc = lpfc_slave_alloc, |
| 5963 | .slave_configure = lpfc_slave_configure, |
| 5964 | .slave_destroy = lpfc_slave_destroy, |
| 5965 | .scan_finished = lpfc_scan_finished, |
| 5966 | .this_id = -1, |
James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 5967 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5968 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
| 5969 | .use_clustering = ENABLE_CLUSTERING, |
| 5970 | .shost_attrs = lpfc_vport_attrs, |
| 5971 | .max_sectors = 0xFFFF, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 5972 | .change_queue_depth = scsi_change_queue_depth, |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 5973 | .track_queue_depth = 1, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5974 | }; |