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