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